@kdeveloper/kvark 0.3.1 → 0.5.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.
@@ -0,0 +1,404 @@
1
+ //#region src/internal/types.ts
2
+ const CONFIG = Symbol("kvark.config");
3
+ const WRITABLE = Symbol("kvark.writable");
4
+ const FAMILY_LINK = Symbol("kvark.familyLink");
5
+ //#endregion
6
+ //#region src/internal/atom.ts
7
+ function atom(config) {
8
+ const internal = Object.create(null);
9
+ internal.get = config.get;
10
+ if (config.debugLabel != null) internal.debugLabel = config.debugLabel;
11
+ if (config.dependencies != null) internal.dependencies = config.dependencies;
12
+ if (config.stalePolicy != null) internal.stalePolicy = config.stalePolicy;
13
+ if (config.set != null) internal.set = config.set;
14
+ if (config.onMount != null) internal.onMount = config.onMount;
15
+ if (config.set != null) return {
16
+ [CONFIG]: internal,
17
+ [WRITABLE]: [],
18
+ debugLabel: config.debugLabel
19
+ };
20
+ return {
21
+ [CONFIG]: internal,
22
+ debugLabel: config.debugLabel
23
+ };
24
+ }
25
+ //#endregion
26
+ //#region src/internal/family.ts
27
+ function getFamilyLink(target) {
28
+ return target[FAMILY_LINK];
29
+ }
30
+ function atomFamily(options) {
31
+ const cachePolicy = options.cachePolicy ?? "keep-all";
32
+ const lruSize = options.lruSize ?? 100;
33
+ const cache = /* @__PURE__ */ new Map();
34
+ const lruOrder = [];
35
+ const storeCallbacks = /* @__PURE__ */ new Set();
36
+ const link = {
37
+ invalidateAtom(target) {
38
+ for (const cb of storeCallbacks) cb(target);
39
+ },
40
+ registerStore(cb) {
41
+ storeCallbacks.add(cb);
42
+ return () => {
43
+ storeCallbacks.delete(cb);
44
+ };
45
+ }
46
+ };
47
+ function attachLink(target) {
48
+ target[FAMILY_LINK] = link;
49
+ }
50
+ function getOrCreate(param) {
51
+ const cached = cache.get(param);
52
+ if (cached != null) {
53
+ if (cachePolicy === "lru") touchLru(param);
54
+ return cached;
55
+ }
56
+ const deps = options.dependencies?.(param);
57
+ const getFn = options.get(param);
58
+ const setFn = options.set?.(param);
59
+ const created = createAtom(options.debugLabel != null ? `${options.debugLabel}(${String(param)})` : void 0, deps, getFn, setFn);
60
+ attachLink(created);
61
+ cache.set(param, created);
62
+ if (cachePolicy === "lru") {
63
+ lruOrder.push(param);
64
+ evictLru();
65
+ }
66
+ return created;
67
+ }
68
+ function createAtom(label, deps, getFn, setFn) {
69
+ const base = { get: getFn };
70
+ if (label != null) base.debugLabel = label;
71
+ if (deps != null) base.dependencies = deps;
72
+ if (options.stalePolicy != null) base.stalePolicy = options.stalePolicy;
73
+ if (setFn != null) {
74
+ base.set = setFn;
75
+ return atom(base);
76
+ }
77
+ return atom(base);
78
+ }
79
+ function touchLru(param) {
80
+ const idx = lruOrder.indexOf(param);
81
+ if (idx !== -1) lruOrder.splice(idx, 1);
82
+ lruOrder.push(param);
83
+ }
84
+ function evictLru() {
85
+ while (lruOrder.length > lruSize) {
86
+ const evicted = lruOrder.shift();
87
+ if (evicted !== void 0) cache.delete(evicted);
88
+ }
89
+ }
90
+ const family = getOrCreate;
91
+ family.invalidate = (param) => {
92
+ const cached = cache.get(param);
93
+ if (cached != null) link.invalidateAtom(cached);
94
+ };
95
+ family.invalidateAll = () => {
96
+ for (const cached of cache.values()) link.invalidateAtom(cached);
97
+ };
98
+ family.remove = (param) => {
99
+ cache.delete(param);
100
+ if (cachePolicy === "lru") {
101
+ const idx = lruOrder.indexOf(param);
102
+ if (idx !== -1) lruOrder.splice(idx, 1);
103
+ }
104
+ };
105
+ family.getCache = () => cache;
106
+ return family;
107
+ }
108
+ //#endregion
109
+ //#region src/internal/store.ts
110
+ const PENDING_STATE = {
111
+ status: "pending",
112
+ value: void 0,
113
+ error: void 0
114
+ };
115
+ var Store = class {
116
+ #atoms = /* @__PURE__ */ new WeakMap();
117
+ #rdeps = /* @__PURE__ */ new Map();
118
+ #pending = /* @__PURE__ */ new Set();
119
+ #controllers = /* @__PURE__ */ new WeakMap();
120
+ #familyUnsubs = /* @__PURE__ */ new Set();
121
+ #registeredFamilies = /* @__PURE__ */ new WeakSet();
122
+ #client = null;
123
+ #getOrCreate(atom) {
124
+ let entry = this.#atoms.get(atom);
125
+ if (entry == null) {
126
+ entry = {
127
+ state: PENDING_STATE,
128
+ version: 0,
129
+ promise: null,
130
+ listeners: /* @__PURE__ */ new Set(),
131
+ mountCount: 0,
132
+ unmount: null
133
+ };
134
+ this.#atoms.set(atom, entry);
135
+ }
136
+ return entry;
137
+ }
138
+ resolve(atom) {
139
+ const entry = this.#getOrCreate(atom);
140
+ if (entry.promise != null) return entry.promise;
141
+ const promise = this.#runGet(atom).finally(() => {
142
+ const e = this.#atoms.get(atom);
143
+ if (e != null) e.promise = null;
144
+ });
145
+ entry.promise = promise;
146
+ return promise;
147
+ }
148
+ async #runGet(atom) {
149
+ const config = atom[CONFIG];
150
+ const dependencies = config.dependencies;
151
+ const stalePolicy = config.stalePolicy ?? "keep";
152
+ const entry = this.#getOrCreate(atom);
153
+ if (dependencies != null) {
154
+ await Promise.all(Object.values(dependencies).map((dep) => this.resolve(dep)));
155
+ this.#registerRdeps(atom, dependencies);
156
+ }
157
+ const ctx = this.#makeCtx(atom, dependencies ?? {});
158
+ try {
159
+ const value = await config.get(ctx);
160
+ if (ctx.signal.aborted) throw new DOMException("The operation was aborted", "AbortError");
161
+ entry.state = {
162
+ status: "fresh",
163
+ value,
164
+ error: void 0
165
+ };
166
+ entry.version++;
167
+ this.#scheduleNotify(atom);
168
+ return value;
169
+ } catch (e) {
170
+ if (isAbortError(e)) throw e;
171
+ const prevValue = extractPreviousValue(entry.state);
172
+ entry.state = {
173
+ status: "error",
174
+ value: stalePolicy === "keep" ? prevValue : void 0,
175
+ error: e
176
+ };
177
+ entry.version++;
178
+ this.#scheduleNotify(atom);
179
+ throw e;
180
+ }
181
+ }
182
+ invalidate(atom) {
183
+ this.#markStale(atom);
184
+ this.#pending.add(atom);
185
+ if (this.#pending.size === 1) queueMicrotask(() => {
186
+ this.#flushPending();
187
+ });
188
+ }
189
+ invalidateMany(atoms) {
190
+ for (const a of atoms) {
191
+ this.#markStale(a);
192
+ this.#pending.add(a);
193
+ }
194
+ if (this.#pending.size > 0) queueMicrotask(() => {
195
+ this.#flushPending();
196
+ });
197
+ }
198
+ #markStale(atom, visited = /* @__PURE__ */ new Set()) {
199
+ if (visited.has(atom)) return;
200
+ visited.add(atom);
201
+ const entry = this.#atoms.get(atom);
202
+ if (entry != null) {
203
+ const stalePolicy = atom[CONFIG].stalePolicy ?? "keep";
204
+ if (entry.state.status === "fresh") if (stalePolicy === "reset") entry.state = PENDING_STATE;
205
+ else entry.state = {
206
+ ...entry.state,
207
+ status: "stale"
208
+ };
209
+ entry.promise = null;
210
+ this.#controllers.get(atom)?.abort();
211
+ }
212
+ const rdeps = this.#rdeps.get(atom);
213
+ if (rdeps != null) for (const dep of rdeps) this.#markStale(dep, visited);
214
+ }
215
+ #markReverseDependentsStale(atom) {
216
+ const rdeps = this.#rdeps.get(atom);
217
+ if (rdeps != null) {
218
+ const visited = new Set([atom]);
219
+ for (const dep of rdeps) {
220
+ this.#markStale(dep, visited);
221
+ this.#pending.add(dep);
222
+ }
223
+ }
224
+ }
225
+ #flushPending() {
226
+ const batch = [...this.#pending];
227
+ this.#pending.clear();
228
+ const toNotify = /* @__PURE__ */ new Set();
229
+ for (const a of batch) {
230
+ const entry = this.#atoms.get(a);
231
+ if (entry != null) for (const l of entry.listeners) toNotify.add(l);
232
+ }
233
+ for (const l of toNotify) l();
234
+ }
235
+ #scheduleNotify(atom) {
236
+ this.#pending.add(atom);
237
+ if (this.#pending.size === 1) queueMicrotask(() => {
238
+ this.#flushPending();
239
+ });
240
+ }
241
+ #registerRdeps(atom, deps) {
242
+ for (const dep of Object.values(deps)) {
243
+ let set = this.#rdeps.get(dep);
244
+ if (set == null) {
245
+ set = /* @__PURE__ */ new Set();
246
+ this.#rdeps.set(dep, set);
247
+ }
248
+ set.add(atom);
249
+ }
250
+ }
251
+ #makeCtx(atom, deps) {
252
+ this.#controllers.get(atom)?.abort();
253
+ const controller = new AbortController();
254
+ this.#controllers.set(atom, controller);
255
+ return {
256
+ signal: controller.signal,
257
+ get: async (key) => {
258
+ const dep = deps[key];
259
+ if (dep == null) throw new Error(`Unknown dependency key: "${String(key)}"`);
260
+ return this.resolve(dep);
261
+ }
262
+ };
263
+ }
264
+ subscribe(atom, listener) {
265
+ const entry = this.#getOrCreate(atom);
266
+ entry.listeners.add(listener);
267
+ this.#autoRegisterFamily(atom);
268
+ if (entry.state.status === "pending" && entry.promise == null) this.resolve(atom);
269
+ entry.mountCount++;
270
+ if (entry.mountCount === 1) {
271
+ const config = atom[CONFIG];
272
+ if (config.onMount != null) {
273
+ const setValue = (value) => {
274
+ entry.state = {
275
+ status: "fresh",
276
+ value,
277
+ error: void 0
278
+ };
279
+ entry.version++;
280
+ this.#scheduleNotify(atom);
281
+ };
282
+ const cleanup = config.onMount(setValue);
283
+ if (typeof cleanup === "function") entry.unmount = cleanup;
284
+ }
285
+ }
286
+ return () => {
287
+ entry.listeners.delete(listener);
288
+ entry.mountCount--;
289
+ if (entry.mountCount === 0 && entry.unmount != null) {
290
+ entry.unmount();
291
+ entry.unmount = null;
292
+ }
293
+ };
294
+ }
295
+ #autoRegisterFamily(atom) {
296
+ const link = getFamilyLink(atom);
297
+ if (link == null) return;
298
+ if (this.#registeredFamilies.has(link)) return;
299
+ this.#registeredFamilies.add(link);
300
+ const unsub = link.registerStore((target) => {
301
+ this.invalidate(target);
302
+ });
303
+ this.#familyUnsubs.add(unsub);
304
+ }
305
+ getSnapshot(atom) {
306
+ return this.#getOrCreate(atom).state;
307
+ }
308
+ getServerSnapshot(atom) {
309
+ const entry = this.#atoms.get(atom);
310
+ if (entry != null) return entry.state;
311
+ return PENDING_STATE;
312
+ }
313
+ async set(atom, ...args) {
314
+ const config = atom[CONFIG];
315
+ if (config.set == null) throw new Error(`Atom${atom.debugLabel != null ? ` "${atom.debugLabel}"` : ""} is not writable`);
316
+ const deps = config.dependencies ?? {};
317
+ const baseCtx = this.#makeCtx(atom, deps);
318
+ const entry = this.#getOrCreate(atom);
319
+ const optimisticSnapshot = { current: null };
320
+ const ctx = {
321
+ ...baseCtx,
322
+ setOptimisticValue: (value) => {
323
+ if (optimisticSnapshot.current == null) optimisticSnapshot.current = {
324
+ state: entry.state,
325
+ version: entry.version
326
+ };
327
+ entry.state = {
328
+ status: "fresh",
329
+ value,
330
+ error: void 0
331
+ };
332
+ entry.version++;
333
+ this.#scheduleNotify(atom);
334
+ this.#markReverseDependentsStale(atom);
335
+ }
336
+ };
337
+ try {
338
+ await config.set(ctx, ...args);
339
+ } catch (e) {
340
+ const snap = optimisticSnapshot.current;
341
+ if (snap != null) {
342
+ entry.state = snap.state;
343
+ entry.version = snap.version;
344
+ this.#scheduleNotify(atom);
345
+ }
346
+ throw e;
347
+ }
348
+ this.invalidate(atom);
349
+ }
350
+ write(atom, value) {
351
+ const entry = this.#getOrCreate(atom);
352
+ this.#controllers.get(atom)?.abort();
353
+ entry.promise = null;
354
+ entry.state = {
355
+ status: "fresh",
356
+ value,
357
+ error: void 0
358
+ };
359
+ entry.version++;
360
+ this.#scheduleNotify(atom);
361
+ this.#markReverseDependentsStale(atom);
362
+ }
363
+ getClient() {
364
+ if (this.#client != null) return this.#client;
365
+ const store = this;
366
+ this.#client = {
367
+ get(atom) {
368
+ return store.resolve(atom);
369
+ },
370
+ set(atom, ...args) {
371
+ return store.set(atom, ...args);
372
+ },
373
+ write(atom, value) {
374
+ store.write(atom, value);
375
+ },
376
+ invalidate(atom) {
377
+ store.invalidate(atom);
378
+ },
379
+ invalidateMany(atoms) {
380
+ store.invalidateMany(atoms);
381
+ },
382
+ subscribe(atom, listener) {
383
+ return store.subscribe(atom, () => {
384
+ listener(store.getSnapshot(atom));
385
+ });
386
+ }
387
+ };
388
+ return this.#client;
389
+ }
390
+ };
391
+ function createStore() {
392
+ return new Store();
393
+ }
394
+ function isAbortError(e) {
395
+ return e instanceof DOMException && e.name === "AbortError";
396
+ }
397
+ function extractPreviousValue(state) {
398
+ if (state.status === "stale" || state.status === "fresh") return state.value;
399
+ if (state.status === "error") return state.value;
400
+ }
401
+ //#endregion
402
+ export { CONFIG as i, atomFamily as n, atom as r, createStore as t };
403
+
404
+ //# sourceMappingURL=store-CmRXgcwh.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-CmRXgcwh.mjs","names":["#atoms","#rdeps","#pending","#controllers","#familyUnsubs","#registeredFamilies","#getOrCreate","#runGet","#registerRdeps","#makeCtx","#scheduleNotify","#markStale","#flushPending","#autoRegisterFamily","#markReverseDependentsStale","#client"],"sources":["../src/internal/types.ts","../src/internal/atom.ts","../src/internal/family.ts","../src/internal/store.ts"],"sourcesContent":["export const CONFIG = Symbol(\"kvark.config\");\nexport const WRITABLE = Symbol(\"kvark.writable\");\nexport const FAMILY_LINK = Symbol(\"kvark.familyLink\");\n\nexport type AtomState<Value> =\n | { status: \"pending\"; value: undefined; error: undefined }\n | { status: \"stale\"; value: Value; error: undefined }\n | { status: \"fresh\"; value: Value; error: undefined }\n | { status: \"error\"; value: Value | undefined; error: unknown };\n\nexport type StalePolicy = \"keep\" | \"suspend\" | \"reset\";\n\nexport type AtomContext<Deps extends Record<string, Atom<unknown>>> = {\n get: <K extends keyof Deps>(key: K) => Promise<AtomValue<Deps[K]>>;\n signal: AbortSignal;\n};\n\nexport type WritableAtomContext<\n Deps extends Record<string, Atom<unknown>>,\n Value,\n> = AtomContext<Deps> & {\n setOptimisticValue: (value: Value) => void;\n};\n\nexport type AtomConfig<\n Value,\n Deps extends Record<string, Atom<unknown>>,\n Args extends readonly unknown[],\n> = {\n dependencies?: Deps;\n stalePolicy?: StalePolicy;\n debugLabel?: string;\n get: (ctx: AtomContext<Deps>) => Promise<Value>;\n set?: (ctx: WritableAtomContext<Deps, Value>, ...args: Args) => Promise<void>;\n onMount?: (set: (value: Value) => void) => (() => void) | void;\n};\n\nexport interface InternalAtomConfig<Value> {\n dependencies?: Record<string, Atom<unknown>>;\n stalePolicy?: StalePolicy;\n debugLabel?: string;\n get: (ctx: AtomContext<Record<string, Atom<unknown>>>) => Promise<Value>;\n set?: (\n ctx: WritableAtomContext<Record<string, Atom<unknown>>, Value>,\n ...args: readonly unknown[]\n ) => Promise<void>;\n onMount?: (set: (value: unknown) => void) => (() => void) | void;\n}\n\nexport interface Atom<out Value> {\n readonly [CONFIG]: InternalAtomConfig<Value>;\n readonly debugLabel: string | undefined;\n}\n\nexport interface WritableAtom<\n out Value,\n in out Args extends readonly unknown[],\n> extends Atom<Value> {\n readonly [WRITABLE]: Args;\n}\n\nexport type AtomValue<A> = A extends Atom<infer V> ? V : never;\nexport type IsWritable<A> = A extends WritableAtom<unknown, readonly unknown[]> ? true : false;\nexport type AtomArgs<A> = A extends WritableAtom<unknown, infer Args> ? Args : never;\n","import type {\n Atom,\n AtomConfig,\n InternalAtomConfig,\n WritableAtom,\n WritableAtomContext,\n} from \"./types.js\";\nimport { CONFIG, WRITABLE } from \"./types.js\";\n\ntype WritableConfig<\n Value,\n Deps extends Record<string, Atom<unknown>>,\n Args extends readonly unknown[],\n> = AtomConfig<Value, Deps, Args> & {\n set: (ctx: WritableAtomContext<Deps, Value>, ...args: Args) => Promise<void>;\n};\n\ntype ReadonlyConfig<Value, Deps extends Record<string, Atom<unknown>>> = Omit<\n AtomConfig<Value, Deps, readonly []>,\n \"set\"\n>;\n\nexport function atom<\n Value,\n Deps extends Record<string, Atom<unknown>> = Record<never, never>,\n Args extends readonly unknown[] = readonly [],\n>(config: WritableConfig<Value, Deps, Args>): WritableAtom<Value, Args>;\n\nexport function atom<Value, Deps extends Record<string, Atom<unknown>> = Record<never, never>>(\n config: ReadonlyConfig<Value, Deps>,\n): Atom<Value>;\n\nexport function atom<\n Value,\n Deps extends Record<string, Atom<unknown>> = Record<never, never>,\n Args extends readonly unknown[] = readonly [],\n>(config: AtomConfig<Value, Deps, Args>): Atom<Value> {\n const internal: InternalAtomConfig<Value> = Object.create(null) as InternalAtomConfig<Value>;\n internal.get = config.get as InternalAtomConfig<Value>[\"get\"];\n\n if (config.debugLabel != null) {\n internal.debugLabel = config.debugLabel;\n }\n if (config.dependencies != null) {\n internal.dependencies = config.dependencies as Record<string, Atom<unknown>>;\n }\n if (config.stalePolicy != null) {\n internal.stalePolicy = config.stalePolicy;\n }\n if (config.set != null) {\n internal.set = config.set as NonNullable<InternalAtomConfig<Value>[\"set\"]>;\n }\n if (config.onMount != null) {\n internal.onMount = config.onMount as NonNullable<InternalAtomConfig<Value>[\"onMount\"]>;\n }\n\n if (config.set != null) {\n return {\n [CONFIG]: internal,\n [WRITABLE]: [] as unknown as Args,\n debugLabel: config.debugLabel,\n } as unknown as Atom<Value>;\n }\n\n return {\n [CONFIG]: internal,\n debugLabel: config.debugLabel,\n } as Atom<Value>;\n}\n","import type { Atom, AtomContext, StalePolicy } from \"./types.js\";\nimport { FAMILY_LINK } from \"./types.js\";\nimport { atom } from \"./atom.js\";\n\nexport type AtomFamilyOptions<\n Param,\n Value,\n Deps extends Record<string, Atom<unknown>>,\n Args extends readonly unknown[],\n> = {\n dependencies?: (param: Param) => Deps;\n stalePolicy?: StalePolicy;\n cachePolicy?: \"keep-all\" | \"lru\";\n lruSize?: number;\n debugLabel?: string;\n get: (param: Param) => (ctx: AtomContext<Deps>) => Promise<Value>;\n set?: (param: Param) => (ctx: AtomContext<Deps>, ...args: Args) => Promise<void>;\n};\n\nexport interface AtomFamily<Param, Value> {\n (param: Param): Atom<Value>;\n invalidate(param: Param): void;\n invalidateAll(): void;\n remove(param: Param): void;\n getCache(): ReadonlyMap<Param, Atom<Value>>;\n}\n\nexport interface FamilyLink {\n invalidateAtom: (atom: Atom<unknown>) => void;\n registerStore: (cb: (atom: Atom<unknown>) => void) => () => void;\n}\n\nexport function getFamilyLink(target: Atom<unknown>): FamilyLink | undefined {\n return (target as unknown as Record<symbol, FamilyLink | undefined>)[FAMILY_LINK];\n}\n\nexport function atomFamily<\n Param,\n Value,\n Deps extends Record<string, Atom<unknown>> = Record<never, never>,\n Args extends readonly unknown[] = readonly [],\n>(options: AtomFamilyOptions<Param, Value, Deps, Args>): AtomFamily<Param, Value> {\n const cachePolicy = options.cachePolicy ?? \"keep-all\";\n const lruSize = options.lruSize ?? 100;\n const cache = new Map<Param, Atom<Value>>();\n const lruOrder: Param[] = [];\n const storeCallbacks = new Set<(atom: Atom<unknown>) => void>();\n\n const link: FamilyLink = {\n invalidateAtom(target: Atom<unknown>): void {\n for (const cb of storeCallbacks) {\n cb(target);\n }\n },\n registerStore(cb: (atom: Atom<unknown>) => void): () => void {\n storeCallbacks.add(cb);\n return () => {\n storeCallbacks.delete(cb);\n };\n },\n };\n\n function attachLink(target: Atom<Value>): void {\n (target as unknown as Record<symbol, FamilyLink>)[FAMILY_LINK] = link;\n }\n\n function getOrCreate(param: Param): Atom<Value> {\n const cached = cache.get(param);\n if (cached != null) {\n if (cachePolicy === \"lru\") {\n touchLru(param);\n }\n return cached;\n }\n\n const deps = options.dependencies?.(param);\n const getFn = options.get(param);\n const setFn = options.set?.(param);\n\n const label =\n options.debugLabel != null ? `${options.debugLabel}(${String(param)})` : undefined;\n\n const created = createAtom(label, deps, getFn, setFn);\n attachLink(created);\n cache.set(param, created);\n\n if (cachePolicy === \"lru\") {\n lruOrder.push(param);\n evictLru();\n }\n\n return created;\n }\n\n function createAtom(\n label: string | undefined,\n deps: Deps | undefined,\n getFn: (ctx: AtomContext<Deps>) => Promise<Value>,\n setFn: ((ctx: AtomContext<Deps>, ...args: Args) => Promise<void>) | undefined,\n ): Atom<Value> {\n const base = {\n get: getFn as (ctx: AtomContext<Deps>) => Promise<Value>,\n } as {\n debugLabel?: string;\n dependencies?: Deps;\n stalePolicy?: StalePolicy;\n get: (ctx: AtomContext<Deps>) => Promise<Value>;\n set?: (ctx: AtomContext<Deps>, ...args: Args) => Promise<void>;\n };\n\n if (label != null) {\n base.debugLabel = label;\n }\n if (deps != null) {\n base.dependencies = deps;\n }\n if (options.stalePolicy != null) {\n base.stalePolicy = options.stalePolicy;\n }\n\n if (setFn != null) {\n base.set = setFn;\n return atom(\n base as typeof base & {\n set: (ctx: AtomContext<Deps>, ...args: Args) => Promise<void>;\n },\n ) as Atom<Value>;\n }\n\n return atom(base as Omit<typeof base, \"set\">);\n }\n\n function touchLru(param: Param): void {\n const idx = lruOrder.indexOf(param);\n if (idx !== -1) {\n lruOrder.splice(idx, 1);\n }\n lruOrder.push(param);\n }\n\n function evictLru(): void {\n while (lruOrder.length > lruSize) {\n const evicted = lruOrder.shift();\n if (evicted !== undefined) {\n cache.delete(evicted);\n }\n }\n }\n\n const family = getOrCreate as AtomFamily<Param, Value>;\n\n family.invalidate = (param: Param): void => {\n const cached = cache.get(param);\n if (cached != null) {\n link.invalidateAtom(cached);\n }\n };\n\n family.invalidateAll = (): void => {\n for (const cached of cache.values()) {\n link.invalidateAtom(cached);\n }\n };\n\n family.remove = (param: Param): void => {\n cache.delete(param);\n if (cachePolicy === \"lru\") {\n const idx = lruOrder.indexOf(param);\n if (idx !== -1) {\n lruOrder.splice(idx, 1);\n }\n }\n };\n\n family.getCache = (): ReadonlyMap<Param, Atom<Value>> => cache;\n\n return family;\n}\n","import type {\n Atom,\n AtomContext,\n AtomState,\n InternalAtomConfig,\n StalePolicy,\n WritableAtom,\n WritableAtomContext,\n} from \"./types.js\";\nimport { CONFIG } from \"./types.js\";\nimport { getFamilyLink } from \"./family.js\";\n\ntype AtomEntry<V> = {\n state: AtomState<V>;\n version: number;\n promise: Promise<V> | null;\n listeners: Set<() => void>;\n mountCount: number;\n unmount: (() => void) | null;\n};\n\nexport interface StoreClient {\n get<V>(atom: Atom<V>): Promise<V>;\n set<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>, ...args: A): Promise<void>;\n write<V>(atom: Atom<V>, value: V): void;\n invalidate(atom: Atom<unknown>): void;\n invalidateMany(atoms: ReadonlyArray<Atom<unknown>>): void;\n subscribe<V>(atom: Atom<V>, listener: (state: AtomState<V>) => void): () => void;\n}\n\nconst PENDING_STATE: AtomState<never> = {\n status: \"pending\",\n value: undefined,\n error: undefined,\n} as AtomState<never>;\n\nexport class Store {\n readonly #atoms = new WeakMap<Atom<unknown>, AtomEntry<unknown>>();\n readonly #rdeps = new Map<Atom<unknown>, Set<Atom<unknown>>>();\n readonly #pending = new Set<Atom<unknown>>();\n readonly #controllers = new WeakMap<Atom<unknown>, AbortController>();\n readonly #familyUnsubs = new Set<() => void>();\n readonly #registeredFamilies = new WeakSet<object>();\n #client: StoreClient | null = null;\n\n #getOrCreate<V>(atom: Atom<V>): AtomEntry<V> {\n let entry = this.#atoms.get(atom) as AtomEntry<V> | undefined;\n if (entry == null) {\n entry = {\n state: PENDING_STATE as AtomState<V>,\n version: 0,\n promise: null,\n listeners: new Set(),\n mountCount: 0,\n unmount: null,\n };\n this.#atoms.set(atom, entry as AtomEntry<unknown>);\n }\n return entry;\n }\n\n resolve<V>(atom: Atom<V>): Promise<V> {\n const entry = this.#getOrCreate(atom);\n if (entry.promise != null) {\n return entry.promise;\n }\n\n const promise = this.#runGet(atom).finally(() => {\n const e = this.#atoms.get(atom) as AtomEntry<V> | undefined;\n if (e != null) {\n e.promise = null;\n }\n });\n entry.promise = promise;\n return promise;\n }\n\n async #runGet<V>(atom: Atom<V>): Promise<V> {\n const config: InternalAtomConfig<V> = atom[CONFIG];\n const dependencies = config.dependencies;\n const stalePolicy: StalePolicy = config.stalePolicy ?? \"keep\";\n const entry = this.#getOrCreate(atom);\n\n if (dependencies != null) {\n await Promise.all(Object.values(dependencies).map((dep) => this.resolve(dep)));\n this.#registerRdeps(atom, dependencies);\n }\n\n const ctx = this.#makeCtx(atom, dependencies ?? {});\n\n try {\n const value = await config.get(ctx);\n if (ctx.signal.aborted) {\n throw new DOMException(\"The operation was aborted\", \"AbortError\");\n }\n entry.state = { status: \"fresh\", value, error: undefined };\n entry.version++;\n this.#scheduleNotify(atom);\n return value;\n } catch (e: unknown) {\n if (isAbortError(e)) {\n throw e;\n }\n const prevValue = extractPreviousValue<V>(entry.state);\n entry.state = {\n status: \"error\",\n value: stalePolicy === \"keep\" ? prevValue : undefined,\n error: e,\n } as AtomState<V>;\n entry.version++;\n this.#scheduleNotify(atom);\n throw e;\n }\n }\n\n invalidate(atom: Atom<unknown>): void {\n this.#markStale(atom);\n this.#pending.add(atom);\n if (this.#pending.size === 1) {\n queueMicrotask(() => {\n this.#flushPending();\n });\n }\n }\n\n invalidateMany(atoms: ReadonlyArray<Atom<unknown>>): void {\n for (const a of atoms) {\n this.#markStale(a);\n this.#pending.add(a);\n }\n if (this.#pending.size > 0) {\n queueMicrotask(() => {\n this.#flushPending();\n });\n }\n }\n\n #markStale(atom: Atom<unknown>, visited = new Set<Atom<unknown>>()): void {\n if (visited.has(atom)) {\n return;\n }\n visited.add(atom);\n\n const entry = this.#atoms.get(atom);\n if (entry != null) {\n const stalePolicy: StalePolicy = atom[CONFIG].stalePolicy ?? \"keep\";\n\n if (entry.state.status === \"fresh\") {\n if (stalePolicy === \"reset\") {\n entry.state = PENDING_STATE;\n } else {\n entry.state = { ...entry.state, status: \"stale\" };\n }\n }\n\n entry.promise = null;\n this.#controllers.get(atom)?.abort();\n }\n\n const rdeps = this.#rdeps.get(atom);\n if (rdeps != null) {\n for (const dep of rdeps) {\n this.#markStale(dep, visited);\n }\n }\n }\n\n #markReverseDependentsStale(atom: Atom<unknown>): void {\n const rdeps = this.#rdeps.get(atom);\n if (rdeps != null) {\n const visited = new Set<Atom<unknown>>([atom]);\n for (const dep of rdeps) {\n this.#markStale(dep, visited);\n this.#pending.add(dep);\n }\n }\n }\n\n #flushPending(): void {\n const batch = [...this.#pending];\n this.#pending.clear();\n const toNotify = new Set<() => void>();\n for (const a of batch) {\n const entry = this.#atoms.get(a);\n if (entry != null) {\n for (const l of entry.listeners) {\n toNotify.add(l);\n }\n }\n }\n for (const l of toNotify) {\n l();\n }\n }\n\n #scheduleNotify(atom: Atom<unknown>): void {\n this.#pending.add(atom);\n if (this.#pending.size === 1) {\n queueMicrotask(() => {\n this.#flushPending();\n });\n }\n }\n\n #registerRdeps(atom: Atom<unknown>, deps: Record<string, Atom<unknown>>): void {\n for (const dep of Object.values(deps)) {\n let set = this.#rdeps.get(dep);\n if (set == null) {\n set = new Set();\n this.#rdeps.set(dep, set);\n }\n set.add(atom);\n }\n }\n\n #makeCtx(\n atom: Atom<unknown>,\n deps: Record<string, Atom<unknown>>,\n ): AtomContext<Record<string, Atom<unknown>>> {\n this.#controllers.get(atom)?.abort();\n const controller = new AbortController();\n this.#controllers.set(atom, controller);\n\n return {\n signal: controller.signal,\n get: async (key: string) => {\n const dep = deps[key];\n if (dep == null) {\n throw new Error(`Unknown dependency key: \"${String(key)}\"`);\n }\n return this.resolve(dep);\n },\n };\n }\n\n subscribe<V>(atom: Atom<V>, listener: () => void): () => void {\n const entry = this.#getOrCreate(atom);\n entry.listeners.add(listener);\n\n this.#autoRegisterFamily(atom);\n\n if (entry.state.status === \"pending\" && entry.promise == null) {\n void this.resolve(atom);\n }\n\n entry.mountCount++;\n if (entry.mountCount === 1) {\n const config: InternalAtomConfig<V> = atom[CONFIG];\n if (config.onMount != null) {\n const setValue = (value: V): void => {\n entry.state = { status: \"fresh\", value, error: undefined };\n entry.version++;\n this.#scheduleNotify(atom);\n };\n const cleanup = config.onMount(setValue as (value: unknown) => void);\n if (typeof cleanup === \"function\") {\n entry.unmount = cleanup;\n }\n }\n }\n\n return () => {\n entry.listeners.delete(listener);\n entry.mountCount--;\n if (entry.mountCount === 0 && entry.unmount != null) {\n entry.unmount();\n entry.unmount = null;\n }\n };\n }\n\n #autoRegisterFamily(atom: Atom<unknown>): void {\n const link = getFamilyLink(atom);\n if (link == null) {\n return;\n }\n if (this.#registeredFamilies.has(link)) {\n return;\n }\n this.#registeredFamilies.add(link);\n const unsub = link.registerStore((target: Atom<unknown>) => {\n this.invalidate(target);\n });\n this.#familyUnsubs.add(unsub);\n }\n\n getSnapshot<V>(atom: Atom<V>): AtomState<V> {\n return this.#getOrCreate(atom).state;\n }\n\n getServerSnapshot<V>(atom: Atom<V>): AtomState<V> {\n const entry = this.#atoms.get(atom) as AtomEntry<V> | undefined;\n if (entry != null) {\n return entry.state;\n }\n return PENDING_STATE as AtomState<V>;\n }\n\n async set<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>, ...args: A): Promise<void> {\n const config: InternalAtomConfig<V> = atom[CONFIG];\n if (config.set == null) {\n throw new Error(\n `Atom${atom.debugLabel != null ? ` \"${atom.debugLabel}\"` : \"\"} is not writable`,\n );\n }\n\n const deps = config.dependencies ?? {};\n const baseCtx = this.#makeCtx(atom, deps);\n const entry = this.#getOrCreate(atom);\n\n // Ref: assignments inside setOptimisticValue are not tracked on a plain `let` for catch narrowing.\n const optimisticSnapshot: {\n current: { state: AtomState<V>; version: number } | null;\n } = { current: null };\n\n const ctx: WritableAtomContext<Record<string, Atom<unknown>>, V> = {\n ...baseCtx,\n setOptimisticValue: (value: V): void => {\n if (optimisticSnapshot.current == null) {\n optimisticSnapshot.current = { state: entry.state, version: entry.version };\n }\n entry.state = { status: \"fresh\", value, error: undefined };\n entry.version++;\n this.#scheduleNotify(atom);\n this.#markReverseDependentsStale(atom);\n },\n };\n\n try {\n await config.set(ctx, ...args);\n } catch (e: unknown) {\n const snap = optimisticSnapshot.current;\n if (snap != null) {\n entry.state = snap.state;\n entry.version = snap.version;\n this.#scheduleNotify(atom);\n }\n throw e;\n }\n\n this.invalidate(atom);\n }\n\n write<V>(atom: Atom<V>, value: V): void {\n const entry = this.#getOrCreate(atom);\n this.#controllers.get(atom)?.abort();\n entry.promise = null;\n entry.state = { status: \"fresh\", value, error: undefined };\n entry.version++;\n this.#scheduleNotify(atom);\n this.#markReverseDependentsStale(atom);\n }\n\n getClient(): StoreClient {\n if (this.#client != null) {\n return this.#client;\n }\n\n const store = this;\n this.#client = {\n get<V>(atom: Atom<V>): Promise<V> {\n return store.resolve(atom);\n },\n set<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>, ...args: A): Promise<void> {\n return store.set(atom, ...args);\n },\n write<V>(atom: Atom<V>, value: V): void {\n store.write(atom, value);\n },\n invalidate(atom: Atom<unknown>): void {\n store.invalidate(atom);\n },\n invalidateMany(atoms: ReadonlyArray<Atom<unknown>>): void {\n store.invalidateMany(atoms);\n },\n subscribe<V>(atom: Atom<V>, listener: (state: AtomState<V>) => void): () => void {\n return store.subscribe(atom, () => {\n listener(store.getSnapshot(atom));\n });\n },\n };\n return this.#client;\n }\n}\n\nexport function createStore(): Store {\n return new Store();\n}\n\nfunction isAbortError(e: unknown): boolean {\n return e instanceof DOMException && e.name === \"AbortError\";\n}\n\nfunction extractPreviousValue<V>(state: AtomState<V>): V | undefined {\n if (state.status === \"stale\" || state.status === \"fresh\") {\n return state.value;\n }\n if (state.status === \"error\") {\n return state.value;\n }\n return undefined;\n}\n"],"mappings":";AAAA,MAAa,SAAS,OAAO,eAAe;AAC5C,MAAa,WAAW,OAAO,iBAAiB;AAChD,MAAa,cAAc,OAAO,mBAAmB;;;AC8BrD,SAAgB,KAId,QAAoD;CACpD,MAAM,WAAsC,OAAO,OAAO,KAAK;AAC/D,UAAS,MAAM,OAAO;AAEtB,KAAI,OAAO,cAAc,KACvB,UAAS,aAAa,OAAO;AAE/B,KAAI,OAAO,gBAAgB,KACzB,UAAS,eAAe,OAAO;AAEjC,KAAI,OAAO,eAAe,KACxB,UAAS,cAAc,OAAO;AAEhC,KAAI,OAAO,OAAO,KAChB,UAAS,MAAM,OAAO;AAExB,KAAI,OAAO,WAAW,KACpB,UAAS,UAAU,OAAO;AAG5B,KAAI,OAAO,OAAO,KAChB,QAAO;GACJ,SAAS;GACT,WAAW,EAAE;EACd,YAAY,OAAO;EACpB;AAGH,QAAO;GACJ,SAAS;EACV,YAAY,OAAO;EACpB;;;;ACnCH,SAAgB,cAAc,QAA+C;AAC3E,QAAQ,OAA6D;;AAGvE,SAAgB,WAKd,SAAgF;CAChF,MAAM,cAAc,QAAQ,eAAe;CAC3C,MAAM,UAAU,QAAQ,WAAW;CAC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CAGvB,MAAS,MAAe,OAAgB;EACtC,MAAM,QAAQ,MAAA,YAAkB,KAAK;AACrC,QAAA,YAAkB,IAAI,KAAK,EAAE,OAAO;AACpC,QAAM,UAAU;AAChB,QAAM,QAAQ;GAAE,QAAQ;GAAS;GAAO,OAAO,KAAA;GAAW;AAC1D,QAAM;AACN,QAAA,eAAqB,KAAK;AAC1B,QAAA,2BAAiC,KAAK;;CAGxC,YAAyB;AACvB,MAAI,MAAA,UAAgB,KAClB,QAAO,MAAA;EAGT,MAAM,QAAQ;AACd,QAAA,SAAe;GACb,IAAO,MAA2B;AAChC,WAAO,MAAM,QAAQ,KAAK;;GAE5B,IAAqC,MAA0B,GAAG,MAAwB;AACxF,WAAO,MAAM,IAAI,MAAM,GAAG,KAAK;;GAEjC,MAAS,MAAe,OAAgB;AACtC,UAAM,MAAM,MAAM,MAAM;;GAE1B,WAAW,MAA2B;AACpC,UAAM,WAAW,KAAK;;GAExB,eAAe,OAA2C;AACxD,UAAM,eAAe,MAAM;;GAE7B,UAAa,MAAe,UAAqD;AAC/E,WAAO,MAAM,UAAU,YAAY;AACjC,cAAS,MAAM,YAAY,KAAK,CAAC;MACjC;;GAEL;AACD,SAAO,MAAA;;;AAIX,SAAgB,cAAqB;AACnC,QAAO,IAAI,OAAO;;AAGpB,SAAS,aAAa,GAAqB;AACzC,QAAO,aAAa,gBAAgB,EAAE,SAAS;;AAGjD,SAAS,qBAAwB,OAAoC;AACnE,KAAI,MAAM,WAAW,WAAW,MAAM,WAAW,QAC/C,QAAO,MAAM;AAEf,KAAI,MAAM,WAAW,QACnB,QAAO,MAAM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kdeveloper/kvark",
3
- "version": "0.3.1",
3
+ "version": "0.5.0",
4
4
  "description": "Atomic state management with explicit dependency graphs",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -21,16 +21,6 @@
