houdini-react 1.3.14 → 2.0.0-go.1

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 (141) hide show
  1. package/package.json +89 -73
  2. package/shim.cjs +64 -0
  3. package/LICENSE +0 -21
  4. package/README.md +0 -36
  5. package/build/plugin/codegen/entries/documentWrappers.d.ts +0 -6
  6. package/build/plugin/codegen/entries/fallbacks.d.ts +0 -5
  7. package/build/plugin/codegen/entries/index.d.ts +0 -16
  8. package/build/plugin/codegen/entries/pages.d.ts +0 -2
  9. package/build/plugin/codegen/index.d.ts +0 -17
  10. package/build/plugin/codegen/manifest.d.ts +0 -5
  11. package/build/plugin/codegen/render.d.ts +0 -7
  12. package/build/plugin/codegen/router.d.ts +0 -7
  13. package/build/plugin/codegen/typeRoot.d.ts +0 -5
  14. package/build/plugin/config.d.ts +0 -4
  15. package/build/plugin/dedent.d.ts +0 -1
  16. package/build/plugin/extract.d.ts +0 -6
  17. package/build/plugin/index.d.ts +0 -5
  18. package/build/plugin/state.d.ts +0 -3
  19. package/build/plugin/transform.d.ts +0 -6
  20. package/build/plugin/vite.d.ts +0 -70
  21. package/build/plugin-cjs/index.js +0 -84192
  22. package/build/plugin-cjs/package.json +0 -1
  23. package/build/plugin-esm/index.js +0 -84184
  24. package/build/plugin-esm/package.json +0 -1
  25. package/build/runtime/client.d.ts +0 -3
  26. package/build/runtime/clientPlugin.d.ts +0 -3
  27. package/build/runtime/componentFields.d.ts +0 -9
  28. package/build/runtime/hooks/index.d.ts +0 -8
  29. package/build/runtime/hooks/useDeepCompareEffect.d.ts +0 -35
  30. package/build/runtime/hooks/useDocumentHandle.d.ts +0 -36
  31. package/build/runtime/hooks/useDocumentStore.d.ts +0 -11
  32. package/build/runtime/hooks/useDocumentSubscription.d.ts +0 -11
  33. package/build/runtime/hooks/useFragment.d.ts +0 -16
  34. package/build/runtime/hooks/useFragmentHandle.d.ts +0 -8
  35. package/build/runtime/hooks/useIsMounted.d.ts +0 -3
  36. package/build/runtime/hooks/useMutation.d.ts +0 -11
  37. package/build/runtime/hooks/useQuery.d.ts +0 -5
  38. package/build/runtime/hooks/useQueryHandle.d.ts +0 -10
  39. package/build/runtime/hooks/useSubscription.d.ts +0 -4
  40. package/build/runtime/hooks/useSubscriptionHandle.d.ts +0 -25
  41. package/build/runtime/index.d.ts +0 -14
  42. package/build/runtime/manifest.d.ts +0 -3
  43. package/build/runtime/routing/Router.d.ts +0 -62
  44. package/build/runtime/routing/cache.d.ts +0 -7
  45. package/build/runtime/routing/hooks.d.ts +0 -40
  46. package/build/runtime/routing/index.d.ts +0 -3
  47. package/build/runtime-cjs/client.d.ts +0 -3
  48. package/build/runtime-cjs/client.js +0 -27
  49. package/build/runtime-cjs/clientPlugin.d.ts +0 -3
  50. package/build/runtime-cjs/clientPlugin.js +0 -39
  51. package/build/runtime-cjs/componentFields.d.ts +0 -9
  52. package/build/runtime-cjs/componentFields.js +0 -83
  53. package/build/runtime-cjs/hooks/index.d.ts +0 -8
  54. package/build/runtime-cjs/hooks/index.js +0 -45
  55. package/build/runtime-cjs/hooks/useDeepCompareEffect.d.ts +0 -35
  56. package/build/runtime-cjs/hooks/useDeepCompareEffect.js +0 -72
  57. package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +0 -36
  58. package/build/runtime-cjs/hooks/useDocumentHandle.js +0 -173
  59. package/build/runtime-cjs/hooks/useDocumentStore.d.ts +0 -11
  60. package/build/runtime-cjs/hooks/useDocumentStore.js +0 -72
  61. package/build/runtime-cjs/hooks/useDocumentSubscription.d.ts +0 -11
  62. package/build/runtime-cjs/hooks/useDocumentSubscription.js +0 -71
  63. package/build/runtime-cjs/hooks/useFragment.d.ts +0 -16
  64. package/build/runtime-cjs/hooks/useFragment.js +0 -97
  65. package/build/runtime-cjs/hooks/useFragmentHandle.d.ts +0 -8
  66. package/build/runtime-cjs/hooks/useFragmentHandle.js +0 -47
  67. package/build/runtime-cjs/hooks/useIsMounted.d.ts +0 -3
  68. package/build/runtime-cjs/hooks/useIsMounted.js +0 -38
  69. package/build/runtime-cjs/hooks/useMutation.d.ts +0 -11
  70. package/build/runtime-cjs/hooks/useMutation.js +0 -52
  71. package/build/runtime-cjs/hooks/useQuery.d.ts +0 -5
  72. package/build/runtime-cjs/hooks/useQuery.js +0 -32
  73. package/build/runtime-cjs/hooks/useQueryHandle.d.ts +0 -10
  74. package/build/runtime-cjs/hooks/useQueryHandle.js +0 -125
  75. package/build/runtime-cjs/hooks/useSubscription.d.ts +0 -4
  76. package/build/runtime-cjs/hooks/useSubscription.js +0 -32
  77. package/build/runtime-cjs/hooks/useSubscriptionHandle.d.ts +0 -25
  78. package/build/runtime-cjs/hooks/useSubscriptionHandle.js +0 -42
  79. package/build/runtime-cjs/index.d.ts +0 -14
  80. package/build/runtime-cjs/index.js +0 -83
  81. package/build/runtime-cjs/manifest.d.ts +0 -3
  82. package/build/runtime-cjs/manifest.js +0 -27
  83. package/build/runtime-cjs/package.json +0 -1
  84. package/build/runtime-cjs/routing/Router.d.ts +0 -62
  85. package/build/runtime-cjs/routing/Router.js +0 -532
  86. package/build/runtime-cjs/routing/cache.d.ts +0 -7
  87. package/build/runtime-cjs/routing/cache.js +0 -58
  88. package/build/runtime-cjs/routing/hooks.d.ts +0 -40
  89. package/build/runtime-cjs/routing/hooks.js +0 -89
  90. package/build/runtime-cjs/routing/index.d.ts +0 -3
  91. package/build/runtime-cjs/routing/index.js +0 -31
  92. package/build/runtime-esm/client.d.ts +0 -3
  93. package/build/runtime-esm/client.js +0 -5
  94. package/build/runtime-esm/clientPlugin.d.ts +0 -3
  95. package/build/runtime-esm/clientPlugin.js +0 -17
  96. package/build/runtime-esm/componentFields.d.ts +0 -9
  97. package/build/runtime-esm/componentFields.js +0 -59
  98. package/build/runtime-esm/hooks/index.d.ts +0 -8
  99. package/build/runtime-esm/hooks/index.js +0 -16
  100. package/build/runtime-esm/hooks/useDeepCompareEffect.d.ts +0 -35
  101. package/build/runtime-esm/hooks/useDeepCompareEffect.js +0 -41
  102. package/build/runtime-esm/hooks/useDocumentHandle.d.ts +0 -36
  103. package/build/runtime-esm/hooks/useDocumentHandle.js +0 -143
  104. package/build/runtime-esm/hooks/useDocumentStore.d.ts +0 -11
  105. package/build/runtime-esm/hooks/useDocumentStore.js +0 -42
  106. package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +0 -11
  107. package/build/runtime-esm/hooks/useDocumentSubscription.js +0 -41
  108. package/build/runtime-esm/hooks/useFragment.d.ts +0 -16
  109. package/build/runtime-esm/hooks/useFragment.js +0 -66
  110. package/build/runtime-esm/hooks/useFragmentHandle.d.ts +0 -8
  111. package/build/runtime-esm/hooks/useFragmentHandle.js +0 -23
  112. package/build/runtime-esm/hooks/useIsMounted.d.ts +0 -3
  113. package/build/runtime-esm/hooks/useIsMounted.js +0 -14
  114. package/build/runtime-esm/hooks/useMutation.d.ts +0 -11
  115. package/build/runtime-esm/hooks/useMutation.js +0 -28
  116. package/build/runtime-esm/hooks/useQuery.d.ts +0 -5
  117. package/build/runtime-esm/hooks/useQuery.js +0 -8
  118. package/build/runtime-esm/hooks/useQueryHandle.d.ts +0 -10
  119. package/build/runtime-esm/hooks/useQueryHandle.js +0 -95
  120. package/build/runtime-esm/hooks/useSubscription.d.ts +0 -4
  121. package/build/runtime-esm/hooks/useSubscription.js +0 -8
  122. package/build/runtime-esm/hooks/useSubscriptionHandle.d.ts +0 -25
  123. package/build/runtime-esm/hooks/useSubscriptionHandle.js +0 -18
  124. package/build/runtime-esm/index.d.ts +0 -14
  125. package/build/runtime-esm/index.js +0 -48
  126. package/build/runtime-esm/manifest.d.ts +0 -3
  127. package/build/runtime-esm/manifest.js +0 -5
  128. package/build/runtime-esm/package.json +0 -1
  129. package/build/runtime-esm/routing/Router.d.ts +0 -62
  130. package/build/runtime-esm/routing/Router.js +0 -495
  131. package/build/runtime-esm/routing/cache.d.ts +0 -7
  132. package/build/runtime-esm/routing/cache.js +0 -33
  133. package/build/runtime-esm/routing/hooks.d.ts +0 -40
  134. package/build/runtime-esm/routing/hooks.js +0 -53
  135. package/build/runtime-esm/routing/index.d.ts +0 -3
  136. package/build/runtime-esm/routing/index.js +0 -6
  137. package/build/server/index.d.ts +0 -1
  138. package/build/server-cjs/index.js +0 -28
  139. package/build/server-cjs/package.json +0 -1
  140. package/build/server-esm/index.js +0 -4
  141. package/build/server-esm/package.json +0 -1
