@celljs/core 4.0.0 → 4.2.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 +49 -68
- package/esm/browser/static-module.d.ts +1 -1
- package/esm/common/annotation/aspect.d.ts +2 -1
- package/esm/common/annotation/aspect.js.map +1 -1
- package/esm/common/annotation/autowired-provider.d.ts +0 -2
- package/esm/common/annotation/autowired-provider.js +4 -13
- package/esm/common/annotation/autowired-provider.js.map +1 -1
- package/esm/common/annotation/autowired.d.ts +1 -1
- package/esm/common/annotation/autowired.js +11 -3
- package/esm/common/annotation/autowired.js.map +1 -1
- package/esm/common/annotation/component.d.ts +4 -8
- package/esm/common/annotation/component.js +0 -6
- package/esm/common/annotation/component.js.map +1 -1
- package/esm/common/annotation/constant.d.ts +1 -1
- package/esm/common/annotation/constant.js +6 -3
- package/esm/common/annotation/constant.js.map +1 -1
- package/esm/common/annotation/detached/autowired-provider.js +2 -2
- package/esm/common/annotation/detached/autowired-provider.js.map +1 -1
- package/esm/common/annotation/index.d.ts +0 -6
- package/esm/common/annotation/index.js +0 -6
- package/esm/common/annotation/index.js.map +1 -1
- package/esm/common/annotation/named.d.ts +2 -1
- package/esm/common/annotation/named.js +5 -1
- package/esm/common/annotation/named.js.map +1 -1
- package/esm/common/annotation/optional.d.ts +2 -1
- package/esm/common/annotation/optional.js +5 -1
- package/esm/common/annotation/optional.js.map +1 -1
- package/esm/common/annotation/post-construct.d.ts +2 -1
- package/esm/common/annotation/post-construct.js +5 -1
- package/esm/common/annotation/post-construct.js.map +1 -1
- package/esm/common/annotation/tagged.d.ts +2 -1
- package/esm/common/annotation/tagged.js +6 -1
- package/esm/common/annotation/tagged.js.map +1 -1
- package/esm/common/annotation/value.d.ts +3 -2
- package/esm/common/annotation/value.js +7 -10
- package/esm/common/annotation/value.js.map +1 -1
- package/esm/common/aop/aop-proxy-factory.d.ts +6 -2
- package/esm/common/aop/aop-proxy-factory.js +44 -28
- package/esm/common/aop/aop-proxy-factory.js.map +1 -1
- package/esm/common/aop/class-filter.js +6 -6
- package/esm/common/aop/class-filter.js.map +1 -1
- package/esm/common/application/application-factory.d.ts +1 -1
- package/esm/common/application/application-factory.js +4 -4
- package/esm/common/application/application-factory.js.map +1 -1
- package/esm/common/application/application-protocol.js +1 -1
- package/esm/common/application/application-protocol.js.map +1 -1
- package/esm/common/config/config-provider.js +2 -1
- package/esm/common/config/config-provider.js.map +1 -1
- package/esm/common/container/auto-bind.d.ts +7 -3
- package/esm/common/container/auto-bind.js +54 -71
- package/esm/common/container/auto-bind.js.map +1 -1
- package/esm/common/container/container-error.d.ts +21 -0
- package/esm/common/container/container-error.js +22 -0
- package/esm/common/container/container-error.js.map +1 -0
- package/esm/common/container/container-provider.d.ts +5 -4
- package/esm/common/container/container-provider.js +2 -1
- package/esm/common/container/container-provider.js.map +1 -1
- package/esm/common/container/container-util.d.ts +5 -7
- package/esm/common/container/container-util.js +8 -19
- package/esm/common/container/container-util.js.map +1 -1
- package/esm/common/container/container.d.ts +104 -0
- package/esm/common/container/container.js +299 -0
- package/esm/common/container/container.js.map +1 -0
- package/esm/common/container/dynamic-container.d.ts +1 -1
- package/esm/common/container/dynamic-container.js +2 -2
- package/esm/common/container/dynamic-container.js.map +1 -1
- package/esm/common/container/index.d.ts +5 -6
- package/esm/common/container/index.js +5 -3
- package/esm/common/container/index.js.map +1 -1
- package/esm/common/container/injection.d.ts +40 -0
- package/esm/common/container/injection.js +109 -0
- package/esm/common/container/injection.js.map +1 -0
- package/esm/common/container/scope.d.ts +2 -3
- package/esm/common/container/scope.js +2 -3
- package/esm/common/container/scope.js.map +1 -1
- package/esm/common/el/application-expression-engine.d.ts +7 -0
- package/esm/common/{provider/provider-creator.js → el/application-expression-engine.js} +11 -11
- package/esm/common/el/application-expression-engine.js.map +1 -0
- package/esm/common/el/core-context-initializer.d.ts +3 -2
- package/esm/common/el/core-context-initializer.js +10 -8
- package/esm/common/el/core-context-initializer.js.map +1 -1
- package/esm/common/el/expression-compiler.d.ts +7 -17
- package/esm/common/el/expression-compiler.js +10 -166
- package/esm/common/el/expression-compiler.js.map +1 -1
- package/esm/common/el/expression-engine.d.ts +61 -0
- package/esm/common/el/expression-engine.js +459 -0
- package/esm/common/el/expression-engine.js.map +1 -0
- package/esm/common/el/expression-handler.d.ts +8 -4
- package/esm/common/el/expression-handler.js +15 -58
- package/esm/common/el/expression-handler.js.map +1 -1
- package/esm/common/el/expression-protocol.d.ts +3 -5
- package/esm/common/el/expression-protocol.js +0 -1
- package/esm/common/el/expression-protocol.js.map +1 -1
- package/esm/common/el/expression-util.d.ts +69 -0
- package/esm/common/el/expression-util.js +346 -0
- package/esm/common/el/expression-util.js.map +1 -0
- package/esm/common/el/index.d.ts +3 -1
- package/esm/common/el/index.js +3 -1
- package/esm/common/el/index.js.map +1 -1
- package/esm/common/logger/abstract-logger.d.ts +4 -2
- package/esm/common/logger/abstract-logger.js +11 -6
- package/esm/common/logger/abstract-logger.js.map +1 -1
- package/esm/common/logger/logger-protocol.d.ts +4 -0
- package/esm/common/logger/logger-protocol.js +2 -0
- package/esm/common/logger/logger-protocol.js.map +1 -1
- package/esm/common/logger/logger.js +7 -7
- package/esm/common/logger/logger.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/provider/provider-protocol.d.ts +5 -9
- package/esm/common/provider/provider-protocol.js +0 -1
- package/esm/common/provider/provider-protocol.js.map +1 -1
- package/esm/common/provider/provider-util.d.ts +1 -1
- package/esm/common/provider/provider-util.js +2 -2
- package/esm/common/provider/provider-util.js.map +1 -1
- package/esm/common/provider/provider.d.ts +7 -6
- package/esm/common/provider/provider.js +15 -26
- package/esm/common/provider/provider.js.map +1 -1
- package/esm/common/static-module.d.ts +1 -1
- package/esm/common/static-module.js +1 -1
- package/esm/common/static-module.js.map +1 -1
- package/esm/common/test/mock-logger.d.ts +1 -0
- package/esm/common/test/mock-logger.js +5 -13
- package/esm/common/test/mock-logger.js.map +1 -1
- package/esm/common/test/test-module.d.ts +1 -1
- package/esm/common/test/test-module.js +1 -1
- package/esm/common/test/test-module.js.map +1 -1
- package/esm/common/utils/annotation-util.js +2 -1
- package/esm/common/utils/annotation-util.js.map +1 -1
- package/esm/common/utils/emitter.d.ts +1 -10
- package/esm/common/utils/emitter.js +0 -56
- package/esm/common/utils/emitter.js.map +1 -1
- package/esm/common/utils/mime-type-util.js +1 -1
- package/esm/common/utils/mime-type-util.js.map +1 -1
- package/esm/common/utils/mime-type.js +1 -1
- package/esm/common/utils/mime-type.js.map +1 -1
- package/esm/common/utils/proxy-util.d.ts +5 -2
- package/esm/common/utils/proxy-util.js +10 -28
- package/esm/common/utils/proxy-util.js.map +1 -1
- package/esm/node/context/context.d.ts +11 -2
- package/esm/node/context/context.js +36 -12
- package/esm/node/context/context.js.map +1 -1
- package/esm/node/index.d.ts +0 -1
- package/esm/node/index.js +0 -1
- package/esm/node/index.js.map +1 -1
- package/esm/node/static-module.d.ts +1 -1
- package/lib/browser/static-module.d.ts +1 -1
- package/lib/common/annotation/aspect.d.ts +2 -1
- package/lib/common/annotation/aspect.d.ts.map +1 -1
- package/lib/common/annotation/aspect.js.map +1 -1
- package/lib/common/annotation/autowired-provider.d.ts +0 -2
- package/lib/common/annotation/autowired-provider.d.ts.map +1 -1
- package/lib/common/annotation/autowired-provider.js +4 -14
- package/lib/common/annotation/autowired-provider.js.map +1 -1
- package/lib/common/annotation/autowired.d.ts +1 -1
- package/lib/common/annotation/autowired.d.ts.map +1 -1
- package/lib/common/annotation/autowired.js +11 -3
- package/lib/common/annotation/autowired.js.map +1 -1
- package/lib/common/annotation/component.d.ts +4 -8
- package/lib/common/annotation/component.d.ts.map +1 -1
- package/lib/common/annotation/component.js +0 -6
- package/lib/common/annotation/component.js.map +1 -1
- package/lib/common/annotation/constant.d.ts +1 -1
- package/lib/common/annotation/constant.d.ts.map +1 -1
- package/lib/common/annotation/constant.js +6 -3
- package/lib/common/annotation/constant.js.map +1 -1
- package/lib/common/annotation/detached/autowired-provider.js +2 -2
- package/lib/common/annotation/detached/autowired-provider.js.map +1 -1
- package/lib/common/annotation/index.d.ts +0 -6
- package/lib/common/annotation/index.d.ts.map +1 -1
- package/lib/common/annotation/index.js +0 -6
- package/lib/common/annotation/index.js.map +1 -1
- package/lib/common/annotation/named.d.ts +2 -1
- package/lib/common/annotation/named.d.ts.map +1 -1
- package/lib/common/annotation/named.js +6 -2
- package/lib/common/annotation/named.js.map +1 -1
- package/lib/common/annotation/optional.d.ts +2 -1
- package/lib/common/annotation/optional.d.ts.map +1 -1
- package/lib/common/annotation/optional.js +6 -2
- package/lib/common/annotation/optional.js.map +1 -1
- package/lib/common/annotation/post-construct.d.ts +2 -1
- package/lib/common/annotation/post-construct.d.ts.map +1 -1
- package/lib/common/annotation/post-construct.js +6 -2
- package/lib/common/annotation/post-construct.js.map +1 -1
- package/lib/common/annotation/tagged.d.ts +2 -1
- package/lib/common/annotation/tagged.d.ts.map +1 -1
- package/lib/common/annotation/tagged.js +7 -2
- package/lib/common/annotation/tagged.js.map +1 -1
- package/lib/common/annotation/value.d.ts +3 -2
- package/lib/common/annotation/value.d.ts.map +1 -1
- package/lib/common/annotation/value.js +7 -10
- package/lib/common/annotation/value.js.map +1 -1
- package/lib/common/aop/aop-proxy-factory.d.ts +6 -2
- package/lib/common/aop/aop-proxy-factory.d.ts.map +1 -1
- package/lib/common/aop/aop-proxy-factory.js +45 -29
- package/lib/common/aop/aop-proxy-factory.js.map +1 -1
- package/lib/common/aop/aop.spec.d.ts +2 -0
- package/lib/common/aop/aop.spec.d.ts.map +1 -0
- package/lib/common/aop/aop.spec.js +170 -0
- package/lib/common/aop/aop.spec.js.map +1 -0
- package/lib/common/aop/class-filter.js +7 -7
- package/lib/common/aop/class-filter.js.map +1 -1
- package/lib/common/application/application-factory.d.ts +1 -1
- package/lib/common/application/application-factory.d.ts.map +1 -1
- package/lib/common/application/application-factory.js +4 -4
- package/lib/common/application/application-factory.js.map +1 -1
- package/lib/common/application/application-protocol.js +1 -1
- package/lib/common/application/application-protocol.js.map +1 -1
- package/lib/common/application/lifecycle.spec.d.ts +2 -0
- package/lib/common/application/lifecycle.spec.d.ts.map +1 -0
- package/lib/common/application/lifecycle.spec.js +155 -0
- package/lib/common/application/lifecycle.spec.js.map +1 -0
- package/lib/common/config/config-provider.js +2 -1
- package/lib/common/config/config-provider.js.map +1 -1
- package/lib/common/container/assembly.spec.d.ts +2 -0
- package/lib/common/container/assembly.spec.d.ts.map +1 -0
- package/lib/common/container/assembly.spec.js +464 -0
- package/lib/common/container/assembly.spec.js.map +1 -0
- package/lib/common/container/auto-bind.d.ts +7 -3
- package/lib/common/container/auto-bind.d.ts.map +1 -1
- package/lib/common/container/auto-bind.js +54 -72
- package/lib/common/container/auto-bind.js.map +1 -1
- package/lib/common/container/container-error.d.ts +22 -0
- package/lib/common/container/container-error.d.ts.map +1 -0
- package/lib/common/container/container-error.js +26 -0
- package/lib/common/container/container-error.js.map +1 -0
- package/lib/common/container/container-provider.d.ts +5 -4
- package/lib/common/container/container-provider.d.ts.map +1 -1
- package/lib/common/container/container-provider.js +3 -2
- package/lib/common/container/container-provider.js.map +1 -1
- package/lib/common/container/container-util.d.ts +5 -7
- package/lib/common/container/container-util.d.ts.map +1 -1
- package/lib/common/container/container-util.js +8 -19
- package/lib/common/container/container-util.js.map +1 -1
- package/lib/common/container/container.d.ts +105 -0
- package/lib/common/container/container.d.ts.map +1 -0
- package/lib/common/container/container.js +305 -0
- package/lib/common/container/container.js.map +1 -0
- package/lib/common/container/container.spec.d.ts +2 -0
- package/lib/common/container/container.spec.d.ts.map +1 -0
- package/lib/common/container/container.spec.js +334 -0
- package/lib/common/container/container.spec.js.map +1 -0
- package/lib/common/container/dynamic-container.d.ts +1 -1
- package/lib/common/container/dynamic-container.d.ts.map +1 -1
- package/lib/common/container/dynamic-container.js +3 -3
- package/lib/common/container/dynamic-container.js.map +1 -1
- package/lib/common/container/index.d.ts +5 -6
- package/lib/common/container/index.d.ts.map +1 -1
- package/lib/common/container/index.js +5 -3
- package/lib/common/container/index.js.map +1 -1
- package/lib/common/container/injection.d.ts +41 -0
- package/lib/common/container/injection.d.ts.map +1 -0
- package/lib/common/container/injection.js +112 -0
- package/lib/common/container/injection.js.map +1 -0
- package/lib/common/container/scope.d.ts +2 -3
- package/lib/common/container/scope.d.ts.map +1 -1
- package/lib/common/container/scope.js +2 -3
- package/lib/common/container/scope.js.map +1 -1
- package/lib/common/el/application-expression-engine.d.ts +8 -0
- package/lib/common/el/application-expression-engine.d.ts.map +1 -0
- package/lib/common/el/application-expression-engine.js +22 -0
- package/lib/common/el/application-expression-engine.js.map +1 -0
- package/lib/common/el/core-context-initializer.d.ts +3 -2
- package/lib/common/el/core-context-initializer.d.ts.map +1 -1
- package/lib/common/el/core-context-initializer.js +9 -7
- package/lib/common/el/core-context-initializer.js.map +1 -1
- package/lib/common/el/expression-compiler.d.ts +7 -17
- package/lib/common/el/expression-compiler.d.ts.map +1 -1
- package/lib/common/el/expression-compiler.js +10 -166
- package/lib/common/el/expression-compiler.js.map +1 -1
- package/lib/common/el/expression-engine.d.ts +62 -0
- package/lib/common/el/expression-engine.d.ts.map +1 -0
- package/lib/common/el/expression-engine.js +465 -0
- package/lib/common/el/expression-engine.js.map +1 -0
- package/lib/common/el/expression-engine.spec.d.ts +2 -0
- package/lib/common/el/expression-engine.spec.d.ts.map +1 -0
- package/lib/common/el/expression-engine.spec.js +100 -0
- package/lib/common/el/expression-engine.spec.js.map +1 -0
- package/lib/common/el/expression-handler.d.ts +8 -4
- package/lib/common/el/expression-handler.d.ts.map +1 -1
- package/lib/common/el/expression-handler.js +14 -60
- package/lib/common/el/expression-handler.js.map +1 -1
- package/lib/common/el/expression-handler.spec.d.ts +2 -0
- package/lib/common/el/expression-handler.spec.d.ts.map +1 -0
- package/lib/common/el/expression-handler.spec.js +98 -0
- package/lib/common/el/expression-handler.spec.js.map +1 -0
- package/lib/common/el/expression-protocol.d.ts +3 -5
- package/lib/common/el/expression-protocol.d.ts.map +1 -1
- package/lib/common/el/expression-protocol.js +1 -2
- package/lib/common/el/expression-protocol.js.map +1 -1
- package/lib/common/el/expression-util.d.ts +70 -0
- package/lib/common/el/expression-util.d.ts.map +1 -0
- package/lib/common/el/expression-util.js +351 -0
- package/lib/common/el/expression-util.js.map +1 -0
- package/lib/common/el/expression-util.spec.d.ts +2 -0
- package/lib/common/el/expression-util.spec.d.ts.map +1 -0
- package/lib/common/el/expression-util.spec.js +45 -0
- package/lib/common/el/expression-util.spec.js.map +1 -0
- package/lib/common/el/index.d.ts +3 -1
- package/lib/common/el/index.d.ts.map +1 -1
- package/lib/common/el/index.js +3 -1
- package/lib/common/el/index.js.map +1 -1
- package/lib/common/el/value-and-el.spec.d.ts +2 -0
- package/lib/common/el/value-and-el.spec.d.ts.map +1 -0
- package/lib/common/el/value-and-el.spec.js +216 -0
- package/lib/common/el/value-and-el.spec.js.map +1 -0
- package/lib/common/logger/abstract-logger.d.ts +4 -2
- package/lib/common/logger/abstract-logger.d.ts.map +1 -1
- package/lib/common/logger/abstract-logger.js +10 -5
- package/lib/common/logger/abstract-logger.js.map +1 -1
- package/lib/common/logger/logger-protocol.d.ts +4 -0
- package/lib/common/logger/logger-protocol.d.ts.map +1 -1
- package/lib/common/logger/logger-protocol.js +3 -1
- package/lib/common/logger/logger-protocol.js.map +1 -1
- package/lib/common/logger/logger.js +7 -7
- package/lib/common/logger/logger.js.map +1 -1
- package/lib/common/logger/logger.spec.d.ts +2 -0
- package/lib/common/logger/logger.spec.d.ts.map +1 -0
- package/lib/common/logger/logger.spec.js +57 -0
- package/lib/common/logger/logger.spec.js.map +1 -0
- 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/provider/provider-protocol.d.ts +5 -9
- package/lib/common/provider/provider-protocol.d.ts.map +1 -1
- package/lib/common/provider/provider-protocol.js +1 -2
- package/lib/common/provider/provider-protocol.js.map +1 -1
- package/lib/common/provider/provider-util.d.ts +1 -1
- package/lib/common/provider/provider-util.d.ts.map +1 -1
- package/lib/common/provider/provider-util.js +2 -2
- package/lib/common/provider/provider-util.js.map +1 -1
- package/lib/common/provider/provider.d.ts +7 -6
- package/lib/common/provider/provider.d.ts.map +1 -1
- package/lib/common/provider/provider.js +16 -26
- package/lib/common/provider/provider.js.map +1 -1
- package/lib/common/static-module.d.ts +1 -1
- package/lib/common/static-module.js +2 -2
- package/lib/common/static-module.js.map +1 -1
- package/lib/common/test/mock-logger.d.ts +1 -0
- package/lib/common/test/mock-logger.d.ts.map +1 -1
- package/lib/common/test/mock-logger.js +5 -12
- package/lib/common/test/mock-logger.js.map +1 -1
- package/lib/common/test/test-module.d.ts +1 -1
- package/lib/common/test/test-module.d.ts.map +1 -1
- package/lib/common/test/test-module.js +2 -2
- package/lib/common/test/test-module.js.map +1 -1
- package/lib/common/utils/annotation-util.js +2 -1
- package/lib/common/utils/annotation-util.js.map +1 -1
- package/lib/common/utils/emitter.d.ts +1 -10
- package/lib/common/utils/emitter.d.ts.map +1 -1
- package/lib/common/utils/emitter.js +1 -58
- package/lib/common/utils/emitter.js.map +1 -1
- package/lib/common/utils/mime-type-util.js +1 -1
- package/lib/common/utils/mime-type-util.js.map +1 -1
- package/lib/common/utils/mime-type.js +1 -1
- package/lib/common/utils/mime-type.js.map +1 -1
- package/lib/common/utils/proxy-util.d.ts +5 -2
- package/lib/common/utils/proxy-util.d.ts.map +1 -1
- package/lib/common/utils/proxy-util.js +12 -30
- package/lib/common/utils/proxy-util.js.map +1 -1
- package/lib/common/utils/utils-behavior.spec.d.ts +2 -0
- package/lib/common/utils/utils-behavior.spec.d.ts.map +1 -0
- package/lib/common/utils/utils-behavior.spec.js +232 -0
- package/lib/common/utils/utils-behavior.spec.js.map +1 -0
- package/lib/node/context/context.d.ts +11 -2
- package/lib/node/context/context.d.ts.map +1 -1
- package/lib/node/context/context.js +36 -10
- package/lib/node/context/context.js.map +1 -1
- package/lib/node/context/context.spec.d.ts +2 -0
- package/lib/node/context/context.spec.d.ts.map +1 -0
- package/lib/node/context/context.spec.js +202 -0
- package/lib/node/context/context.spec.js.map +1 -0
- package/lib/node/index.d.ts +0 -1
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +0 -1
- package/lib/node/index.js.map +1 -1
- package/lib/node/static-module.d.ts +1 -1
- package/package.json +9 -21
- package/src/common/annotation/aspect.ts +2 -1
- package/src/common/annotation/autowired-provider.ts +4 -17
- package/src/common/annotation/autowired.ts +14 -6
- package/src/common/annotation/component.ts +6 -26
- package/src/common/annotation/constant.ts +10 -7
- package/src/common/annotation/detached/autowired-provider.ts +2 -2
- package/src/common/annotation/index.ts +0 -6
- package/src/common/annotation/named.ts +7 -1
- package/src/common/annotation/optional.ts +6 -1
- package/src/common/annotation/post-construct.ts +6 -1
- package/src/common/annotation/tagged.ts +8 -1
- package/src/common/annotation/value.ts +9 -11
- package/src/common/aop/aop-proxy-factory.ts +52 -30
- package/src/common/aop/aop.spec.ts +145 -0
- package/src/common/aop/class-filter.ts +6 -6
- package/src/common/application/application-factory.ts +4 -5
- package/src/common/application/application-protocol.ts +1 -1
- package/src/common/application/lifecycle.spec.ts +148 -0
- package/src/common/config/config-provider.ts +1 -1
- package/src/common/container/assembly.spec.ts +288 -0
- package/src/common/container/auto-bind.ts +56 -74
- package/src/common/container/container-error.ts +31 -0
- package/src/common/container/container-provider.ts +9 -7
- package/src/common/container/container-util.ts +8 -19
- package/src/common/container/container.spec.ts +262 -0
- package/src/common/container/container.ts +363 -0
- package/src/common/container/dynamic-container.ts +2 -2
- package/src/common/container/index.ts +5 -7
- package/src/common/container/injection.ts +135 -0
- package/src/common/container/scope.ts +2 -1
- package/src/common/el/application-expression-engine.ts +9 -0
- package/src/common/el/core-context-initializer.ts +9 -8
- package/src/common/el/expression-compiler.ts +9 -168
- package/src/common/el/expression-engine.spec.ts +107 -0
- package/src/common/el/expression-engine.ts +487 -0
- package/src/common/el/expression-handler.spec.ts +109 -0
- package/src/common/el/expression-handler.ts +17 -57
- package/src/common/el/expression-protocol.ts +4 -8
- package/src/common/el/expression-util.spec.ts +45 -0
- package/src/common/el/expression-util.ts +362 -0
- package/src/common/el/index.ts +3 -1
- package/src/common/el/value-and-el.spec.ts +186 -0
- package/src/common/logger/abstract-logger.ts +12 -6
- package/src/common/logger/logger-protocol.ts +5 -0
- package/src/common/logger/logger.spec.ts +61 -0
- package/src/common/logger/logger.ts +7 -7
- package/src/common/provider/index.ts +0 -2
- package/src/common/provider/provider-protocol.ts +5 -11
- package/src/common/provider/provider-util.ts +3 -3
- package/src/common/provider/provider.ts +17 -29
- package/src/common/static-module.ts +1 -1
- package/src/common/test/mock-logger.ts +3 -2
- package/src/common/test/test-module.ts +1 -1
- package/src/common/utils/annotation-util.ts +2 -2
- package/src/common/utils/emitter.ts +1 -63
- package/src/common/utils/mime-type-util.ts +1 -1
- package/src/common/utils/mime-type.ts +1 -1
- package/src/common/utils/proxy-util.ts +8 -28
- package/src/common/utils/utils-behavior.spec.ts +259 -0
- package/src/node/context/context.spec.ts +219 -0
- package/src/node/context/context.ts +35 -10
- package/src/node/index.ts +0 -1
- package/esm/common/annotation/decorate.d.ts +0 -1
- package/esm/common/annotation/decorate.js +0 -2
- package/esm/common/annotation/decorate.js.map +0 -1
- package/esm/common/annotation/inject.d.ts +0 -1
- package/esm/common/annotation/inject.js +0 -2
- package/esm/common/annotation/inject.js.map +0 -1
- package/esm/common/annotation/injectable.d.ts +0 -1
- package/esm/common/annotation/injectable.js +0 -2
- package/esm/common/annotation/injectable.js.map +0 -1
- package/esm/common/annotation/pre-destroy.d.ts +0 -1
- package/esm/common/annotation/pre-destroy.js +0 -2
- package/esm/common/annotation/pre-destroy.js.map +0 -1
- package/esm/common/annotation/target-name.d.ts +0 -1
- package/esm/common/annotation/target-name.js +0 -2
- package/esm/common/annotation/target-name.js.map +0 -1
- package/esm/common/annotation/unmanaged.d.ts +0 -1
- package/esm/common/annotation/unmanaged.js +0 -2
- package/esm/common/annotation/unmanaged.js.map +0 -1
- package/esm/common/container/container-factory.d.ts +0 -4
- package/esm/common/container/container-factory.js +0 -9
- package/esm/common/container/container-factory.js.map +0 -1
- package/esm/common/el/jexl-engine-provider.d.ts +0 -5
- package/esm/common/el/jexl-engine-provider.js +0 -22
- package/esm/common/el/jexl-engine-provider.js.map +0 -1
- package/esm/common/provider/provider-creator.d.ts +0 -6
- package/esm/common/provider/provider-creator.js.map +0 -1
- package/esm/node/utils/crc.d.ts +0 -1
- package/esm/node/utils/crc.js +0 -7
- package/esm/node/utils/crc.js.map +0 -1
- package/esm/node/utils/index.d.ts +0 -1
- package/esm/node/utils/index.js +0 -2
- package/esm/node/utils/index.js.map +0 -1
- package/lib/common/annotation/decorate.d.ts +0 -2
- package/lib/common/annotation/decorate.d.ts.map +0 -1
- package/lib/common/annotation/decorate.js +0 -6
- package/lib/common/annotation/decorate.js.map +0 -1
- package/lib/common/annotation/inject.d.ts +0 -2
- package/lib/common/annotation/inject.d.ts.map +0 -1
- package/lib/common/annotation/inject.js +0 -6
- package/lib/common/annotation/inject.js.map +0 -1
- package/lib/common/annotation/injectable.d.ts +0 -2
- package/lib/common/annotation/injectable.d.ts.map +0 -1
- package/lib/common/annotation/injectable.js +0 -6
- package/lib/common/annotation/injectable.js.map +0 -1
- package/lib/common/annotation/pre-destroy.d.ts +0 -2
- package/lib/common/annotation/pre-destroy.d.ts.map +0 -1
- package/lib/common/annotation/pre-destroy.js +0 -6
- package/lib/common/annotation/pre-destroy.js.map +0 -1
- package/lib/common/annotation/target-name.d.ts +0 -2
- package/lib/common/annotation/target-name.d.ts.map +0 -1
- package/lib/common/annotation/target-name.js +0 -6
- package/lib/common/annotation/target-name.js.map +0 -1
- package/lib/common/annotation/unmanaged.d.ts +0 -2
- package/lib/common/annotation/unmanaged.d.ts.map +0 -1
- package/lib/common/annotation/unmanaged.js +0 -6
- package/lib/common/annotation/unmanaged.js.map +0 -1
- package/lib/common/container/container-factory.d.ts +0 -5
- package/lib/common/container/container-factory.d.ts.map +0 -1
- package/lib/common/container/container-factory.js +0 -13
- package/lib/common/container/container-factory.js.map +0 -1
- package/lib/common/el/jexl-engine-provider.d.ts +0 -6
- package/lib/common/el/jexl-engine-provider.d.ts.map +0 -1
- package/lib/common/el/jexl-engine-provider.js +0 -25
- package/lib/common/el/jexl-engine-provider.js.map +0 -1
- package/lib/common/provider/provider-creator.d.ts +0 -7
- package/lib/common/provider/provider-creator.d.ts.map +0 -1
- package/lib/common/provider/provider-creator.js +0 -22
- package/lib/common/provider/provider-creator.js.map +0 -1
- package/lib/node/utils/crc.d.ts +0 -2
- package/lib/node/utils/crc.d.ts.map +0 -1
- package/lib/node/utils/crc.js +0 -10
- package/lib/node/utils/crc.js.map +0 -1
- package/lib/node/utils/index.d.ts +0 -2
- package/lib/node/utils/index.d.ts.map +0 -1
- package/lib/node/utils/index.js +0 -18
- package/lib/node/utils/index.js.map +0 -1
- package/src/common/annotation/decorate.ts +0 -1
- package/src/common/annotation/inject.ts +0 -1
- package/src/common/annotation/injectable.ts +0 -1
- package/src/common/annotation/pre-destroy.ts +0 -1
- package/src/common/annotation/target-name.ts +0 -1
- package/src/common/annotation/unmanaged.ts +0 -1
- package/src/common/container/container-factory.ts +0 -9
- package/src/common/el/jexl-engine-provider.ts +0 -18
- package/src/common/provider/provider-creator.ts +0 -12
- package/src/node/utils/crc.ts +0 -7
- package/src/node/utils/index.ts +0 -1
|
@@ -6,15 +6,14 @@ import './application-state';
|
|
|
6
6
|
import { autoBind } from '../container/auto-bind';
|
|
7
7
|
import commonModule from '../static-module';
|
|
8
8
|
import { currentThis } from '../utils';
|
|
9
|
-
import { ContainerModule } from '
|
|
10
|
-
import { ContainerFactory } from '../container/container-factory';
|
|
9
|
+
import { Container, ContainerModule } from '../container/container';
|
|
11
10
|
|
|
12
11
|
export class ApplicationFactory {
|
|
13
12
|
static async create(applicationProps: ApplicationProps, ...modules: ContainerModule[]): Promise<Application> {
|
|
14
13
|
currentThis.cellProps = applicationProps;
|
|
15
|
-
const container =
|
|
14
|
+
const container = new Container();
|
|
15
|
+
container.load(commonModule, autoBind(), ...modules);
|
|
16
16
|
ContainerProvider.set(container);
|
|
17
|
-
|
|
18
|
-
return application;
|
|
17
|
+
return container.get<Application>(Application);
|
|
19
18
|
}
|
|
20
19
|
}
|
|
@@ -113,7 +113,7 @@ export abstract class AbstractApplicationStateService<T extends string> implemen
|
|
|
113
113
|
|
|
114
114
|
set state(state: T) {
|
|
115
115
|
if (state !== this._state) {
|
|
116
|
-
|
|
116
|
+
// A state that was reached stays reached: late `reachedState()` calls resolve at once.
|
|
117
117
|
this._state = state;
|
|
118
118
|
if (this.deferred[state] === undefined) {
|
|
119
119
|
this.deferred[state] = new Deferred();
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { describe, it } from 'bun:test';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { ApplicationFactory } from './application-factory';
|
|
4
|
+
import { ApplicationLifecycle, ApplicationStateService, ApplicationState, Application } from './application-protocol';
|
|
5
|
+
import { Component } from '../annotation';
|
|
6
|
+
import { ContainerUtil } from '../container/container-util';
|
|
7
|
+
import { Scope } from '../container/scope';
|
|
8
|
+
import { Logger } from '../logger/logger-protocol';
|
|
9
|
+
import { MockLogger } from '../test/mock-logger';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 应用生命周期的约定(阶段 1.E 行为测试):ApplicationLifecycle 的调用顺序、出错时的行为、状态变化。
|
|
13
|
+
*/
|
|
14
|
+
interface Recorder { events: string[], errors: string[] }
|
|
15
|
+
|
|
16
|
+
function recordingLogger(rec: Recorder) {
|
|
17
|
+
@Component({ id: Logger, rebind: true, scope: Scope.Transient })
|
|
18
|
+
class RecordingLogger extends MockLogger {
|
|
19
|
+
override error(message: any): void {
|
|
20
|
+
rec.errors.push(String(message));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return RecordingLogger;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('core 应用生命周期', () => {
|
|
27
|
+
|
|
28
|
+
it('start():先调用全部 initialize,再按顺序 await 每个 onStart;stop() 调用 onStop', async () => {
|
|
29
|
+
const rec: Recorder = { events: [], errors: [] };
|
|
30
|
+
recordingLogger(rec);
|
|
31
|
+
@Component(ApplicationLifecycle)
|
|
32
|
+
class First implements ApplicationLifecycle<Application> {
|
|
33
|
+
initialize() { rec.events.push('init:first'); }
|
|
34
|
+
async onStart() {
|
|
35
|
+
await new Promise(r => setTimeout(r, 5));
|
|
36
|
+
rec.events.push('start:first');
|
|
37
|
+
}
|
|
38
|
+
onStop() { rec.events.push('stop:first'); }
|
|
39
|
+
}
|
|
40
|
+
@Component(ApplicationLifecycle)
|
|
41
|
+
class Second implements ApplicationLifecycle<Application> {
|
|
42
|
+
initialize() { rec.events.push('init:second'); }
|
|
43
|
+
onStart() { rec.events.push('start:second'); }
|
|
44
|
+
onStop() { rec.events.push('stop:second'); }
|
|
45
|
+
}
|
|
46
|
+
const app = await ApplicationFactory.create({});
|
|
47
|
+
expect(rec.events).to.deep.equal([]);
|
|
48
|
+
await app.start();
|
|
49
|
+
const inits = rec.events.slice(0, 2);
|
|
50
|
+
expect(inits).to.have.members(['init:first', 'init:second']);
|
|
51
|
+
expect(rec.events.slice(2)).to.have.members(['start:first', 'start:second']);
|
|
52
|
+
await app.stop();
|
|
53
|
+
expect(rec.events.slice(4)).to.have.members(['stop:first', 'stop:second']);
|
|
54
|
+
expect(rec.errors).to.deep.equal([]);
|
|
55
|
+
expect([First, Second]).to.have.length(2);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('onStart 按 getAll 的顺序逐个 await(不是并发)', async () => {
|
|
59
|
+
const order: string[] = [];
|
|
60
|
+
let running = 0;
|
|
61
|
+
let maxRunning = 0;
|
|
62
|
+
for (const name of ['a', 'b', 'c']) {
|
|
63
|
+
@Component(ApplicationLifecycle)
|
|
64
|
+
class L implements ApplicationLifecycle<Application> {
|
|
65
|
+
async onStart() {
|
|
66
|
+
running++;
|
|
67
|
+
maxRunning = Math.max(maxRunning, running);
|
|
68
|
+
await new Promise(r => setTimeout(r, 2));
|
|
69
|
+
order.push(name);
|
|
70
|
+
running--;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
void L;
|
|
74
|
+
}
|
|
75
|
+
const app = await ApplicationFactory.create({});
|
|
76
|
+
await app.start();
|
|
77
|
+
expect(order).to.have.members(['a', 'b', 'c']);
|
|
78
|
+
expect(maxRunning).to.equal(1);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('initialize / onStart / onStop 抛错只记 error 日志,不影响其他生命周期,也不让 start() 失败', async () => {
|
|
82
|
+
const rec: Recorder = { events: [], errors: [] };
|
|
83
|
+
recordingLogger(rec);
|
|
84
|
+
@Component(ApplicationLifecycle)
|
|
85
|
+
class Broken implements ApplicationLifecycle<Application> {
|
|
86
|
+
initialize() { throw new Error('init boom'); }
|
|
87
|
+
onStart() { throw new Error('start boom'); }
|
|
88
|
+
onStop() { throw new Error('stop boom'); }
|
|
89
|
+
}
|
|
90
|
+
@Component(ApplicationLifecycle)
|
|
91
|
+
class Healthy implements ApplicationLifecycle<Application> {
|
|
92
|
+
initialize() { rec.events.push('init'); }
|
|
93
|
+
onStart() { rec.events.push('start'); }
|
|
94
|
+
onStop() { rec.events.push('stop'); }
|
|
95
|
+
}
|
|
96
|
+
const app = await ApplicationFactory.create({});
|
|
97
|
+
await app.start();
|
|
98
|
+
await app.stop();
|
|
99
|
+
expect(rec.events).to.deep.equal(['init', 'start', 'stop']);
|
|
100
|
+
expect(rec.errors).to.deep.equal(['Could not initialize lifecycle', 'Could not start lifecycle', 'Could not stop lifecycle']);
|
|
101
|
+
expect([Broken, Healthy]).to.have.length(2);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('没有任何 ApplicationLifecycle 时 start / stop 正常', async () => {
|
|
105
|
+
const app = await ApplicationFactory.create({});
|
|
106
|
+
await app.start();
|
|
107
|
+
await app.stop();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('状态:init → started → ready,stop 之后是 stoped;reachedState 与 onStateChanged', async () => {
|
|
111
|
+
const app = await ApplicationFactory.create({});
|
|
112
|
+
const states = ContainerUtil.get<ApplicationStateService<ApplicationState>>(ApplicationStateService);
|
|
113
|
+
expect(states.state).to.equal('init');
|
|
114
|
+
const seen: string[] = [];
|
|
115
|
+
states.onStateChanged(s => seen.push(s));
|
|
116
|
+
const ready = states.reachedState('ready');
|
|
117
|
+
const readyOrStopped = states.reachedAnyState('ready', 'stoped');
|
|
118
|
+
await app.start();
|
|
119
|
+
await ready;
|
|
120
|
+
await readyOrStopped;
|
|
121
|
+
expect(states.state).to.equal('ready');
|
|
122
|
+
await app.stop();
|
|
123
|
+
expect(states.state).to.equal('stoped');
|
|
124
|
+
expect(seen).to.deep.equal(['started', 'ready', 'stoped']);
|
|
125
|
+
// 当前状态再等会立刻 resolve
|
|
126
|
+
await states.reachedState('stoped');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('离开一个状态之后,再 reachedState(那个状态) 立即 resolve(F7)', async () => {
|
|
130
|
+
const app = await ApplicationFactory.create({});
|
|
131
|
+
const states = ContainerUtil.get<ApplicationStateService<ApplicationState>>(ApplicationStateService);
|
|
132
|
+
await app.start();
|
|
133
|
+
const race = (p: Promise<void>) => Promise.race([p.then(() => 'resolved'), new Promise(r => setTimeout(() => r('pending'), 20))]);
|
|
134
|
+
expect(await race(states.reachedState('ready'))).to.equal('resolved');
|
|
135
|
+
expect(await race(states.reachedState('started'))).to.equal('resolved');
|
|
136
|
+
expect(await race(states.reachedState('stoped'))).to.equal('pending');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('同一个状态重复设置不会重复通知', async () => {
|
|
140
|
+
await ApplicationFactory.create({});
|
|
141
|
+
const states = ContainerUtil.get<ApplicationStateService<ApplicationState>>(ApplicationStateService);
|
|
142
|
+
const seen: string[] = [];
|
|
143
|
+
states.onStateChanged(s => seen.push(s));
|
|
144
|
+
states.state = 'started';
|
|
145
|
+
states.state = 'started';
|
|
146
|
+
expect(seen).to.deep.equal(['started']);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -9,7 +9,7 @@ export class ConfigProviderImpl implements ConfigProvider {
|
|
|
9
9
|
protected readonly expressionHandler: ExpressionHandler;
|
|
10
10
|
|
|
11
11
|
get<T>(key: string, defaultValue?: T): T {
|
|
12
|
-
return this.expressionHandler.handle(`\${${key}}`)
|
|
12
|
+
return this.expressionHandler.handle(`\${${key}}`) ?? defaultValue;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { describe, it } from 'bun:test';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { ApplicationFactory } from '../application/application-factory';
|
|
4
|
+
import {
|
|
5
|
+
Component, Autowired, Optional, Constant, AutowiredProvider, PostConstruct, Named, Tagged
|
|
6
|
+
} from '../annotation';
|
|
7
|
+
import { ContainerUtil } from './container-util';
|
|
8
|
+
import { ContainerProvider } from './container-provider';
|
|
9
|
+
import { Scope } from './scope';
|
|
10
|
+
import { Provider } from '../provider';
|
|
11
|
+
import { ConfigProvider } from '../config/config-protocol';
|
|
12
|
+
import { autoBind } from './auto-bind';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 组件装配的约定(阶段 1.E 行为测试):只用公开的注解、ApplicationFactory 和 ContainerUtil 断言,
|
|
16
|
+
* 不碰 inversify 的 API,这样阶段 2 换容器时这些用例可以原样复用。
|
|
17
|
+
*
|
|
18
|
+
* 注意:组件元数据是全局登记的,ApplicationFactory.create() 里的 autoBind() 会把登记过的全部取走。
|
|
19
|
+
* 所以每个用例都在自己的函数里定义类,然后马上 create,用例之间互不影响。
|
|
20
|
+
*/
|
|
21
|
+
async function boot(props: Record<string, any> = {}) {
|
|
22
|
+
return ApplicationFactory.create(props);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('core 组件装配', () => {
|
|
26
|
+
|
|
27
|
+
it('@Component 不带参数时以类本身为 id,默认单例', async () => {
|
|
28
|
+
@Component()
|
|
29
|
+
class Plain { }
|
|
30
|
+
await boot();
|
|
31
|
+
const a = ContainerUtil.get(Plain);
|
|
32
|
+
expect(a).to.be.instanceOf(Plain);
|
|
33
|
+
expect(ContainerUtil.get(Plain)).to.equal(a);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('@Component(id) 同时可以按类和按 id 取到,且是同一个实例', async () => {
|
|
37
|
+
const Greeter = Symbol('Greeter');
|
|
38
|
+
@Component(Greeter)
|
|
39
|
+
class GreeterImpl { hello() { return 'hi'; } }
|
|
40
|
+
await boot();
|
|
41
|
+
const byId = ContainerUtil.get<GreeterImpl>(Greeter);
|
|
42
|
+
expect(byId.hello()).to.equal('hi');
|
|
43
|
+
expect(ContainerUtil.get(GreeterImpl)).to.equal(byId);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('一个组件可以登记多个 id,都指向同一个实例', async () => {
|
|
47
|
+
const A = Symbol('A');
|
|
48
|
+
const B = Symbol('B');
|
|
49
|
+
@Component({ id: [A, B] })
|
|
50
|
+
class Both { }
|
|
51
|
+
await boot();
|
|
52
|
+
expect(ContainerUtil.get(A)).to.be.instanceOf(Both);
|
|
53
|
+
expect(ContainerUtil.get(A)).to.equal(ContainerUtil.get(B));
|
|
54
|
+
expect(ContainerUtil.get(Both)).to.equal(ContainerUtil.get(A));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('Scope.Transient 每次取都是新实例', async () => {
|
|
58
|
+
@Component({ scope: Scope.Transient })
|
|
59
|
+
class Fresh { }
|
|
60
|
+
await boot();
|
|
61
|
+
expect(ContainerUtil.get(Fresh)).not.to.equal(ContainerUtil.get(Fresh));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('@Autowired 属性注入:按声明的类型,也可以显式给 id', async () => {
|
|
65
|
+
const Repo = Symbol('Repo');
|
|
66
|
+
@Component(Repo)
|
|
67
|
+
class RepoImpl { find() { return 'row'; } }
|
|
68
|
+
@Component()
|
|
69
|
+
class Dep { }
|
|
70
|
+
@Component()
|
|
71
|
+
class Service {
|
|
72
|
+
@Autowired(Repo)
|
|
73
|
+
readonly repo: RepoImpl;
|
|
74
|
+
@Autowired()
|
|
75
|
+
readonly dep: Dep;
|
|
76
|
+
}
|
|
77
|
+
await boot();
|
|
78
|
+
const s = ContainerUtil.get(Service);
|
|
79
|
+
expect(s.repo.find()).to.equal('row');
|
|
80
|
+
expect(s.dep).to.equal(ContainerUtil.get(Dep));
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('@Autowired 构造器参数注入', async () => {
|
|
84
|
+
const Clock = Symbol('Clock');
|
|
85
|
+
@Component(Clock)
|
|
86
|
+
class FixedClock { now() { return 42; } }
|
|
87
|
+
@Component()
|
|
88
|
+
class UsesClock {
|
|
89
|
+
constructor(@Autowired(Clock) readonly clock: FixedClock) { }
|
|
90
|
+
}
|
|
91
|
+
await boot();
|
|
92
|
+
expect(ContainerUtil.get(UsesClock).clock.now()).to.equal(42);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('同一 id 有多个实现时,数组类型的 @Autowired 拿到全部', async () => {
|
|
96
|
+
const Plugin = Symbol('Plugin');
|
|
97
|
+
@Component(Plugin)
|
|
98
|
+
class P1 { readonly name = 'p1'; }
|
|
99
|
+
@Component(Plugin)
|
|
100
|
+
class P2 { readonly name = 'p2'; }
|
|
101
|
+
@Component()
|
|
102
|
+
class Host {
|
|
103
|
+
@Autowired(Plugin)
|
|
104
|
+
readonly plugins: { name: string }[];
|
|
105
|
+
}
|
|
106
|
+
await boot();
|
|
107
|
+
expect(ContainerUtil.get(Host).plugins.map(p => p.name).sort()).to.deep.equal(['p1', 'p2']);
|
|
108
|
+
expect(ContainerUtil.getAll(Plugin)).to.have.length(2);
|
|
109
|
+
expect([P1, P2]).to.have.length(2);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('@Optional:没有实现时单值为 undefined,数组为 []', async () => {
|
|
113
|
+
const Missing = Symbol('Missing');
|
|
114
|
+
const MissingMany = Symbol('MissingMany');
|
|
115
|
+
@Component()
|
|
116
|
+
class Tolerant {
|
|
117
|
+
@Autowired(Missing) @Optional()
|
|
118
|
+
readonly one?: unknown;
|
|
119
|
+
@Autowired(MissingMany) @Optional()
|
|
120
|
+
readonly many: unknown[];
|
|
121
|
+
}
|
|
122
|
+
await boot();
|
|
123
|
+
const t = ContainerUtil.get(Tolerant);
|
|
124
|
+
expect(t.one).to.equal(undefined);
|
|
125
|
+
expect(t.many).to.deep.equal([]);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('没有实现又不是 @Optional 时,取的时候报错,错误信息里有缺的 id', async () => {
|
|
129
|
+
const Absent = Symbol('AbsentService');
|
|
130
|
+
@Component()
|
|
131
|
+
class Needy {
|
|
132
|
+
@Autowired(Absent)
|
|
133
|
+
readonly absent: unknown;
|
|
134
|
+
}
|
|
135
|
+
await boot();
|
|
136
|
+
expect(() => ContainerUtil.get(Needy)).to.throw(/AbsentService/);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('@Component({ id, name / tag / default }) 按名字、标签或默认选实现,类本身仍可直接取(F1)', async () => {
|
|
140
|
+
const Store = Symbol('Store');
|
|
141
|
+
@Component({ id: Store, name: 'redis' })
|
|
142
|
+
class RedisStore { readonly kind = 'redis'; }
|
|
143
|
+
@Component({ id: Store, tag: { tag: 'region', value: 'eu' } })
|
|
144
|
+
class EuStore { readonly kind = 'eu'; }
|
|
145
|
+
@Component({ id: Store, default: true })
|
|
146
|
+
class MemoryStore { readonly kind = 'memory'; }
|
|
147
|
+
@Component()
|
|
148
|
+
class Consumer {
|
|
149
|
+
@Autowired(Store) @Named('redis')
|
|
150
|
+
readonly redis: { kind: string };
|
|
151
|
+
@Autowired(Store) @Tagged('region', 'eu')
|
|
152
|
+
readonly eu: { kind: string };
|
|
153
|
+
@Autowired(Store)
|
|
154
|
+
readonly fallback: { kind: string };
|
|
155
|
+
}
|
|
156
|
+
await boot();
|
|
157
|
+
const c = ContainerUtil.get(Consumer);
|
|
158
|
+
expect([c.redis.kind, c.eu.kind, c.fallback.kind]).to.deep.equal(['redis', 'eu', 'memory']);
|
|
159
|
+
expect(ContainerUtil.get<{ kind: string }>(Store, { name: 'redis' })).to.equal(ContainerUtil.get(RedisStore));
|
|
160
|
+
expect(ContainerUtil.get<{ kind: string }>(Store, { tags: { region: 'eu' } })).to.equal(ContainerUtil.get(EuStore));
|
|
161
|
+
expect(ContainerUtil.get(Store)).to.equal(ContainerUtil.get(MemoryStore));
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('rebind: true 替换先加载的模块里的实现(应用覆盖框架或其他包的组件)', async () => {
|
|
165
|
+
const Mailer = Symbol('Mailer');
|
|
166
|
+
@Component(Mailer)
|
|
167
|
+
class DefaultMailer { readonly who = 'default'; }
|
|
168
|
+
const base = autoBind();
|
|
169
|
+
@Component({ id: Mailer, rebind: true })
|
|
170
|
+
class CustomMailer { readonly who = 'custom'; }
|
|
171
|
+
const overrides = autoBind();
|
|
172
|
+
await ApplicationFactory.create({}, base, overrides);
|
|
173
|
+
expect(ContainerUtil.getAll<{ who: string }>(Mailer).map(m => m.who)).to.deep.equal(['custom']);
|
|
174
|
+
expect([DefaultMailer, CustomMailer]).to.have.length(2);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('同一批 autoBind 里也可以 rebind 本批先定义的组件(按定义顺序登记)', async () => {
|
|
178
|
+
const Mailer = Symbol('SameBatchMailer');
|
|
179
|
+
@Component(Mailer)
|
|
180
|
+
class DefaultMailer { readonly who = 'default'; }
|
|
181
|
+
@Component({ id: Mailer, rebind: true })
|
|
182
|
+
class CustomMailer { readonly who = 'custom'; }
|
|
183
|
+
await boot();
|
|
184
|
+
expect(ContainerUtil.getAll<{ who: string }>(Mailer).map(m => m.who)).to.deep.equal(['custom']);
|
|
185
|
+
expect([DefaultMailer, CustomMailer]).to.have.length(2);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('rebind 替换框架自带组件:替换后注入点拿到的是新实现', async () => {
|
|
189
|
+
@Component({ id: ConfigProvider, rebind: true })
|
|
190
|
+
class FixedConfig {
|
|
191
|
+
get(key: string) { return key === 'answer' ? 42 : undefined; }
|
|
192
|
+
}
|
|
193
|
+
@Component()
|
|
194
|
+
class ReadsConfig {
|
|
195
|
+
@Autowired(ConfigProvider)
|
|
196
|
+
readonly config: FixedConfig;
|
|
197
|
+
}
|
|
198
|
+
await boot();
|
|
199
|
+
expect(ContainerUtil.get(ReadsConfig).config).to.be.instanceOf(FixedConfig);
|
|
200
|
+
expect(ContainerUtil.get(ReadsConfig).config.get('answer')).to.equal(42);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('@Constant 登记常量,多个 id 都能取到', async () => {
|
|
204
|
+
const Token = Symbol('Token');
|
|
205
|
+
const Alias = Symbol('TokenAlias');
|
|
206
|
+
@Constant([Token, Alias], { secret: 'abc' })
|
|
207
|
+
class Holder { }
|
|
208
|
+
await boot();
|
|
209
|
+
expect(ContainerUtil.get(Token)).to.deep.equal({ secret: 'abc' });
|
|
210
|
+
expect(ContainerUtil.get(Alias)).to.equal(ContainerUtil.get(Token));
|
|
211
|
+
expect(Holder).to.be.a('function');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('@AutowiredProvider 注入 Provider:按 priority 从小到大排序(sortSync)', async () => {
|
|
215
|
+
const Step = Symbol('Step');
|
|
216
|
+
@Component(Step)
|
|
217
|
+
class Late { readonly priority = 300; readonly name = 'late'; }
|
|
218
|
+
@Component(Step)
|
|
219
|
+
class Early { readonly priority = 100; readonly name = 'early'; }
|
|
220
|
+
@Component(Step)
|
|
221
|
+
class Middle { readonly priority = 200; readonly name = 'middle'; }
|
|
222
|
+
@Component()
|
|
223
|
+
class Pipeline {
|
|
224
|
+
@AutowiredProvider(Step)
|
|
225
|
+
readonly steps: Provider<{ name: string, priority: number }>;
|
|
226
|
+
}
|
|
227
|
+
await boot();
|
|
228
|
+
const names = ContainerUtil.get(Pipeline).steps.sortSync().map(s => s.name);
|
|
229
|
+
expect(names).to.have.members(['early', 'middle', 'late']);
|
|
230
|
+
// Prioritizeable:priority 大的排前面
|
|
231
|
+
expect(names).to.deep.equal(['late', 'middle', 'early']);
|
|
232
|
+
expect([Late, Early, Middle]).to.have.length(3);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('@PostConstruct 在注入完成后调用一次,单例只调用一次', async () => {
|
|
236
|
+
let calls = 0;
|
|
237
|
+
@Component()
|
|
238
|
+
class Dep { readonly ok = true; }
|
|
239
|
+
@Component()
|
|
240
|
+
class Init {
|
|
241
|
+
@Autowired()
|
|
242
|
+
readonly dep: Dep;
|
|
243
|
+
seenDep = false;
|
|
244
|
+
@PostConstruct()
|
|
245
|
+
protected init() {
|
|
246
|
+
calls++;
|
|
247
|
+
this.seenDep = this.dep.ok;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
await boot();
|
|
251
|
+
expect(ContainerUtil.get(Init).seenDep).to.equal(true);
|
|
252
|
+
ContainerUtil.get(Init);
|
|
253
|
+
expect(calls).to.equal(1);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('detached 的 @Autowired:不在容器里的对象也能按需从当前容器取值', async () => {
|
|
257
|
+
const Clock = Symbol('DetachedClock');
|
|
258
|
+
@Component(Clock)
|
|
259
|
+
class Clk { now() { return 7; } }
|
|
260
|
+
class NotAComponent {
|
|
261
|
+
@Autowired({ id: Clock, detached: true })
|
|
262
|
+
readonly clock: Clk;
|
|
263
|
+
}
|
|
264
|
+
await boot();
|
|
265
|
+
expect(new NotAComponent().clock.now()).to.equal(7);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('detached 不支持构造器参数,给出明确的错误', () => {
|
|
269
|
+
expect(() => {
|
|
270
|
+
class Bad {
|
|
271
|
+
constructor(@Autowired({ id: Symbol('x'), detached: true }) readonly x: unknown) { }
|
|
272
|
+
}
|
|
273
|
+
return Bad;
|
|
274
|
+
}).to.throw(/not supported/);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('每次 ApplicationFactory.create 都换成新的容器,ContainerUtil 指向最新的那个', async () => {
|
|
278
|
+
@Component()
|
|
279
|
+
class Counter { value = 0; }
|
|
280
|
+
await boot();
|
|
281
|
+
const first = ContainerProvider.provide();
|
|
282
|
+
ContainerUtil.get(Counter).value = 5;
|
|
283
|
+
await boot();
|
|
284
|
+
expect(ContainerProvider.provide()).not.to.equal(first);
|
|
285
|
+
// 新容器里没有再登记 Counter(元数据已被上一次 create 取走)
|
|
286
|
+
expect(() => ContainerUtil.get(Counter)).to.throw();
|
|
287
|
+
});
|
|
288
|
+
});
|
|
@@ -1,101 +1,83 @@
|
|
|
1
|
-
import { interfaces, ContainerModule } from 'inversify';
|
|
2
1
|
import { METADATA_KEY } from '../constants';
|
|
3
|
-
import { ComponentMetadata, ConstantOption } from '../annotation';
|
|
2
|
+
import type { ComponentMetadata, ConstantOption } from '../annotation';
|
|
4
3
|
import { ConfigUtil } from '../config/config-util';
|
|
5
4
|
import { AopProxyFactory, ClassFilter } from '../aop/aop-protocol';
|
|
6
|
-
import {
|
|
5
|
+
import { Binding, ComponentId, Container, ContainerModule, ContainerModuleRegistry } from './container';
|
|
7
6
|
import { Scope } from './scope';
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
return new ContainerModule((bind, unbind, isBound, rebind, ...rest) => {
|
|
11
|
-
if (registry) {
|
|
12
|
-
registry(bind, unbind, isBound, rebind, ...rest);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
8
|
+
type Bind = <T>(id: ComponentId<T>) => Binding<T>;
|
|
16
9
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
/**
|
|
11
|
+
* A module of the components registered (`@Component`, `@Constant` and the decorators built on them)
|
|
12
|
+
* since the previous `autoBind()`, in the order they were defined; `registry` adds bindings by hand.
|
|
13
|
+
* A DI module file imports its components, then exports `autoBind()`.
|
|
14
|
+
*/
|
|
15
|
+
export function autoBind(registry?: ContainerModuleRegistry): ContainerModule {
|
|
16
|
+
const components: ComponentMetadata[] = Reflect.getMetadata(METADATA_KEY.component, Reflect) || [];
|
|
17
|
+
const constants: ConstantOption[] = Reflect.getMetadata(METADATA_KEY.constantValue, Reflect) || [];
|
|
20
18
|
Reflect.defineMetadata(METADATA_KEY.component, [], Reflect);
|
|
21
19
|
Reflect.defineMetadata(METADATA_KEY.constantValue, [], Reflect);
|
|
22
|
-
return new ContainerModule((bind, unbind, isBound, rebind
|
|
23
|
-
for (
|
|
24
|
-
|
|
25
|
-
resolve(metadata, bind, rebind);
|
|
20
|
+
return new ContainerModule((bind, unbind, isBound, rebind) => {
|
|
21
|
+
for (const metadata of components) {
|
|
22
|
+
bindComponent(metadata, bind, rebind);
|
|
26
23
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (registry) {
|
|
30
|
-
registry(bind, unbind, isBound, rebind, ...rest);
|
|
24
|
+
for (const metadata of constants) {
|
|
25
|
+
bindConstant(metadata, bind, rebind);
|
|
31
26
|
}
|
|
27
|
+
registry?.(bind, unbind, isBound, rebind);
|
|
32
28
|
});
|
|
33
29
|
}
|
|
34
30
|
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (target.constructor && classFilter.matches(target.constructor, metadata)) {
|
|
40
|
-
const aopProxyFactory = ContainerUtil.get<AopProxyFactory>(AopProxyFactory);
|
|
41
|
-
return aopProxyFactory.create({
|
|
42
|
-
target,
|
|
43
|
-
metadata
|
|
44
|
-
}).getProxy();
|
|
31
|
+
function proxyIfNeeded(container: Container, metadata: ComponentMetadata, instance: any) {
|
|
32
|
+
if (ConfigUtil.getRaw().cell?.aop?.enabled && instance?.constructor) {
|
|
33
|
+
if (container.get<ClassFilter>(ClassFilter).matches(instance.constructor, metadata)) {
|
|
34
|
+
return container.get<AopProxyFactory>(AopProxyFactory).create({ target: instance, metadata }).getProxy();
|
|
45
35
|
}
|
|
46
36
|
}
|
|
47
|
-
|
|
48
|
-
return target;
|
|
37
|
+
return instance;
|
|
49
38
|
}
|
|
50
39
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
mid = rebind(id2 || id).to(target);
|
|
59
|
-
} else {
|
|
60
|
-
mid = bind(id).to(target);
|
|
61
|
-
}
|
|
40
|
+
/**
|
|
41
|
+
* The first identifier (the class itself unless the decorator says otherwise) is bound to the class,
|
|
42
|
+
* the others resolve to it. `rebind` replaces the bindings of the first other identifier.
|
|
43
|
+
*/
|
|
44
|
+
function bindComponent(metadata: ComponentMetadata, bind: Bind, rebind: Bind): void {
|
|
45
|
+
const { ids: [primary, ...aliases], scope, name, tag, proxy, onActivation, target } = metadata;
|
|
46
|
+
const main = (metadata.rebind && aliases.length === 0 ? rebind : bind)(primary).to(target);
|
|
62
47
|
if (scope === Scope.Singleton) {
|
|
63
|
-
|
|
64
|
-
} else if (scope === Scope.Transient) {
|
|
65
|
-
mid = mid.inTransientScope();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (name) {
|
|
69
|
-
mid = mid.whenTargetNamed(name);
|
|
70
|
-
} else if (tag) {
|
|
71
|
-
mid = mid.whenTargetTagged(tag.tag, tag.value);
|
|
72
|
-
} else if (metadata.default) {
|
|
73
|
-
mid = mid.whenTargetIsDefault();
|
|
74
|
-
} else if (when) {
|
|
75
|
-
mid = mid.when(when);
|
|
48
|
+
main.inSingletonScope();
|
|
76
49
|
}
|
|
77
|
-
|
|
78
50
|
if (onActivation) {
|
|
79
|
-
|
|
51
|
+
main.onActivation(onActivation);
|
|
80
52
|
} else if (proxy) {
|
|
81
|
-
|
|
53
|
+
main.onActivation((context, instance) => proxyIfNeeded(context.container, metadata, instance));
|
|
82
54
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
55
|
+
const constrain = (binding: Binding) => {
|
|
56
|
+
if (name !== undefined) {
|
|
57
|
+
binding.whenTargetNamed(name);
|
|
58
|
+
} else if (tag) {
|
|
59
|
+
binding.whenTargetTagged(tag.tag, tag.value);
|
|
60
|
+
} else if (metadata.default) {
|
|
61
|
+
binding.whenTargetIsDefault();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
if (aliases.length === 0) {
|
|
65
|
+
constrain(main);
|
|
86
66
|
}
|
|
67
|
+
aliases.forEach((alias, index) => {
|
|
68
|
+
const binding = (metadata.rebind && index === 0 ? rebind : bind)(alias).toService(primary);
|
|
69
|
+
// An alias of a singleton is that singleton: it is cached too.
|
|
70
|
+
if (scope === Scope.Singleton) {
|
|
71
|
+
binding.inSingletonScope();
|
|
72
|
+
}
|
|
73
|
+
constrain(binding);
|
|
74
|
+
});
|
|
87
75
|
}
|
|
88
76
|
|
|
89
|
-
function
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
} else {
|
|
95
|
-
bind(id!).toConstantValue(metadata.constantValue);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
for (const item of ids) {
|
|
99
|
-
bind(item!).toService(id!);
|
|
77
|
+
function bindConstant(metadata: ConstantOption, bind: Bind, rebind: Bind): void {
|
|
78
|
+
const [first, ...others] = Array.isArray(metadata.id) ? metadata.id : [metadata.id];
|
|
79
|
+
(metadata.rebind ? rebind : bind)(first).toConstantValue(metadata.constantValue);
|
|
80
|
+
for (const id of others) {
|
|
81
|
+
bind(id).toConstantValue(metadata.constantValue);
|
|
100
82
|
}
|
|
101
83
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why the container could not give a component. `code` is stable (the same codes `cell check` reports),
|
|
3
|
+
* `hint` says how to fix it in one sentence and `path` is the chain of identifiers being resolved,
|
|
4
|
+
* outermost first (docs/design/agent-first.md R5).
|
|
5
|
+
*/
|
|
6
|
+
export class ContainerError extends Error {
|
|
7
|
+
override readonly name = 'ContainerError';
|
|
8
|
+
readonly code: ContainerError.Code;
|
|
9
|
+
readonly hint: string;
|
|
10
|
+
readonly path: string[];
|
|
11
|
+
|
|
12
|
+
constructor(options: { code: ContainerError.Code, message: string, hint: string, path?: string[] }) {
|
|
13
|
+
super(options.message);
|
|
14
|
+
this.code = options.code;
|
|
15
|
+
this.hint = options.hint;
|
|
16
|
+
this.path = options.path ?? [];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export namespace ContainerError {
|
|
21
|
+
export type Code =
|
|
22
|
+
| 'CELL_DI_NO_BINDING'
|
|
23
|
+
| 'CELL_DI_AMBIGUOUS'
|
|
24
|
+
| 'CELL_DI_CIRCULAR'
|
|
25
|
+
| 'CELL_DI_MISSING_INJECT'
|
|
26
|
+
| 'CELL_DI_INCOMPLETE_BINDING';
|
|
27
|
+
|
|
28
|
+
export function is(error: unknown, code?: Code): error is ContainerError {
|
|
29
|
+
return error instanceof ContainerError && (code === undefined || error.code === code);
|
|
30
|
+
}
|
|
31
|
+
}
|