houdini 1.0.0-next.2 → 1.0.0-next.21

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 (195) hide show
  1. package/README.md +4 -1
  2. package/build/cmd-cjs/index.js +5366 -2772
  3. package/build/cmd-esm/index.js +5340 -2746
  4. package/build/codegen/generators/artifacts/index.d.ts +2 -2
  5. package/build/codegen/generators/artifacts/indexFile.d.ts +2 -2
  6. package/build/codegen/generators/artifacts/selection.d.ts +5 -5
  7. package/build/codegen/generators/artifacts/utils.d.ts +0 -1
  8. package/build/codegen/generators/indexFile/index.d.ts +2 -2
  9. package/build/codegen/generators/persistedQueries/index.d.ts +2 -2
  10. package/build/codegen/generators/runtime/graphqlFunction.d.ts +2 -2
  11. package/build/codegen/generators/runtime/index.d.ts +2 -2
  12. package/build/codegen/generators/runtime/runtimeConfig.d.ts +7 -0
  13. package/build/codegen/generators/typescript/documentTypes.d.ts +2 -0
  14. package/build/codegen/generators/typescript/imperativeTypeDef.d.ts +2 -0
  15. package/build/codegen/generators/typescript/index.d.ts +2 -2
  16. package/build/codegen/generators/typescript/typeReference.d.ts +4 -2
  17. package/build/codegen/generators/typescript/types.d.ts +0 -1
  18. package/build/codegen/index.d.ts +2 -2
  19. package/build/codegen/transforms/addID.d.ts +2 -2
  20. package/build/codegen/transforms/composeQueries.d.ts +4 -4
  21. package/build/codegen/transforms/fragmentVariables.d.ts +3 -2
  22. package/build/codegen/transforms/list.d.ts +2 -2
  23. package/build/codegen/transforms/paginate.d.ts +2 -2
  24. package/build/codegen/transforms/schema.d.ts +2 -2
  25. package/build/codegen/transforms/typename.d.ts +2 -2
  26. package/build/codegen/utils/flattenSelections.d.ts +1 -1
  27. package/build/codegen/validators/noIDAlias.d.ts +2 -2
  28. package/build/codegen/validators/plugins.d.ts +2 -2
  29. package/build/codegen/validators/typeCheck.d.ts +2 -2
  30. package/build/codegen/validators/uniqueNames.d.ts +2 -2
  31. package/build/codegen-cjs/index.js +4694 -2137
  32. package/build/codegen-esm/index.js +4682 -2125
  33. package/build/lib/config.d.ts +15 -96
  34. package/build/lib/deepMerge.d.ts +1 -0
  35. package/build/lib/graphql.d.ts +5 -2
  36. package/build/lib/index.d.ts +2 -0
  37. package/build/lib/path.d.ts +1 -1
  38. package/build/lib/pipeline.d.ts +1 -1
  39. package/build/lib/plugin.d.ts +2 -0
  40. package/build/lib/types.d.ts +257 -6
  41. package/build/lib/walk.d.ts +4 -1
  42. package/build/lib-cjs/index.js +4108 -928
  43. package/build/lib-esm/index.js +4078 -907
  44. package/build/runtime/cache/cache.d.ts +28 -11
  45. package/build/runtime/cache/lists.d.ts +1 -0
  46. package/build/runtime/cache/staleManager.d.ts +30 -0
  47. package/build/runtime/cache/storage.d.ts +23 -20
  48. package/build/runtime/cache/stuff.d.ts +0 -2
  49. package/build/runtime/cache/subscription.d.ts +2 -1
  50. package/build/runtime/client/documentStore.d.ts +20 -17
  51. package/build/runtime/client/index.d.ts +13 -11
  52. package/build/runtime/client/plugins/cache.d.ts +1 -1
  53. package/build/runtime/client/plugins/fetch.d.ts +1 -1
  54. package/build/runtime/client/plugins/fetchParams.d.ts +2 -2
  55. package/build/runtime/client/plugins/injectedPlugins.d.ts +2 -1
  56. package/build/runtime/client/plugins/mutation.d.ts +1 -1
  57. package/build/runtime/client/plugins/query.d.ts +1 -1
  58. package/build/runtime/client/plugins/subscription.d.ts +2 -3
  59. package/build/runtime/client/plugins/throwOnError.d.ts +1 -1
  60. package/build/runtime/client/utils/documentPlugins.d.ts +3 -3
  61. package/build/runtime/generated.d.ts +1 -0
  62. package/build/runtime/imports/pluginConfig.d.ts +3 -0
  63. package/build/runtime/index.d.ts +1 -1
  64. package/build/runtime/lib/config.d.ts +27 -24
  65. package/build/runtime/lib/flatten.d.ts +2 -0
  66. package/build/runtime/lib/index.d.ts +1 -0
  67. package/build/runtime/lib/key.d.ts +6 -0
  68. package/build/runtime/lib/scalars.d.ts +3 -3
  69. package/build/runtime/lib/types.d.ts +47 -47
  70. package/build/runtime/public/cache.d.ts +26 -6
  71. package/build/runtime/public/record.d.ts +26 -17
  72. package/build/runtime/public/tests/test.d.ts +52 -10
  73. package/build/runtime/public/types.d.ts +8 -0
  74. package/build/runtime-cjs/cache/cache.d.ts +28 -11
  75. package/build/runtime-cjs/cache/cache.js +97 -22
  76. package/build/runtime-cjs/cache/gc.js +9 -0
  77. package/build/runtime-cjs/cache/lists.d.ts +1 -0
  78. package/build/runtime-cjs/cache/lists.js +9 -6
  79. package/build/runtime-cjs/cache/staleManager.d.ts +30 -0
  80. package/build/runtime-cjs/cache/staleManager.js +95 -0
  81. package/build/runtime-cjs/cache/storage.d.ts +23 -20
  82. package/build/runtime-cjs/cache/storage.js +11 -13
  83. package/build/runtime-cjs/cache/stuff.d.ts +0 -2
  84. package/build/runtime-cjs/cache/stuff.js +2 -19
  85. package/build/runtime-cjs/cache/subscription.d.ts +2 -1
  86. package/build/runtime-cjs/cache/subscription.js +11 -7
  87. package/build/runtime-cjs/client/documentStore.d.ts +20 -17
  88. package/build/runtime-cjs/client/documentStore.js +13 -9
  89. package/build/runtime-cjs/client/index.d.ts +13 -11
  90. package/build/runtime-cjs/client/index.js +48 -19
  91. package/build/runtime-cjs/client/plugins/cache.d.ts +1 -1
  92. package/build/runtime-cjs/client/plugins/cache.js +12 -10
  93. package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -1
  94. package/build/runtime-cjs/client/plugins/fetch.js +10 -9
  95. package/build/runtime-cjs/client/plugins/fetchParams.d.ts +2 -2
  96. package/build/runtime-cjs/client/plugins/fetchParams.js +9 -4
  97. package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +2 -1
  98. package/build/runtime-cjs/client/plugins/mutation.d.ts +1 -1
  99. package/build/runtime-cjs/client/plugins/mutation.js +3 -3
  100. package/build/runtime-cjs/client/plugins/query.d.ts +1 -1
  101. package/build/runtime-cjs/client/plugins/query.js +5 -5
  102. package/build/runtime-cjs/client/plugins/subscription.d.ts +2 -3
  103. package/build/runtime-cjs/client/plugins/subscription.js +7 -5
  104. package/build/runtime-cjs/client/plugins/throwOnError.d.ts +1 -1
  105. package/build/runtime-cjs/client/plugins/throwOnError.js +3 -3
  106. package/build/runtime-cjs/client/utils/documentPlugins.d.ts +3 -3
  107. package/build/runtime-cjs/generated.d.ts +1 -0
  108. package/build/runtime-cjs/imports/pluginConfig.d.ts +3 -0
  109. package/build/runtime-cjs/imports/pluginConfig.js +27 -0
  110. package/build/runtime-cjs/index.d.ts +1 -1
  111. package/build/runtime-cjs/lib/config.d.ts +27 -24
  112. package/build/runtime-cjs/lib/config.js +11 -1
  113. package/build/runtime-cjs/lib/flatten.d.ts +2 -0
  114. package/build/runtime-cjs/lib/flatten.js +41 -0
  115. package/build/runtime-cjs/lib/index.d.ts +1 -0
  116. package/build/runtime-cjs/lib/index.js +1 -0
  117. package/build/runtime-cjs/lib/key.d.ts +6 -0
  118. package/build/runtime-cjs/lib/key.js +41 -0
  119. package/build/runtime-cjs/lib/scalars.d.ts +3 -3
  120. package/build/runtime-cjs/lib/scalars.js +13 -2
  121. package/build/runtime-cjs/lib/types.d.ts +47 -47
  122. package/build/runtime-cjs/lib/types.js +26 -30
  123. package/build/runtime-cjs/public/cache.d.ts +26 -6
  124. package/build/runtime-cjs/public/cache.js +32 -32
  125. package/build/runtime-cjs/public/list.js +6 -28
  126. package/build/runtime-cjs/public/record.d.ts +26 -17
  127. package/build/runtime-cjs/public/record.js +27 -187
  128. package/build/runtime-cjs/public/tests/test.d.ts +52 -10
  129. package/build/runtime-cjs/public/tests/test.js +27 -2
  130. package/build/runtime-cjs/public/types.d.ts +8 -0
  131. package/build/runtime-esm/cache/cache.d.ts +28 -11
  132. package/build/runtime-esm/cache/cache.js +99 -24
  133. package/build/runtime-esm/cache/gc.js +9 -0
  134. package/build/runtime-esm/cache/lists.d.ts +1 -0
  135. package/build/runtime-esm/cache/lists.js +9 -6
  136. package/build/runtime-esm/cache/staleManager.d.ts +30 -0
  137. package/build/runtime-esm/cache/staleManager.js +71 -0
  138. package/build/runtime-esm/cache/storage.d.ts +23 -20
  139. package/build/runtime-esm/cache/storage.js +11 -13
  140. package/build/runtime-esm/cache/stuff.d.ts +0 -2
  141. package/build/runtime-esm/cache/stuff.js +1 -17
  142. package/build/runtime-esm/cache/subscription.d.ts +2 -1
  143. package/build/runtime-esm/cache/subscription.js +12 -8
  144. package/build/runtime-esm/client/documentStore.d.ts +20 -17
  145. package/build/runtime-esm/client/documentStore.js +14 -10
  146. package/build/runtime-esm/client/index.d.ts +13 -11
  147. package/build/runtime-esm/client/index.js +49 -21
  148. package/build/runtime-esm/client/plugins/cache.d.ts +1 -1
  149. package/build/runtime-esm/client/plugins/cache.js +11 -9
  150. package/build/runtime-esm/client/plugins/fetch.d.ts +1 -1
  151. package/build/runtime-esm/client/plugins/fetch.js +9 -8
  152. package/build/runtime-esm/client/plugins/fetchParams.d.ts +2 -2
  153. package/build/runtime-esm/client/plugins/fetchParams.js +8 -3
  154. package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +2 -1
  155. package/build/runtime-esm/client/plugins/mutation.d.ts +1 -1
  156. package/build/runtime-esm/client/plugins/mutation.js +2 -2
  157. package/build/runtime-esm/client/plugins/query.d.ts +1 -1
  158. package/build/runtime-esm/client/plugins/query.js +4 -4
  159. package/build/runtime-esm/client/plugins/subscription.d.ts +2 -3
  160. package/build/runtime-esm/client/plugins/subscription.js +6 -4
  161. package/build/runtime-esm/client/plugins/throwOnError.d.ts +1 -1
  162. package/build/runtime-esm/client/plugins/throwOnError.js +2 -2
  163. package/build/runtime-esm/client/utils/documentPlugins.d.ts +3 -3
  164. package/build/runtime-esm/generated.d.ts +1 -0
  165. package/build/runtime-esm/imports/pluginConfig.d.ts +3 -0
  166. package/build/runtime-esm/imports/pluginConfig.js +5 -0
  167. package/build/runtime-esm/index.d.ts +1 -1
  168. package/build/runtime-esm/lib/config.d.ts +27 -24
  169. package/build/runtime-esm/lib/config.js +11 -1
  170. package/build/runtime-esm/lib/flatten.d.ts +2 -0
  171. package/build/runtime-esm/lib/flatten.js +17 -0
  172. package/build/runtime-esm/lib/index.d.ts +1 -0
  173. package/build/runtime-esm/lib/index.js +1 -0
  174. package/build/runtime-esm/lib/key.d.ts +6 -0
  175. package/build/runtime-esm/lib/key.js +17 -0
  176. package/build/runtime-esm/lib/scalars.d.ts +3 -3
  177. package/build/runtime-esm/lib/scalars.js +13 -2
  178. package/build/runtime-esm/lib/types.d.ts +47 -47
  179. package/build/runtime-esm/lib/types.js +26 -30
  180. package/build/runtime-esm/public/cache.d.ts +26 -6
  181. package/build/runtime-esm/public/cache.js +31 -30
  182. package/build/runtime-esm/public/list.js +6 -28
  183. package/build/runtime-esm/public/record.d.ts +26 -17
  184. package/build/runtime-esm/public/record.js +26 -183
  185. package/build/runtime-esm/public/tests/test.d.ts +52 -10
  186. package/build/runtime-esm/public/tests/test.js +26 -1
  187. package/build/runtime-esm/public/types.d.ts +8 -0
  188. package/build/test/index.d.ts +3 -3
  189. package/build/test-cjs/index.js +5007 -2465
  190. package/build/test-esm/index.js +4995 -2453
  191. package/build/vite/houdini.d.ts +2 -0
  192. package/build/vite-cjs/index.js +5344 -2744
  193. package/build/vite-esm/index.js +5319 -2719
  194. package/package.json +6 -5
  195. package/build/codegen/generators/typescript/imperativeCache.d.ts +0 -2
