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,5 +1,7 @@
1
+ /// <reference types="svelte" />
1
2
  import type { FetchContext } from '$houdini/runtime/client/plugins/fetch';
2
- import type { CachePolicies, GraphQLVariables, GraphQLObject, MutationArtifact, QueryArtifact, QueryResult } from '$houdini/runtime/lib/types';
3
+ import type { CachePolicies, GraphQLVariables, GraphQLObject, MutationArtifact, QueryArtifact, QueryResult, CursorHandlers, OffsetHandlers, PageInfo } from '$houdini/runtime/lib/types';
4
+ import type { Subscriber } from 'svelte/store';
3
5
  import type { PluginArtifactData } from '../../plugin/artifactData';
4
6
  import type { ClientFetchParams, LoadEventFetchParams, QueryStoreFetchParams, RequestEventFetchParams } from '../types';
5
7
  import { BaseStore } from './base';
@@ -31,3 +33,27 @@ export declare function fetchParams<_Data extends GraphQLObject, _Input>(artifac
31
33
  policy: CachePolicies | undefined;
32
34
  params: QueryStoreFetchParams<_Data, _Input>;
33
35
  }>;
36
+ export type CursorStoreResult<_Data extends GraphQLObject, _Input extends GraphQLVariables> = QueryResult<_Data, _Input> & {
37
+ pageInfo: PageInfo;
38
+ };
39
+ export declare class QueryStoreCursor<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends QueryStore<_Data, _Input> {
40
+ #private;
41
+ paginated: boolean;
42
+ constructor(config: StoreConfig<_Data, _Input, QueryArtifact>);
43
+ fetch(params?: RequestEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
44
+ fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
45
+ fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
46
+ fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
47
+ loadPreviousPage(args?: Parameters<Required<CursorHandlers<_Data, _Input>>['loadPreviousPage']>[0]): Promise<QueryResult<_Data, _Input>>;
48
+ loadNextPage(args?: Parameters<CursorHandlers<_Data, _Input>['loadNextPage']>[0]): Promise<QueryResult<_Data, _Input>>;
49
+ subscribe(run: Subscriber<CursorStoreResult<_Data, _Input>>, invalidate?: ((value?: CursorStoreResult<_Data, _Input> | undefined) => void) | undefined): () => void;
50
+ }
51
+ export declare class QueryStoreOffset<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends QueryStore<_Data, _Input> {
52
+ #private;
53
+ paginated: boolean;
54
+ loadNextPage(args?: Parameters<OffsetHandlers<_Data, _Input>['loadNextPage']>[0]): Promise<void>;
55
+ fetch(params?: RequestEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
56
+ fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
57
+ fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
58
+ fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
59
+ }
@@ -25,11 +25,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
25
25
  var query_exports = {};
26
26
  __export(query_exports, {
27
27
  QueryStore: () => QueryStore,
28
+ QueryStoreCursor: () => QueryStoreCursor,
29
+ QueryStoreOffset: () => QueryStoreOffset,
28
30
  fetchParams: () => fetchParams
29
31
  });
30
32
  module.exports = __toCommonJS(query_exports);
31
33
  var import_config = require("$houdini/runtime/lib/config");
32
34
  var log = __toESM(require("$houdini/runtime/lib/log"), 1);
35
+ var import_pageInfo = require("$houdini/runtime/lib/pageInfo");
36
+ var import_pagination = require("$houdini/runtime/lib/pagination");
33
37
  var import_types = require("$houdini/runtime/lib/types");
34
38
  var import_store = require("svelte/store");
35
39
  var import_adapter = require("../adapter");
@@ -52,7 +56,7 @@ class QueryStore extends import_base.BaseStore {
52
56
  this.variables = variables;
53
57
  }
54
58
  async fetch(args) {
55
- const client = await (0, import_client.initClient)();
59
+ const client = (0, import_client.getClient)();
56
60
  this.setup(false);
57
61
  const { policy, params, context } = await fetchParams(this.artifact, this.storeName, args);
58
62
  if (!import_adapter.isBrowser && !(params && "fetch" in params) && (!params || !("event" in params))) {
@@ -190,8 +194,122 @@ export async function load(${log.yellow("event")}: LoadEvent) {
190
194
  // in a server-side mutation:
191
195
  await mutation.mutate({ ... }, ${log.yellow("{ event }")})
192
196
  `;
197
+ class QueryStoreCursor extends QueryStore {
198
+ paginated = true;
199
+ constructor(config) {
200
+ super(config);
201
+ }
202
+ #_handlers = null;
203
+ async #handlers() {
204
+ if (this.#_handlers) {
205
+ return this.#_handlers;
206
+ }
207
+ const paginationObserver = (0, import_client.getClient)().observe({
208
+ artifact: this.artifact
209
+ });
210
+ this.#_handlers = (0, import_pagination.cursorHandlers)({
211
+ artifact: this.artifact,
212
+ getState: () => (0, import_store.get)(this.observer).data,
213
+ getVariables: () => (0, import_store.get)(this.observer).variables,
214
+ fetch: super.fetch.bind(this),
215
+ getSession: import_session.getSession,
216
+ fetchUpdate: async (args, updates) => {
217
+ return paginationObserver.send({
218
+ ...args,
219
+ cacheParams: {
220
+ applyUpdates: updates,
221
+ disableSubscriptions: true,
222
+ ...args?.cacheParams
223
+ }
224
+ });
225
+ }
226
+ });
227
+ return this.#_handlers;
228
+ }
229
+ async fetch(args) {
230
+ const handlers = await this.#handlers();
231
+ return await handlers.fetch.call(this, args);
232
+ }
233
+ async loadPreviousPage(args) {
234
+ const handlers = await this.#handlers();
235
+ try {
236
+ return await handlers.loadPreviousPage(args);
237
+ } catch (e) {
238
+ const err = e;
239
+ if (err.name === "AbortError") {
240
+ return (0, import_store.get)(this.observer);
241
+ } else {
242
+ throw err;
243
+ }
244
+ }
245
+ }
246
+ async loadNextPage(args) {
247
+ const handlers = await this.#handlers();
248
+ try {
249
+ return await handlers.loadNextPage(args);
250
+ } catch (e) {
251
+ const err = e;
252
+ if (err.name === "AbortError") {
253
+ return (0, import_store.get)(this.observer);
254
+ } else {
255
+ throw err;
256
+ }
257
+ }
258
+ }
259
+ subscribe(run, invalidate) {
260
+ const combined = (0, import_store.derived)([{ subscribe: super.subscribe.bind(this) }], ([$parent]) => {
261
+ return {
262
+ ...$parent,
263
+ pageInfo: (0, import_pageInfo.extractPageInfo)($parent.data, this.artifact.refetch.path)
264
+ };
265
+ });
266
+ return combined.subscribe(run, invalidate);
267
+ }
268
+ }
269
+ class QueryStoreOffset extends QueryStore {
270
+ paginated = true;
271
+ async loadNextPage(args) {
272
+ const handlers = await this.#handlers();
273
+ return await handlers.loadNextPage.call(this, args);
274
+ }
275
+ async fetch(args) {
276
+ const handlers = await this.#handlers();
277
+ return await handlers.fetch.call(this, args);
278
+ }
279
+ #_handlers = null;
280
+ async #handlers() {
281
+ if (this.#_handlers) {
282
+ return this.#_handlers;
283
+ }
284
+ const paginationObserver = (0, import_client.getClient)().observe({
285
+ artifact: this.artifact
286
+ });
287
+ this.#_handlers = (0, import_pagination.offsetHandlers)({
288
+ artifact: this.artifact,
289
+ storeName: this.name,
290
+ fetch: super.fetch.bind(this),
291
+ getState: () => (0, import_store.get)(this.observer).data,
292
+ getVariables: () => (0, import_store.get)(this.observer).variables,
293
+ getSession: import_session.getSession,
294
+ fetchUpdate: async (args) => {
295
+ return paginationObserver.send({
296
+ ...args,
297
+ variables: {
298
+ ...args?.variables
299
+ },
300
+ cacheParams: {
301
+ applyUpdates: ["append"]
302
+ }
303
+ });
304
+ }
305
+ });
306
+ return this.#_handlers;
307
+ }
308
+ }
193
309
  // Annotate the CommonJS export names for ESM import in node:
194
310
  0 && (module.exports = {
195
311
  QueryStore,
312
+ QueryStoreCursor,
313
+ QueryStoreOffset,
196
314
  fetchParams
197
315
  });
@@ -23,7 +23,6 @@ __export(subscription_exports, {
23
23
  module.exports = __toCommonJS(subscription_exports);
24
24
  var import_types = require("$houdini/runtime/lib/types");
25
25
  var import_store = require("svelte/store");
26
- var import_client = require("../client");
27
26
  var import_session = require("../session");
28
27
  var import_base = require("./base");
29
28
  class SubscriptionStore extends import_base.BaseStore {
@@ -35,7 +34,6 @@ class SubscriptionStore extends import_base.BaseStore {
35
34
  }
36
35
  async listen(variables, args) {
37
36
  this.fetchingStore.set(true);
38
- await (0, import_client.initClient)();
39
37
  this.observer.send({
40
38
  variables,
41
39
  session: await (0, import_session.getSession)(),
@@ -44,7 +42,6 @@ class SubscriptionStore extends import_base.BaseStore {
44
42
  }
45
43
  async unlisten() {
46
44
  this.fetchingStore.set(false);
47
- await (0, import_client.initClient)();
48
45
  await this.observer.cleanup();
49
46
  }
50
47
  subscribe(run, invalidate) {
@@ -1,3 +1,2 @@
1
1
  import type { HoudiniClient } from '$houdini/runtime/client';
2
- export declare function initClient(): Promise<HoudiniClient>;
3
2
  export declare function getClient(): HoudiniClient;
@@ -1,11 +1,4 @@
1
- let client = null;
2
- async function initClient() {
3
- if (client) {
4
- return client;
5
- }
6
- client = (await import("HOUDINI_CLIENT_PATH")).default;
7
- return client;
8
- }
1
+ import client from "HOUDINI_CLIENT_PATH";
9
2
  function getClient() {
10
3
  if (!client) {
11
4
  throw new Error("client hasn't been initialized");
@@ -13,6 +6,5 @@ function getClient() {
13
6
  return client;
14
7
  }
15
8
  export {
16
- getClient,
17
- initClient
9
+ getClient
18
10
  };
@@ -2,7 +2,7 @@
2
2
  import type { Fragment, FragmentArtifact } from '$houdini/runtime/lib/types';
3
3
  import type { Readable } from 'svelte/store';
4
4
  import type { FragmentStore } from './stores';
5
- import type { FragmentStorePaginated } from './stores/pagination/fragment';
5
+ import type { FragmentStorePaginated } from './stores/fragment';
6
6
  export declare function fragment<_Fragment extends Fragment<any>>(ref: _Fragment, fragment: FragmentStore<_Fragment['shape'], {}>): Readable<Exclude<_Fragment['shape'], undefined>> & {
7
7
  data: Readable<_Fragment>;
8
8
  artifact: FragmentArtifact;
@@ -1,7 +1,7 @@
1
1
  import { DocumentStore } from "$houdini/runtime/client";
2
2
  import { get } from "svelte/store";
3
3
  import { isBrowser } from "../adapter";
4
- import { getClient, initClient } from "../client";
4
+ import { getClient } from "../client";
5
5
  class BaseStore {
6
6
  #params;
7
7
  get artifact() {
@@ -50,11 +50,6 @@ class BaseStore {
50
50
  #subscriberCount = 0;
51
51
  setup(init = true) {
52
52
  let initPromise = Promise.resolve();
53
- try {
54
- getClient();
55
- } catch {
56
- initPromise = initClient();
57
- }
58
53
  initPromise.then(() => {
59
54
  if (this.#unsubscribe) {
60
55
  return;
@@ -1,6 +1,10 @@
1
- import type { GraphQLObject, FragmentArtifact, HoudiniFetchContext, GraphQLVariables } from '$houdini/runtime/lib/types';
1
+ /// <reference types="svelte" />
2
+ import type { DocumentStore } from '$houdini/runtime/client';
3
+ import type { GraphQLObject, FragmentArtifact, HoudiniFetchContext, GraphQLVariables, QueryArtifact, PageInfo, CursorHandlers } from '$houdini/runtime/lib/types';
2
4
  import { fragmentKey } from '$houdini/runtime/lib/types';
3
- import type { FragmentStoreInstance } from '../types';
5
+ import type { Readable, Subscriber } from 'svelte/store';
6
+ import type { FragmentStoreInstance, OffsetFragmentStoreInstance } from '../types';
7
+ import type { StoreConfig } from './query';
4
8
  export declare class FragmentStore<_Data extends GraphQLObject, _ReferenceType extends {}, _Input extends GraphQLVariables = GraphQLVariables> {
5
9
  artifact: FragmentArtifact;
6
10
  name: string;
@@ -16,3 +20,55 @@ export declare class FragmentStore<_Data extends GraphQLObject, _ReferenceType e
16
20
  initialValue: _Data | null;
17
21
  };
18
22
  }
23
+ type FragmentStoreConfig<_Data extends GraphQLObject, _Input> = StoreConfig<_Data, _Input, FragmentArtifact> & {
24
+ paginationArtifact: QueryArtifact;
25
+ };
26
+ declare class BasePaginatedFragmentStore<_Data extends GraphQLObject, _Input> {
27
+ paginated: boolean;
28
+ protected paginationArtifact: QueryArtifact;
29
+ name: string;
30
+ kind: "HoudiniFragment";
31
+ artifact: FragmentArtifact;
32
+ constructor(config: FragmentStoreConfig<_Data, _Input>);
33
+ protected queryVariables(getState: () => _Data | null): _Input;
34
+ }
35
+ export declare class FragmentStoreCursor<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends BasePaginatedFragmentStore<_Data, _Input> {
36
+ get(initialValue: _Data | null): {
37
+ kind: "HoudiniFragment";
38
+ subscribe: (run: Subscriber<FragmentPaginatedResult<_Data, {
39
+ pageInfo: PageInfo;
40
+ }>>, invalidate?: ((value?: FragmentPaginatedResult<_Data, {
41
+ pageInfo: PageInfo;
42
+ }> | undefined) => void) | undefined) => (() => void);
43
+ fetch: (args?: import("$houdini/runtime/lib/types").FetchParams<_Input> | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
44
+ loadNextPage: (args?: {
45
+ first?: number | undefined;
46
+ after?: string | undefined;
47
+ fetch?: typeof fetch | undefined;
48
+ metadata?: {} | undefined;
49
+ } | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
50
+ loadPreviousPage: (args?: {
51
+ last?: number | undefined;
52
+ before?: string | undefined;
53
+ fetch?: typeof fetch | undefined;
54
+ metadata?: {} | undefined;
55
+ } | undefined) => Promise<import("$houdini/runtime/lib/types").QueryResult<_Data, _Input>>;
56
+ };
57
+ protected storeHandlers(observer: DocumentStore<_Data, _Input>, initialValue: _Data | null, getState: () => _Data | null, getVariables: () => NonNullable<_Input>): CursorHandlers<_Data, _Input>;
58
+ }
59
+ export declare class FragmentStoreOffset<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends BasePaginatedFragmentStore<_Data, _Input> {
60
+ get(initialValue: _Data | null): OffsetFragmentStoreInstance<_Data, _Input>;
61
+ }
62
+ export type FragmentStorePaginated<_Data extends GraphQLObject, _Input> = Readable<{
63
+ data: _Data;
64
+ fetching: boolean;
65
+ pageInfo: PageInfo;
66
+ }> & {
67
+ loadNextPage(pageCount?: number, after?: string | number, houdiniContext?: HoudiniFetchContext): Promise<void>;
68
+ loadPreviousPage(pageCount?: number, before?: string, houdiniContext?: HoudiniFetchContext): Promise<void>;
69
+ };
70
+ export type FragmentPaginatedResult<_Data, _ExtraFields = {}> = {
71
+ data: _Data | null;
72
+ fetching: boolean;
73
+ } & _ExtraFields;
74
+ export {};
@@ -1,9 +1,14 @@
1
1
  import cache from "$houdini/runtime/cache";
2
- import { getCurrentConfig } from "$houdini/runtime/lib/config";
2
+ import { getCurrentConfig, keyFieldsForType } from "$houdini/runtime/lib/config";
3
+ import { siteURL } from "$houdini/runtime/lib/constants";
4
+ import { extractPageInfo } from "$houdini/runtime/lib/pageInfo";
5
+ import { cursorHandlers, offsetHandlers } from "$houdini/runtime/lib/pagination";
3
6
  import { marshalInputs } from "$houdini/runtime/lib/scalars";
4
7
  import { CompiledFragmentKind, fragmentKey } from "$houdini/runtime/lib/types";
5
- import { derived } from "svelte/store";
8
+ import { get, derived } from "svelte/store";
6
9
  import { isBrowser } from "../adapter";
10
+ import { getClient } from "../client";
11
+ import { getSession } from "../session";
7
12
  import { BaseStore } from "./base";
8
13
  class FragmentStore {
9
14
  artifact;
@@ -52,6 +57,177 @@ Please ensure that you have passed a record that has ${this.artifact.name} mixed
52
57
  };
53
58
  }
54
59
  }
60
+ class BasePaginatedFragmentStore {
61
+ paginated = true;
62
+ paginationArtifact;
63
+ name;
64
+ kind = CompiledFragmentKind;
65
+ artifact;
66
+ constructor(config) {
67
+ this.paginationArtifact = config.paginationArtifact;
68
+ this.name = config.storeName;
69
+ this.artifact = config.artifact;
70
+ }
71
+ queryVariables(getState) {
72
+ const config = getCurrentConfig();
73
+ const { targetType } = this.paginationArtifact.refetch || {};
74
+ const typeConfig = config.types?.[targetType || ""];
75
+ if (!typeConfig) {
76
+ throw new Error(
77
+ `Missing type refetch configuration for ${targetType}. For more information, see ${siteURL}/guides/pagination#paginated-fragments`
78
+ );
79
+ }
80
+ let idVariables = {};
81
+ const value = getState();
82
+ if (typeConfig.resolve?.arguments) {
83
+ idVariables = typeConfig.resolve.arguments?.(value) || {};
84
+ } else {
85
+ const keys = keyFieldsForType(config, targetType || "");
86
+ idVariables = Object.fromEntries(keys.map((key) => [key, value[key]]));
87
+ }
88
+ return {
89
+ ...idVariables
90
+ };
91
+ }
92
+ }
93
+ class FragmentStoreCursor extends BasePaginatedFragmentStore {
94
+ get(initialValue) {
95
+ const base = new FragmentStore({
96
+ artifact: this.artifact,
97
+ storeName: this.name
98
+ });
99
+ const store = base.get(initialValue);
100
+ const paginationStore = getClient().observe({
101
+ artifact: this.paginationArtifact,
102
+ initialValue: store.initialValue
103
+ });
104
+ const handlers = this.storeHandlers(
105
+ paginationStore,
106
+ initialValue,
107
+ () => get(store),
108
+ () => store.variables
109
+ );
110
+ const subscribe = (run, invalidate) => {
111
+ const combined = derived([store, paginationStore], ([$parent, $pagination]) => {
112
+ return {
113
+ ...$pagination,
114
+ data: $parent,
115
+ pageInfo: extractPageInfo($parent, this.paginationArtifact.refetch.path)
116
+ };
117
+ });
118
+ return combined.subscribe(run, invalidate);
119
+ };
120
+ return {
121
+ kind: CompiledFragmentKind,
122
+ subscribe,
123
+ fetch: handlers.fetch,
124
+ loadNextPage: handlers.loadNextPage,
125
+ loadPreviousPage: handlers.loadPreviousPage
126
+ };
127
+ }
128
+ storeHandlers(observer, initialValue, getState, getVariables) {
129
+ return cursorHandlers({
130
+ getState,
131
+ getVariables,
132
+ artifact: this.paginationArtifact,
133
+ fetchUpdate: async (args, updates) => {
134
+ return observer.send({
135
+ session: await getSession(),
136
+ ...args,
137
+ variables: {
138
+ ...args?.variables,
139
+ ...this.queryVariables(getState)
140
+ },
141
+ cacheParams: {
142
+ applyUpdates: updates,
143
+ disableSubscriptions: true
144
+ }
145
+ });
146
+ },
147
+ fetch: async (args) => {
148
+ return await observer.send({
149
+ session: await getSession(),
150
+ ...args,
151
+ variables: {
152
+ ...args?.variables,
153
+ ...this.queryVariables(getState)
154
+ },
155
+ cacheParams: {
156
+ disableSubscriptions: true
157
+ }
158
+ });
159
+ },
160
+ getSession
161
+ });
162
+ }
163
+ }
164
+ class FragmentStoreOffset extends BasePaginatedFragmentStore {
165
+ get(initialValue) {
166
+ const base = new FragmentStore({
167
+ artifact: this.artifact,
168
+ storeName: this.name
169
+ });
170
+ const store = base.get(initialValue);
171
+ const paginationStore = getClient().observe({
172
+ artifact: this.paginationArtifact,
173
+ initialValue: store.initialValue
174
+ });
175
+ const getState = () => get(store);
176
+ const handlers = offsetHandlers({
177
+ getState,
178
+ getVariables: () => store.variables,
179
+ artifact: this.paginationArtifact,
180
+ fetch: async (args) => {
181
+ return paginationStore.send({
182
+ ...args,
183
+ session: await getSession(),
184
+ variables: {
185
+ ...this.queryVariables(getState),
186
+ ...args?.variables
187
+ },
188
+ cacheParams: {
189
+ disableSubscriptions: true
190
+ }
191
+ });
192
+ },
193
+ fetchUpdate: async (args) => {
194
+ return paginationStore.send({
195
+ session: await getSession(),
196
+ ...args,
197
+ variables: {
198
+ ...this.queryVariables(getState),
199
+ ...args?.variables
200
+ },
201
+ cacheParams: {
202
+ disableSubscriptions: true,
203
+ applyUpdates: ["append"]
204
+ }
205
+ });
206
+ },
207
+ getSession,
208
+ storeName: this.name
209
+ });
210
+ const subscribe = (run, invalidate) => {
211
+ const combined = derived([store, paginationStore], ([$parent, $pagination]) => {
212
+ return {
213
+ ...$pagination,
214
+ data: $parent
215
+ };
216
+ });
217
+ return combined.subscribe(run, invalidate);
218
+ };
219
+ return {
220
+ kind: CompiledFragmentKind,
221
+ data: derived(paginationStore, ($value) => $value.data),
222
+ subscribe,
223
+ fetch: handlers.fetch,
224
+ loadNextPage: handlers.loadNextPage,
225
+ fetching: derived(paginationStore, ($store) => $store.fetching)
226
+ };
227
+ }
228
+ }
55
229
  export {
56
- FragmentStore
230
+ FragmentStore,
231
+ FragmentStoreCursor,
232
+ FragmentStoreOffset
57
233
  };
@@ -1,5 +1,4 @@
1
- export * from './pagination';
2
- export { FragmentStore } from './fragment';
1
+ export { FragmentStore, FragmentStoreCursor, FragmentStoreOffset } from './fragment';
3
2
  export { SubscriptionStore } from './subscription';
4
3
  export { MutationStore, type MutationConfig } from './mutation';
5
- export { QueryStore } from './query';
4
+ export { QueryStore, QueryStoreCursor, QueryStoreOffset } from './query';
@@ -1,11 +1,14 @@
1
- export * from "./pagination";
2
- import { FragmentStore } from "./fragment";
1
+ import { FragmentStore, FragmentStoreCursor, FragmentStoreOffset } from "./fragment";
3
2
  import { SubscriptionStore } from "./subscription";
4
3
  import { MutationStore } from "./mutation";
5
- import { QueryStore } from "./query";
4
+ import { QueryStore, QueryStoreCursor, QueryStoreOffset } from "./query";
6
5
  export {
7
6
  FragmentStore,
7
+ FragmentStoreCursor,
8
+ FragmentStoreOffset,
8
9
  MutationStore,
9
10
  QueryStore,
11
+ QueryStoreCursor,
12
+ QueryStoreOffset,
10
13
  SubscriptionStore
11
14
  };
@@ -1,4 +1,3 @@
1
- import { initClient } from "../client";
2
1
  import { BaseStore } from "./base";
3
2
  import { fetchParams } from "./query";
4
3
  class MutationStore extends BaseStore {
@@ -10,7 +9,6 @@ class MutationStore extends BaseStore {
10
9
  abortController,
11
10
  ...mutationConfig
12
11
  } = {}) {
13
- await initClient();
14
12
  const { context } = await fetchParams(this.artifact, this.artifact.name, {
15
13
  fetch,
16
14
  metadata,
@@ -1,5 +1,7 @@
1
+ /// <reference types="svelte" />
1
2
  import type { FetchContext } from '$houdini/runtime/client/plugins/fetch';
2
- import type { CachePolicies, GraphQLVariables, GraphQLObject, MutationArtifact, QueryArtifact, QueryResult } from '$houdini/runtime/lib/types';
3
+ import type { CachePolicies, GraphQLVariables, GraphQLObject, MutationArtifact, QueryArtifact, QueryResult, CursorHandlers, OffsetHandlers, PageInfo } from '$houdini/runtime/lib/types';
4
+ import type { Subscriber } from 'svelte/store';
3
5
  import type { PluginArtifactData } from '../../plugin/artifactData';
4
6
  import type { ClientFetchParams, LoadEventFetchParams, QueryStoreFetchParams, RequestEventFetchParams } from '../types';
5
7
  import { BaseStore } from './base';
@@ -31,3 +33,27 @@ export declare function fetchParams<_Data extends GraphQLObject, _Input>(artifac
31
33
  policy: CachePolicies | undefined;
32
34
  params: QueryStoreFetchParams<_Data, _Input>;
33
35
  }>;
36
+ export type CursorStoreResult<_Data extends GraphQLObject, _Input extends GraphQLVariables> = QueryResult<_Data, _Input> & {
37
+ pageInfo: PageInfo;
38
+ };
39
+ export declare class QueryStoreCursor<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends QueryStore<_Data, _Input> {
40
+ #private;
41
+ paginated: boolean;
42
+ constructor(config: StoreConfig<_Data, _Input, QueryArtifact>);
43
+ fetch(params?: RequestEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
44
+ fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
45
+ fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
46
+ fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
47
+ loadPreviousPage(args?: Parameters<Required<CursorHandlers<_Data, _Input>>['loadPreviousPage']>[0]): Promise<QueryResult<_Data, _Input>>;
48
+ loadNextPage(args?: Parameters<CursorHandlers<_Data, _Input>['loadNextPage']>[0]): Promise<QueryResult<_Data, _Input>>;
49
+ subscribe(run: Subscriber<CursorStoreResult<_Data, _Input>>, invalidate?: ((value?: CursorStoreResult<_Data, _Input> | undefined) => void) | undefined): () => void;
50
+ }
51
+ export declare class QueryStoreOffset<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends QueryStore<_Data, _Input> {
52
+ #private;
53
+ paginated: boolean;
54
+ loadNextPage(args?: Parameters<OffsetHandlers<_Data, _Input>['loadNextPage']>[0]): Promise<void>;
55
+ fetch(params?: RequestEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
56
+ fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
57
+ fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
58
+ fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
59
+ }