houdini 1.2.2 → 1.2.4

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 (64) hide show
  1. package/build/cmd-cjs/index.js +183 -63
  2. package/build/cmd-esm/index.js +183 -63
  3. package/build/codegen-cjs/index.js +181 -61
  4. package/build/codegen-esm/index.js +181 -61
  5. package/build/lib/fs.d.ts +8 -1
  6. package/build/lib/index.d.ts +1 -0
  7. package/build/lib/parse.d.ts +1 -1
  8. package/build/lib/types.d.ts +11 -0
  9. package/build/lib-cjs/index.js +181 -69
  10. package/build/lib-esm/index.js +179 -69
  11. package/build/runtime/cache/cache.d.ts +5 -1
  12. package/build/runtime/cache/lists.d.ts +3 -3
  13. package/build/runtime/cache/storage.d.ts +8 -2
  14. package/build/runtime/cache/subscription.d.ts +1 -0
  15. package/build/runtime/client/documentStore.d.ts +9 -2
  16. package/build/runtime/client/index.d.ts +6 -3
  17. package/build/runtime/lib/index.d.ts +1 -0
  18. package/build/runtime/lib/lru.d.ts +52 -0
  19. package/build/runtime/lib/types.d.ts +1 -0
  20. package/build/runtime-cjs/cache/cache.d.ts +5 -1
  21. package/build/runtime-cjs/cache/cache.js +84 -27
  22. package/build/runtime-cjs/cache/lists.d.ts +3 -3
  23. package/build/runtime-cjs/cache/lists.js +20 -8
  24. package/build/runtime-cjs/cache/storage.d.ts +8 -2
  25. package/build/runtime-cjs/cache/storage.js +22 -5
  26. package/build/runtime-cjs/cache/subscription.d.ts +1 -0
  27. package/build/runtime-cjs/cache/subscription.js +3 -0
  28. package/build/runtime-cjs/client/documentStore.d.ts +9 -2
  29. package/build/runtime-cjs/client/documentStore.js +13 -9
  30. package/build/runtime-cjs/client/index.d.ts +6 -3
  31. package/build/runtime-cjs/client/index.js +6 -8
  32. package/build/runtime-cjs/client/plugins/cache.js +3 -0
  33. package/build/runtime-cjs/client/plugins/mutation.js +10 -6
  34. package/build/runtime-cjs/lib/index.d.ts +1 -0
  35. package/build/runtime-cjs/lib/index.js +1 -0
  36. package/build/runtime-cjs/lib/lru.d.ts +52 -0
  37. package/build/runtime-cjs/lib/lru.js +73 -0
  38. package/build/runtime-cjs/lib/types.d.ts +1 -0
  39. package/build/runtime-cjs/lib/types.js +7 -2
  40. package/build/runtime-esm/cache/cache.d.ts +5 -1
  41. package/build/runtime-esm/cache/cache.js +84 -27
  42. package/build/runtime-esm/cache/lists.d.ts +3 -3
  43. package/build/runtime-esm/cache/lists.js +20 -8
  44. package/build/runtime-esm/cache/storage.d.ts +8 -2
  45. package/build/runtime-esm/cache/storage.js +22 -5
  46. package/build/runtime-esm/cache/subscription.d.ts +1 -0
  47. package/build/runtime-esm/cache/subscription.js +3 -0
  48. package/build/runtime-esm/client/documentStore.d.ts +9 -2
  49. package/build/runtime-esm/client/documentStore.js +13 -9
  50. package/build/runtime-esm/client/index.d.ts +6 -3
  51. package/build/runtime-esm/client/index.js +6 -8
  52. package/build/runtime-esm/client/plugins/cache.js +3 -0
  53. package/build/runtime-esm/client/plugins/mutation.js +10 -6
  54. package/build/runtime-esm/lib/index.d.ts +1 -0
  55. package/build/runtime-esm/lib/index.js +1 -0
  56. package/build/runtime-esm/lib/lru.d.ts +52 -0
  57. package/build/runtime-esm/lib/lru.js +48 -0
  58. package/build/runtime-esm/lib/types.d.ts +1 -0
  59. package/build/runtime-esm/lib/types.js +5 -1
  60. package/build/test-cjs/index.js +181 -61
  61. package/build/test-esm/index.js +181 -61
  62. package/build/vite-cjs/index.js +200 -62
  63. package/build/vite-esm/index.js +200 -62
  64. package/package.json +1 -1
