@gracile/engine 0.6.0 → 0.7.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/build/static.d.ts +8 -2
  2. package/dist/build/static.d.ts.map +1 -1
  3. package/dist/build/static.js +38 -8
  4. package/dist/dev/dev.d.ts +4 -1
  5. package/dist/dev/dev.d.ts.map +1 -1
  6. package/dist/dev/dev.js +32 -19
  7. package/dist/dev/vite-logger.d.ts +2 -0
  8. package/dist/dev/vite-logger.d.ts.map +1 -0
  9. package/dist/dev/vite-logger.js +2 -0
  10. package/dist/errors/create-vite-better-error.d.ts +6 -0
  11. package/dist/errors/create-vite-better-error.d.ts.map +1 -0
  12. package/dist/errors/create-vite-better-error.js +27 -0
  13. package/dist/errors/errors-data.d.ts +81 -0
  14. package/dist/errors/errors-data.d.ts.map +1 -0
  15. package/dist/errors/errors-data.js +98 -0
  16. package/dist/errors/errors.d.ts +22 -0
  17. package/dist/errors/errors.d.ts.map +1 -0
  18. package/dist/errors/errors.js +122 -0
  19. package/dist/errors/pages.d.ts +4 -0
  20. package/dist/errors/pages.d.ts.map +1 -0
  21. package/dist/errors/pages.js +135 -0
  22. package/dist/logging/messages.d.ts +2 -0
  23. package/dist/logging/messages.d.ts.map +1 -0
  24. package/dist/logging/messages.js +6 -0
  25. package/dist/plugin.d.ts.map +1 -1
  26. package/dist/plugin.js +82 -43
  27. package/dist/render/markers.d.ts +3 -0
  28. package/dist/render/markers.d.ts.map +1 -0
  29. package/dist/render/markers.js +4 -0
  30. package/dist/render/route-template.d.ts +5 -10
  31. package/dist/render/route-template.d.ts.map +1 -1
  32. package/dist/render/route-template.js +68 -48
  33. package/dist/render/utils.d.ts +24 -1
  34. package/dist/render/utils.d.ts.map +1 -1
  35. package/dist/render/utils.js +23 -1
  36. package/dist/routes/collect.d.ts +2 -1
  37. package/dist/routes/collect.d.ts.map +1 -1
  38. package/dist/routes/collect.js +15 -11
  39. package/dist/routes/load-module.d.ts +1 -1
  40. package/dist/routes/load-module.d.ts.map +1 -1
  41. package/dist/routes/load-module.js +31 -5
  42. package/dist/routes/match.d.ts +1 -1
  43. package/dist/routes/match.d.ts.map +1 -1
  44. package/dist/routes/match.js +26 -12
  45. package/dist/routes/route.d.ts +2 -2
  46. package/dist/routes/route.d.ts.map +1 -1
  47. package/dist/routes/route.js +14 -12
  48. package/dist/server/adapters/hono.d.ts +5 -2
  49. package/dist/server/adapters/hono.d.ts.map +1 -1
  50. package/dist/server/adapters/hono.js +12 -6
  51. package/dist/server/adapters/node.d.ts +4 -2
  52. package/dist/server/adapters/node.d.ts.map +1 -1
  53. package/dist/server/adapters/node.js +27 -12
  54. package/dist/server/constants.d.ts +1 -1
  55. package/dist/server/constants.d.ts.map +1 -1
  56. package/dist/server/constants.js +1 -1
  57. package/dist/server/request.d.ts +7 -2
  58. package/dist/server/request.d.ts.map +1 -1
  59. package/dist/server/request.js +95 -69
  60. package/dist/server/utils.d.ts.map +1 -1
  61. package/dist/server/utils.js +5 -4
  62. package/dist/tsconfig.tsbuildinfo +1 -1
  63. package/dist/user-config.d.ts +35 -1
  64. package/dist/user-config.d.ts.map +1 -1
  65. package/dist/vite/plugins/build-routes.d.ts +6 -2
  66. package/dist/vite/plugins/build-routes.d.ts.map +1 -1
  67. package/dist/vite/plugins/build-routes.js +69 -35
  68. package/dist/vite/plugins/virtual-routes.d.ts +10 -0
  69. package/dist/vite/plugins/virtual-routes.d.ts.map +1 -1
  70. package/dist/vite/plugins/virtual-routes.js +56 -4
  71. package/package.json +10 -11
  72. package/dist/assertions.d.ts +0 -13
  73. package/dist/assertions.d.ts.map +0 -1
  74. package/dist/assertions.js +0 -45
  75. package/dist/errors/templates.d.ts +0 -3
  76. package/dist/errors/templates.d.ts.map +0 -1
  77. package/dist/errors/templates.js +0 -69
