houdini-svelte 2.1.9 → 2.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/build/plugin-cjs/index.js +7 -5
  2. package/build/plugin-esm/index.js +7 -5
  3. package/build/preprocess-cjs/index.js +4 -4
  4. package/build/preprocess-esm/index.js +4 -4
  5. package/build/runtime/client.d.ts +1 -0
  6. package/build/runtime/fragments.d.ts +1 -1
  7. package/build/runtime/stores/fragment.d.ts +58 -2
  8. package/build/runtime/stores/index.d.ts +2 -3
  9. package/build/runtime/stores/query.d.ts +27 -1
  10. package/build/runtime-cjs/client.d.ts +1 -0
  11. package/build/runtime-cjs/client.js +22 -5
  12. package/build/runtime-cjs/fragments.d.ts +1 -1
  13. package/build/runtime-cjs/stores/base.js +5 -0
  14. package/build/runtime-cjs/stores/fragment.d.ts +58 -2
  15. package/build/runtime-cjs/stores/fragment.js +184 -2
  16. package/build/runtime-cjs/stores/index.d.ts +2 -3
  17. package/build/runtime-cjs/stores/index.js +9 -3
  18. package/build/runtime-cjs/stores/mutation.js +2 -0
  19. package/build/runtime-cjs/stores/query.d.ts +27 -1
  20. package/build/runtime-cjs/stores/query.js +123 -1
  21. package/build/runtime-cjs/stores/subscription.js +3 -0
  22. package/build/runtime-esm/client.d.ts +1 -0
  23. package/build/runtime-esm/client.js +18 -2
  24. package/build/runtime-esm/fragments.d.ts +1 -1
  25. package/build/runtime-esm/stores/base.js +6 -1
  26. package/build/runtime-esm/stores/fragment.d.ts +58 -2
  27. package/build/runtime-esm/stores/fragment.js +183 -3
  28. package/build/runtime-esm/stores/index.d.ts +2 -3
  29. package/build/runtime-esm/stores/index.js +6 -3
  30. package/build/runtime-esm/stores/mutation.js +2 -0
  31. package/build/runtime-esm/stores/query.d.ts +27 -1
  32. package/build/runtime-esm/stores/query.js +124 -4
  33. package/build/runtime-esm/stores/subscription.js +3 -0
  34. package/build/test-cjs/index.js +7 -5
  35. package/build/test-esm/index.js +7 -5
  36. package/package.json +1 -1
  37. package/build/runtime/stores/pagination/fragment.d.ts +0 -58
  38. package/build/runtime/stores/pagination/index.d.ts +0 -2
  39. package/build/runtime/stores/pagination/query.d.ts +0 -30
  40. package/build/runtime-cjs/stores/pagination/fragment.d.ts +0 -58
  41. package/build/runtime-cjs/stores/pagination/fragment.js +0 -207
  42. package/build/runtime-cjs/stores/pagination/index.d.ts +0 -2
  43. package/build/runtime-cjs/stores/pagination/index.js +0 -35
  44. package/build/runtime-cjs/stores/pagination/query.d.ts +0 -30
  45. package/build/runtime-cjs/stores/pagination/query.js +0 -147
  46. package/build/runtime-esm/stores/pagination/fragment.d.ts +0 -58
  47. package/build/runtime-esm/stores/pagination/fragment.js +0 -182
  48. package/build/runtime-esm/stores/pagination/index.d.ts +0 -2
  49. package/build/runtime-esm/stores/pagination/index.js +0 -8
  50. package/build/runtime-esm/stores/pagination/query.d.ts +0 -30
  51. package/build/runtime-esm/stores/pagination/query.js +0 -122
@@ -82652,10 +82652,10 @@ function plugin_config(config) {
82652
82652
  mutation: "../runtime/stores/mutation.MutationStore",
82653
82653
  fragment: "../runtime/stores/fragment.FragmentStore",
82654
82654
  subscription: "../runtime/stores/subscription.SubscriptionStore",
82655
- queryCursor: "../runtime/stores/pagination/query.QueryStoreCursor",
82656
- queryOffset: "../runtime/stores/pagination/query.QueryStoreOffset",
82657
- fragmentCursor: "../runtime/stores/pagination/fragment.FragmentStoreCursor",
82658
- fragmentOffset: "../runtime/stores/pagination/fragment.FragmentStoreOffset",
82655
+ queryCursor: "../runtime/stores/query.QueryStoreCursor",
82656
+ queryOffset: "../runtime/stores/query.QueryStoreOffset",
82657
+ fragmentCursor: "../runtime/stores/fragment.FragmentStoreCursor",
82658
+ fragmentOffset: "../runtime/stores/fragment.FragmentStoreOffset",
82659
82659
  ...cfg?.customStores
82660
82660
  }
