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.
- package/build/plugin-cjs/index.js +4 -6
- package/build/plugin-esm/index.js +4 -6
- package/build/preprocess-cjs/index.js +4 -4
- package/build/preprocess-esm/index.js +4 -4
- package/build/runtime/client.d.ts +0 -1
- package/build/runtime/fragments.d.ts +1 -1
- package/build/runtime/stores/fragment.d.ts +58 -2
- package/build/runtime/stores/index.d.ts +2 -3
- package/build/runtime/stores/query.d.ts +27 -1
- package/build/runtime-cjs/client.d.ts +0 -1
- package/build/runtime-cjs/client.js +5 -14
- package/build/runtime-cjs/fragments.d.ts +1 -1
- package/build/runtime-cjs/stores/base.js +0 -5
- package/build/runtime-cjs/stores/fragment.d.ts +58 -2
- package/build/runtime-cjs/stores/fragment.js +180 -2
- package/build/runtime-cjs/stores/index.d.ts +2 -3
- package/build/runtime-cjs/stores/index.js +8 -2
- package/build/runtime-cjs/stores/mutation.js +0 -2
- package/build/runtime-cjs/stores/query.d.ts +27 -1
- package/build/runtime-cjs/stores/query.js +119 -1
- package/build/runtime-cjs/stores/subscription.js +0 -3
- package/build/runtime-esm/client.d.ts +0 -1
- package/build/runtime-esm/client.js +2 -10
- package/build/runtime-esm/fragments.d.ts +1 -1
- package/build/runtime-esm/stores/base.js +1 -6
- package/build/runtime-esm/stores/fragment.d.ts +58 -2
- package/build/runtime-esm/stores/fragment.js +179 -3
- package/build/runtime-esm/stores/index.d.ts +2 -3
- package/build/runtime-esm/stores/index.js +6 -3
- package/build/runtime-esm/stores/mutation.js +0 -2
- package/build/runtime-esm/stores/query.d.ts +27 -1
- package/build/runtime-esm/stores/query.js +120 -4
- package/build/runtime-esm/stores/subscription.js +0 -3
- package/build/test-cjs/index.js +4 -6
- package/build/test-esm/index.js +4 -6
- package/package.json +1 -1
- package/build/runtime/stores/pagination/fragment.d.ts +0 -58
- package/build/runtime/stores/pagination/index.d.ts +0 -2
- package/build/runtime/stores/pagination/query.d.ts +0 -30
- package/build/runtime-cjs/stores/pagination/fragment.d.ts +0 -58
- package/build/runtime-cjs/stores/pagination/fragment.js +0 -210
- package/build/runtime-cjs/stores/pagination/index.d.ts +0 -2
- package/build/runtime-cjs/stores/pagination/index.js +0 -35
- package/build/runtime-cjs/stores/pagination/query.d.ts +0 -30
- package/build/runtime-cjs/stores/pagination/query.js +0 -150
- package/build/runtime-esm/stores/pagination/fragment.d.ts +0 -58
- package/build/runtime-esm/stores/pagination/fragment.js +0 -185
- package/build/runtime-esm/stores/pagination/index.d.ts +0 -2
- package/build/runtime-esm/stores/pagination/index.js +0 -8
- package/build/runtime-esm/stores/pagination/query.d.ts +0 -30
- package/build/runtime-esm/stores/pagination/query.js +0 -125
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { getCurrentConfig } from "$houdini/runtime/lib/config";
|
|
2
2
|
import * as log from "$houdini/runtime/lib/log";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { extractPageInfo } from "$houdini/runtime/lib/pageInfo";
|
|
4
|
+
import { cursorHandlers, offsetHandlers } from "$houdini/runtime/lib/pagination";
|
|
5
|
+
import { CompiledQueryKind, CachePolicy, ArtifactKind } from "$houdini/runtime/lib/types";
|
|
6
|
+
import { get, derived } from "svelte/store";
|
|
5
7
|
import { clientStarted, isBrowser } from "../adapter";
|
|
6
|
-
import {
|
|
8
|
+
import { getClient } from "../client";
|
|
7
9
|
import { getSession } from "../session";
|
|
8
10
|
import { BaseStore } from "./base";
|
|
9
11
|
class QueryStore extends BaseStore {
|
|
@@ -22,7 +24,7 @@ class QueryStore extends BaseStore {
|
|
|
22
24
|
this.variables = variables;
|
|
23
25
|
}
|
|
24
26
|
async fetch(args) {
|
|
25
|
-
const client =
|
|
27
|
+
const client = getClient();
|
|
26
28
|
this.setup(false);
|
|
27
29
|
const { policy, params, context } = await fetchParams(this.artifact, this.storeName, args);
|
|
28
30
|
if (!isBrowser && !(params && "fetch" in params) && (!params || !("event" in params))) {
|
|
@@ -160,7 +162,121 @@ export async function load(${log.yellow("event")}: LoadEvent) {
|
|
|
160
162
|
// in a server-side mutation:
|
|
161
163
|
await mutation.mutate({ ... }, ${log.yellow("{ event }")})
|
|
162
164
|
`;
|
|
165
|
+
class QueryStoreCursor extends QueryStore {
|
|
166
|
+
paginated = true;
|
|
167
|
+
constructor(config) {
|
|
168
|
+
super(config);
|
|
169
|
+
}
|
|
170
|
+
#_handlers = null;
|
|
171
|
+
async #handlers() {
|
|
172
|
+
if (this.#_handlers) {
|
|
173
|
+
return this.#_handlers;
|
|
174
|
+
}
|
|
175
|
+
const paginationObserver = getClient().observe({
|
|
176
|
+
artifact: this.artifact
|
|
177
|
+
});
|
|
178
|
+
this.#_handlers = cursorHandlers({
|
|
179
|
+
artifact: this.artifact,
|
|
180
|
+
getState: () => get(this.observer).data,
|
|
181
|
+
getVariables: () => get(this.observer).variables,
|
|
182
|
+
fetch: super.fetch.bind(this),
|
|
183
|
+
getSession,
|
|
184
|
+
fetchUpdate: async (args, updates) => {
|
|
185
|
+
return paginationObserver.send({
|
|
186
|
+
...args,
|
|
187
|
+
cacheParams: {
|
|
188
|
+
applyUpdates: updates,
|
|
189
|
+
disableSubscriptions: true,
|
|
190
|
+
...args?.cacheParams
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
return this.#_handlers;
|
|
196
|
+
}
|
|
197
|
+
async fetch(args) {
|
|
198
|
+
const handlers = await this.#handlers();
|
|
199
|
+
return await handlers.fetch.call(this, args);
|
|
200
|
+
}
|
|
201
|
+
async loadPreviousPage(args) {
|
|
202
|
+
const handlers = await this.#handlers();
|
|
203
|
+
try {
|
|
204
|
+
return await handlers.loadPreviousPage(args);
|
|
205
|
+
} catch (e) {
|
|
206
|
+
const err = e;
|
|
207
|
+
if (err.name === "AbortError") {
|
|
208
|
+
return get(this.observer);
|
|
209
|
+
} else {
|
|
210
|
+
throw err;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
async loadNextPage(args) {
|
|
215
|
+
const handlers = await this.#handlers();
|
|
216
|
+
try {
|
|
217
|
+
return await handlers.loadNextPage(args);
|
|
218
|
+
} catch (e) {
|
|
219
|
+
const err = e;
|
|
220
|
+
if (err.name === "AbortError") {
|
|
221
|
+
return get(this.observer);
|
|
222
|
+
} else {
|
|
223
|
+
throw err;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
subscribe(run, invalidate) {
|
|
228
|
+
const combined = derived([{ subscribe: super.subscribe.bind(this) }], ([$parent]) => {
|
|
229
|
+
return {
|
|
230
|
+
...$parent,
|
|
231
|
+
pageInfo: extractPageInfo($parent.data, this.artifact.refetch.path)
|
|
232
|
+
};
|
|
233
|
+
});
|
|
234
|
+
return combined.subscribe(run, invalidate);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
class QueryStoreOffset extends QueryStore {
|
|
238
|
+
paginated = true;
|
|
239
|
+
async loadNextPage(args) {
|
|
240
|
+
const handlers = await this.#handlers();
|
|
241
|
+
return await handlers.loadNextPage.call(this, args);
|
|
242
|
+
}
|
|
243
|
+
async fetch(args) {
|
|
244
|
+
const handlers = await this.#handlers();
|
|
245
|
+
return await handlers.fetch.call(this, args);
|
|
246
|
+
}
|
|
247
|
+
#_handlers = null;
|
|
248
|
+
async #handlers() {
|
|
249
|
+
if (this.#_handlers) {
|
|
250
|
+
return this.#_handlers;
|
|
251
|
+
}
|
|
252
|
+
const paginationObserver = getClient().observe({
|
|
253
|
+
artifact: this.artifact
|
|
254
|
+
});
|
|
255
|
+
this.#_handlers = offsetHandlers({
|
|
256
|
+
artifact: this.artifact,
|
|
257
|
+
storeName: this.name,
|
|
258
|
+
fetch: super.fetch.bind(this),
|
|
259
|
+
getState: () => get(this.observer).data,
|
|
260
|
+
getVariables: () => get(this.observer).variables,
|
|
261
|
+
getSession,
|
|
262
|
+
fetchUpdate: async (args) => {
|
|
263
|
+
return paginationObserver.send({
|
|
264
|
+
...args,
|
|
265
|
+
variables: {
|
|
266
|
+
...args?.variables
|
|
267
|
+
},
|
|
268
|
+
cacheParams: {
|
|
269
|
+
applyUpdates: ["append"]
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
return this.#_handlers;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
163
277
|
export {
|
|
164
278
|
QueryStore,
|
|
279
|
+
QueryStoreCursor,
|
|
280
|
+
QueryStoreOffset,
|
|
165
281
|
fetchParams
|
|
166
282
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CompiledSubscriptionKind } from "$houdini/runtime/lib/types";
|
|
2
2
|
import { derived, writable } from "svelte/store";
|
|
3
|
-
import { initClient } from "../client";
|
|
4
3
|
import { getSession } from "../session";
|
|
5
4
|
import { BaseStore } from "./base";
|
|
6
5
|
class SubscriptionStore extends BaseStore {
|
|
@@ -12,7 +11,6 @@ class SubscriptionStore extends BaseStore {
|
|
|
12
11
|
}
|
|
13
12
|
async listen(variables, args) {
|
|
14
13
|
this.fetchingStore.set(true);
|
|
15
|
-
await initClient();
|
|
16
14
|
this.observer.send({
|
|
17
15
|
variables,
|
|
18
16
|
session: await getSession(),
|
|
@@ -21,7 +19,6 @@ class SubscriptionStore extends BaseStore {
|
|
|
21
19
|
}
|
|
22
20
|
async unlisten() {
|
|
23
21
|
this.fetchingStore.set(false);
|
|
24
|
-
await initClient();
|
|
25
22
|
await this.observer.cleanup();
|
|
26
23
|
}
|
|
27
24
|
subscribe(run, invalidate) {
|
package/build/test-cjs/index.js
CHANGED
|
@@ -212509,10 +212509,10 @@ function plugin_config(config) {
|
|
|
212509
212509
|
mutation: "../runtime/stores/mutation.MutationStore",
|
|
212510
212510
|
fragment: "../runtime/stores/fragment.FragmentStore",
|
|
212511
212511
|
subscription: "../runtime/stores/subscription.SubscriptionStore",
|
|
212512
|
-
queryCursor: "../runtime/stores/
|
|
212513
|
-
queryOffset: "../runtime/stores/
|
|
212514
|
-
fragmentCursor: "../runtime/stores/
|
|
212515
|
-
fragmentOffset: "../runtime/stores/
|
|
212512
|
+
queryCursor: "../runtime/stores/query.QueryStoreCursor",
|
|
212513
|
+
queryOffset: "../runtime/stores/query.QueryStoreOffset",
|
|
212514
|
+
fragmentCursor: "../runtime/stores/fragment.FragmentStoreCursor",
|
|
212515
|
+
fragmentOffset: "../runtime/stores/fragment.FragmentStoreOffset",
|
|
212516
212516
|
...cfg?.customStores
|
|
212517
212517
|
}
|
|
212518
212518
|
};
|
|
@@ -282710,7 +282710,6 @@ async function queryStore({ config, pluginRoot }, doc) {
|
|
|
282710
282710
|
const { store_class, statement } = store_import2(config, which);
|
|
282711
282711
|
const storeData = `${statement}
|
|
282712
282712
|
import artifact from '$houdini/artifacts/${artifactName}'
|
|
282713
|
-
import { initClient } from '$houdini/plugins/houdini-svelte/runtime/client'
|
|
282714
282713
|
|
|
282715
282714
|
export class ${storeName} extends ${store_class} {
|
|
282716
282715
|
constructor() {
|
|
@@ -282723,7 +282722,6 @@ export class ${storeName} extends ${store_class} {
|
|
|
282723
282722
|
}
|
|
282724
282723
|
|
|
282725
282724
|
export async function load_${artifactName}(params) {
|
|
282726
|
-
await initClient()
|
|
282727
282725
|
|
|
282728
282726
|
const store = new ${storeName}()
|
|
282729
282727
|
|
package/build/test-esm/index.js
CHANGED
|
@@ -212499,10 +212499,10 @@ function plugin_config(config) {
|
|
|
212499
212499
|
mutation: "../runtime/stores/mutation.MutationStore",
|
|
212500
212500
|
fragment: "../runtime/stores/fragment.FragmentStore",
|
|
212501
212501
|
subscription: "../runtime/stores/subscription.SubscriptionStore",
|
|
212502
|
-
queryCursor: "../runtime/stores/
|
|
212503
|
-
queryOffset: "../runtime/stores/
|
|
212504
|
-
fragmentCursor: "../runtime/stores/
|
|
212505
|
-
fragmentOffset: "../runtime/stores/
|
|
212502
|
+
queryCursor: "../runtime/stores/query.QueryStoreCursor",
|
|
212503
|
+
queryOffset: "../runtime/stores/query.QueryStoreOffset",
|
|
212504
|
+
fragmentCursor: "../runtime/stores/fragment.FragmentStoreCursor",
|
|
212505
|
+
fragmentOffset: "../runtime/stores/fragment.FragmentStoreOffset",
|
|
212506
212506
|
...cfg?.customStores
|
|
212507
212507
|
}
|
|
212508
212508
|
};
|
|
@@ -282699,7 +282699,6 @@ async function queryStore({ config, pluginRoot }, doc) {
|
|
|
282699
282699
|
const { store_class, statement } = store_import2(config, which);
|
|
282700
282700
|
const storeData = `${statement}
|
|
282701
282701
|
import artifact from '$houdini/artifacts/${artifactName}'
|
|
282702
|
-
import { initClient } from '$houdini/plugins/houdini-svelte/runtime/client'
|
|
282703
282702
|
|
|
282704
282703
|
export class ${storeName} extends ${store_class} {
|
|
282705
282704
|
constructor() {
|
|
@@ -282712,7 +282711,6 @@ export class ${storeName} extends ${store_class} {
|
|
|
282712
282711
|
}
|
|
282713
282712
|
|
|
282714
282713
|
export async function load_${artifactName}(params) {
|
|
282715
|
-
await initClient()
|
|
282716
282714
|
|
|
282717
282715
|
const store = new ${storeName}()
|
|
282718
282716
|
|
package/package.json
CHANGED
|
@@ -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,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,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,210 +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 fragment_exports = {};
|
|
20
|
-
__export(fragment_exports, {
|
|
21
|
-
FragmentStoreCursor: () => FragmentStoreCursor,
|
|
22
|
-
FragmentStoreOffset: () => FragmentStoreOffset
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(fragment_exports);
|
|
25
|
-
var import_config = require("$houdini/runtime/lib/config");
|
|
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
|
-
var import_types = require("$houdini/runtime/lib/types");
|
|
30
|
-
var import_store = require("svelte/store");
|
|
31
|
-
var import_client = require("../../client");
|
|
32
|
-
var import_session = require("../../session");
|
|
33
|
-
var import_fragment = require("../fragment");
|
|
34
|
-
class BasePaginatedFragmentStore {
|
|
35
|
-
paginated = true;
|
|
36
|
-
paginationArtifact;
|
|
37
|
-
name;
|
|
38
|
-
kind = import_types.CompiledFragmentKind;
|
|
39
|
-
artifact;
|
|
40
|
-
constructor(config) {
|
|
41
|
-
this.paginationArtifact = config.paginationArtifact;
|
|
42
|
-
this.name = config.storeName;
|
|
43
|
-
this.artifact = config.artifact;
|
|
44
|
-
}
|
|
45
|
-
queryVariables(getState) {
|
|
46
|
-
const config = (0, import_config.getCurrentConfig)();
|
|
47
|
-
const { targetType } = this.paginationArtifact.refetch || {};
|
|
48
|
-
const typeConfig = config.types?.[targetType || ""];
|
|
49
|
-
if (!typeConfig) {
|
|
50
|
-
throw new Error(
|
|
51
|
-
`Missing type refetch configuration for ${targetType}. For more information, see ${import_constants.siteURL}/guides/pagination#paginated-fragments`
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
let idVariables = {};
|
|
55
|
-
const value = getState();
|
|
56
|
-
if (typeConfig.resolve?.arguments) {
|
|
57
|
-
idVariables = typeConfig.resolve.arguments?.(value) || {};
|
|
58
|
-
} else {
|
|
59
|
-
const keys = (0, import_config.keyFieldsForType)(config, targetType || "");
|
|
60
|
-
idVariables = Object.fromEntries(keys.map((key) => [key, value[key]]));
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
...idVariables
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
class FragmentStoreCursor extends BasePaginatedFragmentStore {
|
|
68
|
-
get(initialValue) {
|
|
69
|
-
const base = new import_fragment.FragmentStore({
|
|
70
|
-
artifact: this.artifact,
|
|
71
|
-
storeName: this.name
|
|
72
|
-
});
|
|
73
|
-
const store = base.get(initialValue);
|
|
74
|
-
const paginationStore = (0, import_client.getClient)().observe({
|
|
75
|
-
artifact: this.paginationArtifact,
|
|
76
|
-
initialValue: store.initialValue
|
|
77
|
-
});
|
|
78
|
-
const handlers = this.storeHandlers(
|
|
79
|
-
paginationStore,
|
|
80
|
-
initialValue,
|
|
81
|
-
() => (0, import_store.get)(store),
|
|
82
|
-
() => store.variables
|
|
83
|
-
);
|
|
84
|
-
const subscribe = (run, invalidate) => {
|
|
85
|
-
const combined = (0, import_store.derived)([store, paginationStore], ([$parent, $pagination]) => {
|
|
86
|
-
return {
|
|
87
|
-
...$pagination,
|
|
88
|
-
data: $parent,
|
|
89
|
-
pageInfo: (0, import_pageInfo.extractPageInfo)($parent, this.paginationArtifact.refetch.path)
|
|
90
|
-
};
|
|
91
|
-
});
|
|
92
|
-
return combined.subscribe(run, invalidate);
|
|
93
|
-
};
|
|
94
|
-
return {
|
|
95
|
-
kind: import_types.CompiledFragmentKind,
|
|
96
|
-
subscribe,
|
|
97
|
-
fetch: handlers.fetch,
|
|
98
|
-
loadNextPage: handlers.loadNextPage,
|
|
99
|
-
loadPreviousPage: handlers.loadPreviousPage
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
storeHandlers(observer, initialValue, getState, getVariables) {
|
|
103
|
-
return (0, import_pagination.cursorHandlers)({
|
|
104
|
-
getState,
|
|
105
|
-
getVariables,
|
|
106
|
-
artifact: this.paginationArtifact,
|
|
107
|
-
fetchUpdate: async (args, updates) => {
|
|
108
|
-
await (0, import_client.initClient)();
|
|
109
|
-
return observer.send({
|
|
110
|
-
session: await (0, import_session.getSession)(),
|
|
111
|
-
...args,
|
|
112
|
-
variables: {
|
|
113
|
-
...args?.variables,
|
|
114
|
-
...this.queryVariables(getState)
|
|
115
|
-
},
|
|
116
|
-
cacheParams: {
|
|
117
|
-
applyUpdates: updates,
|
|
118
|
-
disableSubscriptions: true
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
|
-
fetch: async (args) => {
|
|
123
|
-
await (0, import_client.initClient)();
|
|
124
|
-
return await observer.send({
|
|
125
|
-
session: await (0, import_session.getSession)(),
|
|
126
|
-
...args,
|
|
127
|
-
variables: {
|
|
128
|
-
...args?.variables,
|
|
129
|
-
...this.queryVariables(getState)
|
|
130
|
-
},
|
|
131
|
-
cacheParams: {
|
|
132
|
-
disableSubscriptions: true
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
},
|
|
136
|
-
getSession: import_session.getSession
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
class FragmentStoreOffset extends BasePaginatedFragmentStore {
|
|
141
|
-
get(initialValue) {
|
|
142
|
-
const base = new import_fragment.FragmentStore({
|
|
143
|
-
artifact: this.artifact,
|
|
144
|
-
storeName: this.name
|
|
145
|
-
});
|
|
146
|
-
const store = base.get(initialValue);
|
|
147
|
-
const paginationStore = (0, import_client.getClient)().observe({
|
|
148
|
-
artifact: this.paginationArtifact,
|
|
149
|
-
initialValue: store.initialValue
|
|
150
|
-
});
|
|
151
|
-
const getState = () => (0, import_store.get)(store);
|
|
152
|
-
const handlers = (0, import_pagination.offsetHandlers)({
|
|
153
|
-
getState,
|
|
154
|
-
getVariables: () => store.variables,
|
|
155
|
-
artifact: this.paginationArtifact,
|
|
156
|
-
fetch: async (args) => {
|
|
157
|
-
return paginationStore.send({
|
|
158
|
-
...args,
|
|
159
|
-
session: await (0, import_session.getSession)(),
|
|
160
|
-
variables: {
|
|
161
|
-
...this.queryVariables(getState),
|
|
162
|
-
...args?.variables
|
|
163
|
-
},
|
|
164
|
-
cacheParams: {
|
|
165
|
-
disableSubscriptions: true
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
},
|
|
169
|
-
fetchUpdate: async (args) => {
|
|
170
|
-
await (0, import_client.initClient)();
|
|
171
|
-
return paginationStore.send({
|
|
172
|
-
session: await (0, import_session.getSession)(),
|
|
173
|
-
...args,
|
|
174
|
-
variables: {
|
|
175
|
-
...this.queryVariables(getState),
|
|
176
|
-
...args?.variables
|
|
177
|
-
},
|
|
178
|
-
cacheParams: {
|
|
179
|
-
disableSubscriptions: true,
|
|
180
|
-
applyUpdates: ["append"]
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
},
|
|
184
|
-
getSession: import_session.getSession,
|
|
185
|
-
storeName: this.name
|
|
186
|
-
});
|
|
187
|
-
const subscribe = (run, invalidate) => {
|
|
188
|
-
const combined = (0, import_store.derived)([store, paginationStore], ([$parent, $pagination]) => {
|
|
189
|
-
return {
|
|
190
|
-
...$pagination,
|
|
191
|
-
data: $parent
|
|
192
|
-
};
|
|
193
|
-
});
|
|
194
|
-
return combined.subscribe(run, invalidate);
|
|
195
|
-
};
|
|
196
|
-
return {
|
|
197
|
-
kind: import_types.CompiledFragmentKind,
|
|
198
|
-
data: (0, import_store.derived)(paginationStore, ($value) => $value.data),
|
|
199
|
-
subscribe,
|
|
200
|
-
fetch: handlers.fetch,
|
|
201
|
-
loadNextPage: handlers.loadNextPage,
|
|
202
|
-
fetching: (0, import_store.derived)(paginationStore, ($store) => $store.fetching)
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
207
|
-
0 && (module.exports = {
|
|
208
|
-
FragmentStoreCursor,
|
|
209
|
-
FragmentStoreOffset
|
|
210
|
-
});
|
|
@@ -1,35 +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 pagination_exports = {};
|
|
20
|
-
__export(pagination_exports, {
|
|
21
|
-
FragmentStoreCursor: () => import_fragment.FragmentStoreCursor,
|
|
22
|
-
FragmentStoreOffset: () => import_fragment.FragmentStoreOffset,
|
|
23
|
-
QueryStoreCursor: () => import_query.QueryStoreCursor,
|
|
24
|
-
QueryStoreOffset: () => import_query.QueryStoreOffset
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(pagination_exports);
|
|
27
|
-
var import_fragment = require("./fragment");
|
|
28
|
-
var import_query = require("./query");
|
|
29
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
-
0 && (module.exports = {
|
|
31
|
-
FragmentStoreCursor,
|
|
32
|
-
FragmentStoreOffset,
|
|
33
|
-
QueryStoreCursor,
|
|
34
|
-
QueryStoreOffset
|
|
35
|
-
});
|