houdini 1.0.0-next.1 → 1.0.0-next.11

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 (256) hide show
  1. package/build/cmd/generate.d.ts +0 -1
  2. package/build/cmd-cjs/index.js +3487 -4695
  3. package/build/cmd-esm/index.js +3473 -4681
  4. package/build/codegen/generators/artifacts/fieldKey.d.ts +1 -1
  5. package/build/codegen/generators/artifacts/index.d.ts +2 -2
  6. package/build/codegen/generators/artifacts/indexFile.d.ts +2 -2
  7. package/build/codegen/generators/artifacts/inputs.d.ts +2 -2
  8. package/build/codegen/generators/artifacts/operations.d.ts +2 -2
  9. package/build/codegen/generators/artifacts/selection.d.ts +5 -5
  10. package/build/codegen/generators/artifacts/utils.d.ts +1 -2
  11. package/build/codegen/generators/definitions/enums.d.ts +1 -1
  12. package/build/codegen/generators/definitions/index.d.ts +1 -1
  13. package/build/codegen/generators/indexFile/index.d.ts +2 -2
  14. package/build/codegen/generators/persistedQueries/index.d.ts +2 -2
  15. package/build/codegen/generators/runtime/graphqlFunction.d.ts +2 -0
  16. package/build/codegen/generators/runtime/index.d.ts +2 -2
  17. package/build/codegen/generators/runtime/injectPlugins.d.ts +7 -0
  18. package/build/codegen/generators/runtime/pluginIndex.d.ts +5 -0
  19. package/build/codegen/generators/typescript/addReferencedInputTypes.d.ts +1 -1
  20. package/build/codegen/generators/typescript/documentTypes.d.ts +2 -0
  21. package/build/codegen/generators/typescript/imperativeTypeDef.d.ts +2 -0
  22. package/build/codegen/generators/typescript/index.d.ts +2 -2
  23. package/build/codegen/generators/typescript/inlineType.d.ts +1 -1
  24. package/build/codegen/generators/typescript/typeReference.d.ts +5 -3
  25. package/build/codegen/generators/typescript/types.d.ts +1 -2
  26. package/build/codegen/index.d.ts +2 -2
  27. package/build/codegen/transforms/addID.d.ts +2 -2
  28. package/build/codegen/transforms/composeQueries.d.ts +5 -5
  29. package/build/codegen/transforms/fragmentVariables.d.ts +4 -3
  30. package/build/codegen/transforms/list.d.ts +2 -2
  31. package/build/codegen/transforms/paginate.d.ts +2 -2
  32. package/build/codegen/transforms/schema.d.ts +2 -2
  33. package/build/codegen/transforms/typename.d.ts +2 -2
  34. package/build/codegen/utils/commonjs.d.ts +2 -0
  35. package/build/codegen/utils/flattenSelections.d.ts +2 -2
  36. package/build/codegen/utils/moduleExport.d.ts +1 -1
  37. package/build/codegen/utils/objectIdentificationSelection.d.ts +1 -1
  38. package/build/codegen/validators/noIDAlias.d.ts +2 -2
  39. package/build/codegen/validators/plugins.d.ts +2 -2
  40. package/build/codegen/validators/typeCheck.d.ts +2 -2
  41. package/build/codegen/validators/uniqueNames.d.ts +2 -2
  42. package/build/codegen-cjs/index.js +3020 -4312
  43. package/build/codegen-esm/index.js +3058 -4350
  44. package/build/lib/config.d.ts +17 -91
  45. package/build/lib/deepMerge.d.ts +1 -0
  46. package/build/lib/fs.d.ts +1 -1
  47. package/build/lib/graphql.d.ts +5 -2
  48. package/build/lib/imports.d.ts +1 -1
  49. package/build/lib/index.d.ts +2 -0
  50. package/build/lib/path.d.ts +1 -1
  51. package/build/lib/pipeline.d.ts +1 -1
  52. package/build/lib/plugin.d.ts +2 -0
  53. package/build/lib/types.d.ts +254 -6
  54. package/build/lib/walk.d.ts +8 -5
  55. package/build/lib-cjs/index.js +885 -2394
  56. package/build/lib-esm/index.js +859 -2370
  57. package/build/runtime/cache/cache.d.ts +36 -17
  58. package/build/runtime/cache/gc.d.ts +1 -1
  59. package/build/runtime/cache/lists.d.ts +3 -2
  60. package/build/runtime/cache/schema.d.ts +2 -2
  61. package/build/runtime/cache/staleManager.d.ts +30 -0
  62. package/build/runtime/cache/storage.d.ts +5 -5
  63. package/build/runtime/cache/stuff.d.ts +1 -3
  64. package/build/runtime/cache/subscription.d.ts +20 -11
  65. package/build/runtime/client/documentStore.d.ts +88 -0
  66. package/build/runtime/client/index.d.ts +27 -0
  67. package/build/runtime/client/plugins/cache.d.ts +8 -0
  68. package/build/runtime/client/plugins/fetch.d.ts +37 -0
  69. package/build/runtime/client/plugins/fetchParams.d.ts +9 -0
  70. package/build/runtime/client/plugins/index.d.ts +7 -0
  71. package/build/runtime/client/plugins/injectedPlugins.d.ts +4 -0
  72. package/build/runtime/client/plugins/mutation.d.ts +1 -0
  73. package/build/runtime/client/plugins/query.d.ts +2 -0
  74. package/build/runtime/client/plugins/subscription.d.ts +17 -0
  75. package/build/runtime/client/plugins/throwOnError.d.ts +7 -0
  76. package/build/runtime/client/utils/documentPlugins.d.ts +3 -0
  77. package/build/runtime/client/utils/index.d.ts +1 -0
  78. package/build/runtime/generated.d.ts +1 -0
  79. package/build/runtime/imports/config.d.ts +3 -0
  80. package/build/runtime/index.d.ts +3 -2
  81. package/build/runtime/lib/config.d.ts +30 -25
  82. package/build/runtime/lib/flatten.d.ts +2 -0
  83. package/build/runtime/lib/index.d.ts +2 -2
  84. package/build/runtime/lib/key.d.ts +6 -0
  85. package/build/runtime/lib/scalars.d.ts +6 -5
  86. package/build/runtime/lib/selection.d.ts +1 -1
  87. package/build/runtime/lib/store.d.ts +19 -0
  88. package/build/runtime/lib/types.d.ts +27 -13
  89. package/build/runtime/public/cache.d.ts +27 -7
  90. package/build/runtime/public/list.d.ts +2 -2
  91. package/build/runtime/public/record.d.ts +27 -18
  92. package/build/runtime/public/tests/test.d.ts +53 -11
  93. package/build/runtime/public/types.d.ts +8 -0
  94. package/build/runtime-cjs/cache/cache.d.ts +36 -17
  95. package/build/runtime-cjs/cache/cache.js +102 -33
  96. package/build/runtime-cjs/cache/gc.d.ts +1 -1
  97. package/build/runtime-cjs/cache/gc.js +9 -0
  98. package/build/runtime-cjs/cache/lists.d.ts +3 -2
  99. package/build/runtime-cjs/cache/lists.js +11 -8
  100. package/build/runtime-cjs/cache/schema.d.ts +2 -2
  101. package/build/runtime-cjs/cache/staleManager.d.ts +30 -0
  102. package/build/runtime-cjs/cache/staleManager.js +95 -0
  103. package/build/runtime-cjs/cache/storage.d.ts +5 -5
  104. package/build/runtime-cjs/cache/storage.js +2 -2
  105. package/build/runtime-cjs/cache/stuff.d.ts +1 -3
  106. package/build/runtime-cjs/cache/stuff.js +2 -19
  107. package/build/runtime-cjs/cache/subscription.d.ts +20 -11
  108. package/build/runtime-cjs/cache/subscription.js +102 -59
  109. package/build/runtime-cjs/client/documentStore.d.ts +88 -0
  110. package/build/runtime-cjs/client/documentStore.js +361 -0
  111. package/build/runtime-cjs/client/index.d.ts +27 -0
  112. package/build/runtime-cjs/client/index.js +113 -0
  113. package/build/runtime-cjs/client/plugins/cache.d.ts +8 -0
  114. package/build/runtime-cjs/client/plugins/cache.js +101 -0
  115. package/build/runtime-cjs/client/plugins/fetch.d.ts +37 -0
  116. package/build/runtime-cjs/{lib/networkUtils.js → client/plugins/fetch.js} +96 -3
  117. package/build/runtime-cjs/client/plugins/fetchParams.d.ts +9 -0
  118. package/build/runtime-cjs/client/plugins/fetchParams.js +45 -0
  119. package/build/runtime-cjs/client/plugins/index.d.ts +7 -0
  120. package/build/runtime-cjs/client/plugins/index.js +24 -0
  121. package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +4 -0
  122. package/build/runtime-cjs/{lib/errors.js → client/plugins/injectedPlugins.js} +7 -15
  123. package/build/runtime-cjs/client/plugins/mutation.d.ts +1 -0
  124. package/build/runtime-cjs/client/plugins/mutation.js +86 -0
  125. package/build/runtime-cjs/client/plugins/query.d.ts +2 -0
  126. package/build/runtime-cjs/client/plugins/query.js +83 -0
  127. package/build/runtime-cjs/client/plugins/subscription.d.ts +17 -0
  128. package/build/runtime-cjs/client/plugins/subscription.js +100 -0
  129. package/build/runtime-cjs/client/plugins/throwOnError.d.ts +7 -0
  130. package/build/runtime-cjs/client/plugins/throwOnError.js +47 -0
  131. package/build/runtime-cjs/client/utils/documentPlugins.d.ts +3 -0
  132. package/build/runtime-cjs/client/utils/documentPlugins.js +56 -0
  133. package/build/runtime-cjs/client/utils/index.d.ts +1 -0
  134. package/build/runtime-cjs/client/utils/index.js +18 -0
  135. package/build/runtime-cjs/generated.d.ts +1 -0
  136. package/build/runtime-cjs/imports/config.d.ts +3 -0
  137. package/build/runtime-cjs/imports/config.js +26 -0
  138. package/build/runtime-cjs/index.d.ts +3 -2
  139. package/build/runtime-cjs/index.js +1 -0
  140. package/build/runtime-cjs/lib/config.d.ts +30 -25
  141. package/build/runtime-cjs/lib/config.js +5 -4
  142. package/build/runtime-cjs/lib/flatten.d.ts +2 -0
  143. package/build/runtime-cjs/lib/flatten.js +41 -0
  144. package/build/runtime-cjs/lib/index.d.ts +2 -2
  145. package/build/runtime-cjs/lib/index.js +2 -2
  146. package/build/runtime-cjs/lib/key.d.ts +6 -0
  147. package/build/runtime-cjs/lib/key.js +41 -0
  148. package/build/runtime-cjs/lib/scalars.d.ts +6 -5
  149. package/build/runtime-cjs/lib/scalars.js +20 -24
  150. package/build/runtime-cjs/lib/selection.d.ts +1 -1
  151. package/build/runtime-cjs/lib/store.d.ts +19 -0
  152. package/build/runtime-cjs/lib/store.js +81 -0
  153. package/build/runtime-cjs/lib/types.d.ts +27 -13
  154. package/build/runtime-cjs/public/cache.d.ts +27 -7
  155. package/build/runtime-cjs/public/cache.js +32 -32
  156. package/build/runtime-cjs/public/list.d.ts +2 -2
  157. package/build/runtime-cjs/public/list.js +6 -28
  158. package/build/runtime-cjs/public/record.d.ts +27 -18
  159. package/build/runtime-cjs/public/record.js +28 -188
  160. package/build/runtime-cjs/public/tests/test.d.ts +53 -11
  161. package/build/runtime-cjs/public/tests/test.js +27 -2
  162. package/build/runtime-cjs/public/types.d.ts +8 -0
  163. package/build/runtime-esm/cache/cache.d.ts +36 -17
  164. package/build/runtime-esm/cache/cache.js +104 -35
  165. package/build/runtime-esm/cache/gc.d.ts +1 -1
  166. package/build/runtime-esm/cache/gc.js +9 -0
  167. package/build/runtime-esm/cache/lists.d.ts +3 -2
  168. package/build/runtime-esm/cache/lists.js +11 -8
  169. package/build/runtime-esm/cache/schema.d.ts +2 -2
  170. package/build/runtime-esm/cache/staleManager.d.ts +30 -0
  171. package/build/runtime-esm/cache/staleManager.js +71 -0
  172. package/build/runtime-esm/cache/storage.d.ts +5 -5
  173. package/build/runtime-esm/cache/storage.js +2 -2
  174. package/build/runtime-esm/cache/stuff.d.ts +1 -3
  175. package/build/runtime-esm/cache/stuff.js +1 -17
  176. package/build/runtime-esm/cache/subscription.d.ts +20 -11
  177. package/build/runtime-esm/cache/subscription.js +103 -60
  178. package/build/runtime-esm/client/documentStore.d.ts +88 -0
  179. package/build/runtime-esm/client/documentStore.js +337 -0
  180. package/build/runtime-esm/client/index.d.ts +27 -0
  181. package/build/runtime-esm/client/index.js +83 -0
  182. package/build/runtime-esm/client/plugins/cache.d.ts +8 -0
  183. package/build/runtime-esm/client/plugins/cache.js +71 -0
  184. package/build/runtime-esm/client/plugins/fetch.d.ts +37 -0
  185. package/build/runtime-esm/client/plugins/fetch.js +152 -0
  186. package/build/runtime-esm/client/plugins/fetchParams.d.ts +9 -0
  187. package/build/runtime-esm/client/plugins/fetchParams.js +21 -0
  188. package/build/runtime-esm/client/plugins/index.d.ts +7 -0
  189. package/build/runtime-esm/client/plugins/index.js +7 -0
  190. package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +4 -0
  191. package/build/runtime-esm/client/plugins/injectedPlugins.js +5 -0
  192. package/build/runtime-esm/client/plugins/mutation.d.ts +1 -0
  193. package/build/runtime-esm/client/plugins/mutation.js +56 -0
  194. package/build/runtime-esm/client/plugins/query.d.ts +2 -0
  195. package/build/runtime-esm/client/plugins/query.js +53 -0
  196. package/build/runtime-esm/client/plugins/subscription.d.ts +17 -0
  197. package/build/runtime-esm/client/plugins/subscription.js +76 -0
  198. package/build/runtime-esm/client/plugins/throwOnError.d.ts +7 -0
  199. package/build/runtime-esm/client/plugins/throwOnError.js +23 -0
  200. package/build/runtime-esm/client/utils/documentPlugins.d.ts +3 -0
  201. package/build/runtime-esm/client/utils/documentPlugins.js +32 -0
  202. package/build/runtime-esm/client/utils/index.d.ts +1 -0
  203. package/build/runtime-esm/client/utils/index.js +1 -0
  204. package/build/runtime-esm/generated.d.ts +1 -0
  205. package/build/runtime-esm/imports/config.d.ts +3 -0
  206. package/build/runtime-esm/imports/config.js +4 -0
  207. package/build/runtime-esm/index.d.ts +3 -2
  208. package/build/runtime-esm/index.js +1 -0
  209. package/build/runtime-esm/lib/config.d.ts +30 -25
  210. package/build/runtime-esm/lib/config.js +5 -4
  211. package/build/runtime-esm/lib/flatten.d.ts +2 -0
  212. package/build/runtime-esm/lib/flatten.js +17 -0
  213. package/build/runtime-esm/lib/index.d.ts +2 -2
  214. package/build/runtime-esm/lib/index.js +2 -2
  215. package/build/runtime-esm/lib/key.d.ts +6 -0
  216. package/build/runtime-esm/lib/key.js +17 -0
  217. package/build/runtime-esm/lib/scalars.d.ts +6 -5
  218. package/build/runtime-esm/lib/scalars.js +20 -24
  219. package/build/runtime-esm/lib/selection.d.ts +1 -1
  220. package/build/runtime-esm/lib/store.d.ts +19 -0
  221. package/build/runtime-esm/lib/store.js +57 -0
  222. package/build/runtime-esm/lib/types.d.ts +27 -13
  223. package/build/runtime-esm/public/cache.d.ts +27 -7
  224. package/build/runtime-esm/public/cache.js +31 -30
  225. package/build/runtime-esm/public/list.d.ts +2 -2
  226. package/build/runtime-esm/public/list.js +6 -28
  227. package/build/runtime-esm/public/record.d.ts +27 -18
  228. package/build/runtime-esm/public/record.js +27 -184
  229. package/build/runtime-esm/public/tests/test.d.ts +53 -11
  230. package/build/runtime-esm/public/tests/test.js +26 -1
  231. package/build/runtime-esm/public/types.d.ts +8 -0
  232. package/build/test/index.d.ts +6 -5
  233. package/build/test-cjs/index.js +3051 -4304
  234. package/build/test-esm/index.js +3048 -4301
  235. package/build/vite/ast.d.ts +1 -1
  236. package/build/vite/houdini.d.ts +1 -1
  237. package/build/vite/imports.d.ts +3 -3
  238. package/build/vite/index.d.ts +1 -1
  239. package/build/vite/schema.d.ts +1 -1
  240. package/build/vite-cjs/index.js +3499 -4691
  241. package/build/vite-esm/index.js +3448 -4640
  242. package/package.json +6 -5
  243. package/build/codegen/generators/typescript/imperativeCache.d.ts +0 -2
  244. package/build/runtime/lib/errors.d.ts +0 -3
  245. package/build/runtime/lib/network.d.ts +0 -79
  246. package/build/runtime/lib/networkUtils.d.ts +0 -8
  247. package/build/runtime-cjs/lib/errors.d.ts +0 -3
  248. package/build/runtime-cjs/lib/network.d.ts +0 -79
  249. package/build/runtime-cjs/lib/network.js +0 -200
  250. package/build/runtime-cjs/lib/networkUtils.d.ts +0 -8
  251. package/build/runtime-esm/lib/errors.d.ts +0 -3
  252. package/build/runtime-esm/lib/errors.js +0 -11
  253. package/build/runtime-esm/lib/network.d.ts +0 -79
  254. package/build/runtime-esm/lib/network.js +0 -170
  255. package/build/runtime-esm/lib/networkUtils.d.ts +0 -8
  256. package/build/runtime-esm/lib/networkUtils.js +0 -60
