@tstdl/base 0.93.182 → 0.93.184
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/server/api-request-token.provider.js +1 -1
- package/api/server/gateway.js +6 -1
- package/authentication/authentication.api.d.ts +13 -40
- package/authentication/authentication.api.js +5 -14
- package/authentication/client/authentication.service.d.ts +6 -14
- package/authentication/client/authentication.service.js +22 -4
- package/authentication/client/module.d.ts +1 -1
- package/authentication/client/module.js +4 -4
- package/authentication/models/index.d.ts +1 -0
- package/authentication/models/index.js +1 -0
- package/authentication/models/totp-results.model.d.ts +11 -0
- package/authentication/models/totp-results.model.js +37 -0
- package/authentication/server/authentication.api-controller.d.ts +3 -3
- package/authentication/server/authentication.api-controller.js +31 -4
- package/authentication/server/authentication.service.d.ts +5 -14
- package/authentication/server/authentication.service.js +6 -4
- package/core.d.ts +0 -5
- package/core.js +0 -8
- package/document-management/api/document-management.api.d.ts +2 -2
- package/document-management/service-models/document.service-model.d.ts +1 -1
- package/examples/config.d.ts +25 -0
- package/examples/config.js +26 -0
- package/notification/server/module.d.ts +1 -1
- package/notification/server/module.js +1 -1
- package/package.json +5 -5
- package/signals/api.d.ts +5 -1
- package/signals/api.js +3 -1
- package/signals/implementation/api.d.ts +10 -1
- package/signals/implementation/api.js +7 -1
- package/signals/implementation/asserts.d.ts +2 -2
- package/signals/implementation/asserts.js +3 -3
- package/signals/implementation/computed.d.ts +7 -34
- package/signals/implementation/computed.js +14 -83
- package/signals/implementation/configure.js +6 -2
- package/signals/implementation/effect.d.ts +65 -46
- package/signals/implementation/effect.js +97 -62
- package/signals/implementation/index.d.ts +2 -4
- package/signals/implementation/index.js +2 -4
- package/signals/implementation/linked_signal.d.ts +36 -0
- package/signals/implementation/linked_signal.js +34 -0
- package/signals/implementation/primitive/computed.d.ts +55 -0
- package/signals/implementation/primitive/computed.js +107 -0
- package/signals/implementation/primitive/effect.d.ts +26 -0
- package/signals/implementation/primitive/effect.js +31 -0
- package/signals/implementation/{equality.d.ts → primitive/equality.d.ts} +1 -1
- package/signals/implementation/{equality.js → primitive/equality.js} +1 -1
- package/signals/implementation/primitive/errors.d.ts +10 -0
- package/signals/implementation/{errors.js → primitive/errors.js} +3 -4
- package/signals/implementation/primitive/formatter.d.ts +19 -0
- package/signals/implementation/primitive/formatter.js +136 -0
- package/signals/implementation/{graph.d.ts → primitive/graph.d.ts} +68 -36
- package/signals/implementation/primitive/graph.js +386 -0
- package/signals/implementation/primitive/linked_signal.d.ts +46 -0
- package/signals/implementation/primitive/linked_signal.js +110 -0
- package/signals/implementation/primitive/signal.d.ts +31 -0
- package/signals/implementation/primitive/signal.js +80 -0
- package/signals/implementation/primitive/untracked.d.ts +12 -0
- package/signals/implementation/primitive/untracked.js +23 -0
- package/signals/implementation/{watch.d.ts → primitive/watch.d.ts} +1 -2
- package/signals/implementation/{watch.js → primitive/watch.js} +22 -16
- package/signals/implementation/resource/api.d.ts +275 -0
- package/signals/implementation/resource/api.js +26 -0
- package/signals/implementation/resource/debounce.d.ts +13 -0
- package/signals/implementation/resource/debounce.js +113 -0
- package/signals/implementation/resource/from_snapshots.d.ts +16 -0
- package/signals/implementation/resource/from_snapshots.js +44 -0
- package/signals/implementation/resource/index.d.ts +11 -0
- package/signals/implementation/resource/index.js +11 -0
- package/signals/implementation/resource/resource.d.ts +110 -0
- package/signals/implementation/resource/resource.js +402 -0
- package/signals/implementation/root_effect_scheduler.d.ts +50 -0
- package/signals/implementation/root_effect_scheduler.js +66 -0
- package/signals/implementation/signal.d.ts +42 -18
- package/signals/implementation/signal.js +29 -49
- package/signals/implementation/to-observable.d.ts +12 -5
- package/signals/implementation/to-observable.js +12 -2
- package/signals/implementation/to-signal.d.ts +9 -18
- package/signals/implementation/to-signal.js +46 -13
- package/signals/implementation/untracked.d.ts +1 -1
- package/signals/implementation/untracked.js +3 -11
- package/signals/operators/debounce.d.ts +8 -0
- package/signals/operators/debounce.js +19 -0
- package/signals/operators/derive-async.js +43 -15
- package/signals/operators/index.d.ts +2 -0
- package/signals/operators/index.js +2 -0
- package/signals/operators/throttle.d.ts +8 -0
- package/signals/operators/throttle.js +31 -0
- package/ai/genkit/tests/multi-region.test.d.ts +0 -2
- package/ai/genkit/tests/multi-region.test.js +0 -179
- package/ai/genkit/tests/token-limit-fallback.test.d.ts +0 -2
- package/ai/genkit/tests/token-limit-fallback.test.js +0 -209
- package/ai/prompts/tests/prompt-builder.test.d.ts +0 -1
- package/ai/prompts/tests/prompt-builder.test.js +0 -22
- package/ai/tests/instructions-formatter.test.d.ts +0 -1
- package/ai/tests/instructions-formatter.test.js +0 -116
- package/ai/tests/steering.test.d.ts +0 -1
- package/ai/tests/steering.test.js +0 -37
- package/api/client/tests/api-client.test.d.ts +0 -1
- package/api/client/tests/api-client.test.js +0 -194
- package/api/server/tests/csrf.middleware.test.d.ts +0 -1
- package/api/server/tests/csrf.middleware.test.js +0 -91
- package/authentication/tests/authentication-password-requirements.validator.test.d.ts +0 -1
- package/authentication/tests/authentication-password-requirements.validator.test.js +0 -29
- package/authentication/tests/authentication.api-controller.test.d.ts +0 -1
- package/authentication/tests/authentication.api-controller.test.js +0 -156
- package/authentication/tests/authentication.api-request-token.provider.test.d.ts +0 -1
- package/authentication/tests/authentication.api-request-token.provider.test.js +0 -48
- package/authentication/tests/authentication.client-error-handling.test.d.ts +0 -1
- package/authentication/tests/authentication.client-error-handling.test.js +0 -123
- package/authentication/tests/authentication.client-middleware.test.d.ts +0 -1
- package/authentication/tests/authentication.client-middleware.test.js +0 -118
- package/authentication/tests/authentication.client-service-methods.test.d.ts +0 -1
- package/authentication/tests/authentication.client-service-methods.test.js +0 -177
- package/authentication/tests/authentication.client-service-refresh.test.d.ts +0 -1
- package/authentication/tests/authentication.client-service-refresh.test.js +0 -153
- package/authentication/tests/authentication.client-service.test.d.ts +0 -1
- package/authentication/tests/authentication.client-service.test.js +0 -76
- package/authentication/tests/authentication.refresh-busy-loop.test.d.ts +0 -1
- package/authentication/tests/authentication.refresh-busy-loop.test.js +0 -84
- package/authentication/tests/authentication.service.test.d.ts +0 -1
- package/authentication/tests/authentication.service.test.js +0 -167
- package/authentication/tests/authentication.test-ancillary-service.d.ts +0 -9
- package/authentication/tests/authentication.test-ancillary-service.js +0 -27
- package/authentication/tests/brute-force-protection.test.d.ts +0 -1
- package/authentication/tests/brute-force-protection.test.js +0 -211
- package/authentication/tests/helper.test.d.ts +0 -1
- package/authentication/tests/helper.test.js +0 -122
- package/authentication/tests/password-requirements.error.test.d.ts +0 -1
- package/authentication/tests/password-requirements.error.test.js +0 -14
- package/authentication/tests/remember.api.test.d.ts +0 -1
- package/authentication/tests/remember.api.test.js +0 -117
- package/authentication/tests/remember.service.test.d.ts +0 -1
- package/authentication/tests/remember.service.test.js +0 -83
- package/authentication/tests/subject.service.test.d.ts +0 -1
- package/authentication/tests/subject.service.test.js +0 -140
- package/authentication/tests/suspended-subject.test.d.ts +0 -1
- package/authentication/tests/suspended-subject.test.js +0 -120
- package/authentication/tests/totp.enrollment.test.d.ts +0 -1
- package/authentication/tests/totp.enrollment.test.js +0 -123
- package/authentication/tests/totp.login.test.d.ts +0 -1
- package/authentication/tests/totp.login.test.js +0 -213
- package/authentication/tests/totp.recovery-codes.test.d.ts +0 -1
- package/authentication/tests/totp.recovery-codes.test.js +0 -97
- package/authentication/tests/totp.status.test.d.ts +0 -1
- package/authentication/tests/totp.status.test.js +0 -72
- package/cancellation/tests/coverage.test.d.ts +0 -1
- package/cancellation/tests/coverage.test.js +0 -49
- package/cancellation/tests/leak.test.d.ts +0 -1
- package/cancellation/tests/leak.test.js +0 -35
- package/cancellation/tests/token.test.d.ts +0 -1
- package/cancellation/tests/token.test.js +0 -136
- package/circuit-breaker/tests/circuit-breaker.test.d.ts +0 -1
- package/circuit-breaker/tests/circuit-breaker.test.js +0 -116
- package/cryptography/tests/cryptography.test.d.ts +0 -1
- package/cryptography/tests/cryptography.test.js +0 -175
- package/cryptography/tests/jwt.test.d.ts +0 -1
- package/cryptography/tests/jwt.test.js +0 -54
- package/cryptography/tests/modern.test.d.ts +0 -1
- package/cryptography/tests/modern.test.js +0 -105
- package/cryptography/tests/module.test.d.ts +0 -1
- package/cryptography/tests/module.test.js +0 -100
- package/cryptography/tests/totp.test.d.ts +0 -1
- package/cryptography/tests/totp.test.js +0 -108
- package/document-management/tests/ai-config-hierarchy.test.d.ts +0 -1
- package/document-management/tests/ai-config-hierarchy.test.js +0 -59
- package/document-management/tests/ai-config-integration.test.d.ts +0 -1
- package/document-management/tests/ai-config-integration.test.js +0 -125
- package/document-management/tests/ai-config-merge.test.d.ts +0 -1
- package/document-management/tests/ai-config-merge.test.js +0 -46
- package/document-management/tests/document-management-ai-overrides.test.d.ts +0 -1
- package/document-management/tests/document-management-ai-overrides.test.js +0 -63
- package/document-management/tests/document-management-core.test.d.ts +0 -1
- package/document-management/tests/document-management-core.test.js +0 -157
- package/document-management/tests/document-management.api.test.d.ts +0 -1
- package/document-management/tests/document-management.api.test.js +0 -101
- package/document-management/tests/document-statistics.service.test.d.ts +0 -1
- package/document-management/tests/document-statistics.service.test.js +0 -498
- package/document-management/tests/document-validation-ai-overrides.test.d.ts +0 -1
- package/document-management/tests/document-validation-ai-overrides.test.js +0 -87
- package/document-management/tests/document.service.test.d.ts +0 -1
- package/document-management/tests/document.service.test.js +0 -143
- package/document-management/tests/enum-helpers.test.d.ts +0 -1
- package/document-management/tests/enum-helpers.test.js +0 -452
- package/document-management/tests/helper.d.ts +0 -24
- package/document-management/tests/helper.js +0 -39
- package/errors/tests/format.test.d.ts +0 -1
- package/errors/tests/format.test.js +0 -84
- package/http/tests/server-timing.test.d.ts +0 -1
- package/http/tests/server-timing.test.js +0 -42
- package/injector/tests/advanced.test.d.ts +0 -1
- package/injector/tests/advanced.test.js +0 -116
- package/injector/tests/async-init.test.d.ts +0 -1
- package/injector/tests/async-init.test.js +0 -77
- package/injector/tests/basic.test.d.ts +0 -1
- package/injector/tests/basic.test.js +0 -114
- package/injector/tests/hierarchical.test.d.ts +0 -1
- package/injector/tests/hierarchical.test.js +0 -59
- package/injector/tests/leak.test.d.ts +0 -1
- package/injector/tests/leak.test.js +0 -45
- package/injector/tests/lifecycles.test.d.ts +0 -1
- package/injector/tests/lifecycles.test.js +0 -109
- package/logger/tests/pretty-print.test.d.ts +0 -1
- package/logger/tests/pretty-print.test.js +0 -60
- package/notification/tests/notification-api.test.d.ts +0 -1
- package/notification/tests/notification-api.test.js +0 -124
- package/notification/tests/notification-client.test.d.ts +0 -1
- package/notification/tests/notification-client.test.js +0 -101
- package/notification/tests/notification-flow.test.d.ts +0 -1
- package/notification/tests/notification-flow.test.js +0 -296
- package/notification/tests/notification-sse.service.test.d.ts +0 -1
- package/notification/tests/notification-sse.service.test.js +0 -43
- package/notification/tests/notification-type.service.test.d.ts +0 -1
- package/notification/tests/notification-type.service.test.js +0 -41
- package/object-storage/s3/tests/s3.object-storage.integration.test.d.ts +0 -1
- package/object-storage/s3/tests/s3.object-storage.integration.test.js +0 -303
- package/orm/tests/build-jsonb.test.d.ts +0 -1
- package/orm/tests/build-jsonb.test.js +0 -39
- package/orm/tests/data-types.test.d.ts +0 -1
- package/orm/tests/data-types.test.js +0 -39
- package/orm/tests/database-extension.test.d.ts +0 -1
- package/orm/tests/database-extension.test.js +0 -63
- package/orm/tests/database-migration.test.d.ts +0 -1
- package/orm/tests/database-migration.test.js +0 -83
- package/orm/tests/decorators.test.d.ts +0 -1
- package/orm/tests/decorators.test.js +0 -77
- package/orm/tests/encryption.test.d.ts +0 -1
- package/orm/tests/encryption.test.js +0 -31
- package/orm/tests/query-complex.test.d.ts +0 -1
- package/orm/tests/query-complex.test.js +0 -172
- package/orm/tests/query-converter-complex.test.d.ts +0 -1
- package/orm/tests/query-converter-complex.test.js +0 -131
- package/orm/tests/query-converter.test.d.ts +0 -1
- package/orm/tests/query-converter.test.js +0 -123
- package/orm/tests/repository-advanced.test.d.ts +0 -1
- package/orm/tests/repository-advanced.test.js +0 -189
- package/orm/tests/repository-attributes.test.d.ts +0 -1
- package/orm/tests/repository-attributes.test.js +0 -83
- package/orm/tests/repository-compound-primary-key.test.d.ts +0 -2
- package/orm/tests/repository-compound-primary-key.test.js +0 -226
- package/orm/tests/repository-comprehensive.test.d.ts +0 -1
- package/orm/tests/repository-comprehensive.test.js +0 -162
- package/orm/tests/repository-coverage.test.d.ts +0 -2
- package/orm/tests/repository-coverage.test.js +0 -242
- package/orm/tests/repository-cti-complex.test.d.ts +0 -1
- package/orm/tests/repository-cti-complex.test.js +0 -151
- package/orm/tests/repository-cti-embedded.test.d.ts +0 -1
- package/orm/tests/repository-cti-embedded.test.js +0 -178
- package/orm/tests/repository-cti-extensive.test.d.ts +0 -2
- package/orm/tests/repository-cti-extensive.test.js +0 -279
- package/orm/tests/repository-cti-mapping.test.d.ts +0 -2
- package/orm/tests/repository-cti-mapping.test.js +0 -108
- package/orm/tests/repository-cti-search.test.d.ts +0 -1
- package/orm/tests/repository-cti-search.test.js +0 -141
- package/orm/tests/repository-cti-soft-delete.test.d.ts +0 -2
- package/orm/tests/repository-cti-soft-delete.test.js +0 -103
- package/orm/tests/repository-cti-transactions.test.d.ts +0 -1
- package/orm/tests/repository-cti-transactions.test.js +0 -112
- package/orm/tests/repository-cti-upsert-many.test.d.ts +0 -2
- package/orm/tests/repository-cti-upsert-many.test.js +0 -115
- package/orm/tests/repository-cti.test.d.ts +0 -2
- package/orm/tests/repository-cti.test.js +0 -390
- package/orm/tests/repository-edge-cases.test.d.ts +0 -1
- package/orm/tests/repository-edge-cases.test.js +0 -178
- package/orm/tests/repository-expiration.test.d.ts +0 -2
- package/orm/tests/repository-expiration.test.js +0 -140
- package/orm/tests/repository-extra-coverage.test.d.ts +0 -2
- package/orm/tests/repository-extra-coverage.test.js +0 -402
- package/orm/tests/repository-mapping.test.d.ts +0 -2
- package/orm/tests/repository-mapping.test.js +0 -65
- package/orm/tests/repository-regression.test.d.ts +0 -1
- package/orm/tests/repository-regression.test.js +0 -288
- package/orm/tests/repository-search-coverage.test.d.ts +0 -1
- package/orm/tests/repository-search-coverage.test.js +0 -107
- package/orm/tests/repository-search.test.d.ts +0 -1
- package/orm/tests/repository-search.test.js +0 -105
- package/orm/tests/repository-soft-delete.test.d.ts +0 -1
- package/orm/tests/repository-soft-delete.test.js +0 -118
- package/orm/tests/repository-transactions-nested.test.d.ts +0 -1
- package/orm/tests/repository-transactions-nested.test.js +0 -178
- package/orm/tests/repository-types.test.d.ts +0 -1
- package/orm/tests/repository-types.test.js +0 -184
- package/orm/tests/repository-undelete.test.d.ts +0 -2
- package/orm/tests/repository-undelete.test.js +0 -201
- package/orm/tests/schema-converter.test.d.ts +0 -1
- package/orm/tests/schema-converter.test.js +0 -82
- package/orm/tests/schema-generation.test.d.ts +0 -2
- package/orm/tests/schema-generation.test.js +0 -174
- package/orm/tests/sql-helpers.test.d.ts +0 -1
- package/orm/tests/sql-helpers.test.js +0 -67
- package/orm/tests/transaction-safety.test.d.ts +0 -1
- package/orm/tests/transaction-safety.test.js +0 -81
- package/orm/tests/transactional.test.d.ts +0 -1
- package/orm/tests/transactional.test.js +0 -215
- package/orm/tests/utils.test.d.ts +0 -1
- package/orm/tests/utils.test.js +0 -70
- package/pdf/tests/utils.test.d.ts +0 -1
- package/pdf/tests/utils.test.js +0 -187
- package/process/tests/spawn.test.d.ts +0 -1
- package/process/tests/spawn.test.js +0 -182
- package/rate-limit/tests/postgres-rate-limiter.test.d.ts +0 -1
- package/rate-limit/tests/postgres-rate-limiter.test.js +0 -84
- package/renderer/tests/renderer.test.d.ts +0 -1
- package/renderer/tests/renderer.test.js +0 -88
- package/rpc/tests/rpc.integration.test.d.ts +0 -1
- package/rpc/tests/rpc.integration.test.js +0 -615
- package/signals/implementation/errors.d.ts +0 -2
- package/signals/implementation/graph.js +0 -312
- package/signals/implementation/writable-signal.d.ts +0 -48
- package/signals/implementation/writable-signal.js +0 -32
- package/task-queue/tests/coverage-branch.test.d.ts +0 -1
- package/task-queue/tests/coverage-branch.test.js +0 -395
- package/task-queue/tests/coverage-enhancement.test.d.ts +0 -1
- package/task-queue/tests/coverage-enhancement.test.js +0 -150
- package/task-queue/tests/dag.test.d.ts +0 -1
- package/task-queue/tests/dag.test.js +0 -188
- package/task-queue/tests/dependencies.test.d.ts +0 -1
- package/task-queue/tests/dependencies.test.js +0 -296
- package/task-queue/tests/enqueue-batch.test.d.ts +0 -1
- package/task-queue/tests/enqueue-batch.test.js +0 -125
- package/task-queue/tests/enqueue-item.test.d.ts +0 -1
- package/task-queue/tests/enqueue-item.test.js +0 -12
- package/task-queue/tests/fan-out-spawning.test.d.ts +0 -1
- package/task-queue/tests/fan-out-spawning.test.js +0 -94
- package/task-queue/tests/idempotent-replacement.test.d.ts +0 -1
- package/task-queue/tests/idempotent-replacement.test.js +0 -114
- package/task-queue/tests/missing-idempotent-tasks.test.d.ts +0 -1
- package/task-queue/tests/missing-idempotent-tasks.test.js +0 -39
- package/task-queue/tests/optimization-edge-cases.test.d.ts +0 -1
- package/task-queue/tests/optimization-edge-cases.test.js +0 -124
- package/task-queue/tests/queue-generic.test.d.ts +0 -1
- package/task-queue/tests/queue-generic.test.js +0 -8
- package/task-queue/tests/queue.test.d.ts +0 -1
- package/task-queue/tests/queue.test.js +0 -756
- package/task-queue/tests/shutdown.test.d.ts +0 -1
- package/task-queue/tests/shutdown.test.js +0 -41
- package/task-queue/tests/task-context.test.d.ts +0 -1
- package/task-queue/tests/task-context.test.js +0 -7
- package/task-queue/tests/task-union.test.d.ts +0 -1
- package/task-queue/tests/task-union.test.js +0 -18
- package/task-queue/tests/transactions.test.d.ts +0 -1
- package/task-queue/tests/transactions.test.js +0 -47
- package/task-queue/tests/typing.test.d.ts +0 -1
- package/task-queue/tests/typing.test.js +0 -9
- package/task-queue/tests/worker.test.d.ts +0 -1
- package/task-queue/tests/worker.test.js +0 -258
- package/task-queue/tests/zombie-parent.test.d.ts +0 -1
- package/task-queue/tests/zombie-parent.test.js +0 -45
- package/task-queue/tests/zombie-recovery.test.d.ts +0 -1
- package/task-queue/tests/zombie-recovery.test.js +0 -51
- package/utils/tests/backoff.test.d.ts +0 -1
- package/utils/tests/backoff.test.js +0 -41
- package/utils/tests/retry-with-backoff.test.d.ts +0 -1
- package/utils/tests/retry-with-backoff.test.js +0 -49
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { describe, expect, test } from 'vitest';
|
|
8
|
-
import '../../polyfills.js';
|
|
9
|
-
import { afterResolve, forwardRef, inject, injectAll, injectArgument, Injectable, injectionToken, Injector, Singleton } from '../index.js';
|
|
10
|
-
describe('Injector Advanced', () => {
|
|
11
|
-
test('forwardRef for circular dependencies', () => {
|
|
12
|
-
let ServiceB = class ServiceB {
|
|
13
|
-
a = inject(forwardRef(() => ServiceA));
|
|
14
|
-
};
|
|
15
|
-
ServiceB = __decorate([
|
|
16
|
-
Singleton()
|
|
17
|
-
], ServiceB);
|
|
18
|
-
let ServiceA = class ServiceA {
|
|
19
|
-
b = inject(ServiceB);
|
|
20
|
-
};
|
|
21
|
-
ServiceA = __decorate([
|
|
22
|
-
Singleton()
|
|
23
|
-
], ServiceA);
|
|
24
|
-
const injector = new Injector('test');
|
|
25
|
-
const a = injector.resolve(ServiceA);
|
|
26
|
-
const b = injector.resolve(ServiceB);
|
|
27
|
-
expect(a.b).toBe(b);
|
|
28
|
-
expect(b.a).toBe(a);
|
|
29
|
-
});
|
|
30
|
-
test('multi-providers and injectAll', () => {
|
|
31
|
-
const PLUGIN = injectionToken('PLUGIN');
|
|
32
|
-
const injector = new Injector('test');
|
|
33
|
-
injector.register(PLUGIN, { useValue: 'plugin1' }, { multi: true });
|
|
34
|
-
injector.register(PLUGIN, { useValue: 'plugin2' }, { multi: true });
|
|
35
|
-
let Consumer = class Consumer {
|
|
36
|
-
plugins = injectAll(PLUGIN);
|
|
37
|
-
};
|
|
38
|
-
Consumer = __decorate([
|
|
39
|
-
Injectable()
|
|
40
|
-
], Consumer);
|
|
41
|
-
const consumer = injector.resolve(Consumer);
|
|
42
|
-
expect(consumer.plugins).toEqual(['plugin1', 'plugin2']);
|
|
43
|
-
});
|
|
44
|
-
test('resolution arguments and injectArgument', () => {
|
|
45
|
-
let Target = class Target {
|
|
46
|
-
arg = injectArgument();
|
|
47
|
-
};
|
|
48
|
-
Target = __decorate([
|
|
49
|
-
Injectable()
|
|
50
|
-
], Target);
|
|
51
|
-
const injector = new Injector('test');
|
|
52
|
-
const instance = injector.resolve(Target, { value: 'test-arg' });
|
|
53
|
-
expect(instance.arg.value).toBe('test-arg');
|
|
54
|
-
});
|
|
55
|
-
test('optional dependencies', () => {
|
|
56
|
-
const MISSING = injectionToken('MISSING');
|
|
57
|
-
let Consumer = class Consumer {
|
|
58
|
-
missing = inject(MISSING, undefined, { optional: true });
|
|
59
|
-
};
|
|
60
|
-
Consumer = __decorate([
|
|
61
|
-
Injectable()
|
|
62
|
-
], Consumer);
|
|
63
|
-
const injector = new Injector('test');
|
|
64
|
-
const consumer = injector.resolve(Consumer);
|
|
65
|
-
expect(consumer.missing).toBeUndefined();
|
|
66
|
-
});
|
|
67
|
-
test('automatic cleanup on injector disposal', async () => {
|
|
68
|
-
let disposed = false;
|
|
69
|
-
let DisposableService = class DisposableService {
|
|
70
|
-
async [Symbol.asyncDispose]() {
|
|
71
|
-
disposed = true;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
DisposableService = __decorate([
|
|
75
|
-
Singleton()
|
|
76
|
-
], DisposableService);
|
|
77
|
-
const injector = new Injector('test');
|
|
78
|
-
injector.resolve(DisposableService);
|
|
79
|
-
expect(disposed).toBe(false);
|
|
80
|
-
await injector.dispose();
|
|
81
|
-
expect(disposed).toBe(true);
|
|
82
|
-
});
|
|
83
|
-
test('addDisposeHandler in afterResolve', async () => {
|
|
84
|
-
let disposed = false;
|
|
85
|
-
let ManualService = class ManualService {
|
|
86
|
-
async [afterResolve](_arg, { addDisposeHandler }) {
|
|
87
|
-
addDisposeHandler(() => { disposed = true; });
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
ManualService = __decorate([
|
|
91
|
-
Singleton()
|
|
92
|
-
], ManualService);
|
|
93
|
-
const injector = new Injector('test');
|
|
94
|
-
await injector.resolveAsync(ManualService);
|
|
95
|
-
expect(disposed).toBe(false);
|
|
96
|
-
await injector.dispose();
|
|
97
|
-
expect(disposed).toBe(true);
|
|
98
|
-
});
|
|
99
|
-
test('factory using inject', () => {
|
|
100
|
-
const VAL = injectionToken('VAL');
|
|
101
|
-
let Dep = class Dep {
|
|
102
|
-
value = 42;
|
|
103
|
-
};
|
|
104
|
-
Dep = __decorate([
|
|
105
|
-
Singleton()
|
|
106
|
-
], Dep);
|
|
107
|
-
const injector = new Injector('test');
|
|
108
|
-
injector.register(VAL, {
|
|
109
|
-
useFactory: () => {
|
|
110
|
-
const dep = inject(Dep);
|
|
111
|
-
return dep.value * 2;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
expect(injector.resolve(VAL)).toBe(84);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '../../polyfills.js';
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { describe, expect, test } from 'vitest';
|
|
8
|
-
import '../../polyfills.js';
|
|
9
|
-
import { afterResolve, inject, Injector, runInInjectionContext, Singleton, injectAsync } from '../index.js';
|
|
10
|
-
describe('Injector Async Initialization', () => {
|
|
11
|
-
test('should call [afterResolve] and wait for it with resolveAsync', async () => {
|
|
12
|
-
let AsyncService = class AsyncService {
|
|
13
|
-
initialized = false;
|
|
14
|
-
async [afterResolve]() {
|
|
15
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
16
|
-
this.initialized = true;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
AsyncService = __decorate([
|
|
20
|
-
Singleton()
|
|
21
|
-
], AsyncService);
|
|
22
|
-
const injector = new Injector('test');
|
|
23
|
-
const instance = await injector.resolveAsync(AsyncService);
|
|
24
|
-
expect(instance.initialized).toBe(true);
|
|
25
|
-
});
|
|
26
|
-
test('should use injectAsync in [afterResolve] to await dependency', async () => {
|
|
27
|
-
let Dependency = class Dependency {
|
|
28
|
-
initialized = false;
|
|
29
|
-
async [afterResolve]() {
|
|
30
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
31
|
-
this.initialized = true;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
Dependency = __decorate([
|
|
35
|
-
Singleton()
|
|
36
|
-
], Dependency);
|
|
37
|
-
let Consumer = class Consumer {
|
|
38
|
-
dependency;
|
|
39
|
-
async [afterResolve]() {
|
|
40
|
-
this.dependency = await injectAsync(Dependency);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
Consumer = __decorate([
|
|
44
|
-
Singleton()
|
|
45
|
-
], Consumer);
|
|
46
|
-
const injector = new Injector('test');
|
|
47
|
-
const consumer = await runInInjectionContext(injector, () => injector.resolveAsync(Consumer));
|
|
48
|
-
expect(consumer.dependency?.initialized).toBe(true);
|
|
49
|
-
});
|
|
50
|
-
test('should support multiple async dependencies', async () => {
|
|
51
|
-
let Dep1 = class Dep1 {
|
|
52
|
-
done = false;
|
|
53
|
-
async [afterResolve]() { this.done = true; }
|
|
54
|
-
};
|
|
55
|
-
Dep1 = __decorate([
|
|
56
|
-
Singleton()
|
|
57
|
-
], Dep1);
|
|
58
|
-
let Dep2 = class Dep2 {
|
|
59
|
-
done = false;
|
|
60
|
-
async [afterResolve]() { this.done = true; }
|
|
61
|
-
};
|
|
62
|
-
Dep2 = __decorate([
|
|
63
|
-
Singleton()
|
|
64
|
-
], Dep2);
|
|
65
|
-
let Consumer = class Consumer {
|
|
66
|
-
d1 = inject(Dep1);
|
|
67
|
-
d2 = inject(Dep2);
|
|
68
|
-
};
|
|
69
|
-
Consumer = __decorate([
|
|
70
|
-
Singleton()
|
|
71
|
-
], Consumer);
|
|
72
|
-
const injector = new Injector('test');
|
|
73
|
-
const consumer = await injector.resolveAsync(Consumer);
|
|
74
|
-
expect(consumer.d1.done).toBe(true);
|
|
75
|
-
expect(consumer.d2.done).toBe(true);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '../../polyfills.js';
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { describe, expect, test } from 'vitest';
|
|
8
|
-
import '../../polyfills.js';
|
|
9
|
-
import { inject, Inject, Injectable, injectionToken, Injector, Singleton } from '../index.js';
|
|
10
|
-
describe('Injector Basic', () => {
|
|
11
|
-
test('should resolve a singleton class', () => {
|
|
12
|
-
let TestService = class TestService {
|
|
13
|
-
id = Math.random();
|
|
14
|
-
};
|
|
15
|
-
TestService = __decorate([
|
|
16
|
-
Singleton()
|
|
17
|
-
], TestService);
|
|
18
|
-
const injector = new Injector('test');
|
|
19
|
-
const instance1 = injector.resolve(TestService);
|
|
20
|
-
const instance2 = injector.resolve(TestService);
|
|
21
|
-
expect(instance1).toBeInstanceOf(TestService);
|
|
22
|
-
expect(instance1.id).toBe(instance2.id);
|
|
23
|
-
});
|
|
24
|
-
test('should resolve a transient class', () => {
|
|
25
|
-
let TestService = class TestService {
|
|
26
|
-
id = Math.random();
|
|
27
|
-
};
|
|
28
|
-
TestService = __decorate([
|
|
29
|
-
Injectable()
|
|
30
|
-
], TestService);
|
|
31
|
-
const injector = new Injector('test');
|
|
32
|
-
const instance1 = injector.resolve(TestService);
|
|
33
|
-
const instance2 = injector.resolve(TestService);
|
|
34
|
-
expect(instance1).toBeInstanceOf(TestService);
|
|
35
|
-
expect(instance1.id).not.toBe(instance2.id);
|
|
36
|
-
});
|
|
37
|
-
test('should use property injection with inject()', () => {
|
|
38
|
-
let Dependency = class Dependency {
|
|
39
|
-
value = 'dependency';
|
|
40
|
-
};
|
|
41
|
-
Dependency = __decorate([
|
|
42
|
-
Singleton()
|
|
43
|
-
], Dependency);
|
|
44
|
-
let Consumer = class Consumer {
|
|
45
|
-
dependency = inject(Dependency);
|
|
46
|
-
};
|
|
47
|
-
Consumer = __decorate([
|
|
48
|
-
Singleton()
|
|
49
|
-
], Consumer);
|
|
50
|
-
const injector = new Injector('test');
|
|
51
|
-
const consumer = injector.resolve(Consumer);
|
|
52
|
-
expect(consumer.dependency).toBeInstanceOf(Dependency);
|
|
53
|
-
expect(consumer.dependency.value).toBe('dependency');
|
|
54
|
-
});
|
|
55
|
-
test('should support manual registration with useValue', () => {
|
|
56
|
-
const TOKEN = injectionToken('TOKEN');
|
|
57
|
-
const injector = new Injector('test');
|
|
58
|
-
injector.register(TOKEN, { useValue: 'manual-value' });
|
|
59
|
-
const value = injector.resolve(TOKEN);
|
|
60
|
-
expect(value).toBe('manual-value');
|
|
61
|
-
});
|
|
62
|
-
test('should support manual registration with useClass', () => {
|
|
63
|
-
class AbstractService {
|
|
64
|
-
}
|
|
65
|
-
let Implementation = class Implementation extends AbstractService {
|
|
66
|
-
getValue() { return 'impl'; }
|
|
67
|
-
};
|
|
68
|
-
Implementation = __decorate([
|
|
69
|
-
Injectable()
|
|
70
|
-
], Implementation);
|
|
71
|
-
const injector = new Injector('test');
|
|
72
|
-
injector.register(AbstractService, { useClass: Implementation });
|
|
73
|
-
const instance = injector.resolve(AbstractService);
|
|
74
|
-
expect(instance).toBeInstanceOf(Implementation);
|
|
75
|
-
expect(instance.getValue()).toBe('impl');
|
|
76
|
-
});
|
|
77
|
-
test('should support manual registration with useFactory', () => {
|
|
78
|
-
const TOKEN = injectionToken('TOKEN');
|
|
79
|
-
const injector = new Injector('test');
|
|
80
|
-
let counter = 0;
|
|
81
|
-
injector.register(TOKEN, { useFactory: () => ++counter });
|
|
82
|
-
expect(injector.resolve(TOKEN)).toBe(1);
|
|
83
|
-
expect(injector.resolve(TOKEN)).toBe(2);
|
|
84
|
-
});
|
|
85
|
-
test('should support global registration', () => {
|
|
86
|
-
const GLOBAL_TOKEN = injectionToken('GLOBAL_TOKEN');
|
|
87
|
-
Injector.register(GLOBAL_TOKEN, { useValue: 'global' });
|
|
88
|
-
const injector = new Injector('test');
|
|
89
|
-
expect(injector.resolve(GLOBAL_TOKEN)).toBe('global');
|
|
90
|
-
});
|
|
91
|
-
test('should support nested dependency injection', () => {
|
|
92
|
-
let Level3 = class Level3 {
|
|
93
|
-
value = 'l3';
|
|
94
|
-
};
|
|
95
|
-
Level3 = __decorate([
|
|
96
|
-
Singleton()
|
|
97
|
-
], Level3);
|
|
98
|
-
let Level2 = class Level2 {
|
|
99
|
-
l3 = inject(Level3);
|
|
100
|
-
};
|
|
101
|
-
Level2 = __decorate([
|
|
102
|
-
Singleton()
|
|
103
|
-
], Level2);
|
|
104
|
-
let Level1 = class Level1 {
|
|
105
|
-
l2 = inject(Level2);
|
|
106
|
-
};
|
|
107
|
-
Level1 = __decorate([
|
|
108
|
-
Singleton()
|
|
109
|
-
], Level1);
|
|
110
|
-
const injector = new Injector('test');
|
|
111
|
-
const l1 = injector.resolve(Level1);
|
|
112
|
-
expect(l1.l2.l3.value).toBe('l3');
|
|
113
|
-
});
|
|
114
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '../../polyfills.js';
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { describe, expect, test } from 'vitest';
|
|
8
|
-
import '../../polyfills.js';
|
|
9
|
-
import { Injectable, injectionToken, Injector, Singleton } from '../index.js';
|
|
10
|
-
describe('Injector Hierarchical', () => {
|
|
11
|
-
test('child should resolve from parent', () => {
|
|
12
|
-
const TOKEN = injectionToken('TOKEN');
|
|
13
|
-
const parent = new Injector('parent');
|
|
14
|
-
parent.register(TOKEN, { useValue: 'parent-value' });
|
|
15
|
-
const child = parent.fork('child');
|
|
16
|
-
expect(child.resolve(TOKEN)).toBe('parent-value');
|
|
17
|
-
});
|
|
18
|
-
test('child should override parent provider', () => {
|
|
19
|
-
const TOKEN = injectionToken('TOKEN');
|
|
20
|
-
const parent = new Injector('parent');
|
|
21
|
-
parent.register(TOKEN, { useValue: 'parent-value' });
|
|
22
|
-
const child = parent.fork('child');
|
|
23
|
-
child.register(TOKEN, { useValue: 'child-value' });
|
|
24
|
-
expect(child.resolve(TOKEN)).toBe('child-value');
|
|
25
|
-
expect(parent.resolve(TOKEN)).toBe('parent-value');
|
|
26
|
-
});
|
|
27
|
-
test('onlySelf should not resolve from parent', () => {
|
|
28
|
-
const TOKEN = injectionToken('TOKEN');
|
|
29
|
-
const parent = new Injector('parent');
|
|
30
|
-
parent.register(TOKEN, { useValue: 'parent-value' });
|
|
31
|
-
const child = parent.fork('child');
|
|
32
|
-
expect(() => child.resolve(TOKEN, undefined, { onlySelf: true })).toThrow(/No provider for .*TOKEN.* registered\./);
|
|
33
|
-
});
|
|
34
|
-
test('skipSelf should skip child and resolve from parent', () => {
|
|
35
|
-
const TOKEN = injectionToken('TOKEN');
|
|
36
|
-
const parent = new Injector('parent');
|
|
37
|
-
parent.register(TOKEN, { useValue: 'parent-value' });
|
|
38
|
-
const child = parent.fork('child');
|
|
39
|
-
child.register(TOKEN, { useValue: 'child-value' });
|
|
40
|
-
expect(child.resolve(TOKEN, undefined, { skipSelf: true })).toBe('parent-value');
|
|
41
|
-
});
|
|
42
|
-
test('injector scoped service should be unique per child', () => {
|
|
43
|
-
let ScopedService = class ScopedService {
|
|
44
|
-
id = Math.random();
|
|
45
|
-
};
|
|
46
|
-
ScopedService = __decorate([
|
|
47
|
-
Injectable()
|
|
48
|
-
], ScopedService);
|
|
49
|
-
const parent = new Injector('parent');
|
|
50
|
-
parent.register(ScopedService, { useClass: ScopedService }, { lifecycle: 'injector' });
|
|
51
|
-
const child1 = parent.fork('child1');
|
|
52
|
-
const child2 = parent.fork('child2');
|
|
53
|
-
const s1 = child1.resolve(ScopedService);
|
|
54
|
-
const s2 = child1.resolve(ScopedService);
|
|
55
|
-
const s3 = child2.resolve(ScopedService);
|
|
56
|
-
expect(s1.id).toBe(s2.id);
|
|
57
|
-
expect(s1.id).not.toBe(s3.id);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { describe, expect, it } from 'vitest';
|
|
8
|
-
import { Injectable } from '../decorators.js';
|
|
9
|
-
import { Injector } from '../injector.js';
|
|
10
|
-
import { injectionToken } from '../token.js';
|
|
11
|
-
describe('Injector Memory Leak', () => {
|
|
12
|
-
it('should not leak memory in #children', async () => {
|
|
13
|
-
const injector = new Injector('TestInjector');
|
|
14
|
-
for (let i = 0; i < 100; i++) {
|
|
15
|
-
const child = injector.fork(`child-${i}`);
|
|
16
|
-
await child.dispose();
|
|
17
|
-
}
|
|
18
|
-
// Since #children is private, we can't easily check it without a getter.
|
|
19
|
-
// But we fixed the code, so let's add a temporary check if we had one.
|
|
20
|
-
// For now, let's just make sure the child.dispose() doesn't throw.
|
|
21
|
-
});
|
|
22
|
-
it('should clear #accesses and #children on dispose', async () => {
|
|
23
|
-
const injector = new Injector('TestInjector');
|
|
24
|
-
const token = injectionToken('test');
|
|
25
|
-
injector.register(token, { useValue: 'test' });
|
|
26
|
-
injector.resolve(token);
|
|
27
|
-
injector.fork('child');
|
|
28
|
-
expect(injector.accesses.length).toBeGreaterThan(0);
|
|
29
|
-
await injector.dispose();
|
|
30
|
-
expect(injector.accesses.length).toBe(0);
|
|
31
|
-
expect(injector.children.length).toBe(0);
|
|
32
|
-
});
|
|
33
|
-
it('should not leak child injectors for transient resolutions without providers', () => {
|
|
34
|
-
const injector = new Injector('TestInjector');
|
|
35
|
-
let TestClass = class TestClass {
|
|
36
|
-
};
|
|
37
|
-
TestClass = __decorate([
|
|
38
|
-
Injectable()
|
|
39
|
-
], TestClass);
|
|
40
|
-
for (let i = 0; i < 100; i++) {
|
|
41
|
-
injector.resolve(TestClass);
|
|
42
|
-
}
|
|
43
|
-
expect(injector.children.length).toBe(0);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '../../polyfills.js';
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import '../../polyfills.js';
|
|
8
|
-
import { describe, expect, test } from 'vitest';
|
|
9
|
-
import { inject, Injectable, Injector, Scoped, Singleton } from '../index.js';
|
|
10
|
-
describe('Injector Lifecycles', () => {
|
|
11
|
-
test('transient lifecycle', () => {
|
|
12
|
-
let TransientService = class TransientService {
|
|
13
|
-
id = Math.random();
|
|
14
|
-
};
|
|
15
|
-
TransientService = __decorate([
|
|
16
|
-
Injectable()
|
|
17
|
-
], TransientService);
|
|
18
|
-
const injector = new Injector('test');
|
|
19
|
-
const instance1 = injector.resolve(TransientService);
|
|
20
|
-
const instance2 = injector.resolve(TransientService);
|
|
21
|
-
expect(instance1.id).not.toBe(instance2.id);
|
|
22
|
-
});
|
|
23
|
-
test('singleton lifecycle', () => {
|
|
24
|
-
let SingletonService = class SingletonService {
|
|
25
|
-
id = Math.random();
|
|
26
|
-
};
|
|
27
|
-
SingletonService = __decorate([
|
|
28
|
-
Singleton()
|
|
29
|
-
], SingletonService);
|
|
30
|
-
const injector = new Injector('test');
|
|
31
|
-
const instance1 = injector.resolve(SingletonService);
|
|
32
|
-
const instance2 = injector.resolve(SingletonService);
|
|
33
|
-
expect(instance1.id).toBe(instance2.id);
|
|
34
|
-
const child = injector.fork('child');
|
|
35
|
-
const instance3 = child.resolve(SingletonService);
|
|
36
|
-
expect(instance3.id).toBe(instance1.id);
|
|
37
|
-
});
|
|
38
|
-
test('injector lifecycle', () => {
|
|
39
|
-
let InjectorScopedService = class InjectorScopedService {
|
|
40
|
-
id = Math.random();
|
|
41
|
-
};
|
|
42
|
-
InjectorScopedService = __decorate([
|
|
43
|
-
Scoped('injector')
|
|
44
|
-
], InjectorScopedService);
|
|
45
|
-
const injector = new Injector('test');
|
|
46
|
-
const instance1 = injector.resolve(InjectorScopedService);
|
|
47
|
-
const instance2 = injector.resolve(InjectorScopedService);
|
|
48
|
-
expect(instance1.id).toBe(instance2.id);
|
|
49
|
-
const child = injector.fork('child');
|
|
50
|
-
const instance3 = child.resolve(InjectorScopedService);
|
|
51
|
-
expect(instance3.id).not.toBe(instance1.id);
|
|
52
|
-
const instance4 = child.resolve(InjectorScopedService);
|
|
53
|
-
expect(instance4.id).toBe(instance3.id);
|
|
54
|
-
});
|
|
55
|
-
test('resolution lifecycle', () => {
|
|
56
|
-
let ResolutionScopedService = class ResolutionScopedService {
|
|
57
|
-
id = Math.random();
|
|
58
|
-
};
|
|
59
|
-
ResolutionScopedService = __decorate([
|
|
60
|
-
Scoped('resolution')
|
|
61
|
-
], ResolutionScopedService);
|
|
62
|
-
let Consumer = class Consumer {
|
|
63
|
-
service1 = inject(ResolutionScopedService);
|
|
64
|
-
service2 = inject(ResolutionScopedService);
|
|
65
|
-
};
|
|
66
|
-
Consumer = __decorate([
|
|
67
|
-
Injectable()
|
|
68
|
-
], Consumer);
|
|
69
|
-
const injector = new Injector('test');
|
|
70
|
-
// Inside one .resolve() call, it should be the same instance
|
|
71
|
-
const consumer = injector.resolve(Consumer);
|
|
72
|
-
expect(consumer.service1.id).toBe(consumer.service2.id);
|
|
73
|
-
// Across different .resolve() calls, it should be different
|
|
74
|
-
const consumer2 = injector.resolve(Consumer);
|
|
75
|
-
expect(consumer2.service1.id).not.toBe(consumer.service1.id);
|
|
76
|
-
});
|
|
77
|
-
test('nested resolution lifecycle', () => {
|
|
78
|
-
let Shared = class Shared {
|
|
79
|
-
id = Math.random();
|
|
80
|
-
};
|
|
81
|
-
Shared = __decorate([
|
|
82
|
-
Scoped('resolution')
|
|
83
|
-
], Shared);
|
|
84
|
-
let Dep1 = class Dep1 {
|
|
85
|
-
shared = inject(Shared);
|
|
86
|
-
};
|
|
87
|
-
Dep1 = __decorate([
|
|
88
|
-
Injectable()
|
|
89
|
-
], Dep1);
|
|
90
|
-
let Dep2 = class Dep2 {
|
|
91
|
-
shared = inject(Shared);
|
|
92
|
-
};
|
|
93
|
-
Dep2 = __decorate([
|
|
94
|
-
Injectable()
|
|
95
|
-
], Dep2);
|
|
96
|
-
let Root = class Root {
|
|
97
|
-
dep1 = inject(Dep1);
|
|
98
|
-
dep2 = inject(Dep2);
|
|
99
|
-
shared = inject(Shared);
|
|
100
|
-
};
|
|
101
|
-
Root = __decorate([
|
|
102
|
-
Injectable()
|
|
103
|
-
], Root);
|
|
104
|
-
const injector = new Injector('test');
|
|
105
|
-
const root = injector.resolve(Root);
|
|
106
|
-
expect(root.shared.id).toBe(root.dep1.shared.id);
|
|
107
|
-
expect(root.shared.id).toBe(root.dep2.shared.id);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
// Mock supports before importing PrettyPrintLogFormatter
|
|
3
|
-
vi.mock('../../supports.js', () => ({
|
|
4
|
-
supportsColoredStdout: true,
|
|
5
|
-
supportsColoredStderr: true,
|
|
6
|
-
}));
|
|
7
|
-
import { PrettyPrintLogFormatter } from '../formatters/pretty-print.js';
|
|
8
|
-
import { LogLevel } from '../level.js';
|
|
9
|
-
describe('PrettyPrintLogFormatter', () => {
|
|
10
|
-
const formatter = new PrettyPrintLogFormatter();
|
|
11
|
-
it('should format a log entry with an error and no context', () => {
|
|
12
|
-
const error = new Error('test error');
|
|
13
|
-
const payload = {
|
|
14
|
-
timestamp: new Date('2026-01-22T13:00:00.000Z'),
|
|
15
|
-
level: LogLevel.Error,
|
|
16
|
-
module: ['Test'],
|
|
17
|
-
message: 'something failed',
|
|
18
|
-
interpolationKeys: [],
|
|
19
|
-
context: {},
|
|
20
|
-
error,
|
|
21
|
-
};
|
|
22
|
-
const formatted = formatter.format(payload);
|
|
23
|
-
expect(formatted).toContain('ERROR:');
|
|
24
|
-
expect(formatted).toContain('[Test]');
|
|
25
|
-
expect(formatted).toContain('something failed');
|
|
26
|
-
expect(formatted).toContain('Error: test error');
|
|
27
|
-
expect(formatted).toContain('at '); // Should include stack trace
|
|
28
|
-
});
|
|
29
|
-
it('should dim stack trace lines', () => {
|
|
30
|
-
const error = new Error('test error');
|
|
31
|
-
const payload = {
|
|
32
|
-
timestamp: new Date('2026-01-22T13:00:00.000Z'),
|
|
33
|
-
level: LogLevel.Error,
|
|
34
|
-
module: ['Test'],
|
|
35
|
-
message: 'something failed',
|
|
36
|
-
interpolationKeys: [],
|
|
37
|
-
context: {},
|
|
38
|
-
error,
|
|
39
|
-
};
|
|
40
|
-
const formatted = formatter.format(payload);
|
|
41
|
-
// Check for dim color escape code \x1b[2m before "at " (including indentation)
|
|
42
|
-
expect(formatted).toContain('\x1b[2m at ');
|
|
43
|
-
});
|
|
44
|
-
it('should highlight "Caused by:" with level color', () => {
|
|
45
|
-
const cause = new Error('the cause');
|
|
46
|
-
const error = new Error('the error', { cause });
|
|
47
|
-
const payload = {
|
|
48
|
-
timestamp: new Date('2026-01-22T13:00:00.000Z'),
|
|
49
|
-
level: LogLevel.Error,
|
|
50
|
-
module: ['Test'],
|
|
51
|
-
message: 'failed',
|
|
52
|
-
interpolationKeys: [],
|
|
53
|
-
context: {},
|
|
54
|
-
error,
|
|
55
|
-
};
|
|
56
|
-
const formatted = formatter.format(payload);
|
|
57
|
-
// LogLevel.Error color is \x1b[31m
|
|
58
|
-
expect(formatted).toContain('\x1b[31mCaused by:');
|
|
59
|
-
});
|
|
60
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|