@kyrielle/injector 2.0.0-alpha.0 → 2.0.0-alpha.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.
Files changed (57) hide show
  1. package/LICENSE +21 -21
  2. package/dist/browser.d.ts +25 -0
  3. package/dist/browser.js +29 -0
  4. package/dist/browser.js.map +1 -0
  5. package/dist/{index.d.ts → common.d.ts} +1 -3
  6. package/dist/common.js +6 -0
  7. package/dist/common.js.map +1 -0
  8. package/dist/current-scope.d.ts +1 -0
  9. package/dist/current-scope.js +7 -0
  10. package/dist/current-scope.js.map +1 -0
  11. package/dist/defs/index.js.map +1 -1
  12. package/dist/defs/injectable.js +2 -2
  13. package/dist/defs/injectable.js.map +1 -1
  14. package/dist/defs/scope.d.ts +1 -1
  15. package/dist/defs/scope.js.map +1 -1
  16. package/dist/defs/token.d.ts +2 -2
  17. package/dist/defs/token.js.map +1 -1
  18. package/dist/global-scope.d.ts +1 -1
  19. package/dist/global-scope.js +5 -4
  20. package/dist/global-scope.js.map +1 -1
  21. package/dist/inject.d.ts +1 -7
  22. package/dist/inject.js +12 -15
  23. package/dist/inject.js.map +1 -1
  24. package/dist/internals/BrowserContext.d.ts +7 -0
  25. package/dist/internals/BrowserContext.js +23 -0
  26. package/dist/internals/BrowserContext.js.map +1 -0
  27. package/dist/internals/InjectionContext.d.ts +12 -0
  28. package/dist/internals/InjectionContext.js +3 -0
  29. package/dist/internals/InjectionContext.js.map +1 -0
  30. package/dist/internals/NodeContext.d.ts +7 -0
  31. package/dist/internals/NodeContext.js +13 -0
  32. package/dist/internals/NodeContext.js.map +1 -0
  33. package/dist/internals/UnsupportedAsyncToken.d.ts +2 -0
  34. package/dist/internals/UnsupportedAsyncToken.js +4 -0
  35. package/dist/internals/UnsupportedAsyncToken.js.map +1 -0
  36. package/dist/node.d.ts +25 -0
  37. package/dist/node.js +29 -0
  38. package/dist/node.js.map +1 -0
  39. package/dist/root-scope.d.ts +7 -0
  40. package/dist/root-scope.js +15 -0
  41. package/dist/root-scope.js.map +1 -0
  42. package/dist/run-in.d.ts +1 -0
  43. package/dist/run-in.js +7 -0
  44. package/dist/run-in.js.map +1 -0
  45. package/dist/scope.d.ts +1 -7
  46. package/dist/scope.js +16 -19
  47. package/dist/scope.js.map +1 -1
  48. package/dist/token.d.ts +1 -1
  49. package/dist/token.js +4 -4
  50. package/dist/token.js.map +1 -1
  51. package/dist/tsconfig.build.tsbuildinfo +1 -1
  52. package/package.json +69 -60
  53. package/dist/async-scope.d.ts +0 -30
  54. package/dist/async-scope.js +0 -14
  55. package/dist/async-scope.js.map +0 -1
  56. package/dist/index.js +0 -8
  57. package/dist/index.js.map +0 -1
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Julien Capellari
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Julien Capellari
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,25 @@
1
+ export * from './common.js';
2
+ /**
3
+ * Returns current scope.
4
+ *
5
+ * @version 2.0.0
6
+ */
7
+ export declare const currentScope$: () => import("./common.js").Scope;
8
+ /**
9
+ * Creates an instance of token, using and storing in scope.
10
+ *
11
+ * @version 1.0.0
12
+ */
13
+ export declare const inject$: <T>(token: import("./common.js").Token<T>, scope?: import("./common.js").Scope) => T;
14
+ /**
15
+ * Runs a function in a given scope. Any {@link inject$} calls within the function will use the provided scope by default.
16
+ *
17
+ * @version 2.0.0
18
+ */
19
+ export declare const runIn$: <T>(scope: import("./common.js").Scope, fn: () => T) => T;
20
+ /**
21
+ * Creates a new {@link ChildScope}, with a given parent defaulting to current scope
22
+ *
23
+ * @version 1.0.0
24
+ */
25
+ export declare const scope$: (name: string, parent?: import("./common.js").Scope) => import("./common.js").ChildScope;
@@ -0,0 +1,29 @@
1
+ import { createCurrentScope$ } from './current-scope.js';
2
+ import { createInject$ } from './inject.js';
3
+ import { BrowserContext } from './internals/BrowserContext.js';
4
+ import { createRunIn$ } from './run-in.js';
5
+ import { createScope$ } from './scope.js';
6
+ const context = new BrowserContext();
7
+ export * from './common.js';
8
+ /**
9
+ * Returns current scope.
10
+ *
11
+ * @version 2.0.0
12
+ */ export const currentScope$ = createCurrentScope$(context);
13
+ /**
14
+ * Creates an instance of token, using and storing in scope.
15
+ *
16
+ * @version 1.0.0
17
+ */ export const inject$ = createInject$(context);
18
+ /**
19
+ * Runs a function in a given scope. Any {@link inject$} calls within the function will use the provided scope by default.
20
+ *
21
+ * @version 2.0.0
22
+ */ export const runIn$ = createRunIn$(context);
23
+ /**
24
+ * Creates a new {@link ChildScope}, with a given parent defaulting to current scope
25
+ *
26
+ * @version 1.0.0
27
+ */ export const scope$ = createScope$(context);
28
+
29
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/browser.ts"],"sourcesContent":["import { createCurrentScope$ } from './current-scope.js';\nimport { createInject$ } from './inject.js';\nimport { BrowserContext } from './internals/BrowserContext.js';\nimport { createRunIn$ } from './run-in.js';\nimport { createScope$ } from './scope.js';\n\nconst context = new BrowserContext();\n\nexport * from './common.js';\n\n/**\n * Returns current scope.\n *\n * @version 2.0.0\n */\nexport const currentScope$ = createCurrentScope$(context);\n\n/**\n * Creates an instance of token, using and storing in scope.\n *\n * @version 1.0.0\n */\nexport const inject$ = createInject$(context);\n\n/**\n * Runs a function in a given scope. Any {@link inject$} calls within the function will use the provided scope by default.\n *\n * @version 2.0.0\n */\nexport const runIn$ = createRunIn$(context);\n\n/**\n * Creates a new {@link ChildScope}, with a given parent defaulting to current scope\n *\n * @version 1.0.0\n */\nexport const scope$ = createScope$(context);"],"names":["createCurrentScope$","createInject$","BrowserContext","createRunIn$","createScope$","context","currentScope$","inject$","runIn$","scope$"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,qBAAqB;AACzD,SAASC,aAAa,QAAQ,cAAc;AAC5C,SAASC,cAAc,QAAQ,gCAAgC;AAC/D,SAASC,YAAY,QAAQ,cAAc;AAC3C,SAASC,YAAY,QAAQ,aAAa;AAE1C,MAAMC,UAAU,IAAIH;AAEpB,cAAc,cAAc;AAE5B;;;;CAIC,GACD,OAAO,MAAMI,gBAAgBN,oBAAoBK,SAAS;AAE1D;;;;CAIC,GACD,OAAO,MAAME,UAAUN,cAAcI,SAAS;AAE9C;;;;CAIC,GACD,OAAO,MAAMG,SAASL,aAAaE,SAAS;AAE5C;;;;CAIC,GACD,OAAO,MAAMI,SAASL,aAAaC,SAAS"}
@@ -1,6 +1,4 @@
1
1
  export * from './defs/index.js';
