@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,487 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The expression language of Cell: what `${...}` in the configuration, `@Value` and the security
|
|
3
|
+
* policies evaluate. Its grammar is the one of jexl 2, which Cell used before:
|
|
4
|
+
*
|
|
5
|
+
* - literals: `'text'`, `"text"`, `42`, `1.5`, `true`, `false`, `[a, b]`, `{ key: value }`;
|
|
6
|
+
* - names: `cell.server.port`, `list[0]`, `map['key']`, filters `users[.age > 18]` (`.age` is a
|
|
7
|
+
* property of each element); a missing property is `undefined`, never an error; a property of an
|
|
8
|
+
* array is the property of its first element;
|
|
9
|
+
* - operators, loosest first: `a ? b : c` and `a ?: b` (`b` when `a` is falsy), `||` and `&&` (same
|
|
10
|
+
* precedence, left to right), `== != > >= < <= in`, `+ -`, `* / //` (`//` rounds down), `% ^`
|
|
11
|
+
* (`^` is power), then `!` and `-` in front;
|
|
12
|
+
* - transforms `value|name(args)` and functions `name(args)`: only the ones added to the engine.
|
|
13
|
+
*
|
|
14
|
+
* Evaluation is synchronous. Expressions cannot call methods, so they only read what the context gives.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** The code of an {@link ExpressionSyntaxError}. */
|
|
18
|
+
export type ExpressionErrorCode = 'CELL_EL_SYNTAX' | 'CELL_EL_UNKNOWN_TRANSFORM' | 'CELL_EL_UNKNOWN_FUNCTION';
|
|
19
|
+
|
|
20
|
+
/** An expression that cannot be parsed, or that uses a transform or function the engine does not have. */
|
|
21
|
+
export class ExpressionSyntaxError extends Error {
|
|
22
|
+
override readonly name = 'ExpressionSyntaxError';
|
|
23
|
+
readonly code: ExpressionErrorCode;
|
|
24
|
+
readonly hint: string;
|
|
25
|
+
readonly expression: string;
|
|
26
|
+
/** Where in `expression` parsing failed. */
|
|
27
|
+
readonly position?: number;
|
|
28
|
+
|
|
29
|
+
constructor(options: { code: ExpressionErrorCode, message: string, hint: string, expression: string, position?: number }) {
|
|
30
|
+
super(options.message);
|
|
31
|
+
this.code = options.code;
|
|
32
|
+
this.hint = options.hint;
|
|
33
|
+
this.expression = options.expression;
|
|
34
|
+
this.position = options.position;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type Evaluate = (context: any, element: any) => any;
|
|
39
|
+
|
|
40
|
+
/** A compiled expression; evaluate it as many times as needed. */
|
|
41
|
+
export class Expression {
|
|
42
|
+
constructor(readonly source: string, protected readonly run: Evaluate) { }
|
|
43
|
+
|
|
44
|
+
/** The value of the expression; names are properties of `context`. */
|
|
45
|
+
evaluate(context: object = {}): any {
|
|
46
|
+
return this.run(context, context);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Compiles and evaluates expressions; holds the transforms and functions they may call. */
|
|
51
|
+
export class ExpressionEngine {
|
|
52
|
+
protected static readonly CACHE_SIZE = 1000;
|
|
53
|
+
|
|
54
|
+
protected readonly transforms = new Map<string, Function>();
|
|
55
|
+
protected readonly functions = new Map<string, Function>();
|
|
56
|
+
protected readonly cache = new Map<string, Expression>();
|
|
57
|
+
|
|
58
|
+
/** `value|name(a, b)` calls `transform(value, a, b)`. */
|
|
59
|
+
addTransform(name: string, transform: (value: any, ...args: any[]) => any): this {
|
|
60
|
+
this.transforms.set(name, transform);
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
addTransforms(transforms: Record<string, (value: any, ...args: any[]) => any>): this {
|
|
65
|
+
for (const [name, transform] of Object.entries(transforms)) {
|
|
66
|
+
this.addTransform(name, transform);
|
|
67
|
+
}
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** `name(a, b)` calls `fn(a, b)`. */
|
|
72
|
+
addFunction(name: string, fn: (...args: any[]) => any): this {
|
|
73
|
+
this.functions.set(name, fn);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
addFunctions(functions: Record<string, (...args: any[]) => any>): this {
|
|
78
|
+
for (const [name, fn] of Object.entries(functions)) {
|
|
79
|
+
this.addFunction(name, fn);
|
|
80
|
+
}
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Compiles once per source text (the latest ones are kept). Throws an {@link ExpressionSyntaxError}. */
|
|
85
|
+
compile(source: string): Expression {
|
|
86
|
+
let expression = this.cache.get(source);
|
|
87
|
+
if (!expression) {
|
|
88
|
+
expression = new Expression(source, new ExpressionParser(source, this).parse());
|
|
89
|
+
if (this.cache.size >= ExpressionEngine.CACHE_SIZE) {
|
|
90
|
+
this.cache.clear();
|
|
91
|
+
}
|
|
92
|
+
this.cache.set(source, expression);
|
|
93
|
+
}
|
|
94
|
+
return expression;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
evaluate(source: string, context: object = {}): any {
|
|
98
|
+
return this.compile(source).evaluate(context);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** @internal what the compiled expressions call */
|
|
102
|
+
call(pool: 'transform' | 'function', name: string, args: any[], source: string): any {
|
|
103
|
+
const fn = (pool === 'transform' ? this.transforms : this.functions).get(name);
|
|
104
|
+
if (!fn) {
|
|
105
|
+
throw new ExpressionSyntaxError({
|
|
106
|
+
code: pool === 'transform' ? 'CELL_EL_UNKNOWN_TRANSFORM' : 'CELL_EL_UNKNOWN_FUNCTION',
|
|
107
|
+
message: `The ${pool} ${name} is not defined (in: ${source}).`,
|
|
108
|
+
hint: `Add it with addT${pool.slice(1)}('${name}', ...) on the ExpressionEngine of the application, or check its spelling.`,
|
|
109
|
+
expression: source
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return fn(...args);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
interface Token {
|
|
117
|
+
type: 'number' | 'string' | 'boolean' | 'identifier' | 'operator' | 'punctuation' | 'end';
|
|
118
|
+
value: any;
|
|
119
|
+
start: number;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Longest first, so that `//` is not `/`. */
|
|
123
|
+
const OPERATORS = ['//', '==', '!=', '>=', '<=', '&&', '||', '+', '-', '*', '/', '%', '^', '>', '<', '!'];
|
|
124
|
+
const PUNCTUATION = '.[]|{}:,()?';
|
|
125
|
+
const PRECEDENCE: Record<string, number> = {
|
|
126
|
+
'||': 10, '&&': 10,
|
|
127
|
+
'==': 20, '!=': 20, '>': 20, '>=': 20, '<': 20, '<=': 20, in: 20,
|
|
128
|
+
'+': 30, '-': 30,
|
|
129
|
+
'*': 40, '/': 40, '//': 40,
|
|
130
|
+
'%': 50, '^': 50
|
|
131
|
+
};
|
|
132
|
+
const BINARY: Record<string, (left: any, right: any) => any> = {
|
|
133
|
+
// eslint-disable-next-line eqeqeq
|
|
134
|
+
'==': (l, r) => l == r,
|
|
135
|
+
// eslint-disable-next-line eqeqeq
|
|
136
|
+
'!=': (l, r) => l != r,
|
|
137
|
+
'>': (l, r) => l > r,
|
|
138
|
+
'>=': (l, r) => l >= r,
|
|
139
|
+
'<': (l, r) => l < r,
|
|
140
|
+
'<=': (l, r) => l <= r,
|
|
141
|
+
in: (l, r) => typeof r === 'string' ? r.indexOf(l) !== -1 : Array.isArray(r) ? r.some(e => e === l) : false,
|
|
142
|
+
'+': (l, r) => l + r,
|
|
143
|
+
'-': (l, r) => l - r,
|
|
144
|
+
'*': (l, r) => l * r,
|
|
145
|
+
'/': (l, r) => l / r,
|
|
146
|
+
'//': (l, r) => Math.floor(l / r),
|
|
147
|
+
'%': (l, r) => l % r,
|
|
148
|
+
'^': (l, r) => Math.pow(l, r)
|
|
149
|
+
};
|
|
150
|
+
const IDENTIFIER_START = /[\p{L}_$]/u;
|
|
151
|
+
const IDENTIFIER_PART = /[\p{L}\p{N}_$]/u;
|
|
152
|
+
|
|
153
|
+
/** A recursive descent parser that compiles to closures: `(context, element) => value`. */
|
|
154
|
+
class ExpressionParser {
|
|
155
|
+
protected readonly tokens: Token[];
|
|
156
|
+
protected index = 0;
|
|
157
|
+
/** Whether the expression being parsed reads `.name`: then a filter keeps the elements it is true for. */
|
|
158
|
+
protected relative = false;
|
|
159
|
+
|
|
160
|
+
constructor(protected readonly source: string, protected readonly engine: ExpressionEngine) {
|
|
161
|
+
this.tokens = this.tokenize();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
parse(): Evaluate {
|
|
165
|
+
if (this.peek().type === 'end') {
|
|
166
|
+
return () => undefined;
|
|
167
|
+
}
|
|
168
|
+
const evaluate = this.ternary();
|
|
169
|
+
if (this.peek().type !== 'end') {
|
|
170
|
+
throw this.unexpected();
|
|
171
|
+
}
|
|
172
|
+
return evaluate;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
protected ternary(): Evaluate {
|
|
176
|
+
const test = this.binary(0);
|
|
177
|
+
if (!this.accept('?')) {
|
|
178
|
+
return test;
|
|
179
|
+
}
|
|
180
|
+
const consequent = this.accept(':') ? undefined : this.ternaryThen();
|
|
181
|
+
const alternate = this.ternary();
|
|
182
|
+
if (!consequent) {
|
|
183
|
+
return (c, e) => test(c, e) || alternate(c, e);
|
|
184
|
+
}
|
|
185
|
+
return (c, e) => test(c, e) ? consequent(c, e) : alternate(c, e);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
protected ternaryThen(): Evaluate {
|
|
189
|
+
const consequent = this.ternary();
|
|
190
|
+
this.expect(':');
|
|
191
|
+
return consequent;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Operators of `minPrecedence` or more, left to right. */
|
|
195
|
+
protected binary(minPrecedence: number): Evaluate {
|
|
196
|
+
let left = this.unary();
|
|
197
|
+
for (;;) {
|
|
198
|
+
const token = this.peek();
|
|
199
|
+
const precedence = token.type === 'operator' ? PRECEDENCE[token.value] : undefined;
|
|
200
|
+
if (precedence === undefined || precedence < minPrecedence) {
|
|
201
|
+
return left;
|
|
202
|
+
}
|
|
203
|
+
this.index++;
|
|
204
|
+
const l = left;
|
|
205
|
+
const r = this.binary(precedence + 1);
|
|
206
|
+
if (token.value === '&&') {
|
|
207
|
+
left = (c, e) => l(c, e) && r(c, e);
|
|
208
|
+
} else if (token.value === '||') {
|
|
209
|
+
left = (c, e) => l(c, e) || r(c, e);
|
|
210
|
+
} else {
|
|
211
|
+
const apply = BINARY[token.value];
|
|
212
|
+
left = (c, e) => apply(l(c, e), r(c, e));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
protected unary(): Evaluate {
|
|
218
|
+
const token = this.peek();
|
|
219
|
+
if (token.type === 'operator' && (token.value === '!' || token.value === '-')) {
|
|
220
|
+
this.index++;
|
|
221
|
+
const operand = this.unary();
|
|
222
|
+
if (token.value === '!') {
|
|
223
|
+
return (c, e) => !operand(c, e);
|
|
224
|
+
}
|
|
225
|
+
return (c, e) => -operand(c, e);
|
|
226
|
+
}
|
|
227
|
+
return this.postfix(this.primary());
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
protected primary(): Evaluate {
|
|
231
|
+
const token = this.next();
|
|
232
|
+
switch (token.type) {
|
|
233
|
+
case 'number':
|
|
234
|
+
case 'string':
|
|
235
|
+
case 'boolean': {
|
|
236
|
+
const value = token.value;
|
|
237
|
+
return () => value;
|
|
238
|
+
}
|
|
239
|
+
case 'identifier': {
|
|
240
|
+
const name: string = token.value;
|
|
241
|
+
if (this.accept('(')) {
|
|
242
|
+
const args = this.list(')');
|
|
243
|
+
const { engine, source } = this;
|
|
244
|
+
return (c, e) => engine.call('function', name, args.map(arg => arg(c, e)), source);
|
|
245
|
+
}
|
|
246
|
+
return c => c?.[name];
|
|
247
|
+
}
|
|
248
|
+
case 'punctuation':
|
|
249
|
+
switch (token.value) {
|
|
250
|
+
case '.': {
|
|
251
|
+
const name = this.identifier();
|
|
252
|
+
this.relative = true;
|
|
253
|
+
return (c, e) => e?.[name];
|
|
254
|
+
}
|
|
255
|
+
case '(': {
|
|
256
|
+
const inner = this.ternary();
|
|
257
|
+
this.expect(')');
|
|
258
|
+
return inner;
|
|
259
|
+
}
|
|
260
|
+
case '[': {
|
|
261
|
+
const items = this.list(']');
|
|
262
|
+
return (c, e) => items.map(item => item(c, e));
|
|
263
|
+
}
|
|
264
|
+
case '{':
|
|
265
|
+
return this.object();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
this.index--;
|
|
269
|
+
throw this.unexpected();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
protected object(): Evaluate {
|
|
273
|
+
const entries: [string, Evaluate][] = [];
|
|
274
|
+
while (!this.accept('}')) {
|
|
275
|
+
const key = this.next();
|
|
276
|
+
if (key.type !== 'identifier' && key.type !== 'string') {
|
|
277
|
+
this.index--;
|
|
278
|
+
throw this.unexpected('a key');
|
|
279
|
+
}
|
|
280
|
+
this.expect(':');
|
|
281
|
+
entries.push([key.value, this.ternary()]);
|
|
282
|
+
if (!this.accept(',')) {
|
|
283
|
+
this.expect('}');
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return (c, e) => {
|
|
288
|
+
const result: Record<string, any> = {};
|
|
289
|
+
for (const [key, value] of entries) {
|
|
290
|
+
result[key] = value(c, e);
|
|
291
|
+
}
|
|
292
|
+
return result;
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** `.name`, `[filter]` and `|transform(args)` after an operand. */
|
|
297
|
+
protected postfix(subject: Evaluate): Evaluate {
|
|
298
|
+
for (;;) {
|
|
299
|
+
if (this.accept('.')) {
|
|
300
|
+
const name = this.identifier();
|
|
301
|
+
const from = subject;
|
|
302
|
+
subject = (c, e) => {
|
|
303
|
+
let value = from(c, e);
|
|
304
|
+
if (value === undefined || value === null) {
|
|
305
|
+
return undefined;
|
|
306
|
+
}
|
|
307
|
+
if (Array.isArray(value)) {
|
|
308
|
+
value = value[0];
|
|
309
|
+
}
|
|
310
|
+
return value?.[name];
|
|
311
|
+
};
|
|
312
|
+
} else if (this.accept('[')) {
|
|
313
|
+
subject = this.filter(subject);
|
|
314
|
+
} else if (this.accept('|')) {
|
|
315
|
+
const name = this.identifier();
|
|
316
|
+
const args = this.accept('(') ? this.list(')') : [];
|
|
317
|
+
const { engine, source } = this;
|
|
318
|
+
const from = subject;
|
|
319
|
+
subject = (c, e) => engine.call('transform', name, [from(c, e), ...args.map(arg => arg(c, e))], source);
|
|
320
|
+
} else {
|
|
321
|
+
return subject;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* `subject[.x > 1]` keeps the elements the filter is true for; any other `subject[key]` is a property
|
|
328
|
+
* (the subject itself or nothing when the key is a boolean).
|
|
329
|
+
*/
|
|
330
|
+
protected filter(subject: Evaluate): Evaluate {
|
|
331
|
+
const outer = this.relative;
|
|
332
|
+
this.relative = false;
|
|
333
|
+
const expression = this.ternary();
|
|
334
|
+
const relative = this.relative;
|
|
335
|
+
this.relative = outer;
|
|
336
|
+
this.expect(']');
|
|
337
|
+
if (relative) {
|
|
338
|
+
return (c, e) => {
|
|
339
|
+
const value = subject(c, e);
|
|
340
|
+
const elements = Array.isArray(value) ? value : value === undefined ? [] : [value];
|
|
341
|
+
return elements.filter(element => expression(c, element));
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
return (c, e) => {
|
|
345
|
+
const value = subject(c, e);
|
|
346
|
+
const key = expression(c, e);
|
|
347
|
+
if (typeof key === 'boolean') {
|
|
348
|
+
return key ? value : undefined;
|
|
349
|
+
}
|
|
350
|
+
return value === undefined || value === null ? undefined : value[key];
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** Comma separated expressions up to `close`; empty items are skipped, like jexl did. */
|
|
355
|
+
protected list(close: string): Evaluate[] {
|
|
356
|
+
const items: Evaluate[] = [];
|
|
357
|
+
while (!this.accept(close)) {
|
|
358
|
+
if (this.accept(',')) {
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
items.push(this.ternary());
|
|
362
|
+
if (!this.accept(',')) {
|
|
363
|
+
this.expect(close);
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return items;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
protected identifier(): string {
|
|
371
|
+
const token = this.next();
|
|
372
|
+
if (token.type !== 'identifier') {
|
|
373
|
+
this.index--;
|
|
374
|
+
throw this.unexpected('a name');
|
|
375
|
+
}
|
|
376
|
+
return token.value;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
protected peek(): Token {
|
|
380
|
+
return this.tokens[this.index];
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
protected next(): Token {
|
|
384
|
+
const token = this.tokens[this.index];
|
|
385
|
+
if (token.type !== 'end') {
|
|
386
|
+
this.index++;
|
|
387
|
+
}
|
|
388
|
+
return token;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
protected accept(punctuation: string): boolean {
|
|
392
|
+
const token = this.tokens[this.index];
|
|
393
|
+
if (token.type === 'punctuation' && token.value === punctuation) {
|
|
394
|
+
this.index++;
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
protected expect(punctuation: string): void {
|
|
401
|
+
if (!this.accept(punctuation)) {
|
|
402
|
+
throw this.unexpected(`'${punctuation}'`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
protected unexpected(expected?: string): ExpressionSyntaxError {
|
|
407
|
+
const token = this.peek();
|
|
408
|
+
const found = token.type === 'end' ? 'end of expression' : `'${this.source.slice(token.start, this.tokens[this.index + 1]?.start ?? this.source.length).trim()}'`;
|
|
409
|
+
return this.syntaxError(token.start, `Unexpected ${found}${expected ? `, expected ${expected}` : ''}`);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
protected syntaxError(position: number, message: string): ExpressionSyntaxError {
|
|
413
|
+
return new ExpressionSyntaxError({
|
|
414
|
+
code: 'CELL_EL_SYNTAX',
|
|
415
|
+
message: `${message} at position ${position} of: ${this.source}`,
|
|
416
|
+
hint: 'Check quotes, brackets and operators; expressions are names, literals, operators, value|transform and function() calls.',
|
|
417
|
+
expression: this.source,
|
|
418
|
+
position
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
protected tokenize(): Token[] {
|
|
423
|
+
const source = this.source;
|
|
424
|
+
const tokens: Token[] = [];
|
|
425
|
+
const isDigit = (c: string | undefined) => c !== undefined && c >= '0' && c <= '9';
|
|
426
|
+
let i = 0;
|
|
427
|
+
while (i < source.length) {
|
|
428
|
+
const c = source[i];
|
|
429
|
+
const start = i;
|
|
430
|
+
if (/\s/.test(c)) {
|
|
431
|
+
i++;
|
|
432
|
+
} else if (c === '\'' || c === '"') {
|
|
433
|
+
// Only \<quote> and \\ are escapes; any other backslash is kept (\d stays \d).
|
|
434
|
+
let value = '';
|
|
435
|
+
i++;
|
|
436
|
+
while (i < source.length && source[i] !== c) {
|
|
437
|
+
if (source[i] === '\\' && i + 1 < source.length) {
|
|
438
|
+
const next = source[i + 1];
|
|
439
|
+
value += next === c || next === '\\' ? next : '\\' + next;
|
|
440
|
+
i += 2;
|
|
441
|
+
} else {
|
|
442
|
+
value += source[i++];
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (i >= source.length) {
|
|
446
|
+
throw this.syntaxError(start, 'Unterminated string');
|
|
447
|
+
}
|
|
448
|
+
i++;
|
|
449
|
+
tokens.push({ type: 'string', value, start });
|
|
450
|
+
} else if (isDigit(c)) {
|
|
451
|
+
while (isDigit(source[i])) {
|
|
452
|
+
i++;
|
|
453
|
+
}
|
|
454
|
+
if (source[i] === '.' && isDigit(source[i + 1])) {
|
|
455
|
+
i++;
|
|
456
|
+
while (isDigit(source[i])) {
|
|
457
|
+
i++;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
tokens.push({ type: 'number', value: parseFloat(source.slice(start, i)), start });
|
|
461
|
+
} else if (IDENTIFIER_START.test(c)) {
|
|
462
|
+
while (i < source.length && IDENTIFIER_PART.test(source[i])) {
|
|
463
|
+
i++;
|
|
464
|
+
}
|
|
465
|
+
const word = source.slice(start, i);
|
|
466
|
+
if (word === 'true' || word === 'false') {
|
|
467
|
+
tokens.push({ type: 'boolean', value: word === 'true', start });
|
|
468
|
+
} else {
|
|
469
|
+
tokens.push({ type: word === 'in' ? 'operator' : 'identifier', value: word, start });
|
|
470
|
+
}
|
|
471
|
+
} else {
|
|
472
|
+
const operator = OPERATORS.find(op => source.startsWith(op, i));
|
|
473
|
+
if (operator) {
|
|
474
|
+
tokens.push({ type: 'operator', value: operator, start });
|
|
475
|
+
i += operator.length;
|
|
476
|
+
} else if (PUNCTUATION.includes(c)) {
|
|
477
|
+
tokens.push({ type: 'punctuation', value: c, start });
|
|
478
|
+
i++;
|
|
479
|
+
} else {
|
|
480
|
+
throw this.syntaxError(start, `Unexpected character '${c}'`);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
tokens.push({ type: 'end', value: undefined, start: source.length });
|
|
485
|
+
return tokens;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { describe, it } from 'bun:test';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { ExpressionCompilerImpl } from './expression-compiler';
|
|
4
|
+
import { ExpressionHandlerImpl } from './expression-handler';
|
|
5
|
+
import { ExpressionEngine } from './expression-engine';
|
|
6
|
+
|
|
7
|
+
function handler(configuration?: Record<string, unknown>): ExpressionHandlerImpl {
|
|
8
|
+
const engine = new ExpressionEngine();
|
|
9
|
+
const compiler = new ExpressionCompilerImpl();
|
|
10
|
+
Object.defineProperty(compiler, 'engine', { value: engine });
|
|
11
|
+
const instance = new ExpressionHandlerImpl();
|
|
12
|
+
Object.defineProperty(instance, 'expressionCompiler', { value: compiler });
|
|
13
|
+
Object.defineProperty(instance, 'expressionContextProvider', { value: { provide: () => configuration } });
|
|
14
|
+
return instance;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('ExpressionHandler', () => {
|
|
18
|
+
it('evaluates every string of nested objects and arrays in place', () => {
|
|
19
|
+
const ctx = { a: { b: 2 }, name: 'cell' };
|
|
20
|
+
const target = { x: '${a.b + 1}', list: ['${name}', 'plain', 7, { deep: 'hi ${name}' }], n: 1, t: true, nil: null };
|
|
21
|
+
const result = handler().handle(target, ctx);
|
|
22
|
+
expect(result).to.equal(target);
|
|
23
|
+
expect(target).to.deep.equal({ x: 3, list: ['cell', 'plain', 7, { deep: 'hi cell' }], n: 1, t: true, nil: null });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('leaves objects marked _ignoreEl alone', () => {
|
|
27
|
+
const ignored = { _ignoreEl: true, value: '${name}' };
|
|
28
|
+
const target = { ignored, other: '${name}' };
|
|
29
|
+
handler().handle(target, { name: 'cell' });
|
|
30
|
+
expect(target.ignored).to.equal(ignored);
|
|
31
|
+
expect(ignored.value).to.equal('${name}');
|
|
32
|
+
expect(target.other).to.equal('cell');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('does not walk into an object an expression evaluates to: values are not templates', () => {
|
|
36
|
+
const ctx = { obj: { greeting: 'hi ${name}' }, name: 'cell' };
|
|
37
|
+
const target = { value: '${obj}' };
|
|
38
|
+
handler().handle(target, ctx);
|
|
39
|
+
expect(target.value).to.deep.equal({ greeting: 'hi ${name}' });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('stops at circular references', () => {
|
|
43
|
+
const target: Record<string, unknown> = { name: '${n}' };
|
|
44
|
+
target.self = target;
|
|
45
|
+
target.list = [target];
|
|
46
|
+
handler().handle(target, { n: 'cell' });
|
|
47
|
+
expect(target.name).to.equal('cell');
|
|
48
|
+
expect(target.self).to.equal(target);
|
|
49
|
+
expect((target.list as unknown[])[0]).to.equal(target);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('does not assign unchanged values (frozen objects without expressions are fine)', () => {
|
|
53
|
+
const frozen = Object.freeze({ a: 1, b: 'text', c: Object.freeze([1, 2]) });
|
|
54
|
+
const target = { frozen, x: '${n}' };
|
|
55
|
+
handler().handle(target, { n: 2 });
|
|
56
|
+
expect(target.x).to.equal(2);
|
|
57
|
+
expect(target.frozen).to.equal(frozen);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('F6: values are text, not expressions', () => {
|
|
61
|
+
const secret = 'S3CRET';
|
|
62
|
+
const env = (x: string) => ({ X: x, _ignoreEl: true });
|
|
63
|
+
|
|
64
|
+
it('a value from the environment is not evaluated', () => {
|
|
65
|
+
const configuration = { cell: { secret, a: '${env.X}' }, env: env('${cell.secret}') };
|
|
66
|
+
expect(handler(configuration).handle('${cell.a}')).to.equal('${cell.secret}');
|
|
67
|
+
expect(configuration.cell.a).to.equal('${cell.secret}');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('nor through another key, in either order', () => {
|
|
71
|
+
const configuration = { cell: { b: '${cell.a}', secret, a: '${env.X}', c: 'x-${cell.a}' }, env: env('${cell.secret}') };
|
|
72
|
+
const h = handler(configuration);
|
|
73
|
+
expect(h.handle('${cell.b}')).to.equal('${cell.secret}');
|
|
74
|
+
expect(h.handle('${cell.c}')).to.equal('x-${cell.secret}');
|
|
75
|
+
expect(configuration.cell.c).to.equal('x-${cell.secret}');
|
|
76
|
+
expect(configuration.cell.b).to.equal('${cell.secret}');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('nor when it is part of a longer text', () => {
|
|
80
|
+
const configuration = { cell: { secret, url: 'http://${env.X}/path' }, env: env('${cell.secret}') };
|
|
81
|
+
expect(handler(configuration).handle('${cell.url}')).to.equal('http://${cell.secret}/path');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('a template variable is not evaluated either (prompt templates)', () => {
|
|
85
|
+
const text = handler().handle('hi {name}', { name: '{secret}', secret: 'S' }, { ignoreSpecialChar: true, bracketBegin: '{', bracketEnd: '}', ignoreContextExpression: true });
|
|
86
|
+
expect(text).to.equal('hi {secret}');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('keys still refer to each other in any order, through any depth', () => {
|
|
90
|
+
const configuration = { cell: { x: '${cell.y}-x', y: '${cell.deep.z}', deep: { z: 'z', n: '${cell.port * 2}' }, port: 21 } };
|
|
91
|
+
const h = handler(configuration);
|
|
92
|
+
expect(h.handle('${cell.x}')).to.equal('z-x');
|
|
93
|
+
expect(h.handle('${cell.deep.n}')).to.equal(42);
|
|
94
|
+
expect(configuration.cell.y).to.equal('z');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('a circular reference fails with the keys involved', () => {
|
|
98
|
+
const configuration = { cell: { a: '${cell.b}', b: '${cell.a}' } };
|
|
99
|
+
expect(() => handler(configuration).handle('${cell.a}')).to.throw('Circular reference in the configuration: cell.a -> cell.b -> cell.a');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('evaluating a value is still possible on purpose, with the eval transform', () => {
|
|
103
|
+
const instance = handler({ cell: { secret, a: '${env.X | eval}' }, env: env('${cell.secret}') });
|
|
104
|
+
const engine = (instance as unknown as { expressionCompiler: { engine: ExpressionEngine } }).expressionCompiler.engine;
|
|
105
|
+
engine.addTransform('eval', (text: string) => instance.handle(text));
|
|
106
|
+
expect(instance.handle('${cell.a}')).to.equal(secret);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|