From 78154763d40f26b55b185be1ecaf94d7f75bff69 Mon Sep 17 00:00:00 2001 From: Xc Date: Sun, 8 Jan 2023 18:29:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86ports=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E7=9A=84=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/index.d.ts | 4 ++-- lib/index.js | 3 ++- lib/port.d.ts | 1 + lib/port.js | 13 ++++++++++++- src/index.ts | 3 ++- src/port.ts | 11 +++++++++++ 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index fc2771f..07454f3 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,7 +1,7 @@ import { operate, select, fetchRows, count, aggregate } from './crud'; import { amap } from './amap'; import { getTranslations } from './locales'; -import { registerPorts, importEntity, exportEntity } from './port'; +import { registerPorts, clearPorts, importEntity, exportEntity } from './port'; declare const aspectDict: { operate: typeof operate; select: typeof select; @@ -15,4 +15,4 @@ declare const aspectDict: { }; export default aspectDict; export * from './AspectDict'; -export { registerPorts, }; +export { registerPorts, clearPorts, }; diff --git a/lib/index.js b/lib/index.js index 303aca1..e781f88 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,12 +1,13 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.registerPorts = void 0; +exports.clearPorts = exports.registerPorts = void 0; const tslib_1 = require("tslib"); const crud_1 = require("./crud"); const amap_1 = require("./amap"); const locales_1 = require("./locales"); const port_1 = require("./port"); Object.defineProperty(exports, "registerPorts", { enumerable: true, get: function () { return port_1.registerPorts; } }); +Object.defineProperty(exports, "clearPorts", { enumerable: true, get: function () { return port_1.clearPorts; } }); const aspectDict = { operate: crud_1.operate, select: crud_1.select, diff --git a/lib/port.d.ts b/lib/port.d.ts index ea6c9ac..d97a055 100644 --- a/lib/port.d.ts +++ b/lib/port.d.ts @@ -2,6 +2,7 @@ import { Importation, Exportation, EntityDict } from 'oak-domain/lib/types/Entity'; import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore'; export declare function registerPorts(importations: Importation[], exportations: Exportation[]): void; +export declare function clearPorts(): void; export declare function importEntity>(params: FormData, context: Cxt): Promise; export declare function exportEntity>(params: { entity: T; diff --git a/lib/port.js b/lib/port.js index 026f7b8..b2ea3c2 100644 --- a/lib/port.js +++ b/lib/port.js @@ -1,23 +1,34 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.exportEntity = exports.importEntity = exports.registerPorts = void 0; +exports.exportEntity = exports.importEntity = exports.clearPorts = exports.registerPorts = void 0; const tslib_1 = require("tslib"); const assert_1 = tslib_1.__importDefault(require("assert")); const Importations = {}; const Exportations = {}; function registerPorts(importations, exportations) { for (const i of importations) { + (0, assert_1.default)(!Importations.hasOwnProperty(i.id), `Importation中的id【${i.id}】重复了`); Object.assign(Importations, { [i.id]: i, }); } for (const e of exportations) { + (0, assert_1.default)(!Exportations.hasOwnProperty(e.id), `Exportation中的id【${e.id}】重复了`); Object.assign(Exportations, { [e.id]: e, }); } } exports.registerPorts = registerPorts; +function clearPorts() { + for (const i in Importations) { + delete Importations[i]; + } + for (const e in Exportations) { + delete Exportations[e]; + } +} +exports.clearPorts = clearPorts; function getImportation(id) { (0, assert_1.default)(Importations.hasOwnProperty(id), `id为[${id}]的importation不存在`); return Importations[id]; diff --git a/src/index.ts b/src/index.ts index 87cb014..7acecb5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import { operate, select, fetchRows, count, aggregate } from './crud'; import { amap } from './amap'; import { getTranslations } from './locales'; -import { registerPorts, importEntity, exportEntity } from './port'; +import { registerPorts, clearPorts, importEntity, exportEntity } from './port'; const aspectDict = { operate, select, @@ -18,4 +18,5 @@ export default aspectDict; export * from './AspectDict'; export { registerPorts, + clearPorts, }; \ No newline at end of file diff --git a/src/port.ts b/src/port.ts index 236e75f..f7e32ae 100644 --- a/src/port.ts +++ b/src/port.ts @@ -7,18 +7,29 @@ const Exportations: Record = {}; export function registerPorts(importations: Importation[], exportations: Exportation[]) { for (const i of importations) { + assert(!Importations.hasOwnProperty(i.id), `Importation中的id【${i.id}】重复了`); Object.assign(Importations, { [i.id]: i, }); } for (const e of exportations) { + assert(!Exportations.hasOwnProperty(e.id), `Exportation中的id【${e.id}】重复了`); Object.assign(Exportations, { [e.id]: e, }); } } +export function clearPorts() { + for (const i in Importations) { + delete Importations[i]; + } + for (const e in Exportations) { + delete Exportations[e]; + } +} + function getImportation(id: string) { assert(Importations.hasOwnProperty(id), `id为[${id}]的importation不存在`); return Importations[id] as Importation;