@kdeveloper/kvark 0.5.1 → 0.6.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.
- package/README.md +28 -0
- package/dist/family.d.mts +30 -5
- package/dist/family.d.mts.map +1 -1
- package/dist/family.mjs +51 -2
- package/dist/family.mjs.map +1 -0
- package/dist/index.mjs +1 -1
- package/dist/react/index.mjs +1 -1
- package/dist/{store-CNjvdLHG.mjs → store-j2laS7Q2.mjs} +19 -12
- package/dist/store-j2laS7Q2.mjs.map +1 -0
- package/dist/vue/index.d.mts +42 -0
- package/dist/vue/index.d.mts.map +1 -0
- package/dist/vue/index.mjs +86 -0
- package/dist/vue/index.mjs.map +1 -0
- package/package.json +27 -9
- package/dist/store-CNjvdLHG.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -272,6 +272,34 @@ postFamily.invalidate(42);
|
|
|
272
272
|
postFamily.invalidateAll();
|
|
273
273
|
```
|
|
274
274
|
|
|
275
|
+
### Object params and `paramKey`
|
|
276
|
+
|
|
277
|
+
By default atoms are cached by **reference** (`===`). When you want equality-by-value — for example when the param is a filter object — supply a `paramKey` function that maps the param to a stable primitive key:
|
|
278
|
+
|
|
279
|
+
```ts
|
|
280
|
+
import { atomFamily, stableFamilyKey } from "@kdeveloper/kvark/family";
|
|
281
|
+
|
|
282
|
+
const searchFamily = atomFamily({
|
|
283
|
+
// Two different object literals with the same fields → same atom
|
|
284
|
+
paramKey: (filters) => stableFamilyKey(filters),
|
|
285
|
+
get: (filters) => async () => fetchResults(filters),
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
searchFamily({ page: 1, query: "hello" }); // creates atom, key = '{"page":1,"query":"hello"}'
|
|
289
|
+
searchFamily({ query: "hello", page: 1 }); // returns the same atom (fields are sorted)
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
The `paramKey` function is called once per `family(param)` invocation. The returned key is used for all cache operations (`get`, `set`, `invalidate`, `remove`, LRU). The original `param` is still passed to `get`, `set`, and `dependencies`.
|
|
293
|
+
|
|
294
|
+
#### `stableFamilyKey(value)`
|
|
295
|
+
|
|
296
|
+
A built-in helper that serialises plain objects and arrays into a deterministic string:
|
|
297
|
+
|
|
298
|
+
- Object fields are **sorted alphabetically** at every nesting level.
|
|
299
|
+
- Supports: `string`, `number`, `boolean`, `null`, `undefined`, `bigint`, plain objects and arrays (nested).
|
|
300
|
+
- Not supported: class instances (other than plain `Object`/`Array`), `Map`, `Set`, `Symbol`, functions, circular references.
|
|
301
|
+
- Memoises by object reference via a `WeakMap` — repeated calls with the **same object reference** are O(1). Treat param objects as **immutable** after the first call; mutating an object after it has been memoised will silently return the stale key.
|
|
302
|
+
|
|
275
303
|
## React Hooks
|
|
276
304
|
|
|
277
305
|
All hooks must be used inside a `<Provider>`.
|
package/dist/family.d.mts
CHANGED
|
@@ -2,23 +2,48 @@ import { c as AtomState, d as StalePolicy, f as WritableAtom, i as Atom, l as At
|
|
|
2
2
|
import { t as atom } from "./atom-DEAcunGv.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/internal/family.d.ts
|
|
5
|
-
type AtomFamilyOptions<Param, Value, Deps extends Record<string, Atom<unknown>>, Args extends readonly unknown[]> = {
|
|
5
|
+
type AtomFamilyOptions<Param, Value, Deps extends Record<string, Atom<unknown>>, Args extends readonly unknown[], Key = Param> = {
|
|
6
6
|
dependencies?: (param: Param) => Deps;
|
|
7
7
|
stalePolicy?: StalePolicy;
|
|
8
8
|
cachePolicy?: "keep-all" | "lru";
|
|
9
9
|
lruSize?: number;
|
|
10
10
|
debugLabel?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Optional function to derive a stable cache key from `param`.
|
|
13
|
+
* Use when `Param` is an object and you want equality-by-value semantics.
|
|
14
|
+
* The returned key is used for all cache operations (get, set, LRU, invalidate, remove).
|
|
15
|
+
* The original `param` is still passed to `get`, `set`, and `dependencies`.
|
|
16
|
+
*
|
|
17
|
+
* For plain objects/arrays you can use `stableFamilyKey` from `@kdeveloper/kvark/family`.
|
|
18
|
+
* Treat the param object as immutable after the first call — `stableFamilyKey` memoises
|
|
19
|
+
* by object reference via a WeakMap.
|
|
20
|
+
*/
|
|
21
|
+
paramKey?: (param: Param) => Key;
|
|
11
22
|
get: (param: Param) => (ctx: AtomContext<Deps>) => Promise<Value>;
|
|
12
23
|
set?: (param: Param) => (ctx: AtomContext<Deps>, ...args: Args) => Promise<void>;
|
|
13
24
|
};
|
|
14
|
-
interface AtomFamily<Param, Value> {
|
|
25
|
+
interface AtomFamily<Param, Value, Key = Param> {
|
|
15
26
|
(param: Param): Atom<Value>;
|
|
16
27
|
invalidate(param: Param): void;
|
|
17
28
|
invalidateAll(): void;
|
|
18
29
|
remove(param: Param): void;
|
|
19
|
-
getCache(): ReadonlyMap<
|
|
30
|
+
getCache(): ReadonlyMap<Key, Atom<Value>>;
|
|
20
31
|
}
|
|
21
|
-
declare function atomFamily<Param, Value, Deps extends Record<string, Atom<unknown>> = Record<never, never>, Args extends readonly unknown[] = readonly []>(options: AtomFamilyOptions<Param, Value, Deps, Args>): AtomFamily<Param, Value>;
|
|
32
|
+
declare function atomFamily<Param, Value, Deps extends Record<string, Atom<unknown>> = Record<never, never>, Args extends readonly unknown[] = readonly [], Key = Param>(options: AtomFamilyOptions<Param, Value, Deps, Args, Key>): AtomFamily<Param, Value, Key>;
|
|
22
33
|
//#endregion
|
|
23
|
-
|
|
34
|
+
//#region src/internal/stable-family-key.d.ts
|
|
35
|
+
/**
|
|
36
|
+
* Produces a deterministic string key for plain-object/array/primitive values.
|
|
37
|
+
*
|
|
38
|
+
* Supported types: string, number, boolean, null, undefined, bigint,
|
|
39
|
+
* plain objects (incl. nested), arrays.
|
|
40
|
+
*
|
|
41
|
+
* Not supported (throws or produces non-unique output): circular references,
|
|
42
|
+
* class instances other than plain Object/Array, Map, Set, Symbol, functions.
|
|
43
|
+
* Treat the parameter as immutable — mutating an object after its first key is
|
|
44
|
+
* computed via a WeakMap memo will silently return the stale cached key.
|
|
45
|
+
*/
|
|
46
|
+
declare function stableFamilyKey(value: unknown): string;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { type Atom, type AtomConfig, type AtomContext, type AtomFamily, type AtomFamilyOptions, type AtomState, type AtomValue, type StalePolicy, type WritableAtom, atom, atomFamily, createStore, stableFamilyKey };
|
|
24
49
|
//# sourceMappingURL=family.d.mts.map
|
package/dist/family.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"family.d.mts","names":[],"sources":["../src/internal/family.ts"],"mappings":";;;;KAIY,iBAAA,4BAGG,MAAA,SAAe,IAAA;
|
|
1
|
+
{"version":3,"file":"family.d.mts","names":[],"sources":["../src/internal/family.ts","../src/internal/stable-family-key.ts"],"mappings":";;;;KAIY,iBAAA,4BAGG,MAAA,SAAe,IAAA,mDAEtB,KAAA;EAEN,YAAA,IAAgB,KAAA,EAAO,KAAA,KAAU,IAAA;EACjC,WAAA,GAAc,WAAA;EACd,WAAA;EACA,OAAA;EACA,UAAA;EAR4B;;;;;;;;;;EAmB5B,QAAA,IAAY,KAAA,EAAO,KAAA,KAAU,GAAA;EAC7B,GAAA,GAAM,KAAA,EAAO,KAAA,MAAW,GAAA,EAAK,WAAA,CAAY,IAAA,MAAU,OAAA,CAAQ,KAAA;EAC3D,GAAA,IAAO,KAAA,EAAO,KAAA,MAAW,GAAA,EAAK,WAAA,CAAY,IAAA,MAAU,IAAA,EAAM,IAAA,KAAS,OAAA;AAAA;AAAA,UAGpD,UAAA,qBAA+B,KAAA;EAAA,CAC7C,KAAA,EAAO,KAAA,GAAQ,IAAA,CAAK,KAAA;EACrB,UAAA,CAAW,KAAA,EAAO,KAAA;EAClB,aAAA;EACA,MAAA,CAAO,KAAA,EAAO,KAAA;EACd,QAAA,IAAY,WAAA,CAAY,GAAA,EAAK,IAAA,CAAK,KAAA;AAAA;AAAA,iBAYpB,UAAA,4BAGD,MAAA,SAAe,IAAA,aAAiB,MAAA,qEAEvC,KAAA,CAAA,CACN,OAAA,EAAS,iBAAA,CAAkB,KAAA,EAAO,KAAA,EAAO,IAAA,EAAM,IAAA,EAAM,GAAA,IAAO,UAAA,CAAW,KAAA,EAAO,KAAA,EAAO,GAAA;;;;;;;AAlDvF;;;;;;;iBCUgB,eAAA,CAAgB,KAAA"}
|
package/dist/family.mjs
CHANGED
|
@@ -1,2 +1,51 @@
|
|
|
1
|
-
import { n as atomFamily, r as atom, t as createStore } from "./store-
|
|
2
|
-
|
|
1
|
+
import { n as atomFamily, r as atom, t as createStore } from "./store-j2laS7Q2.mjs";
|
|
2
|
+
//#region src/internal/stable-family-key.ts
|
|
3
|
+
/**
|
|
4
|
+
* Produces a deterministic string key for plain-object/array/primitive values.
|
|
5
|
+
*
|
|
6
|
+
* Supported types: string, number, boolean, null, undefined, bigint,
|
|
7
|
+
* plain objects (incl. nested), arrays.
|
|
8
|
+
*
|
|
9
|
+
* Not supported (throws or produces non-unique output): circular references,
|
|
10
|
+
* class instances other than plain Object/Array, Map, Set, Symbol, functions.
|
|
11
|
+
* Treat the parameter as immutable — mutating an object after its first key is
|
|
12
|
+
* computed via a WeakMap memo will silently return the stale cached key.
|
|
13
|
+
*/
|
|
14
|
+
const memo = /* @__PURE__ */ new WeakMap();
|
|
15
|
+
function stableFamilyKey(value) {
|
|
16
|
+
if (value === null) return "null";
|
|
17
|
+
if (value === void 0) return "undefined";
|
|
18
|
+
const t = typeof value;
|
|
19
|
+
if (t === "string") return JSON.stringify(value);
|
|
20
|
+
if (t === "number") return String(value);
|
|
21
|
+
if (t === "boolean") return String(value);
|
|
22
|
+
if (t === "bigint") return `${String(value)}n`;
|
|
23
|
+
if (t !== "object") throw new TypeError(`stableFamilyKey: unsupported type "${t}" (${String(value)})`);
|
|
24
|
+
const obj = value;
|
|
25
|
+
const cached = memo.get(obj);
|
|
26
|
+
if (cached !== void 0) return cached;
|
|
27
|
+
const result = serializeValue(obj);
|
|
28
|
+
memo.set(obj, result);
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
function serializeValue(value) {
|
|
32
|
+
if (value === null) return "null";
|
|
33
|
+
if (value === void 0) return "undefined";
|
|
34
|
+
const t = typeof value;
|
|
35
|
+
if (t === "string") return JSON.stringify(value);
|
|
36
|
+
if (t === "number") return String(value);
|
|
37
|
+
if (t === "boolean") return String(value);
|
|
38
|
+
if (t === "bigint") return `${String(value)}n`;
|
|
39
|
+
if (t !== "object") throw new TypeError(`stableFamilyKey: unsupported type "${t}" (${String(value)})`);
|
|
40
|
+
if (Array.isArray(value)) return `[${value.map(serializeValue).join(",")}]`;
|
|
41
|
+
const proto = Object.getPrototypeOf(value);
|
|
42
|
+
if (proto !== Object.prototype && proto !== null) throw new TypeError(`stableFamilyKey: only plain objects are supported (got ${String(proto?.constructor?.name ?? "unknown")})`);
|
|
43
|
+
return `{${Object.keys(value).sort().map((k) => {
|
|
44
|
+
const v = value[k];
|
|
45
|
+
return `${JSON.stringify(k)}:${serializeValue(v)}`;
|
|
46
|
+
}).join(",")}}`;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { atom, atomFamily, createStore, stableFamilyKey };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=family.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"family.mjs","names":[],"sources":["../src/internal/stable-family-key.ts"],"sourcesContent":["/**\n * Produces a deterministic string key for plain-object/array/primitive values.\n *\n * Supported types: string, number, boolean, null, undefined, bigint,\n * plain objects (incl. nested), arrays.\n *\n * Not supported (throws or produces non-unique output): circular references,\n * class instances other than plain Object/Array, Map, Set, Symbol, functions.\n * Treat the parameter as immutable — mutating an object after its first key is\n * computed via a WeakMap memo will silently return the stale cached key.\n */\n\nconst memo = new WeakMap<object, string>();\n\nexport function stableFamilyKey(value: unknown): string {\n if (value === null) return \"null\";\n if (value === undefined) return \"undefined\";\n\n const t = typeof value;\n\n if (t === \"string\") return JSON.stringify(value);\n if (t === \"number\") return String(value);\n if (t === \"boolean\") return String(value);\n if (t === \"bigint\") return `${String(value)}n`;\n\n if (t !== \"object\") {\n throw new TypeError(`stableFamilyKey: unsupported type \"${t}\" (${String(value)})`);\n }\n\n const obj = value as object;\n const cached = memo.get(obj);\n if (cached !== undefined) return cached;\n\n const result = serializeValue(obj);\n memo.set(obj, result);\n return result;\n}\n\nfunction serializeValue(value: unknown): string {\n if (value === null) return \"null\";\n if (value === undefined) return \"undefined\";\n\n const t = typeof value;\n\n if (t === \"string\") return JSON.stringify(value);\n if (t === \"number\") return String(value);\n if (t === \"boolean\") return String(value);\n if (t === \"bigint\") return `${String(value)}n`;\n\n if (t !== \"object\") {\n throw new TypeError(`stableFamilyKey: unsupported type \"${t}\" (${String(value)})`);\n }\n\n if (Array.isArray(value)) {\n const items = (value as unknown[]).map(serializeValue);\n return `[${items.join(\",\")}]`;\n }\n\n const proto = Object.getPrototypeOf(value);\n if (proto !== Object.prototype && proto !== null) {\n throw new TypeError(\n `stableFamilyKey: only plain objects are supported (got ${String(proto?.constructor?.name ?? \"unknown\")})`,\n );\n }\n\n const keys = Object.keys(value as Record<string, unknown>).sort();\n const pairs = keys.map((k) => {\n const v = (value as Record<string, unknown>)[k];\n return `${JSON.stringify(k)}:${serializeValue(v)}`;\n });\n return `{${pairs.join(\",\")}}`;\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAM,uBAAO,IAAI,SAAyB;AAE1C,SAAgB,gBAAgB,OAAwB;AACtD,KAAI,UAAU,KAAM,QAAO;AAC3B,KAAI,UAAU,KAAA,EAAW,QAAO;CAEhC,MAAM,IAAI,OAAO;AAEjB,KAAI,MAAM,SAAU,QAAO,KAAK,UAAU,MAAM;AAChD,KAAI,MAAM,SAAU,QAAO,OAAO,MAAM;AACxC,KAAI,MAAM,UAAW,QAAO,OAAO,MAAM;AACzC,KAAI,MAAM,SAAU,QAAO,GAAG,OAAO,MAAM,CAAC;AAE5C,KAAI,MAAM,SACR,OAAM,IAAI,UAAU,sCAAsC,EAAE,KAAK,OAAO,MAAM,CAAC,GAAG;CAGpF,MAAM,MAAM;CACZ,MAAM,SAAS,KAAK,IAAI,IAAI;AAC5B,KAAI,WAAW,KAAA,EAAW,QAAO;CAEjC,MAAM,SAAS,eAAe,IAAI;AAClC,MAAK,IAAI,KAAK,OAAO;AACrB,QAAO;;AAGT,SAAS,eAAe,OAAwB;AAC9C,KAAI,UAAU,KAAM,QAAO;AAC3B,KAAI,UAAU,KAAA,EAAW,QAAO;CAEhC,MAAM,IAAI,OAAO;AAEjB,KAAI,MAAM,SAAU,QAAO,KAAK,UAAU,MAAM;AAChD,KAAI,MAAM,SAAU,QAAO,OAAO,MAAM;AACxC,KAAI,MAAM,UAAW,QAAO,OAAO,MAAM;AACzC,KAAI,MAAM,SAAU,QAAO,GAAG,OAAO,MAAM,CAAC;AAE5C,KAAI,MAAM,SACR,OAAM,IAAI,UAAU,sCAAsC,EAAE,KAAK,OAAO,MAAM,CAAC,GAAG;AAGpF,KAAI,MAAM,QAAQ,MAAM,CAEtB,QAAO,IADQ,MAAoB,IAAI,eAAe,CACrC,KAAK,IAAI,CAAC;CAG7B,MAAM,QAAQ,OAAO,eAAe,MAAM;AAC1C,KAAI,UAAU,OAAO,aAAa,UAAU,KAC1C,OAAM,IAAI,UACR,0DAA0D,OAAO,OAAO,aAAa,QAAQ,UAAU,CAAC,GACzG;AAQH,QAAO,IALM,OAAO,KAAK,MAAiC,CAAC,MAAM,CAC9C,KAAK,MAAM;EAC5B,MAAM,IAAK,MAAkC;AAC7C,SAAO,GAAG,KAAK,UAAU,EAAE,CAAC,GAAG,eAAe,EAAE;GAChD,CACe,KAAK,IAAI,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { r as atom, t as createStore } from "./store-
|
|
1
|
+
import { r as atom, t as createStore } from "./store-j2laS7Q2.mjs";
|
|
2
2
|
export { atom, createStore };
|
package/dist/react/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as CONFIG } from "../store-
|
|
1
|
+
import { i as CONFIG } from "../store-j2laS7Q2.mjs";
|
|
2
2
|
import { createContext, useCallback, useContext, useSyncExternalStore } from "react";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/react/provider.tsx
|
|
@@ -33,6 +33,9 @@ function atomFamily(options) {
|
|
|
33
33
|
const cache = /* @__PURE__ */ new Map();
|
|
34
34
|
const lruOrder = [];
|
|
35
35
|
const storeCallbacks = /* @__PURE__ */ new Set();
|
|
36
|
+
function keyOf(param) {
|
|
37
|
+
return options.paramKey != null ? options.paramKey(param) : param;
|
|
38
|
+
}
|
|
36
39
|
const link = {
|
|
37
40
|
invalidateAtom(target) {
|
|
38
41
|
for (const cb of storeCallbacks) cb(target);
|
|
@@ -48,19 +51,21 @@ function atomFamily(options) {
|
|
|
48
51
|
target[FAMILY_LINK] = link;
|
|
49
52
|
}
|
|
50
53
|
function getOrCreate(param) {
|
|
51
|
-
const
|
|
54
|
+
const key = keyOf(param);
|
|
55
|
+
const cached = cache.get(key);
|
|
52
56
|
if (cached != null) {
|
|
53
|
-
if (cachePolicy === "lru") touchLru(
|
|
57
|
+
if (cachePolicy === "lru") touchLru(key);
|
|
54
58
|
return cached;
|
|
55
59
|
}
|
|
56
60
|
const deps = options.dependencies?.(param);
|
|
57
61
|
const getFn = options.get(param);
|
|
58
62
|
const setFn = options.set?.(param);
|
|
59
|
-
const
|
|
63
|
+
const labelSuffix = options.paramKey != null ? String(key) : String(param);
|
|
64
|
+
const created = createAtom(options.debugLabel != null ? `${options.debugLabel}(${labelSuffix})` : void 0, deps, getFn, setFn);
|
|
60
65
|
attachLink(created);
|
|
61
|
-
cache.set(
|
|
66
|
+
cache.set(key, created);
|
|
62
67
|
if (cachePolicy === "lru") {
|
|
63
|
-
lruOrder.push(
|
|
68
|
+
lruOrder.push(key);
|
|
64
69
|
evictLru();
|
|
65
70
|
}
|
|
66
71
|
return created;
|
|
@@ -76,10 +81,10 @@ function atomFamily(options) {
|
|
|
76
81
|
}
|
|
77
82
|
return atom(base);
|
|
78
83
|
}
|
|
79
|
-
function touchLru(
|
|
80
|
-
const idx = lruOrder.indexOf(
|
|
84
|
+
function touchLru(key) {
|
|
85
|
+
const idx = lruOrder.indexOf(key);
|
|
81
86
|
if (idx !== -1) lruOrder.splice(idx, 1);
|
|
82
|
-
lruOrder.push(
|
|
87
|
+
lruOrder.push(key);
|
|
83
88
|
}
|
|
84
89
|
function evictLru() {
|
|
85
90
|
while (lruOrder.length > lruSize) {
|
|
@@ -89,16 +94,18 @@ function atomFamily(options) {
|
|
|
89
94
|
}
|
|
90
95
|
const family = getOrCreate;
|
|
91
96
|
family.invalidate = (param) => {
|
|
92
|
-
const
|
|
97
|
+
const key = keyOf(param);
|
|
98
|
+
const cached = cache.get(key);
|
|
93
99
|
if (cached != null) link.invalidateAtom(cached);
|
|
94
100
|
};
|
|
95
101
|
family.invalidateAll = () => {
|
|
96
102
|
for (const cached of cache.values()) link.invalidateAtom(cached);
|
|
97
103
|
};
|
|
98
104
|
family.remove = (param) => {
|
|
99
|
-
|
|
105
|
+
const key = keyOf(param);
|
|
106
|
+
cache.delete(key);
|
|
100
107
|
if (cachePolicy === "lru") {
|
|
101
|
-
const idx = lruOrder.indexOf(
|
|
108
|
+
const idx = lruOrder.indexOf(key);
|
|
102
109
|
if (idx !== -1) lruOrder.splice(idx, 1);
|
|
103
110
|
}
|
|
104
111
|
};
|
|
@@ -388,4 +395,4 @@ function extractPreviousValue(state) {
|
|
|
388
395
|
//#endregion
|
|
389
396
|
export { CONFIG as i, atomFamily as n, atom as r, createStore as t };
|
|
390
397
|
|
|
391
|
-
//# sourceMappingURL=store-
|
|
398
|
+
//# sourceMappingURL=store-j2laS7Q2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-j2laS7Q2.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 interface WritableAtomContext<\n Deps extends Record<string, Atom<unknown>>,\n Value,\n> extends AtomContext<Deps> {\n setOptimisticValue(value: Value): void;\n setOptimisticValue(mutate: (prev: Value | undefined) => 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>>, any>,\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 \"@/internal/types.js\";\nimport { CONFIG, WRITABLE } from \"@/internal/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 \"@/internal/types.js\";\nimport { FAMILY_LINK } from \"@/internal/types.js\";\nimport { atom } from \"@/internal/atom.js\";\n\nexport type AtomFamilyOptions<\n Param,\n Value,\n Deps extends Record<string, Atom<unknown>>,\n Args extends readonly unknown[],\n Key = Param,\n> = {\n dependencies?: (param: Param) => Deps;\n stalePolicy?: StalePolicy;\n cachePolicy?: \"keep-all\" | \"lru\";\n lruSize?: number;\n debugLabel?: string;\n /**\n * Optional function to derive a stable cache key from `param`.\n * Use when `Param` is an object and you want equality-by-value semantics.\n * The returned key is used for all cache operations (get, set, LRU, invalidate, remove).\n * The original `param` is still passed to `get`, `set`, and `dependencies`.\n *\n * For plain objects/arrays you can use `stableFamilyKey` from `@kdeveloper/kvark/family`.\n * Treat the param object as immutable after the first call — `stableFamilyKey` memoises\n * by object reference via a WeakMap.\n */\n paramKey?: (param: Param) => Key;\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, Key = Param> {\n (param: Param): Atom<Value>;\n invalidate(param: Param): void;\n invalidateAll(): void;\n remove(param: Param): void;\n getCache(): ReadonlyMap<Key, 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 Key = Param,\n>(options: AtomFamilyOptions<Param, Value, Deps, Args, Key>): AtomFamily<Param, Value, Key> {\n const cachePolicy = options.cachePolicy ?? \"keep-all\";\n const lruSize = options.lruSize ?? 100;\n const cache = new Map<Key, Atom<Value>>();\n const lruOrder: Key[] = [];\n const storeCallbacks = new Set<(atom: Atom<unknown>) => void>();\n\n function keyOf(param: Param): Key {\n return options.paramKey != null ? options.paramKey(param) : (param as unknown as Key);\n }\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 key = keyOf(param);\n const cached = cache.get(key);\n if (cached != null) {\n if (cachePolicy === \"lru\") {\n touchLru(key);\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 labelSuffix = options.paramKey != null ? String(key) : String(param);\n const label = options.debugLabel != null ? `${options.debugLabel}(${labelSuffix})` : undefined;\n\n const created = createAtom(label, deps, getFn, setFn);\n attachLink(created);\n cache.set(key, created);\n\n if (cachePolicy === \"lru\") {\n lruOrder.push(key);\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(key: Key): void {\n const idx = lruOrder.indexOf(key);\n if (idx !== -1) {\n lruOrder.splice(idx, 1);\n }\n lruOrder.push(key);\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, Key>;\n\n family.invalidate = (param: Param): void => {\n const key = keyOf(param);\n const cached = cache.get(key);\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 const key = keyOf(param);\n cache.delete(key);\n if (cachePolicy === \"lru\") {\n const idx = lruOrder.indexOf(key);\n if (idx !== -1) {\n lruOrder.splice(idx, 1);\n }\n }\n };\n\n family.getCache = (): ReadonlyMap<Key, 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 \"@/internal/types.js\";\nimport { CONFIG } from \"@/internal/types.js\";\nimport { getFamilyLink } from \"@/internal/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 write<V>(atom: Atom<V>, mutate: (prev: V | undefined) => 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: (valueOrMutate: V | ((prev: V | undefined) => V)): void => {\n if (optimisticSnapshot.current == null) {\n optimisticSnapshot.current = { state: entry.state, version: entry.version };\n }\n const next =\n typeof valueOrMutate === \"function\"\n ? (valueOrMutate as (prev: V | undefined) => V)(extractPreviousValue(entry.state))\n : valueOrMutate;\n entry.state = { status: \"fresh\", value: next, 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 write<V>(atom: Atom<V>, mutate: (prev: V | undefined) => V): void;\n write<V>(atom: Atom<V>, valueOrMutate: V | ((prev: V | undefined) => V)): void {\n const entry = this.#getOrCreate(atom);\n this.#controllers.get(atom)?.abort();\n entry.promise = null;\n const next =\n typeof valueOrMutate === \"function\"\n ? (valueOrMutate as (prev: V | undefined) => V)(extractPreviousValue(entry.state))\n : valueOrMutate;\n entry.state = { status: \"fresh\", value: next, 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 this.#client = {\n get: <V>(atom: Atom<V>): Promise<V> => this.resolve(atom),\n set: <V, A extends readonly unknown[]>(atom: WritableAtom<V, A>, ...args: A): Promise<void> =>\n this.set(atom, ...args),\n write: <V>(atom: Atom<V>, valueOrMutate: V | ((prev: V | undefined) => V)): void =>\n this.write(atom, valueOrMutate as V),\n invalidate: (atom: Atom<unknown>): void => this.invalidate(atom),\n invalidateMany: (atoms: ReadonlyArray<Atom<unknown>>): void => this.invalidateMany(atoms),\n subscribe: <V>(atom: Atom<V>, listener: (state: AtomState<V>) => void): (() => void) =>\n this.subscribe(atom, () => {\n listener(this.getSnapshot(atom));\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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MAAA;AAGT,QAAA,SAAe;GACb,MAAS,SAA8B,KAAK,QAAQ,KAAK;GACzD,MAAuC,MAA0B,GAAG,SAClE,KAAK,IAAI,MAAM,GAAG,KAAK;GACzB,QAAW,MAAe,kBACxB,KAAK,MAAM,MAAM,cAAmB;GACtC,aAAa,SAA8B,KAAK,WAAW,KAAK;GAChE,iBAAiB,UAA8C,KAAK,eAAe,MAAM;GACzF,YAAe,MAAe,aAC5B,KAAK,UAAU,YAAY;AACzB,aAAS,KAAK,YAAY,KAAK,CAAC;KAChC;GACL;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"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { f as WritableAtom, i as Atom, n as StoreClient, t as Store } from "../store-DQL8VJhU.mjs";
|
|
2
|
+
import * as _$vue from "vue";
|
|
3
|
+
import { PropType, ShallowRef } from "vue";
|
|
4
|
+
|
|
5
|
+
//#region src/vue/provider.d.ts
|
|
6
|
+
declare const Provider: _$vue.DefineComponent<_$vue.ExtractPropTypes<{
|
|
7
|
+
store: {
|
|
8
|
+
type: PropType<Store>;
|
|
9
|
+
required: true;
|
|
10
|
+
};
|
|
11
|
+
}>, () => _$vue.VNode<_$vue.RendererNode, _$vue.RendererElement, {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}>[] | undefined, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<_$vue.ExtractPropTypes<{
|
|
14
|
+
store: {
|
|
15
|
+
type: PropType<Store>;
|
|
16
|
+
required: true;
|
|
17
|
+
};
|
|
18
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, _$vue.ComponentProvideOptions, true, {}, any>;
|
|
19
|
+
declare function useStore(): Store;
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/vue/use-atom-value.d.ts
|
|
22
|
+
type ObservedValue<V> = {
|
|
23
|
+
value: V;
|
|
24
|
+
isStale: boolean;
|
|
25
|
+
error: unknown;
|
|
26
|
+
};
|
|
27
|
+
declare function useAtomValue<V>(atom: Atom<V>): Readonly<ShallowRef<V>>;
|
|
28
|
+
declare function useAtomValue<V>(atom: Atom<V>, opts: {
|
|
29
|
+
observe: true;
|
|
30
|
+
}): Readonly<ShallowRef<ObservedValue<V>>>;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/vue/use-set-atom.d.ts
|
|
33
|
+
declare function useSetAtom<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>): (...args: A) => Promise<void>;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/vue/use-atom.d.ts
|
|
36
|
+
declare function useAtom<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>): readonly [Readonly<ShallowRef<V>>, (...args: A) => Promise<void>];
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/vue/use-atom-context.d.ts
|
|
39
|
+
declare function useAtomContext<R>(callback: (ctx: StoreClient) => Promise<R>): () => Promise<R>;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { Provider, useAtom, useAtomContext, useAtomValue, useSetAtom, useStore };
|
|
42
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/vue/provider.ts","../../src/vue/use-atom-value.ts","../../src/vue/use-set-atom.ts","../../src/vue/use-atom.ts","../../src/vue/use-atom-context.ts"],"mappings":";;;;;cAWa,QAAA,QAAQ,eAAA,CAGgB,KAAA,CAHhB,gBAAA;;UAGQ,QAAA,CAAS,KAAA;;;sBAHjB,KAAA,CAAA,YAAA;;gIAGgB,KAAA,CAAA,gBAAA;;UAAR,QAAA,CAAS,KAAA;;;;iBAQtB,QAAA,CAAA,GAAY,KAAA;;;KClBvB,aAAA;EACH,KAAA,EAAO,CAAA;EACP,OAAA;EACA,KAAA;AAAA;AAAA,iBAGc,YAAA,GAAA,CAAgB,IAAA,EAAM,IAAA,CAAK,CAAA,IAAK,QAAA,CAAS,UAAA,CAAW,CAAA;AAAA,iBACpD,YAAA,GAAA,CACd,IAAA,EAAM,IAAA,CAAK,CAAA,GACX,IAAA;EAAQ,OAAA;AAAA,IACP,QAAA,CAAS,UAAA,CAAW,aAAA,CAAc,CAAA;;;iBCXrB,UAAA,iCAAA,CACd,IAAA,EAAM,YAAA,CAAa,CAAA,EAAG,CAAA,QACjB,IAAA,EAAM,CAAA,KAAM,OAAA;;;iBCAH,OAAA,iCAAA,CACd,IAAA,EAAM,YAAA,CAAa,CAAA,EAAG,CAAA,cACX,QAAA,CAAS,UAAA,CAAW,CAAA,QAAS,IAAA,EAAM,CAAA,KAAM,OAAA;;;iBCJtC,cAAA,GAAA,CAAkB,QAAA,GAAW,GAAA,EAAK,WAAA,KAAgB,OAAA,CAAQ,CAAA,UAAW,OAAA,CAAQ,CAAA"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { defineComponent, inject, provide, readonly, shallowRef, watchEffect } from "vue";
|
|
2
|
+
//#region src/vue/provider.ts
|
|
3
|
+
const StoreKey = Symbol("kvark-store");
|
|
4
|
+
const Provider = defineComponent({
|
|
5
|
+
name: "KvarkProvider",
|
|
6
|
+
props: { store: {
|
|
7
|
+
type: Object,
|
|
8
|
+
required: true
|
|
9
|
+
} },
|
|
10
|
+
setup(props, { slots }) {
|
|
11
|
+
provide(StoreKey, props.store);
|
|
12
|
+
return () => slots["default"]?.();
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
function useStore() {
|
|
16
|
+
const store = inject(StoreKey);
|
|
17
|
+
if (store == null) throw new Error("useStore must be used within a <Provider>");
|
|
18
|
+
return store;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/vue/use-atom-value.ts
|
|
22
|
+
function useAtomValue(atom, opts) {
|
|
23
|
+
const store = useStore();
|
|
24
|
+
function derive(snapshot) {
|
|
25
|
+
if (snapshot.status === "pending") {
|
|
26
|
+
store.resolve(atom);
|
|
27
|
+
if (opts?.observe === true) return {
|
|
28
|
+
value: void 0,
|
|
29
|
+
isStale: false,
|
|
30
|
+
error: void 0
|
|
31
|
+
};
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (snapshot.status === "stale") {
|
|
35
|
+
store.resolve(atom);
|
|
36
|
+
if (opts?.observe === true) return {
|
|
37
|
+
value: snapshot.value,
|
|
38
|
+
isStale: true,
|
|
39
|
+
error: void 0
|
|
40
|
+
};
|
|
41
|
+
return snapshot.value;
|
|
42
|
+
}
|
|
43
|
+
if (snapshot.status === "error") {
|
|
44
|
+
if (opts?.observe === true && snapshot.value !== void 0) return {
|
|
45
|
+
value: snapshot.value,
|
|
46
|
+
isStale: false,
|
|
47
|
+
error: snapshot.error
|
|
48
|
+
};
|
|
49
|
+
throw snapshot.error;
|
|
50
|
+
}
|
|
51
|
+
if (opts?.observe === true) return {
|
|
52
|
+
value: snapshot.value,
|
|
53
|
+
isStale: false,
|
|
54
|
+
error: void 0
|
|
55
|
+
};
|
|
56
|
+
return snapshot.value;
|
|
57
|
+
}
|
|
58
|
+
const result = shallowRef(derive(store.getSnapshot(atom)));
|
|
59
|
+
watchEffect((onCleanup) => {
|
|
60
|
+
onCleanup(store.subscribe(atom, () => {
|
|
61
|
+
result.value = derive(store.getSnapshot(atom));
|
|
62
|
+
}));
|
|
63
|
+
});
|
|
64
|
+
return readonly(result);
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/vue/use-set-atom.ts
|
|
68
|
+
function useSetAtom(atom) {
|
|
69
|
+
const store = useStore();
|
|
70
|
+
return (...args) => store.set(atom, ...args);
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/vue/use-atom.ts
|
|
74
|
+
function useAtom(atom) {
|
|
75
|
+
return [useAtomValue(atom), useSetAtom(atom)];
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/vue/use-atom-context.ts
|
|
79
|
+
function useAtomContext(callback) {
|
|
80
|
+
const store = useStore();
|
|
81
|
+
return () => callback(store.getClient());
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
export { Provider, useAtom, useAtomContext, useAtomValue, useSetAtom, useStore };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/vue/provider.ts","../../src/vue/use-atom-value.ts","../../src/vue/use-set-atom.ts","../../src/vue/use-atom.ts","../../src/vue/use-atom-context.ts"],"sourcesContent":["import {\n type InjectionKey,\n type PropType,\n defineComponent,\n inject,\n provide,\n} from \"vue\";\nimport { Store } from \"@/internal/store.js\";\n\nconst StoreKey: InjectionKey<Store> = Symbol(\"kvark-store\");\n\nexport const Provider = defineComponent({\n name: \"KvarkProvider\",\n props: {\n store: { type: Object as PropType<Store>, required: true },\n },\n setup(props, { slots }) {\n provide(StoreKey, props.store);\n return () => slots[\"default\"]?.();\n },\n});\n\nexport function useStore(): Store {\n const store = inject(StoreKey);\n if (store == null) {\n throw new Error(\"useStore must be used within a <Provider>\");\n }\n return store;\n}\n","import { type ShallowRef, readonly, shallowRef, watchEffect } from \"vue\";\nimport type { Atom, AtomState } from \"@/internal/types.js\";\nimport { useStore } from \"@/vue/provider.js\";\n\ntype ObservedValue<V> = {\n value: V;\n isStale: boolean;\n error: unknown;\n};\n\nexport function useAtomValue<V>(atom: Atom<V>): Readonly<ShallowRef<V>>;\nexport function useAtomValue<V>(\n atom: Atom<V>,\n opts: { observe: true },\n): Readonly<ShallowRef<ObservedValue<V>>>;\nexport function useAtomValue<V>(\n atom: Atom<V>,\n opts?: { observe: true },\n): Readonly<ShallowRef<V | ObservedValue<V>>> {\n const store = useStore();\n\n function derive(snapshot: AtomState<V>): V | ObservedValue<V> {\n if (snapshot.status === \"pending\") {\n void store.resolve(atom);\n if (opts?.observe === true) {\n return { value: undefined as V, isStale: false, error: undefined };\n }\n return undefined as V;\n }\n\n if (snapshot.status === \"stale\") {\n void store.resolve(atom);\n if (opts?.observe === true) {\n return { value: snapshot.value, isStale: true, error: undefined };\n }\n return snapshot.value;\n }\n\n if (snapshot.status === \"error\") {\n if (opts?.observe === true && snapshot.value !== undefined) {\n return { value: snapshot.value as V, isStale: false, error: snapshot.error };\n }\n throw snapshot.error;\n }\n\n // status === \"fresh\"\n if (opts?.observe === true) {\n return { value: snapshot.value, isStale: false, error: undefined };\n }\n return snapshot.value;\n }\n\n const result = shallowRef(derive(store.getSnapshot(atom)));\n\n watchEffect((onCleanup) => {\n const unsub = store.subscribe(atom, () => {\n result.value = derive(store.getSnapshot(atom));\n });\n onCleanup(unsub);\n });\n\n return readonly(result) as Readonly<ShallowRef<V | ObservedValue<V>>>;\n}\n","import type { WritableAtom } from \"@/internal/types.js\";\nimport { useStore } from \"@/vue/provider.js\";\n\nexport function useSetAtom<V, A extends readonly unknown[]>(\n atom: WritableAtom<V, A>,\n): (...args: A) => Promise<void> {\n const store = useStore();\n return (...args: A): Promise<void> => store.set(atom, ...args);\n}\n","import type { ShallowRef } from \"vue\";\nimport type { WritableAtom } from \"@/internal/types.js\";\nimport { useAtomValue } from \"@/vue/use-atom-value.js\";\nimport { useSetAtom } from \"@/vue/use-set-atom.js\";\n\nexport function useAtom<V, A extends readonly unknown[]>(\n atom: WritableAtom<V, A>,\n): readonly [Readonly<ShallowRef<V>>, (...args: A) => Promise<void>] {\n const value = useAtomValue(atom);\n const setter = useSetAtom(atom);\n return [value, setter] as const;\n}\n","import type { StoreClient } from \"@/internal/store.js\";\nimport { useStore } from \"@/vue/provider.js\";\n\nexport function useAtomContext<R>(callback: (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;AACxC,UAAO,QAAQ,OAAO,MAAM,YAAY,KAAK,CAAC;IAC9C,CACc;GAChB;AAEF,QAAO,SAAS,OAAO;;;;AC1DzB,SAAgB,WACd,MAC+B;CAC/B,MAAM,QAAQ,UAAU;AACxB,SAAQ,GAAG,SAA2B,MAAM,IAAI,MAAM,GAAG,KAAK;;;;ACFhE,SAAgB,QACd,MACmE;AAGnE,QAAO,CAFO,aAAa,KAAK,EACjB,WAAW,KAAK,CACT;;;;ACPxB,SAAgB,eAAkB,UAA8D;CAC9F,MAAM,QAAQ,UAAU;AACxB,cAAyB,SAAS,MAAM,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kdeveloper/kvark",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Atomic state management with explicit dependency graphs",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
8
8
|
],
|
|
9
9
|
"type": "module",
|
|
10
|
+
"main": "./dist/index.mjs",
|
|
11
|
+
"module": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
10
13
|
"exports": {
|
|
11
14
|
".": {
|
|
12
|
-
"types": "./dist/index.d.
|
|
13
|
-
"import": "./dist/index.
|
|
15
|
+
"types": "./dist/index.d.mts",
|
|
16
|
+
"import": "./dist/index.mjs"
|
|
14
17
|
},
|
|
15
18
|
"./react": {
|
|
16
|
-
"types": "./dist/react/index.d.
|
|
17
|
-
"import": "./dist/react/index.
|
|
19
|
+
"types": "./dist/react/index.d.mts",
|
|
20
|
+
"import": "./dist/react/index.mjs"
|
|
21
|
+
},
|
|
22
|
+
"./vue": {
|
|
23
|
+
"types": "./dist/vue/index.d.mts",
|
|
24
|
+
"import": "./dist/vue/index.mjs"
|
|
18
25
|
},
|
|
19
26
|
"./family": {
|
|
20
|
-
"types": "./dist/family.d.
|
|
21
|
-
"import": "./dist/family.
|
|
27
|
+
"types": "./dist/family.d.mts",
|
|
28
|
+
"import": "./dist/family.mjs"
|
|
22
29
|
}
|
|
23
30
|
},
|
|
24
31
|
"devDependencies": {
|
|
@@ -26,6 +33,7 @@
|
|
|
26
33
|
"@testing-library/react": "^16.3.2",
|
|
27
34
|
"@types/react": "^19.2.14",
|
|
28
35
|
"@types/react-dom": "^19.2.3",
|
|
36
|
+
"@vue/test-utils": "^2.4.6",
|
|
29
37
|
"jsdom": "^29.0.1",
|
|
30
38
|
"oxfmt": "^0.42.0",
|
|
31
39
|
"oxlint": "^1.57.0",
|
|
@@ -33,10 +41,20 @@
|
|
|
33
41
|
"react-dom": "^19.2.4",
|
|
34
42
|
"tsdown": "^0.21.6",
|
|
35
43
|
"typescript": "^6.0.2",
|
|
36
|
-
"vitest": "^4.1.2"
|
|
44
|
+
"vitest": "^4.1.2",
|
|
45
|
+
"vue": "^3.5.31"
|
|
37
46
|
},
|
|
38
47
|
"peerDependencies": {
|
|
39
|
-
"react": ">=18"
|
|
48
|
+
"react": ">=18",
|
|
49
|
+
"vue": ">=3.4"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"react": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"vue": {
|
|
56
|
+
"optional": true
|
|
57
|
+
}
|
|
40
58
|
},
|
|
41
59
|
"engines": {
|
|
42
60
|
"node": ">=20"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store-CNjvdLHG.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 interface WritableAtomContext<\n Deps extends Record<string, Atom<unknown>>,\n Value,\n> extends AtomContext<Deps> {\n setOptimisticValue(value: Value): void;\n setOptimisticValue(mutate: (prev: Value | undefined) => 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>>, any>,\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 \"@/internal/types.js\";\nimport { CONFIG, WRITABLE } from \"@/internal/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 \"@/internal/types.js\";\nimport { FAMILY_LINK } from \"@/internal/types.js\";\nimport { atom } from \"@/internal/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 \"@/internal/types.js\";\nimport { CONFIG } from \"@/internal/types.js\";\nimport { getFamilyLink } from \"@/internal/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 write<V>(atom: Atom<V>, mutate: (prev: V | undefined) => 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: (valueOrMutate: V | ((prev: V | undefined) => V)): void => {\n if (optimisticSnapshot.current == null) {\n optimisticSnapshot.current = { state: entry.state, version: entry.version };\n }\n const next =\n typeof valueOrMutate === \"function\"\n ? (valueOrMutate as (prev: V | undefined) => V)(extractPreviousValue(entry.state))\n : valueOrMutate;\n entry.state = { status: \"fresh\", value: next, 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 write<V>(atom: Atom<V>, mutate: (prev: V | undefined) => V): void;\n write<V>(atom: Atom<V>, valueOrMutate: V | ((prev: V | undefined) => V)): void {\n const entry = this.#getOrCreate(atom);\n this.#controllers.get(atom)?.abort();\n entry.promise = null;\n const next =\n typeof valueOrMutate === \"function\"\n ? (valueOrMutate as (prev: V | undefined) => V)(extractPreviousValue(entry.state))\n : valueOrMutate;\n entry.state = { status: \"fresh\", value: next, 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 this.#client = {\n get: <V>(atom: Atom<V>): Promise<V> => this.resolve(atom),\n set: <V, A extends readonly unknown[]>(atom: WritableAtom<V, A>, ...args: A): Promise<void> =>\n this.set(atom, ...args),\n write: <V>(atom: Atom<V>, valueOrMutate: V | ((prev: V | undefined) => V)): void =>\n this.write(atom, valueOrMutate as V),\n invalidate: (atom: Atom<unknown>): void => this.invalidate(atom),\n invalidateMany: (atoms: ReadonlyArray<Atom<unknown>>): void => this.invalidateMany(atoms),\n subscribe: <V>(atom: Atom<V>, listener: (state: AtomState<V>) => void): (() => void) =>\n this.subscribe(atom, () => {\n listener(this.getSnapshot(atom));\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;CACnC,MAAM,wBAAQ,IAAI,KAAyB;CAC3C,MAAM,WAAoB,EAAE;CAC5B,MAAM,iCAAiB,IAAI,KAAoC;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