houdini 1.0.0-next.1 → 1.0.0-next.3

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 (224) hide show
  1. package/build/cmd/generate.d.ts +0 -1
  2. package/build/cmd-cjs/index.js +1400 -2836
  3. package/build/cmd-esm/index.js +1400 -2836
  4. package/build/codegen/generators/artifacts/fieldKey.d.ts +1 -1
  5. package/build/codegen/generators/artifacts/index.d.ts +1 -1
  6. package/build/codegen/generators/artifacts/indexFile.d.ts +1 -1
  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 +1 -1
  10. package/build/codegen/generators/artifacts/utils.d.ts +1 -1
  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 +1 -1
  14. package/build/codegen/generators/persistedQueries/index.d.ts +1 -1
  15. package/build/codegen/generators/runtime/graphqlFunction.d.ts +2 -0
  16. package/build/codegen/generators/runtime/index.d.ts +1 -1
  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/{imperativeCache.d.ts → imperativeTypeDef.d.ts} +1 -1
  22. package/build/codegen/generators/typescript/index.d.ts +1 -1
  23. package/build/codegen/generators/typescript/inlineType.d.ts +1 -1
  24. package/build/codegen/generators/typescript/typeReference.d.ts +1 -1
  25. package/build/codegen/generators/typescript/types.d.ts +1 -1
  26. package/build/codegen/index.d.ts +1 -1
  27. package/build/codegen/transforms/addID.d.ts +1 -1
  28. package/build/codegen/transforms/composeQueries.d.ts +2 -2
  29. package/build/codegen/transforms/fragmentVariables.d.ts +3 -2
  30. package/build/codegen/transforms/list.d.ts +1 -1
  31. package/build/codegen/transforms/paginate.d.ts +1 -1
  32. package/build/codegen/transforms/schema.d.ts +1 -1
  33. package/build/codegen/transforms/typename.d.ts +1 -1
  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 +1 -1
  39. package/build/codegen/validators/typeCheck.d.ts +1 -1
  40. package/build/codegen-cjs/index.js +1320 -2779
  41. package/build/codegen-esm/index.js +1320 -2779
  42. package/build/lib/config.d.ts +9 -4
  43. package/build/lib/fs.d.ts +1 -1
  44. package/build/lib/graphql.d.ts +1 -1
  45. package/build/lib/imports.d.ts +1 -1
  46. package/build/lib/types.d.ts +3 -3
  47. package/build/lib/walk.d.ts +8 -5
  48. package/build/lib-cjs/index.js +155 -1856
  49. package/build/lib-esm/index.js +155 -1856
  50. package/build/runtime/cache/cache.d.ts +10 -8
  51. package/build/runtime/cache/gc.d.ts +1 -1
  52. package/build/runtime/cache/lists.d.ts +3 -2
  53. package/build/runtime/cache/schema.d.ts +2 -2
  54. package/build/runtime/cache/stuff.d.ts +2 -2
  55. package/build/runtime/cache/subscription.d.ts +19 -11
  56. package/build/runtime/client/documentStore.d.ts +87 -0
  57. package/build/runtime/client/index.d.ts +25 -0
  58. package/build/runtime/client/plugins/cache.d.ts +8 -0
  59. package/build/runtime/client/plugins/fetch.d.ts +37 -0
  60. package/build/runtime/client/plugins/fetchParams.d.ts +9 -0
  61. package/build/runtime/client/plugins/index.d.ts +7 -0
  62. package/build/runtime/client/plugins/injectedPlugins.d.ts +3 -0
  63. package/build/runtime/client/plugins/mutation.d.ts +1 -0
  64. package/build/runtime/client/plugins/query.d.ts +2 -0
  65. package/build/runtime/client/plugins/subscription.d.ts +18 -0
  66. package/build/runtime/client/plugins/throwOnError.d.ts +7 -0
  67. package/build/runtime/client/utils/documentPlugins.d.ts +3 -0
  68. package/build/runtime/client/utils/index.d.ts +1 -0
  69. package/build/runtime/generated.d.ts +1 -0
  70. package/build/runtime/imports/config.d.ts +3 -0
  71. package/build/runtime/index.d.ts +3 -2
  72. package/build/runtime/lib/config.d.ts +26 -25
  73. package/build/runtime/lib/index.d.ts +1 -2
  74. package/build/runtime/lib/scalars.d.ts +6 -5
  75. package/build/runtime/lib/selection.d.ts +1 -1
  76. package/build/runtime/lib/store.d.ts +19 -0
  77. package/build/runtime/lib/types.d.ts +22 -9
  78. package/build/runtime/public/cache.d.ts +20 -7
  79. package/build/runtime/public/list.d.ts +2 -2
  80. package/build/runtime/public/record.d.ts +18 -18
  81. package/build/runtime/public/tests/test.d.ts +44 -1
  82. package/build/runtime/public/types.d.ts +8 -0
  83. package/build/runtime-cjs/cache/cache.d.ts +10 -8
  84. package/build/runtime-cjs/cache/cache.js +5 -11
  85. package/build/runtime-cjs/cache/gc.d.ts +1 -1
  86. package/build/runtime-cjs/cache/lists.d.ts +3 -2
  87. package/build/runtime-cjs/cache/lists.js +5 -2
  88. package/build/runtime-cjs/cache/schema.d.ts +2 -2
  89. package/build/runtime-cjs/cache/stuff.d.ts +2 -2
  90. package/build/runtime-cjs/cache/subscription.d.ts +19 -11
  91. package/build/runtime-cjs/cache/subscription.js +95 -56
  92. package/build/runtime-cjs/client/documentStore.d.ts +87 -0
  93. package/build/runtime-cjs/client/documentStore.js +360 -0
  94. package/build/runtime-cjs/client/index.d.ts +25 -0
  95. package/build/runtime-cjs/client/index.js +87 -0
  96. package/build/runtime-cjs/client/plugins/cache.d.ts +8 -0
  97. package/build/runtime-cjs/client/plugins/cache.js +99 -0
  98. package/build/runtime-cjs/client/plugins/fetch.d.ts +37 -0
  99. package/build/runtime-cjs/{lib/networkUtils.js → client/plugins/fetch.js} +95 -3
  100. package/build/runtime-cjs/client/plugins/fetchParams.d.ts +9 -0
  101. package/build/runtime-cjs/client/plugins/fetchParams.js +40 -0
  102. package/build/runtime-cjs/client/plugins/index.d.ts +7 -0
  103. package/build/runtime-cjs/client/plugins/index.js +24 -0
  104. package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +3 -0
  105. package/build/runtime-cjs/{lib/errors.js → client/plugins/injectedPlugins.js} +7 -15
  106. package/build/runtime-cjs/client/plugins/mutation.d.ts +1 -0
  107. package/build/runtime-cjs/client/plugins/mutation.js +86 -0
  108. package/build/runtime-cjs/client/plugins/query.d.ts +2 -0
  109. package/build/runtime-cjs/client/plugins/query.js +83 -0
  110. package/build/runtime-cjs/client/plugins/subscription.d.ts +18 -0
  111. package/build/runtime-cjs/client/plugins/subscription.js +98 -0
  112. package/build/runtime-cjs/client/plugins/throwOnError.d.ts +7 -0
  113. package/build/runtime-cjs/client/plugins/throwOnError.js +47 -0
  114. package/build/runtime-cjs/client/utils/documentPlugins.d.ts +3 -0
  115. package/build/runtime-cjs/client/utils/documentPlugins.js +56 -0
  116. package/build/runtime-cjs/client/utils/index.d.ts +1 -0
  117. package/build/runtime-cjs/client/utils/index.js +18 -0
  118. package/build/runtime-cjs/generated.d.ts +1 -0
  119. package/build/runtime-cjs/imports/config.d.ts +3 -0
  120. package/build/runtime-cjs/imports/config.js +26 -0
  121. package/build/runtime-cjs/index.d.ts +3 -2
  122. package/build/runtime-cjs/index.js +1 -0
  123. package/build/runtime-cjs/lib/config.d.ts +26 -25
  124. package/build/runtime-cjs/lib/config.js +5 -4
  125. package/build/runtime-cjs/lib/index.d.ts +1 -2
  126. package/build/runtime-cjs/lib/index.js +1 -2
  127. package/build/runtime-cjs/lib/scalars.d.ts +6 -5
  128. package/build/runtime-cjs/lib/scalars.js +20 -24
  129. package/build/runtime-cjs/lib/selection.d.ts +1 -1
  130. package/build/runtime-cjs/lib/store.d.ts +19 -0
  131. package/build/runtime-cjs/lib/store.js +81 -0
  132. package/build/runtime-cjs/lib/types.d.ts +22 -9
  133. package/build/runtime-cjs/public/cache.d.ts +20 -7
  134. package/build/runtime-cjs/public/cache.js +29 -32
  135. package/build/runtime-cjs/public/list.d.ts +2 -2
  136. package/build/runtime-cjs/public/list.js +6 -28
  137. package/build/runtime-cjs/public/record.d.ts +18 -18
  138. package/build/runtime-cjs/public/record.js +23 -189
  139. package/build/runtime-cjs/public/tests/test.d.ts +44 -1
  140. package/build/runtime-cjs/public/tests/test.js +27 -2
  141. package/build/runtime-cjs/public/types.d.ts +8 -0
  142. package/build/runtime-esm/cache/cache.d.ts +10 -8
  143. package/build/runtime-esm/cache/cache.js +5 -11
  144. package/build/runtime-esm/cache/gc.d.ts +1 -1
  145. package/build/runtime-esm/cache/lists.d.ts +3 -2
  146. package/build/runtime-esm/cache/lists.js +5 -2
  147. package/build/runtime-esm/cache/schema.d.ts +2 -2
  148. package/build/runtime-esm/cache/stuff.d.ts +2 -2
  149. package/build/runtime-esm/cache/subscription.d.ts +19 -11
  150. package/build/runtime-esm/cache/subscription.js +95 -56
  151. package/build/runtime-esm/client/documentStore.d.ts +87 -0
  152. package/build/runtime-esm/client/documentStore.js +336 -0
  153. package/build/runtime-esm/client/index.d.ts +25 -0
  154. package/build/runtime-esm/client/index.js +58 -0
  155. package/build/runtime-esm/client/plugins/cache.d.ts +8 -0
  156. package/build/runtime-esm/client/plugins/cache.js +69 -0
  157. package/build/runtime-esm/client/plugins/fetch.d.ts +37 -0
  158. package/build/runtime-esm/client/plugins/fetch.js +151 -0
  159. package/build/runtime-esm/client/plugins/fetchParams.d.ts +9 -0
  160. package/build/runtime-esm/client/plugins/fetchParams.js +16 -0
  161. package/build/runtime-esm/client/plugins/index.d.ts +7 -0
  162. package/build/runtime-esm/client/plugins/index.js +7 -0
  163. package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +3 -0
  164. package/build/runtime-esm/client/plugins/injectedPlugins.js +5 -0
  165. package/build/runtime-esm/client/plugins/mutation.d.ts +1 -0
  166. package/build/runtime-esm/client/plugins/mutation.js +56 -0
  167. package/build/runtime-esm/client/plugins/query.d.ts +2 -0
  168. package/build/runtime-esm/client/plugins/query.js +53 -0
  169. package/build/runtime-esm/client/plugins/subscription.d.ts +18 -0
  170. package/build/runtime-esm/client/plugins/subscription.js +74 -0
  171. package/build/runtime-esm/client/plugins/throwOnError.d.ts +7 -0
  172. package/build/runtime-esm/client/plugins/throwOnError.js +23 -0
  173. package/build/runtime-esm/client/utils/documentPlugins.d.ts +3 -0
  174. package/build/runtime-esm/client/utils/documentPlugins.js +32 -0
  175. package/build/runtime-esm/client/utils/index.d.ts +1 -0
  176. package/build/runtime-esm/client/utils/index.js +1 -0
  177. package/build/runtime-esm/generated.d.ts +1 -0
  178. package/build/runtime-esm/imports/config.d.ts +3 -0
  179. package/build/runtime-esm/imports/config.js +4 -0
  180. package/build/runtime-esm/index.d.ts +3 -2
  181. package/build/runtime-esm/index.js +1 -0
  182. package/build/runtime-esm/lib/config.d.ts +26 -25
  183. package/build/runtime-esm/lib/config.js +5 -4
  184. package/build/runtime-esm/lib/index.d.ts +1 -2
  185. package/build/runtime-esm/lib/index.js +1 -2
  186. package/build/runtime-esm/lib/scalars.d.ts +6 -5
  187. package/build/runtime-esm/lib/scalars.js +20 -24
  188. package/build/runtime-esm/lib/selection.d.ts +1 -1
  189. package/build/runtime-esm/lib/store.d.ts +19 -0
  190. package/build/runtime-esm/lib/store.js +57 -0
  191. package/build/runtime-esm/lib/types.d.ts +22 -9
  192. package/build/runtime-esm/public/cache.d.ts +20 -7
  193. package/build/runtime-esm/public/cache.js +28 -30
  194. package/build/runtime-esm/public/list.d.ts +2 -2
  195. package/build/runtime-esm/public/list.js +6 -28
  196. package/build/runtime-esm/public/record.d.ts +18 -18
  197. package/build/runtime-esm/public/record.js +22 -185
  198. package/build/runtime-esm/public/tests/test.d.ts +44 -1
  199. package/build/runtime-esm/public/tests/test.js +26 -1
  200. package/build/runtime-esm/public/types.d.ts +8 -0
  201. package/build/test/index.d.ts +4 -3
  202. package/build/test-cjs/index.js +1334 -2766
  203. package/build/test-esm/index.js +1334 -2766
  204. package/build/vite/ast.d.ts +1 -1
  205. package/build/vite/houdini.d.ts +1 -1
  206. package/build/vite/imports.d.ts +3 -3
  207. package/build/vite/index.d.ts +1 -1
  208. package/build/vite/schema.d.ts +1 -1
  209. package/build/vite-cjs/index.js +1395 -2821
  210. package/build/vite-esm/index.js +1395 -2821
  211. package/package.json +1 -1
  212. package/build/runtime/lib/errors.d.ts +0 -3
  213. package/build/runtime/lib/network.d.ts +0 -79
  214. package/build/runtime/lib/networkUtils.d.ts +0 -8
  215. package/build/runtime-cjs/lib/errors.d.ts +0 -3
  216. package/build/runtime-cjs/lib/network.d.ts +0 -79
  217. package/build/runtime-cjs/lib/network.js +0 -200
  218. package/build/runtime-cjs/lib/networkUtils.d.ts +0 -8
  219. package/build/runtime-esm/lib/errors.d.ts +0 -3
  220. package/build/runtime-esm/lib/errors.js +0 -11
  221. package/build/runtime-esm/lib/network.d.ts +0 -79
  222. package/build/runtime-esm/lib/network.js +0 -170
  223. package/build/runtime-esm/lib/networkUtils.d.ts +0 -8
  224. package/build/runtime-esm/lib/networkUtils.js +0 -60
