@akashjs/runtime 0.1.29 → 0.1.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/store.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkA3VPGLBN_cjs=require('./chunk-A3VPGLBN.cjs');require('./chunk-RTJ6UDGV.cjs');Object.defineProperty(exports,"__getStoreInstances",{enumerable:true,get:function(){return chunkA3VPGLBN_cjs.d}});Object.defineProperty(exports,"clearStores",{enumerable:true,get:function(){return chunkA3VPGLBN_cjs.c}});Object.defineProperty(exports,"configureStores",{enumerable:true,get:function(){return chunkA3VPGLBN_cjs.a}});Object.defineProperty(exports,"defineStore",{enumerable:true,get:function(){return chunkA3VPGLBN_cjs.b}});//# sourceMappingURL=store.cjs.map
1
+ 'use strict';var chunkOCBLY4E4_cjs=require('./chunk-OCBLY4E4.cjs');require('./chunk-RTJ6UDGV.cjs');Object.defineProperty(exports,"__getStoreInstances",{enumerable:true,get:function(){return chunkOCBLY4E4_cjs.d}});Object.defineProperty(exports,"clearStores",{enumerable:true,get:function(){return chunkOCBLY4E4_cjs.c}});Object.defineProperty(exports,"configureStores",{enumerable:true,get:function(){return chunkOCBLY4E4_cjs.a}});Object.defineProperty(exports,"defineStore",{enumerable:true,get:function(){return chunkOCBLY4E4_cjs.b}});//# sourceMappingURL=store.cjs.map
2
2
  //# sourceMappingURL=store.cjs.map
