houdini 1.0.0-next.7 → 1.0.0-next.9

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 (100) hide show
  1. package/build/cmd-cjs/index.js +93 -66
  2. package/build/cmd-esm/index.js +66 -39
  3. package/build/codegen/generators/typescript/typeReference.d.ts +4 -2
  4. package/build/codegen/generators/typescript/types.d.ts +0 -1
  5. package/build/codegen-cjs/index.js +67 -39
  6. package/build/codegen-esm/index.js +54 -26
  7. package/build/lib/config.d.ts +2 -1
  8. package/build/lib/path.d.ts +1 -1
  9. package/build/lib-cjs/index.js +40 -37
  10. package/build/lib-esm/index.js +14 -11
  11. package/build/runtime/cache/cache.d.ts +6 -6
  12. package/build/runtime/cache/storage.d.ts +5 -5
  13. package/build/runtime/cache/stuff.d.ts +0 -2
  14. package/build/runtime/client/documentStore.d.ts +4 -3
  15. package/build/runtime/client/index.d.ts +6 -5
  16. package/build/runtime/client/plugins/cache.d.ts +1 -1
  17. package/build/runtime/client/plugins/fetch.d.ts +1 -1
  18. package/build/runtime/client/plugins/fetchParams.d.ts +1 -1
  19. package/build/runtime/client/plugins/injectedPlugins.d.ts +2 -1
  20. package/build/runtime/client/plugins/mutation.d.ts +1 -1
  21. package/build/runtime/client/plugins/query.d.ts +1 -1
  22. package/build/runtime/client/plugins/subscription.d.ts +1 -1
  23. package/build/runtime/client/plugins/throwOnError.d.ts +1 -1
  24. package/build/runtime/client/utils/documentPlugins.d.ts +2 -2
  25. package/build/runtime/lib/flatten.d.ts +2 -0
  26. package/build/runtime/lib/types.d.ts +2 -0
  27. package/build/runtime/public/record.d.ts +1 -2
  28. package/build/runtime-cjs/cache/cache.d.ts +6 -6
  29. package/build/runtime-cjs/cache/cache.js +6 -5
  30. package/build/runtime-cjs/cache/lists.js +3 -3
  31. package/build/runtime-cjs/cache/storage.d.ts +5 -5
  32. package/build/runtime-cjs/cache/storage.js +2 -2
  33. package/build/runtime-cjs/cache/stuff.d.ts +0 -2
  34. package/build/runtime-cjs/cache/stuff.js +2 -19
  35. package/build/runtime-cjs/cache/subscription.js +5 -4
  36. package/build/runtime-cjs/client/documentStore.d.ts +4 -3
  37. package/build/runtime-cjs/client/documentStore.js +4 -4
  38. package/build/runtime-cjs/client/index.d.ts +6 -5
  39. package/build/runtime-cjs/client/index.js +45 -19
  40. package/build/runtime-cjs/client/plugins/cache.d.ts +1 -1
  41. package/build/runtime-cjs/client/plugins/cache.js +3 -3
  42. package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -1
  43. package/build/runtime-cjs/client/plugins/fetch.js +7 -7
  44. package/build/runtime-cjs/client/plugins/fetchParams.d.ts +1 -1
  45. package/build/runtime-cjs/client/plugins/fetchParams.js +3 -3
  46. package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +2 -1
  47. package/build/runtime-cjs/client/plugins/mutation.d.ts +1 -1
  48. package/build/runtime-cjs/client/plugins/mutation.js +3 -3
  49. package/build/runtime-cjs/client/plugins/query.d.ts +1 -1
  50. package/build/runtime-cjs/client/plugins/query.js +3 -3
  51. package/build/runtime-cjs/client/plugins/subscription.d.ts +1 -1
  52. package/build/runtime-cjs/client/plugins/subscription.js +3 -3
  53. package/build/runtime-cjs/client/plugins/throwOnError.d.ts +1 -1
  54. package/build/runtime-cjs/client/plugins/throwOnError.js +3 -3
  55. package/build/runtime-cjs/client/utils/documentPlugins.d.ts +2 -2
  56. package/build/runtime-cjs/lib/flatten.d.ts +2 -0
  57. package/build/runtime-cjs/lib/flatten.js +41 -0
  58. package/build/runtime-cjs/lib/types.d.ts +2 -0
  59. package/build/runtime-cjs/public/cache.js +2 -2
  60. package/build/runtime-cjs/public/record.d.ts +1 -2
  61. package/build/runtime-cjs/public/record.js +1 -2
  62. package/build/runtime-esm/cache/cache.d.ts +6 -6
  63. package/build/runtime-esm/cache/cache.js +7 -6
  64. package/build/runtime-esm/cache/lists.js +3 -3
  65. package/build/runtime-esm/cache/storage.d.ts +5 -5
  66. package/build/runtime-esm/cache/storage.js +2 -2
  67. package/build/runtime-esm/cache/stuff.d.ts +0 -2
  68. package/build/runtime-esm/cache/stuff.js +1 -17
  69. package/build/runtime-esm/cache/subscription.js +6 -5
  70. package/build/runtime-esm/client/documentStore.d.ts +4 -3
  71. package/build/runtime-esm/client/documentStore.js +5 -5
  72. package/build/runtime-esm/client/index.d.ts +6 -5
  73. package/build/runtime-esm/client/index.js +46 -21
  74. package/build/runtime-esm/client/plugins/cache.d.ts +1 -1
  75. package/build/runtime-esm/client/plugins/cache.js +2 -2
  76. package/build/runtime-esm/client/plugins/fetch.d.ts +1 -1
  77. package/build/runtime-esm/client/plugins/fetch.js +6 -6
  78. package/build/runtime-esm/client/plugins/fetchParams.d.ts +1 -1
  79. package/build/runtime-esm/client/plugins/fetchParams.js +2 -2
  80. package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +2 -1
  81. package/build/runtime-esm/client/plugins/mutation.d.ts +1 -1
  82. package/build/runtime-esm/client/plugins/mutation.js +2 -2
  83. package/build/runtime-esm/client/plugins/query.d.ts +1 -1
  84. package/build/runtime-esm/client/plugins/query.js +2 -2
  85. package/build/runtime-esm/client/plugins/subscription.d.ts +1 -1
  86. package/build/runtime-esm/client/plugins/subscription.js +2 -2
  87. package/build/runtime-esm/client/plugins/throwOnError.d.ts +1 -1
  88. package/build/runtime-esm/client/plugins/throwOnError.js +2 -2
  89. package/build/runtime-esm/client/utils/documentPlugins.d.ts +2 -2
  90. package/build/runtime-esm/lib/flatten.d.ts +2 -0
  91. package/build/runtime-esm/lib/flatten.js +17 -0
  92. package/build/runtime-esm/lib/types.d.ts +2 -0
  93. package/build/runtime-esm/public/cache.js +2 -2
  94. package/build/runtime-esm/public/record.d.ts +1 -2
  95. package/build/runtime-esm/public/record.js +1 -2
  96. package/build/test-cjs/index.js +67 -39
  97. package/build/test-esm/index.js +54 -26
  98. package/build/vite-cjs/index.js +90 -58
  99. package/build/vite-esm/index.js +64 -32
  100. package/package.json +4 -4
