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.
- package/build/plugin-cjs/index.js +577 -565
- package/build/plugin-esm/index.js +577 -565
- package/build/preprocess-cjs/index.js +582 -581
- package/build/preprocess-esm/index.js +582 -581
- package/build/runtime/stores/index.d.ts +1 -1
- package/build/runtime/stores/pagination/cursor.d.ts +13 -0
- package/build/runtime/stores/pagination/fetch.d.ts +3 -0
- package/build/runtime/stores/pagination/fragment.d.ts +7 -4
- package/build/runtime/stores/pagination/offset.d.ts +20 -0
- package/build/runtime/stores/pagination/pageInfo.d.ts +13 -0
- package/build/runtime/stores/pagination/query.d.ts +4 -3
- package/build/runtime/stores/query.d.ts +54 -2
- package/build/runtime/types.d.ts +28 -40
- package/build/runtime-cjs/stores/index.d.ts +1 -1
- package/build/runtime-cjs/stores/pagination/cursor.d.ts +13 -0
- package/build/runtime-cjs/stores/pagination/cursor.js +191 -0
- package/build/runtime-cjs/stores/pagination/fetch.d.ts +3 -0
- package/build/runtime-cjs/stores/pagination/fetch.js +16 -0
- package/build/runtime-cjs/stores/pagination/fragment.d.ts +7 -4
- package/build/runtime-cjs/stores/pagination/fragment.js +9 -6
- package/build/runtime-cjs/stores/pagination/offset.d.ts +20 -0
- package/build/runtime-cjs/stores/pagination/offset.js +89 -0
- package/build/runtime-cjs/stores/pagination/pageInfo.d.ts +13 -0
- package/build/runtime-cjs/stores/pagination/pageInfo.js +79 -0
- package/build/runtime-cjs/stores/pagination/query.d.ts +4 -3
- package/build/runtime-cjs/stores/pagination/query.js +9 -10
- package/build/runtime-cjs/stores/query.d.ts +54 -2
- package/build/runtime-cjs/types.d.ts +28 -40
- package/build/runtime-esm/stores/index.d.ts +1 -1
- package/build/runtime-esm/stores/pagination/cursor.d.ts +13 -0
- package/build/runtime-esm/stores/pagination/cursor.js +167 -0
- package/build/runtime-esm/stores/pagination/fetch.d.ts +3 -0
- package/build/runtime-esm/stores/pagination/fetch.js +0 -0
- package/build/runtime-esm/stores/pagination/fragment.d.ts +7 -4
- package/build/runtime-esm/stores/pagination/fragment.js +7 -4
- package/build/runtime-esm/stores/pagination/offset.d.ts +20 -0
- package/build/runtime-esm/stores/pagination/offset.js +65 -0
- package/build/runtime-esm/stores/pagination/pageInfo.d.ts +13 -0
- package/build/runtime-esm/stores/pagination/pageInfo.js +52 -0
- package/build/runtime-esm/stores/pagination/query.d.ts +4 -3
- package/build/runtime-esm/stores/pagination/query.js +4 -5
- package/build/runtime-esm/stores/query.d.ts +54 -2
- package/build/runtime-esm/types.d.ts +28 -40
- package/build/test-cjs/index.js +1405 -1211
- package/build/test-esm/index.js +1405 -1211
- package/package.json +2 -2
|
@@ -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,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>>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { DocumentStore } from '$houdini/runtime/client';
|
|
2
|
-
import type { FragmentArtifact, GraphQLObject, HoudiniFetchContext, QueryArtifact
|
|
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
|
-
|
|
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;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SendParams } from '$houdini/runtime/client/documentStore';
|
|
2
|
+
import type { GraphQLObject, QueryArtifact, QueryResult } from '$houdini/runtime/lib/types';
|
|
3
|
+
import type { QueryStoreFetchParams } from '../query';
|
|
4
|
+
import type { FetchFn } from './fetch';
|
|
5
|
+
export declare function offsetHandlers<_Data extends GraphQLObject, _Input extends {}>({ artifact, storeName, getState, getVariables, fetch: parentFetch, fetchUpdate: parentFetchUpdate, }: {
|
|
6
|
+
artifact: QueryArtifact;
|
|
7
|
+
fetch: FetchFn<_Data, _Input>;
|
|
8
|
+
fetchUpdate: (arg: SendParams) => ReturnType<FetchFn<_Data, _Input>>;
|
|
9
|
+
storeName: string;
|
|
10
|
+
getState: () => _Data | null;
|
|
11
|
+
getVariables: () => _Input;
|
|
12
|
+
}): {
|
|
13
|
+
loadNextPage: ({ limit, offset, fetch, metadata, }?: {
|
|
14
|
+
limit?: number | undefined;
|
|
15
|
+
offset?: number | undefined;
|
|
16
|
+
fetch?: typeof fetch | undefined;
|
|
17
|
+
metadata?: {} | undefined;
|
|
18
|
+
}) => Promise<void>;
|
|
19
|
+
fetch(args?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
20
|
+
};
|
|
@@ -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;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { GraphQLObject, QueryArtifact, QueryResult
|
|
1
|
+
import type { GraphQLObject, QueryArtifact, QueryResult } from '$houdini/runtime/lib/types';
|
|
2
2
|
import type { Subscriber } from 'svelte/store';
|
|
3
|
-
import type {
|
|
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
|
};
|
|
@@ -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 {};
|
package/build/runtime/types.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { FetchQueryResult, CompiledFragmentKind, QueryResult, GraphQLObject
|
|
2
|
-
import type { LoadEvent
|
|
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
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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,191 @@
|
|
|
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 cursor_exports = {};
|
|
20
|
+
__export(cursor_exports, {
|
|
21
|
+
cursorHandlers: () => cursorHandlers
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(cursor_exports);
|
|
24
|
+
var import_lib = require("$houdini/runtime/lib");
|
|
25
|
+
var import_config = require("$houdini/runtime/lib/config");
|
|
26
|
+
var import_constants = require("$houdini/runtime/lib/constants");
|
|
27
|
+
var import_deepEquals = require("$houdini/runtime/lib/deepEquals");
|
|
28
|
+
var import_store = require("svelte/store");
|
|
29
|
+
var import_session = require("../../session");
|
|
30
|
+
var import_query = require("../query");
|
|
31
|
+
var import_pageInfo = require("./pageInfo");
|
|
32
|
+
function cursorHandlers({
|
|
33
|
+
artifact,
|
|
34
|
+
storeName,
|
|
35
|
+
initialValue,
|
|
36
|
+
fetchUpdate: parentFetchUpdate,
|
|
37
|
+
fetch: parentFetch,
|
|
38
|
+
getState,
|
|
39
|
+
getVariables
|
|
40
|
+
}) {
|
|
41
|
+
const pageInfo = (0, import_store.writable)((0, import_pageInfo.extractPageInfo)(initialValue, artifact.refetch.path));
|
|
42
|
+
const loadPage = async ({
|
|
43
|
+
pageSizeVar,
|
|
44
|
+
input,
|
|
45
|
+
functionName,
|
|
46
|
+
metadata = {},
|
|
47
|
+
fetch,
|
|
48
|
+
where
|
|
49
|
+
}) => {
|
|
50
|
+
const config = (0, import_config.getCurrentConfig)();
|
|
51
|
+
const loadVariables = {
|
|
52
|
+
...getVariables(),
|
|
53
|
+
...input
|
|
54
|
+
};
|
|
55
|
+
if (!loadVariables[pageSizeVar] && !artifact.refetch.pageSize) {
|
|
56
|
+
throw (0, import_pageInfo.missingPageSizeError)(functionName);
|
|
57
|
+
}
|
|
58
|
+
let isSinglePage = artifact.refetch?.mode === "SinglePage";
|
|
59
|
+
const targetFetch = isSinglePage ? parentFetch : parentFetchUpdate;
|
|
60
|
+
const { data } = await targetFetch(
|
|
61
|
+
{
|
|
62
|
+
variables: loadVariables,
|
|
63
|
+
fetch,
|
|
64
|
+
metadata,
|
|
65
|
+
policy: isSinglePage ? artifact.policy : import_lib.CachePolicy.NetworkOnly,
|
|
66
|
+
session: await (0, import_session.getSession)()
|
|
67
|
+
},
|
|
68
|
+
isSinglePage ? [] : [where === "start" ? "prepend" : "append"]
|
|
69
|
+
);
|
|
70
|
+
const resultPath = [...artifact.refetch.path];
|
|
71
|
+
if (artifact.refetch.embedded) {
|
|
72
|
+
const { targetType } = artifact.refetch;
|
|
73
|
+
if (!config.types?.[targetType]?.resolve) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`Missing type resolve configuration for ${targetType}. For more information, see ${import_constants.siteURL}/guides/pagination#paginated-fragments`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
resultPath.unshift(config.types[targetType].resolve.queryField);
|
|
79
|
+
}
|
|
80
|
+
pageInfo.set((0, import_pageInfo.extractPageInfo)(data, resultPath));
|
|
81
|
+
};
|
|
82
|
+
const getPageInfo = () => {
|
|
83
|
+
return (0, import_pageInfo.extractPageInfo)(getState(), artifact.refetch?.path ?? []);
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
loadNextPage: async ({
|
|
87
|
+
first,
|
|
88
|
+
after,
|
|
89
|
+
fetch,
|
|
90
|
+
metadata
|
|
91
|
+
} = {}) => {
|
|
92
|
+
if (artifact.refetch?.direction === "backward") {
|
|
93
|
+
console.warn(`\u26A0\uFE0F ${storeName}.loadNextPage was called but it does not support forwards pagination.
|
|
94
|
+
If you think this is an error, please open an issue on GitHub`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const currentPageInfo = getPageInfo();
|
|
98
|
+
if (!currentPageInfo.hasNextPage) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const input = {
|
|
102
|
+
first: first ?? artifact.refetch.pageSize,
|
|
103
|
+
after: after ?? currentPageInfo.endCursor,
|
|
104
|
+
before: null,
|
|
105
|
+
last: null
|
|
106
|
+
};
|
|
107
|
+
return await loadPage({
|
|
108
|
+
pageSizeVar: "first",
|
|
109
|
+
functionName: "loadNextPage",
|
|
110
|
+
input,
|
|
111
|
+
fetch,
|
|
112
|
+
metadata,
|
|
113
|
+
where: "end"
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
loadPreviousPage: async ({
|
|
117
|
+
last,
|
|
118
|
+
before,
|
|
119
|
+
fetch,
|
|
120
|
+
metadata
|
|
121
|
+
} = {}) => {
|
|
122
|
+
if (artifact.refetch?.direction === "forward") {
|
|
123
|
+
console.warn(`\u26A0\uFE0F ${storeName}.loadPreviousPage was called but it does not support backwards pagination.
|
|
124
|
+
If you think this is an error, please open an issue on GitHub`);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const currentPageInfo = getPageInfo();
|
|
128
|
+
if (!currentPageInfo.hasPreviousPage) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const input = {
|
|
132
|
+
before: before ?? currentPageInfo.startCursor,
|
|
133
|
+
last: last ?? artifact.refetch.pageSize,
|
|
134
|
+
first: null,
|
|
135
|
+
after: null
|
|
136
|
+
};
|
|
137
|
+
return await loadPage({
|
|
138
|
+
pageSizeVar: "last",
|
|
139
|
+
functionName: "loadPreviousPage",
|
|
140
|
+
input,
|
|
141
|
+
fetch,
|
|
142
|
+
metadata,
|
|
143
|
+
where: "start"
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
pageInfo,
|
|
147
|
+
async fetch(args) {
|
|
148
|
+
const { params } = await (0, import_query.fetchParams)(artifact, storeName, args);
|
|
149
|
+
const { variables } = params ?? {};
|
|
150
|
+
if (variables && !(0, import_deepEquals.deepEquals)(getVariables(), variables)) {
|
|
151
|
+
return await parentFetch(params);
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
var currentPageInfo = (0, import_pageInfo.extractPageInfo)(getState(), artifact.refetch.path);
|
|
155
|
+
} catch {
|
|
156
|
+
return await parentFetch(params);
|
|
157
|
+
}
|
|
158
|
+
const queryVariables = {};
|
|
159
|
+
const count = (0, import_pageInfo.countPage)(artifact.refetch.path.concat("edges"), getState()) || artifact.refetch.pageSize;
|
|
160
|
+
if (count && count > artifact.refetch.pageSize) {
|
|
161
|
+
if (currentPageInfo.hasPreviousPage && currentPageInfo.hasNextPage && !(variables?.["first"] && variables?.["after"] || variables?.["last"] && variables?.["before"])) {
|
|
162
|
+
console.warn(`\u26A0\uFE0F Encountered a fetch() in the middle of the connection.
|
|
163
|
+
Make sure to pass a cursor value by hand that includes the current set (ie the entry before startCursor)
|
|
164
|
+
`);
|
|
165
|
+
}
|
|
166
|
+
if (!currentPageInfo.hasPreviousPage) {
|
|
167
|
+
queryVariables["first"] = count;
|
|
168
|
+
queryVariables["after"] = null;
|
|
169
|
+
queryVariables["last"] = null;
|
|
170
|
+
queryVariables["before"] = null;
|
|
171
|
+
} else if (!currentPageInfo.hasNextPage) {
|
|
172
|
+
queryVariables["last"] = count;
|
|
173
|
+
queryVariables["first"] = null;
|
|
174
|
+
queryVariables["after"] = null;
|
|
175
|
+
queryVariables["before"] = null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
Object.assign(queryVariables, variables ?? {});
|
|
179
|
+
const result = await parentFetch({
|
|
180
|
+
...params,
|
|
181
|
+
variables: queryVariables
|
|
182
|
+
});
|
|
183
|
+
pageInfo.set((0, import_pageInfo.extractPageInfo)(result.data, artifact.refetch.path));
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
189
|
+
0 && (module.exports = {
|
|
190
|
+
cursorHandlers
|
|
191
|
+
});
|
|
@@ -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>>;
|
|
@@ -0,0 +1,16 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var fetch_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(fetch_exports);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { DocumentStore } from '$houdini/runtime/client';
|
|
2
|
-
import type { FragmentArtifact, GraphQLObject, HoudiniFetchContext, QueryArtifact
|
|
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
|
-
|
|
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;
|
|
@@ -24,13 +24,14 @@ __export(fragment_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(fragment_exports);
|
|
25
25
|
var import_config = require("$houdini/runtime/lib/config");
|
|
26
26
|
var import_constants = require("$houdini/runtime/lib/constants");
|
|
27
|
-
var import_pageInfo = require("$houdini/runtime/lib/pageInfo");
|
|
28
|
-
var import_pagination = require("$houdini/runtime/lib/pagination");
|
|
29
27
|
var import_types = require("$houdini/runtime/lib/types");
|
|
30
28
|
var import_store = require("svelte/store");
|
|
31
29
|
var import_client = require("../../client");
|
|
32
30
|
var import_session = require("../../session");
|
|
33
31
|
var import_fragment = require("../fragment");
|
|
32
|
+
var import_cursor = require("./cursor");
|
|
33
|
+
var import_offset = require("./offset");
|
|
34
|
+
var import_pageInfo = require("./pageInfo");
|
|
34
35
|
class BasePaginatedFragmentStore {
|
|
35
36
|
paginated = true;
|
|
36
37
|
paginationArtifact;
|
|
@@ -93,14 +94,17 @@ class FragmentStoreCursor extends BasePaginatedFragmentStore {
|
|
|
93
94
|
};
|
|
94
95
|
return {
|
|
95
96
|
kind: import_types.CompiledFragmentKind,
|
|
97
|
+
data: (0, import_store.derived)(store, ($value) => $value),
|
|
96
98
|
subscribe,
|
|
99
|
+
fetching: (0, import_store.derived)([paginationStore], ([$store]) => $store.fetching),
|
|
97
100
|
fetch: handlers.fetch,
|
|
101
|
+
pageInfo: handlers.pageInfo,
|
|
98
102
|
loadNextPage: handlers.loadNextPage,
|
|
99
103
|
loadPreviousPage: handlers.loadPreviousPage
|
|
100
104
|
};
|
|
101
105
|
}
|
|
102
106
|
storeHandlers(observer, initialValue, getState, getVariables) {
|
|
103
|
-
return (0,
|
|
107
|
+
return (0, import_cursor.cursorHandlers)({
|
|
104
108
|
getState,
|
|
105
109
|
getVariables,
|
|
106
110
|
artifact: this.paginationArtifact,
|
|
@@ -133,7 +137,7 @@ class FragmentStoreCursor extends BasePaginatedFragmentStore {
|
|
|
133
137
|
}
|
|
134
138
|
});
|
|
135
139
|
},
|
|
136
|
-
|
|
140
|
+
initialValue,
|
|
137
141
|
storeName: this.name
|
|
138
142
|
});
|
|
139
143
|
}
|
|
@@ -150,7 +154,7 @@ class FragmentStoreOffset extends BasePaginatedFragmentStore {
|
|
|
150
154
|
initialValue: store.initialValue
|
|
151
155
|
});
|
|
152
156
|
const getState = () => (0, import_store.get)(store);
|
|
153
|
-
const handlers = (0,
|
|
157
|
+
const handlers = (0, import_offset.offsetHandlers)({
|
|
154
158
|
getState,
|
|
155
159
|
getVariables: () => store.variables,
|
|
156
160
|
artifact: this.paginationArtifact,
|
|
@@ -182,7 +186,6 @@ class FragmentStoreOffset extends BasePaginatedFragmentStore {
|
|
|
182
186
|
}
|
|
183
187
|
});
|
|
184
188
|
},
|
|
185
|
-
getSession: import_session.getSession,
|
|
186
189
|
storeName: this.name
|
|
187
190
|
});
|
|
188
191
|
const subscribe = (run, invalidate) => {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SendParams } from '$houdini/runtime/client/documentStore';
|
|
2
|
+
import type { GraphQLObject, QueryArtifact, QueryResult } from '$houdini/runtime/lib/types';
|
|
3
|
+
import type { QueryStoreFetchParams } from '../query';
|
|
4
|
+
import type { FetchFn } from './fetch';
|
|
5
|
+
export declare function offsetHandlers<_Data extends GraphQLObject, _Input extends {}>({ artifact, storeName, getState, getVariables, fetch: parentFetch, fetchUpdate: parentFetchUpdate, }: {
|
|
6
|
+
artifact: QueryArtifact;
|
|
7
|
+
fetch: FetchFn<_Data, _Input>;
|
|
8
|
+
fetchUpdate: (arg: SendParams) => ReturnType<FetchFn<_Data, _Input>>;
|
|
9
|
+
storeName: string;
|
|
10
|
+
getState: () => _Data | null;
|
|
11
|
+
getVariables: () => _Input;
|
|
12
|
+
}): {
|
|
13
|
+
loadNextPage: ({ limit, offset, fetch, metadata, }?: {
|
|
14
|
+
limit?: number | undefined;
|
|
15
|
+
offset?: number | undefined;
|
|
16
|
+
fetch?: typeof fetch | undefined;
|
|
17
|
+
metadata?: {} | undefined;
|
|
18
|
+
}) => Promise<void>;
|
|
19
|
+
fetch(args?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
|
|
20
|
+
};
|