@@ -1,89 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
- var hooks_exports = {};
26
- __export(hooks_exports, {
27
- Context: () => Context,
28
- LocationContext: () => LocationContext,
29
- useCache: () => useCache,
30
- useClient: () => useClient,
31
- useLocation: () => useLocation,
32
- useRouterContext: () => useRouterContext,
33
- useSession: () => useSession
34
- });
35
- module.exports = __toCommonJS(hooks_exports);
36
- var import_config = __toESM(require("$houdini/runtime/imports/config"));
37
- var import_react = __toESM(require("react"));
38
- const Context = import_react.default.createContext(null);
39
- const LocationContext = import_react.default.createContext({
40
- pathname: "",
41
- params: {},
42
- goto: () => {
43
- }
44
- });
45
- const useLocation = () => (0, import_react.useContext)(LocationContext);
46
- const useRouterContext = () => {
47
- const ctx = import_react.default.useContext(Context);
48
- if (!ctx) {
49
- throw new Error("Could not find router context");
50
- }
51
- return ctx;
52
- };
53
- function useClient() {
54
- return useRouterContext().client;
55
- }
56
- function useCache() {
57
- return useRouterContext().cache;
58
- }
59
- function useSession() {
60
- const ctx = useRouterContext();
61
- const updateSession = (newSession) => {
62
- ctx.data_cache.clear();
63
- ctx.setSession(newSession);
64
- const auth = import_config.default.router?.auth;
65
- if (!auth) {
66
- return;
67
- }
68
- const url = "redirect" in auth ? auth.redirect : auth.url;
69
- fetch(url, {
70
- method: "POST",
71
- body: JSON.stringify(newSession),
72
- headers: {
73
- "Content-Type": "application/json",
74
- Accept: "application/json"
75
- }
76
- });
77
- };
78
- return [ctx.session, updateSession];
79
- }
80
- // Annotate the CommonJS export names for ESM import in node:
81
- 0 && (module.exports = {
82
- Context,
83
- LocationContext,
84
- useCache,
85
- useClient,
86
- useLocation,
87
- useRouterContext,
88
- useSession
89
- });
@@ -1,3 +0,0 @@
1
- export * from './Router';
2
- export * from './hooks';
3
- export { type SuspenseCache, suspense_cache } from './cache';
@@ -1,31 +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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var routing_exports = {};
21
- __export(routing_exports, {
22
- suspense_cache: () => import_cache.suspense_cache
23
- });
24
- module.exports = __toCommonJS(routing_exports);
25
- __reExport(routing_exports, require("./Router"), module.exports);
26
- __reExport(routing_exports, require("./hooks"), module.exports);
27
- var import_cache = require("./cache");
28
- // Annotate the CommonJS export names for ESM import in node:
29
- 0 && (module.exports = {
30
- suspense_cache
31
- });
@@ -1,3 +0,0 @@
1
- import type { HoudiniClient } from '$houdini/runtime/client';
2
- declare const _default: () => HoudiniClient;
3
- export default _default;
@@ -1,5 +0,0 @@
1
- var client_default = () => {
2
- };
3
- export {
4
- client_default as default
5
- };
@@ -1,3 +0,0 @@
1
- import type { ClientPlugin } from 'houdini';
2
- declare const plugin: () => ClientPlugin;
3
- export default plugin;
@@ -1,17 +0,0 @@
1
- const plugin = () => () => {
2
- return {
3
- start(ctx, { next }) {
4
- next({
5
- ...ctx,
6
- cacheParams: {
7
- ...ctx.cacheParams,
8
- serverSideFallback: false
9
- }
10
- });
11
- }
12
- };
13
- };
14
- var clientPlugin_default = plugin;
15
- export {
16
- clientPlugin_default as default
17
- };
@@ -1,9 +0,0 @@
1
- import { type Cache } from '$houdini/runtime/cache/cache';
2
- import type { DocumentArtifact, GraphQLValue } from 'houdini';
3
- export declare function injectComponents({ cache, selection, data, variables, parentType, }: {
4
- cache: Cache;
5
- selection: DocumentArtifact['selection'];
6
- data: GraphQLValue | null;
7
- variables: Record<string, GraphQLValue> | undefined | null;
8
- parentType?: string;
9
- }): void;
@@ -1,59 +0,0 @@
1
- import { defaultComponentField } from "$houdini/runtime/cache/cache";
2
- import { getFieldsForType } from "$houdini/runtime/lib/selection";
3
- function injectComponents({
4
- cache,
5
- selection,
6
- data,
7
- variables,
8
- parentType = "Query"
9
- }) {
10
- if (data === null) {
11
- return;
12
- }
13
- if (typeof data !== "object") {
14
- return;
15
- }
16
- if (Array.isArray(data)) {
17
- data.forEach(
18
- (item) => injectComponents({
19
- cache,
20
- selection,
21
- data: item,
22
- variables,
23
- parentType
24
- })
25
- );
26
- return;
27
- }
28
- const typename = data["__typename"];
29
- const fields = getFieldsForType(selection, typename, false);
30
- if (!fields) {
31
- return;
32
- }
33
- for (const [field, subSelection] of Object.entries(fields)) {
34
- if (subSelection.component) {
35
- if (!cache._internal_unstable.componentCache[subSelection.component.key]) {
36
- continue;
37
- }
38
- data[field] = defaultComponentField({
39
- variables,
40
- parent: cache._internal_unstable.id(parentType, data) ?? "",
41
- cache,
42
- component: subSelection.component
43
- });
44
- }
45
- const dataValue = data[field];
46
- if (subSelection.selection) {
47
- injectComponents({
48
- cache,
49
- selection: subSelection.selection,
50
- data: dataValue,
51
- variables,
52
- parentType: subSelection.type
53
- });
54
- }
55
- }
56
- }
57
- export {
58
- injectComponents
59
- };
@@ -1,8 +0,0 @@
1
- export { useQuery } from './useQuery';
2
- export { useQueryHandle } from './useQueryHandle';
3
- export { useFragment } from './useFragment';
4
- export { useFragmentHandle } from './useFragmentHandle';
5
- export { useMutation } from './useMutation';
6
- export { useSubscription } from './useSubscription';
7
- export { type DocumentHandle } from './useDocumentHandle';
8
- export { type UseQueryConfig } from './useQueryHandle';
@@ -1,16 +0,0 @@
1
- import { useQuery } from "./useQuery";
2
- import { useQueryHandle } from "./useQueryHandle";
3
- import { useFragment } from "./useFragment";
4
- import { useFragmentHandle } from "./useFragmentHandle";
5
- import { useMutation } from "./useMutation";
6
- import { useSubscription } from "./useSubscription";
7
- import {} from "./useDocumentHandle";
8
- import {} from "./useQueryHandle";
9
- export {
10
- useFragment,
11
- useFragmentHandle,
12
- useMutation,
13
- useQuery,
14
- useQueryHandle,
15
- useSubscription
16
- };
@@ -1,35 +0,0 @@
1
- import * as React from 'react';
2
- type UseEffectParams = Parameters<typeof React.useEffect>;
3
- type EffectCallback = UseEffectParams[0];
4
- type DependencyList = UseEffectParams[1];
5
- type UseEffectReturn = ReturnType<typeof React.useEffect>;
6
- /**
7
- * @param value the value to be memoized (usually a dependency list)
8
- * @returns a memoized version of the value as long as it remains deeply equal
9
- */
10
- export declare function useDeepCompareMemoize<T>(value: T): T;
11
- declare function useDeepCompareEffect(callback: EffectCallback, dependencies: DependencyList): UseEffectReturn;
12
- export declare function useDeepCompareEffectNoCheck(callback: EffectCallback, dependencies: DependencyList): UseEffectReturn;
13
- export default useDeepCompareEffect;
14
- /**
15
- The MIT License (MIT)
16
- Copyright (c) 2020 Kent C. Dodds
17
-
18
- Permission is hereby granted, free of charge, to any person obtaining a copy
19
- of this software and associated documentation files (the "Software"), to deal
20
- in the Software without restriction, including without limitation the rights
21
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22
- copies of the Software, and to permit persons to whom the Software is
23
- furnished to do so, subject to the following conditions:
24
-
25
- The above copyright notice and this permission notice shall be included in all
26
- copies or substantial portions of the Software.
27
-
28
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34
- SOFTWARE.
35
- */
@@ -1,41 +0,0 @@
1
- import { deepEquals } from "$houdini/runtime/lib/deepEquals";
2
- import * as React from "react";
3
- function checkDeps(deps) {
4
- if (!deps || !deps.length) {
5
- throw new Error(
6
- "useDeepCompareEffect should not be used with no dependencies. Use React.useEffect instead."
7
- );
8
- }
9
- if (deps.every(isPrimitive)) {
10
- throw new Error(
11
- "useDeepCompareEffect should not be used with dependencies that are all primitive values. Use React.useEffect instead."
12
- );
13
- }
14
- }
15
- function isPrimitive(val) {
16
- return val == null || /^[sbn]/.test(typeof val);
17
- }
18
- function useDeepCompareMemoize(value) {
19
- const ref = React.useRef(value);
20
- const signalRef = React.useRef(0);
21
- if (!deepEquals(value, ref.current)) {
22
- ref.current = value;
23
- signalRef.current += 1;
24
- }
25
- return React.useMemo(() => ref.current, [signalRef.current]);
26
- }
27
- function useDeepCompareEffect(callback, dependencies) {
28
- if (process.env.NODE_ENV !== "production") {
29
- checkDeps(dependencies);
30
- }
31
- return React.useEffect(callback, useDeepCompareMemoize(dependencies));
32
- }
33
- function useDeepCompareEffectNoCheck(callback, dependencies) {
34
- return React.useEffect(callback, useDeepCompareMemoize(dependencies));
35
- }
36
- var useDeepCompareEffect_default = useDeepCompareEffect;
37
- export {
38
- useDeepCompareEffect_default as default,
39
- useDeepCompareEffectNoCheck,
40
- useDeepCompareMemoize
41
- };
@@ -1,36 +0,0 @@
1
- import type { DocumentStore } from '$houdini/runtime/client';
2
- import type { GraphQLObject, GraphQLVariables, CursorHandlers, OffsetHandlers, PageInfo, FetchFn, QueryResult, DocumentArtifact, QueryArtifact } from '$houdini/runtime/lib/types';
3
- export declare function useDocumentHandle<_Artifact extends QueryArtifact, _Data extends GraphQLObject, _Input extends GraphQLVariables>({ artifact, observer, storeValue, }: {
4
- artifact: DocumentArtifact;
5
- observer: DocumentStore<_Data, _Input>;
6
- storeValue: QueryResult<_Data, _Input>;
7
- }): DocumentHandle<_Artifact, _Data, _Input> & {
8
- fetch: FetchFn<_Data, _Input>;
9
- };
10
- export type DocumentHandle<_Artifact extends QueryArtifact, _Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables> = {
11
- data: _Data;
12
- partial: boolean;
13
- fetch: FetchFn<_Data, Partial<_Input>>;
14
- variables: _Input;
15
- } & RefetchHandlers<_Artifact, _Data, _Input>;
16
- type RefetchHandlers<_Artifact extends QueryArtifact, _Data extends GraphQLObject, _Input> = _Artifact extends {
17
- refetch: {
18
- paginated: true;
19
- method: 'cursor';
20
- };
21
- } ? {
22
- loadNext: CursorHandlers<_Data, _Input>['loadNextPage'];
23
- loadNextPending: boolean;
24
- loadPrevious: CursorHandlers<_Data, _Input>['loadPreviousPage'];
25
- loadPreviousPending: boolean;
26
- pageInfo: PageInfo;
27
- } : _Artifact extends {
28
- refetch: {
29
- paginated: true;
30
- method: 'offset';
31
- };
32
- } ? {
33
- loadNext: OffsetHandlers<_Data, _Input>['loadNextPage'];
34
- loadNextPending: boolean;
35
- } : {};
36
- export {};
@@ -1,143 +0,0 @@
1
- import { extractPageInfo } from "$houdini/runtime/lib/pageInfo";
2
- import { cursorHandlers, offsetHandlers } from "$houdini/runtime/lib/pagination";
3
- import { ArtifactKind } from "$houdini/runtime/lib/types";
4
- import React from "react";
5
- import { useClient, useSession, useLocation } from "../routing/hooks";
6
- function useDocumentHandle({
7
- artifact,
8
- observer,
9
- storeValue
10
- }) {
11
- const [forwardPending, setForwardPending] = React.useState(false);
12
- const [backwardPending, setBackwardPending] = React.useState(false);
13
- const location = useLocation();
14
- const [session] = useSession();
15
- const client = useClient();
16
- const paginationObserver = React.useMemo(() => {
17
- if (!artifact.refetch?.paginated) {
18
- return null;
19
- }
20
- return client.observe({ artifact });
21
- }, [artifact.name]);
22
- return React.useMemo(() => {
23
- const wrapLoad = (setLoading, fn) => {
24
- return async (value) => {
25
- setLoading(true);
26
- let result = null;
27
- let err = null;
28
- try {
29
- result = await fn(value);
30
- } catch (e) {
31
- err = e;
32
- }
33
- setLoading(false);
34
- if (err && err.name !== "AbortError") {
35
- throw err;
36
- }
37
- return result || observer.state;
38
- };
39
- };
40
- const fetchQuery = (args) => {
41
- const usedVariables = Object.fromEntries(
42
- Object.keys(observer.artifact.input?.fields ?? {}).reduce(
43
- (entries, fieldName) => {
44
- if (!(fieldName in location.params)) {
45
- return entries;
46
- }
47
- return [...entries, [fieldName, location.params[fieldName]]];
48
- },
49
- []
50
- )
51
- );
52
- return observer.send({
53
- ...args,
54
- variables: {
55
- ...usedVariables,
56
- ...args?.variables
57
- },
58
- session
59
- });
60
- };
61
- if (artifact.kind !== ArtifactKind.Query || !artifact.refetch?.paginated) {
62
- return {
63
- artifact,
64
- data: storeValue.data,
65
- variables: storeValue.variables,
66
- fetch: fetchQuery,
67
- partial: storeValue.partial
68
- };
69
- }
70
- if (artifact.refetch.method === "cursor") {
71
- const handlers = cursorHandlers({
72
- artifact,
73
- getState: () => storeValue.data,
74
- getVariables: () => storeValue.variables,
75
- fetch: fetchQuery,
76
- fetchUpdate: (args, updates) => {
77
- return paginationObserver.send({
78
- ...args,
79
- cacheParams: {
80
- ...args?.cacheParams,
81
- disableSubscriptions: true,
82
- applyUpdates: updates
83
- },
84
- session
85
- });
86
- },
87
- getSession: async () => session
88
- });
89
- return {
90
- artifact,
91
- data: storeValue.data,
92
- variables: storeValue.variables,
93
- fetch: handlers.fetch,
94
- partial: storeValue.partial,
95
- loadNext: wrapLoad(setForwardPending, handlers.loadNextPage),
96
- loadNextPending: forwardPending,
97
- loadPrevious: wrapLoad(setBackwardPending, handlers.loadPreviousPage),
98
- loadPreviousPending: backwardPending,
99
- pageInfo: extractPageInfo(storeValue.data, artifact.refetch.path)
100
- };
101
- }
102
- if (artifact.refetch.method === "offset") {
103
- const handlers = offsetHandlers({
104
- artifact,
105
- getState: () => storeValue.data,
106
- getVariables: () => storeValue.variables,
107
- storeName: artifact.name,
108
- fetch: fetchQuery,
109
- fetchUpdate: async (args, updates = ["append"]) => {
110
- return paginationObserver.send({
111
- ...args,
112
- cacheParams: {
113
- disableSubscriptions: true,
114
- applyUpdates: updates,
115
- ...args?.cacheParams
116
- }
117
- });
118
- },
119
- getSession: async () => session
120
- });
121
- return {
122
- artifact,
123
- data: storeValue.data,
124
- variables: storeValue.variables,
125
- fetch: handlers.fetch,
126
- partial: storeValue.partial,
127
- loadNext: wrapLoad(setForwardPending, handlers.loadNextPage),
128
- loadNextPending: forwardPending
129
- };
130
- }
131
- return {
132
- artifact,
133
- data: storeValue.data,
134
- variables: storeValue.variables,
135
- fetch: fetchQuery,
136
- refetch: fetchQuery,
137
- partial: storeValue.partial
138
- };
139
- }, [artifact, observer, session, storeValue]);
140
- }
141
- export {
142
- useDocumentHandle
143
- };
@@ -1,11 +0,0 @@
1
- import type { DocumentArtifact, GraphQLVariables, QueryResult } from '$houdini/lib/types';
2
- import type { DocumentStore, ObserveParams } from '$houdini/runtime/client';
3
- import type { GraphQLObject } from 'houdini';
4
- export type UseDocumentStoreParams<_Artifact extends DocumentArtifact, _Data extends GraphQLObject, _Input extends GraphQLVariables> = {
5
- artifact: _Artifact;
6
- observer?: DocumentStore<_Data, _Input>;
7
- } & Partial<ObserveParams<_Data, DocumentArtifact, _Input>>;
8
- export declare function useDocumentStore<_Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables, _Artifact extends DocumentArtifact = DocumentArtifact>({ artifact, observer: obs, ...observeParams }: UseDocumentStoreParams<_Artifact, _Data, _Input>): [
9
- QueryResult<_Data, _Input>,
10
- DocumentStore<_Data, _Input>
11
- ];
@@ -1,42 +0,0 @@
1
- import * as React from "react";
2
- import { useClient } from "../routing/hooks";
3
- import { useIsMountedRef } from "./useIsMounted";
4
- function useDocumentStore({
5
- artifact,
6
- observer: obs,
7
- ...observeParams
8
- }) {
9
- const client = useClient();
10
- const isMountedRef = useIsMountedRef();
11
- let [observer, setObserver] = React.useState(
12
- () => obs ?? client.observe({
13
- artifact,
14
- ...observeParams
15
- })
16
- );
17
- const box = React.useRef(observer.state);
18
- if (obs && obs !== observer) {
19
- box.current = obs.state;
20
- setObserver(obs);
21
- }
22
- const subscribe = React.useCallback(
23
- (fn) => {
24
- return observer.subscribe((val) => {
25
- box.current = val;
26
- if (isMountedRef.current) {
27
- fn();
28
- }
29
- });
30
- },
31
- [observer]
32
- );
33
- const storeValue = React.useSyncExternalStore(
34
- subscribe,
35
- () => box.current,
36
- () => box.current
37
- );
38
- return [storeValue, observer];
39
- }
40
- export {
41
- useDocumentStore
42
- };
@@ -1,11 +0,0 @@
1
- import type { DocumentArtifact, GraphQLVariables, QueryResult } from '$houdini/lib/types';
2
- import type { DocumentStore, SendParams } from '$houdini/runtime/client';
3
- import type { GraphQLObject } from 'houdini';
4
- import { type UseDocumentStoreParams } from './useDocumentStore';
5
- export declare function useDocumentSubscription<_Artifact extends DocumentArtifact = DocumentArtifact, _Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables>({ artifact, variables, send, disabled, ...observeParams }: UseDocumentStoreParams<_Artifact, _Data, _Input> & {
6
- variables: _Input;
7
- disabled?: boolean;
8
- send?: Partial<SendParams>;
9
- }): [QueryResult<_Data, _Input> & {
10
- parent?: string | null;
11
- }, DocumentStore<_Data, _Input>];
@@ -1,41 +0,0 @@
1
- import { useSession } from "../routing/hooks";
2
- import useDeepCompareEffect from "./useDeepCompareEffect";
3
- import { useDocumentStore } from "./useDocumentStore";
4
- function useDocumentSubscription({
5
- artifact,
6
- variables,
7
- send,
8
- disabled,
9
- ...observeParams
10
- }) {
11
- const [storeValue, observer] = useDocumentStore({
12
- artifact,
13
- ...observeParams
14
- });
15
- const [session] = useSession();
16
- useDeepCompareEffect(() => {
17
- if (!disabled) {
18
- observer.send({
19
- variables,
20
- session,
21
- metadata: {},
22
- ...send
23
- });
24
- }
25
- return () => {
26
- if (!disabled) {
27
- observer.cleanup();
28
- }
29
- };
30
- }, [disabled, session, observer, variables ?? {}, send ?? {}]);
31
- return [
32
- {
33
- parent: send?.stuff?.parentID,
34
- ...storeValue
35
- },
36
- observer
37
- ];
38
- }
39
- export {
40
- useDocumentSubscription
41
- };
@@ -1,16 +0,0 @@
1
- import { fragmentKey } from '$houdini/runtime/lib/types';
2
- import type { GraphQLObject, GraphQLVariables, FragmentArtifact } from '$houdini/runtime/lib/types';
3
- export declare function useFragment<_Data extends GraphQLObject, _ReferenceType extends {}, _Input extends GraphQLVariables = GraphQLVariables>(reference: _Data | {
4
- [fragmentKey]: _ReferenceType;
5
- } | null, document: {
6
- artifact: FragmentArtifact;
7
- }): _Data | null;
8
- export declare function fragmentReference<_Data extends GraphQLObject, _Input, _ReferenceType extends {}>(reference: _Data | {
9
- [fragmentKey]: _ReferenceType;
10
- } | null, document: {
11
- artifact: FragmentArtifact;
12
- }): {
13
- variables: _Input;
14
- parent: string;
15
- loading: boolean;
16
- };