82661
82661
  };
@@ -152853,6 +152853,7 @@ async function queryStore({ config, pluginRoot }, doc) {
152853
152853
  const { store_class, statement } = store_import2(config, which);
152854
152854
  const storeData = `${statement}
152855
152855
  import artifact from '$houdini/artifacts/${artifactName}'
152856
+ import { initClient } from '$houdini/plugins/houdini-svelte/runtime/client'
152856
152857
 
152857
152858
  export class ${storeName} extends ${store_class} {
152858
152859
  constructor() {
@@ -152865,6 +152866,7 @@ export class ${storeName} extends ${store_class} {
152865
152866
  }
152866
152867
 
152867
152868
  export async function load_${artifactName}(params) {
152869
+ await initClient()
152868
152870
 
152869
152871
  const store = new ${storeName}()
152870
152872
 
@@ -154238,7 +154240,7 @@ export const redirect = svelteKitRedirect
154238
154240
  path_exports.dirname(networkFilePath),
154239
154241
  path_exports.join(config.projectRoot, plugin_config(config).client)
154240
154242
  );
154241
- return content.replace("HOUDINI_CLIENT_PATH", relativePath);
154243
+ return content.replaceAll("HOUDINI_CLIENT_PATH", relativePath);
154242
154244
  }
154243
154245
  },
154244
154246
  artifactData,
@@ -82648,10 +82648,10 @@ function plugin_config(config) {
82648
82648
  mutation: "../runtime/stores/mutation.MutationStore",
82649
82649
  fragment: "../runtime/stores/fragment.FragmentStore",
82650
82650
  subscription: "../runtime/stores/subscription.SubscriptionStore",
82651
- queryCursor: "../runtime/stores/pagination/query.QueryStoreCursor",
82652
- queryOffset: "../runtime/stores/pagination/query.QueryStoreOffset",
82653
- fragmentCursor: "../runtime/stores/pagination/fragment.FragmentStoreCursor",
82654
- fragmentOffset: "../runtime/stores/pagination/fragment.FragmentStoreOffset",
82651
+ queryCursor: "../runtime/stores/query.QueryStoreCursor",
82652
+ queryOffset: "../runtime/stores/query.QueryStoreOffset",
82653
+ fragmentCursor: "../runtime/stores/fragment.FragmentStoreCursor",
82654
+ fragmentOffset: "../runtime/stores/fragment.FragmentStoreOffset",
82655
82655
  ...cfg?.customStores
82656
82656
  }
82657
82657
  };
@@ -152848,6 +152848,7 @@ async function queryStore({ config, pluginRoot }, doc) {
152848
152848
  const { store_class, statement } = store_import2(config, which);
152849
152849
  const storeData = `${statement}
152850
152850
  import artifact from '$houdini/artifacts/${artifactName}'
152851
+ import { initClient } from '$houdini/plugins/houdini-svelte/runtime/client'
152851
152852
 
152852
152853
  export class ${storeName} extends ${store_class} {
152853
152854
  constructor() {
@@ -152860,6 +152861,7 @@ export class ${storeName} extends ${store_class} {
152860
152861
  }
152861
152862
 
152862
152863
  export async function load_${artifactName}(params) {
152864
+ await initClient()
152863
152865
 
152864
152866
  const store = new ${storeName}()
152865
152867
 
@@ -154233,7 +154235,7 @@ export const redirect = svelteKitRedirect
154233
154235
  path_exports.dirname(networkFilePath),
154234
154236
  path_exports.join(config.projectRoot, plugin_config(config).client)
154235
154237
  );
154236
- return content.replace("HOUDINI_CLIENT_PATH", relativePath);
154238
+ return content.replaceAll("HOUDINI_CLIENT_PATH", relativePath);
154237
154239
  }
154238
154240
  },
154239
154241
  artifactData,
@@ -86584,10 +86584,10 @@ function plugin_config(config) {
86584
86584
  mutation: "../runtime/stores/mutation.MutationStore",
86585
86585
  fragment: "../runtime/stores/fragment.FragmentStore",
86586
86586
  subscription: "../runtime/stores/subscription.SubscriptionStore",
86587
- queryCursor: "../runtime/stores/pagination/query.QueryStoreCursor",
86588
- queryOffset: "../runtime/stores/pagination/query.QueryStoreOffset",
86589
- fragmentCursor: "../runtime/stores/pagination/fragment.FragmentStoreCursor",
86590
- fragmentOffset: "../runtime/stores/pagination/fragment.FragmentStoreOffset",
86587
+ queryCursor: "../runtime/stores/query.QueryStoreCursor",
86588
+ queryOffset: "../runtime/stores/query.QueryStoreOffset",
86589
+ fragmentCursor: "../runtime/stores/fragment.FragmentStoreCursor",
86590
+ fragmentOffset: "../runtime/stores/fragment.FragmentStoreOffset",
86591
86591
  ...cfg?.customStores
86592
86592
  }
86593
86593
  };
