houdini-svelte 2.1.9 → 2.1.11

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 +7 -5
  2. package/build/plugin-esm/index.js +7 -5
  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 +1 -0
  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 +1 -0
  11. package/build/runtime-cjs/client.js +22 -5
  12. package/build/runtime-cjs/fragments.d.ts +1 -1
  13. package/build/runtime-cjs/stores/base.js +5 -0
  14. package/build/runtime-cjs/stores/fragment.d.ts +58 -2
  15. package/build/runtime-cjs/stores/fragment.js +184 -2
  16. package/build/runtime-cjs/stores/index.d.ts +2 -3
  17. package/build/runtime-cjs/stores/index.js +9 -3
  18. package/build/runtime-cjs/stores/mutation.js +2 -0
  19. package/build/runtime-cjs/stores/query.d.ts +27 -1
  20. package/build/runtime-cjs/stores/query.js +123 -1
  21. package/build/runtime-cjs/stores/subscription.js +3 -0
  22. package/build/runtime-esm/client.d.ts +1 -0
  23. package/build/runtime-esm/client.js +18 -2
  24. package/build/runtime-esm/fragments.d.ts +1 -1
  25. package/build/runtime-esm/stores/base.js +6 -1
  26. package/build/runtime-esm/stores/fragment.d.ts +58 -2
  27. package/build/runtime-esm/stores/fragment.js +183 -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 +2 -0
  31. package/build/runtime-esm/stores/query.d.ts +27 -1
  32. package/build/runtime-esm/stores/query.js +124 -4
  33. package/build/runtime-esm/stores/subscription.js +3 -0
  34. package/build/test-cjs/index.js +7 -5
  35. package/build/test-esm/index.js +7 -5
  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 -207
  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 -147
  46. package/build/runtime-esm/stores/pagination/fragment.d.ts +0 -58
  47. package/build/runtime-esm/stores/pagination/fragment.js +0 -182
  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 -122
@@ -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 { ArtifactKind, CachePolicy, CompiledQueryKind } from "$houdini/runtime/lib/types";
4
- import { get } from "svelte/store";
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 { getClient } from "../client";
8
+ import { getClient, initClient } 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 = getClient();
27
+ const client = await initClient();
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,125 @@ 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
+ await initClient();
176
+ const paginationObserver = getClient().observe({
177
+ artifact: this.artifact
178
+ });
179
+ this.#_handlers = cursorHandlers({
180
+ artifact: this.artifact,
181
+ getState: () => get(this.observer).data,
182
+ getVariables: () => get(this.observer).variables,
183
+ fetch: super.fetch.bind(this),
184
+ getSession,
185
+ fetchUpdate: async (args, updates) => {
186
+ await initClient();
187
+ return paginationObserver.send({
188
+ ...args,
189
+ cacheParams: {
190
+ applyUpdates: updates,
191
+ disableSubscriptions: true,
192
+ ...args?.cacheParams
193
+ }
194
+ });
195
+ }
196
+ });
197
+ return this.#_handlers;
198
+ }
199
+ async fetch(args) {
200
+ const handlers = await this.#handlers();
201
+ return await handlers.fetch.call(this, args);
202
+ }
203
+ async loadPreviousPage(args) {
204
+ const handlers = await this.#handlers();
205
+ try {
206
+ return await handlers.loadPreviousPage(args);
207
+ } catch (e) {
208
+ const err = e;
209
+ if (err.name === "AbortError") {
210
+ return get(this.observer);
211
+ } else {
212
+ throw err;
213
+ }
214
+ }
215
+ }
216
+ async loadNextPage(args) {
217
+ const handlers = await this.#handlers();
218
+ try {
219
+ return await handlers.loadNextPage(args);
220
+ } catch (e) {
221
+ const err = e;
222
+ if (err.name === "AbortError") {
223
+ return get(this.observer);
224
+ } else {
225
+ throw err;
226
+ }
227
+ }
228
+ }
229
+ subscribe(run, invalidate) {
230
+ const combined = derived([{ subscribe: super.subscribe.bind(this) }], ([$parent]) => {
231
+ return {
232
+ ...$parent,
233
+ pageInfo: extractPageInfo($parent.data, this.artifact.refetch.path)
234
+ };
235
+ });
236
+ return combined.subscribe(run, invalidate);
237
+ }
238
+ }
239
+ class QueryStoreOffset extends QueryStore {
240
+ paginated = true;
241
+ async loadNextPage(args) {
242
+ const handlers = await this.#handlers();
243
+ return await handlers.loadNextPage.call(this, args);
244
+ }
245
+ async fetch(args) {
246
+ const handlers = await this.#handlers();
247
+ return await handlers.fetch.call(this, args);
248
+ }
249
+ #_handlers = null;
250
+ async #handlers() {
251
+ if (this.#_handlers) {
252
+ return this.#_handlers;
253
+ }
254
+ await initClient();
255
+ const paginationObserver = getClient().observe({
256
+ artifact: this.artifact
257
+ });
258
+ this.#_handlers = offsetHandlers({
259
+ artifact: this.artifact,
260
+ storeName: this.name,
261
+ fetch: super.fetch.bind(this),
262
+ getState: () => get(this.observer).data,
263
+ getVariables: () => get(this.observer).variables,
264
+ getSession,
265
+ fetchUpdate: async (args) => {
266
+ await initClient();
267
+ return paginationObserver.send({
268
+ ...args,
269
+ variables: {
270
+ ...args?.variables
271
+ },
272
+ cacheParams: {
273
+ applyUpdates: ["append"]
274
+ }
275
+ });
276
+ }
277
+ });
278
+ return this.#_handlers;
279
+ }
280
+ }
163
281
  export {
164
282
  QueryStore,
283
+ QueryStoreCursor,
284
+ QueryStoreOffset,
165
285
  fetchParams
166
286
  };
