houdini-react 1.2.0-react.1 → 1.2.6

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 (127) hide show
  1. package/README.md +1 -1
  2. package/build/plugin/codegen/entries.d.ts +6 -0
  3. package/build/plugin/codegen/index.d.ts +14 -0
  4. package/build/plugin/codegen/manifest.d.ts +42 -0
  5. package/build/plugin/codegen/render.d.ts +2 -0
  6. package/build/plugin/codegen/router.d.ts +8 -0
  7. package/build/plugin/codegen/typeRoot.d.ts +6 -0
  8. package/build/plugin/config.d.ts +1 -0
  9. package/build/plugin/conventions.d.ts +24 -0
  10. package/build/plugin/dedent.d.ts +1 -0
  11. package/build/plugin/extract.d.ts +1 -1
  12. package/build/plugin/index.d.ts +4 -2
  13. package/build/plugin/vite.d.ts +19 -0
  14. package/build/plugin-cjs/index.js +32672 -1115
  15. package/build/plugin-esm/index.js +32666 -1111
  16. package/build/runtime/client.d.ts +3 -0
  17. package/build/runtime/clientPlugin.d.ts +3 -0
  18. package/build/runtime/hooks/useDocumentHandle.d.ts +4 -4
  19. package/build/runtime/hooks/useDocumentStore.d.ts +6 -5
  20. package/build/runtime/hooks/useDocumentSubscription.d.ts +4 -3
  21. package/build/runtime/hooks/useFragment.d.ts +3 -2
  22. package/build/runtime/hooks/useFragmentHandle.d.ts +2 -3
  23. package/build/runtime/hooks/useMutation.d.ts +2 -2
  24. package/build/runtime/hooks/useQuery.d.ts +3 -3
  25. package/build/runtime/hooks/useQueryHandle.d.ts +3 -3
  26. package/build/runtime/hooks/useSubscription.d.ts +2 -2
  27. package/build/runtime/hooks/useSubscriptionHandle.d.ts +3 -3
  28. package/build/runtime/index.d.ts +29 -1
  29. package/build/runtime/manifest.d.ts +3 -0
  30. package/build/runtime/routing/components/Link.d.ts +5 -0
  31. package/build/runtime/routing/components/Router.d.ts +52 -0
  32. package/build/runtime/routing/components/index.d.ts +2 -0
  33. package/build/runtime/routing/index.d.ts +3 -0
  34. package/build/runtime/routing/lib/cache.d.ts +7 -0
  35. package/build/runtime/routing/lib/match.d.ts +38 -0
  36. package/build/runtime/routing/lib/types.d.ts +24 -0
  37. package/build/runtime-cjs/client.d.ts +3 -0
  38. package/build/runtime-cjs/client.js +26 -0
  39. package/build/runtime-cjs/clientPlugin.d.ts +3 -0
  40. package/build/{next-cjs/index.js → runtime-cjs/clientPlugin.js} +15 -26
  41. package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +4 -4
  42. package/build/runtime-cjs/hooks/useDocumentHandle.js +0 -1
  43. package/build/runtime-cjs/hooks/useDocumentStore.d.ts +6 -5
  44. package/build/runtime-cjs/hooks/useDocumentStore.js +9 -4
  45. package/build/runtime-cjs/hooks/useDocumentSubscription.d.ts +4 -3
  46. package/build/runtime-cjs/hooks/useDocumentSubscription.js +13 -8
  47. package/build/runtime-cjs/hooks/useFragment.d.ts +3 -2
  48. package/build/runtime-cjs/hooks/useFragment.js +9 -7
  49. package/build/runtime-cjs/hooks/useFragmentHandle.d.ts +2 -3
  50. package/build/runtime-cjs/hooks/useMutation.d.ts +2 -2
  51. package/build/runtime-cjs/hooks/useQuery.d.ts +3 -3
  52. package/build/runtime-cjs/hooks/useQueryHandle.d.ts +3 -3
  53. package/build/runtime-cjs/hooks/useQueryHandle.js +4 -4
  54. package/build/runtime-cjs/hooks/useSubscription.d.ts +2 -2
  55. package/build/runtime-cjs/hooks/useSubscriptionHandle.d.ts +3 -3
  56. package/build/runtime-cjs/index.d.ts +29 -1
  57. package/build/runtime-cjs/index.js +87 -3
  58. package/build/runtime-cjs/manifest.d.ts +3 -0
  59. package/build/runtime-cjs/manifest.js +27 -0
  60. package/build/runtime-cjs/routing/components/Link.d.ts +5 -0
  61. package/build/runtime-cjs/{hooks/useHoudiniClient.js → routing/components/Link.js} +22 -13
  62. package/build/runtime-cjs/routing/components/Router.d.ts +52 -0
  63. package/build/runtime-cjs/routing/components/Router.js +267 -0
  64. package/build/runtime-cjs/routing/components/index.d.ts +2 -0
  65. package/build/runtime-cjs/{context.js → routing/components/index.js} +13 -19
  66. package/build/runtime-cjs/routing/index.d.ts +3 -0
  67. package/build/runtime-cjs/routing/index.js +30 -0
  68. package/build/runtime-cjs/routing/lib/cache.d.ts +7 -0
  69. package/build/runtime-cjs/{lib → routing/lib}/cache.js +23 -40
  70. package/build/runtime-cjs/routing/lib/match.d.ts +38 -0
  71. package/build/runtime-cjs/routing/lib/match.js +149 -0
  72. package/build/runtime-cjs/routing/lib/types.d.ts +24 -0
  73. package/build/runtime-cjs/routing/lib/types.js +16 -0
  74. package/build/runtime-esm/client.d.ts +3 -0
  75. package/build/runtime-esm/client.js +4 -0
  76. package/build/runtime-esm/clientPlugin.d.ts +3 -0
  77. package/build/runtime-esm/clientPlugin.js +17 -0
  78. package/build/runtime-esm/hooks/useDocumentHandle.d.ts +4 -4
  79. package/build/runtime-esm/hooks/useDocumentHandle.js +1 -4
  80. package/build/runtime-esm/hooks/useDocumentStore.d.ts +6 -5
  81. package/build/runtime-esm/hooks/useDocumentStore.js +9 -4
  82. package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +4 -3
  83. package/build/runtime-esm/hooks/useDocumentSubscription.js +13 -8
  84. package/build/runtime-esm/hooks/useFragment.d.ts +3 -2
  85. package/build/runtime-esm/hooks/useFragment.js +9 -7
  86. package/build/runtime-esm/hooks/useFragmentHandle.d.ts +2 -3
  87. package/build/runtime-esm/hooks/useMutation.d.ts +2 -2
  88. package/build/runtime-esm/hooks/useQuery.d.ts +3 -3
  89. package/build/runtime-esm/hooks/useQueryHandle.d.ts +3 -3
  90. package/build/runtime-esm/hooks/useQueryHandle.js +4 -4
  91. package/build/runtime-esm/hooks/useSubscription.d.ts +2 -2
  92. package/build/runtime-esm/hooks/useSubscriptionHandle.d.ts +3 -3
  93. package/build/runtime-esm/index.d.ts +29 -1
  94. package/build/runtime-esm/index.js +79 -2
  95. package/build/runtime-esm/manifest.d.ts +3 -0
  96. package/build/runtime-esm/manifest.js +5 -0
  97. package/build/runtime-esm/routing/components/Link.d.ts +5 -0
  98. package/build/runtime-esm/routing/components/Link.js +21 -0
  99. package/build/runtime-esm/routing/components/Router.d.ts +52 -0
  100. package/build/runtime-esm/routing/components/Router.js +230 -0
  101. package/build/runtime-esm/routing/components/index.d.ts +2 -0
  102. package/build/runtime-esm/routing/components/index.js +8 -0
  103. package/build/runtime-esm/routing/index.d.ts +3 -0
  104. package/build/runtime-esm/routing/index.js +5 -0
  105. package/build/runtime-esm/routing/lib/cache.d.ts +7 -0
  106. package/build/runtime-esm/routing/lib/cache.js +29 -0
  107. package/build/runtime-esm/routing/lib/match.d.ts +38 -0
  108. package/build/runtime-esm/routing/lib/match.js +122 -0
  109. package/build/runtime-esm/routing/lib/types.d.ts +24 -0
  110. package/build/runtime-esm/routing/lib/types.js +0 -0
  111. package/package.json +7 -11
  112. package/build/next/index.d.ts +0 -2
  113. package/build/next-cjs/package.json +0 -1
  114. package/build/next-esm/index.js +0 -26
  115. package/build/next-esm/package.json +0 -1
  116. package/build/runtime/context.d.ts +0 -7
  117. package/build/runtime/hooks/useHoudiniClient.d.ts +0 -2
  118. package/build/runtime/lib/cache.d.ts +0 -62
  119. package/build/runtime-cjs/context.d.ts +0 -7
  120. package/build/runtime-cjs/hooks/useHoudiniClient.d.ts +0 -2
  121. package/build/runtime-cjs/lib/cache.d.ts +0 -62
  122. package/build/runtime-esm/context.d.ts +0 -7
  123. package/build/runtime-esm/context.js +0 -10
  124. package/build/runtime-esm/hooks/useHoudiniClient.d.ts +0 -2
  125. package/build/runtime-esm/hooks/useHoudiniClient.js +0 -12
  126. package/build/runtime-esm/lib/cache.d.ts +0 -62
  127. package/build/runtime-esm/lib/cache.js +0 -47