@@ -86581,10 +86581,10 @@ function plugin_config(config) {
86581
86581
  mutation: "../runtime/stores/mutation.MutationStore",
86582
86582
  fragment: "../runtime/stores/fragment.FragmentStore",
86583
86583
  subscription: "../runtime/stores/subscription.SubscriptionStore",
86584
- queryCursor: "../runtime/stores/pagination/query.QueryStoreCursor",
86585
- queryOffset: "../runtime/stores/pagination/query.QueryStoreOffset",
86586
- fragmentCursor: "../runtime/stores/pagination/fragment.FragmentStoreCursor",
86587
- fragmentOffset: "../runtime/stores/pagination/fragment.FragmentStoreOffset",
86584
+ queryCursor: "../runtime/stores/query.QueryStoreCursor",
86585
+ queryOffset: "../runtime/stores/query.QueryStoreOffset",
86586
+ fragmentCursor: "../runtime/stores/fragment.FragmentStoreCursor",
86587
+ fragmentOffset: "../runtime/stores/fragment.FragmentStoreOffset",
86588
86588
  ...cfg?.customStores
86589
86589
  }
86590
86590
  };
@@ -1,2 +1,3 @@
1
1
  import type { HoudiniClient } from '$houdini/runtime/client';
2
+ export declare function initClient(): Promise<HoudiniClient>;
2
3
  export declare function getClient(): HoudiniClient;
@@ -2,7 +2,7 @@
2
2
  import type { Fragment, FragmentArtifact } from '$houdini/runtime/lib/types';
3
3
  import type { Readable } from 'svelte/store';
4
4
  import type { FragmentStore } from './stores';
5
- import type { FragmentStorePaginated } from './stores/pagination/fragment';
5
+ import type { FragmentStorePaginated } from './stores/fragment';
6
6
  export declare function fragment<_Fragment extends Fragment<any>>(ref: _Fragment, fragment: FragmentStore<_Fragment['shape'], {}>): Readable<Exclude<_Fragment['shape'], undefined>> & {
7
7
  data: Readable<_Fragment>;
8
8
  artifact: FragmentArtifact;
@@ -1,6 +1,10 @@
1
- import type { GraphQLObject, FragmentArtifact, HoudiniFetchContext, GraphQLVariables } from '$houdini/runtime/lib/types';
1
+ /// <reference types="svelte" />
2
+ import type { DocumentStore } from '$houdini/runtime/client';
3
+ import type { GraphQLObject, FragmentArtifact, HoudiniFetchContext, GraphQLVariables, QueryArtifact, PageInfo, CursorHandlers } from '$houdini/runtime/lib/types';
2
4
  import { fragmentKey } from '$houdini/runtime/lib/types';
3
- import type { FragmentStoreInstance } from '../types';
5
+ import type { Readable, Subscriber } from 'svelte/store';
6
+ import type { FragmentStoreInstance, OffsetFragmentStoreInstance } from '../types';
7
+ import type { StoreConfig } from './query';
4
8
  export declare class FragmentStore<_Data extends GraphQLObject, _ReferenceType extends {}, _Input extends GraphQLVariables = GraphQLVariables> {
5
9
  artifact: FragmentArtifact;
6
10
  name: string;
@@ -16,3 +20,55 @@ export declare class FragmentStore<_Data extends GraphQLObject, _ReferenceType e
16
20
  initialValue: _Data | null;
17
21
  };
18
22
  }