@@ -1,5 +1,27 @@
1
1
  import { render as renderLitSsr, } from '@lit-labs/ssr';
2
2
  import { collectResult } from '@lit-labs/ssr/lib/render-result.js';
3
- export async function renderSsrTemplate(template) {
3
+ /**
4
+ * Just a tiny wrapper for `render` and `collectResult` from `@lit-labs/ssr`.
5
+ *
6
+ * Useful for testing server only partials.
7
+ *
8
+ * @example
9
+ * ```js
10
+ * import assert from 'node:assert';
11
+ * import {
12
+ * html,
13
+ * type ServerRenderedTemplate,
14
+ * } from '@gracile/gracile/server-html';
15
+ *
16
+ * const myServerTemplate1 = (): ServerRenderedTemplate => html`
17
+ * <div>Hello</div>
18
+ * `;
19
+ *
20
+ * const result = await renderLitTemplate(myServerTemplate1());
21
+ *
22
+ * assert.match(result, /Hello/);
23
+ * ```
24
+ */
25
+ export async function renderLitTemplate(template) {
4
26
  return collectResult(renderLitSsr(template));
5
27
  }
@@ -1,3 +1,4 @@
1
1
  import type * as R from './route.js';
2
- export declare function collectRoutes(root: string, excludePatterns?: string[]): Promise<R.RoutesManifest>;
2
+ export declare const WATCHED_FILES_REGEX: RegExp;
3
+ export declare function collectRoutes(routes: R.RoutesManifest, root: string, excludePatterns?: string[]): Promise<void>;
3
4
  //# sourceMappingURL=collect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"collect.d.ts","sourceRoot":"","sources":["../../src/routes/collect.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,KAAK,CAAC,MAAM,YAAY,CAAC;AA4DrC,wBAAsB,aAAa,CAClC,IAAI,EAAE,MAAM,EACZ,eAAe,GAAE,MAAM,EAAO,GAE5B,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC,CA+F3B"}
1
+ {"version":3,"file":"collect.d.ts","sourceRoot":"","sources":["../../src/routes/collect.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,KAAK,CAAC,MAAM,YAAY,CAAC;AAuDrC,eAAO,MAAM,mBAAmB,QAC+B,CAAC;AAGhE,wBAAsB,aAAa,CAClC,MAAM,EAAE,CAAC,CAAC,cAAc,EACxB,IAAI,EAAE,MAAM,EACZ,eAAe,GAAE,MAAM,EAAO,GAE5B,OAAO,CAAC,IAAI,CAAC,CAoGf"}
@@ -1,19 +1,20 @@
1
1
  import { join } from 'node:path';
2
- import { logger } from '@gracile/internal-utils/logger';
2
+ import { getLogger } from '@gracile/internal-utils/logger/helpers';
3
3
  import * as paths from '@gracile/internal-utils/paths';
4
4
  import { fdir as Fdir } from 'fdir';
5
5
  import c from 'picocolors';
6
6
  import { URLPattern } from 'urlpattern-polyfill/urlpattern';
7
7
  import { createFilter } from 'vite';
8
- // import type { ViteDevServer } from 'vite';
8
+ import { emptyRoutes } from '../logging/messages.js';
9
9
  import { prepareSortableRoutes, routeComparator } from './comparator.js';
10
10
  import { REGEXES } from './load-module.js';
11
+ const logger = getLogger();
11
12
  function extractRoutePatterns(routeFilePath) {
12
13
  const routePathname = routeFilePath.replace(/\.[j|t]s$/, '');
13
- let pathParts = routePathname.split(process.platform === 'win32' ? '\\' : '/');
14
+ let pathParts = routePathname.split(paths.isWindows() ? paths.WINDOWS_PATH_SEPARATOR : '/');
14
15
  const last = pathParts.at(-1);
15
- if (typeof last === 'undefined')
16
- throw new TypeError('Cannot parse file path.');
16
+ if (last === undefined)
17
+ throw new ReferenceError('Cannot parse file path.');
17
18
  if (
18
19
  // NOTE: /foo/(foo) => /foo
19
20
  /\((.*)\)/.test(last) ||
@@ -22,9 +23,6 @@ function extractRoutePatterns(routeFilePath) {
22
23
  pathParts.pop();
23
24
  if (pathParts.length === 1 && pathParts.at(0) === 'index')
24
25
  pathParts = [];
25
- // NOTE: Disabled for now, but might be useful later
26
- // if (pathParts.length === 1 && pathParts.at(0) === '404')
27
- // pathParts = ['__404'];
28
26
  let hasParams = false;
29
27
  const pathRelNorm = pathParts.map((pathEntry) => {
30
28
  let entry = pathEntry;
@@ -48,8 +46,9 @@ function extractRoutePatterns(routeFilePath) {
48
46
  hasParams,
49
47
  };
50
48
  }
51
- const routes = new Map();
52
- export async function collectRoutes(root /* vite: ViteDevServer */, excludePatterns = []) {
49
+ export const WATCHED_FILES_REGEX = /\/src\/routes\/(.*)\.(ts|js|css|scss|sass|less|styl|stylus)$/;
50
+ // const routes: R.RoutesManifest = new Map<string, R.Route>();
51
+ export async function collectRoutes(routes, root /* vite: ViteDevServer */, excludePatterns = []) {
53
52
  routes.clear();
54
53
  const routesFolder = 'src/routes';
55
54
  const routesFolderAbsolute = join(root, routesFolder);
@@ -69,6 +68,12 @@ export async function collectRoutes(root /* vite: ViteDevServer */, excludePatte
69
68
  ...excludePatterns,
70
69
  ]);
71
70
  const serverEntrypoints = allFilesInRoutes.filter((f) => serverEntrypointsFilter(f));
71
+ if (serverEntrypoints.length === 0) {
72
+ logger.warnOnce(emptyRoutes(), {
73
+ timestamp: true,
74
+ });
75
+ return;
76
+ }
72
77
  // MARK: Routes priority order
73
78
  // TODO: `prepareSortableRoutes` and `routeComparator` in same function `sortRoutes`
74
79
  const serverEntrypointsSorted = prepareSortableRoutes(serverEntrypoints)
@@ -117,5 +122,4 @@ export async function collectRoutes(root /* vite: ViteDevServer */, excludePatte
117
122
  route.pageAssets.push(assetPathWithExt);
118
123
  });
119
124
  });
120
- return routes;
121
125
  }
@@ -1,4 +1,4 @@
1
- import type { ViteDevServer } from 'vite';
1
+ import { type ViteDevServer } from 'vite';
2
2
  import * as R from './route.js';
3
3
  export declare const REGEXES: {
4
4
  param: RegExp;
@@ -1 +1 @@
1
- {"version":3,"file":"load-module.d.ts","sourceRoot":"","sources":["../../src/routes/load-module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AAGhC,eAAO,MAAM,OAAO;;;;;;CASnB,CAAC;AAEF,wBAAsB,sBAAsB,CAAC,EAC5C,IAAI,EACJ,KAAK,EACL,YAAY,GACZ,EAAE;IACF,IAAI,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IACjC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC;IACf,YAAY,CAAC,EAAE,CAAC,CAAC,aAAa,GAAG,SAAS,CAAC;CAC3C,0BA2BA"}
1
+ {"version":3,"file":"load-module.d.ts","sourceRoot":"","sources":["../../src/routes/load-module.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,MAAM,CAAC;AAG1C,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AAGhC,eAAO,MAAM,OAAO;;;;;;CASnB,CAAC;AAQF,wBAAsB,sBAAsB,CAAC,EAC5C,IAAI,EACJ,KAAK,EACL,YAAY,GACZ,EAAE;IACF,IAAI,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IACjC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC;IACf,YAAY,CAAC,EAAE,CAAC,CAAC,aAAa,GAAG,SAAS,CAAC;CAC3C,0BA8CA"}
@@ -1,3 +1,9 @@
1
+ import { collectErrorMetadata } from '@gracile-labs/better-errors/dev/utils';
2
+ import { enhanceViteSSRError } from '@gracile-labs/better-errors/dev/vite';
3
+ import { join } from 'path';
4
+ import { pathToFileURL } from 'url';
5
+ import {} from 'vite';
6
+ import { GracileError, GracileErrorData } from '../errors/errors.js';
1
7
  import * as R from './route.js';
2
8
  // const ROUTE_SPREAD = /^\.{3}.+$/;
3
9
  export const REGEXES = {
@@ -9,11 +15,32 @@ export const REGEXES = {
9
15
  // index: /^(index\.(js|ts)|\((.*)\)\.(js|ts))$/,
10
16
  index: /\((.*)\)/,
11
17
  };
18
+ const incorrectRouteModuleError = (p) => new GracileError({
19
+ ...GracileErrorData.InvalidRouteExport,
20
+ message: GracileErrorData.InvalidRouteExport.message(p),
21
+ });
12
22
  export async function loadForeignRouteObject({ vite, route, routeImports, }) {
13
23
  // NOTE: Check and assert unknown userland module to correct RouteModule instance (in the engine's realm)
14
24
  let unknownRouteModule = null;
15
- if (vite)
16
- unknownRouteModule = await vite.ssrLoadModule(route.filePath);
25
+ if (vite) {
26
+ try {
27
+ unknownRouteModule = await vite.ssrLoadModule(route.filePath /* + 's' */, {});
28
+ }
29
+ catch (e) {
30
+ const err = e;
31
+ const filePath = pathToFileURL(join(vite.config.root, route.filePath));
32
+ const rootFolder = pathToFileURL(vite.config.root);
33
+ // NOTE: Maybe it's not required here? But just upstream (safeError…)
34
+ const enhance = enhanceViteSSRError({
35
+ error: err,
36
+ filePath,
37
+ // @ts-expect-error Typings mismatches
38
+ vite,
39
+ });
40
+ const errorWithMetadata = collectErrorMetadata(enhance, rootFolder);
41
+ throw errorWithMetadata;
42
+ }
43
+ }
17
44
  else if (routeImports) {
18
45
  const ri = routeImports.get(route.pattern.pathname);
19
46
  if (ri)
@@ -22,11 +49,10 @@ export async function loadForeignRouteObject({ vite, route, routeImports, }) {
22
49
  if (unknownRouteModule === null)
23
50
  throw new Error('Cannot find route module.');
24
51
  const routeModuleFactory = unknownRouteModule['default'];
25
- const errorBase = `Incorrect route module ${route.filePath}!`;
26
52
  if (typeof routeModuleFactory !== 'function')
27
- throw new TypeError(`${errorBase} Not a function.`);
53
+ throw incorrectRouteModuleError(route.filePath);
28
54
  const routeModule = routeModuleFactory(R.RouteModule);
29
55
  if (routeModule instanceof R.RouteModule === false)
30
- throw new TypeError(`${errorBase} Not a RouteModule.`);
56
+ throw incorrectRouteModuleError(route.filePath);
31
57
  return routeModule;
32
58
  }
@@ -13,6 +13,6 @@ export declare function getRoute(options: {
13
13
  vite?: ViteDevServer | undefined;
14
14
  routes: R.RoutesManifest;
15
15
  routeImports?: R.RoutesImports | undefined;
16
- }): Promise<RouteInfos>;
16
+ }): Promise<RouteInfos | null>;
17
17
  export {};
18
18
  //# sourceMappingURL=match.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../src/routes/match.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAG1C,OAAO,KAAK,KAAK,CAAC,MAAM,YAAY,CAAC;AAErC,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,G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C;CAC3C,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAiC7B"}
@@ -15,18 +15,18 @@ function matchRouteFromUrl(url, routes) {
15
15
  }
16
16
  }
17
17
  if (!match || !foundRoute)
18
- throw new Error(`No route matching for ${url}`, { cause: 404 });
18
+ return null;
19
19
  const params = Object.freeze({ ...match.pathname.groups });
20
20
  return { match, foundRoute, params, pathname };
21
21
  }
22
- function extractStaticPaths(options) {
22
+ async function extractStaticPaths(options) {
23
23
  if (!options.foundRoute.hasParams)
24
24
  return null;
25
25
  if (!options.routeModule.staticPaths)
26
26
  return null;
27
27
  const routeStaticPaths = options.routeModule.staticPaths;
28
28
  let props;
29
- const staticPaths = routeStaticPaths();
29
+ const staticPaths = await Promise.resolve(routeStaticPaths());
30
30
  let hasCorrectParams = false;
31
31
  staticPaths.forEach((providedRouteOptions) => {
32
32
  const routeOptions = providedRouteOptions;
@@ -38,24 +38,38 @@ function extractStaticPaths(options) {
38
38
  }
39
39
  });
40
40
  if (hasCorrectParams === false)
41
- throw new Error(`Incorrect route parameters for \`${options.pathname}\`.\n` +
42
- `Check \`staticPaths\` for \`${options.foundRoute.filePath}\`.`);
41
+ // throw new Error(
42
+ // `Incorrect route parameters for \`${options.pathname}\`.\n` +
43
+ // `Check \`staticPaths\` for \`${options.foundRoute.filePath}\`.`,
44
+ // );
45
+ return null;
43
46
  return { staticPaths, props };
44
47
  }
45
48
  export async function getRoute(options) {
46
- const { foundRoute, pathname, params } = matchRouteFromUrl(options.url, options.routes);
49
+ // throw new GracileError(new Error(`No route matching for ${url}`), {
50
+ // cause: 404,
51
+ // });
52
+ const matchedRoute = matchRouteFromUrl(options.url, options.routes);
53
+ if (!matchedRoute)
54
+ return matchedRoute;
55
+ const { foundRoute, pathname, params } = matchedRoute;
47
56
  // TODO: Simplify all the routes things
48
57
  const routeModule = await loadForeignRouteObject({
49
58
  vite: options.vite,
50
59
  route: foundRoute,
51
60
  routeImports: options.routeImports,
52
61
  });
53
- const staticPaths = extractStaticPaths({
54
- routeModule,
55
- foundRoute,
56
- pathname,
57
- params,
58
- });
62
+ let staticPaths = null;
63
+ if (routeModule.staticPaths) {
64
+ staticPaths = await extractStaticPaths({
65
+ routeModule,
66
+ foundRoute,
67
+ pathname,
68
+ params,
69
+ });
70
+ if (!staticPaths)
71
+ return null;
72
+ }
59
73
  return {
60
74
  params,
61
75
  props: staticPaths?.props,
@@ -24,7 +24,7 @@ export declare class RouteModule {
24
24
  #private;
25
25
  get staticPaths(): StaticPathsGeneric | undefined;
26
26
  get locals(): {};
27
- get handler(): Handler<object | Response | undefined> | Partial<Record<MethodHtml, Handler<object | Response | undefined>> & Record<MethodNonHtml, Handler<Response>>> | undefined;
27
+ get handler(): HandlerGeneric | undefined;
28
28
  get document(): DocumentTemplate<RouteContextGeneric> | undefined;
29
29
  get prerender(): boolean | undefined;
30
30
  get template(): ((context: RouteContextGeneric) => RouteTemplateResult) | undefined;
@@ -50,7 +50,7 @@ export type Handler<Data extends HandlerData | HandlerDataHtml = never> = (conte
50
50
  responseInit: ResponseInit;
51
51
  }) => MaybePromise<Data> | MaybePromise<void>;
52
52
  export type HandlerGeneric = Handler<HandlerData | HandlerDataHtml> | Partial<Record<MethodHtml, Handler<HandlerData | HandlerDataHtml>> & Record<MethodNonHtml, Handler<Response>>>;
53
- export type StaticPathsGeneric = () => StaticPathOptionsGeneric[];
53
+ export type StaticPathsGeneric = () => MaybePromise<StaticPathOptionsGeneric[]>;
54
54
  export type HandlerData = Response | undefined;
55
55
  export type HandlerDataHtml = HandlerData | object;
56
56
  export type StaticPathOptionsGeneric = {
@@ -1 +1 @@
1
- {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/routes/route.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAK1C,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAA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OAAO,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,YAAY,CAAC,sBAAsB,CAAC,CAAC;AAClE,MAAM,MAAM,mBAAmB,GAAG,YAAY,CAC7C,cAAc,CAAC,CAAC,CAAC,GAAG,sBAAsB,CAC1C,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAC3B,YAAY,SAAS,mBAAmB,GAAG,mBAAmB,IAE3D,CAAC,OAAO,EAAE,YAAY,KAAK,cAAc,CAAC;AAE9C,MAAM,MAAM,YAAY,CAAC,YAAY,IAAI,CACxC,OAAO,EAAE,YAAY,KACjB,mBAAmB,CAAC;AAKzB,MAAM,WAAW,KAAK;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,UAAU,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,EAAE,CAAC;CAErB;AAID,MAAM,MAAM,cAAc,GAAG,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAChD,MAAM,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AACvE,MAAM,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
@@ -36,18 +36,20 @@ export class RouteModule {
36
36
  return this.#template;
37
37
  }
38
38
  constructor(options) {
39
- if (typeof options.staticPaths === 'function')
40
- this.#staticPaths = options.staticPaths;
41
- if ((typeof options.handler === 'object' ||
42
- typeof options.handler === 'function') &&
43
- options.handler)
44
- this.#handler = options.handler;
39
+ // if (typeof options.staticPaths === 'function')
40
+ this.#staticPaths = options.staticPaths;
41
+ // if (
42
+ // (typeof options.handler === 'object' ||
43
+ // typeof options.handler === 'function') &&
44
+ // options.handler
45
+ // )
46
+ this.#handler = options.handler;
45
47
  this.#locals = {};
46
- if (typeof options.template === 'function')
47
- this.#template = options.template;
48
- if (typeof options.document === 'function')
49
- this.#document = options.document;
50
- if (typeof options.prerender === 'boolean')
51
- this.#prerender = options.prerender;
48
+ // if (typeof options.template === 'function')
49
+ this.#template = options.template;
50
+ // if (typeof options.document === 'function')
51
+ this.#document = options.document;
52
+ // if (typeof options.prerender === 'boolean')
53
+ this.#prerender = options.prerender;
52
54
  }
53
55
  }
@@ -1,4 +1,4 @@
1
- import type { GracileHandler } from '../request.js';
1
+ import type { AdapterOptions, GracileHandler } from '../request.js';
2
2
  export type { GracileHandler };
3
3
  export type GracileHonoHandler = (context: {
4
4
  req: {
@@ -6,8 +6,11 @@ export type GracileHonoHandler = (context: {
6
6
  };
7
7
  var: unknown;
8
8
  }) => Promise<Response>;
9
+ export interface HonoAdapterOptions extends AdapterOptions {
10
+ }
9
11
  /**
10
12
  * @param handler - Takes a pre-built Gracile handler from `./dist/server/entrypoint.js`.
13
+ * @param options - If you need more control.
11
14
  * @example
12
15
  * `/src/server.js`
13
16
  * ```js
@@ -25,7 +28,7 @@ export type GracileHonoHandler = (context: {
25
28
  * serve(app);
26
29
  * ```
27
30
  */
28
- export declare const honoAdapter: (handler: GracileHandler) => GracileHonoHandler;
31
+ export declare const honoAdapter: (handler: GracileHandler, options?: HonoAdapterOptions) => GracileHonoHandler;
29
32
  /**
30
33
  *
31
34
  * @param root - resolve `dist/client` from this file path.
@@ -1 +1 @@
1
- {"version":3,"file":"hono.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/hono.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE;IAC1C,GAAG,EAAE;QAAE,GAAG,EAAE,OAAO,CAAA;KAAE,CAAC;IACtB,GAAG,EAAE,OAAO,CAAC;CACb,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAExB;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,WAAW,YACb,cAAc,KAAG,kBAc1B,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,UAK7C;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"hono.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/hono.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpE,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE;IAC1C,GAAG,EAAE;QAAE,GAAG,EAAE,OAAO,CAAA;KAAE,CAAC;IACtB,GAAG,EAAE,OAAO,CAAC;CACb,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAExB,MAAM,WAAW,kBAAmB,SAAQ,cAAc;CAEzD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,WAAW,YACb,cAAc,YAAY,kBAAkB,KAAG,kBAmBxD,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,UAK7C;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
@@ -1,10 +1,12 @@
1
- // import { logger } from '@gracile/internal-utils/logger';
2
1
  import { relative } from 'node:path';
3
2
  import { Readable } from 'node:stream';
4
3
  import { fileURLToPath } from 'node:url';
5
- import { server } from '../constants.js';
4
+ import { createLogger } from '@gracile/internal-utils/logger/helpers';
5
+ import { GracileError, GracileErrorData } from '../../errors/errors.js';
6
+ import { constants } from '../constants.js';
6
7
  /**
7
8
  * @param handler - Takes a pre-built Gracile handler from `./dist/server/entrypoint.js`.
9
+ * @param options - If you need more control.
8
10
  * @example
9
11
  * `/src/server.js`
10
12
  * ```js
@@ -22,9 +24,10 @@ import { server } from '../constants.js';
22
24
  * serve(app);
23
25
  * ```
24
26
  */
25
- export const honoAdapter = (handler) => async (context) => {
27
+ export const honoAdapter = (handler, options) => async (context) => {
28
+ createLogger(options?.logger);
26
29
  const result = await handler(context.req.raw, context.var);
27
- // TODO: Hhandle stream abortion as gracefully as with Express.
30
+ // TODO: Handle stream abortion as gracefully as with Express.
28
31
  if (result?.body) {
29
32
  // NOTE: Typings mismatches
30
33
  const body = Readable.toWeb(result.body);
@@ -32,7 +35,10 @@ export const honoAdapter = (handler) => async (context) => {
32
35
  }
33
36
  if (result?.response)
34
37
  return result.response;
35
- throw new Error('Rendering was impossible in the Hono adapter!');
38
+ throw new GracileError({
39
+ ...GracileErrorData.InvalidResponseInAdapter,
40
+ message: GracileErrorData.InvalidResponseInAdapter.message('Hono'),
41
+ });
36
42
  };
37
43
  /**
38
44
  *
@@ -50,6 +56,6 @@ export const honoAdapter = (handler) => async (context) => {
50
56
  * ```
51
57
  */
52
58
  export function getClientDistPath(root) {
53
- return relative(process.cwd(), fileURLToPath(new URL(server.CLIENT_DIST_DIR, root)));
59
+ return relative(process.cwd(), fileURLToPath(new URL(constants.CLIENT_DIST_DIR, root)));
54
60
  }
55
61
  export { printUrls } from '../utils.js';
@@ -1,7 +1,9 @@
1
1
  import type { IncomingMessage, ServerResponse } from 'http';
2
- import { type GracileHandler } from '../request.js';
2
+ import { type AdapterOptions, type GracileHandler } from '../request.js';
3
3
  export type { GracileHandler };
4
4
  export type GracileNodeHandler = (req: IncomingMessage, res: ServerResponse, locals?: unknown) => Promise<ServerResponse<IncomingMessage> | null | void>;
5
+ export interface NodeAdapterOptions extends AdapterOptions {
6
+ }
5
7
  /**
6
8
  * @param handler - Takes a pre-built Gracile handler from `./dist/server/entrypoint.js`.
7
9
  * @example
@@ -20,7 +22,7 @@ export type GracileNodeHandler = (req: IncomingMessage, res: ServerResponse, loc
20
22
  * const server = app.listen();
21
23
  * ```
22
24
  */
23
- export declare function nodeAdapter(handler: GracileHandler): GracileNodeHandler;
25
+ export declare function nodeAdapter(handler: GracileHandler, options?: NodeAdapterOptions): GracileNodeHandler;
24
26
  /**
25
27
  * @param root - resolve `dist/client` from this file path.
26
28
  * @example
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/node.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAI5D,OAAO,EAAE,KAAK,cAAc,EAAc,MAAM,eAAe,CAAC;AAoBhE,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B,MAAM,MAAM,kBAAkB,GAAG,CAChC,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,MAAM,CAAC,EAAE,OAAO,KAEZ,OAAO,CAAC,cAAc,CAAC,eAAe,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;AAE5D;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,kBAAkB,CAkDvE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,UAE7C;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/node.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAI5D,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,cAAc,EAEnB,MAAM,eAAe,CAAC;AAoBvB,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B,MAAM,MAAM,kBAAkB,GAAG,CAChC,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,MAAM,CAAC,EAAE,OAAO,KAEZ,OAAO,CAAC,cAAc,CAAC,eAAe,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;AAE5D,MAAM,WAAW,kBAAmB,SAAQ,cAAc;CAEzD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAC1B,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,kBAAkB,GAC1B,kBAAkB,CAoEpB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,UAE7C;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
@@ -1,10 +1,11 @@
1
+ import { Writable } from 'node:stream';
1
2
  import { fileURLToPath } from 'node:url';
2
3
  import { env } from '@gracile/internal-utils/env';
3
- import { logger } from '@gracile/internal-utils/logger';
4
+ import { createLogger } from '@gracile/internal-utils/logger/helpers';
4
5
  import { createServerAdapter } from '@whatwg-node/server';
5
- import { Writable } from 'stream';
6
- import { server } from '../constants.js';
7
- import { isRedirect } from '../request.js';
6
+ import { GracileError, GracileErrorData } from '../../errors/errors.js';
7
+ import { constants } from '../constants.js';
8
+ import { isRedirect, } from '../request.js';
8
9
  // NOTE: Find a more canonical way to ponyfill the Node HTTP request to standard Request
9
10
  // @ts-expect-error Abusing this feature!
10
11
  const nodeRequestToStandardRequest = createServerAdapter((request) => request);
@@ -36,16 +37,28 @@ function standardResponseInitToNodeResponse(responseInit, res) {
36
37
  * const server = app.listen();
37
38
  * ```
38
39
  */
39
- export function nodeAdapter(handler) {
40
+ export function nodeAdapter(handler, options) {
40
41
  return async function nodeHandler(req, res, locals) {
41
- const request = (await Promise.resolve(nodeRequestToStandardRequest.handleNodeRequest(
42
- // HACK: Incorrect typings
43
- req)));
42
+ const logger = createLogger(options?.logger);
43
+ let webRequest;
44
+ try {
45
+ webRequest = (await Promise.resolve(nodeRequestToStandardRequest.handleNodeRequest(
46
+ // HACK: Exact optional properties
47
+ req)));
48
+ }
49
+ catch (e) {
50
+ throw new GracileError({
51
+ ...GracileErrorData.InvalidRequestInAdapter,
52
+ message: GracileErrorData.InvalidRequestInAdapter.message('Node'),
53
+ }, {
54
+ cause: e,
55
+ });
56
+ }
44
57
  const mergedLocals = {
45
58
  ...(locals ?? {}),
46
59
  ...('locals' in res && typeof res.locals === 'object' ? res.locals : {}),
47
60
  };
48
- const result = await handler(request, mergedLocals);
61
+ const result = await handler(webRequest, mergedLocals);
49
62
  if (result?.body) {
50
63
  standardResponseInitToNodeResponse(result.init, res);
51
64
  // NOTE: We can't do similar thing with Hono with just
@@ -70,9 +83,11 @@ export function nodeAdapter(handler) {
70
83
  .catch((e) => logger.error(String(e)));
71
84
  return piped;
72
85
  }
73
- return null;
74
86
  }
75
- return null;
87
+ throw new GracileError({
88
+ ...GracileErrorData.InvalidResponseInAdapter,
89
+ message: GracileErrorData.InvalidResponseInAdapter.message('Node'),
90
+ });
76
91
  };
77
92
  }
78
93
  /**
@@ -89,6 +104,6 @@ export function nodeAdapter(handler) {
89
104
  * ```
90
105
  */
91
106
  export function getClientDistPath(root) {
92
- return fileURLToPath(new URL(server.CLIENT_DIST_DIR, root));
107
+ return fileURLToPath(new URL(constants.CLIENT_DIST_DIR, root));
93
108
  }
94
109
  export { printUrls } from '../utils.js';
@@ -16,7 +16,7 @@
16
16
  * );
17
17
  * ```
18
18
  */
19
- export declare const server: Readonly<{
19
+ export declare const constants: Readonly<{
20
20
  LOCALHOST: "localhost";
21
21
  IP_LOCALHOST: "127.0.0.1";
22
22
  IP_EXPOSED: "0.0.0.0";
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/server/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,MAAM;;;;;;;EAQjB,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/server/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,SAAS;;;;;;;EAQpB,CAAC"}
@@ -16,7 +16,7 @@
16
16
  * );
17
17
  * ```
18
18
  */
19
- export const server = Object.freeze({
19
+ export const constants = Object.freeze({
20
20
  LOCALHOST: 'localhost',
21
21
  IP_LOCALHOST: '127.0.0.1',
22
22
  IP_EXPOSED: '0.0.0.0',
@@ -1,6 +1,7 @@
1
1
  import { Readable } from 'node:stream';
2
- import type { ViteDevServer } from 'vite';
2
+ import type { Logger, ViteDevServer } from 'vite';
3
3
  import type * as R from '../routes/route.js';
4
+ import type { GracileConfig } from '../user-config.js';
4
5
  type StandardResponse = {
5
6
  response: Response;
6
7
  body?: never;
@@ -11,6 +12,9 @@ type ResponseWithNodeReadable = {
11
12
  body: Readable;
12
13
  init: ResponseInit;
13
14
  };
15
+ export interface AdapterOptions {
16
+ logger?: Logger;
17
+ }
14
18
  /**
15
19
  * The underlying handler interface that you can use to build your own adapter.
16
20
  */
@@ -18,13 +22,14 @@ export type GracileHandler = (request: Request, locals?: unknown) => Promise<Sta
18
22
  export declare function isRedirect(response: Response): {
19
23
  location: string;
20
24
  } | null;
21
- export declare function createGracileHandler({ vite, routes, routeImports, routeAssets, root, serverMode, }: {
25
+ export declare function createGracileHandler({ vite, routes, routeImports, routeAssets, root, serverMode, gracileConfig, }: {
22
26
  vite?: ViteDevServer | undefined;
23
27
  routes: R.RoutesManifest;
24
28
  routeImports?: R.RoutesImports | undefined;
25
29
  routeAssets?: R.RoutesAssets;
26
30
  root: string;
27
31
  serverMode?: boolean | undefined;
32
+ gracileConfig: GracileConfig;
28
33
  }): GracileHandler;
29
34
  export {};
30
35
  //# sourceMappingURL=request.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/server/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIvC,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,MAAM,CAAC;AAOxD,OAAO,KAAK,KAAK,CAAC,MAAM,oBAAoB,CAAC;AAI7C,KAAK,gBAAgB,GAAG;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,IAAI,CAAC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