crelte 0.5.8 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/dist/blocks/Blocks.d.ts +41 -4
  2. package/dist/blocks/Blocks.d.ts.map +1 -1
  3. package/dist/blocks/Blocks.js +47 -2
  4. package/dist/blocks/Blocks.svelte +2 -16
  5. package/dist/blocks/Blocks.svelte.d.ts +20 -37
  6. package/dist/blocks/Blocks.svelte.d.ts.map +1 -1
  7. package/dist/blocks/index.d.ts +2 -2
  8. package/dist/blocks/index.d.ts.map +1 -1
  9. package/dist/blocks/index.js +2 -2
  10. package/dist/cookies/ServerCookies.d.ts +1 -1
  11. package/dist/cookies/ServerCookies.js +1 -1
  12. package/dist/cookies/index.d.ts +1 -1
  13. package/dist/crelte.d.ts +21 -10
  14. package/dist/crelte.d.ts.map +1 -1
  15. package/dist/index.d.ts +19 -14
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +17 -13
  18. package/dist/init/client.d.ts +2 -2
  19. package/dist/init/client.d.ts.map +1 -1
  20. package/dist/init/client.js +3 -2
  21. package/dist/init/server.d.ts +7 -6
  22. package/dist/init/server.d.ts.map +1 -1
  23. package/dist/init/server.js +6 -6
  24. package/dist/loadData/Globals.d.ts +3 -3
  25. package/dist/loadData/Globals.js +3 -3
  26. package/dist/loadData/loadData.d.ts +8 -18
  27. package/dist/loadData/loadData.d.ts.map +1 -1
  28. package/dist/loadData/loadData.js +2 -2
  29. package/dist/node/index.d.ts +5 -0
  30. package/dist/node/index.d.ts.map +1 -1
  31. package/dist/node/index.js +84 -35
  32. package/dist/plugins/Events.d.ts +4 -4
  33. package/dist/plugins/Plugins.d.ts +2 -2
  34. package/dist/plugins/index.d.ts +2 -3
  35. package/dist/plugins/index.d.ts.map +1 -1
  36. package/dist/plugins/index.js +2 -1
  37. package/dist/queries/Queries.d.ts +9 -0
  38. package/dist/queries/Queries.d.ts.map +1 -1
  39. package/dist/queries/Queries.js +29 -17
  40. package/dist/queries/QueryError.d.ts +2 -0
  41. package/dist/queries/QueryError.d.ts.map +1 -1
  42. package/dist/queries/QueryError.js +6 -1
  43. package/dist/queries/gql.d.ts +2 -2
  44. package/dist/queries/gql.js +2 -2
  45. package/dist/queries/index.d.ts +7 -5
  46. package/dist/queries/index.d.ts.map +1 -1
  47. package/dist/queries/vars.d.ts +7 -7
  48. package/dist/queries/vars.d.ts.map +1 -1
  49. package/dist/queries/vars.js +10 -8
  50. package/dist/routing/LoadRunner.d.ts +1 -1
  51. package/dist/routing/LoadRunner.js +1 -1
  52. package/dist/routing/index.d.ts +4 -4
  53. package/dist/routing/index.d.ts.map +1 -1
  54. package/dist/routing/route/BaseRoute.d.ts +25 -25
  55. package/dist/routing/route/BaseRoute.js +24 -24
  56. package/dist/routing/route/Request.d.ts +4 -4
  57. package/dist/routing/route/Request.js +4 -4
  58. package/dist/routing/route/Route.d.ts +2 -2
  59. package/dist/routing/route/Route.js +2 -2
  60. package/dist/routing/router/BaseRouter.d.ts +4 -4
  61. package/dist/routing/router/BaseRouter.js +3 -3
  62. package/dist/routing/router/ClientRouter.d.ts +1 -1
  63. package/dist/routing/router/ClientRouter.js +1 -1
  64. package/dist/routing/router/Router.d.ts +27 -25
  65. package/dist/routing/router/Router.d.ts.map +1 -1
  66. package/dist/routing/router/Router.js +24 -21
  67. package/dist/routing/router/ServerRouter.d.ts +1 -1
  68. package/dist/routing/router/ServerRouter.js +1 -1
  69. package/dist/server/CrelteServer.d.ts +5 -5
  70. package/dist/server/CrelteServer.d.ts.map +1 -1
  71. package/dist/server/CrelteServer.js +4 -4
  72. package/dist/server/Request.d.ts +7 -1
  73. package/dist/server/Request.d.ts.map +1 -1
  74. package/dist/server/Request.js +7 -1
  75. package/dist/server/ServerRouter.d.ts +1 -1
  76. package/dist/server/ServerRouter.d.ts.map +1 -1
  77. package/dist/server/index.d.ts +4 -4
  78. package/dist/server/index.d.ts.map +1 -1
  79. package/dist/server/index.js +1 -1
  80. package/dist/server/shared.d.ts +7 -13
  81. package/dist/server/shared.d.ts.map +1 -1
  82. package/dist/server/shared.js +14 -16
  83. package/dist/ssr/SsrCache.d.ts +56 -4
  84. package/dist/ssr/SsrCache.d.ts.map +1 -1
  85. package/dist/ssr/SsrCache.js +94 -20
  86. package/dist/std/index.d.ts +13 -0
  87. package/dist/std/index.d.ts.map +1 -1
  88. package/dist/std/index.js +13 -0
  89. package/dist/std/rand/index.d.ts +34 -0
  90. package/dist/std/rand/index.d.ts.map +1 -0
  91. package/dist/std/rand/index.js +45 -0
  92. package/dist/std/rand/internal.d.ts +8 -0
  93. package/dist/std/rand/internal.d.ts.map +1 -0
  94. package/dist/std/rand/internal.js +15 -0
  95. package/dist/std/stores/Writable.d.ts +1 -1
  96. package/dist/std/stores/Writable.js +1 -1
  97. package/dist/translations/index.d.ts +28 -0
  98. package/dist/translations/index.d.ts.map +1 -0
  99. package/dist/translations/index.js +31 -0
  100. package/dist/translations/loadTranslations.d.ts +23 -0
  101. package/dist/translations/loadTranslations.d.ts.map +1 -0
  102. package/dist/translations/loadTranslations.js +26 -0
  103. package/dist/translations/loader/GlobalLoader.d.ts +34 -0
  104. package/dist/translations/loader/GlobalLoader.d.ts.map +1 -0
  105. package/dist/translations/loader/GlobalLoader.js +45 -0
  106. package/dist/translations/loader/fileLoader/ClientFileLoader.d.ts +10 -0
  107. package/dist/translations/loader/fileLoader/ClientFileLoader.d.ts.map +1 -0
  108. package/dist/translations/loader/fileLoader/ClientFileLoader.js +24 -0
  109. package/dist/translations/loader/fileLoader/NodeFileLoader.d.ts +9 -0
  110. package/dist/translations/loader/fileLoader/NodeFileLoader.d.ts.map +1 -0
  111. package/dist/translations/loader/fileLoader/NodeFileLoader.js +21 -0
  112. package/dist/translations/loader/fileLoader/fileLoader.d.ts +5 -0
  113. package/dist/translations/loader/fileLoader/fileLoader.d.ts.map +1 -0
  114. package/dist/translations/loader/fileLoader/fileLoader.js +16 -0
  115. package/dist/translations/loader/index.d.ts +7 -0
  116. package/dist/translations/loader/index.d.ts.map +1 -0
  117. package/dist/translations/loader/index.js +1 -0
  118. package/dist/translations/translationsPlugin.d.ts +64 -0
  119. package/dist/translations/translationsPlugin.d.ts.map +1 -0
  120. package/dist/translations/translationsPlugin.js +110 -0
  121. package/dist/translations/utils.d.ts +8 -0
  122. package/dist/translations/utils.d.ts.map +1 -0
  123. package/dist/translations/utils.js +15 -0
  124. package/dist/vite/index.d.ts.map +1 -1
  125. package/dist/vite/index.js +30 -38
  126. package/package.json +9 -1
  127. package/src/blocks/Blocks.svelte +3 -78
  128. package/src/blocks/Blocks.ts +63 -6
  129. package/src/blocks/index.ts +2 -2
  130. package/src/cookies/ServerCookies.ts +1 -1
  131. package/src/cookies/index.ts +1 -1
  132. package/src/crelte.ts +21 -10
  133. package/src/index.ts +19 -14
  134. package/src/init/client.ts +3 -2
  135. package/src/init/server.ts +14 -8
  136. package/src/loadData/Globals.ts +3 -3
  137. package/src/loadData/loadData.ts +8 -18
  138. package/src/node/index.ts +100 -39
  139. package/src/plugins/Events.ts +4 -4
  140. package/src/plugins/Plugins.ts +2 -2
  141. package/src/plugins/index.ts +2 -3
  142. package/src/queries/Queries.ts +35 -18
  143. package/src/queries/QueryError.ts +10 -1
  144. package/src/queries/gql.ts +2 -2
  145. package/src/queries/index.ts +7 -4
  146. package/src/queries/vars.ts +12 -8
  147. package/src/routing/LoadRunner.ts +1 -1
  148. package/src/routing/index.ts +13 -3
  149. package/src/routing/route/BaseRoute.ts +25 -25
  150. package/src/routing/route/Request.ts +4 -4
  151. package/src/routing/route/Route.ts +2 -2
  152. package/src/routing/router/BaseRouter.ts +4 -4
  153. package/src/routing/router/ClientRouter.ts +1 -1
  154. package/src/routing/router/Router.ts +28 -25
  155. package/src/routing/router/ServerRouter.ts +1 -1
  156. package/src/server/CrelteServer.ts +5 -5
  157. package/src/server/Request.ts +7 -1
  158. package/src/server/ServerRouter.ts +1 -2
  159. package/src/server/index.ts +17 -3
  160. package/src/server/shared.ts +28 -33
  161. package/src/ssr/SsrCache.ts +104 -22
  162. package/src/std/index.ts +14 -0
  163. package/src/std/rand/index.ts +55 -0
  164. package/src/std/rand/internal.ts +17 -0
  165. package/src/std/stores/Writable.ts +1 -1
  166. package/src/translations/index.ts +56 -0
  167. package/src/translations/loadTranslations.ts +33 -0
  168. package/src/translations/loader/GlobalLoader.ts +62 -0
  169. package/src/translations/loader/fileLoader/ClientFileLoader.ts +40 -0
  170. package/src/translations/loader/fileLoader/NodeFileLoader.ts +32 -0
  171. package/src/translations/loader/fileLoader/fileLoader.ts +19 -0
  172. package/src/translations/loader/index.ts +8 -0
  173. package/src/translations/translationsPlugin.ts +145 -0
  174. package/src/translations/utils.ts +17 -0
  175. package/src/vite/index.ts +43 -39
