houdini-react 2.0.0-next.2 → 2.0.0-next.23

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 (171) hide show
  1. package/bin/houdini-react +88 -0
  2. package/package.json +43 -22
  3. package/postInstall.js +353 -0
  4. package/runtime/client.ts +5 -0
  5. package/runtime/clientPlugin.ts +17 -0
  6. package/runtime/componentFields.ts +79 -0
  7. package/runtime/hooks/index.ts +9 -0
  8. package/runtime/hooks/useDeepCompareEffect.ts +91 -0
  9. package/runtime/hooks/useDocumentHandle.ts +232 -0
  10. package/runtime/hooks/useDocumentStore.ts +76 -0
  11. package/runtime/hooks/useDocumentSubscription.ts +62 -0
  12. package/runtime/hooks/useFragment.ts +93 -0
  13. package/runtime/hooks/useFragmentHandle.ts +46 -0
  14. package/runtime/hooks/useIsMounted.ts +14 -0
  15. package/runtime/hooks/useMutation.ts +70 -0
  16. package/runtime/hooks/useQuery.ts +12 -0
  17. package/runtime/hooks/useQueryHandle.ts +185 -0
  18. package/runtime/hooks/useSubscription.ts +12 -0
  19. package/runtime/hooks/useSubscriptionHandle.ts +33 -0
  20. package/runtime/hydration.tsx +155 -0
  21. package/runtime/index.tsx +49 -0
  22. package/runtime/manifest.ts +6 -0
  23. package/runtime/package.json +1 -0
  24. package/runtime/routing/Router.tsx +885 -0
  25. package/runtime/routing/cache.ts +54 -0
  26. package/runtime/routing/index.ts +2 -0
  27. package/server/index.d.ts +1 -0
  28. package/server/index.js +4 -0
  29. package/server/react-streaming.d.js +0 -0
  30. package/vite/index.d.ts +3 -0
  31. package/vite/index.js +284 -0
  32. package/vite/transform.d.ts +11 -0
  33. package/vite/transform.js +92 -0
  34. package/README.md +0 -36
  35. package/build/plugin/codegen/entries/documentWrappers.d.ts +0 -6
  36. package/build/plugin/codegen/entries/fallbacks.d.ts +0 -5
  37. package/build/plugin/codegen/entries/index.d.ts +0 -16
  38. package/build/plugin/codegen/entries/pages.d.ts +0 -2
  39. package/build/plugin/codegen/index.d.ts +0 -17
  40. package/build/plugin/codegen/manifest.d.ts +0 -5
  41. package/build/plugin/codegen/render.d.ts +0 -7
  42. package/build/plugin/codegen/router.d.ts +0 -7
  43. package/build/plugin/codegen/typeRoot.d.ts +0 -5
  44. package/build/plugin/config.d.ts +0 -4
  45. package/build/plugin/dedent.d.ts +0 -1
  46. package/build/plugin/extract.d.ts +0 -6
  47. package/build/plugin/index.d.ts +0 -5
  48. package/build/plugin/state.d.ts +0 -3
  49. package/build/plugin/transform.d.ts +0 -6
  50. package/build/plugin/vite.d.ts +0 -27
  51. package/build/plugin-cjs/index.js +0 -90119
  52. package/build/plugin-cjs/package.json +0 -1
  53. package/build/plugin-esm/index.js +0 -90115
  54. package/build/runtime/client.d.ts +0 -3
  55. package/build/runtime/clientPlugin.d.ts +0 -3
  56. package/build/runtime/componentFields.d.ts +0 -9
  57. package/build/runtime/hooks/index.d.ts +0 -8
  58. package/build/runtime/hooks/useDeepCompareEffect.d.ts +0 -35
  59. package/build/runtime/hooks/useDocumentHandle.d.ts +0 -36
  60. package/build/runtime/hooks/useDocumentStore.d.ts +0 -11
  61. package/build/runtime/hooks/useDocumentSubscription.d.ts +0 -11
  62. package/build/runtime/hooks/useFragment.d.ts +0 -16
  63. package/build/runtime/hooks/useFragmentHandle.d.ts +0 -8
  64. package/build/runtime/hooks/useIsMounted.d.ts +0 -3
  65. package/build/runtime/hooks/useMutation.d.ts +0 -14
  66. package/build/runtime/hooks/useQuery.d.ts +0 -5
  67. package/build/runtime/hooks/useQueryHandle.d.ts +0 -10
  68. package/build/runtime/hooks/useSubscription.d.ts +0 -4
  69. package/build/runtime/hooks/useSubscriptionHandle.d.ts +0 -25
  70. package/build/runtime/index.d.ts +0 -14
  71. package/build/runtime/manifest.d.ts +0 -3
  72. package/build/runtime/routing/Router.d.ts +0 -62
  73. package/build/runtime/routing/cache.d.ts +0 -7
  74. package/build/runtime/routing/hooks.d.ts +0 -40
  75. package/build/runtime/routing/index.d.ts +0 -3
  76. package/build/runtime-cjs/client.d.ts +0 -3
  77. package/build/runtime-cjs/client.js +0 -25
  78. package/build/runtime-cjs/clientPlugin.d.ts +0 -3
  79. package/build/runtime-cjs/clientPlugin.js +0 -37
  80. package/build/runtime-cjs/componentFields.d.ts +0 -9
  81. package/build/runtime-cjs/componentFields.js +0 -83
  82. package/build/runtime-cjs/hooks/index.d.ts +0 -8
  83. package/build/runtime-cjs/hooks/index.js +0 -45
  84. package/build/runtime-cjs/hooks/useDeepCompareEffect.d.ts +0 -35
  85. package/build/runtime-cjs/hooks/useDeepCompareEffect.js +0 -76
  86. package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +0 -36
  87. package/build/runtime-cjs/hooks/useDocumentHandle.js +0 -177
  88. package/build/runtime-cjs/hooks/useDocumentStore.d.ts +0 -11
  89. package/build/runtime-cjs/hooks/useDocumentStore.js +0 -76
  90. package/build/runtime-cjs/hooks/useDocumentSubscription.d.ts +0 -11
  91. package/build/runtime-cjs/hooks/useDocumentSubscription.js +0 -76
  92. package/build/runtime-cjs/hooks/useFragment.d.ts +0 -16
  93. package/build/runtime-cjs/hooks/useFragment.js +0 -102
  94. package/build/runtime-cjs/hooks/useFragmentHandle.d.ts +0 -8
  95. package/build/runtime-cjs/hooks/useFragmentHandle.js +0 -47
  96. package/build/runtime-cjs/hooks/useIsMounted.d.ts +0 -3
  97. package/build/runtime-cjs/hooks/useIsMounted.js +0 -38
  98. package/build/runtime-cjs/hooks/useMutation.d.ts +0 -14
  99. package/build/runtime-cjs/hooks/useMutation.js +0 -67
  100. package/build/runtime-cjs/hooks/useQuery.d.ts +0 -5
  101. package/build/runtime-cjs/hooks/useQuery.js +0 -32
  102. package/build/runtime-cjs/hooks/useQueryHandle.d.ts +0 -10
  103. package/build/runtime-cjs/hooks/useQueryHandle.js +0 -131
  104. package/build/runtime-cjs/hooks/useSubscription.d.ts +0 -4
  105. package/build/runtime-cjs/hooks/useSubscription.js +0 -32
  106. package/build/runtime-cjs/hooks/useSubscriptionHandle.d.ts +0 -25
  107. package/build/runtime-cjs/hooks/useSubscriptionHandle.js +0 -42
  108. package/build/runtime-cjs/index.d.ts +0 -14
  109. package/build/runtime-cjs/index.js +0 -88
  110. package/build/runtime-cjs/manifest.d.ts +0 -3
  111. package/build/runtime-cjs/manifest.js +0 -25
  112. package/build/runtime-cjs/package.json +0 -1
  113. package/build/runtime-cjs/routing/Router.d.ts +0 -62
  114. package/build/runtime-cjs/routing/Router.js +0 -540
  115. package/build/runtime-cjs/routing/cache.d.ts +0 -7
  116. package/build/runtime-cjs/routing/cache.js +0 -61
  117. package/build/runtime-cjs/routing/hooks.d.ts +0 -40
  118. package/build/runtime-cjs/routing/hooks.js +0 -93
  119. package/build/runtime-cjs/routing/index.d.ts +0 -3
  120. package/build/runtime-cjs/routing/index.js +0 -33
  121. package/build/runtime-esm/client.d.ts +0 -3
  122. package/build/runtime-esm/client.js +0 -5
  123. package/build/runtime-esm/clientPlugin.d.ts +0 -3
  124. package/build/runtime-esm/clientPlugin.js +0 -17
  125. package/build/runtime-esm/componentFields.d.ts +0 -9
  126. package/build/runtime-esm/componentFields.js +0 -59
  127. package/build/runtime-esm/hooks/index.d.ts +0 -8
  128. package/build/runtime-esm/hooks/index.js +0 -15
  129. package/build/runtime-esm/hooks/useDeepCompareEffect.d.ts +0 -35
  130. package/build/runtime-esm/hooks/useDeepCompareEffect.js +0 -41
  131. package/build/runtime-esm/hooks/useDocumentHandle.d.ts +0 -36
  132. package/build/runtime-esm/hooks/useDocumentHandle.js +0 -143
  133. package/build/runtime-esm/hooks/useDocumentStore.d.ts +0 -11
  134. package/build/runtime-esm/hooks/useDocumentStore.js +0 -42
  135. package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +0 -11
  136. package/build/runtime-esm/hooks/useDocumentSubscription.js +0 -42
  137. package/build/runtime-esm/hooks/useFragment.d.ts +0 -16
  138. package/build/runtime-esm/hooks/useFragment.js +0 -67
  139. package/build/runtime-esm/hooks/useFragmentHandle.d.ts +0 -8
  140. package/build/runtime-esm/hooks/useFragmentHandle.js +0 -23
  141. package/build/runtime-esm/hooks/useIsMounted.d.ts +0 -3
  142. package/build/runtime-esm/hooks/useIsMounted.js +0 -14
  143. package/build/runtime-esm/hooks/useMutation.d.ts +0 -14
  144. package/build/runtime-esm/hooks/useMutation.js +0 -42
  145. package/build/runtime-esm/hooks/useQuery.d.ts +0 -5
  146. package/build/runtime-esm/hooks/useQuery.js +0 -8
  147. package/build/runtime-esm/hooks/useQueryHandle.d.ts +0 -10
  148. package/build/runtime-esm/hooks/useQueryHandle.js +0 -97
  149. package/build/runtime-esm/hooks/useSubscription.d.ts +0 -4
  150. package/build/runtime-esm/hooks/useSubscription.js +0 -8
  151. package/build/runtime-esm/hooks/useSubscriptionHandle.d.ts +0 -25
  152. package/build/runtime-esm/hooks/useSubscriptionHandle.js +0 -18
  153. package/build/runtime-esm/index.d.ts +0 -14
  154. package/build/runtime-esm/index.js +0 -48
  155. package/build/runtime-esm/manifest.d.ts +0 -3
  156. package/build/runtime-esm/manifest.js +0 -5
  157. package/build/runtime-esm/routing/Router.d.ts +0 -62
  158. package/build/runtime-esm/routing/Router.js +0 -499
  159. package/build/runtime-esm/routing/cache.d.ts +0 -7
  160. package/build/runtime-esm/routing/cache.js +0 -36
  161. package/build/runtime-esm/routing/hooks.d.ts +0 -40
  162. package/build/runtime-esm/routing/hooks.js +0 -53
  163. package/build/runtime-esm/routing/index.d.ts +0 -3
  164. package/build/runtime-esm/routing/index.js +0 -6
  165. package/build/server/index.d.ts +0 -1
  166. package/build/server-cjs/index.js +0 -28
  167. package/build/server-cjs/package.json +0 -1
  168. package/build/server-esm/index.js +0 -4
  169. package/build/server-esm/package.json +0 -1
  170. /package/{build/plugin-esm → server}/package.json +0 -0
  171. /package/{build/runtime-esm → vite}/package.json +0 -0
