houdini-svelte 2.1.8 → 2.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/build/plugin-cjs/index.js +4 -6
  2. package/build/plugin-esm/index.js +4 -6
  3. package/build/preprocess-cjs/index.js +4 -4
  4. package/build/preprocess-esm/index.js +4 -4
  5. package/build/runtime/client.d.ts +0 -1
  6. package/build/runtime/fragments.d.ts +1 -1
  7. package/build/runtime/stores/fragment.d.ts +58 -2
  8. package/build/runtime/stores/index.d.ts +2 -3
  9. package/build/runtime/stores/query.d.ts +27 -1
  10. package/build/runtime-cjs/client.d.ts +0 -1
  11. package/build/runtime-cjs/client.js +5 -14
  12. package/build/runtime-cjs/fragments.d.ts +1 -1
  13. package/build/runtime-cjs/stores/base.js +0 -5
  14. package/build/runtime-cjs/stores/fragment.d.ts +58 -2
  15. package/build/runtime-cjs/stores/fragment.js +180 -2
  16. package/build/runtime-cjs/stores/index.d.ts +2 -3
  17. package/build/runtime-cjs/stores/index.js +8 -2
  18. package/build/runtime-cjs/stores/mutation.js +0 -2
  19. package/build/runtime-cjs/stores/query.d.ts +27 -1
  20. package/build/runtime-cjs/stores/query.js +119 -1
  21. package/build/runtime-cjs/stores/subscription.js +0 -3
  22. package/build/runtime-esm/client.d.ts +0 -1
  23. package/build/runtime-esm/client.js +2 -10
  24. package/build/runtime-esm/fragments.d.ts +1 -1
  25. package/build/runtime-esm/stores/base.js +1 -6
  26. package/build/runtime-esm/stores/fragment.d.ts +58 -2
  27. package/build/runtime-esm/stores/fragment.js +179 -3
  28. package/build/runtime-esm/stores/index.d.ts +2 -3
  29. package/build/runtime-esm/stores/index.js +6 -3
  30. package/build/runtime-esm/stores/mutation.js +0 -2
  31. package/build/runtime-esm/stores/query.d.ts +27 -1
  32. package/build/runtime-esm/stores/query.js +120 -4
  33. package/build/runtime-esm/stores/subscription.js +0 -3
  34. package/build/test-cjs/index.js +4 -6
  35. package/build/test-esm/index.js +4 -6
  36. package/package.json +1 -1
  37. package/build/runtime/stores/pagination/fragment.d.ts +0 -58
  38. package/build/runtime/stores/pagination/index.d.ts +0 -2
  39. package/build/runtime/stores/pagination/query.d.ts +0 -30
  40. package/build/runtime-cjs/stores/pagination/fragment.d.ts +0 -58
  41. package/build/runtime-cjs/stores/pagination/fragment.js +0 -210
  42. package/build/runtime-cjs/stores/pagination/index.d.ts +0 -2
  43. package/build/runtime-cjs/stores/pagination/index.js +0 -35
  44. package/build/runtime-cjs/stores/pagination/query.d.ts +0 -30
  45. package/build/runtime-cjs/stores/pagination/query.js +0 -150
  46. package/build/runtime-esm/stores/pagination/fragment.d.ts +0 -58
  47. package/build/runtime-esm/stores/pagination/fragment.js +0 -185
  48. package/build/runtime-esm/stores/pagination/index.d.ts +0 -2
  49. package/build/runtime-esm/stores/pagination/index.js +0 -8
  50. package/build/runtime-esm/stores/pagination/query.d.ts +0 -30
  51. package/build/runtime-esm/stores/pagination/query.js +0 -125