@@ -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
+ });
@@ -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 }: {
@@ -52,14 +52,14 @@ export declare class Layer {
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,7 +69,7 @@ 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
74
  kind: OperationKind.insert;
75
75
  location: OperationLocation;
@@ -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
  }
@@ -1,6 +1,4 @@
1
- import { GraphQLValue } from '../lib/types';
2
- import { LinkedList } from './cache';
3
- export declare function flattenList<T>(source: LinkedList<T>): T[];
1
+ import type { GraphQLValue } from '../lib/types';
4
2
  export declare function evaluateKey(key: string, variables?: {
5
3
  [key: string]: GraphQLValue;
6
4
  }): string;
@@ -18,25 +18,9 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var stuff_exports = {};
20
20
  __export(stuff_exports, {
21
- evaluateKey: () => evaluateKey,
22
- flattenList: () => flattenList
21
+ evaluateKey: () => evaluateKey
23
22
  });
24
23
  module.exports = __toCommonJS(stuff_exports);
25
- function flattenList(source) {
26
- const flat = [];
27
- const unvisited = [source || []];
28
- while (unvisited.length > 0) {
29
- const target = unvisited.shift();
30
- for (const id of target) {
31
- if (Array.isArray(id)) {
32
- unvisited.push(id);
33
- continue;
34
- }
35
- flat.push(id);
36
- }
37
- }
38
- return flat;
39
- }
40
24
  function evaluateKey(key, variables = {}) {
41
25
  let evaluated = "";
42
26
  let varName = "";
@@ -65,6 +49,5 @@ function evaluateKey(key, variables = {}) {
65
49
  const varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
66
50
  // Annotate the CommonJS export names for ESM import in node:
67
51
  0 && (module.exports = {
68
- evaluateKey,
69
- flattenList
52
+ evaluateKey
70
53
  });
@@ -1,6 +1,9 @@
1
- import type { SubscriptionSpec, SubscriptionSelection, GraphQLObject } from '../lib/types';
2
- import type { GraphQLValue } from '../lib/types';
3
- import { Cache } from './cache';
1
+ import type { GraphQLValue, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
2
+ import type { Cache } from './cache';
3
+ export type FieldSelection = [
4
+ SubscriptionSpec,
5
+ Required<SubscriptionSelection>['fields'] | undefined
6
+ ];
4
7
  export declare class InMemorySubscriptions {
5
8
  private cache;
6
9
  constructor(cache: Cache);
@@ -16,22 +19,28 @@ export declare class InMemorySubscriptions {
16
19
  [key: string]: GraphQLValue;
17
20
  };
18
21
  }): void;
19
- addFieldSubscription({ id, key, field, spec, parentType, variables, }: {
22
+ addFieldSubscription({ id, key, selection, type, }: {
20
23
  id: string;
21
24
  key: string;
22
- field: Required<SubscriptionSelection>['fields'][string];
23
- spec: SubscriptionSpec;
25
+ selection: FieldSelection;
26
+ type: string;
27
+ }): void;
28
+ registerList({ list, id, key, parentType, selection, filters, variables, }: {
29
+ list: Required<Required<SubscriptionSelection>['fields'][string]>['list'];
30
+ selection: SubscriptionSelection;
31
+ id: string;
24
32
  parentType: string;
25
- variables: GraphQLObject;
33
+ key: string;
34
+ filters: Required<SubscriptionSelection>['fields'][string]['filters'];
35
+ variables: Record<string, any>;
26
36
  }): void;
27
- addMany({ parent, selection, variables, subscribers, parentType, }: {
37
+ addMany({ parent, variables, subscribers, parentType, }: {
28
38
  parent: string;
29
- selection: SubscriptionSelection;
30
39
  variables: {};
31
- subscribers: SubscriptionSpec[];
40
+ subscribers: FieldSelection[];
32
41
  parentType: string;
33
42
  }): void;
34
- get(id: string, field: string): SubscriptionSpec[];
43
+ get(id: string, field: string): FieldSelection[];
35
44
  remove(id: string, selection: SubscriptionSelection, targets: SubscriptionSpec[], variables: {}, visited?: string[]): void;
36
45
  private removeSubscribers;
37
46
  removeAllSubscribers(id: string, targets?: SubscriptionSpec[], visited?: string[]): void;
@@ -21,6 +21,7 @@ __export(subscription_exports, {
21
21
  InMemorySubscriptions: () => InMemorySubscriptions
22
22
  });
23
23
  module.exports = __toCommonJS(subscription_exports);
24
+ var import_flatten = require("../lib/flatten");
24
25
  var import_selection = require("../lib/selection");
25
26
  var import_stuff = require("./stuff");
26
27
  class InMemorySubscriptions {
@@ -41,22 +42,36 @@ class InMemorySubscriptions {
41
42
  const __typename = this.cache._internal_unstable.storage.get(parent, "__typename").value;
42
43
  let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename);
43
44
  for (const fieldSelection of Object.values(targetSelection || {})) {
44
- const { keyRaw, selection: innerSelection, type } = fieldSelection;
45
+ const { keyRaw, selection: innerSelection, type, list, filters } = fieldSelection;
45
46
  const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
47
+ let targetSelection2;
48
+ if (innerSelection) {
49
+ const __typename2 = this.cache._internal_unstable.storage.get(parent, "__typename").value;
50
+ targetSelection2 = (0, import_selection.getFieldsForType)(innerSelection, __typename2);
51
+ }
46
52
  this.addFieldSubscription({
47
53
  id: parent,
48
54
  key,
49
- field: fieldSelection,
50
- spec,
51
- parentType: parentType || spec.rootType,
52
- variables
55
+ selection: [spec, targetSelection2],
56
+ type
53
57
  });
58
+ if (list) {
59
+ this.registerList({
60
+ list,
61
+ filters,
62
+ id: parent,
63
+ key,
64
+ variables,
65
+ selection: innerSelection,
66
+ parentType: parentType || spec.rootType
67
+ });
68
+ }
54
69
  if (innerSelection) {
55
70
  const { value: linkedRecord } = this.cache._internal_unstable.storage.get(
56
71
  parent,
57
72
  key
58
73
  );
59
- let children = !Array.isArray(linkedRecord) ? [linkedRecord] : (0, import_stuff.flattenList)(linkedRecord) || [];
74
+ let children = !Array.isArray(linkedRecord) ? [linkedRecord] : (0, import_flatten.flatten)(linkedRecord) || [];
60
75
  for (const child of children) {
61
76
  if (!child) {
62
77
  continue;
@@ -75,11 +90,10 @@ class InMemorySubscriptions {
75
90
  addFieldSubscription({
76
91
  id,
77
92
  key,
78
- field,
79
- spec,
80
- parentType,
81
- variables
93
+ selection,
94
+ type
82
95
  }) {
96
+ const spec = selection[0];
83
97
  if (!this.subscribers[id]) {
84
98
  this.subscribers[id] = {};
85
99
  }
@@ -90,8 +104,8 @@ class InMemorySubscriptions {
90
104
  this.keyVersions[key] = /* @__PURE__ */ new Set();
91
105
  }
92
106
  this.keyVersions[key].add(key);
93
- if (!this.subscribers[id][key].map(({ set }) => set).includes(spec.set)) {
94
- this.subscribers[id][key].push(spec);
107
+ if (!this.subscribers[id][key].map(([{ set }]) => set).includes(spec.set)) {
108
+ this.subscribers[id][key].push([spec, selection[1]]);
95
109
  }
96
110
  if (!this.referenceCounts[id]) {
97
111
  this.referenceCounts[id] = {};
@@ -102,61 +116,88 @@ class InMemorySubscriptions {
102
116
  const counts = this.referenceCounts[id][key];
103
117
  counts.set(spec.set, (counts.get(spec.set) || 0) + 1);
104
118
  this.cache._internal_unstable.lifetimes.resetLifetime(id, key);
105
- const { selection, list, filters } = field;
106
- if (selection && list) {
107
- this.cache._internal_unstable.lists.add({
108
- name: list.name,
109
- connection: list.connection,
110
- recordID: id,
111
- recordType: this.cache._internal_unstable.storage.get(id, "__typename")?.value || parentType,
112
- listType: list.type,
113
- key,
114
- selection,
115
- filters: Object.entries(filters || {}).reduce((acc, [key2, { kind, value }]) => {
116
- return {
117
- ...acc,
118
- [key2]: kind !== "Variable" ? value : variables[value]
119
- };
120
- }, {})
121
- });
122
- }
119
+ const { selection: innerSelection } = selection[1]?.[key] ?? {};
120
+ }
121
+ registerList({
122
+ list,
123
+ id,
124
+ key,
125
+ parentType,
126
+ selection,
127
+ filters,
128
+ variables
129
+ }) {
130
+ this.cache._internal_unstable.lists.add({
131
+ name: list.name,
132
+ connection: list.connection,
133
+ recordID: id,
134
+ recordType: this.cache._internal_unstable.storage.get(id, "__typename")?.value || parentType,
135
+ listType: list.type,
136
+ key,
137
+ selection,
138
+ filters: Object.entries(filters || {}).reduce((acc, [key2, { kind, value }]) => {
139
+ return {
140
+ ...acc,
141
+ [key2]: kind !== "Variable" ? value : variables[value]
142
+ };
143
+ }, {})
144
+ });
123
145
  }
124
146
  addMany({
125
147
  parent,
126
- selection,
127
148
  variables,
128
149
  subscribers,
129
150
  parentType
130
151
  }) {
131
- let targetSelection = (0, import_selection.getFieldsForType)(selection, parentType);
132
- for (const fieldSelection of Object.values(targetSelection)) {
133
- const { type: linkedType, keyRaw, selection: innerSelection } = fieldSelection;
134
- const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
135
- for (const spec of subscribers) {
152
+ for (const [spec, targetSelection] of subscribers) {
153
+ for (const selection of Object.values(targetSelection ?? {})) {
154
+ const {
155
+ type: linkedType,
156
+ keyRaw,
157
+ selection: innerSelection,
158
+ list,
159
+ filters
160
+ } = selection;
161
+ const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
162
+ const fieldSelection = innerSelection ? (0, import_selection.getFieldsForType)(innerSelection, parentType) : void 0;
136
163
  this.addFieldSubscription({
137
164
  id: parent,
138
165
  key,
139
- field: fieldSelection,
140
- spec,
141
- parentType,
142
- variables
166
+ selection: [spec, fieldSelection],
167
+ type: linkedType
143
168
  });
144
- }
145
- if (innerSelection) {
146
- const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
147
- const children = !Array.isArray(link) ? [link] : (0, import_stuff.flattenList)(link);
148
- for (const linkedRecord of children) {
149
- if (!linkedRecord) {
150
- continue;
151
- }
152
- this.addMany({
153
- parent: linkedRecord,
154
- selection: innerSelection,
169
+ if (list) {
170
+ this.registerList({
171
+ list,
172
+ filters,
173
+ id: parent,
174
+ key,
155
175
  variables,
156
- subscribers,
157
- parentType: linkedType
176
+ selection: innerSelection,
177
+ parentType: parentType || spec.rootType
158
178
  });
159
179
  }
180
+ const childSelection = selection.selection;
181
+ if (childSelection) {
182
+ const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
183
+ const children = !Array.isArray(link) ? [link] : (0, import_flatten.flatten)(link);
184
+ for (const linkedRecord of children) {
185
+ if (!linkedRecord) {
186
+ continue;
187
+ }
188
+ const __typename = this.cache._internal_unstable.storage.get(
189
+ linkedRecord,
190
+ "__typename"
191
+ ).value;
192
+ let targetSelection2 = (0, import_selection.getFieldsForType)(childSelection, __typename);
193
+ this.addMany({
194
+ parent: linkedRecord,
195
+ variables,
196
+ subscribers: subscribers.map(([sub]) => [sub, targetSelection2]),
197
+ parentType: linkedType
198
+ });
199
+ }
200
+ }
160
201
  }
161
202
  }
162
203
  }
@@ -166,14 +207,16 @@ class InMemorySubscriptions {
166
207
  remove(id, selection, targets, variables, visited = []) {
167
208
  visited.push(id);
168
209
  const linkedIDs = [];
169
- for (const fieldSelection of Object.values(selection.fields || {})) {
210
+ const __typename = this.cache._internal_unstable.storage.get(id, "__typename").value;
211
+ let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename);
212
+ for (const fieldSelection of Object.values(targetSelection || {})) {
170
213
  const key = (0, import_stuff.evaluateKey)(fieldSelection.keyRaw, variables);
171
214
  this.removeSubscribers(id, key, targets);
172
- if (!fieldSelection.selection?.fields) {
215
+ if (!fieldSelection.selection) {
173
216
  continue;
174
217
  }
175
218
  const { value: previousValue } = this.cache._internal_unstable.storage.get(id, key);
176
- const links = !Array.isArray(previousValue) ? [previousValue] : (0, import_stuff.flattenList)(previousValue);
219
+ const links = !Array.isArray(previousValue) ? [previousValue] : (0, import_flatten.flatten)(previousValue);
177
220
  for (const link of links) {
178
221
  if (link !== null) {
179
222
  linkedIDs.push([link, fieldSelection.selection || {}]);
@@ -200,20 +243,20 @@ class InMemorySubscriptions {
200
243
  }
201
244
  if (this.subscribers[id]) {
202
245
  this.subscribers[id][fieldName] = this.get(id, fieldName).filter(
203
- ({ set }) => !targets.includes(set)
246
+ ([{ set }]) => !targets.includes(set)
204
247
  );
205
248
  }
206
249
  }
207
250
  removeAllSubscribers(id, targets, visited = []) {
208
251
  visited.push(id);
209
252
  for (const field of Object.keys(this.subscribers[id] || [])) {
210
- const subscribers = targets || this.subscribers[id][field];
253
+ const subscribers = targets || this.subscribers[id][field].map(([spec]) => spec);
211
254
  this.removeSubscribers(id, field, subscribers);
212
255
  const { value, kind } = this.cache._internal_unstable.storage.get(id, field);
213
256
  if (kind === "scalar") {
214
257
  continue;
215
258
  }
216
- const nextTargets = Array.isArray(value) ? (0, import_stuff.flattenList)(value) : [value];
259
+ const nextTargets = Array.isArray(value) ? (0, import_flatten.flatten)(value) : [value];
217
260
  for (const id2 of nextTargets) {
218
261
  if (visited.includes(id2)) {
219
262
  continue;
@@ -0,0 +1,88 @@
1
+ import type { HoudiniClient } from '.';
2
+ import type { Layer } from '../cache/storage';
3
+ import type { ConfigFile } from '../lib/config';
4
+ import { Writable } from '../lib/store';
5
+ import type { CachePolicy, DocumentArtifact, QueryResult, GraphQLObject, SubscriptionSpec } from '../lib/types';
6
+ export declare class DocumentStore<_Data extends GraphQLObject, _Input extends Record<string, any>> extends Writable<QueryResult<_Data, _Input>> {
7
+ #private;
8
+ constructor({ artifact, plugins, pipeline, client, cache, initialValue, fetching, }: {
9
+ artifact: DocumentArtifact;
10
+ plugins?: ClientHooks[];
11
+ pipeline?: ClientHooks[];
12
+ client: HoudiniClient | null;
13
+ cache?: boolean;
14
+ initialValue?: _Data | null;
15
+ fetching?: boolean;
16
+ });
17
+ send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, }?: {
18
+ fetch?: Fetch;
19
+ variables?: Record<string, any> | null;
20
+ metadata?: App.Metadata | null;
21
+ session?: App.Session | null;
22
+ policy?: CachePolicy;
23
+ stuff?: Partial<App.Stuff>;
24
+ cacheParams?: ClientPluginContext['cacheParams'];
25
+ setup?: boolean;
26
+ }): Promise<QueryResult<_Data, _Input>>;
27
+ }
28
+ declare function marshalVariables<_Data extends GraphQLObject, _Input extends {}>(ctx: ClientPluginContext): Record<string, any>;
29
+ export type ClientPlugin = () => ClientHooks | null | (ClientHooks | ClientPlugin | null)[];
30
+ export type ClientHooks = {
31
+ start?: ClientPluginEnterPhase;
32
+ beforeNetwork?: ClientPluginEnterPhase;
33
+ network?: ClientPluginEnterPhase;
34
+ afterNetwork?: ClientPluginExitPhase;
35
+ end?: ClientPluginExitPhase;
36
+ cleanup?(ctx: ClientPluginContext): void | Promise<void>;
37
+ catch?(ctx: ClientPluginContext, args: ClientPluginErrorHandlers): void | Promise<void>;
38
+ };
39
+ export type Fetch = typeof globalThis.fetch;
40
+ export type ClientPluginContext = {
41
+ config: ConfigFile;
42
+ text: string;
43
+ hash: string;
44
+ artifact: DocumentArtifact;
45
+ policy?: CachePolicy;
46
+ fetch?: Fetch;
47
+ variables?: Record<string, any>;
48
+ metadata?: App.Metadata | null;
49
+ session?: App.Session | null;
50
+ fetchParams?: RequestInit;
51
+ cacheParams?: {
52
+ layer?: Layer;
53
+ notifySubscribers?: SubscriptionSpec[];
54
+ forceNotify?: boolean;
55
+ disableWrite?: boolean;
56
+ disableRead?: boolean;
57
+ applyUpdates?: string[];
58
+ };
59
+ stuff: App.Stuff;
60
+ };
61
+ type ClientPluginPhase<Handlers> = (ctx: ClientPluginContext, handlers: Handlers) => void | Promise<void>;
62
+ export type ClientPluginEnterPhase = ClientPluginPhase<ClientPluginEnterHandlers>;
63
+ export type ClientPluginExitPhase = ClientPluginPhase<ClientPluginExitHandlers>;
64
+ export type ClientPluginEnterHandlers = {
65
+ initialValue: QueryResult;
66
+ /** A reference to the houdini client to access any configuration values */
67
+ client: HoudiniClient;
68
+ /** Move onto the next step using the provided context. */
69
+ next(ctx: ClientPluginContext): void;
70
+ /** Terminate the current chain */
71
+ resolve(ctx: ClientPluginContext, data: QueryResult): void;
72
+ /** Update the stores state without resolving the promise */
73
+ updateState(updater: (old: QueryResult) => QueryResult): void;
74
+ /** Return true if the variables have changed */
75
+ variablesChanged: (ctx: ClientPluginContext) => boolean;
76
+ /** Returns the marshaled variables for the operation */
77
+ marshalVariables: typeof marshalVariables;
78
+ };
79
+ /** Exit handlers are the same as enter handles but don't need to resolve with a specific value */
80
+ export type ClientPluginExitHandlers = Omit<ClientPluginEnterHandlers, 'resolve'> & {
81
+ resolve: (ctx: ClientPluginContext, data?: QueryResult) => void;
82
+ value: QueryResult;
83
+ };
84
+ /** Exit handlers are the same as enter handles but don't need to resolve with a specific value */
85
+ export type ClientPluginErrorHandlers = ClientPluginEnterHandlers & {
86
+ error: unknown;
87
+ };
88
+ export {};