23
+ type FragmentStoreConfig<_Data extends GraphQLObject, _Input> = StoreConfig<_Data, _Input, FragmentArtifact> & {
24
+ paginationArtifact: QueryArtifact;
25
+ };
26
+ declare class BasePaginatedFragmentStore<_Data extends GraphQLObject, _Input> {
27
+ paginated: boolean;
28
+ protected paginationArtifact: QueryArtifact;
29
+ name: string;
30
+ kind: "HoudiniFragment";
31
+ artifact: FragmentArtifact;
32
+ constructor(config: FragmentStoreConfig<_Data, _Input>);
33
+ protected queryVariables(getState: () => _Data | null): _Input;
34
+ }
35
+ export declare class FragmentStoreCursor<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends BasePaginatedFragmentStore<_Data, _Input> {
36
+ get(initialValue: _Data | null): {
37
+ kind: "HoudiniFragment";
38
+ subscribe: (run: Subscriber<FragmentPaginatedResult<_Data, {
39
+ pageInfo: PageInfo;
40
+ }>>, invalidate?: ((value?: FragmentPaginatedResult<_Data, {
41
+ pageInfo: PageInfo;
42
+ }> | undefined) => void) | undefined) => (() => void);
43
+ fetch: (args?: import("$houdini/runtime/lib/types").FetchParams<_Input> | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
44
+ loadNextPage: (args?: {
45
+ first?: number | undefined;
46
+ after?: string | undefined;
47
+ fetch?: typeof fetch | undefined;
48
+ metadata?: {} | undefined;
49
+ } | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
50
+ loadPreviousPage: (args?: {
51
+ last?: number | undefined;
52
+ before?: string | undefined;
53
+ fetch?: typeof fetch | undefined;
54
+ metadata?: {} | undefined;
55
+ } | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
56
+ };
57
+ protected storeHandlers(observer: DocumentStore<_Data, _Input>, initialValue: _Data | null, getState: () => _Data | null, getVariables: () => NonNullable<_Input>): CursorHandlers<_Data, _Input>;
58
+ }
59
+ export declare class FragmentStoreOffset<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends BasePaginatedFragmentStore<_Data, _Input> {
60
+ get(initialValue: _Data | null): OffsetFragmentStoreInstance<_Data, _Input>;
61
+ }
62
+ export type FragmentStorePaginated<_Data extends GraphQLObject, _Input> = Readable<{
63
+ data: _Data;
64
+ fetching: boolean;
65
+ pageInfo: PageInfo;
66
+ }> & {
67
+ loadNextPage(pageCount?: number, after?: string | number, houdiniContext?: HoudiniFetchContext): Promise<void>;
68
+ loadPreviousPage(pageCount?: number, before?: string, houdiniContext?: HoudiniFetchContext): Promise<void>;
69
+ };
70
+ export type FragmentPaginatedResult<_Data, _ExtraFields = {}> = {
71
+ data: _Data | null;
72
+ fetching: boolean;
73
+ } & _ExtraFields;
74
+ export {};
@@ -1,5 +1,4 @@
1
- export * from './pagination';
2
- export { FragmentStore } from './fragment';
1
+ export { QueryStore, QueryStoreCursor, QueryStoreOffset } from './query';
2
+ export { FragmentStore, FragmentStoreCursor, FragmentStoreOffset } from './fragment';
3
3
  export { SubscriptionStore } from './subscription';
4
4
  export { MutationStore, type MutationConfig } from './mutation';
5
- export { QueryStore } from './query';
@@ -1,5 +1,7 @@
1
+ /// <reference types="svelte" />
1
2
  import type { FetchContext } from '$houdini/runtime/client/plugins/fetch';
2
- import type { CachePolicies, GraphQLVariables, GraphQLObject, MutationArtifact, QueryArtifact, QueryResult } from '$houdini/runtime/lib/types';
3
+ import type { CachePolicies, GraphQLVariables, GraphQLObject, MutationArtifact, QueryArtifact, QueryResult, CursorHandlers, OffsetHandlers, PageInfo } from '$houdini/runtime/lib/types';
4
+ import type { Subscriber } from 'svelte/store';
3
5
  import type { PluginArtifactData } from '../../plugin/artifactData';
4
6
  import type { ClientFetchParams, LoadEventFetchParams, QueryStoreFetchParams, RequestEventFetchParams } from '../types';
5
7
  import { BaseStore } from './base';
@@ -31,3 +33,27 @@ export declare function fetchParams<_Data extends GraphQLObject, _Input>(artifac
31
33
  policy: CachePolicies | undefined;
32
34
  params: QueryStoreFetchParams<_Data, _Input>;
33
35
  }>;
36
+ export type CursorStoreResult<_Data extends GraphQLObject, _Input extends GraphQLVariables> = QueryResult<_Data, _Input> & {
37
+ pageInfo: PageInfo;
38
+ };
39
+ export declare class QueryStoreCursor<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends QueryStore<_Data, _Input> {
40
+ #private;
41
+ paginated: boolean;
42
+ constructor(config: StoreConfig<_Data, _Input, QueryArtifact>);
43
+ fetch(params?: RequestEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
44
+ fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
45
+ fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
46
+ fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
47
+ loadPreviousPage(args?: Parameters<Required<CursorHandlers<_Data, _Input>>['loadPreviousPage']>[0]): Promise<QueryResult<_Data, _Input>>;
48
+ loadNextPage(args?: Parameters<CursorHandlers<_Data, _Input>['loadNextPage']>[0]): Promise<QueryResult<_Data, _Input>>;
49
+ subscribe(run: Subscriber<CursorStoreResult<_Data, _Input>>, invalidate?: ((value?: CursorStoreResult<_Data, _Input> | undefined) => void) | undefined): () => void;
50
+ }
51
+ export declare class QueryStoreOffset<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends QueryStore<_Data, _Input> {
52
+ #private;
53
+ paginated: boolean;
54
+ loadNextPage(args?: Parameters<OffsetHandlers<_Data, _Input>['loadNextPage']>[0]): Promise<void>;
55
+ fetch(params?: RequestEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
56
+ fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
57
+ fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
58
+ fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
59
+ }
@@ -1,2 +1,3 @@
1
1
  import type { HoudiniClient } from '$houdini/runtime/client';
2
+ export declare function initClient(): Promise<HoudiniClient>;
2
3
  export declare function getClient(): HoudiniClient;
@@ -24,17 +24,34 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
  var client_exports = {};
26
26
  __export(client_exports, {
27
- getClient: () => getClient
27
+ getClient: () => getClient,
28
+ initClient: () => initClient
28
29
  });
29
30
  module.exports = __toCommonJS(client_exports);
30
- var import_HOUDINI_CLIENT_PATH = __toESM(require("HOUDINI_CLIENT_PATH"), 1);
31
+ let client = null;
32
+ async function initClient() {
33
+ if (client) {
34
+ return client;
35
+ }
36
+ client = (await import("HOUDINI_CLIENT_PATH")).default;
37
+ const delay = (ms) => new Promise((res) => setTimeout(res, ms));
38
+ for (let retry = 0; retry < 10; retry++) {
39
+ if (client) {
40
+ break;
41
+ }
42
+ await delay(100);
43
+ client = (await import("HOUDINI_CLIENT_PATH")).default;
44
+ }
45
+ return client;
46
+ }
31
47
  function getClient() {
32
- if (!import_HOUDINI_CLIENT_PATH.default) {
48
+ if (!client) {
33
49
  throw new Error("client hasn't been initialized");
34
50
  }
35
- return import_HOUDINI_CLIENT_PATH.default;
51
+ return client;
36
52
  }
37
53
  // Annotate the CommonJS export names for ESM import in node:
38
54
  0 && (module.exports = {
39
- getClient
55
+ getClient,
56
+ initClient
40
57
  });
@@ -2,7 +2,7 @@
2
2
  import type { Fragment, FragmentArtifact } from '$houdini/runtime/lib/types';
3
3
  import type { Readable } from 'svelte/store';
4
4
  import type { FragmentStore } from './stores';
5
- import type { FragmentStorePaginated } from './stores/pagination/fragment';
5
+ import type { FragmentStorePaginated } from './stores/fragment';
6
6
  export declare function fragment<_Fragment extends Fragment<any>>(ref: _Fragment, fragment: FragmentStore<_Fragment['shape'], {}>): Readable<Exclude<_Fragment['shape'], undefined>> & {
7
7
  data: Readable<_Fragment>;
8
8
  artifact: FragmentArtifact;
@@ -73,6 +73,11 @@ class BaseStore {
73
73
  #subscriberCount = 0;
74
74
  setup(init = true) {
75
75
  let initPromise = Promise.resolve();
76
+ try {
77
+ (0, import_client2.getClient)();
78
+ } catch {
79
+ initPromise = (0, import_client2.initClient)();
80
+ }
76
81
  initPromise.then(() => {
77
82
  if (this.#unsubscribe) {
78
83
  return;
@@ -1,6 +1,10 @@
1
- import type { GraphQLObject, FragmentArtifact, HoudiniFetchContext, GraphQLVariables } from '$houdini/runtime/lib/types';
1
+ /// <reference types="svelte" />
2
+ import type { DocumentStore } from '$houdini/runtime/client';
3
+ import type { GraphQLObject, FragmentArtifact, HoudiniFetchContext, GraphQLVariables, QueryArtifact, PageInfo, CursorHandlers } from '$houdini/runtime/lib/types';
2
4
  import { fragmentKey } from '$houdini/runtime/lib/types';
3
- import type { FragmentStoreInstance } from '../types';
5
+ import type { Readable, Subscriber } from 'svelte/store';
6
+ import type { FragmentStoreInstance, OffsetFragmentStoreInstance } from '../types';
7
+ import type { StoreConfig } from './query';
4
8
  export declare class FragmentStore<_Data extends GraphQLObject, _ReferenceType extends {}, _Input extends GraphQLVariables = GraphQLVariables> {
5
9
  artifact: FragmentArtifact;
6
10
  name: string;
@@ -16,3 +20,55 @@ export declare class FragmentStore<_Data extends GraphQLObject, _ReferenceType e
16
20
  initialValue: _Data | null;
17
21
  };
18
22
  }
23
+ type FragmentStoreConfig<_Data extends GraphQLObject, _Input> = StoreConfig<_Data, _Input, FragmentArtifact> & {
24
+ paginationArtifact: QueryArtifact;
25
+ };
26
+ declare class BasePaginatedFragmentStore<_Data extends GraphQLObject, _Input> {
27
+ paginated: boolean;
28
+ protected paginationArtifact: QueryArtifact;
29
+ name: string;
30
+ kind: "HoudiniFragment";
31
+ artifact: FragmentArtifact;
32
+ constructor(config: FragmentStoreConfig<_Data, _Input>);
33
+ protected queryVariables(getState: () => _Data | null): _Input;
34
+ }
35
+ export declare class FragmentStoreCursor<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends BasePaginatedFragmentStore<_Data, _Input> {
36
+ get(initialValue: _Data | null): {
37
+ kind: "HoudiniFragment";
38
+ subscribe: (run: Subscriber<FragmentPaginatedResult<_Data, {
39
+ pageInfo: PageInfo;
40
+ }>>, invalidate?: ((value?: FragmentPaginatedResult<_Data, {
41
+ pageInfo: PageInfo;
42
+ }> | undefined) => void) | undefined) => (() => void);
43
+ fetch: (args?: import("$houdini/runtime/lib/types").FetchParams<_Input> | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
44
+ loadNextPage: (args?: {
45
+ first?: number | undefined;
46
+ after?: string | undefined;
47
+ fetch?: typeof fetch | undefined;
48
+ metadata?: {} | undefined;
49
+ } | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
50
+ loadPreviousPage: (args?: {
51
+ last?: number | undefined;
52
+ before?: string | undefined;
53
+ fetch?: typeof fetch | undefined;
54
+ metadata?: {} | undefined;
55
+ } | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
56
+ };
57
+ protected storeHandlers(observer: DocumentStore<_Data, _Input>, initialValue: _Data | null, getState: () => _Data | null, getVariables: () => NonNullable<_Input>): CursorHandlers<_Data, _Input>;
58
+ }
59
+ export declare class FragmentStoreOffset<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends BasePaginatedFragmentStore<_Data, _Input> {
60
+ get(initialValue: _Data | null): OffsetFragmentStoreInstance<_Data, _Input>;
61
+ }
62
+ export type FragmentStorePaginated<_Data extends GraphQLObject, _Input> = Readable<{
63
+ data: _Data;
64
+ fetching: boolean;
65
+ pageInfo: PageInfo;
66
+ }> & {
67
+ loadNextPage(pageCount?: number, after?: string | number, houdiniContext?: HoudiniFetchContext): Promise<void>;
68
+ loadPreviousPage(pageCount?: number, before?: string, houdiniContext?: HoudiniFetchContext): Promise<void>;
69
+ };
70
+ export type FragmentPaginatedResult<_Data, _ExtraFields = {}> = {
71
+ data: _Data | null;
72
+ fetching: boolean;
73
+ } & _ExtraFields;
74
+ export {};
@@ -24,15 +24,22 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
  var fragment_exports = {};
26
26
  __export(fragment_exports, {
27
- FragmentStore: () => FragmentStore
27
+ FragmentStore: () => FragmentStore,
28
+ FragmentStoreCursor: () => FragmentStoreCursor,
29
+ FragmentStoreOffset: () => FragmentStoreOffset
28
30
  });
29
31
  module.exports = __toCommonJS(fragment_exports);
30
32
  var import_cache = __toESM(require("$houdini/runtime/cache"), 1);
31
33
  var import_config = require("$houdini/runtime/lib/config");
34
+ var import_constants = require("$houdini/runtime/lib/constants");
35
+ var import_pageInfo = require("$houdini/runtime/lib/pageInfo");
36
+ var import_pagination = require("$houdini/runtime/lib/pagination");
32
37
  var import_scalars = require("$houdini/runtime/lib/scalars");
33
38
  var import_types = require("$houdini/runtime/lib/types");
34
39
  var import_store = require("svelte/store");
35
40
  var import_adapter = require("../adapter");
41
+ var import_client = require("../client");
42
+ var import_session = require("../session");
36
43
  var import_base = require("./base");
37
44
  class FragmentStore {
38
45
  artifact;
@@ -81,7 +88,182 @@ Please ensure that you have passed a record that has ${this.artifact.name} mixed
81
88
  };
82
89
  }
83
90
  }
91
+ class BasePaginatedFragmentStore {
92
+ paginated = true;
93
+ paginationArtifact;
94
+ name;
95
+ kind = import_types.CompiledFragmentKind;
96
+ artifact;
97
+ constructor(config) {
98
+ this.paginationArtifact = config.paginationArtifact;
99
+ this.name = config.storeName;
100
+ this.artifact = config.artifact;
101
+ }
102
+ queryVariables(getState) {
103
+ const config = (0, import_config.getCurrentConfig)();
104
+ const { targetType } = this.paginationArtifact.refetch || {};
105
+ const typeConfig = config.types?.[targetType || ""];
106
+ if (!typeConfig) {
107
+ throw new Error(
108
+ `Missing type refetch configuration for ${targetType}. For more information, see ${import_constants.siteURL}/guides/pagination#paginated-fragments`
109
+ );
110
+ }
111
+ let idVariables = {};
112
+ const value = getState();
113
+ if (typeConfig.resolve?.arguments) {
114
+ idVariables = typeConfig.resolve.arguments?.(value) || {};
115
+ } else {
116
+ const keys = (0, import_config.keyFieldsForType)(config, targetType || "");
117
+ idVariables = Object.fromEntries(keys.map((key) => [key, value[key]]));
118
+ }
119
+ return {
120
+ ...idVariables
121
+ };
122
+ }
123
+ }
124
+ class FragmentStoreCursor extends BasePaginatedFragmentStore {
125
+ get(initialValue) {
126
+ const base = new FragmentStore({
127
+ artifact: this.artifact,
128
+ storeName: this.name
129
+ });
130
+ const store = base.get(initialValue);
131
+ const paginationStore = (0, import_client.getClient)().observe({
132
+ artifact: this.paginationArtifact,
133
+ initialValue: store.initialValue
134
+ });
135
+ const handlers = this.storeHandlers(
136
+ paginationStore,
137
+ initialValue,
138
+ () => (0, import_store.get)(store),
139
+ () => store.variables
140
+ );
141
+ const subscribe = (run, invalidate) => {
142
+ const combined = (0, import_store.derived)([store, paginationStore], ([$parent, $pagination]) => {
143
+ return {
144
+ ...$pagination,
145
+ data: $parent,
146
+ pageInfo: (0, import_pageInfo.extractPageInfo)($parent, this.paginationArtifact.refetch.path)
147
+ };
148
+ });
149
+ return combined.subscribe(run, invalidate);
150
+ };
151
+ return {
152
+ kind: import_types.CompiledFragmentKind,
153
+ subscribe,
154
+ fetch: handlers.fetch,
155
+ loadNextPage: handlers.loadNextPage,
156
+ loadPreviousPage: handlers.loadPreviousPage
157
+ };
158
+ }
159
+ storeHandlers(observer, initialValue, getState, getVariables) {
160
+ return (0, import_pagination.cursorHandlers)({
161
+ getState,
162
+ getVariables,
163
+ artifact: this.paginationArtifact,
164
+ fetchUpdate: async (args, updates) => {
165
+ await (0, import_client.initClient)();
166
+ return observer.send({
167
+ session: await (0, import_session.getSession)(),
168
+ ...args,
169
+ variables: {
170
+ ...args?.variables,
171
+ ...this.queryVariables(getState)
172
+ },
173
+ cacheParams: {
174
+ applyUpdates: updates,
175
+ disableSubscriptions: true
176
+ }
177
+ });
178
+ },
179
+ fetch: async (args) => {
180
+ await (0, import_client.initClient)();
181
+ return await observer.send({
182
+ session: await (0, import_session.getSession)(),
183
+ ...args,
184
+ variables: {
185
+ ...args?.variables,
186
+ ...this.queryVariables(getState)
187
+ },
188
+ cacheParams: {
189
+ disableSubscriptions: true
190
+ }
191
+ });
192
+ },
193
+ getSession: import_session.getSession
194
+ });
195
+ }
196
+ }
197
+ class FragmentStoreOffset extends BasePaginatedFragmentStore {
198
+ get(initialValue) {
199
+ const base = new FragmentStore({
200
+ artifact: this.artifact,
201
+ storeName: this.name
202
+ });
203
+ const store = base.get(initialValue);
204
+ const paginationStore = (0, import_client.getClient)().observe({
205
+ artifact: this.paginationArtifact,
206
+ initialValue: store.initialValue
207
+ });
208
+ const getState = () => (0, import_store.get)(store);
209
+ const handlers = (0, import_pagination.offsetHandlers)({
210
+ getState,
211
+ getVariables: () => store.variables,
212
+ artifact: this.paginationArtifact,
213
+ fetch: async (args) => {
214
+ await (0, import_client.initClient)();
215
+ return paginationStore.send({
216
+ ...args,
217
+ session: await (0, import_session.getSession)(),
218
+ variables: {
219
+ ...this.queryVariables(getState),
220
+ ...args?.variables
221
+ },
222
+ cacheParams: {
223
+ disableSubscriptions: true
224
+ }
225
+ });
226
+ },
227
+ fetchUpdate: async (args) => {
228
+ await (0, import_client.initClient)();
229
+ return paginationStore.send({
230
+ session: await (0, import_session.getSession)(),
231
+ ...args,
232
+ variables: {
233
+ ...this.queryVariables(getState),
234
+ ...args?.variables
235
+ },
236
+ cacheParams: {
237
+ disableSubscriptions: true,
238
+ applyUpdates: ["append"]
239
+ }
240
+ });
241
+ },
242
+ getSession: import_session.getSession,
243
+ storeName: this.name
244
+ });
245
+ const subscribe = (run, invalidate) => {
246
+ const combined = (0, import_store.derived)([store, paginationStore], ([$parent, $pagination]) => {
247
+ return {
248
+ ...$pagination,
249
+ data: $parent
250
+ };
251
+ });
252
+ return combined.subscribe(run, invalidate);
253
+ };
254
+ return {
255
+ kind: import_types.CompiledFragmentKind,
256
+ data: (0, import_store.derived)(paginationStore, ($value) => $value.data),
257
+ subscribe,
258
+ fetch: handlers.fetch,
259
+ loadNextPage: handlers.loadNextPage,
260
+ fetching: (0, import_store.derived)(paginationStore, ($store) => $store.fetching)
261
+ };
262
+ }
263
+ }
84
264
  // Annotate the CommonJS export names for ESM import in node:
85
265
  0 && (module.exports = {
86
- FragmentStore
266
+ FragmentStore,
267
+ FragmentStoreCursor,
268
+ FragmentStoreOffset
87
269
  });
@@ -1,5 +1,4 @@
1
- export * from './pagination';
2
- export { FragmentStore } from './fragment';
1
+ export { QueryStore, QueryStoreCursor, QueryStoreOffset } from './query';
2
+ export { FragmentStore, FragmentStoreCursor, FragmentStoreOffset } from './fragment';
3
3
  export { SubscriptionStore } from './subscription';
4
4
  export { MutationStore, type MutationConfig } from './mutation';
5
- export { QueryStore } from './query';
@@ -15,25 +15,31 @@ var __copyProps = (to, from, except, desc) => {
15
15
  }
16
16
  return to;
17
17
  };
18
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
19
  var stores_exports = {};
21
20
  __export(stores_exports, {
22
21
  FragmentStore: () => import_fragment.FragmentStore,
22
+ FragmentStoreCursor: () => import_fragment.FragmentStoreCursor,
23
+ FragmentStoreOffset: () => import_fragment.FragmentStoreOffset,
23
24
  MutationStore: () => import_mutation.MutationStore,
24
25
  QueryStore: () => import_query.QueryStore,
26
+ QueryStoreCursor: () => import_query.QueryStoreCursor,
27
+ QueryStoreOffset: () => import_query.QueryStoreOffset,
25
28
  SubscriptionStore: () => import_subscription.SubscriptionStore
26
29
  });
27
30
  module.exports = __toCommonJS(stores_exports);
28
- __reExport(stores_exports, require("./pagination"), module.exports);
31
+ var import_query = require("./query");
29
32
  var import_fragment = require("./fragment");
30
33
  var import_subscription = require("./subscription");
31
34
  var import_mutation = require("./mutation");
32
- var import_query = require("./query");
33
35
  // Annotate the CommonJS export names for ESM import in node:
34
36
  0 && (module.exports = {
35
37
  FragmentStore,
38
+ FragmentStoreCursor,
39
+ FragmentStoreOffset,
36
40
  MutationStore,
37
41
  QueryStore,
42
+ QueryStoreCursor,
43
+ QueryStoreOffset,
38
44
  SubscriptionStore
39
45
  });
@@ -21,6 +21,7 @@ __export(mutation_exports, {
21
21
  MutationStore: () => MutationStore
22
22
  });
23
23
  module.exports = __toCommonJS(mutation_exports);
24
+ var import_client = require("../client");
24
25
  var import_base = require("./base");
25
26
  var import_query = require("./query");
26
27
  class MutationStore extends import_base.BaseStore {
@@ -32,6 +33,7 @@ class MutationStore extends import_base.BaseStore {
32
33
  abortController,
33
34
  ...mutationConfig
34
35
  } = {}) {
36
+ await (0, import_client.initClient)();
35
37
  const { context } = await (0, import_query.fetchParams)(this.artifact, this.artifact.name, {
36
38
  fetch,
37
39
  metadata,