@softistx/riva 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +168 -2
  3. package/dist/batch.d.ts +5 -0
  4. package/dist/batch.d.ts.map +1 -0
  5. package/dist/chunks/index-2g2s3y31.js +58 -0
  6. package/dist/chunks/index-2g2s3y31.js.map +10 -0
  7. package/dist/chunks/index-46sbdyt0.js +84 -0
  8. package/dist/chunks/index-46sbdyt0.js.map +12 -0
  9. package/dist/chunks/index-5xnfwj57.js +21 -0
  10. package/dist/chunks/index-5xnfwj57.js.map +10 -0
  11. package/dist/chunks/index-asz1gnp1.js +50 -0
  12. package/dist/chunks/index-asz1gnp1.js.map +10 -0
  13. package/dist/chunks/index-e4vzsfy1.js +253 -0
  14. package/dist/chunks/index-e4vzsfy1.js.map +11 -0
  15. package/dist/chunks/index-tn8ankny.js +137 -0
  16. package/dist/chunks/index-tn8ankny.js.map +10 -0
  17. package/dist/chunks/index-vz93xwnj.js +35 -0
  18. package/dist/chunks/index-vz93xwnj.js.map +10 -0
  19. package/dist/chunks/index-y6bzw104.js +53 -0
  20. package/dist/chunks/index-y6bzw104.js.map +11 -0
  21. package/dist/client.d.ts +48 -0
  22. package/dist/client.d.ts.map +1 -0
  23. package/dist/computed.d.ts +21 -0
  24. package/dist/computed.d.ts.map +1 -0
  25. package/dist/data/index.d.ts +19 -0
  26. package/dist/data/index.d.ts.map +1 -0
  27. package/dist/data/index.js +60 -0
  28. package/dist/data/index.js.map +10 -0
  29. package/dist/data/types.d.ts +12 -0
  30. package/dist/data/types.d.ts.map +1 -0
  31. package/dist/duration.d.ts +5 -0
  32. package/dist/duration.d.ts.map +1 -0
  33. package/dist/effect.d.ts +5 -0
  34. package/dist/effect.d.ts.map +1 -0
  35. package/dist/entities/api.d.ts +18 -0
  36. package/dist/entities/api.d.ts.map +1 -0
  37. package/dist/entities/denormalize.d.ts +13 -0
  38. package/dist/entities/denormalize.d.ts.map +1 -0
  39. package/dist/entities/identity.d.ts +11 -0
  40. package/dist/entities/identity.d.ts.map +1 -0
  41. package/dist/entities/index.d.ts +6 -0
  42. package/dist/entities/index.d.ts.map +1 -0
  43. package/dist/entities/index.js +414 -0
  44. package/dist/entities/index.js.map +16 -0
  45. package/dist/entities/json.d.ts +15 -0
  46. package/dist/entities/json.d.ts.map +1 -0
  47. package/dist/entities/normalize.d.ts +11 -0
  48. package/dist/entities/normalize.d.ts.map +1 -0
  49. package/dist/entities/policy.d.ts +41 -0
  50. package/dist/entities/policy.d.ts.map +1 -0
  51. package/dist/entities/store.d.ts +47 -0
  52. package/dist/entities/store.d.ts.map +1 -0
  53. package/dist/env.d.ts +15 -0
  54. package/dist/env.d.ts.map +1 -0
  55. package/dist/errors.d.ts +38 -0
  56. package/dist/errors.d.ts.map +1 -0
  57. package/dist/flush.d.ts +11 -0
  58. package/dist/flush.d.ts.map +1 -0
  59. package/dist/graph.d.ts +47 -0
  60. package/dist/graph.d.ts.map +1 -0
  61. package/dist/index.d.ts +14 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +502 -0
  64. package/dist/index.js.map +18 -0
  65. package/dist/infinite/index.d.ts +3 -0
  66. package/dist/infinite/index.d.ts.map +1 -0
  67. package/dist/infinite/index.js +207 -0
  68. package/dist/infinite/index.js.map +13 -0
  69. package/dist/infinite/infinite.d.ts +8 -0
  70. package/dist/infinite/infinite.d.ts.map +1 -0
  71. package/dist/infinite/more.d.ts +19 -0
  72. package/dist/infinite/more.d.ts.map +1 -0
  73. package/dist/infinite/refetch.d.ts +16 -0
  74. package/dist/infinite/refetch.d.ts.map +1 -0
  75. package/dist/infinite/slots.d.ts +22 -0
  76. package/dist/infinite/slots.d.ts.map +1 -0
  77. package/dist/infinite/types.d.ts +68 -0
  78. package/dist/infinite/types.d.ts.map +1 -0
  79. package/dist/key.d.ts +3 -0
  80. package/dist/key.d.ts.map +1 -0
  81. package/dist/mutation-run.d.ts +5 -0
  82. package/dist/mutation-run.d.ts.map +1 -0
  83. package/dist/mutation.d.ts +53 -0
  84. package/dist/mutation.d.ts.map +1 -0
  85. package/dist/query-cache.d.ts +33 -0
  86. package/dist/query-cache.d.ts.map +1 -0
  87. package/dist/query-entry.d.ts +85 -0
  88. package/dist/query-entry.d.ts.map +1 -0
  89. package/dist/query-observe.d.ts +9 -0
  90. package/dist/query-observe.d.ts.map +1 -0
  91. package/dist/query-run.d.ts +12 -0
  92. package/dist/query-run.d.ts.map +1 -0
  93. package/dist/query.d.ts +100 -0
  94. package/dist/query.d.ts.map +1 -0
  95. package/dist/retry.d.ts +18 -0
  96. package/dist/retry.d.ts.map +1 -0
  97. package/dist/scope.d.ts +16 -0
  98. package/dist/scope.d.ts.map +1 -0
  99. package/dist/signal.d.ts +22 -0
  100. package/dist/signal.d.ts.map +1 -0
  101. package/dist/ssr/codec.d.ts +10 -0
  102. package/dist/ssr/codec.d.ts.map +1 -0
  103. package/dist/ssr/dehydrate.d.ts +37 -0
  104. package/dist/ssr/dehydrate.d.ts.map +1 -0
  105. package/dist/ssr/hydrate.d.ts +20 -0
  106. package/dist/ssr/hydrate.d.ts.map +1 -0
  107. package/dist/ssr/index.d.ts +5 -0
  108. package/dist/ssr/index.d.ts.map +1 -0
  109. package/dist/ssr/index.js +136 -0
  110. package/dist/ssr/index.js.map +11 -0
  111. package/dist/store/def.d.ts +31 -0
  112. package/dist/store/def.d.ts.map +1 -0
  113. package/dist/store/index.d.ts +3 -0
  114. package/dist/store/index.d.ts.map +1 -0
  115. package/dist/store/index.js +215 -0
  116. package/dist/store/index.js.map +14 -0
  117. package/dist/store/instance.d.ts +14 -0
  118. package/dist/store/instance.d.ts.map +1 -0
  119. package/dist/store/run.d.ts +12 -0
  120. package/dist/store/run.d.ts.map +1 -0
  121. package/dist/store/store.d.ts +10 -0
  122. package/dist/store/store.d.ts.map +1 -0
  123. package/dist/store/types.d.ts +70 -0
  124. package/dist/store/types.d.ts.map +1 -0
  125. package/dist/store/view.d.ts +10 -0
  126. package/dist/store/view.d.ts.map +1 -0
  127. package/docs/README.md +19 -0
  128. package/docs/guide/data.md +36 -0
  129. package/docs/guide/entities.md +90 -0
  130. package/docs/guide/errors.md +31 -0
  131. package/docs/guide/infinite.md +62 -0
  132. package/docs/guide/mutations.md +73 -0
  133. package/docs/guide/queries.md +93 -0
  134. package/docs/guide/signals.md +72 -0
  135. package/docs/guide/ssr.md +65 -0
  136. package/docs/guide/store.md +88 -0
  137. package/docs/troubleshooting.md +343 -0
  138. package/package.json +84 -5