@@ -1,76 +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
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var useDeepCompareEffect_exports = {};
30
- __export(useDeepCompareEffect_exports, {
31
- default: () => useDeepCompareEffect_default,
32
- useDeepCompareEffectNoCheck: () => useDeepCompareEffectNoCheck,
33
- useDeepCompareMemoize: () => useDeepCompareMemoize
34
- });
35
- module.exports = __toCommonJS(useDeepCompareEffect_exports);
36
- var import_deepEquals = require("$houdini/runtime/lib/deepEquals");
37
- var React = __toESM(require("react"));
38
- function checkDeps(deps) {
39
- if (!deps || !deps.length) {
40
- throw new Error(
41
- "useDeepCompareEffect should not be used with no dependencies. Use React.useEffect instead."
42
- );
43
- }
44
- if (deps.every(isPrimitive)) {
45
- throw new Error(
46
- "useDeepCompareEffect should not be used with dependencies that are all primitive values. Use React.useEffect instead."
47
- );
48
- }
49
- }
50
- function isPrimitive(val) {
51
- return val == null || /^[sbn]/.test(typeof val);
52
- }
53
- function useDeepCompareMemoize(value) {
54
- const ref = React.useRef(value);
55
- const signalRef = React.useRef(0);
56
- if (!(0, import_deepEquals.deepEquals)(value, ref.current)) {
57
- ref.current = value;
58
- signalRef.current += 1;
59
- }
60
- return React.useMemo(() => ref.current, [signalRef.current]);
61
- }
62
- function useDeepCompareEffect(callback, dependencies) {
63
- if (process.env.NODE_ENV !== "production") {
64
- checkDeps(dependencies);
65
- }
66
- return React.useEffect(callback, useDeepCompareMemoize(dependencies));
67
- }
68
- function useDeepCompareEffectNoCheck(callback, dependencies) {
69
- return React.useEffect(callback, useDeepCompareMemoize(dependencies));
70
- }
71
- var useDeepCompareEffect_default = useDeepCompareEffect;
72
- // Annotate the CommonJS export names for ESM import in node:
73
- 0 && (module.exports = {
74
- useDeepCompareEffectNoCheck,
75
- useDeepCompareMemoize
76
- });
@@ -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,177 +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
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var useDocumentHandle_exports = {};
30
- __export(useDocumentHandle_exports, {
31
- useDocumentHandle: () => useDocumentHandle
32
- });
33
- module.exports = __toCommonJS(useDocumentHandle_exports);
34
- var import_pageInfo = require("$houdini/runtime/lib/pageInfo");
35
- var import_pagination = require("$houdini/runtime/lib/pagination");
36
- var import_types = require("$houdini/runtime/lib/types");
37
- var import_react = __toESM(require("react"));
38
- var import_hooks = require("../routing/hooks");
39
- function useDocumentHandle({
40
- artifact,
41
- observer,
42
- storeValue
43
- }) {
44
- const [forwardPending, setForwardPending] = import_react.default.useState(false);
45
- const [backwardPending, setBackwardPending] = import_react.default.useState(false);
46
- const location = (0, import_hooks.useLocation)();
47
- const [session] = (0, import_hooks.useSession)();
48
- const client = (0, import_hooks.useClient)();
49
- const paginationObserver = import_react.default.useMemo(() => {
50
- if (!artifact.refetch?.paginated) {
51
- return null;
52
- }
53
- return client.observe({ artifact });
54
- }, [artifact.name]);
55
- return import_react.default.useMemo(() => {
56
- const wrapLoad = (setLoading, fn) => {
57
- return async (value) => {
58
- setLoading(true);
59
- let result = null;
60
- let err = null;
61
- try {
62
- result = await fn(value);
63
- } catch (e) {
64
- err = e;
65
- }
66
- setLoading(false);
67
- if (err && err.name !== "AbortError") {
68
- throw err;
69
- }
70
- return result || observer.state;
71
- };
72
- };
73
- const fetchQuery = (args) => {
74
- const usedVariables = Object.fromEntries(
75
- Object.keys(observer.artifact.input?.fields ?? {}).reduce(
76
- (entries, fieldName) => {
77
- if (!(fieldName in location.params)) {
78
- return entries;
79
- }
80
- return [...entries, [fieldName, location.params[fieldName]]];
81
- },
82
- []
83
- )
84
- );
85
- return observer.send({
86
- ...args,
87
- variables: {
88
- ...usedVariables,
89
- ...args?.variables
90
- },
91
- session
92
- });
93
- };
94
- if (artifact.kind !== import_types.ArtifactKind.Query || !artifact.refetch?.paginated) {
95
- return {
96
- artifact,
97
- data: storeValue.data,
98
- variables: storeValue.variables,
99
- fetch: fetchQuery,
100
- partial: storeValue.partial
101
- };
102
- }
103
- if (artifact.refetch.method === "cursor") {
104
- const handlers = (0, import_pagination.cursorHandlers)({
105
- artifact,
106
- getState: () => storeValue.data,
107
- getVariables: () => storeValue.variables,
108
- fetch: fetchQuery,
109
- fetchUpdate: (args, updates) => {
110
- return paginationObserver.send({
111
- ...args,
112
- cacheParams: {
113
- ...args?.cacheParams,
114
- disableSubscriptions: true,
115
- applyUpdates: updates
116
- },
117
- session
118
- });
119
- },
120
- getSession: async () => session
121
- });
122
- return {
123
- artifact,
124
- data: storeValue.data,
125
- variables: storeValue.variables,
126
- fetch: handlers.fetch,
127
- partial: storeValue.partial,
128
- loadNext: wrapLoad(setForwardPending, handlers.loadNextPage),
129
- loadNextPending: forwardPending,
130
- loadPrevious: wrapLoad(setBackwardPending, handlers.loadPreviousPage),
131
- loadPreviousPending: backwardPending,
132
- pageInfo: (0, import_pageInfo.extractPageInfo)(storeValue.data, artifact.refetch.path)
133
- };
134
- }
135
- if (artifact.refetch.method === "offset") {
136
- const handlers = (0, import_pagination.offsetHandlers)({
137
- artifact,
138
- getState: () => storeValue.data,
139
- getVariables: () => storeValue.variables,
140
- storeName: artifact.name,
141
- fetch: fetchQuery,
142
- fetchUpdate: async (args, updates = ["append"]) => {
143
- return paginationObserver.send({
144
- ...args,
145
- cacheParams: {
146
- disableSubscriptions: true,
147
- applyUpdates: updates,
148
- ...args?.cacheParams
149
- }
150
- });
151
- },
152
- getSession: async () => session
153
- });
154
- return {
155
- artifact,
156
- data: storeValue.data,
157
- variables: storeValue.variables,
158
- fetch: handlers.fetch,
159
- partial: storeValue.partial,
160
- loadNext: wrapLoad(setForwardPending, handlers.loadNextPage),
161
- loadNextPending: forwardPending
162
- };
163
- }
164
- return {
165
- artifact,
166
- data: storeValue.data,
167
- variables: storeValue.variables,
168
- fetch: fetchQuery,
169
- refetch: fetchQuery,
170
- partial: storeValue.partial
171
- };
172
- }, [artifact, observer, session, storeValue]);
173
- }
174
- // Annotate the CommonJS export names for ESM import in node:
175
- 0 && (module.exports = {
176
- useDocumentHandle
177
- });
@@ -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,76 +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
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var useDocumentStore_exports = {};
30
- __export(useDocumentStore_exports, {
31
- useDocumentStore: () => useDocumentStore
32
- });
33
- module.exports = __toCommonJS(useDocumentStore_exports);
34
- var React = __toESM(require("react"));
35
- var import_hooks = require("../routing/hooks");
36
- var import_useIsMounted = require("./useIsMounted");
37
- function useDocumentStore({
38
- artifact,
39
- observer: obs,
40
- ...observeParams
41
- }) {
42
- const client = (0, import_hooks.useClient)();
43
- const isMountedRef = (0, import_useIsMounted.useIsMountedRef)();
44
- let [observer, setObserver] = React.useState(
45
- () => obs ?? client.observe({
46
- artifact,
47
- ...observeParams
48
- })
49
- );
50
- const box = React.useRef(observer.state);
51
- if (obs && obs !== observer) {
52
- box.current = obs.state;
53
- setObserver(obs);
54
- }
55
- const subscribe = React.useCallback(
56
- (fn) => {
57
- return observer.subscribe((val) => {
58
- box.current = val;
59
- if (isMountedRef.current) {
60
- fn();
61
- }
62
- });
63
- },
64
- [observer]
65
- );
66
- const storeValue = React.useSyncExternalStore(
67
- subscribe,
68
- () => box.current,
69
- () => box.current
70
- );
71
- return [storeValue, observer];
72
- }
73
- // Annotate the CommonJS export names for ESM import in node:
74
- 0 && (module.exports = {
75
- useDocumentStore
76
- });
@@ -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,76 +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
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var useDocumentSubscription_exports = {};
30
- __export(useDocumentSubscription_exports, {
31
- useDocumentSubscription: () => useDocumentSubscription
32
- });
33
- module.exports = __toCommonJS(useDocumentSubscription_exports);
34
- var import_hooks = require("../routing/hooks");
35
- var import_useDeepCompareEffect = __toESM(require("./useDeepCompareEffect"));
36
- var import_useDocumentStore = require("./useDocumentStore");
37
- function useDocumentSubscription({
38
- artifact,
39
- variables,
40
- send,
41
- disabled,
42
- ...observeParams
43
- }) {
44
- const [storeValue, observer] = (0, import_useDocumentStore.useDocumentStore)({
45
- artifact,
46
- ...observeParams
47
- });
48
- const [session] = (0, import_hooks.useSession)();
49
- (0, import_useDeepCompareEffect.default)(() => {
50
- if (!disabled) {
51
- observer.send({
52
- variables,
53
- session,
54
- // TODO: metadata
55
- metadata: {},
56
- ...send
57
- });
58
- }
59
- return () => {
60
- if (!disabled) {
61
- observer.cleanup();
62
- }
63
- };
64
- }, [disabled, session, observer, variables ?? {}, send ?? {}]);
65
- return [
66
- {
67
- parent: send?.stuff?.parentID,
68
- ...storeValue
69
- },
70
- observer
71
- ];
72
- }
73
- // Annotate the CommonJS export names for ESM import in node:
74
- 0 && (module.exports = {
75
- useDocumentSubscription
76
- });
@@ -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
- };
@@ -1,102 +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
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var useFragment_exports = {};
30
- __export(useFragment_exports, {
31
- fragmentReference: () => fragmentReference,
32
- useFragment: () => useFragment
33
- });
34
- module.exports = __toCommonJS(useFragment_exports);
35
- var import_deepEquals = require("$houdini/runtime/lib/deepEquals");
36
- var import_types = require("$houdini/runtime/lib/types");
37
- var React = __toESM(require("react"));
38
- var import_routing = require("../routing");
39
- var import_useDeepCompareEffect = require("./useDeepCompareEffect");
40
- var import_useDocumentSubscription = require("./useDocumentSubscription");
41
- function useFragment(reference, document) {
42
- const { cache } = (0, import_routing.useRouterContext)();
43
- const { parent, variables, loading } = fragmentReference(
44
- reference,
45
- document
46
- );
47
- let cachedValue = reference;
48
- if (reference && parent) {
49
- cachedValue = cache.read({
50
- selection: document.artifact.selection,
51
- parent,
52
- variables,
53
- loading
54
- }).data;
55
- }
56
- const [storeValue] = (0, import_useDocumentSubscription.useDocumentSubscription)({
57
- artifact: document.artifact,
58
- variables,
59
- initialValue: cachedValue,
60
- // dont subscribe to anything if we are loading
61
- disabled: loading,
62
- send: {
63
- stuff: {
64
- parentID: parent
65
- },
66
- setup: true
67
- }
68
- });
69
- const lastReference = React.useRef(null);
70
- return React.useMemo(() => {
71
- const parentChange = storeValue.parent !== parent || !(0, import_deepEquals.deepEquals)({ parent, variables }, lastReference.current);
72
- if (parentChange) {
73
- lastReference.current = { parent, variables: { ...variables } };
74
- return cachedValue;
75
- }
76
- return storeValue.data;
77
- }, [
78
- (0, import_useDeepCompareEffect.useDeepCompareMemoize)({
79
- parent,
80
- variables,
81
- cachedValue,
82
- storeValue: storeValue.data,
83
- storeParent: storeValue.parent
84
- })
85
- ]);
86
- }
87
- function fragmentReference(reference, document) {
88
- const { variables, parent } = reference?.[import_types.fragmentKey]?.values?.[document.artifact.name] ?? {};
89
- if (reference && import_types.fragmentKey in reference && (!variables || !parent)) {
90
- console.warn(
91
- `\u26A0\uFE0F Parent does not contain the information for this fragment. Something is wrong.
92
- Please ensure that you have passed a record that has ${document.artifact.name} mixed into it.`
93
- );
94
- }
95
- const loading = Boolean(reference?.[import_types.fragmentKey]?.loading);
96
- return { variables, parent, loading };
97
- }
98
- // Annotate the CommonJS export names for ESM import in node:
99
- 0 && (module.exports = {
100
- fragmentReference,
101
- useFragment
102
- });
@@ -1,8 +0,0 @@
1
- import type { GraphQLObject, FragmentArtifact, QueryArtifact, fragmentKey, GraphQLVariables } from '$houdini/runtime/lib/types';
2
- import { type DocumentHandle } from './useDocumentHandle';
3
- export declare function useFragmentHandle<_Artifact extends FragmentArtifact, _Data extends GraphQLObject, _ReferenceType extends {}, _PaginationArtifact extends QueryArtifact, _Input extends GraphQLVariables = GraphQLVariables>(reference: _Data | {
4
- [fragmentKey]: _ReferenceType;
5
- } | null, document: {
6
- artifact: FragmentArtifact;
7
- refetchArtifact?: QueryArtifact;
8
- }): DocumentHandle<_PaginationArtifact, _Data, _Input>;
@@ -1,47 +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 useFragmentHandle_exports = {};
20
- __export(useFragmentHandle_exports, {
21
- useFragmentHandle: () => useFragmentHandle
22
- });
23
- module.exports = __toCommonJS(useFragmentHandle_exports);
24
- var import_useDocumentHandle = require("./useDocumentHandle");
25
- var import_useDocumentStore = require("./useDocumentStore");
26
- var import_useFragment = require("./useFragment");
27
- function useFragmentHandle(reference, document) {
28
- const data = (0, import_useFragment.useFragment)(reference, document);
29
- const { variables } = (0, import_useFragment.fragmentReference)(reference, document);
30
- const [handleValue, handleObserver] = (0, import_useDocumentStore.useDocumentStore)({
31
- artifact: document.refetchArtifact ?? document.artifact
32
- });
33
- const handle = (0, import_useDocumentHandle.useDocumentHandle)({
34
- observer: handleObserver,
35
- storeValue: handleValue,
36
- artifact: document.refetchArtifact ?? document.artifact
37
- });
38
- return {
39
- ...handle,
40
- variables,
41
- data
42
- };
43
- }
44
- // Annotate the CommonJS export names for ESM import in node:
45
- 0 && (module.exports = {
46
- useFragmentHandle
47
- });
@@ -1,3 +0,0 @@
1
- export declare function useIsMountedRef(): {
2
- current: boolean;
3
- };