injeca 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { F as Container, Ft as Logger, I as ContainerOptions, O as EffectSetup, a as InvocationHandle, at as ConditionalDependency, ct as DependencyMap, d as ProvideOption, dt as KeyOptions, g as Registration, gt as ProvidedKey, h as ProvideOptionWithKeys, ht as ProvidedBy, lt as FallbackDependency, n as Transaction, o as InvokeOption, pt as OptionalDependency, st as DependencyDeclarations, u as InvokeOptionWithKeys, ut as InferProvided, vt as ResolutionCondition, wt as OwnerRecord, y as Graph, yt as ResolveDependencyDeclaration } from "./index-DXguNx2M.mjs";
1
+ import { A as PeekValue, At as OwnerRecord, H as ContainerOptions, O as PeekDependency, P as EffectSetup, S as Graph, St as ProvidedKey, Tt as ResolveDependencyDeclaration, V as Container, Vt as Logger, _ as Registration, _t as KeyOptions, d as InvokeOptionWithKeys, dt as ConditionalDependency, f as ProvideOption, g as ProvideOptionWithKeys, gt as InferProvided, ht as FallbackDependency, k as PeekResult, mt as DependencyMap, n as Transaction, o as InvocationHandle, pt as DependencyDeclarations, s as InvokeOption, wt as ResolutionCondition, xt as ProvidedBy, yt as OptionalDependency } from "./index-DTYp044J.mjs";
2
2
  import { setActiveSub } from "alien-signals";
3
3
  /** The identity of an event. Any object with a string `id` is an event key, for example an eventa definition. */