@@ -16,12 +16,103 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var networkUtils_exports = {};
20
- __export(networkUtils_exports, {
19
+ var fetch_exports = {};
20
+ __export(fetch_exports, {
21
21
  extractFiles: () => extractFiles,
22
+ fetchPlugin: () => fetchPlugin,
22
23
  isExtractableFile: () => isExtractableFile
23
24
  });
24
- module.exports = __toCommonJS(networkUtils_exports);
25
+ module.exports = __toCommonJS(fetch_exports);
26
+ var import_types = require("../../lib/types");
27
+ const fetchPlugin = (target) => {
28
+ return () => {
29
+ return {
30
+ async network(ctx, { client, resolve, marshalVariables }) {
31
+ const fetch = ctx.fetch ?? globalThis.fetch;
32
+ const fetchParams = {
33
+ text: ctx.text,
34
+ hash: ctx.hash,
35
+ variables: marshalVariables(ctx)
36
+ };
37
+ let fetchFn = defaultFetch(client.url, ctx.fetchParams);
38
+ if (target) {
39
+ if (typeof target === "string") {
40
+ fetchFn = defaultFetch(target, ctx.fetchParams);
41
+ } else {
42
+ fetchFn = target;
43
+ }
44
+ }
45
+ const result = await fetchFn({
46
+ fetch: (url, args) => {
47
+ const newArgs = handleMultipart(fetchParams, args) ?? args;
48
+ return fetch(url, newArgs);
49
+ },
50
+ metadata: ctx.metadata,
51
+ session: ctx.session || {},
52
+ ...fetchParams
53
+ });
54
+ resolve(ctx, {
55
+ fetching: false,
56
+ variables: ctx.variables ?? null,
57
+ data: result.data,
58
+ errors: !result.errors || result.errors.length === 0 ? null : result.errors,
59
+ partial: false,
60
+ source: import_types.DataSource.Network
61
+ });
62
+ }
63
+ };
64
+ };
65
+ };
66
+ const defaultFetch = (url, params) => {
67
+ if (!url) {
68
+ throw new Error(
69
+ "Could not find configured client url. Please specify one in your houdini.config.js file."
70
+ );
71
+ }
72
+ return async ({ fetch, text, variables }) => {
73
+ const result = await fetch(url, {
74
+ method: "POST",
75
+ body: JSON.stringify({ query: text, variables }),
76
+ ...params,
77
+ headers: {
78
+ Accept: "application/graphql+json, application/json",
79
+ "Content-Type": "application/json",
80
+ ...params?.headers
81
+ }
82
+ });
83
+ return await result.json();
84
+ };
85
+ };
86
+ function handleMultipart(params, args) {
87
+ const { clone, files } = extractFiles({
88
+ query: params.text,
89
+ variables: params.variables
90
+ });
91
+ if (files.size) {
92
+ const req = args;
93
+ let headers = {};
94
+ if (req?.headers) {
95
+ const filtered = Object.entries(req?.headers).filter(([key, value]) => {
96
+ return !(key.toLowerCase() == "content-type" && value.toLowerCase() == "application/json");
97
+ });
98
+ headers = Object.fromEntries(filtered);
99
+ }
100
+ const form = new FormData();
101
+ const operationJSON = JSON.stringify(clone);
102
+ form.set("operations", operationJSON);
103
+ const map = {};
104
+ let i = 0;
105
+ files.forEach((paths) => {
106
+ map[++i] = paths;
107
+ });
108
+ form.set("map", JSON.stringify(map));
109
+ i = 0;
110
+ files.forEach((paths, file) => {
111
+ form.set(`${++i}`, file, file.name);
112
+ });
113
+ return { ...req, headers, body: form };
114
+ }
115
+ }
25
116
  function isExtractableFile(value) {
26
117
  return typeof File !== "undefined" && value instanceof File || typeof Blob !== "undefined" && value instanceof Blob;
27
118
  }
@@ -81,5 +172,6 @@ function isPlainObject(value) {
81
172
  // Annotate the CommonJS export names for ESM import in node:
82
173
  0 && (module.exports = {
83
174
  extractFiles,
175
+ fetchPlugin,
84
176
  isExtractableFile
85
177
  });
@@ -0,0 +1,9 @@
1
+ import type { DocumentArtifact } from '../../lib/types';
2
+ import type { ClientPlugin, ClientPluginContext } from '../documentStore';
3
+ export type FetchParamFn = (ctx: FetchParamsInput) => Required<ClientPluginContext>['fetchParams'];
4
+ export declare const fetchParamsPlugin: (fn?: FetchParamFn) => ClientPlugin;
5
+ export type FetchParamsInput = Pick<ClientPluginContext, 'config' | 'policy' | 'variables' | 'metadata' | 'session' | 'stuff'> & {
6
+ text: string;
7
+ hash: string;
8
+ artifact: DocumentArtifact;
9
+ };
@@ -0,0 +1,40 @@
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 fetchParams_exports = {};
20
+ __export(fetchParams_exports, {
21
+ fetchParamsPlugin: () => fetchParamsPlugin
22
+ });
23
+ module.exports = __toCommonJS(fetchParams_exports);
24
+ const fetchParamsPlugin = (fn = () => ({})) => () => ({
25
+ beforeNetwork(ctx, { next, marshalVariables }) {
26
+ next({
27
+ ...ctx,
28
+ fetchParams: fn({
29
+ ...ctx,
30
+ variables: marshalVariables(ctx),
31
+ text: ctx.artifact.raw,
32
+ hash: ctx.artifact.hash
33
+ })
34
+ });
35
+ }
36
+ });
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ fetchParamsPlugin
40
+ });
@@ -0,0 +1,7 @@
1
+ export * from './fetch';
2
+ export * from './cache';
3
+ export * from './query';
4
+ export * from './mutation';
5
+ export * from './subscription';
6
+ export * from './throwOnError';
7
+ export * from './fetchParams';
@@ -0,0 +1,24 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var plugins_exports = {};
17
+ module.exports = __toCommonJS(plugins_exports);
18
+ __reExport(plugins_exports, require("./fetch"), module.exports);
19
+ __reExport(plugins_exports, require("./cache"), module.exports);
20
+ __reExport(plugins_exports, require("./query"), module.exports);
21
+ __reExport(plugins_exports, require("./mutation"), module.exports);
22
+ __reExport(plugins_exports, require("./subscription"), module.exports);
23
+ __reExport(plugins_exports, require("./throwOnError"), module.exports);
24
+ __reExport(plugins_exports, require("./fetchParams"), module.exports);
@@ -0,0 +1,3 @@
1
+ import type { ClientPlugin } from '../documentStore';
2
+ declare const plugins: ClientPlugin[];
3
+ export default plugins;
@@ -16,20 +16,12 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var errors_exports = {};
20
- __export(errors_exports, {
21
- errorsToGraphQLLayout: () => errorsToGraphQLLayout
19
+ var injectedPlugins_exports = {};
20
+ __export(injectedPlugins_exports, {
21
+ default: () => injectedPlugins_default
22
22
  });
23
- module.exports = __toCommonJS(errors_exports);
24
- function errorsToGraphQLLayout(errors) {
25
- if (Array.isArray(errors)) {
26
- return errors.map((error) => {
27
- return { message: error };
28
- });
29
- }
30
- return [{ message: errors }];
31
- }
23
+ module.exports = __toCommonJS(injectedPlugins_exports);
24
+ const plugins = [];
25
+ var injectedPlugins_default = plugins;
32
26
  // Annotate the CommonJS export names for ESM import in node:
33
- 0 && (module.exports = {
34
- errorsToGraphQLLayout
35
- });
27
+ 0 && (module.exports = {});
@@ -0,0 +1 @@
1
+ export declare const mutationPlugin: import("..").ClientPlugin;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var mutation_exports = {};
26
+ __export(mutation_exports, {
27
+ mutationPlugin: () => mutationPlugin
28
+ });
29
+ module.exports = __toCommonJS(mutation_exports);
30
+ var import_cache = __toESM(require("../../cache"), 1);
31
+ var import_scalars = require("../../lib/scalars");
32
+ var import_types = require("../../lib/types");
33
+ var import_utils = require("../utils");
34
+ const mutationPlugin = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Mutation, () => {
35
+ return {
36
+ async start(ctx, { next, marshalVariables }) {
37
+ const layer = import_cache.default._internal_unstable.storage.createLayer(true);
38
+ const optimisticResponse = ctx.stuff.optimisticResponse;
39
+ let toNotify = [];
40
+ if (optimisticResponse) {
41
+ toNotify = import_cache.default.write({
42
+ selection: ctx.artifact.selection,
43
+ data: await (0, import_scalars.marshalSelection)({
44
+ selection: ctx.artifact.selection,
45
+ data: optimisticResponse
46
+ }),
47
+ variables: marshalVariables(ctx),
48
+ layer: layer.id
49
+ });
50
+ }
51
+ ctx.cacheParams = {
52
+ ...ctx.cacheParams,
53
+ layer,
54
+ notifySubscribers: toNotify,
55
+ forceNotify: true
56
+ };
57
+ next(ctx);
58
+ },
59
+ afterNetwork(ctx, { resolve }) {
60
+ ctx.cacheParams?.layer?.clear();
61
+ resolve(ctx);
62
+ },
63
+ end(ctx, { resolve, value }) {
64
+ const hasErrors = value.errors && value.errors.length > 0;
65
+ if (hasErrors) {
66
+ ctx.cacheParams?.layer?.clear();
67
+ }
68
+ if (ctx.cacheParams?.layer) {
69
+ import_cache.default._internal_unstable.storage.resolveLayer(ctx.cacheParams.layer.id);
70
+ }
71
+ resolve(ctx);
72
+ },
73
+ catch(ctx, { error }) {
74
+ if (ctx.cacheParams?.layer) {
75
+ const { layer } = ctx.cacheParams;
76
+ layer.clear();
77
+ import_cache.default._internal_unstable.storage.resolveLayer(layer.id);
78
+ }
79
+ throw error;
80
+ }
81
+ };
82
+ });
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {
85
+ mutationPlugin
86
+ });
@@ -0,0 +1,2 @@
1
+ import type { ClientPlugin } from '../documentStore';
2
+ export declare const queryPlugin: ClientPlugin;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var query_exports = {};
26
+ __export(query_exports, {
27
+ queryPlugin: () => queryPlugin
28
+ });
29
+ module.exports = __toCommonJS(query_exports);
30
+ var import_cache = __toESM(require("../../cache"), 1);
31
+ var import_types = require("../../lib/types");
32
+ var import_utils = require("../utils");
33
+ const queryPlugin = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Query, function() {
34
+ let subscriptionSpec = null;
35
+ let lastVariables = null;
36
+ let artifactName = "";
37
+ return {
38
+ start(ctx, { next }) {
39
+ ctx.variables = {
40
+ ...lastVariables,
41
+ ...ctx.variables
42
+ };
43
+ next(ctx);
44
+ },
45
+ end(ctx, { resolve, marshalVariables, variablesChanged }) {
46
+ if (variablesChanged(ctx)) {
47
+ artifactName = ctx.artifact.name;
48
+ if (subscriptionSpec) {
49
+ import_cache.default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() || {});
50
+ }
51
+ lastVariables = { ...marshalVariables(ctx) };
52
+ subscriptionSpec = {
53
+ rootType: ctx.artifact.rootType,
54
+ selection: ctx.artifact.selection,
55
+ variables: () => lastVariables,
56
+ set: (newValue) => {
57
+ console.log("setting from cache update");
58
+ resolve(ctx, {
59
+ data: newValue,
60
+ errors: null,
61
+ fetching: false,
62
+ partial: false,
63
+ source: import_types.DataSource.Cache,
64
+ variables: ctx.variables ?? null
65
+ });
66
+ }
67
+ };
68
+ import_cache.default.subscribe(subscriptionSpec, lastVariables ?? {});
69
+ }
70
+ resolve(ctx);
71
+ },
72
+ cleanup() {
73
+ if (subscriptionSpec) {
74
+ import_cache.default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() ?? {});
75
+ lastVariables = null;
76
+ }
77
+ }
78
+ };
79
+ });
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ queryPlugin
83
+ });
@@ -0,0 +1,18 @@
1
+ import type { GraphQLObject } from '../../lib/types';
2
+ import type { ClientPluginContext } from '../documentStore';
3
+ export declare function subscriptionPlugin(factory: SubscriptionHandler): import("../documentStore").ClientPlugin;
4
+ export type SubscriptionHandler = (ctx: ClientPluginContext) => {
5
+ subscribe: (payload: {
6
+ query: string;
7
+ variables?: {};
8
+ }, handlers: {
9
+ next: (payload: {
10
+ data?: GraphQLObject;
11
+ errors?: readonly {
12
+ message: string;
13
+ }[];
14
+ }) => void;
15
+ error: (data: {}) => void;
16
+ complete: () => void;
17
+ }) => () => void;
18
+ };
@@ -0,0 +1,98 @@
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 subscription_exports = {};
20
+ __export(subscription_exports, {
21
+ subscriptionPlugin: () => subscriptionPlugin
22
+ });
23
+ module.exports = __toCommonJS(subscription_exports);
24
+ var import_deepEquals = require("../../lib/deepEquals");
25
+ var import_types = require("../../lib/types");
26
+ var import_utils = require("../utils");
27
+ function subscriptionPlugin(factory) {
28
+ return (0, import_utils.documentPlugin)(import_types.ArtifactKind.Subscription, () => {
29
+ let clearSubscription = null;
30
+ let socketClient = null;
31
+ let check = null;
32
+ return {
33
+ start(ctx, { resolve, next, initialValue }) {
34
+ if (typeof globalThis.window === "undefined") {
35
+ resolve(ctx, initialValue);
36
+ return;
37
+ }
38
+ next(ctx);
39
+ },
40
+ network(ctx, { resolve, initialValue, variablesChanged, marshalVariables }) {
41
+ const checkValue = {
42
+ fetchParams: ctx.fetchParams ?? {},
43
+ session: ctx.session ?? {},
44
+ metadata: ctx.metadata ?? {}
45
+ };
46
+ const changed = variablesChanged(ctx);
47
+ const sessionChange = !(0, import_deepEquals.deepEquals)(check, checkValue);
48
+ if (!changed && !sessionChange) {
49
+ resolve(ctx, initialValue);
50
+ return;
51
+ }
52
+ check = checkValue;
53
+ clearSubscription?.();
54
+ if (!socketClient || sessionChange) {
55
+ socketClient = factory(ctx);
56
+ }
57
+ clearSubscription = socketClient.subscribe(
58
+ {
59
+ query: ctx.artifact.raw,
60
+ variables: marshalVariables(ctx)
61
+ },
62
+ {
63
+ next: ({ data, errors }) => {
64
+ resolve(ctx, {
65
+ data: data ?? null,
66
+ errors: [...errors ?? []],
67
+ fetching: false,
68
+ partial: true,
69
+ source: import_types.DataSource.Network,
70
+ variables: ctx.variables ?? null
71
+ });
72
+ },
73
+ error(data) {
74
+ clearSubscription?.();
75
+ resolve(ctx, {
76
+ partial: true,
77
+ source: import_types.DataSource.Network,
78
+ data: null,
79
+ errors: [data],
80
+ fetching: false,
81
+ variables: ctx.variables ?? null
82
+ });
83
+ },
84
+ complete() {
85
+ }
86
+ }
87
+ );
88
+ },
89
+ cleanup() {
90
+ clearSubscription?.();
91
+ }
92
+ };
93
+ });
94
+ }
95
+ // Annotate the CommonJS export names for ESM import in node:
96
+ 0 && (module.exports = {
97
+ subscriptionPlugin
98
+ });
@@ -0,0 +1,7 @@
1
+ import type { QueryResult } from '../../lib';
2
+ import type { ClientPlugin } from '../documentStore';
3
+ export type ThrowOnErrorParams = {
4
+ operations: ('all' | 'query' | 'mutation' | 'subscription')[];
5
+ error?: (errors: NonNullable<QueryResult<any, any>['errors']>) => unknown;
6
+ };
7
+ export declare const throwOnErrorPlugin: ({ operations, error }: ThrowOnErrorParams) => ClientPlugin;
@@ -0,0 +1,47 @@
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 throwOnError_exports = {};
20
+ __export(throwOnError_exports, {
21
+ throwOnErrorPlugin: () => throwOnErrorPlugin
22
+ });
23
+ module.exports = __toCommonJS(throwOnError_exports);
24
+ var import_lib = require("../../lib");
25
+ const throwOnErrorPlugin = ({ operations, error }) => () => {
26
+ const all = operations.includes("all");
27
+ const throwOnKind = (kind) => all || {
28
+ [import_lib.ArtifactKind.Query]: operations.includes("query"),
29
+ [import_lib.ArtifactKind.Mutation]: operations.includes("mutation"),
30
+ [import_lib.ArtifactKind.Fragment]: false,
31
+ [import_lib.ArtifactKind.Subscription]: operations.includes("subscription")
32
+ }[kind];
33
+ return {
34
+ async end(ctx, { value, resolve }) {
35
+ if (value.errors && value.errors.length > 0 && throwOnKind(ctx.artifact.kind)) {
36
+ const result = await (error ?? defaultErrorFn)(value.errors);
37
+ throw result;
38
+ }
39
+ resolve(ctx);
40
+ }
41
+ };
42
+ };
43
+ const defaultErrorFn = async (errors) => new Error(errors.map((error) => error.message).join(". ") + ".");
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ throwOnErrorPlugin
47
+ });
@@ -0,0 +1,3 @@
1
+ import type { ArtifactKind } from '../../lib/types';
2
+ import type { ClientPlugin } from '../documentStore';
3
+ export declare const documentPlugin: (kind: ArtifactKind, source: ClientPlugin) => ClientPlugin;
@@ -0,0 +1,56 @@
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 documentPlugins_exports = {};
20
+ __export(documentPlugins_exports, {
21
+ documentPlugin: () => documentPlugin
22
+ });
23
+ module.exports = __toCommonJS(documentPlugins_exports);
24
+ const documentPlugin = (kind, source) => {
25
+ return () => {
26
+ const sourceHandlers = source();
27
+ const enterWrapper = (handler) => {
28
+ return !handler ? void 0 : (ctx, handlers) => {
29
+ if (ctx.artifact.kind !== kind) {
30
+ return handlers.next(ctx);
31
+ }
32
+ return handler(ctx, handlers);
33
+ };
34
+ };
35
+ const exitWrapper = (handler) => {
36
+ return !handler ? void 0 : (ctx, handlers) => {
37
+ if (ctx.artifact.kind !== kind) {
38
+ return handlers.resolve(ctx);
39
+ }
40
+ return handler(ctx, handlers);
41
+ };
42
+ };
43
+ return {
44
+ start: enterWrapper(sourceHandlers.start),
45
+ network: enterWrapper(sourceHandlers.network),
46
+ afterNetwork: exitWrapper(sourceHandlers.afterNetwork),
47
+ end: exitWrapper(sourceHandlers.end),
48
+ catch: sourceHandlers.catch ? (ctx, handlers) => sourceHandlers.catch(ctx, handlers) : void 0,
49
+ cleanup: (...args) => sourceHandlers.cleanup?.(...args)
50
+ };
51
+ };
52
+ };
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ documentPlugin
56
+ });
@@ -0,0 +1 @@
1
+ export * from './documentPlugins';
@@ -0,0 +1,18 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var utils_exports = {};
17
+ module.exports = __toCommonJS(utils_exports);
18
+ __reExport(utils_exports, require("./documentPlugins"), module.exports);
@@ -1,4 +1,5 @@
1
1
  export type CacheTypeDef = {
2
2
  types: {};
3
3
  lists: {};
4
+ queries: [];
4
5
  };