houdini-svelte 1.1.2 → 1.1.4-react.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/build/plugin-cjs/index.js +261 -225
  2. package/build/plugin-esm/index.js +261 -225
  3. package/build/preprocess-cjs/index.js +272 -225
  4. package/build/preprocess-esm/index.js +272 -225
  5. package/build/runtime/stores/index.d.ts +1 -1
  6. package/build/runtime/stores/pagination/fragment.d.ts +4 -7
  7. package/build/runtime/stores/pagination/query.d.ts +3 -4
  8. package/build/runtime/stores/query.d.ts +2 -54
  9. package/build/runtime/types.d.ts +40 -28
  10. package/build/runtime-cjs/stores/index.d.ts +1 -1
  11. package/build/runtime-cjs/stores/pagination/fragment.d.ts +4 -7
  12. package/build/runtime-cjs/stores/pagination/fragment.js +6 -9
  13. package/build/runtime-cjs/stores/pagination/query.d.ts +3 -4
  14. package/build/runtime-cjs/stores/pagination/query.js +28 -22
  15. package/build/runtime-cjs/stores/query.d.ts +2 -54
  16. package/build/runtime-cjs/types.d.ts +40 -28
  17. package/build/runtime-esm/stores/index.d.ts +1 -1
  18. package/build/runtime-esm/stores/pagination/fragment.d.ts +4 -7
  19. package/build/runtime-esm/stores/pagination/fragment.js +4 -7
  20. package/build/runtime-esm/stores/pagination/query.d.ts +3 -4
  21. package/build/runtime-esm/stores/pagination/query.js +23 -17
  22. package/build/runtime-esm/stores/query.d.ts +2 -54
  23. package/build/runtime-esm/types.d.ts +40 -28
  24. package/build/test-cjs/index.js +601 -491
  25. package/build/test-esm/index.js +601 -491
  26. package/package.json +2 -2
  27. package/build/runtime/stores/pagination/cursor.d.ts +0 -13
  28. package/build/runtime/stores/pagination/fetch.d.ts +0 -3
  29. package/build/runtime/stores/pagination/offset.d.ts +0 -20
  30. package/build/runtime/stores/pagination/pageInfo.d.ts +0 -13
  31. package/build/runtime-cjs/stores/pagination/cursor.d.ts +0 -13
  32. package/build/runtime-cjs/stores/pagination/cursor.js +0 -191
  33. package/build/runtime-cjs/stores/pagination/fetch.d.ts +0 -3
  34. package/build/runtime-cjs/stores/pagination/fetch.js +0 -16
  35. package/build/runtime-cjs/stores/pagination/offset.d.ts +0 -20
  36. package/build/runtime-cjs/stores/pagination/offset.js +0 -89
  37. package/build/runtime-cjs/stores/pagination/pageInfo.d.ts +0 -13
  38. package/build/runtime-cjs/stores/pagination/pageInfo.js +0 -79
  39. package/build/runtime-esm/stores/pagination/cursor.d.ts +0 -13
  40. package/build/runtime-esm/stores/pagination/cursor.js +0 -167
  41. package/build/runtime-esm/stores/pagination/fetch.d.ts +0 -3
  42. package/build/runtime-esm/stores/pagination/fetch.js +0 -0
  43. package/build/runtime-esm/stores/pagination/offset.d.ts +0 -20
  44. package/build/runtime-esm/stores/pagination/offset.js +0 -65
  45. package/build/runtime-esm/stores/pagination/pageInfo.d.ts +0 -13
  46. package/build/runtime-esm/stores/pagination/pageInfo.js +0 -52
@@ -1,9 +1,8 @@
1
- import type { GraphQLObject, QueryArtifact, QueryResult } from '$houdini/runtime/lib/types';
1
+ import type { GraphQLObject, QueryArtifact, QueryResult, CursorHandlers, OffsetHandlers, PageInfo } from '$houdini/runtime/lib/types';
2
2
  import type { Subscriber } from 'svelte/store';
3
- import type { CursorHandlers, OffsetHandlers } from '../../types';
4
- import type { ClientFetchParams, LoadEventFetchParams, QueryStoreFetchParams, RequestEventFetchParams, StoreConfig } from '../query';
3
+ import type { ClientFetchParams, LoadEventFetchParams, QueryStoreFetchParams, RequestEventFetchParams } from '../../types';
4
+ import { StoreConfig } from '../query';
5
5
  import { QueryStore } from '../query';