2
- export * from './async-scope.js';
3
2
  export * from './global-scope.js';
4
- export * from './inject.js';
5
- export * from './scope.js';
6
3
  export * from './token.js';
4
+ export * from './root-scope.js';
package/dist/common.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from './defs/index.js';
2
+ export * from './global-scope.js';
3
+ export * from './token.js';
4
+ export * from './root-scope.js';
5
+
6
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/common.ts"],"sourcesContent":["export * from './defs/index.js';\n\nexport * from './global-scope.js';\nexport * from './token.js';\nexport * from './root-scope.js';\n"],"names":[],"mappings":"AAAA,cAAc,kBAAkB;AAEhC,cAAc,oBAAoB;AAClC,cAAc,aAAa;AAC3B,cAAc,kBAAkB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ /** @internal */ export function createCurrentScope$(context) {
2
+ return function currentScope$() {
3
+ return context.getScope();
4
+ };
5
+ }
6
+
7
+ //# sourceMappingURL=current-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/current-scope.ts"],"sourcesContent":["import type { Scope } from './defs/index.js';\nimport type { InjectionContext } from './internals/InjectionContext.js';\n\n/** @internal */\nexport function createCurrentScope$(context: InjectionContext) {\n return function currentScope$(): Scope {\n return context.getScope();\n };\n}\n"],"names":["createCurrentScope$","context","currentScope$","getScope"],"mappings":"AAGA,cAAc,GACd,OAAO,SAASA,oBAAoBC,OAAyB;IAC3D,OAAO,SAASC;QACd,OAAOD,QAAQE,QAAQ;IACzB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/defs/index.ts"],"sourcesContent":["export * from './injectable.js';\r\nexport * from './scope.js';\r\nexport * from './token.js';"],"names":[],"mappings":"AAAA,cAAc,kBAAkB;AAChC,cAAc,aAAa;AAC3B,cAAc,aAAa"}
1
+ {"version":3,"sources":["../../src/defs/index.ts"],"sourcesContent":["export * from './injectable.js';\nexport * from './scope.js';\nexport * from './token.js';"],"names":[],"mappings":"AAAA,cAAc,kBAAkB;AAChC,cAAc,aAAa;AAC3B,cAAc,aAAa"}
@@ -1,5 +1,5 @@
1
- /**
2
- * Extract value type from an Injectable type
1
+ /**
2
+ * Extract value type from an Injectable type
3
3
  */ export { };
4
4
 
5
5
  //# sourceMappingURL=injectable.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/defs/injectable.ts"],"sourcesContent":["import type { Scope } from './scope.js';\r\n\r\n/**\r\n * Object that can be injected.\r\n */\r\nexport interface Injectable<out T = unknown> {\r\n /**\r\n * Create a new instance of objet, and store it in a scope.\r\n * @param scope Scope used to store instance, defaults to global scope.\r\n */\r\n inject(scope: Scope): T;\r\n}\r\n\r\n/**\r\n * Object that can be asynchronously injected.\r\n */\r\nexport interface AsyncInjectable<out T = unknown> extends Injectable<PromiseLike<T>> {}\r\n\r\n/**\r\n * Extract value type from an Injectable type\r\n */\r\nexport type InjectedValue<R extends Injectable> = R extends Injectable<infer D> ? D : never;"],"names":[],"mappings":"AAkBA;;CAEC,GACD,WAA4F"}
1
+ {"version":3,"sources":["../../src/defs/injectable.ts"],"sourcesContent":["import type { Scope } from './scope.js';\n\n/**\n * Object that can be injected.\n */\nexport interface Injectable<out T = unknown> {\n /**\n * Create a new instance of objet, and store it in a scope.\n * @param scope Scope used to store instance, defaults to global scope.\n */\n inject(scope: Scope): T;\n}\n\n/**\n * Object that can be asynchronously injected.\n */\nexport interface AsyncInjectable<out T = unknown> extends Injectable<PromiseLike<T>> {}\n\n/**\n * Extract value type from an Injectable type\n */\nexport type InjectedValue<R extends Injectable> = R extends Injectable<infer D> ? D : never;"],"names":[],"mappings":"AAkBA;;CAEC,GACD,WAA4F"}
@@ -3,6 +3,7 @@ import type { Token } from './token.js';
3
3
  * Root scope, map matching tokens to instances