@@ -1,5 +1,6 @@
1
1
  import { CompiledSubscriptionKind } from "$houdini/runtime/lib/types";
2
2
  import { derived, writable } from "svelte/store";
3
+ import { initClient } from "../client";
3
4
  import { getSession } from "../session";
4
5
  import { BaseStore } from "./base";
5
6
  class SubscriptionStore extends BaseStore {
@@ -10,6 +11,7 @@ class SubscriptionStore extends BaseStore {
10
11
  this.fetchingStore = writable(false);
11
12
  }
12
13
  async listen(variables, args) {
14
+ await initClient();
13
15
  this.fetchingStore.set(true);
14
16
  this.observer.send({
15
17
  variables,
@@ -18,6 +20,7 @@ class SubscriptionStore extends BaseStore {
18
20
  });
19
21
  }
20
22
  async unlisten() {
23
+ await initClient();
21
24
  this.fetchingStore.set(false);
22
25
  await this.observer.cleanup();
23
26
  }
@@ -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/pagination/query.QueryStoreCursor",
212513
- queryOffset: "../runtime/stores/pagination/query.QueryStoreOffset",
212514
- fragmentCursor: "../runtime/stores/pagination/fragment.FragmentStoreCursor",
212515
- fragmentOffset: "../runtime/stores/pagination/fragment.FragmentStoreOffset",
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,6 +282710,7 @@ 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'
282713
282714
 
282714
282715
  export class ${storeName} extends ${store_class} {
282715
282716
  constructor() {
@@ -282722,6 +282723,7 @@ export class ${storeName} extends ${store_class} {
282722
282723
  }
282723
282724
 
282724
282725
  export async function load_${artifactName}(params) {
282726
+ await initClient()
282725
282727
 
282726
282728
  const store = new ${storeName}()
282727
282729
 
@@ -284095,7 +284097,7 @@ export const redirect = svelteKitRedirect
284095
284097
  path_exports.dirname(networkFilePath),
284096
284098
  path_exports.join(config.projectRoot, plugin_config(config).client)
284097
284099
  );
284098
- return content.replace("HOUDINI_CLIENT_PATH", relativePath);
284100
+ return content.replaceAll("HOUDINI_CLIENT_PATH", relativePath);
284099
284101
  }
284100
284102
  },
284101
284103
  artifactData,
@@ -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/pagination/query.QueryStoreCursor",
212503
- queryOffset: "../runtime/stores/pagination/query.QueryStoreOffset",
212504
- fragmentCursor: "../runtime/stores/pagination/fragment.FragmentStoreCursor",
212505
- fragmentOffset: "../runtime/stores/pagination/fragment.FragmentStoreOffset",
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,6 +282699,7 @@ 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'
282702
282703
 
282703
282704
  export class ${storeName} extends ${store_class} {
282704
282705
  constructor() {
@@ -282711,6 +282712,7 @@ export class ${storeName} extends ${store_class} {
282711
282712
  }
282712
282713
 
282713
282714
  export async function load_${artifactName}(params) {
282715
+ await initClient()
282714
282716
 
282715
282717
  const store = new ${storeName}()
282716
282718
 
@@ -284084,7 +284086,7 @@ export const redirect = svelteKitRedirect
284084
284086
  path_exports.dirname(networkFilePath),
284085
284087
  path_exports.join(config.projectRoot, plugin_config(config).client)
284086
284088
  );
284087
- return content.replace("HOUDINI_CLIENT_PATH", relativePath);
284089
+ return content.replaceAll("HOUDINI_CLIENT_PATH", relativePath);
284088
284090
  }
284089
284091
  },
284090
284092
  artifactData,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini-svelte",
3
- "version": "2.1.9",
3
+ "version": "2.1.11",
4
4
  "description": "The svelte plugin for houdini",
5
5
  "keywords": [
6
6
  "typescript",
@@ -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,2 +0,0 @@
1
- export { FragmentStoreCursor, FragmentStoreOffset } from './fragment';
2
- export { QueryStoreCursor, QueryStoreOffset } from './query';
@@ -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,207 +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
- return observer.send({
109
- session: await (0, import_session.getSession)(),
110
- ...args,
111
- variables: {
112
- ...args?.variables,
113
- ...this.queryVariables(getState)
114
- },
115
- cacheParams: {
116
- applyUpdates: updates,
117
- disableSubscriptions: true
118
- }
119
- });
120
- },
121
- fetch: async (args) => {
122
- return await observer.send({
123
- session: await (0, import_session.getSession)(),
124
- ...args,
125
- variables: {
126
- ...args?.variables,
127
- ...this.queryVariables(getState)
128
- },
129
- cacheParams: {
130
- disableSubscriptions: true
131
- }
132
- });
133
- },
134
- getSession: import_session.getSession
135
- });
136
- }
137
- }
138
- class FragmentStoreOffset extends BasePaginatedFragmentStore {
139
- get(initialValue) {
140
- const base = new import_fragment.FragmentStore({
141
- artifact: this.artifact,
142
- storeName: this.name
143
- });
144
- const store = base.get(initialValue);
145
- const paginationStore = (0, import_client.getClient)().observe({
146
- artifact: this.paginationArtifact,
147
- initialValue: store.initialValue
148
- });
149
- const getState = () => (0, import_store.get)(store);
150
- const handlers = (0, import_pagination.offsetHandlers)({
151
- getState,
152
- getVariables: () => store.variables,
153
- artifact: this.paginationArtifact,
154
- fetch: async (args) => {
155
- return paginationStore.send({
156
- ...args,
157
- session: await (0, import_session.getSession)(),
158
- variables: {
159
- ...this.queryVariables(getState),
160
- ...args?.variables
161
- },
162
- cacheParams: {
163
- disableSubscriptions: true
164
- }
165
- });
166
- },
167
- fetchUpdate: async (args) => {
168
- return paginationStore.send({
169
- session: await (0, import_session.getSession)(),
170
- ...args,
171
- variables: {
172
- ...this.queryVariables(getState),
173
- ...args?.variables
174
- },
175
- cacheParams: {
176
- disableSubscriptions: true,
177
- applyUpdates: ["append"]
178
- }
179
- });
180
- },
181
- getSession: import_session.getSession,
182
- storeName: this.name
183
- });
184
- const subscribe = (run, invalidate) => {
185
- const combined = (0, import_store.derived)([store, paginationStore], ([$parent, $pagination]) => {
186
- return {
187
- ...$pagination,
188
- data: $parent
189
- };
190
- });
191
- return combined.subscribe(run, invalidate);
192
- };
193
- return {
194
- kind: import_types.CompiledFragmentKind,
195
- data: (0, import_store.derived)(paginationStore, ($value) => $value.data),
196
- subscribe,
197
- fetch: handlers.fetch,
198
- loadNextPage: handlers.loadNextPage,
199
- fetching: (0, import_store.derived)(paginationStore, ($store) => $store.fetching)
200
- };
201
- }
202
- }
203
- // Annotate the CommonJS export names for ESM import in node:
204
- 0 && (module.exports = {
205
- FragmentStoreCursor,
206
- FragmentStoreOffset
207
- });
@@ -1,2 +0,0 @@
1
- export { FragmentStoreCursor, FragmentStoreOffset } from './fragment';
2
- export { QueryStoreCursor, QueryStoreOffset } from './query';
@@ -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
- });