@fougere/container 0.6.0-alpha.0 → 0.7.0-alpha.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.
@@ -6,42 +6,16 @@ export type Constructor<T = unknown> = new (...args: any[]) => T;
6
6
  * Registration options.
7
7
  */
8
8
  export interface RegisterOptions {
9
- /**
10
- * Lifetime of the resolved value. Default: 'transient'.
11
- *
12
- * Two words, because two are used: `Config` is a singleton, every handler,
13
- * presenter, collector and provider is transient — a fresh instance per
14
- * resolution, which is what keeps one call's state out of the next. A third,
15
- * `'scoped'`, was declared and never passed by any caller: {@link Container.createScope}
16
- * already answers "one instance per frond, per surface", and two mechanisms for
17
- * one need is one too many.
18
- */
9
+ /** Lifetime of the resolved value. */
19
10
  lifetime?: 'singleton' | 'transient';
20
11
  /** Dependency type names for type-based resolution (from AST scan). */
21
12
  deps?: string[];
22
13
  }
23
- /**
24
- * Anything holding a resource can say so, and disposing the container says it back.
25
- *
26
- * Not an interface a class implements — a shape a class happens to have. A handler
27
- * that opens nothing declares nothing.
28
- */
14
+ /** Anything holding a resource can say so, and disposing the container says it back. */
29
15
  export interface Disposable {
30
16
  dispose(): void | Promise<void>;
31
17
  }
