houdini 1.0.0-next.3 → 1.0.0-next.5
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/build/cmd-cjs/index.js +1254 -1062
- package/build/cmd-esm/index.js +1254 -1062
- package/build/codegen/generators/artifacts/selection.d.ts +3 -3
- package/build/codegen/generators/artifacts/utils.d.ts +0 -1
- package/build/codegen-cjs/index.js +847 -717
- package/build/codegen-esm/index.js +847 -717
- package/build/lib/config.d.ts +10 -90
- package/build/lib/deepMerge.d.ts +1 -0
- package/build/lib/graphql.d.ts +5 -2
- package/build/lib/index.d.ts +2 -0
- package/build/lib/pipeline.d.ts +1 -1
- package/build/lib/plugin.d.ts +2 -0
- package/build/lib/types.d.ts +250 -2
- package/build/lib-cjs/index.js +351 -162
- package/build/lib-esm/index.js +349 -162
- package/build/runtime/cache/cache.d.ts +23 -6
- package/build/runtime/cache/staleManager.d.ts +30 -0
- package/build/runtime/cache/subscription.d.ts +2 -1
- package/build/runtime/client/documentStore.d.ts +1 -1
- package/build/runtime/client/plugins/fetchParams.d.ts +1 -1
- package/build/runtime/client/plugins/subscription.d.ts +1 -2
- package/build/runtime/lib/config.d.ts +4 -0
- package/build/runtime/lib/index.d.ts +1 -0
- package/build/runtime/lib/key.d.ts +6 -0
- package/build/runtime/lib/types.d.ts +4 -5
- package/build/runtime/public/cache.d.ts +8 -1
- package/build/runtime/public/record.d.ts +11 -1
- package/build/runtime/public/tests/test.d.ts +9 -10
- package/build/runtime-cjs/cache/cache.d.ts +23 -6
- package/build/runtime-cjs/cache/cache.js +95 -21
- package/build/runtime-cjs/cache/gc.js +9 -0
- package/build/runtime-cjs/cache/lists.js +3 -3
- package/build/runtime-cjs/cache/staleManager.d.ts +30 -0
- package/build/runtime-cjs/cache/staleManager.js +95 -0
- package/build/runtime-cjs/cache/subscription.d.ts +2 -1
- package/build/runtime-cjs/cache/subscription.js +6 -3
- package/build/runtime-cjs/client/documentStore.d.ts +1 -1
- package/build/runtime-cjs/client/documentStore.js +1 -0
- package/build/runtime-cjs/client/plugins/cache.js +5 -3
- package/build/runtime-cjs/client/plugins/fetch.js +1 -0
- package/build/runtime-cjs/client/plugins/fetchParams.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/fetchParams.js +6 -1
- package/build/runtime-cjs/client/plugins/query.js +1 -1
- package/build/runtime-cjs/client/plugins/subscription.d.ts +1 -2
- package/build/runtime-cjs/client/plugins/subscription.js +2 -0
- package/build/runtime-cjs/lib/config.d.ts +4 -0
- package/build/runtime-cjs/lib/index.d.ts +1 -0
- package/build/runtime-cjs/lib/index.js +1 -0
- package/build/runtime-cjs/lib/key.d.ts +6 -0
- package/build/runtime-cjs/lib/key.js +41 -0
- package/build/runtime-cjs/lib/types.d.ts +4 -5
- package/build/runtime-cjs/public/cache.d.ts +8 -1
- package/build/runtime-cjs/public/cache.js +3 -0
- package/build/runtime-cjs/public/record.d.ts +11 -1
- package/build/runtime-cjs/public/record.js +8 -1
- package/build/runtime-cjs/public/tests/test.d.ts +9 -10
- package/build/runtime-esm/cache/cache.d.ts +23 -6
- package/build/runtime-esm/cache/cache.js +96 -22
- package/build/runtime-esm/cache/gc.js +9 -0
- package/build/runtime-esm/cache/lists.js +3 -3
- package/build/runtime-esm/cache/staleManager.d.ts +30 -0
- package/build/runtime-esm/cache/staleManager.js +71 -0
- package/build/runtime-esm/cache/subscription.d.ts +2 -1
- package/build/runtime-esm/cache/subscription.js +6 -3
- package/build/runtime-esm/client/documentStore.d.ts +1 -1
- package/build/runtime-esm/client/documentStore.js +1 -0
- package/build/runtime-esm/client/plugins/cache.js +5 -3
- package/build/runtime-esm/client/plugins/fetch.js +1 -0
- package/build/runtime-esm/client/plugins/fetchParams.d.ts +1 -1
- package/build/runtime-esm/client/plugins/fetchParams.js +6 -1
- package/build/runtime-esm/client/plugins/query.js +1 -1
- package/build/runtime-esm/client/plugins/subscription.d.ts +1 -2
- package/build/runtime-esm/client/plugins/subscription.js +2 -0
- package/build/runtime-esm/lib/config.d.ts +4 -0
- package/build/runtime-esm/lib/index.d.ts +1 -0
- package/build/runtime-esm/lib/index.js +1 -0
- package/build/runtime-esm/lib/key.d.ts +6 -0
- package/build/runtime-esm/lib/key.js +17 -0
- package/build/runtime-esm/lib/types.d.ts +4 -5
- package/build/runtime-esm/public/cache.d.ts +8 -1
- package/build/runtime-esm/public/cache.js +3 -0
- package/build/runtime-esm/public/record.d.ts +11 -1
- package/build/runtime-esm/public/record.js +8 -1
- package/build/runtime-esm/public/tests/test.d.ts +9 -10
- package/build/test-cjs/index.js +930 -788
- package/build/test-esm/index.js +930 -788
- package/build/vite-cjs/index.js +1232 -1039
- package/build/vite-esm/index.js +1232 -1039
- package/package.json +3 -2
|
@@ -22,12 +22,14 @@ __export(cache_exports, {
|
|
|
22
22
|
rootID: () => rootID
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(cache_exports);
|
|
25
|
+
var import_lib = require("../lib");
|
|
25
26
|
var import_config = require("../lib/config");
|
|
26
27
|
var import_deepEquals = require("../lib/deepEquals");
|
|
27
28
|
var import_selection = require("../lib/selection");
|
|
28
29
|
var import_gc = require("./gc");
|
|
29
30
|
var import_lists = require("./lists");
|
|
30
31
|
var import_schema = require("./schema");
|
|
32
|
+
var import_staleManager = require("./staleManager");
|
|
31
33
|
var import_storage = require("./storage");
|
|
32
34
|
var import_stuff = require("./stuff");
|
|
33
35
|
var import_subscription = require("./subscription");
|
|
@@ -40,6 +42,7 @@ class Cache {
|
|
|
40
42
|
subscriptions: new import_subscription.InMemorySubscriptions(this),
|
|
41
43
|
lists: new import_lists.ListManager(this, rootID),
|
|
42
44
|
lifetimes: new import_gc.GarbageCollector(this),
|
|
45
|
+
staleManager: new import_staleManager.StaleManager(this),
|
|
43
46
|
schema: new import_schema.SchemaManager(this)
|
|
44
47
|
});
|
|
45
48
|
if (config) {
|
|
@@ -69,13 +72,14 @@ class Cache {
|
|
|
69
72
|
return subscribers;
|
|
70
73
|
}
|
|
71
74
|
read(...args) {
|
|
72
|
-
const { data, partial, hasData } = this._internal_unstable.getSelection(...args);
|
|
75
|
+
const { data, partial, stale, hasData } = this._internal_unstable.getSelection(...args);
|
|
73
76
|
if (!hasData) {
|
|
74
|
-
return { data: null, partial: false };
|
|
77
|
+
return { data: null, partial: false, stale: false };
|
|
75
78
|
}
|
|
76
79
|
return {
|
|
77
80
|
data,
|
|
78
|
-
partial
|
|
81
|
+
partial,
|
|
82
|
+
stale
|
|
79
83
|
};
|
|
80
84
|
}
|
|
81
85
|
subscribe(spec, variables = {}) {
|
|
@@ -111,6 +115,30 @@ class Cache {
|
|
|
111
115
|
setConfig(config) {
|
|
112
116
|
this._internal_unstable.setConfig(config);
|
|
113
117
|
}
|
|
118
|
+
markTypeStale(type, options = {}) {
|
|
119
|
+
if (!type) {
|
|
120
|
+
this._internal_unstable.staleManager.markAllStale();
|
|
121
|
+
} else if (!options.field) {
|
|
122
|
+
this._internal_unstable.staleManager.markTypeStale(type);
|
|
123
|
+
} else {
|
|
124
|
+
this._internal_unstable.staleManager.markTypeFieldStale(
|
|
125
|
+
type,
|
|
126
|
+
options.field,
|
|
127
|
+
options.when
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
markRecordStale(id, options) {
|
|
132
|
+
if (options.field) {
|
|
133
|
+
const key = (0, import_lib.computeKey)({ field: options.field, args: options.when ?? {} });
|
|
134
|
+
this._internal_unstable.staleManager.markFieldStale(id, key);
|
|
135
|
+
} else {
|
|
136
|
+
this._internal_unstable.staleManager.markRecordStale(id);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
getFieldTime(id, field) {
|
|
140
|
+
return this._internal_unstable.staleManager.getFieldTime(id, field);
|
|
141
|
+
}
|
|
114
142
|
}
|
|
115
143
|
class CacheInternal {
|
|
116
144
|
_disabled = false;
|
|
@@ -126,6 +154,7 @@ class CacheInternal {
|
|
|
126
154
|
lists;
|
|
127
155
|
cache;
|
|
128
156
|
lifetimes;
|
|
157
|
+
staleManager;
|
|
129
158
|
schema;
|
|
130
159
|
constructor({
|
|
131
160
|
storage,
|
|
@@ -133,6 +162,7 @@ class CacheInternal {
|
|
|
133
162
|
lists,
|
|
134
163
|
cache,
|
|
135
164
|
lifetimes,
|
|
165
|
+
staleManager,
|
|
136
166
|
schema
|
|
137
167
|
}) {
|
|
138
168
|
this.storage = storage;
|
|
@@ -140,6 +170,7 @@ class CacheInternal {
|
|
|
140
170
|
this.lists = lists;
|
|
141
171
|
this.cache = cache;
|
|
142
172
|
this.lifetimes = lifetimes;
|
|
173
|
+
this.staleManager = staleManager;
|
|
143
174
|
this.schema = schema;
|
|
144
175
|
this._disabled = typeof globalThis.window === "undefined";
|
|
145
176
|
try {
|
|
@@ -157,10 +188,11 @@ class CacheInternal {
|
|
|
157
188
|
selection,
|
|
158
189
|
variables = {},
|
|
159
190
|
parent = rootID,
|
|
160
|
-
applyUpdates
|
|
191
|
+
applyUpdates,
|
|
161
192
|
layer,
|
|
162
193
|
toNotify = [],
|
|
163
|
-
forceNotify
|
|
194
|
+
forceNotify,
|
|
195
|
+
forceStale
|
|
164
196
|
}) {
|
|
165
197
|
if (this._disabled) {
|
|
166
198
|
return [];
|
|
@@ -178,7 +210,7 @@ class CacheInternal {
|
|
|
178
210
|
selection: fieldSelection,
|
|
179
211
|
operations,
|
|
180
212
|
abstract: isAbstract,
|
|
181
|
-
|
|
213
|
+
updates,
|
|
182
214
|
nullable
|
|
183
215
|
} = targetSelection[field];
|
|
184
216
|
const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
|
|
@@ -195,16 +227,31 @@ class CacheInternal {
|
|
|
195
227
|
const displayLayer = layer.isDisplayLayer(displayLayers);
|
|
196
228
|
if (displayLayer) {
|
|
197
229
|
this.lifetimes.resetLifetime(parent, key);
|
|
230
|
+
if (forceStale) {
|
|
231
|
+
this.staleManager.markFieldStale(parent, key);
|
|
232
|
+
} else {
|
|
233
|
+
this.staleManager.setFieldTimeToNow(parent, key);
|
|
234
|
+
}
|
|
198
235
|
}
|
|
199
236
|
if (!fieldSelection) {
|
|
200
237
|
let newValue = value;
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
238
|
+
if (updates && applyUpdates && Array.isArray(value)) {
|
|
239
|
+
for (const update of applyUpdates) {
|
|
240
|
+
if (!updates.includes(update)) {
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
if (update === "append") {
|
|
244
|
+
newValue = (previousValue || []).concat(value);
|
|
245
|
+
} else if (update === "prepend") {
|
|
246
|
+
newValue = value.concat(previousValue || []);
|
|
247
|
+
}
|
|
206
248
|
}
|
|
207
249
|
}
|
|
250
|
+
if (updates && applyUpdates?.includes("prepend") && ["endCursor", "hasNextPage"].includes(key)) {
|
|
251
|
+
newValue = previousValue;
|
|
252
|
+
} else if (updates && applyUpdates?.includes("append") && ["startCursor", "hasPreviousPage"].includes(key)) {
|
|
253
|
+
newValue = previousValue;
|
|
254
|
+
}
|
|
208
255
|
const valueChanged = !(0, import_deepEquals.deepEquals)(newValue, previousValue);
|
|
209
256
|
if (displayLayer && (valueChanged || forceNotify)) {
|
|
210
257
|
toNotify.push(...currentSubscribers);
|
|
@@ -264,7 +311,7 @@ class CacheInternal {
|
|
|
264
311
|
}
|
|
265
312
|
} else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
|
|
266
313
|
let oldIDs = [...previousValue || []];
|
|
267
|
-
const emptyEdges = !
|
|
314
|
+
const emptyEdges = !updates ? [] : oldIDs.map((id) => {
|
|
268
315
|
if (!id) {
|
|
269
316
|
return "";
|
|
270
317
|
}
|
|
@@ -292,7 +339,7 @@ class CacheInternal {
|
|
|
292
339
|
layer,
|
|
293
340
|
forceNotify
|
|
294
341
|
});
|
|
295
|
-
if (applyUpdates &&
|
|
342
|
+
if (applyUpdates && updates) {
|
|
296
343
|
if (key === "edges") {
|
|
297
344
|
const newNodeIDs = [];
|
|
298
345
|
for (const id of newIDs) {
|
|
@@ -320,12 +367,17 @@ class CacheInternal {
|
|
|
320
367
|
return true;
|
|
321
368
|
});
|
|
322
369
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
370
|
+
for (const update of applyUpdates) {
|
|
371
|
+
if (update !== "replace" && !updates.includes(update)) {
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
if (update === "prepend") {
|
|
375
|
+
linkedIDs = newIDs.concat(oldIDs);
|
|
376
|
+
} else if (update === "append") {
|
|
377
|
+
linkedIDs = oldIDs.concat(newIDs);
|
|
378
|
+
} else if (update === "replace") {
|
|
379
|
+
linkedIDs = newIDs;
|
|
380
|
+
}
|
|
329
381
|
}
|
|
330
382
|
} else {
|
|
331
383
|
linkedIDs = nestedIDs;
|
|
@@ -411,12 +463,13 @@ class CacheInternal {
|
|
|
411
463
|
stepsFromConnection = null
|
|
412
464
|
}) {
|
|
413
465
|
if (parent === null) {
|
|
414
|
-
return { data: null, partial: false, hasData: true };
|
|
466
|
+
return { data: null, partial: false, stale: false, hasData: true };
|
|
415
467
|
}
|
|
416
468
|
const target = {};
|
|
417
469
|
let hasData = false;
|
|
418
470
|
let partial = false;
|
|
419
471
|
let cascadeNull = false;
|
|
472
|
+
let stale = false;
|
|
420
473
|
const typename = this.storage.get(parent, "__typename").value;
|
|
421
474
|
let targetSelection = (0, import_selection.getFieldsForType)(selection, typename);
|
|
422
475
|
for (const [
|
|
@@ -425,6 +478,10 @@ class CacheInternal {
|
|
|
425
478
|
] of Object.entries(targetSelection)) {
|
|
426
479
|
const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
|
|
427
480
|
const { value } = this.storage.get(parent, key);
|
|
481
|
+
const dt_field = this.staleManager.getFieldTime(parent, key);
|
|
482
|
+
if (dt_field === null) {
|
|
483
|
+
stale = true;
|
|
484
|
+
}
|
|
428
485
|
let nextStep = stepsFromConnection;
|
|
429
486
|
if (nextStep !== null) {
|
|
430
487
|
if (nextStep >= 2) {
|
|
@@ -464,6 +521,9 @@ class CacheInternal {
|
|
|
464
521
|
if (listValue.partial) {
|
|
465
522
|
partial = true;
|
|
466
523
|
}
|
|
524
|
+
if (listValue.stale) {
|
|
525
|
+
stale = true;
|
|
526
|
+
}
|
|
467
527
|
if (listValue.hasData || value.length === 0) {
|
|
468
528
|
hasData = true;
|
|
469
529
|
}
|
|
@@ -478,6 +538,9 @@ class CacheInternal {
|
|
|
478
538
|
if (objectFields.partial) {
|
|
479
539
|
partial = true;
|
|
480
540
|
}
|
|
541
|
+
if (objectFields.stale) {
|
|
542
|
+
stale = true;
|
|
543
|
+
}
|
|
481
544
|
if (objectFields.hasData) {
|
|
482
545
|
hasData = true;
|
|
483
546
|
}
|
|
@@ -489,6 +552,7 @@ class CacheInternal {
|
|
|
489
552
|
return {
|
|
490
553
|
data: cascadeNull ? null : target,
|
|
491
554
|
partial: hasData && partial,
|
|
555
|
+
stale: hasData && stale,
|
|
492
556
|
hasData
|
|
493
557
|
};
|
|
494
558
|
}
|
|
@@ -516,6 +580,7 @@ class CacheInternal {
|
|
|
516
580
|
}) {
|
|
517
581
|
const result = [];
|
|
518
582
|
let partialData = false;
|
|
583
|
+
let stale = false;
|
|
519
584
|
let hasValues = false;
|
|
520
585
|
for (const entry of linkedList) {
|
|
521
586
|
if (Array.isArray(entry)) {
|
|
@@ -535,7 +600,12 @@ class CacheInternal {
|
|
|
535
600
|
result.push(entry);
|
|
536
601
|
continue;
|
|
537
602
|
}
|
|
538
|
-
const {
|
|
603
|
+
const {
|
|
604
|
+
data,
|
|
605
|
+
partial,
|
|
606
|
+
stale: local_stale,
|
|
607
|
+
hasData
|
|
608
|
+
} = this.getSelection({
|
|
539
609
|
parent: entry,
|
|
540
610
|
selection: fields,
|
|
541
611
|
variables,
|
|
@@ -545,6 +615,9 @@ class CacheInternal {
|
|
|
545
615
|
if (partial) {
|
|
546
616
|
partialData = true;
|
|
547
617
|
}
|
|
618
|
+
if (local_stale) {
|
|
619
|
+
stale = true;
|
|
620
|
+
}
|
|
548
621
|
if (hasData) {
|
|
549
622
|
hasValues = true;
|
|
550
623
|
}
|
|
@@ -552,6 +625,7 @@ class CacheInternal {
|
|
|
552
625
|
return {
|
|
553
626
|
data: result,
|
|
554
627
|
partial: partialData,
|
|
628
|
+
stale,
|
|
555
629
|
hasData: hasValues
|
|
556
630
|
};
|
|
557
631
|
}
|
|
@@ -37,6 +37,8 @@ class GarbageCollector {
|
|
|
37
37
|
this.lifetimes.get(id).set(field, 0);
|
|
38
38
|
}
|
|
39
39
|
tick() {
|
|
40
|
+
const dt_tick = Date.now().valueOf();
|
|
41
|
+
const config_max_time = this.cache._internal_unstable.config.defaultLifetime;
|
|
40
42
|
for (const [id, fieldMap] of this.lifetimes.entries()) {
|
|
41
43
|
for (const [field, lifetime] of fieldMap.entries()) {
|
|
42
44
|
if (this.cache._internal_unstable.subscriptions.get(id, field).length > 0) {
|
|
@@ -50,6 +52,13 @@ class GarbageCollector {
|
|
|
50
52
|
if ([...fieldMap.keys()].length === 0) {
|
|
51
53
|
this.lifetimes.delete(id);
|
|
52
54
|
}
|
|
55
|
+
this.cache._internal_unstable.staleManager.delete(id, field);
|
|
56
|
+
}
|
|
57
|
+
if (config_max_time && config_max_time > 0) {
|
|
58
|
+
const dt_valueOf = this.cache.getFieldTime(id, field);
|
|
59
|
+
if (dt_valueOf && dt_tick - dt_valueOf > config_max_time) {
|
|
60
|
+
this.cache._internal_unstable.staleManager.markFieldStale(id, field);
|
|
61
|
+
}
|
|
53
62
|
}
|
|
54
63
|
}
|
|
55
64
|
}
|
|
@@ -176,7 +176,7 @@ class List {
|
|
|
176
176
|
edges: {
|
|
177
177
|
keyRaw: "edges",
|
|
178
178
|
type: "ConnectionEdge",
|
|
179
|
-
|
|
179
|
+
updates: ["append", "prepend"],
|
|
180
180
|
selection: {
|
|
181
181
|
fields: {
|
|
182
182
|
node: {
|
|
@@ -212,7 +212,7 @@ class List {
|
|
|
212
212
|
newEntries: {
|
|
213
213
|
keyRaw: this.key,
|
|
214
214
|
type: listType,
|
|
215
|
-
|
|
215
|
+
updates: ["append", "prepend"],
|
|
216
216
|
selection: {
|
|
217
217
|
...selection,
|
|
218
218
|
fields: {
|
|
@@ -235,7 +235,7 @@ class List {
|
|
|
235
235
|
data: insertData,
|
|
236
236
|
variables,
|
|
237
237
|
parent: this.recordID,
|
|
238
|
-
applyUpdates:
|
|
238
|
+
applyUpdates: [where === "first" ? "prepend" : "append"]
|
|
239
239
|
});
|
|
240
240
|
}
|
|
241
241
|
removeID(id, variables = {}) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Cache } from './cache';
|
|
2
|
+
export declare class StaleManager {
|
|
3
|
+
#private;
|
|
4
|
+
cache: Cache;
|
|
5
|
+
private fieldsTime;
|
|
6
|
+
constructor(cache: Cache);
|
|
7
|
+
/**
|
|
8
|
+
* get the FieldTime info
|
|
9
|
+
* @param id User:1
|
|
10
|
+
* @param field firstName
|
|
11
|
+
*/
|
|
12
|
+
getFieldTime(id: string, field: string): number | undefined | null;
|
|
13
|
+
/**
|
|
14
|
+
* set the date to a field
|
|
15
|
+
* @param id User:1
|
|
16
|
+
* @param field firstName
|
|
17
|
+
*/
|
|
18
|
+
setFieldTimeToNow(id: string, field: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* set null to a field (stale)
|
|
21
|
+
* @param id User:1
|
|
22
|
+
* @param field firstName
|
|
23
|
+
*/
|
|
24
|
+
markFieldStale(id: string, field: string): void;
|
|
25
|
+
markAllStale(): void;
|
|
26
|
+
markRecordStale(id: string): void;
|
|
27
|
+
markTypeStale(type: string): void;
|
|
28
|
+
markTypeFieldStale(type: string, field: string, when?: {}): void;
|
|
29
|
+
delete(id: string, field: string): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var staleManager_exports = {};
|
|
20
|
+
__export(staleManager_exports, {
|
|
21
|
+
StaleManager: () => StaleManager
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(staleManager_exports);
|
|
24
|
+
var import_lib = require("../lib");
|
|
25
|
+
class StaleManager {
|
|
26
|
+
cache;
|
|
27
|
+
fieldsTime = /* @__PURE__ */ new Map();
|
|
28
|
+
constructor(cache) {
|
|
29
|
+
this.cache = cache;
|
|
30
|
+
}
|
|
31
|
+
#initMapId = (id) => {
|
|
32
|
+
if (!this.fieldsTime.get(id)) {
|
|
33
|
+
this.fieldsTime.set(id, /* @__PURE__ */ new Map());
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
getFieldTime(id, field) {
|
|
37
|
+
return this.fieldsTime.get(id)?.get(field);
|
|
38
|
+
}
|
|
39
|
+
setFieldTimeToNow(id, field) {
|
|
40
|
+
this.#initMapId(id);
|
|
41
|
+
this.fieldsTime.get(id)?.set(field, new Date().valueOf());
|
|
42
|
+
}
|
|
43
|
+
markFieldStale(id, field) {
|
|
44
|
+
this.#initMapId(id);
|
|
45
|
+
this.fieldsTime.get(id)?.set(field, null);
|
|
46
|
+
}
|
|
47
|
+
markAllStale() {
|
|
48
|
+
for (const [id, fieldMap] of this.fieldsTime.entries()) {
|
|
49
|
+
for (const [field] of fieldMap.entries()) {
|
|
50
|
+
this.markFieldStale(id, field);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
markRecordStale(id) {
|
|
55
|
+
const fieldsTimeOfType = this.fieldsTime.get(id);
|
|
56
|
+
if (fieldsTimeOfType) {
|
|
57
|
+
for (const [field] of fieldsTimeOfType.entries()) {
|
|
58
|
+
this.markFieldStale(id, field);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
markTypeStale(type) {
|
|
63
|
+
for (const [id, fieldMap] of this.fieldsTime.entries()) {
|
|
64
|
+
if (id.startsWith(`${type}:`)) {
|
|
65
|
+
for (const [field] of fieldMap.entries()) {
|
|
66
|
+
this.markFieldStale(id, field);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
markTypeFieldStale(type, field, when) {
|
|
72
|
+
const key = (0, import_lib.computeKey)({ field, args: when });
|
|
73
|
+
for (const [id, fieldMap] of this.fieldsTime.entries()) {
|
|
74
|
+
if (id.startsWith(`${type}:`)) {
|
|
75
|
+
for (const local_field of fieldMap.keys()) {
|
|
76
|
+
if (local_field === key) {
|
|
77
|
+
this.markFieldStale(id, field);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
delete(id, field) {
|
|
84
|
+
if (this.fieldsTime.has(id)) {
|
|
85
|
+
this.fieldsTime.get(id)?.delete(field);
|
|
86
|
+
if (this.fieldsTime.get(id)?.size === 0) {
|
|
87
|
+
this.fieldsTime.delete(id);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
93
|
+
0 && (module.exports = {
|
|
94
|
+
StaleManager
|
|
95
|
+
});
|
|
@@ -19,10 +19,11 @@ export declare class InMemorySubscriptions {
|
|
|
19
19
|
[key: string]: GraphQLValue;
|
|
20
20
|
};
|
|
21
21
|
}): void;
|
|
22
|
-
addFieldSubscription({ id, key, selection, }: {
|
|
22
|
+
addFieldSubscription({ id, key, selection, type, }: {
|
|
23
23
|
id: string;
|
|
24
24
|
key: string;
|
|
25
25
|
selection: FieldSelection;
|
|
26
|
+
type: string;
|
|
26
27
|
}): void;
|
|
27
28
|
registerList({ list, id, key, parentType, selection, filters, variables, }: {
|
|
28
29
|
list: Required<Required<SubscriptionSelection>['fields'][string]>['list'];
|
|
@@ -51,7 +51,8 @@ class InMemorySubscriptions {
|
|
|
51
51
|
this.addFieldSubscription({
|
|
52
52
|
id: parent,
|
|
53
53
|
key,
|
|
54
|
-
selection: [spec, targetSelection2]
|
|
54
|
+
selection: [spec, targetSelection2],
|
|
55
|
+
type
|
|
55
56
|
});
|
|
56
57
|
if (list) {
|
|
57
58
|
this.registerList({
|
|
@@ -88,7 +89,8 @@ class InMemorySubscriptions {
|
|
|
88
89
|
addFieldSubscription({
|
|
89
90
|
id,
|
|
90
91
|
key,
|
|
91
|
-
selection
|
|
92
|
+
selection,
|
|
93
|
+
type
|
|
92
94
|
}) {
|
|
93
95
|
const spec = selection[0];
|
|
94
96
|
if (!this.subscribers[id]) {
|
|
@@ -160,7 +162,8 @@ class InMemorySubscriptions {
|
|
|
160
162
|
this.addFieldSubscription({
|
|
161
163
|
id: parent,
|
|
162
164
|
key,
|
|
163
|
-
selection: [spec, fieldSelection]
|
|
165
|
+
selection: [spec, fieldSelection],
|
|
166
|
+
type: linkedType
|
|
164
167
|
});
|
|
165
168
|
if (list) {
|
|
166
169
|
this.registerList({
|
|
@@ -52,7 +52,8 @@ const cachePolicyPlugin = ({
|
|
|
52
52
|
data: value.data,
|
|
53
53
|
errors: null,
|
|
54
54
|
source: import_types.DataSource.Cache,
|
|
55
|
-
partial: value.partial
|
|
55
|
+
partial: value.partial,
|
|
56
|
+
stale: value.stale
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
59
|
useCache = !!(value.data !== null && allowed);
|
|
@@ -63,10 +64,11 @@ const cachePolicyPlugin = ({
|
|
|
63
64
|
data: value.data,
|
|
64
65
|
errors: null,
|
|
65
66
|
source: import_types.DataSource.Cache,
|
|
66
|
-
partial: value.partial
|
|
67
|
+
partial: value.partial,
|
|
68
|
+
stale: value.stale
|
|
67
69
|
});
|
|
68
70
|
}
|
|
69
|
-
if (useCache && !value.partial) {
|
|
71
|
+
if (useCache && !value.partial && !value.stale) {
|
|
70
72
|
return;
|
|
71
73
|
}
|
|
72
74
|
}
|
|
@@ -5,5 +5,5 @@ export declare const fetchParamsPlugin: (fn?: FetchParamFn) => ClientPlugin;
|
|
|
5
5
|
export type FetchParamsInput = Pick<ClientPluginContext, 'config' | 'policy' | 'variables' | 'metadata' | 'session' | 'stuff'> & {
|
|
6
6
|
text: string;
|
|
7
7
|
hash: string;
|
|
8
|
-
|
|
8
|
+
document: DocumentArtifact;
|
|
9
9
|
};
|
|
@@ -26,7 +26,12 @@ const fetchParamsPlugin = (fn = () => ({})) => () => ({
|
|
|
26
26
|
next({
|
|
27
27
|
...ctx,
|
|
28
28
|
fetchParams: fn({
|
|
29
|
-
|
|
29
|
+
config: ctx.config,
|
|
30
|
+
policy: ctx.policy,
|
|
31
|
+
metadata: ctx.metadata,
|
|
32
|
+
session: ctx.session,
|
|
33
|
+
stuff: ctx.stuff,
|
|
34
|
+
document: ctx.artifact,
|
|
30
35
|
variables: marshalVariables(ctx),
|
|
31
36
|
text: ctx.artifact.raw,
|
|
32
37
|
hash: ctx.artifact.hash
|
|
@@ -54,12 +54,12 @@ const queryPlugin = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Q
|
|
|
54
54
|
selection: ctx.artifact.selection,
|
|
55
55
|
variables: () => lastVariables,
|
|
56
56
|
set: (newValue) => {
|
|
57
|
-
console.log("setting from cache update");
|
|
58
57
|
resolve(ctx, {
|
|
59
58
|
data: newValue,
|
|
60
59
|
errors: null,
|
|
61
60
|
fetching: false,
|
|
62
61
|
partial: false,
|
|
62
|
+
stale: false,
|
|
63
63
|
source: import_types.DataSource.Cache,
|
|
64
64
|
variables: ctx.variables ?? null
|
|
65
65
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { GraphQLObject } from '../../lib/types';
|
|
2
1
|
import type { ClientPluginContext } from '../documentStore';
|
|
3
2
|
export declare function subscriptionPlugin(factory: SubscriptionHandler): import("../documentStore").ClientPlugin;
|
|
4
3
|
export type SubscriptionHandler = (ctx: ClientPluginContext) => {
|
|
@@ -7,7 +6,7 @@ export type SubscriptionHandler = (ctx: ClientPluginContext) => {
|
|
|
7
6
|
variables?: {};
|
|
8
7
|
}, handlers: {
|
|
9
8
|
next: (payload: {
|
|
10
|
-
data?:
|
|
9
|
+
data?: {} | null;
|
|
11
10
|
errors?: readonly {
|
|
12
11
|
message: string;
|
|
13
12
|
}[];
|
|
@@ -66,6 +66,7 @@ function subscriptionPlugin(factory) {
|
|
|
66
66
|
errors: [...errors ?? []],
|
|
67
67
|
fetching: false,
|
|
68
68
|
partial: true,
|
|
69
|
+
stale: false,
|
|
69
70
|
source: import_types.DataSource.Network,
|
|
70
71
|
variables: ctx.variables ?? null
|
|
71
72
|
});
|
|
@@ -74,6 +75,7 @@ function subscriptionPlugin(factory) {
|
|
|
74
75
|
clearSubscription?.();
|
|
75
76
|
resolve(ctx, {
|
|
76
77
|
partial: true,
|
|
78
|
+
stale: false,
|
|
77
79
|
source: import_types.DataSource.Network,
|
|
78
80
|
data: null,
|
|
79
81
|
errors: [data],
|
|
@@ -55,6 +55,10 @@ export type ConfigFile = {
|
|
|
55
55
|
* Specifies whether or not the cache should always use partial data. For more information: https://www.houdinigraphql.com/guides/caching-data#partial-data
|
|
56
56
|
*/
|
|
57
57
|
defaultPartial?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Specifies after how long a data goes stale in miliseconds. (default: `undefined`)
|
|
60
|
+
*/
|
|
61
|
+
defaultLifetime?: number;
|
|
58
62
|
/**
|
|
59
63
|
* Specifies whether mutations should append or prepend list. For more information: https://www.houdinigraphql.com/api/graphql (default: `append`)
|
|
60
64
|
*/
|
|
@@ -22,3 +22,4 @@ __reExport(lib_exports, require("./log"), module.exports);
|
|
|
22
22
|
__reExport(lib_exports, require("./scalars"), module.exports);
|
|
23
23
|
__reExport(lib_exports, require("./types"), module.exports);
|
|
24
24
|
__reExport(lib_exports, require("./store"), module.exports);
|
|
25
|
+
__reExport(lib_exports, require("./key"), module.exports);
|