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
@@ -1,14 +1,15 @@
1
+ import { flatten } from "../lib/flatten";
1
2
  import { DocumentStore } from "./documentStore";
2
3
  import {
3
- fetchParamsPlugin,
4
- fetchPlugin,
5
- mutationPlugin,
6
- queryPlugin,
7
- throwOnErrorPlugin
4
+ fetchParams as fetchParamsPlugin,
5
+ fetch as fetchPlugin,
6
+ mutation as mutationPlugin,
7
+ query as queryPlugin,
8
+ throwOnError as throwOnErrorPlugin
8
9
  } from "./plugins";
9
10
  import pluginsFromPlugins from "./plugins/injectedPlugins";
10
11
  import { DocumentStore as DocumentStore2 } from "./documentStore";
11
- import { fetchPlugin as fetchPlugin2, mutationPlugin as mutationPlugin2, queryPlugin as queryPlugin2, subscriptionPlugin } from "./plugins";
12
+ import { fetch, mutation, query, subscription } from "./plugins";
12
13
  class HoudiniClient {
13
14
  url;
14
15
  #plugins;
@@ -18,16 +19,18 @@ class HoudiniClient {
18
19
  "A client cannot be given a pipeline and a list of plugins at the same time."
19
20
  );
20
21
  }
21
- this.#plugins = [].concat(
22
- throwOnError ? [throwOnErrorPlugin(throwOnError)] : [],
23
- fetchParamsPlugin(fetchParams),
24
- pipeline ?? [
25
- queryPlugin,
26
- mutationPlugin
27
- ].concat(
28
- plugins ?? [],
29
- pluginsFromPlugins,
30
- fetchPlugin()
22
+ this.#plugins = flatten(
23
+ [].concat(
24
+ throwOnError ? [throwOnErrorPlugin(throwOnError)] : [],
25
+ fetchParamsPlugin(fetchParams),
26
+ pipeline ?? [
27
+ queryPlugin,
28
+ mutationPlugin
29
+ ].concat(
30
+ plugins ?? [],
31
+ pluginsFromPlugins,
32
+ fetchPlugin()
33
+ )
31
34
  )
32
35
  );
33
36
  this.url = url;
@@ -41,18 +44,40 @@ class HoudiniClient {
41
44
  return new DocumentStore({
42
45
  client: this,
43
46
  artifact,
44
- plugins: this.#plugins,
47
+ plugins: createPluginHooks(this.#plugins),
45
48
  cache,
46
49
  initialValue,
47
50
  fetching
48
51
  });
49
52
  }
50
53
  }
54
+ function createPluginHooks(plugins) {
55
+ return plugins.reduce((hooks, plugin) => {
56
+ const result = plugin();
57
+ if (!result) {
58
+ return hooks;
59
+ }
60
+ if (!Array.isArray(result)) {
61
+ return hooks.concat(result);
62
+ }
63
+ for (const value of result) {
64
+ if (!value) {
65
+ continue;
66
+ }
67
+ if (typeof value === "function") {
68
+ return hooks.concat(createPluginHooks([value]));
69
+ }
70
+ hooks.push(value);
71
+ }
72
+ return hooks;
73
+ }, []);
74
+ }
51
75
  export {
52
76
  DocumentStore2 as DocumentStore,
53
77
  HoudiniClient,
54
- fetchPlugin2 as fetchPlugin,
55
- mutationPlugin2 as mutationPlugin,
56
- queryPlugin2 as queryPlugin,
57
- subscriptionPlugin
78
+ createPluginHooks,
79
+ fetch,
80
+ mutation,
81
+ query,
82
+ subscription
58
83
  };
@@ -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 cache from "../../cache";
2
2
  import { ArtifactKind, CachePolicy, DataSource } from "../../lib/types";
