import type { GGLocatorKey } from "./GGLocatorKey"; import { GGLocatorScopeDebug, GGLocatorScopeDebugList } from "./GGLocatorScopeDebug"; import { type Values } from "@grest-ts/common"; type ConstructorOf = new (...args: any[]) => T; /** * service-locator pattern for async context cases. */ export declare class GGLocatorScope { readonly name: string; readonly serviceName: string; private readonly parent; private readonly values; private readonly registrationStacks; private readonly creationStack; constructor(name: string, parent?: GGLocatorScope, serviceName?: string); private _get; get(token: GGLocatorKey): T; tryGet(token: GGLocatorKey): T | undefined; getByTokenName(name: string, type: ConstructorOf): T; set(token: GGLocatorKey, value: T): void; overwrite(token: GGLocatorKey, value: T): void; has(token: GGLocatorKey): boolean; /** * Returns all registered key names in this scope. * Used by testkit to report available services to test runner. */ getKeys(): string[]; private _lifecycleHandler?; setLifecycleOwner(handler: ((service: GGLocatorLifecycleCallbacks) => void) | undefined): void; setWithLifecycle(token: GGLocatorKey, value: T, lifecycle: GGLocatorLifecycleCallbacks): void; setImmediate(fn: () => R): NodeJS.Immediate; setTimeout(fn: () => R, timeout: number): NodeJS.Timeout; setInterval(fn: () => R, timeout: number): NodeJS.Timeout; /** * Wraps a function with a async context run() call. Safe for most cases. * Consider wrapWithEnter in case you want same context for that function forever. */ wrapWithRun any>(fn: T): T; /** * Wraps function to ensure this scope is active before each call. * Unlike wrapWithRun, doesn't create a new async boundary - just ensures scope is entered. * More performant for high-frequency event handlers where scope doesn't change. */ wrapWithEnter any>(fn: T): T; getScopeDebug(): GGLocatorScopeDebug; getScopeDebugFull(list?: GGLocatorScopeDebugList): GGLocatorScopeDebugList; branch(name: string, serviceName?: string): GGLocatorScope; run(fn: () => R): R; enter(): this; ensureEntered(): void; reset(): void; } /** * Service initialization order - determines the sequence in which services start and stop. * Services with lower values start first and stop last (reverse order for teardown). * * Example startup order: CONFIG → DATABASE → HTTP → INTL → BUSINESS → PERIODIC_JOBS → SERVICE_DISCOVERY */ export declare const GGLocatorServiceType: Readonly<{ readonly CONFIG: 0; readonly DATABASE: 10; readonly HTTP: 20; readonly INTL: 25; readonly BUSINESS: 30; readonly PERIODIC_JOBS: 40; readonly SERVICE_DISCOVERY: 999; }>; export type GGLocatorServiceType = Values; /** * Service lifecycle callbacks registered with GGServiceRegistry. * * Services register these during construction (in GGRuntime.compose) to participate * in the runtime lifecycle - startup, teardown, and per-request context hooks. */ export interface GGLocatorLifecycleCallbacks { type: GGLocatorServiceType | (number & {}); start: () => any | Promise; teardown?: () => any | Promise; } export {}; //# sourceMappingURL=GGLocatorScope.d.ts.map