package/dist/store.js CHANGED
@@ -1,2 +1,2 @@
1
- export{d as __getStoreInstances,c as clearStores,a as configureStores,b as defineStore}from'./chunk-4PK4YNND.js';import'./chunk-TWA4T6PX.js';//# sourceMappingURL=store.js.map
1
+ export{d as __getStoreInstances,c as clearStores,a as configureStores,b as defineStore}from'./chunk-DZGRBVSY.js';import'./chunk-TWA4T6PX.js';//# sourceMappingURL=store.js.map
2
2
  //# sourceMappingURL=store.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akashjs/runtime",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "description": "AkashJS core runtime — signals, components, DOM rendering",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/store.ts"],"names":["globalPlugins","configureStores","options","storeInstances","defineStore","id","definition","initialState","store","createStoreInstance","stateSignals","stateKeys","key","signal","getterFn","computed","plugins","actionFn","args","plugin","fresh","partial","value","snapshot","subscribers","subscribeEffect","callback","isInitial","effect","cb","clearStores","__getStoreInstances"],"mappings":"wCAoFA,IAAMA,EAA+B,EAAC,CAG/B,SAASC,CAAAA,CAAgBC,EAA2C,CACzEF,CAAAA,CAAc,IAAA,CAAK,GAAGE,EAAQ,OAAO,EACvC,CAIA,IAAMC,EAAiB,IAAI,GAAA,CAQpB,SAASC,CAAAA,CAKdC,EACAC,CAAAA,CACsB,CACtB,OAAO,IAAM,CAEX,GAAIH,CAAAA,CAAe,GAAA,CAAIE,CAAE,EACvB,OAAOF,CAAAA,CAAe,GAAA,CAAIE,CAAE,EAG9B,IAAME,CAAAA,CAAeD,CAAAA,CAAW,KAAA,GAC1BE,CAAAA,CAAQC,CAAAA,CAAoBJ,CAAAA,CAAIE,CAAAA,CAAcD,CAAU,CAAA,CAC9D,OAAAH,CAAAA,CAAe,GAAA,CAAIE,EAAIG,CAAK,CAAA,CACrBA,CACT,CACF,CAEA,SAASC,CAAAA,CAKPJ,CAAAA,CACAE,CAAAA,CACAD,EACgB,CAEhB,IAAMI,CAAAA,CAAgD,GAChDC,CAAAA,CAAY,MAAA,CAAO,IAAA,CAAKJ,CAAY,EAE1C,IAAA,IAAWK,CAAAA,IAAOD,EAChBD,CAAAA,CAAaE,CAAG,EAAIC,CAAAA,CAAON,CAAAA,CAAaK,CAAG,CAAC,EAI9C,IAAMJ,GAAAA,CAAa,CAAE,GAAA,CAAKH,CAAG,CAAA,CAG7B,IAAA,IAAWO,CAAAA,IAAOD,CAAAA,CAChBH,IAAMI,CAAG,CAAA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AAAA,IAAOD,CAAAA,CAChBY,CAAAA,CAASX,CAAG,EAAIF,CAAAA,CAAaE,CAAG,CAAA,EAAE,CAEpC,OAAOW,CACT,CAAA,CAGA,IAAMC,CAAAA,CAAc,IAAI,GAAA,CACpBC,CAAAA,CAAuC,KAC3CjB,GAAAA,CAAM,UAAA,CAAckB,GAA+C,CAGjE,GAFAF,CAAAA,CAAY,GAAA,CAAIE,CAAQ,CAAA,CAEpB,CAACD,CAAAA,CAAiB,CACpB,IAAIE,CAAAA,CAAY,IAAA,CAChBF,CAAAA,CAAkBG,CAAAA,CAAO,IAAM,CAE7B,IAAA,IAAWhB,CAAAA,IAAOD,CAAAA,CAChBD,EAAaE,CAAG,CAAA,EAAE,CAGpB,GAAIe,EAAW,CACbA,CAAAA,CAAY,KAAA,CACZ,MACF,CACA,IAAMJ,CAAAA,CAAWf,GAAAA,CAAM,SAAA,GACvB,IAAA,IAAWqB,CAAAA,IAAML,EACfK,CAAAA,CAAGN,CAAQ,EAEf,CAAC,EACH,CACA,OAAO,IAAM,CACXC,CAAAA,CAAY,MAAA,CAAOE,CAAQ,EAEvBF,CAAAA,CAAY,IAAA,GAAS,CAAA,EAAKC,CAAAA,GAC5BA,GAAgB,CAChBA,CAAAA,CAAkB,IAAA,EAEtB,CACF,EAGA,IAAA,IAAWN,CAAAA,IAAUH,GAAAA,CAASG,CAAAA,CAAO,OAAOX,GAAK,CAAA,CAEjD,OAAOA,GACT,CAKO,SAASsB,CAAAA,EAAoB,CAClC3B,CAAAA,CAAe,QACjB,CAGO,SAAS4B,CAAAA,EAAyD,CACvE,OAAO5B,CACT","file":"chunk-4PK4YNND.js","sourcesContent":["/**\n * Global state management via defineStore().\n *\n * Stores are singleton signal containers that persist across\n * components. They provide shared state, computed getters,\n * and actions — no external library needed.\n *\n * ```ts\n * const useCounterStore = defineStore('counter', {\n * state: () => ({ count: 0, name: 'Counter' }),\n * getters: {\n * doubled: (state) => state.count() * 2,\n * },\n * actions: {\n * increment() { this.count.update(c => c + 1); },\n * reset() { this.count.set(0); },\n * },\n * });\n *\n * // In any component:\n * const store = useCounterStore();\n * store.count(); // 0\n * store.doubled(); // 0\n * store.increment();\n * store.count(); // 1\n * ```\n */\n\nimport { signal, computed, effect } from './signals.js';\nimport type { Signal, ReadonlySignal } from './signals.js';\n\n// --- Types ---\n\ntype StateFactory<S> = () => S;\n\ntype Getters<S, G> = {\n [K in keyof G]: (state: SignalifiedState<S>) => G[K];\n};\n\ntype Actions<A> = {\n [K in keyof A]: A[K] extends (...args: infer P) => infer R\n ? (...args: P) => R\n : never;\n};\n\n/** Maps plain state values to signals */\ntype SignalifiedState<S> = {\n [K in keyof S]: Signal<S[K]>;\n};\n\n/** The store instance returned to consumers */\nexport type Store<S, G, A> = SignalifiedState<S> & {\n [K in keyof G]: ReadonlySignal<G[K]>;\n} & {\n [K in keyof A]: A[K] extends (...args: infer P) => infer R\n ? (...args: P) => R\n : never;\n} & {\n /** Reset all state to initial values */\n $reset(): void;\n /** Merge partial state into the store */\n $patch(partial: Partial<S>): void;\n /** Subscribe to all state changes */\n $subscribe(callback: (state: S) => void): () => void;\n /** Get a plain snapshot of current state */\n $snapshot(): S;\n /** Store ID */\n $id: string;\n};\n\nexport interface StoreDefinition<S, G, A> {\n state: StateFactory<S>;\n getters?: Getters<S, G>;\n actions?: A;\n plugins?: StorePlugin[];\n}\n\n// --- Plugin system ---\n\nexport interface StorePlugin {\n init?(store: Store<any, any, any>): void;\n onAction?(store: Store<any, any, any>, actionName: string, args: unknown[]): void;\n}\n\nconst globalPlugins: StorePlugin[] = [];\n\n/** Register global plugins that apply to all stores */\nexport function configureStores(options: { plugins: StorePlugin[] }): void {\n globalPlugins.push(...options.plugins);\n}\n\n// --- Store registry (singleton) ---\n\nconst storeInstances = new Map<string, Store<any, any, any>>();\n\n// --- defineStore ---\n\n/**\n * Define a global store. Returns a composable function that\n * always returns the same store instance (singleton).\n */\nexport function defineStore<\n S extends Record<string, unknown>,\n G extends Record<string, unknown> = {},\n A extends Record<string, (...args: any[]) => any> = {},\n>(\n id: string,\n definition: StoreDefinition<S, G, A>,\n): () => Store<S, G, A> {\n return () => {\n // Return existing instance if already created\n if (storeInstances.has(id)) {\n return storeInstances.get(id) as Store<S, G, A>;\n }\n\n const initialState = definition.state();\n const store = createStoreInstance(id, initialState, definition);\n storeInstances.set(id, store);\n return store;\n };\n}\n\nfunction createStoreInstance<\n S extends Record<string, unknown>,\n G extends Record<string, unknown>,\n A extends Record<string, (...args: any[]) => any>,\n>(\n id: string,\n initialState: S,\n definition: StoreDefinition<S, G, A>,\n): Store<S, G, A> {\n // Create signals for each state property\n const stateSignals: Record<string, Signal<unknown>> = {};\n const stateKeys = Object.keys(initialState);\n\n for (const key of stateKeys) {\n stateSignals[key] = signal(initialState[key]);\n }\n\n // Build the store object first so getters can reference other getters via `this`\n const store: any = { $id: id };\n\n // Add state signals\n for (const key of stateKeys) {\n store[key] = stateSignals[key];\n }\n\n // Create computed getters — bound to store so `this.otherGetter()` works\n if (definition.getters) {\n for (const [key, getterFn] of Object.entries(definition.getters)) {\n store[key] = computed(() =>\n (getterFn as Function).call(store, stateSignals),\n );\n }\n }\n\n // Collect all plugins (global + per-store)\n const plugins = [...globalPlugins, ...(definition.plugins ?? [])];\n\n // Bind actions with `this` pointing to the full store (state + getters + actions)\n if (definition.actions) {\n for (const [key, actionFn] of Object.entries(definition.actions)) {\n store[key] = (...args: unknown[]) => {\n for (const plugin of plugins) plugin.onAction?.(store, key, args);\n return (actionFn as Function).apply(store, args);\n };\n }\n }\n\n // $reset\n store.$reset = () => {\n const fresh = definition.state();\n for (const key of stateKeys) {\n stateSignals[key].set(fresh[key as keyof S]);\n }\n };\n\n // $patch — merge partial state\n store.$patch = (partial: Partial<S>) => {\n for (const [key, value] of Object.entries(partial)) {\n if (key in stateSignals) {\n stateSignals[key].set(value);\n }\n }\n };\n\n // $snapshot\n store.$snapshot = (): S => {\n const snapshot: Record<string, unknown> = {};\n for (const key of stateKeys) {\n snapshot[key] = stateSignals[key]();\n }\n return snapshot as S;\n };\n\n // $subscribe — watch all state signals and notify on change\n const subscribers = new Set<(state: S) => void>();\n let subscribeEffect: (() => void) | null = null;\n store.$subscribe = (callback: (state: S) => void): (() => void) => {\n subscribers.add(callback);\n // Start watching if this is the first subscriber\n if (!subscribeEffect) {\n let isInitial = true;\n subscribeEffect = effect(() => {\n // Read all state signals to track them\n for (const key of stateKeys) {\n stateSignals[key]();\n }\n // Skip initial run — only notify on actual changes\n if (isInitial) {\n isInitial = false;\n return;\n }\n const snapshot = store.$snapshot();\n for (const cb of subscribers) {\n cb(snapshot);\n }\n });\n }\n return () => {\n subscribers.delete(callback);\n // Dispose effect when no subscribers remain\n if (subscribers.size === 0 && subscribeEffect) {\n subscribeEffect();\n subscribeEffect = null;\n }\n };\n };\n\n // Initialize plugins\n for (const plugin of plugins) plugin.init?.(store);\n\n return store as Store<S, G, A>;\n}\n\n/**\n * Clear all store instances (useful for testing).\n */\nexport function clearStores(): void {\n storeInstances.clear();\n}\n\n/** @internal — exposes store registry for devtools */\nexport function __getStoreInstances(): Map<string, Store<any, any, any>> {\n return storeInstances;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/store.ts"],"names":["globalPlugins","configureStores","options","storeInstances","defineStore","id","definition","initialState","store","createStoreInstance","stateSignals","stateKeys","key","signal","getterFn","computed","plugins","actionFn","args","plugin","fresh","partial","value","snapshot","subscribers","subscribeEffect","callback","isInitial","effect","cb","clearStores","__getStoreInstances"],"mappings":"mEAoFA,IAAMA,EAA+B,EAAC,CAG/B,SAASC,CAAAA,CAAgBC,EAA2C,CACzEF,CAAAA,CAAc,IAAA,CAAK,GAAGE,EAAQ,OAAO,EACvC,CAIA,IAAMC,EAAiB,IAAI,GAAA,CAQpB,SAASC,CAAAA,CAKdC,EACAC,CAAAA,CACsB,CACtB,OAAO,IAAM,CAEX,GAAIH,CAAAA,CAAe,GAAA,CAAIE,CAAE,EACvB,OAAOF,CAAAA,CAAe,GAAA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ACA,OAAO,IAAM,CACXC,CAAAA,CAAY,MAAA,CAAOE,CAAQ,EAEvBF,CAAAA,CAAY,IAAA,GAAS,CAAA,EAAKC,CAAAA,GAC5BA,GAAgB,CAChBA,CAAAA,CAAkB,IAAA,EAEtB,CACF,EAGA,IAAA,IAAWN,CAAAA,IAAUH,CAAAA,CAASG,CAAAA,CAAO,OAAOX,CAAK,CAAA,CAEjD,OAAOA,CACT,CAKO,SAASsB,CAAAA,EAAoB,CAClC3B,CAAAA,CAAe,QACjB,CAGO,SAAS4B,CAAAA,EAAyD,CACvE,OAAO5B,CACT","file":"chunk-A3VPGLBN.cjs","sourcesContent":["/**\n * Global state management via defineStore().\n *\n * Stores are singleton signal containers that persist across\n * components. They provide shared state, computed getters,\n * and actions — no external library needed.\n *\n * ```ts\n * const useCounterStore = defineStore('counter', {\n * state: () => ({ count: 0, name: 'Counter' }),\n * getters: {\n * doubled: (state) => state.count() * 2,\n * },\n * actions: {\n * increment() { this.count.update(c => c + 1); },\n * reset() { this.count.set(0); },\n * },\n * });\n *\n * // In any component:\n * const store = useCounterStore();\n * store.count(); // 0\n * store.doubled(); // 0\n * store.increment();\n * store.count(); // 1\n * ```\n */\n\nimport { signal, computed, effect } from './signals.js';\nimport type { Signal, ReadonlySignal } from './signals.js';\n\n// --- Types ---\n\ntype StateFactory<S> = () => S;\n\ntype Getters<S, G> = {\n [K in keyof G]: (state: SignalifiedState<S>) => G[K];\n};\n\ntype Actions<A> = {\n [K in keyof A]: A[K] extends (...args: infer P) => infer R\n ? (...args: P) => R\n : never;\n};\n\n/** Maps plain state values to signals */\ntype SignalifiedState<S> = {\n [K in keyof S]: Signal<S[K]>;\n};\n\n/** The store instance returned to consumers */\nexport type Store<S, G, A> = SignalifiedState<S> & {\n [K in keyof G]: ReadonlySignal<G[K]>;\n} & {\n [K in keyof A]: A[K] extends (...args: infer P) => infer R\n ? (...args: P) => R\n : never;\n} & {\n /** Reset all state to initial values */\n $reset(): void;\n /** Merge partial state into the store */\n $patch(partial: Partial<S>): void;\n /** Subscribe to all state changes */\n $subscribe(callback: (state: S) => void): () => void;\n /** Get a plain snapshot of current state */\n $snapshot(): S;\n /** Store ID */\n $id: string;\n};\n\nexport interface StoreDefinition<S, G, A> {\n state: StateFactory<S>;\n getters?: Getters<S, G>;\n actions?: A;\n plugins?: StorePlugin[];\n}\n\n// --- Plugin system ---\n\nexport interface StorePlugin {\n init?(store: Store<any, any, any>): void;\n onAction?(store: Store<any, any, any>, actionName: string, args: unknown[]): void;\n}\n\nconst globalPlugins: StorePlugin[] = [];\n\n/** Register global plugins that apply to all stores */\nexport function configureStores(options: { plugins: StorePlugin[] }): void {\n globalPlugins.push(...options.plugins);\n}\n\n// --- Store registry (singleton) ---\n\nconst storeInstances = new Map<string, Store<any, any, any>>();\n\n// --- defineStore ---\n\n/**\n * Define a global store. Returns a composable function that\n * always returns the same store instance (singleton).\n */\nexport function defineStore<\n S extends Record<string, unknown>,\n G extends Record<string, unknown> = {},\n A extends Record<string, (...args: any[]) => any> = {},\n>(\n id: string,\n definition: StoreDefinition<S, G, A>,\n): () => Store<S, G, A> {\n return () => {\n // Return existing instance if already created\n if (storeInstances.has(id)) {\n return storeInstances.get(id) as Store<S, G, A>;\n }\n\n const initialState = definition.state();\n const store = createStoreInstance(id, initialState, definition);\n storeInstances.set(id, store);\n return store;\n };\n}\n\nfunction createStoreInstance<\n S extends Record<string, unknown>,\n G extends Record<string, unknown>,\n A extends Record<string, (...args: any[]) => any>,\n>(\n id: string,\n initialState: S,\n definition: StoreDefinition<S, G, A>,\n): Store<S, G, A> {\n // Create signals for each state property\n const stateSignals: Record<string, Signal<unknown>> = {};\n const stateKeys = Object.keys(initialState);\n\n for (const key of stateKeys) {\n stateSignals[key] = signal(initialState[key]);\n }\n\n // Build the store object first so getters can reference other getters via `this`\n const store: any = { $id: id };\n\n // Add state signals\n for (const key of stateKeys) {\n store[key] = stateSignals[key];\n }\n\n // Create computed getters — bound to store so `this.otherGetter()` works\n if (definition.getters) {\n for (const [key, getterFn] of Object.entries(definition.getters)) {\n store[key] = computed(() =>\n (getterFn as Function).call(store, stateSignals),\n );\n }\n }\n\n // Collect all plugins (global + per-store)\n const plugins = [...globalPlugins, ...(definition.plugins ?? [])];\n\n // Bind actions with `this` pointing to the full store (state + getters + actions)\n if (definition.actions) {\n for (const [key, actionFn] of Object.entries(definition.actions)) {\n store[key] = (...args: unknown[]) => {\n for (const plugin of plugins) plugin.onAction?.(store, key, args);\n return (actionFn as Function).apply(store, args);\n };\n }\n }\n\n // $reset\n store.$reset = () => {\n const fresh = definition.state();\n for (const key of stateKeys) {\n stateSignals[key].set(fresh[key as keyof S]);\n }\n };\n\n // $patch — merge partial state\n store.$patch = (partial: Partial<S>) => {\n for (const [key, value] of Object.entries(partial)) {\n if (key in stateSignals) {\n stateSignals[key].set(value);\n }\n }\n };\n\n // $snapshot\n store.$snapshot = (): S => {\n const snapshot: Record<string, unknown> = {};\n for (const key of stateKeys) {\n snapshot[key] = stateSignals[key]();\n }\n return snapshot as S;\n };\n\n // $subscribe — watch all state signals and notify on change\n const subscribers = new Set<(state: S) => void>();\n let subscribeEffect: (() => void) | null = null;\n store.$subscribe = (callback: (state: S) => void): (() => void) => {\n subscribers.add(callback);\n // Start watching if this is the first subscriber\n if (!subscribeEffect) {\n let isInitial = true;\n subscribeEffect = effect(() => {\n // Read all state signals to track them\n for (const key of stateKeys) {\n stateSignals[key]();\n }\n // Skip initial run — only notify on actual changes\n if (isInitial) {\n isInitial = false;\n return;\n }\n const snapshot = store.$snapshot();\n for (const cb of subscribers) {\n cb(snapshot);\n }\n });\n }\n return () => {\n subscribers.delete(callback);\n // Dispose effect when no subscribers remain\n if (subscribers.size === 0 && subscribeEffect) {\n subscribeEffect();\n subscribeEffect = null;\n }\n };\n };\n\n // Initialize plugins\n for (const plugin of plugins) plugin.init?.(store);\n\n return store as Store<S, G, A>;\n}\n\n/**\n * Clear all store instances (useful for testing).\n */\nexport function clearStores(): void {\n storeInstances.clear();\n}\n\n/** @internal — exposes store registry for devtools */\nexport function __getStoreInstances(): Map<string, Store<any, any, any>> {\n return storeInstances;\n}\n"]}