4
4
  */
5
5
  export interface RootScope {
6
+ readonly name: string;
6
7
  /**
7
8
  * Return value stored at given token
8
9
  */
@@ -20,7 +21,6 @@ export interface RootScope {
20
21
  * Child scope, map matching tokens to instances, with inheritance.
21
22
  */
22
23
  export interface ChildScope extends RootScope {
23
- readonly name: string;
24
24
  readonly parentScope: Scope;
25
25
  }
26
26
  export type Scope = RootScope | ChildScope;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/defs/scope.ts"],"sourcesContent":["import type { Token } from './token.js';\r\n\r\n/**\r\n * Root scope, map matching tokens to instances\r\n */\r\nexport interface RootScope {\r\n /**\r\n * Return value stored at given token\r\n */\r\n get<T>(token: Token<T>): T | undefined;\r\n\r\n /**\r\n * Update value stored at given token\r\n */\r\n set<T>(token: Token<T>, obj: T): void;\r\n\r\n /**\r\n * Removes all token stored in the current scope\r\n */\r\n clear(): void;\r\n}\r\n\r\n/**\r\n * Child scope, map matching tokens to instances, with inheritance.\r\n */\r\nexport interface ChildScope extends RootScope {\r\n readonly name: string;\r\n readonly parentScope: Scope;\r\n}\r\n\r\nexport type Scope = RootScope | ChildScope;"],"names":[],"mappings":"AA8BA,WAA2C"}
1
+ {"version":3,"sources":["../../src/defs/scope.ts"],"sourcesContent":["import type { Token } from './token.js';\n\n/**\n * Root scope, map matching tokens to instances\n */\nexport interface RootScope {\n readonly name: string;\n\n /**\n * Return value stored at given token\n */\n get<T>(token: Token<T>): T | undefined;\n\n /**\n * Update value stored at given token\n */\n set<T>(token: Token<T>, obj: T): void;\n\n /**\n * Removes all token stored in the current scope\n */\n clear(): void;\n}\n\n/**\n * Child scope, map matching tokens to instances, with inheritance.\n */\nexport interface ChildScope extends RootScope {\n readonly parentScope: Scope;\n}\n\nexport type Scope = RootScope | ChildScope;"],"names":[],"mappings":"AA+BA,WAA2C"}
@@ -1,10 +1,10 @@
1
1
  import type { Injectable } from './injectable.js';
2
2
  /**
3
- * Class based token
3
+ * Class-based token
4
4
  */
5
5
  export type ClassToken<out T = unknown> = new () => T;
6
6
  /**
7
- * Symbol based token
7
+ * Symbol-based token
8
8
  */
9
9
  export type SymbolToken<T = unknown> = symbol & Injectable<T>;
10
10
  export type Token<T = unknown> = ClassToken<T> | SymbolToken<T>;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/defs/token.ts"],"sourcesContent":["import type { Injectable } from './injectable.js';\r\n\r\n/**\r\n * Class based token\r\n */\r\nexport type ClassToken<out T = unknown> = new () => T;\r\n\r\n/**\r\n * Symbol based token\r\n */\r\nexport type SymbolToken<T = unknown> = symbol & Injectable<T>;\r\n\r\nexport type Token<T = unknown> = ClassToken<T> | SymbolToken<T>;"],"names":[],"mappings":"AAYA,WAAgE"}
1
+ {"version":3,"sources":["../../src/defs/token.ts"],"sourcesContent":["import type { Injectable } from './injectable.js';\n\n/**\n * Class-based token\n */\nexport type ClassToken<out T = unknown> = new () => T;\n\n/**\n * Symbol-based token\n */\nexport type SymbolToken<T = unknown> = symbol & Injectable<T>;\n\nexport type Token<T = unknown> = ClassToken<T> | SymbolToken<T>;"],"names":[],"mappings":"AAYA,WAAgE"}
@@ -1,6 +1,6 @@
1
1
  import type { RootScope } from './defs/index.js';
2
2
  /**
3
- * Returns a new {@link RootScope}
3
+ * Returns the global {@link RootScope}
4
4
  *
5
5
  * @version 1.0.0
6
6
  */
@@ -1,12 +1,13 @@
1
1
  // Constants
2
2
  const GLOBAL_SCOPE_MAP = Symbol.for('kyrielle/injector:GLOBAL_SCOPE_MAP');
3
- /**
4
- * Returns a new {@link RootScope}
5
- *
6
- * @version 1.0.0
3
+ /**
4
+ * Returns the global {@link RootScope}
5
+ *
6
+ * @version 1.0.0
7
7
  */ export function globalScope$() {
8
8
  const map = globalThis[GLOBAL_SCOPE_MAP] ??= new Map();
9
9
  return {
10
+ name: '[[global]]',
10
11
  get: (token)=>map.get(token),
11
12
  set: (token, value)=>map.set(token, value),
12
13
  clear: ()=>map.clear()
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/global-scope.ts"],"sourcesContent":["import type { RootScope, Token } from './defs/index.js';\r\n\r\n// Constants\r\nconst GLOBAL_SCOPE_MAP = Symbol.for('kyrielle/injector:GLOBAL_SCOPE_MAP');\r\n\r\n/**\r\n * Returns a new {@link RootScope}\r\n *\r\n * @version 1.0.0\r\n */\r\nexport function globalScope$(): RootScope {\r\n const map = (globalThis as { [GLOBAL_SCOPE_MAP]?: Map<Token, unknown> })[GLOBAL_SCOPE_MAP] ??= new Map();\r\n\r\n return {\r\n get: <T>(token: Token<T>) => map.get(token) as T,\r\n set: (token, value) => map.set(token, value),\r\n clear: () => map.clear(),\r\n };\r\n}\r\n"],"names":["GLOBAL_SCOPE_MAP","Symbol","for","globalScope$","map","globalThis","Map","get","token","set","value","clear"],"mappings":"AAEA,YAAY;AACZ,MAAMA,mBAAmBC,OAAOC,GAAG,CAAC;AAEpC;;;;CAIC,GACD,OAAO,SAASC;IACd,MAAMC,MAAM,AAACC,UAA2D,CAACL,iBAAiB,KAAK,IAAIM;IAEnG,OAAO;QACLC,KAAK,CAAIC,QAAoBJ,IAAIG,GAAG,CAACC;QACrCC,KAAK,CAACD,OAAOE,QAAUN,IAAIK,GAAG,CAACD,OAAOE;QACtCC,OAAO,IAAMP,IAAIO,KAAK;IACxB;AACF"}
1
+ {"version":3,"sources":["../src/global-scope.ts"],"sourcesContent":["import type { RootScope, Token } from './defs/index.js';\n\n// Constants\nconst GLOBAL_SCOPE_MAP = Symbol.for('kyrielle/injector:GLOBAL_SCOPE_MAP');\n\n/**\n * Returns the global {@link RootScope}\n *\n * @version 1.0.0\n */\nexport function globalScope$(): RootScope {\n const map = (globalThis as { [GLOBAL_SCOPE_MAP]?: Map<Token, unknown> })[GLOBAL_SCOPE_MAP] ??= new Map();\n\n return {\n name: '[[global]]',\n get: <T>(token: Token<T>) => map.get(token) as T,\n set: (token, value) => map.set(token, value),\n clear: () => map.clear(),\n };\n}\n"],"names":["GLOBAL_SCOPE_MAP","Symbol","for","globalScope$","map","globalThis","Map","name","get","token","set","value","clear"],"mappings":"AAEA,YAAY;AACZ,MAAMA,mBAAmBC,OAAOC,GAAG,CAAC;AAEpC;;;;CAIC,GACD,OAAO,SAASC;IACd,MAAMC,MAAM,AAACC,UAA2D,CAACL,iBAAiB,KAAK,IAAIM;IAEnG,OAAO;QACLC,MAAM;QACNC,KAAK,CAAIC,QAAoBL,IAAII,GAAG,CAACC;QACrCC,KAAK,CAACD,OAAOE,QAAUP,IAAIM,GAAG,CAACD,OAAOE;QACtCC,OAAO,IAAMR,IAAIQ,KAAK;IACxB;AACF"}
package/dist/inject.d.ts CHANGED
@@ -1,7 +1 @@
1
- import type { Scope, Token } from './defs/index.js';
2
- /**
3
- * Creates an instance of token, using & storing in scope.
4
- *
5
- * @version 1.0.0
6
- */
7
- export declare function inject$<T>(token: Token<T>, scope?: Scope): T;
1
+ export {};
package/dist/inject.js CHANGED
@@ -1,19 +1,16 @@
1
- import { globalScope$ } from './global-scope.js';
2
- /**
3
- * Creates an instance of token, using & storing in scope.
4
- *
5
- * @version 1.0.0
6
- */ export function inject$(token, scope = globalScope$()) {
7
- let value = scope.get(token);
8
- if (value === undefined) {
9
- if (typeof token === 'function') {
10
- value = new token();
11
- } else {
12
- value = token.inject(scope);
1
+ /** @internal */ export function createInject$(context) {
2
+ return function inject$(token, scope = context.getScope()) {
3
+ let value = scope.get(token);
4
+ if (value === undefined) {
5
+ if (typeof token === 'function') {
6
+ value = context.runInScope(scope, ()=>new token());
7
+ } else {
8
+ value = context.runInScope(scope, ()=>token.inject(scope));
9
+ }
10
+ scope.set(token, value);
13
11
  }
14
- scope.set(token, value);
15
- }
16
- return value;
12
+ return value;
13
+ };
17
14
  }
18
15
 
19
16
  //# sourceMappingURL=inject.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/inject.ts"],"sourcesContent":["import type { Scope, Token } from './defs/index.js';\r\nimport { globalScope$ } from './global-scope.js';\r\n\r\n/**\r\n * Creates an instance of token, using & storing in scope.\r\n *\r\n * @version 1.0.0\r\n */\r\nexport function inject$<T>(token: Token<T>, scope: Scope = globalScope$()): T {\r\n let value = scope.get(token);\r\n\r\n if (value === undefined) {\r\n if (typeof token === 'function') {\r\n value = new token();\r\n } else {\r\n value = token.inject(scope);\r\n }\r\n\r\n scope.set(token, value);\r\n }\r\n\r\n return value;\r\n}\r\n"],"names":["globalScope$","inject$","token","scope","value","get","undefined","inject","set"],"mappings":"AACA,SAASA,YAAY,QAAQ,oBAAoB;AAEjD;;;;CAIC,GACD,OAAO,SAASC,QAAWC,KAAe,EAAEC,QAAeH,cAAc;IACvE,IAAII,QAAQD,MAAME,GAAG,CAACH;IAEtB,IAAIE,UAAUE,WAAW;QACvB,IAAI,OAAOJ,UAAU,YAAY;YAC/BE,QAAQ,IAAIF;QACd,OAAO;YACLE,QAAQF,MAAMK,MAAM,CAACJ;QACvB;QAEAA,MAAMK,GAAG,CAACN,OAAOE;IACnB;IAEA,OAAOA;AACT"}
1
+ {"version":3,"sources":["../src/inject.ts"],"sourcesContent":["import type { InjectionContext } from './internals/InjectionContext.js';\nimport type { Scope, Token } from './defs/index.js';\n\n/** @internal */\nexport function createInject$(context: InjectionContext) {\n return function inject$<T>(token: Token<T>, scope: Scope = context.getScope()): T {\n let value = scope.get(token);\n\n if (value === undefined) {\n if (typeof token === 'function') {\n value = context.runInScope(scope, () => new token());\n } else {\n value = context.runInScope(scope, () => token.inject(scope));\n }\n\n scope.set(token, value);\n }\n\n return value;\n };\n}"],"names":["createInject$","context","inject$","token","scope","getScope","value","get","undefined","runInScope","inject","set"],"mappings":"AAGA,cAAc,GACd,OAAO,SAASA,cAAcC,OAAyB;IACrD,OAAO,SAASC,QAAWC,KAAe,EAAEC,QAAeH,QAAQI,QAAQ,EAAE;QAC3E,IAAIC,QAAQF,MAAMG,GAAG,CAACJ;QAEtB,IAAIG,UAAUE,WAAW;YACvB,IAAI,OAAOL,UAAU,YAAY;gBAC/BG,QAAQL,QAAQQ,UAAU,CAACL,OAAO,IAAM,IAAID;YAC9C,OAAO;gBACLG,QAAQL,QAAQQ,UAAU,CAACL,OAAO,IAAMD,MAAMO,MAAM,CAACN;YACvD;YAEAA,MAAMO,GAAG,CAACR,OAAOG;QACnB;QAEA,OAAOA;IACT;AACF"}
@@ -0,0 +1,7 @@
1
+ import type { Scope } from '../defs/index.js';
2
+ import type { InjectionContext } from './InjectionContext.js';
3
+ export declare class BrowserContext implements InjectionContext {
4
+ private _scope;
5
+ getScope(): Scope;
6
+ runInScope<T>(scope: Scope, fn: () => T): T;
7
+ }
@@ -0,0 +1,23 @@
1
+ import { globalScope$ } from '../global-scope.js';
2
+ import { UnsupportedAsyncToken } from './UnsupportedAsyncToken.js';
3
+ export class BrowserContext {
4
+ _scope = globalScope$();
5
+ getScope() {
6
+ return this._scope;
7
+ }
8
+ runInScope(scope, fn) {
9
+ const oldScope = this._scope;
10
+ this._scope = scope;
11
+ try {
12
+ const result = fn();
13
+ if (result instanceof Promise) {
14
+ throw new UnsupportedAsyncToken('Async tokens are not supported in browsers');
15
+ }
16
+ return result;
17
+ } finally{
18
+ this._scope = oldScope;
19
+ }
20
+ }
21
+ }
22
+
23
+ //# sourceMappingURL=BrowserContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/internals/BrowserContext.ts"],"sourcesContent":["import type { Scope } from '../defs/index.js';\nimport type { InjectionContext } from './InjectionContext.js';\nimport { globalScope$ } from '../global-scope.js';\nimport { UnsupportedAsyncToken } from './UnsupportedAsyncToken.js';\n\nexport class BrowserContext implements InjectionContext {\n private _scope: Scope = globalScope$();\n\n getScope(): Scope {\n return this._scope;\n }\n\n runInScope<T>(scope: Scope, fn: () => T): T {\n const oldScope = this._scope;\n this._scope = scope;\n\n try {\n const result = fn();\n\n if (result instanceof Promise) {\n throw new UnsupportedAsyncToken('Async tokens are not supported in browsers');\n }\n\n return result;\n } finally {\n this._scope = oldScope;\n }\n }\n}"],"names":["globalScope$","UnsupportedAsyncToken","BrowserContext","_scope","getScope","runInScope","scope","fn","oldScope","result","Promise"],"mappings":"AAEA,SAASA,YAAY,QAAQ,qBAAqB;AAClD,SAASC,qBAAqB,QAAQ,6BAA6B;AAEnE,OAAO,MAAMC;IACHC,SAAgBH,eAAe;IAEvCI,WAAkB;QAChB,OAAO,IAAI,CAACD,MAAM;IACpB;IAEAE,WAAcC,KAAY,EAAEC,EAAW,EAAK;QAC1C,MAAMC,WAAW,IAAI,CAACL,MAAM;QAC5B,IAAI,CAACA,MAAM,GAAGG;QAEd,IAAI;YACF,MAAMG,SAASF;YAEf,IAAIE,kBAAkBC,SAAS;gBAC7B,MAAM,IAAIT,sBAAsB;YAClC;YAEA,OAAOQ;QACT,SAAU;YACR,IAAI,CAACN,MAAM,GAAGK;QAChB;IACF;AACF"}
@@ -0,0 +1,12 @@
1
+ import type { Scope } from '../defs/scope.js';
2
+ export interface InjectionContext {
3
+ /**
4
+ * Returns the current scope.
5
+ */
6
+ getScope(): Scope;
7
+ /**
8
+ * Runs the given function within the given scope.
9
+ * Any {@link getScope} call made within the function will return the given scope.
10
+ */
11
+ runInScope<T>(scope: Scope, fn: () => T): T;
12
+ }
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=InjectionContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/internals/InjectionContext.ts"],"sourcesContent":["import type { Scope } from '../defs/scope.js';\n\nexport interface InjectionContext {\n /**\n * Returns the current scope.\n */\n getScope(): Scope;\n\n /**\n * Runs the given function within the given scope.\n * Any {@link getScope} call made within the function will return the given scope.\n */\n runInScope<T>(scope: Scope, fn: () => T): T;\n}"],"names":[],"mappings":"AAEA,WAWC"}
@@ -0,0 +1,7 @@
1
+ import type { InjectionContext } from './InjectionContext.js';
2
+ import type { Scope } from '../defs/index.js';
3
+ export declare class NodeContext implements InjectionContext {
4
+ private readonly _storage;
5
+ getScope(): Scope;
6
+ runInScope<T>(scope: Scope, fn: () => T): T;
7
+ }
@@ -0,0 +1,13 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { globalScope$ } from '../global-scope.js';
3
+ export class NodeContext {
4
+ _storage = new AsyncLocalStorage();
5
+ getScope() {
6
+ return this._storage.getStore() ?? globalScope$();
7
+ }
8
+ runInScope(scope, fn) {
9
+ return this._storage.run(scope, fn);
10
+ }
11
+ }
12
+
13
+ //# sourceMappingURL=NodeContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/internals/NodeContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\nimport { globalScope$ } from '../global-scope.js';\nimport type { InjectionContext } from './InjectionContext.js';\nimport type { Scope } from '../defs/index.js';\n\nexport class NodeContext implements InjectionContext {\n private readonly _storage = new AsyncLocalStorage<Scope>();\n\n getScope(): Scope {\n return this._storage.getStore() ?? globalScope$();\n }\n\n runInScope<T>(scope: Scope, fn: () => T): T {\n return this._storage.run(scope, fn);\n }\n}"],"names":["AsyncLocalStorage","globalScope$","NodeContext","_storage","getScope","getStore","runInScope","scope","fn","run"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,mBAAmB;AACrD,SAASC,YAAY,QAAQ,qBAAqB;AAIlD,OAAO,MAAMC;IACMC,WAAW,IAAIH,oBAA2B;IAE3DI,WAAkB;QAChB,OAAO,IAAI,CAACD,QAAQ,CAACE,QAAQ,MAAMJ;IACrC;IAEAK,WAAcC,KAAY,EAAEC,EAAW,EAAK;QAC1C,OAAO,IAAI,CAACL,QAAQ,CAACM,GAAG,CAACF,OAAOC;IAClC;AACF"}
@@ -0,0 +1,2 @@
1
+ export declare class UnsupportedAsyncToken extends Error {
2
+ }
@@ -0,0 +1,4 @@
1
+ export class UnsupportedAsyncToken extends Error {
2
+ }
3
+
4
+ //# sourceMappingURL=UnsupportedAsyncToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/internals/UnsupportedAsyncToken.ts"],"sourcesContent":["export class UnsupportedAsyncToken extends Error {}"],"names":["UnsupportedAsyncToken","Error"],"mappings":"AAAA,OAAO,MAAMA,8BAA8BC;AAAO"}
package/dist/node.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ export * from './common.js';
2
+ /**
3
+ * Returns current scope.
4
+ *
5
+ * @version 2.0.0
6
+ */
7
+ export declare const currentScope$: () => import("./common.js").Scope;
8
+ /**
9
+ * Creates an instance of token, using and storing in scope.
10
+ *
11
+ * @version 1.0.0
12
+ */
13
+ export declare const inject$: <T>(token: import("./common.js").Token<T>, scope?: import("./common.js").Scope) => T;
14
+ /**
15
+ * Runs a function in a given scope. Any {@link inject$} calls within the function will use the provided scope by default.
16
+ *
17
+ * @version 2.0.0
18
+ */
19
+ export declare const runIn$: <T>(scope: import("./common.js").Scope, fn: () => T) => T;
20
+ /**
21
+ * Creates a new {@link ChildScope}, with a given parent defaulting to current scope
22
+ *
23
+ * @version 1.0.0
24
+ */
25
+ export declare const scope$: (name: string, parent?: import("./common.js").Scope) => import("./common.js").ChildScope;
package/dist/node.js ADDED
@@ -0,0 +1,29 @@
1
+ import { createCurrentScope$ } from './current-scope.js';
2
+ import { createInject$ } from './inject.js';
3
+ import { NodeContext } from './internals/NodeContext.js';
4
+ import { createRunIn$ } from './run-in.js';
5
+ import { createScope$ } from './scope.js';
6
+ const context = new NodeContext();
7
+ export * from './common.js';
8
+ /**
9
+ * Returns current scope.
10
+ *
11
+ * @version 2.0.0
12
+ */ export const currentScope$ = createCurrentScope$(context);
13
+ /**
14
+ * Creates an instance of token, using and storing in scope.
15
+ *
16
+ * @version 1.0.0
17
+ */ export const inject$ = createInject$(context);
18
+ /**
19
+ * Runs a function in a given scope. Any {@link inject$} calls within the function will use the provided scope by default.
20
+ *
21
+ * @version 2.0.0
22
+ */ export const runIn$ = createRunIn$(context);
23
+ /**
24
+ * Creates a new {@link ChildScope}, with a given parent defaulting to current scope
25
+ *
26
+ * @version 1.0.0
27
+ */ export const scope$ = createScope$(context);
28
+
29
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/node.ts"],"sourcesContent":["import { createCurrentScope$ } from './current-scope.js';\nimport { createInject$ } from './inject.js';\nimport { NodeContext } from './internals/NodeContext.js';\nimport { createRunIn$ } from './run-in.js';\nimport { createScope$ } from './scope.js';\n\nconst context = new NodeContext();\n\nexport * from './common.js';\n\n/**\n * Returns current scope.\n *\n * @version 2.0.0\n */\nexport const currentScope$ = createCurrentScope$(context);\n\n/**\n * Creates an instance of token, using and storing in scope.\n *\n * @version 1.0.0\n */\nexport const inject$ = createInject$(context);\n\n/**\n * Runs a function in a given scope. Any {@link inject$} calls within the function will use the provided scope by default.\n *\n * @version 2.0.0\n */\nexport const runIn$ = createRunIn$(context);\n\n/**\n * Creates a new {@link ChildScope}, with a given parent defaulting to current scope\n *\n * @version 1.0.0\n */\nexport const scope$ = createScope$(context);"],"names":["createCurrentScope$","createInject$","NodeContext","createRunIn$","createScope$","context","currentScope$","inject$","runIn$","scope$"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,qBAAqB;AACzD,SAASC,aAAa,QAAQ,cAAc;AAC5C,SAASC,WAAW,QAAQ,6BAA6B;AACzD,SAASC,YAAY,QAAQ,cAAc;AAC3C,SAASC,YAAY,QAAQ,aAAa;AAE1C,MAAMC,UAAU,IAAIH;AAEpB,cAAc,cAAc;AAE5B;;;;CAIC,GACD,OAAO,MAAMI,gBAAgBN,oBAAoBK,SAAS;AAE1D;;;;CAIC,GACD,OAAO,MAAME,UAAUN,cAAcI,SAAS;AAE9C;;;;CAIC,GACD,OAAO,MAAMG,SAASL,aAAaE,SAAS;AAE5C;;;;CAIC,GACD,OAAO,MAAMI,SAASL,aAAaC,SAAS"}
@@ -0,0 +1,7 @@
1
+ import type { RootScope } from './defs/index.js';
2
+ /**
3
+ * Returns a new {@link RootScope}
4
+ *
5
+ * @version 2.0.0
6
+ */
7
+ export declare function rootScope$(name: string): RootScope;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Returns a new {@link RootScope}
3
+ *
4
+ * @version 2.0.0
5
+ */ export function rootScope$(name) {
6
+ const map = new Map();
7
+ return {
8
+ name,
9
+ get: (token)=>map.get(token),
10
+ set: (token, value)=>map.set(token, value),
11
+ clear: ()=>map.clear()
12
+ };
13
+ }
14
+
15
+ //# sourceMappingURL=root-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/root-scope.ts"],"sourcesContent":["import type { RootScope, Token } from './defs/index.js';\n\n/**\n * Returns a new {@link RootScope}\n *\n * @version 2.0.0\n */\nexport function rootScope$(name: string): RootScope {\n const map = new Map();\n\n return {\n name,\n get: <T>(token: Token<T>) => map.get(token) as T,\n set: (token, value) => map.set(token, value),\n clear: () => map.clear(),\n };\n}\n"],"names":["rootScope$","name","map","Map","get","token","set","value","clear"],"mappings":"AAEA;;;;CAIC,GACD,OAAO,SAASA,WAAWC,IAAY;IACrC,MAAMC,MAAM,IAAIC;IAEhB,OAAO;QACLF;QACAG,KAAK,CAAIC,QAAoBH,IAAIE,GAAG,CAACC;QACrCC,KAAK,CAACD,OAAOE,QAAUL,IAAII,GAAG,CAACD,OAAOE;QACtCC,OAAO,IAAMN,IAAIM,KAAK;IACxB;AACF"}
@@ -0,0 +1 @@
1
+ export {};
package/dist/run-in.js ADDED
@@ -0,0 +1,7 @@
1
+ /** @internal */ export function createRunIn$(context) {
2
+ return function runIn$(scope, fn) {
3
+ return context.runInScope(scope, fn);
4
+ };
5
+ }
6
+
7
+ //# sourceMappingURL=run-in.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/run-in.ts"],"sourcesContent":["import type { Scope } from './defs/index.js';\nimport type { InjectionContext } from './internals/InjectionContext.js';\n\n/** @internal */\nexport function createRunIn$(context: InjectionContext) {\n return function runIn$<T>(scope: Scope, fn: () => T): T {\n return context.runInScope(scope, fn);\n };\n}"],"names":["createRunIn$","context","runIn$","scope","fn","runInScope"],"mappings":"AAGA,cAAc,GACd,OAAO,SAASA,aAAaC,OAAyB;IACpD,OAAO,SAASC,OAAUC,KAAY,EAAEC,EAAW;QACjD,OAAOH,QAAQI,UAAU,CAACF,OAAOC;IACnC;AACF"}
package/dist/scope.d.ts CHANGED
@@ -1,7 +1 @@
1
- import type { ChildScope, Scope } from './defs/index.js';
2
- /**
3
- * Creates a new {@link ChildScope}, with given parent defaulting to global scope
4
- *
5
- * @version 1.0.0
6
- */
7
- export declare function scope$(name: string, parent?: Scope): ChildScope;
1
+ export {};
package/dist/scope.js CHANGED
@@ -1,22 +1,19 @@
1
- import { globalScope$ } from './global-scope.js';
2
- /**
3
- * Creates a new {@link ChildScope}, with given parent defaulting to global scope
4
- *
5
- * @version 1.0.0
6
- */ export function scope$(name, parent = globalScope$()) {
7
- const map = new Map();
8
- return {
9
- name,
10
- parentScope: parent,
11
- get (token) {
12
- let value = map.get(token);
13
- if (value === undefined) {
14
- value = parent.get(token);
15
- }
16
- return value;
17
- },
18
- set: (token, value)=>map.set(token, value),
19
- clear: ()=>map.clear()
1
+ /** @internal */ export function createScope$(context) {
2
+ return function scope$(name, parent = context.getScope()) {
3
+ const map = new Map();
4
+ return {
5
+ name,
6
+ parentScope: parent,
7
+ get (token) {
8
+ let value = map.get(token);
9
+ if (value === undefined) {
10
+ value = parent.get(token);
11
+ }
12
+ return value;
13
+ },
14
+ set: (token, value)=>map.set(token, value),
15
+ clear: ()=>map.clear()
16
+ };
20
17
  };
21
18
  }
22
19
 
package/dist/scope.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/scope.ts"],"sourcesContent":["import type { ChildScope, Scope, Token } from './defs/index.js';\r\nimport { globalScope$ } from './global-scope.js';\r\n\r\n/**\r\n * Creates a new {@link ChildScope}, with given parent defaulting to global scope\r\n *\r\n * @version 1.0.0\r\n */\r\nexport function scope$(name: string, parent: Scope = globalScope$()): ChildScope {\r\n const map = new Map<Token, unknown>();\r\n\r\n return {\r\n name,\r\n parentScope: parent,\r\n get<T>(token: Token<T>) {\r\n let value = map.get(token) as T | undefined;\r\n\r\n if (value === undefined) {\r\n value = parent.get(token);\r\n }\r\n\r\n return value;\r\n },\r\n set: (token, value) => map.set(token, value),\r\n clear: () => map.clear(),\r\n };\r\n}\r\n"],"names":["globalScope$","scope$","name","parent","map","Map","parentScope","get","token","value","undefined","set","clear"],"mappings":"AACA,SAASA,YAAY,QAAQ,oBAAoB;AAEjD;;;;CAIC,GACD,OAAO,SAASC,OAAOC,IAAY,EAAEC,SAAgBH,cAAc;IACjE,MAAMI,MAAM,IAAIC;IAEhB,OAAO;QACLH;QACAI,aAAaH;QACbI,KAAOC,KAAe;YACpB,IAAIC,QAAQL,IAAIG,GAAG,CAACC;YAEpB,IAAIC,UAAUC,WAAW;gBACvBD,QAAQN,OAAOI,GAAG,CAACC;YACrB;YAEA,OAAOC;QACT;QACAE,KAAK,CAACH,OAAOC,QAAUL,IAAIO,GAAG,CAACH,OAAOC;QACtCG,OAAO,IAAMR,IAAIQ,KAAK;IACxB;AACF"}
1
+ {"version":3,"sources":["../src/scope.ts"],"sourcesContent":["import type { InjectionContext } from './internals/InjectionContext.js';\nimport type { ChildScope, Scope, Token } from './defs/index.js';\n\n/** @internal */\nexport function createScope$(context: InjectionContext) {\n return function scope$(name: string, parent: Scope = context.getScope()): ChildScope {\n const map = new Map<Token, unknown>();\n\n return {\n name,\n parentScope: parent,\n get<T>(token: Token<T>) {\n let value = map.get(token) as T | undefined;\n\n if (value === undefined) {\n value = parent.get(token);\n }\n\n return value;\n },\n set: (token, value) => map.set(token, value),\n clear: () => map.clear(),\n };\n };\n}"],"names":["createScope$","context","scope$","name","parent","getScope","map","Map","parentScope","get","token","value","undefined","set","clear"],"mappings":"AAGA,cAAc,GACd,OAAO,SAASA,aAAaC,OAAyB;IACpD,OAAO,SAASC,OAAOC,IAAY,EAAEC,SAAgBH,QAAQI,QAAQ,EAAE;QACrE,MAAMC,MAAM,IAAIC;QAEhB,OAAO;YACLJ;YACAK,aAAaJ;YACbK,KAAOC,KAAe;gBACpB,IAAIC,QAAQL,IAAIG,GAAG,CAACC;gBAEpB,IAAIC,UAAUC,WAAW;oBACvBD,QAAQP,OAAOK,GAAG,CAACC;gBACrB;gBAEA,OAAOC;YACT;YACAE,KAAK,CAACH,OAAOC,QAAUL,IAAIO,GAAG,CAACH,OAAOC;YACtCG,OAAO,IAAMR,IAAIQ,KAAK;QACxB;IACF;AACF"}
package/dist/token.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type Scope, type SymbolToken } from './defs/index.js';
2
2
  /**
3
- * Creates an injectable token, using init as instance creator.
3
+ * Creates an injectable token, using init as an instance creator.
4
4
  *
5
5
  * @version 1.0.0
6
6
  */
package/dist/token.js CHANGED
@@ -1,7 +1,7 @@
1
- /**
2
- * Creates an injectable token, using init as instance creator.
3
- *
4
- * @version 1.0.0
1
+ /**
2
+ * Creates an injectable token, using init as an instance creator.
3
+ *
4
+ * @version 1.0.0
5
5
  */ export function token$(name, init) {
6
6
  return Object.assign(Symbol(name), {
7
7
  inject: init
package/dist/token.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/token.ts"],"sourcesContent":["import { type Scope, type SymbolToken } from './defs/index.js';\r\n\r\n/**\r\n * Creates an injectable token, using init as instance creator.\r\n *\r\n * @version 1.0.0\r\n */\r\nexport function token$<T>(name: string, init: TokenInitCallback<T>): SymbolToken<T> {\r\n return Object.assign(Symbol(name), {\r\n inject: init,\r\n });\r\n}\r\n\r\nexport type TokenInitCallback<out T> = (scope: Scope) => T;\r\n"],"names":["token$","name","init","Object","assign","Symbol","inject"],"mappings":"AAEA;;;;CAIC,GACD,OAAO,SAASA,OAAUC,IAAY,EAAEC,IAA0B;IAChE,OAAOC,OAAOC,MAAM,CAACC,OAAOJ,OAAO;QACjCK,QAAQJ;IACV;AACF"}
1
+ {"version":3,"sources":["../src/token.ts"],"sourcesContent":["import { type Scope, type SymbolToken } from './defs/index.js';\n\n/**\n * Creates an injectable token, using init as an instance creator.\n *\n * @version 1.0.0\n */\nexport function token$<T>(name: string, init: TokenInitCallback<T>): SymbolToken<T> {\n return Object.assign(Symbol(name), {\n inject: init,\n });\n}\n\nexport type TokenInitCallback<out T> = (scope: Scope) => T;\n"],"names":["token$","name","init","Object","assign","Symbol","inject"],"mappings":"AAEA;;;;CAIC,GACD,OAAO,SAASA,OAAUC,IAAY,EAAEC,IAA0B;IAChE,OAAOC,OAAOC,MAAM,CAACC,OAAOJ,OAAO;QACjCK,QAAQJ;IACV;AACF"}