@venok/core 1.0.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/application/config.d.ts +35 -0
- package/application/config.js +85 -0
- package/application/context.d.ts +198 -0
- package/application/context.js +325 -0
- package/application/factory.d.ts +43 -0
- package/application/factory.js +147 -0
- package/constants.d.ts +46 -0
- package/constants.js +53 -0
- package/context/creator.d.ts +9 -0
- package/context/creator.js +32 -0
- package/context/execution-host.d.ts +16 -0
- package/context/execution-host.js +30 -0
- package/context/external/creator.d.ts +63 -0
- package/context/external/creator.js +159 -0
- package/context/external/proxy.d.ts +5 -0
- package/context/external/proxy.js +19 -0
- package/decorators/apply.decorator.d.ts +10 -0
- package/decorators/apply.decorator.js +24 -0
- package/decorators/bind.decorator.d.ts +11 -0
- package/decorators/bind.decorator.js +20 -0
- package/decorators/catch.decorator.d.ts +17 -0
- package/decorators/catch.decorator.js +26 -0
- package/decorators/create-param.decorator.d.ts +29 -0
- package/decorators/create-param.decorator.js +51 -0
- package/decorators/dependencies.decorator.d.ts +6 -0
- package/decorators/dependencies.decorator.js +17 -0
- package/decorators/exception-filters.decorator.d.ts +21 -0
- package/decorators/exception-filters.decorator.js +41 -0
- package/decorators/global.decorator.d.ts +10 -0
- package/decorators/global.decorator.js +19 -0
- package/decorators/index.d.ts +15 -0
- package/decorators/index.js +31 -0
- package/decorators/inject.decorator.d.ts +26 -0
- package/decorators/inject.decorator.js +45 -0
- package/decorators/injectable.decorator.d.ts +40 -0
- package/decorators/injectable.decorator.js +51 -0
- package/decorators/module.decorator.d.ts +14 -0
- package/decorators/module.decorator.js +38 -0
- package/decorators/optional.decorator.d.ts +14 -0
- package/decorators/optional.decorator.js +30 -0
- package/decorators/set-metadata.decorator.d.ts +18 -0
- package/decorators/set-metadata.decorator.js +30 -0
- package/decorators/use-guards.decorator.d.ts +21 -0
- package/decorators/use-guards.decorator.js +40 -0
- package/decorators/use-interceptors.decorator.d.ts +21 -0
- package/decorators/use-interceptors.decorator.js +40 -0
- package/decorators/use-pipes.decorator.d.ts +21 -0
- package/decorators/use-pipes.decorator.js +39 -0
- package/discovery/meta-host-collection.d.ts +32 -0
- package/discovery/meta-host-collection.js +79 -0
- package/discovery/module.d.ts +5 -0
- package/discovery/module.js +24 -0
- package/discovery/service.d.ts +68 -0
- package/discovery/service.js +90 -0
- package/errors/exceptions/circular-dependency.exception.d.ts +4 -0
- package/errors/exceptions/circular-dependency.exception.js +11 -0
- package/errors/exceptions/index.d.ts +8 -0
- package/errors/exceptions/index.js +24 -0
- package/errors/exceptions/invalid-class-module.exception.d.ts +4 -0
- package/errors/exceptions/invalid-class-module.exception.js +11 -0
- package/errors/exceptions/invalid-class-scope.exception.d.ts +5 -0
- package/errors/exceptions/invalid-class-scope.exception.js +14 -0
- package/errors/exceptions/invalid-class.exception.d.ts +4 -0
- package/errors/exceptions/invalid-class.exception.js +11 -0
- package/errors/exceptions/invalid-exception-filter.exception.d.ts +4 -0
- package/errors/exceptions/invalid-exception-filter.exception.js +11 -0
- package/errors/exceptions/invalid-module.exception.d.ts +4 -0
- package/errors/exceptions/invalid-module.exception.js +11 -0
- package/errors/exceptions/runtime.exception.d.ts +4 -0
- package/errors/exceptions/runtime.exception.js +12 -0
- package/errors/exceptions/undefined-dependency.exception.d.ts +6 -0
- package/errors/exceptions/undefined-dependency.exception.js +11 -0
- package/errors/exceptions/undefined-forwardref.exception.d.ts +5 -0
- package/errors/exceptions/undefined-forwardref.exception.js +11 -0
- package/errors/exceptions/undefined-module.exception.d.ts +4 -0
- package/errors/exceptions/undefined-module.exception.js +11 -0
- package/errors/exceptions/unknown-dependencies.exception.d.ts +16 -0
- package/errors/exceptions/unknown-dependencies.exception.js +15 -0
- package/errors/exceptions/unknown-element.exception.d.ts +4 -0
- package/errors/exceptions/unknown-element.exception.js +12 -0
- package/errors/exceptions/unknown-export.exception.d.ts +4 -0
- package/errors/exceptions/unknown-export.exception.js +11 -0
- package/errors/exceptions/unknown-module.exception.d.ts +4 -0
- package/errors/exceptions/unknown-module.exception.js +10 -0
- package/errors/messages.d.ts +15 -0
- package/errors/messages.js +126 -0
- package/exceptions/external/filter-context.d.ts +10 -0
- package/exceptions/external/filter-context.js +37 -0
- package/exceptions/external/filter.d.ts +5 -0
- package/exceptions/external/filter.js +16 -0
- package/exceptions/external/handler.d.ts +9 -0
- package/exceptions/external/handler.js +31 -0
- package/exceptions/filter-context.d.ts +14 -0
- package/exceptions/filter-context.js +55 -0
- package/exceptions/select-exception-filter-metadata.d.ts +2 -0
- package/exceptions/select-exception-filter-metadata.js +6 -0
- package/exceptions/zone/handler.d.ts +5 -0
- package/exceptions/zone/handler.js +15 -0
- package/exceptions/zone/zone.d.ts +5 -0
- package/exceptions/zone/zone.js +32 -0
- package/guards/consumer.d.ts +9 -0
- package/guards/consumer.js +33 -0
- package/guards/context-creator.d.ts +17 -0
- package/guards/context-creator.js +69 -0
- package/guards/index.d.ts +2 -0
- package/guards/index.js +18 -0
- package/helpers/color.helper.d.ts +9 -0
- package/helpers/color.helper.js +14 -0
- package/helpers/context-id-factory.helper.d.ts +2 -0
- package/helpers/context-id-factory.helper.js +15 -0
- package/helpers/context.helper.d.ts +23 -0
- package/helpers/context.helper.js +49 -0
- package/helpers/extends-metadata.helper.d.ts +1 -0
- package/helpers/extends-metadata.helper.js +9 -0
- package/helpers/flatten.helper.d.ts +1 -0
- package/helpers/flatten.helper.js +9 -0
- package/helpers/messages.helper.d.ts +2 -0
- package/helpers/messages.helper.js +7 -0
- package/helpers/noop.helper.d.ts +1 -0
- package/helpers/noop.helper.js +5 -0
- package/helpers/random-string-generator.helper.d.ts +1 -0
- package/helpers/random-string-generator.helper.js +6 -0
- package/helpers/rethrow.helper.d.ts +1 -0
- package/helpers/rethrow.helper.js +7 -0
- package/helpers/shared.helper.d.ts +10 -0
- package/helpers/shared.helper.js +33 -0
- package/helpers/silent.helper.d.ts +10 -0
- package/helpers/silent.helper.js +18 -0
- package/helpers/transient.helper.d.ts +12 -0
- package/helpers/transient.helper.js +26 -0
- package/helpers/uuid.helper.d.ts +15 -0
- package/helpers/uuid.helper.js +54 -0
- package/helpers/validate-each.helper.d.ts +8 -0
- package/helpers/validate-each.helper.js +25 -0
- package/hooks/before-app-shutdown.hook.d.ts +9 -0
- package/hooks/before-app-shutdown.hook.js +45 -0
- package/hooks/index.d.ts +5 -0
- package/hooks/index.js +21 -0
- package/hooks/on-app-bootstrap.hook.d.ts +8 -0
- package/hooks/on-app-bootstrap.hook.js +45 -0
- package/hooks/on-app-shutdown.hook.d.ts +9 -0
- package/hooks/on-app-shutdown.hook.js +46 -0
- package/hooks/on-module-destroy.hook.d.ts +8 -0
- package/hooks/on-module-destroy.hook.js +45 -0
- package/hooks/on-module-init.hook.d.ts +8 -0
- package/hooks/on-module-init.hook.js +45 -0
- package/index.d.ts +10 -0
- package/index.js +32 -0
- package/injector/constants.d.ts +2 -0
- package/injector/constants.js +7 -0
- package/injector/container.d.ts +61 -0
- package/injector/container.js +194 -0
- package/injector/helpers/class-scope.helper.d.ts +2 -0
- package/injector/helpers/class-scope.helper.js +9 -0
- package/injector/helpers/classifier.helper.d.ts +4 -0
- package/injector/helpers/classifier.helper.js +17 -0
- package/injector/helpers/is-durable.helper.d.ts +2 -0
- package/injector/helpers/is-durable.helper.js +9 -0
- package/injector/index.d.ts +5 -0
- package/injector/index.js +20 -0
- package/injector/injector.d.ts +87 -0
- package/injector/injector.js +452 -0
- package/injector/instance/links-host.d.ts +22 -0
- package/injector/instance/links-host.js +50 -0
- package/injector/instance/loader.d.ts +21 -0
- package/injector/instance/loader.js +73 -0
- package/injector/instance/resolver.d.ts +16 -0
- package/injector/instance/resolver.js +43 -0
- package/injector/instance/wrapper.d.ts +90 -0
- package/injector/instance/wrapper.js +272 -0
- package/injector/internal-core-module/core-providers.d.ts +4 -0
- package/injector/internal-core-module/core-providers.js +21 -0
- package/injector/internal-core-module/internal-core-module-factory.d.ts +8 -0
- package/injector/internal-core-module/internal-core-module-factory.js +42 -0
- package/injector/internal-core-module/internal-core-module.d.ts +4 -0
- package/injector/internal-core-module/internal-core-module.js +31 -0
- package/injector/module/compiler.d.ts +19 -0
- package/injector/module/compiler.js +27 -0
- package/injector/module/container.d.ts +6 -0
- package/injector/module/container.js +24 -0
- package/injector/module/lazy/loader.d.ts +21 -0
- package/injector/module/lazy/loader.js +49 -0
- package/injector/module/lazy/options.d.ts +6 -0
- package/injector/module/lazy/options.js +2 -0
- package/injector/module/module.d.ts +74 -0
- package/injector/module/module.js +383 -0
- package/injector/module/ref.d.ts +106 -0
- package/injector/module/ref.js +62 -0
- package/injector/module/token-factory.d.ts +13 -0
- package/injector/module/token-factory.js +71 -0
- package/injector/settlement-signal.d.ts +37 -0
- package/injector/settlement-signal.js +55 -0
- package/inspector/graph-inspector.d.ts +26 -0
- package/inspector/graph-inspector.js +163 -0
- package/inspector/initialize-on-preview.allowlist.d.ts +6 -0
- package/inspector/initialize-on-preview.allowlist.js +13 -0
- package/inspector/interfaces/edge.interface.d.ts +28 -0
- package/inspector/interfaces/edge.interface.js +2 -0
- package/inspector/interfaces/enhancer-metadata-cache-entry.interface.d.ts +12 -0
- package/inspector/interfaces/enhancer-metadata-cache-entry.interface.js +2 -0
- package/inspector/interfaces/entrypoint.interface.d.ts +10 -0
- package/inspector/interfaces/entrypoint.interface.js +2 -0
- package/inspector/interfaces/extras.interface.d.ts +18 -0
- package/inspector/interfaces/extras.interface.js +2 -0
- package/inspector/interfaces/node.interface.d.ts +49 -0
- package/inspector/interfaces/node.interface.js +2 -0
- package/inspector/interfaces/serialized-graph-json.interface.d.ts +14 -0
- package/inspector/interfaces/serialized-graph-json.interface.js +2 -0
- package/inspector/interfaces/serialized-graph-metadata.interface.d.ts +10 -0
- package/inspector/interfaces/serialized-graph-metadata.interface.js +2 -0
- package/inspector/noop-graph-inspector.d.ts +2 -0
- package/inspector/noop-graph-inspector.js +8 -0
- package/inspector/partial-graph.host.d.ts +7 -0
- package/inspector/partial-graph.host.js +15 -0
- package/inspector/serialized-graph.d.ts +52 -0
- package/inspector/serialized-graph.js +121 -0
- package/interceptors/consumer.d.ts +9 -0
- package/interceptors/consumer.js +37 -0
- package/interceptors/context-creator.d.ts +17 -0
- package/interceptors/context-creator.js +67 -0
- package/interceptors/index.d.ts +2 -0
- package/interceptors/index.js +18 -0
- package/interfaces/abstract.interface.d.ts +3 -0
- package/interfaces/abstract.interface.js +2 -0
- package/interfaces/application/context-options.interface.d.ts +41 -0
- package/interfaces/application/context-options.interface.js +9 -0
- package/interfaces/application/context.interface.d.ts +162 -0
- package/interfaces/application/context.interface.js +2 -0
- package/interfaces/application/index.d.ts +1 -0
- package/interfaces/application/index.js +17 -0
- package/interfaces/context/arguments-host.interface.d.ts +22 -0
- package/interfaces/context/arguments-host.interface.js +2 -0
- package/interfaces/context/execution.interface.d.ts +18 -0
- package/interfaces/context/execution.interface.js +2 -0
- package/interfaces/features/exception-filter.interface.d.ts +21 -0
- package/interfaces/features/exception-filter.interface.js +2 -0
- package/interfaces/features/guards.interface.d.ts +20 -0
- package/interfaces/features/guards.interface.js +2 -0
- package/interfaces/features/interceptor.interface.d.ts +30 -0
- package/interfaces/features/interceptor.interface.js +2 -0
- package/interfaces/features/pipes.interface.d.ts +37 -0
- package/interfaces/features/pipes.interface.js +2 -0
- package/interfaces/helper.interface.d.ts +3 -0
- package/interfaces/helper.interface.js +2 -0
- package/interfaces/hooks/before-application-shutdown.interface.d.ts +3 -0
- package/interfaces/hooks/before-application-shutdown.interface.js +2 -0
- package/interfaces/hooks/index.d.ts +5 -0
- package/interfaces/hooks/index.js +21 -0
- package/interfaces/hooks/on-application-bootstrap.interface.d.ts +9 -0
- package/interfaces/hooks/on-application-bootstrap.interface.js +2 -0
- package/interfaces/hooks/on-application-shutdown.interface.d.ts +9 -0
- package/interfaces/hooks/on-application-shutdown.interface.js +2 -0
- package/interfaces/hooks/on-destroy.interface.d.ts +10 -0
- package/interfaces/hooks/on-destroy.interface.js +2 -0
- package/interfaces/hooks/on-init.interface.d.ts +8 -0
- package/interfaces/hooks/on-init.interface.js +2 -0
- package/interfaces/index.d.ts +6 -0
- package/interfaces/index.js +22 -0
- package/interfaces/injectable.interface.d.ts +1 -0
- package/interfaces/injectable.interface.js +2 -0
- package/interfaces/modules/configurable/async-options.interface.d.ts +42 -0
- package/interfaces/modules/configurable/async-options.interface.js +2 -0
- package/interfaces/modules/configurable/cls.interface.d.ts +13 -0
- package/interfaces/modules/configurable/cls.interface.js +2 -0
- package/interfaces/modules/configurable/host.interface.d.ts +62 -0
- package/interfaces/modules/configurable/host.interface.js +2 -0
- package/interfaces/modules/configurable/index.d.ts +3 -0
- package/interfaces/modules/configurable/index.js +19 -0
- package/interfaces/modules/definition.interface.d.ts +4 -0
- package/interfaces/modules/definition.interface.js +2 -0
- package/interfaces/modules/dynamic-module.interface.d.ts +23 -0
- package/interfaces/modules/dynamic-module.interface.js +2 -0
- package/interfaces/modules/forward-reference.interface.d.ts +3 -0
- package/interfaces/modules/forward-reference.interface.js +2 -0
- package/interfaces/modules/index.d.ts +9 -0
- package/interfaces/modules/index.js +25 -0
- package/interfaces/modules/injection-token.interface.d.ts +5 -0
- package/interfaces/modules/injection-token.interface.js +2 -0
- package/interfaces/modules/introspection-result.interface.d.ts +10 -0
- package/interfaces/modules/introspection-result.interface.js +2 -0
- package/interfaces/modules/module-metadata.interface.d.ts +24 -0
- package/interfaces/modules/module-metadata.interface.js +2 -0
- package/interfaces/modules/module.interface.d.ts +2 -0
- package/interfaces/modules/module.interface.js +2 -0
- package/interfaces/modules/optional-factory-dependency.interface.d.ts +8 -0
- package/interfaces/modules/optional-factory-dependency.interface.js +2 -0
- package/interfaces/modules/override.interface.d.ts +5 -0
- package/interfaces/modules/override.interface.js +2 -0
- package/interfaces/modules/provider.interface.d.ts +142 -0
- package/interfaces/modules/provider.interface.js +2 -0
- package/interfaces/scope.interface.d.ts +35 -0
- package/interfaces/scope.interface.js +23 -0
- package/interfaces/type.interface.d.ts +3 -0
- package/interfaces/type.interface.js +2 -0
- package/metadata-scanner.d.ts +4 -0
- package/metadata-scanner.js +34 -0
- package/module/configurable-module.builder.d.ts +93 -0
- package/module/configurable-module.builder.js +204 -0
- package/module/constants.d.ts +4 -0
- package/module/constants.js +7 -0
- package/module/helpers/generate-options-injection-token.helper.d.ts +1 -0
- package/module/helpers/generate-options-injection-token.helper.js +9 -0
- package/module/helpers/get-injection-providers.helper.d.ts +8 -0
- package/module/helpers/get-injection-providers.helper.js +36 -0
- package/module/helpers/index.d.ts +2 -0
- package/module/helpers/index.js +18 -0
- package/module/index.d.ts +2 -0
- package/module/index.js +18 -0
- package/package.json +35 -0
- package/pipes/consumer.d.ts +9 -0
- package/pipes/consumer.js +15 -0
- package/pipes/context-creator.d.ts +18 -0
- package/pipes/context-creator.js +70 -0
- package/pipes/index.d.ts +2 -0
- package/pipes/index.js +18 -0
- package/scanner.d.ts +81 -0
- package/scanner.js +374 -0
- package/services/console.service.d.ts +86 -0
- package/services/console.service.js +233 -0
- package/services/index.d.ts +1 -0
- package/services/index.js +17 -0
- package/services/logger.service.d.ts +157 -0
- package/services/logger.service.js +269 -0
- package/services/reflector.service.d.ts +110 -0
- package/services/reflector.service.js +87 -0
- package/test/context/execution-host.spec.d.ts +1 -0
- package/test/context/execution-host.spec.js +31 -0
- package/test/context/external/creator.spec.d.ts +1 -0
- package/test/context/external/creator.spec.js +149 -0
- package/test/context/external/proxy.spec.d.ts +1 -0
- package/test/context/external/proxy.spec.js +45 -0
- package/test/exceptions/external/handler.spec.d.ts +1 -0
- package/test/exceptions/external/handler.spec.js +89 -0
- package/test/exceptions/filter-context.spec.d.ts +2 -0
- package/test/exceptions/filter-context.spec.js +91 -0
- package/test/exceptions/messages.spec.d.ts +0 -0
- package/test/exceptions/messages.spec.js +201 -0
- package/test/exceptions/zona/handler.spec.d.ts +1 -0
- package/test/exceptions/zona/handler.spec.js +51 -0
- package/test/exceptions/zona/zone.spec.d.ts +1 -0
- package/test/exceptions/zona/zone.spec.js +66 -0
- package/test/guards/consumer.spec.d.ts +1 -0
- package/test/guards/consumer.spec.js +47 -0
- package/test/guards/context-creator.spec.d.ts +1 -0
- package/test/guards/context-creator.spec.js +138 -0
- package/test/helpers/context-id-factory.spec.d.ts +1 -0
- package/test/helpers/context-id-factory.spec.js +9 -0
- package/test/helpers/shared.spec.d.ts +1 -0
- package/test/helpers/shared.spec.js +122 -0
- package/test/hooks/before-app-shutdown.hook.spec.d.ts +1 -0
- package/test/hooks/before-app-shutdown.hook.spec.js +44 -0
- package/test/hooks/on-app-bootstrap.hook.spec.d.ts +1 -0
- package/test/hooks/on-app-bootstrap.hook.spec.js +43 -0
- package/test/hooks/on-app-shutdown.hook.spec.d.ts +1 -0
- package/test/hooks/on-app-shutdown.hook.spec.js +43 -0
- package/test/hooks/on-module-destroy.hook.spec.d.ts +1 -0
- package/test/hooks/on-module-destroy.hook.spec.js +43 -0
- package/test/hooks/on-module-init.hook.spec.d.ts +1 -0
- package/test/hooks/on-module-init.hook.spec.js +43 -0
- package/test/injector/compiler.spec.d.ts +1 -0
- package/test/injector/compiler.spec.js +42 -0
- package/test/injector/container.spec.d.ts +1 -0
- package/test/injector/container.spec.js +203 -0
- package/test/injector/helpers/classifier.spec.d.ts +1 -0
- package/test/injector/helpers/classifier.spec.js +102 -0
- package/test/injector/injector.spec.d.ts +1 -0
- package/test/injector/injector.spec.js +678 -0
- package/test/injector/instance/loader.spec.d.ts +1 -0
- package/test/injector/instance/loader.spec.js +108 -0
- package/test/injector/instance/wrapper.spec.d.ts +1 -0
- package/test/injector/instance/wrapper.spec.js +772 -0
- package/test/injector/internal-core-module/internal-core-module-factory.spec.d.ts +1 -0
- package/test/injector/internal-core-module/internal-core-module-factory.spec.js +27 -0
- package/test/injector/module/lazy/loader.spec.d.ts +1 -0
- package/test/injector/module/lazy/loader.spec.js +71 -0
- package/test/injector/module/module.spec.d.ts +1 -0
- package/test/injector/module/module.spec.js +410 -0
- package/test/injector/module/token-factory.spec.d.ts +1 -0
- package/test/injector/module/token-factory.spec.js +84 -0
- package/test/interceptors/consumer.spec.d.ts +1 -0
- package/test/interceptors/consumer.spec.js +136 -0
- package/test/interceptors/context-creator.spec.d.ts +1 -0
- package/test/interceptors/context-creator.spec.js +139 -0
- package/test/metadata-scanner.spec.d.ts +1 -0
- package/test/metadata-scanner.spec.js +41 -0
- package/test/module/configurable-module.builder.spec.d.ts +1 -0
- package/test/module/configurable-module.builder.spec.js +102 -0
- package/test/module/helpers/get-injection-providers.helper.spec.d.ts +1 -0
- package/test/module/helpers/get-injection-providers.helper.spec.js +49 -0
- package/test/pipes/consumer.spec.d.ts +1 -0
- package/test/pipes/consumer.spec.js +42 -0
- package/test/pipes/context-creator.spec.d.ts +1 -0
- package/test/pipes/context-creator.spec.js +108 -0
- package/test/scanner.spec.d.ts +1 -0
- package/test/scanner.spec.js +620 -0
- package/test/services/logger.service.spec.d.ts +1 -0
- package/test/services/logger.service.spec.js +487 -0
- package/test/services/reflector.service.spec.d.ts +1 -0
- package/test/services/reflector.service.spec.js +105 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VenokFactory = exports.VenokFactoryStatic = void 0;
|
|
4
|
+
const container_1 = require("@venok/core/injector/container");
|
|
5
|
+
const config_1 = require("@venok/core/application/config");
|
|
6
|
+
const logger_service_1 = require("@venok/core/services/logger.service");
|
|
7
|
+
const context_1 = require("@venok/core/application/context");
|
|
8
|
+
const graph_inspector_1 = require("@venok/core/inspector/graph-inspector");
|
|
9
|
+
const uuid_helper_1 = require("@venok/core/helpers/uuid.helper");
|
|
10
|
+
const injector_1 = require("@venok/core/injector/injector");
|
|
11
|
+
const loader_1 = require("@venok/core/injector/instance/loader");
|
|
12
|
+
const metadata_scanner_1 = require("@venok/core/metadata-scanner");
|
|
13
|
+
const scanner_1 = require("@venok/core/scanner");
|
|
14
|
+
const zone_1 = require("@venok/core/exceptions/zone/zone");
|
|
15
|
+
const constants_1 = require("@venok/core/constants");
|
|
16
|
+
const shared_helper_1 = require("@venok/core/helpers/shared.helper");
|
|
17
|
+
const noop_graph_inspector_1 = require("@venok/core/inspector/noop-graph-inspector");
|
|
18
|
+
const rethrow_helper_1 = require("@venok/core/helpers/rethrow.helper");
|
|
19
|
+
/**
|
|
20
|
+
* @publicApi
|
|
21
|
+
*/
|
|
22
|
+
class VenokFactoryStatic {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.logger = new logger_service_1.Logger("VenokFactory", {
|
|
25
|
+
timestamp: true,
|
|
26
|
+
});
|
|
27
|
+
this.abortOnError = true;
|
|
28
|
+
this.autoFlushLogs = false;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates an instance of VenokApplicationContext.
|
|
32
|
+
*
|
|
33
|
+
* @param moduleCls Entry (root) application module class
|
|
34
|
+
* @param options Optional Venok application configuration
|
|
35
|
+
*
|
|
36
|
+
* @returns A promise that, when resolved,
|
|
37
|
+
* contains a reference to the VenokApplicationContext instance.
|
|
38
|
+
*/
|
|
39
|
+
async createApplicationContext(moduleCls, options) {
|
|
40
|
+
const applicationConfig = new config_1.ApplicationConfig();
|
|
41
|
+
const container = new container_1.VenokContainer(applicationConfig);
|
|
42
|
+
const graphInspector = this.createGraphInspector(options, container);
|
|
43
|
+
this.setAbortOnError(options);
|
|
44
|
+
this.registerLoggerConfiguration(options);
|
|
45
|
+
await this.initialize(moduleCls, container, graphInspector, applicationConfig, options);
|
|
46
|
+
const modules = container.getModules().values();
|
|
47
|
+
const root = modules.next().value;
|
|
48
|
+
const context = this.createVenokInstance(new context_1.ApplicationContext(container, applicationConfig, options, root));
|
|
49
|
+
if (this.autoFlushLogs) {
|
|
50
|
+
context.flushLogsOnOverride();
|
|
51
|
+
}
|
|
52
|
+
// return context.init();
|
|
53
|
+
return context;
|
|
54
|
+
}
|
|
55
|
+
createVenokInstance(instance) {
|
|
56
|
+
return this.createProxy(instance);
|
|
57
|
+
}
|
|
58
|
+
setAbortOnError(options) {
|
|
59
|
+
this.abortOnError = !(options && options.abortOnError === false);
|
|
60
|
+
}
|
|
61
|
+
async initialize(module, container, graphInspector, config = new config_1.ApplicationConfig(), options = {}) {
|
|
62
|
+
uuid_helper_1.UuidFactory.mode = options.snapshot ? uuid_helper_1.UuidFactoryMode.Deterministic : uuid_helper_1.UuidFactoryMode.Random;
|
|
63
|
+
const injector = new injector_1.Injector({ preview: options.preview });
|
|
64
|
+
const instanceLoader = new loader_1.InstanceLoader(container, injector, graphInspector);
|
|
65
|
+
const metadataScanner = new metadata_scanner_1.MetadataScanner();
|
|
66
|
+
const dependenciesScanner = new scanner_1.DependenciesScanner(container, metadataScanner, graphInspector, config);
|
|
67
|
+
// Maybe Error
|
|
68
|
+
const teardown = !this.abortOnError ? rethrow_helper_1.rethrow : undefined;
|
|
69
|
+
try {
|
|
70
|
+
this.logger.log(constants_1.MESSAGES.APPLICATION_START);
|
|
71
|
+
await zone_1.ExceptionsZone.asyncRun(async () => {
|
|
72
|
+
await dependenciesScanner.scan(module);
|
|
73
|
+
await instanceLoader.createInstancesOfDependencies();
|
|
74
|
+
dependenciesScanner.applyApplicationProviders();
|
|
75
|
+
}, teardown, this.autoFlushLogs);
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
this.handleInitializationError(e);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
handleInitializationError(err) {
|
|
82
|
+
if (this.abortOnError) {
|
|
83
|
+
process.abort();
|
|
84
|
+
}
|
|
85
|
+
(0, rethrow_helper_1.rethrow)(err);
|
|
86
|
+
}
|
|
87
|
+
createProxy(target) {
|
|
88
|
+
const proxy = this.createExceptionProxy();
|
|
89
|
+
return new Proxy(target, {
|
|
90
|
+
get: proxy,
|
|
91
|
+
set: proxy,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
createExceptionProxy() {
|
|
95
|
+
return (receiver, prop) => {
|
|
96
|
+
if (!(prop in receiver)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if ((0, shared_helper_1.isFunction)(receiver[prop])) {
|
|
100
|
+
return this.createExceptionZone(receiver, prop);
|
|
101
|
+
}
|
|
102
|
+
return receiver[prop];
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
createExceptionZone(receiver, prop) {
|
|
106
|
+
// Maybe Error
|
|
107
|
+
const teardown = !this.abortOnError ? rethrow_helper_1.rethrow : undefined;
|
|
108
|
+
return (...args) => {
|
|
109
|
+
let result;
|
|
110
|
+
zone_1.ExceptionsZone.run(() => {
|
|
111
|
+
result = receiver[prop](...args);
|
|
112
|
+
}, teardown);
|
|
113
|
+
return result;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
registerLoggerConfiguration(options) {
|
|
117
|
+
if (!options) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const { logger, bufferLogs, autoFlushLogs } = options;
|
|
121
|
+
if (!!logger && !(0, shared_helper_1.isNull)(logger)) {
|
|
122
|
+
logger_service_1.Logger.overrideLogger(logger);
|
|
123
|
+
}
|
|
124
|
+
if (bufferLogs) {
|
|
125
|
+
logger_service_1.Logger.attachBuffer();
|
|
126
|
+
}
|
|
127
|
+
this.autoFlushLogs = autoFlushLogs ?? true;
|
|
128
|
+
}
|
|
129
|
+
createGraphInspector(appOptions, container) {
|
|
130
|
+
return appOptions?.snapshot ? new graph_inspector_1.GraphInspector(container) : noop_graph_inspector_1.NoopGraphInspector;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.VenokFactoryStatic = VenokFactoryStatic;
|
|
134
|
+
/**
|
|
135
|
+
* Use VenokFactory to create an application instance.
|
|
136
|
+
*
|
|
137
|
+
* ### Specifying an entry module
|
|
138
|
+
*
|
|
139
|
+
* Pass the required *root module* for the application via the module parameter.
|
|
140
|
+
* By convention, it is usually called `ApplicationModule`. Starting with this
|
|
141
|
+
* module, Venok assembles the dependency graph and begins the process of
|
|
142
|
+
* Dependency Injection and instantiates the classes needed to launch your
|
|
143
|
+
* application.
|
|
144
|
+
*
|
|
145
|
+
* @publicApi
|
|
146
|
+
*/
|
|
147
|
+
exports.VenokFactory = new VenokFactoryStatic();
|
package/constants.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare const MESSAGES: {
|
|
2
|
+
APPLICATION_START: string;
|
|
3
|
+
APPLICATION_READY: string;
|
|
4
|
+
UNKNOWN_EXCEPTION_MESSAGE: string;
|
|
5
|
+
ERROR_DURING_SHUTDOWN: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const FORBIDDEN_MESSAGE = "Forbidden resource";
|
|
8
|
+
export declare const MODULE_METADATA: {
|
|
9
|
+
IMPORTS: string;
|
|
10
|
+
PROVIDERS: string;
|
|
11
|
+
EXPORTS: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const PIPES_METADATA = "__pipes__";
|
|
14
|
+
export declare const GUARDS_METADATA = "__guards__";
|
|
15
|
+
export declare const INTERCEPTORS_METADATA = "__interceptors__";
|
|
16
|
+
export declare const EXCEPTION_FILTERS_METADATA = "__exceptionFilters__";
|
|
17
|
+
export declare const ENHANCER_KEY_TO_SUBTYPE_MAP: {
|
|
18
|
+
readonly __guards__: "guard";
|
|
19
|
+
readonly __interceptors__: "interceptor";
|
|
20
|
+
readonly __pipes__: "pipe";
|
|
21
|
+
readonly __exceptionFilters__: "filter";
|
|
22
|
+
};
|
|
23
|
+
export type EnhancerSubtype = (typeof ENHANCER_KEY_TO_SUBTYPE_MAP)[keyof typeof ENHANCER_KEY_TO_SUBTYPE_MAP];
|
|
24
|
+
export declare const APP_INTERCEPTOR = "APP_INTERCEPTOR";
|
|
25
|
+
export declare const APP_PIPE = "APP_PIPE";
|
|
26
|
+
export declare const APP_GUARD = "APP_GUARD";
|
|
27
|
+
export declare const APP_FILTER = "APP_FILTER";
|
|
28
|
+
export declare const ENHANCER_TOKEN_TO_SUBTYPE_MAP: Record<typeof APP_GUARD | typeof APP_PIPE | typeof APP_FILTER | typeof APP_INTERCEPTOR, EnhancerSubtype>;
|
|
29
|
+
export declare const REQUEST = "REQUEST";
|
|
30
|
+
export declare const GLOBAL_MODULE_METADATA = "__module:global__";
|
|
31
|
+
export declare const HOST_METADATA = "host";
|
|
32
|
+
export declare const PATH_METADATA = "path";
|
|
33
|
+
export declare const PARAMTYPES_METADATA = "design:paramtypes";
|
|
34
|
+
export declare const SELF_DECLARED_DEPS_METADATA = "self:paramtypes";
|
|
35
|
+
export declare const OPTIONAL_DEPS_METADATA = "optional:paramtypes";
|
|
36
|
+
export declare const PROPERTY_DEPS_METADATA = "self:properties_metadata";
|
|
37
|
+
export declare const OPTIONAL_PROPERTY_DEPS_METADATA = "optional:properties_metadata";
|
|
38
|
+
export declare const SCOPE_OPTIONS_METADATA = "scope:options";
|
|
39
|
+
export declare const MODULE_PATH = "__module_path__";
|
|
40
|
+
export declare const ROUTE_ARGS_METADATA = "__routeArguments__";
|
|
41
|
+
export declare const CUSTOM_ROUTE_ARGS_METADATA = "__customRouteArgs__";
|
|
42
|
+
export declare const FILTER_CATCH_EXCEPTIONS = "__filterCatchExceptions__";
|
|
43
|
+
export declare const INJECTABLE_WATERMARK = "__injectable__";
|
|
44
|
+
export declare const CATCH_WATERMARK = "__catch__";
|
|
45
|
+
export declare const ENTRY_PROVIDER_WATERMARK = "__entryProvider__";
|
|
46
|
+
export declare const INQUIRER = "INQUIRER";
|
package/constants.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.INQUIRER = exports.ENTRY_PROVIDER_WATERMARK = exports.CATCH_WATERMARK = exports.INJECTABLE_WATERMARK = exports.FILTER_CATCH_EXCEPTIONS = exports.CUSTOM_ROUTE_ARGS_METADATA = exports.ROUTE_ARGS_METADATA = exports.MODULE_PATH = exports.SCOPE_OPTIONS_METADATA = exports.OPTIONAL_PROPERTY_DEPS_METADATA = exports.PROPERTY_DEPS_METADATA = exports.OPTIONAL_DEPS_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.PATH_METADATA = exports.HOST_METADATA = exports.GLOBAL_MODULE_METADATA = exports.REQUEST = exports.ENHANCER_TOKEN_TO_SUBTYPE_MAP = exports.APP_FILTER = exports.APP_GUARD = exports.APP_PIPE = exports.APP_INTERCEPTOR = exports.ENHANCER_KEY_TO_SUBTYPE_MAP = exports.EXCEPTION_FILTERS_METADATA = exports.INTERCEPTORS_METADATA = exports.GUARDS_METADATA = exports.PIPES_METADATA = exports.MODULE_METADATA = exports.FORBIDDEN_MESSAGE = exports.MESSAGES = void 0;
|
|
4
|
+
exports.MESSAGES = {
|
|
5
|
+
APPLICATION_START: `Starting Venok application...`,
|
|
6
|
+
APPLICATION_READY: `Venok application successfully started`,
|
|
7
|
+
UNKNOWN_EXCEPTION_MESSAGE: "Internal server error",
|
|
8
|
+
ERROR_DURING_SHUTDOWN: "Error happened during shutdown",
|
|
9
|
+
};
|
|
10
|
+
exports.FORBIDDEN_MESSAGE = "Forbidden resource";
|
|
11
|
+
exports.MODULE_METADATA = {
|
|
12
|
+
IMPORTS: "imports",
|
|
13
|
+
PROVIDERS: "providers",
|
|
14
|
+
EXPORTS: "exports",
|
|
15
|
+
};
|
|
16
|
+
exports.PIPES_METADATA = "__pipes__";
|
|
17
|
+
exports.GUARDS_METADATA = "__guards__";
|
|
18
|
+
exports.INTERCEPTORS_METADATA = "__interceptors__";
|
|
19
|
+
exports.EXCEPTION_FILTERS_METADATA = "__exceptionFilters__";
|
|
20
|
+
exports.ENHANCER_KEY_TO_SUBTYPE_MAP = {
|
|
21
|
+
[exports.GUARDS_METADATA]: "guard",
|
|
22
|
+
[exports.INTERCEPTORS_METADATA]: "interceptor",
|
|
23
|
+
[exports.PIPES_METADATA]: "pipe",
|
|
24
|
+
[exports.EXCEPTION_FILTERS_METADATA]: "filter",
|
|
25
|
+
};
|
|
26
|
+
exports.APP_INTERCEPTOR = "APP_INTERCEPTOR";
|
|
27
|
+
exports.APP_PIPE = "APP_PIPE";
|
|
28
|
+
exports.APP_GUARD = "APP_GUARD";
|
|
29
|
+
exports.APP_FILTER = "APP_FILTER";
|
|
30
|
+
exports.ENHANCER_TOKEN_TO_SUBTYPE_MAP = {
|
|
31
|
+
[exports.APP_GUARD]: "guard",
|
|
32
|
+
[exports.APP_INTERCEPTOR]: "interceptor",
|
|
33
|
+
[exports.APP_PIPE]: "pipe",
|
|
34
|
+
[exports.APP_FILTER]: "filter",
|
|
35
|
+
};
|
|
36
|
+
exports.REQUEST = "REQUEST";
|
|
37
|
+
exports.GLOBAL_MODULE_METADATA = "__module:global__";
|
|
38
|
+
exports.HOST_METADATA = "host";
|
|
39
|
+
exports.PATH_METADATA = "path";
|
|
40
|
+
exports.PARAMTYPES_METADATA = "design:paramtypes";
|
|
41
|
+
exports.SELF_DECLARED_DEPS_METADATA = "self:paramtypes";
|
|
42
|
+
exports.OPTIONAL_DEPS_METADATA = "optional:paramtypes";
|
|
43
|
+
exports.PROPERTY_DEPS_METADATA = "self:properties_metadata";
|
|
44
|
+
exports.OPTIONAL_PROPERTY_DEPS_METADATA = "optional:properties_metadata";
|
|
45
|
+
exports.SCOPE_OPTIONS_METADATA = "scope:options";
|
|
46
|
+
exports.MODULE_PATH = "__module_path__";
|
|
47
|
+
exports.ROUTE_ARGS_METADATA = "__routeArguments__";
|
|
48
|
+
exports.CUSTOM_ROUTE_ARGS_METADATA = "__customRouteArgs__";
|
|
49
|
+
exports.FILTER_CATCH_EXCEPTIONS = "__filterCatchExceptions__";
|
|
50
|
+
exports.INJECTABLE_WATERMARK = "__injectable__";
|
|
51
|
+
exports.CATCH_WATERMARK = "__catch__";
|
|
52
|
+
exports.ENTRY_PROVIDER_WATERMARK = "__entryProvider__";
|
|
53
|
+
exports.INQUIRER = "INQUIRER";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ContextId, InstanceWrapper } from "@venok/core/injector/instance/wrapper";
|
|
2
|
+
export declare abstract class ContextCreator {
|
|
3
|
+
abstract createConcreteContext<T extends any[], R extends any[]>(metadata: T, contextId?: ContextId, inquirerId?: string): R;
|
|
4
|
+
getGlobalMetadata?<T extends any[]>(contextId?: ContextId, inquirerId?: string): T;
|
|
5
|
+
createContext<T extends unknown[] = any, R extends unknown[] = any>(instance: object, callback: (...args: any[]) => void, metadataKey: string, contextId?: ContextId, inquirerId?: string): R;
|
|
6
|
+
reflectClassMetadata<T>(instance: object, metadataKey: string): T;
|
|
7
|
+
reflectMethodMetadata<T>(callback: (...args: unknown[]) => unknown, metadataKey: string): T;
|
|
8
|
+
protected getContextId(contextId: ContextId, instanceWrapper: InstanceWrapper): ContextId;
|
|
9
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContextCreator = void 0;
|
|
4
|
+
const constants_1 = require("@venok/core/injector/constants");
|
|
5
|
+
class ContextCreator {
|
|
6
|
+
createContext(instance, callback, metadataKey, contextId = constants_1.STATIC_CONTEXT, inquirerId) {
|
|
7
|
+
const globalMetadata = this.getGlobalMetadata && this.getGlobalMetadata(contextId, inquirerId);
|
|
8
|
+
const classMetadata = this.reflectClassMetadata(instance, metadataKey);
|
|
9
|
+
const methodMetadata = this.reflectMethodMetadata(callback, metadataKey);
|
|
10
|
+
return [
|
|
11
|
+
...this.createConcreteContext(globalMetadata || [], contextId, inquirerId),
|
|
12
|
+
...this.createConcreteContext(classMetadata, contextId, inquirerId),
|
|
13
|
+
...this.createConcreteContext(methodMetadata, contextId, inquirerId),
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
reflectClassMetadata(instance, metadataKey) {
|
|
17
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
18
|
+
return Reflect.getMetadata(metadataKey, prototype.constructor);
|
|
19
|
+
}
|
|
20
|
+
reflectMethodMetadata(callback, metadataKey) {
|
|
21
|
+
return Reflect.getMetadata(metadataKey, callback);
|
|
22
|
+
}
|
|
23
|
+
getContextId(contextId, instanceWrapper) {
|
|
24
|
+
return contextId.getParent
|
|
25
|
+
? contextId.getParent({
|
|
26
|
+
token: instanceWrapper.token,
|
|
27
|
+
isTreeDurable: instanceWrapper.isDependencyTreeDurable(),
|
|
28
|
+
})
|
|
29
|
+
: contextId;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.ContextCreator = ContextCreator;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Type } from "@venok/core/interfaces";
|
|
2
|
+
import { ExecutionContext } from "@venok/core/interfaces/context/execution.interface";
|
|
3
|
+
import { ContextType } from "@venok/core/interfaces/context/arguments-host.interface";
|
|
4
|
+
export declare class ExecutionContextHost implements ExecutionContext {
|
|
5
|
+
private readonly args;
|
|
6
|
+
private readonly constructorRef;
|
|
7
|
+
private readonly handler;
|
|
8
|
+
private contextType;
|
|
9
|
+
constructor(args: any[], constructorRef?: Type<any>, handler?: Function);
|
|
10
|
+
setType<TContext extends string = ContextType>(type: TContext): void;
|
|
11
|
+
getType<TContext extends string = ContextType>(): TContext;
|
|
12
|
+
getClass<T = any>(): Type<T>;
|
|
13
|
+
getHandler(): Function;
|
|
14
|
+
getArgs<T extends Array<any> = any[]>(): T;
|
|
15
|
+
getArgByIndex<T = any>(index: number): T;
|
|
16
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExecutionContextHost = void 0;
|
|
4
|
+
class ExecutionContextHost {
|
|
5
|
+
constructor(args, constructorRef = null, handler = null) {
|
|
6
|
+
this.args = args;
|
|
7
|
+
this.constructorRef = constructorRef;
|
|
8
|
+
this.handler = handler;
|
|
9
|
+
this.contextType = "native";
|
|
10
|
+
}
|
|
11
|
+
setType(type) {
|
|
12
|
+
type && (this.contextType = type);
|
|
13
|
+
}
|
|
14
|
+
getType() {
|
|
15
|
+
return this.contextType;
|
|
16
|
+
}
|
|
17
|
+
getClass() {
|
|
18
|
+
return this.constructorRef;
|
|
19
|
+
}
|
|
20
|
+
getHandler() {
|
|
21
|
+
return this.handler;
|
|
22
|
+
}
|
|
23
|
+
getArgs() {
|
|
24
|
+
return this.args;
|
|
25
|
+
}
|
|
26
|
+
getArgByIndex(index) {
|
|
27
|
+
return this.args[index];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ExecutionContextHost = ExecutionContextHost;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ParamData } from "@venok/core/decorators/create-param.decorator";
|
|
2
|
+
import { GuardsConsumer, GuardsContextCreator } from "@venok/core/guards";
|
|
3
|
+
import { InterceptorsConsumer, InterceptorsContextCreator } from "@venok/core/interceptors";
|
|
4
|
+
import { ModulesContainer } from "@venok/core/injector/module/container";
|
|
5
|
+
import { PipesConsumer, PipesContextCreator } from "@venok/core/pipes";
|
|
6
|
+
import { VenokContainer } from "@venok/core/injector/container";
|
|
7
|
+
import { ContextType } from "@venok/core/interfaces/context/arguments-host.interface";
|
|
8
|
+
import { PipeTransform } from "@venok/core/interfaces/features/pipes.interface";
|
|
9
|
+
import { ContextId } from "@venok/core/injector/instance/wrapper";
|
|
10
|
+
import { ParamProperties } from "@venok/core/helpers/context.helper";
|
|
11
|
+
import { ExternalExceptionFilterContext } from "@venok/core/exceptions/external/filter-context";
|
|
12
|
+
export interface ParamsFactory {
|
|
13
|
+
exchangeKeyForValue(type: number, data: ParamData, args: any): any;
|
|
14
|
+
}
|
|
15
|
+
export type ParamsMetadata = Record<number, ParamMetadata>;
|
|
16
|
+
export interface ParamMetadata {
|
|
17
|
+
index: number;
|
|
18
|
+
data?: ParamData;
|
|
19
|
+
}
|
|
20
|
+
type ParamPropertiesWithMetatype<T = any> = ParamProperties & {
|
|
21
|
+
metatype?: T;
|
|
22
|
+
};
|
|
23
|
+
export interface ExternalHandlerMetadata {
|
|
24
|
+
argsLength: number;
|
|
25
|
+
paramtypes: any[];
|
|
26
|
+
getParamsMetadata: (moduleKey: string, contextId?: ContextId, inquirerId?: string) => ParamPropertiesWithMetatype[];
|
|
27
|
+
}
|
|
28
|
+
export interface ExternalContextOptions {
|
|
29
|
+
guards?: boolean;
|
|
30
|
+
interceptors?: boolean;
|
|
31
|
+
filters?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare class ExternalContextCreator {
|
|
34
|
+
private readonly guardsContextCreator;
|
|
35
|
+
private readonly guardsConsumer;
|
|
36
|
+
private readonly interceptorsContextCreator;
|
|
37
|
+
private readonly interceptorsConsumer;
|
|
38
|
+
private readonly modulesContainer;
|
|
39
|
+
private readonly pipesContextCreator;
|
|
40
|
+
private readonly pipesConsumer;
|
|
41
|
+
private readonly filtersContextCreator;
|
|
42
|
+
private readonly contextUtils;
|
|
43
|
+
private readonly externalErrorProxy;
|
|
44
|
+
private container;
|
|
45
|
+
constructor(guardsContextCreator: GuardsContextCreator, guardsConsumer: GuardsConsumer, interceptorsContextCreator: InterceptorsContextCreator, interceptorsConsumer: InterceptorsConsumer, modulesContainer: ModulesContainer, pipesContextCreator: PipesContextCreator, pipesConsumer: PipesConsumer, filtersContextCreator: ExternalExceptionFilterContext);
|
|
46
|
+
static fromContainer(container: VenokContainer): ExternalContextCreator;
|
|
47
|
+
create<TParamsMetadata extends ParamsMetadata = ParamsMetadata, TContext extends string = ContextType>(instance: object, callback: (...args: unknown[]) => unknown, methodName: string, metadataKey?: string, paramsFactory?: ParamsFactory, contextId?: ContextId, inquirerId?: string, options?: ExternalContextOptions, contextType?: TContext): (...args: any[]) => Promise<any>;
|
|
48
|
+
getMetadata<TMetadata, TContext extends string = ContextType>(instance: any, methodName: string, metadataKey?: string, paramsFactory?: ParamsFactory, contextType?: TContext): ExternalHandlerMetadata;
|
|
49
|
+
getContextModuleKey(moduleCtor: Function | undefined): string;
|
|
50
|
+
exchangeKeysForValues<TMetadata = any>(keys: string[], metadata: TMetadata, moduleContext: string, paramsFactory: ParamsFactory, contextId?: ContextId, inquirerId?: string, contextFactory?: (args: unknown[]) => import("../execution-host").ExecutionContextHost): ParamProperties[];
|
|
51
|
+
createPipesFn(pipes: PipeTransform[], paramsOptions: (ParamProperties & {
|
|
52
|
+
metatype?: unknown;
|
|
53
|
+
})[]): ((args: unknown[], ...params: unknown[]) => Promise<void>) | null;
|
|
54
|
+
getParamValue<T>(value: T, { metatype, type, data }: {
|
|
55
|
+
metatype: any;
|
|
56
|
+
type: any;
|
|
57
|
+
data: any;
|
|
58
|
+
}, pipes: PipeTransform[]): Promise<any>;
|
|
59
|
+
transformToResult(resultOrDeferred: any): Promise<any>;
|
|
60
|
+
createGuardsFn<TContext extends string = ContextType>(guards: any[], instance: object, callback: (...args: any[]) => any, contextType?: TContext): Function | null;
|
|
61
|
+
registerRequestProvider<T = any>(request: T, contextId: ContextId): void;
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExternalContextCreator = void 0;
|
|
4
|
+
const guards_1 = require("@venok/core/guards");
|
|
5
|
+
const interceptors_1 = require("@venok/core/interceptors");
|
|
6
|
+
const pipes_1 = require("@venok/core/pipes");
|
|
7
|
+
const constants_1 = require("@venok/core/injector/constants");
|
|
8
|
+
const constants_2 = require("@venok/core/constants");
|
|
9
|
+
const shared_helper_1 = require("@venok/core/helpers/shared.helper");
|
|
10
|
+
const rxjs_1 = require("rxjs");
|
|
11
|
+
const exceptions_1 = require("@venok/core/errors/exceptions");
|
|
12
|
+
const context_helper_1 = require("@venok/core/helpers/context.helper");
|
|
13
|
+
const proxy_1 = require("@venok/core/context/external/proxy");
|
|
14
|
+
const filter_context_1 = require("@venok/core/exceptions/external/filter-context");
|
|
15
|
+
class ExternalContextCreator {
|
|
16
|
+
constructor(guardsContextCreator, guardsConsumer, interceptorsContextCreator, interceptorsConsumer, modulesContainer, pipesContextCreator, pipesConsumer, filtersContextCreator) {
|
|
17
|
+
this.guardsContextCreator = guardsContextCreator;
|
|
18
|
+
this.guardsConsumer = guardsConsumer;
|
|
19
|
+
this.interceptorsContextCreator = interceptorsContextCreator;
|
|
20
|
+
this.interceptorsConsumer = interceptorsConsumer;
|
|
21
|
+
this.modulesContainer = modulesContainer;
|
|
22
|
+
this.pipesContextCreator = pipesContextCreator;
|
|
23
|
+
this.pipesConsumer = pipesConsumer;
|
|
24
|
+
this.filtersContextCreator = filtersContextCreator;
|
|
25
|
+
this.contextUtils = new context_helper_1.ContextUtils();
|
|
26
|
+
this.externalErrorProxy = new proxy_1.ExternalErrorProxy();
|
|
27
|
+
}
|
|
28
|
+
static fromContainer(container) {
|
|
29
|
+
const guardsContextCreator = new guards_1.GuardsContextCreator(container, container.applicationConfig);
|
|
30
|
+
const guardsConsumer = new guards_1.GuardsConsumer();
|
|
31
|
+
const interceptorsContextCreator = new interceptors_1.InterceptorsContextCreator(container, container.applicationConfig);
|
|
32
|
+
const interceptorsConsumer = new interceptors_1.InterceptorsConsumer();
|
|
33
|
+
const pipesContextCreator = new pipes_1.PipesContextCreator(container, container.applicationConfig);
|
|
34
|
+
const pipesConsumer = new pipes_1.PipesConsumer();
|
|
35
|
+
const filtersContextCreator = new filter_context_1.ExternalExceptionFilterContext(container, container.applicationConfig);
|
|
36
|
+
const externalContextCreator = new ExternalContextCreator(guardsContextCreator, guardsConsumer, interceptorsContextCreator, interceptorsConsumer, container.getModules(), pipesContextCreator, pipesConsumer, filtersContextCreator);
|
|
37
|
+
externalContextCreator.container = container;
|
|
38
|
+
return externalContextCreator;
|
|
39
|
+
}
|
|
40
|
+
create(instance, callback, methodName, metadataKey, paramsFactory, contextId = constants_1.STATIC_CONTEXT, inquirerId, options = {
|
|
41
|
+
interceptors: true,
|
|
42
|
+
guards: true,
|
|
43
|
+
filters: true,
|
|
44
|
+
}, contextType = "http") {
|
|
45
|
+
const module = this.getContextModuleKey(instance.constructor);
|
|
46
|
+
const { argsLength, paramtypes, getParamsMetadata } = this.getMetadata(instance, methodName, metadataKey, paramsFactory, contextType);
|
|
47
|
+
const pipes = this.pipesContextCreator.create(instance, callback, module, contextId, inquirerId);
|
|
48
|
+
const guards = this.guardsContextCreator.create(instance, callback, module, contextId, inquirerId);
|
|
49
|
+
const exceptionFilter = this.filtersContextCreator.create(instance, callback, module, contextId, inquirerId);
|
|
50
|
+
const interceptors = options.interceptors
|
|
51
|
+
? this.interceptorsContextCreator.create(instance, callback, module, contextId, inquirerId)
|
|
52
|
+
: [];
|
|
53
|
+
const paramsMetadata = getParamsMetadata(module, contextId, inquirerId);
|
|
54
|
+
const paramsOptions = paramsMetadata ? this.contextUtils.mergeParamsMetatypes(paramsMetadata, paramtypes) : [];
|
|
55
|
+
const fnCanActivate = options.guards ? this.createGuardsFn(guards, instance, callback, contextType) : null;
|
|
56
|
+
const fnApplyPipes = this.createPipesFn(pipes, paramsOptions);
|
|
57
|
+
const handler = (initialArgs, ...args) => async () => {
|
|
58
|
+
if (fnApplyPipes) {
|
|
59
|
+
await fnApplyPipes(initialArgs, ...args);
|
|
60
|
+
return callback.apply(instance, initialArgs);
|
|
61
|
+
}
|
|
62
|
+
return callback.apply(instance, args);
|
|
63
|
+
};
|
|
64
|
+
const target = async (...args) => {
|
|
65
|
+
const initialArgs = this.contextUtils.createNullArray(argsLength);
|
|
66
|
+
fnCanActivate && (await fnCanActivate(args));
|
|
67
|
+
const result = await this.interceptorsConsumer.intercept(interceptors, args, instance, callback, handler(initialArgs, ...args), contextType);
|
|
68
|
+
return this.transformToResult(result);
|
|
69
|
+
};
|
|
70
|
+
return options.filters ? this.externalErrorProxy.createProxy(target, exceptionFilter, contextType) : target;
|
|
71
|
+
}
|
|
72
|
+
getMetadata(instance, methodName, metadataKey, paramsFactory, contextType) {
|
|
73
|
+
// const cacheMetadata = this.handlerMetadataStorage.get(instance, methodName);
|
|
74
|
+
// if (cacheMetadata) {
|
|
75
|
+
// return cacheMetadata;
|
|
76
|
+
// }
|
|
77
|
+
const metadata = this.contextUtils.reflectCallbackMetadata(instance, methodName, metadataKey || "") || {};
|
|
78
|
+
const keys = Object.keys(metadata);
|
|
79
|
+
const argsLength = this.contextUtils.getArgumentsLength(keys, metadata);
|
|
80
|
+
const paramtypes = this.contextUtils.reflectCallbackParamtypes(instance, methodName);
|
|
81
|
+
const contextFactory = this.contextUtils.getContextFactory(contextType, instance, instance[methodName]);
|
|
82
|
+
const getParamsMetadata = (moduleKey, contextId = constants_1.STATIC_CONTEXT, inquirerId) => paramsFactory
|
|
83
|
+
? this.exchangeKeysForValues(keys, metadata, moduleKey, paramsFactory, contextId, inquirerId, contextFactory)
|
|
84
|
+
: null;
|
|
85
|
+
const handlerMetadata = {
|
|
86
|
+
argsLength,
|
|
87
|
+
paramtypes,
|
|
88
|
+
getParamsMetadata,
|
|
89
|
+
};
|
|
90
|
+
// this.handlerMetadataStorage.set(instance, methodName, handlerMetadata);
|
|
91
|
+
return handlerMetadata;
|
|
92
|
+
}
|
|
93
|
+
getContextModuleKey(moduleCtor) {
|
|
94
|
+
const emptyModuleKey = "";
|
|
95
|
+
if (!moduleCtor) {
|
|
96
|
+
return emptyModuleKey;
|
|
97
|
+
}
|
|
98
|
+
const moduleContainerEntries = this.modulesContainer.entries();
|
|
99
|
+
for (const [key, moduleRef] of moduleContainerEntries) {
|
|
100
|
+
if (moduleRef.hasProvider(moduleCtor)) {
|
|
101
|
+
return key;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return emptyModuleKey;
|
|
105
|
+
}
|
|
106
|
+
exchangeKeysForValues(keys, metadata, moduleContext, paramsFactory, contextId = constants_1.STATIC_CONTEXT, inquirerId, contextFactory = this.contextUtils.getContextFactory("http")) {
|
|
107
|
+
this.pipesContextCreator.setModuleContext(moduleContext);
|
|
108
|
+
return keys.map((key) => {
|
|
109
|
+
// Maybe Error
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
const { index, data, pipes: pipesCollection } = metadata[key];
|
|
112
|
+
const pipes = this.pipesContextCreator.createConcreteContext(pipesCollection, contextId, inquirerId);
|
|
113
|
+
const type = this.contextUtils.mapParamType(key);
|
|
114
|
+
if (key.includes(constants_2.CUSTOM_ROUTE_ARGS_METADATA)) {
|
|
115
|
+
// Maybe Error
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
const { factory } = metadata[key];
|
|
118
|
+
const customExtractValue = this.contextUtils.getCustomFactory(factory, data, contextFactory);
|
|
119
|
+
return { index, extractValue: customExtractValue, type, data, pipes };
|
|
120
|
+
}
|
|
121
|
+
const numericType = Number(type);
|
|
122
|
+
const extractValue = (...args) => paramsFactory.exchangeKeyForValue(numericType, data, args);
|
|
123
|
+
return { index, extractValue, type: numericType, data, pipes };
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
createPipesFn(pipes, paramsOptions) {
|
|
127
|
+
const pipesFn = async (args, ...params) => {
|
|
128
|
+
const resolveParamValue = async (param) => {
|
|
129
|
+
const { index, extractValue, type, data, metatype, pipes: paramPipes } = param;
|
|
130
|
+
const value = extractValue(...params);
|
|
131
|
+
args[index] = await this.getParamValue(value, { metatype, type, data }, pipes.concat(paramPipes));
|
|
132
|
+
};
|
|
133
|
+
await Promise.all(paramsOptions.map(resolveParamValue));
|
|
134
|
+
};
|
|
135
|
+
return paramsOptions.length ? pipesFn : null;
|
|
136
|
+
}
|
|
137
|
+
async getParamValue(value, { metatype, type, data }, pipes) {
|
|
138
|
+
return (0, shared_helper_1.isEmpty)(pipes) ? value : this.pipesConsumer.apply(value, { metatype, type, data }, pipes);
|
|
139
|
+
}
|
|
140
|
+
async transformToResult(resultOrDeferred) {
|
|
141
|
+
if ((0, rxjs_1.isObservable)(resultOrDeferred)) {
|
|
142
|
+
return (0, rxjs_1.lastValueFrom)(resultOrDeferred);
|
|
143
|
+
}
|
|
144
|
+
return resultOrDeferred;
|
|
145
|
+
}
|
|
146
|
+
createGuardsFn(guards, instance, callback, contextType) {
|
|
147
|
+
const canActivateFn = async (args) => {
|
|
148
|
+
const canActivate = await this.guardsConsumer.tryActivate(guards, args, instance, callback, contextType);
|
|
149
|
+
if (!canActivate) {
|
|
150
|
+
throw new exceptions_1.RuntimeException(constants_2.FORBIDDEN_MESSAGE);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
return guards.length ? canActivateFn : null;
|
|
154
|
+
}
|
|
155
|
+
registerRequestProvider(request, contextId) {
|
|
156
|
+
this.container.registerRequestProvider(request, contextId);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.ExternalContextCreator = ExternalContextCreator;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ContextType } from "@venok/core/interfaces/context/arguments-host.interface";
|
|
2
|
+
import { ExternalExceptionsHandler } from "@venok/core/exceptions/external/handler";
|
|
3
|
+
export declare class ExternalErrorProxy {
|
|
4
|
+
createProxy<TContext extends string = ContextType>(targetCallback: (...args: any[]) => any, exceptionsHandler: ExternalExceptionsHandler, type?: TContext): (...args: any[]) => Promise<any>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExternalErrorProxy = void 0;
|
|
4
|
+
const execution_host_1 = require("@venok/core/context/execution-host");
|
|
5
|
+
class ExternalErrorProxy {
|
|
6
|
+
createProxy(targetCallback, exceptionsHandler, type) {
|
|
7
|
+
return async (...args) => {
|
|
8
|
+
try {
|
|
9
|
+
return await targetCallback(...args);
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
const host = new execution_host_1.ExecutionContextHost(args);
|
|
13
|
+
host.setType(type);
|
|
14
|
+
return exceptionsHandler.next(e, host);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.ExternalErrorProxy = ExternalErrorProxy;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function that returns a new decorator that applies all decorators provided by param
|
|
3
|
+
*
|
|
4
|
+
* Useful to build new decorators (or a decorator factory) encapsulating multiple decorators related with the same feature
|
|
5
|
+
*
|
|
6
|
+
* @param decorators one or more decorators (e.g., `ApplyGuard(...)`)
|
|
7
|
+
*
|
|
8
|
+
* @publicApi
|
|
9
|
+
*/
|
|
10
|
+
export declare function applyDecorators(...decorators: Array<ClassDecorator | MethodDecorator | PropertyDecorator>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyDecorators = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Function that returns a new decorator that applies all decorators provided by param
|
|
6
|
+
*
|
|
7
|
+
* Useful to build new decorators (or a decorator factory) encapsulating multiple decorators related with the same feature
|
|
8
|
+
*
|
|
9
|
+
* @param decorators one or more decorators (e.g., `ApplyGuard(...)`)
|
|
10
|
+
*
|
|
11
|
+
* @publicApi
|
|
12
|
+
*/
|
|
13
|
+
function applyDecorators(...decorators) {
|
|
14
|
+
return (target, propertyKey, descriptor) => {
|
|
15
|
+
for (const decorator of decorators) {
|
|
16
|
+
if (target instanceof Function && !descriptor) {
|
|
17
|
+
decorator(target);
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
decorator(target, propertyKey, descriptor);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.applyDecorators = applyDecorators;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decorator that binds *parameter decorators* to the method that follows.
|
|
3
|
+
*
|
|
4
|
+
* Useful when the language doesn't provide a 'Parameter Decorator' feature
|
|
5
|
+
* (i.e., vanilla JavaScript).
|
|
6
|
+
*
|
|
7
|
+
* @param decorators one or more parameter decorators (e.g., `Req()`)
|
|
8
|
+
*
|
|
9
|
+
* @publicApi
|
|
10
|
+
*/
|
|
11
|
+
export declare function Bind(...decorators: any[]): MethodDecorator;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Bind = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Decorator that binds *parameter decorators* to the method that follows.
|
|
6
|
+
*
|
|
7
|
+
* Useful when the language doesn't provide a 'Parameter Decorator' feature
|
|
8
|
+
* (i.e., vanilla JavaScript).
|
|
9
|
+
*
|
|
10
|
+
* @param decorators one or more parameter decorators (e.g., `Req()`)
|
|
11
|
+
*
|
|
12
|
+
* @publicApi
|
|
13
|
+
*/
|
|
14
|
+
function Bind(...decorators) {
|
|
15
|
+
return (target, key, descriptor) => {
|
|
16
|
+
decorators.forEach((fn, index) => fn(target, key, index));
|
|
17
|
+
return descriptor;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
exports.Bind = Bind;
|