@@ -0,0 +1,52 @@
1
+ /**
2
+ * This file is a copy and paste of a very simple and effective LRU cache
3
+ * using javascript maps. It was copied under the MIT license found at the
4
+ * bottom of the page.
5
+ */
6
+ /**
7
+ * JS maps (both plain objects and Map) maintain key insertion
8
+ * order, which means there is an easy way to simulate LRU behavior
9
+ * that should also perform quite well:
10
+ *
11
+ * To insert a new value, first delete the key from the inner _map,
12
+ * then _map.set(k, v). By deleting and reinserting, you ensure that the
13
+ * map sees the key as the last inserted key.
14
+ *
15
+ * Get does the same: if the key is present, delete and reinsert it.
16
+ */
17
+ export declare class LRUCache<T> {
18
+ _capacity: number;
19
+ _map: Map<string, T>;
20
+ constructor(capacity?: number);
21
+ set(key: string, value: T): void;
22
+ get(key: string): T | null;
23
+ has(key: string): boolean;
24
+ delete(key: string): void;
25
+ size(): number;
26
+ capacity(): number;
27
+ clear(): void;
28
+ }
29
+ export declare function createLRUCache<T>(capacity?: number): LRUCache<T>;
30
+ /**
31
+ MIT License
32
+
33
+ Copyright (c) Meta Platforms, Inc. and affiliates.
34
+
35
+ Permission is hereby granted, free of charge, to any person obtaining a copy
36
+ of this software and associated documentation files (the "Software"), to deal
37
+ in the Software without restriction, including without limitation the rights
38
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
39
+ copies of the Software, and to permit persons to whom the Software is
40
+ furnished to do so, subject to the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be included in all
43
+ copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
48
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
50
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
51
+ SOFTWARE.
52
+ */
@@ -0,0 +1,73 @@
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 lru_exports = {};
20
+ __export(lru_exports, {
21
+ LRUCache: () => LRUCache,
22
+ createLRUCache: () => createLRUCache
23
+ });
24
+ module.exports = __toCommonJS(lru_exports);
25
+ class LRUCache {
26
+ _capacity;
27
+ _map;
28
+ constructor(capacity = 1e3) {
29
+ this._capacity = capacity;
30
+ this._map = /* @__PURE__ */ new Map();
31
+ }
32
+ set(key, value) {
33
+ this._map.delete(key);
34
+ this._map.set(key, value);
35
+ if (this._map.size > this._capacity) {
36
+ const firstKey = this._map.keys().next();
37
+ if (!firstKey.done) {
38
+ this._map.delete(firstKey.value);
39
+ }
40
+ }
41
+ }
42
+ get(key) {
43
+ const value = this._map.get(key);
44
+ if (value != null) {
45
+ this._map.delete(key);
46
+ this._map.set(key, value);
47
+ }
48
+ return value ?? null;
49
+ }
50
+ has(key) {
51
+ return this._map.has(key);
52
+ }
53
+ delete(key) {
54
+ this._map.delete(key);
55
+ }
56
+ size() {
57
+ return this._map.size;
58
+ }
59
+ capacity() {
60
+ return this._capacity - this._map.size;
61
+ }
62
+ clear() {
63
+ this._map.clear();
64
+ }
65
+ }
66
+ function createLRUCache(capacity = 1e3) {
67
+ return new LRUCache(capacity);
68
+ }
69
+ // Annotate the CommonJS export names for ESM import in node:
70
+ 0 && (module.exports = {
71
+ LRUCache,
72
+ createLRUCache
73
+ });
@@ -316,4 +316,5 @@ interface VariableNode {
316
316
  }
317
317
  export declare const PendingValue: unique symbol;
318
318
  export type LoadingType = typeof PendingValue;
319
+ export declare function isPending(value: any): value is LoadingType;
319
320
  export {};
@@ -28,7 +28,8 @@ __export(types_exports, {
28
28
  PaginateMode: () => PaginateMode,
29
29
  PendingValue: () => PendingValue,
30
30
  RefetchUpdateMode: () => RefetchUpdateMode,
31
- fragmentKey: () => fragmentKey
31
+ fragmentKey: () => fragmentKey,
32
+ isPending: () => isPending
32
33
  });
33
34
  module.exports = __toCommonJS(types_exports);
