injeca 0.1.5 → 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
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
|
|
@@ -51,7 +51,7 @@ type BuildContext<D extends DependencyMap | undefined = undefined> = {
|
|
|
51
51
|
} : {
|
|
52
52
|
dependsOn: D;
|
|
53
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 };
|
|
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
55
|
type ProvideOptionObject<T, D extends DependencyMap | undefined = undefined> = {
|
|
56
56
|
build: (context: BuildContext<D>) => T | Promise<T>;
|
|
57
57
|
} & (D extends undefined ? {
|
|
@@ -85,6 +85,10 @@ declare function createContainer(options?: LoggerOptions): Container;
|
|
|
85
85
|
interface ProvidedKey<Key, _T, _D extends DependencyMap | undefined> {
|
|
86
86
|
key: Key;
|
|
87
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;
|
|
88
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>>;
|
|
89
93
|
declare function provide$1<T, Key extends string, Deps extends Record<string, string | ProvidedKey<any, any, any>>>(container: Container, option: ProvideOptionWithKeys<T, Deps> & {
|
|
90
94
|
autoNameStackIndex?: number;
|
|
@@ -122,5 +126,5 @@ declare function resolve<Deps extends Record<string, string | ProvidedKey<any, a
|
|
|
122
126
|
declare function start(): Promise<void>;
|
|
123
127
|
declare function stop(): Promise<void>;
|
|
124
128
|
//#endregion
|
|
125
|
-
export {
|
|
126
|
-
//# sourceMappingURL=global-
|
|
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.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as setLogger, i as resolve, n as provide, o as start, r as resetContainer, s as stop, t as invoke } from "./global-
|
|
1
|
+
import { a as setLogger, i as resolve, n as provide, o as start, r as resetContainer, s as stop, t as invoke } from "./global-BLY6_SI_.mjs";
|
|
2
2
|
export { invoke, provide, resetContainer, resolve, setLogger, start, stop };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export { BuildContext, Container, DependencyMap, 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 };
|
|
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 };
|
|
@@ -1 +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.5\",\n \"packageManager\": \"pnpm@10.25.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.1\",\n \"@moeru/eslint-config\": \"^0.1.0-beta.13\",\n \"@moeru/std\": \"^0.1.0-beta.13\",\n \"@moeru/tsconfig\": \"^0.1.0-beta.13\",\n \"@types/node\": \"^25.0.2\",\n \"bumpp\": \"^10.3.2\",\n \"eslint\": \"^9.39.2\",\n \"eslint-plugin-oxlint\": \"^1.32.0\",\n \"oxlint\": \"^1.32.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.2.7\",\n \"vitest\": \"^4.0.15\"\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 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 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;;AAG3B,SAAgB,iBAAiB;AAC/B,mBAAkB,iBAAiB;;AAOrC,SAAgB,QAAmF,cAAyE,QAAsF;AAChQ,KAAI,UAAU,QAAQ,OAAO,WAAW,WACtC,QAAOA,UAAa,iBAAiB,cAAqB;EAAE,OAAO;EAAQ,oBAAoB;EAAG,CAAQ;AAG5G,QAAOA,UAAa,iBAAiB,cAAqB;EAAE,GAAG;EAAQ,oBAAoB;EAAG,CAAQ;;AAKxG,SAAgB,OA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edKey<'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,UAAU,QAAQ,OAAO,WAAW,WACtC,QAAOA,UAAa,iBAAiB,cAAqB;EAAE,OAAO;EAAQ,oBAAoB;EAAG,CAAQ;AAG5G,QAAOA,UAAa,iBAAiB,cAAqB;EAAE,GAAG;EAAQ,oBAAoB;EAAG,CAAQ;;AAKxG,SAAgB,OAAgC,QAA2D;AACzG,KAAI,OAAO,WAAW,WACpB,iBAAgB,YAAY,KAAK,EAAE,UAAU,QAAQ,CAAQ;KAG7D,iBAAgB,YAAY,KAAK,OAAc;;AAInD,SAAgB,QAA0E,WAA8D;AACtJ,QAAOC,UAAa,iBAAiB,UAAU;;AAGjD,SAAgB,QAAuB;AACrC,QAAOC,QAAW,gBAAgB;;AAGpC,SAAgB,OAAsB;AACpC,QAAOC,OAAU,gBAAgB;;;;;WC9CzB;;;;ACoBV,SAAS,eAAe,IAAo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Aa,SAAS;;;;AAKjE,eAAsB,mBAAmB,WAAqC;CAC5E,MAAM,iBAAiB,gBAAgB,UAAU,gBAAgB;AAGjE,MAAK,MAAM,eAAe,eAAe,SAAS,EAAE;EAClD,MAAMA,cAAY,UAAU,eAAe,IAAI,YAAY;AAC3D,MAAIA,aAAW,YAAY;AACzB,aAAU,OAAO,WAAW,YAAY;GAExC,MAAM,YAAY,YAAY,KAAK;AACnC,SAAMA,YAAU,YAAY;GAC5B,MAAM,WAAW,YAAY,KAAK,GAAG;AAErC,aAAU,OAAO,mBAAmB,aAAa,SAAS;;;;AAKhE,eAAsBC,QAAM,WAAqC;AAC/D,OAAM,oBAAoB,UAAU;AAEpC,MAAK,MAAM,cAAc,UAAU,aAAa;EAC9C,MAAMP,uBAA4C,EAAE;AAEpD,MAAI,WAAW,UACb,MAAK,MAAM,CAAC,KAAK,YAAY,OAAO,QAAQ,WAAW,UAAU,CAC/D,sBAAqB,OAAO,MAAM,gBAAgB,WAAW,cAAc,QAAQ,CAAC;AAIxF,QAAM,WAAW,SAAS,qBAAqB;;AAGjD,WAAU,OAAO,SAAS;;AAG5B,eAAsBQ,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",
|
|
@@ -43,22 +43,22 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@antfu/eslint-config": "^6.7.
|
|
47
|
-
"@moeru/eslint-config": "^0.1.0-beta.
|
|
48
|
-
"@moeru/std": "^0.1.0-beta.
|
|
49
|
-
"@moeru/tsconfig": "^0.1.0-beta.
|
|
50
|
-
"@types/node": "^25.0.
|
|
51
|
-
"bumpp": "^10.
|
|
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
52
|
"eslint": "^9.39.2",
|
|
53
|
-
"eslint-plugin-oxlint": "^1.
|
|
54
|
-
"oxlint": "^1.
|
|
53
|
+
"eslint-plugin-oxlint": "^1.39.0",
|
|
54
|
+
"oxlint": "^1.39.0",
|
|
55
55
|
"publint": "^0.3.16",
|
|
56
56
|
"taze": "^19.9.2",
|
|
57
57
|
"tsdown": "^0.17.4",
|
|
58
58
|
"typescript": "^5.9.3",
|
|
59
59
|
"unplugin-unused": "^0.5.6",
|
|
60
|
-
"vite": "^7.
|
|
61
|
-
"vitest": "^4.0.
|
|
60
|
+
"vite": "^7.3.1",
|
|
61
|
+
"vitest": "^4.0.17"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "tsdown",
|