6
- import { type PageInfo } from './pageInfo';
7
6
  export type CursorStoreResult<_Data extends GraphQLObject, _Input extends {}> = QueryResult<_Data, _Input> & {
8
7
  pageInfo: PageInfo;
9
8
  };
@@ -1,38 +1,37 @@
1
+ import { extractPageInfo } from "$houdini/runtime/lib/pageInfo";
2
+ import { cursorHandlers, offsetHandlers } from "$houdini/runtime/lib/pagination";
1
3
  import { get, derived } from "svelte/store";
2
4
  import { getClient, initClient } from "../../client";
5
+ import { getSession } from "../../session";
3
6
  import { QueryStore } from "../query";
4
- import { cursorHandlers } from "./cursor";
5
- import { offsetHandlers } from "./offset";
6
- import { extractPageInfo } from "./pageInfo";
7
7
  class QueryStoreCursor extends QueryStore {
8
8
  paginated = true;
9
9
  constructor(config) {
10
10
  super(config);
11
11
  }
12
12
  #_handlers = null;
13
- get #handlers() {
13
+ async #handlers() {
14
14
  if (this.#_handlers) {
15
15
  return this.#_handlers;
16
16
  }
17
+ await initClient();
17
18
  const paginationObserver = getClient().observe({
18
19
  artifact: this.artifact
19
20
  });
20
21
  this.#_handlers = cursorHandlers({
21
22
  artifact: this.artifact,
22
- initialValue: get(this.observer).data,
23
23
  getState: () => get(this.observer).data,
24
24
  getVariables: () => get(this.observer).variables,
25
25
  storeName: this.name,
26
26
  fetch: super.fetch.bind(this),
27
+ getSession,
27
28
  fetchUpdate: async (args, updates) => {
28
- await initClient();
29
29
  return paginationObserver.send({
30
30
  ...args,
31
- variables: {
32
- ...args?.variables
33
- },
34
31
  cacheParams: {
35
- applyUpdates: updates
32
+ applyUpdates: updates,
33
+ disableSubscriptions: true,
34
+ ...args?.cacheParams
36
35
  }
37
36
  });
38
37
  }
@@ -40,13 +39,16 @@ class QueryStoreCursor extends QueryStore {
40
39
  return this.#_handlers;
41
40
  }
42
41
  async fetch(args) {
43
- return this.#handlers.fetch.call(this, args);
42
+ const handlers = await this.#handlers();
43
+ return await handlers.fetch.call(this, args);
44
44
  }
45
45
  async loadPreviousPage(args) {
46
- return this.#handlers.loadPreviousPage(args);
46
+ const handlers = await this.#handlers();
47
+ return await handlers.loadPreviousPage(args);
47
48
  }
48
49
  async loadNextPage(args) {
49
- return this.#handlers.loadNextPage(args);
50
+ const handlers = await this.#handlers();
51
+ return await handlers.loadNextPage(args);
50
52
  }
51
53
  subscribe(run, invalidate) {
52
54
  const combined = derived([{ subscribe: super.subscribe.bind(this) }], ([$parent]) => {
@@ -61,16 +63,19 @@ class QueryStoreCursor extends QueryStore {
61
63
  class QueryStoreOffset extends QueryStore {
62
64
  paginated = true;
63
65
  async loadNextPage(args) {
64
- return this.#handlers.loadNextPage.call(this, args);
66
+ const handlers = await this.#handlers();
67
+ return await handlers.loadNextPage.call(this, args);
65
68
  }
66
- fetch(args) {
67
- return this.#handlers.fetch.call(this, args);
69
+ async fetch(args) {
70
+ const handlers = await this.#handlers();
71
+ return await handlers.fetch.call(this, args);
68
72
  }
69
73
  #_handlers = null;
70
- get #handlers() {
74
+ async #handlers() {
71
75
  if (this.#_handlers) {
72
76
  return this.#_handlers;
73
77
  }
78
+ await initClient();
74
79
  const paginationObserver = getClient().observe({
75
80
  artifact: this.artifact
76
81
  });
@@ -80,6 +85,7 @@ class QueryStoreOffset extends QueryStore {
80
85
  fetch: super.fetch,
81
86
  getState: () => get(this.observer).data,
82
87
  getVariables: () => get(this.observer).variables,
88
+ getSession,
83
89
  fetchUpdate: async (args) => {
84
90
  await initClient();
85
91
  return paginationObserver.send({
@@ -1,7 +1,7 @@
1
1
  import type { FetchContext } from '$houdini/runtime/client/plugins/fetch';
2
- import type { GraphQLObject, HoudiniFetchContext, MutationArtifact, QueryArtifact, QueryResult, CachePolicies } from '$houdini/runtime/lib/types';
3
- import type { LoadEvent, RequestEvent } from '@sveltejs/kit';
2
+ import type { GraphQLObject, MutationArtifact, QueryArtifact, QueryResult, CachePolicies } from '$houdini/runtime/lib/types';
4
3
  import type { PluginArtifactData } from '../../plugin/artifactData';
4
+ import type { ClientFetchParams, LoadEventFetchParams, QueryStoreFetchParams, RequestEventFetchParams } from '../types';
5
5
  import { BaseStore } from './base';
6
6
  export declare class QueryStore<_Data extends GraphQLObject, _Input extends {}> extends BaseStore<_Data, _Input, QueryArtifact> {
7
7
  variables: boolean;
@@ -31,55 +31,3 @@ export declare function fetchParams<_Data extends GraphQLObject, _Input>(artifac
31
31
  policy: CachePolicies | undefined;
32
32
  params: QueryStoreFetchParams<_Data, _Input>;
33
33
  }>;
34
- type FetchGlobalParams<_Data extends GraphQLObject, _Input> = {
35
- variables?: _Input;
36
- /**
37
- * The policy to use when performing the fetch. If set to CachePolicy.NetworkOnly,
38
- * a request will always be sent, even if the variables are the same as the last call
39
- * to fetch.
40
- */
41
- policy?: CachePolicies;
42
- /**
43
- * An object that will be passed to the fetch function.
44
- * You can do what you want with it!
45
- */
46
- metadata?: App.Metadata;
47
- /**
48
- * Set to true if you want the promise to pause while it's resolving.
49
- * Only enable this if you know what you are doing. This will cause route
50
- * transitions to pause while loading data.
51
- */
52
- blocking?: boolean;
53
- /**
54
- * A function to call after the fetch happens (whether fake or not)
55
- */
56
- then?: (val: _Data | null) => void | Promise<void>;
57
- };
58
- export type LoadEventFetchParams<_Data extends GraphQLObject, _Input> = FetchGlobalParams<_Data, _Input> & {
59
- /**
60
- * Directly the `even` param coming from the `load` function
61
- */
62
- event?: LoadEvent;
63
- };
64
- export type RequestEventFetchParams<_Data extends GraphQLObject, _Input> = FetchGlobalParams<_Data, _Input> & {
65
- /**
66
- * A RequestEvent should be provided when the store is being used in an endpoint.
67
- * When this happens, fetch also needs to be provided
68
- */
69
- event?: RequestEvent;
70
- /**
71
- * The fetch function to use when using this store in an endpoint.
72
- */
73
- fetch?: LoadEvent['fetch'];
74
- };
75
- export type ClientFetchParams<_Data extends GraphQLObject, _Input> = FetchGlobalParams<_Data, _Input> & {
76
- /**
77
- * An object containing all of the current info necessary for a
78
- * client-side fetch. Must be called in component initialization with
79
- * something like this: `const context = getHoudiniFetchContext()`
80
- */
81
- context?: HoudiniFetchContext;
82
- };
83
- export type QueryStoreFetchParams<_Data extends GraphQLObject, _Input> = QueryStoreLoadParams<_Data, _Input> | ClientFetchParams<_Data, _Input>;
84
- export type QueryStoreLoadParams<_Data extends GraphQLObject, _Input> = LoadEventFetchParams<_Data, _Input> | RequestEventFetchParams<_Data, _Input>;
85
- export {};
@@ -1,8 +1,6 @@
1
- import type { FetchQueryResult, CompiledFragmentKind, QueryResult, GraphQLObject } from '$houdini/runtime/lib/types';
2
- import type { LoadEvent } from '@sveltejs/kit';
3
- import type { Readable, Writable } from 'svelte/store';
4
- import type { QueryStoreFetchParams } from './stores';
5
- import type { PageInfo } from './stores/pagination/pageInfo';
1
+ import type { FetchQueryResult, CompiledFragmentKind, QueryResult, GraphQLObject, CursorHandlers, OffsetHandlers, PageInfo, HoudiniFetchContext, FetchParams } from '$houdini/runtime/lib/types';
2
+ import type { LoadEvent, RequestEvent } from '@sveltejs/kit';
3
+ import type { Readable } from 'svelte/store';
6
4
  export type QueryInputs<_Data> = FetchQueryResult<_Data> & {
7
5
  variables: {
8
6
  [key: string]: any;
@@ -54,29 +52,43 @@ export type OffsetFragmentStoreInstance<_Data extends GraphQLObject, _Input> = {
54
52
  subscribe: Readable<Reshape<_Data, _Input>>['subscribe'];
55
53
  fetching: Readable<boolean>;
56
54
  } & OffsetHandlers<_Data, _Input>;
57
- export type CursorHandlers<_Data extends GraphQLObject, _Input> = {
58
- loadNextPage: (args?: {
59
- first?: number;
60
- after?: string;
61
- fetch?: typeof globalThis.fetch;
62
- metadata?: {};
63
- }) => Promise<void>;
64
- loadPreviousPage: (args?: {
65
- last?: number;
66
- before?: string;
67
- fetch?: typeof globalThis.fetch;
68
- metadata?: {};
69
- }) => Promise<void>;
70
- pageInfo: Writable<PageInfo>;
71
- fetch(args?: QueryStoreFetchParams<_Data, _Input> | undefined): Promise<QueryResult<_Data, _Input>>;
55
+ type FetchGlobalParams<_Data extends GraphQLObject, _Input> = FetchParams<_Input> & {
56
+ /**
57
+ * Set to true if you want the promise to pause while it's resolving.
58
+ * Only enable this if you know what you are doing. This will cause route
59
+ * transitions to pause while loading data.
60
+ */
61
+ blocking?: boolean;
62
+ /**
63
+ * A function to call after the fetch happens (whether fake or not)
64
+ */
65
+ then?: (val: _Data | null) => void | Promise<void>;
72
66
  };
73
- export type OffsetHandlers<_Data extends GraphQLObject, _Input> = {
74
- loadNextPage: (args?: {
75
- limit?: number;
76
- offset?: number;
77
- metadata?: {};
78
- fetch?: typeof globalThis.fetch;
79
- }) => Promise<void>;
80
- fetch(args?: QueryStoreFetchParams<_Data, _Input> | undefined): Promise<QueryResult<_Data, _Input>>;
67
+ export type LoadEventFetchParams<_Data extends GraphQLObject, _Input> = FetchGlobalParams<_Data, _Input> & {
68
+ /**
69
+ * Directly the `even` param coming from the `load` function
70
+ */
71
+ event?: LoadEvent;
81
72
  };
73
+ export type RequestEventFetchParams<_Data extends GraphQLObject, _Input> = FetchGlobalParams<_Data, _Input> & {
74
+ /**
75
+ * A RequestEvent should be provided when the store is being used in an endpoint.
76
+ * When this happens, fetch also needs to be provided
77
+ */
78
+ event?: RequestEvent;
79
+ /**
80
+ * The fetch function to use when using this store in an endpoint.
81
+ */
82
+ fetch?: LoadEvent['fetch'];
83
+ };
84
+ export type ClientFetchParams<_Data extends GraphQLObject, _Input> = FetchGlobalParams<_Data, _Input> & {
85
+ /**
86
+ * An object containing all of the current info necessary for a
87
+ * client-side fetch. Must be called in component initialization with
88
+ * something like this: `const context = getHoudiniFetchContext()`
89
+ */
90
+ context?: HoudiniFetchContext;
91
+ };
92
+ export type QueryStoreFetchParams<_Data extends GraphQLObject, _Input> = QueryStoreLoadParams<_Data, _Input> | ClientFetchParams<_Data, _Input>;
93
+ export type QueryStoreLoadParams<_Data extends GraphQLObject, _Input> = LoadEventFetchParams<_Data, _Input> | RequestEventFetchParams<_Data, _Input>;
82
94
  export {};