houdini-svelte 1.1.4-react.0 → 1.1.4

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 (46) hide show
  1. package/build/plugin-cjs/index.js +577 -565
  2. package/build/plugin-esm/index.js +577 -565
  3. package/build/preprocess-cjs/index.js +582 -581
  4. package/build/preprocess-esm/index.js +582 -581
  5. package/build/runtime/stores/index.d.ts +1 -1
  6. package/build/runtime/stores/pagination/cursor.d.ts +13 -0
  7. package/build/runtime/stores/pagination/fetch.d.ts +3 -0
  8. package/build/runtime/stores/pagination/fragment.d.ts +7 -4
  9. package/build/runtime/stores/pagination/offset.d.ts +20 -0
  10. package/build/runtime/stores/pagination/pageInfo.d.ts +13 -0
  11. package/build/runtime/stores/pagination/query.d.ts +4 -3
  12. package/build/runtime/stores/query.d.ts +54 -2
  13. package/build/runtime/types.d.ts +28 -40
  14. package/build/runtime-cjs/stores/index.d.ts +1 -1
  15. package/build/runtime-cjs/stores/pagination/cursor.d.ts +13 -0
  16. package/build/runtime-cjs/stores/pagination/cursor.js +191 -0
  17. package/build/runtime-cjs/stores/pagination/fetch.d.ts +3 -0
  18. package/build/runtime-cjs/stores/pagination/fetch.js +16 -0
  19. package/build/runtime-cjs/stores/pagination/fragment.d.ts +7 -4
  20. package/build/runtime-cjs/stores/pagination/fragment.js +9 -6
  21. package/build/runtime-cjs/stores/pagination/offset.d.ts +20 -0
  22. package/build/runtime-cjs/stores/pagination/offset.js +89 -0
  23. package/build/runtime-cjs/stores/pagination/pageInfo.d.ts +13 -0
  24. package/build/runtime-cjs/stores/pagination/pageInfo.js +79 -0
  25. package/build/runtime-cjs/stores/pagination/query.d.ts +4 -3
  26. package/build/runtime-cjs/stores/pagination/query.js +9 -10
  27. package/build/runtime-cjs/stores/query.d.ts +54 -2
  28. package/build/runtime-cjs/types.d.ts +28 -40
  29. package/build/runtime-esm/stores/index.d.ts +1 -1
  30. package/build/runtime-esm/stores/pagination/cursor.d.ts +13 -0
  31. package/build/runtime-esm/stores/pagination/cursor.js +167 -0
  32. package/build/runtime-esm/stores/pagination/fetch.d.ts +3 -0
  33. package/build/runtime-esm/stores/pagination/fetch.js +0 -0
  34. package/build/runtime-esm/stores/pagination/fragment.d.ts +7 -4
  35. package/build/runtime-esm/stores/pagination/fragment.js +7 -4
  36. package/build/runtime-esm/stores/pagination/offset.d.ts +20 -0
  37. package/build/runtime-esm/stores/pagination/offset.js +65 -0
  38. package/build/runtime-esm/stores/pagination/pageInfo.d.ts +13 -0
  39. package/build/runtime-esm/stores/pagination/pageInfo.js +52 -0
  40. package/build/runtime-esm/stores/pagination/query.d.ts +4 -3
  41. package/build/runtime-esm/stores/pagination/query.js +4 -5
  42. package/build/runtime-esm/stores/query.d.ts +54 -2
  43. package/build/runtime-esm/types.d.ts +28 -40
  44. package/build/test-cjs/index.js +1405 -1211
  45. package/build/test-esm/index.js +1405 -1211
  46. package/package.json +2 -2
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var offset_exports = {};
20
+ __export(offset_exports, {
21
+ offsetHandlers: () => offsetHandlers
22
+ });
23
+ module.exports = __toCommonJS(offset_exports);
24
+ var import_lib = require("$houdini/runtime/lib");
25
+ var import_deepEquals = require("$houdini/runtime/lib/deepEquals");
26
+ var import_session = require("../../session");
27
+ var import_query = require("../query");
28
+ var import_pageInfo = require("./pageInfo");
29
+ function offsetHandlers({
30
+ artifact,
31
+ storeName,
32
+ getState,
33
+ getVariables,
34
+ fetch: parentFetch,
35
+ fetchUpdate: parentFetchUpdate
36
+ }) {
37
+ let getOffset = () => artifact.refetch?.start || (0, import_pageInfo.countPage)(artifact.refetch.path, getState()) || artifact.refetch.pageSize;
38
+ let currentOffset = getOffset() ?? 0;
39
+ return {
40
+ loadNextPage: async ({
41
+ limit,
42
+ offset,
43
+ fetch,
44
+ metadata
45
+ } = {}) => {
46
+ const queryVariables = {
47
+ ...getVariables(),
48
+ offset: offset ?? getOffset()
49
+ };
50
+ if (limit || limit === 0) {
51
+ queryVariables.limit = limit;
52
+ }
53
+ if (!queryVariables.limit && !artifact.refetch.pageSize) {
54
+ throw (0, import_pageInfo.missingPageSizeError)("loadNextPage");
55
+ }
56
+ let isSinglePage = artifact.refetch?.mode === "SinglePage";
57
+ const targetFetch = isSinglePage ? parentFetch : parentFetchUpdate;
58
+ await targetFetch({
59
+ variables: queryVariables,
60
+ fetch,
61
+ metadata,
62
+ policy: isSinglePage ? artifact.policy : import_lib.CachePolicy.NetworkOnly,
63
+ session: await (0, import_session.getSession)()
64
+ });
65
+ const pageSize = queryVariables.limit || artifact.refetch.pageSize;
66
+ currentOffset = offset + pageSize;
67
+ },
68
+ async fetch(args) {
69
+ const { params } = await (0, import_query.fetchParams)(artifact, storeName, args);
70
+ const { variables } = params ?? {};
71
+ if (variables && !(0, import_deepEquals.deepEquals)(getVariables(), variables)) {
72
+ return parentFetch.call(this, params);
73
+ }
74
+ const count = currentOffset || getOffset();
75
+ const queryVariables = {};
76
+ if (!artifact.refetch.pageSize || count > artifact.refetch.pageSize) {
77
+ queryVariables.limit = count;
78
+ }
79
+ return await parentFetch.call(this, {
80
+ ...params,
81
+ variables: queryVariables
82
+ });
83
+ }
84
+ };
85
+ }
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ offsetHandlers
89
+ });
@@ -0,0 +1,13 @@
1
+ import type { GraphQLObject } from '$houdini/runtime/lib/types';
2
+ export declare function nullPageInfo(): PageInfo;
3
+ export type PageInfo = {
4
+ startCursor: string | null;
5
+ endCursor: string | null;
6
+ hasNextPage: boolean;
7
+ hasPreviousPage: boolean;
8
+ };
9
+ export declare function missingPageSizeError(fnName: string): {
10
+ message: string;
11
+ };
12
+ export declare function extractPageInfo(data: any, path: string[]): PageInfo;
13
+ export declare function countPage<_Data extends GraphQLObject>(source: string[], value: _Data | null): number;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var pageInfo_exports = {};
20
+ __export(pageInfo_exports, {
21
+ countPage: () => countPage,
22
+ extractPageInfo: () => extractPageInfo,
23
+ missingPageSizeError: () => missingPageSizeError,
24
+ nullPageInfo: () => nullPageInfo
25
+ });
26
+ module.exports = __toCommonJS(pageInfo_exports);
27
+ var import_constants = require("$houdini/runtime/lib/constants");
28
+ function nullPageInfo() {
29
+ return { startCursor: null, endCursor: null, hasNextPage: false, hasPreviousPage: false };
30
+ }
31
+ function missingPageSizeError(fnName) {
32
+ return {
33
+ message: `${fnName} is missing the required page arguments. For more information, please visit this link: ${import_constants.siteURL}/guides/pagination`
34
+ };
35
+ }
36
+ function extractPageInfo(data, path) {
37
+ if (!data) {
38
+ return {
39
+ startCursor: null,
40
+ endCursor: null,
41
+ hasNextPage: false,
42
+ hasPreviousPage: false
43
+ };
44
+ }
45
+ let localPath = [...path];
46
+ let current = data;
47
+ while (localPath.length > 0) {
48
+ if (!current) {
49
+ break;
50
+ }
51
+ current = current[localPath.shift()];
52
+ }
53
+ return current?.pageInfo ?? nullPageInfo();
54
+ }
55
+ function countPage(source, value) {
56
+ let data = value;
57
+ if (value === null || data === null || data === void 0) {
58
+ return 0;
59
+ }
60
+ for (const field of source) {
61
+ const obj = data[field];
62
+ if (obj && !Array.isArray(obj)) {
63
+ data = obj;
64
+ } else if (!data) {
65
+ throw new Error("Could not count page size");
66
+ }
67
+ if (Array.isArray(obj)) {
68
+ return obj.length;
69
+ }
70
+ }
71
+ return 0;
72
+ }
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ countPage,
76
+ extractPageInfo,
77
+ missingPageSizeError,
78
+ nullPageInfo
79
+ });
@@ -1,8 +1,9 @@
1
- import type { GraphQLObject, QueryArtifact, QueryResult, CursorHandlers, OffsetHandlers, PageInfo } from '$houdini/runtime/lib/types';
1
+ import type { GraphQLObject, QueryArtifact, QueryResult } from '$houdini/runtime/lib/types';
2
2
  import type { Subscriber } from 'svelte/store';