4
4
  interface EventKey {
@@ -21,15 +21,31 @@ interface ListenerEntry<H> {
21
21
  declare function createContainer(options?: ContainerOptions): Container;
22
22
  /**
23
23
  * Runs `setup` and stores the returned disposer on the container. `dispose(container)` runs the disposers in reverse order.
24
+ *
25
+ * When the disposal of the container started or ended, the disposer runs at once after `setup`, so that the resource does not leak.
26
+ * A disposer that throws throws to the caller. A disposer promise that rejects is reported outside the call, as an unhandled error.
24
27
  */
25
28
  declare function effect$1(container: Container, setup: EffectSetup): void;
29
+ interface DisposeOptions {
30
+ /**
31
+ * Ends the wait when the signal aborts, and rejects with the reason. The disposal continues in the background. There is no default.
32
+ * Each service that did not stop yet gets a `wait-aborted` record in the observe stream.
33
+ */
34
+ signal?: AbortSignal;
35
+ }
26
36
  /**
27
37
  * Withdraws the registrations and invocations of the container, disposes the child containers, and runs the container effects in reverse order.
28
38
  *
29
- * One error keeps its identity. More than one error becomes an `AggregateError`.
30
- * A call from the cleanup chain of the same container rejects with `reentrant-dispose`. A second call from outside gets the same promise.
39
+ * One error keeps its identity. More than one error becomes an `AggregateError`. A second call from outside without a signal gets the same promise.
40
+ *
41
+ * A call from the cleanup chain of the container or of a descendant cannot wait, because the disposal waits for that cleanup.
42
+ * The same is true for a cleanup of a service that holds a service of the subtree, directly or through other instances, or a consumer service of a `perConsumer` registration of it.
43
+ * injeca finds such a call by the signal of the cleanup, or by the synchronous part of the cleanup. It warns, sends a `reentrant-call` record, and resolves at once. The disposal continues.
44
+ *
45
+ * When `options.signal` aborts, the call rejects with the reason and stops waiting. The disposal continues: the container stays in `disposing`, and calls on it fail with `build-after-dispose`.
46
+ * A later `dispose()` waits for the same disposal and gets its result. An aborted signal starts the disposal, then rejects at once.
31
47
  */
32
- declare function dispose(container: Container): Promise<void>;
48
+ declare function dispose(container: Container, options?: DisposeOptions): Promise<void>;
33
49
  /**
34
50
  * Registers an invocation: a service without a value. The callback runs when the required dependencies are available.
35
51
  * Before `start()`, it waits for `start()`.
@@ -48,11 +64,13 @@ declare function defineKey<T>(name: string, options?: KeyOptions): ProvidedKey<s
48
64
  *
49
65
  * A change of the selection is a change of identity: the dependent gets `dependency-change`.
50
66
  * It is required, unless it is wrapped in `optional()`.
67
+ * A `where(key, condition)` marker in the list filters that candidate only. `where(firstAvailable(...), condition)` filters each candidate.
68
+ * The selection is the first available candidate that passes its conditions.
51
69
  */
52
- declare function firstAvailable<const Keys extends readonly KeyLike[]>(...keys: Keys): FallbackDependency<InferProvided<Keys[number]>>;
70
+ declare function firstAvailable<const Keys extends readonly (KeyLike | ConditionalDependency<unknown>)[]>(...keys: Keys): FallbackDependency<InferProvided<Keys[number]>>;
53
71
  /**
54
72
  * Marks an optional dependency. The dependent gets `{ value, status }`, or `undefined` when no provider runs.
55
- * It also accepts a `firstAvailable` marker and a `where` marker.
73
+ * It also accepts a `firstAvailable` marker and a `where` marker, with their conditions.
56
74
  */
57
75
  declare function optional<T>(dependency: KeyLike<T> | FallbackDependency<T> | ConditionalDependency<T>): OptionalDependency<T>;
58
76
  /**
@@ -61,18 +79,32 @@ declare function optional<T>(dependency: KeyLike<T> | FallbackDependency<T> | Co
61
79
  * If it returns `false`, the dependency does not resolve. A required dependency keeps the dependent `pending`. An optional one is `undefined`.
62
80
  * The condition must be pure and synchronous. A thrown error counts as `false` and goes to the observe stream.
63
81
  * Wrap the result in `optional()`, or pass an `optional()` marker, to combine the two.
82
+ *
83
+ * For a `firstAvailable` marker, the condition filters each candidate. The selection is the first available candidate that passes.
84
+ * A candidate that `firstAvailable(where(key, other), ...)` filters must pass both conditions.
64
85
  */
65
86
  declare function where<T>(dependency: OptionalDependency<T>, condition: ResolutionCondition): OptionalDependency<T>;
87
+ declare function where<T>(dependency: FallbackDependency<T>, condition: ResolutionCondition): FallbackDependency<T>;
66
88
  declare function where<T>(dependency: KeyLike<T>, condition: ResolutionCondition): ConditionalDependency<T>;
67
89
  interface StartOptions {
68
- /** Rejects with `start-timeout` when not every service runs after this many milliseconds. There is no default. */
69
- timeoutMs?: number;
90
+ /**
91
+ * Ends the wait when the signal aborts. The services keep converging.
92
+ * A timeout reason (`name === 'TimeoutError'`) rejects with `start-timeout` and the explanations. Another reason rejects as it is. There is no default.
93
+ */
94
+ signal?: AbortSignal;
95
+ }
96
+ interface StopOptions {
97
+ /**
98
+ * Ends the wait when the signal aborts, and rejects with the reason. The cleanups that did not settle keep running.
99
+ * Each service that did not stop yet gets a `wait-aborted` record in the observe stream. There is no default.
100
+ */
101
+ signal?: AbortSignal;
70
102
  }
71
103
  /**
72
104
  * Begins convergence of the container and of each child container that was started.
73
105
  *
74
106
  * Resolves when all their services and invocations are `running`. Rejects with the build and start errors.
75
- * A service in `failed` tries again. A required key without a provider keeps the promise pending, unless `timeoutMs` is set.
107
+ * A service in `failed` tries again. A required key without a provider keeps the promise pending, unless `options.signal` aborts.
76
108
  * A child container that was never started does not start. Call `start(child)` for it.
77
109
  */
78
110
  declare function start$1(container: Container, options?: StartOptions): Promise<void>;
@@ -81,8 +113,15 @@ declare function start$1(container: Container, options?: StartOptions): Promise<
81
113
  *
82
114
  * The registrations stay. The container stays usable, and a later `start()` builds them again. `dispose()` clears the container.
83
115
  * Rejects with the teardown errors.
116
+ *
117
+ * When `options.signal` aborts, it rejects with the reason and stops waiting. The container stays stopped: a later `start()` builds again.
118
+ * The services that did not stop yet stay in `stopping` until their cleanups settle.
119
+ *
120
+ * A call from the cleanup chain of the container or of a descendant cannot wait, because the stop waits for that cleanup.
121
+ * The same is true for a cleanup of a service that holds a service of the subtree, directly or through other instances.
122
+ * injeca finds such a call by the signal of the cleanup, or by the synchronous part of the cleanup. It warns, sends a `reentrant-call` record, and resolves at once. The stop continues.
84
123
  */
85
- declare function stop$1(container: Container): Promise<void>;
124
+ declare function stop$1(container: Container, options?: StopOptions): Promise<void>;
86
125
  /**
87
126
  * Stores a listener for `eventKey`. The container owns it: `dispose(container)` removes it.
88
127
  *
@@ -106,12 +145,29 @@ declare function provide$1<D extends DependencyMap | undefined, T = any, Key ext
106
145
  }): Registration<Key, T, D>;
107
146
  declare function provide$1<T, Key extends string, Deps extends DependencyDeclarations>(container: Container, key: ProvidedKey<Key, T, DependencyMap | undefined>, option: ProvideOptionWithKeys<NoInfer<T>, Deps>): Registration<Key, T, ResolveDependencyDeclaration<Deps>>;
108
147
  declare function provide$1<T, Key extends string>(container: Container, key: ProvidedKey<Key, T, DependencyMap | undefined>, option: ProvideOption<NoInfer<T>, undefined>): Registration<Key, T, undefined>;
148
+ interface ResolveOptions {
149
+ /**
150
+ * Ends the wait when the signal aborts. A timeout reason (`name === 'TimeoutError'`) rejects with `wait-timeout`, with the reason as `cause`.
151
+ * Another reason rejects as it is. Use `timeout(container, ms)` for a timeout on the container clock. There is no default.
152
+ */
153
+ signal?: AbortSignal;
154
+ }
109
155
  /**
110
156
  * Waits until the dependencies are available and returns their values. Before `start()`, it builds and starts them.
111
157
  *
112
- * Rejects when a required dependency fails. The values can become stale after a run-time change. Use it for one-time code.
158
+ * Rejects when a required dependency fails. With `options.signal`, it rejects when the signal aborts. An aborted signal rejects at once.
159
+ * Each rejection removes the hidden resolver of the call. The values can become stale after a run-time change. Use it for one-time code.
160
+ */
161
+ declare function resolve$1<Deps extends DependencyDeclarations>(container: Container, dependsOn: Deps, options?: ResolveOptions): Promise<ResolveDependencyDeclaration<Deps>>;
162
+ /**
163
+ * Returns a signal that aborts after `ms` milliseconds of the clock of `container`.
164
+ *
165
+ * The reason is a `DOMException` with the name `TimeoutError`, as for `AbortSignal.timeout()`. Use it in place of `AbortSignal.timeout()`, because that one does not use the container clock.
166
+ * With the system clock, the timer does not keep a Node process alive.
113
167
  */
114
- declare function resolve$1<Deps extends DependencyDeclarations>(container: Container, dependsOn: Deps): Promise<ResolveDependencyDeclaration<Deps>>;
168
+ declare function timeout(container: Container, ms: number): AbortSignal;
169
+ /** Returns a signal that aborts when `signal` aborts, or after `ms` milliseconds of the clock of `container`. Without `signal`, it is `timeout(container, ms)`. */
170
+ declare function withTimeout(signal: AbortSignal | undefined, ms: number, container: Container): AbortSignal;
115
171
  /**
116
172
  * Creates a transaction for `container`.
117
173
  *
@@ -123,9 +179,17 @@ declare function transaction(container: Container): Transaction;
123
179
  /**
124
180
  * Returns the graph queries of `container`. They cover the container and its descendants. Each query is a pure read.
125
181
  *
126
- * A key resolves as for a consumer in the container: from the container, then from its ancestors. A key that only a descendant has resolves to the first such service.
182
+ * A key resolves as for a consumer in the container: from the container and the exports of its children, then from each ancestor and the exports of its children.
183
+ * A key that only a descendant has resolves to the first such service.
127
184
  */
128
185
  declare function graph(container: Container): Graph;
186
+ /**
187
+ * Reads the value of a dependency now, without a wait. It is a pure read: it does not demand, build, or start a service.
188
+ *
189
+ * The dependency resolves as for a consumer in `container`: a key, `where(key, condition)`, or `firstAvailable(...)`. An `optional` marker has no effect.
190
+ * The result is the value with its status, or the reason why no value is available now. A `perConsumer` key has a value only after something demanded its service for `container`.
191
+ */
192
+ declare function peek<D extends PeekDependency>(container: Container, dependency: D): PeekResult<PeekValue<D>>;
129
193
  /**
130
194
  * Returns the current listeners for `eventKey` in `container` and its descendants, in registration order.
131
195
  *
@@ -146,8 +210,8 @@ declare function provide<T, Key extends string, Deps extends DependencyDeclarati
146
210
  declare function provide<T, Key extends string>(key: ProvidedKey<Key, T, DependencyMap | undefined>, option: ProvideOption<NoInfer<T>, undefined>): Registration<Key, T, undefined>;
147
211
  declare function invoke<Deps extends DependencyDeclarations>(option: InvokeOptionWithKeys<Deps>): InvocationHandle;
148
212
  declare function invoke<D extends DependencyMap>(option: InvokeOption<D>): InvocationHandle;
149
- declare function resolve<Deps extends DependencyDeclarations>(dependsOn: Deps): Promise<ResolveDependencyDeclaration<Deps>>;
213
+ declare function resolve<Deps extends DependencyDeclarations>(dependsOn: Deps, options?: ResolveOptions): Promise<ResolveDependencyDeclaration<Deps>>;
150
214
  declare function start(options?: StartOptions): Promise<void>;
151
- declare function stop(): Promise<void>;
152
- export { createContainer as C, ListenerEntry as D, EventKey as E, ListenerMetadata as O, invoke$1 as S, effect$1 as T, stop$1 as _, resolve as a, optional as b, stop as c, transaction as d, resolve$1 as f, start$1 as g, StartOptions as h, resetContainer as i, listeners as l, listen as m, invoke as n, setLogger as o, provide$1 as p, provide as r, start as s, getContainer as t, graph as u, defineKey as v, dispose as w, where as x, firstAvailable as y };
153
- //# sourceMappingURL=global-B9Bk2EG2.d.mts.map
215
+ declare function stop(options?: StopOptions): Promise<void>;
216
+ export { dispose as A, defineKey as C, invoke$1 as D, where as E, EventKey as M, ListenerEntry as N, DisposeOptions as O, ListenerMetadata as P, stop$1 as S, optional as T, provide$1 as _, resolve as a, StopOptions as b, stop as c, graph as d, transaction as f, resolve$1 as g, ResolveOptions as h, resetContainer as i, effect$1 as j, createContainer as k, listeners as l, withTimeout as m, invoke as n, setLogger as o, timeout as p, provide as r, start as s, getContainer as t, peek as u, listen as v, firstAvailable as w, start$1 as x, StartOptions as y };
217
+ //# sourceMappingURL=global-DPfe26g5.d.mts.map
package/dist/global.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as resolve, c as stop, i as resetContainer, n as invoke, o as setLogger, r as provide, s as start, t as getContainer } from "./global-B9Bk2EG2.mjs";
1
+ import { a as resolve, c as stop, i as resetContainer, n as invoke, o as setLogger, r as provide, s as start, t as getContainer } from "./global-DPfe26g5.mjs";
2
2
  export { getContainer, invoke, provide, resetContainer, resolve, setLogger, start, stop };
package/dist/global.mjs CHANGED
@@ -1 +1 @@
1
- export { t as getContainer, n as invoke, r as provide, i as resetContainer, a as resolve, o as setLogger, s as start, c as stop } from "./global-C0Nk0pU8.mjs";
1
+ export { t as getContainer, n as invoke, r as provide, i as resetContainer, a as resolve, o as setLogger, s as start, c as stop } from "./global-B5N-d-TO.mjs";
@@ -1,4 +1,7 @@
1
1
  import { Logg } from "@guiiai/logg";
2
+ /**
3
+ * The logger of a container. `warn` always writes. The other methods write the lifecycle trace, and injeca calls them only when the `logging` option of the container is `true`.
4
+ */
2
5
  interface Logger {
3
6
  provide: (name: string, dependencies: string[]) => void;
4
7
  invoke: (dependencies: string[]) => void;
@@ -9,9 +12,19 @@ interface Logger {
9
12
  hookOnStop: (name: string) => void;
10
13
  hookOnStopComplete: (name: string, duration: number) => void;
11
14
  running: () => void;
15
+ /** A call that injeca handled in another way than the caller asked, for example a re-entrant `dispose()` that resolved at once. */
16
+ warn: (message: string) => void;
12
17
  }
13
18
  interface LoggerOptions {
14
- enabled?: boolean;
19
+ /**
20
+ * Writes the lifecycle trace: `provide`, `invoke`, builds, `start` and `stop` hooks, and `running`. It defaults to `false`.
21
+ * A child container uses the value of its parent, unless it sets its own. `warn` does not depend on it.
22
+ */
23
+ logging?: boolean;
24
+ /**
25
+ * The logger. It defaults to the logger of the parent container, then to `createDefaultLogger()`.
26
+ * To also silence the warnings, for example in tests, pass `createNoopLogger()`.
27
+ */
15
28
  logger?: Logger;
16
29
  }
17
30
  declare function createDefaultLogger(): Logger;
@@ -20,7 +33,7 @@ declare function createNoopLogger(): Logger;
20
33
  /**
21
34
  * The time source of a container. Pass a custom clock to control time in tests.
22
35
  *
23
- * The reconciler uses it for requeue delays and hook timeouts. The work queue does not use it. It drains on microtasks.
36
+ * The reconciler uses it for requeue delays and hook timeouts, and `timeout()` uses it for its signal. The work queue does not use it. It drains on microtasks.
24
37
  */
25
38
  interface Clock {
26
39
  now: () => number;
@@ -161,13 +174,19 @@ interface ServiceExplanation {
161
174
  readonly name: string;
162
175
  readonly kind: 'service' | 'invocation';
163
176
  readonly owner: OwnerRecord;
164
- readonly phase: ServicePhase;
177
+ /** The phase of the service. It is `undefined` for a key without a service. Then `owner` is the owner of the container of the query. */
178
+ readonly phase: ServicePhase | undefined;
165
179
  /** The effective status of a running service. */
166
180
  readonly status?: ServiceStatus;
167
181
  readonly reason?: string;
168
182
  /** The cause chain of the effective status. */
169
183
  readonly cause?: StatusCause;
170
184
  readonly blockers: readonly ServiceBlocker[];
185
+ /**
186
+ * The new instance of a replacement in progress, from `replace()`, a transaction, or a make-before-break rebuild.
187
+ * The old instance serves until the new one completes `start`. Its phase and blockers tell why the swap did not happen yet.
188
+ */
189
+ readonly replacement?: ServiceExplanation;
171
190
  }
172
191
  declare const providedType: unique symbol;
173
192
  declare const optionalType: unique symbol;
@@ -213,8 +232,10 @@ interface OptionalDependency<T> {
213
232
  readonly [optionalBrand]: true;
214
233
  /** The names of the keys, in order. More than one name comes from `optional(firstAvailable(...))`. */
215
234
  readonly dependencies: readonly string[];
216
- /** The resolution condition from `where`, when the marker has one. */
235
+ /** The resolution condition from `where`, when the marker has one. It filters each candidate. */
217
236
  readonly condition?: ResolutionCondition;
237
+ /** The resolution conditions of single candidates, from `firstAvailable(where(key, condition), ...)`, by key name. */
238
+ readonly candidateConditions?: Readonly<Record<string, ResolutionCondition>>;
218
239
  /** Carries the value type. It has no value at run time. */
219
240
  readonly [optionalType]?: T;
220
241
  }
@@ -227,11 +248,18 @@ interface ConditionalDependency<T> {
227
248
  /** Carries the value type. It has no value at run time. */
228
249
  readonly [conditionalType]?: T;
229
250
  }
230
- /** A fallback dependency marker from `firstAvailable(...keys)`. It resolves to the first available provider in the list. */
251
+ /**
252
+ * A fallback dependency marker from `firstAvailable(...keys)`. It resolves to the first available provider in the list.
253
+ * A resolution condition filters the candidates. The selection is the first available candidate that passes.
254
+ */
231
255
  interface FallbackDependency<T> {
232
256
  readonly [fallbackBrand]: true;
233
257
  /** The names of the keys, in order of preference. */
234
258
  readonly dependencies: readonly string[];
259
+ /** The resolution condition from `where(firstAvailable(...), condition)`. It filters each candidate. */
260
+ readonly condition?: ResolutionCondition;
261
+ /** The resolution conditions of single candidates, from `firstAvailable(where(key, condition), ...)`, by key name. */
262
+ readonly candidateConditions?: Readonly<Record<string, ResolutionCondition>>;
235
263
  /** Carries the value type. It has no value at run time. */
236
264
  readonly [fallbackType]?: T;
237
265
  }
@@ -243,7 +271,7 @@ interface OptionalValue<T> {
243
271
  readonly value: T;
244
272
  readonly status: ServiceStatus;
245
273
  }
246
- type InferProvided<T> = T extends ProvidedKey<any, infer P, any> ? P : T extends ProvidedBy<infer P> ? P : never;
274
+ type InferProvided<T> = T extends ProvidedKey<any, infer P, any> ? P : T extends ProvidedBy<infer P> ? P : T extends ConditionalDependency<infer P> ? P : never;
247
275
  /** A required dependency is its value. An optional dependency is `{ value, status }` or `undefined`. */
248
276
  type ResolveDependencyDeclaration<Deps extends DependencyDeclarations> = { [K in keyof Deps]: Deps[K] extends OptionalDependency<infer T> ? OptionalValue<T> | undefined : Deps[K] extends FallbackDependency<infer T> ? T : Deps[K] extends ConditionalDependency<infer T> ? T : Deps[K] extends ProvidedKey<any, infer T, any> ? T : Deps[K] extends ProvidedBy<infer T> ? T : any; };
249
277
  /** The hooks that `on` registers in `build` and in an invocation callback. */
@@ -334,7 +362,8 @@ type TimeoutContext = { readonly [H in 'start' | 'stop']: {
334
362
  /**
335
363
  * Decides what happens when a `start` or `stop` hook times out. It runs synchronously.
336
364
  *
337
- * A value that is not a decision, a promise, or a throw gives `fail` with `hook-timeout`.
365
+ * For a `start` timeout, a value that is not a decision or a promise gives `fail` with `hook-timeout`.
366
+ * For a `stop` timeout, it gives `handled`, so that the stop continues. A throw gives `fail` for both hooks.
338
367
  */
339
368
  type TimeoutHandler = (context: TimeoutContext) => unknown;
340
369
  /** The timeouts of the `start` and `stop` hooks in milliseconds. A missing value means no timeout. */
@@ -357,11 +386,13 @@ interface PolicyOptions {
357
386
  maxAttempts?: number;
358
387
  /** The timeouts of the `start` and `stop` hooks. Each field overrides the same field of the container. */
359
388
  timeouts?: HookTimeouts;
360
- /** Decides what happens when a hook times out. Without it, the result is `fail` with `hook-timeout`. */
389
+ /** Decides what happens when a hook times out. Without it, a `start` timeout gives `fail` with `hook-timeout`, and a `stop` timeout counts as `handled`. */
361
390
  onTimeout?: TimeoutHandler;
362
391
  }
363
392
  interface Container {
364
393
  logger: Logger;
394
+ /** `true` when the container writes the lifecycle trace to `logger`. A child container reads it when it is created. */
395
+ logging: boolean;
365
396
  readonly owner: OwnerRecord;
366
397
  readonly parent: Container | undefined;
367
398
  }
@@ -450,6 +481,8 @@ interface GraphService {
450
481
  readonly metadata: ServiceMetadata;
451
482
  readonly exclusive: boolean;
452
483
  readonly perConsumer: boolean;
484
+ /** `true` for a registration that `provide(..., { export: true })` exports to the resolution area of the parent container. */
485
+ readonly exported: boolean;
453
486
  /** The owner record of the consumer container of a `perConsumer` instance. */
454
487
  readonly consumer?: OwnerRecord;
455
488
  }
@@ -524,9 +557,61 @@ interface Graph {
524
557
  readonly cycles: () => readonly (readonly GraphService[])[];
525
558
  /** The services that a proposed change stops, rebuilds, or notifies. It runs on a copy of the graph. */
526
559
  readonly impact: (change: ImpactChange) => ImpactResult;
527
- /** Why the service of `key` is not `running`: missing, conflicting, rejected, failed, or unavailable dependencies. */
528
- readonly explain: (key: KeyReference) => ServiceExplanation | undefined;
560
+ /**
561
+ * Why the service of `key` is not `running`: missing, conflicting, rejected, failed, or unavailable dependencies.
562
+ * A key without a service gives `phase: undefined` and one `missing-provider` blocker.
563
+ */
564
+ readonly explain: (key: KeyReference) => ServiceExplanation;
529
565
  }
566
+ /** The value type of a dependency declaration for `peek`. */
567
+ type PeekValue<D> = D extends OptionalDependency<infer T> ? T : D extends FallbackDependency<infer T> ? T : D extends ConditionalDependency<infer T> ? T : D extends ProvidedKey<string, infer T, DependencyMap | undefined> ? T : D extends ProvidedBy<infer T> ? T : unknown;
568
+ /**
569
+ * The result of `peek`: the value now, or the reason why no value is available now.
570
+ *
571
+ * - `resolved`: a running provider serves the key with the status `ready` or `degraded`.
572
+ * - `unavailable`: a running provider has the effective status `unavailable`. `reason` and `cause` tell why.
573
+ * - `not-running`: a provider exists, but it does not run. `phase` is its phase. A `failed` provider has `error`.
574
+ * - `rejected`: a resolution condition rejected the provider.
575
+ * - `conflict`: the key is exclusive and has more than one declaration. `owners` lists them.
576
+ * - `missing`: no provider exists.
577
+ *
578
+ * `key` is the key name of the provider. For `firstAvailable`, it is the selected key, or the first key when no key has a provider.
579
+ */
580
+ type PeekResult<T> = {
581
+ readonly kind: 'resolved';
582
+ readonly key: string;
583
+ readonly owner: OwnerRecord;
584
+ readonly value: T;
585
+ readonly status: Exclude<ServiceStatus, 'unavailable'>;
586
+ readonly instanceId: string;
587
+ } | {
588
+ readonly kind: 'unavailable';
589
+ readonly key: string;
590
+ readonly owner: OwnerRecord;
591
+ readonly instanceId: string;
592
+ readonly reason?: string;
593
+ readonly cause?: StatusCause;
594
+ } | {
595
+ readonly kind: 'not-running';
596
+ readonly key: string;
597
+ readonly owner: OwnerRecord;
598
+ readonly phase: ServicePhase;
599
+ readonly error?: unknown;
600
+ } | {
601
+ readonly kind: 'rejected';
602
+ readonly key: string;
603
+ readonly owner: OwnerRecord;
604
+ readonly metadata: ServiceMetadata;
605
+ } | {
606
+ readonly kind: 'conflict';
607
+ readonly key: string;
608
+ readonly owners: readonly OwnerRecord[];
609
+ } | {
610
+ readonly kind: 'missing';
611
+ readonly key: string;
612
+ };
613
+ /** A dependency declaration that `peek` reads. An `optional` marker has no effect. */
614
+ type PeekDependency = DependencyDeclaration;
530
615
  /** The registration options that each object form of `provide` accepts. */
531
616
  interface RegistrationOptions extends PolicyOptions {
532
617
  /** A record that resolution conditions and graph queries read. injeca freezes a copy. */
@@ -536,6 +621,12 @@ interface RegistrationOptions extends PolicyOptions {
536
621
  * Each instance disposes with its consumer container.
537
622
  */
538
623
  perConsumer?: boolean;
624
+ /**
625
+ * Exports the registration one level up. The registration stays in its container: its owner, its disposal, its dependencies, and its phases.
626
+ * It is also a candidate for consumers in the resolution area of the parent container: the parent and each descendant of the parent.
627
+ * For an exclusive key, it counts as a declaration in that area. On a root container, it has no effect.
628
+ */
629
+ export?: boolean;
539
630
  }
540
631
  type ProvideOptionObject<T, D extends DependencyMap | undefined = undefined> = {
541
632
  build: (context: BuildContext<D>) => T | Promise<T>;
@@ -570,8 +661,24 @@ type InvokeOptionWithKeys<Deps extends DependencyDeclarations> = InvokeOptionObj
570
661
  * An option without `metadata`, `maxAttempts`, `timeouts`, or `onTimeout` keeps that value of the registration. `perConsumer` does not change.
571
662
  */
572
663
  interface ReplaceFunction<T> {
573
- <Deps extends DependencyDeclarations>(option: ProvideOptionWithKeys<T, Deps>): Promise<boolean>;
574
- (option: ProvideOption<T, undefined>): Promise<boolean>;
664
+ <Deps extends DependencyDeclarations>(option: ProvideOptionWithKeys<T, Deps>, options?: ReplaceOptions): Promise<boolean>;
665
+ (option: ProvideOption<T, undefined>, options?: ReplaceOptions): Promise<boolean>;
666
+ }
667
+ /** The options of `replace()`. */
668
+ interface ReplaceOptions {
669
+ /**
670
+ * Cancels the pending replacement when the signal aborts, as a newer `replace` does. The old instance stays, and `replace()` resolves `false`.
671
+ * An aborted signal resolves `false` at once and changes nothing. After the swap, the signal has no effect.
672
+ */
673
+ signal?: AbortSignal;
674
+ }
675
+ /** The options of `withdraw()` of a registration or an invocation. */
676
+ interface WithdrawOptions {
677
+ /**
678
+ * Ends the wait when the signal aborts, and rejects with the reason. The withdrawal continues. There is no default.
679
+ * The service gets a `wait-aborted` record in the observe stream when it did not finish its withdrawal. An aborted signal still starts the withdrawal.
680
+ */
681
+ signal?: AbortSignal;
575
682
  }
576
683
  /**
577
684
  * The result of `provide`: the typed key of the service, with `withdraw()` and `replace()`.
@@ -581,13 +688,16 @@ interface Registration<Key, T, D extends DependencyMap | undefined> extends Prov
581
688
  * Withdraws the service. Dependents stop first. Then the service runs its `stop` hooks and effect disposers.
582
689
  *
583
690
  * Resolves `false` for a stale registration and does not change any service. Rejects with the teardown errors.
691
+ *
692
+ * A call from a cleanup that the withdrawal waits for cannot wait: of the service, of a consumer service of it, or of a service that holds it.
693
+ * injeca finds such a call by the signal of the cleanup, or by the synchronous part of the cleanup. It warns, sends a `reentrant-call` record, and resolves `true` at once. The withdrawal continues.
584
694
  */
585
- readonly withdraw: () => Promise<boolean>;
695
+ readonly withdraw: (options?: WithdrawOptions) => Promise<boolean>;
586
696
  /**
587
697
  * Replaces the instance of the service without a gap.
588
698
  *
589
699
  * The old instance keeps serving with its status while the new instance runs `build` and `start`. The swap is one batch.
590
- * Resolves `true` after the swap. Resolves `false` for a stale registration, or when a newer `replace` or a withdrawal supersedes this call.
700
+ * Resolves `true` after the swap. Resolves `false` for a stale registration, when a newer `replace` or a withdrawal supersedes this call, or when `options.signal` aborts before the swap.
591
701
  * Rejects with the build or start error of the new instance, and the old instance does not change.
592
702
  * Rejects with `replace-while-stopping` when the service is in `stopping`.
593
703
  */
@@ -595,8 +705,10 @@ interface Registration<Key, T, D extends DependencyMap | undefined> extends Prov
595
705
  }
596
706
  /** The result of `invoke`. */
597
707
  interface InvocationHandle {
598
- /** Withdraws the invocation. Resolves `false` when it is already withdrawn. Rejects with the teardown errors. */
599
- readonly withdraw: () => Promise<boolean>;
708
+ /** The name of the invocation. Graph queries, for example `graph(container).dependencies(key)` and `explain(key)`, accept it. */
709
+ readonly key: string;
710
+ /** Withdraws the invocation. Resolves `false` when it is already withdrawn. Rejects with the teardown errors. `options` work as for `withdraw()` of a registration. */
711
+ readonly withdraw: (options?: WithdrawOptions) => Promise<boolean>;
600
712
  }
601
713
  interface DeclareOptions {
602
714
  /** The declared edges. A later `tx.provide` without `dependsOn` uses them. */
@@ -616,6 +728,11 @@ interface TransactionReplace {
616
728
  <T, Deps extends DependencyDeclarations>(key: ProvidedKey<string, T, DependencyMap | undefined> | string, option: ProvideOptionWithKeys<NoInfer<T>, Deps>): void;
617
729
  <T>(key: ProvidedKey<string, T, DependencyMap | undefined> | string, option: ProvideOption<NoInfer<T>, undefined>): void;
618
730
  }
731
+ /** The options of `tx.commit()`. */
732
+ interface TransactionCommitOptions {
733
+ /** Aborts the transaction when the signal aborts before the publish. */
734
+ signal?: AbortSignal;
735
+ }
619
736
  /**
620
737
  * A set of registrations that publish together. `transaction(container)` creates it.
621
738
  *
@@ -634,10 +751,13 @@ interface Transaction {
634
751
  * A service whose required dependencies are not available goes to `pending`. That is not a failure.
635
752
  * If one build fails, nothing publishes, no `start` hook runs, and the promise rejects with the build error.
636
753
  * Resolves after the publish. It does not wait for the `start` hooks.
754
+ *
755
+ * When `options.signal` aborts before the publish, the transaction aborts and rolls back, and the commit rejects at once with the reason.
756
+ * An aborted signal rejects at once and builds nothing. After the publish, the signal has no effect.
637
757
  */
638
- readonly commit: () => Promise<void>;
758
+ readonly commit: (options?: TransactionCommitOptions) => Promise<void>;
639
759
  /** Removes all declared and built services of the transaction. A build that settles later cannot publish. */
640
760
  readonly abort: () => Promise<void>;
641
761
  }
642
- export { HookResult as $, HookContextFor as A, ServiceStatus as At, TimeoutHandler as B, ImpactChange as C, DependencyState as Ct, Disposer as D, ServiceExplanation as Dt, DependencyHookContext as E, ServiceBlocker as Et, Container as F, Logger as Ft, DecisionKind as G, DecideFor as H, ContainerOptions as I, LoggerOptions as It, DependencyHook as J, DecisionOptions as K, HookTimeouts as L, createDefaultLogger as Lt, HookHandler as M, StatusCause as Mt, InvocationContext as N, Clock as Nt, EffectSetup as O, ServicePhase as Ot, LifecycleContext as P, systemClock as Pt, HookDecisionKind as Q, PolicyOptions as R, createLoggLogger as Rt, GraphService as S, DependencySnapshot as St, BuildContext as T, OwnerValue as Tt, Decision as U, Decide as V, DecisionFor as W, FailDecision as X, ExponentialBackoff as Y, HandledDecision as Z, RegistrationOptions as _, ProviderInfo as _t, InvocationHandle as a, ConditionalDependency as at, GraphDependency as b, ServiceMetadata as bt, InvokeOptionObject as c, DependencyMap as ct, ProvideOption as d, KeyOptions as dt, RebuildDecision as et, ProvideOptionFunc as f, KeyReference as ft, Registration as g, ProvidedKey as gt, ProvideOptionWithKeys as h, ProvidedBy as ht, TransactionReplace as i, StopDecision as it, HookDependencies as j, SetStatusOptions as jt, HookContext as k, ServiceState as kt, InvokeOptionObjectWithKeys as l, FallbackDependency as lt, ProvideOptionObjectWithKeys as m, OptionalValue as mt, Transaction as n, RequeueOptions as nt, InvokeOption as o, DependencyDeclaration as ot, ProvideOptionObject as p, OptionalDependency as pt, DecisionSource as q, TransactionProvide as r, ServiceHook as rt, InvokeOptionFunc as s, DependencyDeclarations as st, DeclareOptions as t, RequeueDecision as tt, InvokeOptionWithKeys as u, InferProvided as ut, ReplaceFunction as v, ResolutionCondition as vt, ImpactResult as w, OwnerRecord as wt, GraphResolution as x, DependencyChange as xt, Graph as y, ResolveDependencyDeclaration as yt, TimeoutContext as z, createNoopLogger as zt };
643
- //# sourceMappingURL=index-DXguNx2M.d.mts.map
762
+ export { DecisionSource as $, PeekValue as A, OwnerRecord as At, LifecycleContext as B, systemClock as Bt, GraphDependency as C, ProviderInfo as Ct, ImpactResult as D, DependencyChange as Dt, ImpactChange as E, ServiceMetadata as Et, HookContext as F, ServiceState as Ft, TimeoutContext as G, createNoopLogger as Gt, ContainerOptions as H, LoggerOptions as Ht, HookContextFor as I, ServiceStatus as It, DecideFor as J, TimeoutHandler as K, HookDependencies as L, SetStatusOptions as Lt, DependencyHookContext as M, ServiceBlocker as Mt, Disposer as N, ServiceExplanation as Nt, PeekDependency as O, DependencySnapshot as Ot, EffectSetup as P, ServicePhase as Pt, DecisionOptions as Q, HookHandler as R, StatusCause as Rt, Graph as S, ProvidedKey as St, GraphService as T, ResolveDependencyDeclaration as Tt, HookTimeouts as U, createDefaultLogger as Ut, Container as V, Logger as Vt, PolicyOptions as W, createLoggLogger as Wt, DecisionFor as X, Decision as Y, DecisionKind as Z, Registration as _, KeyOptions as _t, TransactionReplace as a, HookResult as at, ReplaceOptions as b, OptionalValue as bt, InvokeOptionFunc as c, RequeueOptions as ct, InvokeOptionWithKeys as d, ConditionalDependency as dt, DependencyHook as et, ProvideOption as f, DependencyDeclaration as ft, ProvideOptionWithKeys as g, InferProvided as gt, ProvideOptionObjectWithKeys as h, FallbackDependency as ht, TransactionProvide as i, HookDecisionKind as it, BuildContext as j, OwnerValue as jt, PeekResult as k, DependencyState as kt, InvokeOptionObject as l, ServiceHook as lt, ProvideOptionObject as m, DependencyMap as mt, Transaction as n, FailDecision as nt, InvocationHandle as o, RebuildDecision as ot, ProvideOptionFunc as p, DependencyDeclarations as pt, Decide as q, TransactionCommitOptions as r, HandledDecision as rt, InvokeOption as s, RequeueDecision as st, DeclareOptions as t, ExponentialBackoff as tt, InvokeOptionObjectWithKeys as u, StopDecision as ut, RegistrationOptions as v, KeyReference as vt, GraphResolution as w, ResolutionCondition as wt, WithdrawOptions as x, ProvidedBy as xt, ReplaceFunction as y, OptionalDependency as yt, InvocationContext as z, Clock as zt };
763
+ //# sourceMappingURL=index-DTYp044J.d.mts.map
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { $ as HookResult, A as HookContextFor, At as ServiceStatus, B as TimeoutHandler, C as ImpactChange, Ct as DependencyState, D as Disposer, Dt as ServiceExplanation, E as DependencyHookContext, Et as ServiceBlocker, F as Container, Ft as Logger, G as DecisionKind, H as DecideFor, I as ContainerOptions, It as LoggerOptions, J as DependencyHook, K as DecisionOptions, L as HookTimeouts, Lt as createDefaultLogger, M as HookHandler, Mt as StatusCause, N as InvocationContext, Nt as Clock, O as EffectSetup, Ot as ServicePhase, P as LifecycleContext, Pt as systemClock, Q as HookDecisionKind, R as PolicyOptions, Rt as createLoggLogger, S as GraphService, St as DependencySnapshot, T as BuildContext, Tt as OwnerValue, U as Decision, V as Decide, W as DecisionFor, X as FailDecision, Y as ExponentialBackoff, Z as HandledDecision, _ as RegistrationOptions, _t as ProviderInfo, a as InvocationHandle, at as ConditionalDependency, b as GraphDependency, bt as ServiceMetadata, c as InvokeOptionObject, ct as DependencyMap, d as ProvideOption, dt as KeyOptions, et as RebuildDecision, f as ProvideOptionFunc, ft as KeyReference, g as Registration, gt as ProvidedKey, h as ProvideOptionWithKeys, ht as ProvidedBy, i as TransactionReplace, it as StopDecision, j as HookDependencies, jt as SetStatusOptions, k as HookContext, kt as ServiceState, l as InvokeOptionObjectWithKeys, lt as FallbackDependency, m as ProvideOptionObjectWithKeys, mt as OptionalValue, n as Transaction, nt as RequeueOptions, o as InvokeOption, ot as DependencyDeclaration, p as ProvideOptionObject, pt as OptionalDependency, q as DecisionSource, r as TransactionProvide, rt as ServiceHook, s as InvokeOptionFunc, st as DependencyDeclarations, t as DeclareOptions, tt as RequeueDecision, u as InvokeOptionWithKeys, ut as InferProvided, v as ReplaceFunction, vt as ResolutionCondition, w as ImpactResult, wt as OwnerRecord, x as GraphResolution, xt as DependencyChange, y as Graph, yt as ResolveDependencyDeclaration, z as TimeoutContext, zt as createNoopLogger } from "./index-DXguNx2M.mjs";
2
- import { C as createContainer, D as ListenerEntry, E as EventKey, O as ListenerMetadata, S as invoke, T as effect, _ as stop, a as resolve$1, b as optional, c as stop$1, d as transaction, f as resolve, g as start, h as StartOptions, l as listeners, m as listen, n as invoke$1, o as setLogger, p as provide, r as provide$1, s as start$1, t as getContainer, u as graph, v as defineKey, w as dispose, x as where, y as firstAvailable } from "./global-B9Bk2EG2.mjs";
1
+ import { $ as DecisionSource, A as PeekValue, At as OwnerRecord, B as LifecycleContext, Bt as systemClock, C as GraphDependency, Ct as ProviderInfo, D as ImpactResult, Dt as DependencyChange, E as ImpactChange, Et as ServiceMetadata, F as HookContext, Ft as ServiceState, G as TimeoutContext, Gt as createNoopLogger, H as ContainerOptions, Ht as LoggerOptions, I as HookContextFor, It as ServiceStatus, J as DecideFor, K as TimeoutHandler, L as HookDependencies, Lt as SetStatusOptions, M as DependencyHookContext, Mt as ServiceBlocker, N as Disposer, Nt as ServiceExplanation, O as PeekDependency, Ot as DependencySnapshot, P as EffectSetup, Pt as ServicePhase, Q as DecisionOptions, R as HookHandler, Rt as StatusCause, S as Graph, St as ProvidedKey, T as GraphService, Tt as ResolveDependencyDeclaration, U as HookTimeouts, Ut as createDefaultLogger, V as Container, Vt as Logger, W as PolicyOptions, Wt as createLoggLogger, X as DecisionFor, Y as Decision, Z as DecisionKind, _ as Registration, _t as KeyOptions, a as TransactionReplace, at as HookResult, b as ReplaceOptions, bt as OptionalValue, c as InvokeOptionFunc, ct as RequeueOptions, d as InvokeOptionWithKeys, dt as ConditionalDependency, et as DependencyHook, f as ProvideOption, ft as DependencyDeclaration, g as ProvideOptionWithKeys, gt as InferProvided, h as ProvideOptionObjectWithKeys, ht as FallbackDependency, i as TransactionProvide, it as HookDecisionKind, j as BuildContext, jt as OwnerValue, k as PeekResult, kt as DependencyState, l as InvokeOptionObject, lt as ServiceHook, m as ProvideOptionObject, mt as DependencyMap, n as Transaction, nt as FailDecision, o as InvocationHandle, ot as RebuildDecision, p as ProvideOptionFunc, pt as DependencyDeclarations, q as Decide, r as TransactionCommitOptions, rt as HandledDecision, s as InvokeOption, st as RequeueDecision, t as DeclareOptions, tt as ExponentialBackoff, u as InvokeOptionObjectWithKeys, ut as StopDecision, v as RegistrationOptions, vt as KeyReference, w as GraphResolution, wt as ResolutionCondition, x as WithdrawOptions, xt as ProvidedBy, y as ReplaceFunction, yt as OptionalDependency, z as InvocationContext, zt as Clock } from "./index-DTYp044J.mjs";
2
+ import { A as dispose, C as defineKey, D as invoke, E as where, M as EventKey, N as ListenerEntry, O as DisposeOptions, P as ListenerMetadata, S as stop, T as optional, _ as provide, a as resolve$1, b as StopOptions, c as stop$1, d as graph, f as transaction, g as resolve, h as ResolveOptions, j as effect, k as createContainer, l as listeners, m as withTimeout, n as invoke$1, o as setLogger, p as timeout, r as provide$1, s as start$1, t as getContainer, u as peek, v as listen, w as firstAvailable, x as start, y as StartOptions } from "./global-DPfe26g5.mjs";
3
3
  interface ObserveRecordBase {
4
4
  /** The key name of the service, or the name of the invocation. */
5
5
  readonly key: string;
@@ -53,9 +53,30 @@ interface ErrorObserveRecord extends ObserveRecordBase {
53
53
  readonly type: 'error';
54
54
  readonly error: unknown;
55
55
  }
56
+ /**
57
+ * The `signal` of `stop()`, `dispose()`, or `withdraw()` aborted before this service stopped. The call stopped waiting. The cleanups of the service keep running.
58
+ * `phase` is the phase at the abort. `abortReason` is the reason of the signal.
59
+ */
60
+ interface WaitAbortedObserveRecord extends ObserveRecordBase {
61
+ readonly type: 'wait-aborted';
62
+ readonly call: 'stop' | 'dispose' | 'withdraw';
63
+ readonly phase: ServicePhase;
64
+ readonly reason: string;
65
+ readonly abortReason: unknown;
66
+ }
67
+ /**
68
+ * A cleanup called `stop()` or `dispose()` of its own container, or of an ancestor, or `withdraw()` of a registration that waits for that cleanup.
69
+ * The wait includes that cleanup, so injeca resolved the call at once. The action continues.
70
+ * `key` is the service of the cleanup, or `''` for a container effect.
71
+ */
72
+ interface ReentrantCallObserveRecord extends ObserveRecordBase {
73
+ readonly type: 'reentrant-call';
74
+ readonly call: 'stop' | 'dispose' | 'withdraw';
75
+ readonly reason: string;
76
+ }
56
77
  /** One record of the observe stream. */
57
- type ObserveRecord = PhaseObserveRecord | StatusObserveRecord | DecisionObserveRecord | IgnoredObserveRecord | TimeoutObserveRecord | RegistrationReplacedObserveRecord | ErrorObserveRecord;
58
- type InjecaErrorCode = 'build-after-dispose' | 'duplicate-service' | 'hook-outside-build' | 'hook-timeout' | 'invalid-argument' | 'invalid-decision' | 'reentrant-dispose' | 'replace-while-stopping' | 'stale-registration' | 'start-timeout' | 'transaction-incomplete' | 'wait-timeout';
78
+ type ObserveRecord = PhaseObserveRecord | StatusObserveRecord | DecisionObserveRecord | IgnoredObserveRecord | TimeoutObserveRecord | RegistrationReplacedObserveRecord | ErrorObserveRecord | WaitAbortedObserveRecord | ReentrantCallObserveRecord;
79
+ type InjecaErrorCode = 'build-after-dispose' | 'duplicate-service' | 'hook-outside-build' | 'hook-timeout' | 'invalid-argument' | 'invalid-decision' | 'service-failed' | 'replace-while-stopping' | 'stale-registration' | 'start-timeout' | 'transaction-incomplete' | 'wait-timeout';
59
80
  interface InjecaErrorOptions {
60
81
  cause?: unknown;
61
82
  }
@@ -96,11 +117,6 @@ export declare class TransactionIncompleteError extends InjecaError {
96
117
  readonly code: 'transaction-incomplete';
97
118
  constructor(message: string, options?: InjecaErrorOptions);
98
119
  }
99
- /** `dispose()` was called from the cleanup chain of the same container. */
100
- export declare class ReentrantDisposeError extends InjecaError {
101
- readonly code: 'reentrant-dispose';
102
- constructor(message: string, options?: InjecaErrorOptions);
103
- }
104
120
  /** A `start` or `stop` hook did not settle before its configured timeout. */
105
121
  export declare class HookTimeoutError extends InjecaError {
106
122
  readonly code: 'hook-timeout';
@@ -120,7 +136,14 @@ export declare class StartTimeoutError extends InjecaError {
120
136
  readonly explanations: readonly ServiceExplanation[];
121
137
  constructor(message: string, explanations: readonly ServiceExplanation[], options?: InjecaErrorOptions);
122
138
  }
123
- /** `waitFor()` did not match before its configured timeout. */
139
+ /** `waitFor()` found the service in `failed`, or waiting for a required provider in `failed`. `cause` is the failure. */
140
+ export declare class ServiceFailedError extends InjecaError {
141
+ readonly code: 'service-failed';
142
+ /** The key name that the caller waited for. */
143
+ readonly key: string;
144
+ constructor(message: string, key: string, options?: InjecaErrorOptions);
145
+ }
146
+ /** `waitFor()` or `resolve()` did not match before its configured timeout. */
124
147
  export declare class WaitTimeoutError extends InjecaError {
125
148
  readonly code: 'wait-timeout';
126
149
  constructor(message: string, options?: InjecaErrorOptions);
@@ -150,15 +173,17 @@ export declare function watch(container: Container, key: WatchKey, callback: (st
150
173
  interface WaitForOptions {
151
174
  /** Waits for this effective status. Without it, `waitFor` waits until the key is available: `ready` or `degraded`. */
152
175
  status?: ServiceStatus;
153
- /** Rejects with `wait-timeout` after this many milliseconds of the container clock. There is no default. */
154
- timeoutMs?: number;
155
- /** Rejects with the abort reason when the signal aborts. */
176
+ /**
177
+ * Ends the wait when the signal aborts. A timeout reason (`name === 'TimeoutError'`) rejects with `wait-timeout`, with the reason as `cause`.
178
+ * Another reason rejects as it is. Use `timeout(container, ms)` for a timeout on the container clock. There is no default.
179
+ */
156
180
  signal?: AbortSignal;
157
181
  }
158
182
  /**
159
183
  * Resolves with the state of `key` when it is available, or when it has `options.status`.
160
184
  *
161
- * It rejects on a timeout or an abort, and when the container is disposed. It has no built-in timeout.
185
+ * It rejects with `service-failed` when the service is in `failed`, or when it waits for a required provider in `failed`, as `resolve` does.
186
+ * It rejects when `options.signal` aborts, at once for an aborted signal, and when the container is disposed. It has no built-in timeout.
162
187
  */
163
188
  export declare function waitFor(container: Container, key: WatchKey, options?: WaitForOptions): Promise<ServiceState>;
164
189
  export declare const injeca: {
@@ -170,5 +195,5 @@ export declare const injeca: {
170
195
  setLogger: typeof setLogger;
171
196
  getContainer: typeof getContainer;
172
197
  };
173
- export { type BuildContext, type Clock, type ConditionalDependency, type Container, type ContainerOptions, type Decide, type DecideFor, type Decision, type DecisionFor, type DecisionKind, type DecisionObserveRecord, type DecisionOptions, type DecisionSource, type DeclareOptions, type DependencyChange, type DependencyDeclaration, type DependencyDeclarations, type DependencyHook, type DependencyHookContext, type DependencyMap, type DependencySnapshot, type DependencyState, type Disposer, type EffectSetup, type ErrorObserveRecord, type EventKey, type ExponentialBackoff, type FailDecision, type FallbackDependency, type Graph, type GraphDependency, type GraphResolution, type GraphService, type HandledDecision, type HookContext, type HookContextFor, type HookDecisionKind, type HookDependencies, type HookHandler, type HookResult, type HookTimeouts, type IgnoredObserveRecord, type ImpactChange, type ImpactResult, type InferProvided, type InjecaErrorCode, type InjecaErrorOptions, type InvocationContext, type InvocationHandle, type InvokeOption, type InvokeOptionFunc, type InvokeOptionObject, type InvokeOptionObjectWithKeys, type InvokeOptionWithKeys, type KeyOptions, type KeyReference, type LifecycleContext, type ListenerEntry, type ListenerMetadata, type Logger, type LoggerOptions, type ObserveRecord, type ObserveRecordBase, type OptionalDependency, type OptionalValue, type OwnerRecord, type OwnerValue, type PhaseObserveRecord, type PolicyOptions, type ProvideOption, type ProvideOptionFunc, type ProvideOptionObject, type ProvideOptionObjectWithKeys, type ProvideOptionWithKeys, type ProvidedBy, type ProvidedKey, type ProviderInfo, type RebuildDecision, type Registration, type RegistrationOptions, type RegistrationReplacedObserveRecord, type ReplaceFunction, type RequeueDecision, type RequeueOptions, type ResolutionCondition, type ResolveDependencyDeclaration, type ServiceBlocker, type ServiceExplanation, type ServiceHook, type ServiceMetadata, type ServicePhase, type ServiceState, type ServiceStatus, type SetStatusOptions, type StartOptions, type StatusCause, type StatusObserveRecord, type StopDecision, type TimeoutContext, type TimeoutHandler, type TimeoutObserveRecord, type Transaction, type TransactionProvide, type TransactionReplace, type WaitForOptions, type WatchKey, createContainer, createDefaultLogger, createLoggLogger, createNoopLogger, defineKey, dispose, effect, firstAvailable, graph, invoke, listen, listeners, optional, provide, resolve, start, stop, systemClock, transaction, where };
198
+ export { type BuildContext, type Clock, type ConditionalDependency, type Container, type ContainerOptions, type Decide, type DecideFor, type Decision, type DecisionFor, type DecisionKind, type DecisionObserveRecord, type DecisionOptions, type DecisionSource, type DeclareOptions, type DependencyChange, type DependencyDeclaration, type DependencyDeclarations, type DependencyHook, type DependencyHookContext, type DependencyMap, type DependencySnapshot, type DependencyState, type DisposeOptions, type Disposer, type EffectSetup, type ErrorObserveRecord, type EventKey, type ExponentialBackoff, type FailDecision, type FallbackDependency, type Graph, type GraphDependency, type GraphResolution, type GraphService, type HandledDecision, type HookContext, type HookContextFor, type HookDecisionKind, type HookDependencies, type HookHandler, type HookResult, type HookTimeouts, type IgnoredObserveRecord, type ImpactChange, type ImpactResult, type InferProvided, type InjecaErrorCode, type InjecaErrorOptions, type InvocationContext, type InvocationHandle, type InvokeOption, type InvokeOptionFunc, type InvokeOptionObject, type InvokeOptionObjectWithKeys, type InvokeOptionWithKeys, type KeyOptions, type KeyReference, type LifecycleContext, type ListenerEntry, type ListenerMetadata, type Logger, type LoggerOptions, type ObserveRecord, type ObserveRecordBase, type OptionalDependency, type OptionalValue, type OwnerRecord, type OwnerValue, type PeekDependency, type PeekResult, type PeekValue, type PhaseObserveRecord, type PolicyOptions, type ProvideOption, type ProvideOptionFunc, type ProvideOptionObject, type ProvideOptionObjectWithKeys, type ProvideOptionWithKeys, type ProvidedBy, type ProvidedKey, type ProviderInfo, type RebuildDecision, type ReentrantCallObserveRecord, type Registration, type RegistrationOptions, type RegistrationReplacedObserveRecord, type ReplaceFunction, type ReplaceOptions, type RequeueDecision, type RequeueOptions, type ResolutionCondition, type ResolveDependencyDeclaration, type ResolveOptions, type ServiceBlocker, type ServiceExplanation, type ServiceHook, type ServiceMetadata, type ServicePhase, type ServiceState, type ServiceStatus, type SetStatusOptions, type StartOptions, type StatusCause, type StatusObserveRecord, type StopDecision, type StopOptions, type TimeoutContext, type TimeoutHandler, type TimeoutObserveRecord, type Transaction, type TransactionCommitOptions, type TransactionProvide, type TransactionReplace, type WaitAbortedObserveRecord, type WaitForOptions, type WatchKey, type WithdrawOptions, createContainer, createDefaultLogger, createLoggLogger, createNoopLogger, defineKey, dispose, effect, firstAvailable, graph, invoke, listen, listeners, optional, peek, provide, resolve, start, stop, systemClock, timeout, transaction, where, withTimeout };
174
199
  //# sourceMappingURL=index.d.mts.map