@fluixi/di 0.0.0-stage → 1.0.0-alpha.99

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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +43 -2
  3. package/dist/errors.cjs +36 -0
  4. package/dist/errors.d.ts +31 -0
  5. package/dist/errors.d.ts.map +1 -0
  6. package/dist/errors.js +34 -0
  7. package/dist/errors.mjs +15 -0
  8. package/dist/hierarchy.cjs +291 -0
  9. package/dist/hierarchy.d.ts +11 -0
  10. package/dist/hierarchy.d.ts.map +1 -0
  11. package/dist/hierarchy.js +47 -0
  12. package/dist/hierarchy.mjs +271 -0
  13. package/dist/index.cjs +374 -0
  14. package/dist/index.d.ts +17 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +15 -0
  17. package/dist/index.mjs +352 -0
  18. package/dist/initializers.cjs +289 -0
  19. package/dist/initializers.d.ts +36 -0
  20. package/dist/initializers.d.ts.map +1 -0
  21. package/dist/initializers.js +45 -0
  22. package/dist/initializers.mjs +267 -0
  23. package/dist/inject.cjs +352 -0
  24. package/dist/inject.d.ts +151 -0
  25. package/dist/inject.d.ts.map +1 -0
  26. package/dist/inject.js +174 -0
  27. package/dist/inject.mjs +332 -0
  28. package/dist/injector.cjs +259 -0
  29. package/dist/injector.d.ts +73 -0
  30. package/dist/injector.d.ts.map +1 -0
  31. package/dist/injector.js +213 -0
  32. package/dist/injector.mjs +239 -0
  33. package/dist/provider.cjs +18 -0
  34. package/dist/provider.d.ts +97 -0
  35. package/dist/provider.d.ts.map +1 -0
  36. package/dist/provider.js +1 -0
  37. package/dist/provider.mjs +0 -0
  38. package/dist/state.cjs +45 -0
  39. package/dist/state.d.ts +35 -0
  40. package/dist/state.d.ts.map +1 -0
  41. package/dist/state.js +26 -0
  42. package/dist/state.mjs +24 -0
  43. package/dist/testing.cjs +275 -0
  44. package/dist/testing.d.ts +50 -0
  45. package/dist/testing.d.ts.map +1 -0
  46. package/dist/testing.js +48 -0
  47. package/dist/testing.mjs +253 -0
  48. package/dist/token.cjs +28 -0
  49. package/dist/token.d.ts +67 -0
  50. package/dist/token.d.ts.map +1 -0
  51. package/dist/token.js +33 -0
  52. package/dist/token.mjs +7 -0
  53. package/dist/tokens.cjs +35 -0
  54. package/dist/tokens.d.ts +53 -0
  55. package/dist/tokens.d.ts.map +1 -0
  56. package/dist/tokens.js +26 -0
  57. package/dist/tokens.mjs +12 -0
  58. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  59. package/package.json +55 -3