3
- import type { ClientFetchParams, LoadEventFetchParams, QueryStoreFetchParams, RequestEventFetchParams } from '../../types';
4
- import { StoreConfig } from '../query';
3
+ import type { CursorHandlers, OffsetHandlers } from '../../types';
4
+ import type { ClientFetchParams, LoadEventFetchParams, QueryStoreFetchParams, RequestEventFetchParams, StoreConfig } from '../query';
5
5
  import { QueryStore } from '../query';
6
+ import { type PageInfo } from './pageInfo';
6
7
  export type CursorStoreResult<_Data extends GraphQLObject, _Input extends {}> = QueryResult<_Data, _Input> & {
7
8
  pageInfo: PageInfo;
8
9
  };
@@ -22,13 +22,13 @@ __export(query_exports, {
22
22
  QueryStoreOffset: () => QueryStoreOffset
23
23
  });
24
24
  module.exports = __toCommonJS(query_exports);
25
- var import_pageInfo = require("$houdini/runtime/lib/pageInfo");
26
- var import_pagination = require("$houdini/runtime/lib/pagination");
27
25
  var import_store = require("svelte/store");
28
26
  var import_client = require("../../client");
29
- var import_session = require("../../session");
30
- var import_query2 = require("../query");
31
- class QueryStoreCursor extends import_query2.QueryStore {
27
+ var import_query = require("../query");
28
+ var import_cursor = require("./cursor");
29
+ var import_offset = require("./offset");
30
+ var import_pageInfo = require("./pageInfo");
31
+ class QueryStoreCursor extends import_query.QueryStore {
32
32
  paginated = true;
33
33
  constructor(config) {
34
34
  super(config);
@@ -42,13 +42,13 @@ class QueryStoreCursor extends import_query2.QueryStore {
42
42
  const paginationObserver = (0, import_client.getClient)().observe({
43
43
  artifact: this.artifact
44
44
  });
45
- this.#_handlers = (0, import_pagination.cursorHandlers)({
45
+ this.#_handlers = (0, import_cursor.cursorHandlers)({
46
46
  artifact: this.artifact,
47
+ initialValue: (0, import_store.get)(this.observer).data,
47
48
  getState: () => (0, import_store.get)(this.observer).data,
48
49
  getVariables: () => (0, import_store.get)(this.observer).variables,
49
50
  storeName: this.name,
50
51
  fetch: super.fetch.bind(this),
51
- getSession: import_session.getSession,
52
52
  fetchUpdate: async (args, updates) => {
53
53
  return paginationObserver.send({
54
54
  ...args,
@@ -84,7 +84,7 @@ class QueryStoreCursor extends import_query2.QueryStore {
84
84
  return combined.subscribe(run, invalidate);
85
85
  }
86
86
  }
87
- class QueryStoreOffset extends import_query2.QueryStore {
87
+ class QueryStoreOffset extends import_query.QueryStore {
88
88
  paginated = true;
89
89
  async loadNextPage(args) {
90
90
  const handlers = await this.#handlers();
@@ -103,13 +103,12 @@ class QueryStoreOffset extends import_query2.QueryStore {
103
103
  const paginationObserver = (0, import_client.getClient)().observe({
104
104
  artifact: this.artifact
105
105
  });
106
- this.#_handlers = (0, import_pagination.offsetHandlers)({
106
+ this.#_handlers = (0, import_offset.offsetHandlers)({
107
107
  artifact: this.artifact,
108
108
  storeName: this.name,
109
109
  fetch: super.fetch,
110
110
  getState: () => (0, import_store.get)(this.observer).data,
111
111
  getVariables: () => (0, import_store.get)(this.observer).variables,
112
- getSession: import_session.getSession,
113
112
  fetchUpdate: async (args) => {
114
113
  await (0, import_client.initClient)();
115
114
  return paginationObserver.send({
@@ -1,7 +1,7 @@
1
1
  import type { FetchContext } from '$houdini/runtime/client/plugins/fetch';
2
- import type { GraphQLObject, MutationArtifact, QueryArtifact, QueryResult, CachePolicies } from '$houdini/runtime/lib/types';
2
+ import type { GraphQLObject, HoudiniFetchContext, MutationArtifact, QueryArtifact, QueryResult, CachePolicies } from '$houdini/runtime/lib/types';
3
+ import type { LoadEvent, RequestEvent } from '@sveltejs/kit';
3
4
  import type { PluginArtifactData } from '../../plugin/artifactData';
4
- import type { ClientFetchParams, LoadEventFetchParams, QueryStoreFetchParams, RequestEventFetchParams } from '../types';
5
5
  import { BaseStore } from './base';
6
6
  export declare class QueryStore<_Data extends GraphQLObject, _Input extends {}> extends BaseStore<_Data, _Input, QueryArtifact> {
7
7
  variables: boolean;
@@ -31,3 +31,55 @@ export declare function fetchParams<_Data extends GraphQLObject, _Input>(artifac
31
31
  policy: CachePolicies | undefined;
32
32
  params: QueryStoreFetchParams<_Data, _Input>;
33
33
  }>;
34
+ type FetchGlobalParams<_Data extends GraphQLObject, _Input> = {
35
+ variables?: _Input;
36
+ /**
37
+ * The policy to use when performing the fetch. If set to CachePolicy.NetworkOnly,
38
+ * a request will always be sent, even if the variables are the same as the last call
39
+ * to fetch.
40
+ */
41
+ policy?: CachePolicies;
42
+ /**
43
+ * An object that will be passed to the fetch function.
44
+ * You can do what you want with it!
45
+ */
46
+ metadata?: App.Metadata;
47
+ /**
48
+ * Set to true if you want the promise to pause while it's resolving.
49
+ * Only enable this if you know what you are doing. This will cause route
50
+ * transitions to pause while loading data.
51
+ */
52
+ blocking?: boolean;
53
+ /**
54
+ * A function to call after the fetch happens (whether fake or not)
55
+ */
56
+ then?: (val: _Data | null) => void | Promise<void>;
57
+ };
58
+ export type LoadEventFetchParams<_Data extends GraphQLObject, _Input> = FetchGlobalParams<_Data, _Input> & {
59
+ /**
60
+ * Directly the `even` param coming from the `load` function
61
+ */
62
+ event?: LoadEvent;
63
+ };
64
+ export type RequestEventFetchParams<_Data extends GraphQLObject, _Input> = FetchGlobalParams<_Data, _Input> & {
65
+ /**
66
+ * A RequestEvent should be provided when the store is being used in an endpoint.
67
+ * When this happens, fetch also needs to be provided
68
+ */
69
+ event?: RequestEvent;
70
+ /**
71
+ * The fetch function to use when using this store in an endpoint.
72
+ */
73
+ fetch?: LoadEvent['fetch'];
74
+ };
75
+ export type ClientFetchParams<_Data extends GraphQLObject, _Input> = FetchGlobalParams<_Data, _Input> & {
76
+ /**
77
+ * An object containing all of the current info necessary for a
78
+ * client-side fetch. Must be called in component initialization with
79
+ * something like this: `const context = getHoudiniFetchContext()`
80
+ */
81
+ context?: HoudiniFetchContext;
82
+ };
83
+ export type QueryStoreFetchParams<_Data extends GraphQLObject, _Input> = QueryStoreLoadParams<_Data, _Input> | ClientFetchParams<_Data, _Input>;
84
+ export type QueryStoreLoadParams<_Data extends GraphQLObject, _Input> = LoadEventFetchParams<_Data, _Input> | RequestEventFetchParams<_Data, _Input>;
85
+ export {};
@@ -1,6 +1,8 @@
1
- import type { FetchQueryResult, CompiledFragmentKind, QueryResult, GraphQLObject, CursorHandlers, OffsetHandlers, PageInfo, HoudiniFetchContext, FetchParams } from '$houdini/runtime/lib/types';
2
- import type { LoadEvent, RequestEvent } from '@sveltejs/kit';
3
- import type { Readable } from 'svelte/store';
1
+ import type { FetchQueryResult, CompiledFragmentKind, QueryResult, GraphQLObject } from '$houdini/runtime/lib/types';
2
+ import type { LoadEvent } from '@sveltejs/kit';
3
+ import type { Readable, Writable } from 'svelte/store';
4
+ import type { QueryStoreFetchParams } from './stores';
5
+ import type { PageInfo } from './stores/pagination/pageInfo';
4
6
  export type QueryInputs<_Data> = FetchQueryResult<_Data> & {
5
7
  variables: {
6
8
  [key: string]: any;
@@ -52,43 +54,29 @@ export type OffsetFragmentStoreInstance<_Data extends GraphQLObject, _Input> = {
52
54
  subscribe: Readable<Reshape<_Data, _Input>>['subscribe'];
53
55
  fetching: Readable<boolean>;
54
56
  } & OffsetHandlers<_Data, _Input>;
55
- type FetchGlobalParams<_Data extends GraphQLObject, _Input> = FetchParams<_Input> & {
56
- /**
57
- * Set to true if you want the promise to pause while it's resolving.
58
- * Only enable this if you know what you are doing. This will cause route
59
- * transitions to pause while loading data.
60
- */
61
- blocking?: boolean;
62
- /**
63
- * A function to call after the fetch happens (whether fake or not)
64
- */
65
- then?: (val: _Data | null) => void | Promise<void>;
57
+ export type CursorHandlers<_Data extends GraphQLObject, _Input> = {
58
+ loadNextPage: (args?: {
59
+ first?: number;
60
+ after?: string;
61
+ fetch?: typeof globalThis.fetch;
62
+ metadata?: {};
63
+ }) => Promise<void>;
64
+ loadPreviousPage: (args?: {
65
+ last?: number;
66
+ before?: string;
67
+ fetch?: typeof globalThis.fetch;
68
+ metadata?: {};
69
+ }) => Promise<void>;
70
+ pageInfo: Writable<PageInfo>;
71
+ fetch(args?: QueryStoreFetchParams<_Data, _Input> | undefined): Promise<QueryResult<_Data, _Input>>;
66
72
  };
67
- export type LoadEventFetchParams<_Data extends GraphQLObject, _Input> = FetchGlobalParams<_Data, _Input> & {
68
- /**
69
- * Directly the `even` param coming from the `load` function
70
- */
71
- event?: LoadEvent;
73
+ export type OffsetHandlers<_Data extends GraphQLObject, _Input> = {
74
+ loadNextPage: (args?: {
75
+ limit?: number;
76
+ offset?: number;
77
+ metadata?: {};
78
+ fetch?: typeof globalThis.fetch;
79
+ }) => Promise<void>;
80
+ fetch(args?: QueryStoreFetchParams<_Data, _Input> | undefined): Promise<QueryResult<_Data, _Input>>;
72
81
  };
73
- export type RequestEventFetchParams<_Data extends GraphQLObject, _Input> = FetchGlobalParams<_Data, _Input> & {
74
- /**
75
- * A RequestEvent should be provided when the store is being used in an endpoint.
76
- * When this happens, fetch also needs to be provided
77
- */
78
- event?: RequestEvent;
79
- /**
80
- * The fetch function to use when using this store in an endpoint.
81
- */
82
- fetch?: LoadEvent['fetch'];
83
- };
84
- export type ClientFetchParams<_Data extends GraphQLObject, _Input> = FetchGlobalParams<_Data, _Input> & {
85
- /**
86
- * An object containing all of the current info necessary for a
87
- * client-side fetch. Must be called in component initialization with
88
- * something like this: `const context = getHoudiniFetchContext()`
89
- */
90
- context?: HoudiniFetchContext;
91
- };
92
- export type QueryStoreFetchParams<_Data extends GraphQLObject, _Input> = QueryStoreLoadParams<_Data, _Input> | ClientFetchParams<_Data, _Input>;
93
- export type QueryStoreLoadParams<_Data extends GraphQLObject, _Input> = LoadEventFetchParams<_Data, _Input> | RequestEventFetchParams<_Data, _Input>;
94
82
  export {};
@@ -2,4 +2,4 @@ export * from './pagination';
2
2
  export { FragmentStore } from './fragment';
3
3
  export { SubscriptionStore } from './subscription';
4
4
  export { MutationStore, type MutationConfig } from './mutation';
5
- export { QueryStore } from './query';
5
+ export { QueryStore, type QueryStoreFetchParams } from './query';
@@ -0,0 +1,13 @@
1
+ import type { SendParams } from '$houdini/runtime/client/documentStore';
2
+ import type { GraphQLObject, QueryArtifact } from '$houdini/runtime/lib/types';
3
+ import type { CursorHandlers } from '../../types';
4
+ import type { FetchFn } from './fetch';
5
+ export declare function cursorHandlers<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, storeName, initialValue, fetchUpdate: parentFetchUpdate, fetch: parentFetch, getState, getVariables, }: {
6
+ artifact: QueryArtifact;
7
+ storeName: string;
8
+ fetch: FetchFn<_Data, _Input>;
9
+ getState: () => _Data | null;
10
+ getVariables: () => _Input;
11
+ initialValue: _Data | null;
12
+ fetchUpdate: (arg: SendParams, updates: string[]) => ReturnType<FetchFn<_Data, _Input>>;
13
+ }): CursorHandlers<_Data, _Input>;
@@ -0,0 +1,167 @@
1
+ import { CachePolicy } from "$houdini/runtime/lib";
2
+ import { getCurrentConfig } from "$houdini/runtime/lib/config";
3
+ import { siteURL } from "$houdini/runtime/lib/constants";
4
+ import { deepEquals } from "$houdini/runtime/lib/deepEquals";
5
+ import { writable } from "svelte/store";
6
+ import { getSession } from "../../session";
7
+ import { fetchParams } from "../query";
8
+ import { countPage, extractPageInfo, missingPageSizeError } from "./pageInfo";
9
+ function cursorHandlers({
10
+ artifact,
11
+ storeName,
12
+ initialValue,
13
+ fetchUpdate: parentFetchUpdate,
14
+ fetch: parentFetch,
15
+ getState,
16
+ getVariables
17
+ }) {
18
+ const pageInfo = writable(extractPageInfo(initialValue, artifact.refetch.path));
19
+ const loadPage = async ({
20
+ pageSizeVar,
21
+ input,
22
+ functionName,
23
+ metadata = {},
24
+ fetch,
25
+ where
26
+ }) => {
27
+ const config = getCurrentConfig();
28
+ const loadVariables = {
29
+ ...getVariables(),
30
+ ...input
31
+ };
32
+ if (!loadVariables[pageSizeVar] && !artifact.refetch.pageSize) {
33
+ throw missingPageSizeError(functionName);
34
+ }
35
+ let isSinglePage = artifact.refetch?.mode === "SinglePage";
36
+ const targetFetch = isSinglePage ? parentFetch : parentFetchUpdate;
37
+ const { data } = await targetFetch(
38
+ {
39
+ variables: loadVariables,
40
+ fetch,
41
+ metadata,
42
+ policy: isSinglePage ? artifact.policy : CachePolicy.NetworkOnly,
43
+ session: await getSession()
44
+ },
45
+ isSinglePage ? [] : [where === "start" ? "prepend" : "append"]
46
+ );
47
+ const resultPath = [...artifact.refetch.path];
48
+ if (artifact.refetch.embedded) {
49
+ const { targetType } = artifact.refetch;
50
+ if (!config.types?.[targetType]?.resolve) {
51
+ throw new Error(
52
+ `Missing type resolve configuration for ${targetType}. For more information, see ${siteURL}/guides/pagination#paginated-fragments`
53
+ );
54
+ }
55
+ resultPath.unshift(config.types[targetType].resolve.queryField);
56
+ }
57
+ pageInfo.set(extractPageInfo(data, resultPath));
58
+ };
59
+ const getPageInfo = () => {
60
+ return extractPageInfo(getState(), artifact.refetch?.path ?? []);
61
+ };
62
+ return {
63
+ loadNextPage: async ({
64
+ first,
65
+ after,
66
+ fetch,
67
+ metadata
68
+ } = {}) => {
69
+ if (artifact.refetch?.direction === "backward") {
70
+ console.warn(`\u26A0\uFE0F ${storeName}.loadNextPage was called but it does not support forwards pagination.
71
+ If you think this is an error, please open an issue on GitHub`);
72
+ return;
73
+ }
74
+ const currentPageInfo = getPageInfo();
75
+ if (!currentPageInfo.hasNextPage) {
76
+ return;
77
+ }
78
+ const input = {
79
+ first: first ?? artifact.refetch.pageSize,
80
+ after: after ?? currentPageInfo.endCursor,
81
+ before: null,
82
+ last: null
83
+ };
84
+ return await loadPage({
85
+ pageSizeVar: "first",
86
+ functionName: "loadNextPage",
87
+ input,
88
+ fetch,
89
+ metadata,
90
+ where: "end"
91
+ });
92
+ },
93
+ loadPreviousPage: async ({
94
+ last,
95
+ before,
96
+ fetch,
97
+ metadata
98
+ } = {}) => {
99
+ if (artifact.refetch?.direction === "forward") {
100
+ console.warn(`\u26A0\uFE0F ${storeName}.loadPreviousPage was called but it does not support backwards pagination.
101
+ If you think this is an error, please open an issue on GitHub`);
102
+ return;
103
+ }
104
+ const currentPageInfo = getPageInfo();
105
+ if (!currentPageInfo.hasPreviousPage) {
106
+ return;
107
+ }
108
+ const input = {
109
+ before: before ?? currentPageInfo.startCursor,
110
+ last: last ?? artifact.refetch.pageSize,
111
+ first: null,
112
+ after: null
113
+ };
114
+ return await loadPage({
115
+ pageSizeVar: "last",
116
+ functionName: "loadPreviousPage",
117
+ input,
118
+ fetch,
119
+ metadata,
120
+ where: "start"
121
+ });
122
+ },
123
+ pageInfo,
124
+ async fetch(args) {
125
+ const { params } = await fetchParams(artifact, storeName, args);
126
+ const { variables } = params ?? {};
127
+ if (variables && !deepEquals(getVariables(), variables)) {
128
+ return await parentFetch(params);
129
+ }
130
+ try {
131
+ var currentPageInfo = extractPageInfo(getState(), artifact.refetch.path);
132
+ } catch {
133
+ return await parentFetch(params);
134
+ }
135
+ const queryVariables = {};
136
+ const count = countPage(artifact.refetch.path.concat("edges"), getState()) || artifact.refetch.pageSize;
137
+ if (count && count > artifact.refetch.pageSize) {
138
+ if (currentPageInfo.hasPreviousPage && currentPageInfo.hasNextPage && !(variables?.["first"] && variables?.["after"] || variables?.["last"] && variables?.["before"])) {
139
+ console.warn(`\u26A0\uFE0F Encountered a fetch() in the middle of the connection.
140
+ Make sure to pass a cursor value by hand that includes the current set (ie the entry before startCursor)
141
+ `);
142
+ }
143
+ if (!currentPageInfo.hasPreviousPage) {
144
+ queryVariables["first"] = count;
145
+ queryVariables["after"] = null;
146
+ queryVariables["last"] = null;
147
+ queryVariables["before"] = null;
148
+ } else if (!currentPageInfo.hasNextPage) {
149
+ queryVariables["last"] = count;
150
+ queryVariables["first"] = null;
151
+ queryVariables["after"] = null;
152
+ queryVariables["before"] = null;
153
+ }
154
+ }
155
+ Object.assign(queryVariables, variables ?? {});
156
+ const result = await parentFetch({
157
+ ...params,
158
+ variables: queryVariables
159
+ });
160
+ pageInfo.set(extractPageInfo(result.data, artifact.refetch.path));
161
+ return result;
162
+ }
163
+ };
164
+ }
165
+ export {
166
+ cursorHandlers
167
+ };
@@ -0,0 +1,3 @@
1
+ import type { GraphQLObject, QueryResult } from '$houdini/runtime/lib/types';
2
+ import type { QueryStoreFetchParams } from '../query';
3
+ export type FetchFn<_Data extends GraphQLObject, _Input = any> = (params?: QueryStoreFetchParams<_Data, _Input>) => Promise<QueryResult<_Data, _Input>>;
File without changes
@@ -1,9 +1,9 @@
1
1
  import type { DocumentStore } from '$houdini/runtime/client';
2
- import type { FragmentArtifact, GraphQLObject, HoudiniFetchContext, QueryArtifact, PageInfo } from '$houdini/runtime/lib/types';
3
- import { CursorHandlers } from '$houdini/runtime/lib/types';
2
+ import type { FragmentArtifact, GraphQLObject, HoudiniFetchContext, QueryArtifact } from '$houdini/runtime/lib/types';
4
3
  import type { Readable, Subscriber } from 'svelte/store';
5
- import type { OffsetFragmentStoreInstance } from '../../types';
4
+ import type { CursorHandlers, OffsetFragmentStoreInstance } from '../../types';
6
5
  import type { StoreConfig } from '../query';
6
+ import { type PageInfo } from './pageInfo';
7
7
  type FragmentStoreConfig<_Data extends GraphQLObject, _Input> = StoreConfig<_Data, _Input, FragmentArtifact> & {
8
8
  paginationArtifact: QueryArtifact;
9
9
  };
@@ -19,12 +19,15 @@ declare class BasePaginatedFragmentStore<_Data extends GraphQLObject, _Input> {
19
19
  export declare class FragmentStoreCursor<_Data extends GraphQLObject, _Input extends Record<string, any>> extends BasePaginatedFragmentStore<_Data, _Input> {
20
20
  get(initialValue: _Data | null): {
21
21
  kind: "HoudiniFragment";
22
+ data: Readable<_Data | null>;
22
23
  subscribe: (run: Subscriber<FragmentPaginatedResult<_Data, {
23
24
  pageInfo: PageInfo;
24
25
  }>>, invalidate?: ((value?: FragmentPaginatedResult<_Data, {
25
26
  pageInfo: PageInfo;
26
27
  }> | undefined) => void) | undefined) => (() => void);
27
- fetch: (args?: import("$houdini/runtime/lib/types").FetchParams<_Input> | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
28
+ fetching: Readable<boolean>;
29
+ fetch: (args?: import("../query").QueryStoreFetchParams<_Data, _Input> | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
30
+ pageInfo: import("svelte/store").Writable<PageInfo>;
28
31
  loadNextPage: (args?: {
29
32
  first?: number | undefined;
30
33
  after?: string | undefined;
@@ -1,12 +1,13 @@
1
1
  import { getCurrentConfig, keyFieldsForType } from "$houdini/runtime/lib/config";
2
2
  import { siteURL } from "$houdini/runtime/lib/constants";
3
- import { extractPageInfo } from "$houdini/runtime/lib/pageInfo";
4
- import { cursorHandlers, offsetHandlers } from "$houdini/runtime/lib/pagination";
5
3
  import { CompiledFragmentKind } from "$houdini/runtime/lib/types";
6
4
  import { derived, get } from "svelte/store";
7
5
  import { getClient, initClient } from "../../client";
8
6
  import { getSession } from "../../session";
9
7
  import { FragmentStore } from "../fragment";
8
+ import { cursorHandlers } from "./cursor";
9
+ import { offsetHandlers } from "./offset";
10
+ import { extractPageInfo } from "./pageInfo";
10
11
  class BasePaginatedFragmentStore {
11
12
  paginated = true;
12
13
  paginationArtifact;
@@ -69,8 +70,11 @@ class FragmentStoreCursor extends BasePaginatedFragmentStore {
69
70
  };
70
71
  return {
71
72
  kind: CompiledFragmentKind,
73
+ data: derived(store, ($value) => $value),
72
74
  subscribe,
75
+ fetching: derived([paginationStore], ([$store]) => $store.fetching),
73
76
  fetch: handlers.fetch,
77
+ pageInfo: handlers.pageInfo,
74
78
  loadNextPage: handlers.loadNextPage,
75
79
  loadPreviousPage: handlers.loadPreviousPage
76
80
  };
@@ -109,7 +113,7 @@ class FragmentStoreCursor extends BasePaginatedFragmentStore {
109
113
  }
110
114
  });
111
115
  },
112
- getSession,
116
+ initialValue,
113
117
  storeName: this.name
114
118
  });
115
119
  }
@@ -158,7 +162,6 @@ class FragmentStoreOffset extends BasePaginatedFragmentStore {
158
162
  }
159
163
  });
160
164
  },
161
- getSession,
162
165
  storeName: this.name
163
166
  });
164
167
  const subscribe = (run, invalidate) => {