@theokit/di 0.2.1 → 0.3.1
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/CHANGELOG.md +12 -0
- package/README.md +24 -0
- package/dist/index.cjs +32 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -2
- package/dist/index.d.ts +20 -2
- package/dist/index.js +32 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -240,7 +240,17 @@ declare class Container {
|
|
|
240
240
|
* try/finally guarantees REQUEST-scoped instances are disposed
|
|
241
241
|
* even if the callback throws.
|
|
242
242
|
*/
|
|
243
|
-
runInRequest<R>(callback: () => R | Promise<R
|
|
243
|
+
runInRequest<R>(callback: () => R | Promise<R>, options?: {
|
|
244
|
+
seed?: unknown;
|
|
245
|
+
}): Promise<R>;
|
|
246
|
+
/**
|
|
247
|
+
* The seed of the active request scope, as passed to
|
|
248
|
+
* `runInRequest(cb, { seed })`.
|
|
249
|
+
*
|
|
250
|
+
* @throws ScopeViolationError outside a request scope.
|
|
251
|
+
* @throws MissingRequestSeedError when the scope was opened without a seed.
|
|
252
|
+
*/
|
|
253
|
+
requestSeed<T>(): T;
|
|
244
254
|
/**
|
|
245
255
|
* Debug helper — returns a snapshot of the dependency graph.
|
|
246
256
|
*
|
|
@@ -609,6 +619,14 @@ declare class ScopeViolationError extends Error {
|
|
|
609
619
|
readonly name: "ScopeViolationError";
|
|
610
620
|
constructor(token: Token, message: string);
|
|
611
621
|
}
|
|
622
|
+
/**
|
|
623
|
+
* Thrown by `container.requestSeed()` inside a request scope that was opened
|
|
624
|
+
* without a seed.
|
|
625
|
+
*/
|
|
626
|
+
declare class MissingRequestSeedError extends Error {
|
|
627
|
+
readonly name: "MissingRequestSeedError";
|
|
628
|
+
constructor();
|
|
629
|
+
}
|
|
612
630
|
/**
|
|
613
631
|
* Thrown when a class is registered as a provider (via `useClass` or shorthand)
|
|
614
632
|
* but lacks the `@Injectable()` decorator. The decorator emits
|
|
@@ -755,4 +773,4 @@ declare class CyclicModuleImportError extends Error {
|
|
|
755
773
|
constructor(cycle: ReadonlyArray<string>);
|
|
756
774
|
}
|
|
757
775
|
|
|
758
|
-
export { AsyncPostConstructInSyncResolveError, AsyncProviderInSyncResolveError, type ClassConstructor, type ClassProvider, Container, ContainerDisposedError, ContainerFrozenError, type ContainerOptions, CyclicDependencyError, CyclicModuleImportError, type DependencyGraph, type Disposable, type ExistingProvider, type FactoryProvider, Inject, Injectable, type InjectableOptions, InvalidExportError, InvalidModuleError, METADATA_KEYS, MissingInjectableError, Module, type ModuleMetadata, Optional, PostConstruct, PreDestroy, Primary, type Provider, Qualifier, ReflectMetadataMissingError, type ResolutionContext, Scope, ScopeViolationError, type Token, TokenNotFoundError, type ValueProvider, describeClassName, describeToken };
|
|
776
|
+
export { AsyncPostConstructInSyncResolveError, AsyncProviderInSyncResolveError, type ClassConstructor, type ClassProvider, Container, ContainerDisposedError, ContainerFrozenError, type ContainerOptions, CyclicDependencyError, CyclicModuleImportError, type DependencyGraph, type Disposable, type ExistingProvider, type FactoryProvider, Inject, Injectable, type InjectableOptions, InvalidExportError, InvalidModuleError, METADATA_KEYS, MissingInjectableError, MissingRequestSeedError, Module, type ModuleMetadata, Optional, PostConstruct, PreDestroy, Primary, type Provider, Qualifier, ReflectMetadataMissingError, type ResolutionContext, Scope, ScopeViolationError, type Token, TokenNotFoundError, type ValueProvider, describeClassName, describeToken };
|
package/dist/index.d.ts
CHANGED
|
@@ -240,7 +240,17 @@ declare class Container {
|
|
|
240
240
|
* try/finally guarantees REQUEST-scoped instances are disposed
|
|
241
241
|
* even if the callback throws.
|
|
242
242
|
*/
|
|
243
|
-
runInRequest<R>(callback: () => R | Promise<R
|
|
243
|
+
runInRequest<R>(callback: () => R | Promise<R>, options?: {
|
|
244
|
+
seed?: unknown;
|
|
245
|
+
}): Promise<R>;
|
|
246
|
+
/**
|
|
247
|
+
* The seed of the active request scope, as passed to
|
|
248
|
+
* `runInRequest(cb, { seed })`.
|
|
249
|
+
*
|
|
250
|
+
* @throws ScopeViolationError outside a request scope.
|
|
251
|
+
* @throws MissingRequestSeedError when the scope was opened without a seed.
|
|
252
|
+
*/
|
|
253
|
+
requestSeed<T>(): T;
|
|
244
254
|
/**
|
|
245
255
|
* Debug helper — returns a snapshot of the dependency graph.
|
|
246
256
|
*
|
|
@@ -609,6 +619,14 @@ declare class ScopeViolationError extends Error {
|
|
|
609
619
|
readonly name: "ScopeViolationError";
|
|
610
620
|
constructor(token: Token, message: string);
|
|
611
621
|
}
|
|
622
|
+
/**
|
|
623
|
+
* Thrown by `container.requestSeed()` inside a request scope that was opened
|
|
624
|
+
* without a seed.
|
|
625
|
+
*/
|
|
626
|
+
declare class MissingRequestSeedError extends Error {
|
|
627
|
+
readonly name: "MissingRequestSeedError";
|
|
628
|
+
constructor();
|
|
629
|
+
}
|
|
612
630
|
/**
|
|
613
631
|
* Thrown when a class is registered as a provider (via `useClass` or shorthand)
|
|
614
632
|
* but lacks the `@Injectable()` decorator. The decorator emits
|
|
@@ -755,4 +773,4 @@ declare class CyclicModuleImportError extends Error {
|
|
|
755
773
|
constructor(cycle: ReadonlyArray<string>);
|
|
756
774
|
}
|
|
757
775
|
|
|
758
|
-
export { AsyncPostConstructInSyncResolveError, AsyncProviderInSyncResolveError, type ClassConstructor, type ClassProvider, Container, ContainerDisposedError, ContainerFrozenError, type ContainerOptions, CyclicDependencyError, CyclicModuleImportError, type DependencyGraph, type Disposable, type ExistingProvider, type FactoryProvider, Inject, Injectable, type InjectableOptions, InvalidExportError, InvalidModuleError, METADATA_KEYS, MissingInjectableError, Module, type ModuleMetadata, Optional, PostConstruct, PreDestroy, Primary, type Provider, Qualifier, ReflectMetadataMissingError, type ResolutionContext, Scope, ScopeViolationError, type Token, TokenNotFoundError, type ValueProvider, describeClassName, describeToken };
|
|
776
|
+
export { AsyncPostConstructInSyncResolveError, AsyncProviderInSyncResolveError, type ClassConstructor, type ClassProvider, Container, ContainerDisposedError, ContainerFrozenError, type ContainerOptions, CyclicDependencyError, CyclicModuleImportError, type DependencyGraph, type Disposable, type ExistingProvider, type FactoryProvider, Inject, Injectable, type InjectableOptions, InvalidExportError, InvalidModuleError, METADATA_KEYS, MissingInjectableError, MissingRequestSeedError, Module, type ModuleMetadata, Optional, PostConstruct, PreDestroy, Primary, type Provider, Qualifier, ReflectMetadataMissingError, type ResolutionContext, Scope, ScopeViolationError, type Token, TokenNotFoundError, type ValueProvider, describeClassName, describeToken };
|
package/dist/index.js
CHANGED
|
@@ -73,6 +73,15 @@ var ScopeViolationError = class extends Error {
|
|
|
73
73
|
super(`Scope violation for token ${describeToken(token)}: ${message}`), this.token = token;
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
+
var MissingRequestSeedError = class extends Error {
|
|
77
|
+
static {
|
|
78
|
+
__name(this, "MissingRequestSeedError");
|
|
79
|
+
}
|
|
80
|
+
name = "MissingRequestSeedError";
|
|
81
|
+
constructor() {
|
|
82
|
+
super("The active request scope has no seed. Pass { seed } to runInRequest: container.runInRequest(cb, { seed }).");
|
|
83
|
+
}
|
|
84
|
+
};
|
|
76
85
|
var MissingInjectableError = class extends Error {
|
|
77
86
|
static {
|
|
78
87
|
__name(this, "MissingInjectableError");
|
|
@@ -522,11 +531,14 @@ var Container = class {
|
|
|
522
531
|
* try/finally guarantees REQUEST-scoped instances are disposed
|
|
523
532
|
* even if the callback throws.
|
|
524
533
|
*/
|
|
525
|
-
async runInRequest(callback) {
|
|
534
|
+
async runInRequest(callback, options) {
|
|
526
535
|
this.assertNotDisposed();
|
|
536
|
+
const hasSeed = options !== void 0 && Object.hasOwn(options, "seed");
|
|
527
537
|
const store = {
|
|
528
538
|
cache: /* @__PURE__ */ new Map(),
|
|
529
|
-
instances: []
|
|
539
|
+
instances: [],
|
|
540
|
+
seed: hasSeed ? options.seed : void 0,
|
|
541
|
+
hasSeed
|
|
530
542
|
};
|
|
531
543
|
try {
|
|
532
544
|
return await this.requestStorage.run(store, async () => callback());
|
|
@@ -535,6 +547,23 @@ var Container = class {
|
|
|
535
547
|
}
|
|
536
548
|
}
|
|
537
549
|
/**
|
|
550
|
+
* The seed of the active request scope, as passed to
|
|
551
|
+
* `runInRequest(cb, { seed })`.
|
|
552
|
+
*
|
|
553
|
+
* @throws ScopeViolationError outside a request scope.
|
|
554
|
+
* @throws MissingRequestSeedError when the scope was opened without a seed.
|
|
555
|
+
*/
|
|
556
|
+
requestSeed() {
|
|
557
|
+
const store = this.requestStorage.getStore();
|
|
558
|
+
if (store === void 0) {
|
|
559
|
+
throw new ScopeViolationError("requestSeed", "requestSeed() requires container.runInRequest(...) to be active.");
|
|
560
|
+
}
|
|
561
|
+
if (!store.hasSeed) {
|
|
562
|
+
throw new MissingRequestSeedError();
|
|
563
|
+
}
|
|
564
|
+
return store.seed;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
538
567
|
* Debug helper — returns a snapshot of the dependency graph.
|
|
539
568
|
*
|
|
540
569
|
* Detects cycles in unused providers too (resolve-time
|
|
@@ -1142,6 +1171,6 @@ function Qualifier(name) {
|
|
|
1142
1171
|
}
|
|
1143
1172
|
__name(Qualifier, "Qualifier");
|
|
1144
1173
|
|
|
1145
|
-
export { AsyncPostConstructInSyncResolveError, AsyncProviderInSyncResolveError, Container, ContainerDisposedError, ContainerFrozenError, CyclicDependencyError, CyclicModuleImportError, Inject, Injectable, InvalidExportError, InvalidModuleError, METADATA_KEYS, MissingInjectableError, Module, Optional, PostConstruct, PreDestroy, Primary, Qualifier, ReflectMetadataMissingError, Scope, ScopeViolationError, TokenNotFoundError, describeClassName, describeToken };
|
|
1174
|
+
export { AsyncPostConstructInSyncResolveError, AsyncProviderInSyncResolveError, Container, ContainerDisposedError, ContainerFrozenError, CyclicDependencyError, CyclicModuleImportError, Inject, Injectable, InvalidExportError, InvalidModuleError, METADATA_KEYS, MissingInjectableError, MissingRequestSeedError, Module, Optional, PostConstruct, PreDestroy, Primary, Qualifier, ReflectMetadataMissingError, Scope, ScopeViolationError, TokenNotFoundError, describeClassName, describeToken };
|
|
1146
1175
|
//# sourceMappingURL=index.js.map
|
|
1147
1176
|
//# sourceMappingURL=index.js.map
|