32
- /**
33
- * DI container interface — the only thing application code sees.
34
- *
35
- * It is deliberately small, and the reason is that the scan already knows the graph:
36
- * every class and every dependency is read from source before boot, so there is
37
- * almost nothing left to bind late. What remains is a Map with a parent chain, plus
38
- * the two gestures the scan cannot cover — {@link createScope} for isolation, and
39
- * {@link setFallback} for a frond that lives in another process.
40
- *
41
- * Resolution is by name, and the names are TYPE names produced by the AST scan.
42
- * The container never sees a type; "DI by type" is realized upstream, in the
43
- * scanner, which is why this file mentions neither.
44
- */
18
+ /** DI container interface — the only thing application code sees. */
45
19
  export interface Container {
46
20
  /** Register a class by name. Its `deps` are resolved from this container. */
47
21
  register<T>(name: string, ctor: Constructor<T>, options?: RegisterOptions): void;
@@ -51,33 +25,11 @@ export interface Container {
51
25
  resolve<T>(name: string): T;
52
26
  /** Check if a name is registered (including parent scopes). */
53
27
  has(name: string): boolean;
54
- /**
55
- * A resolver of last resort, consulted when no scope holds the name.
56
- *
57
- * It exists for one reason: a frond declared in `remotes` registers nothing locally,
58
- * so its façade cannot be *found* — it has to be fabricated. Set on the root, inherited
59
- * by every scope. Returning `undefined` means "I don't know either", and the miss
60
- * throws as before.
61
- *
62
- * Optional: a container without one behaves exactly as it did.
63
- */
28
+ /** A resolver of last resort, consulted when no scope holds the name. */
64
29
  setFallback?(resolve: (name: string) => unknown): void;
65
30
  /** Create a child scope. Inherits parent registrations. */
66
31
  createScope(): Container;
67
- /**
68
- * Dispose the container: every instance it KEPT — the singletons — that has a
69
- * `dispose` method is told, most recent first, and awaited. A failure does not
70
- * silence the rest; they travel out together in an `AggregateError`.
71
- *
72
- * This used to clear the registry and nothing else, while the doc above it promised
73
- * disposal — so `await using app` (which routes here through `app[Symbol.asyncDispose]`)
74
- * announced a cleanup that never happened. A container that holds instances is the
75
- * only thing that knows they exist; if it stays silent, nobody else can speak.
76
- *
77
- * What it does NOT dispose: a transient, handed over and forgotten in the same
78
- * breath, whose caller is the one who knows when it is done; and a value passed to
79
- * {@link registerValue}, which the container did not build.
80
- */
32
+ /** Dispose the container. */
81
33
  dispose(): Promise<void>;
82
34
  }
83
35
  //# sourceMappingURL=container.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,WAAW,GAAG,WAAW,CAAC;IACrC,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;;;GAKG;AACH,M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AC;CACjC;AAED,qEAAqE;AACrE,MAAM,WAAW,SAAS;IACxB,6EAA6E;IAC7E,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAEjF,0CAA0C;IAC1C,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAE/C,oCAAoC;IACpC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC;IAE5B,+DAA+D;IAC/D,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAE3B,yEAAyE;IACzE,WAAW,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,IAAI,CAAC;IAEvD,2DAA2D;IAC3D,WAAW,IAAI,SAAS,CAAC;IAEzB,6BAA6B;IAC7B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fougere/container",
3
- "version": "0.6.0-alpha.0",
3
+ "version": "0.7.0-alpha.0",
4
4
  "description": "Fougere's DI container: resolution by type, wired from the AST scan. Zero dependencies.",
5
5
  "keywords": [
6
6
  "fougere",
package/src/container.ts CHANGED
@@ -8,44 +8,18 @@ export type Constructor<T = unknown> = new (...args: any[]) => T;
8
8
  * Registration options.
9
9
  */
10
10
  export interface RegisterOptions {
11
- /**
12
- * Lifetime of the resolved value. Default: 'transient'.
13
- *
14
- * Two words, because two are used: `Config` is a singleton, every handler,
15
- * presenter, collector and provider is transient — a fresh instance per
16
- * resolution, which is what keeps one call's state out of the next. A third,
17
- * `'scoped'`, was declared and never passed by any caller: {@link Container.createScope}
18
- * already answers "one instance per frond, per surface", and two mechanisms for
19
- * one need is one too many.
20
- */
11
+ /** Lifetime of the resolved value. */
21
12
  lifetime?: 'singleton' | 'transient';
22
13
  /** Dependency type names for type-based resolution (from AST scan). */
23
14
  deps?: string[];
24
15
  }
25
16
 
26
- /**
27
- * Anything holding a resource can say so, and disposing the container says it back.
28
- *
29
- * Not an interface a class implements — a shape a class happens to have. A handler
30
- * that opens nothing declares nothing.
31
- */
17
+ /** Anything holding a resource can say so, and disposing the container says it back. */
32
18
  export interface Disposable {
33
19
  dispose(): void | Promise<void>;
34
20
  }
35
21
 
36
- /**
37
- * DI container interface — the only thing application code sees.
38
- *
39
- * It is deliberately small, and the reason is that the scan already knows the graph:
40
- * every class and every dependency is read from source before boot, so there is
41
- * almost nothing left to bind late. What remains is a Map with a parent chain, plus
42
- * the two gestures the scan cannot cover — {@link createScope} for isolation, and
43
- * {@link setFallback} for a frond that lives in another process.
44
- *
45
- * Resolution is by name, and the names are TYPE names produced by the AST scan.
46
- * The container never sees a type; "DI by type" is realized upstream, in the
47
- * scanner, which is why this file mentions neither.
48
- */
22
+ /** DI container interface — the only thing application code sees. */
49
23
  export interface Container {
50
24
  /** Register a class by name. Its `deps` are resolved from this container. */
51
25
  register<T>(name: string, ctor: Constructor<T>, options?: RegisterOptions): void;
@@ -59,34 +33,12 @@ export interface Container {
59
33
  /** Check if a name is registered (including parent scopes). */
60
34
  has(name: string): boolean;
61
35
 
62
- /**
63
- * A resolver of last resort, consulted when no scope holds the name.
64
- *
65
- * It exists for one reason: a frond declared in `remotes` registers nothing locally,
66
- * so its façade cannot be *found* — it has to be fabricated. Set on the root, inherited
67
- * by every scope. Returning `undefined` means "I don't know either", and the miss
68
- * throws as before.
69
- *
70
- * Optional: a container without one behaves exactly as it did.
71
- */
36
+ /** A resolver of last resort, consulted when no scope holds the name. */
72
37
  setFallback?(resolve: (name: string) => unknown): void;
73
38
 
74
39
  /** Create a child scope. Inherits parent registrations. */
75
40
  createScope(): Container;
76
41
 
77
- /**
78
- * Dispose the container: every instance it KEPT — the singletons — that has a
79
- * `dispose` method is told, most recent first, and awaited. A failure does not
80
- * silence the rest; they travel out together in an `AggregateError`.
81
- *
82
- * This used to clear the registry and nothing else, while the doc above it promised
83
- * disposal — so `await using app` (which routes here through `app[Symbol.asyncDispose]`)
84
- * announced a cleanup that never happened. A container that holds instances is the
85
- * only thing that knows they exist; if it stays silent, nobody else can speak.
86
- *
87
- * What it does NOT dispose: a transient, handed over and forgotten in the same
88
- * breath, whose caller is the one who knows when it is done; and a value passed to
89
- * {@link registerValue}, which the container did not build.
90
- */
42
+ /** Dispose the container. */
91
43
  dispose(): Promise<void>;
92
44
  }