@nisli/core 0.56.0 → 0.57.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 +38 -6
- package/dist/bundler/component.js +409 -0
- package/dist/bundler/component.js.map +7 -0
- package/dist/bundler/context.js +27 -0
- package/dist/bundler/context.js.map +7 -0
- package/dist/bundler/diagnostics.js +55 -0
- package/dist/bundler/diagnostics.js.map +7 -0
- package/dist/bundler/disposable.js +9 -0
- package/dist/bundler/disposable.js.map +7 -0
- package/dist/bundler/element-context.js +47 -0
- package/dist/bundler/element-context.js.map +7 -0
- package/dist/bundler/emitter.js +70 -0
- package/dist/bundler/emitter.js.map +7 -0
- package/dist/bundler/hmr/registry.js +72 -0
- package/dist/bundler/hmr/registry.js.map +7 -0
- package/dist/bundler/hmr/transform.js +30 -0
- package/dist/bundler/hmr/transform.js.map +7 -0
- package/dist/bundler/index.js +103 -0
- package/dist/bundler/index.js.map +7 -0
- package/dist/bundler/injector.js +75 -0
- package/dist/bundler/injector.js.map +7 -0
- package/dist/bundler/lifecycle.js +56 -0
- package/dist/bundler/lifecycle.js.map +7 -0
- package/dist/bundler/projection.js +92 -0
- package/dist/bundler/projection.js.map +7 -0
- package/dist/bundler/query.js +302 -0
- package/dist/bundler/query.js.map +7 -0
- package/dist/bundler/ref.js +16 -0
- package/dist/bundler/ref.js.map +7 -0
- package/dist/bundler/resource.js +99 -0
- package/dist/bundler/resource.js.map +7 -0
- package/dist/bundler/settle.js +43 -0
- package/dist/bundler/settle.js.map +7 -0
- package/dist/bundler/signal.js +403 -0
- package/dist/bundler/signal.js.map +7 -0
- package/dist/bundler/template-audit.js +162 -0
- package/dist/bundler/template-audit.js.map +7 -0
- package/dist/bundler/template.js +847 -0
- package/dist/bundler/template.js.map +7 -0
- package/dist/bundler/view-transition.js +20 -0
- package/dist/bundler/view-transition.js.map +7 -0
- package/dist/bundler/vite-hmr/plugin.js +32 -0
- package/dist/bundler/vite-hmr/plugin.js.map +7 -0
- package/dist/bundler/vite-hmr/runtime.js +8 -0
- package/dist/bundler/vite-hmr/runtime.js.map +7 -0
- package/dist/index.js +2607 -47
- package/dist/index.js.map +7 -1
- package/dist/index.production.js +2 -0
- package/dist/index.production.js.map +6 -0
- package/dist/{diagnostics.d.ts → types/diagnostics.d.ts} +8 -15
- package/dist/{template-audit.d.ts → types/template-audit.d.ts} +4 -5
- package/package.json +12 -9
- package/dist/component.js +0 -633
- package/dist/component.js.map +0 -1
- package/dist/context.js +0 -55
- package/dist/context.js.map +0 -1
- package/dist/diagnostics.js +0 -118
- package/dist/diagnostics.js.map +0 -1
- package/dist/disposable.js +0 -8
- package/dist/disposable.js.map +0 -1
- package/dist/element-context.js +0 -108
- package/dist/element-context.js.map +0 -1
- package/dist/emitter.js +0 -91
- package/dist/emitter.js.map +0 -1
- package/dist/hmr/registry.js +0 -136
- package/dist/hmr/registry.js.map +0 -1
- package/dist/hmr/transform.js +0 -52
- package/dist/hmr/transform.js.map +0 -1
- package/dist/injector.js +0 -118
- package/dist/injector.js.map +0 -1
- package/dist/lifecycle.js +0 -117
- package/dist/lifecycle.js.map +0 -1
- package/dist/projection.js +0 -179
- package/dist/projection.js.map +0 -1
- package/dist/query.js +0 -429
- package/dist/query.js.map +0 -1
- package/dist/ref.js +0 -43
- package/dist/ref.js.map +0 -1
- package/dist/resource.js +0 -129
- package/dist/resource.js.map +0 -1
- package/dist/settle.js +0 -106
- package/dist/settle.js.map +0 -1
- package/dist/signal.js +0 -645
- package/dist/signal.js.map +0 -1
- package/dist/template-audit.js +0 -246
- package/dist/template-audit.js.map +0 -1
- package/dist/template.js +0 -1244
- package/dist/template.js.map +0 -1
- package/dist/view-transition.js +0 -98
- package/dist/view-transition.js.map +0 -1
- package/dist/vite-hmr/plugin.js +0 -62
- package/dist/vite-hmr/plugin.js.map +0 -1
- package/dist/vite-hmr/runtime.js +0 -17
- package/dist/vite-hmr/runtime.js.map +0 -1
- /package/dist/{component.d.ts → types/component.d.ts} +0 -0
- /package/dist/{context.d.ts → types/context.d.ts} +0 -0
- /package/dist/{disposable.d.ts → types/disposable.d.ts} +0 -0
- /package/dist/{element-context.d.ts → types/element-context.d.ts} +0 -0
- /package/dist/{emitter.d.ts → types/emitter.d.ts} +0 -0
- /package/dist/{hmr → types/hmr}/registry.d.ts +0 -0
- /package/dist/{hmr → types/hmr}/transform.d.ts +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{injector.d.ts → types/injector.d.ts} +0 -0
- /package/dist/{lifecycle.d.ts → types/lifecycle.d.ts} +0 -0
- /package/dist/{projection.d.ts → types/projection.d.ts} +0 -0
- /package/dist/{query.d.ts → types/query.d.ts} +0 -0
- /package/dist/{ref.d.ts → types/ref.d.ts} +0 -0
- /package/dist/{resource.d.ts → types/resource.d.ts} +0 -0
- /package/dist/{settle.d.ts → types/settle.d.ts} +0 -0
- /package/dist/{signal.d.ts → types/signal.d.ts} +0 -0
- /package/dist/{template.d.ts → types/template.d.ts} +0 -0
- /package/dist/{view-transition.d.ts → types/view-transition.d.ts} +0 -0
- /package/dist/{vite-hmr → types/vite-hmr}/plugin.d.ts +0 -0
- /package/dist/{vite-hmr → types/vite-hmr}/runtime.d.ts +0 -0
package/dist/query.js
DELETED
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* query.ts — Keyed logical-request store (ADR 0030.2 T1).
|
|
3
|
-
*
|
|
4
|
-
* The cache unit is a per-key RECORD living in `QueryClient`:
|
|
5
|
-
* `{data, error, status, fetchedAt}` as signals, plus exactly one `run()`
|
|
6
|
-
* owning the retry loop, a per-run `AbortController` handed to the fetcher,
|
|
7
|
-
* and the cache commit. `query()` is a thin OBSERVER: an effect keeps it
|
|
8
|
-
* registered on the record its current key points at, and its outputs are
|
|
9
|
-
* `computed()` views over that record. Dedup unit = logical request, by
|
|
10
|
-
* construction (issues 0005–0009 close as a class).
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* const tasks = query(
|
|
14
|
-
* () => ['tasks', scopeId.value],
|
|
15
|
-
* (signal) => api.getTasks(scopeId.value, { signal }),
|
|
16
|
-
* );
|
|
17
|
-
* tasks.data // ReadonlySignal<Task[] | undefined>
|
|
18
|
-
* tasks.loading // ReadonlySignal<boolean>
|
|
19
|
-
* tasks.error // ReadonlySignal<Error | null>
|
|
20
|
-
* tasks.status // ReadonlySignal<'idle' | 'loading' | 'success' | 'error'>
|
|
21
|
-
* tasks.refetch() // force a refetch (joins an in-flight run)
|
|
22
|
-
* tasks.dispose() // standalone callers; component setup auto-disposes
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* Ownership rules (ADR 0030.2 §8, binding):
|
|
26
|
-
* - The most-recently-mounted enabled observer's fetcher/options own the
|
|
27
|
-
* next run for a shared key; `staleTime` freshness is per-observer POLICY
|
|
28
|
-
* (it decides whether *that* observer triggers a run), while the record
|
|
29
|
-
* state is shared truth.
|
|
30
|
-
* - `invalidate()` marks records stale and reruns only records with ≥1
|
|
31
|
-
* enabled observer; disabled observers revalidate on re-enable.
|
|
32
|
-
* - A zero-observer record's in-flight run completes and commits.
|
|
33
|
-
* - Records are NEVER garbage-collected: the cache is unbounded for the
|
|
34
|
-
* life of the client (restates today's unbounded-cache bound). Bound it
|
|
35
|
-
* operationally with `clear()` or a fresh client per app lifetime.
|
|
36
|
-
*
|
|
37
|
-
* Key contract: keys are FLAT — `readonly (string|number|boolean|null)[]`.
|
|
38
|
-
* Objects and `undefined` are rejected with coded error N602 (`null` is
|
|
39
|
-
* the optional sentinel). Flat keys are order-sensitive: prefer
|
|
40
|
-
* per-endpoint key-builder helpers — a reordered key is a silent cache
|
|
41
|
-
* *miss*, benign relative to a collision, but a miss.
|
|
42
|
-
*
|
|
43
|
-
* SSG stance (documented, not built): under core-render, records fetch
|
|
44
|
-
* into the build-lifetime client and must TERMINATE before snapshot —
|
|
45
|
-
* `await settle()` is the barrier. Otherwise queries must be statically
|
|
46
|
-
* disabled for the build.
|
|
47
|
-
*/
|
|
48
|
-
import { signal, effect, computed, untrack, } from './signal.js';
|
|
49
|
-
import { hasContext, getCurrentComponent } from './context.js';
|
|
50
|
-
import { disposable } from './disposable.js';
|
|
51
|
-
import { inject } from './injector.js';
|
|
52
|
-
import { __enrollPending } from './settle.js';
|
|
53
|
-
import { formatDiag } from './diagnostics.js';
|
|
54
|
-
// Diagnostics go through the core leaf (diagnostics.ts). Codes N602–N603
|
|
55
|
-
// belong to the query/async cluster (N601 retired before release — see
|
|
56
|
-
// the eliminated-class note below).
|
|
57
|
-
/** Build the coded error for key-contract violations. Always thrown —
|
|
58
|
-
* key validity is a contract, not an advisory diagnostic. */
|
|
59
|
-
function keyError(detail) {
|
|
60
|
-
return new Error(formatDiag('N602', `invalid query key: ${detail}. Keys must be flat `
|
|
61
|
-
+ 'readonly (string | number | boolean | null)[] arrays — spread '
|
|
62
|
-
+ 'object params into tuple elements; null is the optional sentinel.'));
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Validate a key against the flat contract and return a detached copy
|
|
66
|
-
* (callers may mutate their array; records must not observe that).
|
|
67
|
-
* Rejects objects, arrays, functions, undefined, and non-finite numbers
|
|
68
|
-
* (NaN/Infinity JSON-serialize as null and would collide) with N602.
|
|
69
|
-
*/
|
|
70
|
-
function validateKey(raw) {
|
|
71
|
-
if (!Array.isArray(raw)) {
|
|
72
|
-
throw keyError(`expected an array, got ${typeof raw}`);
|
|
73
|
-
}
|
|
74
|
-
for (let i = 0; i < raw.length; i++) {
|
|
75
|
-
const el = raw[i];
|
|
76
|
-
if (el === null)
|
|
77
|
-
continue;
|
|
78
|
-
const t = typeof el;
|
|
79
|
-
if (t === 'string' || t === 'boolean')
|
|
80
|
-
continue;
|
|
81
|
-
if (t === 'number') {
|
|
82
|
-
if (Number.isFinite(el))
|
|
83
|
-
continue;
|
|
84
|
-
throw keyError(`non-finite number at index ${i} (would collide with null)`);
|
|
85
|
-
}
|
|
86
|
-
if (el === undefined) {
|
|
87
|
-
throw keyError(`undefined at index ${i}`);
|
|
88
|
-
}
|
|
89
|
-
throw keyError(`${t} at index ${i}`);
|
|
90
|
-
}
|
|
91
|
-
return raw.slice();
|
|
92
|
-
}
|
|
93
|
-
/** THE one serializer: JSON.stringify of the validated flat array. */
|
|
94
|
-
function serializeKey(key) {
|
|
95
|
-
return JSON.stringify(key);
|
|
96
|
-
}
|
|
97
|
-
/** Element-wise prefix match over validated keys (=== is sound: elements
|
|
98
|
-
* are primitives and NaN is rejected by the contract). */
|
|
99
|
-
function matchesPrefix(key, prefix) {
|
|
100
|
-
if (prefix.length > key.length)
|
|
101
|
-
return false;
|
|
102
|
-
for (let i = 0; i < prefix.length; i++) {
|
|
103
|
-
if (key[i] !== prefix[i])
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
/** Monotonic mount counter — "most recently mounted" is decided by
|
|
109
|
-
* query() construction order, not re-registration order. */
|
|
110
|
-
let nextMountIndex = 0;
|
|
111
|
-
/** Read a record signal without tracking it into the ambient observer —
|
|
112
|
-
* the observer effect must depend on keys/enabled/version ONLY, never on
|
|
113
|
-
* record state (that is what keeps refetch loops unrepresentable). */
|
|
114
|
-
function peek(s) {
|
|
115
|
-
let v;
|
|
116
|
-
untrack(() => { v = s.value; });
|
|
117
|
-
return v;
|
|
118
|
-
}
|
|
119
|
-
function toError(cause) {
|
|
120
|
-
if (cause instanceof Error)
|
|
121
|
-
return cause;
|
|
122
|
-
try {
|
|
123
|
-
return new Error(String(cause));
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
return new Error('Unknown error');
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Global keyed logical-request store. One per app: resolved via
|
|
131
|
-
* `inject(QueryClient)` (auto-singleton; override with
|
|
132
|
-
* `provide(QueryClient, ...)` BEFORE the first query() call).
|
|
133
|
-
*
|
|
134
|
-
* Records are never GC'd — see the module doc for the bound.
|
|
135
|
-
*/
|
|
136
|
-
export class QueryClient {
|
|
137
|
-
/** @internal */ _records = new Map();
|
|
138
|
-
/** @internal clear() bumps this; observer effects track it and re-resolve. */
|
|
139
|
-
_version = signal(0);
|
|
140
|
-
/** @internal live observer count (N601 mixed-client diagnostic). */
|
|
141
|
-
_observers = 0;
|
|
142
|
-
/**
|
|
143
|
-
* Mark records matching the key prefix stale and rerun those with ≥1
|
|
144
|
-
* enabled observer (using the owning observer's fetcher/options).
|
|
145
|
-
* Disabled observers revalidate on re-enable; a record with only
|
|
146
|
-
* disabled/no observers stays stale until one arrives. Returns the
|
|
147
|
-
* number of records invalidated.
|
|
148
|
-
*
|
|
149
|
-
* invalidate(['tasks']) matches ['tasks'], ['tasks', '1'], ['tasks', '2', 'x'].
|
|
150
|
-
*/
|
|
151
|
-
invalidate(keyPrefix) {
|
|
152
|
-
const prefix = validateKey(keyPrefix);
|
|
153
|
-
let count = 0;
|
|
154
|
-
for (const rec of this._records.values()) {
|
|
155
|
-
if (!matchesPrefix(rec.key, prefix))
|
|
156
|
-
continue;
|
|
157
|
-
count++;
|
|
158
|
-
rec.stale = true;
|
|
159
|
-
const owner = ownerOf(rec, /* requireEnabled */ true);
|
|
160
|
-
if (owner)
|
|
161
|
-
startRun(rec, owner.fetcher, owner.retry);
|
|
162
|
-
}
|
|
163
|
-
return count;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Drop every record. In-flight runs are aborted (a settle() termination).
|
|
167
|
-
* Live observers re-resolve fresh records on the version bump — enabled
|
|
168
|
-
* ones revalidate immediately.
|
|
169
|
-
*/
|
|
170
|
-
clear() {
|
|
171
|
-
for (const rec of this._records.values()) {
|
|
172
|
-
rec.generation++;
|
|
173
|
-
rec.controller?.abort();
|
|
174
|
-
rec.terminate?.();
|
|
175
|
-
rec.controller = null;
|
|
176
|
-
rec.terminate = null;
|
|
177
|
-
rec.runPromise = null;
|
|
178
|
-
rec.running = false;
|
|
179
|
-
rec.observers.clear();
|
|
180
|
-
}
|
|
181
|
-
this._records.clear();
|
|
182
|
-
this._version.value++;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Imperatively warm a record. Joins an in-flight run; a fresh record
|
|
186
|
-
* (per the given staleTime) is a no-op. Otherwise starts a run with THE
|
|
187
|
-
* GIVEN fetcher — an explicit imperative is its own owner. The run
|
|
188
|
-
* commits even with zero observers. Resolves at run termination.
|
|
189
|
-
*/
|
|
190
|
-
prefetch(key, fetcher, staleTime = 0) {
|
|
191
|
-
const rec = resolveRecord(this, key);
|
|
192
|
-
if (rec.running)
|
|
193
|
-
return rec.runPromise ?? Promise.resolve();
|
|
194
|
-
if (!rec.stale && peek(rec.status) === 'success' && staleTime > 0
|
|
195
|
-
&& Date.now() - peek(rec.fetchedAt) < staleTime) {
|
|
196
|
-
return Promise.resolve();
|
|
197
|
-
}
|
|
198
|
-
return startRun(rec, fetcher, 0);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
/** Get-or-create the record for a key. Validation throws N602. */
|
|
202
|
-
function resolveRecord(client, rawKey) {
|
|
203
|
-
const key = validateKey(rawKey);
|
|
204
|
-
const serialized = serializeKey(key);
|
|
205
|
-
let rec = client._records.get(serialized);
|
|
206
|
-
if (!rec) {
|
|
207
|
-
rec = {
|
|
208
|
-
key,
|
|
209
|
-
serialized,
|
|
210
|
-
data: signal(undefined),
|
|
211
|
-
error: signal(null),
|
|
212
|
-
status: signal('idle'),
|
|
213
|
-
fetchedAt: signal(0),
|
|
214
|
-
stale: false,
|
|
215
|
-
running: false,
|
|
216
|
-
generation: 0,
|
|
217
|
-
controller: null,
|
|
218
|
-
runPromise: null,
|
|
219
|
-
terminate: null,
|
|
220
|
-
observers: new Set(),
|
|
221
|
-
};
|
|
222
|
-
client._records.set(serialized, rec); // never deleted — documented bound
|
|
223
|
-
}
|
|
224
|
-
return rec;
|
|
225
|
-
}
|
|
226
|
-
/** The observer whose fetcher/options own the next run: most recently
|
|
227
|
-
* mounted, preferring enabled observers (a disabled observer asked not
|
|
228
|
-
* to fetch — its fetcher should not fire). */
|
|
229
|
-
function ownerOf(rec, requireEnabled = false) {
|
|
230
|
-
let best;
|
|
231
|
-
let bestDisabled;
|
|
232
|
-
for (const obs of rec.observers) {
|
|
233
|
-
if (obs.enabled) {
|
|
234
|
-
if (!best || obs.mountIndex > best.mountIndex)
|
|
235
|
-
best = obs;
|
|
236
|
-
}
|
|
237
|
-
else if (!requireEnabled) {
|
|
238
|
-
if (!bestDisabled || obs.mountIndex > bestDisabled.mountIndex)
|
|
239
|
-
bestDisabled = obs;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return best ?? bestDisabled;
|
|
243
|
-
}
|
|
244
|
-
/** Does this record need a run, per THIS observer's freshness policy?
|
|
245
|
-
* Called only on real transitions (registration, re-enable, clear());
|
|
246
|
-
* record reads are untracked, so commits never re-trigger observers. */
|
|
247
|
-
function needsRun(rec, observer) {
|
|
248
|
-
if (rec.running)
|
|
249
|
-
return false; // join the in-flight logical request
|
|
250
|
-
if (rec.stale)
|
|
251
|
-
return true;
|
|
252
|
-
const status = peek(rec.status);
|
|
253
|
-
if (status === 'idle' || status === 'error')
|
|
254
|
-
return true;
|
|
255
|
-
if (observer.staleTime <= 0)
|
|
256
|
-
return true;
|
|
257
|
-
return Date.now() - peek(rec.fetchedAt) >= observer.staleTime;
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* THE run: one logical request owning the retry loop and the commit.
|
|
261
|
-
* Supersedes (aborts) any in-flight run for the record. Enrolls in the
|
|
262
|
-
* settle() registry on start and terminates it at commit, terminal error,
|
|
263
|
-
* or abort — never at raw promise settlement.
|
|
264
|
-
*/
|
|
265
|
-
function startRun(rec, fetcher, retry) {
|
|
266
|
-
// Supersede: abort IS the superseded run's termination.
|
|
267
|
-
rec.controller?.abort();
|
|
268
|
-
rec.terminate?.();
|
|
269
|
-
const generation = ++rec.generation;
|
|
270
|
-
const controller = new AbortController();
|
|
271
|
-
const terminate = __enrollPending();
|
|
272
|
-
rec.controller = controller;
|
|
273
|
-
rec.terminate = terminate;
|
|
274
|
-
rec.running = true;
|
|
275
|
-
rec.stale = false;
|
|
276
|
-
rec.status.value = 'loading';
|
|
277
|
-
rec.error.value = null;
|
|
278
|
-
const run = (async () => {
|
|
279
|
-
try {
|
|
280
|
-
let lastError = null;
|
|
281
|
-
for (let attempt = 0; attempt <= retry; attempt++) {
|
|
282
|
-
if (generation !== rec.generation)
|
|
283
|
-
return; // superseded
|
|
284
|
-
try {
|
|
285
|
-
// The microtask hop makes a synchronous fetcher throw a normal
|
|
286
|
-
// rejection — it enters the same retry/terminal path (issue 0008).
|
|
287
|
-
const result = await Promise.resolve().then(() => fetcher(controller.signal));
|
|
288
|
-
if (generation !== rec.generation)
|
|
289
|
-
return;
|
|
290
|
-
rec.data.value = result;
|
|
291
|
-
rec.error.value = null;
|
|
292
|
-
rec.fetchedAt.value = Date.now();
|
|
293
|
-
rec.status.value = 'success';
|
|
294
|
-
return; // commit
|
|
295
|
-
}
|
|
296
|
-
catch (cause) {
|
|
297
|
-
lastError = toError(cause);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
if (generation !== rec.generation)
|
|
301
|
-
return;
|
|
302
|
-
rec.error.value = lastError;
|
|
303
|
-
rec.status.value = 'error'; // terminal error after retries
|
|
304
|
-
}
|
|
305
|
-
finally {
|
|
306
|
-
if (generation === rec.generation) {
|
|
307
|
-
rec.running = false;
|
|
308
|
-
rec.controller = null;
|
|
309
|
-
rec.runPromise = null;
|
|
310
|
-
rec.terminate = null;
|
|
311
|
-
}
|
|
312
|
-
terminate(); // idempotent — superseded runs already terminated at abort
|
|
313
|
-
}
|
|
314
|
-
})();
|
|
315
|
-
rec.runPromise = run;
|
|
316
|
-
return run;
|
|
317
|
-
}
|
|
318
|
-
// ── Mixed clients: an eliminated class (formerly N601) ──────────────
|
|
319
|
-
// With inject() as the single resolution path, the only way two clients
|
|
320
|
-
// could mix was provide(QueryClient, ...) landing after queries already
|
|
321
|
-
// bound the auto-created singleton. The injector now throws N501 at that
|
|
322
|
-
// exact provide() (DI freeze, ADR 0030.2 T6), so the split-brain state is
|
|
323
|
-
// unrepresentable in dev and was always silent in prod — the symptom-side
|
|
324
|
-
// warning this block used to hold (N601) died with its cause. Retired
|
|
325
|
-
// before release; the code number is not reused.
|
|
326
|
-
// ── query() — the thin observer ─────────────────────────────────────
|
|
327
|
-
/**
|
|
328
|
-
* Observe the record the reactive key points at.
|
|
329
|
-
*
|
|
330
|
-
* @param keyFn - Returns the flat cache key. Signal reads are tracked; a
|
|
331
|
-
* key change re-registers the observer on the new record.
|
|
332
|
-
* @param fetcher - Fetches the data; receives the run's AbortSignal.
|
|
333
|
-
* @param options - staleTime / retry / enabled / initialData.
|
|
334
|
-
* @throws N602 synchronously when the initial key violates the contract.
|
|
335
|
-
*/
|
|
336
|
-
export function query(keyFn, fetcher, options = {}) {
|
|
337
|
-
const { staleTime = 0, retry = 0, enabled, initialData } = options;
|
|
338
|
-
const client = inject(QueryClient);
|
|
339
|
-
// Surface key-contract violations at the call site: the observer effect
|
|
340
|
-
// is error-contained (a later reactive key going invalid is logged with
|
|
341
|
-
// the same coded message), so the construction-time key must be checked
|
|
342
|
-
// synchronously. untrack: query() may run under an ambient observer
|
|
343
|
-
// (component setup) and key signals must not widen its dependencies.
|
|
344
|
-
untrack(() => { validateKey(keyFn()); });
|
|
345
|
-
const observer = {
|
|
346
|
-
mountIndex: nextMountIndex++,
|
|
347
|
-
fetcher: fetcher,
|
|
348
|
-
staleTime,
|
|
349
|
-
retry,
|
|
350
|
-
enabled: true,
|
|
351
|
-
record: null,
|
|
352
|
-
};
|
|
353
|
-
client._observers++;
|
|
354
|
-
const recSig = signal(null);
|
|
355
|
-
const enabledSig = signal(true);
|
|
356
|
-
let disposed = false;
|
|
357
|
-
let prevEnabled = null;
|
|
358
|
-
let prevVersion = -1;
|
|
359
|
-
// The registration effect — depends on keyFn signals, enabled() signals,
|
|
360
|
-
// and the client version. NEVER on record state (all record reads are
|
|
361
|
-
// untracked), so commits cannot re-trigger it: run starts happen only on
|
|
362
|
-
// the real transitions listed in needsRun()'s doc.
|
|
363
|
-
const stopEffect = effect(() => {
|
|
364
|
-
if (disposed)
|
|
365
|
-
return;
|
|
366
|
-
const version = client._version.value;
|
|
367
|
-
const key = keyFn();
|
|
368
|
-
const on = enabled ? !!enabled() : true;
|
|
369
|
-
const rec = resolveRecord(client, key);
|
|
370
|
-
observer.enabled = on;
|
|
371
|
-
enabledSig.value = on;
|
|
372
|
-
const moved = rec !== observer.record;
|
|
373
|
-
if (moved) {
|
|
374
|
-
observer.record?.observers.delete(observer);
|
|
375
|
-
rec.observers.add(observer);
|
|
376
|
-
observer.record = rec;
|
|
377
|
-
if (initialData !== undefined && peek(rec.status) === 'idle'
|
|
378
|
-
&& peek(rec.data) === undefined) {
|
|
379
|
-
rec.data.value = initialData; // seed; not a fetch — status stays idle
|
|
380
|
-
}
|
|
381
|
-
recSig.value = rec;
|
|
382
|
-
}
|
|
383
|
-
const reEnabled = prevEnabled === false && on;
|
|
384
|
-
const versionChanged = version !== prevVersion;
|
|
385
|
-
prevEnabled = on;
|
|
386
|
-
prevVersion = version;
|
|
387
|
-
if (on && (moved || reEnabled || versionChanged) && needsRun(rec, observer)) {
|
|
388
|
-
const owner = ownerOf(rec) ?? observer;
|
|
389
|
-
startRun(rec, owner.fetcher, owner.retry);
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
const dispose = () => {
|
|
393
|
-
if (disposed)
|
|
394
|
-
return;
|
|
395
|
-
disposed = true;
|
|
396
|
-
observer.record?.observers.delete(observer);
|
|
397
|
-
observer.record = null;
|
|
398
|
-
client._observers--;
|
|
399
|
-
stopEffect();
|
|
400
|
-
// NOTE: no abort — a zero-observer in-flight run completes and commits.
|
|
401
|
-
};
|
|
402
|
-
if (hasContext()) {
|
|
403
|
-
getCurrentComponent().addDisposer(dispose);
|
|
404
|
-
}
|
|
405
|
-
const refetch = () => {
|
|
406
|
-
if (disposed)
|
|
407
|
-
return;
|
|
408
|
-
const rec = observer.record;
|
|
409
|
-
if (!rec || !observer.enabled)
|
|
410
|
-
return;
|
|
411
|
-
if (rec.running)
|
|
412
|
-
return; // join the in-flight logical request (dedup)
|
|
413
|
-
const owner = ownerOf(rec) ?? observer;
|
|
414
|
-
startRun(rec, owner.fetcher, owner.retry);
|
|
415
|
-
};
|
|
416
|
-
const result = {
|
|
417
|
-
data: computed(() => {
|
|
418
|
-
const rec = recSig.value;
|
|
419
|
-
return (rec ? rec.data.value : initialData);
|
|
420
|
-
}),
|
|
421
|
-
loading: computed(() => enabledSig.value && recSig.value?.status.value === 'loading'),
|
|
422
|
-
error: computed(() => recSig.value?.error.value ?? null),
|
|
423
|
-
status: computed(() => recSig.value?.status.value ?? 'idle'),
|
|
424
|
-
refetch,
|
|
425
|
-
dispose,
|
|
426
|
-
};
|
|
427
|
-
return disposable(result, dispose);
|
|
428
|
-
}
|
|
429
|
-
//# sourceMappingURL=query.js.map
|
package/dist/query.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,OAAO,EACL,MAAM,EACN,MAAM,EACN,QAAQ,EACR,OAAO,GAGR,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,UAAU,EAA2B,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,yEAAyE;AACzE,uEAAuE;AACvE,oCAAoC;AAEpC;8DAC8D;AAC9D,SAAS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AI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO;YAAE,OAAO;QACtC,IAAI,GAAG,CAAC,OAAO;YAAE,OAAO,CAAC,6CAA6C;QACtE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC;QACvC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC,CAAC;IAEF,MAAM,MAAM,GAAG;QACb,IAAI,EAAE,QAAQ,CAAC,GAAG,EAAE;YAClB,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC;YACzB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAkB,CAAC;QAC/D,CAAC,CAAC;QACF,OAAO,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC;QACrF,KAAK,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC;QACxD,MAAM,EAAE,QAAQ,CAAc,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC;QACzE,OAAO;QACP,OAAO;KACR,CAAC;IACF,OAAO,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC"}
|
package/dist/ref.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ref.ts — Element reference primitive for imperative DOM access
|
|
3
|
-
*
|
|
4
|
-
* `ref()` creates a container that receives a DOM element reference
|
|
5
|
-
* after the template is mounted. Use it for focus management, DOM
|
|
6
|
-
* measurement, scroll management, and third-party library init.
|
|
7
|
-
*
|
|
8
|
-
* ```ts
|
|
9
|
-
* const inputRef = ref<HTMLInputElement>();
|
|
10
|
-
*
|
|
11
|
-
* onMount(() => inputRef.current?.focus());
|
|
12
|
-
*
|
|
13
|
-
* return html`<input ref="${inputRef}" @keydown.enter=${onSubmit} />`;
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* The template engine detects `Ref` objects in `ref="${...}"`
|
|
17
|
-
* attribute bindings and assigns the referenced element.
|
|
18
|
-
*/
|
|
19
|
-
// ── Brand for ref detection in templates ─────────────────────────────
|
|
20
|
-
export const REF_BRAND = Symbol.for('backlog.ref');
|
|
21
|
-
// ── Public API ──────────────────────────────────────────────────────
|
|
22
|
-
/**
|
|
23
|
-
* Create a ref container for imperative DOM access.
|
|
24
|
-
*
|
|
25
|
-
* After the template is mounted, `ref.current` holds the element.
|
|
26
|
-
* After dispose, `ref.current` is set back to null.
|
|
27
|
-
*/
|
|
28
|
-
export function ref() {
|
|
29
|
-
return {
|
|
30
|
-
[REF_BRAND]: true,
|
|
31
|
-
current: null,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Check if a value is a Ref.
|
|
36
|
-
* Used by the template engine to detect refs in expression slots.
|
|
37
|
-
*/
|
|
38
|
-
export function isRef(value) {
|
|
39
|
-
return (value !== null &&
|
|
40
|
-
typeof value === 'object' &&
|
|
41
|
-
REF_BRAND in value);
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=ref.js.map
|
package/dist/ref.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../src/ref.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,wEAAwE;AAExE,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;AAUnD,uEAAuE;AAEvE;;;;;GAKG;AACH,MAAM,UAAU,GAAG;IACjB,OAAO;QACL,CAAC,SAAS,CAAC,EAAE,IAAa;QAC1B,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,KAAK,CAAC,KAAc;IAClC,OAAO,CACL,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,SAAS,IAAK,KAAiC,CAChD,CAAC;AACJ,CAAC"}
|
package/dist/resource.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* resource.ts — Local async derivations with reactive source tracking.
|
|
3
|
-
*
|
|
4
|
-
* `resource()` is the async counterpart to a local computed value: source
|
|
5
|
-
* dependencies are tracked synchronously, while the loader runs outside the
|
|
6
|
-
* reactive observer and commits only the newest live generation.
|
|
7
|
-
*/
|
|
8
|
-
import { getCurrentComponent, hasContext } from './context.js';
|
|
9
|
-
import { disposable } from './disposable.js';
|
|
10
|
-
import { __enrollPending } from './settle.js';
|
|
11
|
-
import { effect, signal } from './signal.js';
|
|
12
|
-
/**
|
|
13
|
-
* Derive local async state from a synchronously tracked source.
|
|
14
|
-
*
|
|
15
|
-
* Only signal reads inside `source` are dependencies. `loader` starts in a
|
|
16
|
-
* microtask, outside the active observer, so signal reads before or after its
|
|
17
|
-
* first await never accidentally widen the source set.
|
|
18
|
-
*/
|
|
19
|
-
export function resource(source, loader) {
|
|
20
|
-
const data = signal(undefined);
|
|
21
|
-
const loading = signal(false);
|
|
22
|
-
const error = signal(null);
|
|
23
|
-
const refreshVersion = signal(0);
|
|
24
|
-
let generation = 0;
|
|
25
|
-
let disposed = false;
|
|
26
|
-
let stopEffect = () => { };
|
|
27
|
-
const dispose = () => {
|
|
28
|
-
if (disposed)
|
|
29
|
-
return;
|
|
30
|
-
disposed = true;
|
|
31
|
-
generation++;
|
|
32
|
-
stopEffect();
|
|
33
|
-
loading.value = false;
|
|
34
|
-
};
|
|
35
|
-
// Register the full resource disposer before effect() registers its own
|
|
36
|
-
// lower-level disposer, so component teardown first invalidates generations
|
|
37
|
-
// and then performs the idempotent raw effect cleanup.
|
|
38
|
-
if (hasContext()) {
|
|
39
|
-
getCurrentComponent().addDisposer(dispose);
|
|
40
|
-
}
|
|
41
|
-
stopEffect = effect(() => {
|
|
42
|
-
refreshVersion.value;
|
|
43
|
-
const currentGeneration = ++generation;
|
|
44
|
-
let sourceValue;
|
|
45
|
-
try {
|
|
46
|
-
sourceValue = source();
|
|
47
|
-
}
|
|
48
|
-
catch (cause) {
|
|
49
|
-
loading.value = false;
|
|
50
|
-
error.value = toError(cause);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
// `undefined` is the single disabled sentinel. It covers the markdown
|
|
54
|
-
// consumer's empty-content branch without growing an options surface.
|
|
55
|
-
if (sourceValue === undefined) {
|
|
56
|
-
data.value = undefined;
|
|
57
|
-
loading.value = false;
|
|
58
|
-
error.value = null;
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const controller = new AbortController();
|
|
62
|
-
loading.value = true;
|
|
63
|
-
error.value = null;
|
|
64
|
-
const enabledSource = sourceValue;
|
|
65
|
-
const isStale = () => (disposed
|
|
66
|
-
|| controller.signal.aborted
|
|
67
|
-
|| currentGeneration !== generation);
|
|
68
|
-
// settle() enrollment (ADR 0030.2 T2): this generation is a pending
|
|
69
|
-
// logical request from here until COMMIT (data/error write) or ABORT
|
|
70
|
-
// (the cleanup below) — never raw loader settlement, so an
|
|
71
|
-
// abort-ignoring loader cannot wedge settle(). Idempotent.
|
|
72
|
-
const settled = __enrollPending();
|
|
73
|
-
// The microtask boundary is deliberate: loader signal reads are NOT source
|
|
74
|
-
// dependencies, and synchronous loader throws become normal rejections.
|
|
75
|
-
void Promise.resolve().then(async () => {
|
|
76
|
-
if (isStale()) {
|
|
77
|
-
settled();
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
const value = await loader(enabledSource, controller.signal);
|
|
82
|
-
if (isStale()) {
|
|
83
|
-
settled();
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
data.value = value;
|
|
87
|
-
loading.value = false;
|
|
88
|
-
settled();
|
|
89
|
-
}
|
|
90
|
-
catch (cause) {
|
|
91
|
-
if (isStale()) {
|
|
92
|
-
settled();
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
error.value = toError(cause);
|
|
96
|
-
loading.value = false;
|
|
97
|
-
settled();
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
return () => {
|
|
101
|
-
if (currentGeneration === generation)
|
|
102
|
-
generation++;
|
|
103
|
-
controller.abort();
|
|
104
|
-
settled();
|
|
105
|
-
};
|
|
106
|
-
});
|
|
107
|
-
const result = {
|
|
108
|
-
data,
|
|
109
|
-
loading,
|
|
110
|
-
error,
|
|
111
|
-
refresh() {
|
|
112
|
-
if (!disposed)
|
|
113
|
-
refreshVersion.value++;
|
|
114
|
-
},
|
|
115
|
-
dispose,
|
|
116
|
-
};
|
|
117
|
-
return disposable(result, dispose);
|
|
118
|
-
}
|
|
119
|
-
function toError(cause) {
|
|
120
|
-
if (cause instanceof Error)
|
|
121
|
-
return cause;
|
|
122
|
-
try {
|
|
123
|
-
return new Error(String(cause));
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
return new Error('Unknown error');
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
//# sourceMappingURL=resource.js.map
|
package/dist/resource.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,UAAU,EAA2B,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAuB,MAAM,aAAa,CAAC;AAelE;;;;;;GAMG;AACH,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