injeca 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dist/{builtin-BN5UvvMB.mjs → builtin-BPDNf8Z-.mjs} +1 -1
- package/dist/{builtin-BN5UvvMB.mjs.map → builtin-BPDNf8Z-.mjs.map} +1 -1
- package/dist/global-BLY6_SI_.d.mts +130 -0
- package/dist/global.d.mts +2 -0
- package/dist/global.mjs +3 -0
- package/dist/index.d.mts +2 -125
- package/dist/index.mjs +2 -280
- package/dist/src-DnnFlmag.mjs +292 -0
- package/dist/src-DnnFlmag.mjs.map +1 -0
- package/package.json +19 -14
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -61,6 +61,33 @@ process.once('SIGINT', async () => {
|
|
|
61
61
|
})
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
+
> [!WARNING]
|
|
65
|
+
>
|
|
66
|
+
> **`injeca` implements singleton / cached dependencies by default**
|
|
67
|
+
>
|
|
68
|
+
> This means every value returned by `build` will be stored and `build` will only
|
|
69
|
+
> got called once.
|
|
70
|
+
>
|
|
71
|
+
> If `build` returns a function, that function is cached (not the result of calling
|
|
72
|
+
> it). This is useful for lazy dependencies, "getters", or wrappers for singleton,
|
|
73
|
+
> but it also means any side effects inside the returned function will run on every call.
|
|
74
|
+
>
|
|
75
|
+
> If you want the returned function to be reusable (e.g. a single window), create
|
|
76
|
+
> the reusable closure once inside `build`, and return a wrapper that calls it:
|
|
77
|
+
>
|
|
78
|
+
> ```ts
|
|
79
|
+
> const settingsWindow = injeca.provide('windows:settings', {
|
|
80
|
+
> dependsOn: { widgetsManager },
|
|
81
|
+
> build: ({ dependsOn }) => {
|
|
82
|
+
> const getWindow = setupReusableSettingsWindow(dependsOn) // created once
|
|
83
|
+
> return async () => await getWindow() // can be called many times
|
|
84
|
+
> },
|
|
85
|
+
> })
|
|
86
|
+
> ```
|
|
87
|
+
|
|
88
|
+
Avoid recreating the reusable function inside the returned function, otherwise
|
|
89
|
+
each call starts from a fresh cache and can create duplicate resources.
|
|
90
|
+
|
|
64
91
|
### Manual containers
|
|
65
92
|
|
|
66
93
|
If you need multiple containers (for tests or per-request scopes), create them
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtin-
|
|
1
|
+
{"version":3,"file":"builtin-BPDNf8Z-.mjs","names":["onStartHooks: (() => void | Promise<void>)[]","onStopHooks: (() => void | Promise<void>)[]"],"sources":["../src/builtin.ts"],"sourcesContent":["export interface LifecycleAppHooks {\n onStart: (hook: () => void | Promise<void>) => void\n onStop: (hook: () => void | Promise<void>) => void\n}\n\nexport interface Lifecycle {\n appHooks: LifecycleAppHooks\n}\n\nexport interface LifecycleTriggerable extends Lifecycle {\n emitOnStart: () => Promise<void>\n emitOnStop: () => Promise<void>\n}\n\nexport function buildLifecycle(): Lifecycle {\n const onStartHooks: (() => void | Promise<void>)[] = []\n const onStopHooks: (() => void | Promise<void>)[] = []\n\n const lifecycle: LifecycleTriggerable = {\n appHooks: {\n onStart(hook: () => void | Promise<void>) {\n if (hook) {\n onStartHooks.push(hook)\n }\n },\n onStop(hook: () => void | Promise<void>) {\n if (hook) {\n onStopHooks.push(hook)\n }\n },\n },\n emitOnStart: async () => {\n for (const hook of onStartHooks) {\n await hook()\n }\n },\n emitOnStop: async () => {\n for (const hook of onStopHooks) {\n await hook()\n }\n },\n }\n\n return lifecycle\n}\n"],"mappings":";AAcA,SAAgB,iBAA4B;CAC1C,MAAMA,eAA+C,EAAE;CACvD,MAAMC,cAA8C,EAAE;AA2BtD,QAzBwC;EACtC,UAAU;GACR,QAAQ,MAAkC;AACxC,QAAI,KACF,cAAa,KAAK,KAAK;;GAG3B,OAAO,MAAkC;AACvC,QAAI,KACF,aAAY,KAAK,KAAK;;GAG3B;EACD,aAAa,YAAY;AACvB,QAAK,MAAM,QAAQ,aACjB,OAAM,MAAM;;EAGhB,YAAY,YAAY;AACtB,QAAK,MAAM,QAAQ,YACjB,OAAM,MAAM;;EAGjB"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Logg } from "@guiiai/logg";
|
|
2
|
+
|
|
3
|
+
//#region src/builtin.d.ts
|
|
4
|
+
interface LifecycleAppHooks {
|
|
5
|
+
onStart: (hook: () => void | Promise<void>) => void;
|
|
6
|
+
onStop: (hook: () => void | Promise<void>) => void;
|
|
7
|
+
}
|
|
8
|
+
interface Lifecycle {
|
|
9
|
+
appHooks: LifecycleAppHooks;
|
|
10
|
+
}
|
|
11
|
+
interface LifecycleTriggerable extends Lifecycle {
|
|
12
|
+
emitOnStart: () => Promise<void>;
|
|
13
|
+
emitOnStop: () => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/logger.d.ts
|
|
17
|
+
interface Logger {
|
|
18
|
+
provide: (name: string, dependencies: string[]) => void;
|
|
19
|
+
invoke: (dependencies: string[]) => void;
|
|
20
|
+
beforeRun: (name: string) => void;
|
|
21
|
+
run: (name: string, duration: number) => void;
|
|
22
|
+
hookOnStart: (name: string) => void;
|
|
23
|
+
hookOnStartComplete: (name: string, duration: number) => void;
|
|
24
|
+
hookOnStop: (name: string) => void;
|
|
25
|
+
hookOnStopComplete: (name: string, duration: number) => void;
|
|
26
|
+
running: () => void;
|
|
27
|
+
}
|
|
28
|
+
interface LoggerOptions {
|
|
29
|
+
enabled?: boolean;
|
|
30
|
+
logger?: Logger;
|
|
31
|
+
}
|
|
32
|
+
declare function createDefaultLogger(): Logger;
|
|
33
|
+
declare function createLoggLogger(logg: Logg): Logger;
|
|
34
|
+
declare function createNoopLogger(): Logger;
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/scoped.d.ts
|
|
37
|
+
type DependencyMap = Record<string, any>;
|
|
38
|
+
interface Container {
|
|
39
|
+
providers: Map<string, ProvideOptionObject<any, any>>;
|
|
40
|
+
instances: Map<string, any>;
|
|
41
|
+
lifecycleHooks: Map<string, LifecycleTriggerable>;
|
|
42
|
+
dependencyGraph: Map<string, string[]>;
|
|
43
|
+
invocations: InvokeOptionObject<any>[];
|
|
44
|
+
logger: Logger;
|
|
45
|
+
}
|
|
46
|
+
type BuildContext<D extends DependencyMap | undefined = undefined> = {
|
|
47
|
+
container: Container;
|
|
48
|
+
name: string;
|
|
49
|
+
} & (D extends undefined ? {
|
|
50
|
+
dependsOn?: unknown;
|
|
51
|
+
} : {
|
|
52
|
+
dependsOn: D;
|
|
53
|
+
});
|
|
54
|
+
type ResolveDependencyDeclaration<Deps extends Record<string, string | ProvidedKey<any, any, any>>> = { [K in keyof Deps]: Deps[K] extends ProvidedKey<any, infer T, any> ? T : Deps[K] extends ProvidedBy<infer T> ? T : any };
|
|
55
|
+
type ProvideOptionObject<T, D extends DependencyMap | undefined = undefined> = {
|
|
56
|
+
build: (context: BuildContext<D>) => T | Promise<T>;
|
|
57
|
+
} & (D extends undefined ? {
|
|
58
|
+
dependsOn?: Record<string, never>;
|
|
59
|
+
} : {
|
|
60
|
+
dependsOn: { [K in keyof D]: string };
|
|
61
|
+
});
|
|
62
|
+
type ProvideOptionFunc<T, D extends DependencyMap | undefined = undefined> = (context: BuildContext<D>) => T | Promise<T>;
|
|
63
|
+
type ProvideOption<T, D extends DependencyMap | undefined = undefined> = ProvideOptionObject<T, D> | ProvideOptionFunc<T, D>;
|
|
64
|
+
interface ProvideOptionObjectWithKeys<T, Deps extends Record<string, string | ProvidedKey<any, any, any>>> {
|
|
65
|
+
build: (context: BuildContext<ResolveDependencyDeclaration<Deps>>) => T | Promise<T>;
|
|
66
|
+
dependsOn: Deps;
|
|
67
|
+
}
|
|
68
|
+
type ProvideOptionWithKeys<T, Deps extends Record<string, string | ProvidedKey<any, any, any>>> = ProvideOptionObjectWithKeys<T, Deps>;
|
|
69
|
+
type InvokeOptionObject<D extends DependencyMap | undefined = undefined> = {
|
|
70
|
+
callback: (dependencies: D) => void | Promise<void>;
|
|
71
|
+
} & (D extends undefined ? {
|
|
72
|
+
dependsOn?: Record<string, never>;
|
|
73
|
+
} : {
|
|
74
|
+
dependsOn: { [K in keyof D]: string };
|
|
75
|
+
});
|
|
76
|
+
type InvokeOptionFunc<D extends DependencyMap | undefined = undefined> = (dependencies: D) => void | Promise<void>;
|
|
77
|
+
type InvokeOption<D extends DependencyMap | undefined = undefined> = InvokeOptionObject<D> | InvokeOptionFunc<D>;
|
|
78
|
+
interface InvokeOptionObjectWithKeys<Deps extends Record<string, string | ProvidedKey<any, any, any>>> {
|
|
79
|
+
callback: (dependencies: ResolveDependencyDeclaration<Deps>) => void | Promise<void>;
|
|
80
|
+
dependsOn: Deps;
|
|
81
|
+
}
|
|
82
|
+
type InvokeOptionWithKeys<Deps extends Record<string, string | ProvidedKey<any, any, any>>> = InvokeOptionObjectWithKeys<Deps>;
|
|
83
|
+
declare const lifecycle: ProvidedKey<'lifecycle', Lifecycle, undefined>;
|
|
84
|
+
declare function createContainer(options?: LoggerOptions): Container;
|
|
85
|
+
interface ProvidedKey<Key, _T, _D extends DependencyMap | undefined> {
|
|
86
|
+
key: Key;
|
|
87
|
+
}
|
|
88
|
+
type ProvidedBy<T> = string & {
|
|
89
|
+
__providedType?: T;
|
|
90
|
+
};
|
|
91
|
+
type InferProvided<T> = T extends ProvidedKey<any, infer P, any> ? P : T extends ProvidedBy<infer P> ? P : never;
|
|
92
|
+
declare function provide$1<T, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, name: Key, option: ProvideOptionWithKeys<T, Deps>): ProvidedKey<Key, T, ResolveDependencyDeclaration<Deps>>;
|
|
93
|
+
declare function provide$1<T, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, option: ProvideOptionWithKeys<T, Deps> & {
|
|
94
|
+
autoNameStackIndex?: number;
|
|
95
|
+
}): ProvidedKey<Key, T, ResolveDependencyDeclaration<Deps>>;
|
|
96
|
+
declare function provide$1<D extends DependencyMap | undefined, T = any, Key extends string = string>(container: Container, name: Key, option: ProvideOption<T, D>): ProvidedKey<Key, T, D>;
|
|
97
|
+
declare function provide$1<D extends DependencyMap | undefined, T = any, Key extends string = string>(container: Container, option: ProvideOption<T, D> & {
|
|
98
|
+
autoNameStackIndex?: number;
|
|
99
|
+
}): ProvidedKey<Key, T, D>;
|
|
100
|
+
declare function invoke$1<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, option: InvokeOptionWithKeys<Deps>): void;
|
|
101
|
+
declare function invoke$1<D extends DependencyMap>(container: Container, option: InvokeOption<D>): void;
|
|
102
|
+
declare function resolve$1<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, dependsOn: Deps): Promise<ResolveDependencyDeclaration<Deps>>;
|
|
103
|
+
declare function start$1(container: Container): Promise<void>;
|
|
104
|
+
declare function stop$1(container: Container): Promise<void>;
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/index.d.ts
|
|
107
|
+
declare const injeca: {
|
|
108
|
+
provide: typeof provide;
|
|
109
|
+
invoke: typeof invoke;
|
|
110
|
+
resolve: typeof resolve;
|
|
111
|
+
start: typeof start;
|
|
112
|
+
stop: typeof stop;
|
|
113
|
+
setLogger: typeof setLogger;
|
|
114
|
+
};
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/global.d.ts
|
|
117
|
+
declare function setLogger(logger: Logger): void;
|
|
118
|
+
declare function resetContainer(): void;
|
|
119
|
+
declare function provide<T, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(name: Key, option: ProvideOptionWithKeys<T, Deps>): ProvidedKey<Key, T, ResolveDependencyDeclaration<Deps>>;
|
|
120
|
+
declare function provide<D extends DependencyMap | undefined, T = any, Key extends string = string>(name: Key, option: ProvideOption<T, D>): ProvidedKey<Key, T, D>;
|
|
121
|
+
declare function provide<T, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(option: ProvideOptionWithKeys<T, Deps>): ProvidedKey<Key, T, ResolveDependencyDeclaration<Deps>>;
|
|
122
|
+
declare function provide<D extends DependencyMap | undefined, T = any, Key extends string = string>(option: ProvideOption<T, D>): ProvidedKey<Key, T, D>;
|
|
123
|
+
declare function invoke<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(option: InvokeOptionWithKeys<Deps>): void;
|
|
124
|
+
declare function invoke<D extends DependencyMap>(option: InvokeOption<D>): void;
|
|
125
|
+
declare function resolve<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(dependsOn: Deps): Promise<ResolveDependencyDeclaration<Deps>>;
|
|
126
|
+
declare function start(): Promise<void>;
|
|
127
|
+
declare function stop(): Promise<void>;
|
|
128
|
+
//#endregion
|
|
129
|
+
export { resolve$1 as A, ProvidedBy as C, invoke$1 as D, createContainer as E, createDefaultLogger as F, createLoggLogger as I, createNoopLogger as L, stop$1 as M, Logger as N, lifecycle as O, LoggerOptions as P, Lifecycle as R, ProvideOptionWithKeys as S, ResolveDependencyDeclaration as T, InvokeOptionWithKeys as _, setLogger as a, ProvideOptionObject as b, injeca as c, DependencyMap as d, InferProvided as f, InvokeOptionObjectWithKeys as g, InvokeOptionObject as h, resolve as i, start$1 as j, provide$1 as k, BuildContext as l, InvokeOptionFunc as m, provide as n, start as o, InvokeOption as p, resetContainer as r, stop as s, invoke as t, Container as u, ProvideOption as v, ProvidedKey as w, ProvideOptionObjectWithKeys as x, ProvideOptionFunc as y };
|
|
130
|
+
//# sourceMappingURL=global-BLY6_SI_.d.mts.map
|
package/dist/global.mjs
ADDED
package/dist/index.d.mts
CHANGED
|
@@ -1,125 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/builtin.d.ts
|
|
4
|
-
interface LifecycleAppHooks {
|
|
5
|
-
onStart: (hook: () => void | Promise<void>) => void;
|
|
6
|
-
onStop: (hook: () => void | Promise<void>) => void;
|
|
7
|
-
}
|
|
8
|
-
interface Lifecycle {
|
|
9
|
-
appHooks: LifecycleAppHooks;
|
|
10
|
-
}
|
|
11
|
-
interface LifecycleTriggerable extends Lifecycle {
|
|
12
|
-
emitOnStart: () => Promise<void>;
|
|
13
|
-
emitOnStop: () => Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/logger.d.ts
|
|
17
|
-
interface Logger {
|
|
18
|
-
provide: (name: string, dependencies: string[]) => void;
|
|
19
|
-
invoke: (dependencies: string[]) => void;
|
|
20
|
-
beforeRun: (name: string) => void;
|
|
21
|
-
run: (name: string, duration: number) => void;
|
|
22
|
-
hookOnStart: (name: string) => void;
|
|
23
|
-
hookOnStartComplete: (name: string, duration: number) => void;
|
|
24
|
-
hookOnStop: (name: string) => void;
|
|
25
|
-
hookOnStopComplete: (name: string, duration: number) => void;
|
|
26
|
-
running: () => void;
|
|
27
|
-
}
|
|
28
|
-
interface LoggerOptions {
|
|
29
|
-
enabled?: boolean;
|
|
30
|
-
logger?: Logger;
|
|
31
|
-
}
|
|
32
|
-
declare function createDefaultLogger(): Logger;
|
|
33
|
-
declare function createLoggLogger(logg: Logg): Logger;
|
|
34
|
-
declare function createNoopLogger(): Logger;
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/scoped.d.ts
|
|
37
|
-
type DependencyMap = Record<string, any>;
|
|
38
|
-
interface Container {
|
|
39
|
-
providers: Map<string, ProvideOptionObject<any, any>>;
|
|
40
|
-
instances: Map<string, any>;
|
|
41
|
-
lifecycleHooks: Map<string, LifecycleTriggerable>;
|
|
42
|
-
dependencyGraph: Map<string, string[]>;
|
|
43
|
-
invocations: InvokeOptionObject<any>[];
|
|
44
|
-
logger: Logger;
|
|
45
|
-
}
|
|
46
|
-
type BuildContext<D extends DependencyMap | undefined = undefined> = {
|
|
47
|
-
container: Container;
|
|
48
|
-
name: string;
|
|
49
|
-
} & (D extends undefined ? {
|
|
50
|
-
dependsOn?: unknown;
|
|
51
|
-
} : {
|
|
52
|
-
dependsOn: D;
|
|
53
|
-
});
|
|
54
|
-
type ResolveDependencyDeclaration<Deps extends Record<string, string | ProvidedKey<any, any, any>>> = { [K in keyof Deps]: Deps[K] extends ProvidedKey<any, infer T, any> ? T : any };
|
|
55
|
-
type ProvideOptionObject<T$1, D extends DependencyMap | undefined = undefined> = {
|
|
56
|
-
build: (context: BuildContext<D>) => T$1 | Promise<T$1>;
|
|
57
|
-
} & (D extends undefined ? {
|
|
58
|
-
dependsOn?: Record<string, never>;
|
|
59
|
-
} : {
|
|
60
|
-
dependsOn: { [K in keyof D]: string };
|
|
61
|
-
});
|
|
62
|
-
type ProvideOptionFunc<T$1, D extends DependencyMap | undefined = undefined> = (context: BuildContext<D>) => T$1 | Promise<T$1>;
|
|
63
|
-
type ProvideOption<T$1, D extends DependencyMap | undefined = undefined> = ProvideOptionObject<T$1, D> | ProvideOptionFunc<T$1, D>;
|
|
64
|
-
interface ProvideOptionObjectWithKeys<T$1, Deps extends Record<string, string | ProvidedKey<any, any, any>>> {
|
|
65
|
-
build: (context: BuildContext<ResolveDependencyDeclaration<Deps>>) => T$1 | Promise<T$1>;
|
|
66
|
-
dependsOn: Deps;
|
|
67
|
-
}
|
|
68
|
-
type ProvideOptionWithKeys<T$1, Deps extends Record<string, string | ProvidedKey<any, any, any>>> = ProvideOptionObjectWithKeys<T$1, Deps>;
|
|
69
|
-
type InvokeOptionObject<D extends DependencyMap | undefined = undefined> = {
|
|
70
|
-
callback: (dependencies: D) => void | Promise<void>;
|
|
71
|
-
} & (D extends undefined ? {
|
|
72
|
-
dependsOn?: Record<string, never>;
|
|
73
|
-
} : {
|
|
74
|
-
dependsOn: { [K in keyof D]: string };
|
|
75
|
-
});
|
|
76
|
-
type InvokeOptionFunc<D extends DependencyMap | undefined = undefined> = (dependencies: D) => void | Promise<void>;
|
|
77
|
-
type InvokeOption<D extends DependencyMap | undefined = undefined> = InvokeOptionObject<D> | InvokeOptionFunc<D>;
|
|
78
|
-
interface InvokeOptionObjectWithKeys<Deps extends Record<string, string | ProvidedKey<any, any, any>>> {
|
|
79
|
-
callback: (dependencies: ResolveDependencyDeclaration<Deps>) => void | Promise<void>;
|
|
80
|
-
dependsOn: Deps;
|
|
81
|
-
}
|
|
82
|
-
type InvokeOptionWithKeys<Deps extends Record<string, string | ProvidedKey<any, any, any>>> = InvokeOptionObjectWithKeys<Deps>;
|
|
83
|
-
declare const lifecycle: ProvidedKey<'lifecycle', Lifecycle, undefined>;
|
|
84
|
-
declare function createContainer(options?: LoggerOptions): Container;
|
|
85
|
-
interface ProvidedKey<Key, _T, _D extends DependencyMap | undefined> {
|
|
86
|
-
key: Key;
|
|
87
|
-
}
|
|
88
|
-
declare function provide<T$1, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, name: Key, option: ProvideOptionWithKeys<T$1, Deps>): ProvidedKey<Key, T$1, ResolveDependencyDeclaration<Deps>>;
|
|
89
|
-
declare function provide<T$1, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, option: ProvideOptionWithKeys<T$1, Deps> & {
|
|
90
|
-
autoNameStackIndex?: number;
|
|
91
|
-
}): ProvidedKey<Key, T$1, ResolveDependencyDeclaration<Deps>>;
|
|
92
|
-
declare function provide<D extends DependencyMap | undefined, T$1 = any, Key extends string = string>(container: Container, name: Key, option: ProvideOption<T$1, D>): ProvidedKey<Key, T$1, D>;
|
|
93
|
-
declare function provide<D extends DependencyMap | undefined, T$1 = any, Key extends string = string>(container: Container, option: ProvideOption<T$1, D> & {
|
|
94
|
-
autoNameStackIndex?: number;
|
|
95
|
-
}): ProvidedKey<Key, T$1, D>;
|
|
96
|
-
declare function invoke<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, option: InvokeOptionWithKeys<Deps>): void;
|
|
97
|
-
declare function invoke<D extends DependencyMap>(container: Container, option: InvokeOption<D>): void;
|
|
98
|
-
declare function resolve<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, dependsOn: Deps): Promise<ResolveDependencyDeclaration<Deps>>;
|
|
99
|
-
declare function start(container: Container): Promise<void>;
|
|
100
|
-
declare function stop(container: Container): Promise<void>;
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/global.d.ts
|
|
103
|
-
declare function setLogger(logger: Logger): void;
|
|
104
|
-
declare function provide$1<T$1, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(name: Key, option: ProvideOptionWithKeys<T$1, Deps>): ProvidedKey<Key, T$1, ResolveDependencyDeclaration<Deps>>;
|
|
105
|
-
declare function provide$1<D extends DependencyMap | undefined, T$1 = any, Key extends string = string>(name: Key, option: ProvideOption<T$1, D>): ProvidedKey<Key, T$1, D>;
|
|
106
|
-
declare function provide$1<T$1, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(option: ProvideOptionWithKeys<T$1, Deps>): ProvidedKey<Key, T$1, ResolveDependencyDeclaration<Deps>>;
|
|
107
|
-
declare function provide$1<D extends DependencyMap | undefined, T$1 = any, Key extends string = string>(option: ProvideOption<T$1, D>): ProvidedKey<Key, T$1, D>;
|
|
108
|
-
declare function invoke$1<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(option: InvokeOptionWithKeys<Deps>): void;
|
|
109
|
-
declare function invoke$1<D extends DependencyMap>(option: InvokeOption<D>): void;
|
|
110
|
-
declare function resolve$1<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(dependsOn: Deps): Promise<ResolveDependencyDeclaration<Deps>>;
|
|
111
|
-
declare function start$1(): Promise<void>;
|
|
112
|
-
declare function stop$1(): Promise<void>;
|
|
113
|
-
//#endregion
|
|
114
|
-
//#region src/index.d.ts
|
|
115
|
-
declare const injeca: {
|
|
116
|
-
provide: typeof provide$1;
|
|
117
|
-
invoke: typeof invoke$1;
|
|
118
|
-
resolve: typeof resolve$1;
|
|
119
|
-
start: typeof start$1;
|
|
120
|
-
stop: typeof stop$1;
|
|
121
|
-
setLogger: typeof setLogger;
|
|
122
|
-
};
|
|
123
|
-
//#endregion
|
|
124
|
-
export { type BuildContext, type Container, type DependencyMap, type InvokeOption, type InvokeOptionFunc, type InvokeOptionObject, type InvokeOptionObjectWithKeys, type InvokeOptionWithKeys, type Lifecycle, type Logger, type LoggerOptions, type ProvideOption, type ProvideOptionFunc, type ProvideOptionObject, type ProvideOptionObjectWithKeys, type ProvideOptionWithKeys, type ProvidedKey, type ResolveDependencyDeclaration, createContainer, createDefaultLogger, createLoggLogger, createNoopLogger, injeca, invoke, lifecycle, provide, resolve, start, stop };
|
|
125
|
-
//# sourceMappingURL=index.d.mts.map
|
|
1
|
+
import { A as resolve, C as ProvidedBy, D as invoke, E as createContainer, F as createDefaultLogger, I as createLoggLogger, L as createNoopLogger, M as stop, N as Logger, O as lifecycle, P as LoggerOptions, R as Lifecycle, S as ProvideOptionWithKeys, T as ResolveDependencyDeclaration, _ as InvokeOptionWithKeys, b as ProvideOptionObject, c as injeca, d as DependencyMap, f as InferProvided, g as InvokeOptionObjectWithKeys, h as InvokeOptionObject, j as start, k as provide, l as BuildContext, m as InvokeOptionFunc, p as InvokeOption, u as Container, v as ProvideOption, w as ProvidedKey, x as ProvideOptionObjectWithKeys, y as ProvideOptionFunc } from "./global-BLY6_SI_.mjs";
|
|
2
|
+
export { ProvidedBy as AsProvidedOf, BuildContext, Container, DependencyMap, InferProvided, InvokeOption, InvokeOptionFunc, InvokeOptionObject, InvokeOptionObjectWithKeys, InvokeOptionWithKeys, Lifecycle, Logger, LoggerOptions, ProvideOption, ProvideOptionFunc, ProvideOptionObject, ProvideOptionObjectWithKeys, ProvideOptionWithKeys, ProvidedKey, ResolveDependencyDeclaration, createContainer, createDefaultLogger, createLoggLogger, createNoopLogger, injeca, invoke, lifecycle, provide, resolve, start, stop };
|
package/dist/index.mjs
CHANGED
|
@@ -1,281 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { nanoid } from "nanoid";
|
|
1
|
+
import { a as provide, c as stop, d as createNoopLogger, i as lifecycle, l as createDefaultLogger, n as createContainer, o as resolve, r as invoke, s as start, t as injeca, u as createLoggLogger } from "./src-DnnFlmag.mjs";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
let globalContainer = createContainer();
|
|
6
|
-
function setLogger(logger) {
|
|
7
|
-
globalContainer.logger = logger;
|
|
8
|
-
}
|
|
9
|
-
function provide$1(nameOrOption, option) {
|
|
10
|
-
if (option != null && typeof option === "function") return provide(globalContainer, nameOrOption, {
|
|
11
|
-
build: option,
|
|
12
|
-
autoNameStackIndex: 2
|
|
13
|
-
});
|
|
14
|
-
return provide(globalContainer, nameOrOption, {
|
|
15
|
-
...option,
|
|
16
|
-
autoNameStackIndex: 2
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
function invoke$1(option) {
|
|
20
|
-
if (typeof option === "function") globalContainer.invocations.push({ callback: option });
|
|
21
|
-
else globalContainer.invocations.push(option);
|
|
22
|
-
}
|
|
23
|
-
function resolve$1(dependsOn) {
|
|
24
|
-
return resolve(globalContainer, dependsOn);
|
|
25
|
-
}
|
|
26
|
-
function start$1() {
|
|
27
|
-
return start(globalContainer);
|
|
28
|
-
}
|
|
29
|
-
function stop$1() {
|
|
30
|
-
return stop(globalContainer);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region package.json
|
|
35
|
-
var name = "injeca";
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region src/logger.ts
|
|
39
|
-
function formatDuration(ms) {
|
|
40
|
-
if (ms < 1) return `${(ms * 1e3).toFixed(3)}µs`;
|
|
41
|
-
if (ms < 1e3) return `${ms.toFixed(3)}ms`;
|
|
42
|
-
return `${(ms / 1e3).toFixed(3)}s`;
|
|
43
|
-
}
|
|
44
|
-
function createDefaultLogger() {
|
|
45
|
-
return {
|
|
46
|
-
provide: (name$1, dependencies) => {
|
|
47
|
-
const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(", ")})` : "";
|
|
48
|
-
console.log(`[${name$1}] PROVIDE ${name$1}${depsStr}`);
|
|
49
|
-
},
|
|
50
|
-
invoke: (dependencies) => {
|
|
51
|
-
const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(", ")})` : "";
|
|
52
|
-
console.log(`[${name}] INVOKE${depsStr}`);
|
|
53
|
-
},
|
|
54
|
-
beforeRun: (name$1) => {
|
|
55
|
-
console.log(`[${name$1}] BEFORE RUN provide: ${name$1}()`);
|
|
56
|
-
},
|
|
57
|
-
run: (name$1, duration) => {
|
|
58
|
-
console.log(`[${name$1}] RUN provide: ${name$1}() in ${formatDuration(duration)}`);
|
|
59
|
-
},
|
|
60
|
-
hookOnStart: (name$1) => {
|
|
61
|
-
console.log(`[${name$1}] HOOK OnStart ${name$1}() executing`);
|
|
62
|
-
},
|
|
63
|
-
hookOnStartComplete: (name$1, duration) => {
|
|
64
|
-
console.log(`[${name$1}] HOOK OnStart ${name$1}() ran successfully in ${formatDuration(duration)}`);
|
|
65
|
-
},
|
|
66
|
-
hookOnStop: (name$1) => {
|
|
67
|
-
console.log(`[${name$1}] HOOK OnStop ${name$1}() executing`);
|
|
68
|
-
},
|
|
69
|
-
hookOnStopComplete: (name$1, duration) => {
|
|
70
|
-
console.log(`[${name$1}] HOOK OnStop ${name$1}() ran successfully in ${formatDuration(duration)}`);
|
|
71
|
-
},
|
|
72
|
-
running: () => {
|
|
73
|
-
console.log(`[${name}] RUNNING`);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function createLoggLogger(logg) {
|
|
78
|
-
return {
|
|
79
|
-
provide: (name$1, dependencies) => {
|
|
80
|
-
const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(", ")})` : "";
|
|
81
|
-
logg.log(`PROVIDE ${name$1}${depsStr}`);
|
|
82
|
-
},
|
|
83
|
-
invoke: (dependencies) => {
|
|
84
|
-
const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(", ")})` : "";
|
|
85
|
-
logg.log(`INVOKE${depsStr}`);
|
|
86
|
-
},
|
|
87
|
-
beforeRun: (name$1) => {
|
|
88
|
-
logg.log(`BEFORE RUN provide: ${name$1}()`);
|
|
89
|
-
},
|
|
90
|
-
run: (name$1, duration) => {
|
|
91
|
-
logg.log(`RUN provide: ${name$1}() in ${formatDuration(duration)}`);
|
|
92
|
-
},
|
|
93
|
-
hookOnStart: (name$1) => {
|
|
94
|
-
logg.log(`HOOK OnStart ${name$1}() executing`);
|
|
95
|
-
},
|
|
96
|
-
hookOnStartComplete: (name$1, duration) => {
|
|
97
|
-
logg.log(`HOOK OnStart ${name$1}() ran successfully in ${formatDuration(duration)}`);
|
|
98
|
-
},
|
|
99
|
-
hookOnStop: (name$1) => {
|
|
100
|
-
logg.log(`HOOK OnStop ${name$1}() executing`);
|
|
101
|
-
},
|
|
102
|
-
hookOnStopComplete: (name$1, duration) => {
|
|
103
|
-
logg.log(`HOOK OnStop ${name$1}() ran successfully in ${formatDuration(duration)}`);
|
|
104
|
-
},
|
|
105
|
-
running: () => {
|
|
106
|
-
logg.log(`RUNNING`);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
function createNoopLogger() {
|
|
111
|
-
return {
|
|
112
|
-
provide: () => {},
|
|
113
|
-
invoke: () => {},
|
|
114
|
-
beforeRun: () => {},
|
|
115
|
-
run: () => {},
|
|
116
|
-
hookOnStart: () => {},
|
|
117
|
-
hookOnStartComplete: () => {},
|
|
118
|
-
hookOnStop: () => {},
|
|
119
|
-
hookOnStopComplete: () => {},
|
|
120
|
-
running: () => {}
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
//#endregion
|
|
125
|
-
//#region src/scoped.ts
|
|
126
|
-
const lifecycle = { key: "lifecycle" };
|
|
127
|
-
function createContainer(options) {
|
|
128
|
-
const logger = options?.enabled === false ? createNoopLogger() : options?.logger ?? createDefaultLogger();
|
|
129
|
-
return {
|
|
130
|
-
providers: /* @__PURE__ */ new Map(),
|
|
131
|
-
instances: /* @__PURE__ */ new Map(),
|
|
132
|
-
lifecycleHooks: /* @__PURE__ */ new Map(),
|
|
133
|
-
dependencyGraph: /* @__PURE__ */ new Map(),
|
|
134
|
-
invocations: [],
|
|
135
|
-
logger
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
function normalizeName(nameOrProvidedKey) {
|
|
139
|
-
if (typeof nameOrProvidedKey === "object" && nameOrProvidedKey !== null && "key" in nameOrProvidedKey) return nameOrProvidedKey.key;
|
|
140
|
-
return nameOrProvidedKey;
|
|
141
|
-
}
|
|
142
|
-
function normalizeProvideOption(nameOrOption, option) {
|
|
143
|
-
if (typeof nameOrOption === "string") {
|
|
144
|
-
if (option == null || !("build" in option) && typeof option !== "function") throw new Error("When using provide(...) as named callback, the second argument must be either a valid ProvideOptionObject<T, D> or a ProvideOptionFunc<T, D>.");
|
|
145
|
-
if (typeof option === "function") return { build: option };
|
|
146
|
-
return option;
|
|
147
|
-
}
|
|
148
|
-
if (typeof nameOrOption === "object" && "key" in nameOrOption) {
|
|
149
|
-
if (option == null || !("build" in option) && typeof option !== "function") throw new Error("When using provide(...) as typed ProvideOptionWithKeys<T, D, Key> callback, the second argument must be either a valid ProvideOptionObject<T, D> or a ProvideOptionFunc<T, D>.");
|
|
150
|
-
if (typeof option === "function") return { build: option };
|
|
151
|
-
return option;
|
|
152
|
-
}
|
|
153
|
-
if (typeof nameOrOption === "function") return { build: nameOrOption };
|
|
154
|
-
return nameOrOption;
|
|
155
|
-
}
|
|
156
|
-
function provide(container, nameOrOption, option) {
|
|
157
|
-
const parentFile = ErrorStackParser.parse(/* @__PURE__ */ new Error("providing"))[option?.autoNameStackIndex ?? 1];
|
|
158
|
-
const name$1 = typeof nameOrOption === "string" ? nameOrOption : `${parentFile.fileName ?? `unknown-${nanoid()}`}:${parentFile.lineNumber ?? 0}:${parentFile.columnNumber ?? 0}`;
|
|
159
|
-
const providerObject = normalizeProvideOption(nameOrOption, option);
|
|
160
|
-
if (providerObject.dependsOn) {
|
|
161
|
-
const resolvedDependsOn = {};
|
|
162
|
-
for (const [key, value] of Object.entries(providerObject.dependsOn)) resolvedDependsOn[key] = normalizeName(value);
|
|
163
|
-
providerObject.dependsOn = resolvedDependsOn;
|
|
164
|
-
}
|
|
165
|
-
container.providers.set(name$1, providerObject);
|
|
166
|
-
const dependencies = providerObject.dependsOn ? Object.values(providerObject.dependsOn) : [];
|
|
167
|
-
container.logger.provide(name$1, dependencies);
|
|
168
|
-
container.dependencyGraph.set(name$1, dependencies);
|
|
169
|
-
return { key: name$1 };
|
|
170
|
-
}
|
|
171
|
-
function invoke(container, option) {
|
|
172
|
-
const invocationObject = typeof option === "function" ? { callback: option } : option;
|
|
173
|
-
if (invocationObject.dependsOn) {
|
|
174
|
-
const resolvedDependsOn = {};
|
|
175
|
-
for (const [key, value] of Object.entries(invocationObject.dependsOn)) resolvedDependsOn[key] = normalizeName(value);
|
|
176
|
-
invocationObject.dependsOn = resolvedDependsOn;
|
|
177
|
-
}
|
|
178
|
-
const dependencies = invocationObject.dependsOn ? Object.values(invocationObject.dependsOn) : [];
|
|
179
|
-
container.logger.invoke(dependencies);
|
|
180
|
-
container.invocations.push(invocationObject);
|
|
181
|
-
}
|
|
182
|
-
async function resolveInstance(container, name$1) {
|
|
183
|
-
if (container.instances.has(name$1)) return container.instances.get(name$1);
|
|
184
|
-
const provider = container.providers.get(name$1);
|
|
185
|
-
if (!provider) throw new Error(`No provider found for '${name$1}'`);
|
|
186
|
-
const resolvedDependencies = {};
|
|
187
|
-
let serviceLifecycle = null;
|
|
188
|
-
if (provider.dependsOn) for (const [key, depName] of Object.entries(provider.dependsOn)) if (depName === "lifecycle") {
|
|
189
|
-
const { buildLifecycle } = await import("./builtin-BN5UvvMB.mjs");
|
|
190
|
-
serviceLifecycle = buildLifecycle();
|
|
191
|
-
resolvedDependencies[key] = serviceLifecycle;
|
|
192
|
-
container.lifecycleHooks.set(name$1, serviceLifecycle);
|
|
193
|
-
} else resolvedDependencies[key] = await resolveInstance(container, depName);
|
|
194
|
-
const context = {
|
|
195
|
-
container,
|
|
196
|
-
dependsOn: resolvedDependencies,
|
|
197
|
-
name: name$1
|
|
198
|
-
};
|
|
199
|
-
container.logger.beforeRun(name$1);
|
|
200
|
-
const startTime = performance.now();
|
|
201
|
-
const instance = await provider.build(context);
|
|
202
|
-
const duration = performance.now() - startTime;
|
|
203
|
-
container.logger.run(name$1, duration);
|
|
204
|
-
container.instances.set(name$1, instance);
|
|
205
|
-
return instance;
|
|
206
|
-
}
|
|
207
|
-
async function resolve(container, dependsOn) {
|
|
208
|
-
const resolved = {};
|
|
209
|
-
for (const [key, depName] of Object.entries(dependsOn)) resolved[key] = await resolveInstance(container, normalizeName(depName));
|
|
210
|
-
return resolved;
|
|
211
|
-
}
|
|
212
|
-
function topologicalSort(dependencyGraph) {
|
|
213
|
-
const visited = /* @__PURE__ */ new Set();
|
|
214
|
-
const visiting = /* @__PURE__ */ new Set();
|
|
215
|
-
const result = [];
|
|
216
|
-
function visit(node) {
|
|
217
|
-
if (visiting.has(node)) throw new Error(`Circular dependency detected involving '${node}'`);
|
|
218
|
-
if (visited.has(node)) return;
|
|
219
|
-
visiting.add(node);
|
|
220
|
-
const dependencies = dependencyGraph.get(node) || [];
|
|
221
|
-
for (const dep of dependencies) visit(dep);
|
|
222
|
-
visiting.delete(node);
|
|
223
|
-
visited.add(node);
|
|
224
|
-
result.push(node);
|
|
225
|
-
}
|
|
226
|
-
for (const node of dependencyGraph.keys()) if (!visited.has(node)) visit(node);
|
|
227
|
-
return result;
|
|
228
|
-
}
|
|
229
|
-
async function startLifecycleHooks(container) {
|
|
230
|
-
const sortedServices = topologicalSort(container.dependencyGraph);
|
|
231
|
-
for (const serviceName of sortedServices) {
|
|
232
|
-
const lifecycle$1 = container.lifecycleHooks.get(serviceName);
|
|
233
|
-
if (lifecycle$1?.emitOnStart) {
|
|
234
|
-
container.logger.hookOnStart(serviceName);
|
|
235
|
-
const startTime = performance.now();
|
|
236
|
-
await lifecycle$1.emitOnStart();
|
|
237
|
-
const duration = performance.now() - startTime;
|
|
238
|
-
container.logger.hookOnStartComplete(serviceName, duration);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
async function stopLifecycleHooks(container) {
|
|
243
|
-
const sortedServices = topologicalSort(container.dependencyGraph);
|
|
244
|
-
for (const serviceName of sortedServices.reverse()) {
|
|
245
|
-
const lifecycle$1 = container.lifecycleHooks.get(serviceName);
|
|
246
|
-
if (lifecycle$1?.emitOnStop) {
|
|
247
|
-
container.logger.hookOnStop(serviceName);
|
|
248
|
-
const startTime = performance.now();
|
|
249
|
-
await lifecycle$1.emitOnStop();
|
|
250
|
-
const duration = performance.now() - startTime;
|
|
251
|
-
container.logger.hookOnStopComplete(serviceName, duration);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
async function start(container) {
|
|
256
|
-
await startLifecycleHooks(container);
|
|
257
|
-
for (const invocation of container.invocations) {
|
|
258
|
-
const resolvedDependencies = {};
|
|
259
|
-
if (invocation.dependsOn) for (const [key, depName] of Object.entries(invocation.dependsOn)) resolvedDependencies[key] = await resolveInstance(container, normalizeName(depName));
|
|
260
|
-
await invocation.callback(resolvedDependencies);
|
|
261
|
-
}
|
|
262
|
-
container.logger.running();
|
|
263
|
-
}
|
|
264
|
-
async function stop(container) {
|
|
265
|
-
await stopLifecycleHooks(container);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
//#endregion
|
|
269
|
-
//#region src/index.ts
|
|
270
|
-
const injeca = {
|
|
271
|
-
provide: provide$1,
|
|
272
|
-
invoke: invoke$1,
|
|
273
|
-
resolve: resolve$1,
|
|
274
|
-
start: start$1,
|
|
275
|
-
stop: stop$1,
|
|
276
|
-
setLogger
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
//#endregion
|
|
280
|
-
export { createContainer, createDefaultLogger, createLoggLogger, createNoopLogger, injeca, invoke, lifecycle, provide, resolve, start, stop };
|
|
281
|
-
//# sourceMappingURL=index.mjs.map
|
|
3
|
+
export { createContainer, createDefaultLogger, createLoggLogger, createNoopLogger, injeca, invoke, lifecycle, provide, resolve, start, stop };
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import ErrorStackParser from "error-stack-parser";
|
|
2
|
+
import { nanoid } from "nanoid";
|
|
3
|
+
|
|
4
|
+
//#region src/global.ts
|
|
5
|
+
let globalContainer = createContainer();
|
|
6
|
+
function setLogger(logger) {
|
|
7
|
+
globalContainer.logger = logger;
|
|
8
|
+
}
|
|
9
|
+
function resetContainer() {
|
|
10
|
+
globalContainer = createContainer();
|
|
11
|
+
}
|
|
12
|
+
function provide(nameOrOption, option) {
|
|
13
|
+
if (option != null && typeof option === "function") return provide$1(globalContainer, nameOrOption, {
|
|
14
|
+
build: option,
|
|
15
|
+
autoNameStackIndex: 2
|
|
16
|
+
});
|
|
17
|
+
return provide$1(globalContainer, nameOrOption, {
|
|
18
|
+
...option,
|
|
19
|
+
autoNameStackIndex: 2
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function invoke(option) {
|
|
23
|
+
if (typeof option === "function") globalContainer.invocations.push({ callback: option });
|
|
24
|
+
else globalContainer.invocations.push(option);
|
|
25
|
+
}
|
|
26
|
+
function resolve(dependsOn) {
|
|
27
|
+
return resolve$1(globalContainer, dependsOn);
|
|
28
|
+
}
|
|
29
|
+
function start() {
|
|
30
|
+
return start$1(globalContainer);
|
|
31
|
+
}
|
|
32
|
+
function stop() {
|
|
33
|
+
return stop$1(globalContainer);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region package.json
|
|
38
|
+
var name = "injeca";
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/logger.ts
|
|
42
|
+
function formatDuration(ms) {
|
|
43
|
+
if (ms < 1) return `${(ms * 1e3).toFixed(3)}µs`;
|
|
44
|
+
if (ms < 1e3) return `${ms.toFixed(3)}ms`;
|
|
45
|
+
return `${(ms / 1e3).toFixed(3)}s`;
|
|
46
|
+
}
|
|
47
|
+
function createDefaultLogger() {
|
|
48
|
+
return {
|
|
49
|
+
provide: (name$1, dependencies) => {
|
|
50
|
+
const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(", ")})` : "";
|
|
51
|
+
console.log(`[${name$1}] PROVIDE ${name$1}${depsStr}`);
|
|
52
|
+
},
|
|
53
|
+
invoke: (dependencies) => {
|
|
54
|
+
const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(", ")})` : "";
|
|
55
|
+
console.log(`[${name}] INVOKE${depsStr}`);
|
|
56
|
+
},
|
|
57
|
+
beforeRun: (name$1) => {
|
|
58
|
+
console.log(`[${name$1}] BEFORE RUN provide: ${name$1}()`);
|
|
59
|
+
},
|
|
60
|
+
run: (name$1, duration) => {
|
|
61
|
+
console.log(`[${name$1}] RUN provide: ${name$1}() in ${formatDuration(duration)}`);
|
|
62
|
+
},
|
|
63
|
+
hookOnStart: (name$1) => {
|
|
64
|
+
console.log(`[${name$1}] HOOK OnStart ${name$1}() executing`);
|
|
65
|
+
},
|
|
66
|
+
hookOnStartComplete: (name$1, duration) => {
|
|
67
|
+
console.log(`[${name$1}] HOOK OnStart ${name$1}() ran successfully in ${formatDuration(duration)}`);
|
|
68
|
+
},
|
|
69
|
+
hookOnStop: (name$1) => {
|
|
70
|
+
console.log(`[${name$1}] HOOK OnStop ${name$1}() executing`);
|
|
71
|
+
},
|
|
72
|
+
hookOnStopComplete: (name$1, duration) => {
|
|
73
|
+
console.log(`[${name$1}] HOOK OnStop ${name$1}() ran successfully in ${formatDuration(duration)}`);
|
|
74
|
+
},
|
|
75
|
+
running: () => {
|
|
76
|
+
console.log(`[${name}] RUNNING`);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function createLoggLogger(logg) {
|
|
81
|
+
return {
|
|
82
|
+
provide: (name$1, dependencies) => {
|
|
83
|
+
const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(", ")})` : "";
|
|
84
|
+
logg.log(`PROVIDE ${name$1}${depsStr}`);
|
|
85
|
+
},
|
|
86
|
+
invoke: (dependencies) => {
|
|
87
|
+
const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(", ")})` : "";
|
|
88
|
+
logg.log(`INVOKE${depsStr}`);
|
|
89
|
+
},
|
|
90
|
+
beforeRun: (name$1) => {
|
|
91
|
+
logg.log(`BEFORE RUN provide: ${name$1}()`);
|
|
92
|
+
},
|
|
93
|
+
run: (name$1, duration) => {
|
|
94
|
+
logg.log(`RUN provide: ${name$1}() in ${formatDuration(duration)}`);
|
|
95
|
+
},
|
|
96
|
+
hookOnStart: (name$1) => {
|
|
97
|
+
logg.log(`HOOK OnStart ${name$1}() executing`);
|
|
98
|
+
},
|
|
99
|
+
hookOnStartComplete: (name$1, duration) => {
|
|
100
|
+
logg.log(`HOOK OnStart ${name$1}() ran successfully in ${formatDuration(duration)}`);
|
|
101
|
+
},
|
|
102
|
+
hookOnStop: (name$1) => {
|
|
103
|
+
logg.log(`HOOK OnStop ${name$1}() executing`);
|
|
104
|
+
},
|
|
105
|
+
hookOnStopComplete: (name$1, duration) => {
|
|
106
|
+
logg.log(`HOOK OnStop ${name$1}() ran successfully in ${formatDuration(duration)}`);
|
|
107
|
+
},
|
|
108
|
+
running: () => {
|
|
109
|
+
logg.log(`RUNNING`);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function createNoopLogger() {
|
|
114
|
+
return {
|
|
115
|
+
provide: () => {},
|
|
116
|
+
invoke: () => {},
|
|
117
|
+
beforeRun: () => {},
|
|
118
|
+
run: () => {},
|
|
119
|
+
hookOnStart: () => {},
|
|
120
|
+
hookOnStartComplete: () => {},
|
|
121
|
+
hookOnStop: () => {},
|
|
122
|
+
hookOnStopComplete: () => {},
|
|
123
|
+
running: () => {}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/scoped.ts
|
|
129
|
+
const lifecycle = { key: "lifecycle" };
|
|
130
|
+
function createContainer(options) {
|
|
131
|
+
const logger = options?.enabled === false ? createNoopLogger() : options?.logger ?? createDefaultLogger();
|
|
132
|
+
return {
|
|
133
|
+
providers: /* @__PURE__ */ new Map(),
|
|
134
|
+
instances: /* @__PURE__ */ new Map(),
|
|
135
|
+
lifecycleHooks: /* @__PURE__ */ new Map(),
|
|
136
|
+
dependencyGraph: /* @__PURE__ */ new Map(),
|
|
137
|
+
invocations: [],
|
|
138
|
+
logger
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function normalizeName(nameOrProvidedKey) {
|
|
142
|
+
if (typeof nameOrProvidedKey === "object" && nameOrProvidedKey !== null && "key" in nameOrProvidedKey) return nameOrProvidedKey.key;
|
|
143
|
+
return nameOrProvidedKey;
|
|
144
|
+
}
|
|
145
|
+
function normalizeProvideOption(nameOrOption, option) {
|
|
146
|
+
if (typeof nameOrOption === "string") {
|
|
147
|
+
if (option == null || !("build" in option) && typeof option !== "function") throw new Error("When using provide(...) as named callback, the second argument must be either a valid ProvideOptionObject<T, D> or a ProvideOptionFunc<T, D>.");
|
|
148
|
+
if (typeof option === "function") return { build: option };
|
|
149
|
+
return option;
|
|
150
|
+
}
|
|
151
|
+
if (typeof nameOrOption === "object" && "key" in nameOrOption) {
|
|
152
|
+
if (option == null || !("build" in option) && typeof option !== "function") throw new Error("When using provide(...) as typed ProvideOptionWithKeys<T, D, Key> callback, the second argument must be either a valid ProvideOptionObject<T, D> or a ProvideOptionFunc<T, D>.");
|
|
153
|
+
if (typeof option === "function") return { build: option };
|
|
154
|
+
return option;
|
|
155
|
+
}
|
|
156
|
+
if (typeof nameOrOption === "function") return { build: nameOrOption };
|
|
157
|
+
return nameOrOption;
|
|
158
|
+
}
|
|
159
|
+
function provide$1(container, nameOrOption, option) {
|
|
160
|
+
const parentFile = ErrorStackParser.parse(/* @__PURE__ */ new Error("providing"))[option?.autoNameStackIndex ?? 1];
|
|
161
|
+
const name$1 = typeof nameOrOption === "string" ? nameOrOption : `${parentFile.fileName ?? `unknown-${nanoid()}`}:${parentFile.lineNumber ?? 0}:${parentFile.columnNumber ?? 0}`;
|
|
162
|
+
const providerObject = normalizeProvideOption(nameOrOption, option);
|
|
163
|
+
if (providerObject.dependsOn) {
|
|
164
|
+
const resolvedDependsOn = {};
|
|
165
|
+
for (const [key, value] of Object.entries(providerObject.dependsOn)) resolvedDependsOn[key] = normalizeName(value);
|
|
166
|
+
providerObject.dependsOn = resolvedDependsOn;
|
|
167
|
+
}
|
|
168
|
+
container.providers.set(name$1, providerObject);
|
|
169
|
+
const dependencies = providerObject.dependsOn ? Object.values(providerObject.dependsOn) : [];
|
|
170
|
+
container.logger.provide(name$1, dependencies);
|
|
171
|
+
container.dependencyGraph.set(name$1, dependencies);
|
|
172
|
+
return { key: name$1 };
|
|
173
|
+
}
|
|
174
|
+
function invoke$1(container, option) {
|
|
175
|
+
const invocationObject = typeof option === "function" ? { callback: option } : option;
|
|
176
|
+
if (invocationObject.dependsOn) {
|
|
177
|
+
const resolvedDependsOn = {};
|
|
178
|
+
for (const [key, value] of Object.entries(invocationObject.dependsOn)) resolvedDependsOn[key] = normalizeName(value);
|
|
179
|
+
invocationObject.dependsOn = resolvedDependsOn;
|
|
180
|
+
}
|
|
181
|
+
const dependencies = invocationObject.dependsOn ? Object.values(invocationObject.dependsOn) : [];
|
|
182
|
+
container.logger.invoke(dependencies);
|
|
183
|
+
container.invocations.push(invocationObject);
|
|
184
|
+
}
|
|
185
|
+
async function resolveInstance(container, name$1) {
|
|
186
|
+
if (container.instances.has(name$1)) {
|
|
187
|
+
const existing = container.instances.get(name$1);
|
|
188
|
+
return existing instanceof Promise ? await existing : existing;
|
|
189
|
+
}
|
|
190
|
+
const provider = container.providers.get(name$1);
|
|
191
|
+
if (!provider) throw new Error(`No provider found for '${name$1}'`);
|
|
192
|
+
const resolvedDependencies = {};
|
|
193
|
+
let serviceLifecycle = null;
|
|
194
|
+
if (provider.dependsOn) for (const [key, depName] of Object.entries(provider.dependsOn)) if (depName === "lifecycle") {
|
|
195
|
+
const { buildLifecycle } = await import("./builtin-BPDNf8Z-.mjs");
|
|
196
|
+
serviceLifecycle = buildLifecycle();
|
|
197
|
+
resolvedDependencies[key] = serviceLifecycle;
|
|
198
|
+
container.lifecycleHooks.set(name$1, serviceLifecycle);
|
|
199
|
+
} else resolvedDependencies[key] = await resolveInstance(container, depName);
|
|
200
|
+
const context = {
|
|
201
|
+
container,
|
|
202
|
+
dependsOn: resolvedDependencies,
|
|
203
|
+
name: name$1
|
|
204
|
+
};
|
|
205
|
+
async function buildAndStore() {
|
|
206
|
+
container.logger.beforeRun(name$1);
|
|
207
|
+
const startTime = performance.now();
|
|
208
|
+
const instance = await provider.build(context);
|
|
209
|
+
const duration = performance.now() - startTime;
|
|
210
|
+
container.logger.run(name$1, duration);
|
|
211
|
+
container.instances.set(name$1, instance);
|
|
212
|
+
return instance;
|
|
213
|
+
}
|
|
214
|
+
const buildPromise = buildAndStore();
|
|
215
|
+
container.instances.set(name$1, buildPromise);
|
|
216
|
+
return await buildPromise;
|
|
217
|
+
}
|
|
218
|
+
async function resolve$1(container, dependsOn) {
|
|
219
|
+
const resolved = {};
|
|
220
|
+
for (const [key, depName] of Object.entries(dependsOn)) resolved[key] = await resolveInstance(container, normalizeName(depName));
|
|
221
|
+
return resolved;
|
|
222
|
+
}
|
|
223
|
+
function topologicalSort(dependencyGraph) {
|
|
224
|
+
const visited = /* @__PURE__ */ new Set();
|
|
225
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
226
|
+
const result = [];
|
|
227
|
+
function visit(node) {
|
|
228
|
+
if (visiting.has(node)) throw new Error(`Circular dependency detected involving '${node}'`);
|
|
229
|
+
if (visited.has(node)) return;
|
|
230
|
+
visiting.add(node);
|
|
231
|
+
const dependencies = dependencyGraph.get(node) || [];
|
|
232
|
+
for (const dep of dependencies) visit(dep);
|
|
233
|
+
visiting.delete(node);
|
|
234
|
+
visited.add(node);
|
|
235
|
+
result.push(node);
|
|
236
|
+
}
|
|
237
|
+
for (const node of dependencyGraph.keys()) if (!visited.has(node)) visit(node);
|
|
238
|
+
return result;
|
|
239
|
+
}
|
|
240
|
+
async function startLifecycleHooks(container) {
|
|
241
|
+
const sortedServices = topologicalSort(container.dependencyGraph);
|
|
242
|
+
for (const serviceName of sortedServices) {
|
|
243
|
+
const lifecycle$1 = container.lifecycleHooks.get(serviceName);
|
|
244
|
+
if (lifecycle$1?.emitOnStart) {
|
|
245
|
+
container.logger.hookOnStart(serviceName);
|
|
246
|
+
const startTime = performance.now();
|
|
247
|
+
await lifecycle$1.emitOnStart();
|
|
248
|
+
const duration = performance.now() - startTime;
|
|
249
|
+
container.logger.hookOnStartComplete(serviceName, duration);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
async function stopLifecycleHooks(container) {
|
|
254
|
+
const sortedServices = topologicalSort(container.dependencyGraph);
|
|
255
|
+
for (const serviceName of sortedServices.reverse()) {
|
|
256
|
+
const lifecycle$1 = container.lifecycleHooks.get(serviceName);
|
|
257
|
+
if (lifecycle$1?.emitOnStop) {
|
|
258
|
+
container.logger.hookOnStop(serviceName);
|
|
259
|
+
const startTime = performance.now();
|
|
260
|
+
await lifecycle$1.emitOnStop();
|
|
261
|
+
const duration = performance.now() - startTime;
|
|
262
|
+
container.logger.hookOnStopComplete(serviceName, duration);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async function start$1(container) {
|
|
267
|
+
await startLifecycleHooks(container);
|
|
268
|
+
for (const invocation of container.invocations) {
|
|
269
|
+
const resolvedDependencies = {};
|
|
270
|
+
if (invocation.dependsOn) for (const [key, depName] of Object.entries(invocation.dependsOn)) resolvedDependencies[key] = await resolveInstance(container, normalizeName(depName));
|
|
271
|
+
await invocation.callback(resolvedDependencies);
|
|
272
|
+
}
|
|
273
|
+
container.logger.running();
|
|
274
|
+
}
|
|
275
|
+
async function stop$1(container) {
|
|
276
|
+
await stopLifecycleHooks(container);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/index.ts
|
|
281
|
+
const injeca = {
|
|
282
|
+
provide,
|
|
283
|
+
invoke,
|
|
284
|
+
resolve,
|
|
285
|
+
start,
|
|
286
|
+
stop,
|
|
287
|
+
setLogger
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
//#endregion
|
|
291
|
+
export { start as _, provide$1 as a, stop$1 as c, createNoopLogger as d, invoke as f, setLogger as g, resolve as h, lifecycle as i, createDefaultLogger as l, resetContainer as m, createContainer as n, resolve$1 as o, provide as p, invoke$1 as r, start$1 as s, injeca as t, createLoggLogger as u, stop as v };
|
|
292
|
+
//# sourceMappingURL=src-DnnFlmag.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-DnnFlmag.mjs","names":["indexProvide","indexResolve","indexStart","indexStop","name","lifecycle: ProvidedKey<'lifecycle', Lifecycle, undefined>","provide","name","resolvedDependsOn: Record<string, string>","invoke","resolvedDependencies: Record<string, any>","serviceLifecycle: any","context: BuildContext<typeof provider.dependsOn>","resolve","resolved: Record<string, any>","result: string[]","lifecycle","start","stop","globalProvide","globalInvoke","globalResolve","globalStart","globalStop","globalSetLogger"],"sources":["../src/global.ts","../package.json","../src/logger.ts","../src/scoped.ts","../src/index.ts"],"sourcesContent":["import type { DependencyMap, InvokeOption, InvokeOptionWithKeys, Logger, ProvideOption, ProvideOptionWithKeys, ResolveDependencyDeclaration } from '.'\nimport type { ProvidedKey } from './scoped'\n\nimport { createContainer, provide as indexProvide, resolve as indexResolve, start as indexStart, stop as indexStop } from '.'\n\nlet globalContainer = createContainer()\n\nexport function setLogger(logger: Logger) {\n globalContainer.logger = logger\n}\n\nexport function resetContainer() {\n globalContainer = createContainer()\n}\n\nexport function provide<T, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(name: Key, option: ProvideOptionWithKeys<T, Deps>): ProvidedKey<Key, T, ResolveDependencyDeclaration<Deps>>\nexport function provide<D extends DependencyMap | undefined, T = any, Key extends string = string>(name: Key, option: ProvideOption<T, D>): ProvidedKey<Key, T, D>\nexport function provide<T, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(option: ProvideOptionWithKeys<T, Deps>): ProvidedKey<Key, T, ResolveDependencyDeclaration<Deps>>\nexport function provide<D extends DependencyMap | undefined, T = any, Key extends string = string>(option: ProvideOption<T, D>): ProvidedKey<Key, T, D>\nexport function provide<D extends DependencyMap | undefined, T = any, Key extends string = string>(nameOrOption: Key | ProvideOption<T, D> | ProvideOptionWithKeys<T, any>, option?: ProvideOption<T, D> | ProvideOptionWithKeys<T, any>): ProvidedKey<Key, T, D> {\n if (option != null && typeof option === 'function') {\n return indexProvide(globalContainer, nameOrOption as any, { build: option, autoNameStackIndex: 2 } as any)\n }\n\n return indexProvide(globalContainer, nameOrOption as any, { ...option, autoNameStackIndex: 2 } as any)\n}\n\nexport function invoke<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(option: InvokeOptionWithKeys<Deps>): void\nexport function invoke<D extends DependencyMap>(option: InvokeOption<D>): void\nexport function invoke<D extends DependencyMap>(option: InvokeOption<D> | InvokeOptionWithKeys<any>): void {\n if (typeof option === 'function') {\n globalContainer.invocations.push({ callback: option } as any)\n }\n else {\n globalContainer.invocations.push(option as any)\n }\n}\n\nexport function resolve<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(dependsOn: Deps): Promise<ResolveDependencyDeclaration<Deps>> {\n return indexResolve(globalContainer, dependsOn)\n}\n\nexport function start(): Promise<void> {\n return indexStart(globalContainer)\n}\n\nexport function stop(): Promise<void> {\n return indexStop(globalContainer)\n}\n","{\n \"name\": \"injeca\",\n \"type\": \"module\",\n \"version\": \"0.1.6\",\n \"packageManager\": \"pnpm@10.28.0\",\n \"description\": \"Pure functional programming based dependency injection library inspired by go.uber.org/fig and go.uber.org/dig.\",\n \"author\": {\n \"name\": \"Moeru AI Project AIRI Team\",\n \"email\": \"airi@moeru.ai\",\n \"url\": \"https://github.com/moeru-ai\"\n },\n \"license\": \"MIT\",\n \"homepage\": \"https://github.com/moeru-ai/injeca\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/moeru-ai/injeca.git\"\n },\n \"exports\": {\n \".\": {\n \"type\": \"./dist/index.d.mts\",\n \"default\": \"./dist/index.mjs\"\n },\n \"./global\": {\n \"type\": \"./dist/global.d.mts\",\n \"default\": \"./dist/global.mjs\"\n }\n },\n \"main\": \"./dist/index.mjs\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.mts\",\n \"files\": [\n \"README.md\",\n \"dist\",\n \"package.json\"\n ],\n \"scripts\": {\n \"build\": \"tsdown\",\n \"test\": \"vitest --coverage\",\n \"test:run\": \"vitest run\",\n \"lint\": \"eslint --cache .\",\n \"lint:fix\": \"eslint --cache --fix .\",\n \"typecheck\": \"tsc --noEmit\",\n \"up\": \"taze -w -r -I -f && pnpm prune && pnpm dedupe\"\n },\n \"peerDependencies\": {\n \"@guiiai/logg\": \">= 1\",\n \"error-stack-parser\": \"^2.1.4\",\n \"nanoid\": \">=5\"\n },\n \"peerDependenciesMeta\": {\n \"@guiiai/logg\": {\n \"optional\": true\n }\n },\n \"devDependencies\": {\n \"@antfu/eslint-config\": \"^6.7.3\",\n \"@moeru/eslint-config\": \"^0.1.0-beta.15\",\n \"@moeru/std\": \"^0.1.0-beta.15\",\n \"@moeru/tsconfig\": \"^0.1.0-beta.15\",\n \"@types/node\": \"^25.0.9\",\n \"bumpp\": \"^10.4.0\",\n \"eslint\": \"^9.39.2\",\n \"eslint-plugin-oxlint\": \"^1.39.0\",\n \"oxlint\": \"^1.39.0\",\n \"publint\": \"^0.3.16\",\n \"taze\": \"^19.9.2\",\n \"tsdown\": \"^0.17.4\",\n \"typescript\": \"^5.9.3\",\n \"unplugin-unused\": \"^0.5.6\",\n \"vite\": \"^7.3.1\",\n \"vitest\": \"^4.0.17\"\n }\n}\n","import type { Logg as LoggLogger } from '@guiiai/logg'\n\nimport { name } from '../package.json'\n\nexport interface Logger {\n provide: (name: string, dependencies: string[]) => void\n invoke: (dependencies: string[]) => void\n beforeRun: (name: string) => void\n run: (name: string, duration: number) => void\n hookOnStart: (name: string) => void\n hookOnStartComplete: (name: string, duration: number) => void\n hookOnStop: (name: string) => void\n hookOnStopComplete: (name: string, duration: number) => void\n running: () => void\n}\n\nexport interface LoggerOptions {\n enabled?: boolean\n logger?: Logger\n}\n\nfunction formatDuration(ms: number): string {\n if (ms < 1) {\n return `${(ms * 1000).toFixed(3)}µs`\n }\n if (ms < 1000) {\n return `${ms.toFixed(3)}ms`\n }\n return `${(ms / 1000).toFixed(3)}s`\n}\n\nexport function createDefaultLogger(): Logger {\n return {\n provide: (name: string, dependencies: string[]) => {\n const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(', ')})` : ''\n // eslint-disable-next-line no-console\n console.log(`[${name}] PROVIDE ${name}${depsStr}`)\n },\n\n invoke: (dependencies: string[]) => {\n const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(', ')})` : ''\n // eslint-disable-next-line no-console\n console.log(`[${name}] INVOKE${depsStr}`)\n },\n\n beforeRun: (name: string) => {\n // eslint-disable-next-line no-console\n console.log(`[${name}] BEFORE RUN provide: ${name}()`)\n },\n\n run: (name: string, duration: number) => {\n // eslint-disable-next-line no-console\n console.log(`[${name}] RUN provide: ${name}() in ${formatDuration(duration)}`)\n },\n\n hookOnStart: (name: string) => {\n // eslint-disable-next-line no-console\n console.log(`[${name}] HOOK OnStart ${name}() executing`)\n },\n\n hookOnStartComplete: (name: string, duration: number) => {\n // eslint-disable-next-line no-console\n console.log(`[${name}] HOOK OnStart ${name}() ran successfully in ${formatDuration(duration)}`)\n },\n\n hookOnStop: (name: string) => {\n // eslint-disable-next-line no-console\n console.log(`[${name}] HOOK OnStop ${name}() executing`)\n },\n\n hookOnStopComplete: (name: string, duration: number) => {\n // eslint-disable-next-line no-console\n console.log(`[${name}] HOOK OnStop ${name}() ran successfully in ${formatDuration(duration)}`)\n },\n\n running: () => {\n // eslint-disable-next-line no-console\n console.log(`[${name}] RUNNING`)\n },\n }\n}\n\nexport function createLoggLogger(logg: LoggLogger): Logger {\n return {\n provide: (name: string, dependencies: string[]) => {\n const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(', ')})` : ''\n logg.log(`PROVIDE ${name}${depsStr}`)\n },\n\n invoke: (dependencies: string[]) => {\n const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(', ')})` : ''\n logg.log(`INVOKE${depsStr}`)\n },\n\n beforeRun: (name: string) => {\n logg.log(`BEFORE RUN provide: ${name}()`)\n },\n\n run: (name: string, duration: number) => {\n logg.log(`RUN provide: ${name}() in ${formatDuration(duration)}`)\n },\n\n hookOnStart: (name: string) => {\n logg.log(`HOOK OnStart ${name}() executing`)\n },\n\n hookOnStartComplete: (name: string, duration: number) => {\n logg.log(`HOOK OnStart ${name}() ran successfully in ${formatDuration(duration)}`)\n },\n\n hookOnStop: (name: string) => {\n logg.log(`HOOK OnStop ${name}() executing`)\n },\n\n hookOnStopComplete: (name: string, duration: number) => {\n logg.log(`HOOK OnStop ${name}() ran successfully in ${formatDuration(duration)}`)\n },\n\n running: () => {\n logg.log(`RUNNING`)\n },\n }\n}\n\nexport function createNoopLogger(): Logger {\n return {\n provide: () => {},\n invoke: () => {},\n beforeRun: () => {},\n run: () => {},\n hookOnStart: () => {},\n hookOnStartComplete: () => {},\n hookOnStop: () => {},\n hookOnStopComplete: () => {},\n running: () => {},\n }\n}\n","import type { Lifecycle, LifecycleTriggerable } from './builtin'\nimport type { Logger, LoggerOptions } from './logger'\n\nimport ErrorStackParser from 'error-stack-parser'\n\nimport { nanoid } from 'nanoid'\n\nimport { createDefaultLogger, createNoopLogger } from './logger'\n\nexport type DependencyMap = Record<string, any>\n\nexport interface Container {\n providers: Map<string, ProvideOptionObject<any, any>>\n instances: Map<string, any>\n lifecycleHooks: Map<string, LifecycleTriggerable>\n dependencyGraph: Map<string, string[]>\n invocations: InvokeOptionObject<any>[]\n logger: Logger\n}\n\nexport type BuildContext<D extends DependencyMap | undefined = undefined> = {\n container: Container\n name: string\n} & (D extends undefined ? { dependsOn?: unknown } : { dependsOn: D })\n\nexport type ResolveDependencyDeclaration<Deps extends Record<string, string | ProvidedKey<any, any, any>>> = {\n [K in keyof Deps]: Deps[K] extends ProvidedKey<any, infer T, any>\n ? T\n : Deps[K] extends ProvidedBy<infer T>\n ? T\n : any\n}\n\nexport type ProvideOptionObject<T, D extends DependencyMap | undefined = undefined> = { build: (context: BuildContext<D>) => T | Promise<T> } & (D extends undefined ? { dependsOn?: Record<string, never> } : { dependsOn: { [K in keyof D]: string } })\nexport type ProvideOptionFunc<T, D extends DependencyMap | undefined = undefined> = (context: BuildContext<D>) => T | Promise<T>\nexport type ProvideOption<T, D extends DependencyMap | undefined = undefined> = ProvideOptionObject<T, D> | ProvideOptionFunc<T, D>\n\nexport interface ProvideOptionObjectWithKeys<T, Deps extends Record<string, string | ProvidedKey<any, any, any>>> {\n build: (context: BuildContext<ResolveDependencyDeclaration<Deps>>) => T | Promise<T>\n dependsOn: Deps\n}\nexport type ProvideOptionWithKeys<T, Deps extends Record<string, string | ProvidedKey<any, any, any>>> = ProvideOptionObjectWithKeys<T, Deps>\n\nexport type InvokeOptionObject<D extends DependencyMap | undefined = undefined> = { callback: (dependencies: D) => void | Promise<void> } & (D extends undefined ? { dependsOn?: Record<string, never> } : { dependsOn: { [K in keyof D]: string } })\nexport type InvokeOptionFunc<D extends DependencyMap | undefined = undefined> = (dependencies: D) => void | Promise<void>\nexport type InvokeOption<D extends DependencyMap | undefined = undefined> = InvokeOptionObject<D> | InvokeOptionFunc<D>\n\nexport interface InvokeOptionObjectWithKeys<Deps extends Record<string, string | ProvidedKey<any, any, any>>> {\n callback: (dependencies: ResolveDependencyDeclaration<Deps>) => void | Promise<void>\n dependsOn: Deps\n}\nexport type InvokeOptionWithKeys<Deps extends Record<string, string | ProvidedKey<any, any, any>>> = InvokeOptionObjectWithKeys<Deps>\n\nexport const lifecycle: ProvidedKey<'lifecycle', Lifecycle, undefined> = { key: 'lifecycle' }\n\nexport function createContainer(options?: LoggerOptions): Container {\n const logger = options?.enabled === false\n ? createNoopLogger()\n : (options?.logger ?? createDefaultLogger())\n\n return {\n providers: new Map(),\n instances: new Map(),\n lifecycleHooks: new Map(),\n dependencyGraph: new Map(),\n invocations: [],\n logger,\n }\n}\n\nexport interface ProvidedKey<Key, _T, _D extends DependencyMap | undefined> {\n key: Key\n}\n\nexport type ProvidedBy<T> = string & { __providedType?: T }\n\nexport type InferProvided<T>\n = T extends ProvidedKey<any, infer P, any>\n ? P\n : T extends ProvidedBy<infer P>\n ? P\n : never\n\nexport function normalizeName(nameOrProvidedKey: string | ProvidedKey<any, any, any>): string {\n if (typeof nameOrProvidedKey === 'object' && nameOrProvidedKey !== null && 'key' in nameOrProvidedKey) {\n return (nameOrProvidedKey as ProvidedKey<any, any, any>).key as string\n }\n\n return nameOrProvidedKey as string\n}\n\nexport function normalizeProvideOption<D extends DependencyMap | undefined, T = any, Key extends string = string>(nameOrOption: Key | ProvidedKey<Key, T, D> | ProvideOption<T, D> | ProvideOptionWithKeys<T, any>, option?: (ProvideOption<T, D> | ProvideOptionWithKeys<T, any>) & { autoNameStackIndex?: number }): ProvideOptionObject<T, D> {\n if (typeof nameOrOption === 'string') {\n if (option == null || (!('build' in option) && typeof option !== 'function')) {\n throw new Error('When using provide(...) as named callback, the second argument must be either a valid ProvideOptionObject<T, D> or a ProvideOptionFunc<T, D>.')\n }\n if (typeof option === 'function') {\n return { build: option } as ProvideOptionObject<T, D>\n }\n\n return option as ProvideOptionObject<T, D>\n }\n if (typeof nameOrOption === 'object' && 'key' in nameOrOption) {\n if (option == null || (!('build' in option) && typeof option !== 'function')) {\n throw new Error('When using provide(...) as typed ProvideOptionWithKeys<T, D, Key> callback, the second argument must be either a valid ProvideOptionObject<T, D> or a ProvideOptionFunc<T, D>.')\n }\n if (typeof option === 'function') {\n return { build: option } as ProvideOptionObject<T, D>\n }\n\n return option as ProvideOptionObject<T, D>\n }\n\n if (typeof nameOrOption === 'function') {\n return { build: nameOrOption } as ProvideOptionObject<T, D>\n }\n\n return nameOrOption as ProvideOptionObject<T, D>\n}\n\nexport function provide<T, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, name: Key, option: ProvideOptionWithKeys<T, Deps>): ProvidedKey<Key, T, ResolveDependencyDeclaration<Deps>>\nexport function provide<T, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, option: ProvideOptionWithKeys<T, Deps> & { autoNameStackIndex?: number }): ProvidedKey<Key, T, ResolveDependencyDeclaration<Deps>>\nexport function provide<D extends DependencyMap | undefined, T = any, Key extends string = string>(container: Container, name: Key, option: ProvideOption<T, D>): ProvidedKey<Key, T, D>\nexport function provide<D extends DependencyMap | undefined, T = any, Key extends string = string>(container: Container, option: ProvideOption<T, D> & { autoNameStackIndex?: number }): ProvidedKey<Key, T, D>\nexport function provide<D extends DependencyMap | undefined, T = any, Key extends string = string>(container: Container, nameOrOption: Key | ProvideOption<T, D> | ProvideOptionWithKeys<T, any>, option?: (ProvideOption<T, D> | ProvideOptionWithKeys<T, any>) & { autoNameStackIndex?: number }): ProvidedKey<Key, T, D> {\n const parentFile = ErrorStackParser.parse(new Error('providing'))[option?.autoNameStackIndex ?? 1]\n const name = typeof nameOrOption === 'string'\n ? nameOrOption\n : `${parentFile.fileName ?? `unknown-${nanoid()}`}:${parentFile.lineNumber ?? 0}:${parentFile.columnNumber ?? 0}`\n\n const providerObject = normalizeProvideOption<D, T, Key>(nameOrOption, option) as unknown as ProvideOptionObject<any, any>\n if (providerObject.dependsOn) {\n const resolvedDependsOn: Record<string, string> = {}\n for (const [key, value] of Object.entries(providerObject.dependsOn)) {\n resolvedDependsOn[key] = normalizeName(value)\n }\n\n providerObject.dependsOn = resolvedDependsOn\n }\n\n container.providers.set(name, providerObject)\n\n const dependencies = providerObject.dependsOn ? Object.values(providerObject.dependsOn) : []\n container.logger.provide(name, dependencies)\n container.dependencyGraph.set(name, dependencies)\n\n return { key: name } as ProvidedKey<Key, T, D>\n}\n\nexport function invoke<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, option: InvokeOptionWithKeys<Deps>): void\nexport function invoke<D extends DependencyMap>(container: Container, option: InvokeOption<D>): void\nexport function invoke<D extends DependencyMap>(container: Container, option: InvokeOption<D> | InvokeOptionWithKeys<any>): void {\n const invocationObject = typeof option === 'function'\n ? { callback: option } as InvokeOptionObject<any>\n : option as InvokeOptionObject<any>\n\n if (invocationObject.dependsOn) {\n const resolvedDependsOn: Record<string, string> = {}\n for (const [key, value] of Object.entries(invocationObject.dependsOn)) {\n resolvedDependsOn[key] = normalizeName(value)\n }\n\n invocationObject.dependsOn = resolvedDependsOn\n }\n\n const dependencies = invocationObject.dependsOn ? Object.values(invocationObject.dependsOn) : []\n\n container.logger.invoke(dependencies)\n container.invocations.push(invocationObject)\n}\n\nasync function resolveInstance<T>(container: Container, name: string): Promise<T> {\n if (container.instances.has(name)) {\n const existing = container.instances.get(name)\n // NOTICE: Cache in-progress promise so concurrent resolve calls share the same build.\n return existing instanceof Promise ? await existing as T : existing as T\n }\n\n const provider = container.providers.get(name)\n if (!provider) {\n throw new Error(`No provider found for '${name}'`)\n }\n\n const resolvedDependencies: Record<string, any> = {}\n let serviceLifecycle: any = null\n\n if (provider.dependsOn) {\n for (const [key, depName] of Object.entries(provider.dependsOn)) {\n if (depName === 'lifecycle') {\n // Create individual lifecycle instance for this service\n const { buildLifecycle } = await import('./builtin')\n serviceLifecycle = buildLifecycle()\n resolvedDependencies[key] = serviceLifecycle\n\n // Track this service's lifecycle\n container.lifecycleHooks.set(name, serviceLifecycle)\n }\n else {\n resolvedDependencies[key] = await resolveInstance(container, depName)\n }\n }\n }\n\n const context: BuildContext<typeof provider.dependsOn> = {\n container,\n dependsOn: resolvedDependencies,\n name,\n }\n\n async function buildAndStore(): Promise<T> {\n container.logger.beforeRun(name)\n\n const startTime = performance.now()\n // NOTICE: here we assert provider is defined because we checked above\n const instance = await provider!.build(context)\n const duration = performance.now() - startTime\n\n container.logger.run(name, duration)\n\n container.instances.set(name, instance)\n\n return instance as T\n }\n\n const buildPromise = buildAndStore()\n container.instances.set(name, buildPromise)\n\n return await buildPromise\n}\n\nexport async function resolve<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, dependsOn: Deps): Promise<ResolveDependencyDeclaration<Deps>> {\n const resolved: Record<string, any> = {}\n\n for (const [key, depName] of Object.entries(dependsOn)) {\n const normalizedName = normalizeName(depName)\n\n resolved[key] = await resolveInstance(container, normalizedName)\n }\n\n return resolved as ResolveDependencyDeclaration<Deps>\n}\n\nfunction topologicalSort(dependencyGraph: Map<string, string[]>): string[] {\n const visited = new Set<string>()\n const visiting = new Set<string>()\n const result: string[] = []\n\n function visit(node: string) {\n if (visiting.has(node)) {\n throw new Error(`Circular dependency detected involving '${node}'`)\n }\n if (visited.has(node)) {\n return\n }\n\n visiting.add(node)\n const dependencies = dependencyGraph.get(node) || []\n for (const dep of dependencies) {\n visit(dep)\n }\n visiting.delete(node)\n visited.add(node)\n result.push(node)\n }\n\n for (const node of dependencyGraph.keys()) {\n if (!visited.has(node)) {\n visit(node)\n }\n }\n\n return result\n}\n\nexport async function startLifecycleHooks(container: Container): Promise<void> {\n const sortedServices = topologicalSort(container.dependencyGraph)\n\n for (const serviceName of sortedServices) {\n const lifecycle = container.lifecycleHooks.get(serviceName)\n if (lifecycle?.emitOnStart) {\n container.logger.hookOnStart(serviceName)\n\n const startTime = performance.now()\n await lifecycle.emitOnStart()\n const duration = performance.now() - startTime\n\n container.logger.hookOnStartComplete(serviceName, duration)\n }\n }\n}\n\nexport async function stopLifecycleHooks(container: Container): Promise<void> {\n const sortedServices = topologicalSort(container.dependencyGraph)\n\n // Shutdown in reverse order\n for (const serviceName of sortedServices.reverse()) {\n const lifecycle = container.lifecycleHooks.get(serviceName)\n if (lifecycle?.emitOnStop) {\n container.logger.hookOnStop(serviceName)\n\n const startTime = performance.now()\n await lifecycle.emitOnStop()\n const duration = performance.now() - startTime\n\n container.logger.hookOnStopComplete(serviceName, duration)\n }\n }\n}\n\nexport async function start(container: Container): Promise<void> {\n await startLifecycleHooks(container)\n\n for (const invocation of container.invocations) {\n const resolvedDependencies: Record<string, any> = {}\n\n if (invocation.dependsOn) {\n for (const [key, depName] of Object.entries(invocation.dependsOn)) {\n resolvedDependencies[key] = await resolveInstance(container, normalizeName(depName))\n }\n }\n\n await invocation.callback(resolvedDependencies)\n }\n\n container.logger.running()\n}\n\nexport async function stop(container: Container): Promise<void> {\n await stopLifecycleHooks(container)\n}\n","import {\n invoke as globalInvoke,\n provide as globalProvide,\n resolve as globalResolve,\n setLogger as globalSetLogger,\n start as globalStart,\n stop as globalStop,\n} from './global'\n\nexport type { Lifecycle } from './builtin'\n\nexport type { Logger, LoggerOptions } from './logger'\n\nexport {\n createDefaultLogger,\n createLoggLogger,\n createNoopLogger,\n} from './logger'\n\nexport {\n createContainer,\n invoke,\n lifecycle,\n provide,\n resolve,\n start,\n stop,\n} from './scoped'\nexport type {\n ProvidedBy as AsProvidedOf,\n BuildContext,\n Container,\n DependencyMap,\n InferProvided,\n InvokeOption,\n InvokeOptionFunc,\n InvokeOptionObject,\n InvokeOptionObjectWithKeys,\n InvokeOptionWithKeys,\n ProvidedKey,\n ProvideOption,\n ProvideOptionFunc,\n ProvideOptionObject,\n ProvideOptionObjectWithKeys,\n ProvideOptionWithKeys,\n ResolveDependencyDeclaration,\n} from './scoped'\n\nexport const injeca = {\n provide: globalProvide,\n invoke: globalInvoke,\n resolve: globalResolve,\n start: globalStart,\n stop: globalStop,\n setLogger: globalSetLogger,\n}\n"],"mappings":";;;;AAKA,IAAI,kBAAkB,iBAAiB;AAEvC,SAAgB,UAAU,QAAgB;AACxC,iBAAgB,SAAS;;AAG3B,SAAgB,iBAAiB;AAC/B,mBAAkB,iBAAiB;;AAOrC,SAAgB,QAAmF,cAAyE,QAAsF;AAChQ,KAAI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,OAAK,WAAqC;AAC9D,OAAM,mBAAmB,UAAU;;;;;ACxRrC,MAAa,SAAS;CACXC;CACDC;CACCC;CACFC;CACDC;CACKC;CACZ"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "injeca",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.6",
|
|
5
5
|
"description": "Pure functional programming based dependency injection library inspired by go.uber.org/fig and go.uber.org/dig.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Moeru AI Project AIRI Team",
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
".": {
|
|
19
19
|
"type": "./dist/index.d.mts",
|
|
20
20
|
"default": "./dist/index.mjs"
|
|
21
|
+
},
|
|
22
|
+
"./global": {
|
|
23
|
+
"type": "./dist/global.d.mts",
|
|
24
|
+
"default": "./dist/global.mjs"
|
|
21
25
|
}
|
|
22
26
|
},
|
|
23
27
|
"main": "./dist/index.mjs",
|
|
@@ -39,21 +43,22 @@
|
|
|
39
43
|
}
|
|
40
44
|
},
|
|
41
45
|
"devDependencies": {
|
|
42
|
-
"@antfu/eslint-config": "^6.
|
|
43
|
-
"@moeru/eslint-config": "0.1.0-beta.
|
|
44
|
-
"@moeru/
|
|
45
|
-
"@
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"eslint
|
|
49
|
-
"oxlint": "^1.
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
46
|
+
"@antfu/eslint-config": "^6.7.3",
|
|
47
|
+
"@moeru/eslint-config": "^0.1.0-beta.15",
|
|
48
|
+
"@moeru/std": "^0.1.0-beta.15",
|
|
49
|
+
"@moeru/tsconfig": "^0.1.0-beta.15",
|
|
50
|
+
"@types/node": "^25.0.9",
|
|
51
|
+
"bumpp": "^10.4.0",
|
|
52
|
+
"eslint": "^9.39.2",
|
|
53
|
+
"eslint-plugin-oxlint": "^1.39.0",
|
|
54
|
+
"oxlint": "^1.39.0",
|
|
55
|
+
"publint": "^0.3.16",
|
|
56
|
+
"taze": "^19.9.2",
|
|
57
|
+
"tsdown": "^0.17.4",
|
|
53
58
|
"typescript": "^5.9.3",
|
|
54
59
|
"unplugin-unused": "^0.5.6",
|
|
55
|
-
"vite": "^7.
|
|
56
|
-
"vitest": "^4.0.
|
|
60
|
+
"vite": "^7.3.1",
|
|
61
|
+
"vitest": "^4.0.17"
|
|
57
62
|
},
|
|
58
63
|
"scripts": {
|
|
59
64
|
"build": "tsdown",
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["provide","indexProvide","invoke","resolve","indexResolve","start","indexStart","stop","indexStop","name","lifecycle: ProvidedKey<'lifecycle', Lifecycle, undefined>","name","resolvedDependsOn: Record<string, string>","resolvedDependencies: Record<string, any>","serviceLifecycle: any","context: BuildContext<typeof provider.dependsOn>","resolved: Record<string, any>","result: string[]","lifecycle","globalProvide","globalInvoke","globalResolve","globalStart","globalStop","globalSetLogger"],"sources":["../src/global.ts","../package.json","../src/logger.ts","../src/scoped.ts","../src/index.ts"],"sourcesContent":["import type { DependencyMap, InvokeOption, InvokeOptionWithKeys, Logger, ProvideOption, ProvideOptionWithKeys, ResolveDependencyDeclaration } from '.'\nimport type { ProvidedKey } from './scoped'\n\nimport { createContainer, provide as indexProvide, resolve as indexResolve, start as indexStart, stop as indexStop } from '.'\n\nlet globalContainer = createContainer()\n\nexport function setLogger(logger: Logger) {\n globalContainer.logger = logger\n}\n\nexport function resetContainer() {\n globalContainer = createContainer()\n}\n\nexport function provide<T, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(name: Key, option: ProvideOptionWithKeys<T, Deps>): ProvidedKey<Key, T, ResolveDependencyDeclaration<Deps>>\nexport function provide<D extends DependencyMap | undefined, T = any, Key extends string = string>(name: Key, option: ProvideOption<T, D>): ProvidedKey<Key, T, D>\nexport function provide<T, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(option: ProvideOptionWithKeys<T, Deps>): ProvidedKey<Key, T, ResolveDependencyDeclaration<Deps>>\nexport function provide<D extends DependencyMap | undefined, T = any, Key extends string = string>(option: ProvideOption<T, D>): ProvidedKey<Key, T, D>\nexport function provide<D extends DependencyMap | undefined, T = any, Key extends string = string>(nameOrOption: Key | ProvideOption<T, D> | ProvideOptionWithKeys<T, any>, option?: ProvideOption<T, D> | ProvideOptionWithKeys<T, any>): ProvidedKey<Key, T, D> {\n if (option != null && typeof option === 'function') {\n return indexProvide(globalContainer, nameOrOption as any, { build: option, autoNameStackIndex: 2 } as any)\n }\n\n return indexProvide(globalContainer, nameOrOption as any, { ...option, autoNameStackIndex: 2 } as any)\n}\n\nexport function invoke<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(option: InvokeOptionWithKeys<Deps>): void\nexport function invoke<D extends DependencyMap>(option: InvokeOption<D>): void\nexport function invoke<D extends DependencyMap>(option: InvokeOption<D> | InvokeOptionWithKeys<any>): void {\n if (typeof option === 'function') {\n globalContainer.invocations.push({ callback: option } as any)\n }\n else {\n globalContainer.invocations.push(option as any)\n }\n}\n\nexport function resolve<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(dependsOn: Deps): Promise<ResolveDependencyDeclaration<Deps>> {\n return indexResolve(globalContainer, dependsOn)\n}\n\nexport function start(): Promise<void> {\n return indexStart(globalContainer)\n}\n\nexport function stop(): Promise<void> {\n return indexStop(globalContainer)\n}\n","{\n \"name\": \"injeca\",\n \"type\": \"module\",\n \"version\": \"0.1.4\",\n \"packageManager\": \"pnpm@10.23.0\",\n \"description\": \"Pure functional programming based dependency injection library inspired by go.uber.org/fig and go.uber.org/dig.\",\n \"author\": {\n \"name\": \"Moeru AI Project AIRI Team\",\n \"email\": \"airi@moeru.ai\",\n \"url\": \"https://github.com/moeru-ai\"\n },\n \"license\": \"MIT\",\n \"homepage\": \"https://github.com/moeru-ai/injeca\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/moeru-ai/injeca.git\"\n },\n \"exports\": {\n \".\": {\n \"type\": \"./dist/index.d.mts\",\n \"default\": \"./dist/index.mjs\"\n }\n },\n \"main\": \"./dist/index.mjs\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.mts\",\n \"files\": [\n \"README.md\",\n \"dist\",\n \"package.json\"\n ],\n \"scripts\": {\n \"build\": \"tsdown\",\n \"test\": \"vitest --coverage\",\n \"test:run\": \"vitest run\",\n \"lint\": \"eslint --cache .\",\n \"lint:fix\": \"eslint --cache --fix .\",\n \"typecheck\": \"tsc --noEmit\",\n \"up\": \"taze -w -r -I -f && pnpm prune && pnpm dedupe\"\n },\n \"peerDependencies\": {\n \"@guiiai/logg\": \">= 1\",\n \"error-stack-parser\": \"^2.1.4\",\n \"nanoid\": \">=5\"\n },\n \"peerDependenciesMeta\": {\n \"@guiiai/logg\": {\n \"optional\": true\n }\n },\n \"devDependencies\": {\n \"@antfu/eslint-config\": \"^6.2.0\",\n \"@moeru/eslint-config\": \"0.1.0-beta.13\",\n \"@moeru/tsconfig\": \"0.1.0-beta.13\",\n \"@types/node\": \"^24.10.1\",\n \"bumpp\": \"^10.3.1\",\n \"eslint\": \"^9.39.1\",\n \"eslint-plugin-oxlint\": \"^1.29.0\",\n \"oxlint\": \"^1.29.0\",\n \"publint\": \"^0.3.15\",\n \"taze\": \"^19.9.0\",\n \"tsdown\": \"^0.16.6\",\n \"typescript\": \"^5.9.3\",\n \"unplugin-unused\": \"^0.5.6\",\n \"vite\": \"^7.2.4\",\n \"vitest\": \"^4.0.13\"\n }\n}\n","import type { Logg as LoggLogger } from '@guiiai/logg'\n\nimport { name } from '../package.json'\n\nexport interface Logger {\n provide: (name: string, dependencies: string[]) => void\n invoke: (dependencies: string[]) => void\n beforeRun: (name: string) => void\n run: (name: string, duration: number) => void\n hookOnStart: (name: string) => void\n hookOnStartComplete: (name: string, duration: number) => void\n hookOnStop: (name: string) => void\n hookOnStopComplete: (name: string, duration: number) => void\n running: () => void\n}\n\nexport interface LoggerOptions {\n enabled?: boolean\n logger?: Logger\n}\n\nfunction formatDuration(ms: number): string {\n if (ms < 1) {\n return `${(ms * 1000).toFixed(3)}µs`\n }\n if (ms < 1000) {\n return `${ms.toFixed(3)}ms`\n }\n return `${(ms / 1000).toFixed(3)}s`\n}\n\nexport function createDefaultLogger(): Logger {\n return {\n provide: (name: string, dependencies: string[]) => {\n const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(', ')})` : ''\n // eslint-disable-next-line no-console\n console.log(`[${name}] PROVIDE ${name}${depsStr}`)\n },\n\n invoke: (dependencies: string[]) => {\n const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(', ')})` : ''\n // eslint-disable-next-line no-console\n console.log(`[${name}] INVOKE${depsStr}`)\n },\n\n beforeRun: (name: string) => {\n // eslint-disable-next-line no-console\n console.log(`[${name}] BEFORE RUN provide: ${name}()`)\n },\n\n run: (name: string, duration: number) => {\n // eslint-disable-next-line no-console\n console.log(`[${name}] RUN provide: ${name}() in ${formatDuration(duration)}`)\n },\n\n hookOnStart: (name: string) => {\n // eslint-disable-next-line no-console\n console.log(`[${name}] HOOK OnStart ${name}() executing`)\n },\n\n hookOnStartComplete: (name: string, duration: number) => {\n // eslint-disable-next-line no-console\n console.log(`[${name}] HOOK OnStart ${name}() ran successfully in ${formatDuration(duration)}`)\n },\n\n hookOnStop: (name: string) => {\n // eslint-disable-next-line no-console\n console.log(`[${name}] HOOK OnStop ${name}() executing`)\n },\n\n hookOnStopComplete: (name: string, duration: number) => {\n // eslint-disable-next-line no-console\n console.log(`[${name}] HOOK OnStop ${name}() ran successfully in ${formatDuration(duration)}`)\n },\n\n running: () => {\n // eslint-disable-next-line no-console\n console.log(`[${name}] RUNNING`)\n },\n }\n}\n\nexport function createLoggLogger(logg: LoggLogger): Logger {\n return {\n provide: (name: string, dependencies: string[]) => {\n const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(', ')})` : ''\n logg.log(`PROVIDE ${name}${depsStr}`)\n },\n\n invoke: (dependencies: string[]) => {\n const depsStr = dependencies.length > 0 ? ` (depends on: ${dependencies.join(', ')})` : ''\n logg.log(`INVOKE${depsStr}`)\n },\n\n beforeRun: (name: string) => {\n logg.log(`BEFORE RUN provide: ${name}()`)\n },\n\n run: (name: string, duration: number) => {\n logg.log(`RUN provide: ${name}() in ${formatDuration(duration)}`)\n },\n\n hookOnStart: (name: string) => {\n logg.log(`HOOK OnStart ${name}() executing`)\n },\n\n hookOnStartComplete: (name: string, duration: number) => {\n logg.log(`HOOK OnStart ${name}() ran successfully in ${formatDuration(duration)}`)\n },\n\n hookOnStop: (name: string) => {\n logg.log(`HOOK OnStop ${name}() executing`)\n },\n\n hookOnStopComplete: (name: string, duration: number) => {\n logg.log(`HOOK OnStop ${name}() ran successfully in ${formatDuration(duration)}`)\n },\n\n running: () => {\n logg.log(`RUNNING`)\n },\n }\n}\n\nexport function createNoopLogger(): Logger {\n return {\n provide: () => {},\n invoke: () => {},\n beforeRun: () => {},\n run: () => {},\n hookOnStart: () => {},\n hookOnStartComplete: () => {},\n hookOnStop: () => {},\n hookOnStopComplete: () => {},\n running: () => {},\n }\n}\n","import type { Lifecycle, LifecycleTriggerable } from './builtin'\nimport type { Logger, LoggerOptions } from './logger'\n\nimport ErrorStackParser from 'error-stack-parser'\n\nimport { nanoid } from 'nanoid'\n\nimport { createDefaultLogger, createNoopLogger } from './logger'\n\nexport type DependencyMap = Record<string, any>\n\nexport interface Container {\n providers: Map<string, ProvideOptionObject<any, any>>\n instances: Map<string, any>\n lifecycleHooks: Map<string, LifecycleTriggerable>\n dependencyGraph: Map<string, string[]>\n invocations: InvokeOptionObject<any>[]\n logger: Logger\n}\n\nexport type BuildContext<D extends DependencyMap | undefined = undefined> = {\n container: Container\n name: string\n} & (D extends undefined ? { dependsOn?: unknown } : { dependsOn: D })\n\nexport type ResolveDependencyDeclaration<Deps extends Record<string, string | ProvidedKey<any, any, any>>> = {\n [K in keyof Deps]: Deps[K] extends ProvidedKey<any, infer T, any> ? T : any\n}\n\nexport type ProvideOptionObject<T, D extends DependencyMap | undefined = undefined> = { build: (context: BuildContext<D>) => T | Promise<T> } & (D extends undefined ? { dependsOn?: Record<string, never> } : { dependsOn: { [K in keyof D]: string } })\nexport type ProvideOptionFunc<T, D extends DependencyMap | undefined = undefined> = (context: BuildContext<D>) => T | Promise<T>\nexport type ProvideOption<T, D extends DependencyMap | undefined = undefined> = ProvideOptionObject<T, D> | ProvideOptionFunc<T, D>\n\nexport interface ProvideOptionObjectWithKeys<T, Deps extends Record<string, string | ProvidedKey<any, any, any>>> {\n build: (context: BuildContext<ResolveDependencyDeclaration<Deps>>) => T | Promise<T>\n dependsOn: Deps\n}\nexport type ProvideOptionWithKeys<T, Deps extends Record<string, string | ProvidedKey<any, any, any>>> = ProvideOptionObjectWithKeys<T, Deps>\n\nexport type InvokeOptionObject<D extends DependencyMap | undefined = undefined> = { callback: (dependencies: D) => void | Promise<void> } & (D extends undefined ? { dependsOn?: Record<string, never> } : { dependsOn: { [K in keyof D]: string } })\nexport type InvokeOptionFunc<D extends DependencyMap | undefined = undefined> = (dependencies: D) => void | Promise<void>\nexport type InvokeOption<D extends DependencyMap | undefined = undefined> = InvokeOptionObject<D> | InvokeOptionFunc<D>\n\nexport interface InvokeOptionObjectWithKeys<Deps extends Record<string, string | ProvidedKey<any, any, any>>> {\n callback: (dependencies: ResolveDependencyDeclaration<Deps>) => void | Promise<void>\n dependsOn: Deps\n}\nexport type InvokeOptionWithKeys<Deps extends Record<string, string | ProvidedKey<any, any, any>>> = InvokeOptionObjectWithKeys<Deps>\n\nexport const lifecycle: ProvidedKey<'lifecycle', Lifecycle, undefined> = { key: 'lifecycle' }\n\nexport function createContainer(options?: LoggerOptions): Container {\n const logger = options?.enabled === false\n ? createNoopLogger()\n : (options?.logger ?? createDefaultLogger())\n\n return {\n providers: new Map(),\n instances: new Map(),\n lifecycleHooks: new Map(),\n dependencyGraph: new Map(),\n invocations: [],\n logger,\n }\n}\n\nexport interface ProvidedKey<Key, _T, _D extends DependencyMap | undefined> {\n key: Key\n}\n\nexport function normalizeName(nameOrProvidedKey: string | ProvidedKey<any, any, any>): string {\n if (typeof nameOrProvidedKey === 'object' && nameOrProvidedKey !== null && 'key' in nameOrProvidedKey) {\n return (nameOrProvidedKey as ProvidedKey<any, any, any>).key as string\n }\n\n return nameOrProvidedKey as string\n}\n\nexport function normalizeProvideOption<D extends DependencyMap | undefined, T = any, Key extends string = string>(nameOrOption: Key | ProvidedKey<Key, T, D> | ProvideOption<T, D> | ProvideOptionWithKeys<T, any>, option?: (ProvideOption<T, D> | ProvideOptionWithKeys<T, any>) & { autoNameStackIndex?: number }): ProvideOptionObject<T, D> {\n if (typeof nameOrOption === 'string') {\n if (option == null || (!('build' in option) && typeof option !== 'function')) {\n throw new Error('When using provide(...) as named callback, the second argument must be either a valid ProvideOptionObject<T, D> or a ProvideOptionFunc<T, D>.')\n }\n if (typeof option === 'function') {\n return { build: option } as ProvideOptionObject<T, D>\n }\n\n return option as ProvideOptionObject<T, D>\n }\n if (typeof nameOrOption === 'object' && 'key' in nameOrOption) {\n if (option == null || (!('build' in option) && typeof option !== 'function')) {\n throw new Error('When using provide(...) as typed ProvideOptionWithKeys<T, D, Key> callback, the second argument must be either a valid ProvideOptionObject<T, D> or a ProvideOptionFunc<T, D>.')\n }\n if (typeof option === 'function') {\n return { build: option } as ProvideOptionObject<T, D>\n }\n\n return option as ProvideOptionObject<T, D>\n }\n\n if (typeof nameOrOption === 'function') {\n return { build: nameOrOption } as ProvideOptionObject<T, D>\n }\n\n return nameOrOption as ProvideOptionObject<T, D>\n}\n\nexport function provide<T, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, name: Key, option: ProvideOptionWithKeys<T, Deps>): ProvidedKey<Key, T, ResolveDependencyDeclaration<Deps>>\nexport function provide<T, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, option: ProvideOptionWithKeys<T, Deps> & { autoNameStackIndex?: number }): ProvidedKey<Key, T, ResolveDependencyDeclaration<Deps>>\nexport function provide<D extends DependencyMap | undefined, T = any, Key extends string = string>(container: Container, name: Key, option: ProvideOption<T, D>): ProvidedKey<Key, T, D>\nexport function provide<D extends DependencyMap | undefined, T = any, Key extends string = string>(container: Container, option: ProvideOption<T, D> & { autoNameStackIndex?: number }): ProvidedKey<Key, T, D>\nexport function provide<D extends DependencyMap | undefined, T = any, Key extends string = string>(container: Container, nameOrOption: Key | ProvideOption<T, D> | ProvideOptionWithKeys<T, any>, option?: (ProvideOption<T, D> | ProvideOptionWithKeys<T, any>) & { autoNameStackIndex?: number }): ProvidedKey<Key, T, D> {\n const parentFile = ErrorStackParser.parse(new Error('providing'))[option?.autoNameStackIndex ?? 1]\n const name = typeof nameOrOption === 'string'\n ? nameOrOption\n : `${parentFile.fileName ?? `unknown-${nanoid()}`}:${parentFile.lineNumber ?? 0}:${parentFile.columnNumber ?? 0}`\n\n const providerObject = normalizeProvideOption<D, T, Key>(nameOrOption, option) as unknown as ProvideOptionObject<any, any>\n if (providerObject.dependsOn) {\n const resolvedDependsOn: Record<string, string> = {}\n for (const [key, value] of Object.entries(providerObject.dependsOn)) {\n resolvedDependsOn[key] = normalizeName(value)\n }\n\n providerObject.dependsOn = resolvedDependsOn\n }\n\n container.providers.set(name, providerObject)\n\n const dependencies = providerObject.dependsOn ? Object.values(providerObject.dependsOn) : []\n container.logger.provide(name, dependencies)\n container.dependencyGraph.set(name, dependencies)\n\n return { key: name } as ProvidedKey<Key, T, D>\n}\n\nexport function invoke<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, option: InvokeOptionWithKeys<Deps>): void\nexport function invoke<D extends DependencyMap>(container: Container, option: InvokeOption<D>): void\nexport function invoke<D extends DependencyMap>(container: Container, option: InvokeOption<D> | InvokeOptionWithKeys<any>): void {\n const invocationObject = typeof option === 'function'\n ? { callback: option } as InvokeOptionObject<any>\n : option as InvokeOptionObject<any>\n\n if (invocationObject.dependsOn) {\n const resolvedDependsOn: Record<string, string> = {}\n for (const [key, value] of Object.entries(invocationObject.dependsOn)) {\n resolvedDependsOn[key] = normalizeName(value)\n }\n\n invocationObject.dependsOn = resolvedDependsOn\n }\n\n const dependencies = invocationObject.dependsOn ? Object.values(invocationObject.dependsOn) : []\n\n container.logger.invoke(dependencies)\n container.invocations.push(invocationObject)\n}\n\nasync function resolveInstance<T>(container: Container, name: string): Promise<T> {\n if (container.instances.has(name)) {\n return container.instances.get(name) as T\n }\n\n const provider = container.providers.get(name)\n if (!provider) {\n throw new Error(`No provider found for '${name}'`)\n }\n\n const resolvedDependencies: Record<string, any> = {}\n let serviceLifecycle: any = null\n\n if (provider.dependsOn) {\n for (const [key, depName] of Object.entries(provider.dependsOn)) {\n if (depName === 'lifecycle') {\n // Create individual lifecycle instance for this service\n const { buildLifecycle } = await import('./builtin')\n serviceLifecycle = buildLifecycle()\n resolvedDependencies[key] = serviceLifecycle\n\n // Track this service's lifecycle\n container.lifecycleHooks.set(name, serviceLifecycle)\n }\n else {\n resolvedDependencies[key] = await resolveInstance(container, depName)\n }\n }\n }\n\n const context: BuildContext<typeof provider.dependsOn> = {\n container,\n dependsOn: resolvedDependencies,\n name,\n }\n\n container.logger.beforeRun(name)\n\n const startTime = performance.now()\n const instance = await provider.build(context)\n const duration = performance.now() - startTime\n\n container.logger.run(name, duration)\n\n container.instances.set(name, instance)\n\n return instance as T\n}\n\nexport async function resolve<Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, dependsOn: Deps): Promise<ResolveDependencyDeclaration<Deps>> {\n const resolved: Record<string, any> = {}\n\n for (const [key, depName] of Object.entries(dependsOn)) {\n const normalizedName = normalizeName(depName)\n\n resolved[key] = await resolveInstance(container, normalizedName)\n }\n\n return resolved as ResolveDependencyDeclaration<Deps>\n}\n\nfunction topologicalSort(dependencyGraph: Map<string, string[]>): string[] {\n const visited = new Set<string>()\n const visiting = new Set<string>()\n const result: string[] = []\n\n function visit(node: string) {\n if (visiting.has(node)) {\n throw new Error(`Circular dependency detected involving '${node}'`)\n }\n if (visited.has(node)) {\n return\n }\n\n visiting.add(node)\n const dependencies = dependencyGraph.get(node) || []\n for (const dep of dependencies) {\n visit(dep)\n }\n visiting.delete(node)\n visited.add(node)\n result.push(node)\n }\n\n for (const node of dependencyGraph.keys()) {\n if (!visited.has(node)) {\n visit(node)\n }\n }\n\n return result\n}\n\nexport async function startLifecycleHooks(container: Container): Promise<void> {\n const sortedServices = topologicalSort(container.dependencyGraph)\n\n for (const serviceName of sortedServices) {\n const lifecycle = container.lifecycleHooks.get(serviceName)\n if (lifecycle?.emitOnStart) {\n container.logger.hookOnStart(serviceName)\n\n const startTime = performance.now()\n await lifecycle.emitOnStart()\n const duration = performance.now() - startTime\n\n container.logger.hookOnStartComplete(serviceName, duration)\n }\n }\n}\n\nexport async function stopLifecycleHooks(container: Container): Promise<void> {\n const sortedServices = topologicalSort(container.dependencyGraph)\n\n // Shutdown in reverse order\n for (const serviceName of sortedServices.reverse()) {\n const lifecycle = container.lifecycleHooks.get(serviceName)\n if (lifecycle?.emitOnStop) {\n container.logger.hookOnStop(serviceName)\n\n const startTime = performance.now()\n await lifecycle.emitOnStop()\n const duration = performance.now() - startTime\n\n container.logger.hookOnStopComplete(serviceName, duration)\n }\n }\n}\n\nexport async function start(container: Container): Promise<void> {\n await startLifecycleHooks(container)\n\n for (const invocation of container.invocations) {\n const resolvedDependencies: Record<string, any> = {}\n\n if (invocation.dependsOn) {\n for (const [key, depName] of Object.entries(invocation.dependsOn)) {\n resolvedDependencies[key] = await resolveInstance(container, normalizeName(depName))\n }\n }\n\n await invocation.callback(resolvedDependencies)\n }\n\n container.logger.running()\n}\n\nexport async function stop(container: Container): Promise<void> {\n await stopLifecycleHooks(container)\n}\n","import {\n invoke as globalInvoke,\n provide as globalProvide,\n resolve as globalResolve,\n setLogger as globalSetLogger,\n start as globalStart,\n stop as globalStop,\n} from './global'\n\nexport type { Lifecycle } from './builtin'\n\nexport type { Logger, LoggerOptions } from './logger'\n\nexport {\n createDefaultLogger,\n createLoggLogger,\n createNoopLogger,\n} from './logger'\n\nexport {\n createContainer,\n invoke,\n lifecycle,\n provide,\n resolve,\n start,\n stop,\n} from './scoped'\nexport type {\n BuildContext,\n Container,\n DependencyMap,\n InvokeOption,\n InvokeOptionFunc,\n InvokeOptionObject,\n InvokeOptionObjectWithKeys,\n InvokeOptionWithKeys,\n ProvidedKey,\n ProvideOption,\n ProvideOptionFunc,\n ProvideOptionObject,\n ProvideOptionObjectWithKeys,\n ProvideOptionWithKeys,\n ResolveDependencyDeclaration,\n} from './scoped'\n\nexport const injeca = {\n provide: globalProvide,\n invoke: globalInvoke,\n resolve: globalResolve,\n start: globalStart,\n stop: globalStop,\n setLogger: globalSetLogger,\n}\n"],"mappings":";;;;AAKA,IAAI,kBAAkB,iBAAiB;AAEvC,SAAgB,UAAU,QAAgB;AACxC,iBAAgB,SAAS;;AAW3B,SAAgBA,UAAmF,cAAyE,QAAsF;AAChQ,KAAI,UAAU,QAAQ,OAAO,WAAW,WACtC,QAAOC,QAAa,iBAAiB,cAAqB;EAAE,OAAO;EAAQ,oBAAoB;EAAG,CAAQ;AAG5G,QAAOA,QAAa,iBAAiB,cAAqB;EAAE,GAAG;EAAQ,oBAAoB;EAAG,CAAQ;;AAKxG,SAAgBC,SAAgC,QAA2D;AACzG,KAAI,OAAO,WAAW,WACpB,iBAAgB,YAAY,KAAK,EAAE,UAAU,QAAQ,CAAQ;KAG7D,iBAAgB,YAAY,KAAK,OAAc;;AAInD,SAAgBC,UAA0E,WAA8D;AACtJ,QAAOC,QAAa,iBAAiB,UAAU;;AAGjD,SAAgBC,UAAuB;AACrC,QAAOC,MAAW,gBAAgB;;AAGpC,SAAgBC,SAAsB;AACpC,QAAOC,KAAU,gBAAgB;;;;;WC9CzB;;;;ACoBV,SAAS,eAAe,IAAoB;AAC1C,KAAI,KAAK,EACP,QAAO,IAAI,KAAK,KAA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