3
- const cachePolicyPlugin = ({
3
+ const cachePolicy = ({
4
4
  enabled,
5
5
  setFetching,
6
6
  cache: localCache = cache
@@ -67,5 +67,5 @@ const cachePolicyPlugin = ({
67
67
  };
68
68
  };
69
69
  export {
70
- cachePolicyPlugin
70
+ cachePolicy
71
71
  };
@@ -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,9 +1,9 @@
1
1
  import { DataSource } from "../../lib/types";
2
- const fetchPlugin = (target) => {
2
+ const fetch = (target) => {
3
3
  return () => {
4
4
  return {
5
5
  async network(ctx, { client, resolve, marshalVariables }) {
6
- const fetch = ctx.fetch ?? globalThis.fetch;
6
+ const fetch2 = ctx.fetch ?? globalThis.fetch;
7
7
  const fetchParams = {
8
8
  text: ctx.text,
9
9
  hash: ctx.hash,
@@ -20,7 +20,7 @@ const fetchPlugin = (target) => {
20
20
  const result = await fetchFn({
21
21
  fetch: (url, args) => {
22
22
  const newArgs = handleMultipart(fetchParams, args) ?? args;
23
- return fetch(url, newArgs);
23
+ return fetch2(url, newArgs);
24
24
  },
25
25
  metadata: ctx.metadata,
26
26
  session: ctx.session || {},
@@ -45,8 +45,8 @@ const defaultFetch = (url, params) => {
45
45
  "Could not find configured client url. Please specify one in your houdini.config.js file."
46
46
  );
47
47
  }
48
- return async ({ fetch, text, variables }) => {
49
- const result = await fetch(url, {
48
+ return async ({ fetch: fetch2, text, variables }) => {
49
+ const result = await fetch2(url, {
50
50
  method: "POST",
51
51
  body: JSON.stringify({ query: text, variables }),
52
52
  ...params,
@@ -147,6 +147,6 @@ function isPlainObject(value) {
147
147
  }
148
148
  export {
149
149
  extractFiles,
150
- fetchPlugin,
150
+ fetch,
151
151
  isExtractableFile
152
152
  };
@@ -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,4 +1,4 @@
1
- const fetchParamsPlugin = (fn = () => ({})) => () => ({
1
+ const fetchParams = (fn = () => ({})) => () => ({
2
2
  beforeNetwork(ctx, { next, marshalVariables }) {
3
3
  next({
4
4
  ...ctx,
@@ -17,5 +17,5 @@ const fetchParamsPlugin = (fn = () => ({})) => () => ({
17
17
  }
18
18
  });
19
19
  export {
20
- fetchParamsPlugin
20
+ fetchParams
21
21
  };
@@ -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;
@@ -2,7 +2,7 @@ import cache from "../../cache";
2
2
  import { marshalSelection } from "../../lib/scalars";
3
3
  import { ArtifactKind } from "../../lib/types";
4
4
  import { documentPlugin } from "../utils";
5
- const mutationPlugin = documentPlugin(ArtifactKind.Mutation, () => {
5
+ const mutation = documentPlugin(ArtifactKind.Mutation, () => {
6
6
  return {
7
7
  async start(ctx, { next, marshalVariables }) {
8
8
  const layer = cache._internal_unstable.storage.createLayer(true);
@@ -52,5 +52,5 @@ const mutationPlugin = documentPlugin(ArtifactKind.Mutation, () => {
52
52
  };
53
53
  });
54
54
  export {
55
- mutationPlugin
55
+ mutation
56
56
  };
@@ -1,2 +1,2 @@
1
1
  import type { ClientPlugin } from '../documentStore';
2
- export declare const queryPlugin: ClientPlugin;
2
+ export declare const query: ClientPlugin;
@@ -1,7 +1,7 @@
1
1
  import cache from "../../cache";
2
2
  import { ArtifactKind, DataSource } from "../../lib/types";
3
3
  import { documentPlugin } from "../utils";
4
- const queryPlugin = documentPlugin(ArtifactKind.Query, function() {
4
+ const query = documentPlugin(ArtifactKind.Query, function() {
5
5
  let subscriptionSpec = null;
6
6
  let lastVariables = null;
7
7
  let artifactName = "";
@@ -49,5 +49,5 @@ const queryPlugin = documentPlugin(ArtifactKind.Query, function() {
49
49
  };
50
50
  });
51
51
  export {
52
- queryPlugin
52
+ query
53
53
  };
@@ -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;
@@ -1,7 +1,7 @@
1
1
  import { deepEquals } from "../../lib/deepEquals";
2
2
  import { ArtifactKind, DataSource } from "../../lib/types";
3
3
  import { documentPlugin } from "../utils";
4
- function subscriptionPlugin(factory) {
4
+ function subscription(factory) {
5
5
  return documentPlugin(ArtifactKind.Subscription, () => {
6
6
  let clearSubscription = null;
7
7
  let socketClient = null;
@@ -72,5 +72,5 @@ function subscriptionPlugin(factory) {
72
72
  });
73
73
  }
74
74
  export {
75
- subscriptionPlugin
75
+ subscription
76
76
  };
@@ -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,5 +1,5 @@
1
1
  import { ArtifactKind } from "../../lib";
2
- const throwOnErrorPlugin = ({ operations, error }) => () => {
2
+ const throwOnError = ({ operations, error }) => () => {
3
3
  const all = operations.includes("all");
4
4
  const throwOnKind = (kind) => all || {
5
5
  [ArtifactKind.Query]: operations.includes("query"),
@@ -19,5 +19,5 @@ const throwOnErrorPlugin = ({ operations, error }) => () => {
19
19
  };
20
20
  const defaultErrorFn = async (errors) => new Error(errors.map((error) => error.message).join(". ") + ".");
21
21
  export {
22
- throwOnErrorPlugin
22
+ throwOnError
23
23
  };
@@ -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[];
@@ -0,0 +1,17 @@
1
+ function flatten(source) {
2
+ if (!source) {
3
+ return [];
4
+ }
5
+ return source.reduce((acc, element) => {
6
+ if (!element) {
7
+ return acc;
8
+ }
9
+ if (Array.isArray(element)) {
10
+ return acc.concat(flatten(element));
11
+ }
12
+ return acc.concat(element);
13
+ }, []);
14
+ }
15
+ export {
16
+ flatten
17
+ };
@@ -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 {};
@@ -64,8 +64,8 @@ Please acknowledge this by setting acceptImperativeInstability to true in your c
64
64
  });
65
65
  return;
66
66
  }
67
- markStale(type, options = {}) {
68
- return this._internal_unstable.markTypeStale(type, options);
67
+ markStale(type, options) {
68
+ return this._internal_unstable.markTypeStale(type ? { ...options, type } : void 0);
69
69
  }
70
70
  }
71
71
  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
  }
@@ -54,8 +54,7 @@ class Record {
54
54
  delete() {
55
55
  this.#cache._internal_unstable.delete(this.#id);
56
56
  }
57
- markStale({
58
- field,
57
+ markStale(field, {
59
58
  when
60
59
  } = {}) {
61
60
  this.#cache._internal_unstable.markRecordStale(this.#id, { field, when });