@@ -1,7 +1,6 @@
1
- import type { GraphQLObject, FragmentArtifact, QueryArtifact } from '$houdini/runtime/lib/types';
2
- import { fragmentKey } from '$houdini/runtime/lib/types';
1
+ import type { GraphQLObject, FragmentArtifact, QueryArtifact, fragmentKey, GraphQLVariables } from '$houdini/runtime/lib/types';
3
2
  import { type DocumentHandle } from './useDocumentHandle';
4
- export declare function useFragmentHandle<_Artifact extends FragmentArtifact, _Data extends GraphQLObject, _ReferenceType extends {}, _PaginationArtifact extends QueryArtifact, _Input extends {} = {}>(reference: _Data | {
3
+ export declare function useFragmentHandle<_Artifact extends FragmentArtifact, _Data extends GraphQLObject, _ReferenceType extends {}, _PaginationArtifact extends QueryArtifact, _Input extends GraphQLVariables = GraphQLVariables>(reference: _Data | {
5
4
  [fragmentKey]: _ReferenceType;
6
5
  } | null, document: {
7
6
  artifact: FragmentArtifact;
@@ -1,10 +1,10 @@
1
- import type { MutationArtifact, GraphQLObject, QueryResult } from '$houdini/runtime/lib/types';
1
+ import type { MutationArtifact, GraphQLObject, QueryResult, GraphQLVariables } from '$houdini/runtime/lib/types';
2
2
  export type MutationHandler<_Result, _Input, _Optimistic extends GraphQLObject> = (args: {
3
3
  variables: _Input;
4
4
  metadata?: App.Metadata;
5
5
  fetch?: typeof globalThis.fetch;
6
6
  optimisticResponse?: _Optimistic;
7
7
  }) => Promise<QueryResult<_Result, _Input>>;
8
- export declare function useMutation<_Result extends GraphQLObject, _Input extends {}, _Optimistic extends GraphQLObject>({ artifact, }: {
8
+ export declare function useMutation<_Result extends GraphQLObject, _Input extends GraphQLVariables, _Optimistic extends GraphQLObject>({ artifact, }: {
9
9
  artifact: MutationArtifact;
10
10
  }): [boolean, MutationHandler<_Result, _Input, _Optimistic>];
@@ -1,5 +1,5 @@
1
- import { type QueryArtifact, GraphQLObject } from '$houdini/runtime/lib/types';
2
- import { UseQueryConfig } from './useQueryHandle';
3
- export declare function useQuery<_Artifact extends QueryArtifact, _Data extends GraphQLObject = GraphQLObject, _Input extends {} = []>(document: {
1
+ import type { GraphQLVariables, GraphQLObject, QueryArtifact } from '$houdini/runtime/lib/types';
2
+ import type { UseQueryConfig } from './useQueryHandle';
3
+ export declare function useQuery<_Artifact extends QueryArtifact, _Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables>(document: {
4
4
  artifact: QueryArtifact;
5
5
  }, variables?: any, config?: UseQueryConfig): _Data;
@@ -1,6 +1,6 @@
1
- import { type QueryArtifact, GraphQLObject, CachePolicies } from '$houdini/runtime/lib/types';
2
- import { DocumentHandle } from './useDocumentHandle';
3
- export declare function useQueryHandle<_Artifact extends QueryArtifact, _Data extends GraphQLObject = GraphQLObject, _Input extends {} = []>({ artifact }: {
1
+ import type { GraphQLObject, CachePolicies, QueryArtifact, GraphQLVariables } from '$houdini/runtime/lib/types';
2
+ import type { DocumentHandle } from './useDocumentHandle';
3
+ export declare function useQueryHandle<_Artifact extends QueryArtifact, _Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables>({ artifact }: {
4
4
  artifact: QueryArtifact;
5
5
  }, variables?: any, config?: UseQueryConfig): DocumentHandle<_Artifact, _Data, _Input>;
6
6
  export type UseQueryConfig = {
@@ -27,16 +27,16 @@ __export(useQueryHandle_exports, {
27
27
  useQueryHandle: () => useQueryHandle
28
28
  });
29
29
  module.exports = __toCommonJS(useQueryHandle_exports);
30
+ var import_lru = require("$houdini/runtime/lib/lru");
30
31
  var import_react = __toESM(require("react"));
31
- var import_cache = require("../lib/cache");
32
+ var import_routing = require("../routing");
32
33
  var import_useDocumentHandle = require("./useDocumentHandle");
33
- var import_useHoudiniClient = require("./useHoudiniClient");
34
34
  var import_useIsMounted = require("./useIsMounted");
35
- const promiseCache = (0, import_cache.createCache)();
35
+ const promiseCache = (0, import_lru.createLRUCache)();
36
36
  function useQueryHandle({ artifact }, variables = null, config = {}) {
37
37
  const identifier = queryIdentifier({ artifact, variables, config });
38
38
  const suspenseValue = promiseCache.get(identifier);
39
- const client = (0, import_useHoudiniClient.useHoudiniClient)();
39
+ const client = (0, import_routing.useClient)();
40
40
  const isMountedRef = (0, import_useIsMounted.useIsMountedRef)();
41
41
  let [observer] = import_react.default.useState(
42
42
  client.observe({
@@ -1,4 +1,4 @@
1
- import { SubscriptionArtifact, GraphQLObject } from '$houdini/runtime/lib/types';
2
- export declare function useSubscription<_Result extends GraphQLObject, _Input extends {}>(document: {
1
+ import type { SubscriptionArtifact, GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
2
+ export declare function useSubscription<_Result extends GraphQLObject, _Input extends GraphQLVariables>(document: {
3
3
  artifact: SubscriptionArtifact;
4
4
  }, variables: _Input): import("houdini").GraphQLObject | null;
@@ -1,5 +1,5 @@
1
- import { SubscriptionArtifact, GraphQLObject } from '$houdini/runtime/lib/types';
2
- export type SubscriptionHandle<_Result extends GraphQLObject, _Input extends {} | null> = {
1
+ import type { SubscriptionArtifact, GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
2
+ export type SubscriptionHandle<_Result extends GraphQLObject, _Input extends GraphQLVariables> = {
3
3
  data: _Result | null;
4
4
  errors: {
5
5
  message: string;
@@ -11,7 +11,7 @@ export type SubscriptionHandle<_Result extends GraphQLObject, _Input extends {}
11
11
  unlisten: () => void;
12
12
  fetching: boolean;
13
13
  };
14
- export declare function useSubscriptionHandle<_Result extends GraphQLObject, _Input extends {}>({ artifact }: {
14
+ export declare function useSubscriptionHandle<_Result extends GraphQLObject, _Input extends GraphQLVariables>({ artifact }: {
15
15
  artifact: SubscriptionArtifact;
16
16
  }, variables: _Input): {
17
17
  data: import("houdini").GraphQLObject | null;
@@ -1,2 +1,30 @@
1
+ import type { Cache } from '$houdini/runtime/cache/cache';
2
+ import { DocumentStore } from '$houdini/runtime/client';
3
+ import { LRUCache } from '$houdini/runtime/lib/lru';
4
+ import { GraphQLObject, GraphQLVariables, QueryArtifact } from '$houdini/runtime/lib/types';
5
+ import React from 'react';
6
+ import { PendingCache } from './routing/components/Router';
7
+ import { SuspenseCache } from './routing/lib/cache';
1
8
  export * from './hooks';
2
- export { HoudiniProvider } from './context';
9
+ export * from './routing';
10
+ export declare function Router({ cache, intialURL, artifact_cache, component_cache, data_cache, pending_cache, last_variables, loaded_queries, loaded_artifacts, }: {
11
+ intialURL: string;
12
+ cache: Cache;
13
+ loaded_queries?: Record<string, {
14
+ data: GraphQLObject;
15
+ variables: GraphQLVariables;
16
+ }>;
17
+ loaded_artifacts?: Record<string, QueryArtifact>;
18
+ } & RouterCache): JSX.Element;
19
+ type RouterCache = {
20
+ artifact_cache: SuspenseCache<QueryArtifact>;
21
+ component_cache: SuspenseCache<(props: any) => React.ReactElement>;
22
+ data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
23
+ last_variables: LRUCache<GraphQLVariables>;
24
+ pending_cache: PendingCache;
25
+ };
26
+ export declare function router_cache({ pending_queries, artifacts, components, }?: {
27
+ pending_queries?: string[];
28
+ artifacts?: Record<string, QueryArtifact>;
29
+ components?: Record<string, (props: any) => React.ReactElement>;
30
+ }): RouterCache;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -16,15 +18,97 @@ var __copyProps = (to, from, except, desc) => {
16
18
  return to;
17
19
  };
18
20
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
19
25
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
26
  var runtime_exports = {};
21
27
  __export(runtime_exports, {
22
- HoudiniProvider: () => import_context.HoudiniProvider
28
+ Router: () => Router,
29
+ router_cache: () => router_cache
23
30
  });
24
31
  module.exports = __toCommonJS(runtime_exports);
32
+ var import_react = __toESM(require("react"));
33
+ var import_client2 = __toESM(require("./client"));
34
+ var import_manifest = __toESM(require("./manifest"));
35
+ var import_routing = require("./routing");
36
+ var import_cache = require("./routing/lib/cache");
25
37
  __reExport(runtime_exports, require("./hooks"), module.exports);
26
- var import_context = require("./context");
38
+ __reExport(runtime_exports, require("./routing"), module.exports);
39
+ function Router({
40
+ cache,
41
+ intialURL,
42
+ artifact_cache,
43
+ component_cache,
44
+ data_cache,
45
+ pending_cache,
46
+ last_variables,
47
+ loaded_queries,
48
+ loaded_artifacts
49
+ }) {
50
+ return /* @__PURE__ */ import_react.default.createElement(
51
+ import_routing.RouterContextProvider,
52
+ {
53
+ client: import_client2.default,
54
+ cache,
55
+ artifact_cache,
56
+ component_cache,
57
+ data_cache,
58
+ pending_cache,
59
+ last_variables
60
+ },
61
+ /* @__PURE__ */ import_react.default.createElement(
62
+ import_routing.Router,
63
+ {
64
+ intialURL,
65
+ manifest: import_manifest.default,
66
+ loaded_queries,
67
+ loaded_artifacts
68
+ }
69
+ )
70
+ );
71
+ }
72
+ function router_cache({
73
+ pending_queries = [],
74
+ artifacts = {},
75
+ components = {}
76
+ } = {}) {
77
+ const result = {
78
+ artifact_cache: (0, import_cache.suspense_cache)(),
79
+ component_cache: (0, import_cache.suspense_cache)(),
80
+ data_cache: (0, import_cache.suspense_cache)(),
81
+ pending_cache: (0, import_cache.suspense_cache)(),
82
+ last_variables: (0, import_cache.suspense_cache)()
83
+ };
84
+ for (const query of pending_queries) {
85
+ result.pending_cache.set(query, signal_promise());
86
+ }
87
+ for (const [name, artifact] of Object.entries(artifacts)) {
88
+ result.artifact_cache.set(name, artifact);
89
+ }
90
+ for (const [name, component] of Object.entries(components)) {
91
+ result.component_cache.set(name, component);
92
+ }
93
+ return result;
94
+ }
95
+ function signal_promise() {
96
+ let resolve = () => {
97
+ };
98
+ let reject = () => {
99
+ };
100
+ const promise = new Promise((res, rej) => {
101
+ resolve = res;
102
+ reject = rej;
103
+ });
104
+ return {
105
+ ...promise,
106
+ resolve,
107
+ reject
108
+ };
109
+ }
27
110
  // Annotate the CommonJS export names for ESM import in node:
28
111
  0 && (module.exports = {
29
- HoudiniProvider
112
+ Router,
113
+ router_cache
30
114
  });
@@ -0,0 +1,3 @@
1
+ import type { RouterManifest } from './routing';
2
+ declare const manifest: RouterManifest;
3
+ export default manifest;
@@ -0,0 +1,27 @@
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 manifest_exports = {};
20
+ __export(manifest_exports, {
21
+ default: () => manifest_default
22
+ });
23
+ module.exports = __toCommonJS(manifest_exports);
24
+ const manifest = {};
25
+ var manifest_default = manifest;
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {});
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export declare function Link({ href, children, style, ...props }: {
3
+ href: string;
4
+ children: React.ReactNode;
5
+ } & React.AnchorHTMLAttributes<HTMLAnchorElement>): JSX.Element;
@@ -22,21 +22,30 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
  mod
23
23
  ));
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
- var useHoudiniClient_exports = {};
26
- __export(useHoudiniClient_exports, {
27
- useHoudiniClient: () => useHoudiniClient
25
+ var Link_exports = {};
26
+ __export(Link_exports, {
27
+ Link: () => Link
28
28
  });
29
- module.exports = __toCommonJS(useHoudiniClient_exports);
30
- var React = __toESM(require("react"));
31
- var import_context = require("../context");
32
- function useHoudiniClient() {
33
- const client = React.useContext(import_context.HoudiniContext);
34
- if (!client) {
35
- throw new Error("Could not find client");
36
- }
37
- return client;
29
+ module.exports = __toCommonJS(Link_exports);
30
+ var import_react = __toESM(require("react"));
31
+ var import_Router = require("./Router");
32
+ function Link({
33
+ href,
34
+ children,
35
+ style,
36
+ ...props
37
+ }) {
38
+ const { goto } = (0, import_Router.useNavigationContext)();
39
+ const [pending, startTransition] = (0, import_react.useTransition)();
40
+ const click = (e) => {
41
+ e.preventDefault();
42
+ startTransition(() => {
43
+ goto(href);
44
+ });
45
+ };
46
+ return /* @__PURE__ */ import_react.default.createElement("a", { href, onClick: click, style, ...props }, children);
38
47
  }
39
48
  // Annotate the CommonJS export names for ESM import in node:
40
49
  0 && (module.exports = {
41
- useHoudiniClient
50
+ Link
42
51
  });
@@ -0,0 +1,52 @@
1
+ import type { Cache } from '$houdini/runtime/cache/cache';
2
+ import { DocumentStore, HoudiniClient } from '$houdini/runtime/client';
3
+ import { LRUCache } from '$houdini/runtime/lib/lru';
4
+ import { GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
5
+ import { QueryArtifact } from '$houdini/runtime/lib/types';
6
+ import React from 'react';
7
+ import { SuspenseCache } from '../lib/cache';
8
+ import type { NavigationContext, RouterManifest } from '../lib/types';
9
+ /**
10
+ * Router is the top level entry point for the filesystem-based router.
11
+ * It is responsible for loading various page sources (including API fetches) and
12
+ * then rendering when appropriate.
13
+ */
14
+ export declare function Router({ manifest, intialURL, loaded_queries, loaded_artifacts, }: {
15
+ manifest: RouterManifest;
16
+ intialURL?: string;
17
+ loaded_queries?: Record<string, {
18
+ data: GraphQLObject;
19
+ variables: GraphQLVariables;
20
+ }>;
21
+ loaded_artifacts?: Record<string, QueryArtifact>;
22
+ }): JSX.Element;
23
+ export declare function useNavigationContext(): NavigationContext;
24
+ export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, pending_cache, last_variables, }: {
25
+ children: React.ReactElement;
26
+ client: HoudiniClient;
27
+ cache: Cache;
28
+ artifact_cache: SuspenseCache<QueryArtifact>;
29
+ component_cache: SuspenseCache<(props: any) => React.ReactElement>;
30
+ data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
31
+ pending_cache: PendingCache;
32
+ last_variables: LRUCache<GraphQLVariables>;
33
+ }): JSX.Element;
34
+ type RouterContext = {
35
+ client: HoudiniClient;
36
+ cache: Cache;
37
+ artifact_cache: SuspenseCache<QueryArtifact>;
38
+ component_cache: SuspenseCache<(props: any) => React.ReactElement>;
39
+ data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
40
+ pending_cache: PendingCache;
41
+ last_variables: LRUCache<GraphQLVariables>;
42
+ };
43
+ export type PendingCache = SuspenseCache<Promise<void> & {
44
+ resolve: () => void;
45
+ reject: () => void;
46
+ }>;
47
+ export declare const useRouterContext: () => RouterContext;
48
+ export declare function useClient(): HoudiniClient;
49
+ export declare function useCache(): Cache;
50
+ export declare function useCurrentVariables(): GraphQLVariables;
51
+ export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentStore<_Data, _Input>];
52
+ export {};
@@ -0,0 +1,267 @@
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 Router_exports = {};
26
+ __export(Router_exports, {
27
+ Router: () => Router,
28
+ RouterContextProvider: () => RouterContextProvider,
29
+ useCache: () => useCache,
30
+ useClient: () => useClient,
31
+ useCurrentVariables: () => useCurrentVariables,
32
+ useNavigationContext: () => useNavigationContext,
33
+ useQueryResult: () => useQueryResult,
34
+ useRouterContext: () => useRouterContext
35
+ });
36
+ module.exports = __toCommonJS(Router_exports);
37
+ var import_deepEquals = require("$houdini/runtime/lib/deepEquals");
38
+ var import_react = __toESM(require("react"));
39
+ var import_react_streaming = require("react-streaming");
40
+ var import_useDocumentStore = require("../../hooks/useDocumentStore");
41
+ var import_match = require("../lib/match");
42
+ const NavContext = import_react.default.createContext({
43
+ currentRoute: "/",
44
+ goto: () => {
45
+ throw new Error("NOT FOUND");
46
+ }
47
+ });
48
+ function Router({
49
+ manifest,
50
+ intialURL,
51
+ loaded_queries,
52
+ loaded_artifacts
53
+ }) {
54
+ const [current, setCurrent] = import_react.default.useState(() => {
55
+ return intialURL || window.location.pathname;
56
+ });
57
+ const [page, variables] = (0, import_match.find_match)(manifest, current);
58
+ useLoadPage({ page, variables, loaded_queries, loaded_artifacts });
59
+ const { component_cache } = useRouterContext();
60
+ const PageComponent = component_cache.get(page.id);
61
+ import_react.default.useEffect(() => {
62
+ if (window.location.pathname !== current) {
63
+ window.history.pushState({}, "", current);
64
+ }
65
+ }, [current]);
66
+ import_react.default.useEffect(() => {
67
+ const onChange = (evt) => {
68
+ setCurrent(window.location.pathname);
69
+ };
70
+ window.addEventListener("popstate", onChange);
71
+ return () => {
72
+ window.removeEventListener("popstate", onChange);
73
+ };
74
+ }, []);
75
+ return /* @__PURE__ */ import_react.default.createElement(
76
+ NavContext.Provider,
77
+ {
78
+ value: {
79
+ currentRoute: current,
80
+ goto: setCurrent
81
+ }
82
+ },
83
+ /* @__PURE__ */ import_react.default.createElement(VariableContext.Provider, { value: variables }, /* @__PURE__ */ import_react.default.createElement(PageComponent, { url: current }))
84
+ );
85
+ }
86
+ function useLoadPage({
87
+ page,
88
+ variables,
89
+ loaded_queries,
90
+ loaded_artifacts
91
+ }) {
92
+ const {
93
+ client,
94
+ cache,
95
+ data_cache,
96
+ component_cache,
97
+ artifact_cache,
98
+ pending_cache,
99
+ last_variables
100
+ } = useRouterContext();
101
+ const stream = (0, import_react_streaming.useStream)();
102
+ function load_query({ id, artifact }) {
103
+ last_variables.set(page.id, variables);
104
+ if (pending_cache.has(id)) {
105
+ return pending_cache.get(id);
106
+ }
107
+ const observer = client.observe({ artifact, cache });
108
+ let resolve = () => {
109
+ };
110
+ let reject = () => {
111
+ };
112
+ const promise = new Promise((res, rej) => {
113
+ resolve = res;
114
+ reject = rej;
115
+ observer.send({
116
+ variables,
117
+ cacheParams: { disableSubscriptions: true }
118
+ }).then(() => {
119
+ data_cache.set(id, observer);
120
+ if (loaded_queries) {
121
+ loaded_queries[artifact.name] = {
122
+ data: observer.state.data,
123
+ variables
124
+ };
125
+ }
126
+ stream?.injectToStream(`
127
+ <script>
128
+ window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
129
+
130
+ if (window.__houdini__nav_caches__?.pending_cache.has("${artifact.name}")) {
131
+ // before we resolve the pending signals,
132
+ // fill the data cache with values we got on the server
133
+ const new_store = window.__houdini__client__.observe({
134
+ artifact: window.__houdini__nav_caches__.artifact_cache.get("${artifact.name}"),
135
+ cache: window.__houdini__cache__,
136
+ initialValue: ${JSON.stringify(observer.state.data)}
137
+ })
138
+
139
+ window.__houdini__nav_caches__.data_cache.set("${artifact.name}", new_store)
140
+
141
+ // we're pushing this store onto the client, it should be initialized
142
+ new_store.send({
143
+ setup: true,
144
+ variables: ${JSON.stringify(variables)}
145
+ })
146
+
147
+ // notify anyone waiting on the pending cache
148
+ window.__houdini__nav_caches__.pending_cache.get("${artifact.name}").resolve()
149
+ window.__houdini__nav_caches__.pending_cache.delete("${artifact.name}")
150
+ }
151
+ <\/script>
152
+ `);
153
+ resolve();
154
+ }).catch(reject).finally(() => {
155
+ pending_cache.delete(id);
156
+ });
157
+ });
158
+ pending_cache.set(id, { ...promise, resolve, reject });
159
+ return pending_cache.get(id);
160
+ }
161
+ if (last_variables.has(page.id) && !(0, import_deepEquals.deepEquals)(last_variables.get(page.id), variables)) {
162
+ data_cache.clear();
163
+ }
164
+ const missing_artifacts = [];
165
+ const found_artifacts = {};
166
+ for (const key of Object.keys(page.documents)) {
167
+ if (artifact_cache.has(key)) {
168
+ found_artifacts[key] = artifact_cache.get(key);
169
+ } else {
170
+ missing_artifacts.push(key);
171
+ }
172
+ }
173
+ for (const artifact_id of missing_artifacts) {
174
+ page.documents[artifact_id].artifact().then((mod) => {
175
+ const artifact = mod.default;
176
+ artifact_cache.set(artifact_id, artifact);
177
+ if (loaded_artifacts) {
178
+ loaded_artifacts[artifact.name] = artifact;
179
+ }
180
+ stream?.injectToStream(`
181
+ <script type="module" src="@@houdini/artifact/${artifact.name}.js" async=""><\/script>
182
+ `);
183
+ load_query({ id: artifact.name, artifact });
184
+ }).catch((err) => {
185
+ console.log(err);
186
+ });
187
+ }
188
+ for (const artifact of Object.values(found_artifacts)) {
189
+ if (!data_cache.has(artifact.name)) {
190
+ load_query({ id: artifact.name, artifact });
191
+ }
192
+ }
193
+ if (!component_cache.has(page.id)) {
194
+ throw new Promise((resolve, reject) => {
195
+ page.component().then((mod) => {
196
+ component_cache.set(page.id, mod.default);
197
+ resolve();
198
+ }).catch(reject);
199
+ });
200
+ }
201
+ }
202
+ function useNavigationContext() {
203
+ return import_react.default.useContext(NavContext);
204
+ }
205
+ function RouterContextProvider({
206
+ children,
207
+ client,
208
+ cache,
209
+ artifact_cache,
210
+ component_cache,
211
+ data_cache,
212
+ pending_cache,
213
+ last_variables
214
+ }) {
215
+ return /* @__PURE__ */ import_react.default.createElement(
216
+ Context.Provider,
217
+ {
218
+ value: {
219
+ client,
220
+ cache,
221
+ artifact_cache,
222
+ component_cache,
223
+ data_cache,
224
+ pending_cache,
225
+ last_variables
226
+ }
227
+ },
228
+ children
229
+ );
230
+ }
231
+ const Context = import_react.default.createContext(null);
232
+ const useRouterContext = () => {
233
+ const ctx = import_react.default.useContext(Context);
234
+ if (!ctx) {
235
+ throw new Error("Could not find router context");
236
+ }
237
+ return ctx;
238
+ };
239
+ function useClient() {
240
+ return useRouterContext().client;
241
+ }
242
+ function useCache() {
243
+ return useRouterContext().cache;
244
+ }
245
+ function useCurrentVariables() {
246
+ return import_react.default.useContext(VariableContext);
247
+ }
248
+ const VariableContext = import_react.default.createContext(null);
249
+ function useQueryResult(name) {
250
+ const store_ref = useRouterContext().data_cache.get(name);
251
+ const [{ data }, observer] = (0, import_useDocumentStore.useDocumentStore)({
252
+ artifact: store_ref.artifact,
253
+ observer: store_ref
254
+ });
255
+ return [data, observer];
256
+ }
257
+ // Annotate the CommonJS export names for ESM import in node:
258
+ 0 && (module.exports = {
259
+ Router,
260
+ RouterContextProvider,
261
+ useCache,
262
+ useClient,
263
+ useCurrentVariables,
264
+ useNavigationContext,
265
+ useQueryResult,
266
+ useRouterContext
267
+ });
@@ -0,0 +1,2 @@
1
+ export { Link } from './Link';
2
+ export { Router, RouterContextProvider, useClient } from './Router';