@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
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import type { Abstract, Newable } from '../utils/types';
|
|
2
|
+
import { ContainerError } from './container-error';
|
|
3
|
+
import { InjectionTarget, InjectionUtil } from './injection';
|
|
4
|
+
import { Scope } from './scope';
|
|
5
|
+
|
|
6
|
+
/** What identifies a component: a class, or a symbol or string that stands for an interface. */
|
|
7
|
+
export type ComponentId<T = any> = string | symbol | Newable<T> | Abstract<T>;
|
|
8
|
+
|
|
9
|
+
/** What a dynamic value, a service alias or an activation handler gets. */
|
|
10
|
+
export interface ResolveContext {
|
|
11
|
+
readonly container: Container;
|
|
12
|
+
/** What is being resolved; with `owner` and `key` when it is injected into a class. */
|
|
13
|
+
readonly target: InjectionTarget;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Selects a binding among those of an identifier: `{ name }` for `@Named`, `{ tags }` for `@Tagged`. */
|
|
17
|
+
export interface BindingQuery {
|
|
18
|
+
name?: string | number | symbol;
|
|
19
|
+
tags?: Record<string | number | symbol, unknown>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type BindingConstraint = (target: InjectionTarget) => boolean;
|
|
23
|
+
|
|
24
|
+
export type ActivationHandler<T = any> = (context: ResolveContext, instance: T) => T;
|
|
25
|
+
|
|
26
|
+
/** How an identifier is resolved: a class, a constant, a factory or another identifier. */
|
|
27
|
+
export class Binding<T = any> {
|
|
28
|
+
type?: 'class' | 'constant' | 'factory' | 'service';
|
|
29
|
+
implementation?: Newable<T>;
|
|
30
|
+
factory?: (context: ResolveContext) => T;
|
|
31
|
+
/** The identifier a `service` binding resolves to. */
|
|
32
|
+
service?: ComponentId;
|
|
33
|
+
scope = Scope.Transient;
|
|
34
|
+
constraint?: BindingConstraint;
|
|
35
|
+
/** The constraint for people and tools: `named redis`, `tagged region=eu`, `default`. */
|
|
36
|
+
condition?: string;
|
|
37
|
+
activation?: ActivationHandler<T>;
|
|
38
|
+
/** Singletons and constants once created. */
|
|
39
|
+
resolved = false;
|
|
40
|
+
value?: T;
|
|
41
|
+
|
|
42
|
+
constructor(readonly id: ComponentId<T>) { }
|
|
43
|
+
|
|
44
|
+
to(implementation: Newable<T>): this {
|
|
45
|
+
this.type = 'class';
|
|
46
|
+
this.implementation = implementation;
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
toConstantValue(value: T): this {
|
|
51
|
+
this.type = 'constant';
|
|
52
|
+
this.value = value;
|
|
53
|
+
this.resolved = true;
|
|
54
|
+
this.scope = Scope.Singleton;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
toDynamicValue(factory: (context: ResolveContext) => T): this {
|
|
59
|
+
this.type = 'factory';
|
|
60
|
+
this.factory = factory;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Resolves another identifier: an alias, the same instance when that one is a singleton. */
|
|
65
|
+
toService(id: ComponentId<T>): this {
|
|
66
|
+
this.type = 'service';
|
|
67
|
+
this.service = id;
|
|
68
|
+
this.factory = context => context.container.get(id);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
inSingletonScope(): this {
|
|
73
|
+
this.scope = Scope.Singleton;
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
inTransientScope(): this {
|
|
78
|
+
this.scope = Scope.Transient;
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
when(constraint: BindingConstraint, condition = 'when'): this {
|
|
83
|
+
this.constraint = constraint;
|
|
84
|
+
this.condition = condition;
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
whenTargetNamed(name: string | number | symbol): this {
|
|
89
|
+
return this.when(target => target.name === name, `named ${String(name)}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
whenTargetTagged(key: string | number | symbol, value: unknown): this {
|
|
93
|
+
return this.when(target => target.tags !== undefined && target.tags[key] === value, `tagged ${String(key)}=${String(value)}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Only where nothing is asked for by name or tag. */
|
|
97
|
+
whenTargetIsDefault(): this {
|
|
98
|
+
return this.when(target => target.name === undefined && target.tags === undefined, 'default');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Called with each new instance (once for singletons); returns the instance to use, e.g. a proxy. */
|
|
102
|
+
onActivation(handler: ActivationHandler<T>): this {
|
|
103
|
+
this.activation = handler;
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type ContainerModuleRegistry = (
|
|
109
|
+
bind: <T>(id: ComponentId<T>) => Binding<T>,
|
|
110
|
+
unbind: (id: ComponentId) => void,
|
|
111
|
+
isBound: (id: ComponentId, query?: BindingQuery) => boolean,
|
|
112
|
+
rebind: <T>(id: ComponentId<T>) => Binding<T>
|
|
113
|
+
) => void;
|
|
114
|
+
|
|
115
|
+
/** A set of bindings that {@link Container.load} adds; what a DI module file exports by default. */
|
|
116
|
+
export class ContainerModule {
|
|
117
|
+
constructor(readonly registry: ContainerModuleRegistry) { }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const EMPTY: readonly Binding[] = [];
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The dependency injection container: bindings by identifier, resolved synchronously. Classes get their
|
|
124
|
+
* constructor parameters and properties from the decorators (`@Autowired`, `@Value`, `@Optional`,
|
|
125
|
+
* `@Named`, `@Tagged`) and `@PostConstruct` is called once they are injected.
|
|
126
|
+
*/
|
|
127
|
+
export class Container {
|
|
128
|
+
protected readonly map = new Map<ComponentId, Binding[]>();
|
|
129
|
+
/** The bindings being resolved and what asked for them, outermost first; for cycles and error messages. */
|
|
130
|
+
protected readonly resolving: Binding[] = [];
|
|
131
|
+
protected readonly requests: InjectionTarget[] = [];
|
|
132
|
+
|
|
133
|
+
constructor(...modules: ContainerModule[]) {
|
|
134
|
+
this.load(...modules);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
load(...modules: ContainerModule[]): void {
|
|
138
|
+
const bind = <T>(id: ComponentId<T>) => this.bind(id);
|
|
139
|
+
const unbind = (id: ComponentId) => this.unbind(id);
|
|
140
|
+
const isBound = (id: ComponentId, query?: BindingQuery) => this.isBound(id, query);
|
|
141
|
+
const rebind = <T>(id: ComponentId<T>) => this.rebind(id);
|
|
142
|
+
for (const module of modules) {
|
|
143
|
+
module.registry(bind, unbind, isBound, rebind);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
bind<T>(id: ComponentId<T>): Binding<T> {
|
|
148
|
+
const binding = new Binding<T>(id);
|
|
149
|
+
const bindings = this.map.get(id);
|
|
150
|
+
if (bindings) {
|
|
151
|
+
bindings.push(binding);
|
|
152
|
+
} else {
|
|
153
|
+
this.map.set(id, [binding]);
|
|
154
|
+
}
|
|
155
|
+
return binding;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Replaces the bindings of the identifier. */
|
|
159
|
+
rebind<T>(id: ComponentId<T>): Binding<T> {
|
|
160
|
+
this.unbind(id);
|
|
161
|
+
return this.bind(id);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
unbind(id: ComponentId): void {
|
|
165
|
+
this.map.delete(id);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Whether the identifier has a binding; with a query, one that matches it. */
|
|
169
|
+
isBound(id: ComponentId, query?: BindingQuery): boolean {
|
|
170
|
+
return query ? this.matching({ ...query, id }).length > 0 : this.map.has(id);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The one binding of the identifier that matches the query; throws when there is none or more than one. */
|
|
174
|
+
get<T>(id: ComponentId<T>, query?: BindingQuery): T {
|
|
175
|
+
return this.resolve(query ? { ...query, id } : { id });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Every binding of the identifier, whatever its constraint; with a query, the ones that match it.
|
|
180
|
+
* Throws when there is none.
|
|
181
|
+
*/
|
|
182
|
+
getAll<T>(id: ComponentId<T>, query?: BindingQuery): T[] {
|
|
183
|
+
return this.resolveAll(query ? { ...query, id } : { id }, !query);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Resolves an injection point: one instance, all of them (`multi`), or none when it is `optional`. */
|
|
187
|
+
resolve<T>(target: InjectionTarget): T {
|
|
188
|
+
if (target.multi) {
|
|
189
|
+
return this.resolveAll(target) as T;
|
|
190
|
+
}
|
|
191
|
+
const bindings = this.matching(target);
|
|
192
|
+
if (bindings.length === 1) {
|
|
193
|
+
return this.instance(bindings[0], target);
|
|
194
|
+
}
|
|
195
|
+
if (bindings.length === 0 && target.optional) {
|
|
196
|
+
return undefined as T;
|
|
197
|
+
}
|
|
198
|
+
throw bindings.length === 0 ? this.noBinding(target) : this.ambiguous(target, bindings);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Every binding by identifier, in the order they were bound; for tools (`cell check`, the dev MCP endpoint). */
|
|
202
|
+
bindings(): ReadonlyMap<ComponentId, readonly Binding[]> {
|
|
203
|
+
return this.map;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
protected resolveAll<T>(target: InjectionTarget, unconstrained = false): T[] {
|
|
207
|
+
const bindings = unconstrained ? this.map.get(target.id) ?? EMPTY : this.matching(target);
|
|
208
|
+
if (bindings.length === 0 && !target.optional) {
|
|
209
|
+
throw this.noBinding(target);
|
|
210
|
+
}
|
|
211
|
+
const instances = new Array<T>(bindings.length);
|
|
212
|
+
for (let i = 0; i < bindings.length; i++) {
|
|
213
|
+
instances[i] = this.instance(bindings[i], target);
|
|
214
|
+
}
|
|
215
|
+
return instances;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
protected matching(target: InjectionTarget): readonly Binding[] {
|
|
219
|
+
const bindings = this.map.get(target.id);
|
|
220
|
+
if (!bindings) {
|
|
221
|
+
return EMPTY;
|
|
222
|
+
}
|
|
223
|
+
for (const binding of bindings) {
|
|
224
|
+
if (binding.constraint && !binding.constraint(target)) {
|
|
225
|
+
return bindings.filter(b => !b.constraint || b.constraint(target));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return bindings;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
protected instance<T>(binding: Binding<T>, target: InjectionTarget): T {
|
|
232
|
+
if (binding.resolved) {
|
|
233
|
+
return binding.value as T;
|
|
234
|
+
}
|
|
235
|
+
if (this.resolving.includes(binding)) {
|
|
236
|
+
throw this.circular(target);
|
|
237
|
+
}
|
|
238
|
+
this.resolving.push(binding);
|
|
239
|
+
this.requests.push(target);
|
|
240
|
+
try {
|
|
241
|
+
const context: ResolveContext = { container: this, target };
|
|
242
|
+
let value: T;
|
|
243
|
+
if (binding.type === 'class') {
|
|
244
|
+
value = this.construct(binding.implementation!);
|
|
245
|
+
} else if (binding.factory) {
|
|
246
|
+
value = binding.factory(context);
|
|
247
|
+
} else {
|
|
248
|
+
throw new ContainerError({
|
|
249
|
+
code: 'CELL_DI_INCOMPLETE_BINDING',
|
|
250
|
+
message: `The binding of ${Container.idName(binding.id)} says nothing to resolve it to.`,
|
|
251
|
+
hint: 'Complete bind(id) with .to(Class), .toConstantValue(value), .toDynamicValue(factory) or .toService(id).',
|
|
252
|
+
path: this.path()
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
if (binding.activation) {
|
|
256
|
+
value = binding.activation(context, value);
|
|
257
|
+
}
|
|
258
|
+
if (binding.scope === Scope.Singleton) {
|
|
259
|
+
binding.value = value;
|
|
260
|
+
binding.resolved = true;
|
|
261
|
+
}
|
|
262
|
+
return value;
|
|
263
|
+
} finally {
|
|
264
|
+
this.resolving.pop();
|
|
265
|
+
this.requests.pop();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
protected construct<T>(type: Newable<T>): T {
|
|
270
|
+
const plan = InjectionUtil.plan(type);
|
|
271
|
+
const parameters = plan.parameters;
|
|
272
|
+
const args = new Array(parameters.length);
|
|
273
|
+
for (let i = 0; i < parameters.length; i++) {
|
|
274
|
+
args[i] = this.resolve(parameters[i]);
|
|
275
|
+
}
|
|
276
|
+
const instance: any = new type(...args);
|
|
277
|
+
for (const property of plan.properties) {
|
|
278
|
+
const value = this.resolve(property);
|
|
279
|
+
// Like a default parameter: an optional property that nothing is bound to keeps its initial value.
|
|
280
|
+
if (value !== undefined || !property.optional) {
|
|
281
|
+
instance[property.key!] = value;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (plan.postConstruct !== undefined) {
|
|
285
|
+
instance[plan.postConstruct]();
|
|
286
|
+
}
|
|
287
|
+
return instance;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** The identifiers being resolved, outermost first, then the one of `target`. */
|
|
291
|
+
protected path(target?: InjectionTarget): string[] {
|
|
292
|
+
const path = this.requests.map(request => Container.idName(request.id));
|
|
293
|
+
return target ? [...path, Container.idName(target.id)] : path;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
protected neededBy(target: InjectionTarget): string {
|
|
297
|
+
return target.owner ? `, needed by ${InjectionUtil.describe(target)}` : '';
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
protected noBinding(target: InjectionTarget): ContainerError {
|
|
301
|
+
const path = this.path(target);
|
|
302
|
+
const name = Container.idName(target.id);
|
|
303
|
+
const bound = this.map.get(target.id) ?? [];
|
|
304
|
+
let candidates = '';
|
|
305
|
+
if (bound.length > 0) {
|
|
306
|
+
candidates = ` The bindings of ${name} do not match: ${bound.map(Container.describe).join(', ')}.`;
|
|
307
|
+
} else if ([...this.map.keys()].some(id => id !== target.id && Container.idName(id) === name)) {
|
|
308
|
+
candidates = ` Another identifier is also named ${name}: two copies of the module that declares it are loaded.`;
|
|
309
|
+
}
|
|
310
|
+
return new ContainerError({
|
|
311
|
+
code: 'CELL_DI_NO_BINDING',
|
|
312
|
+
message: `No binding for ${Container.describe({ id: target.id, ...Container.query(target) })}${this.neededBy(target)}${Container.chain(path)}.${candidates}`,
|
|
313
|
+
hint: 'Bind the identifier in a DI module (@Component(<id>) in a file the module imports), or mark the injection @Optional().',
|
|
314
|
+
path
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
protected ambiguous(target: InjectionTarget, bindings: readonly Binding[]): ContainerError {
|
|
319
|
+
const path = this.path(target);
|
|
320
|
+
return new ContainerError({
|
|
321
|
+
code: 'CELL_DI_AMBIGUOUS',
|
|
322
|
+
message: `${bindings.length} bindings match ${Container.idName(target.id)}${this.neededBy(target)}${Container.chain(path)}: ${bindings.map(Container.describe).join(', ')}.`,
|
|
323
|
+
hint: 'Inject all of them with @Autowired on an array, give one rebind: true to replace the others, or select one with @Named / @Tagged.',
|
|
324
|
+
path
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
protected circular(target: InjectionTarget): ContainerError {
|
|
329
|
+
const path = this.path(target);
|
|
330
|
+
return new ContainerError({
|
|
331
|
+
code: 'CELL_DI_CIRCULAR',
|
|
332
|
+
message: `Circular dependency: ${path.join(' → ')}.`,
|
|
333
|
+
hint: 'Break the cycle: get one side lazily (a Provider, or @Autowired({ detached: true }) on a property), or move the shared part into another component.',
|
|
334
|
+
path
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
protected static chain(path: string[]): string {
|
|
339
|
+
return path.length > 1 ? ` (${path.join(' → ')})` : '';
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
protected static query(target: InjectionTarget): BindingQuery {
|
|
343
|
+
return { name: target.name, tags: target.tags };
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** `RedisStore [named redis]`, `Symbol(Store) named redis`. */
|
|
347
|
+
static describe(binding: Binding | (BindingQuery & { id: ComponentId })): string {
|
|
348
|
+
if (binding instanceof Binding) {
|
|
349
|
+
const what = binding.type === 'class' ? binding.implementation!.name || '(anonymous class)'
|
|
350
|
+
: binding.type === 'service' ? `→ ${Container.idName(binding.service)}` : (binding.type ?? 'incomplete');
|
|
351
|
+
return binding.condition ? `${what} [${binding.condition}]` : what;
|
|
352
|
+
}
|
|
353
|
+
const tags = binding.tags ? Reflect.ownKeys(binding.tags).map(key => ` tagged ${String(key)}=${String(binding.tags![key])}`).join('') : '';
|
|
354
|
+
return `${Container.idName(binding.id)}${binding.name !== undefined ? ` named ${String(binding.name)}` : ''}${tags}`;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
static idName(id: unknown): string {
|
|
358
|
+
if (typeof id === 'function') {
|
|
359
|
+
return id.name || '(anonymous class)';
|
|
360
|
+
}
|
|
361
|
+
return String(id);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Container } from '
|
|
1
|
+
import { Container } from './container';
|
|
2
2
|
|
|
3
|
-
//
|
|
3
|
+
// The toolchain replaces this file with the DI modules of the application (@celljs/vite ContainerGenerator).
|
|
4
4
|
export const container: Promise<Container> = Promise.resolve(new Container());
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
export * from './container
|
|
1
|
+
export * from './container';
|
|
2
|
+
export * from './container-error';
|
|
3
|
+
export * from './injection';
|
|
4
|
+
export * from './scope';
|
|
2
5
|
export * from './auto-bind';
|
|
6
|
+
export * from './container-provider';
|
|
3
7
|
export * from './container-util';
|
|
4
|
-
export * from './scope';
|
|
5
|
-
export * from './container-factory';
|
|
6
|
-
import { interfaces } from 'inversify';
|
|
7
|
-
export type Container = interfaces.Container;
|
|
8
|
-
export type ContainerModule = interfaces.ContainerModule;
|
|
9
|
-
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { ComponentId } from './container';
|
|
2
|
+
import { ContainerError } from './container-error';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A constructor parameter or property to inject: what to inject (`id`, all of them with `multi`,
|
|
6
|
+
* nothing when `optional` and unbound) and which binding (`name`, `tags`). Also what a dynamic value
|
|
7
|
+
* or constraint gets to see; `owner` and `key` are absent when the container is asked directly.
|
|
8
|
+
*/
|
|
9
|
+
export interface InjectionTarget {
|
|
10
|
+
readonly id: ComponentId;
|
|
11
|
+
readonly multi?: boolean;
|
|
12
|
+
readonly optional?: boolean;
|
|
13
|
+
readonly name?: string | number | symbol;
|
|
14
|
+
readonly tags?: Readonly<Record<string | number | symbol, unknown>>;
|
|
15
|
+
/** The class that declares the parameter or property. */
|
|
16
|
+
readonly owner?: Function;
|
|
17
|
+
/** The property, or the index of the constructor parameter. */
|
|
18
|
+
readonly key?: string | symbol | number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** How the container creates instances of a class; computed once per class. */
|
|
22
|
+
export interface InjectionPlan {
|
|
23
|
+
readonly parameters: readonly InjectionTarget[];
|
|
24
|
+
readonly properties: readonly InjectionTarget[];
|
|
25
|
+
readonly postConstruct?: string | symbol;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type Point = { -readonly [K in keyof InjectionTarget]?: InjectionTarget[K] };
|
|
29
|
+
|
|
30
|
+
const PARAMETERS = 'cell:di:parameters';
|
|
31
|
+
const PROPERTIES = 'cell:di:properties';
|
|
32
|
+
const POST_CONSTRUCT = 'cell:di:post-construct';
|
|
33
|
+
/** What TypeScript writes for parameters whose type is an interface, a union or a primitive. */
|
|
34
|
+
const NOT_AN_ID: unknown[] = [Object, Function, Array, String, Number, Boolean, Symbol, BigInt, Promise];
|
|
35
|
+
|
|
36
|
+
export namespace InjectionUtil {
|
|
37
|
+
|
|
38
|
+
const plans = new WeakMap<Function, InjectionPlan>();
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The injection point of a parameter or property decorator (`@Autowired`, `@Optional`, `@Named`...):
|
|
42
|
+
* the first decorator creates it, the others complete it. Subclasses inherit the properties.
|
|
43
|
+
*/
|
|
44
|
+
export function point(target: any, key: string | symbol | undefined, index?: number): Point {
|
|
45
|
+
if (index !== undefined) {
|
|
46
|
+
if (key !== undefined) {
|
|
47
|
+
throw new Error(`${target.constructor.name}.${String(key)}: only constructor parameters and properties can be injected.`);
|
|
48
|
+
}
|
|
49
|
+
let parameters: Point[] | undefined = Reflect.getOwnMetadata(PARAMETERS, target);
|
|
50
|
+
if (!parameters) {
|
|
51
|
+
parameters = [];
|
|
52
|
+
Reflect.defineMetadata(PARAMETERS, parameters, target);
|
|
53
|
+
}
|
|
54
|
+
return parameters[index] ??= { owner: target, key: index };
|
|
55
|
+
}
|
|
56
|
+
const owner = target.constructor;
|
|
57
|
+
let properties: Map<string | symbol, Point> | undefined = Reflect.getOwnMetadata(PROPERTIES, owner);
|
|
58
|
+
if (!properties) {
|
|
59
|
+
properties = new Map(Reflect.getMetadata(PROPERTIES, owner));
|
|
60
|
+
Reflect.defineMetadata(PROPERTIES, properties, owner);
|
|
61
|
+
}
|
|
62
|
+
let point = properties.get(key!);
|
|
63
|
+
if (!point || point.owner !== owner) {
|
|
64
|
+
point = { owner, key };
|
|
65
|
+
properties.set(key!, point);
|
|
66
|
+
}
|
|
67
|
+
return point;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Forgets a property: its value does not come from the container (`detached` injections). */
|
|
71
|
+
export function remove(target: any, key: string | symbol): void {
|
|
72
|
+
const properties: Map<string | symbol, Point> | undefined = Reflect.getOwnMetadata(PROPERTIES, target.constructor);
|
|
73
|
+
properties?.delete(key);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function setPostConstruct(target: any, key: string | symbol): void {
|
|
77
|
+
Reflect.defineMetadata(POST_CONSTRUCT, key, target.constructor);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function plan(type: Function): InjectionPlan {
|
|
81
|
+
let plan = plans.get(type);
|
|
82
|
+
if (!plan) {
|
|
83
|
+
plan = {
|
|
84
|
+
parameters: parameters(type),
|
|
85
|
+
properties: [...(Reflect.getMetadata(PROPERTIES, type) as Map<string | symbol, Point> | undefined)?.values() ?? []].map(complete),
|
|
86
|
+
postConstruct: Reflect.getMetadata(POST_CONSTRUCT, type)
|
|
87
|
+
};
|
|
88
|
+
plans.set(type, plan);
|
|
89
|
+
}
|
|
90
|
+
return plan;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The parameters of the nearest constructor in the class hierarchy that TypeScript or a decorator described. */
|
|
94
|
+
function parameters(type: Function): InjectionTarget[] {
|
|
95
|
+
for (let c: any = type; c && c !== Function.prototype; c = Object.getPrototypeOf(c)) {
|
|
96
|
+
const points: Point[] | undefined = Reflect.getOwnMetadata(PARAMETERS, c);
|
|
97
|
+
const types: unknown[] | undefined = Reflect.getOwnMetadata('design:paramtypes', c);
|
|
98
|
+
if (points || types) {
|
|
99
|
+
const count = Math.max(points?.length ?? 0, types?.length ?? 0);
|
|
100
|
+
const result: InjectionTarget[] = [];
|
|
101
|
+
for (let i = 0; i < count; i++) {
|
|
102
|
+
const point: Point = points?.[i] ?? { owner: c, key: i };
|
|
103
|
+
const declared = types?.[i];
|
|
104
|
+
result.push(complete(point.id === undefined && typeof declared === 'function' && !NOT_AN_ID.includes(declared)
|
|
105
|
+
? { ...point, id: declared as Function } : point));
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function complete(point: Point): InjectionTarget {
|
|
114
|
+
if (point.id === undefined) {
|
|
115
|
+
throw missing(point);
|
|
116
|
+
}
|
|
117
|
+
return point as InjectionTarget;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function missing(point: Point): ContainerError {
|
|
121
|
+
const where = describe(point);
|
|
122
|
+
return new ContainerError({
|
|
123
|
+
code: 'CELL_DI_MISSING_INJECT',
|
|
124
|
+
message: `${where} has no @Autowired (or @Value), so the container does not know what to inject.`,
|
|
125
|
+
hint: 'Add @Autowired(<id>) to the constructor parameter or property; an interface type needs the id explicitly.',
|
|
126
|
+
path: [where]
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** `UserService.repository` or `UserService constructor parameter #0`. */
|
|
131
|
+
export function describe(target: Partial<InjectionTarget>): string {
|
|
132
|
+
const owner = target.owner?.name || '(anonymous class)';
|
|
133
|
+
return typeof target.key === 'number' ? `${owner} constructor parameter #${target.key}` : `${owner}.${String(target.key)}`;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Component } from '../annotation/component';
|
|
2
|
+
import { ExpressionEngine } from './expression-engine';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The expression engine of the application, `@Autowired(ExpressionEngine)`: CoreContextInitializer adds
|
|
6
|
+
* the `replace`, `regexp` and `eval` transforms to it; add your own transforms and functions the same way.
|
|
7
|
+
*/
|
|
8
|
+
@Component(ExpressionEngine)
|
|
9
|
+
export class ApplicationExpressionEngine extends ExpressionEngine { }
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { Component, Autowired } from '../annotation';
|
|
2
2
|
import { ContainerUtil } from '../container';
|
|
3
|
-
import { ContextInitializer, ExpressionContext,
|
|
3
|
+
import { ContextInitializer, ExpressionContext, ExpressionHandler } from './expression-protocol';
|
|
4
|
+
import { ExpressionEngine } from './expression-engine';
|
|
4
5
|
|
|
5
6
|
@Component(ContextInitializer)
|
|
6
7
|
export class CoreContextInitializer implements ContextInitializer {
|
|
7
8
|
|
|
8
|
-
@Autowired(
|
|
9
|
-
protected readonly
|
|
9
|
+
@Autowired(ExpressionEngine)
|
|
10
|
+
protected readonly engine: ExpressionEngine;
|
|
10
11
|
|
|
11
12
|
initialize(ctx: ExpressionContext): void {
|
|
12
13
|
if (typeof process !== 'undefined') {
|
|
13
14
|
ctx.env = { ...process.env, _ignoreEl: true };
|
|
14
15
|
}
|
|
15
|
-
const jexlEngine = this.jexlEngineProvider.provide();
|
|
16
|
-
jexlEngine.addTransform('replace',
|
|
17
|
-
(val: string, searchValue: string | RegExp, replaceValue: string) => val && val.replace(new RegExp(searchValue, 'g'), replaceValue));
|
|
18
|
-
jexlEngine.addTransform('regexp', (pattern: string, flags?: string) => new RegExp(pattern, flags));
|
|
19
16
|
const expressionHandler = ContainerUtil.get<ExpressionHandler>(ExpressionHandler);
|
|
20
|
-
|
|
17
|
+
this.engine.addTransforms({
|
|
18
|
+
replace: (val: string, searchValue: string | RegExp, replaceValue: string) => val && val.replace(new RegExp(searchValue, 'g'), replaceValue),
|
|
19
|
+
regexp: (pattern: string, flags?: string) => new RegExp(pattern, flags),
|
|
20
|
+
eval: (text: string) => expressionHandler.handle(text)
|
|
21
|
+
});
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
priority = 500;
|