@@ -1,30 +0,0 @@
1
- /// <reference types="svelte" />
2
- import type { GraphQLObject, QueryArtifact, QueryResult, CursorHandlers, OffsetHandlers, PageInfo, GraphQLVariables } from '$houdini/runtime/lib/types';
3
- import type { Subscriber } from 'svelte/store';
4
- import type { ClientFetchParams, LoadEventFetchParams, QueryStoreFetchParams, RequestEventFetchParams } from '../../types';
5
- import type { StoreConfig } from '../query';
6
- import { QueryStore } from '../query';
7
- export type CursorStoreResult<_Data extends GraphQLObject, _Input extends GraphQLVariables> = QueryResult<_Data, _Input> & {
8
- pageInfo: PageInfo;
9
- };
10
- export declare class QueryStoreCursor<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends QueryStore<_Data, _Input> {
11
- #private;
12
- paginated: boolean;
13
- constructor(config: StoreConfig<_Data, _Input, QueryArtifact>);
14
- fetch(params?: RequestEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
15
- fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
16
- fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
17
- fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
18
- loadPreviousPage(args?: Parameters<Required<CursorHandlers<_Data, _Input>>['loadPreviousPage']>[0]): Promise<QueryResult<_Data, _Input>>;
19
- loadNextPage(args?: Parameters<CursorHandlers<_Data, _Input>['loadNextPage']>[0]): Promise<QueryResult<_Data, _Input>>;
20
- subscribe(run: Subscriber<CursorStoreResult<_Data, _Input>>, invalidate?: ((value?: CursorStoreResult<_Data, _Input> | undefined) => void) | undefined): () => void;
21
- }
22
- export declare class QueryStoreOffset<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends QueryStore<_Data, _Input> {
23
- #private;
24
- paginated: boolean;
25
- loadNextPage(args?: Parameters<OffsetHandlers<_Data, _Input>['loadNextPage']>[0]): Promise<void>;
26
- fetch(params?: RequestEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
27
- fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
28
- fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
29
- fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
30
- }
@@ -1,150 +0,0 @@
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 query_exports = {};
20
- __export(query_exports, {
21
- QueryStoreCursor: () => QueryStoreCursor,
22
- QueryStoreOffset: () => QueryStoreOffset
23
- });
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
- var import_store = require("svelte/store");
28
- var import_client = require("../../client");
29
- var import_session = require("../../session");
30
- var import_query = require("../query");
31
- class QueryStoreCursor extends import_query.QueryStore {
32
- paginated = true;
33
- constructor(config) {
34
- super(config);
35
- }
36
- #_handlers = null;
37
- async #handlers() {
38
- if (this.#_handlers) {
39
- return this.#_handlers;
40
- }
41
- await (0, import_client.initClient)();
42
- const paginationObserver = (0, import_client.getClient)().observe({
43
- artifact: this.artifact
44
- });
45
- this.#_handlers = (0, import_pagination.cursorHandlers)({
46
- artifact: this.artifact,
47
- getState: () => (0, import_store.get)(this.observer).data,
48
- getVariables: () => (0, import_store.get)(this.observer).variables,
49
- fetch: super.fetch.bind(this),
50
- getSession: import_session.getSession,
51
- fetchUpdate: async (args, updates) => {
52
- return paginationObserver.send({
53
- ...args,
54
- cacheParams: {
55
- applyUpdates: updates,
56
- disableSubscriptions: true,
57
- ...args?.cacheParams
58
- }
59
- });
60
- }
61
- });
62
- return this.#_handlers;
63
- }
64
- async fetch(args) {
65
- const handlers = await this.#handlers();
66
- return await handlers.fetch.call(this, args);
67
- }
68
- async loadPreviousPage(args) {
69
- const handlers = await this.#handlers();
70
- try {
71
- return await handlers.loadPreviousPage(args);
72
- } catch (e) {
73
- const err = e;
74
- if (err.name === "AbortError") {
75
- return (0, import_store.get)(this.observer);
76
- } else {
77
- throw err;
78
- }
79
- }
80
- }
81
- async loadNextPage(args) {
82
- const handlers = await this.#handlers();
83
- try {
84
- return await handlers.loadNextPage(args);
85
- } catch (e) {
86
- const err = e;
87
- if (err.name === "AbortError") {
88
- return (0, import_store.get)(this.observer);
89
- } else {
90
- throw err;
91
- }
92
- }
93
- }
94
- subscribe(run, invalidate) {
95
- const combined = (0, import_store.derived)([{ subscribe: super.subscribe.bind(this) }], ([$parent]) => {
96
- return {
97
- ...$parent,
98
- pageInfo: (0, import_pageInfo.extractPageInfo)($parent.data, this.artifact.refetch.path)
99
- };
100
- });
101
- return combined.subscribe(run, invalidate);
102
- }
103
- }
104
- class QueryStoreOffset extends import_query.QueryStore {
105
- paginated = true;
106
- async loadNextPage(args) {
107
- const handlers = await this.#handlers();
108
- return await handlers.loadNextPage.call(this, args);
109
- }
110
- async fetch(args) {
111
- const handlers = await this.#handlers();
112
- return await handlers.fetch.call(this, args);
113
- }
114
- #_handlers = null;
115
- async #handlers() {
116
- if (this.#_handlers) {
117
- return this.#_handlers;
118
- }
119
- await (0, import_client.initClient)();
120
- const paginationObserver = (0, import_client.getClient)().observe({
121
- artifact: this.artifact
122
- });
123
- this.#_handlers = (0, import_pagination.offsetHandlers)({
124
- artifact: this.artifact,
125
- storeName: this.name,
126
- fetch: super.fetch.bind(this),
127
- getState: () => (0, import_store.get)(this.observer).data,
128
- getVariables: () => (0, import_store.get)(this.observer).variables,
129
- getSession: import_session.getSession,
130
- fetchUpdate: async (args) => {
131
- await (0, import_client.initClient)();
132
- return paginationObserver.send({
133
- ...args,
134
- variables: {
135
- ...args?.variables
136
- },
137
- cacheParams: {
138
- applyUpdates: ["append"]
139
- }
140
- });
141
- }
142
- });
143
- return this.#_handlers;
144
- }
145
- }
146
- // Annotate the CommonJS export names for ESM import in node:
147
- 0 && (module.exports = {
148
- QueryStoreCursor,
149
- QueryStoreOffset
150
- });
@@ -1,58 +0,0 @@
1
- /// <reference types="svelte" />
2
- import type { DocumentStore } from '$houdini/runtime/client';
3
- import type { FragmentArtifact, GraphQLObject, HoudiniFetchContext, QueryArtifact, PageInfo, CursorHandlers, GraphQLVariables } from '$houdini/runtime/lib/types';
4
- import type { Readable, Subscriber } from 'svelte/store';
5
- import type { OffsetFragmentStoreInstance } from '../../types';
6
- import type { StoreConfig } from '../query';
7
- type FragmentStoreConfig<_Data extends GraphQLObject, _Input> = StoreConfig<_Data, _Input, FragmentArtifact> & {
8
- paginationArtifact: QueryArtifact;
9
- };
10
- declare class BasePaginatedFragmentStore<_Data extends GraphQLObject, _Input> {
11
- paginated: boolean;
12
- protected paginationArtifact: QueryArtifact;
13
- name: string;
14
- kind: "HoudiniFragment";
15
- artifact: FragmentArtifact;
16
- constructor(config: FragmentStoreConfig<_Data, _Input>);
17
- protected queryVariables(getState: () => _Data | null): _Input;
18
- }
19
- export declare class FragmentStoreCursor<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends BasePaginatedFragmentStore<_Data, _Input> {
20
- get(initialValue: _Data | null): {
21
- kind: "HoudiniFragment";
22
- subscribe: (run: Subscriber<FragmentPaginatedResult<_Data, {
23
- pageInfo: PageInfo;
24
- }>>, invalidate?: ((value?: FragmentPaginatedResult<_Data, {
25
- pageInfo: PageInfo;
26
- }> | 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
- loadNextPage: (args?: {
29
- first?: number | undefined;
30
- after?: string | undefined;
31
- fetch?: typeof fetch | undefined;
32
- metadata?: {} | undefined;
33
- } | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
34
- loadPreviousPage: (args?: {
35
- last?: number | undefined;
36
- before?: string | undefined;
37
- fetch?: typeof fetch | undefined;
38
- metadata?: {} | undefined;
39
- } | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
40
- };
41
- protected storeHandlers(observer: DocumentStore<_Data, _Input>, initialValue: _Data | null, getState: () => _Data | null, getVariables: () => NonNullable<_Input>): CursorHandlers<_Data, _Input>;
42
- }
43
- export declare class FragmentStoreOffset<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends BasePaginatedFragmentStore<_Data, _Input> {
44
- get(initialValue: _Data | null): OffsetFragmentStoreInstance<_Data, _Input>;
45
- }
46
- export type FragmentStorePaginated<_Data extends GraphQLObject, _Input> = Readable<{
47
- data: _Data;
48
- fetching: boolean;
49
- pageInfo: PageInfo;
50
- }> & {
51
- loadNextPage(pageCount?: number, after?: string | number, houdiniContext?: HoudiniFetchContext): Promise<void>;
52
- loadPreviousPage(pageCount?: number, before?: string, houdiniContext?: HoudiniFetchContext): Promise<void>;
53
- };
54
- export type FragmentPaginatedResult<_Data, _ExtraFields = {}> = {
55
- data: _Data | null;
56
- fetching: boolean;
57
- } & _ExtraFields;
58
- export {};
@@ -1,185 +0,0 @@
1
- import { getCurrentConfig, keyFieldsForType } from "$houdini/runtime/lib/config";
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
- import { CompiledFragmentKind } from "$houdini/runtime/lib/types";
6
- import { derived, get } from "svelte/store";
7
- import { getClient, initClient } from "../../client";
8
- import { getSession } from "../../session";
9
- import { FragmentStore } from "../fragment";
10
- class BasePaginatedFragmentStore {
11
- paginated = true;
12
- paginationArtifact;
13
- name;
14
- kind = CompiledFragmentKind;
15
- artifact;
16
- constructor(config) {
17
- this.paginationArtifact = config.paginationArtifact;
18
- this.name = config.storeName;
19
- this.artifact = config.artifact;
20
- }
21
- queryVariables(getState) {
22
- const config = getCurrentConfig();
23
- const { targetType } = this.paginationArtifact.refetch || {};
24
- const typeConfig = config.types?.[targetType || ""];
25
- if (!typeConfig) {
26
- throw new Error(
27
- `Missing type refetch configuration for ${targetType}. For more information, see ${siteURL}/guides/pagination#paginated-fragments`
28
- );
29
- }
30
- let idVariables = {};
31
- const value = getState();
32
- if (typeConfig.resolve?.arguments) {
33
- idVariables = typeConfig.resolve.arguments?.(value) || {};
34
- } else {
35
- const keys = keyFieldsForType(config, targetType || "");
36
- idVariables = Object.fromEntries(keys.map((key) => [key, value[key]]));
37
- }
38
- return {
39
- ...idVariables
40
- };
41
- }
42
- }
43
- class FragmentStoreCursor extends BasePaginatedFragmentStore {
44
- get(initialValue) {
45
- const base = new FragmentStore({
46
- artifact: this.artifact,
47
- storeName: this.name
48
- });
49
- const store = base.get(initialValue);
50
- const paginationStore = getClient().observe({
51
- artifact: this.paginationArtifact,
52
- initialValue: store.initialValue
53
- });
54
- const handlers = this.storeHandlers(
55
- paginationStore,
56
- initialValue,
57
- () => get(store),
58
- () => store.variables
59
- );
60
- const subscribe = (run, invalidate) => {
61
- const combined = derived([store, paginationStore], ([$parent, $pagination]) => {
62
- return {
63
- ...$pagination,
64
- data: $parent,
65
- pageInfo: extractPageInfo($parent, this.paginationArtifact.refetch.path)
66
- };
67
- });
68
- return combined.subscribe(run, invalidate);
69
- };
70
- return {
71
- kind: CompiledFragmentKind,
72
- subscribe,
73
- fetch: handlers.fetch,
74
- loadNextPage: handlers.loadNextPage,
75
- loadPreviousPage: handlers.loadPreviousPage
76
- };
77
- }
78
- storeHandlers(observer, initialValue, getState, getVariables) {
79
- return cursorHandlers({
80
- getState,
81
- getVariables,
82
- artifact: this.paginationArtifact,
83
- fetchUpdate: async (args, updates) => {
84
- await initClient();
85
- return observer.send({
86
- session: await getSession(),
87
- ...args,
88
- variables: {
89
- ...args?.variables,
90
- ...this.queryVariables(getState)
91
- },
92
- cacheParams: {
93
- applyUpdates: updates,
94
- disableSubscriptions: true
95
- }
96
- });
97
- },
98
- fetch: async (args) => {
99
- await initClient();
100
- return await observer.send({
101
- session: await getSession(),
102
- ...args,
103
- variables: {
104
- ...args?.variables,
105
- ...this.queryVariables(getState)
106
- },
107
- cacheParams: {
108
- disableSubscriptions: true
109
- }
110
- });
111
- },
112
- getSession
113
- });
114
- }
115
- }
116
- class FragmentStoreOffset extends BasePaginatedFragmentStore {
117
- get(initialValue) {
118
- const base = new FragmentStore({
119
- artifact: this.artifact,
120
- storeName: this.name
121
- });
122
- const store = base.get(initialValue);
123
- const paginationStore = getClient().observe({
124
- artifact: this.paginationArtifact,
125
- initialValue: store.initialValue
126
- });
127
- const getState = () => get(store);
128
- const handlers = offsetHandlers({
129
- getState,
130
- getVariables: () => store.variables,
131
- artifact: this.paginationArtifact,
132
- fetch: async (args) => {
133
- return paginationStore.send({
134
- ...args,
135
- session: await getSession(),
136
- variables: {
137
- ...this.queryVariables(getState),
138
- ...args?.variables
139
- },
140
- cacheParams: {
141
- disableSubscriptions: true
142
- }
143
- });
144
- },
145
- fetchUpdate: async (args) => {
146
- await initClient();
147
- return paginationStore.send({
148
- session: await getSession(),
149
- ...args,
150
- variables: {
151
- ...this.queryVariables(getState),
152
- ...args?.variables
153
- },
154
- cacheParams: {
155
- disableSubscriptions: true,
156
- applyUpdates: ["append"]
157
- }
158
- });
159
- },
160
- getSession,
161
- storeName: this.name
162
- });
163
- const subscribe = (run, invalidate) => {
164
- const combined = derived([store, paginationStore], ([$parent, $pagination]) => {
165
- return {
166
- ...$pagination,
167
- data: $parent
168
- };
169
- });
170
- return combined.subscribe(run, invalidate);
171
- };
172
- return {
173
- kind: CompiledFragmentKind,
174
- data: derived(paginationStore, ($value) => $value.data),
175
- subscribe,
176
- fetch: handlers.fetch,
177
- loadNextPage: handlers.loadNextPage,
178
- fetching: derived(paginationStore, ($store) => $store.fetching)
179
- };
180
- }
181
- }
182
- export {
183
- FragmentStoreCursor,
184
- FragmentStoreOffset
185
- };
@@ -1,2 +0,0 @@
1
- export { FragmentStoreCursor, FragmentStoreOffset } from './fragment';
2
- export { QueryStoreCursor, QueryStoreOffset } from './query';
@@ -1,8 +0,0 @@
1
- import { FragmentStoreCursor, FragmentStoreOffset } from "./fragment";
2
- import { QueryStoreCursor, QueryStoreOffset } from "./query";
3
- export {
4
- FragmentStoreCursor,
5
- FragmentStoreOffset,
6
- QueryStoreCursor,
7
- QueryStoreOffset
8
- };
@@ -1,30 +0,0 @@
1
- /// <reference types="svelte" />
2
- import type { GraphQLObject, QueryArtifact, QueryResult, CursorHandlers, OffsetHandlers, PageInfo, GraphQLVariables } from '$houdini/runtime/lib/types';
3
- import type { Subscriber } from 'svelte/store';
4
- import type { ClientFetchParams, LoadEventFetchParams, QueryStoreFetchParams, RequestEventFetchParams } from '../../types';
5
- import type { StoreConfig } from '../query';
6
- import { QueryStore } from '../query';
7
- export type CursorStoreResult<_Data extends GraphQLObject, _Input extends GraphQLVariables> = QueryResult<_Data, _Input> & {
8
- pageInfo: PageInfo;
9
- };
10
- export declare class QueryStoreCursor<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends QueryStore<_Data, _Input> {
11
- #private;
12
- paginated: boolean;
13
- constructor(config: StoreConfig<_Data, _Input, QueryArtifact>);
14
- fetch(params?: RequestEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
15
- fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
16
- fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
17
- fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
18
- loadPreviousPage(args?: Parameters<Required<CursorHandlers<_Data, _Input>>['loadPreviousPage']>[0]): Promise<QueryResult<_Data, _Input>>;
19
- loadNextPage(args?: Parameters<CursorHandlers<_Data, _Input>['loadNextPage']>[0]): Promise<QueryResult<_Data, _Input>>;
20
- subscribe(run: Subscriber<CursorStoreResult<_Data, _Input>>, invalidate?: ((value?: CursorStoreResult<_Data, _Input> | undefined) => void) | undefined): () => void;
21
- }
22
- export declare class QueryStoreOffset<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends QueryStore<_Data, _Input> {
23
- #private;
24
- paginated: boolean;
25
- loadNextPage(args?: Parameters<OffsetHandlers<_Data, _Input>['loadNextPage']>[0]): Promise<void>;
26
- fetch(params?: RequestEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
27
- fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
28
- fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
29
- fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
30
- }
@@ -1,125 +0,0 @@
1
- import { extractPageInfo } from "$houdini/runtime/lib/pageInfo";
2
- import { cursorHandlers, offsetHandlers } from "$houdini/runtime/lib/pagination";
3
- import { get, derived } from "svelte/store";
4
- import { getClient, initClient } from "../../client";
5
- import { getSession } from "../../session";
6
- import { QueryStore } from "../query";
7
- class QueryStoreCursor extends QueryStore {
8
- paginated = true;
9
- constructor(config) {
10
- super(config);
11
- }
12
- #_handlers = null;
13
- async #handlers() {
14
- if (this.#_handlers) {
15
- return this.#_handlers;
16
- }
17
- await initClient();
18
- const paginationObserver = getClient().observe({
19
- artifact: this.artifact
20
- });
21
- this.#_handlers = cursorHandlers({
22
- artifact: this.artifact,
23
- getState: () => get(this.observer).data,
24
- getVariables: () => get(this.observer).variables,
25
- fetch: super.fetch.bind(this),
26
- getSession,
27
- fetchUpdate: async (args, updates) => {
28
- return paginationObserver.send({
29
- ...args,
30
- cacheParams: {
31
- applyUpdates: updates,
32
- disableSubscriptions: true,
33
- ...args?.cacheParams
34
- }
35
- });
36
- }
37
- });
38
- return this.#_handlers;
39
- }
40
- async fetch(args) {
41
- const handlers = await this.#handlers();
42
- return await handlers.fetch.call(this, args);
43
- }
44
- async loadPreviousPage(args) {
45
- const handlers = await this.#handlers();
46
- try {
47
- return await handlers.loadPreviousPage(args);
48
- } catch (e) {
49
- const err = e;
50
- if (err.name === "AbortError") {
51
- return get(this.observer);
52
- } else {
53
- throw err;
54
- }
55
- }
56
- }
57
- async loadNextPage(args) {
58
- const handlers = await this.#handlers();
59
- try {
60
- return await handlers.loadNextPage(args);
61
- } catch (e) {
62
- const err = e;
63
- if (err.name === "AbortError") {
64
- return get(this.observer);
65
- } else {
66
- throw err;
67
- }
68
- }
69
- }
70
- subscribe(run, invalidate) {
71
- const combined = derived([{ subscribe: super.subscribe.bind(this) }], ([$parent]) => {
72
- return {
73
- ...$parent,
74
- pageInfo: extractPageInfo($parent.data, this.artifact.refetch.path)
75
- };
76
- });
77
- return combined.subscribe(run, invalidate);
78
- }
79
- }
80
- class QueryStoreOffset extends QueryStore {
81
- paginated = true;
82
- async loadNextPage(args) {
83
- const handlers = await this.#handlers();
84
- return await handlers.loadNextPage.call(this, args);
85
- }
86
- async fetch(args) {
87
- const handlers = await this.#handlers();
88
- return await handlers.fetch.call(this, args);
89
- }
90
- #_handlers = null;
91
- async #handlers() {
92
- if (this.#_handlers) {
93
- return this.#_handlers;
94
- }
95
- await initClient();
96
- const paginationObserver = getClient().observe({
97
- artifact: this.artifact
98
- });
99
- this.#_handlers = offsetHandlers({
100
- artifact: this.artifact,
101
- storeName: this.name,
102
- fetch: super.fetch.bind(this),
103
- getState: () => get(this.observer).data,
104
- getVariables: () => get(this.observer).variables,
105
- getSession,
106
- fetchUpdate: async (args) => {
107
- await initClient();
108
- return paginationObserver.send({
109
- ...args,
110
- variables: {
111
- ...args?.variables
112
- },
113
- cacheParams: {
114
- applyUpdates: ["append"]
115
- }
116
- });
117
- }
118
- });
119
- return this.#_handlers;
120
- }
121
- }
122
- export {
123
- QueryStoreCursor,
124
- QueryStoreOffset
125
- };