package/src/node/index.ts CHANGED
@@ -5,6 +5,7 @@ import { createReadStream } from 'node:fs';
5
5
  import {
6
6
  EnvData,
7
7
  initEnvData,
8
+ initSites,
8
9
  modRender,
9
10
  modRenderError,
10
11
  } from '../server/shared.js';
@@ -18,6 +19,8 @@ import {
18
19
  webResponseToResponse,
19
20
  writeFile,
20
21
  } from './utils.js';
22
+ import { timeout } from '../std/index.js';
23
+ import { SiteFromGraphQl } from '../routing/Site.js';
21
24
 
22
25
  function localDir(...args: string[]) {
23
26
  return join(path.dirname(fileURLToPath(import.meta.url)), ...args);
@@ -31,23 +34,21 @@ async function writeSitesCache(data: any): Promise<void> {
31
34
  return await writeFile(localDir('sites.json'), JSON.stringify(data));
32
35
  }
33
36
 
34
- export default async function createServer(serverMod: any, buildTime: string) {
35
- const env = await initEnvData(PLATFORM, {
37
+ async function initRouter(
38
+ serverMod: any,
39
+ env: EnvData,
40
+ ): Promise<[SiteFromGraphQl[], ServerRouter]> {
41
+ const sites = await initSites(env, {
36
42
  enabled: process.env.NODE_ENV === 'production',
37
43
  writeSitesCache,
38
44
  readSitesCache,
39
45
  });
40
- const template = await readFile(localDir('index.html'));
41
- const globalEtag = '"' + buildTime + '"';
42
- const ssrManifest = JSON.parse(
43
- await readFile(localDir('ssr-manifest.json')),
44
- );
45
46
 
46
47
  const router = new ServerRouter(
47
48
  env.endpointUrl,
48
49
  env.frontendUrl,
49
50
  env.env,
50
- env.sites,
51
+ sites,
51
52
  {
52
53
  endpointToken: env.endpointToken,
53
54
  },
@@ -59,62 +60,122 @@ export default async function createServer(serverMod: any, buildTime: string) {
59
60
  await serverMod.routes(router);
60
61
  }
61
62
 
63
+ return [sites, router];
64
+ }
65
+
66
+ /**
67
+ * Create and start the server
68
+ *
69
+ * Generally this call should automatically happen via the vite build step.
70
+ */
71
+ export default async function createServer(serverMod: any, buildTime: string) {
72
+ const env = await initEnvData(PLATFORM);
73
+ const template = await readFile(localDir('index.html'));
74
+ const globalEtag = '"' + buildTime + '"';
75
+ const ssrManifest = JSON.parse(
76
+ await readFile(localDir('ssr-manifest.json')),
77
+ );
78
+
79
+ let sites: SiteFromGraphQl[] | null = null;
80
+ let router: ServerRouter | null = null;
81
+ let routesError: any = null;
82
+
83
+ // let's try to init the router
84
+ // if it fails we start a retry loop
85
+ // this way the server can start even if the endpoint is not yet available
86
+ try {
87
+ [sites, router] = await initRouter(serverMod, env);
88
+ } catch (e) {
89
+ routesError = e;
90
+ console.error('Failed to setup router:', e);
91
+
92
+ // retry loop
93
+ (async () => {
94
+ while (!router) {
95
+ await timeout(1000);
96
+
97
+ try {
98
+ [sites, router] = await initRouter(serverMod, env);
99
+ routesError = null;
100
+ } catch (e) {
101
+ routesError = e;
102
+ console.error('Failed to setup router:', e);
103
+ }
104
+ }
105
+ })();
106
+ }
107
+
62
108
  const publicDir = localDir('public');
63
109
 
64
- http.createServer(async (nReq, res) => {
65
- if (await servePublic(nReq, res, publicDir, globalEtag)) return;
110
+ const handle = async (req: Request, res: ServerResponse) => {
111
+ // if router is not set, just render the error page
112
+ if (routesError || !router || !sites) {
113
+ throw routesError ?? new Error('Router not initialized');
114
+ }
66
115
 
67
- // todo this is not safe if we are not in a trusted environment
68
- const baseUrl =
69
- (nReq.headers['x-forwarded-proto'] ?? 'http') +
70
- '://' +
71
- nReq.headers['host'];
116
+ const routeResp = await router.z_handle(req);
117
+ if (routeResp) {
118
+ await webResponseToResponse(routeResp, res);
119
+ return;
120
+ }
72
121
 
73
- const req = requestToWebRequest(baseUrl, nReq);
122
+ if (await basicAuthCheck(req, res, env)) return;
74
123
 
75
- let thrownError: any = null;
124
+ const response = await modRender(env, sites, serverMod, template, req, {
125
+ ssrManifest,
126
+ });
127
+ await webResponseToResponse(response, res);
128
+ };
76
129
 
130
+ http.createServer(async (nodeReq, res) => {
131
+ let req: Request | null = null;
132
+ let err: any;
77
133
  try {
78
- const routeResp = await router.z_handle(req);
79
- if (routeResp) {
80
- await webResponseToResponse(routeResp, res);
81
- return;
82
- }
134
+ if (await servePublic(nodeReq, res, publicDir, globalEtag)) return;
83
135
 
84
- if (await basicAuthCheck(nReq, res, env)) return;
136
+ // todo this is not safe if we are not in a trusted environment
137
+ const baseUrl =
138
+ (nodeReq.headers['x-forwarded-proto'] ?? 'http') +
139
+ '://' +
140
+ nodeReq.headers['host'];
141
+
142
+ req = requestToWebRequest(baseUrl, nodeReq);
143
+
144
+ await handle(req, res);
85
145
 
86
- const response = await modRender(env, serverMod, template, req, {
87
- ssrManifest,
88
- });
89
- await webResponseToResponse(response, res);
90
146
  return;
91
- } catch (e: any) {
92
- if (typeof serverMod.renderError !== 'function') {
93
- console.log('error', e);
94
- throw e;
95
- }
147
+ } catch (e) {
148
+ err = e;
149
+ }
96
150
 
97
- thrownError = e;
151
+ if (typeof serverMod.renderError !== 'function' || !req) {
152
+ basicError(res, err);
153
+ return;
98
154
  }
99
155
 
100
156
  try {
101
157
  const response = await modRenderError(
102
158
  env,
103
159
  serverMod,
104
- thrownError,
160
+ err,
105
161
  template,
106
162
  req,
107
163
  { ssrManifest },
108
164
  );
109
165
  await webResponseToResponse(response, res);
110
- return;
111
166
  } catch (e) {
112
- console.log('error', e);
113
- throw e;
167
+ basicError(res, e);
114
168
  }
115
169
  }).listen(8080);
116
170
  }
117
171
 
172
+ function basicError(res: ServerResponse, err: any) {
173
+ console.error('Internal Server Error:', err);
174
+ res.statusCode = 500;
175
+ res.end('Internal Server Error: ' + err?.message);
176
+ return;
177
+ }
178
+
118
179
  const MIME_TYPES: Record<string, string> = {
119
180
  '.html': 'text/html',
120
181
  '.css': 'text/css',
@@ -203,7 +264,7 @@ async function servePublic(
203
264
  * for staging or unlisted instances.
204
265
  */
205
266
  async function basicAuthCheck(
206
- req: IncomingMessage,
267
+ req: Request,
207
268
  res: ServerResponse,
208
269
  { env }: EnvData,
209
270
  ): Promise<boolean> {
@@ -213,7 +274,7 @@ async function basicAuthCheck(
213
274
  // ignore if one information is missing
214
275
  if (!user || !password) return false;
215
276
 
216
- const authHeader = req.headers['authorization'];
277
+ const authHeader = req.headers.get('authorization');
217
278
 
218
279
  if (!authHeader || !authHeader.startsWith('Basic ')) {
219
280
  res.statusCode = 401;
@@ -12,23 +12,23 @@ export default class Events {
12
12
  /**
13
13
  * Listens for an event.
14
14
  *
15
- * ## beforeRequest
15
+ * #### beforeRequest
16
16
  * Please prefer to return not return a promise only if you need to wait
17
17
  * for something. This allows a push request to be done without a microtask.
18
18
  * Allowing for a better DX.
19
19
  *
20
- * ## loadEntry
20
+ * #### loadEntry
21
21
  * This will execute all listeners in sequence and stop on the first one
22
22
  * which returns an entry.
23
23
  * Will be executed in preload as well.
24
24
  *
25
- * ## beforeQueryEntry
25
+ * #### beforeQueryEntry
26
26
  * This allows to modify the entry query variables before the entry query
27
27
  * is executed.
28
28
  * Will be executed in preload as well.
29
29
  *
30
30
  *
31
- * ## afterLoadEntry
31
+ * #### afterLoadEntry
32
32
  * Will be executed in preload as well.
33
33
  *
34
34
  * @returns a function to remove the listener
@@ -15,8 +15,8 @@ export interface Plugin {
15
15
  * a configurePluginname function which will be called by youre user and should
16
16
  * return a createPlugin function.
17
17
  *
18
- * ## Example App.svelte in module="context"
19
- * ```
18
+ * #### Example App.svelte in module="context"
19
+ * ```js
20
20
  * import { createPlugin, configurePlugin } from 'some-plugin';
21
21
  *
22
22
  * export plugins = [createPlugin, configurePlugin({ enableFeature: true })];
@@ -1,5 +1,4 @@
1
1
  import Events from './Events.js';
2
- import { Plugin, PluginCreator } from './Plugins.js';
2
+ import Plugins, { type Plugin, type PluginCreator } from './Plugins.js';
3
3
 
4
- export type { Plugin, PluginCreator };
5
- export { Events };
4
+ export { Plugins, Events, Plugin, PluginCreator };
@@ -91,12 +91,21 @@ export default class Queries {
91
91
  this.request = request;
92
92
  }
93
93
 
94
+ /**
95
+ * Create a new Queries instance
96
+ *
97
+ * @param endpoint the craft GraphQl endpoint
98
+ * @param frontend the frontend url where the server queries are reachable
99
+ * @param ssrCache the ssrCache to use for caching
100
+ * @param opts options
101
+ * @returns
102
+ */
94
103
  static new(
95
104
  endpoint: string,
96
105
  frontend: string,
97
106
  ssrCache: SsrCache,
98
107
  opts: QueriesOptions = {},
99
- ) {
108
+ ): Queries {
100
109
  return new Queries(
101
110
  new Inner(endpoint, frontend, ssrCache, opts),
102
111
  opts?.route ?? null,
@@ -131,6 +140,8 @@ export default class Queries {
131
140
  // for convenience we set the siteId as variable if it is known
132
141
  if (siteId !== null) vars = { siteId, ...vars };
133
142
 
143
+ // todo, maybe we should set the XCraftSiteId, with the siteId from vars?
144
+
134
145
  return this.inner.query(query, vars, {
135
146
  previewToken,
136
147
  siteToken,
@@ -217,16 +228,15 @@ class Inner {
217
228
 
218
229
  try {
219
230
  const resp = await this.queryNotCached(query, vars, opts);
231
+
220
232
  if (key) {
221
233
  // todo maybe we should objClone here?
222
234
  this.ssrCache.set(key, resp);
223
235
 
224
- // ! because the listeners get's in the previous if statement and will
225
- // always be set when the key is set
236
+ // ! (never null) because the listeners get's in the previous
237
+ // if statement and will always be set when the key is set
226
238
  const listeners = this.listeners.get(key)!;
227
- listeners.forEach(([resolve, _error]) => {
228
- resolve(resp);
229
- });
239
+ listeners.forEach(([resolve, _error]) => resolve(resp));
230
240
 
231
241
  this.listeners.delete(key);
232
242
  }
@@ -234,12 +244,10 @@ class Inner {
234
244
  return resp;
235
245
  } catch (e: unknown) {
236
246
  if (key) {
237
- // ! because the listeners get's in the previous if statement and will
238
- // always be set when the key is set
247
+ // ! (never null) because the listeners get's in the previous
248
+ // if statement and will always be set when the key is set
239
249
  const listeners = this.listeners.get(key)!;
240
- listeners.forEach(([_resolve, error]) => {
241
- error(e);
242
- });
250
+ listeners.forEach(([_resolve, error]) => error(e));
243
251
 
244
252
  this.listeners.delete(key);
245
253
  }
@@ -291,11 +299,17 @@ class Inner {
291
299
  body = { query: query.query, variables: vars };
292
300
  }
293
301
 
294
- const resp = await fetch(url, {
295
- method: 'POST',
296
- headers,
297
- body: JSON.stringify(body),
298
- });
302
+ let resp: Response;
303
+
304
+ try {
305
+ resp = await fetch(url, {
306
+ method: 'POST',
307
+ headers,
308
+ body: JSON.stringify(body),
309
+ });
310
+ } catch (e: any) {
311
+ throw new Error(`query to '${url}' failed with: ${e.message}`);
312
+ }
299
313
 
300
314
  if (!resp.ok) {
301
315
  throw new QueryError(
@@ -322,8 +336,11 @@ class Inner {
322
336
  }
323
337
 
324
338
  if ('errors' in jsonResp) {
325
- console.log(logName + ' errors', jsonResp.errors);
326
- throw new QueryError({ status: resp.status }, jsonResp.errors);
339
+ console.error(logName + ' errors', jsonResp.errors);
340
+ throw new QueryError(
341
+ { status: resp.status, errors: jsonResp.errors },
342
+ 'received errors',
343
+ );
327
344
  }
328
345
 
329
346
  return jsonResp.data ?? null;
@@ -1,6 +1,7 @@
1
1
  export type QueryErrorResponse = {
2
2
  status?: number;
3
3
  body?: string;
4
+ errors?: any[];
4
5
  };
5
6
 
6
7
  // todo improve this
@@ -32,6 +33,14 @@ export default class QueryError extends Error {
32
33
  * The error message in string form
33
34
  */
34
35
  get message(): string {
35
- return 'QueryError: ' + JSON.stringify(this.resp);
36
+ return 'QueryError: ' + JSON.stringify(this.resp, null, ' ');
36
37
  }
37
38
  }
39
+
40
+ export function isQueryError(err: any): err is QueryError {
41
+ return (
42
+ typeof err === 'object' &&
43
+ err !== null &&
44
+ typeof err.__QueryError__ === 'function'
45
+ );
46
+ }
@@ -5,8 +5,8 @@ import { isQuery, Query } from './Queries.js';
5
5
  * @param strings
6
6
  * @param keys
7
7
  *
8
- * ## Example
9
- * ```
8
+ * #### Example
9
+ * ```js
10
10
  * const query = gql`query ($id: ID!) { page(id: $id) { id } }`;
11
11
  * ```
12
12
  */
@@ -5,7 +5,7 @@ import Queries, {
5
5
  QueryOptions,
6
6
  } from '../queries/Queries.js';
7
7
  import { gql } from './gql.js';
8
- import QueryError from './QueryError.js';
8
+ import QueryError, { QueryErrorResponse } from './QueryError.js';
9
9
  import { QueryVar, ValidIf, vars, varsIdsEqual } from './vars.js';
10
10
 
11
11
  export {
@@ -15,6 +15,7 @@ export {
15
15
  type Query,
16
16
  isQuery,
17
17
  QueryError,
18
+ type QueryErrorResponse,
18
19
  gql,
19
20
  vars,
20
21
  type ValidIf,
@@ -22,14 +23,16 @@ export {
22
23
  varsIdsEqual,
23
24
  };
24
25
 
25
- type InferQueryVarType<T> = T extends QueryVar<infer U> ? U : never;
26
+ /** @hidden */
27
+ export type InferQueryVarType<T> = T extends QueryVar<infer U> ? U : never;
26
28
 
27
- type InferVariableTypes<T> = {
29
+ /** @hidden */
30
+ export type InferVariableTypes<T> = {
28
31
  [K in keyof T]: InferQueryVarType<T[K]>;
29
32
  };
30
33
 
31
34
  /**
32
- * ## Example
35
+ * #### Example
33
36
  * ```ts
34
37
  * import { vars, Caching } from 'crelte/queries';
35
38
  *
@@ -9,7 +9,7 @@ export const vars = {
9
9
  * Id is almost the same as number but will also parse
10
10
  * strings, but only allow non negative integers
11
11
  *
12
- * ## Warning
12
+ * #### Warning
13
13
  * Ids are not automatically safe to be cached
14
14
  * you need to validate the response to make sure filters
15
15
  * with this id returned something
@@ -24,7 +24,7 @@ export const vars = {
24
24
  *
25
25
  * The numbers are always unique and sorted in ascending order
26
26
  *
27
- * ## Warning
27
+ * #### Warning
28
28
  * Ids are not automatically safe to be cached, it is also not
29
29
  * enough to just check if the filter returned some results.
30
30
  * Since for example a `relatedTo` filter works like an `or` and
@@ -180,7 +180,11 @@ export class QueryVar<T = any> {
180
180
  }
181
181
 
182
182
  export function isQueryVar(v: any): v is QueryVar {
183
- return v && typeof v === 'object' && typeof v.__QueryVar__ === 'function';
183
+ return (
184
+ typeof v === 'object' &&
185
+ v !== null &&
186
+ typeof v.__QueryVar__ === 'function'
187
+ );
184
188
  }
185
189
 
186
190
  // does not do string to number conversion
@@ -194,8 +198,8 @@ function isValidId(id: any): id is number {
194
198
  * The first argument needs to come from a `vars.ids()` variable.
195
199
  * The second argument should come from a query, where the output is trusted.
196
200
  *
197
- * ## Example
198
- * ```
201
+ * #### Example
202
+ * ```js
199
203
  * export const variables = {
200
204
  * categories: vars.ids()
201
205
  * };
@@ -206,15 +210,15 @@ function isValidId(id: any): id is number {
206
210
  * };
207
211
  * ```
208
212
  *
209
- * ## Note
213
+ * #### Note
210
214
  * The following cases are considered equal:
211
- * ```
215
+ * ```js
212
216
  * varsIdsEqual(null, null);
213
217
  * varsIdsEqual([], null);
214
218
  * varsIdsEqual([1,2], ['2',1]);
215
219
  * ```
216
220
  * These are not equal:
217
- * ```
221
+ * ```js
218
222
  * varsIdsEqual([1], null);
219
223
  * varsIdsEqual([2,1], [2,1]); // because the second arg gets ordered
220
224
  * ```
@@ -52,7 +52,7 @@ export default class LoadRunner {
52
52
  /**
53
53
  * @returns true if the load was completed
54
54
  *
55
- * ## Throws
55
+ * #### Throws
56
56
  * if there was an error but not if the request
57
57
  * was cancelled before
58
58
  */
@@ -1,22 +1,32 @@
1
1
  import Router, { type UpdateRequest } from './router/Router.js';
2
- import Route, { type RouteOptions } from './route/Route.js';
2
+ import Route, {
3
+ type TemplateModule,
4
+ type RouteOptions,
5
+ } from './route/Route.js';
3
6
  import Request, {
4
7
  type RequestOptions,
5
8
  type DelayRender,
6
9
  } from './route/Request.js';
7
- import Site from './Site.js';
8
- import BaseRoute from './route/BaseRoute.js';
10
+ import Site, { type SiteFromGraphQl } from './Site.js';
11
+ import BaseRoute, {
12
+ type BaseRouteOptions,
13
+ type RouteOrigin,
14
+ } from './route/BaseRoute.js';
9
15
  import { shouldInterceptClick } from './utils.js';
10
16
 
11
17
  export {
12
18
  Router,
13
19
  UpdateRequest,
14
20
  BaseRoute,
21
+ BaseRouteOptions,
15
22
  Route,
16
23
  RouteOptions,
24
+ TemplateModule,
17
25
  Site,
26
+ SiteFromGraphQl,
18
27
  Request,
19
28
  DelayRender,
20
29
  RequestOptions,
21
30
  shouldInterceptClick,
31
+ RouteOrigin,
22
32
  };