@bevelo/query 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.
@@ -0,0 +1,2 @@
1
+ import { $ as MutationMeta, A as initialQueryState, B as ERROR_TAG, C as DeriveSnapshotInput, Ct as RetryPolicy, D as deriveMutationSnapshot, Dt as TaggedKey, E as deriveInfiniteSnapshot, Et as SuccessQuerySnapshot, F as DefinedQuerySnapshot, G as InfiniteExtra, H as FetchDirection, I as DehydrateOptions, J as LoadingErrorQuerySnapshot, K as InfiniteQuerySpec, L as DehydratedCache, M as reduceQueryState, N as DATA_TAG, O as deriveQuerySnapshot, Ot as keepPrevious, P as DataOfKey, Q as MutationFilterRecord, R as DehydratedMutation, S as serializeKey, St as RetryDelay, T as QueryAction, Tt as StaleWindow, U as FetchPhase, V as ErrorOfKey, W as HydrateOptions, X as MutationEntryState, Y as MutateCallOptions, Z as MutationFilter, _ as isPlainObject, _t as QueryStatus, a as packCache, at as PendingQuerySnapshot, b as matchesQueryFilter, bt as RefetchIntervalValue, c as computeBackoffMs, ct as QueryFilter, d as mutationSpec, dt as QueryFnContext, et as MutationSnapshot, f as querySpec, ft as QueryKey, g as keepEqual, gt as QuerySpec, h as shouldRetryAttempt, ht as QuerySnapshot, i as defaultShouldDehydrateQuery, it as PageData, j as reduceMutationState, k as initialMutationState, kt as skipToken, l as infiniteQuerySpec, lt as QueryFilterRecord, m as resolveStaleMs, mt as QueryRefetchOptions, n as RawDehydratableQuery, nt as MutationStatus, o as selectHydrateQueries, ot as PlaceholderQuerySnapshot, p as resolveNetworkAction, pt as QueryMeta, q as InfiniteSnapshot, r as defaultShouldDehydrateMutation, rt as NetworkPolicy, s as clampPages, st as QueryEntryState, t as RawDehydratableMutation, tt as MutationSpec, u as isEntryStale, ut as QueryFn, v as keyStartsWith, vt as QueryTypeFilter, w as MutationAction, wt as SkipToken, x as partialMatchValue, xt as RefetchTrigger, y as matchesMutationFilter, yt as RefetchErrorQuerySnapshot, z as DehydratedQuery } from "../index-C7f4d6Gg.cjs";
2
+ export { DATA_TAG, DataOfKey, DefinedQuerySnapshot, DehydrateOptions, DehydratedCache, DehydratedMutation, DehydratedQuery, DeriveSnapshotInput, ERROR_TAG, ErrorOfKey, FetchDirection, FetchPhase, HydrateOptions, InfiniteExtra, InfiniteQuerySpec, InfiniteSnapshot, LoadingErrorQuerySnapshot, MutateCallOptions, MutationAction, MutationEntryState, MutationFilter, MutationFilterRecord, MutationMeta, MutationSnapshot, MutationSpec, MutationStatus, NetworkPolicy, PageData, PendingQuerySnapshot, PlaceholderQuerySnapshot, QueryAction, QueryEntryState, QueryFilter, QueryFilterRecord, QueryFn, QueryFnContext, QueryKey, QueryMeta, QueryRefetchOptions, QuerySnapshot, QuerySpec, QueryStatus, QueryTypeFilter, RawDehydratableMutation, RawDehydratableQuery, RefetchErrorQuerySnapshot, RefetchIntervalValue, RefetchTrigger, RetryDelay, RetryPolicy, SkipToken, StaleWindow, SuccessQuerySnapshot, TaggedKey, clampPages, computeBackoffMs, defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, deriveInfiniteSnapshot, deriveMutationSnapshot, deriveQuerySnapshot, infiniteQuerySpec, initialMutationState, initialQueryState, isEntryStale, isPlainObject, keepEqual, keepPrevious, keyStartsWith, matchesMutationFilter, matchesQueryFilter, mutationSpec, packCache, partialMatchValue, querySpec, reduceMutationState, reduceQueryState, resolveNetworkAction, resolveStaleMs, selectHydrateQueries, serializeKey, shouldRetryAttempt, skipToken };
@@ -0,0 +1,2 @@
1
+ import { $ as MutationMeta, A as initialQueryState, B as ERROR_TAG, C as DeriveSnapshotInput, Ct as RetryPolicy, D as deriveMutationSnapshot, Dt as TaggedKey, E as deriveInfiniteSnapshot, Et as SuccessQuerySnapshot, F as DefinedQuerySnapshot, G as InfiniteExtra, H as FetchDirection, I as DehydrateOptions, J as LoadingErrorQuerySnapshot, K as InfiniteQuerySpec, L as DehydratedCache, M as reduceQueryState, N as DATA_TAG, O as deriveQuerySnapshot, Ot as keepPrevious, P as DataOfKey, Q as MutationFilterRecord, R as DehydratedMutation, S as serializeKey, St as RetryDelay, T as QueryAction, Tt as StaleWindow, U as FetchPhase, V as ErrorOfKey, W as HydrateOptions, X as MutationEntryState, Y as MutateCallOptions, Z as MutationFilter, _ as isPlainObject, _t as QueryStatus, a as packCache, at as PendingQuerySnapshot, b as matchesQueryFilter, bt as RefetchIntervalValue, c as computeBackoffMs, ct as QueryFilter, d as mutationSpec, dt as QueryFnContext, et as MutationSnapshot, f as querySpec, ft as QueryKey, g as keepEqual, gt as QuerySpec, h as shouldRetryAttempt, ht as QuerySnapshot, i as defaultShouldDehydrateQuery, it as PageData, j as reduceMutationState, k as initialMutationState, kt as skipToken, l as infiniteQuerySpec, lt as QueryFilterRecord, m as resolveStaleMs, mt as QueryRefetchOptions, n as RawDehydratableQuery, nt as MutationStatus, o as selectHydrateQueries, ot as PlaceholderQuerySnapshot, p as resolveNetworkAction, pt as QueryMeta, q as InfiniteSnapshot, r as defaultShouldDehydrateMutation, rt as NetworkPolicy, s as clampPages, st as QueryEntryState, t as RawDehydratableMutation, tt as MutationSpec, u as isEntryStale, ut as QueryFn, v as keyStartsWith, vt as QueryTypeFilter, w as MutationAction, wt as SkipToken, x as partialMatchValue, xt as RefetchTrigger, y as matchesMutationFilter, yt as RefetchErrorQuerySnapshot, z as DehydratedQuery } from "../index-C7f4d6Gg.js";
2
+ export { DATA_TAG, DataOfKey, DefinedQuerySnapshot, DehydrateOptions, DehydratedCache, DehydratedMutation, DehydratedQuery, DeriveSnapshotInput, ERROR_TAG, ErrorOfKey, FetchDirection, FetchPhase, HydrateOptions, InfiniteExtra, InfiniteQuerySpec, InfiniteSnapshot, LoadingErrorQuerySnapshot, MutateCallOptions, MutationAction, MutationEntryState, MutationFilter, MutationFilterRecord, MutationMeta, MutationSnapshot, MutationSpec, MutationStatus, NetworkPolicy, PageData, PendingQuerySnapshot, PlaceholderQuerySnapshot, QueryAction, QueryEntryState, QueryFilter, QueryFilterRecord, QueryFn, QueryFnContext, QueryKey, QueryMeta, QueryRefetchOptions, QuerySnapshot, QuerySpec, QueryStatus, QueryTypeFilter, RawDehydratableMutation, RawDehydratableQuery, RefetchErrorQuerySnapshot, RefetchIntervalValue, RefetchTrigger, RetryDelay, RetryPolicy, SkipToken, StaleWindow, SuccessQuerySnapshot, TaggedKey, clampPages, computeBackoffMs, defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, deriveInfiniteSnapshot, deriveMutationSnapshot, deriveQuerySnapshot, infiniteQuerySpec, initialMutationState, initialQueryState, isEntryStale, isPlainObject, keepEqual, keepPrevious, keyStartsWith, matchesMutationFilter, matchesQueryFilter, mutationSpec, packCache, partialMatchValue, querySpec, reduceMutationState, reduceQueryState, resolveNetworkAction, resolveStaleMs, selectHydrateQueries, serializeKey, shouldRetryAttempt, skipToken };
@@ -0,0 +1,494 @@
1
+ import { a as partialMatchValue, c as computeBackoffMs, d as mutationSpec, f as querySpec, h as shouldRetryAttempt, i as matchesQueryFilter, l as infiniteQuerySpec, m as resolveStaleMs, n as keyStartsWith, o as serializeKey, p as resolveNetworkAction, r as matchesMutationFilter, s as clampPages, t as isPlainObject, u as isEntryStale } from "../key-BtYrMAlu.js";
2
+ // src/pure/types.ts
3
+ const DATA_TAG = Symbol("bevelo.query.data");
4
+ const ERROR_TAG = Symbol("bevelo.query.error");
5
+ /** Marker value passed instead of `queryFn` to pause a query cleanly. */
6
+ const skipToken = Symbol("bevelo.query.skip");
7
+ /** Placeholder helper that keeps the previous query data while keys change. */
8
+ function keepPrevious(previousData) {
9
+ return previousData;
10
+ }
11
+ // src/pure/structural.ts
12
+ /**
13
+ * Compares `prev` and `next` recursively for plain objects and arrays. Whenever every
14
+ * child keeps the same value or reference, `prev` is returned so downstream equality
15
+ * checks (`Object.is`) see zero change.
16
+ */
17
+ function keepEqual(prev, next) {
18
+ if (Object.is(prev, next)) return next;
19
+ const prevArray = Array.isArray(prev);
20
+ const nextArray = Array.isArray(next);
21
+ if (prevArray && nextArray) {
22
+ const pArr = prev;
23
+ const nArr = next;
24
+ const len = nArr.length;
25
+ let copy = pArr.length === len ? void 0 : new Array(len);
26
+ for (let i = 0; i < len; i += 1) {
27
+ const child = keepEqual(i < pArr.length ? pArr[i] : void 0, nArr[i]);
28
+ if (copy !== void 0) copy[i] = child;
29
+ else if (!Object.is(child, pArr[i])) {
30
+ copy = new Array(len);
31
+ for (let j = 0; j < i; j += 1) copy[j] = pArr[j];
32
+ copy[i] = child;
33
+ }
34
+ }
35
+ return copy ?? pArr;
36
+ }
37
+ if (!prevArray && !nextArray && isPlainObject(prev) && isPlainObject(next)) {
38
+ const pObj = prev;
39
+ const nObj = next;
40
+ const pKeys = Object.keys(pObj);
41
+ const nKeys = Object.keys(nObj);
42
+ let result = pKeys.length === nKeys.length ? void 0 : {};
43
+ for (let i = 0; i < nKeys.length; i += 1) {
44
+ const k = nKeys[i];
45
+ const hasPrev = Object.prototype.hasOwnProperty.call(pObj, k);
46
+ const merged = hasPrev ? keepEqual(pObj[k], nObj[k]) : nObj[k];
47
+ if (result !== void 0) result[k] = merged;
48
+ else if (!hasPrev || !Object.is(merged, pObj[k])) {
49
+ result = {};
50
+ for (let j = 0; j < i; j += 1) {
51
+ const prevK = nKeys[j];
52
+ result[prevK] = pObj[prevK];
53
+ }
54
+ result[k] = merged;
55
+ }
56
+ }
57
+ return result ?? prev;
58
+ }
59
+ return next;
60
+ }
61
+ // src/pure/state.ts
62
+ /** Creates the initial state record for a cache entry. */
63
+ function initialQueryState(seed) {
64
+ const hasSeedData = seed !== void 0 && seed.data !== void 0;
65
+ return {
66
+ data: hasSeedData ? seed.data : void 0,
67
+ dataUpdatedAt: hasSeedData ? seed.dataUpdatedAt ?? 0 : 0,
68
+ dataUpdateCount: hasSeedData ? 1 : 0,
69
+ error: null,
70
+ errorUpdatedAt: 0,
71
+ errorUpdateCount: 0,
72
+ fetchFailureCount: 0,
73
+ fetchFailureReason: null,
74
+ fetchMeta: null,
75
+ invalidated: false,
76
+ status: hasSeedData ? "success" : seed?.status ?? "pending",
77
+ fetchPhase: "idle"
78
+ };
79
+ }
80
+ /** Pure state transition function for a `QueryEntry`. */
81
+ function reduceQueryState(state, action) {
82
+ switch (action.type) {
83
+ case "fetch": return {
84
+ ...state,
85
+ fetchPhase: "fetching",
86
+ fetchMeta: action.meta ?? null,
87
+ fetchFailureCount: 0,
88
+ fetchFailureReason: null
89
+ };
90
+ case "pause": return state.fetchPhase === "fetching" ? {
91
+ ...state,
92
+ fetchPhase: "paused"
93
+ } : state;
94
+ case "continue": return state.fetchPhase === "paused" ? {
95
+ ...state,
96
+ fetchPhase: "fetching"
97
+ } : state;
98
+ case "fail": return {
99
+ ...state,
100
+ fetchFailureCount: state.fetchFailureCount + 1,
101
+ fetchFailureReason: action.error
102
+ };
103
+ case "success": {
104
+ const nextData = action.structuralSharing ? keepEqual(state.data, action.data) : action.data;
105
+ const keepPrevData = nextData === void 0;
106
+ return {
107
+ ...state,
108
+ data: keepPrevData ? state.data : nextData,
109
+ dataUpdatedAt: action.updatedAt,
110
+ dataUpdateCount: state.dataUpdateCount + 1,
111
+ error: null,
112
+ errorUpdatedAt: state.errorUpdatedAt,
113
+ fetchFailureCount: 0,
114
+ fetchFailureReason: null,
115
+ invalidated: false,
116
+ status: "success",
117
+ fetchPhase: "idle"
118
+ };
119
+ }
120
+ case "error": return {
121
+ ...state,
122
+ error: action.error,
123
+ errorUpdatedAt: action.updatedAt,
124
+ errorUpdateCount: state.errorUpdateCount + 1,
125
+ fetchFailureCount: state.fetchFailureCount + 1,
126
+ fetchFailureReason: action.error,
127
+ status: "error",
128
+ fetchPhase: "idle"
129
+ };
130
+ case "cancel": return action.revert ?? {
131
+ ...state,
132
+ fetchPhase: "idle"
133
+ };
134
+ case "invalidate": return {
135
+ ...state,
136
+ invalidated: true
137
+ };
138
+ case "setData": {
139
+ const nextData = action.structuralSharing ? keepEqual(state.data, action.data) : action.data;
140
+ return {
141
+ ...state,
142
+ data: nextData,
143
+ dataUpdatedAt: action.updatedAt,
144
+ dataUpdateCount: state.dataUpdateCount + 1,
145
+ error: null,
146
+ invalidated: false,
147
+ status: "success"
148
+ };
149
+ }
150
+ }
151
+ }
152
+ /** Builds a discriminated `QuerySnapshot` from raw entry state and selected data. */
153
+ function deriveQuerySnapshot(input) {
154
+ const { state, selectedData, isPlaceholder, isFetchedAfterMount, staleTime, now, refetch, promise } = input;
155
+ const isFetching = state.fetchPhase === "fetching";
156
+ const isPaused = state.fetchPhase === "paused";
157
+ const isStale = isPlaceholder || isEntryStale(state, staleTime, now);
158
+ const isFetched = state.dataUpdateCount > 0 || state.errorUpdateCount > 0;
159
+ const hasError = state.status === "error" && state.error !== null;
160
+ const effectiveData = selectedData;
161
+ const hasData = effectiveData !== void 0;
162
+ if (isPlaceholder && hasData) return {
163
+ status: "success",
164
+ data: effectiveData,
165
+ error: null,
166
+ dataUpdatedAt: state.dataUpdatedAt,
167
+ errorUpdatedAt: state.errorUpdatedAt,
168
+ failureCount: state.fetchFailureCount,
169
+ failureReason: state.fetchFailureReason,
170
+ errorUpdateCount: state.errorUpdateCount,
171
+ fetchPhase: state.fetchPhase,
172
+ isPending: false,
173
+ isLoading: false,
174
+ isInitialLoading: false,
175
+ isError: false,
176
+ isLoadingError: false,
177
+ isRefetchError: false,
178
+ isSuccess: true,
179
+ isFetching,
180
+ isPaused,
181
+ isPlaceholderData: true,
182
+ isRefetching: isFetching,
183
+ isStale,
184
+ isFetched,
185
+ isFetchedAfterMount,
186
+ refetch,
187
+ promise
188
+ };
189
+ if (hasError && !hasData) return {
190
+ status: "error",
191
+ data: void 0,
192
+ error: state.error,
193
+ dataUpdatedAt: state.dataUpdatedAt,
194
+ errorUpdatedAt: state.errorUpdatedAt,
195
+ failureCount: state.fetchFailureCount,
196
+ failureReason: state.fetchFailureReason,
197
+ errorUpdateCount: state.errorUpdateCount,
198
+ fetchPhase: state.fetchPhase,
199
+ isPending: false,
200
+ isLoading: false,
201
+ isInitialLoading: false,
202
+ isError: true,
203
+ isLoadingError: true,
204
+ isRefetchError: false,
205
+ isSuccess: false,
206
+ isFetching,
207
+ isPaused,
208
+ isPlaceholderData: false,
209
+ isRefetching: isFetching,
210
+ isStale,
211
+ isFetched,
212
+ isFetchedAfterMount,
213
+ refetch,
214
+ promise
215
+ };
216
+ if (hasError && hasData) return {
217
+ status: "error",
218
+ data: effectiveData,
219
+ error: state.error,
220
+ dataUpdatedAt: state.dataUpdatedAt,
221
+ errorUpdatedAt: state.errorUpdatedAt,
222
+ failureCount: state.fetchFailureCount,
223
+ failureReason: state.fetchFailureReason,
224
+ errorUpdateCount: state.errorUpdateCount,
225
+ fetchPhase: state.fetchPhase,
226
+ isPending: false,
227
+ isLoading: false,
228
+ isInitialLoading: false,
229
+ isError: true,
230
+ isLoadingError: false,
231
+ isRefetchError: true,
232
+ isSuccess: false,
233
+ isFetching,
234
+ isPaused,
235
+ isPlaceholderData: false,
236
+ isRefetching: isFetching,
237
+ isStale,
238
+ isFetched,
239
+ isFetchedAfterMount,
240
+ refetch,
241
+ promise
242
+ };
243
+ if (state.status === "success" && hasData) return {
244
+ status: "success",
245
+ data: effectiveData,
246
+ error: null,
247
+ dataUpdatedAt: state.dataUpdatedAt,
248
+ errorUpdatedAt: state.errorUpdatedAt,
249
+ failureCount: state.fetchFailureCount,
250
+ failureReason: state.fetchFailureReason,
251
+ errorUpdateCount: state.errorUpdateCount,
252
+ fetchPhase: state.fetchPhase,
253
+ isPending: false,
254
+ isLoading: false,
255
+ isInitialLoading: false,
256
+ isError: false,
257
+ isLoadingError: false,
258
+ isRefetchError: false,
259
+ isSuccess: true,
260
+ isFetching,
261
+ isPaused,
262
+ isPlaceholderData: false,
263
+ isRefetching: isFetching,
264
+ isStale,
265
+ isFetched,
266
+ isFetchedAfterMount,
267
+ refetch,
268
+ promise
269
+ };
270
+ const isLoading = isFetching;
271
+ return {
272
+ status: "pending",
273
+ data: void 0,
274
+ error: null,
275
+ dataUpdatedAt: state.dataUpdatedAt,
276
+ errorUpdatedAt: state.errorUpdatedAt,
277
+ failureCount: state.fetchFailureCount,
278
+ failureReason: state.fetchFailureReason,
279
+ errorUpdateCount: state.errorUpdateCount,
280
+ fetchPhase: state.fetchPhase,
281
+ isPending: true,
282
+ isLoading,
283
+ isInitialLoading: isLoading,
284
+ isError: false,
285
+ isLoadingError: false,
286
+ isRefetchError: false,
287
+ isSuccess: false,
288
+ isFetching,
289
+ isPaused,
290
+ isPlaceholderData: false,
291
+ isRefetching: false,
292
+ isStale,
293
+ isFetched,
294
+ isFetchedAfterMount,
295
+ refetch,
296
+ promise
297
+ };
298
+ }
299
+ /** Derives an `InfiniteSnapshot` from a base snapshot plus pagination flags. */
300
+ function deriveInfiniteSnapshot(base, pagination) {
301
+ return {
302
+ ...base,
303
+ ...pagination
304
+ };
305
+ }
306
+ /** Creates initial state for a `Mutation`. */
307
+ function initialMutationState() {
308
+ return {
309
+ context: void 0,
310
+ data: void 0,
311
+ error: null,
312
+ failureCount: 0,
313
+ failureReason: null,
314
+ isPaused: false,
315
+ status: "idle",
316
+ variables: void 0,
317
+ submittedAt: 0
318
+ };
319
+ }
320
+ /** Pure state transition function for a `MutationEntry`. */
321
+ function reduceMutationState(state, action) {
322
+ switch (action.type) {
323
+ case "pending": return {
324
+ ...state,
325
+ context: action.context,
326
+ data: void 0,
327
+ error: null,
328
+ failureCount: 0,
329
+ failureReason: null,
330
+ isPaused: false,
331
+ status: "pending",
332
+ variables: action.variables,
333
+ submittedAt: action.submittedAt
334
+ };
335
+ case "context": return {
336
+ ...state,
337
+ context: action.context
338
+ };
339
+ case "fail": return state.status === "pending" ? {
340
+ ...state,
341
+ failureCount: state.failureCount + 1,
342
+ failureReason: action.error
343
+ } : state;
344
+ case "pause": return state.status === "pending" ? {
345
+ ...state,
346
+ isPaused: true
347
+ } : state;
348
+ case "continue": return state.status === "pending" ? {
349
+ ...state,
350
+ isPaused: false
351
+ } : state;
352
+ case "success": return {
353
+ ...state,
354
+ data: action.data,
355
+ error: null,
356
+ failureCount: 0,
357
+ failureReason: null,
358
+ isPaused: false,
359
+ status: "success"
360
+ };
361
+ case "error": return {
362
+ ...state,
363
+ data: void 0,
364
+ error: action.error,
365
+ failureCount: state.failureCount + 1,
366
+ failureReason: action.error,
367
+ isPaused: false,
368
+ status: "error"
369
+ };
370
+ }
371
+ }
372
+ /** Derives a public discriminated `MutationSnapshot`. */
373
+ function deriveMutationSnapshot(state, commands) {
374
+ const shared = {
375
+ variables: state.variables,
376
+ context: state.context,
377
+ failureCount: state.failureCount,
378
+ failureReason: state.failureReason,
379
+ isPaused: state.isPaused,
380
+ submittedAt: state.submittedAt,
381
+ ...commands
382
+ };
383
+ if (state.status === "pending") return {
384
+ ...shared,
385
+ status: "pending",
386
+ data: void 0,
387
+ error: null,
388
+ isIdle: false,
389
+ isPending: true,
390
+ isError: false,
391
+ isSuccess: false,
392
+ variables: state.variables
393
+ };
394
+ if (state.status === "error") return {
395
+ ...shared,
396
+ status: "error",
397
+ data: void 0,
398
+ error: state.error,
399
+ isIdle: false,
400
+ isPending: false,
401
+ isError: true,
402
+ isSuccess: false,
403
+ variables: state.variables
404
+ };
405
+ if (state.status === "success") return {
406
+ ...shared,
407
+ status: "success",
408
+ data: state.data,
409
+ error: null,
410
+ isIdle: false,
411
+ isPending: false,
412
+ isError: false,
413
+ isSuccess: true,
414
+ variables: state.variables
415
+ };
416
+ return {
417
+ ...shared,
418
+ status: "idle",
419
+ data: void 0,
420
+ error: null,
421
+ isIdle: true,
422
+ isPending: false,
423
+ isError: false,
424
+ isSuccess: false
425
+ };
426
+ }
427
+ // src/pure/hydration.ts
428
+ function defaultShouldDehydrateQuery(record) {
429
+ return record.state.status === "success";
430
+ }
431
+ function defaultShouldDehydrateMutation(record) {
432
+ return record.state.isPaused;
433
+ }
434
+ /** Converts live cache records into a serializable `DehydratedCache` snapshot. */
435
+ function packCache(queries, mutations, options = {}) {
436
+ const shouldQuery = options.shouldDehydrateQuery ?? defaultShouldDehydrateQuery;
437
+ const shouldMutation = options.shouldDehydrateMutation ?? defaultShouldDehydrateMutation;
438
+ const serializeData = options.serializeData;
439
+ const outQueries = [];
440
+ for (const q of queries) {
441
+ if (!shouldQuery(q)) continue;
442
+ const rawData = q.state.data;
443
+ const data = serializeData && rawData !== void 0 ? serializeData(rawData) : rawData;
444
+ const isPendingWithPromise = q.state.status === "pending" && q.promise !== void 0;
445
+ outQueries.push({
446
+ queryHash: q.queryHash,
447
+ queryKey: q.queryKey,
448
+ state: {
449
+ ...q.state,
450
+ data,
451
+ fetchPhase: isPendingWithPromise ? "fetching" : "idle"
452
+ },
453
+ ...q.meta !== void 0 ? { meta: q.meta } : {},
454
+ ...isPendingWithPromise ? { promise: q.promise } : {}
455
+ });
456
+ }
457
+ const outMutations = [];
458
+ for (const m of mutations) {
459
+ if (!shouldMutation({
460
+ mutationKey: m.mutationKey,
461
+ state: m.state
462
+ })) continue;
463
+ outMutations.push({
464
+ state: m.state,
465
+ ...m.mutationKey !== void 0 ? { mutationKey: m.mutationKey } : {},
466
+ ...m.meta !== void 0 ? { meta: m.meta } : {},
467
+ ...m.scope !== void 0 ? { scope: m.scope } : {}
468
+ });
469
+ }
470
+ return {
471
+ queries: outQueries,
472
+ mutations: outMutations
473
+ };
474
+ }
475
+ /** Filters dehydrated queries to those fresher than existing cache entries and deserializes data. */
476
+ function selectHydrateQueries(cache, existingUpdatedAt, options = {}) {
477
+ const deserialize = options.deserializeData;
478
+ const accepted = [];
479
+ for (const entry of cache.queries) {
480
+ const existingTs = existingUpdatedAt(entry.queryHash);
481
+ if (existingTs !== void 0 && existingTs >= entry.state.dataUpdatedAt) continue;
482
+ const rawData = entry.state.data;
483
+ const data = deserialize && rawData !== void 0 ? deserialize(rawData) : rawData;
484
+ accepted.push({
485
+ ...entry,
486
+ state: {
487
+ ...entry.state,
488
+ data
489
+ }
490
+ });
491
+ }
492
+ return accepted;
493
+ }
494
+ export { DATA_TAG, ERROR_TAG, clampPages, computeBackoffMs, defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, deriveInfiniteSnapshot, deriveMutationSnapshot, deriveQuerySnapshot, infiniteQuerySpec, initialMutationState, initialQueryState, isEntryStale, isPlainObject, keepEqual, keepPrevious, keyStartsWith, matchesMutationFilter, matchesQueryFilter, mutationSpec, packCache, partialMatchValue, querySpec, reduceMutationState, reduceQueryState, resolveNetworkAction, resolveStaleMs, selectHydrateQueries, serializeKey, shouldRetryAttempt, skipToken };
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@bevelo/query",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Async server-state caching, deduplication, retry, hydration and observer engine.",
6
+ "main": "./dist/live/index.cjs",
7
+ "module": "./dist/live/index.js",
8
+ "types": "./dist/live/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/live/index.d.ts",
12
+ "import": "./dist/live/index.js",
13
+ "require": "./dist/live/index.cjs"
14
+ },
15
+ "./core": {
16
+ "types": "./dist/pure/index.d.ts",
17
+ "import": "./dist/pure/index.js",
18
+ "require": "./dist/pure/index.cjs"
19
+ },
20
+ "./persist": {
21
+ "types": "./dist/live/persist.d.ts",
22
+ "import": "./dist/live/persist.js",
23
+ "require": "./dist/live/persist.cjs"
24
+ },
25
+ "./broadcast": {
26
+ "types": "./dist/live/broadcast.d.ts",
27
+ "import": "./dist/live/broadcast.js",
28
+ "require": "./dist/live/broadcast.cjs"
29
+ }
30
+ },
31
+ "dependencies": {
32
+ "@bevelo/runtime": "0.1.0"
33
+ },
34
+ "sideEffects": false,
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "license": "MIT",
39
+ "homepage": "https://github.com/bevelo/bevelo#readme",
40
+ "bugs": {
41
+ "url": "https://github.com/bevelo/bevelo/issues"
42
+ },
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "https://github.com/bevelo/bevelo.git",
46
+ "directory": "packages/query"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "scripts": {
52
+ "build": "vp pack",
53
+ "typecheck": "tsc -p tsconfig.json",
54
+ "test": "vp test run"
55
+ }
6
56
  }