@blac/core 2.0.20 → 2.1.0

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.
Files changed (78) hide show
  1. package/dist/StateContainerRegistry-C75QpeaO.cjs +1260 -0
  2. package/dist/StateContainerRegistry-C75QpeaO.cjs.map +1 -0
  3. package/dist/StateContainerRegistry-DL5Ai7wh.js +1153 -0
  4. package/dist/StateContainerRegistry-DL5Ai7wh.js.map +1 -0
  5. package/dist/StateContainerRegistry-DWOzx7Gd.js +1154 -0
  6. package/dist/StateContainerRegistry-DWOzx7Gd.js.map +1 -0
  7. package/dist/StateContainerRegistry-G81GcCRm.cjs +1261 -0
  8. package/dist/StateContainerRegistry-G81GcCRm.cjs.map +1 -0
  9. package/dist/acquire-CE0uq0Dx.cjs +46 -0
  10. package/dist/acquire-CE0uq0Dx.cjs.map +1 -0
  11. package/dist/acquire-CU0u8BMn.js +35 -0
  12. package/dist/acquire-CU0u8BMn.js.map +1 -0
  13. package/dist/acquire-CkgLJ8WL.cjs +46 -0
  14. package/dist/acquire-CkgLJ8WL.cjs.map +1 -0
  15. package/dist/acquire-DTvfYJ0y.js +35 -0
  16. package/dist/acquire-DTvfYJ0y.js.map +1 -0
  17. package/dist/config-C1T6Jw7n.cjs +32 -0
  18. package/dist/config-C1T6Jw7n.cjs.map +1 -0
  19. package/dist/config-D2A8ZYRM.js +16 -0
  20. package/dist/config-D2A8ZYRM.js.map +1 -0
  21. package/dist/config-D34BkraU.cjs +32 -0
  22. package/dist/config-D34BkraU.cjs.map +1 -0
  23. package/dist/config-ZVy_yFZ3.js +16 -0
  24. package/dist/config-ZVy_yFZ3.js.map +1 -0
  25. package/dist/config.d.cts +7 -3
  26. package/dist/config.d.ts +7 -3
  27. package/dist/constants.d.cts +2 -13
  28. package/dist/constants.d.ts +2 -13
  29. package/dist/core/StateContainer.d.ts +21 -0
  30. package/dist/core/StateContainerRegistry.d.ts +48 -5
  31. package/dist/debug.cjs +3 -3
  32. package/dist/debug.js +3 -3
  33. package/dist/decorators/blac.d.ts +2 -0
  34. package/dist/ensure-11-asM1e.js +677 -0
  35. package/dist/ensure-11-asM1e.js.map +1 -0
  36. package/dist/ensure-BEeY5Ab7.js +673 -0
  37. package/dist/ensure-BEeY5Ab7.js.map +1 -0
  38. package/dist/ensure-D3WWWwMo.cjs +714 -0
  39. package/dist/ensure-D3WWWwMo.cjs.map +1 -0
  40. package/dist/ensure-r1C_7K6_.cjs +718 -0
  41. package/dist/ensure-r1C_7K6_.cjs.map +1 -0
  42. package/dist/events.d.cts +42 -0
  43. package/dist/events.d.ts +42 -0
  44. package/dist/index.cjs +60 -6
  45. package/dist/index.cjs.map +1 -1
  46. package/dist/index.d.cts +4 -3
  47. package/dist/index.d.ts +4 -3
  48. package/dist/index.js +56 -8
  49. package/dist/index.js.map +1 -1
  50. package/dist/management-8x1OVMi6.js +38 -0
  51. package/dist/management-8x1OVMi6.js.map +1 -0
  52. package/dist/management-BZgsi29F.js +38 -0
  53. package/dist/management-BZgsi29F.js.map +1 -0
  54. package/dist/management-Dg2SxUb6.cjs +85 -0
  55. package/dist/management-Dg2SxUb6.cjs.map +1 -0
  56. package/dist/management-hkY13log.cjs +85 -0
  57. package/dist/management-hkY13log.cjs.map +1 -0
  58. package/dist/plugins.cjs +1 -1
  59. package/dist/plugins.js +1 -1
  60. package/dist/registry/index.d.ts +1 -1
  61. package/dist/registry/release.d.ts +17 -1
  62. package/dist/testing.cjs +4 -4
  63. package/dist/testing.js +4 -4
  64. package/dist/utils/static-props.d.ts +5 -0
  65. package/dist/utils/structural-key.d.ts +11 -1
  66. package/dist/watch/index.d.ts +1 -0
  67. package/dist/watch/observe.d.ts +13 -0
  68. package/dist/watch-BDiwCPmb.js +108 -0
  69. package/dist/watch-BDiwCPmb.js.map +1 -0
  70. package/dist/watch-BW7gYiDf.js +108 -0
  71. package/dist/watch-BW7gYiDf.js.map +1 -0
  72. package/dist/watch-aoNLQAXp.cjs +119 -0
  73. package/dist/watch-aoNLQAXp.cjs.map +1 -0
  74. package/dist/watch-entry.cjs +1 -1
  75. package/dist/watch-entry.js +1 -1
  76. package/dist/watch-lEco5Tbl.cjs +119 -0
  77. package/dist/watch-lEco5Tbl.cjs.map +1 -0
  78. package/package.json +3 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StateContainerRegistry-DWOzx7Gd.js","names":[],"sources":["../src/config.ts","../src/plugin/PluginManager.ts","../src/constants.ts","../src/utils/static-props.ts","../src/utils/structural-key.ts","../src/core/symbols.ts","../src/core/StateContainerRegistry.ts"],"sourcesContent":["/**\n * Global configuration for @blac/core\n */\n\nexport type EqualityFn = <S>(prev: S, next: S) => boolean;\n\nexport interface BlacConfig {\n /**\n * Equality check used by `StateContainer.applyState` to skip emits when\n * `prev` and `next` are structurally equal. Default: `shallowEqualState`.\n *\n * Return `true` to skip the emit (states considered equal).\n *\n * Applies to `emit`/`update` only — `patch` does not consult this fn; it\n * relies on its own per-key `Object.is` pre-check plus structural no-op\n * detection to skip redundant notifications.\n */\n equality: EqualityFn;\n\n /**\n * Circuit breaker: maximum number of live instances allowed under a single\n * bloc constructor before `acquire` throws. Guards against runaway instance\n * creation — typically an unstable/args-derived key churning out instances\n * that are never disposed (a memory leak that eventually freezes the app).\n *\n * Default: `100000`. Set to `Infinity` (or any non-positive value) to disable.\n */\n maxInstancesPerType: number;\n\n /**\n * Circuit breaker: maximum number of distinct live references (consumers)\n * allowed on a single instance before `acquire` throws. Guards against the\n * other leak shape — consumer cleanup (e.g. `useBloc` unmount `release`)\n * never firing, so refs accumulate without bound on one instance.\n *\n * Default: `100000`. Set to `Infinity` (or any non-positive value) to disable.\n */\n maxRefsPerInstance: number;\n\n /**\n * Dev-only soft circuit breaker: if a single instance emits more than this\n * many *real* state changes within a rolling one-second window, log a single\n * `console.warn`. This is the \"frozen app\" smell — almost always a tight loop\n * (RAF/animation, or an effect that emits on every commit) pushing\n * high-frequency data through bloc state, which then saturates subscribers,\n * plugins (logging/devtools), and the main thread.\n *\n * Heuristic by nature — warns, never throws, since high-frequency state can\n * occasionally be legitimate. No-op in production. Default: `1000`. Set to\n * `Infinity` (or any non-positive value) to disable.\n */\n maxEmitsPerSecond: number;\n}\n\n/**\n * Default equality: shallow per-key `Object.is` comparison.\n * Falls through to `false` for primitives/null so reference-only state still\n * behaves correctly.\n */\nexport const shallowEqualState: EqualityFn = (prev, next) => {\n if (Object.is(prev, next)) return true;\n if (typeof prev !== 'object' || prev === null) return false;\n if (typeof next !== 'object' || next === null) return false;\n\n const prevKeys = Object.keys(prev as object);\n if (prevKeys.length !== Object.keys(next as object).length) return false;\n\n for (let i = 0; i < prevKeys.length; i++) {\n const key = prevKeys[i];\n if (\n !Object.is(\n (prev as Record<string, unknown>)[key],\n (next as Record<string, unknown>)[key],\n )\n ) {\n return false;\n }\n }\n return true;\n};\n\nconst defaultConfig: BlacConfig = {\n equality: shallowEqualState,\n maxInstancesPerType: 100000,\n maxRefsPerInstance: 100000,\n maxEmitsPerSecond: 1000,\n};\n\nlet globalConfig: BlacConfig = { ...defaultConfig };\n\n/**\n * Configure global defaults for @blac/core.\n *\n * @example\n * ```ts\n * import { configureBlac, shallowEqualState } from '@blac/core';\n *\n * // Swap in a deep-equality check for all blocs\n * configureBlac({ equality: myDeepEqual });\n * ```\n */\nexport function configureBlac(config: Partial<BlacConfig>): void {\n globalConfig = { ...globalConfig, ...config };\n}\n\n/**\n * Get the current global configuration.\n * @internal\n */\nexport function getBlacConfig(): BlacConfig {\n return globalConfig;\n}\n\n/**\n * Reset configuration to defaults (useful for testing).\n * @internal\n */\nexport function resetBlacConfig(): void {\n globalConfig = { ...defaultConfig };\n}\n","import { ALL_PATHS, type PathSet } from '@dirtytalk/structural';\nimport type { StateContainer } from '../core/StateContainer';\nimport type { StateContainerRegistry } from '../core/StateContainerRegistry';\nimport type {\n BlacPlugin,\n PluginContext,\n PluginConfig,\n InstanceMetadata,\n} from './BlacPlugin';\n\n/**\n * Internal structure for tracking installed plugins.\n *\n * `installContext` is the context handed to `onInstall` — it has no\n * `container`. Per-container contexts are built on demand by\n * `buildContext()` so each event carries the right focal container\n * without mutating a shared object.\n * @internal\n */\ninterface InstalledPlugin {\n plugin: BlacPlugin;\n config: PluginConfig;\n installContext: PluginContext;\n}\n\n/**\n * Per-container bookkeeping for the channel-bridge plugin dispatcher.\n *\n * - `unsub` tears down the channel subscription on dispose.\n * - `prevState` is the state snapshot the manager will hand plugins as\n * `prev` on the next flush; it is updated to the post-flush state after\n * each dispatch.\n * @internal\n */\ninterface ContainerBridge {\n unsub: () => void;\n prevState: any;\n}\n\n/**\n * Manages plugin lifecycle for the BlaC state management system.\n *\n * The manager hooks into two surfaces:\n *\n * 1. **Registry lifecycle events** (`created`, `disposed`, `refAcquired`,\n * `refReleased`, `depsChanged`) — synchronous, fired by the registry.\n *\n * 2. **Per-container channel flushes** — microtask-coalesced. For each\n * container, the manager subscribes once at create-time with\n * `ALL_PATHS` interest and stashes `prevState`. On every flush it\n * captures the new state + the changed `PathSet` and dispatches\n * `onStateChange(ctx, prev, next, paths)` to every enabled plugin.\n *\n * The `ALL_PATHS` subscription cost: plugins counted as a consumer with\n * `ALL_PATHS` interest will defeat the single-consumer-skip optimization\n * in `StructuralContainer`. This is the intended trade-off — devtools /\n * persist plugins genuinely want every change, and stateful plugins\n * (logging) can decode `paths` via `container.interner.lookup(id)` to log\n * only relevant fields. Plugins that want low overhead should remain\n * uninstalled or environment-gated.\n *\n * @example\n * ```ts\n * const manager = createPluginManager(registry);\n * manager.install(myPlugin, { environment: 'development' });\n * ```\n */\nexport class PluginManager {\n private plugins = new Map<string, InstalledPlugin>();\n private registry: StateContainerRegistry;\n private lifecycleUnsubscribers: (() => void)[] = [];\n\n /**\n * Per-container channel-bridge bookkeeping. Subscribed at `created`,\n * torn down at `disposed`. Holds the rolling `prevState` snapshot the\n * manager hands plugins on each flush.\n */\n private containerBridges = new WeakMap<\n StateContainer<any, any, any>,\n ContainerBridge\n >();\n\n /**\n * Create a new PluginManager\n * @param registry - The StateContainerRegistry to monitor for lifecycle events\n */\n constructor(registry: StateContainerRegistry) {\n this.registry = registry;\n this.setupLifecycleHooks();\n }\n\n /**\n * Install a plugin with optional configuration\n * @param plugin - The plugin to install\n * @param config - Optional plugin configuration\n * @throws Error if plugin is already installed\n */\n install(plugin: BlacPlugin, config: PluginConfig = {}): void {\n const effectiveConfig: PluginConfig = {\n enabled: true,\n environment: 'all',\n ...config,\n };\n\n if (!this.shouldEnablePlugin(effectiveConfig)) {\n console.log(\n `[BlaC] Plugin \"${plugin.name}\" skipped (environment mismatch)`,\n );\n return;\n }\n\n if (this.plugins.has(plugin.name)) {\n throw new Error(`Plugin \"${plugin.name}\" is already installed`);\n }\n\n const installContext = this.buildContext(undefined);\n\n this.plugins.set(plugin.name, {\n plugin,\n config: effectiveConfig,\n installContext,\n });\n\n this.backfillPlugin(this.plugins.get(plugin.name)!);\n\n if (plugin.onInstall) {\n try {\n plugin.onInstall(installContext);\n } catch (error) {\n console.error(\n `[BlaC] Error installing plugin \"${plugin.name}\":`,\n error,\n );\n this.plugins.delete(plugin.name);\n throw error;\n }\n }\n\n console.log(`[BlaC] Plugin \"${plugin.name}\" v${plugin.version} installed`);\n }\n\n /**\n * Uninstall a plugin by name\n * @param pluginName - The name of the plugin to uninstall\n * @throws Error if plugin is not installed\n */\n uninstall(pluginName: string): void {\n const installed = this.plugins.get(pluginName);\n if (!installed) {\n throw new Error(`Plugin \"${pluginName}\" is not installed`);\n }\n\n if (installed.plugin.onUninstall) {\n try {\n installed.plugin.onUninstall();\n } catch (error) {\n console.error(\n `[BlaC] Error uninstalling plugin \"${pluginName}\":`,\n error,\n );\n }\n }\n\n this.plugins.delete(pluginName);\n console.log(`[BlaC] Plugin \"${pluginName}\" uninstalled`);\n }\n\n /**\n * Get an installed plugin by name\n * @param pluginName - The name of the plugin to retrieve\n * @returns The plugin instance or undefined if not found\n */\n getPlugin(pluginName: string): BlacPlugin | undefined {\n return this.plugins.get(pluginName)?.plugin;\n }\n\n /**\n * Get all installed plugins\n * @returns Array of all installed plugins\n */\n getAllPlugins(): BlacPlugin[] {\n return Array.from(this.plugins.values()).map((p) => p.plugin);\n }\n\n /**\n * Check if a plugin is installed\n * @param pluginName - The name of the plugin to check\n * @returns true if the plugin is installed\n */\n hasPlugin(pluginName: string): boolean {\n return this.plugins.has(pluginName);\n }\n\n /**\n * Uninstall all plugins\n */\n clear(): void {\n for (const name of this.plugins.keys()) {\n this.uninstall(name);\n }\n }\n\n destroy(): void {\n this.clear();\n for (const unsub of this.lifecycleUnsubscribers) {\n unsub();\n }\n this.lifecycleUnsubscribers = [];\n }\n\n /**\n * Wire registry lifecycle events into plugin dispatch.\n *\n * `onStateChange` is NOT wired through `registry.on('stateChanged', …)` —\n * that event lacks the `PathSet` payload. Instead, on each `created` we\n * subscribe to the container's channel directly so we get\n * `(paths)` and capture `(prev, next)` via the per-container snapshot.\n */\n private setupLifecycleHooks(): void {\n this.lifecycleUnsubscribers = [\n this.registry.on('created', (instance) => {\n this.attachStateBridge(instance);\n this.notifyPlugins('onCreated', instance);\n }),\n this.registry.on('disposed', (instance) => {\n this.notifyPlugins('onDestroyed', instance);\n this.detachStateBridge(instance);\n }),\n this.registry.on('refAcquired', (instance, refId) => {\n this.notifyPlugins('onRefAcquired', instance, refId);\n }),\n this.registry.on('refReleased', (instance, refId) => {\n this.notifyPlugins('onRefReleased', instance, refId);\n }),\n this.registry.on('depsChanged', (instance, previousDeps, currentDeps) => {\n this.notifyPlugins(\n 'onDepsChanged',\n instance,\n previousDeps,\n currentDeps,\n );\n }),\n this.registry.on(\n 'hydrationChanged',\n (instance, status, previousStatus) => {\n this.notifyPlugins(\n 'onHydrationChange',\n instance,\n status,\n previousStatus,\n );\n },\n ),\n ];\n }\n\n /**\n * Subscribe to the container's channel with `ALL_PATHS` interest, so we\n * fire on every flush. Capture `prev` from the snapshot taken on the\n * previous flush (or at create-time for the first flush) and pass the\n * channel's `paths` argument straight through to plugins.\n *\n * Per-container bookkeeping is stored in a `WeakMap` keyed by the\n * container itself, so a disposed/GC'd container drops cleanly.\n */\n private attachStateBridge(container: StateContainer<any, any, any>): void {\n // Defensive: if a container is somehow created twice (it shouldn't be),\n // don't double-subscribe — the existing bridge is canonical.\n if (this.containerBridges.has(container)) return;\n\n const bridge: ContainerBridge = {\n unsub: () => {},\n prevState: container.state,\n };\n this.containerBridges.set(container, bridge);\n\n bridge.unsub = container.channel.subscribe(\n () => ALL_PATHS,\n (paths) => this.dispatchStateChange(container, paths),\n );\n }\n\n private detachStateBridge(container: StateContainer<any, any, any>): void {\n const bridge = this.containerBridges.get(container);\n if (!bridge) return;\n bridge.unsub();\n this.containerBridges.delete(container);\n }\n\n /**\n * Backfill a newly-installed plugin with the app's existing instances.\n *\n * Iterates every registered `Type` and its live instances (`getAll`\n * already skips disposed), attaching the state bridge (idempotent — see\n * `attachStateBridge`) and, if the plugin implements `onCreated`, invoking\n * it directly for each instance. Scoped to this single plugin only — the\n * broadcast `notifyPlugins` would re-notify *every* plugin of *every*\n * instance, which is wrong here.\n */\n private backfillPlugin(installed: InstalledPlugin): void {\n const { plugin } = installed;\n for (const Type of this.registry.getTypes()) {\n for (const instance of this.registry.getAll(Type)) {\n // getAll returns the readonly public view; internal bridging needs the\n // real container (same friction the `as any` in queryInstances handles).\n const container = instance as StateContainer<any, any, any>;\n this.attachStateBridge(container);\n\n if (!plugin.onCreated) continue;\n try {\n plugin.onCreated(this.buildContext(container));\n } catch (error) {\n console.error(\n `[BlaC] Error in plugin \"${plugin.name}\" onCreated (backfill):`,\n error,\n );\n }\n }\n }\n }\n\n /**\n * Channel-flush callback. Snapshots `next`, hands `(prev, next, paths)`\n * to every enabled plugin's `onStateChange`, then updates `prevState`\n * for the next flush.\n *\n * Note: `prev` is captured once and reused across plugins — every\n * plugin sees the same `prev`/`next`/`paths` regardless of dispatch\n * order, matching the \"snapshot prev once per flush\" invariant.\n */\n private dispatchStateChange(\n container: StateContainer<any, any, any>,\n paths: PathSet,\n ): void {\n const bridge = this.containerBridges.get(container);\n if (!bridge) return;\n\n const prev = bridge.prevState;\n const next = container.state;\n bridge.prevState = next;\n\n let ctx: PluginContext | undefined;\n for (const { plugin, config } of this.plugins.values()) {\n if (!config.enabled) continue;\n // eslint-disable-next-line @typescript-eslint/unbound-method -- invoked via .call below\n const hook = plugin.onStateChange;\n if (typeof hook !== 'function') continue;\n\n try {\n ctx ??= this.buildContext(container);\n hook.call(plugin, ctx, prev, next, paths);\n } catch (error) {\n console.error(\n `[BlaC] Error in plugin \"${plugin.name}\" onStateChange:`,\n error,\n );\n }\n }\n }\n\n /**\n * Notify all plugins of a lifecycle event.\n *\n * Builds a fresh `PluginContext` per dispatch (instance becomes\n * `ctx.container`), so plugins can reach the focal bloc through\n * `ctx.container`. The context is built lazily on the first matching\n * hook and reused for every other plugin in this dispatch — zero\n * builds if no enabled plugin implements `hookName`.\n */\n private notifyPlugins(\n hookName: Exclude<keyof BlacPlugin, 'onStateChange'>,\n instance: StateContainer<any, any, any>,\n ...extraArgs: any[]\n ): void {\n let ctx: PluginContext | undefined;\n for (const { plugin, config } of this.plugins.values()) {\n if (!config.enabled) continue;\n\n const hook = plugin[hookName];\n if (typeof hook !== 'function') continue;\n\n try {\n ctx ??= this.buildContext(instance);\n (hook as any).call(plugin, ctx, ...extraArgs);\n } catch (error) {\n console.error(\n `[BlaC] Error in plugin \"${plugin.name}\" ${hookName}:`,\n error,\n );\n }\n }\n }\n\n /**\n * Build a `PluginContext` for a given focal container. The context is\n * cheap to build — its methods close over `this.registry` directly —\n * so we create one per dispatch rather than caching per container.\n * This sidesteps the lifetime question of \"when do we evict a cached\n * context?\" and keeps `paths`-vs-`container` lifetimes cleanly\n * separated.\n */\n private buildContext(\n container: StateContainer<any, any, any> | undefined,\n ): PluginContext {\n const registry = this.registry;\n return {\n container,\n\n getInstanceMetadata: (\n instance: StateContainer<any, any, any>,\n ): InstanceMetadata => {\n return {\n id: instance.$blac.id,\n className: instance.constructor.name,\n isDisposed: instance.$blac.disposed,\n name: instance.$blac.name,\n createdAt: instance.$blac.createdAt,\n state: instance.state,\n hydrationStatus: instance.$blac.hydration.status,\n isHydrated: instance.$blac.hydration.isHydrated,\n hydrationError: instance.$blac.hydration.error,\n changedWhileHydrating: instance.$blac.hydration.changedWhileHydrating,\n args: instance.args,\n };\n },\n\n getState: <S extends object = any>(instance: StateContainer<S>): S => {\n return instance.state;\n },\n\n getHydrationStatus: (instance: StateContainer<any, any, any>) => {\n return instance.$blac.hydration.status;\n },\n\n startHydration: (instance: StateContainer<any, any, any>) => {\n instance.$blac.hydration.begin();\n },\n\n applyHydratedState: <S extends object = any>(\n instance: StateContainer<S>,\n state: S,\n ): boolean => {\n return instance.$blac.hydration.apply(state);\n },\n\n finishHydration: (instance: StateContainer<any, any, any>) => {\n instance.$blac.hydration.finish();\n },\n\n failHydration: (\n instance: StateContainer<any, any, any>,\n error: Error,\n ) => {\n instance.$blac.hydration.fail(error);\n },\n\n waitForHydration: (instance: StateContainer<any, any, any>) => {\n return instance.$blac.hydration.wait();\n },\n\n queryInstances: <T extends StateContainer<any, any, any>>(\n typeClass: new (...args: any[]) => T,\n ): T[] => {\n return registry.getAll(typeClass as any);\n },\n\n getAllTypes: () => {\n return registry.getTypes();\n },\n\n getStats: () => {\n return registry.getStats();\n },\n\n getRefIds: (instanceId: string): string[] => {\n const entry = registry.findEntryById(instanceId);\n return entry ? Array.from(entry.refs.keys()) : [];\n },\n };\n }\n\n /**\n * Check if plugin should be enabled based on environment\n */\n private shouldEnablePlugin(config: PluginConfig): boolean {\n if (!config.enabled) return false;\n if (config.environment === 'all') return true;\n\n const currentEnv = this.getCurrentEnvironment();\n return currentEnv === config.environment;\n }\n\n /**\n * Get current environment\n */\n private getCurrentEnvironment(): 'development' | 'production' | 'test' {\n if (typeof process !== 'undefined') {\n if (process.env.NODE_ENV === 'test') return 'test';\n if (process.env.NODE_ENV === 'production') return 'production';\n return 'development';\n }\n return 'development';\n }\n}\n\n/**\n * Create a plugin manager instance\n * @param registry - The StateContainerRegistry to monitor for lifecycle events\n * @returns A new PluginManager instance\n */\nexport function createPluginManager(\n registry: StateContainerRegistry,\n): PluginManager {\n return new PluginManager(registry);\n}\n","/**\n * Default configuration constants for BlaC\n *\n * Centralized location for all magic numbers and default values.\n */\n\n/**\n * Default configuration constants for BlaC\n */\nexport const BLAC_DEFAULTS = {\n /**\n * Default instance key for shared instances\n */\n DEFAULT_INSTANCE_KEY: 'default',\n} as const;\n\n/**\n * Static property names for StateContainer classes\n * Used for feature flags and configuration on bloc classes\n */\nexport const BLAC_STATIC_PROPS = {\n /**\n * Mark a bloc to never be auto-disposed (kept alive permanently)\n */\n KEEP_ALIVE: 'keepAlive',\n\n /**\n * Exclude a bloc from DevTools reporting (prevents infinite loops)\n */\n EXCLUDE_FROM_DEVTOOLS: '__excludeFromDevTools',\n\n /**\n * Per-class equality function used to short-circuit `emit`/`patch` when the\n * new state is structurally equal to the previous state. Falls back to the\n * global `configureBlac({ equality })` value when unset.\n */\n EQUALITY: '__equality',\n\n /**\n * Per-class key function: `static key = (args) => string`.\n * When set, the registry calls `Type.key(args)` to derive the instance key\n * instead of using a structural hash of `args`. Allows blocs to ignore\n * non-identity fields (e.g., `readonly` flags) while still keying by id.\n */\n KEY: 'key',\n\n /** Mark a bloc as always per-mount: `static isolated = true`. */\n ISOLATED: 'isolated',\n} as const;\n\n/**\n * Standard error message prefix\n */\nexport const BLAC_ERROR_PREFIX = '[BlaC]' as const;\n","/**\n * Utility functions for accessing static properties on StateContainer classes\n */\n\nimport { BLAC_STATIC_PROPS } from '../constants';\nimport type { EqualityFn } from '../config';\nimport { StateContainerConstructor } from '../types/utilities';\n\n/**\n * Get a static property from a class constructor\n * Type-safe helper that avoids (Type as any) casts\n *\n * @param Type - The class constructor\n * @param propName - The property name to access\n * @param defaultValue - Optional default value if property is undefined\n * @returns The property value or default\n */\nexport function getStaticProp<\n V,\n T extends StateContainerConstructor = StateContainerConstructor,\n>(Type: T, propName: string, defaultValue?: V): V | undefined {\n return (Type as any)[propName] ?? defaultValue;\n}\n\n/**\n * Check if a class is marked as keepAlive.\n * KeepAlive classes are never auto-disposed when ref count reaches 0.\n * @param Type - The class constructor to check\n * @returns true if the class has `static keepAlive = true`\n */\nexport function isKeepAliveClass<T extends StateContainerConstructor>(\n Type: T,\n): boolean {\n return getStaticProp<boolean>(Type, BLAC_STATIC_PROPS.KEEP_ALIVE) === true;\n}\n\n/**\n * Check if a class should be excluded from DevTools.\n * Used to prevent infinite loops when DevTools tracks itself.\n * @param Type - The class constructor to check\n * @returns true if the class has `static __excludeFromDevTools = true`\n */\nexport function isExcludedFromDevTools<T extends StateContainerConstructor>(\n Type: T,\n): boolean {\n return (\n getStaticProp<boolean>(Type, BLAC_STATIC_PROPS.EXCLUDE_FROM_DEVTOOLS) ===\n true\n );\n}\n\n/**\n * Get the per-class equality function set via `@blac({ equality })`, if any.\n * @param Type - The class constructor to check\n * @returns the equality function or `undefined`\n */\nexport function getClassEquality<T extends StateContainerConstructor>(\n Type: T,\n): EqualityFn | undefined {\n const fn = getStaticProp<EqualityFn>(Type, BLAC_STATIC_PROPS.EQUALITY);\n return typeof fn === 'function' ? fn : undefined;\n}\n\n/**\n * Get the per-class key function set via `@blac({ key })` or `static key = …`, if any.\n * Used by the registry to derive a stable instance key from `args`.\n * @param Type - The class constructor to check\n * @returns the key function or `undefined`\n */\nexport function getClassKey(\n Type: unknown,\n): ((args: any) => string) | undefined {\n const fn = getStaticProp<(args: any) => string>(\n Type as StateContainerConstructor,\n BLAC_STATIC_PROPS.KEY,\n undefined,\n );\n return typeof fn === 'function' ? fn : undefined;\n}\n\n/**\n * Check if a class is marked as always-per-mount.\n * @returns true if the class has `static isolated = true`\n */\nexport function isIsolatedClass<T extends StateContainerConstructor>(\n Type: T,\n): boolean {\n return getStaticProp<boolean>(Type, BLAC_STATIC_PROPS.ISOLATED) === true;\n}\n","/**\n * Deterministic, order-independent hash of serializable args.\n * Sorts object keys so {a,b} === {b,a}.\n *\n * - Functions throw a friendly `[blac]` error — they must be passed via `deps`.\n * - `Date` (and anything else with a `toJSON`) serializes via that `toJSON`\n * (e.g. as an ISO string), since `JSON.stringify` calls it before the\n * replacer ever sees the value — there's no cheap way to guard against\n * non-plain objects here.\n * - `BigInt` and circular args throw `JSON.stringify`'s own raw `TypeError`,\n * not the friendly `[blac]` message.\n * - `undefined` values inside objects are preserved via a reserved sentinel\n * (rather than being dropped, which is `JSON.stringify`'s default and would\n * let structurally different args collide on the same key).\n */\n\nexport const DEFAULT_STRUCTURAL_KEY = 'default';\n\n/** Reserved sentinel standing in for `undefined` values inside args objects. */\nconst UNDEFINED_SENTINEL = '\\0undefined';\n\n/**\n * Produce a stable string key for serializable args.\n * - `undefined` / `void` args → `'default'` sentinel (no-args blocs stay on the default key).\n * - Object keys are sorted for order-independence.\n * - Arrays keep their insertion order.\n * - Functions throw — they must be passed via `deps`, not `args`.\n */\nexport function structuralKey(args: unknown): string {\n if (args === undefined || args === null) {\n return DEFAULT_STRUCTURAL_KEY;\n }\n\n return JSON.stringify(args, function (_k, v) {\n if (typeof v === 'function') {\n throw new Error(\n '[blac] args must be serializable; put refs/callbacks in `deps`',\n );\n }\n if (v === undefined) {\n return UNDEFINED_SENTINEL;\n }\n if (v && typeof v === 'object' && !Array.isArray(v)) {\n return Object.keys(v)\n .sort()\n .reduce(\n (o, k) => {\n (o as any)[k] = (v as any)[k];\n return o;\n },\n {} as Record<string, unknown>,\n );\n }\n return v;\n });\n}\n","/**\n * @internal Apply one owner's (consumer's) deps slice to an instance.\n * Called by framework adapters (e.g. @blac/react useBloc) — not public API.\n */\nexport const APPLY_DEPS = Symbol('blac.applyDeps');\n\n/**\n * @internal Withdraw one owner's entire deps slice (consumer unmounted).\n * Called by framework adapters — not public API.\n */\nexport const REMOVE_DEPS_OWNER = Symbol('blac.removeDepsOwner');\n\n/**\n * @internal Subscribe to this specific instance's own disposal, bypassing\n * the global registry `'disposed'` event. Called by `watch()` — not public\n * API.\n */\nexport const ON_DISPOSE = Symbol('blac.onDispose');\n\n/**\n * @internal Symbol-keyed configuration entry point on `StateContainer`.\n * Writes the instance's identity fields (`_name`/`_debug`/`_instanceId`),\n * resolves per-class equality, emits the registry `created` event, and runs\n * `init()` once.\n *\n * Framework-only — the registry (`StateContainerRegistry.ensure`) and testing\n * helpers are the sole callers, mirroring the `APPLY_DEPS` precedent.\n */\nexport const INIT_CONFIG = Symbol('blac.initConfig');\n","import type {\n HydrationStatus,\n StateContainer,\n StateContainerConfig,\n} from './StateContainer';\nimport {\n createPluginManager,\n type PluginManager,\n} from '../plugin/PluginManager';\nimport { BLAC_DEFAULTS, BLAC_ERROR_PREFIX } from '../constants';\nimport { getBlacConfig } from '../config';\nimport { isKeepAliveClass, getClassKey } from '../utils/static-props';\nimport { structuralKey, DEFAULT_STRUCTURAL_KEY } from '../utils/structural-key';\nimport {\n InstanceReadonlyState,\n StateContainerConstructor,\n StateContainerInstance,\n} from '../types/utilities';\nimport { INIT_CONFIG } from './symbols';\n\n/**\n * @internal Compile-time-only cast interface (same style as `core/meta.ts`'s\n * `MetaInternals`) used to reach `StateContainer`'s private `_depEdges` from\n * within the same package without widening the public surface.\n */\ninterface DepEdgeInternals {\n _depEdges: Map<StateContainerConstructor, Set<string>> | null;\n}\n\n/**\n * Entry in the instance registry, tracking the instance and its named references\n * @template T - Instance type\n */\nexport interface InstanceEntry<T = any> {\n /** The state container instance */\n instance: T;\n /** Map of active reference IDs to their acquire count (supports paired acquire/release) */\n refs: Map<string, number>;\n /** The args used when this entry was first created; used for dev-warn on arg mismatch. */\n args?: unknown;\n /** Memoized structuralKey(args) for the dev arg-mismatch warning. */\n argsKey?: string;\n /** `depend()`-owners currently holding this instance (see `acquire`'s `dependent` option). */\n dependents?: Set<StateContainer<any, any, any>>;\n /**\n * `$blac.id` this entry is indexed under in `_byId`, captured at index time.\n * Removal always keys off THIS stored id (never a fresh `$blac.id` read),\n * so an id that changes later (e.g. `INIT_CONFIG` running after insertion)\n * can never orphan the index.\n */\n id?: string;\n}\n\n/**\n * Lifecycle events emitted by the registry\n */\nexport type LifecycleEvent =\n | 'created'\n | 'stateChanged'\n | 'disposed'\n | 'refAcquired'\n | 'refReleased'\n | 'depsChanged'\n | 'hydrationChanged';\n\n/**\n * Listener function type for each lifecycle event\n * @template E - The lifecycle event type\n */\nexport type LifecycleListener<E extends LifecycleEvent> = E extends 'created'\n ? (container: StateContainer<any, any, any>) => void\n : E extends 'stateChanged'\n ? (\n container: StateContainer<any, any, any>,\n previousState: any,\n currentState: any,\n ) => void\n : E extends 'disposed'\n ? (container: StateContainer<any, any, any>) => void\n : E extends 'refAcquired'\n ? (container: StateContainer<any, any, any>, refId: string) => void\n : E extends 'refReleased'\n ? (container: StateContainer<any, any, any>, refId: string) => void\n : E extends 'depsChanged'\n ? (\n container: StateContainer<any, any, any>,\n previousDeps: Readonly<Record<string, unknown>>,\n currentDeps: Readonly<Record<string, unknown>>,\n ) => void\n : E extends 'hydrationChanged'\n ? (\n container: StateContainer<any, any, any>,\n status: HydrationStatus,\n previousStatus: HydrationStatus,\n ) => void\n : never;\n\n/**\n * Central registry for managing StateContainer instances.\n * Handles instance lifecycle, named ref tracking, and lifecycle event emission.\n *\n * @example\n * ```ts\n * const registry = new StateContainerRegistry();\n * const instance = registry.acquire(MyBloc); // ownership, must release\n * const other = registry.ensure(OtherBloc); // no ownership, bloc-to-bloc\n * registry.on('stateChanged', (container, prev, next) => {\n * console.log('State changed:', prev, '->', next);\n * });\n * ```\n */\nexport class StateContainerRegistry {\n private readonly instancesByConstructor = new WeakMap<\n StateContainerConstructor,\n Map<string, InstanceEntry>\n >();\n\n /**\n * Known storage key for each live instance, so disposal can delete its\n * Map entry directly instead of scanning every entry for identity (P3).\n */\n private readonly _keyByInstance = new WeakMap<\n StateContainer<any, any, any>,\n string\n >();\n\n /** Id index for O(1) `findEntryById` lookups (P6, used by devtools' `getRefIds`). */\n private readonly _byId = new Map<string, InstanceEntry>();\n\n private readonly types = new Set<StateContainerConstructor>();\n\n private _registeredTypes = new WeakSet<StateContainerConstructor>();\n\n private readonly listeners = new Map<\n LifecycleEvent,\n Set<(...args: any[]) => void>\n >();\n\n private _stateChangedListenerCount = 0;\n get hasStateChangedListeners(): boolean {\n return this._stateChangedListenerCount > 0;\n }\n private _pendingStateChanges: Array<\n [StateContainer<any, any, any>, any, any]\n > | null = null;\n\n private _autoRefIdCounter = 0;\n\n constructor() {\n // Self-prune on direct dispose (bypassing release()) and sweep any\n // depend()-owner edges this instance held, so orphaned dependencies\n // (created via `ensure`, which never adds a public ref) don't leak.\n this.on('disposed', (container) => this._handleDisposed(container));\n }\n\n /**\n * Registry-internal reaction to any instance's `disposed` lifecycle event.\n * Prunes its Map entry, if this registry was tracking it (i.e. it was\n * `acquire()`/`ensure()`'d, not a bare `new`), and always releases its\n * dependent edges on whatever it `depend()`'d on.\n */\n private _handleDisposed(container: StateContainer<any, any, any>): void {\n const Type = container.constructor as StateContainerConstructor;\n this._pruneEntry(Type, container);\n // Sweep edges actually RESOLVED (via handle.track/untracked), not just\n // the single declared default key on `$blac.dependencies`. A dep that\n // was `depend()`-declared but never resolved never acquired a registry\n // entry/dependents edge, so there is nothing to release for it here.\n const depEdges = (container as unknown as DepEdgeInternals)._depEdges;\n if (depEdges) {\n for (const [DepType, keys] of depEdges) {\n for (const key of keys) {\n this._releaseDependent(DepType, key, container);\n }\n }\n }\n }\n\n /**\n * Remove the Map entry for `container`, if this registry is tracking it.\n * O(1): looks up the entry's key via `_keyByInstance` instead of scanning\n * every entry for identity. Keeps an identity guard so a recreated entry\n * under the same key (a fresh instance under a reused/derived key) is\n * never deleted by a stale container's disposal.\n * @returns true if an entry was found and removed\n */\n private _pruneEntry(\n Type: StateContainerConstructor,\n container: StateContainer<any, any, any>,\n ): boolean {\n const instances = this.instancesByConstructor.get(Type);\n if (!instances) return false;\n const key = this._keyByInstance.get(container);\n if (key === undefined) return false;\n const entry = instances.get(key);\n if (!entry || entry.instance !== container) return false;\n instances.delete(key);\n this._forgetEntry(entry);\n this._maybeDropType(Type, instances);\n return true;\n }\n\n /**\n * Single removal point for the `_byId` index (P6). Every path that drops\n * an `InstanceEntry` from the registry MUST route through this so the\n * index can never leak a stale id -> entry mapping.\n */\n private _forgetEntry(entry: InstanceEntry): void {\n if (entry.id !== undefined) {\n this._byId.delete(entry.id);\n }\n }\n\n /**\n * O(1) entry lookup by `$blac.id`, used by `PluginContext.getRefIds`\n * instead of a nested scan over every type x every instance.\n */\n findEntryById(id: string): InstanceEntry | undefined {\n return this._byId.get(id);\n }\n\n /**\n * Storage key `container` is CURRENTLY indexed under, or `undefined` if this\n * registry never tracked it (bare `new`) or no longer does (disposed/pruned,\n * or its key was taken over by a newer instance). Lets callers that hold only\n * an instance address it without knowing the `args` it was acquired with.\n */\n keyOf(instance: StateContainerInstance): string | undefined {\n // Parameter is `StateContainerInstance` so `getAll`'s output (typed\n // `InstanceReadonlyState`, which `Omit`s the private members away) can be\n // passed straight in — otherwise every call site needs this cast instead.\n const container = instance as unknown as StateContainer<any, any, any>;\n const key = this._keyByInstance.get(container);\n if (key === undefined) return undefined;\n // `_keyByInstance` is never pruned — it relies on GC of the instance — so it\n // still answers for a disposed container. Confirm the live entry under that\n // key is STILL this container: once a fresh instance has taken the key over\n // (same args ⇒ same structural key, so this is the normal case after a\n // teardown + recreate), handing the key back would let a caller such as\n // `releaseInstance` drop a ref belonging to that unrelated instance — or\n // force-dispose it. Identity is the only thing separating the two.\n const entry = this.instancesByConstructor\n .get(container.constructor as StateContainerConstructor)\n ?.get(key);\n return entry?.instance === container ? key : undefined;\n }\n\n /**\n * Drop `Type` from `types` once its instances map is empty, so constructors\n * (and anything keyed on them, e.g. a per-class PathInterner) aren't held\n * alive forever. Deliberate consequence: `getStats()`/`getTypes()` no\n * longer list types with zero live instances.\n */\n private _maybeDropType(\n Type: StateContainerConstructor,\n instances: Map<string, InstanceEntry>,\n ): void {\n if (instances.size === 0) this.types.delete(Type);\n }\n\n /**\n * Drop `dependent`'s edge on the `Type`/`key` entry (a `depend()`-resolved\n * instance). When that leaves the entry with no dependents AND no public\n * refs AND it isn't keepAlive, dispose it — this recurses into the same\n * `disposed` listener, so dep-of-dep chains unwind naturally.\n */\n private _releaseDependent(\n Type: StateContainerConstructor,\n key: string,\n dependent: StateContainer<any, any, any>,\n ): void {\n const instances = this.instancesByConstructor.get(Type);\n const entry = instances?.get(key);\n if (!entry) return;\n entry.dependents?.delete(dependent);\n if (\n (!entry.dependents || entry.dependents.size === 0) &&\n entry.refs.size === 0 &&\n !isKeepAliveClass(Type) &&\n !entry.instance.$blac.disposed\n ) {\n entry.instance.dispose();\n }\n }\n\n /**\n * Register a type for lifecycle event tracking\n * @param constructor - The StateContainer class constructor\n */\n registerType<T extends StateContainerConstructor>(constructor: T): void {\n this.types.add(constructor);\n }\n\n /**\n * Register a StateContainer class with configuration\n * @param constructor - The StateContainer class constructor\n * @throws Error if type is already registered\n */\n register<T extends StateContainerConstructor>(constructor: T): void {\n const className = constructor.name;\n\n if (this._registeredTypes.has(constructor)) {\n throw new Error(\n `${BLAC_ERROR_PREFIX} Type \"${className}\" is already registered`,\n );\n }\n\n this._registeredTypes.add(constructor);\n this.registerType(constructor);\n }\n\n private ensureInstancesMap<T extends StateContainerConstructor>(\n Type: T,\n ): Map<string, InstanceEntry> {\n let instances = this.instancesByConstructor.get(Type);\n if (!instances) {\n instances = new Map<string, InstanceEntry>();\n this.instancesByConstructor.set(Type, instances);\n }\n return instances;\n }\n\n /**\n * Get the instances Map for a specific class (public API for stats/debugging)\n */\n getInstancesMap<T extends StateContainerConstructor>(\n Type: T,\n ): Map<string, InstanceEntry> {\n return this.instancesByConstructor.get(Type) || new Map();\n }\n\n /**\n * Directly insert an instance entry into the registry without going through\n * acquire/release. Creates the internal WeakMap bucket for the constructor if\n * it does not exist yet. Replaces any existing entry for the same key.\n *\n * The provided instance is NOT configured or disposed here — callers are\n * responsible for any initConfig / dispose calls. Intended for testing\n * helpers that create stubs outside the normal acquisition path.\n *\n * @internal Used by testing helpers only.\n */\n insertInstance<T extends StateContainerConstructor>(\n Type: T,\n instanceKey: string,\n instance: InstanceType<T>,\n refs: Map<string, number> = new Map(),\n ): void {\n const instances = this.ensureInstancesMap(Type);\n const existingEntry = instances.get(instanceKey);\n if (existingEntry && existingEntry.instance !== instance) {\n if (!existingEntry.instance.$blac.disposed) {\n existingEntry.instance.dispose();\n }\n this._forgetEntry(existingEntry);\n }\n const entry: InstanceEntry = { instance, refs };\n instances.set(instanceKey, entry);\n this._keyByInstance.set(instance, instanceKey);\n // Testing helper: `instance` may not have gone through `INIT_CONFIG` yet,\n // so `$blac.id` here may not be its FINAL id (see `acquire`'s comment).\n // Index whatever id is current now; removal always keys off `entry.id`.\n entry.id = instance.$blac.id;\n this._byId.set(entry.id, entry);\n }\n\n /**\n * Resolve the storage key for an instance. This is the single source of truth\n * for keying — `acquire` and `release` MUST agree, otherwise a ref taken under\n * an args-derived key is never dropped (instance leaks).\n *\n * Resolution order (explicit beats derived):\n * explicit key > `static key(args)` > structural hash of args > default sentinel.\n *\n * @param Type - The StateContainer class constructor\n * @param instanceKey - Explicit key, or undefined to derive from args\n * @param args - Construction args used for structural/`static key` derivation\n */\n resolveKey<T extends StateContainerConstructor = StateContainerConstructor>(\n Type: T,\n instanceKey: string | undefined,\n args: unknown,\n ): string {\n if (instanceKey !== undefined) {\n return instanceKey;\n }\n const keyFn = getClassKey(Type);\n if (keyFn) {\n return keyFn(args);\n }\n if (args !== undefined) {\n return structuralKey(args);\n }\n return DEFAULT_STRUCTURAL_KEY;\n }\n\n /**\n * Circuit breaker for runaway instance creation. Throws when a single\n * constructor would exceed `maxInstancesPerType` live instances — almost\n * always an unstable instance key (e.g. a new object/array passed as `args`\n * every render, or a missing `static key`) leaking an instance per render.\n */\n private assertInstanceLimit(\n Type: StateContainerConstructor,\n currentCount: number,\n ): void {\n const limit = getBlacConfig().maxInstancesPerType;\n if (limit > 0 && currentCount >= limit) {\n throw new Error(\n `${BLAC_ERROR_PREFIX} ${Type.name} exceeded the maximum of ${limit} live instances. ` +\n `This usually means the instance key is unstable — e.g. \\`args\\` that ` +\n `change identity every render, or a missing \\`static key\\` — so a new ` +\n `instance is created and never disposed (memory leak). Stabilize the key, ` +\n `add a \\`static key(args)\\`, or raise \\`configureBlac({ maxInstancesPerType })\\`.`,\n );\n }\n }\n\n /**\n * Circuit breaker for runaway reference growth. Throws when one instance\n * accumulates more than `maxRefsPerInstance` distinct live refs — almost\n * always consumer cleanup (e.g. `useBloc`'s unmount `release`) never firing.\n */\n private assertRefLimit(\n Type: StateContainerConstructor,\n resolvedKey: string,\n refCount: number,\n ): void {\n const limit = getBlacConfig().maxRefsPerInstance;\n if (limit > 0 && refCount > limit) {\n throw new Error(\n `${BLAC_ERROR_PREFIX} ${Type.name} instance \"${resolvedKey}\" exceeded the maximum of ${limit} live references. ` +\n `This usually means references are acquired without a matching release ` +\n `(e.g. a consumer that never unmounts/cleans up), leaking refs that keep ` +\n `the instance alive forever. Ensure every acquire is paired with a release, ` +\n `or raise \\`configureBlac({ maxRefsPerInstance })\\`.`,\n );\n }\n }\n\n /**\n * Acquire an instance with ref tracking (ownership semantics).\n * Creates a new instance if one doesn't exist, or returns existing and adds a ref.\n * You must call `release()` with the same refId when done.\n *\n * @internal Internal key tier. Public callers use the args-based `acquire`\n * wrapper; `useBloc` and `watch` address a pre-resolved key here.\n * @param Type - The StateContainer class constructor\n * @param instanceKey - Pre-resolved instance key (defaults to 'default')\n * @param options - Acquisition options\n * @param options.canCreate - Whether to create new instance if not found (default: true)\n * @param options.countRef - Whether to add a reference (default: true)\n * @param options.refId - Named reference ID for debugging; auto-generated if omitted\n * @param options.dependent - The `depend()`-owner resolving this instance, if any;\n * recorded so its dependent edge can be released on the owner's disposal.\n * @returns The state container instance\n */\n acquire<T extends StateContainerConstructor = StateContainerConstructor>(\n Type: T,\n instanceKey?: string,\n options: {\n canCreate?: boolean;\n countRef?: boolean;\n refId?: string;\n args?: unknown;\n dependent?: StateContainer<any, any, any>;\n } = {},\n ): InstanceType<T> {\n const { canCreate = true, countRef = true } = options;\n const args = options.args;\n\n const resolvedKey = this.resolveKey(Type, instanceKey, args);\n\n const config: StateContainerConfig = {\n instanceId: resolvedKey,\n args,\n };\n\n const instances = this.ensureInstancesMap(Type);\n let entry = instances.get(resolvedKey);\n\n // Detect stale disposed entries (disposed directly, not through release)\n if (entry?.instance.$blac.disposed) {\n instances.delete(resolvedKey);\n entry = undefined;\n }\n\n if (entry) {\n // Dev-warn when the same key is reused with structurally different args.\n if (\n process.env.NODE_ENV !== 'production' &&\n args !== undefined &&\n entry.args !== undefined\n ) {\n const incomingKey = structuralKey(args);\n const storedKey = (entry.argsKey ??= structuralKey(entry.args));\n if (incomingKey !== storedKey) {\n console.warn(\n `${BLAC_ERROR_PREFIX} ${Type.name} instance key \"${resolvedKey}\" was acquired with different args. ` +\n `Existing args: ${storedKey}, new args: ${incomingKey}. ` +\n `The existing instance will be reused. If distinct args should produce distinct instances, ` +\n `either remove the explicit instanceKey or provide a \\`static key\\` function that reflects the difference.`,\n );\n }\n }\n\n if (countRef) {\n const refId = options.refId ?? `_auto_${this._autoRefIdCounter++}`;\n entry.refs.set(refId, (entry.refs.get(refId) ?? 0) + 1);\n this.assertRefLimit(Type, resolvedKey, entry.refs.size);\n this.emit('refAcquired', entry.instance, refId);\n }\n\n if (options.dependent) {\n (entry.dependents ??= new Set()).add(options.dependent);\n }\n\n return entry.instance;\n }\n\n if (!canCreate) {\n throw new Error(\n `${BLAC_ERROR_PREFIX} ${Type.name} instance \"${resolvedKey}\" not found and creation is disabled.`,\n );\n }\n\n // Circuit breaker: refuse to create when this type already holds too many\n // live instances — a runaway key (unstable/args-derived) never disposing.\n this.assertInstanceLimit(Type, instances.size);\n\n // Create new shared instance\n const instance = new Type() as InstanceType<T>;\n const initialRefs = new Map<string, number>();\n let initialRefId: string | undefined;\n if (countRef) {\n initialRefId = options.refId ?? `_auto_${this._autoRefIdCounter++}`;\n initialRefs.set(initialRefId, 1);\n }\n const newEntry: InstanceEntry = { instance, refs: initialRefs, args };\n if (options.dependent) {\n (newEntry.dependents ??= new Set()).add(options.dependent);\n }\n // Register the entry + type BEFORE running init() so a cyclic ensure()\n // or a plugin onCreated that queries/ensures the registry sees this\n // instance instead of recursing into a fresh duplicate.\n instances.set(resolvedKey, newEntry);\n this.registerType(Type);\n // Key index goes in WITH the entry, not after `INIT_CONFIG`: it doesn't\n // depend on `$blac.id`, and `_pruneEntry` relies on it exclusively (there\n // is no identity scan to fall back on). An `init()` — or a plugin\n // `onCreated` — that disposes the instance must still be prunable.\n this._keyByInstance.set(instance, resolvedKey);\n\n try {\n instance[INIT_CONFIG](config);\n } catch (error) {\n instances.delete(resolvedKey);\n throw error;\n }\n\n // The id index, by contrast, must wait for `INIT_CONFIG`: `$blac.id` is\n // assigned inside it, so only now is the id the final one.\n newEntry.id = instance.$blac.id;\n this._byId.set(newEntry.id, newEntry);\n\n if (initialRefId) {\n this.emit('refAcquired', instance, initialRefId);\n }\n\n return instance;\n }\n\n /**\n * Borrow an existing instance without adding a ref (borrowing semantics).\n * Tracks cross-bloc dependency for reactive updates.\n *\n * @internal Internal key tier; public callers use the args-based `borrow`.\n * @param Type - The StateContainer class constructor\n * @param instanceKey - Pre-resolved instance key (defaults to 'default')\n * @returns The state container instance\n * @throws Error if instance doesn't exist\n */\n borrow<T extends StateContainerConstructor = StateContainerConstructor>(\n Type: T,\n instanceKey: string = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY,\n ): InstanceType<T> {\n return this.acquire(Type, instanceKey, {\n canCreate: false,\n countRef: false,\n });\n }\n\n /**\n * Safely borrow an existing instance (borrowing semantics with error handling).\n * Returns discriminated union for type-safe conditional access.\n *\n * @internal Internal key tier; public callers use the args-based `borrowSafe`.\n * @param Type - The StateContainer class constructor\n * @param instanceKey - Pre-resolved instance key (defaults to 'default')\n * @returns Discriminated union with either the instance or an error\n */\n borrowSafe<T extends StateContainerConstructor = StateContainerConstructor>(\n Type: T,\n instanceKey: string = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY,\n ):\n | { error: Error; instance: null }\n | { error: null; instance: InstanceType<T> } {\n try {\n const instance = this.borrow(Type, instanceKey);\n return { error: null, instance };\n } catch (error: any) {\n return { error, instance: null };\n }\n }\n\n /**\n * Ensure an instance exists without taking ownership (for bloc-to-bloc communication).\n * Gets existing instance OR creates it if it doesn't exist, without adding a ref.\n * Tracks cross-bloc dependency for reactive updates.\n *\n * Use this in bloc-to-bloc communication when you need to ensure an instance exists\n * but don't want to claim ownership (no ref added).\n *\n * @internal Internal key tier; public callers use the args-based `ensure`.\n * @param Type - The StateContainer class constructor\n * @param instanceKey - Pre-resolved instance key, or undefined to derive from `args`\n * (`static key(args)` / structural hash), matching `acquire`.\n * @param args - Construction args; used for keying when no explicit key is given\n * @returns The state container instance\n */\n ensure<T extends StateContainerConstructor = StateContainerConstructor>(\n Type: T,\n instanceKey?: string,\n args?: unknown,\n ): InstanceType<T> {\n return this.acquire(Type, instanceKey, {\n canCreate: true,\n countRef: false,\n args,\n });\n }\n\n /**\n * Release a reference to an instance.\n * Removes the ref and disposes when refs is empty (unless keepAlive).\n * Releasing an already-removed refId is a no-op (idempotent).\n *\n * @internal Internal key tier; public callers use the args-based `release`.\n * @param Type - The StateContainer class constructor\n * @param instanceKey - Pre-resolved instance key (defaults to 'default')\n * @param forceDispose - Force immediate disposal regardless of refs\n * @param refId - The specific ref to remove; removes one arbitrary ref if omitted\n */\n release<T extends StateContainerConstructor>(\n Type: T,\n instanceKey: string = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY,\n forceDispose = false,\n refId?: string,\n ): void {\n const instances = this.instancesByConstructor.get(Type);\n const entry = instances?.get(instanceKey);\n\n if (!instances || !entry) return;\n\n // Force dispose immediately\n if (forceDispose) {\n if (!entry.instance.$blac.disposed) {\n entry.instance.dispose();\n }\n instances.delete(instanceKey);\n this._forgetEntry(entry);\n this._maybeDropType(Type, instances);\n return;\n }\n\n // Decrement the named ref's count; when no refId is given, drop one\n // arbitrary ref so an unscoped release still frees a reference.\n let releasedRefId: string | undefined;\n if (refId !== undefined) {\n const count = entry.refs.get(refId) ?? 0;\n if (count <= 1) {\n entry.refs.delete(refId);\n } else {\n entry.refs.set(refId, count - 1);\n }\n releasedRefId = refId;\n } else {\n const firstKey = entry.refs.keys().next().value;\n if (firstKey !== undefined) {\n const count = entry.refs.get(firstKey) ?? 0;\n if (count <= 1) {\n entry.refs.delete(firstKey);\n } else {\n entry.refs.set(firstKey, count - 1);\n }\n releasedRefId = firstKey;\n }\n }\n\n if (releasedRefId) {\n this.emit('refReleased', entry.instance, releasedRefId);\n }\n\n // Check static keepAlive property\n const keepAlive = isKeepAliveClass(Type);\n\n // Auto-dispose when refs are empty (unless keepAlive). Orphaned\n // depend()-created dependencies are swept via the `disposed` listener\n // (see `_handleDisposed`/`_releaseDependent`), not here.\n if (entry.refs.size === 0 && !keepAlive) {\n if (!entry.instance.$blac.disposed) {\n entry.instance.dispose();\n }\n instances.delete(instanceKey);\n this._forgetEntry(entry);\n this._maybeDropType(Type, instances);\n }\n }\n\n /**\n * Get all instances of a specific type.\n * @param Type - The StateContainer class constructor\n * @returns Array of all instances\n */\n getAll<T extends StateContainerConstructor>(\n Type: T,\n ): InstanceReadonlyState<T>[] {\n const instances = this.instancesByConstructor.get(Type);\n const result: InstanceReadonlyState<T>[] = [];\n if (!instances) return result;\n for (const entry of instances.values()) {\n if (!entry.instance.$blac.disposed) {\n result.push(entry.instance);\n }\n }\n return result;\n }\n\n /**\n * Safely iterate over all instances of a type.\n * Skips disposed instances and catches callback errors.\n * @param Type - The StateContainer class constructor\n * @param callback - Function to call for each instance\n */\n forEach<T extends StateContainerConstructor>(\n Type: T,\n callback: (instance: InstanceReadonlyState<T>) => void,\n ): void {\n const instances = this.instancesByConstructor.get(Type);\n if (!instances) return;\n for (const entry of instances.values()) {\n const instance = entry.instance;\n if (!instance.$blac.disposed) {\n try {\n callback(instance);\n } catch (error) {\n console.error(\n `${BLAC_ERROR_PREFIX} forEach callback error for ${Type.name}:`,\n error,\n );\n }\n }\n }\n }\n\n /**\n * Clear all instances of a specific type (disposes them).\n * @param Type - The StateContainer class constructor\n */\n clear<T extends StateContainerConstructor>(Type: T): void {\n const instances = this.instancesByConstructor.get(Type);\n if (!instances) return;\n // Dispose all instances\n for (const entry of instances.values()) {\n if (!entry.instance.$blac.disposed) {\n entry.instance.dispose();\n }\n this._forgetEntry(entry);\n }\n // Clear the Map\n instances.clear();\n this._maybeDropType(Type, instances);\n }\n\n /**\n * Get reference count for an instance (number of active refs).\n *\n * @internal Internal key tier; public callers use the args-based `getRefCount`.\n * @param Type - The StateContainer class constructor\n * @param instanceKey - Pre-resolved instance key (defaults to 'default')\n * @returns Current ref count (0 if instance doesn't exist)\n */\n getRefCount<T extends StateContainerConstructor>(\n Type: T,\n instanceKey: string = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY,\n ): number {\n const instances = this.instancesByConstructor.get(Type);\n const entry = instances?.get(instanceKey);\n return entry?.refs.size ?? 0;\n }\n\n /**\n * Get all active reference IDs for an instance.\n *\n * @internal Internal key tier; public callers use the args-based `getRefIds`.\n * @param Type - The StateContainer class constructor\n * @param instanceKey - Pre-resolved instance key (defaults to 'default')\n * @returns Array of ref ID strings (empty if instance doesn't exist)\n */\n getRefIds<T extends StateContainerConstructor>(\n Type: T,\n instanceKey: string = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY,\n ): string[] {\n const instances = this.instancesByConstructor.get(Type);\n if (!instances) return [];\n const entry = instances.get(instanceKey);\n return entry ? Array.from(entry.refs.keys()) : [];\n }\n\n /**\n * Check if an instance exists.\n *\n * @internal Internal key tier; public callers use the args-based `hasInstance`.\n * @param Type - The StateContainer class constructor\n * @param instanceKey - Pre-resolved instance key (defaults to 'default')\n * @returns true if instance exists\n */\n hasInstance<T extends StateContainerConstructor>(\n Type: T,\n instanceKey: string = BLAC_DEFAULTS.DEFAULT_INSTANCE_KEY,\n ): boolean {\n const instances = this.instancesByConstructor.get(Type);\n return instances?.has(instanceKey) ?? false;\n }\n\n /**\n * Clear all instances from all types (for testing)\n *\n * Iterates all registered types and clears their instances.\n * Also clears type tracking to reset the registry state.\n */\n clearAll(): void {\n // Step 1: Clear instances from each type (while we still have the types list)\n for (const Type of this.types) {\n this.clear(Type);\n }\n // Step 2: Now clear type tracking (resets registry state for tests)\n this.types.clear();\n this._registeredTypes = new WeakSet<StateContainerConstructor>();\n }\n\n /**\n * Get registry statistics for debugging.\n * @returns Object with registeredTypes, totalInstances, and typeBreakdown\n */\n getStats(): {\n registeredTypes: number;\n totalInstances: number;\n typeBreakdown: Record<string, number>;\n } {\n const typeBreakdown: Record<string, number> = {};\n let totalInstances = 0;\n\n // Collect stats from each registered type\n for (const Type of this.types) {\n const typeName = Type.name;\n const instances = this.getInstancesMap(Type);\n const count = instances.size;\n\n typeBreakdown[typeName] = count;\n totalInstances += count;\n }\n\n return {\n registeredTypes: this.types.size,\n totalInstances,\n typeBreakdown,\n };\n }\n\n /**\n * Get all registered types (for plugin system).\n * @returns Array of all registered StateContainer class constructors\n */\n getTypes(): StateContainerConstructor[] {\n return Array.from(this.types);\n }\n\n /**\n * Subscribe to lifecycle events\n * @param event - The lifecycle event to listen for\n * @param listener - The listener function to call when the event occurs\n * @returns Unsubscribe function\n */\n on<E extends LifecycleEvent>(\n event: E,\n listener: LifecycleListener<E>,\n ): () => void {\n if (!this.listeners.has(event)) {\n this.listeners.set(event, new Set());\n }\n const instance = this.listeners.get(event);\n if (!instance) {\n throw new Error(\n `${BLAC_ERROR_PREFIX} Failed to register listener for event '${event}'`,\n );\n }\n\n instance.add(listener as (...args: any[]) => void);\n\n if (event === 'stateChanged') {\n this._stateChangedListenerCount++;\n }\n\n // Return unsubscribe function\n return () => {\n const deleted = this.listeners\n .get(event)\n ?.delete(listener as (...args: any[]) => void);\n if (deleted && event === 'stateChanged') {\n this._stateChangedListenerCount--;\n }\n };\n }\n\n /**\n * Emit lifecycle event to all listeners\n * @internal - Called by StateContainer lifecycle methods\n */\n emit(event: 'created', container: StateContainer<any, any, any>): void;\n emit(event: 'disposed', container: StateContainer<any, any, any>): void;\n emit(\n event: 'stateChanged',\n container: StateContainer<any, any, any>,\n previousState: any,\n currentState: any,\n ): void;\n emit(\n event: 'refAcquired',\n container: StateContainer<any, any, any>,\n refId: string,\n ): void;\n emit(\n event: 'refReleased',\n container: StateContainer<any, any, any>,\n refId: string,\n ): void;\n emit(\n event: 'depsChanged',\n container: StateContainer<any, any, any>,\n previousDeps: Readonly<Record<string, unknown>>,\n currentDeps: Readonly<Record<string, unknown>>,\n ): void;\n emit(\n event: 'hydrationChanged',\n container: StateContainer<any, any, any>,\n status: HydrationStatus,\n previousStatus: HydrationStatus,\n ): void;\n emit(event: LifecycleEvent, ...args: any[]): void {\n const listeners = this.listeners.get(event);\n if (!listeners || listeners.size === 0) return; // Zero overhead when no listeners\n\n for (const listener of listeners) {\n try {\n listener(...args);\n } catch (error) {\n console.error(\n `${BLAC_ERROR_PREFIX} Listener error for '${event}':`,\n error,\n );\n }\n }\n }\n\n /**\n * Schedule a deferred stateChanged notification via microtask.\n * Skips entirely when no stateChanged listeners are registered.\n * @internal - Called by StateContainer.applyState\n */\n notifyStateChanged(\n container: StateContainer<any, any, any>,\n previousState: any,\n newState: any,\n ): void {\n if (this._stateChangedListenerCount === 0) return;\n\n if (!this._pendingStateChanges) {\n this._pendingStateChanges = [];\n queueMicrotask(() => this.flushStateChanged());\n }\n this._pendingStateChanges.push([container, previousState, newState]);\n }\n\n private flushStateChanged(): void {\n const pending = this._pendingStateChanges;\n this._pendingStateChanges = null;\n if (!pending) return;\n\n for (const [container, prev, next] of pending) {\n this.emit('stateChanged', container, prev, next);\n }\n }\n}\n\n/**\n * Global default registry instance\n */\nexport const globalRegistry = new StateContainerRegistry();\n\n/**\n * Global plugin manager (initialized lazily)\n */\nlet _globalPluginManager: PluginManager | null = null;\n\n/**\n * Get the global plugin manager\n */\nexport function getPluginManager(): PluginManager {\n if (!_globalPluginManager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