@pumped-fn/lite 2.1.0 → 2.1.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["atomSymbol: unique symbol","flowSymbol: unique symbol","tagSymbol: unique symbol","taggedSymbol: unique symbol","controllerDepSymbol: unique symbol","presetSymbol: unique symbol","controllerSymbol: unique symbol","tagExecutorSymbol: unique symbol","typedSymbol: unique symbol","resourceSymbol: unique symbol","phase: \"tag\" | \"flow-input\"","label: string","cause: unknown","tagRegistry: WeakRef<Lite.Tag<unknown, boolean>>[]","live: Lite.Tag<unknown, boolean>[]","liveRefs: WeakRef<Lite.Tag<unknown, boolean>>[]","tag","tags","atom","live: Lite.Atom<unknown>[]","liveRefs: WeakRef<Lite.Atom<unknown>>[]","tagInstance: Lite.Tag<T, boolean>","result: T[]","atomInstance: Lite.Atom<T>","resource","parentData?: Lite.ContextData","tag","ctrl: Lite.Controller<T>","selector: (value: T) => S","eq: (prev: S, next: S) => boolean","atom: Lite.Atom<T>","scope: ScopeImpl","atom","ctx: Lite.ResolveContext","event: Lite.ResolveEvent","result: Record<string, unknown>","results: T[]","current: Lite.ExecutionContext | undefined","flow","parsedInput: unknown"],"sources":["../src/symbols.ts","../src/errors.ts","../src/tag.ts","../src/atom.ts","../src/flow.ts","../src/preset.ts","../src/resource.ts","../src/service.ts","../src/scope.ts","../src/index.ts"],"sourcesContent":["export const atomSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/atom\")\nexport const flowSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/flow\")\nexport const tagSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/tag\")\nexport const taggedSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/tagged\")\nexport const controllerDepSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/controller-dep\")\nexport const presetSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/preset\")\nexport const controllerSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/controller\")\nexport const tagExecutorSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/tag-executor\")\nexport const typedSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/typed\")\nexport const resourceSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/resource\")\n","export class ParseError extends Error {\n override readonly name = \"ParseError\"\n\n constructor(\n message: string,\n readonly phase: \"tag\" | \"flow-input\",\n readonly label: string,\n override readonly cause: unknown\n ) {\n super(message)\n }\n}\n","import { tagSymbol, taggedSymbol, tagExecutorSymbol } from \"./symbols\"\nimport { ParseError } from \"./errors\"\nimport type { Lite } from \"./types\"\n\nexport interface TagOptions<T, HasDefault extends boolean> {\n label: string\n default?: HasDefault extends true ? T : never\n parse?: (raw: unknown) => T\n}\n\nconst registry = new WeakMap<Lite.Tag<unknown, boolean>, WeakRef<Lite.Atom<unknown>>[]>()\nconst tagRegistry: WeakRef<Lite.Tag<unknown, boolean>>[] = []\n\n/**\n * Returns all tags that have been created.\n *\n * Uses WeakRef internally so tags can be garbage collected when no longer referenced.\n * Stale references are cleaned up lazily on each call (not between calls).\n *\n * @returns Array of all live Tag instances. Returns `Tag<unknown, boolean>[]` because\n * the registry cannot preserve individual tag type parameters at runtime.\n *\n * Performance: O(n) where n = total tags created. For typical usage (< 100 tags),\n * this is negligible. Cleanup happens during query, not continuously.\n *\n * @example\n * ```typescript\n * const allTags = getAllTags()\n * for (const t of allTags) {\n * console.log(t.label, t.atoms().length)\n * }\n * ```\n */\nexport function getAllTags(): Lite.Tag<unknown, boolean>[] {\n const live: Lite.Tag<unknown, boolean>[] = []\n const liveRefs: WeakRef<Lite.Tag<unknown, boolean>>[] = []\n\n for (const ref of tagRegistry) {\n const tag = ref.deref()\n if (tag) {\n live.push(tag)\n liveRefs.push(ref)\n }\n }\n\n tagRegistry.length = 0\n tagRegistry.push(...liveRefs)\n\n return live\n}\n\nexport function registerAtomToTags(\n atom: Lite.Atom<unknown>,\n tags: Lite.Tagged<any>[]\n): void {\n for (const tagged of tags) {\n let refs = registry.get(tagged.tag)\n if (!refs) {\n refs = []\n registry.set(tagged.tag, refs)\n }\n refs.push(new WeakRef(atom))\n }\n}\n\nfunction getAtomsForTag(tag: Lite.Tag<unknown, boolean>): Lite.Atom<unknown>[] {\n const refs = registry.get(tag)\n if (!refs) return []\n\n const live: Lite.Atom<unknown>[] = []\n const liveRefs: WeakRef<Lite.Atom<unknown>>[] = []\n\n for (const ref of refs) {\n const atom = ref.deref()\n if (atom) {\n live.push(atom)\n liveRefs.push(ref)\n }\n }\n\n if (liveRefs.length > 0) {\n registry.set(tag, liveRefs)\n } else {\n registry.delete(tag)\n }\n\n return live\n}\n\n/**\n * Creates a metadata tag for attaching and retrieving typed values from Atoms and Flows.\n *\n * @param options - Configuration object with label and optional default value\n * @returns A Tag instance that can create tagged values and query them from sources\n *\n * @example\n * ```typescript\n * const nameTag = tag<string>({ label: \"name\" })\n * const myAtom = atom({\n * factory: (ctx) => \"value\",\n * tags: [nameTag(\"MyAtom\")]\n * })\n * ```\n */\nexport function tag<T>(options: { label: string }): Lite.Tag<T, false>\nexport function tag<T>(options: {\n label: string\n default: T\n}): Lite.Tag<T, true>\nexport function tag<T>(options: {\n label: string\n parse: (raw: unknown) => T\n}): Lite.Tag<T, false>\nexport function tag<T>(options: {\n label: string\n parse: (raw: unknown) => T\n default: T\n}): Lite.Tag<T, true>\nexport function tag<T>(options: TagOptions<T, boolean>): Lite.Tag<T, boolean> {\n const key = Symbol.for(`@pumped-fn/lite/tag/${options.label}`)\n const hasDefault = \"default\" in options\n const defaultValue = hasDefault ? options.default : undefined\n const parse = options.parse\n\n let tagInstance: Lite.Tag<T, boolean>\n\n function createTagged(value: T): Lite.Tagged<T> {\n let validatedValue = value\n if (parse) {\n try {\n validatedValue = parse(value)\n } catch (err) {\n throw new ParseError(\n `Failed to parse tag \"${options.label}\"`,\n \"tag\",\n options.label,\n err\n )\n }\n }\n return {\n [taggedSymbol]: true,\n key,\n value: validatedValue,\n tag: tagInstance,\n }\n }\n\n function get(source: Lite.TagSource): T {\n const tags = Array.isArray(source) ? source : source.tags ?? []\n for (let i = 0; i < tags.length; i++) {\n if (tags[i]!.key === key) return tags[i]!.value as unknown as T\n }\n if (hasDefault) return defaultValue as unknown as T\n throw new Error(`Tag \"${options.label}\" not found and has no default`)\n }\n\n function find(source: Lite.TagSource): T | undefined {\n const tags = Array.isArray(source) ? source : source.tags ?? []\n for (let i = 0; i < tags.length; i++) {\n if (tags[i]!.key === key) return tags[i]!.value as unknown as T\n }\n if (hasDefault) return defaultValue as unknown as T\n return undefined\n }\n\n function collect(source: Lite.TagSource): T[] {\n const tags = Array.isArray(source) ? source : source.tags ?? []\n const result: T[] = []\n for (let i = 0; i < tags.length; i++) {\n if (tags[i]!.key === key) result.push(tags[i]!.value as unknown as T)\n }\n return result\n }\n\n /**\n * Returns all atoms that have been created with this tag.\n *\n * Uses WeakRef internally so atoms can be garbage collected when no longer referenced.\n * Stale references are cleaned up lazily on each call.\n *\n * @returns Array of atoms using this tag. Returns `Atom<unknown>[]` because multiple\n * atom types with different return types can use the same tag - TypeScript cannot\n * track this runtime relationship.\n *\n * Performance: O(n) where n = atoms using this tag. Cleanup happens during query.\n */\n function atoms(): Lite.Atom<unknown>[] {\n return getAtomsForTag(tagInstance as Lite.Tag<unknown, boolean>)\n }\n\n tagInstance = Object.assign(createTagged, {\n [tagSymbol]: true as const,\n key,\n label: options.label,\n hasDefault,\n defaultValue,\n parse,\n get,\n find,\n collect,\n atoms,\n }) as unknown as Lite.Tag<T, boolean>\n\n tagRegistry.push(new WeakRef(tagInstance as Lite.Tag<unknown, boolean>))\n\n return tagInstance\n}\n\n/**\n * Type guard to check if a value is a Tag.\n *\n * @param value - The value to check\n * @returns True if the value is a Tag, false otherwise\n *\n * @example\n * ```typescript\n * if (isTag(value)) {\n * const tagged = value(\"myValue\")\n * }\n * ```\n */\nexport function isTag(value: unknown): value is Lite.Tag<unknown, boolean> {\n return (\n typeof value === \"function\" &&\n (value as unknown as Record<symbol, unknown>)[tagSymbol] === true\n )\n}\n\n/**\n * Type guard to check if a value is a Tagged value.\n *\n * @param value - The value to check\n * @returns True if the value is a Tagged value, false otherwise\n *\n * @example\n * ```typescript\n * if (isTagged(value)) {\n * console.log(value.key, value.value)\n * }\n * ```\n */\nexport function isTagged(value: unknown): value is Lite.Tagged<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<symbol, unknown>)[taggedSymbol] === true\n )\n}\n\n/**\n * Tag execution helpers for declaring how tags should be resolved from dependency sources.\n */\nexport const tags = {\n /**\n * Creates a required tag executor that throws if the tag is not found.\n *\n * @param tag - The tag to execute\n * @returns A tag executor that requires the tag to be present\n *\n * @example\n * ```typescript\n * const myAtom = atom({\n * deps: { name: tags.required(nameTag) },\n * factory: (ctx, { name }) => `Hello ${name}`\n * })\n * ```\n */\n required<T>(tag: Lite.Tag<T, boolean>): Lite.TagExecutor<T, T> {\n return { [tagExecutorSymbol]: true, tag, mode: \"required\" }\n },\n\n /**\n * Creates an optional tag executor that returns undefined if the tag is not found.\n *\n * @param tag - The tag to execute\n * @returns A tag executor that allows the tag to be absent\n *\n * @example\n * ```typescript\n * const myAtom = atom({\n * deps: { name: tags.optional(nameTag) },\n * factory: (ctx, { name }) => name ?? \"Anonymous\"\n * })\n * ```\n */\n optional<T>(tag: Lite.Tag<T, boolean>): Lite.TagExecutor<T | undefined, T> {\n return { [tagExecutorSymbol]: true, tag, mode: \"optional\" }\n },\n\n /**\n * Creates a tag executor that collects all values for the given tag.\n *\n * @param tag - The tag to execute\n * @returns A tag executor that returns an array of all matching tag values\n *\n * @example\n * ```typescript\n * const myAtom = atom({\n * deps: { names: tags.all(nameTag) },\n * factory: (ctx, { names }) => names.join(\", \")\n * })\n * ```\n */\n all<T>(tag: Lite.Tag<T, boolean>): Lite.TagExecutor<T[], T> {\n return { [tagExecutorSymbol]: true, tag, mode: \"all\" }\n },\n}\n\n/**\n * Type guard to check if a value is a TagExecutor.\n *\n * @param value - The value to check\n * @returns True if the value is a TagExecutor, false otherwise\n *\n * @example\n * ```typescript\n * if (isTagExecutor(value)) {\n * console.log(value.mode, value.tag)\n * }\n * ```\n */\nexport function isTagExecutor(value: unknown): value is Lite.TagExecutor<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n tagExecutorSymbol in value\n )\n}\n","import { atomSymbol, controllerDepSymbol } from \"./symbols\"\nimport { registerAtomToTags } from \"./tag\"\nimport type { Lite, MaybePromise } from \"./types\"\n\nexport interface AtomConfig<T, D extends Record<string, Lite.Dependency>> {\n deps?: D\n factory: Lite.AtomFactory<T, D>\n tags?: Lite.Tagged<any>[]\n keepAlive?: boolean\n}\n\n/**\n * Creates a long-lived dependency that can be resolved and reused within a scope.\n *\n * @param config - Configuration object containing factory function, optional dependencies, and tags\n * @returns An Atom instance that can be resolved to produce a value of type T\n *\n * @example\n * ```typescript\n * const dbAtom = atom({\n * factory: async (ctx) => createDatabase()\n * })\n * ```\n */\nexport function atom<T>(config: {\n deps?: undefined\n factory: (ctx: Lite.ResolveContext) => MaybePromise<T>\n tags?: Lite.Tagged<any>[]\n keepAlive?: boolean\n}): Lite.Atom<T>\n\nexport function atom<\n T,\n const D extends Record<string, Lite.Atom<unknown> | Lite.ControllerDep<unknown> | { mode: string }>,\n>(config: {\n deps: D\n factory: (ctx: Lite.ResolveContext, deps: Lite.InferDeps<D>) => MaybePromise<T>\n tags?: Lite.Tagged<any>[]\n keepAlive?: boolean\n}): Lite.Atom<T>\n\nexport function atom<T, D extends Record<string, Lite.Dependency>>(\n config: AtomConfig<T, D>\n): Lite.Atom<T> {\n const atomInstance: Lite.Atom<T> = {\n [atomSymbol]: true,\n factory: config.factory as unknown as Lite.AtomFactory<T, Record<string, Lite.Dependency>>,\n deps: config.deps as unknown as Record<string, Lite.Dependency> | undefined,\n tags: config.tags,\n keepAlive: config.keepAlive,\n }\n\n if (config.tags?.length) {\n registerAtomToTags(atomInstance, config.tags)\n }\n\n return atomInstance\n}\n\n/**\n * Type guard to check if a value is an Atom.\n *\n * @param value - The value to check\n * @returns True if the value is an Atom, false otherwise\n *\n * @example\n * ```typescript\n * if (isAtom(value)) {\n * await scope.resolve(value)\n * }\n * ```\n */\nexport function isAtom(value: unknown): value is Lite.Atom<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<symbol, unknown>)[atomSymbol] === true\n )\n}\n\n/**\n * Wraps an Atom to receive a Controller instead of the resolved value.\n * The Controller provides full lifecycle control: get, resolve, release, invalidate, and subscribe.\n *\n * @param atom - The Atom to wrap\n * @param options - Optional configuration:\n * - `resolve: true` — auto-resolves the dep before the parent factory runs; `config.get()` is safe.\n * - `watch: true` — atom deps only; requires `resolve: true`; automatically re-runs the parent factory\n * when the dep resolves to a new value (value-equality gated via `Object.is` by default). Replaces\n * manual `ctx.cleanup(ctx.scope.on('resolved', dep, () => ctx.invalidate()))` wiring. Watch\n * listeners are auto-cleaned on re-resolve, release, and dispose.\n * - `eq` — custom equality function `(a: T, b: T) => boolean`; only used with `watch: true`.\n * @returns A ControllerDep that resolves to a Controller for the Atom\n *\n * @example\n * ```typescript\n * // resolve only\n * const serverAtom = atom({\n * deps: { config: controller(configAtom, { resolve: true }) },\n * factory: (_, { config }) => createServer(config.get().port),\n * })\n *\n * // watch: re-runs parent when dep value changes\n * const profileAtom = atom({\n * deps: { token: controller(tokenAtom, { resolve: true, watch: true }) },\n * factory: (_, { token }) => ({ id: `user-${token.get().jwt}` }),\n * })\n *\n * // watch with custom equality\n * const derivedAtom = atom({\n * deps: { src: controller(srcAtom, { resolve: true, watch: true, eq: (a, b) => a.id === b.id }) },\n * factory: (_, { src }) => src.get().name,\n * })\n * ```\n */\nexport function controller<T>(\n atom: Lite.Atom<T>,\n options?: Lite.ControllerDepOptions<T>\n): Lite.ControllerDep<T> {\n return {\n [controllerDepSymbol]: true,\n atom,\n resolve: options?.resolve,\n watch: options?.watch,\n eq: options?.eq,\n }\n}\n\n/**\n * Type guard to check if a value is a ControllerDep wrapper.\n *\n * @param value - The value to check\n * @returns True if the value is a ControllerDep wrapper, false otherwise\n *\n * @example\n * ```typescript\n * if (isControllerDep(dep)) {\n * const ctrl = scope.controller(dep.atom)\n * }\n * ```\n */\nexport function isControllerDep(value: unknown): value is Lite.ControllerDep<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<symbol, unknown>)[controllerDepSymbol] === true\n )\n}\n","import { flowSymbol, typedSymbol } from \"./symbols\"\nimport type { Lite, MaybePromise } from \"./types\"\n\n/**\n * Type marker for flow input without runtime parsing.\n * Use this when you want typed input but don't need validation.\n *\n * @example\n * ```typescript\n * const myFlow = flow({\n * parse: typed<{ name: string }>(),\n * factory: (ctx) => {\n * return ctx.input.name.toUpperCase()\n * }\n * })\n * ```\n */\nexport function typed<T>(): Lite.Typed<T> {\n return { [typedSymbol]: true }\n}\n\nexport interface FlowConfig<\n Output,\n Input,\n D extends Record<string, Lite.Dependency>,\n> {\n name?: string\n parse?: ((raw: unknown) => MaybePromise<Input>) | Lite.Typed<Input>\n deps?: D\n factory: Lite.FlowFactory<Output, Input, D>\n tags?: Lite.Tagged<any>[]\n}\n\n/**\n * Creates a short-lived execution unit that processes input and produces output.\n *\n * @param config - Configuration object containing factory function, optional dependencies, and tags\n * @returns A Flow instance that can be executed within an execution context\n *\n * @example\n * ```typescript\n * const processUser = flow({\n * factory: async (ctx) => {\n * const userId = ctx.input\n * return await fetchUser(userId)\n * }\n * })\n * ```\n */\nexport function flow<TOutput>(config: {\n name?: string\n parse?: undefined\n deps?: undefined\n factory: (ctx: Lite.ExecutionContext) => MaybePromise<TOutput>\n tags?: Lite.Tagged<any>[]\n}): Lite.Flow<TOutput, void>\n\nexport function flow<TOutput, TInput>(config: {\n name?: string\n parse: (raw: unknown) => MaybePromise<TInput>\n deps?: undefined\n factory: (ctx: Lite.ExecutionContext & { readonly input: NoInfer<TInput> }) => MaybePromise<TOutput>\n tags?: Lite.Tagged<any>[]\n}): Lite.Flow<TOutput, TInput>\n\nexport function flow<TOutput, TInput>(config: {\n name?: string\n parse: Lite.Typed<TInput>\n deps?: undefined\n factory: (ctx: Lite.ExecutionContext & { readonly input: NoInfer<TInput> }) => MaybePromise<TOutput>\n tags?: Lite.Tagged<any>[]\n}): Lite.Flow<TOutput, TInput>\n\nexport function flow<\n TOutput,\n const D extends Record<string, Lite.Atom<unknown> | Lite.ControllerDep<unknown> | Lite.Resource<unknown, Record<string, Lite.Dependency>> | { mode: string }>,\n>(config: {\n name?: string\n parse?: undefined\n deps: D\n factory: (ctx: Lite.ExecutionContext, deps: Lite.InferDeps<D>) => MaybePromise<TOutput>\n tags?: Lite.Tagged<any>[]\n}): Lite.Flow<TOutput, void>\n\nexport function flow<\n TOutput,\n TInput,\n const D extends Record<string, Lite.Atom<unknown> | Lite.ControllerDep<unknown> | Lite.Resource<unknown, Record<string, Lite.Dependency>> | { mode: string }>,\n>(config: {\n name?: string\n parse: (raw: unknown) => MaybePromise<TInput>\n deps: D\n factory: (ctx: Lite.ExecutionContext & { readonly input: NoInfer<TInput> }, deps: Lite.InferDeps<D>) => MaybePromise<TOutput>\n tags?: Lite.Tagged<any>[]\n}): Lite.Flow<TOutput, TInput>\n\nexport function flow<\n TOutput,\n TInput,\n const D extends Record<string, Lite.Atom<unknown> | Lite.ControllerDep<unknown> | Lite.Resource<unknown, Record<string, Lite.Dependency>> | { mode: string }>,\n>(config: {\n name?: string\n parse: Lite.Typed<TInput>\n deps: D\n factory: (ctx: Lite.ExecutionContext & { readonly input: NoInfer<TInput> }, deps: Lite.InferDeps<D>) => MaybePromise<TOutput>\n tags?: Lite.Tagged<any>[]\n}): Lite.Flow<TOutput, TInput>\n\nexport function flow<\n TOutput,\n TInput,\n D extends Record<string, Lite.Dependency>,\n>(config: FlowConfig<TOutput, TInput, D>): Lite.Flow<TOutput, TInput> {\n const parse = config.parse\n const isTypedMarker =\n typeof parse === \"object\" && parse !== null && typedSymbol in parse\n\n return {\n [flowSymbol]: true,\n name: config.name,\n parse: isTypedMarker\n ? undefined\n : (parse as ((raw: unknown) => MaybePromise<TInput>) | undefined),\n factory: config.factory as unknown as Lite.FlowFactory<\n TOutput,\n TInput,\n Record<string, Lite.Dependency>\n >,\n deps: config.deps as unknown as Record<string, Lite.Dependency> | undefined,\n tags: config.tags,\n }\n}\n\n/**\n * Type guard to check if a value is a Flow.\n *\n * @param value - The value to check\n * @returns True if the value is a Flow, false otherwise\n *\n * @example\n * ```typescript\n * if (isFlow(value)) {\n * await ctx.exec({ flow: value, input: data })\n * }\n * ```\n */\nexport function isFlow(value: unknown): value is Lite.Flow<unknown, unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<symbol, unknown>)[flowSymbol] === true\n )\n}\n","import { presetSymbol } from \"./symbols\"\nimport type { Lite, MaybePromise } from \"./types\"\nimport { isAtom } from \"./atom\"\nimport { isFlow } from \"./flow\"\n\n/**\n * Creates a preset that overrides an Atom's factory within a scope.\n *\n * @param target - The Atom to preset\n * @param value - The preset value (can be a direct value or another Atom)\n * @returns A Preset instance to be used in scope configuration\n *\n * @example\n * ```typescript\n * const scope = createScope({\n * presets: [preset(dbAtom, mockDatabase)]\n * })\n * ```\n */\nexport function preset<T>(\n target: Lite.Atom<T>,\n value: T | Lite.Atom<T>\n): Lite.Preset<T>\n\n/**\n * Creates a preset that overrides a Flow's execution within a scope.\n *\n * @param target - The Flow to preset\n * @param value - The replacement (another Flow or a function that receives ctx with parsed input)\n * @returns A Preset instance to be used in scope configuration\n *\n * @example\n * ```typescript\n * // Replace with another flow\n * const scope = createScope({\n * presets: [preset(processFlow, mockProcessFlow)]\n * })\n *\n * // Replace with a function (deps are NOT resolved)\n * const scope = createScope({\n * presets: [preset(processFlow, (ctx) => ({ result: ctx.input }))]\n * })\n * ```\n */\nexport function preset<TOutput, TInput>(\n target: Lite.Flow<TOutput, TInput>,\n value: Lite.Flow<TOutput, TInput> | ((ctx: Lite.ExecutionContext & { readonly input: TInput }) => MaybePromise<TOutput>)\n): Lite.Preset<TOutput, TInput>\n\nexport function preset<T, I>(\n target: Lite.PresetTarget<T, I>,\n value: Lite.PresetValue<T, I>\n): Lite.Preset<T, I> {\n if (!isAtom(target) && !isFlow(target)) {\n throw new Error(\"preset target must be Atom or Flow\")\n }\n if (target === value) {\n throw new Error(\"preset cannot reference itself\")\n }\n return {\n [presetSymbol]: true,\n target,\n value,\n }\n}\n\n/**\n * Type guard to check if a value is a Preset.\n *\n * @param value - The value to check\n * @returns True if the value is a Preset, false otherwise\n *\n * @example\n * ```typescript\n * if (isPreset(value)) {\n * console.log(value.target, value.value)\n * }\n * ```\n */\nexport function isPreset(value: unknown): value is Lite.Preset<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<symbol, unknown>)[presetSymbol] === true\n )\n}\n","import { resourceSymbol } from \"./symbols\"\nimport type { Lite, MaybePromise } from \"./types\"\n\n/**\n * Creates an execution-scoped dependency that is resolved per execution chain.\n * Fresh instance on first encounter, seek-up on nested execs within the same chain.\n *\n * @param config - Configuration object containing factory function and optional dependencies\n * @returns A Resource instance that can be declared as a dependency in flows and other resources\n *\n * @example\n * ```typescript\n * const requestLogger = resource({\n * deps: { logService: logServiceAtom },\n * factory: (ctx, { logService }) => {\n * const logger = logService.child({ requestId: ctx.data.get(\"requestId\") })\n * ctx.onClose(() => logger.flush())\n * return logger\n * }\n * })\n * ```\n */\nexport function resource<T>(config: {\n name?: string\n deps?: undefined\n factory: (ctx: Lite.ExecutionContext) => MaybePromise<T>\n}): Lite.Resource<T>\n\nexport function resource<\n T,\n const D extends Record<string, Lite.Atom<unknown> | Lite.ControllerDep<unknown> | Lite.Resource<unknown, Record<string, Lite.Dependency>> | { mode: string }>,\n>(config: {\n name?: string\n deps: D\n factory: (ctx: Lite.ExecutionContext, deps: Lite.InferDeps<D>) => MaybePromise<T>\n}): Lite.Resource<T>\n\nexport function resource<T, D extends Record<string, Lite.Dependency>>(\n config: {\n name?: string\n deps?: D\n factory: Lite.ResourceFactory<T, D>\n }\n): Lite.Resource<T> {\n return Object.freeze({\n [resourceSymbol]: true,\n name: config.name,\n deps: config.deps as unknown as Record<string, Lite.Dependency> | undefined,\n factory: config.factory as unknown as Lite.ResourceFactory<T, Record<string, Lite.Dependency>>,\n }) as Lite.Resource<T>\n}\n\n/**\n * Type guard to check if a value is a Resource.\n *\n * @param value - The value to check\n * @returns True if the value is a Resource, false otherwise\n *\n * @example\n * ```typescript\n * if (isResource(value)) {\n * // value is Lite.Resource<unknown>\n * }\n * ```\n */\nexport function isResource(value: unknown): value is Lite.Resource<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<symbol, unknown>)[resourceSymbol] === true\n )\n}\n","import { atomSymbol } from \"./symbols\"\nimport type { Lite, MaybePromise } from \"./types\"\n\n/** Creates an atom with methods constrained to (ctx: ExecutionContext, ...args) => result. */\nexport function service<T extends Lite.ServiceMethods>(config: {\n deps?: undefined\n factory: (ctx: Lite.ResolveContext) => MaybePromise<T>\n tags?: Lite.Tagged<any>[]\n}): Lite.Atom<T>\n\nexport function service<\n T extends Lite.ServiceMethods,\n const D extends Record<string, Lite.Atom<unknown> | Lite.ControllerDep<unknown> | Lite.TagExecutor<any>>,\n>(config: {\n deps: D\n factory: (ctx: Lite.ResolveContext, deps: Lite.InferDeps<D>) => MaybePromise<T>\n tags?: Lite.Tagged<any>[]\n}): Lite.Atom<T>\n\nexport function service<T extends Lite.ServiceMethods, D extends Record<string, Lite.Dependency>>(config: {\n deps?: D\n factory: Lite.AtomFactory<T, D>\n tags?: Lite.Tagged<any>[]\n}): Lite.Atom<T> {\n return {\n [atomSymbol]: true,\n factory: config.factory as unknown as Lite.AtomFactory<T, Record<string, Lite.Dependency>>,\n deps: config.deps as unknown as Record<string, Lite.Dependency> | undefined,\n tags: config.tags,\n }\n}\n","import { controllerSymbol, tagExecutorSymbol } from \"./symbols\"\nimport type { Lite, MaybePromise, AtomState } from \"./types\"\nimport { isAtom, isControllerDep } from \"./atom\"\nimport { isFlow } from \"./flow\"\nimport { isResource } from \"./resource\"\nimport { ParseError } from \"./errors\"\n\nconst resourceKeys = new WeakMap<Lite.Resource<unknown>, symbol>()\nlet resourceKeyCounter = 0\n\nfunction getResourceKey(resource: Lite.Resource<unknown>): symbol {\n let key = resourceKeys.get(resource)\n if (!key) {\n key = Symbol(`resource:${resource.name ?? resourceKeyCounter++}`)\n resourceKeys.set(resource, key)\n }\n return key\n}\n\nconst inflightResources = new WeakMap<Lite.ContextData, Map<symbol, Promise<unknown>>>()\nconst resolvingResources = new Set<symbol>()\n\ntype ListenerEvent = 'resolving' | 'resolved' | '*'\n\nclass ContextDataImpl implements Lite.ContextData {\n private readonly map = new Map<string | symbol, unknown>()\n\n constructor(\n private readonly parentData?: Lite.ContextData\n ) {}\n\n // Raw Map operations\n get(key: string | symbol): unknown {\n return this.map.get(key)\n }\n\n set(key: string | symbol, value: unknown): void {\n this.map.set(key, value)\n }\n\n has(key: string | symbol): boolean {\n return this.map.has(key)\n }\n\n delete(key: string | symbol): boolean {\n return this.map.delete(key)\n }\n\n clear(): void {\n this.map.clear()\n }\n\n seek(key: string | symbol): unknown {\n if (this.map.has(key)) {\n return this.map.get(key)\n }\n return this.parentData?.seek(key)\n }\n\n // Tag-based operations\n getTag<T>(tag: Lite.Tag<T, boolean>): T | undefined {\n return this.map.get(tag.key) as T | undefined\n }\n\n setTag<T>(tag: Lite.Tag<T, boolean>, value: T): void {\n this.map.set(tag.key, value)\n }\n\n hasTag<T, H extends boolean>(tag: Lite.Tag<T, H>): boolean {\n return this.map.has(tag.key)\n }\n\n deleteTag<T, H extends boolean>(tag: Lite.Tag<T, H>): boolean {\n return this.map.delete(tag.key)\n }\n\n seekTag<T>(tag: Lite.Tag<T, boolean>): T | undefined {\n if (this.map.has(tag.key)) {\n return this.map.get(tag.key) as T\n }\n return this.parentData?.seekTag(tag)\n }\n\n getOrSetTag<T>(tag: Lite.Tag<T, true>): T\n getOrSetTag<T>(tag: Lite.Tag<T, true>, value: T): T\n getOrSetTag<T>(tag: Lite.Tag<T, false>, value: T): T\n getOrSetTag<T>(tag: Lite.Tag<T, boolean>, value?: T): T {\n if (this.map.has(tag.key)) {\n return this.map.get(tag.key) as T\n }\n const storedValue = value !== undefined ? value : (tag.defaultValue as T)\n this.map.set(tag.key, storedValue)\n return storedValue\n }\n}\n\ninterface AtomEntry<T> {\n state: AtomState\n value?: T\n hasValue: boolean\n error?: Error\n cleanups: (() => MaybePromise<void>)[]\n listeners: Map<ListenerEvent, Set<() => void>>\n pendingInvalidate: boolean\n pendingSet?: { value: T } | { fn: (prev: T) => T }\n data?: ContextDataImpl\n dependents: Set<Lite.Atom<unknown>>\n gcScheduled: ReturnType<typeof setTimeout> | null\n}\n\nclass SelectHandleImpl<T, S> implements Lite.SelectHandle<S> {\n private listeners = new Set<() => void>()\n private currentValue: S\n private ctrlUnsub: (() => void) | null = null\n\n constructor(\n private ctrl: Lite.Controller<T>,\n private selector: (value: T) => S,\n private eq: (prev: S, next: S) => boolean\n ) {\n if (ctrl.state !== 'resolved') {\n throw new Error(\"Cannot select from unresolved atom\")\n }\n\n this.currentValue = selector(ctrl.get())\n\n this.ctrlUnsub = ctrl.on('resolved', () => {\n const nextValue = this.selector(this.ctrl.get())\n if (!this.eq(this.currentValue, nextValue)) {\n this.currentValue = nextValue\n this.notifyListeners()\n }\n })\n }\n\n get(): S {\n return this.currentValue\n }\n\n subscribe(listener: () => void): () => void {\n this.listeners.add(listener)\n\n return () => {\n this.listeners.delete(listener)\n if (this.listeners.size === 0) {\n this.cleanup()\n }\n }\n }\n\n private notifyListeners(): void {\n for (const listener of this.listeners) {\n listener()\n }\n }\n\n private cleanup(): void {\n this.ctrlUnsub?.()\n this.ctrlUnsub = null\n this.listeners.clear()\n }\n}\n\nclass ControllerImpl<T> implements Lite.Controller<T> {\n readonly [controllerSymbol] = true\n\n constructor(\n private atom: Lite.Atom<T>,\n private scope: ScopeImpl\n ) {}\n\n get state(): AtomState {\n const entry = this.scope.getEntry(this.atom)\n return entry?.state ?? 'idle'\n }\n\n get(): T {\n const entry = this.scope.getEntry(this.atom)\n if (!entry || entry.state === 'idle') {\n throw new Error(\"Atom not resolved\")\n }\n if (entry.state === 'failed' && entry.error) {\n throw entry.error\n }\n if (entry.state === 'resolving' && entry.hasValue) {\n return entry.value as T\n }\n if (entry.state === 'resolved' && entry.hasValue) {\n return entry.value as T\n }\n throw new Error(\"Atom not resolved\")\n }\n\n async resolve(): Promise<T> {\n return this.scope.resolve(this.atom)\n }\n\n async release(): Promise<void> {\n return this.scope.release(this.atom)\n }\n\n invalidate(): void {\n this.scope.invalidate(this.atom)\n }\n\n set(value: T): void {\n this.scope.scheduleSet(this.atom, value)\n }\n\n update(fn: (prev: T) => T): void {\n this.scope.scheduleUpdate(this.atom, fn)\n }\n\n on(event: ListenerEvent, listener: () => void): () => void {\n return this.scope.addListener(this.atom, event, listener)\n }\n}\n\nclass ScopeImpl implements Lite.Scope {\n private cache = new Map<Lite.Atom<unknown>, AtomEntry<unknown>>()\n private presets = new Map<Lite.Atom<unknown> | Lite.Flow<unknown, unknown>, unknown>()\n private resolving = new Set<Lite.Atom<unknown>>()\n private pending = new Map<Lite.Atom<unknown>, Promise<unknown>>()\n private stateListeners = new Map<AtomState, Map<Lite.Atom<unknown>, Set<() => void>>>()\n private invalidationQueue = new Set<Lite.Atom<unknown>>()\n private invalidationScheduled = false\n private invalidationChain: Set<Lite.Atom<unknown>> | null = null\n private chainPromise: Promise<void> | null = null\n private initialized = false\n private controllers = new Map<Lite.Atom<unknown>, ControllerImpl<unknown>>()\n private gcOptions: Required<Lite.GCOptions>\n readonly extensions: Lite.Extension[]\n readonly tags: Lite.Tagged<any>[]\n readonly ready: Promise<void>\n\n private scheduleInvalidation<T>(atom: Lite.Atom<T>): void {\n const entry = this.cache.get(atom) as AtomEntry<T> | undefined\n if (!entry || entry.state === \"idle\") return\n\n if (entry.state === \"resolving\") {\n entry.pendingInvalidate = true\n return\n }\n\n this.invalidationQueue.add(atom)\n\n if (!this.chainPromise) {\n this.invalidationChain = new Set()\n this.invalidationScheduled = true\n this.chainPromise = new Promise<void>((resolve, reject) => {\n queueMicrotask(() => {\n this.processInvalidationChain().then(resolve).catch(reject)\n })\n })\n }\n }\n\n private async processInvalidationChain(): Promise<void> {\n try {\n while (this.invalidationQueue.size > 0) {\n const atom = this.invalidationQueue.values().next().value as Lite.Atom<unknown>\n this.invalidationQueue.delete(atom)\n\n if (this.invalidationChain!.has(atom)) {\n const chainAtoms = Array.from(this.invalidationChain!)\n chainAtoms.push(atom)\n const path = chainAtoms\n .map(a => a.factory?.name || \"<anonymous>\")\n .join(\" → \")\n throw new Error(`Infinite invalidation loop detected: ${path}`)\n }\n\n this.invalidationChain!.add(atom)\n await this.doInvalidateSequential(atom)\n }\n } finally {\n this.invalidationChain = null\n this.chainPromise = null\n this.invalidationScheduled = false\n }\n }\n\n constructor(options?: Lite.ScopeOptions) {\n this.extensions = options?.extensions ?? []\n this.tags = options?.tags ?? []\n\n for (const p of options?.presets ?? []) {\n this.presets.set(p.target, p.value)\n }\n\n this.gcOptions = {\n enabled: options?.gc?.enabled ?? true,\n graceMs: options?.gc?.graceMs ?? 3000,\n }\n\n this.ready = this.init()\n }\n\n private async init(): Promise<void> {\n for (const ext of this.extensions) {\n if (ext.init) {\n await ext.init(this)\n }\n }\n this.initialized = true\n }\n\n getEntry<T>(atom: Lite.Atom<T>): AtomEntry<T> | undefined {\n return this.cache.get(atom) as AtomEntry<T> | undefined\n }\n\n private getOrCreateEntry<T>(atom: Lite.Atom<T>): AtomEntry<T> {\n let entry = this.cache.get(atom) as AtomEntry<T> | undefined\n if (!entry) {\n entry = {\n state: 'idle',\n hasValue: false,\n cleanups: [],\n listeners: new Map([\n ['resolving', new Set()],\n ['resolved', new Set()],\n ['*', new Set()],\n ]),\n pendingInvalidate: false,\n dependents: new Set(),\n gcScheduled: null,\n }\n this.cache.set(atom, entry as AtomEntry<unknown>)\n }\n return entry\n }\n\n addListener<T>(atom: Lite.Atom<T>, event: ListenerEvent, listener: () => void): () => void {\n this.cancelScheduledGC(atom)\n \n const entry = this.getOrCreateEntry(atom)\n const listeners = entry.listeners.get(event)!\n listeners.add(listener)\n return () => {\n listeners.delete(listener)\n this.maybeScheduleGC(atom)\n }\n }\n\n private getSubscriberCount<T>(atom: Lite.Atom<T>): number {\n const entry = this.cache.get(atom)\n if (!entry) return 0\n let count = 0\n for (const listeners of entry.listeners.values()) {\n count += listeners.size\n }\n return count\n }\n\n private maybeScheduleGC<T>(atom: Lite.Atom<T>): void {\n if (!this.gcOptions.enabled) return\n if (atom.keepAlive) return\n \n const entry = this.cache.get(atom)\n if (!entry) return\n if (entry.state === 'idle') return\n \n const subscriberCount = this.getSubscriberCount(atom)\n if (subscriberCount > 0) return\n if (entry.dependents.size > 0) return\n \n if (entry.gcScheduled) return\n \n entry.gcScheduled = setTimeout(() => {\n this.executeGC(atom)\n }, this.gcOptions.graceMs)\n }\n\n private cancelScheduledGC<T>(atom: Lite.Atom<T>): void {\n const entry = this.cache.get(atom)\n if (entry?.gcScheduled) {\n clearTimeout(entry.gcScheduled)\n entry.gcScheduled = null\n }\n }\n\n private async executeGC<T>(atom: Lite.Atom<T>): Promise<void> {\n const entry = this.cache.get(atom)\n if (!entry) return\n \n entry.gcScheduled = null\n \n if (this.getSubscriberCount(atom) > 0) return\n if (entry.dependents.size > 0) return\n if (atom.keepAlive) return\n \n await this.release(atom)\n \n if (atom.deps) {\n for (const dep of Object.values(atom.deps)) {\n const depAtom = isAtom(dep) ? dep : isControllerDep(dep) ? dep.atom : null\n if (!depAtom) continue\n \n const depEntry = this.cache.get(depAtom)\n if (depEntry) {\n depEntry.dependents.delete(atom)\n this.maybeScheduleGC(depAtom)\n }\n }\n }\n }\n\n private notifyListeners<T>(atom: Lite.Atom<T>, event: 'resolving' | 'resolved'): void {\n const entry = this.cache.get(atom)\n if (!entry) return\n\n const eventListeners = entry.listeners.get(event)\n if (eventListeners) {\n for (const listener of eventListeners) {\n listener()\n }\n }\n\n const allListeners = entry.listeners.get('*')\n if (allListeners) {\n for (const listener of allListeners) {\n listener()\n }\n }\n }\n\n private notifyAllListeners<T>(atom: Lite.Atom<T>): void {\n const entry = this.cache.get(atom)\n if (!entry) return\n\n const allListeners = entry.listeners.get('*')\n if (allListeners) {\n for (const listener of allListeners) {\n listener()\n }\n }\n }\n\n private emitStateChange(state: AtomState, atom: Lite.Atom<unknown>): void {\n const stateMap = this.stateListeners.get(state)\n if (stateMap) {\n const listeners = stateMap.get(atom)\n if (listeners) {\n for (const listener of listeners) {\n listener()\n }\n }\n }\n }\n\n on(event: AtomState, atom: Lite.Atom<unknown>, listener: () => void): () => void {\n let stateMap = this.stateListeners.get(event)\n if (!stateMap) {\n stateMap = new Map()\n this.stateListeners.set(event, stateMap)\n }\n let listeners = stateMap.get(atom)\n if (!listeners) {\n listeners = new Set()\n stateMap.set(atom, listeners)\n }\n listeners.add(listener)\n\n const capturedStateMap = stateMap\n const capturedListeners = listeners\n\n return () => {\n capturedListeners.delete(listener)\n if (capturedListeners.size === 0) {\n capturedStateMap.delete(atom)\n if (capturedStateMap.size === 0) {\n this.stateListeners.delete(event)\n }\n }\n }\n }\n\n async resolve<T>(atom: Lite.Atom<T>): Promise<T> {\n if (!this.initialized) {\n await this.ready\n }\n\n const entry = this.cache.get(atom) as AtomEntry<T> | undefined\n if (entry?.state === 'resolved') {\n return entry.value as T\n }\n\n const pendingPromise = this.pending.get(atom)\n if (pendingPromise) {\n return pendingPromise as Promise<T>\n }\n\n if (this.resolving.has(atom)) {\n throw new Error(\"Circular dependency detected\")\n }\n\n const presetValue = this.presets.get(atom)\n if (presetValue !== undefined) {\n if (isAtom(presetValue)) {\n return this.resolve(presetValue as Lite.Atom<T>)\n }\n const newEntry = this.getOrCreateEntry(atom)\n newEntry.state = 'resolved'\n newEntry.value = presetValue as T\n newEntry.hasValue = true\n this.emitStateChange('resolved', atom)\n this.notifyListeners(atom, 'resolved')\n return newEntry.value\n }\n\n this.resolving.add(atom)\n\n const promise = this.doResolve(atom)\n this.pending.set(atom, promise as Promise<unknown>)\n\n try {\n return await promise\n } finally {\n this.resolving.delete(atom)\n this.pending.delete(atom)\n }\n }\n\n private async doResolve<T>(atom: Lite.Atom<T>): Promise<T> {\n const entry = this.getOrCreateEntry(atom)\n\n const wasResolving = entry.state === 'resolving'\n if (!wasResolving) {\n for (let i = entry.cleanups.length - 1; i >= 0; i--) {\n await entry.cleanups[i]?.()\n }\n entry.cleanups = []\n entry.state = 'resolving'\n this.emitStateChange('resolving', atom)\n this.notifyListeners(atom, 'resolving')\n }\n\n const resolvedDeps = await this.resolveDeps(atom.deps, undefined, atom)\n\n const ctx: Lite.ResolveContext = {\n cleanup: (fn) => entry.cleanups.push(fn),\n invalidate: () => {\n this.scheduleInvalidation(atom)\n },\n scope: this,\n get data() {\n if (!entry.data) {\n entry.data = new ContextDataImpl()\n }\n return entry.data\n },\n }\n\n const factory = atom.factory as (\n ctx: Lite.ResolveContext,\n deps?: Record<string, unknown>\n ) => MaybePromise<T>\n\n const doResolve = async () => {\n if (atom.deps && Object.keys(atom.deps).length > 0) {\n return factory(ctx, resolvedDeps)\n } else {\n return factory(ctx)\n }\n }\n\n try {\n const event: Lite.ResolveEvent = { kind: \"atom\", target: atom as Lite.Atom<unknown>, scope: this }\n const value = await this.applyResolveExtensions(event, doResolve)\n entry.state = 'resolved'\n entry.value = value\n entry.hasValue = true\n entry.error = undefined\n this.emitStateChange('resolved', atom)\n this.notifyListeners(atom, 'resolved')\n\n if (entry.pendingInvalidate) {\n entry.pendingInvalidate = false\n this.invalidationChain?.delete(atom)\n this.scheduleInvalidation(atom)\n } else if (entry.pendingSet) {\n this.invalidationChain?.delete(atom)\n this.scheduleInvalidation(atom)\n }\n\n return value\n } catch (err) {\n entry.state = 'failed'\n entry.error = err instanceof Error ? err : new Error(String(err))\n entry.value = undefined\n entry.hasValue = false\n this.emitStateChange('failed', atom)\n this.notifyAllListeners(atom)\n\n if (entry.pendingInvalidate) {\n entry.pendingInvalidate = false\n this.invalidationChain?.delete(atom)\n this.scheduleInvalidation(atom)\n }\n\n throw entry.error\n }\n }\n\n private async applyResolveExtensions<T>(\n event: Lite.ResolveEvent,\n doResolve: () => Promise<T>\n ): Promise<T> {\n let next = doResolve\n\n for (let i = this.extensions.length - 1; i >= 0; i--) {\n const ext = this.extensions[i]\n if (ext?.wrapResolve) {\n const currentNext = next\n next = ext.wrapResolve.bind(ext, currentNext, event) as () => Promise<T>\n }\n }\n\n return next()\n }\n\n async resolveDeps(\n deps: Record<string, Lite.Dependency> | undefined,\n ctx?: Lite.ExecutionContext,\n dependentAtom?: Lite.Atom<unknown>\n ): Promise<Record<string, unknown>> {\n if (!deps) return {}\n\n const result: Record<string, unknown> = {}\n\n for (const [key, dep] of Object.entries(deps)) {\n if (isAtom(dep)) {\n result[key] = await this.resolve(dep)\n if (dependentAtom) {\n const depEntry = this.getEntry(dep)\n if (depEntry) {\n depEntry.dependents.add(dependentAtom)\n }\n }\n } else if (isControllerDep(dep)) {\n if (dep.watch) {\n if (!dependentAtom) throw new Error(\"controller({ watch: true }) is only supported in atom dependencies\")\n if (!dep.resolve) throw new Error(\"controller({ watch: true }) requires resolve: true\")\n }\n const ctrl = this.controller(dep.atom)\n if (dep.resolve) {\n await ctrl.resolve()\n }\n result[key] = ctrl\n if (dependentAtom) {\n const depEntry = this.getEntry(dep.atom)\n if (depEntry) {\n depEntry.dependents.add(dependentAtom)\n }\n }\n if (dep.watch) {\n const eq = dep.eq ?? Object.is\n let prev = ctrl.get() as unknown\n const unsub = this.on(\"resolved\", dep.atom, () => {\n const next = ctrl.get() as unknown\n if (!eq(prev, next)) {\n prev = next\n this.scheduleInvalidation(dependentAtom!)\n }\n })\n const depEntry = this.getEntry(dependentAtom!)\n if (depEntry) depEntry.cleanups.push(unsub)\n else unsub()\n }\n } else if (tagExecutorSymbol in (dep as object)) {\n const tagExecutor = dep as Lite.TagExecutor<unknown, boolean>\n\n switch (tagExecutor.mode) {\n case \"required\": {\n const value = ctx\n ? ctx.data.seekTag(tagExecutor.tag)\n : tagExecutor.tag.find(this.tags)\n if (value !== undefined) {\n result[key] = value\n } else if (tagExecutor.tag.hasDefault) {\n result[key] = tagExecutor.tag.defaultValue\n } else {\n throw new Error(`Tag \"${tagExecutor.tag.label}\" not found`)\n }\n break\n }\n case \"optional\": {\n const value = ctx\n ? ctx.data.seekTag(tagExecutor.tag)\n : tagExecutor.tag.find(this.tags)\n result[key] = value ?? tagExecutor.tag.defaultValue\n break\n }\n case \"all\": {\n result[key] = ctx\n ? this.collectFromHierarchy(ctx, tagExecutor.tag)\n : tagExecutor.tag.collect(this.tags)\n break\n }\n }\n } else if (isResource(dep)) {\n if (!ctx) {\n throw new Error(\"Resource deps require an ExecutionContext\")\n }\n\n const resource = dep as Lite.Resource<unknown>\n const resourceKey = getResourceKey(resource)\n const storeCtx = ctx.parent ?? ctx\n\n if (storeCtx.data.has(resourceKey)) {\n result[key] = storeCtx.data.get(resourceKey)\n continue\n }\n\n const existingSeek = ctx.data.seek(resourceKey)\n if (existingSeek !== undefined || ctx.data.has(resourceKey)) {\n result[key] = existingSeek\n continue\n }\n\n if (resolvingResources.has(resourceKey)) {\n throw new Error(`Circular resource dependency detected: ${resource.name ?? \"anonymous\"}`)\n }\n\n let flights = inflightResources.get(storeCtx.data)\n if (!flights) {\n flights = new Map()\n inflightResources.set(storeCtx.data, flights)\n }\n\n const inflight = flights.get(resourceKey)\n if (inflight) {\n result[key] = await inflight\n continue\n }\n\n const resolve = async () => {\n resolvingResources.add(resourceKey)\n try {\n const resourceDeps = await this.resolveDeps(resource.deps, ctx)\n\n const event: Lite.ResolveEvent = {\n kind: \"resource\",\n target: resource,\n ctx: storeCtx,\n }\n\n const doResolve = async () => {\n const factory = resource.factory as (\n ctx: Lite.ExecutionContext,\n deps?: Record<string, unknown>\n ) => MaybePromise<unknown>\n if (resource.deps && Object.keys(resource.deps).length > 0) {\n return factory(storeCtx, resourceDeps)\n }\n return factory(storeCtx)\n }\n\n const value = await this.applyResolveExtensions(event, doResolve)\n storeCtx.data.set(resourceKey, value)\n return value\n } finally {\n resolvingResources.delete(resourceKey)\n }\n }\n\n const promise = resolve()\n flights.set(resourceKey, promise)\n\n try {\n result[key] = await promise\n } finally {\n flights.delete(resourceKey)\n }\n }\n }\n\n return result\n }\n\n private collectFromHierarchy<T>(ctx: Lite.ExecutionContext, tag: Lite.Tag<T, boolean>): T[] {\n const results: T[] = []\n let current: Lite.ExecutionContext | undefined = ctx\n\n while (current) {\n const value = current.data.getTag(tag)\n if (value !== undefined) {\n results.push(value)\n }\n current = current.parent\n }\n\n return results\n }\n\n controller<T>(atom: Lite.Atom<T>): Lite.Controller<T>\n controller<T>(atom: Lite.Atom<T>, options: { resolve: true }): Promise<Lite.Controller<T>>\n controller<T>(atom: Lite.Atom<T>, options?: Lite.ControllerOptions): Lite.Controller<T> | Promise<Lite.Controller<T>>\n controller<T>(atom: Lite.Atom<T>, options?: Lite.ControllerOptions): Lite.Controller<T> | Promise<Lite.Controller<T>> {\n let ctrl = this.controllers.get(atom) as ControllerImpl<T> | undefined\n if (!ctrl) {\n ctrl = new ControllerImpl(atom, this)\n this.controllers.set(atom, ctrl as ControllerImpl<unknown>)\n }\n if (options?.resolve) {\n return ctrl.resolve().then(() => ctrl)\n }\n return ctrl\n }\n\n select<T, S>(\n atom: Lite.Atom<T>,\n selector: (value: T) => S,\n options?: Lite.SelectOptions<S>\n ): Lite.SelectHandle<S> {\n const ctrl = this.controller(atom)\n const eq = options?.eq ?? ((a, b) => a === b)\n return new SelectHandleImpl(ctrl, selector, eq)\n }\n\n getFlowPreset<O, I>(flow: Lite.Flow<O, I>): Lite.PresetValue<O, I> | undefined {\n return this.presets.get(flow as Lite.Flow<unknown, unknown>) as Lite.PresetValue<O, I> | undefined\n }\n\n invalidate<T>(atom: Lite.Atom<T>): void {\n const entry = this.cache.get(atom)\n if (!entry) return\n\n if (entry.state === 'idle') return\n\n if (entry.state === 'resolving') {\n entry.pendingInvalidate = true\n return\n }\n\n this.scheduleInvalidation(atom)\n }\n\n scheduleSet<T>(atom: Lite.Atom<T>, value: T): void {\n const entry = this.cache.get(atom) as AtomEntry<T> | undefined\n if (!entry || entry.state === 'idle') {\n throw new Error(\"Atom not resolved\")\n }\n if (entry.state === 'failed' && entry.error) {\n throw entry.error\n }\n\n if (entry.state === 'resolving') {\n entry.pendingSet = { value }\n return\n }\n\n entry.pendingSet = { value }\n this.scheduleInvalidation(atom)\n }\n\n scheduleUpdate<T>(atom: Lite.Atom<T>, fn: (prev: T) => T): void {\n const entry = this.cache.get(atom) as AtomEntry<T> | undefined\n if (!entry || entry.state === 'idle') {\n throw new Error(\"Atom not resolved\")\n }\n if (entry.state === 'failed' && entry.error) {\n throw entry.error\n }\n\n if (entry.state === 'resolving') {\n entry.pendingSet = { fn }\n return\n }\n\n entry.pendingSet = { fn }\n this.scheduleInvalidation(atom)\n }\n\n private async doInvalidateSequential<T>(atom: Lite.Atom<T>): Promise<void> {\n const entry = this.cache.get(atom) as AtomEntry<T> | undefined\n if (!entry) return\n if (entry.state === \"idle\") return\n\n const previousValue = entry.value\n const pendingSet = entry.pendingSet\n entry.pendingSet = undefined\n\n for (let i = entry.cleanups.length - 1; i >= 0; i--) {\n const cleanup = entry.cleanups[i]\n if (cleanup) await cleanup()\n }\n entry.cleanups = []\n\n entry.state = \"resolving\"\n entry.value = previousValue\n entry.error = undefined\n entry.pendingInvalidate = false\n this.pending.delete(atom)\n this.resolving.delete(atom)\n this.emitStateChange(\"resolving\", atom)\n this.notifyListeners(atom, \"resolving\")\n\n if (pendingSet) {\n if ('value' in pendingSet) {\n entry.value = pendingSet.value\n } else {\n entry.value = pendingSet.fn(previousValue as T)\n }\n entry.state = 'resolved'\n entry.hasValue = true\n this.emitStateChange('resolved', atom)\n this.notifyListeners(atom, 'resolved')\n return\n }\n\n await this.resolve(atom)\n }\n\n async release<T>(atom: Lite.Atom<T>): Promise<void> {\n const entry = this.cache.get(atom)\n if (!entry) return\n\n if (entry.gcScheduled) {\n clearTimeout(entry.gcScheduled)\n entry.gcScheduled = null\n }\n\n for (let i = entry.cleanups.length - 1; i >= 0; i--) {\n const cleanup = entry.cleanups[i]\n if (cleanup) await cleanup()\n }\n\n this.cache.delete(atom)\n this.controllers.delete(atom)\n }\n\n async dispose(): Promise<void> {\n for (const ext of this.extensions) {\n if (ext.dispose) {\n await ext.dispose(this)\n }\n }\n\n for (const entry of this.cache.values()) {\n if (entry.gcScheduled) {\n clearTimeout(entry.gcScheduled)\n entry.gcScheduled = null\n }\n }\n\n const atoms = Array.from(this.cache.keys())\n for (const atom of atoms) {\n await this.release(atom as Lite.Atom<unknown>)\n }\n }\n\n async flush(): Promise<void> {\n if (this.chainPromise) {\n await this.chainPromise\n }\n }\n\n createContext(options?: Lite.CreateContextOptions): Lite.ExecutionContext {\n const ctx = new ExecutionContextImpl(this, options)\n\n for (const tagged of options?.tags ?? []) {\n ctx.data.set(tagged.key, tagged.value)\n }\n\n for (const tagged of this.tags) {\n if (!ctx.data.has(tagged.key)) {\n ctx.data.set(tagged.key, tagged.value)\n }\n }\n\n return ctx\n }\n}\n\nclass ExecutionContextImpl implements Lite.ExecutionContext {\n private cleanups: ((result: Lite.CloseResult) => MaybePromise<void>)[] = []\n private closed = false\n private readonly _input: unknown\n private _data: ContextDataImpl | undefined\n private readonly _execName: string | undefined\n private readonly _flowName: string | undefined\n readonly parent: Lite.ExecutionContext | undefined\n\n constructor(\n readonly scope: ScopeImpl,\n options?: Lite.CreateContextOptions & {\n parent?: Lite.ExecutionContext\n input?: unknown\n execName?: string\n flowName?: string\n }\n ) {\n this.parent = options?.parent\n this._input = options?.input\n this._execName = options?.execName\n this._flowName = options?.flowName\n }\n\n get input(): unknown {\n return this._input\n }\n\n get name(): string | undefined {\n return this._execName ?? this._flowName\n }\n\n get data(): Lite.ContextData {\n if (!this._data) {\n this._data = new ContextDataImpl(this.parent?.data)\n }\n return this._data\n }\n\n async exec(options: {\n flow: Lite.Flow<unknown, unknown>\n input?: unknown\n rawInput?: unknown\n name?: string\n tags?: Lite.Tagged<any>[]\n } | Lite.ExecFnOptions<unknown>): Promise<unknown> {\n if (this.closed) {\n throw new Error(\"ExecutionContext is closed\")\n }\n\n if (\"flow\" in options) {\n const { flow, input, rawInput, name: execName, tags: execTags } = options\n\n const presetValue = this.scope.getFlowPreset(flow)\n if (presetValue !== undefined && isFlow(presetValue)) {\n return this.exec({ ...options, flow: presetValue })\n }\n\n const rawValue = rawInput !== undefined ? rawInput : input\n let parsedInput: unknown = rawValue\n if (flow.parse) {\n const label = execName ?? flow.name ?? \"anonymous\"\n try {\n parsedInput = await flow.parse(rawValue)\n } catch (err) {\n throw new ParseError(\n `Failed to parse flow input \"${label}\"`,\n \"flow-input\",\n label,\n err\n )\n }\n }\n\n const childCtx = new ExecutionContextImpl(this.scope, {\n parent: this,\n input: parsedInput,\n execName,\n flowName: flow.name\n })\n\n for (const tagged of execTags ?? []) {\n childCtx.data.set(tagged.key, tagged.value)\n }\n\n for (const tagged of flow.tags ?? []) {\n if (!childCtx.data.has(tagged.key)) {\n childCtx.data.set(tagged.key, tagged.value)\n }\n }\n\n try {\n const result = presetValue !== undefined && typeof presetValue === 'function'\n ? await childCtx.execPresetFn(flow, presetValue as (ctx: Lite.ExecutionContext) => unknown)\n : await childCtx.execFlowInternal(flow)\n await childCtx.close({ ok: true })\n return result\n } catch (error) {\n await childCtx.close({ ok: false, error })\n throw error\n }\n } else {\n const childCtx = new ExecutionContextImpl(this.scope, {\n parent: this,\n execName: options.name,\n flowName: options.fn.name || undefined,\n input: options.params\n })\n\n try {\n const result = await childCtx.execFnInternal(options)\n await childCtx.close({ ok: true })\n return result\n } catch (error) {\n await childCtx.close({ ok: false, error })\n throw error\n }\n }\n }\n\n private async execFlowInternal(flow: Lite.Flow<unknown, unknown>): Promise<unknown> {\n const resolvedDeps = await this.scope.resolveDeps(flow.deps, this)\n\n const factory = flow.factory as unknown as (\n ctx: Lite.ExecutionContext,\n deps?: Record<string, unknown>\n ) => MaybePromise<unknown>\n\n const doExec = async (): Promise<unknown> => {\n if (flow.deps && Object.keys(flow.deps).length > 0) {\n return factory(this, resolvedDeps)\n } else {\n return factory(this)\n }\n }\n\n return this.applyExecExtensions(flow, doExec)\n }\n\n private async execFnInternal(options: Lite.ExecFnOptions<unknown>): Promise<unknown> {\n const { fn, params } = options\n const doExec = () => Promise.resolve(fn(this, ...params))\n return this.applyExecExtensions(fn, doExec)\n }\n\n async execPresetFn(\n flow: Lite.Flow<unknown, unknown>,\n fn: (ctx: Lite.ExecutionContext) => MaybePromise<unknown>\n ): Promise<unknown> {\n const doExec = () => Promise.resolve(fn(this))\n return this.applyExecExtensions(flow, doExec)\n }\n\n private async applyExecExtensions(\n target: Lite.Flow<unknown, unknown> | ((ctx: Lite.ExecutionContext, ...args: unknown[]) => MaybePromise<unknown>),\n doExec: () => Promise<unknown>\n ): Promise<unknown> {\n let next = doExec\n\n for (let i = this.scope.extensions.length - 1; i >= 0; i--) {\n const ext = this.scope.extensions[i]\n if (ext?.wrapExec) {\n const currentNext = next\n next = ext.wrapExec.bind(ext, currentNext, target, this) as () => Promise<unknown>\n }\n }\n\n return next()\n }\n\n onClose(fn: (result: Lite.CloseResult) => MaybePromise<void>): void {\n this.cleanups.push(fn)\n }\n\n async close(result: Lite.CloseResult = { ok: true }): Promise<void> {\n if (this.closed) return\n\n this.closed = true\n\n for (let i = this.cleanups.length - 1; i >= 0; i--) {\n const cleanup = this.cleanups[i]\n if (cleanup) await cleanup(result)\n }\n }\n}\n\n/**\n * Creates a DI container that manages Atom resolution, caching, and lifecycle.\n *\n * The scope is returned synchronously, with a `ready` promise that resolves\n * when all extensions have been initialized. Resolution methods automatically\n * wait for `ready` before proceeding.\n *\n * @param options - Optional configuration for extensions, presets, and tags\n * @returns A Scope instance with a `ready` promise for extension initialization\n *\n * @example\n * ```typescript\n * const scope = createScope({\n * extensions: [loggingExtension],\n * presets: [preset(dbAtom, testDb)]\n * })\n *\n * // Option 1: resolve() waits for ready internally\n * const db = await scope.resolve(dbAtom)\n *\n * // Option 2: explicit wait\n * await scope.ready\n * const db = await scope.resolve(dbAtom)\n * ```\n */\nexport function createScope(options?: Lite.ScopeOptions): Lite.Scope {\n return new ScopeImpl(options)\n}\n","export type { Lite, AtomState } from \"./types\"\nexport {\n atomSymbol,\n flowSymbol,\n tagSymbol,\n taggedSymbol,\n controllerDepSymbol,\n presetSymbol,\n controllerSymbol,\n tagExecutorSymbol,\n typedSymbol,\n resourceSymbol,\n} from \"./symbols\"\nexport { tag, tags, isTag, isTagged, isTagExecutor, getAllTags } from \"./tag\"\nexport { atom, isAtom, controller, isControllerDep } from \"./atom\"\nexport { flow, isFlow, typed } from \"./flow\"\nexport { preset, isPreset } from \"./preset\"\nexport { resource, isResource } from \"./resource\"\nexport { service } from \"./service\"\nexport { createScope } from \"./scope\"\nexport { ParseError } from \"./errors\"\n\nexport const VERSION = \"0.0.1\"\n"],"mappings":";AAAA,MAAaA,aAA4B,OAAO,IAAI,uBAAuB;AAC3E,MAAaC,aAA4B,OAAO,IAAI,uBAAuB;AAC3E,MAAaC,YAA2B,OAAO,IAAI,sBAAsB;AACzE,MAAaC,eAA8B,OAAO,IAAI,yBAAyB;AAC/E,MAAaC,sBAAqC,OAAO,IAAI,iCAAiC;AAC9F,MAAaC,eAA8B,OAAO,IAAI,yBAAyB;AAC/E,MAAaC,mBAAkC,OAAO,IAAI,6BAA6B;AACvF,MAAaC,oBAAmC,OAAO,IAAI,+BAA+B;AAC1F,MAAaC,cAA6B,OAAO,IAAI,wBAAwB;AAC7E,MAAaC,iBAAgC,OAAO,IAAI,2BAA2B;;;;ACTnF,IAAa,aAAb,cAAgC,MAAM;CACpC,AAAkB,OAAO;CAEzB,YACE,SACA,AAASC,OACT,AAASC,OACT,AAAkBC,OAClB;AACA,QAAM,QAAQ;EAJL;EACA;EACS;;;;;;ACGtB,MAAM,2BAAW,IAAI,SAAoE;AACzF,MAAMC,cAAqD,EAAE;;;;;;;;;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;;AA8BxC,SAAgB,YAAY,SAAyC;AACnE,QAAO,IAAI,UAAU,QAAQ;;;;;AC7oC/B,MAAa,UAAU"}
1
+ {"version":3,"file":"index.mjs","names":["atomSymbol: unique symbol","flowSymbol: unique symbol","tagSymbol: unique symbol","taggedSymbol: unique symbol","controllerDepSymbol: unique symbol","presetSymbol: unique symbol","controllerSymbol: unique symbol","tagExecutorSymbol: unique symbol","typedSymbol: unique symbol","resourceSymbol: unique symbol","phase: \"tag\" | \"flow-input\"","label: string","cause: unknown","tagRegistry: WeakRef<Lite.Tag<unknown, boolean>>[]","live: Lite.Tag<unknown, boolean>[]","liveRefs: WeakRef<Lite.Tag<unknown, boolean>>[]","tag","tags","atom","live: Lite.Atom<unknown>[]","liveRefs: WeakRef<Lite.Atom<unknown>>[]","tagInstance: Lite.Tag<T, boolean>","result: T[]","atomInstance: Lite.Atom<T>","atomInstance: Lite.Atom<T>","resource","parentData?: Lite.ContextData","tag","ctrl: Lite.Controller<T>","selector: (value: T) => S","eq: (prev: S, next: S) => boolean","atom: Lite.Atom<T>","scope: ScopeImpl","atom","ctx: Lite.ResolveContext","event: Lite.ResolveEvent","result: Record<string, unknown>","parallel: Promise<void>[]","deferredResources: [string, Lite.Resource<unknown>][]","results: T[]","current: Lite.ExecutionContext | undefined","flow","parsedInput: unknown"],"sources":["../src/symbols.ts","../src/errors.ts","../src/tag.ts","../src/atom.ts","../src/flow.ts","../src/preset.ts","../src/resource.ts","../src/service.ts","../src/equality.ts","../src/scope.ts","../src/index.ts"],"sourcesContent":["export const atomSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/atom\")\nexport const flowSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/flow\")\nexport const tagSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/tag\")\nexport const taggedSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/tagged\")\nexport const controllerDepSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/controller-dep\")\nexport const presetSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/preset\")\nexport const controllerSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/controller\")\nexport const tagExecutorSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/tag-executor\")\nexport const typedSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/typed\")\nexport const resourceSymbol: unique symbol = Symbol.for(\"@pumped-fn/lite/resource\")\n","export class ParseError extends Error {\n override readonly name = \"ParseError\"\n\n constructor(\n message: string,\n readonly phase: \"tag\" | \"flow-input\",\n readonly label: string,\n override readonly cause: unknown\n ) {\n super(message)\n }\n}\n","import { tagSymbol, taggedSymbol, tagExecutorSymbol } from \"./symbols\"\nimport { ParseError } from \"./errors\"\nimport type { Lite } from \"./types\"\n\nexport interface TagOptions<T, HasDefault extends boolean> {\n label: string\n default?: HasDefault extends true ? T : never\n parse?: (raw: unknown) => T\n}\n\nconst registry = new WeakMap<Lite.Tag<unknown, boolean>, WeakRef<Lite.Atom<unknown>>[]>()\nconst tagRegistry: WeakRef<Lite.Tag<unknown, boolean>>[] = []\n\n/**\n * Returns all tags that have been created.\n *\n * Uses WeakRef internally so tags can be garbage collected when no longer referenced.\n * Stale references are cleaned up lazily on each call (not between calls).\n *\n * @returns Array of all live Tag instances. Returns `Tag<unknown, boolean>[]` because\n * the registry cannot preserve individual tag type parameters at runtime.\n *\n * Performance: O(n) where n = total tags created. For typical usage (< 100 tags),\n * this is negligible. Cleanup happens during query, not continuously.\n *\n * @example\n * ```typescript\n * const allTags = getAllTags()\n * for (const t of allTags) {\n * console.log(t.label, t.atoms().length)\n * }\n * ```\n */\nexport function getAllTags(): Lite.Tag<unknown, boolean>[] {\n const live: Lite.Tag<unknown, boolean>[] = []\n const liveRefs: WeakRef<Lite.Tag<unknown, boolean>>[] = []\n\n for (const ref of tagRegistry) {\n const tag = ref.deref()\n if (tag) {\n live.push(tag)\n liveRefs.push(ref)\n }\n }\n\n tagRegistry.length = 0\n tagRegistry.push(...liveRefs)\n\n return live\n}\n\nexport function registerAtomToTags(\n atom: Lite.Atom<unknown>,\n tags: Lite.Tagged<any>[]\n): void {\n for (const tagged of tags) {\n let refs = registry.get(tagged.tag)\n if (!refs) {\n refs = []\n registry.set(tagged.tag, refs)\n }\n refs.push(new WeakRef(atom))\n }\n}\n\nfunction getAtomsForTag(tag: Lite.Tag<unknown, boolean>): Lite.Atom<unknown>[] {\n const refs = registry.get(tag)\n if (!refs) return []\n\n const live: Lite.Atom<unknown>[] = []\n const liveRefs: WeakRef<Lite.Atom<unknown>>[] = []\n\n for (const ref of refs) {\n const atom = ref.deref()\n if (atom) {\n live.push(atom)\n liveRefs.push(ref)\n }\n }\n\n if (liveRefs.length > 0) {\n registry.set(tag, liveRefs)\n } else {\n registry.delete(tag)\n }\n\n return live\n}\n\n/**\n * Creates a metadata tag for attaching and retrieving typed values from Atoms and Flows.\n *\n * @param options - Configuration object with label and optional default value\n * @returns A Tag instance that can create tagged values and query them from sources\n *\n * @example\n * ```typescript\n * const nameTag = tag<string>({ label: \"name\" })\n * const myAtom = atom({\n * factory: (ctx) => \"value\",\n * tags: [nameTag(\"MyAtom\")]\n * })\n * ```\n */\nexport function tag<T>(options: { label: string }): Lite.Tag<T, false>\nexport function tag<T>(options: {\n label: string\n default: T\n}): Lite.Tag<T, true>\nexport function tag<T>(options: {\n label: string\n parse: (raw: unknown) => T\n}): Lite.Tag<T, false>\nexport function tag<T>(options: {\n label: string\n parse: (raw: unknown) => T\n default: T\n}): Lite.Tag<T, true>\nexport function tag<T>(options: TagOptions<T, boolean>): Lite.Tag<T, boolean> {\n const key = Symbol(`@pumped-fn/lite/tag/${options.label}`)\n const hasDefault = \"default\" in options\n const defaultValue = hasDefault ? options.default : undefined\n const parse = options.parse\n\n let tagInstance: Lite.Tag<T, boolean>\n\n function createTagged(value: T): Lite.Tagged<T> {\n let validatedValue = value\n if (parse) {\n try {\n validatedValue = parse(value)\n } catch (err) {\n throw new ParseError(\n `Failed to parse tag \"${options.label}\"`,\n \"tag\",\n options.label,\n err\n )\n }\n }\n return {\n [taggedSymbol]: true,\n key,\n value: validatedValue,\n tag: tagInstance,\n }\n }\n\n function get(source: Lite.TagSource): T {\n const tags = Array.isArray(source) ? source : source.tags ?? []\n for (let i = 0; i < tags.length; i++) {\n if (tags[i]!.key === key) return tags[i]!.value as unknown as T\n }\n if (hasDefault) return defaultValue as unknown as T\n throw new Error(`Tag \"${options.label}\" not found and has no default`)\n }\n\n function find(source: Lite.TagSource): T | undefined {\n const tags = Array.isArray(source) ? source : source.tags ?? []\n for (let i = 0; i < tags.length; i++) {\n if (tags[i]!.key === key) return tags[i]!.value as unknown as T\n }\n if (hasDefault) return defaultValue as unknown as T\n return undefined\n }\n\n function collect(source: Lite.TagSource): T[] {\n const tags = Array.isArray(source) ? source : source.tags ?? []\n const result: T[] = []\n for (let i = 0; i < tags.length; i++) {\n if (tags[i]!.key === key) result.push(tags[i]!.value as unknown as T)\n }\n return result\n }\n\n /**\n * Returns all atoms that have been created with this tag.\n *\n * Uses WeakRef internally so atoms can be garbage collected when no longer referenced.\n * Stale references are cleaned up lazily on each call.\n *\n * @returns Array of atoms using this tag. Returns `Atom<unknown>[]` because multiple\n * atom types with different return types can use the same tag - TypeScript cannot\n * track this runtime relationship.\n *\n * Performance: O(n) where n = atoms using this tag. Cleanup happens during query.\n */\n function atoms(): Lite.Atom<unknown>[] {\n return getAtomsForTag(tagInstance as Lite.Tag<unknown, boolean>)\n }\n\n tagInstance = Object.assign(createTagged, {\n [tagSymbol]: true as const,\n key,\n label: options.label,\n hasDefault,\n defaultValue,\n parse,\n get,\n find,\n collect,\n atoms,\n }) as unknown as Lite.Tag<T, boolean>\n\n tagRegistry.push(new WeakRef(tagInstance as Lite.Tag<unknown, boolean>))\n\n return tagInstance\n}\n\n/**\n * Type guard to check if a value is a Tag.\n *\n * @param value - The value to check\n * @returns True if the value is a Tag, false otherwise\n *\n * @example\n * ```typescript\n * if (isTag(value)) {\n * const tagged = value(\"myValue\")\n * }\n * ```\n */\nexport function isTag(value: unknown): value is Lite.Tag<unknown, boolean> {\n return (\n typeof value === \"function\" &&\n (value as unknown as Record<symbol, unknown>)[tagSymbol] === true\n )\n}\n\n/**\n * Type guard to check if a value is a Tagged value.\n *\n * @param value - The value to check\n * @returns True if the value is a Tagged value, false otherwise\n *\n * @example\n * ```typescript\n * if (isTagged(value)) {\n * console.log(value.key, value.value)\n * }\n * ```\n */\nexport function isTagged(value: unknown): value is Lite.Tagged<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<symbol, unknown>)[taggedSymbol] === true\n )\n}\n\n/**\n * Tag execution helpers for declaring how tags should be resolved from dependency sources.\n */\nexport const tags = {\n /**\n * Creates a required tag executor that throws if the tag is not found.\n *\n * @param tag - The tag to execute\n * @returns A tag executor that requires the tag to be present\n *\n * @example\n * ```typescript\n * const myAtom = atom({\n * deps: { name: tags.required(nameTag) },\n * factory: (ctx, { name }) => `Hello ${name}`\n * })\n * ```\n */\n required<T>(tag: Lite.Tag<T, boolean>): Lite.TagExecutor<T, T> {\n return { [tagExecutorSymbol]: true, tag, mode: \"required\" }\n },\n\n /**\n * Creates an optional tag executor that returns undefined if the tag is not found.\n *\n * @param tag - The tag to execute\n * @returns A tag executor that allows the tag to be absent\n *\n * @example\n * ```typescript\n * const myAtom = atom({\n * deps: { name: tags.optional(nameTag) },\n * factory: (ctx, { name }) => name ?? \"Anonymous\"\n * })\n * ```\n */\n optional<T>(tag: Lite.Tag<T, boolean>): Lite.TagExecutor<T | undefined, T> {\n return { [tagExecutorSymbol]: true, tag, mode: \"optional\" }\n },\n\n /**\n * Creates a tag executor that collects all values for the given tag.\n *\n * @param tag - The tag to execute\n * @returns A tag executor that returns an array of all matching tag values\n *\n * @example\n * ```typescript\n * const myAtom = atom({\n * deps: { names: tags.all(nameTag) },\n * factory: (ctx, { names }) => names.join(\", \")\n * })\n * ```\n */\n all<T>(tag: Lite.Tag<T, boolean>): Lite.TagExecutor<T[], T> {\n return { [tagExecutorSymbol]: true, tag, mode: \"all\" }\n },\n}\n\n/**\n * Type guard to check if a value is a TagExecutor.\n *\n * @param value - The value to check\n * @returns True if the value is a TagExecutor, false otherwise\n *\n * @example\n * ```typescript\n * if (isTagExecutor(value)) {\n * console.log(value.mode, value.tag)\n * }\n * ```\n */\nexport function isTagExecutor(value: unknown): value is Lite.TagExecutor<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n tagExecutorSymbol in value\n )\n}\n","import { atomSymbol, controllerDepSymbol } from \"./symbols\"\nimport { registerAtomToTags } from \"./tag\"\nimport type { Lite, MaybePromise } from \"./types\"\n\nexport interface AtomConfig<T, D extends Record<string, Lite.Dependency>> {\n deps?: D\n factory: Lite.AtomFactory<T, D>\n tags?: Lite.Tagged<any>[]\n keepAlive?: boolean\n}\n\n/**\n * Creates a long-lived dependency that can be resolved and reused within a scope.\n *\n * @param config - Configuration object containing factory function, optional dependencies, and tags\n * @returns An Atom instance that can be resolved to produce a value of type T\n *\n * @example\n * ```typescript\n * const dbAtom = atom({\n * factory: async (ctx) => createDatabase()\n * })\n * ```\n */\nexport function atom<T>(config: {\n deps?: undefined\n factory: (ctx: Lite.ResolveContext) => MaybePromise<T>\n tags?: Lite.Tagged<any>[]\n keepAlive?: boolean\n}): Lite.Atom<T>\n\nexport function atom<\n T,\n const D extends Record<string, Lite.Atom<unknown> | Lite.ControllerDep<unknown> | { mode: string }>,\n>(config: {\n deps: D\n factory: (ctx: Lite.ResolveContext, deps: Lite.InferDeps<D>) => MaybePromise<T>\n tags?: Lite.Tagged<any>[]\n keepAlive?: boolean\n}): Lite.Atom<T>\n\nexport function atom<T, D extends Record<string, Lite.Dependency>>(\n config: AtomConfig<T, D>\n): Lite.Atom<T> {\n const atomInstance: Lite.Atom<T> = {\n [atomSymbol]: true,\n factory: config.factory as unknown as Lite.AtomFactory<T, Record<string, Lite.Dependency>>,\n deps: config.deps as unknown as Record<string, Lite.Dependency> | undefined,\n tags: config.tags,\n keepAlive: config.keepAlive,\n }\n\n if (config.tags?.length) {\n registerAtomToTags(atomInstance, config.tags)\n }\n\n return atomInstance\n}\n\n/**\n * Type guard to check if a value is an Atom.\n *\n * @param value - The value to check\n * @returns True if the value is an Atom, false otherwise\n *\n * @example\n * ```typescript\n * if (isAtom(value)) {\n * await scope.resolve(value)\n * }\n * ```\n */\nexport function isAtom(value: unknown): value is Lite.Atom<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<symbol, unknown>)[atomSymbol] === true\n )\n}\n\n/**\n * Wraps an Atom to receive a Controller instead of the resolved value.\n * The Controller provides full lifecycle control: get, resolve, release, invalidate, and subscribe.\n *\n * @param atom - The Atom to wrap\n * @param options - Optional configuration:\n * - `resolve: true` — auto-resolves the dep before the parent factory runs; `config.get()` is safe.\n * - `watch: true` — atom deps only; requires `resolve: true`; automatically re-runs the parent factory\n * when the dep resolves to a new value (value-equality gated via plain-object `shallowEqual` by default,\n * otherwise `Object.is`). Replaces\n * manual `ctx.cleanup(ctx.scope.on('resolved', dep, () => ctx.invalidate()))` wiring. Watch\n * listeners are auto-cleaned on re-resolve, release, and dispose.\n * - `eq` — custom equality function `(a: T, b: T) => boolean`; only used with `watch: true`.\n * @returns A ControllerDep that resolves to a Controller for the Atom\n *\n * @example\n * ```typescript\n * // resolve only\n * const serverAtom = atom({\n * deps: { config: controller(configAtom, { resolve: true }) },\n * factory: (_, { config }) => createServer(config.get().port),\n * })\n *\n * // watch: re-runs parent when dep value changes\n * const profileAtom = atom({\n * deps: { token: controller(tokenAtom, { resolve: true, watch: true }) },\n * factory: (_, { token }) => ({ id: `user-${token.get().jwt}` }),\n * })\n *\n * // watch with custom equality\n * const derivedAtom = atom({\n * deps: { src: controller(srcAtom, { resolve: true, watch: true, eq: (a, b) => a.id === b.id }) },\n * factory: (_, { src }) => src.get().name,\n * })\n * ```\n */\nexport function controller<T>(\n atom: Lite.Atom<T>,\n options?: Lite.ControllerDepOptions<T>\n): Lite.ControllerDep<T> {\n return {\n [controllerDepSymbol]: true,\n atom,\n resolve: options?.resolve,\n watch: options?.watch,\n eq: options?.eq,\n }\n}\n\n/**\n * Type guard to check if a value is a ControllerDep wrapper.\n *\n * @param value - The value to check\n * @returns True if the value is a ControllerDep wrapper, false otherwise\n *\n * @example\n * ```typescript\n * if (isControllerDep(dep)) {\n * const ctrl = scope.controller(dep.atom)\n * }\n * ```\n */\nexport function isControllerDep(value: unknown): value is Lite.ControllerDep<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<symbol, unknown>)[controllerDepSymbol] === true\n )\n}\n","import { flowSymbol, typedSymbol } from \"./symbols\"\nimport type { Lite, MaybePromise } from \"./types\"\n\n/**\n * Type marker for flow input without runtime parsing.\n * Use this when you want typed input but don't need validation.\n *\n * @example\n * ```typescript\n * const myFlow = flow({\n * parse: typed<{ name: string }>(),\n * factory: (ctx) => {\n * return ctx.input.name.toUpperCase()\n * }\n * })\n * ```\n */\nexport function typed<T>(): Lite.Typed<T> {\n return { [typedSymbol]: true }\n}\n\nexport interface FlowConfig<\n Output,\n Input,\n D extends Record<string, Lite.Dependency>,\n> {\n name?: string\n parse?: ((raw: unknown) => MaybePromise<Input>) | Lite.Typed<Input>\n deps?: D\n factory: Lite.FlowFactory<Output, Input, D>\n tags?: Lite.Tagged<any>[]\n}\n\n/**\n * Creates a short-lived execution unit that processes input and produces output.\n *\n * @param config - Configuration object containing factory function, optional dependencies, and tags\n * @returns A Flow instance that can be executed within an execution context\n *\n * @example\n * ```typescript\n * const processUser = flow({\n * factory: async (ctx) => {\n * const userId = ctx.input\n * return await fetchUser(userId)\n * }\n * })\n * ```\n */\nexport function flow<TOutput>(config: {\n name?: string\n parse?: undefined\n deps?: undefined\n factory: (ctx: Lite.ExecutionContext) => MaybePromise<TOutput>\n tags?: Lite.Tagged<any>[]\n}): Lite.Flow<TOutput, void>\n\nexport function flow<TOutput, TInput>(config: {\n name?: string\n parse: (raw: unknown) => MaybePromise<TInput>\n deps?: undefined\n factory: (ctx: Lite.ExecutionContext & { readonly input: NoInfer<TInput> }) => MaybePromise<TOutput>\n tags?: Lite.Tagged<any>[]\n}): Lite.Flow<TOutput, TInput>\n\nexport function flow<TOutput, TInput>(config: {\n name?: string\n parse: Lite.Typed<TInput>\n deps?: undefined\n factory: (ctx: Lite.ExecutionContext & { readonly input: NoInfer<TInput> }) => MaybePromise<TOutput>\n tags?: Lite.Tagged<any>[]\n}): Lite.Flow<TOutput, TInput>\n\nexport function flow<\n TOutput,\n const D extends Record<string, Lite.Atom<unknown> | Lite.ControllerDep<unknown> | Lite.Resource<unknown, Record<string, Lite.Dependency>> | { mode: string }>,\n>(config: {\n name?: string\n parse?: undefined\n deps: D\n factory: (ctx: Lite.ExecutionContext, deps: Lite.InferDeps<D>) => MaybePromise<TOutput>\n tags?: Lite.Tagged<any>[]\n}): Lite.Flow<TOutput, void>\n\nexport function flow<\n TOutput,\n TInput,\n const D extends Record<string, Lite.Atom<unknown> | Lite.ControllerDep<unknown> | Lite.Resource<unknown, Record<string, Lite.Dependency>> | { mode: string }>,\n>(config: {\n name?: string\n parse: (raw: unknown) => MaybePromise<TInput>\n deps: D\n factory: (ctx: Lite.ExecutionContext & { readonly input: NoInfer<TInput> }, deps: Lite.InferDeps<D>) => MaybePromise<TOutput>\n tags?: Lite.Tagged<any>[]\n}): Lite.Flow<TOutput, TInput>\n\nexport function flow<\n TOutput,\n TInput,\n const D extends Record<string, Lite.Atom<unknown> | Lite.ControllerDep<unknown> | Lite.Resource<unknown, Record<string, Lite.Dependency>> | { mode: string }>,\n>(config: {\n name?: string\n parse: Lite.Typed<TInput>\n deps: D\n factory: (ctx: Lite.ExecutionContext & { readonly input: NoInfer<TInput> }, deps: Lite.InferDeps<D>) => MaybePromise<TOutput>\n tags?: Lite.Tagged<any>[]\n}): Lite.Flow<TOutput, TInput>\n\nexport function flow<\n TOutput,\n TInput,\n D extends Record<string, Lite.Dependency>,\n>(config: FlowConfig<TOutput, TInput, D>): Lite.Flow<TOutput, TInput> {\n const parse = config.parse\n const isTypedMarker =\n typeof parse === \"object\" && parse !== null && typedSymbol in parse\n\n return {\n [flowSymbol]: true,\n name: config.name,\n parse: isTypedMarker\n ? undefined\n : (parse as ((raw: unknown) => MaybePromise<TInput>) | undefined),\n factory: config.factory as unknown as Lite.FlowFactory<\n TOutput,\n TInput,\n Record<string, Lite.Dependency>\n >,\n deps: config.deps as unknown as Record<string, Lite.Dependency> | undefined,\n tags: config.tags,\n }\n}\n\n/**\n * Type guard to check if a value is a Flow.\n *\n * @param value - The value to check\n * @returns True if the value is a Flow, false otherwise\n *\n * @example\n * ```typescript\n * if (isFlow(value)) {\n * await ctx.exec({ flow: value, input: data })\n * }\n * ```\n */\nexport function isFlow(value: unknown): value is Lite.Flow<unknown, unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<symbol, unknown>)[flowSymbol] === true\n )\n}\n","import { presetSymbol } from \"./symbols\"\nimport type { Lite, MaybePromise } from \"./types\"\nimport { isAtom } from \"./atom\"\nimport { isFlow } from \"./flow\"\n\n/**\n * Creates a preset that overrides an Atom's factory within a scope.\n *\n * @param target - The Atom to preset\n * @param value - The preset value (can be a direct value or another Atom)\n * @returns A Preset instance to be used in scope configuration\n *\n * @example\n * ```typescript\n * const scope = createScope({\n * presets: [preset(dbAtom, mockDatabase)]\n * })\n * ```\n */\nexport function preset<T>(\n target: Lite.Atom<T>,\n value: T | Lite.Atom<T>\n): Lite.Preset<T>\n\n/**\n * Creates a preset that overrides a Flow's execution within a scope.\n *\n * @param target - The Flow to preset\n * @param value - The replacement (another Flow or a function that receives ctx with parsed input)\n * @returns A Preset instance to be used in scope configuration\n *\n * @example\n * ```typescript\n * // Replace with another flow\n * const scope = createScope({\n * presets: [preset(processFlow, mockProcessFlow)]\n * })\n *\n * // Replace with a function (deps are NOT resolved)\n * const scope = createScope({\n * presets: [preset(processFlow, (ctx) => ({ result: ctx.input }))]\n * })\n * ```\n */\nexport function preset<TOutput, TInput>(\n target: Lite.Flow<TOutput, TInput>,\n value: Lite.Flow<TOutput, TInput> | ((ctx: Lite.ExecutionContext & { readonly input: TInput }) => MaybePromise<TOutput>)\n): Lite.Preset<TOutput, TInput>\n\nexport function preset<T, I>(\n target: Lite.PresetTarget<T, I>,\n value: Lite.PresetValue<T, I>\n): Lite.Preset<T, I> {\n if (!isAtom(target) && !isFlow(target)) {\n throw new Error(\"preset target must be Atom or Flow\")\n }\n if (target === value) {\n throw new Error(\"preset cannot reference itself\")\n }\n return {\n [presetSymbol]: true,\n target,\n value,\n }\n}\n\n/**\n * Type guard to check if a value is a Preset.\n *\n * @param value - The value to check\n * @returns True if the value is a Preset, false otherwise\n *\n * @example\n * ```typescript\n * if (isPreset(value)) {\n * console.log(value.target, value.value)\n * }\n * ```\n */\nexport function isPreset(value: unknown): value is Lite.Preset<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<symbol, unknown>)[presetSymbol] === true\n )\n}\n","import { resourceSymbol } from \"./symbols\"\nimport type { Lite, MaybePromise } from \"./types\"\n\n/**\n * Creates an execution-scoped dependency that is resolved per execution chain.\n * Fresh instance on first encounter, seek-up on nested execs within the same chain.\n *\n * @param config - Configuration object containing factory function and optional dependencies\n * @returns A Resource instance that can be declared as a dependency in flows and other resources\n *\n * @example\n * ```typescript\n * const requestLogger = resource({\n * deps: { logService: logServiceAtom },\n * factory: (ctx, { logService }) => {\n * const logger = logService.child({ requestId: ctx.data.get(\"requestId\") })\n * ctx.onClose(() => logger.flush())\n * return logger\n * }\n * })\n * ```\n */\nexport function resource<T>(config: {\n name?: string\n deps?: undefined\n factory: (ctx: Lite.ExecutionContext) => MaybePromise<T>\n}): Lite.Resource<T>\n\nexport function resource<\n T,\n const D extends Record<string, Lite.Atom<unknown> | Lite.ControllerDep<unknown> | Lite.Resource<unknown, Record<string, Lite.Dependency>> | { mode: string }>,\n>(config: {\n name?: string\n deps: D\n factory: (ctx: Lite.ExecutionContext, deps: Lite.InferDeps<D>) => MaybePromise<T>\n}): Lite.Resource<T>\n\nexport function resource<T, D extends Record<string, Lite.Dependency>>(\n config: {\n name?: string\n deps?: D\n factory: Lite.ResourceFactory<T, D>\n }\n): Lite.Resource<T> {\n return Object.freeze({\n [resourceSymbol]: true,\n name: config.name,\n deps: config.deps as unknown as Record<string, Lite.Dependency> | undefined,\n factory: config.factory as unknown as Lite.ResourceFactory<T, Record<string, Lite.Dependency>>,\n }) as Lite.Resource<T>\n}\n\n/**\n * Type guard to check if a value is a Resource.\n *\n * @param value - The value to check\n * @returns True if the value is a Resource, false otherwise\n *\n * @example\n * ```typescript\n * if (isResource(value)) {\n * // value is Lite.Resource<unknown>\n * }\n * ```\n */\nexport function isResource(value: unknown): value is Lite.Resource<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<symbol, unknown>)[resourceSymbol] === true\n )\n}\n","import { atomSymbol } from \"./symbols\"\nimport { registerAtomToTags } from \"./tag\"\nimport type { Lite, MaybePromise } from \"./types\"\n\n/** Creates an atom with methods constrained to (ctx: ExecutionContext, ...args) => result. */\nexport function service<T extends Lite.ServiceMethods>(config: {\n deps?: undefined\n factory: (ctx: Lite.ResolveContext) => MaybePromise<T>\n tags?: Lite.Tagged<any>[]\n}): Lite.Atom<T>\n\nexport function service<\n T extends Lite.ServiceMethods,\n const D extends Record<string, Lite.Atom<unknown> | Lite.ControllerDep<unknown> | Lite.TagExecutor<any>>,\n>(config: {\n deps: D\n factory: (ctx: Lite.ResolveContext, deps: Lite.InferDeps<D>) => MaybePromise<T>\n tags?: Lite.Tagged<any>[]\n}): Lite.Atom<T>\n\nexport function service<T extends Lite.ServiceMethods, D extends Record<string, Lite.Dependency>>(config: {\n deps?: D\n factory: Lite.AtomFactory<T, D>\n tags?: Lite.Tagged<any>[]\n}): Lite.Atom<T> {\n const atomInstance: Lite.Atom<T> = {\n [atomSymbol]: true,\n factory: config.factory as unknown as Lite.AtomFactory<T, Record<string, Lite.Dependency>>,\n deps: config.deps as unknown as Record<string, Lite.Dependency> | undefined,\n tags: config.tags,\n }\n\n if (config.tags?.length) {\n registerAtomToTags(atomInstance, config.tags)\n }\n\n return atomInstance\n}\n","function isPlainObject(value: object): value is Record<PropertyKey, unknown> {\n const prototype = Object.getPrototypeOf(value)\n return prototype === Object.prototype || prototype === null\n}\n\nfunction enumerableOwnKeys(value: object): Array<string | symbol> {\n return Reflect.ownKeys(value).filter((key) => Object.prototype.propertyIsEnumerable.call(value, key))\n}\n\nexport function shallowEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true\n if (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) return false\n if (!isPlainObject(a) || !isPlainObject(b)) return false\n\n const objA = a as Record<PropertyKey, unknown>\n const objB = b as Record<PropertyKey, unknown>\n const keysA = enumerableOwnKeys(objA)\n if (keysA.length !== enumerableOwnKeys(objB).length) return false\n\n for (const key of keysA) {\n if (!Object.hasOwn(objB, key)) return false\n if (!Object.is(objA[key], objB[key])) return false\n }\n\n return true\n}\n","import { controllerSymbol, tagExecutorSymbol } from \"./symbols\"\nimport type { Lite, MaybePromise, AtomState } from \"./types\"\nimport { isAtom, isControllerDep } from \"./atom\"\nimport { shallowEqual } from \"./equality\"\nimport { isFlow } from \"./flow\"\nimport { isResource } from \"./resource\"\nimport { ParseError } from \"./errors\"\n\nconst resourceKeys = new WeakMap<Lite.Resource<unknown>, symbol>()\nlet resourceKeyCounter = 0\n\nfunction getResourceKey(resource: Lite.Resource<unknown>): symbol {\n let key = resourceKeys.get(resource)\n if (!key) {\n key = Symbol(`resource:${resource.name ?? resourceKeyCounter++}`)\n resourceKeys.set(resource, key)\n }\n return key\n}\n\nconst inflightResources = new WeakMap<Lite.ContextData, Map<symbol, Promise<unknown>>>()\nconst resolvingResourcesMap = new WeakMap<Lite.ContextData, Set<symbol>>()\n\ntype ListenerEvent = 'resolving' | 'resolved' | '*'\n\nclass ContextDataImpl implements Lite.ContextData {\n private readonly map = new Map<string | symbol, unknown>()\n\n constructor(\n private readonly parentData?: Lite.ContextData\n ) {}\n\n // Raw Map operations\n get(key: string | symbol): unknown {\n return this.map.get(key)\n }\n\n set(key: string | symbol, value: unknown): void {\n this.map.set(key, value)\n }\n\n has(key: string | symbol): boolean {\n return this.map.has(key)\n }\n\n delete(key: string | symbol): boolean {\n return this.map.delete(key)\n }\n\n clear(): void {\n this.map.clear()\n }\n\n seek(key: string | symbol): unknown {\n if (this.map.has(key)) {\n return this.map.get(key)\n }\n return this.parentData?.seek(key)\n }\n\n seekHas(key: string | symbol): boolean {\n if (this.map.has(key)) return true\n return this.parentData?.seekHas(key) ?? false\n }\n\n // Tag-based operations\n getTag<T>(tag: Lite.Tag<T, boolean>): T | undefined {\n return this.map.get(tag.key) as T | undefined\n }\n\n setTag<T>(tag: Lite.Tag<T, boolean>, value: T): void {\n this.map.set(tag.key, value)\n }\n\n hasTag<T, H extends boolean>(tag: Lite.Tag<T, H>): boolean {\n return this.map.has(tag.key)\n }\n\n deleteTag<T, H extends boolean>(tag: Lite.Tag<T, H>): boolean {\n return this.map.delete(tag.key)\n }\n\n seekTag<T>(tag: Lite.Tag<T, boolean>): T | undefined {\n if (this.map.has(tag.key)) {\n return this.map.get(tag.key) as T\n }\n return this.parentData?.seekTag(tag)\n }\n\n getOrSetTag<T>(tag: Lite.Tag<T, true>): T\n getOrSetTag<T>(tag: Lite.Tag<T, true>, value: T): T\n getOrSetTag<T>(tag: Lite.Tag<T, false>, value: T): T\n getOrSetTag<T>(tag: Lite.Tag<T, boolean>, value?: T): T {\n if (this.map.has(tag.key)) {\n return this.map.get(tag.key) as T\n }\n const storedValue = value !== undefined ? value : (tag.defaultValue as T)\n this.map.set(tag.key, storedValue)\n return storedValue\n }\n}\n\ninterface AtomEntry<T> {\n state: AtomState\n value?: T\n hasValue: boolean\n error?: Error\n cleanups: (() => MaybePromise<void>)[]\n listeners: Map<ListenerEvent, Set<() => void>>\n pendingInvalidate: boolean\n pendingSet?: { value: T } | { fn: (prev: T) => T }\n data?: ContextDataImpl\n dependents: Set<Lite.Atom<unknown>>\n gcScheduled: ReturnType<typeof setTimeout> | null\n}\n\nclass SelectHandleImpl<T, S> implements Lite.SelectHandle<S> {\n private listeners = new Set<() => void>()\n private currentValue: S\n private ctrlUnsub: (() => void) | null = null\n\n constructor(\n private ctrl: Lite.Controller<T>,\n private selector: (value: T) => S,\n private eq: (prev: S, next: S) => boolean\n ) {\n if (ctrl.state !== 'resolved') {\n throw new Error(\"Cannot select from unresolved atom\")\n }\n\n this.currentValue = selector(ctrl.get())\n this.ctrlUnsub = ctrl.on('resolved', () => {\n const nextValue = this.selector(this.ctrl.get())\n if (!this.eq(this.currentValue, nextValue)) {\n this.currentValue = nextValue\n this.notifyListeners()\n }\n })\n }\n\n get(): S {\n return this.currentValue\n }\n\n subscribe(listener: () => void): () => void {\n if (!this.ctrlUnsub) {\n this.currentValue = this.selector(this.ctrl.get())\n this.ctrlUnsub = this.ctrl.on('resolved', () => {\n const nextValue = this.selector(this.ctrl.get())\n if (!this.eq(this.currentValue, nextValue)) {\n this.currentValue = nextValue\n this.notifyListeners()\n }\n })\n }\n this.listeners.add(listener)\n\n return () => {\n this.listeners.delete(listener)\n if (this.listeners.size === 0) {\n this.cleanup()\n }\n }\n }\n\n private notifyListeners(): void {\n for (const listener of [...this.listeners]) {\n listener()\n }\n }\n\n dispose(): void {\n this.listeners.clear()\n this.cleanup()\n }\n\n private cleanup(): void {\n this.ctrlUnsub?.()\n this.ctrlUnsub = null\n }\n}\n\nclass ControllerImpl<T> implements Lite.Controller<T> {\n readonly [controllerSymbol] = true\n\n constructor(\n private atom: Lite.Atom<T>,\n private scope: ScopeImpl\n ) {}\n\n get state(): AtomState {\n const entry = this.scope.getEntry(this.atom)\n return entry?.state ?? 'idle'\n }\n\n get(): T {\n const entry = this.scope.getEntry(this.atom)\n if (!entry || entry.state === 'idle') {\n throw new Error(\"Atom not resolved\")\n }\n if (entry.state === 'failed' && entry.error) {\n throw entry.error\n }\n if (entry.state === 'resolving' && entry.hasValue) {\n return entry.value as T\n }\n if (entry.state === 'resolved' && entry.hasValue) {\n return entry.value as T\n }\n throw new Error(\"Atom not resolved\")\n }\n\n async resolve(): Promise<T> {\n return this.scope.resolve(this.atom)\n }\n\n async release(): Promise<void> {\n return this.scope.release(this.atom)\n }\n\n invalidate(): void {\n this.scope.invalidate(this.atom)\n }\n\n set(value: T): void {\n this.scope.scheduleSet(this.atom, value)\n }\n\n update(fn: (prev: T) => T): void {\n this.scope.scheduleUpdate(this.atom, fn)\n }\n\n on(event: ListenerEvent, listener: () => void): () => void {\n return this.scope.addListener(this.atom, event, listener)\n }\n}\n\nclass ScopeImpl implements Lite.Scope {\n private cache = new Map<Lite.Atom<unknown>, AtomEntry<unknown>>()\n private presets = new Map<Lite.Atom<unknown> | Lite.Flow<unknown, unknown>, unknown>()\n private resolving = new Set<Lite.Atom<unknown>>()\n private pending = new Map<Lite.Atom<unknown>, Promise<unknown>>()\n private stateListeners = new Map<AtomState, Map<Lite.Atom<unknown>, Set<() => void>>>()\n private invalidationQueue = new Set<Lite.Atom<unknown>>()\n private invalidationScheduled = false\n private invalidationChain: Set<Lite.Atom<unknown>> | null = null\n private chainPromise: Promise<void> | null = null\n private chainError: unknown = null\n private initialized = false\n private disposed = false\n private controllers = new Map<Lite.Atom<unknown>, ControllerImpl<unknown>>()\n private gcOptions: Required<Lite.GCOptions>\n readonly extensions: Lite.Extension[]\n readonly tags: Lite.Tagged<any>[]\n readonly resolveExts: Lite.Extension[]\n readonly execExts: Lite.Extension[]\n readonly ready: Promise<void>\n\n private scheduleInvalidation<T>(atom: Lite.Atom<T>): void {\n const entry = this.cache.get(atom) as AtomEntry<T> | undefined\n if (!entry || entry.state === \"idle\") return\n\n if (entry.state === \"resolving\") {\n entry.pendingInvalidate = true\n return\n }\n\n this.invalidationQueue.add(atom)\n\n if (!this.chainPromise) {\n this.invalidationChain = new Set()\n this.invalidationScheduled = true\n this.chainError = null\n const chainPromise = (async () => {\n await new Promise<void>((resolve) => {\n queueMicrotask(resolve)\n })\n\n try {\n await this.processInvalidationChain()\n } catch (error) {\n if (this.chainError === null) {\n this.chainError = error\n }\n }\n })()\n this.chainPromise = chainPromise\n }\n }\n\n private async processInvalidationChain(): Promise<void> {\n try {\n while (this.invalidationQueue.size > 0 && !this.disposed) {\n const atom = this.invalidationQueue.values().next().value as Lite.Atom<unknown>\n this.invalidationQueue.delete(atom)\n\n if (this.invalidationChain!.has(atom)) {\n const chainAtoms = Array.from(this.invalidationChain!)\n chainAtoms.push(atom)\n const path = chainAtoms\n .map(a => a.factory?.name || \"<anonymous>\")\n .join(\" → \")\n throw new Error(`Infinite invalidation loop detected: ${path}`)\n }\n\n this.invalidationChain!.add(atom)\n await this.doInvalidateSequential(atom)\n }\n } finally {\n this.invalidationChain = null\n this.chainPromise = null\n this.invalidationScheduled = false\n }\n }\n\n constructor(options?: Lite.ScopeOptions) {\n this.extensions = options?.extensions ?? []\n this.tags = options?.tags ?? []\n this.resolveExts = this.extensions.filter(e => e.wrapResolve)\n this.execExts = this.extensions.filter(e => e.wrapExec)\n\n for (const p of options?.presets ?? []) {\n this.presets.set(p.target, p.value)\n }\n\n this.gcOptions = {\n enabled: options?.gc?.enabled ?? true,\n graceMs: options?.gc?.graceMs ?? 3000,\n }\n\n this.ready = this.init()\n }\n\n private async init(): Promise<void> {\n for (const ext of this.extensions) {\n if (ext.init) {\n await ext.init(this)\n }\n }\n this.initialized = true\n }\n\n getEntry<T>(atom: Lite.Atom<T>): AtomEntry<T> | undefined {\n return this.cache.get(atom) as AtomEntry<T> | undefined\n }\n\n private getOrCreateEntry<T>(atom: Lite.Atom<T>): AtomEntry<T> {\n let entry = this.cache.get(atom) as AtomEntry<T> | undefined\n if (!entry) {\n entry = {\n state: 'idle',\n hasValue: false,\n cleanups: [],\n listeners: new Map([\n ['resolving', new Set()],\n ['resolved', new Set()],\n ['*', new Set()],\n ]),\n pendingInvalidate: false,\n dependents: new Set(),\n gcScheduled: null,\n }\n this.cache.set(atom, entry as AtomEntry<unknown>)\n }\n return entry\n }\n\n addListener<T>(atom: Lite.Atom<T>, event: ListenerEvent, listener: () => void): () => void {\n this.cancelScheduledGC(atom)\n \n const entry = this.getOrCreateEntry(atom)\n const listeners = entry.listeners.get(event)!\n listeners.add(listener)\n return () => {\n listeners.delete(listener)\n this.maybeScheduleGC(atom)\n }\n }\n\n private getSubscriberCount<T>(atom: Lite.Atom<T>): number {\n const entry = this.cache.get(atom)\n if (!entry) return 0\n let count = 0\n for (const listeners of entry.listeners.values()) {\n count += listeners.size\n }\n return count\n }\n\n private maybeScheduleGC<T>(atom: Lite.Atom<T>): void {\n if (!this.gcOptions.enabled) return\n if (atom.keepAlive) return\n \n const entry = this.cache.get(atom)\n if (!entry) return\n if (entry.state === 'idle') return\n \n const subscriberCount = this.getSubscriberCount(atom)\n if (subscriberCount > 0) return\n if (entry.dependents.size > 0) return\n \n if (entry.gcScheduled) return\n \n entry.gcScheduled = setTimeout(() => {\n this.executeGC(atom)\n }, this.gcOptions.graceMs)\n }\n\n private cancelScheduledGC<T>(atom: Lite.Atom<T>): void {\n const entry = this.cache.get(atom)\n if (entry?.gcScheduled) {\n clearTimeout(entry.gcScheduled)\n entry.gcScheduled = null\n }\n }\n\n private async executeGC<T>(atom: Lite.Atom<T>): Promise<void> {\n const entry = this.cache.get(atom)\n if (!entry) return\n \n entry.gcScheduled = null\n \n if (this.getSubscriberCount(atom) > 0) return\n if (entry.dependents.size > 0) return\n if (atom.keepAlive) return\n \n await this.release(atom)\n \n if (atom.deps) {\n for (const dep of Object.values(atom.deps)) {\n const depAtom = isAtom(dep) ? dep : isControllerDep(dep) ? dep.atom : null\n if (!depAtom) continue\n \n const depEntry = this.cache.get(depAtom)\n if (depEntry) {\n depEntry.dependents.delete(atom)\n this.maybeScheduleGC(depAtom)\n }\n }\n }\n }\n\n private notifyListeners<T>(atom: Lite.Atom<T>, event: 'resolving' | 'resolved'): void {\n const entry = this.cache.get(atom)\n if (!entry) return\n\n const eventListeners = entry.listeners.get(event)\n if (eventListeners?.size) {\n for (const listener of [...eventListeners]) {\n listener()\n }\n }\n\n const allListeners = entry.listeners.get('*')\n if (allListeners?.size) {\n for (const listener of [...allListeners]) {\n listener()\n }\n }\n }\n\n private notifyAllListeners<T>(atom: Lite.Atom<T>): void {\n const entry = this.cache.get(atom)\n if (!entry) return\n\n const allListeners = entry.listeners.get('*')\n if (allListeners?.size) {\n for (const listener of [...allListeners]) {\n listener()\n }\n }\n }\n\n private emitStateChange(state: AtomState, atom: Lite.Atom<unknown>): void {\n const stateMap = this.stateListeners.get(state)\n if (stateMap) {\n const listeners = stateMap.get(atom)\n if (listeners?.size) {\n for (const listener of [...listeners]) {\n listener()\n }\n }\n }\n }\n\n on(event: AtomState, atom: Lite.Atom<unknown>, listener: () => void): () => void {\n let stateMap = this.stateListeners.get(event)\n if (!stateMap) {\n stateMap = new Map()\n this.stateListeners.set(event, stateMap)\n }\n let listeners = stateMap.get(atom)\n if (!listeners) {\n listeners = new Set()\n stateMap.set(atom, listeners)\n }\n listeners.add(listener)\n\n const capturedStateMap = stateMap\n const capturedListeners = listeners\n\n return () => {\n capturedListeners.delete(listener)\n if (capturedListeners.size === 0) {\n capturedStateMap.delete(atom)\n if (capturedStateMap.size === 0) {\n this.stateListeners.delete(event)\n }\n }\n }\n }\n\n async resolve<T>(atom: Lite.Atom<T>): Promise<T> {\n if (this.disposed) throw new Error(\"Scope is disposed\")\n\n if (!this.initialized) {\n await this.ready\n }\n\n const entry = this.cache.get(atom) as AtomEntry<T> | undefined\n if (entry?.state === 'resolved') {\n return entry.value as T\n }\n\n const pendingPromise = this.pending.get(atom)\n if (pendingPromise) {\n return pendingPromise as Promise<T>\n }\n\n if (this.resolving.has(atom)) {\n throw new Error(\"Circular dependency detected\")\n }\n\n if (this.presets.has(atom)) {\n const presetValue = this.presets.get(atom)\n if (isAtom(presetValue)) {\n return this.resolve(presetValue as Lite.Atom<T>)\n }\n const newEntry = this.getOrCreateEntry(atom)\n newEntry.state = 'resolved'\n newEntry.value = presetValue as T\n newEntry.hasValue = true\n this.emitStateChange('resolved', atom)\n this.notifyListeners(atom, 'resolved')\n return newEntry.value\n }\n\n this.resolving.add(atom)\n\n const promise = this.doResolve(atom)\n this.pending.set(atom, promise as Promise<unknown>)\n\n try {\n return await promise\n } finally {\n this.resolving.delete(atom)\n this.pending.delete(atom)\n }\n }\n\n private async doResolve<T>(atom: Lite.Atom<T>): Promise<T> {\n const entry = this.getOrCreateEntry(atom)\n\n const wasResolving = entry.state === 'resolving'\n if (!wasResolving) {\n for (let i = entry.cleanups.length - 1; i >= 0; i--) {\n try { await entry.cleanups[i]?.() } catch {}\n }\n entry.cleanups = []\n entry.state = 'resolving'\n this.emitStateChange('resolving', atom)\n this.notifyListeners(atom, 'resolving')\n }\n\n const resolvedDeps = await this.resolveDeps(atom.deps, undefined, atom)\n\n const ctx: Lite.ResolveContext = {\n cleanup: (fn) => entry.cleanups.push(fn),\n invalidate: () => {\n this.scheduleInvalidation(atom)\n },\n scope: this,\n get data() {\n if (!entry.data) {\n entry.data = new ContextDataImpl()\n }\n return entry.data\n },\n }\n\n const factory = atom.factory as (\n ctx: Lite.ResolveContext,\n deps?: Record<string, unknown>\n ) => MaybePromise<T>\n\n const doResolve = async () => {\n if (atom.deps) {\n return factory(ctx, resolvedDeps)\n } else {\n return factory(ctx)\n }\n }\n\n try {\n const event: Lite.ResolveEvent = { kind: \"atom\", target: atom as Lite.Atom<unknown>, scope: this }\n const value = await this.applyResolveExtensions(event, doResolve)\n entry.state = 'resolved'\n entry.value = value\n entry.hasValue = true\n entry.error = undefined\n this.emitStateChange('resolved', atom)\n this.notifyListeners(atom, 'resolved')\n\n if (entry.pendingInvalidate) {\n entry.pendingInvalidate = false\n this.invalidationChain?.delete(atom)\n this.scheduleInvalidation(atom)\n } else if (entry.pendingSet) {\n this.invalidationChain?.delete(atom)\n this.scheduleInvalidation(atom)\n }\n\n return value\n } catch (err) {\n entry.state = 'failed'\n entry.error = err instanceof Error ? err : new Error(String(err))\n entry.value = undefined\n entry.hasValue = false\n this.emitStateChange('failed', atom)\n this.notifyAllListeners(atom)\n\n if (entry.pendingInvalidate) {\n entry.pendingInvalidate = false\n this.invalidationChain?.delete(atom)\n this.scheduleInvalidation(atom)\n } else if (entry.pendingSet && 'value' in entry.pendingSet) {\n this.invalidationChain?.delete(atom)\n this.scheduleInvalidation(atom)\n } else {\n entry.pendingSet = undefined\n }\n\n throw entry.error\n }\n }\n\n private async applyResolveExtensions<T>(\n event: Lite.ResolveEvent,\n doResolve: () => Promise<T>\n ): Promise<T> {\n let next = doResolve\n\n for (let i = this.resolveExts.length - 1; i >= 0; i--) {\n const ext = this.resolveExts[i]!\n const currentNext = next\n next = ext.wrapResolve!.bind(ext, currentNext, event) as () => Promise<T>\n }\n\n return next()\n }\n\n async resolveDeps(\n deps: Record<string, Lite.Dependency> | undefined,\n ctx?: Lite.ExecutionContext,\n dependentAtom?: Lite.Atom<unknown>\n ): Promise<Record<string, unknown>> {\n if (!deps) return {}\n\n const result: Record<string, unknown> = {}\n const parallel: Promise<void>[] = []\n const deferredResources: [string, Lite.Resource<unknown>][] = []\n\n for (const key in deps) {\n const dep = deps[key]!\n if (isAtom(dep)) {\n parallel.push(\n this.resolve(dep).then(value => {\n result[key] = value\n if (dependentAtom) {\n const depEntry = this.getEntry(dep)\n if (depEntry) depEntry.dependents.add(dependentAtom)\n }\n })\n )\n } else if (isControllerDep(dep)) {\n if (dep.watch) {\n if (!dependentAtom) throw new Error(\"controller({ watch: true }) is only supported in atom dependencies\")\n if (!dep.resolve) throw new Error(\"controller({ watch: true }) requires resolve: true\")\n }\n const ctrl = this.controller(dep.atom)\n if (dep.resolve) {\n parallel.push(\n ctrl.resolve().then(() => {\n result[key] = ctrl\n if (dependentAtom) {\n const depEntry = this.getEntry(dep.atom)\n if (depEntry) depEntry.dependents.add(dependentAtom)\n }\n if (dep.watch) {\n const eq = dep.eq ?? shallowEqual\n let prev = ctrl.get() as unknown\n const unsub = this.on(\"resolved\", dep.atom, () => {\n const next = ctrl.get() as unknown\n if (!eq(prev, next)) {\n this.scheduleInvalidation(dependentAtom!)\n }\n prev = next\n })\n const depEntry = this.getEntry(dependentAtom!)\n if (depEntry) depEntry.cleanups.push(unsub)\n else unsub()\n }\n })\n )\n } else {\n result[key] = ctrl\n if (dependentAtom) {\n const depEntry = this.getEntry(dep.atom)\n if (depEntry) depEntry.dependents.add(dependentAtom)\n }\n }\n } else if (tagExecutorSymbol in (dep as object)) {\n const tagExecutor = dep as Lite.TagExecutor<unknown, boolean>\n\n switch (tagExecutor.mode) {\n case \"required\": {\n const value = ctx\n ? ctx.data.seekTag(tagExecutor.tag)\n : tagExecutor.tag.find(this.tags)\n if (value !== undefined) {\n result[key] = value\n } else if (tagExecutor.tag.hasDefault) {\n result[key] = tagExecutor.tag.defaultValue\n } else {\n throw new Error(`Tag \"${tagExecutor.tag.label}\" not found`)\n }\n break\n }\n case \"optional\": {\n const value = ctx\n ? ctx.data.seekTag(tagExecutor.tag)\n : tagExecutor.tag.find(this.tags)\n result[key] = value ?? tagExecutor.tag.defaultValue\n break\n }\n case \"all\": {\n result[key] = ctx\n ? this.collectFromHierarchy(ctx, tagExecutor.tag)\n : tagExecutor.tag.collect(this.tags)\n break\n }\n }\n } else if (isResource(dep)) {\n deferredResources.push([key, dep as Lite.Resource<unknown>])\n }\n }\n\n if (parallel.length === 1) await parallel[0]\n else if (parallel.length > 1) await Promise.all(parallel)\n\n for (const [key, resource] of deferredResources) {\n if (!ctx) {\n throw new Error(\"Resource deps require an ExecutionContext\")\n }\n\n const resourceKey = getResourceKey(resource)\n const storeCtx = ctx.parent ?? ctx\n\n if (storeCtx.data.has(resourceKey)) {\n result[key] = storeCtx.data.get(resourceKey)\n continue\n }\n\n if (ctx.data.seekHas(resourceKey)) {\n result[key] = ctx.data.seek(resourceKey)\n continue\n }\n\n let flights = inflightResources.get(storeCtx.data)\n if (!flights) {\n flights = new Map()\n inflightResources.set(storeCtx.data, flights)\n }\n\n const inflight = flights.get(resourceKey)\n if (inflight) {\n result[key] = await inflight\n continue\n }\n\n let localResolvingResources = resolvingResourcesMap.get(storeCtx.data)\n if (!localResolvingResources) {\n localResolvingResources = new Set()\n resolvingResourcesMap.set(storeCtx.data, localResolvingResources)\n }\n\n if (localResolvingResources.has(resourceKey)) {\n throw new Error(`Circular resource dependency detected: ${resource.name ?? \"anonymous\"}`)\n }\n\n const resolve = async () => {\n localResolvingResources.add(resourceKey)\n try {\n const resourceDeps = await this.resolveDeps(resource.deps, ctx)\n\n const event: Lite.ResolveEvent = {\n kind: \"resource\",\n target: resource,\n ctx: storeCtx,\n }\n\n const doResolve = async () => {\n const factory = resource.factory as (\n ctx: Lite.ExecutionContext,\n deps?: Record<string, unknown>\n ) => MaybePromise<unknown>\n if (resource.deps) {\n return factory(storeCtx, resourceDeps)\n }\n return factory(storeCtx)\n }\n\n const value = await this.applyResolveExtensions(event, doResolve)\n storeCtx.data.set(resourceKey, value)\n return value\n } finally {\n localResolvingResources.delete(resourceKey)\n }\n }\n\n const promise = resolve()\n flights.set(resourceKey, promise)\n\n try {\n result[key] = await promise\n } finally {\n flights.delete(resourceKey)\n }\n }\n\n return result\n }\n\n private collectFromHierarchy<T>(ctx: Lite.ExecutionContext, tag: Lite.Tag<T, boolean>): T[] {\n const results: T[] = []\n let current: Lite.ExecutionContext | undefined = ctx\n\n while (current) {\n const value = current.data.getTag(tag)\n if (value !== undefined) {\n results.push(value)\n }\n current = current.parent\n }\n\n return results\n }\n\n controller<T>(atom: Lite.Atom<T>): Lite.Controller<T>\n controller<T>(atom: Lite.Atom<T>, options: { resolve: true }): Promise<Lite.Controller<T>>\n controller<T>(atom: Lite.Atom<T>, options?: Lite.ControllerOptions): Lite.Controller<T> | Promise<Lite.Controller<T>>\n controller<T>(atom: Lite.Atom<T>, options?: Lite.ControllerOptions): Lite.Controller<T> | Promise<Lite.Controller<T>> {\n if (this.disposed) throw new Error(\"Scope is disposed\")\n let ctrl = this.controllers.get(atom) as ControllerImpl<T> | undefined\n if (!ctrl) {\n ctrl = new ControllerImpl(atom, this)\n this.controllers.set(atom, ctrl as ControllerImpl<unknown>)\n }\n if (options?.resolve) {\n return ctrl.resolve().then(() => ctrl)\n }\n return ctrl\n }\n\n select<T, S>(\n atom: Lite.Atom<T>,\n selector: (value: T) => S,\n options?: Lite.SelectOptions<S>\n ): Lite.SelectHandle<S> {\n const ctrl = this.controller(atom)\n const eq = options?.eq ?? Object.is\n return new SelectHandleImpl(ctrl, selector, eq)\n }\n\n getFlowPreset<O, I>(flow: Lite.Flow<O, I>): Lite.PresetValue<O, I> | undefined {\n return this.presets.get(flow as Lite.Flow<unknown, unknown>) as Lite.PresetValue<O, I> | undefined\n }\n\n invalidate<T>(atom: Lite.Atom<T>): void {\n const entry = this.cache.get(atom)\n if (!entry) return\n\n if (entry.state === 'idle') return\n\n if (entry.state === 'resolving') {\n entry.pendingInvalidate = true\n return\n }\n\n this.scheduleInvalidation(atom)\n }\n\n scheduleSet<T>(atom: Lite.Atom<T>, value: T): void {\n const entry = this.cache.get(atom) as AtomEntry<T> | undefined\n if (!entry || entry.state === 'idle') {\n throw new Error(\"Atom not resolved\")\n }\n if (entry.state === 'failed' && entry.error) {\n throw entry.error\n }\n\n if (entry.state === 'resolving') {\n entry.pendingSet = { value }\n return\n }\n\n entry.pendingSet = { value }\n this.scheduleInvalidation(atom)\n }\n\n scheduleUpdate<T>(atom: Lite.Atom<T>, fn: (prev: T) => T): void {\n const entry = this.cache.get(atom) as AtomEntry<T> | undefined\n if (!entry || entry.state === 'idle') {\n throw new Error(\"Atom not resolved\")\n }\n if (entry.state === 'failed' && entry.error) {\n throw entry.error\n }\n\n if (entry.state === 'resolving') {\n entry.pendingSet = { fn }\n return\n }\n\n entry.pendingSet = { fn }\n this.scheduleInvalidation(atom)\n }\n\n private async doInvalidateSequential<T>(atom: Lite.Atom<T>): Promise<void> {\n const entry = this.cache.get(atom) as AtomEntry<T> | undefined\n if (!entry) return\n if (entry.state === \"idle\") return\n\n const previousValue = entry.value\n const pendingSet = entry.pendingSet\n entry.pendingSet = undefined\n\n if (pendingSet) {\n entry.state = \"resolving\"\n entry.value = previousValue\n entry.error = undefined\n entry.pendingInvalidate = false\n this.pending.delete(atom)\n this.resolving.delete(atom)\n this.emitStateChange(\"resolving\", atom)\n this.notifyListeners(atom, \"resolving\")\n\n if ('value' in pendingSet) {\n entry.value = pendingSet.value\n } else {\n entry.value = pendingSet.fn(previousValue as T)\n }\n entry.state = 'resolved'\n entry.hasValue = true\n this.emitStateChange('resolved', atom)\n this.notifyListeners(atom, 'resolved')\n this.invalidationChain?.delete(atom)\n return\n }\n\n for (let i = entry.cleanups.length - 1; i >= 0; i--) {\n try { await entry.cleanups[i]?.() } catch {}\n }\n entry.cleanups = []\n\n entry.state = \"resolving\"\n entry.value = previousValue\n entry.error = undefined\n entry.pendingInvalidate = false\n this.pending.delete(atom)\n this.resolving.delete(atom)\n this.emitStateChange(\"resolving\", atom)\n this.notifyListeners(atom, \"resolving\")\n\n try {\n await this.resolve(atom)\n } catch (e) {\n if (!entry.pendingSet && !entry.pendingInvalidate) throw e\n }\n }\n\n async release<T>(atom: Lite.Atom<T>): Promise<void> {\n const entry = this.cache.get(atom)\n if (!entry) return\n\n if (entry.gcScheduled) {\n clearTimeout(entry.gcScheduled)\n entry.gcScheduled = null\n }\n\n for (let i = entry.cleanups.length - 1; i >= 0; i--) {\n try { await entry.cleanups[i]?.() } catch {}\n }\n\n if (atom.deps) {\n for (const dep of Object.values(atom.deps)) {\n const depAtom = isAtom(dep) ? dep : isControllerDep(dep) ? dep.atom : null\n if (!depAtom) continue\n const depEntry = this.cache.get(depAtom)\n if (depEntry) {\n depEntry.dependents.delete(atom)\n this.maybeScheduleGC(depAtom)\n }\n }\n }\n\n this.cache.delete(atom)\n this.controllers.delete(atom)\n\n for (const [state, stateMap] of this.stateListeners) {\n stateMap.delete(atom)\n if (stateMap.size === 0) this.stateListeners.delete(state)\n }\n }\n\n async dispose(): Promise<void> {\n if (this.chainPromise) {\n try { await this.chainPromise } catch {}\n }\n\n this.disposed = true\n\n this.invalidationQueue.clear()\n this.invalidationChain = null\n this.chainPromise = null\n\n for (const ext of this.extensions) {\n if (ext.dispose) {\n await ext.dispose(this)\n }\n }\n\n for (const entry of this.cache.values()) {\n if (entry.gcScheduled) {\n clearTimeout(entry.gcScheduled)\n entry.gcScheduled = null\n }\n }\n\n const atoms = Array.from(this.cache.keys())\n for (const atom of atoms) {\n await this.release(atom as Lite.Atom<unknown>)\n }\n }\n\n async flush(): Promise<void> {\n if (this.chainPromise) {\n await this.chainPromise\n }\n if (this.chainError !== null) {\n const error = this.chainError\n this.chainError = null\n throw error\n }\n }\n\n createContext(options?: Lite.CreateContextOptions): Lite.ExecutionContext {\n if (this.disposed) throw new Error(\"Scope is disposed\")\n const ctx = new ExecutionContextImpl(this, options)\n\n for (const tagged of options?.tags ?? []) {\n ctx.data.set(tagged.key, tagged.value)\n }\n\n for (const tagged of this.tags) {\n if (!ctx.data.has(tagged.key)) {\n ctx.data.set(tagged.key, tagged.value)\n }\n }\n\n return ctx\n }\n}\n\nclass ExecutionContextImpl implements Lite.ExecutionContext {\n private cleanups: ((result: Lite.CloseResult) => MaybePromise<void>)[] = []\n private closed = false\n private readonly _input: unknown\n private _data: ContextDataImpl | undefined\n private readonly _execName: string | undefined\n private readonly _flowName: string | undefined\n readonly parent: Lite.ExecutionContext | undefined\n\n constructor(\n readonly scope: ScopeImpl,\n options?: Lite.CreateContextOptions & {\n parent?: Lite.ExecutionContext\n input?: unknown\n execName?: string\n flowName?: string\n }\n ) {\n this.parent = options?.parent\n this._input = options?.input\n this._execName = options?.execName\n this._flowName = options?.flowName\n }\n\n get input(): unknown {\n return this._input\n }\n\n get name(): string | undefined {\n return this._execName ?? this._flowName\n }\n\n get data(): Lite.ContextData {\n if (!this._data) {\n this._data = new ContextDataImpl(this.parent?.data)\n }\n return this._data\n }\n\n async exec(options: {\n flow: Lite.Flow<unknown, unknown>\n input?: unknown\n rawInput?: unknown\n name?: string\n tags?: Lite.Tagged<any>[]\n } | Lite.ExecFnOptions<unknown>): Promise<unknown> {\n if (this.closed) {\n throw new Error(\"ExecutionContext is closed\")\n }\n\n if (\"flow\" in options) {\n const { flow, input, rawInput, name: execName, tags: execTags } = options\n\n const presetValue = this.scope.getFlowPreset(flow)\n if (presetValue !== undefined && isFlow(presetValue)) {\n return this.exec({ ...options, flow: presetValue })\n }\n\n const rawValue = rawInput !== undefined ? rawInput : input\n let parsedInput: unknown = rawValue\n if (flow.parse) {\n const label = execName ?? flow.name ?? \"anonymous\"\n try {\n parsedInput = await flow.parse(rawValue)\n } catch (err) {\n throw new ParseError(\n `Failed to parse flow input \"${label}\"`,\n \"flow-input\",\n label,\n err\n )\n }\n }\n\n const childCtx = new ExecutionContextImpl(this.scope, {\n parent: this,\n input: parsedInput,\n execName,\n flowName: flow.name\n })\n\n for (const tagged of execTags ?? []) {\n childCtx.data.set(tagged.key, tagged.value)\n }\n\n for (const tagged of flow.tags ?? []) {\n if (!childCtx.data.has(tagged.key)) {\n childCtx.data.set(tagged.key, tagged.value)\n }\n }\n\n try {\n const result = presetValue !== undefined && typeof presetValue === 'function'\n ? await childCtx.execPresetFn(flow, presetValue as (ctx: Lite.ExecutionContext) => unknown)\n : await childCtx.execFlowInternal(flow)\n await childCtx.close({ ok: true })\n return result\n } catch (error) {\n await childCtx.close({ ok: false, error })\n throw error\n }\n } else {\n const childCtx = new ExecutionContextImpl(this.scope, {\n parent: this,\n execName: options.name,\n flowName: options.fn.name || undefined,\n input: options.params\n })\n\n try {\n const result = await childCtx.execFnInternal(options)\n await childCtx.close({ ok: true })\n return result\n } catch (error) {\n await childCtx.close({ ok: false, error })\n throw error\n }\n }\n }\n\n private async execFlowInternal(flow: Lite.Flow<unknown, unknown>): Promise<unknown> {\n const resolvedDeps = await this.scope.resolveDeps(flow.deps, this)\n\n const factory = flow.factory as unknown as (\n ctx: Lite.ExecutionContext,\n deps?: Record<string, unknown>\n ) => MaybePromise<unknown>\n\n const doExec = async (): Promise<unknown> => {\n if (flow.deps) {\n return factory(this, resolvedDeps)\n } else {\n return factory(this)\n }\n }\n\n return this.applyExecExtensions(flow, doExec)\n }\n\n private async execFnInternal(options: Lite.ExecFnOptions<unknown>): Promise<unknown> {\n const { fn, params } = options\n const doExec = () => Promise.resolve(fn(this, ...params))\n return this.applyExecExtensions(fn, doExec)\n }\n\n async execPresetFn(\n flow: Lite.Flow<unknown, unknown>,\n fn: (ctx: Lite.ExecutionContext) => MaybePromise<unknown>\n ): Promise<unknown> {\n const doExec = () => Promise.resolve(fn(this))\n return this.applyExecExtensions(flow, doExec)\n }\n\n private async applyExecExtensions(\n target: Lite.Flow<unknown, unknown> | ((ctx: Lite.ExecutionContext, ...args: unknown[]) => MaybePromise<unknown>),\n doExec: () => Promise<unknown>\n ): Promise<unknown> {\n let next = doExec\n\n for (let i = this.scope.execExts.length - 1; i >= 0; i--) {\n const ext = this.scope.execExts[i]!\n const currentNext = next\n next = ext.wrapExec!.bind(ext, currentNext, target, this) as () => Promise<unknown>\n }\n\n return next()\n }\n\n onClose(fn: (result: Lite.CloseResult) => MaybePromise<void>): void {\n this.cleanups.push(fn)\n }\n\n async close(result: Lite.CloseResult = { ok: true }): Promise<void> {\n if (this.closed) return\n\n this.closed = true\n\n for (let i = this.cleanups.length - 1; i >= 0; i--) {\n try { await this.cleanups[i]?.(result) } catch {}\n }\n }\n}\n\n/**\n * Creates a DI container that manages Atom resolution, caching, and lifecycle.\n *\n * The scope is returned synchronously, with a `ready` promise that resolves\n * when all extensions have been initialized. Resolution methods automatically\n * wait for `ready` before proceeding.\n *\n * @param options - Optional configuration for extensions, presets, and tags\n * @returns A Scope instance with a `ready` promise for extension initialization\n *\n * @example\n * ```typescript\n * const scope = createScope({\n * extensions: [loggingExtension],\n * presets: [preset(dbAtom, testDb)]\n * })\n *\n * // Option 1: resolve() waits for ready internally\n * const db = await scope.resolve(dbAtom)\n *\n * // Option 2: explicit wait\n * await scope.ready\n * const db = await scope.resolve(dbAtom)\n * ```\n */\nexport function createScope(options?: Lite.ScopeOptions): Lite.Scope {\n return new ScopeImpl(options)\n}\n","export type { Lite, AtomState } from \"./types\"\nexport {\n atomSymbol,\n flowSymbol,\n tagSymbol,\n taggedSymbol,\n controllerDepSymbol,\n presetSymbol,\n controllerSymbol,\n tagExecutorSymbol,\n typedSymbol,\n resourceSymbol,\n} from \"./symbols\"\nexport { tag, tags, isTag, isTagged, isTagExecutor, getAllTags } from \"./tag\"\nexport { atom, isAtom, controller, isControllerDep } from \"./atom\"\nexport { flow, isFlow, typed } from \"./flow\"\nexport { preset, isPreset } from \"./preset\"\nexport { resource, isResource } from \"./resource\"\nexport { service } from \"./service\"\nexport { createScope } from \"./scope\"\nexport { shallowEqual } from \"./equality\"\nexport { ParseError } from \"./errors\"\n\nexport const VERSION = \"0.0.1\"\n"],"mappings":";AAAA,MAAaA,aAA4B,OAAO,IAAI,uBAAuB;AAC3E,MAAaC,aAA4B,OAAO,IAAI,uBAAuB;AAC3E,MAAaC,YAA2B,OAAO,IAAI,sBAAsB;AACzE,MAAaC,eAA8B,OAAO,IAAI,yBAAyB;AAC/E,MAAaC,sBAAqC,OAAO,IAAI,iCAAiC;AAC9F,MAAaC,eAA8B,OAAO,IAAI,yBAAyB;AAC/E,MAAaC,mBAAkC,OAAO,IAAI,6BAA6B;AACvF,MAAaC,oBAAmC,OAAO,IAAI,+BAA+B;AAC1F,MAAaC,cAA6B,OAAO,IAAI,wBAAwB;AAC7E,MAAaC,iBAAgC,OAAO,IAAI,2BAA2B;;;;ACTnF,IAAa,aAAb,cAAgC,MAAM;CACpC,AAAkB,OAAO;CAEzB,YACE,SACA,AAASC,OACT,AAASC,OACT,AAAkBC,OAClB;AACA,QAAM,QAAQ;EAJL;EACA;EACS;;;;;;ACGtB,MAAM,2BAAW,IAAI,SAAoE;AACzF,MAAMC,cAAqD,EAAE;;;;;;;;;;;;;;;;;;;;;AAsB7D,SAAgB,aAA2C;CACzD,MAAMC,OAAqC,EAAE;CAC7C,MAAMC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B,MAAM,eAAe,QAAQ,QAAQ,GAAG,KAAK,CAAC;AAC9C,SAAO,KAAK,oBAAoBA,QAAM,OAAO;;CAG/C,MAAc,oBACZ,QACA,QACkB;EAClB,IAAI,OAAO;AAEX,OAAK,IAAI,IAAI,KAAK,MAAM,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK;GACxD,MAAM,MAAM,KAAK,MAAM,SAAS;GAChC,MAAM,cAAc;AACpB,UAAO,IAAI,SAAU,KAAK,KAAK,aAAa,QAAQ,KAAK;;AAG3D,SAAO,MAAM;;CAGf,QAAQ,IAA4D;AAClE,OAAK,SAAS,KAAK,GAAG;;CAGxB,MAAM,MAAM,SAA2B,EAAE,IAAI,MAAM,EAAiB;AAClE,MAAI,KAAK,OAAQ;AAEjB,OAAK,SAAS;AAEd,OAAK,IAAI,IAAI,KAAK,SAAS,SAAS,GAAG,KAAK,GAAG,IAC7C,KAAI;AAAE,SAAM,KAAK,SAAS,KAAK,OAAO;UAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BrD,SAAgB,YAAY,SAAyC;AACnE,QAAO,IAAI,UAAU,QAAQ;;;;;ACtvC/B,MAAa,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pumped-fn/lite",
3
- "version": "2.1.0",
3
+ "version": "2.1.3",
4
4
  "description": "Lightweight dependency injection with minimal reactivity",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",