@@ -7,8 +7,8 @@ export declare class DocumentStore<_Data extends GraphQLObject, _Input extends R
7
7
  #private;
8
8
  constructor({ artifact, plugins, pipeline, client, cache, initialValue, fetching, }: {
9
9
  artifact: DocumentArtifact;
10
- plugins?: ClientPlugin[];
11
- pipeline?: ClientPlugin[];
10
+ plugins?: ClientHooks[];
11
+ pipeline?: ClientHooks[];
12
12
  client: HoudiniClient | null;
13
13
  cache?: boolean;
14
14
  initialValue?: _Data | null;
@@ -26,7 +26,8 @@ export declare class DocumentStore<_Data extends GraphQLObject, _Input extends R
26
26
  }): Promise<QueryResult<_Data, _Input>>;
27
27
  }
28
28
  declare function marshalVariables<_Data extends GraphQLObject, _Input extends {}>(ctx: ClientPluginContext): Record<string, any>;
29
- export type ClientPlugin = () => {
29
+ export type ClientPlugin = () => ClientHooks | null | (ClientHooks | ClientPlugin | null)[];
30
+ export type ClientHooks = {
30
31
  start?: ClientPluginEnterPhase;
31
32
  beforeNetwork?: ClientPluginEnterPhase;
32
33
  network?: ClientPluginEnterPhase;
@@ -1,15 +1,15 @@
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
15
  export type ObserveParams<_Data extends GraphQLObject, _Artifact extends DocumentArtifact = DocumentArtifact> = {
@@ -24,3 +24,4 @@ export declare class HoudiniClient {
24
24
  constructor({ url, fetchParams, plugins, pipeline, throwOnError }: ConstructorArgs);
25
25
  observe<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, cache, initialValue, fetching, }: ObserveParams<_Data>): DocumentStore<_Data, _Input>;
26
26
  }
27
+ export declare function createPluginHooks(plugins: ClientPlugin[]): ClientHooks[];
@@ -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;
@@ -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;
@@ -1,7 +1,7 @@
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;
@@ -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;
@@ -1,2 +1,2 @@
1
1
  import type { ClientPlugin } from '../documentStore';
2
- export declare const queryPlugin: ClientPlugin;
2
+ export declare const query: ClientPlugin;
@@ -1,5 +1,5 @@
1
1
  import type { ClientPluginContext } from '../documentStore';
2
- export declare function subscriptionPlugin(factory: SubscriptionHandler): import("../documentStore").ClientPlugin;
2
+ export declare function subscription(factory: SubscriptionHandler): import("../documentStore").ClientPlugin;
3
3
  export type SubscriptionHandler = (ctx: ClientPluginContext) => {
4
4
  subscribe: (payload: {
5
5
  query: string;
@@ -4,4 +4,4 @@ export type ThrowOnErrorParams = {
4
4
  operations: ('all' | 'query' | 'mutation' | 'subscription')[];
5
5
  error?: (errors: NonNullable<QueryResult<any, any>['errors']>) => unknown;
6
6
  };
7
- export declare const throwOnErrorPlugin: ({ operations, error }: ThrowOnErrorParams) => ClientPlugin;
7
+ export declare const throwOnError: ({ operations, error }: ThrowOnErrorParams) => ClientPlugin;
@@ -1,3 +1,3 @@
1
1
  import type { ArtifactKind } from '../../lib/types';
2
- import type { ClientPlugin } from '../documentStore';
3
- export declare const documentPlugin: (kind: ArtifactKind, source: ClientPlugin) => ClientPlugin;
2
+ import type { ClientPlugin, ClientHooks } from '../documentStore';
3
+ export declare const documentPlugin: (kind: ArtifactKind, source: () => ClientHooks) => ClientPlugin;
@@ -0,0 +1,2 @@
1
+ import type { NestedList } from './types';
2
+ export declare function flatten<T>(source?: NestedList<T>): T[];
@@ -182,4 +182,6 @@ export type RequestPayload<GraphQLObject = any> = {
182
182
  message: string;
183
183
  }[] | null;
184
184
  };
185
+ export type NestedList<_Result = string> = (_Result | null | NestedList<_Result>)[];
186
+ export type ValueOf<Parent> = Parent[keyof Parent];
185
187
  export {};
@@ -34,8 +34,7 @@ export declare class Record<Def extends CacheTypeDef, Type extends ValidTypes<De
34
34
  * @param field
35
35
  * @param when
36
36
  */
37
- markStale<Field extends TypeFieldNames<Def, Type>>({ field, when, }?: {
38
- field?: Field;
37
+ markStale<Field extends TypeFieldNames<Def, Type>>(field?: Field, { when, }?: {
39
38
  when?: ArgType<Def, Type, Field>;
40
39
  }): void;
41
40
  }
@@ -1,5 +1,5 @@
1
1
  import type { ConfigFile } from '../lib/config';
2
- import type { GraphQLObject, GraphQLValue, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
2
+ import type { GraphQLObject, GraphQLValue, NestedList, SubscriptionSelection, SubscriptionSpec } from '../lib/types';
3
3
  import { GarbageCollector } from './gc';
4
4
  import type { ListCollection } from './lists';
5
5
  import { ListManager } from './lists';
@@ -34,7 +34,8 @@ export declare class Cache {
34
34
  list(name: string, parentID?: string, allLists?: boolean): ListCollection;
35
35
  delete(id: string): void;
36
36
  setConfig(config: ConfigFile): void;
37
- markTypeStale(type?: string, options?: {
37
+ markTypeStale(options?: {
38
+ type: string;
38
39
  field?: string;
39
40
  when?: {};
40
41
  }): void;
@@ -98,10 +99,10 @@ declare class CacheInternal {
98
99
  hydrateNestedList({ fields, variables, linkedList, stepsFromConnection, }: {
99
100
  fields: SubscriptionSelection;
100
101
  variables?: {};
101
- linkedList: LinkedList;
102
+ linkedList: NestedList;
102
103
  stepsFromConnection: number | null;
103
104
  }): {
104
- data: LinkedList<GraphQLValue>;
105
+ data: NestedList<GraphQLValue>;
105
106
  partial: boolean;
106
107
  stale: boolean;
107
108
  hasData: boolean;
@@ -119,11 +120,10 @@ declare class CacheInternal {
119
120
  layer: Layer;
120
121
  forceNotify?: boolean;
121
122
  }): {
122
- nestedIDs: LinkedList;
123
+ nestedIDs: NestedList;
123
124
  newIDs: (string | null)[];
124
125
  };
125
126
  collectGarbage(): void;
126
127
  }
127
128
  export declare const rootID = "_ROOT_";
128
- export type LinkedList<_Result = string> = (_Result | null | LinkedList<_Result>)[];
129
129
  export {};
@@ -25,6 +25,7 @@ module.exports = __toCommonJS(cache_exports);
25
25
  var import_lib = require("../lib");
26
26
  var import_config = require("../lib/config");
27
27
  var import_deepEquals = require("../lib/deepEquals");
28
+ var import_flatten = require("../lib/flatten");
28
29
  var import_selection = require("../lib/selection");
29
30
  var import_gc = require("./gc");
30
31
  var import_lists = require("./lists");
@@ -115,14 +116,14 @@ class Cache {
115
116
  setConfig(config) {
116
117
  this._internal_unstable.setConfig(config);
117
118
  }
118
- markTypeStale(type, options = {}) {
119
- if (!type) {
119
+ markTypeStale(options) {
120
+ if (!options) {
120
121
  this._internal_unstable.staleManager.markAllStale();
121
122
  } else if (!options.field) {
122
- this._internal_unstable.staleManager.markTypeStale(type);
123
+ this._internal_unstable.staleManager.markTypeStale(options.type);
123
124
  } else {
124
125
  this._internal_unstable.staleManager.markTypeFieldStale(
125
- type,
126
+ options.type,
126
127
  options.field,
127
128
  options.when
128
129
  );
@@ -261,7 +262,7 @@ class CacheInternal {
261
262
  if (previousValue === null) {
262
263
  continue;
263
264
  }
264
- const previousLinks = (0, import_stuff.flattenList)([previousValue]);
265
+ const previousLinks = (0, import_flatten.flatten)([previousValue]);
265
266
  for (const link of previousLinks) {
266
267
  this.subscriptions.remove(link, fieldSelection, specs, variables);
267
268
  }
@@ -23,8 +23,8 @@ __export(lists_exports, {
23
23
  ListManager: () => ListManager
24
24
  });
25
25
  module.exports = __toCommonJS(lists_exports);
26
+ var import_flatten = require("../lib/flatten");
26
27
  var import_cache = require("./cache");
27
- var import_stuff = require("./stuff");
28
28
  class ListManager {
29
29
  rootID;
30
30
  cache;
@@ -258,7 +258,7 @@ class List {
258
258
  embeddedConnectionID,
259
259
  "edges"
260
260
  );
261
- for (const edge of (0, import_stuff.flattenList)(edges) || []) {
261
+ for (const edge of (0, import_flatten.flatten)(edges) || []) {
262
262
  if (!edge) {
263
263
  continue;
264
264
  }
@@ -336,7 +336,7 @@ class List {
336
336
  let entries = [];
337
337
  let value = this.cache._internal_unstable.storage.get(this.recordID, this.key).value;
338
338
  if (!this.connection) {
339
- entries = (0, import_stuff.flattenList)(value);
339
+ entries = (0, import_flatten.flatten)(value);
340
340
  } else {
341
341
  entries = this.cache._internal_unstable.storage.get(value, "edges").value;
342
342
  }
@@ -21,7 +21,7 @@ export declare class InMemoryStorage {
21
21
  kind: 'link' | 'scalar' | 'unknown';
22
22
  displayLayers: number[];
23
23
  };
24
- writeLink(id: string, field: string, value: string | LinkedList): number;
24
+ writeLink(id: string, field: string, value: string | NestedList): number;
25
25
  writeField(id: string, field: string, value: GraphQLValue): number;
26
26
  resolveLayer(id: number): void;
27
27
  get topLayer(): Layer;
@@ -37,7 +37,7 @@ export declare class Layer {
37
37
  get(id: string, field: string): [GraphQLField, 'link' | 'scalar'];
38
38
  getOperations(id: string, field: string): Operation[] | undefined;
39
39
  writeField(id: string, field: string, value: GraphQLField): LayerID;
40
- writeLink(id: string, field: string, value: null | string | LinkedList): LayerID;
40
+ writeLink(id: string, field: string, value: null | string | NestedList): LayerID;
41
41
  isDisplayLayer(displayLayers: number[]): boolean;
42
42
  clear(): void;
43
43
  replaceID({ from, to }: {
@@ -52,14 +52,14 @@ export declare class Layer {
52
52
  writeLayer(layer: Layer): void;
53
53
  private addFieldOperation;
54
54
  }
55
- type GraphQLField = GraphQLValue | LinkedList;
55
+ type GraphQLField = GraphQLValue | NestedList;
56
56
  type EntityMap<_Value> = {
57
57
  [id: string]: {
58
58
  [field: string]: _Value;
59
59
  };
60
60
  };
61
61
  type EntityFieldMap = EntityMap<GraphQLField>;
62
- type LinkMap = EntityMap<string | null | LinkedList>;
62
+ type LinkMap = EntityMap<string | null | NestedList>;
63
63
  type OperationMap = {
64
64
  [id: string]: {
65
65
  deleted?: boolean;
@@ -69,7 +69,7 @@ type OperationMap = {
69
69
  };
70
70
  };
71
71
  };
72
- type LinkedList<_Result = string> = (_Result | null | LinkedList<_Result>)[];
72
+ type NestedList<_Result = string> = (_Result | null | NestedList<_Result>)[];
73
73
  type InsertOperation = {
74
74
  kind: OperationKind.insert;
75
75
  location: OperationLocation;
@@ -24,7 +24,7 @@ __export(storage_exports, {
24
24
  OperationLocation: () => OperationLocation
25
25
  });
26
26
  module.exports = __toCommonJS(storage_exports);
27
- var import_stuff = require("./stuff");
27
+ var import_flatten = require("../lib/flatten");
28
28
  class InMemoryStorage {
29
29
  data;
30
30
  idCount = 0;
@@ -224,7 +224,7 @@ class Layer {
224
224
  }
225
225
  writeLink(id, field, value) {
226
226
  const valueList = Array.isArray(value) ? value : [value];
227
- for (const value2 of (0, import_stuff.flattenList)(valueList)) {
227
+ for (const value2 of (0, import_flatten.flatten)(valueList)) {
228
228
  if (!value2) {
229
229
  continue;
230
230
  }
@@ -1,6 +1,4 @@
1
1
  import type { GraphQLValue } from '../lib/types';
2
- import type { LinkedList } from './cache';
3
- export declare function flattenList<T>(source: LinkedList<T>): T[];
4
2
  export declare function evaluateKey(key: string, variables?: {
5
3
  [key: string]: GraphQLValue;
6
4
  }): string;
@@ -18,25 +18,9 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var stuff_exports = {};
20
20
  __export(stuff_exports, {
21
- evaluateKey: () => evaluateKey,
22
- flattenList: () => flattenList
21
+ evaluateKey: () => evaluateKey
23
22
  });
24
23
  module.exports = __toCommonJS(stuff_exports);
25
- function flattenList(source) {
26
- const flat = [];
27
- const unvisited = [source || []];
28
- while (unvisited.length > 0) {
29
- const target = unvisited.shift();
30
- for (const id of target) {
31
- if (Array.isArray(id)) {
32
- unvisited.push(id);
33
- continue;
34
- }
35
- flat.push(id);
36
- }
37
- }
38
- return flat;
39
- }
40
24
  function evaluateKey(key, variables = {}) {
41
25
  let evaluated = "";
42
26
  let varName = "";
@@ -65,6 +49,5 @@ function evaluateKey(key, variables = {}) {
65
49
  const varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
66
50
  // Annotate the CommonJS export names for ESM import in node:
67
51
  0 && (module.exports = {
68
- evaluateKey,
69
- flattenList
52
+ evaluateKey
70
53
  });
@@ -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 {
@@ -70,7 +71,7 @@ class InMemorySubscriptions {
70
71
  parent,
71
72
  key
72
73
  );
73
- let children = !Array.isArray(linkedRecord) ? [linkedRecord] : (0, import_stuff.flattenList)(linkedRecord) || [];
74
+ let children = !Array.isArray(linkedRecord) ? [linkedRecord] : (0, import_flatten.flatten)(linkedRecord) || [];
74
75
  for (const child of children) {
75
76
  if (!child) {
76
77
  continue;
@@ -179,7 +180,7 @@ class InMemorySubscriptions {
179
180
  const childSelection = selection.selection;
180
181
  if (childSelection) {
181
182
  const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
182
- const children = !Array.isArray(link) ? [link] : (0, import_stuff.flattenList)(link);
183
+ const children = !Array.isArray(link) ? [link] : (0, import_flatten.flatten)(link);
183
184
  for (const linkedRecord of children) {
184
185
  if (!linkedRecord) {
185
186
  continue;
@@ -215,7 +216,7 @@ class InMemorySubscriptions {
215
216
  continue;
216
217
  }
217
218
  const { value: previousValue } = this.cache._internal_unstable.storage.get(id, key);
218
- const links = !Array.isArray(previousValue) ? [previousValue] : (0, import_stuff.flattenList)(previousValue);
219
+ const links = !Array.isArray(previousValue) ? [previousValue] : (0, import_flatten.flatten)(previousValue);
219
220
  for (const link of links) {
220
221
  if (link !== null) {
221
222
  linkedIDs.push([link, fieldSelection.selection || {}]);
@@ -255,7 +256,7 @@ class InMemorySubscriptions {
255
256
  if (kind === "scalar") {
256
257
  continue;
257
258
  }
258
- const nextTargets = Array.isArray(value) ? (0, import_stuff.flattenList)(value) : [value];
259
+ const nextTargets = Array.isArray(value) ? (0, import_flatten.flatten)(value) : [value];
259
260
  for (const id2 of nextTargets) {
260
261
  if (visited.includes(id2)) {
261
262
  continue;
@@ -7,8 +7,8 @@ export declare class DocumentStore<_Data extends GraphQLObject, _Input extends R
7
7
  #private;
8
8
  constructor({ artifact, plugins, pipeline, client, cache, initialValue, fetching, }: {
9
9
  artifact: DocumentArtifact;
10
- plugins?: ClientPlugin[];
11
- pipeline?: ClientPlugin[];
10
+ plugins?: ClientHooks[];
11
+ pipeline?: ClientHooks[];
12
12
  client: HoudiniClient | null;
13
13
  cache?: boolean;
14
14
  initialValue?: _Data | null;
@@ -26,7 +26,8 @@ export declare class DocumentStore<_Data extends GraphQLObject, _Input extends R
26
26
  }): Promise<QueryResult<_Data, _Input>>;
27
27
  }
28
28
  declare function marshalVariables<_Data extends GraphQLObject, _Input extends {}>(ctx: ClientPluginContext): Record<string, any>;
29
- export type ClientPlugin = () => {
29
+ export type ClientPlugin = () => ClientHooks | null | (ClientHooks | ClientPlugin | null)[];
30
+ export type ClientHooks = {
30
31
  start?: ClientPluginEnterPhase;
31
32
  beforeNetwork?: ClientPluginEnterPhase;
32
33
  network?: ClientPluginEnterPhase;
@@ -71,13 +71,13 @@ class DocumentStore extends import_store.Writable {
71
71
  this.#client = client;
72
72
  this.#lastVariables = null;
73
73
  this.#configFile = (0, import_config.getCurrentConfig)();
74
- this.#plugins = (pipeline ?? [
75
- (0, import_plugins.cachePolicyPlugin)({
74
+ this.#plugins = pipeline ?? [
75
+ (0, import_plugins.cachePolicy)({
76
76
  enabled: cache,
77
77
  setFetching: (fetching2) => this.update((state) => ({ ...state, fetching: fetching2 }))
78
- }),
78
+ })(),
79
79
  ...plugins ?? []
80
- ]).map((factory) => factory());
80
+ ];
81
81
  }
82
82
  async send({
83
83
  metadata,
@@ -1,15 +1,15 @@
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
15
  export type ObserveParams<_Data extends GraphQLObject, _Artifact extends DocumentArtifact = DocumentArtifact> = {
@@ -24,3 +24,4 @@ export declare class HoudiniClient {
24
24
  constructor({ url, fetchParams, plugins, pipeline, throwOnError }: ConstructorArgs);
25
25
  observe<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, cache, initialValue, fetching, }: ObserveParams<_Data>): DocumentStore<_Data, _Input>;
26
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,41 @@ 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
+ const result = plugin();
86
+ if (!result) {
87
+ return hooks;
88
+ }
89
+ if (!Array.isArray(result)) {
90
+ return hooks.concat(result);
91
+ }
92
+ for (const value of result) {
93
+ if (!value) {
94
+ continue;
95
+ }
96
+ if (typeof value === "function") {
97
+ return hooks.concat(createPluginHooks([value]));
98
+ }
99
+ hooks.push(value);
100
+ }
101
+ return hooks;
102
+ }, []);
103
+ }
79
104
  // Annotate the CommonJS export names for ESM import in node:
80
105
  0 && (module.exports = {
81
106
  DocumentStore,
82
107
  HoudiniClient,
83
- fetchPlugin,
84
- mutationPlugin,
85
- queryPlugin,
86
- subscriptionPlugin
108
+ createPluginHooks,
109
+ fetch,
110
+ mutation,
111
+ query,
112
+ subscription
87
113
  });
@@ -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,12 +24,12 @@ 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
@@ -97,5 +97,5 @@ const cachePolicyPlugin = ({
97
97
  };
98
98
  // Annotate the CommonJS export names for ESM import in node:
99
99
  0 && (module.exports = {
100
- cachePolicyPlugin
100
+ cachePolicy
101
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 || {},
@@ -70,8 +70,8 @@ const defaultFetch = (url, params) => {
70
70
  "Could not find configured client url. Please specify one in your houdini.config.js file."
71
71
  );
72
72
  }
73
- return async ({ fetch, text, variables }) => {
74
- const result = await fetch(url, {
73
+ return async ({ fetch: fetch2, text, variables }) => {
74
+ const result = await fetch2(url, {
75
75
  method: "POST",
76
76
  body: JSON.stringify({ query: text, variables }),
77
77
  ...params,
@@ -173,6 +173,6 @@ function isPlainObject(value) {
173
173
  // Annotate the CommonJS export names for ESM import in node:
174
174
  0 && (module.exports = {
175
175
  extractFiles,
176
- fetchPlugin,
176
+ fetch,
177
177
  isExtractableFile
178
178
  });