@celljs/core 4.5.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -49
- package/esm/browser/index.d.ts +0 -1
- package/esm/browser/index.js +0 -1
- package/esm/browser/index.js.map +1 -1
- package/esm/browser/shell/application-shell.d.ts +23 -3
- package/esm/browser/shell/application-shell.js +60 -4
- package/esm/browser/shell/application-shell.js.map +1 -1
- package/esm/browser/shell/index.d.ts +0 -1
- package/esm/browser/shell/index.js +0 -1
- package/esm/browser/shell/index.js.map +1 -1
- package/esm/common/annotation/autowired.d.ts +8 -2
- package/esm/common/annotation/autowired.js +7 -8
- package/esm/common/annotation/autowired.js.map +1 -1
- package/esm/common/annotation/detached/autowired-provider.js +1 -2
- package/esm/common/annotation/detached/autowired-provider.js.map +1 -1
- package/esm/common/annotation/value.d.ts +1 -0
- package/esm/common/annotation/value.js +3 -4
- package/esm/common/annotation/value.js.map +1 -1
- package/esm/common/aop/aop-proxy-factory.d.ts +2 -1
- package/esm/common/aop/aop-proxy-factory.js +10 -3
- package/esm/common/aop/aop-proxy-factory.js.map +1 -1
- package/esm/common/aop/class-filter.d.ts +2 -0
- package/esm/common/aop/class-filter.js +10 -3
- package/esm/common/aop/class-filter.js.map +1 -1
- package/esm/common/application/application-entry.js +0 -9
- package/esm/common/application/application-entry.js.map +1 -1
- package/esm/common/application/application-factory.d.ts +9 -3
- package/esm/common/application/application-factory.js +13 -6
- package/esm/common/application/application-factory.js.map +1 -1
- package/esm/common/application/application-protocol.d.ts +12 -0
- package/esm/common/application/application-protocol.js +1 -0
- package/esm/common/application/application-protocol.js.map +1 -1
- package/esm/common/application/application-state.d.ts +1 -1
- package/esm/common/application/application-state.js +4 -4
- package/esm/common/application/application-state.js.map +1 -1
- package/esm/common/application/application.d.ts +4 -2
- package/esm/common/application/application.js +19 -7
- package/esm/common/application/application.js.map +1 -1
- package/esm/common/application/index.d.ts +2 -0
- package/esm/common/application/index.js +2 -0
- package/esm/common/application/index.js.map +1 -1
- package/esm/common/config/config-util.d.ts +0 -1
- package/esm/common/config/config-util.js +0 -6
- package/esm/common/config/config-util.js.map +1 -1
- package/esm/common/container/container-error.d.ts +1 -1
- package/esm/common/container/container-error.js.map +1 -1
- package/esm/common/container/container.d.ts +1 -0
- package/esm/common/container/container.js +6 -1
- package/esm/common/container/container.js.map +1 -1
- package/esm/common/container/index.d.ts +0 -2
- package/esm/common/container/index.js +0 -2
- package/esm/common/container/index.js.map +1 -1
- package/esm/common/container/injection.d.ts +15 -1
- package/esm/common/container/injection.js +37 -1
- package/esm/common/container/injection.js.map +1 -1
- package/esm/common/el/core-context-initializer.d.ts +2 -1
- package/esm/common/el/core-context-initializer.js +5 -3
- package/esm/common/el/core-context-initializer.js.map +1 -1
- package/esm/common/provider/index.d.ts +0 -1
- package/esm/common/provider/index.js +0 -1
- package/esm/common/provider/index.js.map +1 -1
- package/esm/common/test/assembly-test-util.d.ts +16 -0
- package/esm/common/test/assembly-test-util.js +34 -0
- package/esm/common/test/assembly-test-util.js.map +1 -0
- package/esm/node/application/exit-signal-lifecycle.d.ts +5 -0
- package/esm/node/application/exit-signal-lifecycle.js +30 -0
- package/esm/node/application/exit-signal-lifecycle.js.map +1 -0
- package/esm/node/application/index.d.ts +1 -2
- package/esm/node/application/index.js +1 -2
- package/esm/node/application/index.js.map +1 -1
- package/lib/browser/index.d.ts +0 -1
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +0 -1
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/shell/application-shell.d.ts +23 -3
- package/lib/browser/shell/application-shell.d.ts.map +1 -1
- package/lib/browser/shell/application-shell.js +62 -5
- package/lib/browser/shell/application-shell.js.map +1 -1
- package/lib/browser/shell/index.d.ts +0 -1
- package/lib/browser/shell/index.d.ts.map +1 -1
- package/lib/browser/shell/index.js +0 -1
- package/lib/browser/shell/index.js.map +1 -1
- package/lib/common/annotation/autowired.d.ts +8 -2
- package/lib/common/annotation/autowired.d.ts.map +1 -1
- package/lib/common/annotation/autowired.js +7 -8
- package/lib/common/annotation/autowired.js.map +1 -1
- package/lib/common/annotation/detached/autowired-provider.d.ts.map +1 -1
- package/lib/common/annotation/detached/autowired-provider.js +1 -2
- package/lib/common/annotation/detached/autowired-provider.js.map +1 -1
- package/lib/common/annotation/value.d.ts +1 -0
- package/lib/common/annotation/value.d.ts.map +1 -1
- package/lib/common/annotation/value.js +3 -4
- package/lib/common/annotation/value.js.map +1 -1
- package/lib/common/aop/aop-proxy-factory.d.ts +2 -1
- package/lib/common/aop/aop-proxy-factory.d.ts.map +1 -1
- package/lib/common/aop/aop-proxy-factory.js +9 -2
- package/lib/common/aop/aop-proxy-factory.js.map +1 -1
- package/lib/common/aop/aop.spec.js +24 -18
- package/lib/common/aop/aop.spec.js.map +1 -1
- package/lib/common/aop/class-filter.d.ts +2 -0
- package/lib/common/aop/class-filter.d.ts.map +1 -1
- package/lib/common/aop/class-filter.js +9 -2
- package/lib/common/aop/class-filter.js.map +1 -1
- package/lib/common/application/application-entry.d.ts.map +1 -1
- package/lib/common/application/application-entry.js +0 -9
- package/lib/common/application/application-entry.js.map +1 -1
- package/lib/common/application/application-factory.d.ts +9 -3
- package/lib/common/application/application-factory.d.ts.map +1 -1
- package/lib/common/application/application-factory.js +13 -6
- package/lib/common/application/application-factory.js.map +1 -1
- package/lib/common/application/application-protocol.d.ts +12 -0
- package/lib/common/application/application-protocol.d.ts.map +1 -1
- package/lib/common/application/application-protocol.js +2 -1
- package/lib/common/application/application-protocol.js.map +1 -1
- package/lib/common/application/application-state.d.ts +1 -1
- package/lib/common/application/application-state.d.ts.map +1 -1
- package/lib/common/application/application-state.js +5 -5
- package/lib/common/application/application-state.js.map +1 -1
- package/lib/common/application/application.d.ts +4 -2
- package/lib/common/application/application.d.ts.map +1 -1
- package/lib/common/application/application.js +18 -6
- package/lib/common/application/application.js.map +1 -1
- package/lib/common/application/index.d.ts +2 -0
- package/lib/common/application/index.d.ts.map +1 -1
- package/lib/common/application/index.js +2 -0
- package/lib/common/application/index.js.map +1 -1
- package/lib/common/application/lifecycle.spec.js +18 -13
- package/lib/common/application/lifecycle.spec.js.map +1 -1
- package/lib/common/config/config-util.d.ts +0 -1
- package/lib/common/config/config-util.d.ts.map +1 -1
- package/lib/common/config/config-util.js +0 -6
- package/lib/common/config/config-util.js.map +1 -1
- package/lib/common/container/assembly.spec.js +115 -43
- package/lib/common/container/assembly.spec.js.map +1 -1
- package/lib/common/container/container-error.d.ts +1 -1
- package/lib/common/container/container-error.d.ts.map +1 -1
- package/lib/common/container/container-error.js.map +1 -1
- package/lib/common/container/container.d.ts +1 -0
- package/lib/common/container/container.d.ts.map +1 -1
- package/lib/common/container/container.js +6 -1
- package/lib/common/container/container.js.map +1 -1
- package/lib/common/container/container.spec.js +6 -1
- package/lib/common/container/container.spec.js.map +1 -1
- package/lib/common/container/index.d.ts +0 -2
- package/lib/common/container/index.d.ts.map +1 -1
- package/lib/common/container/index.js +0 -2
- package/lib/common/container/index.js.map +1 -1
- package/lib/common/container/injection.d.ts +15 -1
- package/lib/common/container/injection.d.ts.map +1 -1
- package/lib/common/container/injection.js +37 -1
- package/lib/common/container/injection.js.map +1 -1
- package/lib/common/el/core-context-initializer.d.ts +2 -1
- package/lib/common/el/core-context-initializer.d.ts.map +1 -1
- package/lib/common/el/core-context-initializer.js +5 -3
- package/lib/common/el/core-context-initializer.js.map +1 -1
- package/lib/common/el/value-and-el.spec.js +35 -26
- package/lib/common/el/value-and-el.spec.js.map +1 -1
- package/lib/common/provider/index.d.ts +0 -1
- package/lib/common/provider/index.d.ts.map +1 -1
- package/lib/common/provider/index.js +0 -1
- package/lib/common/provider/index.js.map +1 -1
- package/lib/common/test/assembly-test-util.d.ts +17 -0
- package/lib/common/test/assembly-test-util.d.ts.map +1 -0
- package/lib/common/test/assembly-test-util.js +37 -0
- package/lib/common/test/assembly-test-util.js.map +1 -0
- package/lib/node/application/exit-signal-lifecycle.d.ts +6 -0
- package/lib/node/application/exit-signal-lifecycle.d.ts.map +1 -0
- package/lib/node/application/exit-signal-lifecycle.js +33 -0
- package/lib/node/application/exit-signal-lifecycle.js.map +1 -0
- package/lib/node/application/index.d.ts +1 -2
- package/lib/node/application/index.d.ts.map +1 -1
- package/lib/node/application/index.js +1 -2
- package/lib/node/application/index.js.map +1 -1
- package/lib/package.spec.js +17 -2
- package/lib/package.spec.js.map +1 -1
- package/package.json +1 -5
- package/src/browser/index.ts +0 -1
- package/src/browser/shell/application-shell.ts +64 -5
- package/src/browser/shell/index.ts +0 -1
- package/src/common/annotation/autowired.ts +14 -11
- package/src/common/annotation/detached/autowired-provider.ts +1 -2
- package/src/common/annotation/value.ts +4 -4
- package/src/common/aop/aop-proxy-factory.ts +6 -4
- package/src/common/aop/aop.spec.ts +26 -18
- package/src/common/aop/class-filter.ts +6 -3
- package/src/common/application/application-entry.ts +1 -9
- package/src/common/application/application-factory.ts +15 -6
- package/src/common/application/application-protocol.ts +14 -1
- package/src/common/application/application-state.ts +1 -1
- package/src/common/application/application.ts +13 -3
- package/src/common/application/index.ts +2 -0
- package/src/common/application/lifecycle.spec.ts +20 -13
- package/src/common/config/config-util.ts +0 -6
- package/src/common/container/assembly.spec.ts +100 -44
- package/src/common/container/container-error.ts +3 -2
- package/src/common/container/container.spec.ts +8 -2
- package/src/common/container/container.ts +7 -2
- package/src/common/container/index.ts +0 -2
- package/src/common/container/injection.ts +40 -3
- package/src/common/el/core-context-initializer.ts +6 -4
- package/src/common/el/value-and-el.spec.ts +34 -25
- package/src/common/provider/index.ts +0 -1
- package/src/common/test/assembly-test-util.ts +41 -0
- package/src/node/application/exit-signal-lifecycle.ts +23 -0
- package/src/node/application/index.ts +1 -2
- package/src/package.spec.ts +16 -3
- package/esm/browser/application/frontend-application-state.d.ts +0 -4
- package/esm/browser/application/frontend-application-state.js +0 -14
- package/esm/browser/application/frontend-application-state.js.map +0 -1
- package/esm/browser/application/frontend-application.d.ts +0 -30
- package/esm/browser/application/frontend-application.js +0 -123
- package/esm/browser/application/frontend-application.js.map +0 -1
- package/esm/browser/application/index.d.ts +0 -2
- package/esm/browser/application/index.js +0 -3
- package/esm/browser/application/index.js.map +0 -1
- package/esm/browser/shell/shell-protocol.d.ts +0 -4
- package/esm/browser/shell/shell-protocol.js +0 -2
- package/esm/browser/shell/shell-protocol.js.map +0 -1
- package/esm/common/container/container-provider.d.ts +0 -7
- package/esm/common/container/container-provider.js +0 -24
- package/esm/common/container/container-provider.js.map +0 -1
- package/esm/common/container/container-util.d.ts +0 -7
- package/esm/common/container/container-util.js +0 -18
- package/esm/common/container/container-util.js.map +0 -1
- package/esm/common/provider/provider-util.d.ts +0 -5
- package/esm/common/provider/provider-util.js +0 -10
- package/esm/common/provider/provider-util.js.map +0 -1
- package/esm/node/application/backend-application-state.d.ts +0 -4
- package/esm/node/application/backend-application-state.js +0 -14
- package/esm/node/application/backend-application-state.js.map +0 -1
- package/esm/node/application/backend-application.d.ts +0 -10
- package/esm/node/application/backend-application.js +0 -52
- package/esm/node/application/backend-application.js.map +0 -1
- package/lib/browser/application/frontend-application-state.d.ts +0 -5
- package/lib/browser/application/frontend-application-state.d.ts.map +0 -1
- package/lib/browser/application/frontend-application-state.js +0 -17
- package/lib/browser/application/frontend-application-state.js.map +0 -1
- package/lib/browser/application/frontend-application.d.ts +0 -31
- package/lib/browser/application/frontend-application.d.ts.map +0 -1
- package/lib/browser/application/frontend-application.js +0 -126
- package/lib/browser/application/frontend-application.js.map +0 -1
- package/lib/browser/application/index.d.ts +0 -3
- package/lib/browser/application/index.d.ts.map +0 -1
- package/lib/browser/application/index.js +0 -19
- package/lib/browser/application/index.js.map +0 -1
- package/lib/browser/shell/shell-protocol.d.ts +0 -5
- package/lib/browser/shell/shell-protocol.d.ts.map +0 -1
- package/lib/browser/shell/shell-protocol.js +0 -5
- package/lib/browser/shell/shell-protocol.js.map +0 -1
- package/lib/common/container/container-provider.d.ts +0 -8
- package/lib/common/container/container-provider.d.ts.map +0 -1
- package/lib/common/container/container-provider.js +0 -27
- package/lib/common/container/container-provider.js.map +0 -1
- package/lib/common/container/container-util.d.ts +0 -8
- package/lib/common/container/container-util.d.ts.map +0 -1
- package/lib/common/container/container-util.js +0 -21
- package/lib/common/container/container-util.js.map +0 -1
- package/lib/common/provider/provider-util.d.ts +0 -6
- package/lib/common/provider/provider-util.d.ts.map +0 -1
- package/lib/common/provider/provider-util.js +0 -13
- package/lib/common/provider/provider-util.js.map +0 -1
- package/lib/node/application/backend-application-state.d.ts +0 -5
- package/lib/node/application/backend-application-state.d.ts.map +0 -1
- package/lib/node/application/backend-application-state.js +0 -17
- package/lib/node/application/backend-application-state.js.map +0 -1
- package/lib/node/application/backend-application.d.ts +0 -11
- package/lib/node/application/backend-application.d.ts.map +0 -1
- package/lib/node/application/backend-application.js +0 -55
- package/lib/node/application/backend-application.js.map +0 -1
- package/src/browser/application/frontend-application-state.ts +0 -11
- package/src/browser/application/frontend-application.ts +0 -121
- package/src/browser/application/index.ts +0 -2
- package/src/browser/shell/shell-protocol.ts +0 -5
- package/src/common/container/container-provider.ts +0 -25
- package/src/common/container/container-util.ts +0 -17
- package/src/common/provider/provider-util.ts +0 -10
- package/src/node/application/backend-application-state.ts +0 -9
- package/src/node/application/backend-application.ts +0 -43
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assembly-test-util.d.ts","sourceRoot":"","sources":["../../../src/common/test/assembly-test-util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,SAAS,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAG7E;;;GAGG;AACH,yBAAiB,gBAAgB,CAAC;IAE9B,UAAiB,MAAM;QACnB,0DAA0D;QAC1D,SAAS,EAAE,SAAS,CAAC;QACrB,kEAAkE;QAClE,OAAO,EAAE,MAAM,CAAC;QAChB,uHAAuH;QACvH,MAAM,EAAE,MAAM,EAAE,CAAC;KACpB;IAED,SAAgB,KAAK,CAAC,YAAY,EAAE,eAAe,EAAE,EAAE,MAAM,EAAE,eAAe,GAAG,MAAM,CAqBtF;CACJ"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssemblyTestUtil = void 0;
|
|
4
|
+
const container_1 = require("../container/container");
|
|
5
|
+
const container_error_1 = require("../container/container-error");
|
|
6
|
+
/**
|
|
7
|
+
* The assembly test of a package: its DI module loads after those of its dependencies (in the order the
|
|
8
|
+
* toolchain loads them) and every binding resolves, as `cell check` checks a project.
|
|
9
|
+
*/
|
|
10
|
+
var AssemblyTestUtil;
|
|
11
|
+
(function (AssemblyTestUtil) {
|
|
12
|
+
function check(dependencies, module) {
|
|
13
|
+
const before = new container_1.Container(...dependencies).bindings();
|
|
14
|
+
const container = new container_1.Container(...dependencies, module);
|
|
15
|
+
const describe = (bindings) => (bindings !== null && bindings !== void 0 ? bindings : []).map(b => container_1.Container.describe(b)).join('\n');
|
|
16
|
+
let changed = 0;
|
|
17
|
+
for (const [id, bindings] of container.bindings()) {
|
|
18
|
+
if (describe(bindings) !== describe(before.get(id))) {
|
|
19
|
+
changed++;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const errors = [];
|
|
23
|
+
for (const id of container.bindings().keys()) {
|
|
24
|
+
try {
|
|
25
|
+
container.getAll(id);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (container_error_1.ContainerError.is(error)) {
|
|
29
|
+
errors.push(`${container_1.Container.idName(id)}: ${error.code} ${error.message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return { container, changed, errors };
|
|
34
|
+
}
|
|
35
|
+
AssemblyTestUtil.check = check;
|
|
36
|
+
})(AssemblyTestUtil || (exports.AssemblyTestUtil = AssemblyTestUtil = {}));
|
|
37
|
+
//# sourceMappingURL=assembly-test-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assembly-test-util.js","sourceRoot":"","sources":["../../../src/common/test/assembly-test-util.ts"],"names":[],"mappings":";;;AAAA,sDAA6E;AAC7E,kEAA8D;AAE9D;;;GAGG;AACH,IAAiB,gBAAgB,CAiChC;AAjCD,WAAiB,gBAAgB;IAW7B,SAAgB,KAAK,CAAC,YAA+B,EAAE,MAAuB;QAC1E,MAAM,MAAM,GAAG,IAAI,qBAAS,CAAC,GAAG,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;QACzD,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,GAAG,YAAY,EAAE,MAAM,CAAC,CAAC;QACzD,MAAM,QAAQ,GAAG,CAAC,QAAwC,EAAE,EAAE,CAAC,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,qBAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3H,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,KAAK,MAAM,CAAC,EAAE,EAAE,QAAQ,CAAC,IAAI,SAAS,CAAC,QAAQ,EAAE,EAAE,CAAC;YAChD,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;gBAClD,OAAO,EAAE,CAAC;YACd,CAAC;QACL,CAAC;QACD,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,KAAK,MAAM,EAAE,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;YAC3C,IAAI,CAAC;gBACD,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACzB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,IAAI,gCAAc,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;oBAC3B,MAAM,CAAC,IAAI,CAAC,GAAG,qBAAS,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBAC3E,CAAC;YACL,CAAC;QACL,CAAC;QACD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAC1C,CAAC;IArBe,iBAAA,KAAK,QAqBpB,CAAA;AACL,CAAC,EAjCgB,gBAAgB,aAAhB,gBAAgB,GAAhB,gBAAgB,QAiChC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Application, ApplicationLifecycle } from '../../common';
|
|
2
|
+
/** Stops the application, then the process, on SIGINT and SIGTERM. A new application replaces the handlers of the previous one. */
|
|
3
|
+
export declare class ExitSignalLifecycle implements ApplicationLifecycle<Application> {
|
|
4
|
+
onStart(application: Application): void;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=exit-signal-lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit-signal-lifecycle.d.ts","sourceRoot":"","sources":["../../../src/node/application/exit-signal-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAa,MAAM,cAAc,CAAC;AAI5E,mIAAmI;AACnI,qBACa,mBAAoB,YAAW,oBAAoB,CAAC,WAAW,CAAC;IAEzE,OAAO,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAatC;CACJ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ExitSignalLifecycle = void 0;
|
|
10
|
+
const common_1 = require("../../common");
|
|
11
|
+
const TAG = Symbol('ExitSignalLifecycle');
|
|
12
|
+
/** Stops the application, then the process, on SIGINT and SIGTERM. A new application replaces the handlers of the previous one. */
|
|
13
|
+
let ExitSignalLifecycle = class ExitSignalLifecycle {
|
|
14
|
+
onStart(application) {
|
|
15
|
+
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
16
|
+
for (const listener of process.listeners(signal)) {
|
|
17
|
+
if (listener[TAG]) {
|
|
18
|
+
process.removeListener(signal, listener);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const listener = () => {
|
|
22
|
+
void application.stop().finally(() => process.exit(0));
|
|
23
|
+
};
|
|
24
|
+
listener[TAG] = true;
|
|
25
|
+
process.once(signal, listener);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.ExitSignalLifecycle = ExitSignalLifecycle;
|
|
30
|
+
exports.ExitSignalLifecycle = ExitSignalLifecycle = __decorate([
|
|
31
|
+
(0, common_1.Component)(common_1.ApplicationLifecycle)
|
|
32
|
+
], ExitSignalLifecycle);
|
|
33
|
+
//# sourceMappingURL=exit-signal-lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit-signal-lifecycle.js","sourceRoot":"","sources":["../../../src/node/application/exit-signal-lifecycle.ts"],"names":[],"mappings":";;;;;;;;;AAAA,yCAA4E;AAE5E,MAAM,GAAG,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAE1C,mIAAmI;AAE5H,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAE5B,OAAO,CAAC,WAAwB;QAC5B,KAAK,MAAM,MAAM,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAU,EAAE,CAAC;YAClD,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC/C,IAAK,QAAgB,CAAC,GAAG,CAAC,EAAE,CAAC;oBACzB,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;gBAC7C,CAAC;YACL,CAAC;YACD,MAAM,QAAQ,GAAG,GAAG,EAAE;gBAClB,KAAK,WAAW,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3D,CAAC,CAAC;YACD,QAAgB,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;YAC9B,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACnC,CAAC;IACL,CAAC;CACJ,CAAA;;8BAhBY,mBAAmB;IAD/B,IAAA,kBAAS,EAAC,6BAAoB,CAAC;GACnB,mBAAmB,CAgB/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/application/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/application/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
|
|
@@ -14,6 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./backend-application-state"), exports);
|
|
17
|
+
__exportStar(require("./exit-signal-lifecycle"), exports);
|
|
19
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/application/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/application/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC"}
|
package/lib/package.spec.js
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const bun_test_1 = require("bun:test");
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
const common_1 = require("./common");
|
|
8
|
+
const assembly_test_util_1 = require("./common/test/assembly-test-util");
|
|
9
|
+
const static_module_1 = __importDefault(require("./common/static-module"));
|
|
10
|
+
const static_module_2 = __importDefault(require("./node/static-module"));
|
|
11
|
+
const node_1 = require("./node");
|
|
12
|
+
common_1.currentThis.cellProps = {};
|
|
13
|
+
(0, bun_test_1.describe)('@celljs/core', () => {
|
|
14
|
+
(0, bun_test_1.it)('the static modules of the backend load and every binding resolves', () => {
|
|
15
|
+
const { container, changed, errors } = assembly_test_util_1.AssemblyTestUtil.check([static_module_1.default], static_module_2.default);
|
|
16
|
+
(0, bun_test_1.expect)(errors).toEqual([]);
|
|
17
|
+
(0, bun_test_1.expect)(changed).toBeGreaterThan(0);
|
|
18
|
+
(0, bun_test_1.expect)(container.get(common_1.Application)).toBeDefined();
|
|
19
|
+
(0, bun_test_1.expect)(container.get(node_1.ExitSignalLifecycle)).toBeInstanceOf(node_1.ExitSignalLifecycle);
|
|
20
|
+
});
|
|
6
21
|
});
|
|
7
22
|
//# sourceMappingURL=package.spec.js.map
|
package/lib/package.spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":";;;;;AAAA,uCAAgD;AAChD,qCAAoD;AACpD,yEAAoE;AACpE,2EAAkD;AAClD,yEAA8C;AAC9C,iCAA6C;AAE7C,oBAAW,CAAC,SAAS,GAAG,EAAE,CAAC;AAE3B,IAAA,mBAAQ,EAAC,cAAc,EAAE,GAAG,EAAE;IAC1B,IAAA,aAAE,EAAC,mEAAmE,EAAE,GAAG,EAAE;QACzE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,qCAAgB,CAAC,KAAK,CAAC,CAAC,uBAAY,CAAC,EAAE,uBAAU,CAAC,CAAC;QAC1F,IAAA,iBAAM,EAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC3B,IAAA,iBAAM,EAAC,OAAO,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACnC,IAAA,iBAAM,EAAC,SAAS,CAAC,GAAG,CAAC,oBAAW,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACjD,IAAA,iBAAM,EAAC,SAAS,CAAC,GAAG,CAAC,0BAAmB,CAAC,CAAC,CAAC,cAAc,CAAC,0BAAmB,CAAC,CAAC;IACnF,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cell-component"
|
|
@@ -52,10 +52,6 @@
|
|
|
52
52
|
"import": "./esm/browser/index.js",
|
|
53
53
|
"default": "./lib/browser/index.js"
|
|
54
54
|
},
|
|
55
|
-
"./lib/browser/application": {
|
|
56
|
-
"import": "./esm/browser/application/index.js",
|
|
57
|
-
"default": "./lib/browser/application/index.js"
|
|
58
|
-
},
|
|
59
55
|
"./lib/browser/shell": {
|
|
60
56
|
"import": "./esm/browser/shell/index.js",
|
|
61
57
|
"default": "./lib/browser/shell/index.js"
|
package/src/browser/index.ts
CHANGED
|
@@ -1,10 +1,69 @@
|
|
|
1
|
-
import { Component } from '../../common';
|
|
2
|
-
import {
|
|
1
|
+
import { Application, ApplicationShell, Component, Value } from '../../common';
|
|
2
|
+
import { parseCssTime } from '../browser';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Attaches the UI to the page: renders it into the element of `html.rootId` (else the body), removes the
|
|
6
|
+
* `cell-preload` indicator once its CSS transition is over, and stops the application when the page goes
|
|
7
|
+
* away (`pagehide`). A UI library implements {@link render}.
|
|
8
|
+
*/
|
|
9
|
+
export abstract class AbstractApplicationShell implements ApplicationShell {
|
|
10
|
+
|
|
11
|
+
@Value('html.rootId')
|
|
12
|
+
protected readonly hostDomId: string;
|
|
13
|
+
|
|
14
|
+
async attach(application: Application): Promise<void> {
|
|
15
|
+
const host = await this.getHost();
|
|
16
|
+
this.render(host);
|
|
17
|
+
await new Promise<void>(resolve => requestAnimationFrame(() => resolve()));
|
|
18
|
+
await this.revealShell(host);
|
|
19
|
+
// pagehide, not unload: browsers deprecate unload and block it by permissions policy.
|
|
20
|
+
window.addEventListener('pagehide', () => void application.stop());
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
protected abstract render(host: HTMLElement): void;
|
|
24
|
+
|
|
25
|
+
/** The element of `html.rootId`, else the body, once the document has one. */
|
|
26
|
+
protected getHost(): Promise<HTMLElement> {
|
|
27
|
+
if (document.body) {
|
|
28
|
+
return Promise.resolve(document.getElementById(this.hostDomId) || document.body);
|
|
29
|
+
}
|
|
30
|
+
return new Promise<HTMLElement>(resolve =>
|
|
31
|
+
window.addEventListener('load', () => resolve(document.getElementById(this.hostDomId) || document.body), { once: true })
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The element that shows while the application starts (a splash screen). */
|
|
36
|
+
protected getStartupIndicator(host: HTMLElement): HTMLElement | undefined {
|
|
37
|
+
const startupElements = host.getElementsByClassName('cell-preload');
|
|
38
|
+
return startupElements.length === 0 ? undefined : startupElements[0] as HTMLElement;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Hides the startup indicator with the `cell-hidden` CSS class, then removes it after its CSS
|
|
43
|
+
* transition.
|
|
44
|
+
*/
|
|
45
|
+
protected revealShell(host: HTMLElement): Promise<void> {
|
|
46
|
+
const startupElem = this.getStartupIndicator(host);
|
|
47
|
+
if (!startupElem) {
|
|
48
|
+
return Promise.resolve();
|
|
49
|
+
}
|
|
50
|
+
return new Promise(resolve => {
|
|
51
|
+
window.requestAnimationFrame(() => {
|
|
52
|
+
startupElem.classList.add('cell-hidden');
|
|
53
|
+
const transitionDuration = parseCssTime(window.getComputedStyle(startupElem).transitionDuration, 0);
|
|
54
|
+
window.setTimeout(() => {
|
|
55
|
+
startupElem.parentElement?.removeChild(startupElem);
|
|
56
|
+
resolve();
|
|
57
|
+
}, transitionDuration);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The shell of an application without a UI library. */
|
|
4
64
|
@Component(ApplicationShell)
|
|
5
|
-
export class ApplicationShellImpl
|
|
6
|
-
|
|
65
|
+
export class ApplicationShellImpl extends AbstractApplicationShell {
|
|
66
|
+
protected render(host: HTMLElement): void {
|
|
7
67
|
host.textContent = 'Hello, Cell.';
|
|
8
68
|
}
|
|
9
|
-
|
|
10
69
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { ContainerUtil } from '../container/container-util';
|
|
2
1
|
import { InjectionUtil } from '../container/injection';
|
|
3
|
-
import type { ComponentId } from '../container/container';
|
|
2
|
+
import type { ComponentId, Container } from '../container/container';
|
|
4
3
|
import { AnnotationUtil } from '../utils';
|
|
5
4
|
|
|
6
5
|
export interface AutowiredOption {
|
|
7
6
|
id?: ComponentId,
|
|
8
7
|
multi?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Resolved when the property is first read, from the container that created the instance, instead of
|
|
10
|
+
* when the instance is created: breaks a circular dependency. Properties only.
|
|
11
|
+
*/
|
|
9
12
|
detached?: boolean
|
|
10
13
|
}
|
|
11
14
|
|
|
@@ -20,8 +23,9 @@ export const Autowired = function (idOrOption?: IdOrAutowiredOption): PropertyDe
|
|
|
20
23
|
};
|
|
21
24
|
};
|
|
22
25
|
|
|
26
|
+
/** The value of a `detached` property, from the container that created the instance. */
|
|
23
27
|
export interface DoGetValue {
|
|
24
|
-
(option: AutowiredOption,
|
|
28
|
+
(option: AutowiredOption, container: Container): any;
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
export interface DoInject {
|
|
@@ -50,17 +54,18 @@ const doInjectDefault: DoInject = ({ id, multi }, t, k, i) => {
|
|
|
50
54
|
point.multi = multi;
|
|
51
55
|
};
|
|
52
56
|
|
|
53
|
-
const doGetValueDefault: DoGetValue = ({ id, multi }) => multi ?
|
|
57
|
+
const doGetValueDefault: DoGetValue = ({ id, multi }, container) => multi ? container.getAll(id!) : container.get(id!);
|
|
54
58
|
|
|
55
59
|
export function applyAutowiredDecorator(option: AutowiredOption, target: any, targetKey: string, index?: number,
|
|
56
60
|
doInject: DoInject = doInjectDefault, doGetValue: DoGetValue = doGetValueDefault) {
|
|
57
61
|
|
|
58
62
|
if (option.detached) {
|
|
59
63
|
if (index !== undefined) {
|
|
60
|
-
throw new Error(
|
|
64
|
+
throw new Error(`${target.name}: a detached injection is resolved when its property is read, so it cannot be a constructor parameter.`);
|
|
61
65
|
}
|
|
62
66
|
// The value comes from the getter: the container leaves the property alone.
|
|
63
67
|
InjectionUtil.remove(target, targetKey);
|
|
68
|
+
InjectionUtil.keepContainer(target);
|
|
64
69
|
createAutowiredProperty(option, doGetValue, target, targetKey);
|
|
65
70
|
} else {
|
|
66
71
|
doInject(option, target, targetKey, index);
|
|
@@ -68,16 +73,14 @@ export function applyAutowiredDecorator(option: AutowiredOption, target: any, ta
|
|
|
68
73
|
return option;
|
|
69
74
|
}
|
|
70
75
|
|
|
76
|
+
/** A getter on the prototype that resolves the value once per instance, then keeps it on the instance. */
|
|
71
77
|
export function createAutowiredProperty(option: AutowiredOption, doGetValue: DoGetValue, target: any, property: string): void {
|
|
72
|
-
let value: any;
|
|
73
78
|
Object.defineProperty(target, property, {
|
|
74
79
|
enumerable: true,
|
|
80
|
+
configurable: true,
|
|
75
81
|
get(): any {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
value = doGetValue(option, target, property);
|
|
80
|
-
|
|
82
|
+
const value = doGetValue(option, InjectionUtil.containerOf(this, property));
|
|
83
|
+
Object.defineProperty(this, property, { value, enumerable: true, configurable: true, writable: true });
|
|
81
84
|
return value;
|
|
82
85
|
}
|
|
83
86
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ContainerUtil } from '../../container/container-util';
|
|
2
1
|
import { applyAutowiredDecorator, DoGetValue, IdOrAutowiredOptionWithoutMulti, parseAutowiredOption } from '../autowired';
|
|
3
2
|
import { PROVIDER, ID_KEY, doInjectForAutowiredProvider } from '../autowired-provider';
|
|
4
3
|
|
|
@@ -10,4 +9,4 @@ export const AutowiredProvider = function (idOrOption?: IdOrAutowiredOptionWitho
|
|
|
10
9
|
};
|
|
11
10
|
};
|
|
12
11
|
|
|
13
|
-
const doGetValueForProvider: DoGetValue = option =>
|
|
12
|
+
const doGetValueForProvider: DoGetValue = (option, container) => container.get(PROVIDER, { tags: { [ID_KEY]: option.id } });
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ConfigUtil } from '../config/config-util';
|
|
2
1
|
import { AnnotationUtil } from '../utils';
|
|
3
2
|
import { ConfigProvider } from '../config/config-protocol';
|
|
4
3
|
import { InjectionUtil } from '../container/injection';
|
|
@@ -8,6 +7,7 @@ export const VALUE = Symbol('Value');
|
|
|
8
7
|
|
|
9
8
|
export interface ValueOption {
|
|
10
9
|
el?: string,
|
|
10
|
+
/** Read every time the property is read, from the container that created the instance. Properties only. */
|
|
11
11
|
detached?: boolean
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -33,9 +33,10 @@ export function parseValueOption(target: any, targetKey: string, index?: number,
|
|
|
33
33
|
export function applyValueDecorator(option: ValueOption, target: any, targetKey: string, index?: number) {
|
|
34
34
|
if (option.detached) {
|
|
35
35
|
if (index !== undefined) {
|
|
36
|
-
throw new Error(
|
|
36
|
+
throw new Error(`${target.name}: a detached @Value is read when its property is read, so it cannot be a constructor parameter.`);
|
|
37
37
|
}
|
|
38
38
|
InjectionUtil.remove(target, targetKey);
|
|
39
|
+
InjectionUtil.keepContainer(target);
|
|
39
40
|
createValueProperty(option, target, targetKey);
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
@@ -50,8 +51,7 @@ export function createValueProperty(option: ValueOption, target: any, property:
|
|
|
50
51
|
Object.defineProperty(target, property, {
|
|
51
52
|
enumerable: true,
|
|
52
53
|
get(): any {
|
|
53
|
-
|
|
54
|
-
return ConfigUtil.get(el);
|
|
54
|
+
return InjectionUtil.containerOf(this, property).get<ConfigProvider>(ConfigProvider).get(option.el!);
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { PROXY_TARGET } from '../utils/proxy-util';
|
|
2
|
-
import {
|
|
3
|
-
import type { ComponentId } from '../container/container';
|
|
2
|
+
import { ComponentId, Container } from '../container/container';
|
|
4
3
|
import { AfterReturningAdvice, AfterThrowsAdvice, AopProxy, AopProxyFactory, AOP_TAG, MethodBeforeAdvice, ProxyConfig } from './aop-protocol';
|
|
5
|
-
import { Component } from '../annotation';
|
|
4
|
+
import { Autowired, Component } from '../annotation';
|
|
6
5
|
|
|
7
6
|
interface Advices {
|
|
8
7
|
before: MethodBeforeAdvice[];
|
|
@@ -13,8 +12,11 @@ interface Advices {
|
|
|
13
12
|
@Component({ id: AopProxyFactory, proxy: false })
|
|
14
13
|
export class AopProxyFactoryImpl implements AopProxyFactory {
|
|
15
14
|
|
|
15
|
+
@Autowired(Container)
|
|
16
|
+
protected readonly container: Container;
|
|
17
|
+
|
|
16
18
|
protected getAdvices<T>(id: ComponentId<T>, tagValues: string[]): T[] {
|
|
17
|
-
const container =
|
|
19
|
+
const container = this.container;
|
|
18
20
|
const advices: T[] = [];
|
|
19
21
|
for (const tagValue of tagValues) {
|
|
20
22
|
const query = { tags: { [AOP_TAG]: tagValue } };
|
|
@@ -2,8 +2,16 @@ import { describe, it } from 'bun:test';
|
|
|
2
2
|
import { expect } from 'chai';
|
|
3
3
|
import { ApplicationFactory } from '../application/application-factory';
|
|
4
4
|
import { Component, Aspect } from '../annotation';
|
|
5
|
-
import { ContainerUtil } from '../container/container-util';
|
|
6
5
|
import { MethodBeforeAdvice, AfterReturningAdvice, AfterThrowsAdvice } from './aop-protocol';
|
|
6
|
+
import { Container, ContainerModule } from '../container/container';
|
|
7
|
+
import { Application } from '../application/application-protocol';
|
|
8
|
+
|
|
9
|
+
let container: Container;
|
|
10
|
+
/** A new container for each test; the components registered since the previous one go into it. */
|
|
11
|
+
async function create(props: Record<string, any>, ...modules: ContainerModule[]): Promise<Application> {
|
|
12
|
+
container = ApplicationFactory.createContainer(props, ...modules);
|
|
13
|
+
return container.get<Application>(Application);
|
|
14
|
+
}
|
|
7
15
|
|
|
8
16
|
/**
|
|
9
17
|
* AOP 的约定(阶段 1.E 行为测试):@Aspect 登记通知,proxy: true 的组件被代理。
|
|
@@ -46,8 +54,8 @@ describe('core AOP', () => {
|
|
|
46
54
|
return a + b;
|
|
47
55
|
}
|
|
48
56
|
}
|
|
49
|
-
await
|
|
50
|
-
expect(await
|
|
57
|
+
await create(AOP_ON);
|
|
58
|
+
expect(await container.get(Calc).add(1, 2)).to.equal(3);
|
|
51
59
|
expect(log).to.deep.equal(['before:add(1,2)', 'run', 'after:add=3']);
|
|
52
60
|
});
|
|
53
61
|
|
|
@@ -60,10 +68,10 @@ describe('core AOP', () => {
|
|
|
60
68
|
throw new Error('nope');
|
|
61
69
|
}
|
|
62
70
|
}
|
|
63
|
-
await
|
|
71
|
+
await create(AOP_ON);
|
|
64
72
|
let caught: Error | undefined;
|
|
65
73
|
try {
|
|
66
|
-
await
|
|
74
|
+
await container.get(Failing).go();
|
|
67
75
|
} catch (e) {
|
|
68
76
|
caught = e as Error;
|
|
69
77
|
}
|
|
@@ -78,8 +86,8 @@ describe('core AOP', () => {
|
|
|
78
86
|
class Sync {
|
|
79
87
|
twice(n: number) { return n * 2; }
|
|
80
88
|
}
|
|
81
|
-
await
|
|
82
|
-
const result =
|
|
89
|
+
await create(AOP_ON);
|
|
90
|
+
const result = container.get(Sync).twice(4) as unknown;
|
|
83
91
|
expect(result).to.be.instanceOf(Promise);
|
|
84
92
|
expect(await result).to.equal(8);
|
|
85
93
|
});
|
|
@@ -91,16 +99,16 @@ describe('core AOP', () => {
|
|
|
91
99
|
class NotProxied {
|
|
92
100
|
hi() { return 'hi'; }
|
|
93
101
|
}
|
|
94
|
-
await
|
|
95
|
-
expect(
|
|
102
|
+
await create(AOP_ON);
|
|
103
|
+
expect(container.get(NotProxied).hi()).to.equal('hi');
|
|
96
104
|
|
|
97
105
|
recordingAspects(log);
|
|
98
106
|
@Component({ proxy: true })
|
|
99
107
|
class Disabled {
|
|
100
108
|
hi() { return 'hi'; }
|
|
101
109
|
}
|
|
102
|
-
await
|
|
103
|
-
expect(
|
|
110
|
+
await create({ aop: { enabled: false } });
|
|
111
|
+
expect(container.get(Disabled).hi()).to.equal('hi');
|
|
104
112
|
expect(log).to.deep.equal([]);
|
|
105
113
|
});
|
|
106
114
|
|
|
@@ -109,8 +117,8 @@ describe('core AOP', () => {
|
|
|
109
117
|
class Lonely {
|
|
110
118
|
hi() { return 'hi'; }
|
|
111
119
|
}
|
|
112
|
-
await
|
|
113
|
-
expect(
|
|
120
|
+
await create(AOP_ON);
|
|
121
|
+
expect(container.get(Lonely).hi()).to.equal('hi');
|
|
114
122
|
});
|
|
115
123
|
|
|
116
124
|
it('pointcut:只作用于 sysTags 里带该标签的组件', async () => {
|
|
@@ -124,9 +132,9 @@ describe('core AOP', () => {
|
|
|
124
132
|
class Other {
|
|
125
133
|
save(x: string) { return `other ${x}`; }
|
|
126
134
|
}
|
|
127
|
-
await
|
|
128
|
-
expect(await
|
|
129
|
-
expect(
|
|
135
|
+
await create(AOP_ON);
|
|
136
|
+
expect(await container.get(Audited).save('a')).to.equal('saved a');
|
|
137
|
+
expect(container.get(Other).save('b')).to.equal('other b');
|
|
130
138
|
expect(log).to.deep.equal(['before:save(a)', 'after:save=saved a']);
|
|
131
139
|
});
|
|
132
140
|
|
|
@@ -138,8 +146,8 @@ describe('core AOP', () => {
|
|
|
138
146
|
readonly label = 'L';
|
|
139
147
|
async m() { return 1; }
|
|
140
148
|
}
|
|
141
|
-
await
|
|
142
|
-
expect(
|
|
149
|
+
await create(AOP_ON);
|
|
150
|
+
expect(container.get(WithField).label).to.equal('L');
|
|
143
151
|
expect(log).to.deep.equal([]);
|
|
144
152
|
});
|
|
145
153
|
});
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { Newable } from '../utils';
|
|
2
|
-
import {
|
|
2
|
+
import { Container } from '../container/container';
|
|
3
3
|
import { AfterReturningAdvice, AfterThrowsAdvice, AOP_TAG, ClassFilter, MethodBeforeAdvice } from './aop-protocol';
|
|
4
|
-
import { Component, ComponentMetadata } from '../annotation';
|
|
4
|
+
import { Autowired, Component, ComponentMetadata } from '../annotation';
|
|
5
5
|
|
|
6
6
|
@Component({ id: ClassFilter, proxy: false })
|
|
7
7
|
export class ClassFilterImpl implements ClassFilter {
|
|
8
8
|
|
|
9
|
+
@Autowired(Container)
|
|
10
|
+
protected readonly container: Container;
|
|
11
|
+
|
|
9
12
|
matches(clazz: Newable<any>, metadata: ComponentMetadata): boolean {
|
|
10
|
-
const container =
|
|
13
|
+
const container = this.container;
|
|
11
14
|
for (const tagValue of metadata.sysTags) {
|
|
12
15
|
const query = { tags: { [AOP_TAG]: tagValue } };
|
|
13
16
|
if (container.isBound(MethodBeforeAdvice, query)
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import { container } from '../container/dynamic-container';
|
|
2
2
|
import { Application } from './application-protocol';
|
|
3
3
|
import { ApplicationHost } from './application-host';
|
|
4
|
-
import { ContainerProvider } from '../container';
|
|
5
4
|
export { container } from '../container/dynamic-container';
|
|
6
5
|
|
|
7
6
|
const host = ApplicationHost.get();
|
|
8
7
|
|
|
9
8
|
(async () => {
|
|
10
9
|
const c = await container;
|
|
11
|
-
try {
|
|
12
|
-
ContainerProvider.provide();
|
|
13
|
-
return;
|
|
14
|
-
} catch (error) {
|
|
15
|
-
// NoOp
|
|
16
|
-
}
|
|
17
|
-
ContainerProvider.set(c);
|
|
18
10
|
await host?.beforeStart?.();
|
|
19
11
|
const application = c.get<Application>(Application);
|
|
20
12
|
try {
|
|
@@ -40,4 +32,4 @@ const host = ApplicationHost.get();
|
|
|
40
32
|
throw error;
|
|
41
33
|
}
|
|
42
34
|
host.failed(error);
|
|
43
|
-
});
|
|
35
|
+
});
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import { ContainerProvider } from '../container/container-provider';
|
|
3
2
|
import { Application, ApplicationProps } from './application-protocol';
|
|
4
|
-
import './application';
|
|
5
|
-
import './application-state';
|
|
6
3
|
import { autoBind } from '../container/auto-bind';
|
|
7
4
|
import commonModule from '../static-module';
|
|
8
5
|
import { currentThis } from '../utils';
|
|
9
6
|
import { Container, ContainerModule } from '../container/container';
|
|
10
7
|
|
|
8
|
+
/** Creates applications in-process, for tests and tools: the common components, `modules` and `props` as configuration. */
|
|
11
9
|
export class ApplicationFactory {
|
|
12
|
-
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A container with the components of @celljs/core, those registered since the last `autoBind()`, and `modules`.
|
|
13
|
+
* The configuration is read before it returns (the application is created), so containers created one
|
|
14
|
+
* after the other each keep their own.
|
|
15
|
+
*/
|
|
16
|
+
static createContainer(applicationProps: ApplicationProps, ...modules: ContainerModule[]): Container {
|
|
13
17
|
currentThis.cellProps = applicationProps;
|
|
14
18
|
const container = new Container();
|
|
15
19
|
container.load(commonModule, autoBind(), ...modules);
|
|
16
|
-
|
|
17
|
-
return container
|
|
20
|
+
container.get<Application>(Application);
|
|
21
|
+
return container;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The application of {@link createContainer}, not started. */
|
|
25
|
+
static async create(applicationProps: ApplicationProps, ...modules: ContainerModule[]): Promise<Application> {
|
|
26
|
+
return ApplicationFactory.createContainer(applicationProps, ...modules).get<Application>(Application);
|
|
18
27
|
}
|
|
19
28
|
}
|
|
@@ -11,6 +11,7 @@ export const ApplicationLifecycle = Symbol('ApplicationLifecycle');
|
|
|
11
11
|
export const Application = Symbol('Application');
|
|
12
12
|
export const ApplicationStateService = Symbol('ApplicationStateService');
|
|
13
13
|
export const ApplicationProps = Symbol('ApplicationProps');
|
|
14
|
+
export const ApplicationShell = Symbol('ApplicationShell');
|
|
14
15
|
|
|
15
16
|
export type ApplicationProps = Record<string, any>;
|
|
16
17
|
|
|
@@ -24,6 +25,10 @@ export interface ApplicationLifecycle<T extends Application> {
|
|
|
24
25
|
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
/**
|
|
29
|
+
* The application: one implementation for every target. `start()` runs the lifecycles, then attaches the
|
|
30
|
+
* {@link ApplicationShell} when the target has one (the browser).
|
|
31
|
+
*/
|
|
27
32
|
export interface Application {
|
|
28
33
|
|
|
29
34
|
start(): Promise<void>;
|
|
@@ -31,6 +36,14 @@ export interface Application {
|
|
|
31
36
|
|
|
32
37
|
}
|
|
33
38
|
|
|
39
|
+
/**
|
|
40
|
+
* What shows a started application: in the browser, the UI attached to the page (`@celljs/core/lib/browser`
|
|
41
|
+
* binds one, `@celljs/react` replaces it). Backends have none.
|
|
42
|
+
*/
|
|
43
|
+
export interface ApplicationShell {
|
|
44
|
+
attach(application: Application): MaybePromise<void>;
|
|
45
|
+
}
|
|
46
|
+
|
|
34
47
|
export abstract class AbstractApplication implements Application {
|
|
35
48
|
|
|
36
49
|
@Autowired(ApplicationLifecycle) @Optional()
|
|
@@ -148,4 +161,4 @@ export abstract class AbstractApplicationStateService<T extends string> implemen
|
|
|
148
161
|
return Promise.race(states.map(s => this.reachedState(s)));
|
|
149
162
|
}
|
|
150
163
|
|
|
151
|
-
}
|
|
164
|
+
}
|
|
@@ -2,6 +2,6 @@ import { Component } from '../annotation';
|
|
|
2
2
|
import { AbstractApplicationStateService, ApplicationState, ApplicationStateService } from './application-protocol';
|
|
3
3
|
|
|
4
4
|
@Component(ApplicationStateService)
|
|
5
|
-
export class
|
|
5
|
+
export class ApplicationStateServiceImpl extends AbstractApplicationStateService<ApplicationState> {
|
|
6
6
|
|
|
7
7
|
}
|