@@ -22,12 +22,15 @@ __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");
28
+ var import_flatten = require("../lib/flatten");
27
29
  var import_selection = require("../lib/selection");
28
30
  var import_gc = require("./gc");
29
31
  var import_lists = require("./lists");
30
32
  var import_schema = require("./schema");
33
+ var import_staleManager = require("./staleManager");
31
34
  var import_storage = require("./storage");
32
35
  var import_stuff = require("./stuff");
33
36
  var import_subscription = require("./subscription");
@@ -40,6 +43,7 @@ class Cache {
40
43
  subscriptions: new import_subscription.InMemorySubscriptions(this),
41
44
  lists: new import_lists.ListManager(this, rootID),
42
45
  lifetimes: new import_gc.GarbageCollector(this),
46
+ staleManager: new import_staleManager.StaleManager(this),
43
47
  schema: new import_schema.SchemaManager(this)
44
48
  });
45
49
  if (config) {
@@ -69,13 +73,14 @@ class Cache {
69
73
  return subscribers;
70
74
  }
71
75
  read(...args) {
72
- const { data, partial, hasData } = this._internal_unstable.getSelection(...args);
76
+ const { data, partial, stale, hasData } = this._internal_unstable.getSelection(...args);
73
77
  if (!hasData) {
74
- return { data: null, partial: false };
78
+ return { data: null, partial: false, stale: false };
75
79
  }
76
80
  return {
77
81
  data,
78
- partial
82
+ partial,
83
+ stale
79
84
  };
80
85
  }
81
86
  subscribe(spec, variables = {}) {
@@ -111,6 +116,30 @@ class Cache {
111
116
  setConfig(config) {
112
117
  this._internal_unstable.setConfig(config);
113
118
  }
119
+ markTypeStale(options) {
120
+ if (!options) {
121
+ this._internal_unstable.staleManager.markAllStale();
122
+ } else if (!options.field) {
123
+ this._internal_unstable.staleManager.markTypeStale(options.type);
124
+ } else {
125
+ this._internal_unstable.staleManager.markTypeFieldStale(
126
+ options.type,
127
+ options.field,
128
+ options.when
129
+ );
130
+ }
131
+ }
132
+ markRecordStale(id, options) {
133
+ if (options.field) {
134
+ const key = (0, import_lib.computeKey)({ field: options.field, args: options.when ?? {} });
135
+ this._internal_unstable.staleManager.markFieldStale(id, key);
136
+ } else {
137
+ this._internal_unstable.staleManager.markRecordStale(id);
138
+ }
139
+ }
140
+ getFieldTime(id, field) {
141
+ return this._internal_unstable.staleManager.getFieldTime(id, field);
142
+ }
114
143
  }
115
144
  class CacheInternal {
116
145
  _disabled = false;
@@ -126,6 +155,7 @@ class CacheInternal {
126
155
  lists;
127
156
  cache;
128
157
  lifetimes;
158
+ staleManager;
129
159
  schema;
130
160
  constructor({
131
161
  storage,
@@ -133,6 +163,7 @@ class CacheInternal {
133
163
  lists,
134
164
  cache,
135
165
  lifetimes,
166
+ staleManager,
136
167
  schema
137
168
  }) {
138
169
  this.storage = storage;
@@ -140,6 +171,7 @@ class CacheInternal {
140
171
  this.lists = lists;
141
172
  this.cache = cache;
142
173
  this.lifetimes = lifetimes;
174
+ this.staleManager = staleManager;
143
175
  this.schema = schema;
144
176
  this._disabled = typeof globalThis.window === "undefined";
145
177
  try {
@@ -157,10 +189,11 @@ class CacheInternal {
157
189
  selection,
158
190
  variables = {},
159
191
  parent = rootID,
160
- applyUpdates = false,
192
+ applyUpdates,
161
193
  layer,
162
194
  toNotify = [],
163
- forceNotify
195
+ forceNotify,
196
+ forceStale
164
197
  }) {
165
198
  if (this._disabled) {
166
199
  return [];
@@ -178,7 +211,7 @@ class CacheInternal {
178
211
  selection: fieldSelection,
179
212
  operations,
180
213
  abstract: isAbstract,
181
- update,
214
+ updates,
182
215
  nullable
183
216
  } = targetSelection[field];
184
217
  const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
@@ -195,16 +228,31 @@ class CacheInternal {
195
228
  const displayLayer = layer.isDisplayLayer(displayLayers);
196
229
  if (displayLayer) {
197
230
  this.lifetimes.resetLifetime(parent, key);
231
+ if (forceStale) {
232
+ this.staleManager.markFieldStale(parent, key);
233
+ } else {
234
+ this.staleManager.setFieldTimeToNow(parent, key);
235
+ }
198
236
  }
199
237
  if (!fieldSelection) {
200
238
  let newValue = value;
201
- if (Array.isArray(value) && applyUpdates && update) {
202
- if (update === "append") {
203
- newValue = (previousValue || []).concat(value);
204
- } else if (update === "prepend") {
205
- newValue = value.concat(previousValue || []);
239
+ if (updates && applyUpdates && Array.isArray(value)) {
240
+ for (const update of applyUpdates) {
241
+ if (!updates.includes(update)) {
242
+ continue;
243
+ }
244
+ if (update === "append") {
245
+ newValue = (previousValue || []).concat(value);
246
+ } else if (update === "prepend") {
247
+ newValue = value.concat(previousValue || []);
248
+ }
206
249
  }
207
250
  }
251
+ if (updates && applyUpdates?.includes("prepend") && ["endCursor", "hasNextPage"].includes(key)) {
252
+ newValue = previousValue;
253
+ } else if (updates && applyUpdates?.includes("append") && ["startCursor", "hasPreviousPage"].includes(key)) {
254
+ newValue = previousValue;
255
+ }
208
256
  const valueChanged = !(0, import_deepEquals.deepEquals)(newValue, previousValue);
209
257
  if (displayLayer && (valueChanged || forceNotify)) {
210
258
  toNotify.push(...currentSubscribers);
@@ -214,7 +262,7 @@ class CacheInternal {
214
262
  if (previousValue === null) {
215
263
  continue;
216
264
  }
217
- const previousLinks = (0, import_stuff.flattenList)([previousValue]);
265
+ const previousLinks = (0, import_flatten.flatten)([previousValue]);
218
266
  for (const link of previousLinks) {
219
267
  this.subscriptions.remove(link, fieldSelection, specs, variables);
220
268
  }
@@ -264,7 +312,7 @@ class CacheInternal {
264
312
  }
265
313
  } else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
266
314
  let oldIDs = [...previousValue || []];
267
- const emptyEdges = !update ? [] : oldIDs.map((id) => {
315
+ const emptyEdges = !updates ? [] : oldIDs.map((id) => {
268
316
  if (!id) {
269
317
  return "";
270
318
  }
@@ -292,7 +340,7 @@ class CacheInternal {
292
340
  layer,
293
341
  forceNotify
294
342
  });
295
- if (applyUpdates && update) {
343
+ if (applyUpdates && updates) {
296
344
  if (key === "edges") {
297
345
  const newNodeIDs = [];
298
346
  for (const id of newIDs) {
@@ -320,12 +368,17 @@ class CacheInternal {
320
368
  return true;
321
369
  });
322
370
  }
323
- if (update === "prepend") {
324
- linkedIDs = newIDs.concat(oldIDs);
325
- } else if (update === "append") {
326
- linkedIDs = oldIDs.concat(newIDs);
327
- } else if (update === "replace") {
328
- linkedIDs = newIDs;
371
+ for (const update of applyUpdates) {
372
+ if (update !== "replace" && !updates.includes(update)) {
373
+ continue;
374
+ }
375
+ if (update === "prepend") {
376
+ linkedIDs = newIDs.concat(oldIDs);
377
+ } else if (update === "append") {
378
+ linkedIDs = oldIDs.concat(newIDs);
379
+ } else if (update === "replace") {
380
+ linkedIDs = newIDs;
381
+ }
329
382
  }
330
383
  } else {
331
384
  linkedIDs = nestedIDs;
@@ -411,12 +464,13 @@ class CacheInternal {
411
464
  stepsFromConnection = null
412
465
  }) {
413
466
  if (parent === null) {
414
- return { data: null, partial: false, hasData: true };
467
+ return { data: null, partial: false, stale: false, hasData: true };
415
468
  }
416
469
  const target = {};
417
470
  let hasData = false;
418
471
  let partial = false;
419
472
  let cascadeNull = false;
473
+ let stale = false;
420
474
  const typename = this.storage.get(parent, "__typename").value;
421
475
  let targetSelection = (0, import_selection.getFieldsForType)(selection, typename);
422
476
  for (const [
@@ -425,6 +479,10 @@ class CacheInternal {
425
479
  ] of Object.entries(targetSelection)) {
426
480
  const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
427
481
  const { value } = this.storage.get(parent, key);
482
+ const dt_field = this.staleManager.getFieldTime(parent, key);
483
+ if (dt_field === null) {
484
+ stale = true;
485
+ }
428
486
  let nextStep = stepsFromConnection;
429
487
  if (nextStep !== null) {
430
488
  if (nextStep >= 2) {
@@ -464,6 +522,9 @@ class CacheInternal {
464
522
  if (listValue.partial) {
465
523
  partial = true;
466
524
  }
525
+ if (listValue.stale) {
526
+ stale = true;
527
+ }
467
528
  if (listValue.hasData || value.length === 0) {
468
529
  hasData = true;
469
530
  }
@@ -478,6 +539,9 @@ class CacheInternal {
478
539
  if (objectFields.partial) {
479
540
  partial = true;
480
541
  }
542
+ if (objectFields.stale) {
543
+ stale = true;
544
+ }
481
545
  if (objectFields.hasData) {
482
546
  hasData = true;
483
547
  }
@@ -489,6 +553,7 @@ class CacheInternal {
489
553
  return {
490
554
  data: cascadeNull ? null : target,
491
555
  partial: hasData && partial,
556
+ stale: hasData && stale,
492
557
  hasData
493
558
  };
494
559
  }
@@ -516,6 +581,7 @@ class CacheInternal {
516
581
  }) {
517
582
  const result = [];
518
583
  let partialData = false;
584
+ let stale = false;
519
585
  let hasValues = false;
520
586
  for (const entry of linkedList) {
521
587
  if (Array.isArray(entry)) {
@@ -535,7 +601,12 @@ class CacheInternal {
535
601
  result.push(entry);
536
602
  continue;
537
603
  }
538
- const { data, partial, hasData } = this.getSelection({
604
+ const {
605
+ data,
606
+ partial,
607
+ stale: local_stale,
608
+ hasData
609
+ } = this.getSelection({
539
610
  parent: entry,
540
611
  selection: fields,
541
612
  variables,
@@ -545,6 +616,9 @@ class CacheInternal {
545
616
  if (partial) {
546
617
  partialData = true;
547
618
  }
619
+ if (local_stale) {
620
+ stale = true;
621
+ }
548
622
  if (hasData) {
549
623
  hasValues = true;
550
624
  }
@@ -552,6 +626,7 @@ class CacheInternal {
552
626
  return {
553
627
  data: result,
554
628
  partial: partialData,
629
+ stale,
555
630
  hasData: hasValues
556
631
  };
557
632
  }
@@ -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
  }
@@ -55,6 +55,7 @@ export declare class List {
55
55
  export declare class ListCollection {
56
56
  lists: List[];
57
57
  constructor(lists: List[]);
58
+ get selection(): SubscriptionSelection;
58
59
  append(...args: Parameters<List['append']>): void;
59
60
  prepend(...args: Parameters<List['prepend']>): void;
60
61
  addToList(...args: Parameters<List['addToList']>): void;
@@ -23,8 +23,8 @@ __export(lists_exports, {
23
23
  ListManager: () => ListManager
24
24
  });
25
25
  module.exports = __toCommonJS(lists_exports);
26
+ var import_flatten = require("../lib/flatten");
26
27
  var import_cache = require("./cache");
27
- var import_stuff = require("./stuff");
28
28
  class ListManager {
29
29
  rootID;
30
30
  cache;
@@ -176,7 +176,7 @@ class List {
176
176
  edges: {
177
177
  keyRaw: "edges",
178
178
  type: "ConnectionEdge",
179
- update: where === "first" ? "prepend" : "append",
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
- update: where === "first" ? "prepend" : "append",
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: true
238
+ applyUpdates: [where === "first" ? "prepend" : "append"]
239
239
  });
240
240
  }
241
241
  removeID(id, variables = {}) {
@@ -258,7 +258,7 @@ class List {
258
258
  embeddedConnectionID,
259
259
  "edges"
260
260
  );
261
- for (const edge of (0, import_stuff.flattenList)(edges) || []) {
261
+ for (const edge of (0, import_flatten.flatten)(edges) || []) {
262
262
  if (!edge) {
263
263
  continue;
264
264
  }
@@ -336,7 +336,7 @@ class List {
336
336
  let entries = [];
337
337
  let value = this.cache._internal_unstable.storage.get(this.recordID, this.key).value;
338
338
  if (!this.connection) {
339
- entries = (0, import_stuff.flattenList)(value);
339
+ entries = (0, import_flatten.flatten)(value);
340
340
  } else {
341
341
  entries = this.cache._internal_unstable.storage.get(value, "edges").value;
342
342
  }
@@ -350,6 +350,9 @@ class ListCollection {
350
350
  constructor(lists) {
351
351
  this.lists = lists;
352
352
  }
353
+ get selection() {
354
+ return this.lists[0].selection;
355
+ }
353
356
  append(...args) {
354
357
  this.lists.forEach((list) => list.append(...args));
355
358
  }
@@ -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
+ });
@@ -7,7 +7,7 @@ export declare class InMemoryStorage {
7
7
  get layerCount(): number;
8
8
  get nextRank(): number;
9
9
  createLayer(optimistic?: boolean): Layer;
10
- insert(id: string, field: string, location: OperationLocation, target: string): void;
10
+ insert(id: string, field: string, location: OperationLocations, target: string): void;
11
11
  remove(id: string, field: string, target: string): void;
12
12
  delete(id: string): void;
13
13
  deleteField(id: string, field: string): void;
@@ -21,7 +21,7 @@ export declare class InMemoryStorage {
21
21
  kind: 'link' | 'scalar' | 'unknown';
22
22
  displayLayers: number[];
23
23
  };
24
- writeLink(id: string, field: string, value: string | LinkedList): number;
24
+ writeLink(id: string, field: string, value: string | NestedList): number;
25
25
  writeField(id: string, field: string, value: GraphQLValue): number;
26
26
  resolveLayer(id: number): void;
27
27
  get topLayer(): Layer;
@@ -37,7 +37,7 @@ export declare class Layer {
37
37
  get(id: string, field: string): [GraphQLField, 'link' | 'scalar'];
38
38
  getOperations(id: string, field: string): Operation[] | undefined;
39
39
  writeField(id: string, field: string, value: GraphQLField): LayerID;
40
- writeLink(id: string, field: string, value: null | string | LinkedList): LayerID;
40
+ writeLink(id: string, field: string, value: null | string | NestedList): LayerID;
41
41
  isDisplayLayer(displayLayers: number[]): boolean;
42
42
  clear(): void;
43
43
  replaceID({ from, to }: {
@@ -47,19 +47,19 @@ export declare class Layer {
47
47
  removeUndefinedFields(): void;
48
48
  delete(id: string): void;
49
49
  deleteField(id: string, field: string): void;
50
- insert(id: string, field: string, where: OperationLocation, target: string): void;
50
+ insert(id: string, field: string, where: OperationLocations, target: string): void;
51
51
  remove(id: string, field: string, target: string): void;
52
52
  writeLayer(layer: Layer): void;
53
53
  private addFieldOperation;
54
54
  }
55
- type GraphQLField = GraphQLValue | LinkedList;
55
+ type GraphQLField = GraphQLValue | NestedList;
56
56
  type EntityMap<_Value> = {
57
57
  [id: string]: {
58
58
  [field: string]: _Value;
59
59
  };
60
60
  };
61
61
  type EntityFieldMap = EntityMap<GraphQLField>;
62
- type LinkMap = EntityMap<string | null | LinkedList>;
62
+ type LinkMap = EntityMap<string | null | NestedList>;
63
63
  type OperationMap = {
64
64
  [id: string]: {
65
65
  deleted?: boolean;
@@ -69,30 +69,33 @@ type OperationMap = {
69
69
  };
70
70
  };
71
71
  };
72
- type LinkedList<_Result = string> = (_Result | null | LinkedList<_Result>)[];
72
+ type NestedList<_Result = string> = (_Result | null | NestedList<_Result>)[];
73
73
  type InsertOperation = {
74
- kind: OperationKind.insert;
75
- location: OperationLocation;
74
+ kind: 'insert';
75
+ location: OperationLocations;
76
76
  id: string;
77
77
  };
78
78
  type RemoveOperation = {
79
- kind: OperationKind.remove;
79
+ kind: 'remove';
80
80
  id: string;
81
81
  };
82
82
  type DeleteOperation = {
83
- kind: OperationKind.delete;
83
+ kind: 'delete';
84
84
  target: string;
85
85
  };
86
86
  type ListOperation = InsertOperation | RemoveOperation;
87
87
  type Operation = ListOperation | DeleteOperation;
88
- export declare enum OperationLocation {
89
- start = "start",
90
- end = "end"
91
- }
92
- export declare enum OperationKind {
93
- delete = "delete",
94
- insert = "insert",
95
- remove = "remove"
96
- }
88
+ type ValuesOf<Target> = Target[keyof Target];
89
+ export declare const OperationLocation: {
90
+ readonly start: "start";
91
+ readonly end: "end";
92
+ };
93
+ export type OperationLocations = ValuesOf<typeof OperationLocation>;
94
+ export declare const OperationKind: {
95
+ readonly delete: "delete";
96
+ readonly insert: "insert";
97
+ readonly remove: "remove";
98
+ };
99
+ export type OperationKinds = ValuesOf<typeof OperationKind>;
97
100
  export type LayerID = number;
98
101
  export {};
@@ -24,7 +24,7 @@ __export(storage_exports, {
24
24
  OperationLocation: () => OperationLocation
25
25
  });
26
26
  module.exports = __toCommonJS(storage_exports);
27
- var import_stuff = require("./stuff");
27
+ var import_flatten = require("../lib/flatten");
28
28
  class InMemoryStorage {
29
29
  data;
30
30
  idCount = 0;
@@ -224,7 +224,7 @@ class Layer {
224
224
  }
225
225
  writeLink(id, field, value) {
226
226
  const valueList = Array.isArray(value) ? value : [value];
227
- for (const value2 of (0, import_stuff.flattenList)(valueList)) {
227
+ for (const value2 of (0, import_flatten.flatten)(valueList)) {
228
228
  if (!value2) {
229
229
  continue;
230
230
  }
@@ -376,17 +376,15 @@ function isInsertOperation(value) {
376
376
  function isRemoveOperation(value) {
377
377
  return !!value && value.kind === OperationKind.remove;
378
378
  }
379
- var OperationLocation = /* @__PURE__ */ ((OperationLocation2) => {
380
- OperationLocation2["start"] = "start";
381
- OperationLocation2["end"] = "end";
382
- return OperationLocation2;
383
- })(OperationLocation || {});
384
- var OperationKind = /* @__PURE__ */ ((OperationKind2) => {
385
- OperationKind2["delete"] = "delete";
386
- OperationKind2["insert"] = "insert";
387
- OperationKind2["remove"] = "remove";
388
- return OperationKind2;
389
- })(OperationKind || {});
379
+ const OperationLocation = {
380
+ start: "start",
381
+ end: "end"
382
+ };
383
+ const OperationKind = {
384
+ delete: "delete",
385
+ insert: "insert",
386
+ remove: "remove"
387
+ };
390
388
  // Annotate the CommonJS export names for ESM import in node:
391
389
  0 && (module.exports = {
392
390
  InMemoryStorage,
@@ -1,6 +1,4 @@
1
1
  import type { GraphQLValue } from '../lib/types';
2
- import type { LinkedList } from './cache';
3
- export declare function flattenList<T>(source: LinkedList<T>): T[];
4
2
  export declare function evaluateKey(key: string, variables?: {
5
3
  [key: string]: GraphQLValue;
6
4
  }): string;