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
|
@@ -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,65 @@
|
|
|
1
|
+
import { CachePolicy } from "$houdini/runtime/lib";
|
|
2
|
+
import { deepEquals } from "$houdini/runtime/lib/deepEquals";
|
|
3
|
+
import { getSession } from "../../session";
|
|
4
|
+
import { fetchParams } from "../query";
|
|
5
|
+
import { countPage, missingPageSizeError } from "./pageInfo";
|
|
6
|
+
function offsetHandlers({
|
|
7
|
+
artifact,
|
|
8
|
+
storeName,
|
|
9
|
+
getState,
|
|
10
|
+
getVariables,
|
|
11
|
+
fetch: parentFetch,
|
|
12
|
+
fetchUpdate: parentFetchUpdate
|
|
13
|
+
}) {
|
|
14
|
+
let getOffset = () => artifact.refetch?.start || countPage(artifact.refetch.path, getState()) || artifact.refetch.pageSize;
|
|
15
|
+
let currentOffset = getOffset() ?? 0;
|
|
16
|
+
return {
|
|
17
|
+
loadNextPage: async ({
|
|
18
|
+
limit,
|
|
19
|
+
offset,
|
|
20
|
+
fetch,
|
|
21
|
+
metadata
|
|
22
|
+
} = {}) => {
|
|
23
|
+
const queryVariables = {
|
|
24
|
+
...getVariables(),
|
|
25
|
+
offset: offset ?? getOffset()
|
|
26
|
+
};
|
|
27
|
+
if (limit || limit === 0) {
|
|
28
|
+
queryVariables.limit = limit;
|
|
29
|
+
}
|
|
30
|
+
if (!queryVariables.limit && !artifact.refetch.pageSize) {
|
|
31
|
+
throw missingPageSizeError("loadNextPage");
|
|
32
|
+
}
|
|
33
|
+
let isSinglePage = artifact.refetch?.mode === "SinglePage";
|
|
34
|
+
const targetFetch = isSinglePage ? parentFetch : parentFetchUpdate;
|
|
35
|
+
await targetFetch({
|
|
36
|
+
variables: queryVariables,
|
|
37
|
+
fetch,
|
|
38
|
+
metadata,
|
|
39
|
+
policy: isSinglePage ? artifact.policy : CachePolicy.NetworkOnly,
|
|
40
|
+
session: await getSession()
|
|
41
|
+
});
|
|
42
|
+
const pageSize = queryVariables.limit || artifact.refetch.pageSize;
|
|
43
|
+
currentOffset = offset + pageSize;
|
|
44
|
+
},
|
|
45
|
+
async fetch(args) {
|
|
46
|
+
const { params } = await fetchParams(artifact, storeName, args);
|
|
47
|
+
const { variables } = params ?? {};
|
|
48
|
+
if (variables && !deepEquals(getVariables(), variables)) {
|
|
49
|
+
return parentFetch.call(this, params);
|
|
50
|
+
}
|
|
51
|
+
const count = currentOffset || getOffset();
|
|
52
|
+
const queryVariables = {};
|
|
53
|
+
if (!artifact.refetch.pageSize || count > artifact.refetch.pageSize) {
|
|
54
|
+
queryVariables.limit = count;
|
|
55
|
+
}
|
|
56
|
+
return await parentFetch.call(this, {
|
|
57
|
+
...params,
|
|
58
|
+
variables: queryVariables
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
offsetHandlers
|
|
65
|
+
};
|
|
@@ -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,52 @@
|
|
|
1
|
+
import { siteURL } from "$houdini/runtime/lib/constants";
|
|
2
|
+
function nullPageInfo() {
|
|
3
|
+
return { startCursor: null, endCursor: null, hasNextPage: false, hasPreviousPage: false };
|
|
4
|
+
}
|
|
5
|
+
function missingPageSizeError(fnName) {
|
|
6
|
+
return {
|
|
7
|
+
message: `${fnName} is missing the required page arguments. For more information, please visit this link: ${siteURL}/guides/pagination`
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function extractPageInfo(data, path) {
|
|
11
|
+
if (!data) {
|
|
12
|
+
return {
|
|
13
|
+
startCursor: null,
|
|
14
|
+
endCursor: null,
|
|
15
|
+
hasNextPage: false,
|
|
16
|
+
hasPreviousPage: false
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
let localPath = [...path];
|
|
20
|
+
let current = data;
|
|
21
|
+
while (localPath.length > 0) {
|
|
22
|
+
if (!current) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
current = current[localPath.shift()];
|
|
26
|
+
}
|
|
27
|
+
return current?.pageInfo ?? nullPageInfo();
|
|
28
|
+
}
|
|
29
|
+
function countPage(source, value) {
|
|
30
|
+
let data = value;
|
|
31
|
+
if (value === null || data === null || data === void 0) {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
for (const field of source) {
|
|
35
|
+
const obj = data[field];
|
|
36
|
+
if (obj && !Array.isArray(obj)) {
|
|
37
|
+
data = obj;
|
|
38
|
+
} else if (!data) {
|
|
39
|
+
throw new Error("Could not count page size");
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(obj)) {
|
|
42
|
+
return obj.length;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
countPage,
|
|
49
|
+
extractPageInfo,
|
|
50
|
+
missingPageSizeError,
|
|
51
|
+
nullPageInfo
|
|
52
|
+
};
|
|
@@ -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,9 +1,9 @@
|
|
|
1
|
-
import { extractPageInfo } from "$houdini/runtime/lib/pageInfo";
|
|
2
|
-
import { cursorHandlers, offsetHandlers } from "$houdini/runtime/lib/pagination";
|
|
3
1
|
import { get, derived } from "svelte/store";
|
|
4
2
|
import { getClient, initClient } from "../../client";
|
|
5
|
-
import { getSession } from "../../session";
|
|
6
3
|
import { QueryStore } from "../query";
|
|
4
|
+
import { cursorHandlers } from "./cursor";
|
|
5
|
+
import { offsetHandlers } from "./offset";
|
|
6
|
+
import { extractPageInfo } from "./pageInfo";
|
|
7
7
|
class QueryStoreCursor extends QueryStore {
|
|
8
8
|
paginated = true;
|
|
9
9
|
constructor(config) {
|
|
@@ -20,11 +20,11 @@ class QueryStoreCursor extends QueryStore {
|
|
|
20
20
|
});
|
|
21
21
|
this.#_handlers = cursorHandlers({
|
|
22
22
|
artifact: this.artifact,
|
|
23
|
+
initialValue: get(this.observer).data,
|
|
23
24
|
getState: () => get(this.observer).data,
|
|
24
25
|
getVariables: () => get(this.observer).variables,
|
|
25
26
|
storeName: this.name,
|
|
26
27
|
fetch: super.fetch.bind(this),
|
|
27
|
-
getSession,
|
|
28
28
|
fetchUpdate: async (args, updates) => {
|
|
29
29
|
return paginationObserver.send({
|
|
30
30
|
...args,
|
|
@@ -85,7 +85,6 @@ class QueryStoreOffset extends QueryStore {
|
|
|
85
85
|
fetch: super.fetch,
|
|
86
86
|
getState: () => get(this.observer).data,
|
|
87
87
|
getVariables: () => get(this.observer).variables,
|
|
88
|
-
getSession,
|
|
89
88
|
fetchUpdate: async (args) => {
|
|
90
89
|
await initClient();
|
|
91
90
|
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
|
|
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 {};
|