34
35
  const CachePolicy = {
@@ -63,6 +64,9 @@ const DataSource = {
63
64
  };
64
65
  const fragmentKey = " $fragments";
65
66
  const PendingValue = Symbol("houdini_loading");
67
+ function isPending(value) {
68
+ return typeof value === "symbol";
69
+ }
66
70
  // Annotate the CommonJS export names for ESM import in node:
67
71
  0 && (module.exports = {
68
72
  ArtifactKind,
@@ -75,5 +79,6 @@ const PendingValue = Symbol("houdini_loading");
75
79
  PaginateMode,
76
80
  PendingValue,
77
81
  RefetchUpdateMode,
78
- fragmentKey
82
+ fragmentKey,
83
+ isPending
79
84
  });
@@ -8,6 +8,7 @@ import type { Layer, LayerID } from './storage';
8
8
  import { InMemoryStorage } from './storage';
9
9
  import { InMemorySubscriptions, type FieldSelection } from './subscription';
10
10
  export declare class Cache {
11
+ #private;
11
12
  _internal_unstable: CacheInternal;
12
13
  constructor({ disabled, ...config }?: ConfigFile & {
13
14
  disabled?: boolean;
@@ -33,7 +34,7 @@ export declare class Cache {
33
34
  subscribe(spec: SubscriptionSpec, variables?: {}): void;
34
35
  unsubscribe(spec: SubscriptionSpec, variables?: {}): void;
35
36
  list(name: string, parentID?: string, allLists?: boolean): ListCollection;
36
- delete(id: string): void;
37
+ delete(id: string, layer?: Layer): void;
37
38
  setConfig(config: ConfigFile): void;
38
39
  markTypeStale(options?: {
39
40
  type: string;
@@ -46,6 +47,9 @@ export declare class Cache {
46
47
  }): void;
47
48
  getFieldTime(id: string, field: string): number | null | undefined;
48
49
  config(): ConfigFile;
50
+ serialize(): string;
51
+ hydrate(...args: Parameters<InMemoryStorage['hydrate']>): void;
52
+ clearLayer(layerID: Layer['id']): void;
49
53
  }
50
54
  declare class CacheInternal {
51
55
  private _disabled;
@@ -33,20 +33,7 @@ class Cache {
33
33
  }) {
34
34
  const layer = layerID ? this._internal_unstable.storage.getLayer(layerID) : this._internal_unstable.storage.topLayer;
35
35
  const subscribers = this._internal_unstable.writeSelection({ ...args, layer }).map((sub) => sub[0]);
36
- const notified = [];
37
- for (const spec of subscribers.concat(notifySubscribers)) {
38
- if (!notified.includes(spec.set)) {
39
- notified.push(spec.set);
40
- spec.set(
41
- this._internal_unstable.getSelection({
42
- parent: spec.parentID || rootID,
43
- selection: spec.selection,
44
- variables: spec.variables?.() || {},
45
- ignoreMasking: false
46
- }).data
47
- );
48
- }
49
- }
36
+ this.#notifySubscribers(subscribers.concat(notifySubscribers));
50
37
  return subscribers;
51
38
  }
52
39
  read(...args) {
@@ -85,10 +72,10 @@ class Cache {
85
72
  }
86
73
  return handler;
87
74
  }
88
- delete(id) {
75
+ delete(id, layer) {
89
76
  this._internal_unstable.subscriptions.removeAllSubscribers(id);
90
- this._internal_unstable.lists.removeIDFromAllLists(id);
91
- this._internal_unstable.storage.delete(id);
77
+ this._internal_unstable.lists.removeIDFromAllLists(id, layer);
78
+ this._internal_unstable.storage.delete(id, layer);
92
79
  }
93
80
  setConfig(config) {
94
81
  this._internal_unstable.setConfig(config);
@@ -120,6 +107,76 @@ class Cache {
120
107
  config() {
121
108
  return this._internal_unstable.config;
122
109
  }
110
+ serialize() {
111
+ return this._internal_unstable.storage.serialize();
112
+ }
113
+ hydrate(...args) {
114
+ return this._internal_unstable.storage.hydrate(...args);
115
+ }
116
+ clearLayer(layerID) {
117
+ const layer = this._internal_unstable.storage.getLayer(layerID);
118
+ if (!layer) {
119
+ throw new Error("Cannot find layer with id: " + layerID);
120
+ }
121
+ const toNotify = [];
122
+ const allFields = [];
123
+ for (const target of [layer.fields, layer.links]) {
124
+ for (const [id, fields] of Object.entries(target)) {
125
+ allFields.push(
126
+ ...Object.entries(fields).map(([field, value]) => ({ id, field, value }))
127
+ );
128
+ }
129
+ }
130
+ const displayFields = [];
131
+ for (const pair of allFields) {
132
+ const { displayLayers } = this._internal_unstable.storage.get(pair.id, pair.field);
133
+ if (!displayLayers.includes(layerID)) {
134
+ continue;
135
+ }
136
+ displayFields.push(pair);
137
+ }
138
+ for (const [id, operation] of Object.entries(layer.operations)) {
139
+ if (operation.deleted) {
140
+ displayFields.push(
141
+ ...this._internal_unstable.subscriptions.activeFields(id).map((field) => ({ id, field }))
142
+ );
143
+ }
144
+ const fields = Object.keys(operation.fields ?? {});
145
+ if (fields.length > 0) {
146
+ displayFields.push(...fields.map((field) => ({ id, field })));
147
+ }
148
+ }
149
+ layer.clear();
150
+ for (const display of displayFields) {
151
+ const { field, id } = display;
152
+ const notify = !("value" in display) || this._internal_unstable.storage.get(id, field).value !== display.value;
153
+ if (notify) {
154
+ toNotify.push(
155
+ ...this._internal_unstable.subscriptions.get(id, field).map((sub) => sub[0])
156
+ );
157
+ }
158
+ }
159
+ this.#notifySubscribers(toNotify);
160
+ }
161
+ #notifySubscribers(subs) {
162
+ if (subs.length === 0) {
163
+ return;
164
+ }
165
+ const notified = [];
166
+ for (const spec of subs) {
167
+ if (!notified.includes(spec.set)) {
168
+ notified.push(spec.set);
169
+ spec.set(
170
+ this._internal_unstable.getSelection({
171
+ parent: spec.parentID || rootID,
172
+ selection: spec.selection,
173
+ variables: spec.variables?.() || {},
174
+ ignoreMasking: false
175
+ }).data
176
+ );
177
+ }
178
+ }
179
+ }
123
180
  }
124
181
  class CacheInternal {
125
182
  _disabled = false;
@@ -407,8 +464,16 @@ class CacheInternal {
407
464
  operation.position || "last",
408
465
  layer
409
466
  );
467
+ } else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
468
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement({
469
+ selection: fieldSelection,
470
+ data: target,
471
+ variables,
472
+ where: operation.position || "last",
473
+ layer
474
+ });
410
475
  } else if (operation.action === "remove" && target instanceof Object && fieldSelection && operation.list) {
411
- this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
476
+ this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables, layer);
412
477
  } else if (operation.action === "delete" && operation.type) {
413
478
  if (typeof target !== "string") {
414
479
  throw new Error("Cannot delete a record with a non-string ID");
@@ -417,15 +482,7 @@ class CacheInternal {
417
482
  if (!targetID) {
418
483
  continue;
419
484
  }
420
- this.cache.delete(targetID);
421
- } else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
422
- this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement({
423
- selection: fieldSelection,
424
- data: target,
425
- variables,
426
- where: operation.position || "last",
427
- layer
428
- });
485
+ this.cache.delete(targetID, layer);
429
486
  }
430
487
  }
431
488
  }
@@ -21,7 +21,7 @@ export declare class ListManager {
21
21
  filters?: List['filters'];
22
22
  abstract?: boolean;
23
23
  }): void;
24
- removeIDFromAllLists(id: string): void;
24
+ removeIDFromAllLists(id: string, layer?: Layer): void;
25
25
  deleteField(parentID: string, field: string): void;
26
26
  }
27
27
  export declare class List {
@@ -54,8 +54,8 @@ export declare class List {
54
54
  layer?: Layer;
55
55
  }): void;
56
56
  addToList(selection: SubscriptionSelection, data: {}, variables: {} | undefined, where: 'first' | 'last', layer?: Layer): void;
57
- removeID(id: string, variables?: {}): true | undefined;
58
- remove(data: {}, variables?: {}): true | undefined;
57
+ removeID(id: string, variables?: {}, layer?: Layer): true | undefined;
58
+ remove(data: {}, variables?: {}, layer?: Layer): true | undefined;
59
59
  listType(data: {
60
60
  __typename?: string;
61
61
  }): string;
@@ -64,10 +64,10 @@ class ListManager {
64
64
  this.lists.get(list.name).get(parentID).lists.push(handler);
65
65
  this.listsByField.get(parentID).get(list.key).push(handler);
66
66
  }
67
- removeIDFromAllLists(id) {
67
+ removeIDFromAllLists(id, layer) {
68
68
  for (const fieldMap of this.lists.values()) {
69
69
  for (const list of fieldMap.values()) {
70
- list.removeID(id);
70
+ list.removeID(id, void 0, layer);
71
71
  }
72
72
  }
73
73
  }
@@ -164,6 +164,10 @@ class List {
164
164
  updates: ["append", "prepend"],
165
165
  selection: {
166
166
  fields: {
167
+ __typename: {
168
+ keyRaw: "__typename",
169
+ type: "String"
170
+ },
167
171
  node: {
168
172
  type: listType,
169
173
  keyRaw: "node",
@@ -188,7 +192,15 @@ class List {
188
192
  };
189
193
  insertData = {
190
194
  newEntry: {
191
- edges: [{ node: { ...data, __typename: listType } }]
195
+ edges: [
196
+ {
197
+ __typename: listType + "Edge",
198
+ node: {
199
+ ...data,
200
+ __typename: listType
201
+ }
202
+ }
203
+ ]
192
204
  }
193
205
  };
194
206
  } else {
@@ -224,7 +236,7 @@ class List {
224
236
  layer: layer?.id
225
237
  });
226
238
  }
227
- removeID(id, variables = {}) {
239
+ removeID(id, variables = {}, layer) {
228
240
  if (!this.validateWhen()) {
229
241
  return;
230
242
  }
@@ -271,7 +283,7 @@ class List {
271
283
  subscribers.map((sub) => sub[0]),
272
284
  variables
273
285
  );
274
- this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID);
286
+ this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID, layer);
275
287
  for (const [spec] of subscribers) {
276
288
  spec.set(
277
289
  this.cache._internal_unstable.getSelection({
@@ -284,12 +296,12 @@ class List {
284
296
  }
285
297
  return true;
286
298
  }
287
- remove(data, variables = {}) {
299
+ remove(data, variables = {}, layer) {
288
300
  const targetID = this.cache._internal_unstable.id(this.listType(data), data);
289
301
  if (!targetID) {
290
302
  return;
291
303
  }
292
- return this.removeID(targetID, variables);
304
+ return this.removeID(targetID, variables, layer);
293
305
  }
294
306
  listType(data) {
295
307
  return data.__typename || this.type;
@@ -321,7 +333,7 @@ class List {
321
333
  layer,
322
334
  where
323
335
  }) {
324
- if (!this.remove(data, variables)) {
336
+ if (!this.remove(data, variables, layer)) {
325
337
  this.addToList(selection, data, variables, where, layer);
326
338
  }
327
339
  }
@@ -8,8 +8,8 @@ export declare class InMemoryStorage {
8
8
  get nextRank(): number;
9
9
  createLayer(optimistic?: boolean): Layer;
10
10
  insert(id: string, field: string, location: OperationLocations, target: string): void;
11
- remove(id: string, field: string, target: string): void;
12
- delete(id: string): void;
11
+ remove(id: string, field: string, target: string, layerToUser?: Layer): void;
12
+ delete(id: string, layerToUser?: Layer): void;
13
13
  deleteField(id: string, field: string): void;
14
14
  getLayer(id: number): Layer;
15
15
  replaceID(replacement: {
@@ -25,6 +25,12 @@ export declare class InMemoryStorage {
25
25
  writeField(id: string, field: string, value: GraphQLValue): number;
26
26
  resolveLayer(id: number): void;
27
27
  get topLayer(): Layer;
28
+ serialize(): string;
29
+ hydrate(args?: {
30
+ rank: number;
31
+ fields: EntityFieldMap;
32
+ links: LinkMap;
33
+ }, layer?: Layer): void;
28
34
  }
29
35
  export declare class Layer {
30
36
  readonly id: LayerID;
@@ -1,7 +1,7 @@
1
1
  import { flatten } from "../lib/flatten";
2
2
  class InMemoryStorage {
3
3
  data;
4
- idCount = 0;
4
+ idCount = 1;
5
5
  rank = 0;
6
6
  constructor() {
7
7
  this.data = [];
@@ -21,11 +21,11 @@ class InMemoryStorage {
21
21
  insert(id, field, location, target) {
22
22
  return this.topLayer.insert(id, field, location, target);
23
23
  }
24
- remove(id, field, target) {
25
- return this.topLayer.remove(id, field, target);
24
+ remove(id, field, target, layerToUser = this.topLayer) {
25
+ return layerToUser.remove(id, field, target);
26
26
  }
27
- delete(id) {
28
- return this.topLayer.delete(id);
27
+ delete(id, layerToUser = this.topLayer) {
28
+ return layerToUser.delete(id);
29
29
  }
30
30
  deleteField(id, field) {
31
31
  return this.topLayer.deleteField(id, field);
@@ -159,6 +159,23 @@ class InMemoryStorage {
159
159
  }
160
160
  return this.data[this.data.length - 1];
161
161
  }
162
+ serialize() {
163
+ return JSON.stringify({
164
+ rank: this.rank,
165
+ fields: this.topLayer.fields,
166
+ links: this.topLayer.links
167
+ });
168
+ }
169
+ hydrate(args, layer) {
170
+ if (!args) {
171
+ return;
172
+ }
173
+ const { rank, fields, links } = args;
174
+ this.rank = rank;
175
+ layer ??= this.createLayer(true);
176
+ layer.fields = fields;
177
+ layer.links = links;
178
+ }
162
179
  }
163
180
  class Layer {
164
181
  id;
@@ -10,6 +10,7 @@ export declare class InMemorySubscriptions {
10
10
  private subscribers;
11
11
  private referenceCounts;
12
12
  private keyVersions;
13
+ activeFields(parent: string): string[];
13
14
  add({ parent, spec, selection, variables, parentType, }: {
14
15
  parent: string;
15
16
  parentType?: string;
@@ -9,6 +9,9 @@ class InMemorySubscriptions {
9
9
  subscribers = {};
10
10
  referenceCounts = {};
11
11
  keyVersions = {};
12
+ activeFields(parent) {
13
+ return Object.keys(this.subscribers[parent] || {});
14
+ }
12
15
  add({
13
16
  parent,
14
17
  spec,
@@ -1,21 +1,27 @@
1
1
  import type { HoudiniClient } from '.';
2
+ import type { Cache } from '../cache/cache';
2
3
  import type { Layer } from '../cache/storage';
3
4
  import type { ConfigFile } from '../lib/config';
4
5
  import { Writable } from '../lib/store';
5
6
  import type { DocumentArtifact, QueryResult, GraphQLObject, SubscriptionSpec, CachePolicies, GraphQLVariables } from '../lib/types';
6
7
  export declare class DocumentStore<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends Writable<QueryResult<_Data, _Input>> {
7
8
  #private;
9
+ readonly artifact: DocumentArtifact;
8
10
  pendingPromise: {
9
11
  then: (val: any) => void;
10
12
  } | null;
11
- constructor({ artifact, plugins, pipeline, client, cache, initialValue, fetching, }: {
13
+ serverSideFallback?: boolean;
14
+ constructor({ artifact, plugins, pipeline, client, cache, enableCache, initialValue, initialVariables, fetching, }: {
12
15
  artifact: DocumentArtifact;
13
16
  plugins?: ClientHooks[];
14
17
  pipeline?: ClientHooks[];
15
18
  client: HoudiniClient | null;
16
- cache?: boolean;
19
+ cache?: Cache;
20
+ enableCache?: boolean;
17
21
  initialValue?: _Data | null;
18
22
  fetching?: boolean;
23
+ serverSideFallback?: boolean;
24
+ initialVariables?: _Input;
19
25
  });
20
26
  send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, silenceEcho, }?: SendParams): Promise<QueryResult<_Data, _Input>>;
21
27
  cleanup(): Promise<void>;
@@ -51,6 +57,7 @@ export type ClientPluginContext = {
51
57
  disableRead?: boolean;
52
58
  disableSubscriptions?: boolean;
53
59
  applyUpdates?: string[];
60
+ serverSideFallback?: boolean;
54
61
  };
55
62
  stuff: App.Stuff;
56
63
  };
@@ -9,20 +9,23 @@ const steps = {
9
9
  backwards: ["end", "afterNetwork"]
10
10
  };
11
11
  class DocumentStore extends Writable {
12
- #artifact;
12
+ artifact;
13
13
  #client;
14
14
  #configFile;
15
15
  #plugins;
16
16
  #lastVariables;
17
17
  #lastContext = null;
18
18
  pendingPromise = null;
19
+ serverSideFallback;
19
20
  constructor({
20
21
  artifact,
21
22
  plugins,
22
23
  pipeline,
23
24
  client,
24
- cache = true,
25
+ cache,
26
+ enableCache = true,
25
27
  initialValue,
28
+ initialVariables,
26
29
  fetching
27
30
  }) {
28
31
  fetching ??= artifact.kind === ArtifactKind.Query;
@@ -33,7 +36,7 @@ class DocumentStore extends Writable {
33
36
  stale: false,
34
37
  source: null,
35
38
  fetching,
36
- variables: null
39
+ variables: initialVariables ?? null
37
40
  };
38
41
  super(initialState, () => {
39
42
  return () => {
@@ -41,13 +44,14 @@ class DocumentStore extends Writable {
41
44
  this.cleanup();
42
45
  };
43
46
  });
44
- this.#artifact = artifact;
47
+ this.artifact = artifact;
45
48
  this.#client = client;
46
49
  this.#lastVariables = null;
47
50
  this.#configFile = getCurrentConfig();
48
51
  this.#plugins = pipeline ?? [
49
52
  cachePolicy({
50
- enabled: cache,
53
+ cache,
54
+ enabled: enableCache,
51
55
  setFetching: (fetching2, data) => {
52
56
  this.update((state) => {
53
57
  const newState = { ...state, fetching: fetching2 };
@@ -74,9 +78,9 @@ class DocumentStore extends Writable {
74
78
  } = {}) {
75
79
  let context = new ClientPluginContextWrapper({
76
80
  config: this.#configFile,
77
- text: this.#artifact.raw,
78
- hash: this.#artifact.hash,
79
- policy: policy ?? this.#artifact.policy,
81
+ text: this.artifact.raw,
82
+ hash: this.artifact.hash,
83
+ policy: policy ?? this.artifact.policy,
80
84
  variables: null,
81
85
  metadata,
82
86
  session,
@@ -89,7 +93,7 @@ class DocumentStore extends Writable {
89
93
  },
90
94
  ...stuff
91
95
  },
92
- artifact: this.#artifact,
96
+ artifact: this.artifact,
93
97
  lastVariables: this.#lastVariables,
94
98
  cacheParams
95
99
  });
@@ -1,4 +1,5 @@
1
1
  /// <reference path="../../../../../houdini.d.ts" />
2
+ import type { Cache } from '../cache/cache';
2
3
  import type { DocumentArtifact, GraphQLVariables, GraphQLObject, NestedList } from '../lib/types';
3
4
  import type { ClientHooks, ClientPlugin } from './documentStore';
4
5
  import { DocumentStore } from './documentStore';
@@ -12,10 +13,12 @@ export type HoudiniClientConstructorArgs = {
12
13
  pipeline?: NestedList<ClientPlugin>;
13
14
  throwOnError?: ThrowOnErrorParams;
14
15
  };
15
- export type ObserveParams<_Data extends GraphQLObject, _Artifact extends DocumentArtifact = DocumentArtifact> = {
16
+ export type ObserveParams<_Data extends GraphQLObject, _Artifact extends DocumentArtifact = DocumentArtifact, _Input extends GraphQLVariables = GraphQLVariables> = {
16
17
  artifact: _Artifact;
17
- cache?: boolean;
18
+ enableCache?: boolean;
19
+ cache?: Cache;
18
20
  initialValue?: _Data | null;
21
+ initialVariables?: _Input;
19
22
  fetching?: boolean;
20
23
  };
21
24
  export declare class HoudiniClient {
@@ -23,6 +26,6 @@ export declare class HoudiniClient {
23
26
  readonly plugins: ClientPlugin[];
24
27
  readonly throwOnError_operations: ThrowOnErrorOperations[];
25
28
  constructor({ url, fetchParams, plugins, pipeline, throwOnError, }: HoudiniClientConstructorArgs);
26
- observe<_Data extends GraphQLObject, _Input extends GraphQLVariables>({ artifact, cache, initialValue, fetching, }: ObserveParams<_Data>): DocumentStore<_Data, _Input>;
29
+ observe<_Data extends GraphQLObject, _Input extends GraphQLVariables>({ enableCache, fetching, ...rest }: ObserveParams<_Data, DocumentArtifact, _Input>): DocumentStore<_Data, _Input>;
27
30
  }
28
31
  export declare function createPluginHooks(plugins: ClientPlugin[]): ClientHooks[];