@tstdl/base 0.85.13 → 0.86.0-beta1
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/api/client/client.js +109 -125
- package/api/client/index.js +1 -18
- package/api/default-error-handlers.js +18 -44
- package/api/index.js +14 -20
- package/api/response.js +99 -123
- package/api/server/api-controller.js +42 -70
- package/api/server/api-request-token.provider.js +12 -40
- package/api/server/error-handler.js +25 -46
- package/api/server/gateway.js +207 -213
- package/api/server/index.js +5 -22
- package/api/server/middlewares/allowed-methods.middleware.js +17 -40
- package/api/server/middlewares/catch-error.middleware.js +12 -33
- package/api/server/middlewares/cors.middleware.js +49 -69
- package/api/server/middlewares/index.js +4 -21
- package/api/server/middlewares/response-time.middleware.js +8 -31
- package/api/server/module.js +18 -42
- package/api/server/tokens.js +2 -25
- package/api/types.js +14 -40
- package/api/utils.js +13 -36
- package/application/application.js +155 -175
- package/application/index.js +1 -18
- package/async-iterator-symbol.js +5 -28
- package/authentication/authentication.api.js +89 -113
- package/authentication/client/api.client.js +28 -57
- package/authentication/client/authentication.service.js +223 -250
- package/authentication/client/http-client.middleware.js +21 -44
- package/authentication/client/index.js +5 -22
- package/authentication/client/module.js +15 -38
- package/authentication/client/tokens.js +5 -29
- package/authentication/errors/index.js +1 -18
- package/authentication/errors/secret-requirements.error.js +6 -29
- package/authentication/index.js +2 -19
- package/authentication/models/authentication-credentials.model.js +37 -66
- package/authentication/models/authentication-session.model.js +51 -80
- package/authentication/models/index.js +6 -23
- package/authentication/models/init-secret-reset-data.model.js +16 -44
- package/authentication/models/secret-check-result.model.js +9 -36
- package/authentication/models/token-payload-base.model.js +31 -59
- package/authentication/models/token.model.js +1 -16
- package/authentication/server/authentication-api-request-token.provider.js +24 -52
- package/authentication/server/authentication-credentials.repository.js +1 -24
- package/authentication/server/authentication-secret-requirements.validator.js +23 -51
- package/authentication/server/authentication-secret-reset.handler.js +1 -24
- package/authentication/server/authentication-session.repository.js +1 -24
- package/authentication/server/authentication-subject.resolver.js +5 -24
- package/authentication/server/authentication-token-payload.provider.js +5 -29
- package/authentication/server/authentication.api-controller.js +88 -114
- package/authentication/server/authentication.service.js +265 -301
- package/authentication/server/helper.js +66 -87
- package/authentication/server/index.js +11 -28
- package/authentication/server/module.js +25 -47
- package/authentication/server/mongo/index.js +2 -19
- package/authentication/server/mongo/mongo-authentication-credentials.repository.js +52 -84
- package/authentication/server/mongo/mongo-authentication-session.repository.js +49 -81
- package/browser/browser-context-controller.js +71 -99
- package/browser/browser-controller.js +73 -100
- package/browser/browser.service.js +83 -114
- package/browser/document-controller.js +48 -81
- package/browser/element-controller.js +139 -160
- package/browser/frame-controller.js +27 -50
- package/browser/index.js +10 -27
- package/browser/locator-controller.js +36 -59
- package/browser/module.js +23 -47
- package/browser/page-controller.js +89 -108
- package/browser/pdf-options.js +73 -103
- package/browser/types.js +1 -16
- package/browser/utils.js +77 -107
- package/collections/awaitable/awaitable-list.js +99 -122
- package/collections/awaitable/awaitable-map.js +93 -116
- package/collections/awaitable/awaitable-set.js +63 -86
- package/collections/awaitable/index.js +3 -20
- package/collections/collection.js +1 -16
- package/collections/index.js +6 -23
- package/collections/keyed-set.js +53 -77
- package/collections/list.js +1 -16
- package/collections/observable/index.js +8 -25
- package/collections/observable/observable-array.js +95 -118
- package/collections/observable/observable-collection-base.js +60 -83
- package/collections/observable/observable-collection.js +1 -16
- package/collections/observable/observable-list-base.js +55 -78
- package/collections/observable/observable-list.js +1 -16
- package/collections/observable/observable-map.js +56 -79
- package/collections/observable/observable-set.js +75 -98
- package/collections/observable/observable-sorted-array-list.js +165 -188
- package/collections/sorted-array-list.js +156 -179
- package/collections/sorted-list.js +1 -16
- package/collections/sorted-map.js +70 -93
- package/container/container.js +422 -437
- package/container/decorators.js +112 -96
- package/container/index.js +10 -27
- package/container/interfaces.js +2 -26
- package/container/provider.js +28 -59
- package/container/resolve-chain.js +74 -99
- package/container/resolve.error.js +10 -35
- package/container/token.js +17 -38
- package/container/type-info.js +1 -16
- package/container/types.js +1 -16
- package/container/utils.js +18 -42
- package/cookie/cookie.js +49 -71
- package/cookie/index.js +1 -18
- package/core.js +46 -75
- package/data-structures/array-dictionary.js +89 -110
- package/data-structures/array-list.js +105 -128
- package/data-structures/cache.js +41 -64
- package/data-structures/circular-buffer.js +195 -216
- package/data-structures/collection.js +86 -109
- package/data-structures/dictionary.js +51 -75
- package/data-structures/index-out-of-bounds.error.js +8 -31
- package/data-structures/index.js +15 -32
- package/data-structures/iterable-weak-map.js +129 -149
- package/data-structures/linked-list.js +367 -385
- package/data-structures/list.js +78 -101
- package/data-structures/map-dictionary.js +55 -78
- package/data-structures/multi-key-map.js +138 -161
- package/data-structures/set.js +54 -77
- package/data-structures/sorted-array-list.js +142 -169
- package/data-structures/weak-ref-map.js +123 -143
- package/database/entity-repository.js +2 -26
- package/database/entity.js +1 -16
- package/database/id.js +8 -29
- package/database/index.js +6 -23
- package/database/module.js +9 -33
- package/database/mongo/classes.js +13 -42
- package/database/mongo/index.js +10 -27
- package/database/mongo/model/document.js +62 -93
- package/database/mongo/model/index.js +1 -18
- package/database/mongo/module.js +51 -71
- package/database/mongo/mongo-base.repository.js +259 -283
- package/database/mongo/mongo-bulk.js +87 -110
- package/database/mongo/mongo-entity-repository.js +270 -296
- package/database/mongo/operations.js +48 -76
- package/database/mongo/query-converter.js +73 -96
- package/database/mongo/simple-entity-repository.js +5 -28
- package/database/mongo/types.js +2 -25
- package/database/query.js +7 -36
- package/database/utils.js +2 -25
- package/disposable/async-disposer.js +93 -105
- package/disposable/disposable.js +7 -33
- package/disposable/index.js +3 -20
- package/disposable/using.js +15 -37
- package/distributed-loop/controller.js +1 -16
- package/distributed-loop/distributed-loop.js +78 -105
- package/distributed-loop/index.js +3 -20
- package/distributed-loop/provider.js +20 -48
- package/enumerable/async-enumerable.js +238 -261
- package/enumerable/enumerable-methods.js +1 -16
- package/enumerable/enumerable.js +177 -200
- package/enumerable/index.js +2 -19
- package/environment.js +25 -57
- package/error/api.error.js +10 -33
- package/error/assertion.error.js +6 -29
- package/error/bad-request.error.js +6 -29
- package/error/custom.error.js +25 -47
- package/error/details.error.js +8 -31
- package/error/forbidden.error.js +6 -29
- package/error/index.js +16 -33
- package/error/invalid-token.error.js +6 -29
- package/error/max-bytes-exceeded.error.js +9 -32
- package/error/method-not-allowed.error.js +6 -29
- package/error/multi.error.js +8 -31
- package/error/not-found.error.js +6 -29
- package/error/not-implemented.error.js +6 -29
- package/error/not-supported.error.js +11 -34
- package/error/timeout.error.js +6 -29
- package/error/unauthorized.error.js +6 -29
- package/error/unsupported-media-type.error.js +6 -29
- package/examples/api/authentication.js +40 -40
- package/examples/api/basic-overview.js +81 -86
- package/examples/api/custom-authentication.js +61 -66
- package/examples/api/streaming.js +89 -94
- package/examples/browser/basic.js +20 -21
- package/examples/http/client.js +12 -13
- package/examples/mail/basic.js +35 -36
- package/examples/mail/templates/hello-name.js +10 -33
- package/examples/pdf/basic.js +44 -45
- package/examples/pdf/templates/hello-name.js +35 -58
- package/examples/reflection/basic.js +52 -84
- package/examples/template/basic.js +30 -31
- package/examples/template/templates/hello-jsx.js +8 -32
- package/examples/template/templates/hello-name.js +18 -41
- package/global-this.js +17 -36
- package/http/client/adapters/undici-http-client.adapter.js +90 -110
- package/http/client/http-client-options.js +14 -37
- package/http/client/http-client-request.js +149 -171
- package/http/client/http-client-response.js +33 -56
- package/http/client/http-client.adapter.js +1 -24
- package/http/client/http-client.js +301 -322
- package/http/client/index.js +6 -23
- package/http/client/module.js +15 -38
- package/http/cookie-parser.js +19 -42
- package/http/http-body.js +52 -75
- package/http/http-form.js +14 -37
- package/http/http-headers.js +86 -109
- package/http/http-query.js +14 -37
- package/http/http-url-parameters.js +8 -31
- package/http/http-value-map.js +110 -133
- package/http/http.error.js +60 -82
- package/http/index.js +11 -28
- package/http/server/http-server-request.js +24 -47
- package/http/server/http-server-response.js +22 -45
- package/http/server/http-server.js +2 -25
- package/http/server/index.js +3 -20
- package/http/server/node/index.js +2 -19
- package/http/server/node/module.js +8 -28
- package/http/server/node/node-http-server.js +208 -234
- package/http/types.js +21 -47
- package/http/utils.js +92 -108
- package/image-service/image-service.js +59 -91
- package/image-service/imgproxy/imgproxy-image-service.js +86 -124
- package/image-service/imgproxy/index.js +1 -18
- package/image-service/index.js +1 -18
- package/import.js +2 -25
- package/index.js +1 -18
- package/interfaces.js +1 -16
- package/json-path/index.js +1 -18
- package/json-path/json-path.js +138 -138
- package/key-value-store/index.js +2 -19
- package/key-value-store/key-value-store.provider.js +1 -24
- package/key-value-store/key-value.store.js +6 -29
- package/key-value-store/mongo/index.js +6 -23
- package/key-value-store/mongo/module.js +17 -35
- package/key-value-store/mongo/mongo-key-value-store.provider.js +20 -48
- package/key-value-store/mongo/mongo-key-value.model.js +1 -16
- package/key-value-store/mongo/mongo-key-value.repository.js +22 -52
- package/key-value-store/mongo/mongo-key-value.store.js +59 -89
- package/key-value-store/mongo/tokens.js +2 -25
- package/lock/index.js +2 -19
- package/lock/lock.js +5 -28
- package/lock/mongo/index.js +5 -22
- package/lock/mongo/lock.js +111 -135
- package/lock/mongo/model.js +1 -16
- package/lock/mongo/module.js +18 -37
- package/lock/mongo/mongo-lock-repository.js +56 -85
- package/lock/mongo/provider.js +38 -68
- package/lock/provider.js +1 -24
- package/lock/web/index.js +3 -20
- package/lock/web/module.js +11 -31
- package/lock/web/web-lock.js +80 -105
- package/lock/web/web-lock.provider.js +27 -57
- package/logger/console/index.js +1 -18
- package/logger/console/logger.js +53 -80
- package/logger/index.js +2 -19
- package/logger/level.js +8 -31
- package/logger/logger.js +37 -60
- package/logger/noop/index.js +1 -18
- package/logger/noop/logger.js +20 -42
- package/mail/clients/nodemailer.mail-client.js +62 -90
- package/mail/index.js +5 -22
- package/mail/mail-log.repository.js +2 -25
- package/mail/mail.client.js +34 -62
- package/mail/mail.service.js +73 -106
- package/mail/models/index.js +6 -23
- package/mail/models/mail-address.model.js +1 -16
- package/mail/models/mail-content.model.js +1 -16
- package/mail/models/mail-data.model.js +1 -16
- package/mail/models/mail-log.model.js +1 -16
- package/mail/models/mail-send-result.model.js +1 -16
- package/mail/models/mail-template.model.js +5 -28
- package/mail/module.js +21 -41
- package/mail/repositories/mongo-mail-log.repository.js +24 -56
- package/mail/tokens.js +2 -25
- package/memory/finalization.js +36 -60
- package/memory/index.js +2 -19
- package/memory/observable-finalization-registry.js +9 -32
- package/message-bus/broadcast-channel/broadcast-channel-message-bus-provider.js +23 -53
- package/message-bus/broadcast-channel/broadcast-channel-message-bus.js +46 -74
- package/message-bus/broadcast-channel/index.js +3 -20
- package/message-bus/broadcast-channel/module.js +11 -31
- package/message-bus/index.js +3 -20
- package/message-bus/local/index.js +3 -20
- package/message-bus/local/local-message-bus-provider.js +35 -65
- package/message-bus/local/local-message-bus.js +38 -66
- package/message-bus/local/module.js +11 -31
- package/message-bus/local/types.js +1 -16
- package/message-bus/message-bus-base.js +41 -63
- package/message-bus/message-bus-provider.js +1 -24
- package/message-bus/message-bus.js +5 -28
- package/migration/index.js +3 -20
- package/migration/migration-state-repository.js +2 -25
- package/migration/migration-state.js +1 -16
- package/migration/migrator.js +80 -108
- package/migration/mongo/index.js +2 -19
- package/migration/mongo/migration-state-repository.js +23 -53
- package/migration/mongo/module.js +15 -34
- package/module/index.js +4 -21
- package/module/module-base.js +37 -60
- package/module/module-metric-reporter.js +58 -77
- package/module/module.js +10 -34
- package/module/modules/function.module.js +11 -34
- package/module/modules/index.js +2 -19
- package/module/modules/web-server.module.js +67 -103
- package/module/utils.js +19 -43
- package/notification/api.js +21 -50
- package/notification/models/index.js +2 -19
- package/notification/models/notification-channel-job.model.js +1 -16
- package/notification/models/notification.model.js +74 -103
- package/notification/module.js +8 -28
- package/notification/notification-channel.service.js +1 -24
- package/notification/notification.repository.js +1 -24
- package/notification/notification.service.js +30 -58
- package/object-storage/index.js +3 -20
- package/object-storage/object-storage-provider.js +1 -24
- package/object-storage/object-storage.js +6 -29
- package/object-storage/object.js +7 -30
- package/object-storage/s3/index.js +3 -20
- package/object-storage/s3/s3.object-storage-provider.js +82 -108
- package/object-storage/s3/s3.object-storage.js +130 -157
- package/object-storage/s3/s3.object.js +39 -62
- package/openid-connect/cached-oidc-configuration.service.js +35 -65
- package/openid-connect/index.js +11 -28
- package/openid-connect/mongo-oidc-state.repository.js +38 -64
- package/openid-connect/oidc-configuration.service.js +38 -66
- package/openid-connect/oidc-state.model.js +1 -16
- package/openid-connect/oidc-state.repository.js +2 -25
- package/openid-connect/oidc.service-model.js +1 -16
- package/openid-connect/oidc.service.js +157 -187
- package/package.json +11 -11
- package/password/have-i-been-pwned.js +21 -39
- package/password/index.js +4 -21
- package/password/password-check-result.model.js +34 -63
- package/password/password-check.js +46 -76
- package/password/password-check.localization.js +86 -111
- package/pdf/index.js +1 -18
- package/pdf/pdf.service.js +171 -206
- package/pool/index.js +1 -18
- package/pool/pool.js +116 -133
- package/process-shutdown.js +54 -77
- package/promise/cancelable-promise.js +23 -41
- package/promise/deferred-promise.js +68 -92
- package/promise/index.js +3 -20
- package/promise/lazy-promise.js +24 -47
- package/queue/enqueue-batch.js +18 -41
- package/queue/index.js +3 -20
- package/queue/mongo/index.js +4 -21
- package/queue/mongo/job.js +1 -16
- package/queue/mongo/mongo-job.repository.js +44 -70
- package/queue/mongo/queue.js +242 -265
- package/queue/mongo/queue.provider.js +44 -70
- package/queue/provider.js +1 -24
- package/queue/queue.js +15 -41
- package/random/index.js +2 -19
- package/random/number-generator/index.js +3 -20
- package/random/number-generator/mulberry32.js +34 -51
- package/random/number-generator/random-number-generator-function.js +1 -24
- package/random/number-generator/random-number-generator.js +8 -31
- package/random/number-generator/seeded-random-number-generator.js +5 -28
- package/random/number-generator/sfc32.js +41 -64
- package/random/number-generator/utils.js +2 -25
- package/random/series.js +41 -43
- package/reflection/decorator-data.js +63 -80
- package/reflection/decorators.js +39 -69
- package/reflection/index.js +5 -22
- package/reflection/reflection-data-map.js +32 -55
- package/reflection/registry.js +112 -132
- package/reflection/types.js +1 -16
- package/reflection/utils.js +96 -124
- package/require.js +3 -26
- package/rpc/endpoints/message-port.rpc-endpoint.js +29 -48
- package/rpc/index.js +4 -21
- package/rpc/model.js +7 -30
- package/rpc/rpc-endpoint.js +17 -40
- package/rpc/rpc-error.js +17 -40
- package/rpc/rpc.js +223 -235
- package/rxjs/cast.js +4 -28
- package/rxjs/index.js +12 -29
- package/rxjs/intersection-observer.js +25 -48
- package/rxjs/media-query.js +8 -27
- package/rxjs/mutation-observer.js +28 -50
- package/rxjs/noop.js +4 -28
- package/rxjs/performance-observer.js +37 -60
- package/rxjs/resize-observer.js +28 -50
- package/rxjs/retry-backoff.js +23 -47
- package/rxjs/slow-array.js +22 -36
- package/rxjs/teardown.js +21 -44
- package/rxjs/timing.js +26 -57
- package/rxjs/touch.js +11 -30
- package/schema/array-constraints/index.js +2 -19
- package/schema/array-constraints/maximum-length.js +19 -42
- package/schema/array-constraints/minimum-length.js +19 -42
- package/schema/coercers/boolean.coercer.js +25 -49
- package/schema/coercers/date.coercer.js +14 -38
- package/schema/coercers/index.js +6 -23
- package/schema/coercers/number.coercer.js +12 -36
- package/schema/coercers/regexp.coercer.js +18 -41
- package/schema/coercers/string.coercer.js +12 -36
- package/schema/coercers/uint8-array.coercer.js +20 -44
- package/schema/constraints/enumeration.js +27 -49
- package/schema/constraints/generic.js +21 -41
- package/schema/constraints/index.js +12 -29
- package/schema/constraints/integer.js +20 -44
- package/schema/constraints/length.js +14 -36
- package/schema/constraints/literal.js +22 -44
- package/schema/constraints/maximum-date.js +23 -46
- package/schema/constraints/maximum-length.js +22 -45
- package/schema/constraints/maximum.js +21 -44
- package/schema/constraints/minimum-date.js +23 -46
- package/schema/constraints/minimum-length.js +22 -45
- package/schema/constraints/minimum.js +21 -44
- package/schema/constraints/pattern.js +23 -46
- package/schema/decorators/class.js +4 -26
- package/schema/decorators/coerce.js +4 -26
- package/schema/decorators/constraint.js +6 -28
- package/schema/decorators/index.js +6 -23
- package/schema/decorators/property.js +16 -38
- package/schema/decorators/types.js +1 -16
- package/schema/decorators/utils.js +45 -73
- package/schema/index.js +10 -27
- package/schema/schema.error.js +59 -72
- package/schema/schema.js +256 -274
- package/schema/schemas/any.js +7 -30
- package/schema/schemas/array.js +21 -44
- package/schema/schemas/assign.js +23 -46
- package/schema/schemas/boolean.js +7 -30
- package/schema/schemas/constraint.js +6 -29
- package/schema/schemas/date.js +20 -43
- package/schema/schemas/defaulted.js +8 -31
- package/schema/schemas/enumeration.js +15 -38
- package/schema/schemas/index.js +26 -43
- package/schema/schemas/instance.js +4 -26
- package/schema/schemas/literal.js +15 -38
- package/schema/schemas/nullable.js +7 -30
- package/schema/schemas/number.js +25 -48
- package/schema/schemas/object.js +10 -34
- package/schema/schemas/omit.js +14 -37
- package/schema/schemas/one-or-many.js +13 -35
- package/schema/schemas/optional.js +6 -30
- package/schema/schemas/partial.js +16 -39
- package/schema/schemas/pick.js +14 -37
- package/schema/schemas/readable-stream.js +7 -30
- package/schema/schemas/record.js +9 -31
- package/schema/schemas/regexp.js +7 -30
- package/schema/schemas/string.js +36 -59
- package/schema/schemas/transform.js +6 -29
- package/schema/schemas/uint8-array.js +27 -50
- package/schema/schemas/union.js +11 -34
- package/schema/schemas/unknown.js +7 -30
- package/schema/transformers/generic.js +16 -39
- package/schema/transformers/index.js +4 -21
- package/schema/transformers/lowercase.js +10 -33
- package/schema/transformers/trim.js +10 -33
- package/schema/transformers/uppercase.js +10 -33
- package/schema/types/index.js +5 -22
- package/schema/types/schema-array-constraint.js +1 -24
- package/schema/types/schema-value-coercer.js +1 -24
- package/schema/types/schema-value-constraint.js +1 -24
- package/schema/types/schema-value-transformer.js +1 -24
- package/schema/types/types.js +161 -191
- package/schema/utils/index.js +2 -19
- package/schema/utils/schema.js +120 -142
- package/schema/utils/value-type.js +51 -74
- package/search-index/elastic/config.js +19 -49
- package/search-index/elastic/index.js +6 -23
- package/search-index/elastic/keyword-rewriter.js +17 -40
- package/search-index/elastic/model/elastic-query.js +1 -16
- package/search-index/elastic/model/index-mapping.js +4 -26
- package/search-index/elastic/model/index.js +3 -20
- package/search-index/elastic/model/sort.js +1 -16
- package/search-index/elastic/module.js +38 -64
- package/search-index/elastic/query-builder/boolean-query-builder.js +46 -69
- package/search-index/elastic/query-builder/index.js +1 -18
- package/search-index/elastic/query-converter.js +174 -192
- package/search-index/elastic/search-index.js +132 -153
- package/search-index/elastic/sort-converter.js +12 -34
- package/search-index/elastic/types.js +1 -16
- package/search-index/error.js +12 -35
- package/search-index/index.js +3 -20
- package/search-index/memory/index.js +1 -18
- package/search-index/memory/memory-search-index.js +130 -152
- package/search-index/search-index.js +30 -53
- package/search-index/search-result.js +1 -16
- package/serializer/handlers/binary.js +19 -47
- package/serializer/handlers/date.js +4 -28
- package/serializer/handlers/error.js +7 -31
- package/serializer/handlers/index.js +7 -24
- package/serializer/handlers/map.js +16 -40
- package/serializer/handlers/regex.js +7 -31
- package/serializer/handlers/register.js +36 -59
- package/serializer/handlers/set.js +13 -37
- package/serializer/index.js +3 -30
- package/serializer/serializable.js +43 -68
- package/serializer/serializer.js +244 -264
- package/serializer/types.js +6 -34
- package/signals/api.js +17 -45
- package/signals/computed-with-dependencies.js +8 -31
- package/signals/effect-with-dependencies.js +8 -31
- package/signals/implementation/api.js +33 -33
- package/signals/implementation/computed.js +125 -104
- package/signals/implementation/configure.js +18 -41
- package/signals/implementation/effect.js +48 -66
- package/signals/implementation/errors.js +5 -29
- package/signals/implementation/graph.js +164 -136
- package/signals/implementation/index.js +10 -27
- package/signals/implementation/signal.js +91 -101
- package/signals/implementation/to-observable.js +21 -38
- package/signals/implementation/to-signal.js +44 -60
- package/signals/implementation/untracked.js +15 -31
- package/signals/implementation/watch.js +58 -73
- package/signals/index.d.ts +1 -0
- package/signals/index.js +7 -23
- package/signals/pipe.js +7 -31
- package/signals/switch-map.js +4 -27
- package/signals/types.js +1 -16
- package/signals/untracked-operator.d.ts +3 -0
- package/signals/untracked-operator.js +12 -0
- package/sse/index.js +2 -19
- package/sse/model.js +1 -16
- package/sse/server-sent-events-source.js +54 -76
- package/sse/server-sent-events.js +48 -72
- package/supports.js +5 -32
- package/templates/index.js +9 -26
- package/templates/module.js +37 -58
- package/templates/providers/file.template-provider.js +39 -81
- package/templates/providers/memory.template-provider.js +27 -55
- package/templates/renderers/handlebars.template-renderer.js +84 -122
- package/templates/renderers/jsx.template-renderer.js +28 -56
- package/templates/renderers/mjml.template-renderer.js +42 -82
- package/templates/renderers/string.template-renderer.js +24 -52
- package/templates/resolvers/file.template-resolver.js +45 -89
- package/templates/resolvers/jsx.template-resolver.js +29 -59
- package/templates/resolvers/string.template-resolver.js +29 -59
- package/templates/template-renderer.provider.js +36 -66
- package/templates/template-resolver.provider.js +36 -66
- package/templates/template.model.js +39 -69
- package/templates/template.provider.js +1 -24
- package/templates/template.renderer.js +11 -34
- package/templates/template.resolver.js +1 -24
- package/templates/template.service.js +49 -82
- package/templates/tokens.js +3 -27
- package/templates/types/jsx.intrinsic-elements.js +1 -16
- package/text/dynamic-text.model.js +41 -70
- package/text/index.js +3 -20
- package/text/localizable-text.model.js +1 -16
- package/text/localization.service.js +196 -229
- package/theme/adapters/css-adapter.js +23 -46
- package/theme/adapters/tailwind-adapter.js +29 -52
- package/theme/index.js +1 -18
- package/theme/theme-service.js +107 -146
- package/threading/index.js +2 -19
- package/threading/thread-pool.js +48 -70
- package/threading/thread-worker.js +3 -26
- package/tokens.js +2 -25
- package/types/geo-json.js +1 -16
- package/types.js +2 -16
- package/utils/alphabet.js +12 -35
- package/utils/any-iterable-iterator.js +4 -27
- package/utils/array/array-backtracker.js +42 -65
- package/utils/array/array.js +76 -79
- package/utils/array/index.js +2 -19
- package/utils/async-iterable-helpers/all.js +25 -46
- package/utils/async-iterable-helpers/any.js +25 -46
- package/utils/async-iterable-helpers/assert.js +22 -43
- package/utils/async-iterable-helpers/batch.js +26 -46
- package/utils/async-iterable-helpers/buffer.js +47 -64
- package/utils/async-iterable-helpers/concat.js +5 -27
- package/utils/async-iterable-helpers/default-if-empty.js +9 -32
- package/utils/async-iterable-helpers/deferred.js +3 -26
- package/utils/async-iterable-helpers/difference.js +24 -48
- package/utils/async-iterable-helpers/distinct.js +23 -44
- package/utils/async-iterable-helpers/drain.js +4 -26
- package/utils/async-iterable-helpers/filter.js +23 -44
- package/utils/async-iterable-helpers/first-or-default.js +8 -30
- package/utils/async-iterable-helpers/first.js +8 -30
- package/utils/async-iterable-helpers/for-each.js +18 -38
- package/utils/async-iterable-helpers/group-single.js +3 -26
- package/utils/async-iterable-helpers/group-to-map.js +20 -41
- package/utils/async-iterable-helpers/group-to-single-map.js +23 -44
- package/utils/async-iterable-helpers/group.js +3 -26
- package/utils/async-iterable-helpers/includes.js +7 -28
- package/utils/async-iterable-helpers/index.js +48 -65
- package/utils/async-iterable-helpers/interrupt.js +19 -43
- package/utils/async-iterable-helpers/is-async-iterable.js +5 -29
- package/utils/async-iterable-helpers/last-or-default.js +13 -36
- package/utils/async-iterable-helpers/last.js +13 -36
- package/utils/async-iterable-helpers/map-many.js +19 -40
- package/utils/async-iterable-helpers/map.js +19 -40
- package/utils/async-iterable-helpers/materialize.js +21 -42
- package/utils/async-iterable-helpers/metadata.js +38 -58
- package/utils/async-iterable-helpers/multiplex.js +23 -44
- package/utils/async-iterable-helpers/observable-iterable.js +31 -53
- package/utils/async-iterable-helpers/pairwise.js +26 -44
- package/utils/async-iterable-helpers/parallel/feed.js +24 -45
- package/utils/async-iterable-helpers/parallel/filter.js +8 -31
- package/utils/async-iterable-helpers/parallel/for-each.js +21 -44
- package/utils/async-iterable-helpers/parallel/group.js +9 -32
- package/utils/async-iterable-helpers/parallel/index.js +7 -24
- package/utils/async-iterable-helpers/parallel/map.js +6 -29
- package/utils/async-iterable-helpers/parallel/tap.js +6 -29
- package/utils/async-iterable-helpers/parallel/types.js +1 -16
- package/utils/async-iterable-helpers/reduce.js +31 -46
- package/utils/async-iterable-helpers/retry.js +43 -58
- package/utils/async-iterable-helpers/single-or-default.js +17 -40
- package/utils/async-iterable-helpers/single.js +19 -42
- package/utils/async-iterable-helpers/skip.js +3 -26
- package/utils/async-iterable-helpers/sort.js +6 -29
- package/utils/async-iterable-helpers/take-until.js +32 -49
- package/utils/async-iterable-helpers/take-while.js +29 -46
- package/utils/async-iterable-helpers/take.js +10 -33
- package/utils/async-iterable-helpers/tap.js +19 -40
- package/utils/async-iterable-helpers/throttle.js +9 -30
- package/utils/async-iterable-helpers/to-array.js +10 -33
- package/utils/async-iterable-helpers/to-async-iterable-iterator.js +40 -59
- package/utils/async-iterable-helpers/to-async-iterator.js +32 -54
- package/utils/async-iterable-helpers/to-set.js +10 -33
- package/utils/async-iterable-helpers/to-sync-iterable.js +6 -27
- package/utils/async-iterable-helpers/types.js +1 -16
- package/utils/async-iterable-helpers/while.js +25 -46
- package/utils/async-iterator-iterable-iterator.js +41 -62
- package/utils/backoff.js +109 -109
- package/utils/base64.js +153 -140
- package/utils/benchmark.js +114 -107
- package/utils/binary-search.js +70 -87
- package/utils/binary.js +50 -61
- package/utils/cancellation-token.js +120 -140
- package/utils/clone.js +43 -64
- package/utils/comparison.js +76 -98
- package/utils/compression.js +107 -118
- package/utils/config-parser.js +21 -48
- package/utils/crc32.js +20 -42
- package/utils/cryptography.js +163 -121
- package/utils/date-time.js +102 -138
- package/utils/encoding.js +62 -60
- package/utils/enum.js +27 -53
- package/utils/equals.js +103 -119
- package/utils/event-loop.js +19 -39
- package/utils/factory-map.js +53 -75
- package/utils/feedable-async-iterable.js +47 -70
- package/utils/file-reader.js +15 -41
- package/utils/format-error.js +36 -57
- package/utils/format.js +32 -53
- package/utils/function/index.js +2 -19
- package/utils/function/memoize.js +38 -53
- package/utils/function/throttle.js +26 -48
- package/utils/helpers.js +93 -102
- package/utils/image.js +62 -88
- package/utils/index.js +48 -65
- package/utils/iterable-helpers/all.js +8 -31
- package/utils/iterable-helpers/any.js +8 -31
- package/utils/iterable-helpers/assert.js +7 -30
- package/utils/iterable-helpers/batch.js +11 -34
- package/utils/iterable-helpers/concat.js +4 -27
- package/utils/iterable-helpers/default-if-empty.js +9 -32
- package/utils/iterable-helpers/deferred.js +2 -25
- package/utils/iterable-helpers/difference.js +21 -45
- package/utils/iterable-helpers/distinct.js +9 -32
- package/utils/iterable-helpers/drain.js +4 -26
- package/utils/iterable-helpers/filter.js +7 -30
- package/utils/iterable-helpers/first-or-default.js +8 -30
- package/utils/iterable-helpers/first.js +8 -30
- package/utils/iterable-helpers/for-each.js +5 -28
- package/utils/iterable-helpers/group-single.js +3 -26
- package/utils/iterable-helpers/group-to-map.js +9 -32
- package/utils/iterable-helpers/group-to-single-map.js +10 -33
- package/utils/iterable-helpers/group.js +3 -26
- package/utils/iterable-helpers/includes.js +3 -26
- package/utils/iterable-helpers/index.js +39 -56
- package/utils/iterable-helpers/is-iterable.js +5 -29
- package/utils/iterable-helpers/last-or-default.js +13 -36
- package/utils/iterable-helpers/last.js +13 -36
- package/utils/iterable-helpers/map-many.js +6 -29
- package/utils/iterable-helpers/map.js +6 -29
- package/utils/iterable-helpers/materialize.js +2 -25
- package/utils/iterable-helpers/metadata.js +16 -38
- package/utils/iterable-helpers/pairwise.js +11 -33
- package/utils/iterable-helpers/range.js +4 -27
- package/utils/iterable-helpers/reduce.js +11 -33
- package/utils/iterable-helpers/single-or-default.js +14 -37
- package/utils/iterable-helpers/single.js +17 -40
- package/utils/iterable-helpers/skip.js +6 -29
- package/utils/iterable-helpers/sort.js +4 -27
- package/utils/iterable-helpers/take-until.js +8 -31
- package/utils/iterable-helpers/take-while.js +10 -33
- package/utils/iterable-helpers/take.js +10 -33
- package/utils/iterable-helpers/tap.js +6 -29
- package/utils/iterable-helpers/types.js +1 -16
- package/utils/iterable-helpers/while.js +8 -31
- package/utils/jwt.js +77 -100
- package/utils/map.js +35 -62
- package/utils/math.js +102 -64
- package/utils/merge.js +26 -45
- package/utils/middleware.js +36 -60
- package/utils/moving-metric.js +155 -188
- package/utils/noop.js +4 -27
- package/utils/object/decycle.js +57 -78
- package/utils/object/dereference.js +46 -44
- package/utils/object/forward-ref.js +57 -73
- package/utils/object/index.js +7 -24
- package/utils/object/lazy-property.js +81 -96
- package/utils/object/merge.js +48 -70
- package/utils/object/object.js +106 -136
- package/utils/object/property-name.js +69 -72
- package/utils/ordered-feedable-async-iterable.js +42 -65
- package/utils/patch-worker.js +69 -90
- package/utils/patterns.js +7 -29
- package/utils/periodic-reporter.js +60 -82
- package/utils/periodic-sampler.js +67 -91
- package/utils/provider-function-iterable.js +26 -48
- package/utils/proxy.js +17 -42
- package/utils/random.js +40 -50
- package/utils/reflection.js +13 -41
- package/utils/repl.js +14 -33
- package/utils/set.js +36 -62
- package/utils/singleton.js +18 -41
- package/utils/sort.js +53 -77
- package/utils/stream/finalize-stream.js +43 -62
- package/utils/stream/index.js +6 -23
- package/utils/stream/readable-stream-adapter.js +35 -57
- package/utils/stream/readable-stream-from-promise.js +7 -28
- package/utils/stream/size-limited-stream.js +12 -35
- package/utils/stream/stream-helper-types.js +1 -16
- package/utils/stream/stream-reader.js +30 -52
- package/utils/string/hypenate.js +2 -25
- package/utils/string/index.js +3 -20
- package/utils/string/title-case.js +6 -26
- package/utils/string/trim.js +9 -32
- package/utils/throw.js +7 -30
- package/utils/timer.js +70 -91
- package/utils/timing.js +52 -80
- package/utils/type-guards.js +253 -1076
- package/utils/type-of.js +25 -43
- package/utils/units.js +53 -124
- package/utils/url-builder.js +47 -68
- package/utils/value-or-provider.js +6 -29
- package/utils/z-base32.js +42 -63
- package/web-types.js +1 -16
package/container/container.js
CHANGED
|
@@ -1,443 +1,428 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (isFirst) {
|
|
239
|
-
for (const fn of context.forwardRefQueue.consume()) {
|
|
240
|
-
fn();
|
|
241
|
-
}
|
|
242
|
-
derefForwardRefs(context);
|
|
243
|
-
for (let i = context.resolutions.length - 1; i >= 0; i--) {
|
|
244
|
-
const resolution = context.resolutions[i];
|
|
245
|
-
if ((0, import_type_guards.isFunction)(resolution.instance?.[import_interfaces.afterResolve])) {
|
|
246
|
-
const returnValue = resolution.instance[import_interfaces.afterResolve]();
|
|
247
|
-
if ((0, import_type_guards.isPromise)(returnValue)) {
|
|
248
|
-
throw new import_resolve_error.ResolveError(`Cannot execute async [afterResolve] for token ${(0, import_token.getTokenName)(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
if ((0, import_type_guards.isDefined)(resolution.registration.options.initializer)) {
|
|
252
|
-
const returnValue = resolution.registration.options.initializer(resolution.instance);
|
|
253
|
-
if ((0, import_type_guards.isPromise)(returnValue)) {
|
|
254
|
-
throw new import_resolve_error.ResolveError(`Cannot execute async initializer for token ${(0, import_token.getTokenName)(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
return instance;
|
|
260
|
-
}
|
|
261
|
-
// eslint-disable-next-line max-statements, max-lines-per-function, complexity
|
|
262
|
-
async _resolveAsync(token, optional, _argument, context, chain, isFirst) {
|
|
263
|
-
if (chain.length > 750 || ++context.resolves > 750) {
|
|
264
|
-
throw new import_resolve_error.ResolveError("Resolve stack overflow. This can happen on circular dependencies with transient lifecycles and self reference. Use scoped or singleton lifecycle instead or @forwardRef().", chain);
|
|
265
|
-
}
|
|
266
|
-
if ((0, import_type_guards.isUndefined)(token)) {
|
|
267
|
-
throw new import_resolve_error.ResolveError("Token is undefined - this might be because of circular dependencies, use alias or forwardRef in this case.", chain);
|
|
268
|
-
}
|
|
269
|
-
if (context.providedInstances.has(token)) {
|
|
270
|
-
return context.providedInstances.get(token);
|
|
271
|
-
}
|
|
272
|
-
const registration = this.tryGetRegistration(token);
|
|
273
|
-
if ((0, import_type_guards.isUndefined)(registration)) {
|
|
274
|
-
if (optional == true) {
|
|
275
|
-
return void 0;
|
|
276
|
-
}
|
|
277
|
-
throw new import_resolve_error.ResolveError(`No provider for ${(0, import_token.getTokenName)(token)} registered.`, chain);
|
|
278
|
-
}
|
|
279
|
-
const resolveArgument = _argument ?? registration.options.defaultArgument ?? await registration.options.defaultArgumentProvider?.(this.getResolveContext(context, chain));
|
|
280
|
-
const argumentIdentity = (0, import_type_guards.isDefined)(registration.options.argumentIdentityProvider) && (registration.options.lifecycle == "resolution" || registration.options.lifecycle == "singleton") ? await registration.options.argumentIdentityProvider(resolveArgument) : resolveArgument;
|
|
281
|
-
if (registration.options.lifecycle == "resolution" && context.instances.has([token, argumentIdentity])) {
|
|
282
|
-
return context.instances.get([token, argumentIdentity]);
|
|
283
|
-
}
|
|
284
|
-
if (registration.options.lifecycle == "singleton" && registration.instances.has(argumentIdentity)) {
|
|
285
|
-
return registration.instances.get(argumentIdentity);
|
|
286
|
-
}
|
|
287
|
-
if (context.resolving.has([token, argumentIdentity])) {
|
|
288
|
-
throw new import_resolve_error.ResolveError("Circular dependency to itself detected. Please check your registrations and providers. @forwardRef might be a solution.", chain);
|
|
289
|
-
}
|
|
290
|
-
context.resolving.set([token, argumentIdentity], true);
|
|
291
|
-
let instance;
|
|
292
|
-
if ((0, import_provider.isClassProvider)(registration.provider)) {
|
|
293
|
-
const typeMetadata = import_reflection.reflectionRegistry.getMetadata(registration.provider.useClass);
|
|
294
|
-
if ((0, import_type_guards.isUndefined)(typeMetadata) || !typeMetadata.data.has(injectMetadataSymbol)) {
|
|
295
|
-
throw new import_resolve_error.ResolveError(`${registration.provider.useClass.name} is not injectable.`, chain);
|
|
296
|
-
}
|
|
297
|
-
if ((0, import_utils.isStubClass)(typeMetadata.constructor)) {
|
|
298
|
-
throw new import_resolve_error.ResolveError(`No provider for ${(0, import_token.getTokenName)(token)} registered.`, chain);
|
|
299
|
-
}
|
|
300
|
-
const boxedParameters = await (0, import_to_array.toArrayAsync)((0, import_map.mapAsync)(typeMetadata.parameters ?? [], async (metadata) => this.resolveInjectionAsync(context, typeMetadata, metadata, resolveArgument, chain)));
|
|
301
|
-
const parameters = boxedParameters.map((box) => box.resolved);
|
|
302
|
-
instance = new typeMetadata.constructor(...parameters);
|
|
303
|
-
for (const [property, metadata] of typeMetadata.properties) {
|
|
304
|
-
if (!metadata.data.has(injectMetadataSymbol)) {
|
|
305
|
-
continue;
|
|
306
|
-
}
|
|
307
|
-
instance[property] = (await this.resolveInjectionAsync(context, typeMetadata, metadata, resolveArgument, chain)).resolved;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
if ((0, import_provider.isValueProvider)(registration.provider)) {
|
|
311
|
-
instance = registration.provider.useValue;
|
|
312
|
-
}
|
|
313
|
-
if ((0, import_provider.isTokenProvider)(registration.provider)) {
|
|
314
|
-
const arg = resolveArgument ?? registration.provider.argument ?? await registration.provider.argumentProvider?.();
|
|
315
|
-
const innerToken = registration.provider.useToken ?? await registration.provider.useTokenProvider();
|
|
316
|
-
instance = await this._resolveAsync(innerToken, false, arg, context, chain.addToken(innerToken), false);
|
|
317
|
-
}
|
|
318
|
-
if ((0, import_provider.isFactoryProvider)(registration.provider)) {
|
|
319
|
-
try {
|
|
320
|
-
instance = await registration.provider.useFactory(resolveArgument, this.getResolveContext(context, chain));
|
|
321
|
-
} catch (error) {
|
|
322
|
-
throw new import_resolve_error.ResolveError("Error in factory.", chain, error);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
if (registration.options.lifecycle == "resolution") {
|
|
326
|
-
context.instances.set([token, argumentIdentity], instance);
|
|
327
|
-
}
|
|
328
|
-
if (registration.options.lifecycle == "singleton") {
|
|
329
|
-
registration.instances.set(argumentIdentity, instance);
|
|
330
|
-
}
|
|
331
|
-
context.resolutions.push({ instance, registration });
|
|
332
|
-
context.resolving.delete([token, argumentIdentity]);
|
|
333
|
-
if (isFirst) {
|
|
334
|
-
for (const fn of context.forwardRefQueue.consume()) {
|
|
335
|
-
await fn();
|
|
336
|
-
}
|
|
337
|
-
derefForwardRefs(context);
|
|
338
|
-
for (let i = context.resolutions.length - 1; i >= 0; i--) {
|
|
339
|
-
const resolution = context.resolutions[i];
|
|
340
|
-
if ((0, import_type_guards.isFunction)(resolution.instance?.[import_interfaces.afterResolve])) {
|
|
341
|
-
await resolution.instance[import_interfaces.afterResolve]();
|
|
342
|
-
}
|
|
343
|
-
if ((0, import_type_guards.isDefined)(resolution.registration.options.initializer)) {
|
|
344
|
-
await resolution.registration.options.initializer(resolution.instance);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
return instance;
|
|
349
|
-
}
|
|
350
|
-
resolveInjection(token, context, typeMetadata, metadata, resolveArgument, chain) {
|
|
351
|
-
const getChain = metadata.metadataType == "constructor-parameter" ? (injectToken2) => chain.addParameter(typeMetadata.constructor, metadata.index, injectToken2).addToken(injectToken2) : (injectToken2) => chain.addProperty(typeMetadata.constructor, metadata.key, injectToken2).addToken(injectToken2);
|
|
352
|
-
const injectMetadata = metadata.data.tryGet(injectMetadataSymbol) ?? {};
|
|
353
|
-
const injectToken = injectMetadata.injectToken ?? metadata.type;
|
|
354
|
-
if ((0, import_type_guards.isDefined)(injectMetadata.injectArgumentMapper) && (!this.hasRegistration(injectToken) || (0, import_type_guards.isDefined)(resolveArgument) || (0, import_type_guards.isUndefined)(injectToken))) {
|
|
355
|
-
const mapped = injectMetadata.injectArgumentMapper(resolveArgument);
|
|
356
|
-
if ((0, import_type_guards.isPromise)(mapped)) {
|
|
357
|
-
throw new import_resolve_error.ResolveError(`Cannot evaluate async argument mapper for token ${(0, import_token.getTokenName)(token)} in synchronous resolve, use resolveAsync instead.`, getChain(injectToken));
|
|
358
|
-
}
|
|
359
|
-
return mapped;
|
|
360
|
-
}
|
|
361
|
-
const parameterResolveArgument = injectMetadata.forwardArgumentMapper?.(resolveArgument) ?? injectMetadata.resolveArgumentProvider?.(this.getResolveContext(context, getChain(injectToken)));
|
|
362
|
-
if ((0, import_type_guards.isPromise)(parameterResolveArgument)) {
|
|
363
|
-
throw new import_resolve_error.ResolveError(`Cannot evaluate async argument provider for token ${(0, import_token.getTokenName)(token)} in synchronous resolve, use resolveAsync instead.`, getChain(injectToken));
|
|
364
|
-
}
|
|
365
|
-
if ((0, import_type_guards.isDefined)(injectMetadata.forwardRefToken)) {
|
|
366
|
-
const forwardRef = import_forward_ref.ForwardRef.create();
|
|
367
|
-
const forwardRefToken = injectMetadata.forwardRefToken;
|
|
368
|
-
context.forwardRefQueue.add(() => {
|
|
369
|
-
const forwardToken = (0, import_type_guards.isFunction)(forwardRefToken) ? forwardRefToken() : forwardRefToken;
|
|
370
|
-
if ((0, import_type_guards.isDefined)(injectMetadata.mapper)) {
|
|
371
|
-
throw new import_resolve_error.ResolveError("Cannot use inject mapper with forwardRef.", getChain(forwardToken));
|
|
372
|
-
}
|
|
373
|
-
const resolved2 = this._resolve(forwardToken, injectMetadata.optional, parameterResolveArgument, context, getChain(forwardToken), false);
|
|
374
|
-
import_forward_ref.ForwardRef.setRef(forwardRef, resolved2);
|
|
375
|
-
});
|
|
376
|
-
context.forwardRefs.add(forwardRef);
|
|
377
|
-
return forwardRef;
|
|
378
|
-
}
|
|
379
|
-
const resolved = this._resolve(injectToken, injectMetadata.optional, parameterResolveArgument, context, getChain(injectToken), false);
|
|
380
|
-
return (0, import_type_guards.isDefined)(injectMetadata.mapper) ? injectMetadata.mapper(resolved) : resolved;
|
|
381
|
-
}
|
|
382
|
-
async resolveInjectionAsync(context, typeMetadata, metadata, resolveArgument, chain) {
|
|
383
|
-
const getChain = metadata.metadataType == "constructor-parameter" ? (injectToken2) => chain.addParameter(typeMetadata.constructor, metadata.index, injectToken2).addToken(injectToken2) : (injectToken2) => chain.addProperty(typeMetadata.constructor, metadata.key, injectToken2).addToken(injectToken2);
|
|
384
|
-
const injectMetadata = metadata.data.tryGet(injectMetadataSymbol) ?? {};
|
|
385
|
-
const injectToken = injectMetadata.injectToken ?? metadata.type;
|
|
386
|
-
if ((0, import_type_guards.isDefined)(injectMetadata.injectArgumentMapper) && (!this.hasRegistration(injectToken) || (0, import_type_guards.isDefined)(resolveArgument) || (0, import_type_guards.isUndefined)(injectToken))) {
|
|
387
|
-
return { resolved: injectMetadata.injectArgumentMapper(resolveArgument) };
|
|
388
|
-
}
|
|
389
|
-
const parameterResolveArgument = await (injectMetadata.forwardArgumentMapper?.(resolveArgument) ?? injectMetadata.resolveArgumentProvider?.(this.getResolveContext(context, getChain(injectToken))));
|
|
390
|
-
if ((0, import_type_guards.isDefined)(injectMetadata.forwardRefToken)) {
|
|
391
|
-
const forwardRef = import_forward_ref.ForwardRef.create();
|
|
392
|
-
const forwardRefToken = injectMetadata.forwardRefToken;
|
|
393
|
-
context.forwardRefQueue.add(async () => {
|
|
394
|
-
const forwardToken = (0, import_type_guards.isFunction)(forwardRefToken) ? forwardRefToken() : forwardRefToken;
|
|
395
|
-
if ((0, import_type_guards.isDefined)(injectMetadata.mapper)) {
|
|
396
|
-
throw new import_resolve_error.ResolveError("Cannot use inject mapper with forwardRef.", getChain(forwardToken));
|
|
397
|
-
}
|
|
398
|
-
const resolved2 = await this._resolveAsync(forwardToken, injectMetadata.optional, parameterResolveArgument, context, getChain(forwardToken), false);
|
|
399
|
-
import_forward_ref.ForwardRef.setRef(forwardRef, resolved2);
|
|
400
|
-
});
|
|
401
|
-
context.forwardRefs.add(forwardRef);
|
|
402
|
-
return { resolved: forwardRef };
|
|
403
|
-
}
|
|
404
|
-
const resolved = await this._resolveAsync(injectToken, injectMetadata.optional, parameterResolveArgument, context, getChain(injectToken), false);
|
|
405
|
-
return { resolved: (0, import_type_guards.isDefined)(injectMetadata.mapper) ? injectMetadata.mapper(resolved) : resolved };
|
|
406
|
-
}
|
|
407
|
-
getResolveContext(resolveContext, chain) {
|
|
408
|
-
const context = {
|
|
409
|
-
isAsync: resolveContext.isAsync,
|
|
410
|
-
resolve: (token, argument, instances) => {
|
|
411
|
-
this.addInstancesToResolveContext(instances, resolveContext);
|
|
412
|
-
return this._resolve(token, false, argument, resolveContext, chain.addToken(token), false);
|
|
413
|
-
},
|
|
414
|
-
resolveAsync: async (token, argument, instances) => {
|
|
415
|
-
this.addInstancesToResolveContext(instances, resolveContext);
|
|
416
|
-
return this._resolveAsync(token, false, argument, resolveContext, chain.addToken(token), false);
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
return context;
|
|
420
|
-
}
|
|
421
|
-
addInstancesToResolveContext(instances, resolveContext) {
|
|
422
|
-
if ((0, import_type_guards.isUndefined)(instances)) {
|
|
423
|
-
return;
|
|
1
|
+
import { CircularBuffer } from '../data-structures/circular-buffer.js';
|
|
2
|
+
import { MultiKeyMap } from '../data-structures/multi-key-map.js';
|
|
3
|
+
import { reflectionRegistry } from '../reflection/index.js';
|
|
4
|
+
import { mapAsync } from '../utils/async-iterable-helpers/map.js';
|
|
5
|
+
import { toArrayAsync } from '../utils/async-iterable-helpers/to-array.js';
|
|
6
|
+
import { ForwardRef } from '../utils/object/forward-ref.js';
|
|
7
|
+
import { objectEntries } from '../utils/object/object.js';
|
|
8
|
+
import { isDefined, isFunction, isPromise, isUndefined } from '../utils/type-guards.js';
|
|
9
|
+
import { Subject } from 'rxjs';
|
|
10
|
+
import { afterResolve } from './interfaces.js';
|
|
11
|
+
import { isClassProvider, isFactoryProvider, isTokenProvider, isValueProvider } from './provider.js';
|
|
12
|
+
import { ResolveChain } from './resolve-chain.js';
|
|
13
|
+
import { ResolveError } from './resolve.error.js';
|
|
14
|
+
import { getTokenName } from './token.js';
|
|
15
|
+
import { isStubClass } from './utils.js';
|
|
16
|
+
export const injectMetadataSymbol = Symbol('Inject metadata');
|
|
17
|
+
export class Container {
|
|
18
|
+
registrationMap;
|
|
19
|
+
registrationSubject;
|
|
20
|
+
/** emits on new registration */
|
|
21
|
+
registration$;
|
|
22
|
+
/** all registrations */
|
|
23
|
+
get registrations() {
|
|
24
|
+
return this.registrationMap.values();
|
|
25
|
+
}
|
|
26
|
+
constructor() {
|
|
27
|
+
this.registrationMap = new Map();
|
|
28
|
+
this.registrationSubject = new Subject();
|
|
29
|
+
this.registration$ = this.registrationSubject.asObservable();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* register a provider for a token
|
|
33
|
+
* @param token token to register
|
|
34
|
+
* @param provider provider used to resolve the token
|
|
35
|
+
* @param options registration options
|
|
36
|
+
*/
|
|
37
|
+
register(token, provider, options = {}) {
|
|
38
|
+
if (isClassProvider(provider) && !isStubClass(provider.useClass)) {
|
|
39
|
+
const injectable = reflectionRegistry.getMetadata(provider.useClass)?.data.has(injectMetadataSymbol) ?? false;
|
|
40
|
+
if (!injectable) {
|
|
41
|
+
throw new Error(`${provider.useClass.name} is not injectable.`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const registration = {
|
|
45
|
+
token,
|
|
46
|
+
provider,
|
|
47
|
+
options,
|
|
48
|
+
instances: new Map()
|
|
49
|
+
};
|
|
50
|
+
this.registrationMap.set(token, registration);
|
|
51
|
+
this.registrationSubject.next(registration);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
|
|
55
|
+
* @param token token to register
|
|
56
|
+
* @param provider provider used to resolve the token
|
|
57
|
+
* @param options registration options
|
|
58
|
+
*/
|
|
59
|
+
registerSingleton(token, provider, options) {
|
|
60
|
+
this.register(token, provider, { ...options, lifecycle: 'singleton' });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* check if token has a registered provider
|
|
64
|
+
* @param token token check
|
|
65
|
+
*/
|
|
66
|
+
hasRegistration(token) {
|
|
67
|
+
return this.registrationMap.has(token);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* get registration
|
|
71
|
+
* @param token token to get registration for
|
|
72
|
+
*/
|
|
73
|
+
getRegistration(token) {
|
|
74
|
+
const registration = this.registrationMap.get(token);
|
|
75
|
+
if (isUndefined(registration)) {
|
|
76
|
+
const tokenName = getTokenName(token);
|
|
77
|
+
throw new Error(`No provider for ${tokenName} registered.`);
|
|
78
|
+
}
|
|
79
|
+
return registration;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* try to get registration
|
|
83
|
+
* @param token token to get registration for
|
|
84
|
+
*/
|
|
85
|
+
tryGetRegistration(token) {
|
|
86
|
+
return this.registrationMap.get(token);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* resolve a token
|
|
90
|
+
* @param token token to resolve
|
|
91
|
+
* @param argument argument used for resolving (overrides token and default arguments)
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
94
|
+
resolve(token, argument, instances) {
|
|
95
|
+
const context = {
|
|
96
|
+
isAsync: false,
|
|
97
|
+
resolves: 0,
|
|
98
|
+
forwardRefQueue: new CircularBuffer(),
|
|
99
|
+
resolutions: [],
|
|
100
|
+
forwardRefs: new Set(),
|
|
101
|
+
providedInstances: new Map(instances),
|
|
102
|
+
instances: new MultiKeyMap(),
|
|
103
|
+
resolving: new MultiKeyMap()
|
|
104
|
+
};
|
|
105
|
+
return this._resolve(token, false, argument, context, ResolveChain.startWith(token), true);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* resolve a token
|
|
109
|
+
* @param token token to resolve
|
|
110
|
+
* @param argument argument used for resolving (overrides token and default arguments)
|
|
111
|
+
* @returns
|
|
112
|
+
*/
|
|
113
|
+
async resolveAsync(token, argument, instances) {
|
|
114
|
+
const context = {
|
|
115
|
+
isAsync: true,
|
|
116
|
+
resolves: 0,
|
|
117
|
+
forwardRefQueue: new CircularBuffer(),
|
|
118
|
+
resolutions: [],
|
|
119
|
+
forwardRefs: new Set(),
|
|
120
|
+
providedInstances: new Map(instances),
|
|
121
|
+
instances: new MultiKeyMap(),
|
|
122
|
+
resolving: new MultiKeyMap()
|
|
123
|
+
};
|
|
124
|
+
return this._resolveAsync(token, false, argument, context, ResolveChain.startWith(token), true);
|
|
125
|
+
}
|
|
126
|
+
// eslint-disable-next-line max-statements, max-lines-per-function, complexity
|
|
127
|
+
_resolve(token, optional, _argument, context, chain, isFirst) {
|
|
128
|
+
if ((chain.length > 750) || (++context.resolves > 750)) {
|
|
129
|
+
throw new ResolveError('Resolve stack overflow. This can happen on circular dependencies with transient lifecycles and self reference. Use scoped or singleton lifecycle instead or @forwardRef().', chain);
|
|
130
|
+
}
|
|
131
|
+
if (isUndefined(token)) {
|
|
132
|
+
throw new ResolveError('Token is undefined - this might be because of circular dependencies, use alias or forwardRef in this case.', chain);
|
|
133
|
+
}
|
|
134
|
+
if (context.providedInstances.has(token)) {
|
|
135
|
+
return context.providedInstances.get(token);
|
|
136
|
+
}
|
|
137
|
+
const registration = this.tryGetRegistration(token);
|
|
138
|
+
if (isUndefined(registration)) {
|
|
139
|
+
if (optional == true) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
throw new ResolveError(`No provider for ${getTokenName(token)} registered.`, chain);
|
|
143
|
+
}
|
|
144
|
+
const resolveArgument = _argument ?? registration.options.defaultArgument ?? registration.options.defaultArgumentProvider?.(this.getResolveContext(context, chain));
|
|
145
|
+
if (isPromise(resolveArgument)) {
|
|
146
|
+
throw new ResolveError(`Cannot evaluate async argument provider for token ${getTokenName(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
147
|
+
}
|
|
148
|
+
const argumentIdentity = (isDefined(registration.options.argumentIdentityProvider) && ((registration.options.lifecycle == 'resolution') || (registration.options.lifecycle == 'singleton')))
|
|
149
|
+
? registration.options.argumentIdentityProvider(resolveArgument)
|
|
150
|
+
: resolveArgument;
|
|
151
|
+
if (isPromise(argumentIdentity)) {
|
|
152
|
+
throw new ResolveError(`Cannot evaluate async argument identity provider for token ${getTokenName(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
153
|
+
}
|
|
154
|
+
if ((registration.options.lifecycle == 'resolution') && context.instances.has([token, argumentIdentity])) {
|
|
155
|
+
return context.instances.get([token, argumentIdentity]);
|
|
156
|
+
}
|
|
157
|
+
if ((registration.options.lifecycle == 'singleton') && registration.instances.has(argumentIdentity)) {
|
|
158
|
+
return registration.instances.get(argumentIdentity);
|
|
159
|
+
}
|
|
160
|
+
if (context.resolving.has([token, argumentIdentity])) {
|
|
161
|
+
throw new ResolveError('Circular dependency to itself detected. Please check your registrations and providers. @forwardRef might be a solution.', chain);
|
|
162
|
+
}
|
|
163
|
+
context.resolving.set([token, argumentIdentity], true);
|
|
164
|
+
let instance;
|
|
165
|
+
if (isClassProvider(registration.provider)) {
|
|
166
|
+
const typeMetadata = reflectionRegistry.getMetadata(registration.provider.useClass);
|
|
167
|
+
if (isUndefined(typeMetadata) || !typeMetadata.data.has(injectMetadataSymbol)) {
|
|
168
|
+
throw new ResolveError(`${registration.provider.useClass.name} is not injectable.`, chain);
|
|
169
|
+
}
|
|
170
|
+
if (isStubClass(typeMetadata.constructor)) {
|
|
171
|
+
throw new ResolveError(`No provider for ${getTokenName(token)} registered.`, chain);
|
|
172
|
+
}
|
|
173
|
+
const parameters = (typeMetadata.parameters ?? []).map((metadata) => this.resolveInjection(token, context, typeMetadata, metadata, resolveArgument, chain));
|
|
174
|
+
instance = new typeMetadata.constructor(...parameters);
|
|
175
|
+
for (const [property, metadata] of typeMetadata.properties) {
|
|
176
|
+
if (!metadata.data.has(injectMetadataSymbol)) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
instance[property] = this.resolveInjection(token, context, typeMetadata, metadata, resolveArgument, chain);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (isValueProvider(registration.provider)) {
|
|
183
|
+
instance = registration.provider.useValue;
|
|
184
|
+
}
|
|
185
|
+
if (isTokenProvider(registration.provider)) {
|
|
186
|
+
const arg = resolveArgument ?? registration.provider.argument ?? registration.provider.argumentProvider?.();
|
|
187
|
+
const innerToken = registration.provider.useToken ?? registration.provider.useTokenProvider();
|
|
188
|
+
if (isPromise(arg)) {
|
|
189
|
+
throw new ResolveError(`Cannot evaluate async argument provider for token ${getTokenName(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
190
|
+
}
|
|
191
|
+
if (isPromise(innerToken)) {
|
|
192
|
+
throw new ResolveError(`Cannot evaluate async token provider for token ${getTokenName(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
193
|
+
}
|
|
194
|
+
instance = this._resolve(innerToken, false, arg, context, chain.addToken(innerToken), false);
|
|
195
|
+
}
|
|
196
|
+
if (isFactoryProvider(registration.provider)) {
|
|
197
|
+
try {
|
|
198
|
+
const result = registration.provider.useFactory(resolveArgument, this.getResolveContext(context, chain));
|
|
199
|
+
if (isPromise(result)) {
|
|
200
|
+
throw new ResolveError(`Cannot evaluate async factory provider for token ${getTokenName(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
201
|
+
}
|
|
202
|
+
instance = result;
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
throw new ResolveError('Error in factory.', chain, error);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (registration.options.lifecycle == 'resolution') {
|
|
209
|
+
context.instances.set([token, argumentIdentity], instance);
|
|
210
|
+
}
|
|
211
|
+
if (registration.options.lifecycle == 'singleton') {
|
|
212
|
+
registration.instances.set(argumentIdentity, instance);
|
|
213
|
+
}
|
|
214
|
+
context.resolutions.push({ instance, registration });
|
|
215
|
+
context.resolving.delete([token, argumentIdentity]);
|
|
216
|
+
if (isFirst) {
|
|
217
|
+
for (const fn of context.forwardRefQueue.consume()) {
|
|
218
|
+
fn();
|
|
219
|
+
}
|
|
220
|
+
derefForwardRefs(context);
|
|
221
|
+
for (let i = context.resolutions.length - 1; i >= 0; i--) {
|
|
222
|
+
const resolution = context.resolutions[i];
|
|
223
|
+
if (isFunction(resolution.instance?.[afterResolve])) {
|
|
224
|
+
const returnValue = resolution.instance[afterResolve]();
|
|
225
|
+
if (isPromise(returnValue)) {
|
|
226
|
+
throw new ResolveError(`Cannot execute async [afterResolve] for token ${getTokenName(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (isDefined(resolution.registration.options.initializer)) {
|
|
230
|
+
const returnValue = resolution.registration.options.initializer(resolution.instance);
|
|
231
|
+
if (isPromise(returnValue)) {
|
|
232
|
+
throw new ResolveError(`Cannot execute async initializer for token ${getTokenName(token)} in synchronous resolve, use resolveAsync instead.`, chain);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return instance;
|
|
424
238
|
}
|
|
425
|
-
|
|
426
|
-
|
|
239
|
+
// eslint-disable-next-line max-statements, max-lines-per-function, complexity
|
|
240
|
+
async _resolveAsync(token, optional, _argument, context, chain, isFirst) {
|
|
241
|
+
if ((chain.length > 750) || (++context.resolves > 750)) {
|
|
242
|
+
throw new ResolveError('Resolve stack overflow. This can happen on circular dependencies with transient lifecycles and self reference. Use scoped or singleton lifecycle instead or @forwardRef().', chain);
|
|
243
|
+
}
|
|
244
|
+
if (isUndefined(token)) {
|
|
245
|
+
throw new ResolveError('Token is undefined - this might be because of circular dependencies, use alias or forwardRef in this case.', chain);
|
|
246
|
+
}
|
|
247
|
+
if (context.providedInstances.has(token)) {
|
|
248
|
+
return context.providedInstances.get(token);
|
|
249
|
+
}
|
|
250
|
+
const registration = this.tryGetRegistration(token);
|
|
251
|
+
if (isUndefined(registration)) {
|
|
252
|
+
if (optional == true) {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
throw new ResolveError(`No provider for ${getTokenName(token)} registered.`, chain);
|
|
256
|
+
}
|
|
257
|
+
const resolveArgument = _argument ?? registration.options.defaultArgument ?? (await registration.options.defaultArgumentProvider?.(this.getResolveContext(context, chain)));
|
|
258
|
+
const argumentIdentity = (isDefined(registration.options.argumentIdentityProvider) && ((registration.options.lifecycle == 'resolution') || (registration.options.lifecycle == 'singleton')))
|
|
259
|
+
? await registration.options.argumentIdentityProvider(resolveArgument)
|
|
260
|
+
: resolveArgument;
|
|
261
|
+
if ((registration.options.lifecycle == 'resolution') && context.instances.has([token, argumentIdentity])) {
|
|
262
|
+
return context.instances.get([token, argumentIdentity]);
|
|
263
|
+
}
|
|
264
|
+
if ((registration.options.lifecycle == 'singleton') && registration.instances.has(argumentIdentity)) {
|
|
265
|
+
return registration.instances.get(argumentIdentity);
|
|
266
|
+
}
|
|
267
|
+
if (context.resolving.has([token, argumentIdentity])) {
|
|
268
|
+
throw new ResolveError('Circular dependency to itself detected. Please check your registrations and providers. @forwardRef might be a solution.', chain);
|
|
269
|
+
}
|
|
270
|
+
context.resolving.set([token, argumentIdentity], true);
|
|
271
|
+
let instance;
|
|
272
|
+
if (isClassProvider(registration.provider)) {
|
|
273
|
+
const typeMetadata = reflectionRegistry.getMetadata(registration.provider.useClass);
|
|
274
|
+
if (isUndefined(typeMetadata) || !typeMetadata.data.has(injectMetadataSymbol)) {
|
|
275
|
+
throw new ResolveError(`${registration.provider.useClass.name} is not injectable.`, chain);
|
|
276
|
+
}
|
|
277
|
+
if (isStubClass(typeMetadata.constructor)) {
|
|
278
|
+
throw new ResolveError(`No provider for ${getTokenName(token)} registered.`, chain);
|
|
279
|
+
}
|
|
280
|
+
const boxedParameters = await toArrayAsync(mapAsync(typeMetadata.parameters ?? [], async (metadata) => this.resolveInjectionAsync(context, typeMetadata, metadata, resolveArgument, chain)));
|
|
281
|
+
const parameters = boxedParameters.map((box) => box.resolved);
|
|
282
|
+
instance = new typeMetadata.constructor(...parameters);
|
|
283
|
+
for (const [property, metadata] of typeMetadata.properties) {
|
|
284
|
+
if (!metadata.data.has(injectMetadataSymbol)) {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
instance[property] = (await this.resolveInjectionAsync(context, typeMetadata, metadata, resolveArgument, chain)).resolved;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (isValueProvider(registration.provider)) {
|
|
291
|
+
instance = registration.provider.useValue;
|
|
292
|
+
}
|
|
293
|
+
if (isTokenProvider(registration.provider)) {
|
|
294
|
+
const arg = resolveArgument ?? registration.provider.argument ?? await registration.provider.argumentProvider?.();
|
|
295
|
+
const innerToken = registration.provider.useToken ?? await registration.provider.useTokenProvider();
|
|
296
|
+
instance = await this._resolveAsync(innerToken, false, arg, context, chain.addToken(innerToken), false);
|
|
297
|
+
}
|
|
298
|
+
if (isFactoryProvider(registration.provider)) {
|
|
299
|
+
try {
|
|
300
|
+
instance = await registration.provider.useFactory(resolveArgument, this.getResolveContext(context, chain));
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
throw new ResolveError('Error in factory.', chain, error);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (registration.options.lifecycle == 'resolution') {
|
|
307
|
+
context.instances.set([token, argumentIdentity], instance);
|
|
308
|
+
}
|
|
309
|
+
if (registration.options.lifecycle == 'singleton') {
|
|
310
|
+
registration.instances.set(argumentIdentity, instance);
|
|
311
|
+
}
|
|
312
|
+
context.resolutions.push({ instance, registration });
|
|
313
|
+
context.resolving.delete([token, argumentIdentity]);
|
|
314
|
+
if (isFirst) {
|
|
315
|
+
for (const fn of context.forwardRefQueue.consume()) {
|
|
316
|
+
await fn();
|
|
317
|
+
}
|
|
318
|
+
derefForwardRefs(context);
|
|
319
|
+
for (let i = context.resolutions.length - 1; i >= 0; i--) {
|
|
320
|
+
const resolution = context.resolutions[i];
|
|
321
|
+
if (isFunction(resolution.instance?.[afterResolve])) {
|
|
322
|
+
await resolution.instance[afterResolve]();
|
|
323
|
+
}
|
|
324
|
+
if (isDefined(resolution.registration.options.initializer)) {
|
|
325
|
+
await resolution.registration.options.initializer(resolution.instance);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return instance;
|
|
330
|
+
}
|
|
331
|
+
resolveInjection(token, context, typeMetadata, metadata, resolveArgument, chain) {
|
|
332
|
+
const getChain = (metadata.metadataType == 'constructor-parameter')
|
|
333
|
+
? (injectToken) => chain.addParameter(typeMetadata.constructor, metadata.index, injectToken).addToken(injectToken)
|
|
334
|
+
: (injectToken) => chain.addProperty(typeMetadata.constructor, metadata.key, injectToken).addToken(injectToken);
|
|
335
|
+
const injectMetadata = metadata.data.tryGet(injectMetadataSymbol) ?? {};
|
|
336
|
+
const injectToken = (injectMetadata.injectToken ?? metadata.type);
|
|
337
|
+
if (isDefined(injectMetadata.injectArgumentMapper) && (!this.hasRegistration(injectToken) || isDefined(resolveArgument) || isUndefined(injectToken))) {
|
|
338
|
+
const mapped = injectMetadata.injectArgumentMapper(resolveArgument);
|
|
339
|
+
if (isPromise(mapped)) {
|
|
340
|
+
throw new ResolveError(`Cannot evaluate async argument mapper for token ${getTokenName(token)} in synchronous resolve, use resolveAsync instead.`, getChain(injectToken));
|
|
341
|
+
}
|
|
342
|
+
return mapped;
|
|
343
|
+
}
|
|
344
|
+
const parameterResolveArgument = injectMetadata.forwardArgumentMapper?.(resolveArgument) ?? injectMetadata.resolveArgumentProvider?.(this.getResolveContext(context, getChain(injectToken)));
|
|
345
|
+
if (isPromise(parameterResolveArgument)) {
|
|
346
|
+
throw new ResolveError(`Cannot evaluate async argument provider for token ${getTokenName(token)} in synchronous resolve, use resolveAsync instead.`, getChain(injectToken));
|
|
347
|
+
}
|
|
348
|
+
if (isDefined(injectMetadata.forwardRefToken)) {
|
|
349
|
+
const forwardRef = ForwardRef.create();
|
|
350
|
+
const forwardRefToken = injectMetadata.forwardRefToken;
|
|
351
|
+
context.forwardRefQueue.add(() => {
|
|
352
|
+
const forwardToken = isFunction(forwardRefToken) ? forwardRefToken() : forwardRefToken;
|
|
353
|
+
if (isDefined(injectMetadata.mapper)) {
|
|
354
|
+
throw new ResolveError('Cannot use inject mapper with forwardRef.', getChain(forwardToken));
|
|
355
|
+
}
|
|
356
|
+
const resolved = this._resolve(forwardToken, injectMetadata.optional, parameterResolveArgument, context, getChain(forwardToken), false);
|
|
357
|
+
ForwardRef.setRef(forwardRef, resolved);
|
|
358
|
+
});
|
|
359
|
+
context.forwardRefs.add(forwardRef);
|
|
360
|
+
return forwardRef;
|
|
361
|
+
}
|
|
362
|
+
const resolved = this._resolve(injectToken, injectMetadata.optional, parameterResolveArgument, context, getChain(injectToken), false);
|
|
363
|
+
return isDefined(injectMetadata.mapper) ? injectMetadata.mapper(resolved) : resolved;
|
|
364
|
+
}
|
|
365
|
+
async resolveInjectionAsync(context, typeMetadata, metadata, resolveArgument, chain) {
|
|
366
|
+
const getChain = (metadata.metadataType == 'constructor-parameter')
|
|
367
|
+
? (injectToken) => chain.addParameter(typeMetadata.constructor, metadata.index, injectToken).addToken(injectToken)
|
|
368
|
+
: (injectToken) => chain.addProperty(typeMetadata.constructor, metadata.key, injectToken).addToken(injectToken);
|
|
369
|
+
const injectMetadata = metadata.data.tryGet(injectMetadataSymbol) ?? {};
|
|
370
|
+
const injectToken = (injectMetadata.injectToken ?? metadata.type);
|
|
371
|
+
if (isDefined(injectMetadata.injectArgumentMapper) && (!this.hasRegistration(injectToken) || isDefined(resolveArgument) || isUndefined(injectToken))) {
|
|
372
|
+
return { resolved: injectMetadata.injectArgumentMapper(resolveArgument) };
|
|
373
|
+
}
|
|
374
|
+
const parameterResolveArgument = await (injectMetadata.forwardArgumentMapper?.(resolveArgument) ?? injectMetadata.resolveArgumentProvider?.(this.getResolveContext(context, getChain(injectToken))));
|
|
375
|
+
if (isDefined(injectMetadata.forwardRefToken)) {
|
|
376
|
+
const forwardRef = ForwardRef.create();
|
|
377
|
+
const forwardRefToken = injectMetadata.forwardRefToken;
|
|
378
|
+
context.forwardRefQueue.add(async () => {
|
|
379
|
+
const forwardToken = isFunction(forwardRefToken) ? forwardRefToken() : forwardRefToken;
|
|
380
|
+
if (isDefined(injectMetadata.mapper)) {
|
|
381
|
+
throw new ResolveError('Cannot use inject mapper with forwardRef.', getChain(forwardToken));
|
|
382
|
+
}
|
|
383
|
+
const resolved = await this._resolveAsync(forwardToken, injectMetadata.optional, parameterResolveArgument, context, getChain(forwardToken), false);
|
|
384
|
+
ForwardRef.setRef(forwardRef, resolved);
|
|
385
|
+
});
|
|
386
|
+
context.forwardRefs.add(forwardRef);
|
|
387
|
+
return { resolved: forwardRef };
|
|
388
|
+
}
|
|
389
|
+
const resolved = await this._resolveAsync(injectToken, injectMetadata.optional, parameterResolveArgument, context, getChain(injectToken), false);
|
|
390
|
+
return { resolved: isDefined(injectMetadata.mapper) ? injectMetadata.mapper(resolved) : resolved };
|
|
391
|
+
}
|
|
392
|
+
getResolveContext(resolveContext, chain) {
|
|
393
|
+
const context = {
|
|
394
|
+
isAsync: resolveContext.isAsync,
|
|
395
|
+
resolve: (token, argument, instances) => {
|
|
396
|
+
this.addInstancesToResolveContext(instances, resolveContext);
|
|
397
|
+
return this._resolve(token, false, argument, resolveContext, chain.addToken(token), false);
|
|
398
|
+
},
|
|
399
|
+
resolveAsync: async (token, argument, instances) => {
|
|
400
|
+
this.addInstancesToResolveContext(instances, resolveContext);
|
|
401
|
+
return this._resolveAsync(token, false, argument, resolveContext, chain.addToken(token), false);
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
return context;
|
|
405
|
+
}
|
|
406
|
+
addInstancesToResolveContext(instances, resolveContext) {
|
|
407
|
+
if (isUndefined(instances)) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
for (const [instanceToken, instance] of instances) {
|
|
411
|
+
resolveContext.providedInstances.set(instanceToken, instance);
|
|
412
|
+
}
|
|
427
413
|
}
|
|
428
|
-
}
|
|
429
414
|
}
|
|
430
415
|
function derefForwardRefs(context) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
416
|
+
for (const resolution of context.resolutions) {
|
|
417
|
+
if (!(typeof resolution.instance == 'object')) {
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
for (const [key, value] of objectEntries(resolution.instance)) {
|
|
421
|
+
if (!context.forwardRefs.has(value)) {
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
resolution.instance[key] = ForwardRef.deref(value);
|
|
425
|
+
}
|
|
440
426
|
}
|
|
441
|
-
}
|
|
442
427
|
}
|
|
443
|
-
const container = new Container();
|
|
428
|
+
export const container = new Container();
|