21
21
  "import": "./dist/family.js"
22
22
  }
23
23
  },
24
- "scripts": {
25
- "build": "tsc --noEmit && tsup",
26
- "lint": "oxlint --deny-warnings",
27
- "lint:fix": "oxlint --fix --deny-warnings",
28
- "lint:types": "tsc --noEmit",
29
- "fmt": "oxfmt .",
30
- "fmt:check": "oxfmt --check .",
31
- "test": "vitest run",
32
- "test:watch": "vitest"
33
- },
34
24
  "devDependencies": {
35
25
  "@testing-library/dom": "^10.4.1",
36
26
  "@testing-library/react": "^16.3.2",
@@ -41,7 +31,7 @@
41
31
  "oxlint": "^1.57.0",
42
32
  "react": ">=18",
43
33
  "react-dom": "^19.2.4",
44
- "tsup": "^8.5.1",
34
+ "tsdown": "^0.21.6",
45
35
  "typescript": "^6.0.2",
46
36
  "vitest": "^4.1.2"
47
37
  },
@@ -51,5 +41,14 @@
51
41
  "engines": {
52
42
  "node": ">=20"
53
43
  },
54
- "packageManager": "pnpm@10.33.0"
55
- }
44
+ "scripts": {
45
+ "build": "tsc --noEmit && tsdown",
46
+ "lint": "oxlint --deny-warnings",
47
+ "lint:fix": "oxlint --fix --deny-warnings",
48
+ "lint:types": "tsc --noEmit",
49
+ "fmt": "oxfmt .",
50
+ "fmt:check": "oxfmt --check .",
51
+ "test": "vitest run",
52
+ "test:watch": "vitest"
53
+ }
54
+ }