@gracile/engine 0.7.0-next.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/build/static.d.ts.map +1 -1
  2. package/dist/build/static.js +6 -1
  3. package/dist/dev/dev.d.ts.map +1 -1
  4. package/dist/dev/dev.js +23 -16
  5. package/dist/dev/vite-logger.d.ts +2 -0
  6. package/dist/dev/vite-logger.d.ts.map +1 -0
  7. package/dist/dev/vite-logger.js +2 -0
  8. package/dist/errors/create-vite-better-error.d.ts +6 -0
  9. package/dist/errors/create-vite-better-error.d.ts.map +1 -0
  10. package/dist/errors/create-vite-better-error.js +27 -0
  11. package/dist/errors/errors-data.d.ts +81 -0
  12. package/dist/errors/errors-data.d.ts.map +1 -0
  13. package/dist/errors/errors-data.js +98 -0
  14. package/dist/errors/errors.d.ts +22 -0
  15. package/dist/errors/errors.d.ts.map +1 -0
  16. package/dist/errors/errors.js +122 -0
  17. package/dist/errors/pages.d.ts +4 -0
  18. package/dist/errors/pages.d.ts.map +1 -0
  19. package/dist/errors/pages.js +135 -0
  20. package/dist/logging/messages.d.ts +2 -0
  21. package/dist/logging/messages.d.ts.map +1 -0
  22. package/dist/logging/messages.js +6 -0
  23. package/dist/plugin.d.ts.map +1 -1
  24. package/dist/plugin.js +33 -5
  25. package/dist/render/route-template.d.ts.map +1 -1
  26. package/dist/render/route-template.js +37 -9
  27. package/dist/routes/collect.d.ts +2 -1
  28. package/dist/routes/collect.d.ts.map +1 -1
  29. package/dist/routes/collect.js +13 -9
  30. package/dist/routes/load-module.d.ts +1 -1
  31. package/dist/routes/load-module.d.ts.map +1 -1
  32. package/dist/routes/load-module.js +31 -5
  33. package/dist/routes/match.d.ts +1 -1
  34. package/dist/routes/match.d.ts.map +1 -1
  35. package/dist/routes/match.js +24 -10
  36. package/dist/routes/route.d.ts +1 -1
  37. package/dist/routes/route.d.ts.map +1 -1
  38. package/dist/routes/route.js +14 -12
  39. package/dist/server/adapters/hono.d.ts +5 -2
  40. package/dist/server/adapters/hono.d.ts.map +1 -1
  41. package/dist/server/adapters/hono.js +9 -3
  42. package/dist/server/adapters/node.d.ts +4 -2
  43. package/dist/server/adapters/node.d.ts.map +1 -1
  44. package/dist/server/adapters/node.js +24 -9
  45. package/dist/server/request.d.ts +4 -1
  46. package/dist/server/request.d.ts.map +1 -1
  47. package/dist/server/request.js +44 -42
  48. package/dist/server/utils.d.ts.map +1 -1
  49. package/dist/server/utils.js +2 -1
  50. package/dist/tsconfig.tsbuildinfo +1 -1
  51. package/dist/vite/plugins/build-routes.d.ts.map +1 -1
  52. package/dist/vite/plugins/build-routes.js +5 -3
  53. package/dist/vite/plugins/virtual-routes.d.ts.map +1 -1
  54. package/dist/vite/plugins/virtual-routes.js +3 -2
  55. package/package.json +5 -4
  56. package/dist/assertions.d.ts +0 -13
  57. package/dist/assertions.d.ts.map +0 -1
  58. package/dist/assertions.js +0 -45
  59. package/dist/errors/templates.d.ts +0 -3
  60. package/dist/errors/templates.d.ts.map +0 -1
  61. package/dist/errors/templates.js +0 -69
@@ -1 +1 @@
1
- {"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../src/build/static.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAK1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,WAAW,uBAAuB;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpB,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,MAAM,EAAE;QACP,KAAK,EAAE,OAAO,CAAC;QACf,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;KACxB,CAAC;IAEF,aAAa,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9B;AAeD,wBAAsB,YAAY,CAAC,EAClC,MAAM,EACN,IAAI,EACJ,UAAU,EACV,IAAoB,EACpB,aAAa,GACb,EAAE;IACF,MAAM,EAAE,cAAc,CAAC;IACvB,IAAI,EAAE,aAAa,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,aAAa,CAAC;CAC7B;;;GAmJA"}
1
+ {"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../src/build/static.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAK1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,WAAW,uBAAuB;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpB,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,MAAM,EAAE;QACP,KAAK,EAAE,OAAO,CAAC;QACf,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;KACxB,CAAC;IAEF,aAAa,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9B;AAeD,wBAAsB,YAAY,CAAC,EAClC,MAAM,EACN,IAAI,EACJ,UAAU,EACV,IAAoB,EACpB,aAAa,GACb,EAAE;IACF,MAAM,EAAE,cAAc,CAAC;IACvB,IAAI,EAAE,aAAa,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,aAAa,CAAC;CAC7B;;;GAwJA"}
@@ -1,6 +1,6 @@
1
1
  import { Buffer } from 'node:buffer';
2
2
  import path, { join } from 'node:path';
3
- import { logger } from '@gracile/internal-utils/logger';
3
+ import { getLogger } from '@gracile/internal-utils/logger/helpers';
4
4
  import c from 'picocolors';