@@ -0,0 +1,239 @@
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
9
+
10
+ // src/injector.ts
11
+ import { openReactiveScope, withReactiveScope } from "@fluixi/reactive/signal";
12
+
13
+ // src/errors.ts
14
+ var InjectionError = class extends Error {
15
+ /**
16
+ * @param message - What went wrong, with the path rendered into it.
17
+ * @param path - The tokens being resolved, outermost first; the last one is the one that failed.
18
+ */
19
+ constructor(message, path) {
20
+ super(message);
21
+ this.path = path;
22
+ this.name = "InjectionError";
23
+ }
24
+ };
25
+
26
+ // src/hierarchy.ts
27
+ import { getRequestContext, onRequestEnd } from "@fluixi/dom";
28
+ import { getOwner } from "@fluixi/reactive/signal";
29
+
30
+ // src/state.ts
31
+ function freshState() {
32
+ return {
33
+ platformProviders: [],
34
+ rootProviders: [],
35
+ platform: null,
36
+ clientRoot: null,
37
+ requestRoots: /* @__PURE__ */ new WeakMap(),
38
+ ownerInjectors: /* @__PURE__ */ new WeakMap(),
39
+ moduleScopes: /* @__PURE__ */ new WeakMap(),
40
+ overrides: /* @__PURE__ */ new Map(),
41
+ explicit: null,
42
+ path: []
43
+ };
44
+ }
45
+ var state = globalThis[/* @__PURE__ */ Symbol.for("fluixi.di")] ??= freshState();
46
+
47
+ // src/hierarchy.ts
48
+ function platformInjector() {
49
+ return state.platform ??= new Injector(null, "platform").register(state.platformProviders);
50
+ }
51
+
52
+ // src/token.ts
53
+ function injectionToken(name, options) {
54
+ return { id: Symbol(name), name, factory: options?.factory, scope: options?.scope ?? "root" };
55
+ }
56
+
57
+ // src/tokens.ts
58
+ var DestroyRef = injectionToken("DestroyRef");
59
+ var INJECTOR = injectionToken("Injector");
60
+
61
+ // src/injector.ts
62
+ var _records, _created, _hooks, _destroyed, _Injector_instances, home_fn, fromProvider_fn, build_fn, make_fn;
63
+ var Injector = class {
64
+ /**
65
+ * @param parent - Where a token this injector does not hold is looked for next; `null` for the
66
+ * top of a chain.
67
+ * @param kind - Where the injector sits in the hierarchy; see {@link InjectorKind}.
68
+ */
69
+ constructor(parent = null, kind = "standalone") {
70
+ this.parent = parent;
71
+ this.kind = kind;
72
+ __privateAdd(this, _Injector_instances);
73
+ __privateAdd(this, _records, /* @__PURE__ */ new Map());
74
+ __privateAdd(this, _created, []);
75
+ __privateAdd(this, _hooks, []);
76
+ __privateAdd(this, _destroyed, false);
77
+ const self = this;
78
+ this.destroyRef = {
79
+ onDestroy(fn) {
80
+ __privateGet(self, _hooks).push(fn);
81
+ return () => {
82
+ const i = __privateGet(self, _hooks).indexOf(fn);
83
+ if (i >= 0) __privateGet(self, _hooks).splice(i, 1);
84
+ };
85
+ },
86
+ get destroyed() {
87
+ return __privateGet(self, _destroyed);
88
+ }
89
+ };
90
+ }
91
+ /** Whether {@link Injector.dispose} has run. A disposed injector refuses every `get`. */
92
+ get destroyed() {
93
+ return __privateGet(this, _destroyed);
94
+ }
95
+ /**
96
+ * Add providers to this injector. A provider for a token already held replaces it, except
97
+ * `multi` providers, which extend the token's list. A provider whose token has a test override
98
+ * is replaced by the override.
99
+ *
100
+ * @param providers - The providers to add, in order.
101
+ * @returns This injector, for chaining.
102
+ */
103
+ register(providers) {
104
+ for (const given of providers) {
105
+ const p = state.overrides.get(given.provide.id) ?? given;
106
+ if (p.multi) {
107
+ const rec = __privateGet(this, _records).get(p.provide.id);
108
+ if (rec?.multi) {
109
+ rec.providers.push(p);
110
+ rec.built = false;
111
+ } else __privateGet(this, _records).set(p.provide.id, { multi: true, providers: [p], built: false, building: false, value: [] });
112
+ } else {
113
+ __privateGet(this, _records).set(p.provide.id, { multi: false, provider: p, built: false, building: false, value: void 0 });
114
+ }
115
+ }
116
+ return this;
117
+ }
118
+ get(token, options = {}) {
119
+ var _a, _b, _c;
120
+ if (__privateGet(this, _destroyed)) throw new InjectionError(`[fluixi/di] "${token.name}" requested from a disposed injector.`, [...state.path, token.name]);
121
+ if (token.id === INJECTOR.id) return this;
122
+ if (token.id === DestroyRef.id) return this.destroyRef;
123
+ let inj = options.skipSelf ? this.parent : this;
124
+ while (inj) {
125
+ const rec = __privateGet(inj, _records).get(token.id);
126
+ if (rec) return __privateMethod(_a = inj, _Injector_instances, build_fn).call(_a, token, rec);
127
+ if (options.self || options.host && inj.kind === "owner") break;
128
+ inj = inj.parent;
129
+ }
130
+ const override = state.overrides.get(token.id);
131
+ if (override && !options.self) return __privateMethod(_b = __privateMethod(this, _Injector_instances, home_fn).call(this, token.scope), _Injector_instances, fromProvider_fn).call(_b, token, override);
132
+ if (token.factory && !options.self && !options.host) {
133
+ return __privateMethod(_c = __privateMethod(this, _Injector_instances, home_fn).call(this, token.scope), _Injector_instances, fromProvider_fn).call(_c, token, { provide: token, useFactory: token.factory });
134
+ }
135
+ if (options.optional) return null;
136
+ const path = [...state.path, token.name];
137
+ throw new InjectionError(
138
+ `[fluixi/di] No provider for "${token.name}" (${path.join(" → ")}). Provide it in an app module, with provide() or provideRoot(), or give the token a { factory }.`,
139
+ path
140
+ );
141
+ }
142
+ /**
143
+ * Release this injector: run the hooks registered on its `DestroyRef`, latest first, then the
144
+ * `onDestroy()` method of every service it built, latest built first, then forget its
145
+ * providers. A hook or `onDestroy()` that throws is logged and the rest still run. Running it
146
+ * again does nothing.
147
+ *
148
+ * Component injectors are disposed when the component unmounts, request roots when the request
149
+ * ends; call it yourself only for injectors you created.
150
+ */
151
+ dispose() {
152
+ if (__privateGet(this, _destroyed)) return;
153
+ __privateSet(this, _destroyed, true);
154
+ const fail = (error) => console.error("[fluixi/di] a destroy hook threw:", error);
155
+ for (const hook of __privateGet(this, _hooks).splice(0).reverse()) {
156
+ try {
157
+ hook();
158
+ } catch (error) {
159
+ fail(error);
160
+ }
161
+ }
162
+ for (const value of __privateGet(this, _created).splice(0).reverse()) {
163
+ const service = value;
164
+ if (service && typeof service.onDestroy === "function") {
165
+ try {
166
+ service.onDestroy();
167
+ } catch (error) {
168
+ fail(error);
169
+ }
170
+ }
171
+ }
172
+ __privateGet(this, _records).clear();
173
+ }
174
+ };
175
+ _records = new WeakMap();
176
+ _created = new WeakMap();
177
+ _hooks = new WeakMap();
178
+ _destroyed = new WeakMap();
179
+ _Injector_instances = new WeakSet();
180
+ /** The injector a self-providing token builds in: the nearest root, or the platform. */
181
+ home_fn = function(scope) {
182
+ let inj = this;
183
+ if (scope === "platform") {
184
+ while (inj.parent) inj = inj.parent;
185
+ return inj.kind === "platform" ? inj : platformInjector();
186
+ }
187
+ let probe = this;
188
+ while (probe) {
189
+ if (probe.kind === "root") return probe;
190
+ probe = probe.parent;
191
+ }
192
+ while (inj.parent && inj.parent.kind !== "platform") inj = inj.parent;
193
+ return inj;
194
+ };
195
+ fromProvider_fn = function(token, provider) {
196
+ let rec = __privateGet(this, _records).get(token.id);
197
+ if (!rec) {
198
+ rec = { multi: false, provider, built: false, building: false, value: void 0 };
199
+ __privateGet(this, _records).set(token.id, rec);
200
+ }
201
+ return __privateMethod(this, _Injector_instances, build_fn).call(this, token, rec);
202
+ };
203
+ build_fn = function(token, rec) {
204
+ if (rec.built) return rec.value;
205
+ if (rec.building) {
206
+ const path = [...state.path, token.name];
207
+ throw new InjectionError(`[fluixi/di] Circular dependency: ${path.join(" → ")}.`, path);
208
+ }
209
+ rec.building = true;
210
+ state.path.push(token.name);
211
+ const previous = state.explicit;
212
+ state.explicit = this;
213
+ try {
214
+ if (rec.multi) {
215
+ rec.value = rec.providers.map((p) => __privateMethod(this, _Injector_instances, make_fn).call(this, token, p));
216
+ } else {
217
+ const module = state.moduleScopes.get(rec.provider);
218
+ rec.value = module ? withReactiveScope(module, () => __privateMethod(this, _Injector_instances, make_fn).call(this, token, rec.provider)) : __privateMethod(this, _Injector_instances, make_fn).call(this, token, rec.provider);
219
+ }
220
+ rec.built = true;
221
+ return rec.value;
222
+ } finally {
223
+ state.explicit = previous;
224
+ state.path.pop();
225
+ rec.building = false;
226
+ }
227
+ };
228
+ make_fn = function(token, p) {
229
+ if ("useValue" in p) return p.useValue;
230
+ if ("useExisting" in p) return this.get(p.useExisting);
231
+ const deps = (p.deps ?? []).map((d) => "token" in d ? this.get(d.token, d) : this.get(d));
232
+ const scope = openReactiveScope({ kind: "service", name: token.name, detail: "useClass" in p ? "useClass" : "useFactory" });
233
+ const value = withReactiveScope(scope, () => "useClass" in p ? new p.useClass(...deps) : p.useFactory(...deps));
234
+ __privateGet(this, _created).push(value);
235
+ return value;
236
+ };
237
+ export {
238
+ Injector
239
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/provider.ts
17
+ var provider_exports = {};
18
+ module.exports = __toCommonJS(provider_exports);
@@ -0,0 +1,97 @@
1
+ /**
2
+ * How a token gets its value in an injector, and the options a resolution takes.
3
+ *
4
+ * @module
5
+ */
6
+ import type { Token } from './token.js';
7
+ /**
8
+ * Options for one resolution, given to `inject()`, `Injector.get()` or a provider's `deps`.
9
+ * They combine: `{ optional: true, skipSelf: true }` looks from the parent up and answers `null`
10
+ * when nothing is found.
11
+ */
12
+ export interface InjectOptions {
13
+ /**
14
+ * Answer `null` instead of throwing an `InjectionError` when nothing provides the token. A
15
+ * self-providing token is still built.
16
+ */
17
+ optional?: boolean;
18
+ /**
19
+ * Look only in the injector asked. Neither its parents nor the token's own factory are
20
+ * consulted.
21
+ */
22
+ self?: boolean;
23
+ /**
24
+ * Start with the parent of the injector asked: a component asking for what its ancestors
25
+ * provide, while providing the same token to its own descendants.
26
+ */
27
+ skipSelf?: boolean;
28
+ /**
29
+ * Stop at the nearest component injector, the one `provide()` created, after looking in it.
30
+ * Keeps a component from reaching past its own host for a dependency. The token's own factory
31
+ * is not consulted.
32
+ */
33
+ host?: boolean;
34
+ }
35
+ /**
36
+ * A dependency of a class or factory provider, resolved in order and passed as arguments: a token,
37
+ * or a token with {@link InjectOptions}.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * { provide: Cache, useFactory: (store, log) => new Cache(store, log),
42
+ * deps: [Store, { token: Logger, optional: true }] }
43
+ * ```
44
+ */
45
+ export type Dependency = Token<unknown> | ({
46
+ token: Token<unknown>;
47
+ } & InjectOptions);
48
+ /** What every provider has: the token it provides, and whether it contributes to a list. */
49
+ interface ProviderBase<T> {
50
+ /** The token this provider answers. */
51
+ provide: Token<T>;
52
+ /**
53
+ * Contribute one value to a list instead of replacing the token's value. Every `multi`
54
+ * provider of the token in one injector forms the list, in registration order, and
55
+ * `inject(token)` returns that array. A child injector with its own `multi` providers for the
56
+ * token has its own list; it does not extend its parent's.
57
+ */
58
+ multi?: boolean;
59
+ }
60
+ /**
61
+ * How an injector produces the value of a token. Exactly one of the four forms:
62
+ *
63
+ * - `useValue`: this value, as given.
64
+ * - `useClass`: a new instance of the class, its constructor called with `deps`.
65
+ * - `useFactory`: the function's result, called with `deps`.
66
+ * - `useExisting`: an alias; whatever another token resolves to.
67
+ *
68
+ * Classes and factories run in the injection context of the injector that holds the provider:
69
+ * `inject()` inside a constructor or factory resolves from there, not from wherever the service
70
+ * was first asked for. What they build is released with that injector (see `DestroyRef`).
71
+ *
72
+ * @typeParam T - The type of the value provided.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * provideRoot([
77
+ * { provide: ApiUrl, useValue: 'https://api.example.com' },
78
+ * { provide: Http, useClass: FetchHttp, deps: [ApiUrl] },
79
+ * { provide: Users, useFactory: () => new UserService(inject(Http)) },
80
+ * { provide: AnyHttp, useExisting: Http },
81
+ * { provide: Interceptors, useValue: authInterceptor, multi: true },
82
+ * ]);
83
+ * ```
84
+ */
85
+ export type Provider<T = any> = ProviderBase<T> & ({
86
+ useValue: T;
87
+ } | {
88
+ useClass: new (...args: any[]) => T;
89
+ deps?: ReadonlyArray<Dependency>;
90
+ } | {
91
+ useFactory: (...args: any[]) => T;
92
+ deps?: ReadonlyArray<Dependency>;
93
+ } | {
94
+ useExisting: Token<T>;
95
+ });
96
+ export {};
97
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;IAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;CAAE,GAAG,aAAa,CAAC,CAAC;AAEtF,4FAA4F;AAC5F,UAAU,YAAY,CAAC,CAAC;IACtB,uCAAuC;IACvC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAClB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,GAC7C,CACI;IAAE,QAAQ,EAAE,CAAC,CAAA;CAAE,GACf;IAAE,QAAQ,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAAC,IAAI,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAA;CAAE,GACzE;IAAE,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAAC,IAAI,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAA;CAAE,GACvE;IAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;CAAE,CAC5B,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
File without changes
package/dist/state.cjs ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/state.ts
21
+ var state_exports = {};
22
+ __export(state_exports, {
23
+ freshState: () => freshState,
24
+ setModuleScope: () => setModuleScope,
25
+ state: () => state
26
+ });
27
+ module.exports = __toCommonJS(state_exports);
28
+ function freshState() {
29
+ return {
30
+ platformProviders: [],
31
+ rootProviders: [],
32
+ platform: null,
33
+ clientRoot: null,
34
+ requestRoots: /* @__PURE__ */ new WeakMap(),
35
+ ownerInjectors: /* @__PURE__ */ new WeakMap(),
36
+ moduleScopes: /* @__PURE__ */ new WeakMap(),
37
+ overrides: /* @__PURE__ */ new Map(),
38
+ explicit: null,
39
+ path: []
40
+ };
41
+ }
42
+ var state = globalThis[/* @__PURE__ */ Symbol.for("fluixi.di")] ??= freshState();
43
+ function setModuleScope(provider, scope) {
44
+ state.moduleScopes.set(provider, scope);
45
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @module
3
+ *
4
+ * The state every copy of this package shares. It lives in the global registry: a server bundle
5
+ * inlines its own copy of the package while packages from node_modules use another, and both
6
+ * must see the same injectors and providers.
7
+ */
8
+ import type { Injector } from './injector.js';
9
+ import type { Provider } from './provider.js';
10
+ export interface DiState {
11
+ platformProviders: Provider[];
12
+ rootProviders: Provider[];
13
+ platform: Injector | null;
14
+ clientRoot: Injector | null;
15
+ requestRoots: WeakMap<object, Injector>;
16
+ ownerInjectors: WeakMap<object, Injector>;
17
+ moduleScopes: WeakMap<object, object>;
18
+ overrides: Map<symbol, Provider>;
19
+ /** The injector `inject()` resolves from when one is set explicitly or is building a service. */
20
+ explicit: Injector | null;
21
+ /** The tokens being resolved, outermost first, for error messages. */
22
+ path: string[];
23
+ }
24
+ export declare function freshState(): DiState;
25
+ export declare const state: DiState;
26
+ /**
27
+ * Record which app module declared `provider`, so the devtools graph groups the services it
28
+ * builds under that module. Called by the framework when it collects an app's modules; app code
29
+ * has no reason to call it.
30
+ *
31
+ * @param provider - A provider from the module's list.
32
+ * @param scope - The module's devtools scope.
33
+ */
34
+ export declare function setModuleScope(provider: Provider, scope: object): void;
35
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,WAAW,OAAO;IACtB,iBAAiB,EAAE,QAAQ,EAAE,CAAC;IAC9B,aAAa,EAAE,QAAQ,EAAE,CAAC;IAC1B,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACxC,cAAc,EAAE,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC1C,YAAY,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACjC,iGAAiG;IACjG,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC1B,sEAAsE;IACtE,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,wBAAgB,UAAU,IAAI,OAAO,CAapC;AAED,eAAO,MAAM,KAAK,EAAE,OAAwG,CAAC;AAE7H;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAEtE"}
package/dist/state.js ADDED
@@ -0,0 +1,26 @@
1
+ export function freshState() {
2
+ return {
3
+ platformProviders: [],
4
+ rootProviders: [],
5
+ platform: null,
6
+ clientRoot: null,
7
+ requestRoots: new WeakMap(),
8
+ ownerInjectors: new WeakMap(),
9
+ moduleScopes: new WeakMap(),
10
+ overrides: new Map(),
11
+ explicit: null,
12
+ path: [],
13
+ };
14
+ }
15
+ export const state = (globalThis[Symbol.for('fluixi.di')] ??= freshState());
16
+ /**
17
+ * Record which app module declared `provider`, so the devtools graph groups the services it
18
+ * builds under that module. Called by the framework when it collects an app's modules; app code
19
+ * has no reason to call it.
20
+ *
21
+ * @param provider - A provider from the module's list.
22
+ * @param scope - The module's devtools scope.
23
+ */
24
+ export function setModuleScope(provider, scope) {
25
+ state.moduleScopes.set(provider, scope);
26
+ }
package/dist/state.mjs ADDED
@@ -0,0 +1,24 @@
1
+ // src/state.ts
2
+ function freshState() {
3
+ return {
4
+ platformProviders: [],
5
+ rootProviders: [],
6
+ platform: null,
7
+ clientRoot: null,
8
+ requestRoots: /* @__PURE__ */ new WeakMap(),
9
+ ownerInjectors: /* @__PURE__ */ new WeakMap(),
10
+ moduleScopes: /* @__PURE__ */ new WeakMap(),
11
+ overrides: /* @__PURE__ */ new Map(),
12
+ explicit: null,
13
+ path: []
14
+ };
15
+ }
16
+ var state = globalThis[/* @__PURE__ */ Symbol.for("fluixi.di")] ??= freshState();
17
+ function setModuleScope(provider, scope) {
18
+ state.moduleScopes.set(provider, scope);
19
+ }
20
+ export {
21
+ freshState,
22
+ setModuleScope,
23
+ state
24
+ };