+4
-5
@@ -169,9 +169,8 @@ declare class AlsToken<T = any> { | ||
| declare class AsyncLocalStorage<T> { | ||
| private store; | ||
| type AsyncLocalStorageInstance<T> = { | ||
| getStore(): T | undefined; | ||
| run<R>(store: T, callback: () => R): R; | ||
| getStore(): T | undefined; | ||
| } | ||
| }; | ||
| declare class AlsStore<T extends Record<string, any> = any> { | ||
| protected readonly als: AsyncLocalStorage<Map<string, any>>; | ||
| protected readonly als: AsyncLocalStorageInstance<Map<string, any>>; | ||
| run<R>(data: Partial<T>, fn: () => R): R; | ||
@@ -178,0 +177,0 @@ get<K extends keyof T>(key: K): T[K] | undefined; |
+9
-18
@@ -1550,20 +1550,11 @@ var __defProp = Object.defineProperty; | ||
| // src/container/AlsStore.ts | ||
| var AsyncLocalStorage = class { | ||
| static { | ||
| __name(this, "AsyncLocalStorage"); | ||
| var resolveAsyncLocalStorage = /* @__PURE__ */ __name(() => { | ||
| const runtimeProcess = process; | ||
| const AsyncLocalStorage = runtimeProcess.getBuiltinModule?.("node:async_hooks")?.AsyncLocalStorage ?? runtimeProcess.getBuiltinModule?.("async_hooks")?.AsyncLocalStorage; | ||
| if (!AsyncLocalStorage) { | ||
| throw new Error("AsyncLocalStorage is not available in this runtime."); | ||
| } | ||
| store; | ||
| run(store, callback) { | ||
| const previous = this.store; | ||
| this.store = store; | ||
| try { | ||
| return callback(); | ||
| } finally { | ||
| this.store = previous; | ||
| } | ||
| } | ||
| getStore() { | ||
| return this.store; | ||
| } | ||
| }; | ||
| return AsyncLocalStorage; | ||
| }, "resolveAsyncLocalStorage"); | ||
| var AsyncLocalStorageImpl = resolveAsyncLocalStorage(); | ||
| var AlsStore = class { | ||
@@ -1573,3 +1564,3 @@ static { | ||
| } | ||
| als = new AsyncLocalStorage(); | ||
| als = new AsyncLocalStorageImpl(); | ||
| run(data, fn) { | ||
@@ -1576,0 +1567,0 @@ const currentStore = this.als.getStore(); |
+1
-1
| { | ||
| "name": "diject", | ||
| "version": "0.1.1", | ||
| "version": "0.1.2", | ||
| "description": "Lightweight TypeScript DI container with decorators, scopes, metadata queries, and AsyncLocalStorage support.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
109523
0.16%2932
-0.34%