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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/README.md +4 -1
  2. package/build/cmd-cjs/index.js +5366 -2772
  3. package/build/cmd-esm/index.js +5340 -2746
  4. package/build/codegen/generators/artifacts/index.d.ts +2 -2
  5. package/build/codegen/generators/artifacts/indexFile.d.ts +2 -2
  6. package/build/codegen/generators/artifacts/selection.d.ts +5 -5
  7. package/build/codegen/generators/artifacts/utils.d.ts +0 -1
  8. package/build/codegen/generators/indexFile/index.d.ts +2 -2
  9. package/build/codegen/generators/persistedQueries/index.d.ts +2 -2
  10. package/build/codegen/generators/runtime/graphqlFunction.d.ts +2 -2
  11. package/build/codegen/generators/runtime/index.d.ts +2 -2
  12. package/build/codegen/generators/runtime/runtimeConfig.d.ts +7 -0
  13. package/build/codegen/generators/typescript/documentTypes.d.ts +2 -0
  14. package/build/codegen/generators/typescript/imperativeTypeDef.d.ts +2 -0
  15. package/build/codegen/generators/typescript/index.d.ts +2 -2
  16. package/build/codegen/generators/typescript/typeReference.d.ts +4 -2
  17. package/build/codegen/generators/typescript/types.d.ts +0 -1
  18. package/build/codegen/index.d.ts +2 -2
  19. package/build/codegen/transforms/addID.d.ts +2 -2
  20. package/build/codegen/transforms/composeQueries.d.ts +4 -4
  21. package/build/codegen/transforms/fragmentVariables.d.ts +3 -2
  22. package/build/codegen/transforms/list.d.ts +2 -2
  23. package/build/codegen/transforms/paginate.d.ts +2 -2
  24. package/build/codegen/transforms/schema.d.ts +2 -2
  25. package/build/codegen/transforms/typename.d.ts +2 -2
  26. package/build/codegen/utils/flattenSelections.d.ts +1 -1
  27. package/build/codegen/validators/noIDAlias.d.ts +2 -2
  28. package/build/codegen/validators/plugins.d.ts +2 -2
  29. package/build/codegen/validators/typeCheck.d.ts +2 -2
  30. package/build/codegen/validators/uniqueNames.d.ts +2 -2
  31. package/build/codegen-cjs/index.js +4694 -2137
  32. package/build/codegen-esm/index.js +4682 -2125
  33. package/build/lib/config.d.ts +15 -96
  34. package/build/lib/deepMerge.d.ts +1 -0
  35. package/build/lib/graphql.d.ts +5 -2
  36. package/build/lib/index.d.ts +2 -0
  37. package/build/lib/path.d.ts +1 -1
  38. package/build/lib/pipeline.d.ts +1 -1
  39. package/build/lib/plugin.d.ts +2 -0
  40. package/build/lib/types.d.ts +257 -6
  41. package/build/lib/walk.d.ts +4 -1
  42. package/build/lib-cjs/index.js +4108 -928
  43. package/build/lib-esm/index.js +4078 -907
  44. package/build/runtime/cache/cache.d.ts +28 -11
  45. package/build/runtime/cache/lists.d.ts +1 -0
  46. package/build/runtime/cache/staleManager.d.ts +30 -0
  47. package/build/runtime/cache/storage.d.ts +23 -20
  48. package/build/runtime/cache/stuff.d.ts +0 -2
  49. package/build/runtime/cache/subscription.d.ts +2 -1
  50. package/build/runtime/client/documentStore.d.ts +20 -17
  51. package/build/runtime/client/index.d.ts +13 -11
  52. package/build/runtime/client/plugins/cache.d.ts +1 -1
  53. package/build/runtime/client/plugins/fetch.d.ts +1 -1
  54. package/build/runtime/client/plugins/fetchParams.d.ts +2 -2
  55. package/build/runtime/client/plugins/injectedPlugins.d.ts +2 -1
  56. package/build/runtime/client/plugins/mutation.d.ts +1 -1
  57. package/build/runtime/client/plugins/query.d.ts +1 -1
  58. package/build/runtime/client/plugins/subscription.d.ts +2 -3
  59. package/build/runtime/client/plugins/throwOnError.d.ts +1 -1
  60. package/build/runtime/client/utils/documentPlugins.d.ts +3 -3
  61. package/build/runtime/generated.d.ts +1 -0
  62. package/build/runtime/imports/pluginConfig.d.ts +3 -0
  63. package/build/runtime/index.d.ts +1 -1
  64. package/build/runtime/lib/config.d.ts +27 -24
  65. package/build/runtime/lib/flatten.d.ts +2 -0
  66. package/build/runtime/lib/index.d.ts +1 -0
  67. package/build/runtime/lib/key.d.ts +6 -0
  68. package/build/runtime/lib/scalars.d.ts +3 -3
  69. package/build/runtime/lib/types.d.ts +47 -47
  70. package/build/runtime/public/cache.d.ts +26 -6
  71. package/build/runtime/public/record.d.ts +26 -17
  72. package/build/runtime/public/tests/test.d.ts +52 -10
  73. package/build/runtime/public/types.d.ts +8 -0
  74. package/build/runtime-cjs/cache/cache.d.ts +28 -11
  75. package/build/runtime-cjs/cache/cache.js +97 -22
  76. package/build/runtime-cjs/cache/gc.js +9 -0
  77. package/build/runtime-cjs/cache/lists.d.ts +1 -0
  78. package/build/runtime-cjs/cache/lists.js +9 -6
  79. package/build/runtime-cjs/cache/staleManager.d.ts +30 -0
  80. package/build/runtime-cjs/cache/staleManager.js +95 -0
  81. package/build/runtime-cjs/cache/storage.d.ts +23 -20
  82. package/build/runtime-cjs/cache/storage.js +11 -13
  83. package/build/runtime-cjs/cache/stuff.d.ts +0 -2
  84. package/build/runtime-cjs/cache/stuff.js +2 -19
  85. package/build/runtime-cjs/cache/subscription.d.ts +2 -1
  86. package/build/runtime-cjs/cache/subscription.js +11 -7
  87. package/build/runtime-cjs/client/documentStore.d.ts +20 -17
  88. package/build/runtime-cjs/client/documentStore.js +13 -9
  89. package/build/runtime-cjs/client/index.d.ts +13 -11
  90. package/build/runtime-cjs/client/index.js +48 -19
  91. package/build/runtime-cjs/client/plugins/cache.d.ts +1 -1
  92. package/build/runtime-cjs/client/plugins/cache.js +12 -10
  93. package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -1
  94. package/build/runtime-cjs/client/plugins/fetch.js +10 -9
  95. package/build/runtime-cjs/client/plugins/fetchParams.d.ts +2 -2
  96. package/build/runtime-cjs/client/plugins/fetchParams.js +9 -4
  97. package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +2 -1
  98. package/build/runtime-cjs/client/plugins/mutation.d.ts +1 -1
  99. package/build/runtime-cjs/client/plugins/mutation.js +3 -3
  100. package/build/runtime-cjs/client/plugins/query.d.ts +1 -1
  101. package/build/runtime-cjs/client/plugins/query.js +5 -5
  102. package/build/runtime-cjs/client/plugins/subscription.d.ts +2 -3
  103. package/build/runtime-cjs/client/plugins/subscription.js +7 -5
  104. package/build/runtime-cjs/client/plugins/throwOnError.d.ts +1 -1
  105. package/build/runtime-cjs/client/plugins/throwOnError.js +3 -3
  106. package/build/runtime-cjs/client/utils/documentPlugins.d.ts +3 -3
  107. package/build/runtime-cjs/generated.d.ts +1 -0
  108. package/build/runtime-cjs/imports/pluginConfig.d.ts +3 -0
  109. package/build/runtime-cjs/imports/pluginConfig.js +27 -0
  110. package/build/runtime-cjs/index.d.ts +1 -1
  111. package/build/runtime-cjs/lib/config.d.ts +27 -24
  112. package/build/runtime-cjs/lib/config.js +11 -1
  113. package/build/runtime-cjs/lib/flatten.d.ts +2 -0
  114. package/build/runtime-cjs/lib/flatten.js +41 -0
  115. package/build/runtime-cjs/lib/index.d.ts +1 -0
  116. package/build/runtime-cjs/lib/index.js +1 -0
  117. package/build/runtime-cjs/lib/key.d.ts +6 -0
  118. package/build/runtime-cjs/lib/key.js +41 -0
  119. package/build/runtime-cjs/lib/scalars.d.ts +3 -3
  120. package/build/runtime-cjs/lib/scalars.js +13 -2
  121. package/build/runtime-cjs/lib/types.d.ts +47 -47
  122. package/build/runtime-cjs/lib/types.js +26 -30
  123. package/build/runtime-cjs/public/cache.d.ts +26 -6
  124. package/build/runtime-cjs/public/cache.js +32 -32
  125. package/build/runtime-cjs/public/list.js +6 -28
  126. package/build/runtime-cjs/public/record.d.ts +26 -17
  127. package/build/runtime-cjs/public/record.js +27 -187
  128. package/build/runtime-cjs/public/tests/test.d.ts +52 -10
  129. package/build/runtime-cjs/public/tests/test.js +27 -2
  130. package/build/runtime-cjs/public/types.d.ts +8 -0
  131. package/build/runtime-esm/cache/cache.d.ts +28 -11
  132. package/build/runtime-esm/cache/cache.js +99 -24
  133. package/build/runtime-esm/cache/gc.js +9 -0
  134. package/build/runtime-esm/cache/lists.d.ts +1 -0
  135. package/build/runtime-esm/cache/lists.js +9 -6
  136. package/build/runtime-esm/cache/staleManager.d.ts +30 -0
  137. package/build/runtime-esm/cache/staleManager.js +71 -0
  138. package/build/runtime-esm/cache/storage.d.ts +23 -20
  139. package/build/runtime-esm/cache/storage.js +11 -13
  140. package/build/runtime-esm/cache/stuff.d.ts +0 -2
  141. package/build/runtime-esm/cache/stuff.js +1 -17
  142. package/build/runtime-esm/cache/subscription.d.ts +2 -1
  143. package/build/runtime-esm/cache/subscription.js +12 -8
  144. package/build/runtime-esm/client/documentStore.d.ts +20 -17
  145. package/build/runtime-esm/client/documentStore.js +14 -10
  146. package/build/runtime-esm/client/index.d.ts +13 -11
  147. package/build/runtime-esm/client/index.js +49 -21
  148. package/build/runtime-esm/client/plugins/cache.d.ts +1 -1
  149. package/build/runtime-esm/client/plugins/cache.js +11 -9
  150. package/build/runtime-esm/client/plugins/fetch.d.ts +1 -1
  151. package/build/runtime-esm/client/plugins/fetch.js +9 -8
  152. package/build/runtime-esm/client/plugins/fetchParams.d.ts +2 -2
  153. package/build/runtime-esm/client/plugins/fetchParams.js +8 -3
  154. package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +2 -1
  155. package/build/runtime-esm/client/plugins/mutation.d.ts +1 -1
  156. package/build/runtime-esm/client/plugins/mutation.js +2 -2
  157. package/build/runtime-esm/client/plugins/query.d.ts +1 -1
  158. package/build/runtime-esm/client/plugins/query.js +4 -4
  159. package/build/runtime-esm/client/plugins/subscription.d.ts +2 -3
  160. package/build/runtime-esm/client/plugins/subscription.js +6 -4
  161. package/build/runtime-esm/client/plugins/throwOnError.d.ts +1 -1
  162. package/build/runtime-esm/client/plugins/throwOnError.js +2 -2
  163. package/build/runtime-esm/client/utils/documentPlugins.d.ts +3 -3
  164. package/build/runtime-esm/generated.d.ts +1 -0
  165. package/build/runtime-esm/imports/pluginConfig.d.ts +3 -0
  166. package/build/runtime-esm/imports/pluginConfig.js +5 -0
  167. package/build/runtime-esm/index.d.ts +1 -1
  168. package/build/runtime-esm/lib/config.d.ts +27 -24
  169. package/build/runtime-esm/lib/config.js +11 -1
  170. package/build/runtime-esm/lib/flatten.d.ts +2 -0
  171. package/build/runtime-esm/lib/flatten.js +17 -0
  172. package/build/runtime-esm/lib/index.d.ts +1 -0
  173. package/build/runtime-esm/lib/index.js +1 -0
  174. package/build/runtime-esm/lib/key.d.ts +6 -0
  175. package/build/runtime-esm/lib/key.js +17 -0
  176. package/build/runtime-esm/lib/scalars.d.ts +3 -3
  177. package/build/runtime-esm/lib/scalars.js +13 -2
  178. package/build/runtime-esm/lib/types.d.ts +47 -47
  179. package/build/runtime-esm/lib/types.js +26 -30
  180. package/build/runtime-esm/public/cache.d.ts +26 -6
  181. package/build/runtime-esm/public/cache.js +31 -30
  182. package/build/runtime-esm/public/list.js +6 -28
  183. package/build/runtime-esm/public/record.d.ts +26 -17
  184. package/build/runtime-esm/public/record.js +26 -183
  185. package/build/runtime-esm/public/tests/test.d.ts +52 -10
  186. package/build/runtime-esm/public/tests/test.js +26 -1
  187. package/build/runtime-esm/public/types.d.ts +8 -0
  188. package/build/test/index.d.ts +3 -3
  189. package/build/test-cjs/index.js +5007 -2465
  190. package/build/test-esm/index.js +4995 -2453
  191. package/build/vite/houdini.d.ts +2 -0
  192. package/build/vite-cjs/index.js +5344 -2744
  193. package/build/vite-esm/index.js +5319 -2719
  194. package/package.json +6 -5
  195. package/build/codegen/generators/typescript/imperativeCache.d.ts +0 -2