5
5
  import { renderRouteTemplate } from '../render/route-template.js';
6
6
  import { collectRoutes } from '../routes/collect.js';
@@ -18,6 +18,7 @@ async function streamToString(stream) {
18
18
  return Buffer.concat(chunks).toString('utf-8');
19
19
  }
20
20
  export async function renderRoutes({ routes, vite, serverMode, root = process.cwd(), gracileConfig, }) {
21
+ const logger = getLogger();
21
22
  logger.info(c.green('Rendering routes…'), { timestamp: true });
22
23
  // MARK: Collect
23
24
  await collectRoutes(routes, root, gracileConfig.routes?.exclude);
@@ -83,6 +84,8 @@ export async function renderRoutes({ routes, vite, serverMode, root = process.cw
83
84
  : 'index.html');
84
85
  if (name === '404/index.html')
85
86
  name = '404.html';
87
+ if (name === '500/index.html')
88
+ name = '500.html';
86
89
  const url = new URL(pathnameWithParams, 'http://gracile-static');
87
90
  // MARK: Render
88
91
  const { output, document } = await renderRouteTemplate({
@@ -103,6 +106,8 @@ export async function renderRoutes({ routes, vite, serverMode, root = process.cw
103
106
  });
104
107
  const htmlString = output ? await streamToString(output) : null;
105
108
  const existing = renderedRoutes.find((rendered) => rendered?.name === name);
109
+ // NOTE: IIRC, this happens when two or more routes has the
110
+ // same priority, that will output the same static path.
106
111
  if (existing)
107
112
  throw new Error(`${c.red(`"${existing.name}" page was defined twice!`)}\n`);
108
113
  const savePrerender = routeModule.prerender || null;
@@ -1 +1 @@
1
- {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/dev/dev.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,MAAM,CAAC;AAG1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAEN,KAAK,cAAc,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD,wBAAsB,gBAAgB,CAAC,EACtC,MAAM,EACN,IAAI,EACJ,aAAa,GACb,EAAE;IACF,MAAM,EAAE,cAAc,CAAC;IACvB,IAAI,EAAE,aAAa,CAAC;IACpB,aAAa,EAAE,aAAa,CAAC;CAC7B,GAAG,OAAO,CAAC;IACX,OAAO,EAAE,cAAc,CAAC;IACxB,MAAM,EAAE,cAAc,CAAC;CACvB,CAAC,CA4CD"}
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/dev/dev.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,MAAM,CAAC;AAG1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAEN,KAAK,cAAc,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD,wBAAsB,gBAAgB,CAAC,EACtC,MAAM,EACN,IAAI,EACJ,aAAa,GACb,EAAE;IACF,MAAM,EAAE,cAAc,CAAC;IACvB,IAAI,EAAE,aAAa,CAAC;IACpB,aAAa,EAAE,aAAa,CAAC;CAC7B,GAAG,OAAO,CAAC;IACX,OAAO,EAAE,cAAc,CAAC;IACxB,MAAM,EAAE,cAAc,CAAC;CACvB,CAAC,CAgDD"}
package/dist/dev/dev.js CHANGED
@@ -1,26 +1,33 @@
1
- import { logger } from '@gracile/internal-utils/logger';
1
+ import { getLogger } from '@gracile/internal-utils/logger/helpers';
2
2
  import c from 'picocolors';
3
3
  import {} from 'vite';
4
- import { collectRoutes } from '../routes/collect.js';
4
+ import { collectRoutes, WATCHED_FILES_REGEX } from '../routes/collect.js';
5
5
  import { createGracileHandler, } from '../server/request.js';
6
6
  import { generateRoutesTypings } from './route-typings.js';
7
7
  export async function createDevHandler({ routes, vite, gracileConfig, }) {
8
+ const logger = getLogger();
8
9
  const root = vite.config.root;
9
- logger.info(c.dim('\nCreating handler…'), { timestamp: true });
10
- await collectRoutes(routes, root, gracileConfig.routes?.exclude);
11
- if (gracileConfig.experimental?.generateRoutesTypings)
12
- generateRoutesTypings(root, routes).catch((error) => logger.error(String(error)));
10
+ logger.info('');
11
+ logger.info(c.dim('Creating the request handler…'), { timestamp: true });
12
+ const collect = async () => {
13
+ await collectRoutes(routes, root, gracileConfig.routes?.exclude);
14
+ if (gracileConfig.experimental?.generateRoutesTypings)
15
+ await generateRoutesTypings(root, routes).catch((error) => logger.error(String(error)));
16
+ };
17
+ await collect();
18
+ let wait;
13
19
  vite.watcher.on('all', (event, file) => {
14
- // console.log({ event });
15
- if (file.match(/\/src\/routes\/(.*)\.(ts|js|css|scss|sass|less|styl|stylus)$/) &&
16
- ['add', 'unlink'].includes(event))
17
- collectRoutes(routes, root, gracileConfig.routes?.exclude)
18
- .then(() => {
19
- vite.hot.send('vite:invalidate');
20
- if (gracileConfig.experimental?.generateRoutesTypings)
21
- generateRoutesTypings(root, routes).catch((error) => logger.error(String(error)));
22
- })
23
- .catch((e) => logger.error(String(e)));
20
+ if (file.match(WATCHED_FILES_REGEX) &&
21
+ ['add', 'unlink'].includes(event)
22
+ //
23
+ ) {
24
+ clearTimeout(wait);
25
+ wait = setTimeout(() => {
26
+ collect()
27
+ .then(() => vite.hot.send('vite:invalidate'))
28
+ .catch((error) => logger.error(String(error)));
29
+ }, 100);
30
+ }
24
31
  });
25
32
  //
26
33
  // NOTE: Wrong place?
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=vite-logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-logger.d.ts","sourceRoot":"","sources":["../../src/dev/vite-logger.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ import { createGracileViteLogger } from '@gracile/internal-utils/logger/vite-logger';
2
+ createGracileViteLogger();
@@ -0,0 +1,6 @@
1
+ import type { ViteDevServer } from 'vite';
2
+ export declare function emitViteBetterError({ error, vite, }: {
3
+ error: Error;
4
+ vite: ViteDevServer;
5
+ }): Promise<string>;
6
+ //# sourceMappingURL=create-vite-better-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-vite-better-error.d.ts","sourceRoot":"","sources":["../../src/errors/create-vite-better-error.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,MAAM,CAAC;AAQxD,wBAAsB,mBAAmB,CAAC,EACzC,KAAK,EACL,IAAI,GACJ,EAAE;IACF,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,aAAa,CAAC;CACpB,mBA6BA"}
@@ -0,0 +1,27 @@
1
+ import { pathToFileURL } from 'node:url';
2
+ import { getLogger } from '@gracile/internal-utils/logger/helpers';
3
+ import { formatErrorMessage } from '@gracile-labs/better-errors/dev/logger';
4
+ import { collectErrorMetadata } from '@gracile-labs/better-errors/dev/utils';
5
+ import { getViteErrorPayload } from '@gracile-labs/better-errors/dev/vite';
6
+ import { renderLitTemplate } from '../render/utils.js';
7
+ import { GRACILE_JS_ERRORS_DOCS_BASE, GracileErrorData } from './errors.js';
8
+ import { builtInErrorPage } from './pages.js';
9
+ const logger = getLogger();
10
+ export async function emitViteBetterError({ error, vite, }) {
11
+ const errorWithMetadata = collectErrorMetadata(error, pathToFileURL(vite.config.root));
12
+ logger.error(formatErrorMessage(errorWithMetadata, false, GracileErrorData, GRACILE_JS_ERRORS_DOCS_BASE), {
13
+ timestamp: true,
14
+ });
15
+ const payload = await getViteErrorPayload({
16
+ docsBaseUrl: GRACILE_JS_ERRORS_DOCS_BASE,
17
+ errorsData: GracileErrorData,
18
+ err: errorWithMetadata,
19
+ });
20
+ setTimeout(() => {
21
+ vite.hot.send(payload);
22
+ // NOTE: Arbitrary value. Lower seems to be too fast, higher is not guaranteed to work.
23
+ }, 200);
24
+ const errorPage = builtInErrorPage(error.name ?? 'Error', true);
25
+ const renderedErrorPage = await renderLitTemplate(errorPage);
26
+ return renderedErrorPage;
27
+ }
@@ -0,0 +1,81 @@
1
+ export interface ErrorData {
2
+ name: string;
3
+ title: string;
4
+ message?: string | ((...params: any) => string) | undefined;
5
+ hint?: string | ((...params: any) => string) | undefined;
6
+ }
7
+ /**
8
+ * @docs
9
+ * @kind heading
10
+ * @name Gracile Errors
11
+ */
12
+ /**
13
+ *
14
+ */
15
+ export declare const FailedToLoadModuleSSR: {
16
+ readonly name: "FailedToLoadModuleSSR";
17
+ readonly title: "Could not import file.";
18
+ readonly message: (importName: string) => string;
19
+ readonly hint: "This is often caused by a typo in the import path. Please make sure the file exists.";
20
+ };
21
+ /**
22
+ *
23
+ */
24
+ /**
25
+ *
26
+ */
27
+ export declare const InvalidRequestInAdapter: {
28
+ readonly name: "InvalidRequestInAdapter";
29
+ readonly title: "Invalid request in adapter.";
30
+ readonly message: (adapterName: string) => string;
31
+ readonly hint: "Check that you have configured the adapter correctly.";
32
+ };
33
+ /**
34
+ *
35
+ */
36
+ export declare const InvalidResponseInAdapter: {
37
+ readonly name: "InvalidResponseInAdapter";
38
+ readonly title: "Invalid response in adapter.";
39
+ readonly message: (adapterName: string) => string;
40
+ readonly hint: undefined;
41
+ };
42
+ /**
43
+ *
44
+ */
45
+ export declare const InvalidRouteDocument: {
46
+ readonly name: "RoutePageRender";
47
+ readonly title: "Invalid route document configuration.";
48
+ readonly message: (routePath: string) => string;
49
+ readonly hint: undefined;
50
+ };
51
+ /**
52
+ *
53
+ */
54
+ export declare const InvalidRouteDocumentResult: {
55
+ readonly name: "RoutePageRender";
56
+ readonly title: "Incorrect document template result.";
57
+ readonly message: (routePath: string) => string;
58
+ readonly hint: undefined;
59
+ };
60
+ /**
61
+ *
62
+ */
63
+ export declare const InvalidRouteExport: {
64
+ readonly name: "InvalidRouteExport";
65
+ readonly title: "Invalid route export.";
66
+ readonly message: (routePath: string) => string;
67
+ readonly hint: "Should export a default `defineRoute` function.";
68
+ };
69
+ /**
70
+ *
71
+ */
72
+ export declare const CouldNotRenderRouteDocument: {
73
+ readonly name: "CouldNotRenderRouteDocument";
74
+ readonly title: "Could not render the route document.";
75
+ readonly message: (routePath: string) => string;
76
+ readonly hint: undefined;
77
+ };
78
+ /**
79
+ *
80
+ */
81
+ //# sourceMappingURL=errors-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-data.d.ts","sourceRoot":"","sources":["../../src/errors/errors-data.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,SAAS;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;IAC5D,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;CACzD;AAED;;;;GAIG;AAGH;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;mCAGX,MAAM;;CAEC,CAAC;AAC/B;;GAEG;AAgBH;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;oCAGZ,MAAM;;CAGA,CAAC;AAC/B;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;oCAGb,MAAM;;CAGA,CAAC;AAC/B;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;kCAGX,MAAM;;CAGE,CAAC;AAC/B;;GAEG;AACH,eAAO,MAAM,0BAA0B;;;kCAGjB,MAAM;;CAGE,CAAC;AAC/B;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;kCAGT,MAAM;;CAEE,CAAC;AAC/B;;GAEG;AACH,eAAO,MAAM,2BAA2B;;;kCAGlB,MAAM;;CAGE,CAAC;AAC/B;;GAEG"}
@@ -0,0 +1,98 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /**
3
+ * @docs
4
+ * @kind heading
5
+ * @name Gracile Errors
6
+ */
7
+ // Gracile Errors, most errors will go here!
8
+ /**
9
+ *
10
+ */
11
+ export const FailedToLoadModuleSSR = {
12
+ name: 'FailedToLoadModuleSSR',
13
+ title: 'Could not import file.',
14
+ message: (importName) => `Could not import \`${importName}\`.`,
15
+ hint: 'This is often caused by a typo in the import path. Please make sure the file exists.',
16
+ };
17
+ /**
18
+ *
19
+ */
20
+ // export const FailedToGlobalLogger = {
21
+ // name: 'FailedToGlobalLogger',
22
+ // title: 'Could not get the global logger.',
23
+ // message: undefined,
24
+ // hint: 'This a Gracile internal fault.',
25
+ // };
26
+ // /**
27
+ // *
28
+ // */
29
+ // export const FailedToGetGracileVersion = {
30
+ // name: 'FailedToGetGracileVersion',
31
+ // title: 'Version must be set before.',
32
+ // message: undefined,
33
+ // hint: 'This a Gracile internal fault.',
34
+ // } as const satisfies ErrorData;
35
+ /**
36
+ *
37
+ */
38
+ export const InvalidRequestInAdapter = {
39
+ name: 'InvalidRequestInAdapter',
40
+ title: 'Invalid request in adapter.',
41
+ message: (adapterName) => `Invalid request for adapter name: \`${adapterName}\`.`,
42
+ hint: 'Check that you have configured the adapter correctly.',
43
+ };
44
+ /**
45
+ *
46
+ */
47
+ export const InvalidResponseInAdapter = {
48
+ name: 'InvalidResponseInAdapter',
49
+ title: 'Invalid response in adapter.',
50
+ message: (adapterName) => `Invalid response for adapter name: \`${adapterName}\`.`,
51
+ hint: undefined,
52
+ };
53
+ /**
54
+ *
55
+ */
56
+ export const InvalidRouteDocument = {
57
+ name: 'RoutePageRender',
58
+ title: 'Invalid route document configuration.',
59
+ message: (routePath) => `Route document must be a function for: \`${routePath}\`.`,
60
+ hint: undefined,
61
+ };
62
+ /**
63
+ *
64
+ */
65
+ export const InvalidRouteDocumentResult = {
66
+ name: 'RoutePageRender',
67
+ title: 'Incorrect document template result.',
68
+ message: (routePath) => `Incorrect document template result for: \`${routePath}\`.`,
69
+ hint: undefined,
70
+ };
71
+ /**
72
+ *
73
+ */
74
+ export const InvalidRouteExport = {
75
+ name: 'InvalidRouteExport',
76
+ title: 'Invalid route export.',
77
+ message: (routePath) => `Incorrect route module: \`${routePath}\`.`,
78
+ hint: `Should export a default \`defineRoute\` function.`,
79
+ };
80
+ /**
81
+ *
82
+ */
83
+ export const CouldNotRenderRouteDocument = {
84
+ name: 'CouldNotRenderRouteDocument',
85
+ title: 'Could not render the route document.',
86
+ message: (routePath) => `Could not render the route document for: \`${routePath}\`.`,
87
+ hint: undefined,
88
+ };
89
+ /**
90
+ *
91
+ */
92
+ // export const NoRoutesFound = {
93
+ // name: 'NoRoutesFound',
94
+ // title: 'Could not find any routes.',
95
+ // message: `Could not find any routes for your project.`,
96
+ // hint: 'You have to populate the `src/routes` folder.',
97
+ // };
98
+ // `Wrong template result for fragment template ${routeInfos.foundRoute.filePath}.`,
@@ -0,0 +1,22 @@
1
+ import { BetterError, type BuiltinErrorTypes } from '@gracile-labs/better-errors/errors';
2
+ export * as GracileErrorData from './errors-data.js';
3
+ export declare const GRACILE_JS_ERRORS_DOCS_BASE = "https://gracile.js.org/docs/references/errors";
4
+ type ErrorTypes = BuiltinErrorTypes | 'GracileError' | 'TemplateError' | 'InternalError' | 'TypeGuardError' | 'AggregateError';
5
+ export declare class GracileError extends BetterError<ErrorTypes> {
6
+ type: ErrorTypes;
7
+ static is(err: unknown): err is GracileError;
8
+ }
9
+ export declare class TemplateError extends GracileError {
10
+ type: ErrorTypes;
11
+ static is(err: unknown): err is TemplateError;
12
+ }
13
+ export declare class InternalError extends GracileError {
14
+ type: ErrorTypes;
15
+ static is(err: unknown): err is InternalError;
16
+ }
17
+ /**
18
+ * An error util. that should never be called in theory.
19
+ */
20
+ export declare class TypeGuardError extends Error {
21
+ }
22
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors/errors.ts"],"names":[],"mappings":"AAIA,OAAO,EACN,WAAW,EACX,KAAK,iBAAiB,EACtB,MAAM,oCAAoC,CAAC;AAI5C,OAAO,KAAK,gBAAgB,MAAM,kBAAkB,CAAC;AAErD,eAAO,MAAM,2BAA2B,kDACQ,CAAC;AAEjD,KAAK,UAAU,GACZ,iBAAiB,GACjB,cAAc,GACd,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,gBAAgB,CAAC;AAQpB,qBAAa,YAAa,SAAQ,WAAW,CAAC,UAAU,CAAC;IACxD,IAAI,EAAE,UAAU,CAAkB;IAElC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,YAAY;CAG5C;AAED,qBAAa,aAAc,SAAQ,YAAY;IAC9C,IAAI,EAAE,UAAU,CAAmB;IAEnC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,aAAa;CAG7C;AAED,qBAAa,aAAc,SAAQ,YAAY;IAC9C,IAAI,EAAE,UAAU,CAAmB;IAEnC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,aAAa;CAG7C;AAuGD;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;CAAG"}
@@ -0,0 +1,122 @@
1
+ /* eslint-disable max-classes-per-file */
2
+ /* eslint-disable @typescript-eslint/lines-between-class-members */
3
+ // NOTE: Taken and adapted from https://github.com/withGracile/Gracile/blob/cf65476b27053333cf5a36f6f9f46b794c98dfa2/packages/Gracile/src/core/errors/errors.ts
4
+ import { BetterError, } from '@gracile-labs/better-errors/errors';
5
+ // import { codeFrame } from '@gracile-labs/better-errors/printer';
6
+ export * as GracileErrorData from './errors-data.js';
7
+ export const GRACILE_JS_ERRORS_DOCS_BASE = 'https://gracile.js.org/docs/references/errors';
8
+ // | 'BetterError'
9
+ // | 'GracileUserError'
10
+ // | 'CompilerError'
11
+ // | 'CSSError'
12
+ // | 'MarkdownError'
13
+ export class GracileError extends BetterError {
14
+ type = 'GracileError';
15
+ static is(err) {
16
+ return err.type === 'GracileError';
17
+ }
18
+ }
19
+ export class TemplateError extends GracileError {
20
+ type = 'TemplateError';
21
+ static is(err) {
22
+ return err.type === 'TemplateError';
23
+ }
24
+ }
25
+ export class InternalError extends GracileError {
26
+ type = 'InternalError';
27
+ static is(err) {
28
+ return err.type === 'InternalError';
29
+ }
30
+ }
31
+ //
32
+ // /* eslint-disable @typescript-eslint/lines-between-class-members */
33
+ // /* eslint-disable max-classes-per-file */
34
+ // import type { buildErrorMessage } from 'vite';
35
+ // export type RollupError = Parameters<typeof buildErrorMessage>['0'];
36
+ // export abstract class BetterError extends Error implements RollupError {
37
+ // // --- RollupError
38
+ // watchFiles?: string[];
39
+ // binding?: string;
40
+ // cause?: unknown;
41
+ // code?: string;
42
+ // exporter?: string;
43
+ // frame?: string;
44
+ // hook?: string;
45
+ // id?: string;
46
+ // ids?: string[];
47
+ // loc?: { column: number; file?: string; line: number };
48
+ // meta?: unknown;
49
+ // names?: string[];
50
+ // plugin?: string;
51
+ // pluginCode?: unknown;
52
+ // pos?: number;
53
+ // reexporter?: string;
54
+ // stack?: string;
55
+ // url?: string;
56
+ // // --- End RollupError
57
+ // constructor(message: string, options?: { cause?: unknown }) {
58
+ // super(message);
59
+ // this.name = 'BetterError';
60
+ // this.cause = options?.cause;
61
+ // }
62
+ // }
63
+ // export class GracileUnknownError extends BetterError {
64
+ // constructor(message: string, options?: { cause?: unknown }) {
65
+ // super(message, options);
66
+ // this.name = 'GracileUnknownError';
67
+ // }
68
+ // }
69
+ // export class SsrError extends BetterError {
70
+ // constructor(message: string, options?: { cause?: unknown }) {
71
+ // super(message, options);
72
+ // this.name = 'SsrError';
73
+ // }
74
+ // }
75
+ // export function isViteError(error: unknown): error is RollupError {
76
+ // if (
77
+ // typeof error === 'object' &&
78
+ // error &&
79
+ // 'message' in error &&
80
+ // 'plugin' in error &&
81
+ // typeof error.plugin === 'string' &&
82
+ // error.plugin.startsWith(`vite:`)
83
+ // )
84
+ // return true;
85
+ // return false;
86
+ // }
87
+ // // export type EsbuildError = {
88
+ // // plugin: 'vite:esbuild';
89
+ // // } & RollupError;
90
+ // // export class GracileRouterError extends Error implements e {
91
+ // // constructor(message: string, options: { cause: unknown }) {
92
+ // // super(message);
93
+ // // this.name = 'GracileRouterError';
94
+ // // this.cause = options.cause;
95
+ // // }
96
+ // // }
97
+ // /**
98
+ // * Special error that is exposed to users.
99
+ // * Compared to BetterError, it contains a subset of information.
100
+ // */
101
+ // export class GracileUserError extends Error {
102
+ // type: ErrorTypes = 'GracileUserError';
103
+ // /**
104
+ // * A message that explains to the user how they can fix the error.
105
+ // */
106
+ // hint: string | undefined;
107
+ // name = 'GracileUserError';
108
+ // constructor(message: string, hint?: string) {
109
+ // super();
110
+ // this.message = message;
111
+ // this.hint = hint;
112
+ // }
113
+ // static is(err: unknown): err is GracileUserError {
114
+ // return (err as GracileUserError).type === 'GracileUserError';
115
+ // }
116
+ // }
117
+ // ---
118
+ /**
119
+ * An error util. that should never be called in theory.
120
+ */
121
+ export class TypeGuardError extends Error {
122
+ }
@@ -0,0 +1,4 @@
1
+ export declare function errorInline(error: Error): import("@lit-labs/ssr").ServerRenderedTemplate;
2
+ export declare function builtIn404Page(path: string, dev?: boolean): import("@lit-labs/ssr").ServerRenderedTemplate;
3
+ export declare function builtInErrorPage(name?: string, dev?: boolean): import("@lit-labs/ssr").ServerRenderedTemplate;
4
+ //# sourceMappingURL=pages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../../src/errors/pages.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,kDASvC;AAgBD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAQ,kDAwFvD;AAOD,wBAAgB,gBAAgB,CAAC,IAAI,SAAU,EAAE,GAAG,UAAQ,kDAoB3D"}
@@ -0,0 +1,135 @@
1
+ import { html } from '@lit-labs/ssr';
2
+ export function errorInline(error) {
3
+ return html `<!-- --></a>
4
+ <div data-ssr-error>
5
+ <strong style="color: red">SSR Template error!</strong>
6
+ <details>
7
+ <summary style="user-select: none; cursor: pointer">Stack trace</summary>
8
+ <pre style="overflow: auto">${error.stack}</pre>
9
+ </details>
10
+ </div>`;
11
+ }
12
+ const minimalStyles = () => html `<style>
13
+ html {
14
+ color-scheme: light dark;
15
+ font-size: 16px;
16
+ line-height: 1.23rem;
17
+ font-family: system-ui;
18
+ }
19
+ </style>`;
20
+ const logo = () =>
21
+ /* prettier-ignore */
22
+ html `<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2" viewBox="0 0 630 630"><g transform="matrix(.877 .23499 -.25635 .95673 119.498 -60.39)"><circle cx="315" cy="315" r="315" style="fill:url(#a)"/><path d="M315 0c173.853 0 315 141.147 315 315S488.853 630 315 630 0 488.853 0 315 141.147 0 315 0Zm0 13.125c166.309 0 300.682 135.566 300.682 301.875S481.309 616.875 315 616.875C148.691 616.875 14.318 481.309 14.318 315S148.691 13.125 315 13.125Z" style="fill:#1a1a1e"/></g><path d="M.238.087A.195.195 0 0 1 .135.058.215.215 0 0 1 .06-.029a.293.293 0 0 1-.028-.135c0-.051.008-.103.024-.156a.699.699 0 0 1 .162-.278.475.475 0 0 1 .115-.089.258.258 0 0 1 .121-.032.14.14 0 0 1 .07.016c.017.011.03.026.038.044a.158.158 0 0 1 .011.058.215.215 0 0 1-.012.07.181.181 0 0 1-.034.058C.512-.458.496-.45.479-.45a.036.036 0 0 1-.022-.007.073.073 0 0 1-.02-.026.162.162 0 0 0 .034-.035.303.303 0 0 0 .032-.056.135.135 0 0 0 .014-.054.05.05 0 0 0-.012-.034C.496-.671.482-.675.463-.675a.16.16 0 0 0-.092.033.447.447 0 0 0-.091.089.764.764 0 0 0-.152.4c0 .061.013.108.04.141.026.034.057.051.094.051A.127.127 0 0 0 .338.013a.243.243 0 0 0 .061-.069.454.454 0 0 0 .062-.19.9.9 0 0 0-.051-.008 1.011 1.011 0 0 0-.056-.002H.322l-.034.002a.1.1 0 0 1 .029-.052.076.076 0 0 1 .051-.016c.02 0 .04.003.061.009a4.452 4.452 0 0 0 .123.039l-.01.031-.029.091a.854.854 0 0 0-.026.108l-.002.043.001.042.002.052C.468.09.453.085.444.076A.063.063 0 0 1 .425.044.148.148 0 0 1 .42.009v-.01l.001-.01a.317.317 0 0 1-.08.071.2.2 0 0 1-.103.027Z" style="fill-rule:nonzero" transform="translate(115.745 497.368) scale(589.0308)"/><path d="M6516.9 5139.28c-23.64 24.86-49.83 45.96-78.54 63.32-38.12 23.04-81.04 34.61-128.8 34.61-46.96 0-90.14-12.37-129.56-37.11-39.27-24.65-70.68-60.51-94.08-107.72-23.09-46.59-34.76-102.43-34.76-167.57 0-62.67 9.75-126.16 29.28-190.46 19.46-64.05 46.21-125.05 80.26-183.02 34.06-57.99 73-109.68 116.79-155.1 44.07-45.7 90.8-81.78 140.17-108.29 50.15-26.95 100.53-40.34 151.1-40.34 37.75 0 67.7 7.39 90.01 21.55 22.8 14.47 39.21 33.58 49.3 57.27 9.78 22.96 14.7 47.62 14.7 73.99 0 29.25-5.21 58.51-15.66 87.77-10.56 29.57-24.99 54.04-43.16 73.48-19.63 20.99-41.46 31.15-65.19 31.15-11.93 0-22.88-3.46-32.82-10.42-9.08-6.35-18.42-17.93-27.5-35.16-2.67-5.08-1.07-11.36 3.71-14.55 11.2-7.47 23.58-20.66 37.4-39.34 14.36-19.4 26.96-40.94 37.83-64.61 10.4-22.67 15.78-42.88 15.78-60.72 0-12.95-3.93-23.85-12.02-32.59-8.3-8.96-22.33-12.61-41.58-12.61-33.94 0-68.72 12.89-104.54 38.15-37.17 26.22-72.55 61.08-106.2 104.51-33.98 43.85-64.59 92.85-91.85 146.98-27.27 54.14-48.81 109.46-64.62 165.98-15.7 56.14-23.58 109.33-23.58 159.58 0 69.79 14.72 124.16 45.02 162.89 29.19 37.32 63.93 56.3 104.57 56.3 30.37 0 58.3-9.68 83.86-28.94 26.57-20.03 50.02-46.45 70.43-79.18 20.72-33.23 37.33-69.39 49.84-108.49 11.42-35.68 18.94-70.7 22.56-105.08-16.51-3-33.42-5.31-50.74-6.95-20.87-1.97-42.72-2.95-65.55-2.95-12.68 0-25.37.2-38.05.6-12.71.39-26.22.99-40.53 1.78a11.194 11.194 0 0 1-11.47-13.97c7.89-30.7 20.71-53.1 37.81-67.57 17.46-14.76 40.4-22.45 69.04-22.45 25.1 0 50.41 3.96 75.93 11.91 24.52 7.64 49.44 15.88 74.77 24.72 24.8 8.66 49.02 15.75 72.65 21.27 3.05.71 5.66 2.66 7.2 5.39 1.55 2.73 1.88 5.98.92 8.96 0 0-12 37.2-12.02 37.24-14.39 43.95-26.17 80.52-35.36 109.68-9.1 28.89-16.03 53.42-20.78 73.6-4.67 19.86-7.8 37.76-9.36 53.72-1.56 16.06-2.34 32.69-2.34 49.92 0 15.83.39 32.26 1.18 49.28.81 17.24 1.61 38.29 2.41 63.16.11 3.29-1.24 6.46-3.68 8.67a11.2 11.2 0 0 1-9 2.79c-26.84-3.58-46.58-11.82-59.55-23.9-13.28-12.36-21.92-26.81-26.04-43.29-3.23-12.91-5.09-25.52-5.59-37.84Zm-207.34 86.73c-44.8 0-86-11.8-123.6-35.4-37.6-23.6-67.6-58-90-103.2-22.4-45.2-33.6-99.4-33.6-162.6 0-61.6 9.6-124 28.8-187.2 19.2-63.2 45.6-123.4 79.2-180.6 33.6-57.2 72-108.2 115.2-153s89-80.2 137.4-106.2c48.4-26 97-39 145.8-39 35.2 0 63.2 6.6 84 19.8 20.8 13.2 35.8 30.6 45 52.2 9.2 21.6 13.8 44.8 13.8 69.6 0 28-5 56-15 84s-23.6 51.2-40.8 69.6c-17.2 18.4-36.2 27.6-57 27.6-9.6 0-18.4-2.8-26.4-8.4-8-5.6-16-16-24-31.2 12-8 25.4-22 40.2-42 14.8-20 27.8-42.2 39-66.6 11.2-24.4 16.8-46.2 16.8-65.4 0-16-5-29.4-15-40.2-10-10.8-26.6-16.2-49.8-16.2-36 0-73 13.4-111 40.2-38 26.8-74.2 62.4-108.6 106.8-34.4 44.4-65.4 94-93 148.8-27.6 54.8-49.4 110.8-65.4 168-16 57.2-24 111.4-24 162.6 0 72.8 15.8 129.4 47.4 169.8 31.6 40.4 69.4 60.6 113.4 60.6 32.8 0 63-10.4 90.6-31.2 27.6-20.8 52-48.2 73.2-82.2 21.2-34 38.2-71 51-111 12.8-40 20.8-79.2 24-117.6-20-4-40.6-7-61.8-9-21.2-2-43.4-3-66.6-3-12.8 0-25.6.2-38.4.6-12.8.4-26.4 1-40.8 1.8 7.2-28 18.6-48.6 34.2-61.8 15.6-13.2 36.2-19.8 61.8-19.8 24 0 48.2 3.8 72.6 11.4 24.4 7.6 49.2 15.8 74.4 24.6 25.2 8.8 49.8 16 73.8 21.6l-12 37.2c-14.4 44-26.2 80.6-35.4 109.8-9.2 29.2-16.2 54-21 74.4-4.8 20.4-8 38.8-9.6 55.2-1.6 16.4-2.4 33.4-2.4 51 0 16 .4 32.6 1.2 49.8.8 17.2 1.6 38.2 2.4 63-24-3.2-41.8-10.2-53.4-21-11.6-10.8-19.2-23.4-22.8-37.8-3.6-14.4-5.4-28.4-5.4-42v-12c0-4 .4-8 1.2-12-28 34.4-60.2 62.6-96.6 84.6-36.4 22-77.4 33-123 33Z" style="fill:#fff" transform="matrix(.49086 0 0 .49086 -2841.17 -2016.62)"/><defs><radialGradient id="a" cx="0" cy="0" r="1" gradientTransform="matrix(315 0 0 315 315 315)" gradientUnits="userSpaceOnUse"><stop offset="0" style="stop-color:white;stop-opacity:1"/><stop offset="1" style="stop-color:#57d5a3;stop-opacity:1"/></radialGradient></defs></svg>`;
23
+ export function builtIn404Page(path, dev = false) {
24
+ return html `
25
+ <!doctype html>
26
+ <html lang="en">
27
+ <head>
28
+ <meta charset="UTF-8" />
29
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
30
+ <meta name="generator" content="Gracile" />
31
+ <title>404: Not found</title>
32
+
33
+ ${minimalStyles()}
34
+ <style>
35
+ body {
36
+ padding: 1rem;
37
+ }
38
+
39
+ pre {
40
+ padding: 0.5rem 0.75rem;
41
+
42
+ overflow-y: auto;
43
+ }
44
+
45
+ button {
46
+ font-size: 2rem;
47
+ }
48
+
49
+ h1 {
50
+ color: tomato;
51
+ }
52
+
53
+ pre {
54
+ border: 1px solid grey;
55
+ border-radius: 0.15rem;
56
+ padding: 1rem;
57
+ }
58
+
59
+ .middle {
60
+ width: 100%;
61
+ height: 100dvh;
62
+ display: flex;
63
+ align-items: center;
64
+ justify-content: center;
65
+ flex-direction: column;
66
+ position: relative;
67
+ top: -5dvh;
68
+ }
69
+
70
+ .gracile-logo {
71
+ height: 8rem;
72
+ width: 8rem;
73
+ margin: 4rem;
74
+ }
75
+
76
+ section {
77
+ text-align: center;
78
+ }
79
+ </style>
80
+ </head>
81
+ <body>
82
+ <main class="middle">
83
+ <div class="gracile-logo">${logo()}</div>
84
+
85
+ <h1>404: Not found</h1>
86
+
87
+ <section>
88
+ <div>Path:</div>
89
+ <pre>${path}</pre>
90
+ </section>
91
+
92
+ ${dev
93
+ ? html ` <section>
94
+ <p>The page or route may be not configured properly.</p>
95
+
96
+ <p>
97
+ See
98
+ <a
99
+ target="_blank"
100
+ href="https://gracile.js.org/docs/learn/usage/defining-routes/"
101
+ >Defining routes</a
102
+ >
103
+ in the documentation.
104
+ </p>
105
+ </section>`
106
+ : null}
107
+ </main>
108
+ </body>
109
+ </html>
110
+ `;
111
+ }
112
+ // TODO: Extract
113
+ // const ESCAPE_SEQUENCE_CHARACTER =
114
+ // // eslint-disable-next-line no-control-regex
115
+ // /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
116
+ export function builtInErrorPage(name = 'Error', dev = false) {
117
+ const title = `500: ${name ? `${name} | ` : ''}Internal Server Error`;
118
+ return html `
119
+ <!doctype html>
120
+ <html lang="en">
121
+ <head>
122
+ <meta charset="UTF-8" />
123
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
124
+ <title>${title}</title>
125
+ ${minimalStyles()}
126
+ ${dev
127
+ ? html `<script type="module" src="/@vite/client"></script>`
128
+ : null}
129
+ </head>
130
+ <body>
131
+ <h1>${title}</h1>
132
+ </body>
133
+ </html>
134
+ `;
135
+ }
@@ -0,0 +1,2 @@
1
+ export declare function emptyRoutes(): string;
2
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/logging/messages.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,WAO1B"}
@@ -0,0 +1,6 @@
1
+ import c from 'picocolors';
2
+ export function emptyRoutes() {
3
+ const message = c.yellow(`No route were found in the \`src/routes/\` folder.\n\n`) +
4
+ c.magenta(`▶ See https://gracile.js.org/docs/learn/usage/defining-routes/.`);
5
+ return `${message}\n`;
6
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAOtD,YAAY,EAAE,aAAa,EAAE,CAAC;AAI9B;;;;;;;;;;;;;;;;;GAiBG;AAIH,eAAO,MAAM,OAAO,YAAa,aAAa,KAAG,GAAG,EA4RnD,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAOtD,YAAY,EAAE,aAAa,EAAE,CAAC;AAI9B;;;;;;;;;;;;;;;;;GAiBG;AAIH,eAAO,MAAM,OAAO,YAAa,aAAa,KAAG,GAAG,EAyTnD,CAAC"}