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,337 @@
1
+ import { getCurrentConfig } from "../lib/config";
2
+ import { deepEquals } from "../lib/deepEquals";
3
+ import { marshalInputs, unmarshalSelection } from "../lib/scalars";
4
+ import { Writable } from "../lib/store";
5
+ import { ArtifactKind } from "../lib/types";
6
+ import { cachePolicy } from "./plugins";
7
+ const steps = {
8
+ forward: ["start", "beforeNetwork", "network"],
9
+ backwards: ["end", "afterNetwork"]
10
+ };
11
+ class DocumentStore extends Writable {
12
+ #artifact;
13
+ #client;
14
+ #configFile;
15
+ #plugins;
16
+ #lastVariables;
17
+ #lastContext = null;
18
+ constructor({
19
+ artifact,
20
+ plugins,
21
+ pipeline,
22
+ client,
23
+ cache = true,
24
+ initialValue,
25
+ fetching
26
+ }) {
27
+ if (fetching === void 0) {
28
+ fetching = artifact.kind === ArtifactKind.Query;
29
+ }
30
+ const initialState = {
31
+ data: initialValue ?? null,
32
+ errors: null,
33
+ partial: false,
34
+ stale: false,
35
+ source: null,
36
+ fetching,
37
+ variables: null
38
+ };
39
+ super(initialState, () => {
40
+ return () => {
41
+ this.#lastVariables = null;
42
+ for (const plugin of this.#plugins) {
43
+ plugin.cleanup?.(this.#lastContext);
44
+ }
45
+ };
46
+ });
47
+ this.#artifact = artifact;
48
+ this.#client = client;
49
+ this.#lastVariables = null;
50
+ this.#configFile = getCurrentConfig();
51
+ this.#plugins = pipeline ?? [
52
+ cachePolicy({
53
+ enabled: cache,
54
+ setFetching: (fetching2) => this.update((state) => ({ ...state, fetching: fetching2 }))
55
+ })(),
56
+ ...plugins ?? []
57
+ ];
58
+ }
59
+ async send({
60
+ metadata,
61
+ session,
62
+ fetch = globalThis.fetch,
63
+ variables,
64
+ policy,
65
+ stuff,
66
+ cacheParams,
67
+ setup = false
68
+ } = {}) {
69
+ let context = new ClientPluginContextWrapper({
70
+ config: this.#configFile,
71
+ text: this.#artifact.raw,
72
+ hash: this.#artifact.hash,
73
+ policy: policy ?? this.#artifact.policy,
74
+ variables: {},
75
+ metadata,
76
+ session,
77
+ fetch,
78
+ stuff: {
79
+ inputs: {
80
+ changed: false,
81
+ init: false,
82
+ marshaled: {}
83
+ },
84
+ ...stuff
85
+ },
86
+ artifact: this.#artifact,
87
+ lastVariables: this.#lastVariables,
88
+ cacheParams
89
+ });
90
+ const draft = context.draft();
91
+ draft.variables = variables ?? {};
92
+ context = context.apply(draft, false);
93
+ return await new Promise((resolve, reject) => {
94
+ const state = {
95
+ setup,
96
+ currentStep: 0,
97
+ index: 0,
98
+ promise: {
99
+ resolved: false,
100
+ resolve,
101
+ reject
102
+ },
103
+ context
104
+ };
105
+ this.#step("forward", state);
106
+ });
107
+ }
108
+ #step(direction, ctx, value) {
109
+ const hook = direction === "error" ? "catch" : steps[direction][ctx.currentStep];
110
+ let valid = (i) => i <= this.#plugins.length;
111
+ let step = (i) => i + 1;
112
+ if (["backwards", "error"].includes(direction)) {
113
+ valid = (i) => i >= 0;
114
+ step = (i) => i - 1;
115
+ }
116
+ for (let index = ctx.index; valid(index); index = step(index)) {
117
+ let target = this.#plugins[index]?.[hook];
118
+ if (!target) {
119
+ continue;
120
+ }
121
+ const draft = ctx.context.draft();
122
+ let variablesRefChanged = (newContext) => newContext.variables !== draft.variables;
123
+ const common = {
124
+ initialValue: this.state,
125
+ client: this.#client,
126
+ variablesChanged,
127
+ marshalVariables,
128
+ updateState: this.update.bind(this),
129
+ next: (newContext) => {
130
+ const nextIndex = ["forward", "error"].includes(direction) ? index + 1 : index;
131
+ const nextStep = ["backwards", "error"].includes(direction) ? 0 : ctx.currentStep;
132
+ this.#step("forward", {
133
+ ...ctx,
134
+ index: nextIndex,
135
+ currentStep: nextStep,
136
+ context: ctx.context.apply(newContext, variablesRefChanged(newContext))
137
+ });
138
+ },
139
+ resolve: (newContext, value2) => {
140
+ const nextIndex = direction === "backwards" ? index - 1 : index;
141
+ this.#step(
142
+ "backwards",
143
+ {
144
+ ...ctx,
145
+ index: nextIndex,
146
+ context: ctx.context.apply(newContext, variablesRefChanged(newContext))
147
+ },
148
+ value2
149
+ );
150
+ }
151
+ };
152
+ let handlers;
153
+ if (direction === "forward") {
154
+ handlers = common;
155
+ } else if (direction === "backwards") {
156
+ handlers = {
157
+ ...common,
158
+ value,
159
+ resolve: (ctx2, data2) => {
160
+ return common.resolve(ctx2, data2 ?? value);
161
+ }
162
+ };
163
+ } else if (direction === "error") {
164
+ handlers = {
165
+ ...common,
166
+ error: value
167
+ };
168
+ }
169
+ try {
170
+ const result = target(draft, handlers);
171
+ result?.catch((err) => {
172
+ this.#step("error", { ...ctx, index: index - 1 }, err);
173
+ });
174
+ } catch (err) {
175
+ this.#step("error", { ...ctx, index: index - 1 }, err);
176
+ }
177
+ return;
178
+ }
179
+ if (direction === "forward") {
180
+ if (ctx.setup) {
181
+ return this.#step(
182
+ "backwards",
183
+ {
184
+ ...ctx,
185
+ currentStep: 0,
186
+ index: this.#plugins.length
187
+ },
188
+ this.state
189
+ );
190
+ }
191
+ if (ctx.currentStep <= steps.forward.length - 2) {
192
+ return this.#step("forward", {
193
+ ...ctx,
194
+ currentStep: ctx.currentStep + 1,
195
+ index: 0
196
+ });
197
+ }
198
+ throw new Error(
199
+ "Called next() on last possible plugin. Your chain is missing a plugin that calls resolve()."
200
+ );
201
+ }
202
+ if (direction === "error") {
203
+ if (!ctx.promise.resolved) {
204
+ ctx.promise.reject(value);
205
+ ctx.promise.resolved = true;
206
+ }
207
+ return;
208
+ }
209
+ if (ctx.currentStep > 0) {
210
+ return this.#step(
211
+ "backwards",
212
+ {
213
+ ...ctx,
214
+ currentStep: ctx.currentStep - 1,
215
+ index: this.#plugins.length - 1
216
+ },
217
+ value
218
+ );
219
+ }
220
+ let data = value.data;
221
+ try {
222
+ data = unmarshalSelection(this.#configFile, this.#artifact.selection, data) ?? null;
223
+ } catch {
224
+ }
225
+ const finalValue = {
226
+ ...value,
227
+ data
228
+ };
229
+ if (!ctx.promise.resolved) {
230
+ ctx.promise.resolve(finalValue);
231
+ ctx.promise.resolved = true;
232
+ }
233
+ this.#lastContext = ctx.context.draft();
234
+ this.#lastVariables = this.#lastContext.stuff.inputs.marshaled;
235
+ this.set(finalValue);
236
+ }
237
+ }
238
+ class ClientPluginContextWrapper {
239
+ #context;
240
+ #lastVariables;
241
+ constructor({
242
+ lastVariables,
243
+ ...values
244
+ }) {
245
+ this.#context = values;
246
+ this.#lastVariables = lastVariables;
247
+ }
248
+ get variables() {
249
+ return this.#context.variables;
250
+ }
251
+ draft() {
252
+ const ctx = {
253
+ ...this.#context
254
+ };
255
+ const applyVariables = this.applyVariables.bind(this);
256
+ return {
257
+ ...ctx,
258
+ get stuff() {
259
+ return ctx.stuff;
260
+ },
261
+ set stuff(val) {
262
+ ctx.stuff = val;
263
+ },
264
+ get variables() {
265
+ return ctx.variables ?? {};
266
+ },
267
+ set variables(val) {
268
+ Object.assign(ctx, applyVariables(ctx, { variables: val }));
269
+ }
270
+ };
271
+ }
272
+ applyVariables(source, values) {
273
+ const artifact = source.artifact;
274
+ const ctx = {
275
+ ...source,
276
+ ...values
277
+ };
278
+ const val = values.variables;
279
+ let changed = {};
280
+ for (const [name, value] of Object.entries(val ?? {})) {
281
+ if (value !== source.variables?.[name]) {
282
+ changed[name] = value;
283
+ }
284
+ }
285
+ ctx.stuff = {
286
+ ...ctx.stuff,
287
+ inputs: {
288
+ ...ctx.stuff.inputs
289
+ }
290
+ };
291
+ const firstInit = !ctx.stuff.inputs || !ctx.stuff.inputs.init;
292
+ const hasChanged = Object.keys(changed).length > 0 || firstInit;
293
+ if (artifact.kind !== ArtifactKind.Fragment && hasChanged) {
294
+ const newVariables = {
295
+ ...ctx.stuff.inputs?.marshaled,
296
+ ...marshalInputs({
297
+ artifact,
298
+ input: changed,
299
+ config: source.config
300
+ })
301
+ };
302
+ ctx.stuff.inputs = {
303
+ init: true,
304
+ marshaled: newVariables,
305
+ changed: true
306
+ };
307
+ ctx.variables = val;
308
+ }
309
+ ctx.stuff = {
310
+ ...ctx.stuff,
311
+ inputs: {
312
+ ...ctx.stuff.inputs,
313
+ changed: !deepEquals(ctx.stuff.inputs.marshaled, this.#lastVariables)
314
+ }
315
+ };
316
+ return ctx;
317
+ }
318
+ apply(values, newVariables) {
319
+ if (newVariables) {
320
+ values = this.applyVariables(this.#context, values);
321
+ }
322
+ const wrapper = new ClientPluginContextWrapper({
323
+ ...values,
324
+ lastVariables: this.#lastVariables
325
+ });
326
+ return wrapper;
327
+ }
328
+ }
329
+ function marshalVariables(ctx) {
330
+ return ctx.stuff.inputs?.marshaled ?? {};
331
+ }
332
+ function variablesChanged(ctx) {
333
+ return ctx.stuff.inputs?.changed;
334
+ }
335
+ export {
336
+ DocumentStore
337
+ };
@@ -0,0 +1,27 @@
1
+ /// <reference path="../../../../../houdini.d.ts" />
2
+ import type { DocumentArtifact, GraphQLObject, NestedList } from '../lib/types';
3
+ import type { ClientPlugin, ClientHooks } from './documentStore';
4
+ import { DocumentStore } from './documentStore';
5
+ import { type FetchParamFn, type ThrowOnErrorParams } from './plugins';
6
+ export { DocumentStore, type ClientPlugin } from './documentStore';
7
+ export { fetch, mutation, query, subscription } from './plugins';
8
+ type ConstructorArgs = {
9
+ url: string;
10
+ fetchParams?: FetchParamFn;
11
+ plugins?: NestedList<ClientPlugin>;
12
+ pipeline?: NestedList<ClientPlugin>;
13
+ throwOnError?: ThrowOnErrorParams;
14
+ };
15
+ export type ObserveParams<_Data extends GraphQLObject, _Artifact extends DocumentArtifact = DocumentArtifact> = {
16
+ artifact: _Artifact;
17
+ cache?: boolean;
18
+ initialValue?: _Data | null;
19
+ fetching?: boolean;
20
+ };
21
+ export declare class HoudiniClient {
22
+ #private;
23
+ url: string;
24
+ constructor({ url, fetchParams, plugins, pipeline, throwOnError }: ConstructorArgs);
25
+ observe<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, cache, initialValue, fetching, }: ObserveParams<_Data>): DocumentStore<_Data, _Input>;
26
+ }
27
+ export declare function createPluginHooks(plugins: ClientPlugin[]): ClientHooks[];
@@ -0,0 +1,83 @@
1
+ import { flatten } from "../lib/flatten";
2
+ import { DocumentStore } from "./documentStore";
3
+ import {
4
+ fetchParams as fetchParamsPlugin,
5
+ fetch as fetchPlugin,
6
+ mutation as mutationPlugin,
7
+ query as queryPlugin,
8
+ throwOnError as throwOnErrorPlugin
9
+ } from "./plugins";
10
+ import pluginsFromPlugins from "./plugins/injectedPlugins";
11
+ import { DocumentStore as DocumentStore2 } from "./documentStore";
12
+ import { fetch, mutation, query, subscription } from "./plugins";
13
+ class HoudiniClient {
14
+ url;
15
+ #plugins;
16
+ constructor({ url, fetchParams, plugins, pipeline, throwOnError }) {
17
+ if (plugins && pipeline) {
18
+ throw new Error(
19
+ "A client cannot be given a pipeline and a list of plugins at the same time."
20
+ );
21
+ }
22
+ this.#plugins = flatten(
23
+ [].concat(
24
+ throwOnError ? [throwOnErrorPlugin(throwOnError)] : [],
25
+ fetchParamsPlugin(fetchParams),
26
+ pipeline ?? [
27
+ queryPlugin,
28
+ mutationPlugin
29
+ ].concat(
30
+ plugins ?? [],
31
+ pluginsFromPlugins,
32
+ fetchPlugin()
33
+ )
34
+ )
35
+ );
36
+ this.url = url;
37
+ }
38
+ observe({
39
+ artifact,
40
+ cache = true,
41
+ initialValue,
42
+ fetching = false
43
+ }) {
44
+ return new DocumentStore({
45
+ client: this,
46
+ artifact,
47
+ plugins: createPluginHooks(this.#plugins),
48
+ cache,
49
+ initialValue,
50
+ fetching
51
+ });
52
+ }
53
+ }
54
+ function createPluginHooks(plugins) {
55
+ return plugins.reduce((hooks, plugin) => {
56
+ const result = plugin();
57
+ if (!result) {
58
+ return hooks;
59
+ }
60
+ if (!Array.isArray(result)) {
61
+ return hooks.concat(result);
62
+ }
63
+ for (const value of result) {
64
+ if (!value) {
65
+ continue;
66
+ }
67
+ if (typeof value === "function") {
68
+ return hooks.concat(createPluginHooks([value]));
69
+ }
70
+ hooks.push(value);
71
+ }
72
+ return hooks;
73
+ }, []);
74
+ }
75
+ export {
76
+ DocumentStore2 as DocumentStore,
77
+ HoudiniClient,
78
+ createPluginHooks,
79
+ fetch,
80
+ mutation,
81
+ query,
82
+ subscription
83
+ };
@@ -0,0 +1,8 @@
1
+ import cache from '../../cache';
2
+ import type { Cache } from '../../cache/cache';
3
+ import type { ClientPlugin } from '../documentStore';
4
+ export declare const cachePolicy: ({ enabled, setFetching, cache: localCache, }: {
5
+ enabled: boolean;
6
+ setFetching: (val: boolean) => void;
7
+ cache?: Cache | undefined;
8
+ }) => ClientPlugin;
@@ -0,0 +1,71 @@
1
+ import cache from "../../cache";
2
+ import { ArtifactKind, CachePolicy, DataSource } from "../../lib/types";
3
+ const cachePolicy = ({
4
+ enabled,
5
+ setFetching,
6
+ cache: localCache = cache
7
+ }) => () => {
8
+ return {
9
+ network(ctx, { next, resolve, marshalVariables }) {
10
+ const { policy, artifact } = ctx;
11
+ let useCache = false;
12
+ if (enabled && artifact.kind === ArtifactKind.Query && !ctx.cacheParams?.disableRead) {
13
+ if (policy !== CachePolicy.NetworkOnly) {
14
+ const value = localCache.read({
15
+ selection: artifact.selection,
16
+ variables: marshalVariables(ctx)
17
+ });
18
+ const allowed = !value.partial || artifact.kind === ArtifactKind.Query && artifact.partial;
19
+ if (policy === CachePolicy.CacheOnly) {
20
+ return resolve(ctx, {
21
+ fetching: false,
22
+ variables: ctx.variables ?? null,
23
+ data: value.data,
24
+ errors: null,
25
+ source: DataSource.Cache,
26
+ partial: value.partial,
27
+ stale: value.stale
28
+ });
29
+ }
30
+ useCache = !!(value.data !== null && allowed);
31
+ if (useCache) {
32
+ resolve(ctx, {
33
+ fetching: false,
34
+ variables: ctx.variables ?? null,
35
+ data: value.data,
36
+ errors: null,
37
+ source: DataSource.Cache,
38
+ partial: value.partial,
39
+ stale: value.stale
40
+ });
41
+ }
42
+ if (useCache && !value.partial && !value.stale) {
43
+ return;
44
+ }
45
+ }
46
+ }
47
+ if (enabled) {
48
+ setTimeout(() => {
49
+ localCache._internal_unstable.collectGarbage();
50
+ }, 0);
51
+ }
52
+ setFetching(!useCache);
53
+ return next(ctx);
54
+ },
55
+ afterNetwork(ctx, { resolve, value, marshalVariables }) {
56
+ if (value.source !== DataSource.Cache && enabled && value.data && !ctx.cacheParams?.disableWrite) {
57
+ localCache.write({
58
+ ...ctx.cacheParams,
59
+ layer: ctx.cacheParams?.layer?.id,
60
+ selection: ctx.artifact.selection,
61
+ data: value.data,
62
+ variables: marshalVariables(ctx)
63
+ });
64
+ }
65
+ resolve(ctx, value);
66
+ }
67
+ };
68
+ };
69
+ export {
70
+ cachePolicy
71
+ };
@@ -0,0 +1,37 @@
1
+ import type { RequestPayload } from '../../lib/types';
2
+ import type { ClientPlugin } from '../documentStore';
3
+ export declare const fetch: (target?: RequestHandler | string) => ClientPlugin;
4
+ export type FetchContext = {
5
+ fetch: typeof globalThis.fetch;
6
+ metadata?: App.Metadata | null;
7
+ session: App.Session | null;
8
+ };
9
+ /**
10
+ * ## Tip 👇
11
+ *
12
+ * To define types for your metadata, create a file `src/app.d.ts` containing the followingI:
13
+ *
14
+ * ```ts
15
+ * declare namespace App { *
16
+ * interface Metadata {}
17
+ * }
18
+ * ```
19
+ *
20
+ */
21
+ export type RequestHandlerArgs = FetchContext & FetchParams;
22
+ export type RequestHandler<_Data = any> = (args: RequestHandlerArgs) => Promise<RequestPayload<_Data>>;
23
+ export type FetchParams = {
24
+ text: string;
25
+ hash: string;
26
+ variables: {
27
+ [key: string]: any;
28
+ };
29
+ };
30
+ export declare function isExtractableFile(value: any): value is ExtractableFile;
31
+ type ExtractableFile = File | Blob;
32
+ /** @typedef {import("./isExtractableFile.mjs").default} isExtractableFile */
33
+ export declare function extractFiles(value: any): {
34
+ clone: any;
35
+ files: Map<any, any>;
36
+ };
37
+ export {};