@@ -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
  });
@@ -19,10 +19,11 @@ export declare class InMemorySubscriptions {
19
19
  [key: string]: GraphQLValue;
20
20
  };
21
21
  }): void;
22
- addFieldSubscription({ id, key, selection, }: {
22
+ addFieldSubscription({ id, key, selection, type, }: {
23
23
  id: string;
24
24
  key: string;
25
25
  selection: FieldSelection;
26
+ type: string;
26
27
  }): void;
27
28
  registerList({ list, id, key, parentType, selection, filters, variables, }: {
28
29
  list: Required<Required<SubscriptionSelection>['fields'][string]>['list'];
@@ -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 {
@@ -51,7 +52,8 @@ class InMemorySubscriptions {
51
52
  this.addFieldSubscription({
52
53
  id: parent,
53
54
  key,
54
- selection: [spec, targetSelection2]
55
+ selection: [spec, targetSelection2],
56
+ type
55
57
  });
56
58
  if (list) {
57
59
  this.registerList({
@@ -69,7 +71,7 @@ class InMemorySubscriptions {
69
71
  parent,
70
72
  key
71
73
  );
72
- let children = !Array.isArray(linkedRecord) ? [linkedRecord] : (0, import_stuff.flattenList)(linkedRecord) || [];
74
+ let children = !Array.isArray(linkedRecord) ? [linkedRecord] : (0, import_flatten.flatten)(linkedRecord) || [];
73
75
  for (const child of children) {
74
76
  if (!child) {
75
77
  continue;
@@ -88,7 +90,8 @@ class InMemorySubscriptions {
88
90
  addFieldSubscription({
89
91
  id,
90
92
  key,
91
- selection
93
+ selection,
94
+ type
92
95
  }) {
93
96
  const spec = selection[0];
94
97
  if (!this.subscribers[id]) {
@@ -160,7 +163,8 @@ class InMemorySubscriptions {
160
163
  this.addFieldSubscription({
161
164
  id: parent,
162
165
  key,
163
- selection: [spec, fieldSelection]
166
+ selection: [spec, fieldSelection],
167
+ type: linkedType
164
168
  });
165
169
  if (list) {
166
170
  this.registerList({
@@ -176,7 +180,7 @@ class InMemorySubscriptions {
176
180
  const childSelection = selection.selection;
177
181
  if (childSelection) {
178
182
  const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
179
- const children = !Array.isArray(link) ? [link] : (0, import_stuff.flattenList)(link);
183
+ const children = !Array.isArray(link) ? [link] : (0, import_flatten.flatten)(link);
180
184
  for (const linkedRecord of children) {
181
185
  if (!linkedRecord) {
182
186
  continue;
@@ -212,7 +216,7 @@ class InMemorySubscriptions {
212
216
  continue;
213
217
  }
214
218
  const { value: previousValue } = this.cache._internal_unstable.storage.get(id, key);
215
- const links = !Array.isArray(previousValue) ? [previousValue] : (0, import_stuff.flattenList)(previousValue);
219
+ const links = !Array.isArray(previousValue) ? [previousValue] : (0, import_flatten.flatten)(previousValue);
216
220
  for (const link of links) {
217
221
  if (link !== null) {
218
222
  linkedIDs.push([link, fieldSelection.selection || {}]);
@@ -252,7 +256,7 @@ class InMemorySubscriptions {
252
256
  if (kind === "scalar") {
253
257
  continue;
254
258
  }
255
- const nextTargets = Array.isArray(value) ? (0, import_stuff.flattenList)(value) : [value];
259
+ const nextTargets = Array.isArray(value) ? (0, import_flatten.flatten)(value) : [value];
256
260
  for (const id2 of nextTargets) {
257
261
  if (visited.includes(id2)) {
258
262
  continue;
@@ -2,31 +2,23 @@ import type { HoudiniClient } from '.';
2
2
  import type { Layer } from '../cache/storage';
3
3
  import type { ConfigFile } from '../lib/config';
4
4
  import { Writable } from '../lib/store';
5
- import type { CachePolicy, DocumentArtifact, QueryResult, GraphQLObject, SubscriptionSpec } from '../lib/types';
5
+ import type { DocumentArtifact, QueryResult, GraphQLObject, SubscriptionSpec, CachePolicies } from '../lib/types';
6
6
  export declare class DocumentStore<_Data extends GraphQLObject, _Input extends Record<string, any>> extends Writable<QueryResult<_Data, _Input>> {
7
7
  #private;
8
8
  constructor({ artifact, plugins, pipeline, client, cache, initialValue, fetching, }: {
9
9
  artifact: DocumentArtifact;
10
- plugins?: ClientPlugin[];
11
- pipeline?: ClientPlugin[];
12
- client: HoudiniClient;
10
+ plugins?: ClientHooks[];
11
+ pipeline?: ClientHooks[];
12
+ client: HoudiniClient | null;
13
13
  cache?: boolean;
14
14
  initialValue?: _Data | null;
15
15
  fetching?: boolean;
16
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>>;
17
+ send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, silenceEcho, }?: SendParams): Promise<QueryResult<_Data, _Input>>;
27
18
  }
28
19
  declare function marshalVariables<_Data extends GraphQLObject, _Input extends {}>(ctx: ClientPluginContext): Record<string, any>;
29
- export type ClientPlugin = () => {
20
+ export type ClientPlugin = () => ClientHooks | null | (ClientHooks | ClientPlugin | null)[];
21
+ export type ClientHooks = {
30
22
  start?: ClientPluginEnterPhase;
31
23
  beforeNetwork?: ClientPluginEnterPhase;
32
24
  network?: ClientPluginEnterPhase;
@@ -41,7 +33,7 @@ export type ClientPluginContext = {
41
33
  text: string;
42
34
  hash: string;
43
35
  artifact: DocumentArtifact;
44
- policy?: CachePolicy;
36
+ policy?: CachePolicies;
45
37
  fetch?: Fetch;
46
38
  variables?: Record<string, any>;
47
39
  metadata?: App.Metadata | null;
@@ -53,7 +45,7 @@ export type ClientPluginContext = {
53
45
  forceNotify?: boolean;
54
46
  disableWrite?: boolean;
55
47
  disableRead?: boolean;
56
- applyUpdates?: boolean;
48
+ applyUpdates?: string[];
57
49
  };
58
50
  stuff: App.Stuff;
59
51
  };
@@ -84,4 +76,15 @@ export type ClientPluginExitHandlers = Omit<ClientPluginEnterHandlers, 'resolve'
84
76
  export type ClientPluginErrorHandlers = ClientPluginEnterHandlers & {
85
77
  error: unknown;
86
78
  };
79
+ export type SendParams = {
80
+ fetch?: Fetch;
81
+ variables?: Record<string, any> | null;
82
+ metadata?: App.Metadata | null;
83
+ session?: App.Session | null;
84
+ policy?: CachePolicies;
85
+ stuff?: Partial<App.Stuff>;
86
+ cacheParams?: ClientPluginContext['cacheParams'];
87
+ setup?: boolean;
88
+ silenceEcho?: boolean;
89
+ };
87
90
  export {};
@@ -47,16 +47,15 @@ class DocumentStore extends import_store.Writable {
47
47
  initialValue,
48
48
  fetching
49
49
  }) {
50
- if (fetching === void 0) {
51
- fetching = artifact.kind === import_types.ArtifactKind.Query;
52
- }
50
+ fetching ??= artifact.kind === import_types.ArtifactKind.Query;
53
51
  const initialState = {
54
52
  data: initialValue ?? null,
55
53
  errors: null,
56
54
  partial: false,
55
+ stale: false,
57
56
  source: null,
58
57
  fetching,
59
- variables: null
58
+ variables: {}
60
59
  };
61
60
  super(initialState, () => {
62
61
  return () => {
@@ -70,13 +69,13 @@ class DocumentStore extends import_store.Writable {
70
69
  this.#client = client;
71
70
  this.#lastVariables = null;
72
71
  this.#configFile = (0, import_config.getCurrentConfig)();
73
- this.#plugins = (pipeline ?? [
74
- (0, import_plugins.cachePolicyPlugin)({
72
+ this.#plugins = pipeline ?? [
73
+ (0, import_plugins.cachePolicy)({
75
74
  enabled: cache,
76
75
  setFetching: (fetching2) => this.update((state) => ({ ...state, fetching: fetching2 }))
77
- }),
76
+ })(),
78
77
  ...plugins ?? []
79
- ]).map((factory) => factory());
78
+ ];
80
79
  }
81
80
  async send({
82
81
  metadata,
@@ -86,7 +85,8 @@ class DocumentStore extends import_store.Writable {
86
85
  policy,
87
86
  stuff,
88
87
  cacheParams,
89
- setup = false
88
+ setup = false,
89
+ silenceEcho = false
90
90
  } = {}) {
91
91
  let context = new ClientPluginContextWrapper({
92
92
  config: this.#configFile,
@@ -117,6 +117,7 @@ class DocumentStore extends import_store.Writable {
117
117
  setup,
118
118
  currentStep: 0,
119
119
  index: 0,
120
+ silenceEcho,
120
121
  promise: {
121
122
  resolved: false,
122
123
  resolve,
@@ -254,6 +255,9 @@ class DocumentStore extends import_store.Writable {
254
255
  }
255
256
  this.#lastContext = ctx.context.draft();
256
257
  this.#lastVariables = this.#lastContext.stuff.inputs.marshaled;
258
+ if (ctx.silenceEcho && finalValue.data === this.state.data) {
259
+ return;
260
+ }
257
261
  this.set(finalValue);
258
262
  }
259
263
  }
@@ -1,25 +1,27 @@
1
1
  /// <reference path="../../../../../houdini.d.ts" />
2
- import type { DocumentArtifact, GraphQLObject } from '../lib/types';
3
- import type { ClientPlugin } from './documentStore';
2
+ import type { DocumentArtifact, GraphQLObject, NestedList } from '../lib/types';
3
+ import type { ClientPlugin, ClientHooks } from './documentStore';
4
4
  import { DocumentStore } from './documentStore';
5
5
  import { type FetchParamFn, type ThrowOnErrorParams } from './plugins';
6
6
  export { DocumentStore, type ClientPlugin } from './documentStore';
7
- export { fetchPlugin, mutationPlugin, queryPlugin, subscriptionPlugin } from './plugins';
7
+ export { fetch, mutation, query, subscription } from './plugins';
8
8
  type ConstructorArgs = {
9
9
  url: string;
10
10
  fetchParams?: FetchParamFn;
11
- plugins?: ClientPlugin[];
12
- pipeline?: ClientPlugin[];
11
+ plugins?: NestedList<ClientPlugin>;
12
+ pipeline?: NestedList<ClientPlugin>;
13
13
  throwOnError?: ThrowOnErrorParams;
14
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
+ };
15
21
  export declare class HoudiniClient {
16
22
  #private;
17
23
  url: string;
18
24
  constructor({ url, fetchParams, plugins, pipeline, throwOnError }: ConstructorArgs);
19
- observe<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, cache, initialValue, fetching, }: {
20
- artifact: DocumentArtifact;
21
- cache?: boolean;
22
- initialValue?: _Data | null;
23
- fetching?: boolean;
24
- }): DocumentStore<_Data, _Input>;
25
+ observe<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, cache, initialValue, fetching, }: ObserveParams<_Data>): DocumentStore<_Data, _Input>;
25
26
  }
27
+ export declare function createPluginHooks(plugins: ClientPlugin[]): ClientHooks[];
@@ -26,12 +26,14 @@ var client_exports = {};
26
26
  __export(client_exports, {
27
27
  DocumentStore: () => import_documentStore2.DocumentStore,
28
28
  HoudiniClient: () => HoudiniClient,
29
- fetchPlugin: () => import_plugins2.fetchPlugin,
30
- mutationPlugin: () => import_plugins2.mutationPlugin,
31
- queryPlugin: () => import_plugins2.queryPlugin,
32
- subscriptionPlugin: () => import_plugins2.subscriptionPlugin
29
+ createPluginHooks: () => createPluginHooks,
30
+ fetch: () => import_plugins2.fetch,
31
+ mutation: () => import_plugins2.mutation,
32
+ query: () => import_plugins2.query,
33
+ subscription: () => import_plugins2.subscription
33
34
  });
34
35
  module.exports = __toCommonJS(client_exports);
36
+ var import_flatten = require("../lib/flatten");
35
37
  var import_documentStore = require("./documentStore");
36
38
  var import_plugins = require("./plugins");
37
39
  var import_injectedPlugins = __toESM(require("./plugins/injectedPlugins"), 1);
@@ -46,16 +48,18 @@ class HoudiniClient {
46
48
  "A client cannot be given a pipeline and a list of plugins at the same time."
47
49
  );
48
50
  }
49
- this.#plugins = [].concat(
50
- throwOnError ? [(0, import_plugins.throwOnErrorPlugin)(throwOnError)] : [],
51
- (0, import_plugins.fetchParamsPlugin)(fetchParams),
52
- pipeline ?? [
53
- import_plugins.queryPlugin,
54
- import_plugins.mutationPlugin
55
- ].concat(
56
- plugins ?? [],
57
- import_injectedPlugins.default,
58
- (0, import_plugins.fetchPlugin)()
51
+ this.#plugins = (0, import_flatten.flatten)(
52
+ [].concat(
53
+ throwOnError ? [(0, import_plugins.throwOnError)(throwOnError)] : [],
54
+ (0, import_plugins.fetchParams)(fetchParams),
55
+ pipeline ?? [
56
+ import_plugins.query,
57
+ import_plugins.mutation
58
+ ].concat(
59
+ plugins ?? [],
60
+ import_injectedPlugins.default,
61
+ (0, import_plugins.fetch)()
62
+ )
59
63
  )
60
64
  );
61
65
  this.url = url;
@@ -69,19 +73,44 @@ class HoudiniClient {
69
73
  return new import_documentStore.DocumentStore({
70
74
  client: this,
71
75
  artifact,
72
- plugins: this.#plugins,
76
+ plugins: createPluginHooks(this.#plugins),
73
77
  cache,
74
78
  initialValue,
75
79
  fetching
76
80
  });
77
81
  }
78
82
  }
83
+ function createPluginHooks(plugins) {
84
+ return plugins.reduce((hooks, plugin) => {
85
+ if (typeof plugin !== "function") {
86
+ throw new Error("Encountered client plugin that's not a function");
87
+ }
88
+ const result = plugin();
89
+ if (!result) {
90
+ return hooks;
91
+ }
92
+ if (!Array.isArray(result)) {
93
+ return hooks.concat(result);
94
+ }
95
+ for (const value of result) {
96
+ if (!value) {
97
+ continue;
98
+ }
99
+ if (typeof value === "function") {
100
+ return hooks.concat(createPluginHooks([value]));
101
+ }
102
+ hooks.push(value);
103
+ }
104
+ return hooks;
105
+ }, []);
106
+ }
79
107
  // Annotate the CommonJS export names for ESM import in node:
80
108
  0 && (module.exports = {
81
109
  DocumentStore,
82
110
  HoudiniClient,
83
- fetchPlugin,
84
- mutationPlugin,
85
- queryPlugin,
86
- subscriptionPlugin
111
+ createPluginHooks,
112
+ fetch,
113
+ mutation,
114
+ query,
115
+ subscription
87
116
  });
@@ -1,7 +1,7 @@
1
1
  import cache from '../../cache';
2
2
  import type { Cache } from '../../cache/cache';
3
3
  import type { ClientPlugin } from '../documentStore';
4
- export declare const cachePolicyPlugin: ({ enabled, setFetching, cache: localCache, }: {
4
+ export declare const cachePolicy: ({ enabled, setFetching, cache: localCache, }: {
5
5
  enabled: boolean;
6
6
  setFetching: (val: boolean) => void;
7
7
  cache?: Cache | undefined;
@@ -24,18 +24,18 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
  var cache_exports = {};
26
26
  __export(cache_exports, {
27
- cachePolicyPlugin: () => cachePolicyPlugin
27
+ cachePolicy: () => cachePolicy
28
28
  });
29
29
  module.exports = __toCommonJS(cache_exports);
30
30
  var import_cache = __toESM(require("../../cache"), 1);
31
31
  var import_types = require("../../lib/types");
32
- const cachePolicyPlugin = ({
32
+ const cachePolicy = ({
33
33
  enabled,
34
34
  setFetching,
35
35
  cache: localCache = import_cache.default
36
36
  }) => () => {
37
37
  return {
38
- network(ctx, { next, resolve, marshalVariables }) {
38
+ network(ctx, { initialValue, next, resolve, marshalVariables }) {
39
39
  const { policy, artifact } = ctx;
40
40
  let useCache = false;
41
41
  if (enabled && artifact.kind === import_types.ArtifactKind.Query && !ctx.cacheParams?.disableRead) {
@@ -48,25 +48,27 @@ const cachePolicyPlugin = ({
48
48
  if (policy === import_types.CachePolicy.CacheOnly) {
49
49
  return resolve(ctx, {
50
50
  fetching: false,
51
- variables: ctx.variables ?? null,
52
- data: value.data,
51
+ variables: ctx.variables ?? {},
52
+ data: allowed ? value.data : initialValue.data,
53
53
  errors: null,
54
54
  source: import_types.DataSource.Cache,
55
- partial: value.partial
55
+ partial: allowed ? value.partial : false,
56
+ stale: value.stale
56
57
  });
57
58
  }
58
59
  useCache = !!(value.data !== null && allowed);
59
60
  if (useCache) {
60
61
  resolve(ctx, {
61
62
  fetching: false,
62
- variables: ctx.variables ?? null,
63
+ variables: ctx.variables ?? {},
63
64
  data: value.data,
64
65
  errors: null,
65
66
  source: import_types.DataSource.Cache,
66
- partial: value.partial
67
+ partial: value.partial,
68
+ stale: value.stale
67
69
  });
68
70
  }
69
- if (useCache && !value.partial) {
71
+ if (useCache && !value.partial && !value.stale) {
70
72
  return;
71
73
  }
72
74
  }
@@ -95,5 +97,5 @@ const cachePolicyPlugin = ({
95
97
  };
96
98
  // Annotate the CommonJS export names for ESM import in node:
97
99
  0 && (module.exports = {
98
- cachePolicyPlugin
100
+ cachePolicy
99
101
  });
@@ -1,6 +1,6 @@
1
1
  import type { RequestPayload } from '../../lib/types';
2
2
  import type { ClientPlugin } from '../documentStore';
3
- export declare const fetchPlugin: (target?: RequestHandler | string) => ClientPlugin;
3
+ export declare const fetch: (target?: RequestHandler | string) => ClientPlugin;
4
4
  export type FetchContext = {
5
5
  fetch: typeof globalThis.fetch;
6
6
  metadata?: App.Metadata | null;
@@ -19,16 +19,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var fetch_exports = {};
20
20
  __export(fetch_exports, {
21
21
  extractFiles: () => extractFiles,
22
- fetchPlugin: () => fetchPlugin,
22
+ fetch: () => fetch,
23
23
  isExtractableFile: () => isExtractableFile
24
24
  });
25
25
  module.exports = __toCommonJS(fetch_exports);
26
26
  var import_types = require("../../lib/types");
27
- const fetchPlugin = (target) => {
27
+ const fetch = (target) => {
28
28
  return () => {
29
29
  return {
30
30
  async network(ctx, { client, resolve, marshalVariables }) {
31
- const fetch = ctx.fetch ?? globalThis.fetch;
31
+ const fetch2 = ctx.fetch ?? globalThis.fetch;
32
32
  const fetchParams = {
33
33
  text: ctx.text,
34
34
  hash: ctx.hash,
@@ -45,7 +45,7 @@ const fetchPlugin = (target) => {
45
45
  const result = await fetchFn({
46
46
  fetch: (url, args) => {
47
47
  const newArgs = handleMultipart(fetchParams, args) ?? args;
48
- return fetch(url, newArgs);
48
+ return fetch2(url, newArgs);
49
49
  },
50
50
  metadata: ctx.metadata,
51
51
  session: ctx.session || {},
@@ -53,10 +53,11 @@ const fetchPlugin = (target) => {
53
53
  });
54
54
  resolve(ctx, {
55
55
  fetching: false,
56
- variables: ctx.variables ?? null,
56
+ variables: ctx.variables ?? {},
57
57
  data: result.data,
58
58
  errors: !result.errors || result.errors.length === 0 ? null : result.errors,
59
59
  partial: false,
60
+ stale: false,
60
61
  source: import_types.DataSource.Network
61
62
  });
62
63
  }
@@ -66,11 +67,11 @@ const fetchPlugin = (target) => {
66
67
  const defaultFetch = (url, params) => {
67
68
  if (!url) {
68
69
  throw new Error(
69
- "Could not find configured client url. Please specify one in your houdini.config.js file."
70
+ "Could not find configured client url. Please specify one in your HoudiniClient constructor."
70
71
  );
71
72
  }
72
- return async ({ fetch, text, variables }) => {
73
- const result = await fetch(url, {
73
+ return async ({ fetch: fetch2, text, variables }) => {
74
+ const result = await fetch2(url, {
74
75
  method: "POST",
75
76
  body: JSON.stringify({ query: text, variables }),
76
77
  ...params,
@@ -172,6 +173,6 @@ function isPlainObject(value) {
172
173
  // Annotate the CommonJS export names for ESM import in node:
173
174
  0 && (module.exports = {
174
175
  extractFiles,
175
- fetchPlugin,
176
+ fetch,
176
177
  isExtractableFile
177
178
  });
@@ -1,9 +1,9 @@
1
1
  import type { DocumentArtifact } from '../../lib/types';
2
2
  import type { ClientPlugin, ClientPluginContext } from '../documentStore';
3
3
  export type FetchParamFn = (ctx: FetchParamsInput) => Required<ClientPluginContext>['fetchParams'];
4
- export declare const fetchParamsPlugin: (fn?: FetchParamFn) => ClientPlugin;
4
+ export declare const fetchParams: (fn?: FetchParamFn) => ClientPlugin;
5
5
  export type FetchParamsInput = Pick<ClientPluginContext, 'config' | 'policy' | 'variables' | 'metadata' | 'session' | 'stuff'> & {
6
6
  text: string;
7
7
  hash: string;
8
- artifact: DocumentArtifact;
8
+ document: DocumentArtifact;
9
9
  };
@@ -18,15 +18,20 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var fetchParams_exports = {};
20
20
  __export(fetchParams_exports, {
21
- fetchParamsPlugin: () => fetchParamsPlugin
21
+ fetchParams: () => fetchParams
22
22
  });
23
23
  module.exports = __toCommonJS(fetchParams_exports);
24
- const fetchParamsPlugin = (fn = () => ({})) => () => ({
24
+ const fetchParams = (fn = () => ({})) => () => ({
25
25
  beforeNetwork(ctx, { next, marshalVariables }) {
26
26
  next({
27
27
  ...ctx,
28
28
  fetchParams: fn({
29
- ...ctx,
29
+ config: ctx.config,
30
+ policy: ctx.policy,
31
+ metadata: ctx.metadata,
32
+ session: ctx.session,
33
+ stuff: ctx.stuff,
34
+ document: ctx.artifact,
30
35
  variables: marshalVariables(ctx),
31
36
  text: ctx.artifact.raw,
32
37
  hash: ctx.artifact.hash
@@ -36,5 +41,5 @@ const fetchParamsPlugin = (fn = () => ({})) => () => ({
36
41
  });
37
42
  // Annotate the CommonJS export names for ESM import in node:
38
43
  0 && (module.exports = {
39
- fetchParamsPlugin
44
+ fetchParams
40
45
  });
@@ -1,3 +1,4 @@
1
+ import type { NestedList } from '../../lib/types';
1
2
  import type { ClientPlugin } from '../documentStore';
2
- declare const plugins: ClientPlugin[];
3
+ declare const plugins: NestedList<ClientPlugin>;
3
4
  export default plugins;
@@ -1 +1 @@
1
- export declare const mutationPlugin: import("..").ClientPlugin;
1
+ export declare const mutation: import("..").ClientPlugin;
@@ -24,14 +24,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
  var mutation_exports = {};
26
26
  __export(mutation_exports, {
27
- mutationPlugin: () => mutationPlugin
27
+ mutation: () => mutation
28
28
  });
29
29
  module.exports = __toCommonJS(mutation_exports);
30
30
  var import_cache = __toESM(require("../../cache"), 1);
31
31
  var import_scalars = require("../../lib/scalars");
32
32
  var import_types = require("../../lib/types");
33
33
  var import_utils = require("../utils");
34
- const mutationPlugin = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Mutation, () => {
34
+ const mutation = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Mutation, () => {
35
35
  return {
36
36
  async start(ctx, { next, marshalVariables }) {
37
37
  const layer = import_cache.default._internal_unstable.storage.createLayer(true);
@@ -82,5 +82,5 @@ const mutationPlugin = (0, import_utils.documentPlugin)(import_types.ArtifactKin
82
82
  });
83
83
  // Annotate the CommonJS export names for ESM import in node:
84
84
  0 && (module.exports = {
85
- mutationPlugin
85
+ mutation
86
86
  });
@@ -1,2 +1,2 @@
1
1
  import type { ClientPlugin } from '../documentStore';
2
- export declare const queryPlugin: ClientPlugin;
2
+ export declare const query: ClientPlugin;
@@ -24,13 +24,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
  var query_exports = {};
26
26
  __export(query_exports, {
27
- queryPlugin: () => queryPlugin
27
+ query: () => query
28
28
  });
29
29
  module.exports = __toCommonJS(query_exports);
30
30
  var import_cache = __toESM(require("../../cache"), 1);
31
31
  var import_types = require("../../lib/types");
32
32
  var import_utils = require("../utils");
33
- const queryPlugin = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Query, function() {
33
+ const query = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Query, function() {
34
34
  let subscriptionSpec = null;
35
35
  let lastVariables = null;
36
36
  let artifactName = "";
@@ -54,14 +54,14 @@ const queryPlugin = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Q
54
54
  selection: ctx.artifact.selection,
55
55
  variables: () => lastVariables,
56
56
  set: (newValue) => {
57
- console.log("setting from cache update");
58
57
  resolve(ctx, {
59
58
  data: newValue,
60
59
  errors: null,
61
60
  fetching: false,
62
61
  partial: false,
62
+ stale: false,
63
63
  source: import_types.DataSource.Cache,
64
- variables: ctx.variables ?? null
64
+ variables: ctx.variables ?? {}
65
65
  });
66
66
  }
67
67
  };
@@ -79,5 +79,5 @@ const queryPlugin = (0, import_utils.documentPlugin)(import_types.ArtifactKind.Q
79
79
  });
80
80
  // Annotate the CommonJS export names for ESM import in node:
81
81
  0 && (module.exports = {
82
- queryPlugin
82
+ query
83
83
  });