houdini-svelte 1.1.2 → 1.1.4-react.0

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 +261 -225
  2. package/build/plugin-esm/index.js +261 -225
  3. package/build/preprocess-cjs/index.js +272 -225
  4. package/build/preprocess-esm/index.js +272 -225
  5. package/build/runtime/stores/index.d.ts +1 -1
  6. package/build/runtime/stores/pagination/fragment.d.ts +4 -7
  7. package/build/runtime/stores/pagination/query.d.ts +3 -4
  8. package/build/runtime/stores/query.d.ts +2 -54
  9. package/build/runtime/types.d.ts +40 -28
  10. package/build/runtime-cjs/stores/index.d.ts +1 -1
  11. package/build/runtime-cjs/stores/pagination/fragment.d.ts +4 -7
  12. package/build/runtime-cjs/stores/pagination/fragment.js +6 -9
  13. package/build/runtime-cjs/stores/pagination/query.d.ts +3 -4
  14. package/build/runtime-cjs/stores/pagination/query.js +28 -22
  15. package/build/runtime-cjs/stores/query.d.ts +2 -54
  16. package/build/runtime-cjs/types.d.ts +40 -28
  17. package/build/runtime-esm/stores/index.d.ts +1 -1
  18. package/build/runtime-esm/stores/pagination/fragment.d.ts +4 -7
  19. package/build/runtime-esm/stores/pagination/fragment.js +4 -7
  20. package/build/runtime-esm/stores/pagination/query.d.ts +3 -4
  21. package/build/runtime-esm/stores/pagination/query.js +23 -17
  22. package/build/runtime-esm/stores/query.d.ts +2 -54
  23. package/build/runtime-esm/types.d.ts +40 -28
  24. package/build/test-cjs/index.js +601 -491
  25. package/build/test-esm/index.js +601 -491
  26. package/package.json +2 -2
  27. package/build/runtime/stores/pagination/cursor.d.ts +0 -13
  28. package/build/runtime/stores/pagination/fetch.d.ts +0 -3
  29. package/build/runtime/stores/pagination/offset.d.ts +0 -20
  30. package/build/runtime/stores/pagination/pageInfo.d.ts +0 -13
  31. package/build/runtime-cjs/stores/pagination/cursor.d.ts +0 -13
  32. package/build/runtime-cjs/stores/pagination/cursor.js +0 -191
  33. package/build/runtime-cjs/stores/pagination/fetch.d.ts +0 -3
  34. package/build/runtime-cjs/stores/pagination/fetch.js +0 -16
  35. package/build/runtime-cjs/stores/pagination/offset.d.ts +0 -20
  36. package/build/runtime-cjs/stores/pagination/offset.js +0 -89
  37. package/build/runtime-cjs/stores/pagination/pageInfo.d.ts +0 -13
  38. package/build/runtime-cjs/stores/pagination/pageInfo.js +0 -79
  39. package/build/runtime-esm/stores/pagination/cursor.d.ts +0 -13
  40. package/build/runtime-esm/stores/pagination/cursor.js +0 -167
  41. package/build/runtime-esm/stores/pagination/fetch.d.ts +0 -3
  42. package/build/runtime-esm/stores/pagination/fetch.js +0 -0
  43. package/build/runtime-esm/stores/pagination/offset.d.ts +0 -20
  44. package/build/runtime-esm/stores/pagination/offset.js +0 -65
  45. package/build/runtime-esm/stores/pagination/pageInfo.d.ts +0 -13
  46. package/build/runtime-esm/stores/pagination/pageInfo.js +0 -52
@@ -1,167 +0,0 @@
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
- };
@@ -1,3 +0,0 @@
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,20 +0,0 @@
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
- };
@@ -1,65 +0,0 @@
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
- };
@@ -1,13 +0,0 @@
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,52 +0,0 @@
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
- };