@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,259 @@
|
|
|
1
|
+
import { describe, it } from 'bun:test';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
// 通过 common 入口导入:直接深导入 utils/mime-type-util 会因 error 模块的循环依赖拿到未初始化的 CustomError
|
|
4
|
+
import {
|
|
5
|
+
UrlUtil, ByteUtil, isUUID, generateUUUID, Emitter, Event, Disposable, DisposableCollection,
|
|
6
|
+
CancellationTokenSource, CancellationToken, cancelled, isCancelled, checkCancelled,
|
|
7
|
+
MimeTypeUtils, MimeType, WaitUntilEvent, InvalidMimeTypeError, IllegalArgumentError
|
|
8
|
+
} from '../index';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* core 常用工具的约定(阶段 1.E 行为测试)。只测公开 API 的输入输出。
|
|
12
|
+
*/
|
|
13
|
+
describe('core utils:UrlUtil.join', () => {
|
|
14
|
+
it('拼接时合并多余的斜杠,保留协议,第一个片段的开头和最后一个片段的结尾各保留一个', () => {
|
|
15
|
+
expect(UrlUtil.join('http://a.com/', '/api/', '/users')).to.equal('http://a.com/api/users');
|
|
16
|
+
expect(UrlUtil.join('/base/', 'x/')).to.equal('/base/x/');
|
|
17
|
+
expect(UrlUtil.join('http:', 'a.com', 'b')).to.equal('http://a.com/b');
|
|
18
|
+
expect(UrlUtil.join('file:///', 'tmp', 'f')).to.equal('file:///tmp/f');
|
|
19
|
+
expect(UrlUtil.join('a', '', 'b')).to.equal('a/b');
|
|
20
|
+
expect(UrlUtil.join()).to.equal('');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('查询串:多个 ? 合成一个,后面的改成 &;? 前的斜杠去掉', () => {
|
|
24
|
+
expect(UrlUtil.join('http://a.com/', '?x=1', '?y=2')).to.equal('http://a.com?x=1&y=2');
|
|
25
|
+
expect(UrlUtil.join('/p/', '#hash')).to.equal('/p#hash');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('不是字符串时抛 TypeError', () => {
|
|
29
|
+
expect(() => UrlUtil.join(1 as any)).to.throw(TypeError);
|
|
30
|
+
expect(() => UrlUtil.join('a', 2 as any)).to.throw(TypeError);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('core utils:ByteUtil 与 UUID', () => {
|
|
35
|
+
it('decode:字符串原样返回,Buffer/Uint8Array 按 UTF-8 解码,空值为空串', () => {
|
|
36
|
+
expect(ByteUtil.decode('文本')).to.equal('文本');
|
|
37
|
+
expect(ByteUtil.decode(Buffer.from('中文🙂'))).to.equal('中文🙂');
|
|
38
|
+
expect(ByteUtil.decode(new TextEncoder().encode('ok'))).to.equal('ok');
|
|
39
|
+
expect(ByteUtil.decode(undefined as any)).to.equal('');
|
|
40
|
+
expect(() => ByteUtil.decode({} as any)).to.throw(IllegalArgumentError);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('base64 编解码往返', () => {
|
|
44
|
+
const b64 = ByteUtil.encodeBase64('héllo 世界');
|
|
45
|
+
expect(b64).to.equal(Buffer.from('héllo 世界').toString('base64'));
|
|
46
|
+
expect(ByteUtil.decode(ByteUtil.decodeBase64(b64))).to.equal('héllo 世界');
|
|
47
|
+
expect(ByteUtil.encodeBase64(new Uint8Array([0, 255]))).to.equal('AP8=');
|
|
48
|
+
expect(ByteUtil.encodeBase64('')).to.equal('');
|
|
49
|
+
expect(ByteUtil.decodeBase64('')).to.have.length(0);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('generateUUUID 生成 v4 UUID,互不重复;isUUID 校验格式', () => {
|
|
53
|
+
const ids = new Set(Array.from({ length: 200 }, () => generateUUUID()));
|
|
54
|
+
expect(ids.size).to.equal(200);
|
|
55
|
+
for (const id of ids) {
|
|
56
|
+
expect(isUUID(id)).to.equal(true);
|
|
57
|
+
expect(id[14]).to.equal('4');
|
|
58
|
+
}
|
|
59
|
+
expect(isUUID('not-a-uuid')).to.equal(false);
|
|
60
|
+
expect(isUUID('3F2504E0-4F89-11D3-9A0C-0305E82C3301')).to.equal(true);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('core utils:Emitter / Event / Disposable', () => {
|
|
65
|
+
it('fire 通知所有监听器;dispose 后的监听器不再收到;thisArgs 生效', () => {
|
|
66
|
+
const emitter = new Emitter<number>();
|
|
67
|
+
const got: number[] = [];
|
|
68
|
+
const ctx = { factor: 10 };
|
|
69
|
+
const d1 = emitter.event(n => got.push(n));
|
|
70
|
+
emitter.event(function (this: typeof ctx, n: number) { got.push(n * this.factor); }, ctx);
|
|
71
|
+
emitter.fire(1);
|
|
72
|
+
d1.dispose();
|
|
73
|
+
d1.dispose();
|
|
74
|
+
emitter.fire(2);
|
|
75
|
+
expect(got).to.deep.equal([1, 10, 20]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('监听器抛错不影响其他监听器', () => {
|
|
79
|
+
const emitter = new Emitter<string>();
|
|
80
|
+
const got: string[] = [];
|
|
81
|
+
const origError = console.error;
|
|
82
|
+
console.error = () => { };
|
|
83
|
+
try {
|
|
84
|
+
emitter.event(() => { throw new Error('bad'); });
|
|
85
|
+
emitter.event(s => got.push(s));
|
|
86
|
+
emitter.fire('x');
|
|
87
|
+
} finally {
|
|
88
|
+
console.error = origError;
|
|
89
|
+
}
|
|
90
|
+
expect(got).to.deep.equal(['x']);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('onFirstListenerAdd / onLastListenerRemove;disposables 数组会收到订阅句柄', () => {
|
|
94
|
+
const log: string[] = [];
|
|
95
|
+
const emitter = new Emitter<void>({ onFirstListenerAdd: () => log.push('first'), onLastListenerRemove: () => log.push('last') });
|
|
96
|
+
const bucket: Disposable[] = [];
|
|
97
|
+
emitter.event(() => { }, undefined, bucket);
|
|
98
|
+
emitter.event(() => { }, undefined, bucket);
|
|
99
|
+
expect(bucket).to.have.length(2);
|
|
100
|
+
bucket.forEach(d => d.dispose());
|
|
101
|
+
expect(log).to.deep.equal(['first', 'last']);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('emitter.dispose 之后 fire 不再通知', () => {
|
|
105
|
+
const emitter = new Emitter<number>();
|
|
106
|
+
const got: number[] = [];
|
|
107
|
+
emitter.event(n => got.push(n));
|
|
108
|
+
emitter.dispose();
|
|
109
|
+
emitter.fire(1);
|
|
110
|
+
expect(got).to.deep.equal([]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('Event.map 转换事件值;Event.None 订阅无效果', () => {
|
|
114
|
+
const emitter = new Emitter<number>();
|
|
115
|
+
const got: string[] = [];
|
|
116
|
+
Event.map(emitter.event, n => `#${n}`)(s => got.push(s));
|
|
117
|
+
emitter.fire(7);
|
|
118
|
+
expect(got).to.deep.equal(['#7']);
|
|
119
|
+
Event.None(() => { throw new Error('never'); }).dispose();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('DisposableCollection:倒序释放,只触发一次 onDispose;单个元素可单独移除', () => {
|
|
123
|
+
const order: string[] = [];
|
|
124
|
+
const coll = new DisposableCollection(Disposable.create(() => order.push('a')));
|
|
125
|
+
coll.push(Disposable.create(() => order.push('b')));
|
|
126
|
+
const removable = coll.push(Disposable.create(() => order.push('c')));
|
|
127
|
+
let fired = 0;
|
|
128
|
+
coll.onDispose(() => fired++);
|
|
129
|
+
removable.dispose();
|
|
130
|
+
expect(coll.disposed).to.equal(false);
|
|
131
|
+
coll.dispose();
|
|
132
|
+
coll.dispose();
|
|
133
|
+
expect(order).to.deep.equal(['b', 'a']);
|
|
134
|
+
expect(coll.disposed).to.equal(true);
|
|
135
|
+
expect(fired).to.equal(1);
|
|
136
|
+
expect(Disposable.is(coll)).to.equal(true);
|
|
137
|
+
expect(Disposable.is({})).to.equal(false);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('DisposableCollection:元素自己 dispose 时从集合里移除,全部移除后触发 onDispose', () => {
|
|
141
|
+
const a = Disposable.create(() => { });
|
|
142
|
+
const coll = new DisposableCollection();
|
|
143
|
+
let fired = 0;
|
|
144
|
+
coll.onDispose(() => fired++);
|
|
145
|
+
coll.pushAll([a]);
|
|
146
|
+
a.dispose();
|
|
147
|
+
expect(coll.disposed).to.equal(true);
|
|
148
|
+
expect(fired).to.equal(1);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe('core utils:取消', () => {
|
|
153
|
+
it('CancellationTokenSource:cancel 前后的状态与事件', () => {
|
|
154
|
+
const source = new CancellationTokenSource();
|
|
155
|
+
const token = source.token;
|
|
156
|
+
let fired = 0;
|
|
157
|
+
token.onCancellationRequested(() => fired++);
|
|
158
|
+
expect(token.isCancellationRequested).to.equal(false);
|
|
159
|
+
source.cancel();
|
|
160
|
+
source.cancel();
|
|
161
|
+
expect(token.isCancellationRequested).to.equal(true);
|
|
162
|
+
expect(fired).to.equal(1);
|
|
163
|
+
expect(() => checkCancelled(token)).to.throw();
|
|
164
|
+
expect(() => checkCancelled(CancellationToken.None)).not.to.throw();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('先 cancel 再取 token 时直接得到已取消的 token;已取消的 token 订阅后异步收到通知', async () => {
|
|
168
|
+
const source = new CancellationTokenSource();
|
|
169
|
+
source.dispose();
|
|
170
|
+
expect(source.token).to.equal(CancellationToken.Cancelled);
|
|
171
|
+
const fired = await new Promise<boolean>(resolve => {
|
|
172
|
+
source.token.onCancellationRequested(() => resolve(true));
|
|
173
|
+
setTimeout(() => resolve(false), 50);
|
|
174
|
+
});
|
|
175
|
+
expect(fired).to.equal(true);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('cancelled() / isCancelled()', () => {
|
|
179
|
+
expect(isCancelled(cancelled())).to.equal(true);
|
|
180
|
+
expect(isCancelled(new Error('other'))).to.equal(false);
|
|
181
|
+
expect(isCancelled(undefined)).to.equal(false);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('core utils:MimeType', () => {
|
|
186
|
+
it('解析类型、子类型、后缀;通配', () => {
|
|
187
|
+
const json = MimeTypeUtils.parseMimeType('application/vnd.api+json');
|
|
188
|
+
expect(json.getType()).to.equal('application');
|
|
189
|
+
expect(json.getSubtype()).to.equal('vnd.api+json');
|
|
190
|
+
expect(json.getSubtypeSuffix()).to.equal('json');
|
|
191
|
+
expect(MimeTypeUtils.parseMimeType('*').isWildcardType()).to.equal(true);
|
|
192
|
+
expect(MimeTypeUtils.parseMimeType('text/*').isWildcardSubtype()).to.equal(true);
|
|
193
|
+
expect(MimeTypeUtils.parseMimeType('text/plain').isConcrete()).to.equal(true);
|
|
194
|
+
expect(MimeType.valueOf('image/png').equals(MimeTypeUtils.IMAGE_PNG)).to.equal(true);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('includes / isCompatibleWith / isMoreSpecific', () => {
|
|
198
|
+
const all = MimeTypeUtils.ALL;
|
|
199
|
+
const text = MimeTypeUtils.parseMimeType('text/*');
|
|
200
|
+
const html = MimeTypeUtils.TEXT_HTML;
|
|
201
|
+
expect(all.includes(html)).to.equal(true);
|
|
202
|
+
expect(text.includes(html)).to.equal(true);
|
|
203
|
+
expect(html.includes(text)).to.equal(false);
|
|
204
|
+
expect(html.isCompatibleWith(text)).to.equal(true);
|
|
205
|
+
expect(html.isCompatibleWith(MimeTypeUtils.APPLICATION_JSON)).to.equal(false);
|
|
206
|
+
expect(html.isMoreSpecific(text)).to.equal(true);
|
|
207
|
+
expect(html.isPresentIn([MimeTypeUtils.TEXT_PLAIN, MimeTypeUtils.TEXT_HTML])).to.equal(true);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('保留参数:charset 和其他参数都能取到,toString 带上参数(F9)', () => {
|
|
211
|
+
const t = MimeTypeUtils.parseMimeType('text/html; charset=UTF-8; level=1');
|
|
212
|
+
expect(t.getCharset()).to.equal('UTF-8');
|
|
213
|
+
expect(t.getParameter('level')).to.equal('1');
|
|
214
|
+
expect(t.toString()).to.equal('text/html;charset=UTF-8;level=1');
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('非法输入抛 InvalidMimeTypeError', () => {
|
|
218
|
+
expect(() => MimeTypeUtils.parseMimeType('')).to.throw(InvalidMimeTypeError);
|
|
219
|
+
expect(() => MimeTypeUtils.parseMimeType('noslash')).to.throw(InvalidMimeTypeError);
|
|
220
|
+
expect(() => MimeTypeUtils.parseMimeType('text/')).to.throw(InvalidMimeTypeError);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('tokenize 按逗号切分,引号里的逗号不切', () => {
|
|
224
|
+
expect(MimeTypeUtils.tokenize('a/b, c/d;x="1,2"')).to.deep.equal(['a/b', ' c/d;x="1,2"']);
|
|
225
|
+
expect(MimeTypeUtils.tokenize('')).to.deep.equal([]);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('sortBySpecificity:具体的排在前面', () => {
|
|
229
|
+
const list = [MimeTypeUtils.ALL, MimeTypeUtils.parseMimeType('text/*'), MimeTypeUtils.TEXT_HTML];
|
|
230
|
+
MimeTypeUtils.sortBySpecificity(list);
|
|
231
|
+
expect(list.map(String)).to.deep.equal(['text/html', 'text/*', '*/*']);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('parseMimeTypes 按逗号解析多个类型(F8)', () => {
|
|
235
|
+
expect(MimeTypeUtils.parseMimeTypes('text/html, application/json').map(String)).to.deep.equal(['text/html', 'application/json']);
|
|
236
|
+
expect(MimeTypeUtils.parseMimeTypes('')).to.deep.equal([]);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('generateMultipartBoundaryString:30–40 个合法字符', () => {
|
|
240
|
+
const b = MimeTypeUtils.generateMultipartBoundaryString();
|
|
241
|
+
expect(b.length).to.be.within(30, 40);
|
|
242
|
+
expect(b).to.match(/^[-_0-9a-zA-Z]+$/);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe('core utils:WaitUntilEvent', () => {
|
|
247
|
+
interface Ev extends WaitUntilEvent { name: string }
|
|
248
|
+
|
|
249
|
+
it('WaitUntilEvent.fire 等待所有 waitUntil 的 Promise;异步调用 waitUntil 报错', async () => {
|
|
250
|
+
const emitter = new Emitter<Ev>();
|
|
251
|
+
const log: string[] = [];
|
|
252
|
+
let late: Ev | undefined;
|
|
253
|
+
emitter.event(e => e.waitUntil(new Promise<void>(r => setTimeout(() => { log.push('slow'); r(); }, 5))));
|
|
254
|
+
emitter.event(e => { late = e; log.push(e.name); });
|
|
255
|
+
await WaitUntilEvent.fire(emitter, { name: 'go' });
|
|
256
|
+
expect(log).to.deep.equal(['go', 'slow']);
|
|
257
|
+
expect(() => late!.waitUntil(Promise.resolve())).to.throw();
|
|
258
|
+
});
|
|
259
|
+
});
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { describe, it } from 'bun:test';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { AttributeScope, Context } from './context';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 请求上下文的约定,与实现无关(以前是 cls-hooked,现在是 AsyncLocalStorage)。
|
|
7
|
+
*
|
|
8
|
+
* cls-hooked 下这些用例有 4 条失败(2026-11-08 在 Node 24.13 和 Bun 1.3.11 上实测):run 里设置的上下文泄漏给
|
|
9
|
+
* await 它的调用方;Node 下外层 await 内层 run 之后看到内层的上下文;Bun 下并发的 run 之间没有隔离(请求之间串上下文);
|
|
10
|
+
* Context.run 没有返回值。换成 AsyncLocalStorage 之后全部通过。同一组场景在 Node 上的结果见
|
|
11
|
+
* cell-refactor/stage0/context-isolation/。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const tick = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms));
|
|
15
|
+
|
|
16
|
+
/** 在 Context.run 里执行 fn,并等它完成。不依赖 run 的返回值,所以同一组用例也能验证以前没有返回值的实现。 */
|
|
17
|
+
function inRun<T>(fn: () => Promise<T>): Promise<T> {
|
|
18
|
+
return new Promise<T>((resolve, reject) => {
|
|
19
|
+
Context.run(async () => {
|
|
20
|
+
try {
|
|
21
|
+
resolve(await fn());
|
|
22
|
+
} catch (error) {
|
|
23
|
+
reject(error);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function named(name: string): Context {
|
|
30
|
+
const ctx = new Context();
|
|
31
|
+
ctx.name = name;
|
|
32
|
+
return ctx;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe('Context', () => {
|
|
36
|
+
it('run 之外没有当前上下文', () => {
|
|
37
|
+
expect(Context.getCurrent()).to.equal(undefined);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('run 里设置的上下文在 await、setTimeout 和 Promise 链之后仍然可见', async () => {
|
|
41
|
+
const ctx = named('a');
|
|
42
|
+
const seen = await inRun(async () => {
|
|
43
|
+
Context.setCurrent(ctx);
|
|
44
|
+
await tick();
|
|
45
|
+
const afterTimer = await new Promise<Context>(resolve => setTimeout(() => resolve(Context.getCurrent()), 1));
|
|
46
|
+
const afterChain = await Promise.resolve()
|
|
47
|
+
.then(() => tick())
|
|
48
|
+
.then(() => Context.getCurrent());
|
|
49
|
+
return [Context.getCurrent(), afterTimer, afterChain];
|
|
50
|
+
});
|
|
51
|
+
expect(seen).to.deep.equal([ctx, ctx, ctx]);
|
|
52
|
+
expect(seen.every(c => c === ctx)).to.equal(true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('run 结束后上下文不会泄漏给 await 它的调用方', async () => {
|
|
56
|
+
await inRun(async () => {
|
|
57
|
+
Context.setCurrent(named('a'));
|
|
58
|
+
});
|
|
59
|
+
expect(Context.getCurrent()).to.equal(undefined);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('嵌套', () => {
|
|
63
|
+
it('内层设置自己的上下文,不影响外层', async () => {
|
|
64
|
+
const outer = named('outer');
|
|
65
|
+
const inner = named('inner');
|
|
66
|
+
const seen = await inRun(async () => {
|
|
67
|
+
Context.setCurrent(outer);
|
|
68
|
+
const inside = await inRun(async () => {
|
|
69
|
+
Context.setCurrent(inner);
|
|
70
|
+
await tick();
|
|
71
|
+
return Context.getCurrent();
|
|
72
|
+
});
|
|
73
|
+
await tick();
|
|
74
|
+
return { inside, after: Context.getCurrent() };
|
|
75
|
+
});
|
|
76
|
+
expect(seen.inside).to.equal(inner);
|
|
77
|
+
expect(seen.after).to.equal(outer);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// 4.x 兼容语义(cls-hooked 一直如此):4.x 不改行为,AsyncLocalStorage 实现以外层的值为原型创建内层的值来保持它;5.0 再评估。
|
|
81
|
+
it('内层在设置自己的上下文之前继承外层的上下文', async () => {
|
|
82
|
+
const outer = named('outer');
|
|
83
|
+
const inherited = await inRun(async () => {
|
|
84
|
+
Context.setCurrent(outer);
|
|
85
|
+
return inRun(async () => Context.getCurrent());
|
|
86
|
+
});
|
|
87
|
+
expect(inherited).to.equal(outer);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('并发的 run 互相隔离', async () => {
|
|
92
|
+
const contexts = Array.from({ length: 50 }, (_, i) => named(`c${i}`));
|
|
93
|
+
const seen = await Promise.all(
|
|
94
|
+
contexts.map((ctx, i) =>
|
|
95
|
+
inRun(async () => {
|
|
96
|
+
Context.setCurrent(ctx);
|
|
97
|
+
await tick(i % 7);
|
|
98
|
+
const first = Context.getCurrent();
|
|
99
|
+
await tick((i * 3) % 5);
|
|
100
|
+
return [first, Context.getCurrent()];
|
|
101
|
+
}),
|
|
102
|
+
),
|
|
103
|
+
);
|
|
104
|
+
seen.forEach(([first, second], i) => {
|
|
105
|
+
expect(first).to.equal(contexts[i]);
|
|
106
|
+
expect(second).to.equal(contexts[i]);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('run 之外 setCurrent 抛错', () => {
|
|
111
|
+
expect(() => Context.setCurrent(new Context())).to.throw('No context available');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('Context.run 的 Promise 以 fn 的返回值 resolve', async () => {
|
|
115
|
+
expect(await Context.run(async () => 42)).to.equal(42);
|
|
116
|
+
expect(await Context.run(() => 'sync')).to.equal('sync');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('bind 的函数在 run 结束后调用,仍然看到绑定时的上下文', async () => {
|
|
120
|
+
const ctx = named('bound');
|
|
121
|
+
const bound = await inRun(async () => {
|
|
122
|
+
Context.setCurrent(ctx);
|
|
123
|
+
return Context.bind(() => Context.getCurrent());
|
|
124
|
+
});
|
|
125
|
+
expect(bound()).to.equal(ctx);
|
|
126
|
+
expect(await new Promise(resolve => setTimeout(() => resolve(bound()), 1))).to.equal(ctx);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('异常', () => {
|
|
130
|
+
it('run 里捕获的异常不影响当前上下文', async () => {
|
|
131
|
+
const ctx = named('a');
|
|
132
|
+
const seen = await inRun(async () => {
|
|
133
|
+
Context.setCurrent(ctx);
|
|
134
|
+
try {
|
|
135
|
+
await tick();
|
|
136
|
+
throw new Error('boom');
|
|
137
|
+
} catch {
|
|
138
|
+
// 被调用方吞掉
|
|
139
|
+
}
|
|
140
|
+
return Context.getCurrent();
|
|
141
|
+
});
|
|
142
|
+
expect(seen).to.equal(ctx);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('内层 run 的异常传到外层,外层上下文不变', async () => {
|
|
146
|
+
const outer = named('outer');
|
|
147
|
+
const boom = new Error('boom');
|
|
148
|
+
const seen = await inRun(async () => {
|
|
149
|
+
Context.setCurrent(outer);
|
|
150
|
+
let caught: unknown;
|
|
151
|
+
try {
|
|
152
|
+
await inRun(async () => {
|
|
153
|
+
Context.setCurrent(named('inner'));
|
|
154
|
+
await tick();
|
|
155
|
+
throw boom;
|
|
156
|
+
});
|
|
157
|
+
} catch (error) {
|
|
158
|
+
caught = error;
|
|
159
|
+
}
|
|
160
|
+
return { caught, after: Context.getCurrent() };
|
|
161
|
+
});
|
|
162
|
+
expect(seen.caught).to.equal(boom);
|
|
163
|
+
expect(seen.after).to.equal(outer);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('Context.run 返回 Promise,fn 的异常让它 reject', async () => {
|
|
167
|
+
const boom = new Error('boom');
|
|
168
|
+
const result = Context.run(async () => {
|
|
169
|
+
throw boom;
|
|
170
|
+
}) as unknown;
|
|
171
|
+
expect(result).to.be.instanceOf(Promise);
|
|
172
|
+
let caught: unknown;
|
|
173
|
+
await (result as Promise<void>).catch(error => {
|
|
174
|
+
caught = error;
|
|
175
|
+
});
|
|
176
|
+
expect(caught).to.equal(boom);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe('属性', () => {
|
|
181
|
+
it('Request 作用域的属性只在本次 run 里可见,App 作用域跨 run 可见', async () => {
|
|
182
|
+
const key = `attr-${Date.now()}`;
|
|
183
|
+
await inRun(async () => {
|
|
184
|
+
Context.setCurrent(new Context());
|
|
185
|
+
Context.setAttr(key, 'request');
|
|
186
|
+
Context.setAttr(`${key}-app`, 'app', AttributeScope.App);
|
|
187
|
+
expect(Context.getAttr(key, AttributeScope.Request)).to.equal('request');
|
|
188
|
+
});
|
|
189
|
+
const other = await inRun(async () => {
|
|
190
|
+
Context.setCurrent(new Context());
|
|
191
|
+
return [Context.getAttr(key, AttributeScope.Request), Context.getAttr(`${key}-app`, AttributeScope.App)];
|
|
192
|
+
});
|
|
193
|
+
expect(other).to.deep.equal([undefined, 'app']);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('不指定作用域时先找 Request,再找 App', async () => {
|
|
197
|
+
const key = `fallback-${Date.now()}`;
|
|
198
|
+
Context.setAttr(key, 'app', AttributeScope.App);
|
|
199
|
+
const seen = await inRun(async () => {
|
|
200
|
+
Context.setCurrent(new Context());
|
|
201
|
+
const before = Context.getAttr(key);
|
|
202
|
+
Context.setAttr(key, 'request');
|
|
203
|
+
return [before, Context.getAttr(key)];
|
|
204
|
+
});
|
|
205
|
+
expect(seen).to.deep.equal(['app', 'request']);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('AttributeScope.App 只读 App 作用域(App 的枚举值是 0,不能当成“不指定”)', async () => {
|
|
209
|
+
const key = `app-only-${Date.now()}`;
|
|
210
|
+
Context.setAttr(key, 'app', AttributeScope.App);
|
|
211
|
+
const seen = await inRun(async () => {
|
|
212
|
+
Context.setCurrent(new Context());
|
|
213
|
+
Context.setAttr(key, 'request');
|
|
214
|
+
return [Context.getAttr(key, AttributeScope.App), Context.getAttr(key, AttributeScope.Request)];
|
|
215
|
+
});
|
|
216
|
+
expect(seen).to.deep.equal(['app', 'request']);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
2
|
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
4
4
|
export enum AttributeScope { App, Request, Session }
|
|
@@ -7,26 +7,51 @@ export const CURRENT_CONTEXT_REQUEST_KEY = 'CurrentContextRequest';
|
|
|
7
7
|
|
|
8
8
|
const appAttrs = new Map<string, any>();
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
/** The values of one `Context.run`. */
|
|
11
|
+
type Store = Record<string, any>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* One storage per process, shared by every copy of this module (the CommonJS and the ES module build,
|
|
15
|
+
* a Vite module runner): a context set through one copy is seen through the others.
|
|
16
|
+
*/
|
|
17
|
+
const STORAGE_KEY = Symbol.for('@celljs/core/context-storage');
|
|
18
|
+
const storage: AsyncLocalStorage<Store> = ((globalThis as Record<symbol, any>)[STORAGE_KEY] ??= new AsyncLocalStorage<Store>());
|
|
19
|
+
|
|
20
|
+
function activeStore(): Store {
|
|
21
|
+
const store = storage.getStore();
|
|
22
|
+
if (!store) {
|
|
23
|
+
throw new Error('No context available. Context.run() or Context.bind() must be called first.');
|
|
24
|
+
}
|
|
25
|
+
return store;
|
|
26
|
+
}
|
|
11
27
|
|
|
12
28
|
export class Context {
|
|
13
29
|
|
|
14
30
|
[key: string | symbol | number]: any;
|
|
15
31
|
|
|
16
|
-
|
|
17
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Runs `fn` in a new context; the returned promise settles with `fn`. A nested run starts from the
|
|
34
|
+
* values of the outer run (it sees the outer current context until it sets its own) and its changes
|
|
35
|
+
* stay inside it: the semantics of 4.x, kept from cls-hooked.
|
|
36
|
+
*/
|
|
37
|
+
static run<T>(fn: (...args: any[]) => T | PromiseLike<T>): Promise<T> {
|
|
38
|
+
return storage.run(Object.create(storage.getStore() ?? null), async () => fn());
|
|
18
39
|
}
|
|
19
40
|
|
|
20
|
-
|
|
21
|
-
|
|
41
|
+
/** `fn` runs in `context` (the values of a run), by default the context active now. */
|
|
42
|
+
static bind<F extends (...args: any[]) => any>(fn: F, context?: Store): F {
|
|
43
|
+
const store = context ?? storage.getStore() ?? Object.create(null);
|
|
44
|
+
return function (this: unknown, ...args: any[]) {
|
|
45
|
+
return storage.run(store, () => fn.apply(this, args));
|
|
46
|
+
} as F;
|
|
22
47
|
}
|
|
23
48
|
|
|
24
49
|
static setCurrent(context: Context) {
|
|
25
|
-
|
|
50
|
+
activeStore()[CURRENT_CONTEXT_REQUEST_KEY] = context;
|
|
26
51
|
}
|
|
27
52
|
|
|
28
53
|
static getCurrent<T extends Context>(): T {
|
|
29
|
-
return
|
|
54
|
+
return storage.getStore()?.[CURRENT_CONTEXT_REQUEST_KEY];
|
|
30
55
|
}
|
|
31
56
|
|
|
32
57
|
static setAttr(key: string, value: any, scope: AttributeScope = AttributeScope.Request) {
|
|
@@ -40,7 +65,7 @@ export class Context {
|
|
|
40
65
|
}
|
|
41
66
|
|
|
42
67
|
static getAttr<T>(key: string, scope?: AttributeScope): T {
|
|
43
|
-
if (scope) {
|
|
68
|
+
if (scope !== undefined) {
|
|
44
69
|
if (scope === AttributeScope.Request) {
|
|
45
70
|
return Context.getCurrent()?.[key];
|
|
46
71
|
} else if (scope === AttributeScope.Session) {
|
|
@@ -49,7 +74,7 @@ export class Context {
|
|
|
49
74
|
return appAttrs.get(key);
|
|
50
75
|
}
|
|
51
76
|
} else {
|
|
52
|
-
let value =
|
|
77
|
+
let value = storage.getStore()?.[key];
|
|
53
78
|
value = value ? value : Context.getCurrent()?.[key];
|
|
54
79
|
return value ? value : appAttrs.get(key);
|
|
55
80
|
}
|
package/src/node/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { decorate } from 'inversify';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decorate.js","sourceRoot":"","sources":["../../../src/common/annotation/decorate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { inject as Inject } from 'inversify';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/common/annotation/inject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { injectable as Injectable } from 'inversify';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectable.js","sourceRoot":"","sources":["../../../src/common/annotation/injectable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { preDestroy as PreDestroy } from 'inversify';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pre-destroy.js","sourceRoot":"","sources":["../../../src/common/annotation/pre-destroy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { targetName as TargetName } from 'inversify';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"target-name.js","sourceRoot":"","sources":["../../../src/common/annotation/target-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { unmanaged as Unmanaged } from 'inversify';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unmanaged.js","sourceRoot":"","sources":["../../../src/common/annotation/unmanaged.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Container } from 'inversify';
|
|
2
|
-
export class ContainerFactory {
|
|
3
|
-
static create(...modules) {
|
|
4
|
-
const container = new Container({ skipBaseClassChecks: true });
|
|
5
|
-
container.load(...modules);
|
|
6
|
-
return container;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=container-factory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"container-factory.js","sourceRoot":"","sources":["../../../src/common/container/container-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA+B,MAAM,WAAW,CAAC;AAEnE,MAAM,OAAO,gBAAgB;IACzB,MAAM,CAAC,MAAM,CAAC,GAAG,OAA0B;QACvC,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,EAAE,mBAAmB,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/D,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;QAC3B,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ"}
|