@@ -0,0 +1,215 @@
1
+ import {
2
+ computed2
3
+ } from "../chunks/index-5xnfwj57.js";
4
+ import {
5
+ resolve,
6
+ signal2
7
+ } from "../chunks/index-y6bzw104.js";
8
+ import {
9
+ RivaError2
10
+ } from "../chunks/index-2g2s3y31.js";
11
+
12
+ // src/store/view.ts
13
+ var refuse = (message) => {
14
+ throw new RivaError2("RIVA_STORE", message);
15
+ };
16
+ var view = (keys, read, write) => new Proxy({}, {
17
+ get: (_, k) => typeof k === "string" && Object.hasOwn(keys, k) ? read(k) : undefined,
18
+ set: (_, k, v) => {
19
+ write(k, v);
20
+ return true;
21
+ }
22
+ });
23
+
24
+ // src/store/def.ts
25
+ var RESERVED = ["kind", "name", "reset", "bind", "then"];
26
+ var dev = false;
27
+ try {
28
+ dev = true;
29
+ } catch {}
30
+ var freeze = (v) => {
31
+ if (dev && v && typeof v === "object" && !Object.isFrozen(v)) {
32
+ Object.freeze(v);
33
+ for (const x of Object.values(v))
34
+ freeze(x);
35
+ }
36
+ return v;
37
+ };
38
+ var inBrowser = () => typeof document !== "undefined";
39
+ var writing = 0;
40
+ var writable = () => writing > 0;
41
+ var put = (client, sig, value) => {
42
+ writing++;
43
+ try {
44
+ client.set(sig, () => value);
45
+ } finally {
46
+ writing--;
47
+ }
48
+ };
49
+ var checkKeys = (name, keys) => {
50
+ const seen = new Set(RESERVED);
51
+ for (const k of keys) {
52
+ if (seen.has(k))
53
+ refuse(`Store "${name}": the key "${k}" is taken (a state, computed or action key, or one of ${RESERVED.join(", ")}).`);
54
+ seen.add(k);
55
+ }
56
+ };
57
+ var stateSignals = (name, state, ssr) => {
58
+ const sigs = {};
59
+ for (const k in state)
60
+ sigs[k] = signal2(freeze(state[k]), {
61
+ name: `${name}.${k}`,
62
+ ssr,
63
+ equals: (a, b) => writable() ? Object.is(a, b) : refuse(`Store "${name}": "${k}" is written outside an action. Write it in an action of the store.`)
64
+ });
65
+ return sigs;
66
+ };
67
+ var computeds = (name, state, derived, sigs) => {
68
+ const comps = {};
69
+ for (const k in derived)
70
+ comps[k] = computed2((get) => derived[k]?.(view(state, (key) => get(sigs[key]), (key) => refuse(`Store "${name}": a computed cannot write "${key}".`)), get), { name: `${name}.${k}` });
71
+ return comps;
72
+ };
73
+
74
+ // src/store/run.ts
75
+ function writer(def, client, st, release) {
76
+ const { name, sigs, members } = def;
77
+ return view(members, (k) => client.get(members[k]), (k, v) => {
78
+ if (!st.live)
79
+ refuse(`Store "${name}": "${k}" is written after its action settled.`);
80
+ if (!Object.hasOwn(sigs, k))
81
+ refuse(`Store "${name}": "${k}" is not a state key, so it cannot be written.`);
82
+ if (!st.sync && !st.held) {
83
+ st.held = true;
84
+ client.graph.depth++;
85
+ queueMicrotask(release);
86
+ }
87
+ put(client, sigs[k], freeze(v));
88
+ });
89
+ }
90
+ function run(def, client, fn, args) {
91
+ const st = { live: true, sync: true, held: false, failure: undefined };
92
+ const g = client.graph;
93
+ const release = () => {
94
+ if (!st.held)
95
+ return;
96
+ st.held = false;
97
+ g.depth--;
98
+ try {
99
+ client.batch(() => {});
100
+ } catch (error) {
101
+ st.failure ??= { error };
102
+ }
103
+ };
104
+ const s = writer(def, client, st, release);
105
+ const ctx = {
106
+ client,
107
+ fetch: (q, ...a) => q.ensure(client, ...a),
108
+ mutate: (m, ...a) => m.run(client, ...a)
109
+ };
110
+ const given = args.slice();
111
+ given.length = Math.max(args.length, fn.length - 2);
112
+ const settle = () => {
113
+ release();
114
+ st.live = false;
115
+ };
116
+ let result;
117
+ try {
118
+ result = client.run(() => client.batch(() => client.untracked(() => fn(s, ...given, ctx))));
119
+ } catch (e) {
120
+ settle();
121
+ throw e;
122
+ } finally {
123
+ st.sync = false;
124
+ }
125
+ if (!result?.then) {
126
+ settle();
127
+ return result;
128
+ }
129
+ return result.then((v) => {
130
+ settle();
131
+ if (st.failure)
132
+ throw st.failure.error;
133
+ return v;
134
+ }, (e) => {
135
+ settle();
136
+ throw e;
137
+ });
138
+ }
139
+
140
+ // src/store/instance.ts
141
+ function instance(def, client) {
142
+ const cached = client.slots.get(def);
143
+ if (cached)
144
+ return cached;
145
+ const { name, sigs, members, actions } = def;
146
+ const claim = `name:${name}`;
147
+ const holder = client.slots.get(claim);
148
+ if (holder !== undefined) {
149
+ if (!inBrowser())
150
+ refuse(`Store "${name}": two stores are named "${name}" on this client: give each store a unique name.`);
151
+ client.slots.delete(holder);
152
+ for (const sig of Object.values(holder.sigs))
153
+ if (sig.name)
154
+ client.graph.named.delete(sig.name);
155
+ }
156
+ client.slots.set(claim, def);
157
+ const seeds = client.graph.seeds;
158
+ if (seeds)
159
+ for (const k in sigs) {
160
+ const sig = sigs[k];
161
+ if (sig?.name !== undefined && seeds.has(sig.name))
162
+ client.untracked(() => freeze(client.get(sig)));
163
+ }
164
+ const bound = {};
165
+ for (const k in actions)
166
+ bound[k] = (...args) => run(def, client, actions[k], args);
167
+ const made = [
168
+ view(members, (k) => client.get(members[k]), (k) => refuse(`Store "${name}": "${k}" is read-only here; write it in an action.`)),
169
+ bound
170
+ ];
171
+ client.slots.set(def, made);
172
+ return made;
173
+ }
174
+
175
+ // src/store/store.ts
176
+ function store(options) {
177
+ const { name, ssr = false } = options;
178
+ const state = options.state;
179
+ const derived = options.computed ?? {};
180
+ const actions = options.actions ?? {};
181
+ checkKeys(name, [
182
+ ...Object.keys(state),
183
+ ...Object.keys(derived),
184
+ ...Object.keys(actions)
185
+ ]);
186
+ const sigs = stateSignals(name, state, ssr);
187
+ const comps = computeds(name, state, derived, sigs);
188
+ const members = { ...sigs, ...comps };
189
+ const data = { name, sigs, members, actions };
190
+ const ambient = {};
191
+ for (const k in actions)
192
+ ambient[k] = (...args) => instance(data, resolve())[1][k](...args);
193
+ return Object.freeze({
194
+ kind: "store",
195
+ name,
196
+ reset: (client = resolve()) => {
197
+ instance(data, client);
198
+ client.batch(() => {
199
+ for (const k in sigs) {
200
+ const sig = sigs[k];
201
+ put(client, sig, sig.initial);
202
+ }
203
+ });
204
+ },
205
+ bind: (client) => instance(data, client),
206
+ ...ambient,
207
+ ...members
208
+ });
209
+ }
210
+ export {
211
+ store
212
+ };
213
+
214
+ //# debugId=BC5EA30508CF2C0D64756E2164756E21
215
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,14 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/store/view.ts", "../src/store/def.ts", "../src/store/run.ts", "../src/store/instance.ts", "../src/store/store.ts"],
4
+ "sourcesContent": [
5
+ "import { RivaError } from '../errors';\n\n/** Throws the error every store refusal uses. */\nexport const refuse = (message: string): never => {\n\tthrow new RivaError('RIVA_STORE', message);\n};\n\n/**\n * The one Proxy behind every store view: an action's `s` (read, guarded\n * write), a computed's `s` (tracked read, no write) and a component's (reads\n * recorded, no write). An unknown key reads `undefined`, so a symbol probe\n * (`then`, a devtools hook) is harmless; writes decide for themselves.\n */\nexport const view = (\n\tkeys: object,\n\tread: (key: string) => unknown,\n\twrite: (key: string, value: unknown) => void,\n): Record<string, unknown> =>\n\tnew Proxy(\n\t\t{},\n\t\t{\n\t\t\tget: (_, k) =>\n\t\t\t\ttypeof k === 'string' && Object.hasOwn(keys, k) ? read(k) : undefined,\n\t\t\tset: (_, k, v) => {\n\t\t\t\twrite(k as string, v);\n\t\t\t\treturn true;\n\t\t\t},\n\t\t},\n\t);\n",
6
+ "import type { RivaClient } from '../client';\nimport type { Readable } from '../computed';\nimport { computed, type Getter } from '../computed';\nimport { type Signal, signal } from '../signal';\nimport type { Action } from './types';\nimport { refuse, view } from './view';\n\n/** The data of one store definition, shared by its action runner and its per-client instance. */\nexport interface StoreDef {\n\treadonly name: string;\n\t/** The state keys' signals, named `<name>.<key>`. */\n\treadonly sigs: Record<string, Signal<unknown>>;\n\t/** The signals and computeds, by key. */\n\treadonly members: Record<string, Readable<unknown>>;\n\t// biome-ignore lint/suspicious/noExplicitAny: any state and computed shape\n\treadonly actions: Record<string, Action<any, any>>;\n}\n\n/** Keys a store cannot use: its own members, and `then` (a store is never thenable). */\nexport const RESERVED = ['kind', 'name', 'reset', 'bind', 'then'];\n\n// Off in a browser bundle that has no `process`.\nlet dev = false;\ntry {\n\tdev = process.env.NODE_ENV !== 'production';\n} catch {}\n\n/** Dev only: a stored value cannot be mutated in place, so a nested write throws. */\nexport const freeze = <T>(v: T): T => {\n\tif (dev && v && typeof v === 'object' && !Object.isFrozen(v)) {\n\t\tObject.freeze(v);\n\t\tfor (const x of Object.values(v)) freeze(x);\n\t}\n\treturn v;\n};\n\n/** The browser keeps the newest of two stores with one name (hot reload); the server refuses. */\nexport const inBrowser = (): boolean => typeof document !== 'undefined';\n\n/**\n * Raised for the length of one synchronous write made through an action's `s`\n * or `reset`: the state signals' `equals` refuses every other write. Safe as\n * module state: it is only raised under a batch (depth > 0, which an action\n * past an `await` takes before its first write), so no listener runs while it\n * is up and a write a listener makes is refused like any other.\n */\nlet writing = 0;\n\n/** Whether a write is allowed now: the guard the state signals' `equals` asks. */\nexport const writable = (): boolean => writing > 0;\n\n/** Writes one state key through its signal, with the guard raised. */\nexport const put = (\n\tclient: RivaClient,\n\tsig: Signal<unknown>,\n\tvalue: unknown,\n): void => {\n\twriting++;\n\ttry {\n\t\tclient.set(sig, () => value);\n\t} finally {\n\t\twriting--;\n\t}\n};\n\n/** Refuses a state, computed or action key that is reserved or used twice. */\nexport const checkKeys = (name: string, keys: readonly string[]): void => {\n\tconst seen = new Set(RESERVED);\n\tfor (const k of keys) {\n\t\tif (seen.has(k))\n\t\t\trefuse(\n\t\t\t\t`Store \"${name}\": the key \"${k}\" is taken (a state, computed or action key, or one of ${RESERVED.join(', ')}).`,\n\t\t\t);\n\t\tseen.add(k);\n\t}\n};\n\n/** The state keys' signals, named `<name>.<key>`, guarded against writes outside an action. */\nexport const stateSignals = (\n\tname: string,\n\tstate: Record<string, unknown>,\n\tssr: boolean,\n): Record<string, Signal<unknown>> => {\n\tconst sigs: Record<string, Signal<unknown>> = {};\n\tfor (const k in state)\n\t\tsigs[k] = signal(freeze(state[k]), {\n\t\t\tname: `${name}.${k}`,\n\t\t\tssr,\n\t\t\tequals: (a, b) =>\n\t\t\t\twritable()\n\t\t\t\t\t? Object.is(a, b)\n\t\t\t\t\t: refuse(\n\t\t\t\t\t\t\t`Store \"${name}\": \"${k}\" is written outside an action. Write it in an action of the store.`,\n\t\t\t\t\t\t),\n\t\t});\n\treturn sigs;\n};\n\n/** The store's computeds, each reading the state through a read-only view. */\nexport const computeds = (\n\tname: string,\n\tstate: Record<string, unknown>,\n\tderived: Record<string, (s: unknown, get: Getter) => unknown>,\n\tsigs: Record<string, Signal<unknown>>,\n): Record<string, Readable<unknown>> => {\n\tconst comps: Record<string, Readable<unknown>> = {};\n\tfor (const k in derived)\n\t\tcomps[k] = computed(\n\t\t\t(get) =>\n\t\t\t\tderived[k]?.(\n\t\t\t\t\tview(\n\t\t\t\t\t\tstate,\n\t\t\t\t\t\t(key) => get(sigs[key] as Signal<unknown>),\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t\trefuse(`Store \"${name}\": a computed cannot write \"${key}\".`),\n\t\t\t\t\t),\n\t\t\t\t\tget,\n\t\t\t\t),\n\t\t\t{ name: `${name}.${k}` },\n\t\t);\n\treturn comps;\n};\n",
7
+ "import type { RivaClient } from '../client';\nimport type { Readable } from '../computed';\nimport type { Signal } from '../signal';\nimport { freeze, put, type StoreDef } from './def';\nimport type { Action, StoreContext } from './types';\nimport { refuse, view } from './view';\n\n/** What `run` and the writer of `s` share while an action runs. */\ninterface Phase {\n\tlive: boolean;\n\tsync: boolean;\n\theld: boolean;\n\tfailure: { error: unknown } | undefined;\n}\n\n/** The `s` of one run: writes state through the guard, holds the notifications past an `await`. */\nfunction writer(\n\tdef: StoreDef,\n\tclient: RivaClient,\n\tst: Phase,\n\trelease: () => void,\n) {\n\tconst { name, sigs, members } = def;\n\treturn view(\n\t\tmembers,\n\t\t(k) => client.get(members[k] as Readable<unknown>),\n\t\t(k, v) => {\n\t\t\tif (!st.live)\n\t\t\t\trefuse(`Store \"${name}\": \"${k}\" is written after its action settled.`);\n\t\t\tif (!Object.hasOwn(sigs, k))\n\t\t\t\trefuse(\n\t\t\t\t\t`Store \"${name}\": \"${k}\" is not a state key, so it cannot be written.`,\n\t\t\t\t);\n\t\t\t// Past an `await`, the writes of one segment make one notification.\n\t\t\tif (!st.sync && !st.held) {\n\t\t\t\tst.held = true;\n\t\t\t\tclient.graph.depth++;\n\t\t\t\tqueueMicrotask(release);\n\t\t\t}\n\t\t\tput(client, sigs[k] as Signal<unknown>, freeze(v));\n\t\t},\n\t);\n}\n\n/**\n * Runs one action on a client: `(s, ...args, ctx)` inside the client's scope,\n * one batch, untracked. `s` writes state until the action settles, then is\n * revoked (reads keep working). After an `await`, the writes of one\n * synchronous segment make one notification, flushed in a microtask; a\n * listener error from that flush rejects the action's promise.\n */\nexport function run(\n\tdef: StoreDef,\n\tclient: RivaClient,\n\t// biome-ignore lint/suspicious/noExplicitAny: any state and computed shape\n\tfn: Action<any, any>,\n\targs: unknown[],\n): unknown {\n\tconst st: Phase = { live: true, sync: true, held: false, failure: undefined };\n\tconst g = client.graph;\n\tconst release = () => {\n\t\tif (!st.held) return;\n\t\tst.held = false;\n\t\tg.depth--;\n\t\ttry {\n\t\t\tclient.batch(() => {});\n\t\t} catch (error) {\n\t\t\tst.failure ??= { error };\n\t\t}\n\t};\n\tconst s = writer(def, client, st, release);\n\tconst ctx: StoreContext = {\n\t\tclient,\n\t\tfetch: (q, ...a) => (q.ensure as (...x: unknown[]) => never)(client, ...a),\n\t\tmutate: (m, ...a) => (m.run as (...x: unknown[]) => never)(client, ...a),\n\t};\n\t// The context goes after the declared arguments: defaults before it shift it.\n\tconst given = args.slice();\n\tgiven.length = Math.max(args.length, fn.length - 2);\n\tconst settle = () => {\n\t\trelease();\n\t\tst.live = false;\n\t};\n\tlet result: unknown;\n\ttry {\n\t\tresult = client.run(() =>\n\t\t\tclient.batch(() => client.untracked(() => fn(s, ...given, ctx))),\n\t\t);\n\t} catch (e) {\n\t\tsettle();\n\t\tthrow e;\n\t} finally {\n\t\tst.sync = false;\n\t}\n\tif (!(result as PromiseLike<unknown> | undefined)?.then) {\n\t\tsettle();\n\t\treturn result;\n\t}\n\treturn (result as Promise<unknown>).then(\n\t\t(v) => {\n\t\t\tsettle();\n\t\t\tif (st.failure) throw st.failure.error;\n\t\t\treturn v;\n\t\t},\n\t\t(e) => {\n\t\t\tsettle();\n\t\t\tthrow e;\n\t\t},\n\t);\n}\n",
8
+ "import type { RivaClient } from '../client';\nimport type { Readable } from '../computed';\nimport { freeze, inBrowser, type StoreDef } from './def';\nimport { run } from './run';\nimport { refuse, view } from './view';\n\nexport type Instance = readonly [\n\tRecord<string, unknown>,\n\tRecord<string, (...args: unknown[]) => unknown>,\n];\n\n/**\n * The store on one client, made on first use and kept in `client.slots`: a\n * read-only view of its state and computeds, and its bound actions. It also\n * claims the store's name on the client: a second store with that name is\n * refused on the server, and takes over in a browser (a hot-reloaded module).\n */\nexport function instance(def: StoreDef, client: RivaClient): Instance {\n\tconst cached = client.slots.get(def) as Instance | undefined;\n\tif (cached) return cached;\n\tconst { name, sigs, members, actions } = def;\n\tconst claim = `name:${name}`;\n\tconst holder = client.slots.get(claim) as StoreDef | undefined;\n\tif (holder !== undefined) {\n\t\tif (!inBrowser())\n\t\t\trefuse(\n\t\t\t\t`Store \"${name}\": two stores are named \"${name}\" on this client: give each store a unique name.`,\n\t\t\t);\n\t\tclient.slots.delete(holder);\n\t\tfor (const sig of Object.values(holder.sigs))\n\t\t\tif (sig.name) client.graph.named.delete(sig.name);\n\t}\n\tclient.slots.set(claim, def);\n\t// A hydrated value is not frozen when it is decoded: freeze it here (dev only).\n\tconst seeds = client.graph.seeds;\n\tif (seeds)\n\t\tfor (const k in sigs) {\n\t\t\tconst sig = sigs[k];\n\t\t\tif (sig?.name !== undefined && seeds.has(sig.name))\n\t\t\t\tclient.untracked(() => freeze(client.get(sig)));\n\t\t}\n\tconst bound: Record<string, (...args: unknown[]) => unknown> = {};\n\tfor (const k in actions)\n\t\tbound[k] = (...args) => run(def, client, actions[k] as never, args);\n\tconst made: Instance = [\n\t\tview(\n\t\t\tmembers,\n\t\t\t(k) => client.get(members[k] as Readable<unknown>),\n\t\t\t(k) =>\n\t\t\t\trefuse(\n\t\t\t\t\t`Store \"${name}\": \"${k}\" is read-only here; write it in an action.`,\n\t\t\t\t),\n\t\t),\n\t\tbound,\n\t];\n\tclient.slots.set(def, made);\n\treturn made;\n}\n",
9
+ "import type { RivaClient } from '../client';\nimport type { Getter } from '../computed';\nimport { resolve } from '../scope';\nimport type { Signal } from '../signal';\nimport { checkKeys, computeds, put, type StoreDef, stateSignals } from './def';\nimport { instance } from './instance';\nimport type { Action, Reserved, Store, StoreOptions } from './types';\n\n/**\n * A domain store: its state, computeds and actions in one definition. Every\n * state key is a signal named `<name>.<key>` and every computed a riva\n * computed, both read as definitions; only actions write.\n */\nexport function store<\n\tconst N extends string,\n\tS extends Record<string, unknown>,\n\tC = Record<never, never>,\n\tA = Record<never, never>,\n>(\n\toptions: StoreOptions<S, C, A> & { name: N } & Reserved<S, C, A>,\n): Store<N, S, C, A> {\n\tconst { name, ssr = false } = options;\n\tconst state = options.state as Record<string, unknown>;\n\tconst derived = (options.computed ?? {}) as Record<\n\t\tstring,\n\t\t(s: unknown, get: Getter) => unknown\n\t>;\n\t// biome-ignore lint/suspicious/noExplicitAny: any state and computed shape\n\tconst actions = (options.actions ?? {}) as Record<string, Action<any, any>>;\n\tcheckKeys(name, [\n\t\t...Object.keys(state),\n\t\t...Object.keys(derived),\n\t\t...Object.keys(actions),\n\t]);\n\tconst sigs = stateSignals(name, state, ssr);\n\tconst comps = computeds(name, state, derived, sigs);\n\tconst members = { ...sigs, ...comps };\n\tconst data: StoreDef = { name, sigs, members, actions };\n\n\tconst ambient: Record<string, (...args: unknown[]) => unknown> = {};\n\tfor (const k in actions)\n\t\tambient[k] = (...args) =>\n\t\t\t(instance(data, resolve())[1][k] as (...a: unknown[]) => unknown)(\n\t\t\t\t...args,\n\t\t\t);\n\n\treturn Object.freeze({\n\t\tkind: 'store',\n\t\tname,\n\t\treset: (client: RivaClient = resolve()) => {\n\t\t\tinstance(data, client);\n\t\t\tclient.batch(() => {\n\t\t\t\tfor (const k in sigs) {\n\t\t\t\t\tconst sig = sigs[k] as Signal<unknown>;\n\t\t\t\t\tput(client, sig, sig.initial);\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t\tbind: (client: RivaClient) => instance(data, client),\n\t\t...ambient,\n\t\t...members,\n\t}) as unknown as Store<N, S, C, A>;\n}\n"
10
+ ],
11
+ "mappings": ";;;;;;;;;;;;AAGO,IAAM,SAAS,CAAC,YAA2B;AAAA,EACjD,MAAM,IAAI,WAAU,cAAc,OAAO;AAAA;AASnC,IAAM,OAAO,CACnB,MACA,MACA,UAEA,IAAI,MACH,CAAC,GACD;AAAA,EACC,KAAK,CAAC,GAAG,MACR,OAAO,MAAM,YAAY,OAAO,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI;AAAA,EAC7D,KAAK,CAAC,GAAG,GAAG,MAAM;AAAA,IACjB,MAAM,GAAa,CAAC;AAAA,IACpB,OAAO;AAAA;AAET,CACD;;;ACTM,IAAM,WAAW,CAAC,QAAQ,QAAQ,SAAS,QAAQ,MAAM;AAGhE,IAAI,MAAM;AACV,IAAI;AAAA,EACH,MAAM;AAAA,EACL,MAAM;AAGD,IAAM,SAAS,CAAI,MAAY;AAAA,EAC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M,SAAS,QAAQ;AAAA,EAEtD,MAAM,UAA2D,CAAC;AAAA,EAClE,WAAW,KAAK;AAAA,IACf,QAAQ,KAAK,IAAI,SACf,SAAS,MAAM,QAAQ,CAAC,EAAE,GAAG,GAC7B,GAAG,IACJ;AAAA,EAEF,OAAO,OAAO,OAAO;AAAA,IACpB,MAAM;AAAA,IACN;AAAA,IACA,OAAO,CAAC,SAAqB,QAAQ,MAAM;AAAA,MAC1C,SAAS,MAAM,MAAM;AAAA,MACrB,OAAO,MAAM,MAAM;AAAA,QAClB,WAAW,KAAK,MAAM;AAAA,UACrB,MAAM,MAAM,KAAK;AAAA,UACjB,IAAI,QAAQ,KAAK,IAAI,OAAO;AAAA,QAC7B;AAAA,OACA;AAAA;AAAA,IAEF,MAAM,CAAC,WAAuB,SAAS,MAAM,MAAM;AAAA,OAChD;AAAA,OACA;AAAA,EACJ,CAAC;AAAA;",
12
+ "debugId": "BC5EA30508CF2C0D64756E2164756E21",
13
+ "names": []
14
+ }
@@ -0,0 +1,14 @@
1
+ import type { RivaClient } from '../client';
2
+ import { type StoreDef } from './def';
3
+ export type Instance = readonly [
4
+ Record<string, unknown>,
5
+ Record<string, (...args: unknown[]) => unknown>
6
+ ];
7
+ /**
8
+ * The store on one client, made on first use and kept in `client.slots`: a
9
+ * read-only view of its state and computeds, and its bound actions. It also
10
+ * claims the store's name on the client: a second store with that name is
11
+ * refused on the server, and takes over in a browser (a hot-reloaded module).
12
+ */
13
+ export declare function instance(def: StoreDef, client: RivaClient): Instance;
14
+ //# sourceMappingURL=instance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../../src/store/instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAqB,KAAK,QAAQ,EAAE,MAAM,OAAO,CAAC;AAIzD,MAAM,MAAM,QAAQ,GAAG,SAAS;IAC/B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACvB,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;CAC/C,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,GAAG,QAAQ,CAwCpE"}
@@ -0,0 +1,12 @@
1
+ import type { RivaClient } from '../client';
2
+ import { type StoreDef } from './def';
3
+ import type { Action } from './types';
4
+ /**
5
+ * Runs one action on a client: `(s, ...args, ctx)` inside the client's scope,
6
+ * one batch, untracked. `s` writes state until the action settles, then is
7
+ * revoked (reads keep working). After an `await`, the writes of one
8
+ * synchronous segment make one notification, flushed in a microtask; a
9
+ * listener error from that flush rejects the action's promise.
10
+ */
11
+ export declare function run(def: StoreDef, client: RivaClient, fn: Action<any, any>, args: unknown[]): unknown;
12
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/store/run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAG5C,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAgB,MAAM,SAAS,CAAC;AAwCpD;;;;;;GAMG;AACH,wBAAgB,GAAG,CAClB,GAAG,EAAE,QAAQ,EACb,MAAM,EAAE,UAAU,EAElB,EAAE,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EACpB,IAAI,EAAE,OAAO,EAAE,GACb,OAAO,CAoDT"}
@@ -0,0 +1,10 @@
1
+ import type { Reserved, Store, StoreOptions } from './types';
2
+ /**
3
+ * A domain store: its state, computeds and actions in one definition. Every
4
+ * state key is a signal named `<name>.<key>` and every computed a riva
5
+ * computed, both read as definitions; only actions write.
6
+ */
7
+ export declare function store<const N extends string, S extends Record<string, unknown>, C = Record<never, never>, A = Record<never, never>>(options: StoreOptions<S, C, A> & {
8
+ name: N;
9
+ } & Reserved<S, C, A>): Store<N, S, C, A>;
10
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAU,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAErE;;;;GAIG;AACH,wBAAgB,KAAK,CACpB,KAAK,CAAC,CAAC,SAAS,MAAM,EACtB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EACxB,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAExB,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAC9D,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CA0CnB"}
@@ -0,0 +1,70 @@
1
+ import type { RivaClient } from '../client';
2
+ import type { Computed, Getter, ReadonlySignal } from '../computed';
3
+ import type { Mutation, RunOptions } from '../mutation';
4
+ import type { EnsureOptions, Query, VarsArgs } from '../query';
5
+ /** What an action, a computed or a component reads: the keys of `S`, read-only. */
6
+ export type View<S> = {
7
+ readonly [K in keyof S]: S[K];
8
+ };
9
+ /** The last argument every action gets: its client, and the engine bound to it. */
10
+ export interface StoreContext {
11
+ readonly client: RivaClient;
12
+ /** Fetches when missing or stale and awaits (`query.ensure(client, …)`). */
13
+ fetch<Vars, Data>(query: Query<Vars, Data, any>, ...args: VarsArgs<Vars, [opts?: EnsureOptions]>): Promise<Data>;
14
+ /** Runs a mutation (`mutation.run(client, …)`). */
15
+ mutate<Vars, Data>(mutation: Mutation<Vars, Data>, ...args: VarsArgs<Vars, [opts?: RunOptions]>): Promise<Data>;
16
+ }
17
+ /** The leading required elements of a tuple. */
18
+ type Required_<P extends unknown[]> = P extends [infer F, ...infer R] ? [F, ...Required_<R>] : [];
19
+ /** Whether the last parameter is a real `StoreContext` (optional or not), never an `any`. */
20
+ type EndsWithContext<P extends unknown[]> = Required<P> extends [...unknown[], infer L] ? 0 extends 1 & L ? false : [Exclude<L, undefined>] extends [StoreContext] ? true : false : false;
21
+ /** The arguments a caller passes: an action's own, without its trailing `StoreContext`. */
22
+ export type Args<P extends unknown[]> = EndsWithContext<P> extends true ? Required<P> extends [...infer H, unknown] ? H extends [...Required_<P>, ...infer Rest] ? [...Required_<P>, ...Partial<Rest>] : H : P : P;
23
+ /** An action whose last parameter is optional or defaulted, with no context after it. */
24
+ type NeedsContext<P extends unknown[]> = P extends [] ? false : EndsWithContext<P> extends true ? false : number extends P['length'] ? true : P extends Required<P> ? false : true;
25
+ /** What the author sees where an action ends with an optional or defaulted parameter. */
26
+ export interface AddContextLast {
27
+ readonly error: 'Add "ctx?: StoreContext" as the last parameter: an action whose last parameter is optional or defaulted must declare it, or the context lands in that parameter.';
28
+ }
29
+ /** The actions as callers see them: `(s, ...args, ctx)` becomes `(...args)`. */
30
+ export type Bound<A> = {
31
+ readonly [K in keyof A]: A[K] extends (s: any, ...a: infer P) => infer R ? NeedsContext<P> extends true ? AddContextLast : (...args: Args<P>) => R : never;
32
+ };
33
+ /** The keys a store cannot use: its own members, and `then`. */
34
+ export type ReservedKey = 'kind' | 'name' | 'reset' | 'bind' | 'then';
35
+ /** Unsatisfiable when a state, computed or action key is reserved, so the definition fails to type. */
36
+ export type Reserved<S, C, A> = [
37
+ Extract<keyof S | keyof C | keyof A, ReservedKey>
38
+ ] extends [never] ? unknown : {
39
+ readonly 'a state, computed or action key is reserved (kind, name, reset, bind, then): rename it': never;
40
+ };
41
+ /** An action: `(s, ...args, ctx)`; annotate the trailing `ctx: StoreContext`. */
42
+ export type Action<S, C> = (s: S & Readonly<C>, ...args: any[]) => unknown;
43
+ export interface StoreOptions<S, C, A> {
44
+ /** Required and unique per client: it prefixes each state key's signal name. */
45
+ name: string;
46
+ /** Every state key travels in an SSR snapshot. Default false. */
47
+ ssr?: boolean;
48
+ state: S;
49
+ /** Derived values: `(s, get) => value`, `s` being the state only. */
50
+ computed?: {
51
+ [K in keyof C]: (s: View<S>, get: Getter) => C[K];
52
+ };
53
+ /** The only writers: `(s, ...args, { client, fetch, mutate })`. */
54
+ actions?: A & Record<string, Action<S, C>>;
55
+ }
56
+ /** A domain store: stateless definitions, their values live per `RivaClient`. */
57
+ export type Store<N extends string, S, C, A> = {
58
+ readonly kind: 'store';
59
+ readonly name: N;
60
+ /** Puts every state key back to its initial value (the ambient client, or the one given). */
61
+ reset(client?: RivaClient): void;
62
+ /** The store on one client: a read-only view of state and computeds, and the actions. */
63
+ bind(client: RivaClient): readonly [View<S & C>, Bound<A>];
64
+ } & {
65
+ readonly [K in keyof S]: ReadonlySignal<S[K]>;
66
+ } & {
67
+ readonly [K in keyof C]: Computed<C[K]>;
68
+ } & Bound<A>;
69
+ export {};
70
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/store/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE/D,mFAAmF;AACnF,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,C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CAAC,CAAC,CAAC,CAAC,CAAC;CAC3D,GAAG;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG;IACvD,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACvC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /** Throws the error every store refusal uses. */
2
+ export declare const refuse: (message: string) => never;
3
+ /**
4
+ * The one Proxy behind every store view: an action's `s` (read, guarded
5
+ * write), a computed's `s` (tracked read, no write) and a component's (reads
6
+ * recorded, no write). An unknown key reads `undefined`, so a symbol probe
7
+ * (`then`, a devtools hook) is harmless; writes decide for themselves.
8
+ */
9
+ export declare const view: (keys: object, read: (key: string) => unknown, write: (key: string, value: unknown) => void) => Record<string, unknown>;
10
+ //# sourceMappingURL=view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/store/view.ts"],"names":[],"mappings":"AAEA,iDAAiD;AACjD,eAAO,MAAM,MAAM,YAAa,MAAM,KAAG,KAExC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,IAAI,SACV,MAAM,QACN,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,SACvB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,KAC1C,MAAM,CAAC,MAAM,EAAE,OAAO,CAWvB,CAAC"}
package/docs/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @softistx/riva docs
2
+
3
+ ## Guides
4
+
5
+ - [Signals](./guide/signals.md): read when you need local state, computeds, effects, batching or ambient reads.
6
+ - [Queries](./guide/queries.md): read when you fetch and cache server data: options, staleness, retry, abort, keys.
7
+ - [Mutations](./guide/mutations.md): read when you write: optimistic updates, rollback, ordering, invalidation.
8
+ - [Entities](./guide/entities.md): read when queries share objects: the normalized cache, `writeEntity`, codecs.
9
+ - [Infinite lists](./guide/infinite.md): read for cursor pagination and infinite scroll.
10
+ - [Stores](./guide/store.md): read to group a domain's state, computeds and actions.
11
+ - [Server rendering](./guide/ssr.md): read for dehydrate, hydrate and the ambient scope on a server.
12
+ - [Data route client](./guide/data.md): read to write a transport that posts to a `/_data` route.
13
+ - [Errors](./guide/errors.md): read to catch riva's errors by class and code.
14
+
15
+ ## Reference
16
+
17
+ - [Troubleshooting](./troubleshooting.md): every error riva throws, by its message, with the fix.
18
+ - [Package README](../README.md): install and one example per area.
19
+ - [Spec](https://github.com/softistx/riva/blob/develop/docs/spec.md): the decision record.
@@ -0,0 +1,36 @@
1
+ # The data route client: `@softistx/riva/data`
2
+
3
+ The browser's side of a `/_data` route, shared by the adapters' `bffTransport` (`@softistx/riva-graphql/bff`, `@softistx/riva-rest/bff`). Import it only to write a transport of your own.
4
+
5
+ ```ts
6
+ import { type BffTransportOptions, postData } from '@softistx/riva/data';
7
+
8
+ const options: BffTransportOptions = { url: '/_data', headers: () => ({ 'x-csrf': token() }) };
9
+ const data = await postData(options, 'rest:getInvoice', { param: { id: '7' } }, signal);
10
+ ```
11
+
12
+ ## `postData(opts, id, variables, signal?)`
13
+
14
+ Posts `{ id, variables }` (variables in the SSR codec, so Dates travel) with same-origin cookies, and returns the decoded `{ data }`.
15
+
16
+ | `opts` field | Default | Effect |
17
+ | --- | --- | --- |
18
+ | `url` | `'/_data'` | The `dataRoute` URL. |
19
+ | `fetch` | the global `fetch`, read at each call | A fetch of your own. |
20
+ | `headers` | none | A function returning `HeadersInit`, called at each request (a CSRF token). |
21
+
22
+ ## Errors
23
+
24
+ | Case | Thrown |
25
+ | --- | --- |
26
+ | The route's `{ error: { code, message, status } }` | `RivaRequestError` with that `code` and `status`, retryable for 5xx, 408 and 429 |
27
+ | An error status with no such body | `RivaHttpError` |
28
+ | A failed fetch | `RivaNetworkError` |
29
+ | An abort | `RivaAbortError` |
30
+ | A body that is not the route's JSON | `RivaRequestError` `RIVA_INVALID_RESPONSE` |
31
+
32
+ ## Writing a transport
33
+
34
+ A transport for `provideGraphQL` or `provideRest` that posts to the route calls `postData(opts, operationId, variables, signal)` and returns the result. The server half is `dataRoute` from `@softistx/riva-react-router/server`.
35
+
36
+ Exports: `postData` and the type `BffTransportOptions`.
@@ -0,0 +1,90 @@
1
+ # The normalized cache: `@softistx/riva/entities`
2
+
3
+ By default a query keeps its data as is, keyed by id and variables. Pass `cache: entities()` to store each entity (an object with a string `__typename` and an `id` or `_id`) once, shared by every query that returns it. A refetch of one query then updates the others, and a `client.get` inside a computed re-evaluates only when an entity it read changed.
4
+
5
+ ```ts
6
+ import { createRivaClient, query } from '@softistx/riva';
7
+ import { entities, evict, invalidateEntity, readEntity, writeEntity } from '@softistx/riva/entities';
8
+
9
+ type Patient = { __typename: 'Patient'; id: string; name: string };
10
+
11
+ const cache = entities({
12
+ keys: { Book: (b) => b['isbn'] as string }, // identity of a type (default: id, then _id)
13
+ // identify: (obj) => 'Type:id' | undefined, // or replace the identity rule
14
+ });
15
+
16
+ const patients = query({
17
+ id: 'patients',
18
+ cache,
19
+ fetch: async () => (await fetch('/api/patients')).json() as Promise<{ items: Patient[] }>,
20
+ });
21
+ const patient = query({
22
+ id: 'patient',
23
+ cache,
24
+ fetch: async (v: { id: string }) => (await fetch(`/api/patients/${v.id}`)).json() as Promise<Patient>,
25
+ });
26
+
27
+ const client = createRivaClient();
28
+ await patients.ensure(client);
29
+ await patient.ensure(client, { id: '1' });
30
+
31
+ writeEntity(client, 'Patient:1', { name: 'Ann' }); // merged; both queries see it
32
+ writeEntity(client, 'Patient:1', (prev) => ({ visits: (prev?.['visits'] as number) + 1 }));
33
+ readEntity(client, 'Patient:1'); // tracked inside a computed; undefined when missing
34
+ invalidateEntity(client, 'Patient:1'); // marks stale every query reaching it, refetches observed ones
35
+ evict(client, 'Patient:1'); // removes it: queries see the field as missing
36
+ ```
37
+
38
+ ## Options of `entities(opts?, codec?)`
39
+
40
+ | Option | Default | Effect |
41
+ | --- | --- | --- |
42
+ | `keys` | `id`, then `_id` | `{ Type: (obj) => string }`: the identity of a type. |
43
+ | `identify` | the rule above | `(obj) => 'Type:id' \| undefined`: replaces the identity rule altogether. |
44
+ | `codec` (2nd argument) | the plain walker | An `EntityCodec` (see below). |
45
+
46
+ ## What is stored
47
+
48
+ - Entities are merged field by field into one store per client (two clients never share). Nested entities, and entities inside arrays, are normalized too; other objects stay inline. An entity unchanged since the last read keeps its identity.
49
+ - A query entry holds the entities it reaches. When the entry is replaced or collected (`gcTime`) they are released, and an entity nobody holds is removed. Entities that reference each other are collected too; a cycle is cut where it loops back when read.
50
+ - A ref to a missing entity reads as `undefined`, never throws.
51
+ - Data that is not JSON (a function, a class instance other than `Date`, a bigint, a cycle) throws `RIVA_CACHE`; nothing is written.
52
+ - A plain read skips fields stored under a key holding `(`, the argument fields a selection-aware codec writes.
53
+ - The plain walker stores every field of an object. A GraphQL selection-aware one (arguments, aliases, fragments) is `normalized()` from `@softistx/riva-graphql/cache`, built on the codec below.
54
+
55
+ ## A miss is refetched, or an error
56
+
57
+ When an observed entry's stored data stops reading (`read` returns `undefined`, for example an evicted entity), the engine refetches it, and `ensure` fetches too rather than resolve nothing. When a fetch's own result cannot be read back, the entry ends in the error status with code `RIVA_CACHE` and `ensure` rejects with it; nothing loops, and the error clears once the data reads again. Optimistic layers and `derive` never trigger it. A refused `setData` throws `RIVA_CACHE` and leaves the entry untouched.
58
+
59
+ ## A codec of your own
60
+
61
+ `entities(opts, codec)` takes an `EntityCodec` that decides how data becomes entities and back, for data whose shape a plain walk cannot know:
62
+
63
+ ```ts
64
+ import { entities, type EntityCodec } from '@softistx/riva/entities';
65
+
66
+ const codec: EntityCodec = {
67
+ // `reader.identify(obj)` gives `Type:id`; nothing is merged until `pending` is returned whole.
68
+ normalize: (reader, data, vars) => ({
69
+ root: { vars, data }, // what the entry keeps
70
+ pending: new Map([['Patient:1', { name: 'Ada' }]]), // fields to merge, by entity
71
+ }),
72
+ // Runs in a computed: read entities through `reader.fields`, so the read is tracked.
73
+ denormalize: (reader, root) => ({ name: reader.fields('Patient:1')?.['name'] }),
74
+ };
75
+
76
+ const cache = entities(undefined, codec);
77
+ ```
78
+
79
+ `EntityReader` is what a codec sees of the store: `identify`, `peek` (committed, untracked) and `fields` (tracked, layers applied). Return `undefined` from `denormalize` for a miss: the engine then refetches.
80
+
81
+ ## The `CachePolicy` hook
82
+
83
+ `CachePolicy`, exported from the main entry, is the hook behind it: `write(client, data, prev, vars)`, `read(client, stored, committed)`, `release(client, stored)`, and for mutations the optional `layer(client, data, vars)` (an optimistic layer, `{ drop() }`) and `commit(client, data, vars)`. `vars` are the variables of the query or mutation that gave `data`.
84
+
85
+ ## Traps
86
+
87
+ - The store follows the identity rules (`keys`, `identify`) of the first policy used on a client. A later policy with other rules, or with rules after `readEntity` or `writeEntity` filled the store, throws `RIVA_CACHE`. Share one `entities()` (or the same options objects) between a client's queries.
88
+ - Entity refs are `Type:id` strings: `Patient:1`.
89
+
90
+ Exports: `entities`, `readEntity`, `writeEntity`, `invalidateEntity`, `evict`, `identifyOf`, `isPlain`, `isRef`; types `EntityPolicy`, `EntitiesOptions`, `Identify`, `Fields`, `EntityCodec`, `EntityReader`, `Normalized`, `Ref`.
@@ -0,0 +1,31 @@
1
+ # Errors
2
+
3
+ Every error riva throws is defined once here, so `instanceof` holds across packages. The adapters throw these classes; they never define their own. Keep one copy of `@softistx/riva` in the tree.
4
+
5
+ ```ts
6
+ import { RivaError, RivaHttpError, RivaRequestError } from '@softistx/riva';
7
+
8
+ const state = client.get(user, { id: '1' });
9
+ if (state.error instanceof RivaHttpError && state.error.status === 404) {
10
+ // not found
11
+ } else if (state.error instanceof RivaRequestError && state.error.retryable) {
12
+ // a retry may help
13
+ } else if (state.error instanceof RivaError) {
14
+ console.log(state.error.code);
15
+ }
16
+ ```
17
+
18
+ | Class | `code` | Notes |
19
+ | --- | --- | --- |
20
+ | `RivaError` | any | Base class; has `code`. |
21
+ | `RivaScopeError` | `RIVA_SCOPE` | A read with no client in scope. |
22
+ | `RivaRequestError` | any | `status?`, `retryable`, `cause`. A failed request. |
23
+ | `RivaHttpError(status)` | `HTTP_<status>` | Retryable for 5xx, 408 and 429. |
24
+ | `RivaNetworkError` | `RIVA_NETWORK` | Retryable. |
25
+ | `RivaAbortError` | `RIVA_ABORT` | Never retried. |
26
+
27
+ Other codes thrown as `RivaError`: `RIVA_CYCLE`, `RIVA_LOOP`, `RIVA_DURATION`, `RIVA_KEY`, `RIVA_CACHE`, `RIVA_STORE`, `RIVA_SSR`. `RIVA_INVALID_RESPONSE` and `RIVA_UNKNOWN` are carried by `RivaRequestError` (a transport answer that is not valid) and by an SSR snapshot (an error that was not a `RivaError`). The adapters add `RIVA_DEFINITION` (a misused definition), `RIVA_VALIDATION`, `RIVA_REST_UNWIRED` and `RIVA_DATA_*`. Each has an entry by its message in [troubleshooting](../troubleshooting.md).
28
+
29
+ Listeners and effects that throw never stop the others: every notification runs, then the single error is rethrown as is, and several become an `AggregateError`.
30
+
31
+ Errors travel in an SSR snapshot as codes, with an empty message (see [ssr](./ssr.md)).