@torpor/build 0.4.5 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/{RouteType-VOBjKJ8I.js → RouteType-B6BMOyYw.mjs} +13 -12
  3. package/dist/RouteType-B6BMOyYw.mjs.map +1 -0
  4. package/dist/{Server-DL9neaq0.d.ts → Server-CF5wDJp6.d.mts} +1 -1
  5. package/dist/Server-CF5wDJp6.d.mts.map +1 -0
  6. package/dist/{ServerEvent-Dnk2FIKQ.js → ServerEvent-CxPwA4lH.mjs} +1 -1
  7. package/dist/ServerEvent-CxPwA4lH.mjs.map +1 -0
  8. package/dist/{Site-B8TxSzPk.d.ts → Site-DgC6WWn1.d.mts} +20 -9
  9. package/dist/Site-DgC6WWn1.d.mts.map +1 -0
  10. package/dist/{_page-ef72MjgG.js → _page-DBSsnHFG.mjs} +1 -1
  11. package/dist/_page-DBSsnHFG.mjs.map +1 -0
  12. package/dist/bin/index.js +7 -7
  13. package/dist/bin/index.js.map +1 -1
  14. package/dist/{connectMiddleware-PBcWWRr-.js → connectMiddleware-D7nehjj3.mjs} +3 -3
  15. package/dist/connectMiddleware-D7nehjj3.mjs.map +1 -0
  16. package/dist/{index.d.ts → index.d.mts} +11 -6
  17. package/dist/index.d.mts.map +1 -0
  18. package/dist/{index.js → index.mjs} +16 -7
  19. package/dist/index.mjs.map +1 -0
  20. package/dist/{nav.d.ts → nav.d.mts} +1 -1
  21. package/dist/nav.d.mts.map +1 -0
  22. package/dist/{nav.js → nav.mjs} +15 -11
  23. package/dist/nav.mjs.map +1 -0
  24. package/dist/{pathToRegex-BTPkBIYJ.js → pathToRegex-TUAMc3zS.mjs} +1 -1
  25. package/dist/pathToRegex-TUAMc3zS.mjs.map +1 -0
  26. package/dist/{response-KnPcsvtU.js → response-C5TtAsh1.mjs} +2 -2
  27. package/dist/response-C5TtAsh1.mjs.map +1 -0
  28. package/dist/{response.d.ts → response.d.mts} +1 -1
  29. package/dist/response.d.mts.map +1 -0
  30. package/dist/{response.js → response.mjs} +2 -2
  31. package/dist/{run-CJy-W5tX.js → run-DiZgkMnG.mjs} +8 -8
  32. package/dist/run-DiZgkMnG.mjs.map +1 -0
  33. package/dist/{run.d.ts → run.d.mts} +3 -3
  34. package/dist/run.d.mts.map +1 -0
  35. package/dist/run.mjs +8 -0
  36. package/dist/{seeOther-C-36lhS5.js → seeOther-B4Yhu9iq.mjs} +1 -1
  37. package/dist/seeOther-B4Yhu9iq.mjs.map +1 -0
  38. package/dist/{server.d.ts → server.d.mts} +2 -2
  39. package/dist/server.d.mts.map +1 -0
  40. package/dist/{server.js → server.mjs} +3 -3
  41. package/dist/{state.d.ts → state.d.mts} +1 -1
  42. package/dist/state.d.mts.map +1 -0
  43. package/dist/state.mjs +3 -0
  44. package/dist/{test.d.ts → test.d.mts} +3 -3
  45. package/dist/test.d.mts.map +1 -0
  46. package/dist/{test.js → test.mjs} +8 -7
  47. package/dist/test.mjs.map +1 -0
  48. package/package.json +27 -25
  49. package/scripts/postbuild.ts +12 -0
  50. package/src/nav/loadData.ts +16 -5
  51. package/src/nav/navigate.ts +1 -0
  52. package/src/site/Router.ts +12 -13
  53. package/src/site/Site.ts +29 -4
  54. package/src/site/clientEntry.ts +1 -1
  55. package/src/site/manifest.ts +5 -2
  56. package/src/test/runTest.ts +1 -0
  57. package/src/types/ManifestRoute.ts +1 -0
  58. package/src/types/Route.ts +11 -0
  59. package/src/types/RouteHandler.ts +4 -0
  60. package/test/api/_hook.server.ts +3 -0
  61. package/test/api/posts/+page.server.ts +3 -0
  62. package/test/api/posts/[id]/+page.server.ts +3 -0
  63. package/test/router.test.ts +78 -0
  64. package/test/routes/+page.server.ts +3 -0
  65. package/test/routes/+page.ts +3 -0
  66. package/test/routes/_error.ts +3 -0
  67. package/test/routes/_hook.server.ts +3 -0
  68. package/test/routes/_layout.server.ts +3 -0
  69. package/test/routes/_layout.ts +3 -0
  70. package/test/routes/posts/+page.ts +3 -0
  71. package/test/routes/posts/[id]/+page.ts +3 -0
  72. package/test/site.test.ts +40 -0
  73. package/tsdown.config.ts +3 -10
  74. package/vitest.config.ts +2 -2
  75. package/dist/RouteType-VOBjKJ8I.js.map +0 -1
  76. package/dist/Server-DL9neaq0.d.ts.map +0 -1
  77. package/dist/ServerEvent-Dnk2FIKQ.js.map +0 -1
  78. package/dist/Site-B8TxSzPk.d.ts.map +0 -1
  79. package/dist/_page-ef72MjgG.js.map +0 -1
  80. package/dist/connectMiddleware-PBcWWRr-.js.map +0 -1
  81. package/dist/index.d.ts.map +0 -1
  82. package/dist/index.js.map +0 -1
  83. package/dist/nav.d.ts.map +0 -1
  84. package/dist/nav.js.map +0 -1
  85. package/dist/pathToRegex-BTPkBIYJ.js.map +0 -1
  86. package/dist/response-KnPcsvtU.js.map +0 -1
  87. package/dist/response.d.ts.map +0 -1
  88. package/dist/run-CJy-W5tX.js.map +0 -1
  89. package/dist/run.d.ts.map +0 -1
  90. package/dist/run.js +0 -8
  91. package/dist/seeOther-C-36lhS5.js.map +0 -1
  92. package/dist/server.d.ts.map +0 -1
  93. package/dist/state.d.ts.map +0 -1
  94. package/dist/state.js +0 -3
  95. package/dist/test.d.ts.map +0 -1
  96. package/dist/test.js.map +0 -1
  97. /package/dist/bin/{index.d.ts → index.d.mts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @torpor/build
2
2
 
3
+ ## 0.4.6
4
+
5
+ ### Patch Changes
6
+
7
+ - cf8d8db: Fix: pass search params to client side navigation
8
+ - 64adf0b: Feat: `subFolder` option when adding routes
9
+ - Updated dependencies [9bca98e]
10
+ - Updated dependencies [7382b6d]
11
+ - Updated dependencies [d68d347]
12
+ - Updated dependencies [4e3d726]
13
+ - Updated dependencies [adfa504]
14
+ - @torpor/view@0.4.14
15
+
3
16
  ## 0.4.5
4
17
 
5
18
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { t as pathToRegex } from "./pathToRegex-BTPkBIYJ.js";
1
+ import { t as pathToRegex } from "./pathToRegex-TUAMc3zS.mjs";
2
2
 
3
3
  //#region src/site/Router.ts
4
4
  /**
@@ -11,16 +11,18 @@ var Router = class {
11
11
  for (let r of routes) this.routes.push(new Route(r.path, {
12
12
  path: r.path,
13
13
  type: r.type,
14
- endPoint: r.endPoint
14
+ endPoint: r.endPoint,
15
+ subFolder: r.subFolder
15
16
  }));
16
17
  this.#sortRoutes();
17
18
  return this;
18
19
  }
19
- addPage(path, type, endPoint) {
20
+ addPage(path, type, endPoint, subFolder) {
20
21
  this.routes.push(new Route(path, {
21
22
  path,
22
23
  type,
23
- endPoint
24
+ endPoint,
25
+ subFolder
24
26
  }));
25
27
  this.#sortRoutes();
26
28
  return this;
@@ -37,14 +39,13 @@ var Router = class {
37
39
  };
38
40
  }
39
41
  }
40
- console.log(`not found: '${path}'`);
41
42
  }
42
43
  #loadHandler(handler, path) {
43
- handler.layouts = this.#findLayouts(path);
44
+ handler.layouts = this.#findLayouts(path, handler);
44
45
  handler.serverEndPoint = this.#findServer(path);
45
- handler.serverHook = this.#findServerHook(path);
46
+ handler.serverHook = this.#findServerHook(handler);
46
47
  }
47
- #findLayouts(path) {
48
+ #findLayouts(path, handler) {
48
49
  let layouts = [];
49
50
  let parts = path.replace(/\/~server$/, "").split("/");
50
51
  let basePath = "";
@@ -52,7 +53,7 @@ var Router = class {
52
53
  if (i > 0) basePath += "/" + parts[i];
53
54
  const layoutPath = basePath + "/_layout";
54
55
  const layoutRoute = this.routes.find((r) => r.path === layoutPath);
55
- if (layoutRoute) layouts.push({
56
+ if (layoutRoute && layoutRoute.handler.subFolder === handler.subFolder) layouts.push({
56
57
  path: layoutPath,
57
58
  endPoint: layoutRoute.handler.endPoint,
58
59
  serverEndPoint: this.#findServer(layoutPath)
@@ -65,9 +66,9 @@ var Router = class {
65
66
  const serverRoute = this.routes.find((r) => r.path === serverPath);
66
67
  return serverRoute && serverRoute.handler.endPoint;
67
68
  }
68
- #findServerHook(path) {
69
+ #findServerHook(handler) {
69
70
  let serverHookPath = "/_hook/~server";
70
- if (path.startsWith("/api/")) serverHookPath = "/api" + serverHookPath;
71
+ if (handler.subFolder !== void 0) serverHookPath = handler.subFolder + serverHookPath;
71
72
  const serverHookRoute = this.routes.find((r) => r.path === serverHookPath);
72
73
  return serverHookRoute && serverHookRoute.handler.endPoint;
73
74
  }
@@ -104,4 +105,4 @@ const ERROR_ROUTE = 8;
104
105
 
105
106
  //#endregion
106
107
  export { LAYOUT_SERVER_ROUTE as a, SERVER_ROUTE as c, LAYOUT_ROUTE as i, Router as l, HOOK_ROUTE as n, PAGE_ROUTE as o, HOOK_SERVER_ROUTE as r, PAGE_SERVER_ROUTE as s, ERROR_ROUTE as t };
107
- //# sourceMappingURL=RouteType-VOBjKJ8I.js.map
108
+ //# sourceMappingURL=RouteType-B6BMOyYw.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RouteType-B6BMOyYw.mjs","names":["#sortRoutes","#loadHandler","#findLayouts","#findServer","#findServerHook","layouts: LayoutHandler[]"],"sources":["../src/site/Router.ts","../src/types/RouteType.ts"],"sourcesContent":["import type LayoutHandler from \"../types/LayoutHandler\";\nimport type ManifestRoute from \"../types/ManifestRoute\";\nimport type RouteHandler from \"../types/RouteHandler\";\nimport pathToRegex from \"../utils/pathToRegex\";\n\n/**\n * A router that handles file routes with layouts, hooks, etc.\n */\nexport default class Router {\n\troutes: Route[] = [];\n\n\tconstructor() {}\n\n\t//add(path: string, file: string) {\n\t//\t// TODO: Call the specific addX method based on the file path\n\t//\tthis.addPage(route, file);\n\t//}\n\n\taddPages(routes: ManifestRoute[]): this {\n\t\tfor (let r of routes) {\n\t\t\tthis.routes.push(\n\t\t\t\tnew Route(r.path, {\n\t\t\t\t\tpath: r.path,\n\t\t\t\t\ttype: r.type,\n\t\t\t\t\tendPoint: r.endPoint,\n\t\t\t\t\tsubFolder: r.subFolder,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tthis.#sortRoutes();\n\t\treturn this;\n\t}\n\n\t// TODO: Allow calling with the endpoint itself, so that you can setup an app with no scaffold\n\taddPage(path: string, type: number, endPoint: () => Promise<any>, subFolder?: string): this {\n\t\tthis.routes.push(\n\t\t\tnew Route(path, {\n\t\t\t\tpath,\n\t\t\t\ttype,\n\t\t\t\tendPoint,\n\t\t\t\tsubFolder,\n\t\t\t}),\n\t\t);\n\t\tthis.#sortRoutes();\n\t\treturn this;\n\t}\n\n\t/*\n\tloadPage(ev: ServerEvent, file: string): Response {\n\t\tlet page = this.pages.get(file);\n\t\tif (!page) {\n\t\t\tpage = {};\n\t\t\tthis.pages.set(file, page);\n\t\t}\n\t}\n\t*/\n\n\tmatch(path: string, query: URLSearchParams): RouteMatch | undefined {\n\t\tfor (let route of this.routes) {\n\t\t\tlet match = path.match(route.regex);\n\t\t\tif (match) {\n\t\t\t\t// Lazy load server endpoints and layouts\n\t\t\t\tif (!route.handler.loaded) {\n\t\t\t\t\tthis.#loadHandler(route.handler, route.path);\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\thandler: route.handler,\n\t\t\t\t\tparams: match.groups,\n\t\t\t\t\tquery,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\t#loadHandler(handler: RouteHandler, path: string) {\n\t\thandler.layouts = this.#findLayouts(path, handler);\n\t\thandler.serverEndPoint = this.#findServer(path);\n\t\thandler.serverHook = this.#findServerHook(handler);\n\t}\n\n\t#findLayouts(path: string, handler: RouteHandler): LayoutHandler[] | undefined {\n\t\tlet layouts: LayoutHandler[] = [];\n\t\tlet parts = path\n\t\t\t// Strip the trailing`~/server` (so we don't look for `~/server/_layout`\n\t\t\t// which will never exist)\n\t\t\t.replace(/\\/~server$/, \"\")\n\t\t\t// The path will always start with / so splitting e.g. `/first/second`\n\t\t\t// will result in ['', 'first', 'second'] and checks for `/_layout`,\n\t\t\t// `/first/_layout` and `/second/_layout`\n\t\t\t.split(\"/\");\n\t\tlet basePath = \"\";\n\t\tfor (let i = 0; i < parts.length; i++) {\n\t\t\tif (i > 0) {\n\t\t\t\tbasePath += \"/\" + parts[i];\n\t\t\t}\n\t\t\tconst layoutPath = basePath + \"/_layout\";\n\t\t\tconst layoutRoute = this.routes.find((r) => r.path === layoutPath);\n\t\t\tif (layoutRoute && layoutRoute.handler.subFolder === handler.subFolder) {\n\t\t\t\tlayouts.push({\n\t\t\t\t\tpath: layoutPath,\n\t\t\t\t\tendPoint: layoutRoute.handler.endPoint,\n\t\t\t\t\tserverEndPoint: this.#findServer(layoutPath),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn layouts.length ? layouts : undefined;\n\t}\n\n\t#findServer(path: string): (() => Promise<any>) | undefined {\n\t\tconst serverPath = path.replace(/\\/$/, \"\") + \"/~server\";\n\t\tconst serverRoute = this.routes.find((r) => r.path === serverPath);\n\t\treturn serverRoute && serverRoute.handler.endPoint;\n\t}\n\n\t#findServerHook(handler: RouteHandler): (() => Promise<any>) | undefined {\n\t\t// TODO: Should this be a collection, like layouts?\n\t\tlet serverHookPath = \"/_hook/~server\";\n\t\tif (handler.subFolder !== undefined) {\n\t\t\tserverHookPath = handler.subFolder + serverHookPath;\n\t\t}\n\t\tconst serverHookRoute = this.routes.find((r) => r.path === serverHookPath);\n\t\treturn serverHookRoute && serverHookRoute.handler.endPoint;\n\t}\n\n\t// HACK: We're doing this here as well as in Site, so that you can use the\n\t// Router externally without Site\n\t#sortRoutes() {\n\t\tthis.routes = this.routes.sort((a, b) => {\n\t\t\t// Sort [param]s after paths\n\t\t\t// There might be a quicker/easier way to do this\n\t\t\tfor (let i = 0; i < Math.min(a.path.length, b.path.length); i++) {\n\t\t\t\tif (a.path[i] === \"[\" && b.path[i] !== \"[\") {\n\t\t\t\t\treturn 1;\n\t\t\t\t} else if (b.path[i] === \"[\" && a.path[i] !== \"[\") {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else if (a.path[i] === b.path[i]) {\n\t\t\t\t\t// Keep going...\n\t\t\t\t} else {\n\t\t\t\t\treturn a.path[i].localeCompare(b.path[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn a.path.length - b.path.length;\n\t\t});\n\t}\n}\n\nclass Route {\n\tpath: string;\n\tregex: RegExp;\n\thandler: RouteHandler;\n\n\tconstructor(path: string, handler: RouteHandler) {\n\t\tthis.path = path;\n\t\tthis.regex = pathToRegex(path);\n\t\tthis.handler = handler;\n\t}\n}\n\ninterface RouteMatch {\n\thandler: RouteHandler;\n\tparams?: Record<string, string>;\n\tquery: URLSearchParams;\n}\n","export const PAGE_ROUTE = 0;\nexport const PAGE_SERVER_ROUTE = 1;\nexport const SERVER_ROUTE = 3;\nexport const LAYOUT_ROUTE = 4;\nexport const LAYOUT_SERVER_ROUTE = 5;\nexport const HOOK_ROUTE = 6;\nexport const HOOK_SERVER_ROUTE = 7;\nexport const ERROR_ROUTE = 8;\n\nexport type RouteType =\n\t| typeof PAGE_ROUTE\n\t| typeof PAGE_SERVER_ROUTE\n\t| typeof SERVER_ROUTE\n\t| typeof LAYOUT_ROUTE\n\t| typeof LAYOUT_SERVER_ROUTE\n\t| typeof HOOK_ROUTE\n\t| typeof HOOK_SERVER_ROUTE\n\t| typeof ERROR_ROUTE\n\t| -1;\n"],"mappings":";;;;;;AAQA,IAAqB,SAArB,MAA4B;CAC3B,SAAkB,EAAE;CAEpB,cAAc;CAOd,SAAS,QAA+B;AACvC,OAAK,IAAI,KAAK,OACb,MAAK,OAAO,KACX,IAAI,MAAM,EAAE,MAAM;GACjB,MAAM,EAAE;GACR,MAAM,EAAE;GACR,UAAU,EAAE;GACZ,WAAW,EAAE;GACb,CAAC,CACF;AAEF,QAAKA,YAAa;AAClB,SAAO;;CAIR,QAAQ,MAAc,MAAc,UAA8B,WAA0B;AAC3F,OAAK,OAAO,KACX,IAAI,MAAM,MAAM;GACf;GACA;GACA;GACA;GACA,CAAC,CACF;AACD,QAAKA,YAAa;AAClB,SAAO;;CAaR,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eAAe;AAC1E,SAAO,mBAAmB,gBAAgB,QAAQ;;CAKnD,cAAc;AACb,OAAK,SAAS,KAAK,OAAO,MAAM,GAAG,MAAM;AAGxC,QAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,KAAK,OAAO,EAAE,IAC3D,KAAI,EAAE,KAAK,OAAO,OAAO,EAAE,KAAK,OAAO,IACtC,QAAO;YACG,EAAE,KAAK,OAAO,OAAO,EAAE,KAAK,OAAO,IAC7C,QAAO;YACG,EAAE,KAAK,OAAO,EAAE,KAAK,IAAI,OAGnC,QAAO,EAAE,KAAK,GAAG,cAAc,EAAE,KAAK,GAAG;AAG3C,UAAO,EAAE,KAAK,SAAS,EAAE,KAAK;IAC7B;;;AAIJ,IAAM,QAAN,MAAY;CACX;CACA;CACA;CAEA,YAAY,MAAc,SAAuB;AAChD,OAAK,OAAO;AACZ,OAAK,QAAQ,YAAY,KAAK;AAC9B,OAAK,UAAU;;;;;;AC3JjB,MAAa,aAAa;AAC1B,MAAa,oBAAoB;AACjC,MAAa,eAAe;AAC5B,MAAa,eAAe;AAC5B,MAAa,sBAAsB;AACnC,MAAa,aAAa;AAC1B,MAAa,oBAAoB;AACjC,MAAa,cAAc"}
@@ -75,4 +75,4 @@ interface Match {
75
75
  }
76
76
  //#endregion
77
77
  export { CookieHelper as a, HeaderHelper as i, MiddlewareFunction as n, ServerEvent as r, Server as t };
78
- //# sourceMappingURL=Server-DL9neaq0.d.ts.map
78
+ //# sourceMappingURL=Server-CF5wDJp6.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Server-CF5wDJp6.d.mts","names":[],"sources":["../src/server/CookieHelper.ts","../src/server/HeaderHelper.ts","../src/server/ServerEvent.ts","../src/server/types/MiddlewareFunction.ts","../src/server/types/ServerFunction.ts","../src/server/Server.ts"],"sourcesContent":[],"mappings":";;;cAEqB,YAAA;WACX;EAHyC,OAE9B,EAEX,GAFW,CAAA,MAAA,EAAA,MA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OJxBrD,CIwB6D,QJxB7D,CAAA;EAEY;;;;;ACHG;EAGf,GAAA,CAAA,IAAA,EAAA,MAAA,EAAA,EAAA,EGkEa,cHlEb,CAAA,EGkE8B,MHlE9B;EACC,KAAA,CAAA,IAAA,EAAA,MAAA,CAAA,EGuEW,KHvEX,GAAA,SAAA;EAED,GAAA,CAAA,GAAA,EAAA,EGoFE,kBHpFF,EAAA,CAAA,EGoFyB,MHpFzB;;cG6GJ,YAAA,CHxGI;EAEY,IAAA,EAAA,MAAA;EAAkB,KAAA,EGwGhC,MHxGgC;EAAA,EAAA,EGyGnC,cHzGmC;gCG2GT;;UAmBrB,KAAA;EF5Ic,EAAA,EE6InB,cF3IA;EACA,MAAA,CAAA,EE2IK,MF3IL,CAAA,MAAA,EAAA,MAAA,CAAA"}
@@ -70,4 +70,4 @@ var ServerEvent = class {
70
70
 
71
71
  //#endregion
72
72
  export { HeaderHelper as n, CookieHelper as r, ServerEvent as t };
73
- //# sourceMappingURL=ServerEvent-Dnk2FIKQ.js.map
73
+ //# sourceMappingURL=ServerEvent-CxPwA4lH.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServerEvent-CxPwA4lH.mjs","names":[],"sources":["../src/server/CookieHelper.ts","../src/server/HeaderHelper.ts","../src/server/ServerEvent.ts"],"sourcesContent":["import { SerializeOptions, parse, serialize } from \"cookie\";\n\nexport default class CookieHelper {\n\trequest: Request;\n\tcookies: Map<string, string> = new Map();\n\n\tconstructor(request: Request) {\n\t\tthis.request = request;\n\t}\n\n\tget(name: string): string | undefined {\n\t\t// If it's been set, return the value from the map\n\t\tif (this.cookies.has(name)) {\n\t\t\treturn parse(this.cookies.get(name)!)[name];\n\t\t}\n\t\t// Otherwise, return the value from the `cookie` header\n\t\tconst header = this.request.headers.get(\"cookie\");\n\t\treturn parse(header ?? \"\")[name];\n\t}\n\n\tset(name: string, value: string, options?: SerializeOptions): void {\n\t\t// Set a cookie header with some default values for security\n\t\toptions ??= {};\n\t\toptions.httpOnly ??= true;\n\t\toptions.secure ??= true;\n\t\toptions.sameSite ??= \"lax\";\n\t\tthis.cookies.set(name, serialize(name, value, options));\n\t}\n\n\tdelete(name: string, options?: SerializeOptions): void {\n\t\t// Set a cookie header with an immediate expiry date\n\t\toptions ??= {};\n\t\toptions.expires = new Date(0);\n\t\tthis.cookies.set(name, serialize(name, \"\", options));\n\t}\n}\n","export default class HeaderHelper {\n\trequest: Request;\n\theaders: Map<string, string> = new Map();\n\n\tconstructor(request: Request) {\n\t\tthis.request = request;\n\t}\n\n\tget(name: string): string | undefined {\n\t\t// If it's been set, return the updated value\n\t\tif (this.headers.has(name)) {\n\t\t\treturn this.headers.get(name);\n\t\t}\n\t\t// Otherwise, return the value from the header\n\t\treturn this.request.headers.get(name) ?? undefined;\n\t}\n\n\tset(name: string, value: string): void {\n\t\tthis.headers.set(name, value);\n\t}\n\n\tdelete(name: string): void {\n\t\tthis.headers.delete(name);\n\t}\n}\n","import CookieHelper from \"./CookieHelper\";\nimport HeaderHelper from \"./HeaderHelper\";\n\nexport default class ServerEvent {\n\trequest: Request;\n\tresponse: Response | undefined | void;\n\t// TODO: Should we cast types??\n\tparams?: Record<string, string>;\n\n\tadapter: any;\n\n\tcookies: CookieHelper;\n\theaders: HeaderHelper;\n\n\tconstructor(request: Request, params?: Record<string, string>) {\n\t\tthis.request = request;\n\t\tthis.params = params;\n\t\tthis.cookies = new CookieHelper(request);\n\t\tthis.headers = new HeaderHelper(request);\n\n\t\t// Adapters may have added the `adapter` property to globalThis\n\t\t// @ts-ignore\n\t\tthis.adapter = globalThis.adapter;\n\t}\n\n\taddHeaders(): void {\n\t\tif (!this.response) {\n\t\t\tthrow new Error(\"Response not created yet\");\n\t\t}\n\n\t\tfor (let cookie of this.cookies.cookies.values()) {\n\t\t\tthis.response.headers.append(\"set-cookie\", cookie);\n\t\t}\n\n\t\tfor (let header of this.headers.headers.entries()) {\n\t\t\tthis.response.headers.append(header[0], header[1]);\n\t\t}\n\t}\n}\n"],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,MAAI,CAAC,KAAK,SACT,OAAM,IAAI,MAAM,2BAA2B;AAG5C,OAAK,IAAI,UAAU,KAAK,QAAQ,QAAQ,QAAQ,CAC/C,MAAK,SAAS,QAAQ,OAAO,cAAc,OAAO;AAGnD,OAAK,IAAI,UAAU,KAAK,QAAQ,QAAQ,SAAS,CAChD,MAAK,SAAS,QAAQ,OAAO,OAAO,IAAI,OAAO,GAAG"}
@@ -1,4 +1,4 @@
1
- import { t as Server } from "./Server-DL9neaq0.js";
1
+ import { t as Server } from "./Server-CF5wDJp6.mjs";
2
2
  import { Plugin, UserConfig } from "vite";
3
3
 
4
4
  //#region src/types/Adapter.d.ts
@@ -19,6 +19,17 @@ declare const HOOK_SERVER_ROUTE = 7;
19
19
  declare const ERROR_ROUTE = 8;
20
20
  type RouteType = typeof PAGE_ROUTE | typeof PAGE_SERVER_ROUTE | typeof SERVER_ROUTE | typeof LAYOUT_ROUTE | typeof LAYOUT_SERVER_ROUTE | typeof HOOK_ROUTE | typeof HOOK_SERVER_ROUTE | typeof ERROR_ROUTE | -1;
21
21
  //#endregion
22
+ //#region src/types/Route.d.ts
23
+ /**
24
+ * A route that is added to the Site.
25
+ */
26
+ interface Route {
27
+ path: string;
28
+ file: string;
29
+ type: RouteType;
30
+ subFolder?: string;
31
+ }
32
+ //#endregion
22
33
  //#region src/site/Site.d.ts
23
34
  /**
24
35
  * The Site class contains the information necessary to setup a @torpor/build
@@ -27,11 +38,7 @@ type RouteType = typeof PAGE_ROUTE | typeof PAGE_SERVER_ROUTE | typeof SERVER_RO
27
38
  declare class Site {
28
39
  #private;
29
40
  root: string;
30
- routes: {
31
- path: string;
32
- file: string;
33
- type: RouteType;
34
- }[];
41
+ routes: Route[];
35
42
  plugins: Plugin[];
36
43
  adapter: Adapter;
37
44
  /**
@@ -51,8 +58,12 @@ declare class Site {
51
58
  /**
52
59
  * Adds a folder of routes, based on the names of the files in the folder
53
60
  * @param folder The folder containing the routes
61
+ * @param subFolder If a subFolder is set, all routes in the folder will be
62
+ * placed under the subFolder, and only hooks, layouts etc will be used if
63
+ * they have the same subFolder. This can be used to create e.g. an `api`
64
+ * set of routes with their own hook for authorization from various clients
54
65
  */
55
- addRouteFolder(folder: string): Promise<void>;
66
+ addRouteFolder(folder: string, subFolder?: string): Promise<void>;
56
67
  /**
57
68
  * Adds a file route, which can have a standard name (e.g. +page.ts) or any
58
69
  * name if you pass the type
@@ -60,8 +71,8 @@ declare class Site {
60
71
  * @param file The file
61
72
  * @param type The file type (if the file name is non-standard)
62
73
  */
63
- addRouteFile(path: string, file: string, type?: "+page" | "+page.server" | "+server" | "_layout" | "_layout.server" | "_hook" | "_hook.server" | "_error"): void;
74
+ addRouteFile(path: string, file: string, type?: "+page" | "+page.server" | "+server" | "_layout" | "_layout.server" | "_hook" | "_hook.server" | "_error", subFolder?: string): void;
64
75
  }
65
76
  //#endregion
66
77
  export { Adapter as n, Site as t };
67
- //# sourceMappingURL=Site-B8TxSzPk.d.ts.map
78
+ //# sourceMappingURL=Site-DgC6WWn1.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Site-DgC6WWn1.d.mts","names":[],"sources":["../src/types/Adapter.ts","../src/types/RouteType.ts","../src/types/Route.ts","../src/site/Site.ts"],"sourcesContent":[],"mappings":";;;;UAGyB,OAAA;oBACN,SAAS;EAHX,SAEQ,CAAA,EAAA,CAAA,IAAA,EAEL,IAFK,EAAA,GAEI,OAFJ,CAAA,IAAA,CAAA,GAAA,IAAA;EACN,KAAA,EAAA,CAAA,MAAA,EAEF,MAFE,EAAA,IAAA,EAEY,IAFZ,EAAA,GAAA,IAAA;;;;cCJN,UAAA;cACA,iBAAA;cACA,YAAA;cACA,YAAA;ADAY,cCCZ,mBAAA,GDDY,CAAA;AACN,cCCN,UAAA,GDDM,CAAA;AAAS,cCEf,iBAAA,GDFe,CAAA;AACR,cCEP,WAAA,GDFO,CAAA;AAAS,KCIjB,SAAA,GDJiB,OCKnB,UDLmB,GAAA,OCMnB,iBDNmB,GAAA,OCOnB,YDPmB,GAAA,OCQnB,YDRmB,GAAA,OCSnB,mBDTmB,GAAA,OCUnB,UDVmB,GAAA,OCWnB,iBDXmB,GAAA,OCYnB,WDZmB,GAAA,CAAA,CAAA;;;;;;AAFJ,UEEA,KAAA,CFFA;EACN,IAAA,EAAA,MAAA;EAAS,IAAA,EAAA,MAAA;EACR,IAAA,EEGb,SFHa;EAAS,SAAA,CAAA,EAAA,MAAA;;;;;AAJZ;;;AAIG,cGuBC,IAAA,CHvBD;EAAS,CAAA,OAAA;EACZ,IAAA,EAAA,MAAA;EAAc,MAAA,EGwBtB,KHxBsB,EAAA;EAAA,OAAA,EG6BrB,MH7BqB,EAAA;WG+BrB;;;AFrCV;AACA;AACA;EACA,MAAa,EAAA,MAAA,EAAA;EACb;AACA;AACA;AACA;AAEA;;EAEU,UAAA,CAAA,EEuCI,UFvCJ;EACA,WAAA,CAAA;EACA;;;;;;;;sDEmDiD;EDhE5B;;;;ACKR;;;EAgCb,YAAA,CAAA,IAAA,EAAA,MAAA,EAAA,IAAA,EAAA,MAAA,EAAA,IAAA,CAAA,EAAA,OAAA,GAAA,cAAA,GAAA,SAAA,GAAA,SAAA,GAAA,gBAAA,GAAA,OAAA,GAAA,cAAA,GAAA,QAAA,EAAA,SAAA,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA"}
@@ -12,4 +12,4 @@ var $page_default = $page;
12
12
 
13
13
  //#endregion
14
14
  export { $page_default as t };
15
- //# sourceMappingURL=_page-ef72MjgG.js.map
15
+ //# sourceMappingURL=_page-DBSsnHFG.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_page-DBSsnHFG.mjs","names":["PAGE_SYMBOL: unique symbol","$page: PageState"],"sources":["../src/state/$page.ts"],"sourcesContent":["import { $watch } from \"@torpor/view\";\nimport type PageState from \"../types/PageState\";\n\nconst PAGE_SYMBOL: unique symbol = Symbol.for(\"t_page\");\n\nconst $page: PageState =\n\t// @ts-ignore\n\t(globalThis[PAGE_SYMBOL] ??=\n\t\t// TODO: Should use the SSR $watch if entering via serverEntry\n\t\t$watch(\n\t\t\t{\n\t\t\t\tstatus: 404,\n\t\t\t\turl: new URL(\"http://localhost\"),\n\t\t\t\tform: undefined,\n\t\t\t\terror: {\n\t\t\t\t\tmessage: \"\",\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tshallow: true,\n\t\t\t},\n\t\t));\n\nexport default $page;\n"],"mappings":";;;AAGA,MAAMA,cAA6B,OAAO,IAAI,SAAS;AAEvD,MAAMC,QAEJ,WAAW,iBAEX,OACC;CACC,QAAQ;CACR,KAAK,IAAI,IAAI,mBAAmB;CAChC,MAAM;CACN,OAAO,EACN,SAAS,IACT;CACD,EACD,EACC,SAAS,MACT,CACD;AAEH,oBAAe"}
package/dist/bin/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #! /usr/bin/env node
2
- import "../pathToRegex-BTPkBIYJ.js";
3
- import "../seeOther-C-36lhS5.js";
4
- import "../response-KnPcsvtU.js";
5
- import { t as run } from "../run-CJy-W5tX.js";
6
- import "../ServerEvent-Dnk2FIKQ.js";
7
- import "../connectMiddleware-PBcWWRr-.js";
2
+ import "../pathToRegex-TUAMc3zS.mjs";
3
+ import "../seeOther-B4Yhu9iq.mjs";
4
+ import "../response-C5TtAsh1.mjs";
5
+ import { t as run } from "../run-DiZgkMnG.mjs";
6
+ import "../ServerEvent-CxPwA4lH.mjs";
7
+ import "../connectMiddleware-D7nehjj3.mjs";
8
8
 
9
9
  //#region src/bin/index.ts
10
10
  const workingDir = process.cwd();
@@ -14,4 +14,4 @@ else if (process.argv.includes("--preview")) await run(workingDir, "preview");
14
14
 
15
15
  //#endregion
16
16
  export { };
17
- //# sourceMappingURL=index.js.map
17
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/bin/index.ts"],"sourcesContent":["#! /usr/bin/env node\nimport run from \"../run/run\";\n\nconst workingDir = process.cwd();\nif (process.argv.includes(\"--dev\")) {\n\tawait run(workingDir, \"dev\");\n} else if (process.argv.includes(\"--build\")) {\n\tawait run(workingDir, \"build\");\n} else if (process.argv.includes(\"--preview\")) {\n\tawait run(workingDir, \"preview\");\n}\n"],"mappings":";;;;;;;;;AAGA,MAAM,aAAa,QAAQ,KAAK;AAChC,IAAI,QAAQ,KAAK,SAAS,QAAQ,CACjC,OAAM,IAAI,YAAY,MAAM;SAClB,QAAQ,KAAK,SAAS,UAAU,CAC1C,OAAM,IAAI,YAAY,QAAQ;SACpB,QAAQ,KAAK,SAAS,YAAY,CAC5C,OAAM,IAAI,YAAY,UAAU"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/bin/index.ts"],"sourcesContent":["#! /usr/bin/env node\nimport run from \"../run/run\";\n\nconst workingDir = process.cwd();\nif (process.argv.includes(\"--dev\")) {\n\tawait run(workingDir, \"dev\");\n} else if (process.argv.includes(\"--build\")) {\n\tawait run(workingDir, \"build\");\n} else if (process.argv.includes(\"--preview\")) {\n\tawait run(workingDir, \"preview\");\n}\n"],"mappings":";;;;;;;;;AAGA,MAAM,aAAa,QAAQ,KAAK;AAChC,IAAI,QAAQ,KAAK,SAAS,QAAQ,CACjC,OAAM,IAAI,YAAY,MAAM;SAClB,QAAQ,KAAK,SAAS,UAAU,CAC1C,OAAM,IAAI,YAAY,QAAQ;SACpB,QAAQ,KAAK,SAAS,YAAY,CAC5C,OAAM,IAAI,YAAY,UAAU"}
@@ -1,5 +1,5 @@
1
- import { t as pathToRegex } from "./pathToRegex-BTPkBIYJ.js";
2
- import { t as ServerEvent } from "./ServerEvent-Dnk2FIKQ.js";
1
+ import { t as pathToRegex } from "./pathToRegex-TUAMc3zS.mjs";
2
+ import { t as ServerEvent } from "./ServerEvent-CxPwA4lH.mjs";
3
3
  import { ServerResponse } from "node:http";
4
4
  import { PassThrough, Readable } from "node:stream";
5
5
 
@@ -249,4 +249,4 @@ const statusCodesWithoutBody = [
249
249
 
250
250
  //#endregion
251
251
  export { Server as n, connectMiddleware as t };
252
- //# sourceMappingURL=connectMiddleware-PBcWWRr-.js.map
252
+ //# sourceMappingURL=connectMiddleware-D7nehjj3.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connectMiddleware-D7nehjj3.mjs","names":["#sortRoutes","v","chunks: Buffer[]"],"sources":["../src/server/Server.ts","../src/server/connect/bufferToArrayBuffer.ts","../src/server/connect/flattenHeaders.ts","../src/server/connect/nodeMessageToNodeResponse.ts","../src/server/connect/readableToBuffer.ts","../src/server/connect/requestToNodeMessage.ts","../src/server/connect/connectMiddleware.ts"],"sourcesContent":["import pathToRegex from \"../utils/pathToRegex\";\nimport ServerEvent from \"./ServerEvent\";\nimport type MiddlewareFunction from \"./types/MiddlewareFunction\";\nimport type ServerFunction from \"./types/ServerFunction\";\n\nconst noop = () => {};\n\n/**\n * A Fetch API Request/Response server.\n */\nexport default class Server {\n\t// TODO: We don't use any of the routes, just add(\"*\") in runDev/runBuild...\n\troutes: RouteHandler[] = [];\n\t// TODO: We only use the Vite middleware here\n\tmiddleware: MiddlewareFunction[] = [];\n\n\tconstructor() {\n\t\tthis.routes = [];\n\t\tthis.middleware = [];\n\t}\n\n\t/**\n\t * The standard Fetch API method that should work in any runtime (including\n\t * Node with polyfills).\n\t * @returns\n\t */\n\tfetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n\t\tconst request = new Request(input, init);\n\t\tconst url = new URL(request.url);\n\t\tconst match = this.match(url.pathname);\n\t\tlet ev = new ServerEvent(request, match?.params);\n\n\t\tif (this.middleware.length) {\n\t\t\t// TODO: Get middleware that applies to this route only?\n\t\t\tawait this.middleware[0](ev, buildNext(this.middleware, 0));\n\t\t\tfunction buildNext(middleware: MiddlewareFunction[], i: number): () => void | Promise<void> {\n\t\t\t\tif (ev.response) {\n\t\t\t\t\treturn noop;\n\t\t\t\t}\n\n\t\t\t\tif (i < middleware.length - 1) {\n\t\t\t\t\tlet next = middleware[i + 1];\n\t\t\t\t\treturn async () => next(ev, buildNext(middleware, i + 1));\n\t\t\t\t} else {\n\t\t\t\t\treturn match\n\t\t\t\t\t\t? async () => {\n\t\t\t\t\t\t\t\tev.response = await match.fn(ev);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: noop;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (match) {\n\t\t\tev.response = await match.fn(ev);\n\t\t} else {\n\t\t\treturn new Response(null, { status: 404 });\n\t\t}\n\n\t\t// TODO: Should I be returning 200 if there's no response? Because it's not an error??\n\t\tev.response ??= new Response(null, { status: 200 });\n\t\tev.addHeaders();\n\n\t\treturn ev.response;\n\t};\n\n\t/**\n\t * Adds a server function at a route path.\n\t * @param path The route path pattern.\n\t * @param fn The function to call when the pattern is matched.\n\t * @returns\n\t */\n\tadd(path: string, fn: ServerFunction): Server {\n\t\tthis.routes.push(new RouteHandler(path, fn));\n\t\tthis.#sortRoutes();\n\t\treturn this;\n\t}\n\n\tmatch(path: string): Match | undefined {\n\t\tfor (let handler of this.routes) {\n\t\t\tlet match = path.match(handler.regex);\n\t\t\tif (match) {\n\t\t\t\treturn {\n\t\t\t\t\tfn: handler.fn,\n\t\t\t\t\tparams: match.groups,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\tconsole.log(`Server path not found: ${path}`);\n\t}\n\n\t// TODO:\n\t//use(path: string, ...fn: MiddlewareFunction[])\n\tuse(...fn: MiddlewareFunction[]): Server {\n\t\tthis.middleware = this.middleware.concat(fn);\n\t\treturn this;\n\t}\n\n\t#sortRoutes() {\n\t\tthis.routes = this.routes.sort((a, b) => {\n\t\t\t// Sort [param]s after paths\n\t\t\t// There might be a quicker/easier way to do this\n\t\t\tfor (let i = 0; i < Math.min(a.path.length, b.path.length); i++) {\n\t\t\t\tif (a.path[i] === \"[\" && b.path[i] !== \"[\") {\n\t\t\t\t\treturn 1;\n\t\t\t\t} else if (b.path[i] === \"[\" && a.path[i] !== \"[\") {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else if (a.path[i] === b.path[i]) {\n\t\t\t\t\t// Keep going...\n\t\t\t\t} else {\n\t\t\t\t\treturn a.path[i].localeCompare(b.path[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn a.path.length - b.path.length;\n\t\t});\n\t}\n}\n\nclass RouteHandler {\n\tpath: string;\n\tregex: RegExp;\n\tfn: ServerFunction;\n\n\tconstructor(path: string, fn: ServerFunction) {\n\t\tthis.path = path;\n\t\tthis.regex = pathToRegex(path);\n\t\tthis.fn = fn;\n\t}\n}\n\n//class MiddlewareHandler {\n//\tpath: string;\n//\tregex: RegExp;\n//\tfn: MiddlewareFunction;\n//\n//\tconstructor(path: string, fn: MiddlewareFunction) {\n//\t\tthis.path = path;\n//\t\tthis.regex = pathToRegex(path);\n//\t\tthis.fn = fn;\n//\t}\n//}\n\ninterface Match {\n\tfn: ServerFunction;\n\tparams?: Record<string, string>;\n}\n","// From https://stackoverflow.com/a/79345620\n// No idea why it is needed\nexport default function bufferToArrayBuffer(buffer: Buffer): ArrayBuffer {\n\treturn buffer.buffer.slice(\n\t\tbuffer.byteOffset,\n\t\tbuffer.byteOffset + buffer.byteLength,\n\t) as ArrayBuffer;\n}\n","import { IncomingHttpHeaders } from \"node:http\";\nimport { OutgoingHttpHeaders } from \"node:http2\";\n\nexport default function flattenHeaders(\n\theaders: IncomingHttpHeaders | OutgoingHttpHeaders,\n): HeadersInit {\n\tconst flatHeaders = new Headers();\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (value === undefined || value === null) {\n\t\t\tcontinue;\n\t\t} else if (Array.isArray(value)) {\n\t\t\tfor (const v of value) {\n\t\t\t\tif (v !== undefined && v !== null) {\n\t\t\t\t\tvalue.forEach((v) => flatHeaders.append(key, v));\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tflatHeaders.set(key, String(value));\n\t\t}\n\t}\n\treturn flatHeaders;\n\n\t/*\n const flatHeaders: [string, string][] = [];\n\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (value === undefined || value === null) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (const v of value) {\n\t\t\t\tif (v != null) {\n\t\t\t\t\tflatHeaders.push([key, String(v)]);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tflatHeaders.push([key, String(value)]);\n\t\t}\n\t}\n\n\treturn flatHeaders;\n */\n}\n","import {\n\ttype IncomingMessage,\n\ttype OutgoingHttpHeader,\n\ttype OutgoingHttpHeaders,\n\tServerResponse,\n} from \"node:http\";\nimport { PassThrough, Readable } from \"node:stream\";\n\n// From https://github.com/vikejs/vike-node/blob/main/packages/vike-node/src/runtime/adapters/createServerResponse.ts\n\n/**\n * Creates a custom ServerResponse object that allows for intercepting and\n * streaming the response.\n *\n * @param incomingMessage The incoming HTTP request message.\n * @returns An object containing the custom ServerResponse and a function that\n * takes a callback to invoke when the response is readable, providing an object\n * with the readable stream, headers and status code.\n */\nexport default function nodeMessageToNodeResponse(\n\tincomingMessage: IncomingMessage,\n): ServerResponseResponse {\n\tconst res = new ServerResponse(incomingMessage);\n\tconst passThrough = new PassThrough();\n\tlet handled = false;\n\n\tconst onReadable = (\n\t\tcb: (result: { readable: Readable; headers: OutgoingHttpHeaders; status: number }) => void,\n\t) => {\n\t\tconst handleReadable = () => {\n\t\t\tif (handled) return;\n\t\t\thandled = true;\n\t\t\tcb({\n\t\t\t\treadable: Readable.from(passThrough),\n\t\t\t\theaders: res.getHeaders(),\n\t\t\t\tstatus: res.statusCode,\n\t\t\t});\n\t\t};\n\n\t\tpassThrough.once(\"readable\", handleReadable);\n\t\tpassThrough.once(\"end\", handleReadable);\n\t};\n\n\tpassThrough.once(\"finish\", () => {\n\t\tres.emit(\"finish\");\n\t});\n\tpassThrough.once(\"close\", () => {\n\t\tres.destroy();\n\t\tres.emit(\"close\");\n\t});\n\tpassThrough.on(\"drain\", () => {\n\t\tres.emit(\"drain\");\n\t});\n\n\tres.write = passThrough.write.bind(passThrough);\n\tres.end = passThrough.end.bind(passThrough) as any;\n\n\tres.writeHead = function writeHead(\n\t\tstatusCode: number,\n\t\tstatusMessage?: string | OutgoingHttpHeaders | OutgoingHttpHeader[],\n\t\theaders?: OutgoingHttpHeaders | OutgoingHttpHeader[],\n\t): ServerResponse {\n\t\tres.statusCode = statusCode;\n\t\tif (typeof statusMessage === \"object\") {\n\t\t\theaders = statusMessage;\n\t\t\tstatusMessage = undefined;\n\t\t}\n\t\tif (headers) {\n\t\t\tfor (const [key, value] of Object.entries(headers)) {\n\t\t\t\tif (value !== undefined) {\n\t\t\t\t\tres.setHeader(key, value);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t};\n\n\treturn {\n\t\tres,\n\t\tonReadable,\n\t};\n}\n\ninterface ServerResponseResponse {\n\tres: ServerResponse;\n\tonReadable: (\n\t\tcb: (result: { readable: Readable; headers: OutgoingHttpHeaders; status: number }) => void,\n\t) => void;\n}\n","import { Readable } from \"node:stream\";\n\nexport default function readableToBuffer(req: Readable): Promise<Buffer> {\n\treturn new Promise<Buffer>((resolve, reject) => {\n\t\tconst chunks: Buffer[] = [];\n\t\treq.on(\"data\", (chunk: Buffer) => {\n\t\t\tchunks.push(chunk);\n\t\t});\n\t\treq.on(\"end\", () => {\n\t\t\tresolve(Buffer.concat(chunks));\n\t\t});\n\t\treq.on(\"error\", (err) => {\n\t\t\treject(err);\n\t\t});\n\t});\n}\n","import { type IncomingMessage } from \"node:http\";\nimport { Readable } from \"node:stream\";\n\n// From https://github.com/vikejs/vike-node/blob/main/packages/vike-node/src/runtime/adapters/connectToWeb.ts\n\nconst DUMMY_BASE_URL = \"http://localhost\";\n\n/**\n * Creates an IncomingMessage object from a web Request.\n *\n * @param {Request} request - The web Request object.\n * @returns {IncomingMessage} An IncomingMessage-like object compatible with Node.js HTTP module.\n */\nexport default function requestToNodeMessage(request: Request): IncomingMessage {\n\tconst parsedUrl = new URL(request.url, DUMMY_BASE_URL);\n\tconst pathAndQuery = (parsedUrl.pathname || \"\") + (parsedUrl.search || \"\");\n\t// HACK: Using Readable.fromWeb locks request.body so that the request cannot be used again\n\t// As we're only using this for Vite middlewares, it's safe to discard the body for now?\n\tconst body = /*request.body ? Readable.fromWeb(request.body as any) :*/ Readable.from([]);\n\n\treturn Object.assign(body, {\n\t\turl: pathAndQuery,\n\t\tmethod: request.method,\n\t\theaders: Object.fromEntries(request.headers),\n\t}) as IncomingMessage;\n}\n","import { IncomingMessage, ServerResponse } from \"node:http\";\nimport type MiddlewareFunction from \"../types/MiddlewareFunction\";\nimport bufferToArrayBuffer from \"./bufferToArrayBuffer\";\nimport flattenHeaders from \"./flattenHeaders\";\nimport nodeMessageToNodeResponse from \"./nodeMessageToNodeResponse\";\nimport readableToBuffer from \"./readableToBuffer\";\nimport requestToNodeMessage from \"./requestToNodeMessage\";\n\n// From https://github.com/vikejs/vike-node/blob/main/packages/vike-node/src/runtime/adapters/connectToWeb.ts\n\n/**\n * Converts a Connect-style middleware to a web-compatible request handler.\n *\n * @param handler - The Connect-style middleware function to be converted.\n * @returns A function that handles web requests and returns a Response or undefined.\n */\nexport default function connectMiddleware(\n\thandler: ConnectMiddleware | ConnectMiddlewareBoolean,\n): MiddlewareFunction {\n\treturn async (ev, next) => {\n\t\tconst req = requestToNodeMessage(ev.request);\n\t\tconst { res, onReadable } = nodeMessageToNodeResponse(req);\n\n\t\treturn new Promise<void>(async (resolve, reject) => {\n\t\t\tonReadable(async ({ readable, headers, status }) => {\n\t\t\t\tconst responseBody = statusCodesWithoutBody.includes(status)\n\t\t\t\t\t? null\n\t\t\t\t\t: //(Readable.toWeb(readable) as ReadableStream);\n\t\t\t\t\t\t// HACK: Chunked bodies are not being\n\t\t\t\t\t\t// read correctly somewhere...\n\t\t\t\t\t\tbufferToArrayBuffer(await readableToBuffer(readable));\n\t\t\t\tev.response = new Response(responseBody, {\n\t\t\t\t\tstatus,\n\t\t\t\t\theaders: flattenHeaders(headers),\n\t\t\t\t});\n\t\t\t\tresolve();\n\t\t\t});\n\n\t\t\tconst cnext = async (error?: unknown) => {\n\t\t\t\tif (error) {\n\t\t\t\t\t// eslint-disable-next-line no-base-to-string\n\t\t\t\t\treject(error instanceof Error ? error : new Error(String(error)));\n\t\t\t\t} else {\n\t\t\t\t\t// TODO: Can we nest the next functions less? This is a bit weird\n\t\t\t\t\tawait next();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\tconst handled = await handler(req, res, cnext);\n\t\t\t\tif (handled === false) {\n\t\t\t\t\tres.destroy();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tawait cnext(e);\n\t\t\t}\n\t\t});\n\t};\n}\n\nconst statusCodesWithoutBody = [\n\t100, // Continue\n\t101, // Switching Protocols\n\t102, // Processing (WebDAV)\n\t103, // Early Hints\n\t204, // No Content\n\t205, // Reset Content\n\t304, // Not Modified\n];\n\ntype NextFunction = (err?: unknown) => void;\ntype ConnectMiddleware<\n\tPlatformRequest extends IncomingMessage = IncomingMessage,\n\tPlatformResponse extends ServerResponse = ServerResponse,\n> = (req: PlatformRequest, res: PlatformResponse, next: NextFunction) => void | Promise<void>;\ntype ConnectMiddlewareBoolean<\n\tPlatformRequest extends IncomingMessage = IncomingMessage,\n\tPlatformResponse extends ServerResponse = ServerResponse,\n> = (req: PlatformRequest, res: PlatformResponse, next: NextFunction) => boolean | Promise<boolean>;\n"],"mappings":";;;;;;AAKA,MAAM,aAAa;;;;AAKnB,IAAqB,SAArB,MAA4B;CAE3B,SAAyB,EAAE;CAE3B,aAAmC,EAAE;CAErC,cAAc;AACb,OAAK,SAAS,EAAE;AAChB,OAAK,aAAa,EAAE;;;;;;;CAQrB,QAAQ,OAAO,OAA0B,SAA0C;EAClF,MAAM,UAAU,IAAI,QAAQ,OAAO,KAAK;EACxC,MAAM,MAAM,IAAI,IAAI,QAAQ,IAAI;EAChC,MAAM,QAAQ,KAAK,MAAM,IAA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AE,KAAK,eAAe,0BAA0B,IAAI;AAE1D,SAAO,IAAI,QAAc,OAAO,SAAS,WAAW;AACnD,cAAW,OAAO,EAAE,UAAU,SAAS,aAAa;IACnD,MAAM,eAAe,uBAAuB,SAAS,OAAO,GACzD,OAID,oBAAoB,MAAM,iBAAiB,SAAS,CAAC;AACvD,OAAG,WAAW,IAAI,SAAS,cAAc;KACxC;KACA,SAAS,eAAe,QAAQ;KAChC,CAAC;AACF,aAAS;KACR;GAEF,MAAM,QAAQ,OAAO,UAAoB;AACxC,QAAI,MAEH,QAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC,CAAC;SAC3D;AAEN,WAAM,MAAM;AACZ,cAAS;;;AAIX,OAAI;AAEH,QADgB,MAAM,QAAQ,KAAK,KAAK,MAAM,KAC9B,OAAO;AACtB,SAAI,SAAS;AACb,cAAS;;YAEF,GAAG;AACX,UAAM,MAAM,EAAE;;IAEd;;;AAIJ,MAAM,yBAAyB;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA"}
@@ -1,5 +1,5 @@
1
- import { a as CookieHelper, i as HeaderHelper } from "./Server-DL9neaq0.js";
2
- import { n as Adapter, t as Site } from "./Site-B8TxSzPk.js";
1
+ import { a as CookieHelper, i as HeaderHelper } from "./Server-CF5wDJp6.mjs";
2
+ import { n as Adapter, t as Site } from "./Site-DgC6WWn1.mjs";
3
3
  import { Component } from "@torpor/view";
4
4
 
5
5
  //#region src/types/ManifestRoute.d.ts
@@ -7,6 +7,7 @@ interface ManifestRoute {
7
7
  path: string;
8
8
  type: number;
9
9
  endPoint: () => Promise<any>;
10
+ subFolder: string | undefined;
10
11
  }
11
12
  //#endregion
12
13
  //#region src/types/RouteLayoutHandler.d.ts
@@ -17,10 +18,14 @@ interface RouteLayoutHandler {
17
18
  }
18
19
  //#endregion
19
20
  //#region src/types/RouteHandler.d.ts
21
+ /**
22
+ * A handler for a route in the Router.
23
+ */
20
24
  interface RouteHandler {
21
25
  path: string;
22
26
  type: number;
23
27
  endPoint: () => Promise<any>;
28
+ subFolder?: string;
24
29
  loaded?: boolean;
25
30
  layouts?: RouteLayoutHandler[];
26
31
  serverEndPoint?: () => Promise<any>;
@@ -36,8 +41,8 @@ declare class Router {
36
41
  routes: Route[];
37
42
  constructor();
38
43
  addPages(routes: ManifestRoute[]): this;
39
- addPage(path: string, type: number, endPoint: () => Promise<any>): this;
40
- match(path: string, query: URLSearchParams): Match | undefined;
44
+ addPage(path: string, type: number, endPoint: () => Promise<any>, subFolder?: string): this;
45
+ match(path: string, query: URLSearchParams): RouteMatch | undefined;
41
46
  }
42
47
  declare class Route {
43
48
  path: string;
@@ -45,7 +50,7 @@ declare class Route {
45
50
  handler: RouteHandler;
46
51
  constructor(path: string, handler: RouteHandler);
47
52
  }
48
- interface Match {
53
+ interface RouteMatch {
49
54
  handler: RouteHandler;
50
55
  params?: Record<string, string>;
51
56
  query: URLSearchParams;
@@ -205,4 +210,4 @@ interface ServerHook {
205
210
  }
206
211
  //#endregion
207
212
  export { type Adapter, type PageEndPoint, type PageLoadEvent, type PageServerAction, type PageServerEndPoint, type PageServerLoad, Router, type ServerEndPoint, type ServerHook, type ServerLoadEvent, type ServerRequest, Site };
208
- //# sourceMappingURL=index.d.ts.map
213
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/ManifestRoute.ts","../src/types/RouteLayoutHandler.ts","../src/types/RouteHandler.ts","../src/site/Router.ts","../src/types/PageLoadEvent.ts","../src/types/PageEndPoint.ts","../src/types/ServerLoadEvent.ts","../src/types/PageServerAction.ts","../src/types/PageServerLoad.ts","../src/types/PageServerEndPoint.ts","../src/types/ServerRequest.ts","../src/types/ServerEndPoint.ts","../src/types/ServerHook.ts"],"sourcesContent":[],"mappings":";;;;;UAAyB,aAAA;;;kBAGR;;;;;UCHQ,kBAAA;;kBAER;yBACO;;;;;;;UCEC,YAAA;MFLA,EAAA,MAAA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HmHP,EAAA,GAAA,CAAA;;;;KIpJL,gBAAA,WACG,oBACH,8BAA8B,QAAQ;;;KCFtC,cAAA,WACG,oBACH,8BAA8B,QAAQ;;;;;;ARJlB,USMA,kBAAA,CTHR;;;;MCHQ,CAAA,EQUjB,cRViB;;;;ECAW,OAKX,CAAA,EOSd,MPTc,CAAA,MAAA,EOSC,gBPTD,CAAA;;;;KQHpB,aAAA,WACG,oBACH,8BAA8B,QAAQ;;;;;;KCCtC,cAAA;MXLoB,EAAA,MAAA,CAAA,EWKc,aXLd;;;;;QWSlB;;;ATT6B;EAQnB,IAAA,CAAA,ESKT,aTLS;EAIN;;;EAES,KAAA,CAAA,ESGX,aTHW;;;;ECZU,GAMT,CAAA,EQad,aRbc;EACZ;;;EAgDmB,GAAA,CAAA,EQhCrB,aRgCqB;EAAkB;;AAAA;EA4FtC,OAAA,CAAA,EQxHG,aRwHH;EACE;;;EAE0B,IAO1B,CAAA,EQ9HF,aR8HE;CACA;;;;;;US3Je,UAAA;;;;mBAIP,oBAAoB"}
@@ -1,5 +1,5 @@
1
- import "./pathToRegex-BTPkBIYJ.js";
2
- import { a as LAYOUT_SERVER_ROUTE, c as SERVER_ROUTE, i as LAYOUT_ROUTE, l as Router, n as HOOK_ROUTE, o as PAGE_ROUTE, r as HOOK_SERVER_ROUTE, s as PAGE_SERVER_ROUTE, t as ERROR_ROUTE } from "./RouteType-VOBjKJ8I.js";
1
+ import "./pathToRegex-TUAMc3zS.mjs";
2
+ import { a as LAYOUT_SERVER_ROUTE, c as SERVER_ROUTE, i as LAYOUT_ROUTE, l as Router, n as HOOK_ROUTE, o as PAGE_ROUTE, r as HOOK_SERVER_ROUTE, s as PAGE_SERVER_ROUTE, t as ERROR_ROUTE } from "./RouteType-B6BMOyYw.mjs";
3
3
  import { promises } from "node:fs";
4
4
  import path from "node:path";
5
5
  import tsconfigPaths from "vite-tsconfig-paths";
@@ -40,18 +40,25 @@ var Site = class {
40
40
  /**
41
41
  * Adds a folder of routes, based on the names of the files in the folder
42
42
  * @param folder The folder containing the routes
43
+ * @param subFolder If a subFolder is set, all routes in the folder will be
44
+ * placed under the subFolder, and only hooks, layouts etc will be used if
45
+ * they have the same subFolder. This can be used to create e.g. an `api`
46
+ * set of routes with their own hook for authorization from various clients
43
47
  */
44
- async addRouteFolder(folder) {
48
+ async addRouteFolder(folder, subFolder) {
45
49
  const routeFolder = path.join(this.root, folder);
46
50
  const routeFiles = await promises.readdir(routeFolder, { recursive: true });
51
+ if (subFolder !== void 0 && !subFolder.startsWith("/")) subFolder = "/" + subFolder;
47
52
  for (let file of routeFiles) if (/^(\+|_).+(\.js|\.ts)$/.test(path.basename(file))) {
48
53
  let routePath = this.#routePath(file);
54
+ if (subFolder !== void 0) routePath = subFolder + routePath;
49
55
  let type = this.#routeType(file);
50
56
  file = path.relative(this.root, path.resolve(routeFolder, file));
51
57
  this.routes.push({
52
58
  path: routePath,
53
59
  file,
54
- type
60
+ type,
61
+ subFolder
55
62
  });
56
63
  }
57
64
  this.#sortRoutes();
@@ -63,13 +70,15 @@ var Site = class {
63
70
  * @param file The file
64
71
  * @param type The file type (if the file name is non-standard)
65
72
  */
66
- addRouteFile(path$1, file, type) {
73
+ addRouteFile(path$1, file, type, subFolder) {
67
74
  let routePath = this.#routePath(path.join(path$1, type ?? path.basename(file)));
68
75
  let routeType = type ? this.#routeTypeFromString(type) : this.#routeType(file);
76
+ if (subFolder !== void 0 && !subFolder.startsWith("/")) subFolder = "/" + subFolder;
69
77
  this.routes.push({
70
78
  path: routePath,
71
79
  file,
72
- type: routeType
80
+ type: routeType,
81
+ subFolder
73
82
  });
74
83
  this.#sortRoutes();
75
84
  }
@@ -113,4 +122,4 @@ var Site = class {
113
122
 
114
123
  //#endregion
115
124
  export { Router, Site };
116
- //# sourceMappingURL=index.js.map
125
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["defaultAdapter: Adapter","defaultAdapter","fpath","fs","#routePath","#routeType","#sortRoutes","path","#routeTypeFromString"],"sources":["../src/site/defaultAdapter.ts","../src/site/Site.ts"],"sourcesContent":["import type Adapter from \"../types/Adapter\";\n\n// TODO: This should be an adapter-auto package that conditionally loads other packages...\n\nconst defaultAdapter: Adapter = {\n\tserve: () => {\n\t\tconsole.log(\"An adapter needs to be set in site.config\");\n\t},\n};\n\nexport default defaultAdapter;\n","import { promises as fs } from \"node:fs\";\nimport fpath from \"node:path\";\nimport { type Plugin, type UserConfig } from \"vite\";\nimport tsconfigPaths from \"vite-tsconfig-paths\";\nimport type Adapter from \"../types/Adapter\";\nimport type Route from \"../types/Route\";\nimport {\n\tERROR_ROUTE,\n\tHOOK_ROUTE,\n\tHOOK_SERVER_ROUTE,\n\tLAYOUT_ROUTE,\n\tLAYOUT_SERVER_ROUTE,\n\tPAGE_ROUTE,\n\tPAGE_SERVER_ROUTE,\n\tRouteType,\n\tSERVER_ROUTE,\n} from \"../types/RouteType\";\nimport defaultAdapter from \"./defaultAdapter\";\n\n// 1. The user sets this up\n// 2. It is passed into serverEntry and clientEntry through a Vite plugin\n// (defined in manifest.ts)\n// 3. In those files, it is used to build a Router\n\n/**\n * The Site class contains the information necessary to setup a @torpor/build\n * site, including routes, plugins, and options.\n */\nexport default class Site {\n\troot: string;\n\troutes: Route[] = [];\n\t// Is default plugins a bad idea?\n\t// HACK: Set loose because otherwise it uses a list of allowed extensions\n\t// TODO: Should probably just do this ourselves and let the user pass in\n\t// tsconfigPaths themselves if they want to do something funky\n\tplugins: Plugin[] = [tsconfigPaths({ loose: true })];\n\t// Is default adapter a bad idea?\n\tadapter: Adapter = defaultAdapter;\n\t/**\n\t * Extra inputs, as absolute file paths, that will be compiled with the\n\t * output. What you do with them after that is up to you. File paths ending\n\t * with server.ts/js will only be compiled with the server output\n\t */\n\tinputs: string[] = [];\n\t/**\n\t * Vite config options to merge with the standard Torpor build options.\n\t * `plugins` and `build.rollupOptions.input` will be overridden, so you\n\t * should set `Site.plugins` and `Site.inputs` instead. Other options may be\n\t * overridden or incompatible, so experimentation may be required\n\t */\n\tviteConfig?: UserConfig;\n\n\tconstructor() {\n\t\tthis.root = process.cwd();\n\t}\n\n\t/**\n\t * Adds a folder of routes, based on the names of the files in the folder\n\t * @param folder The folder containing the routes\n\t * @param subFolder If a subFolder is set, all routes in the folder will be\n\t * placed under the subFolder, and only hooks, layouts etc will be used if\n\t * they have the same subFolder. This can be used to create e.g. an `api`\n\t * set of routes with their own hook for authorization from various clients\n\t */\n\tasync addRouteFolder(folder: string, subFolder?: string): Promise<void> {\n\t\tconst routeFolder = fpath.join(this.root, folder);\n\t\tconst routeFiles = await fs.readdir(routeFolder, { recursive: true });\n\t\tif (subFolder !== undefined && !subFolder.startsWith(\"/\")) {\n\t\t\tsubFolder = \"/\" + subFolder;\n\t\t}\n\t\tfor (let file of routeFiles) {\n\t\t\t// The file must start with `+` or `_` and end with `.js` or `.ts`\n\t\t\tif (/^(\\+|_).+(\\.js|\\.ts)$/.test(fpath.basename(file))) {\n\t\t\t\tlet routePath = this.#routePath(file);\n\t\t\t\tif (subFolder !== undefined) {\n\t\t\t\t\troutePath = subFolder + routePath;\n\t\t\t\t}\n\t\t\t\tlet type = this.#routeType(file);\n\t\t\t\tfile = fpath.relative(this.root, fpath.resolve(routeFolder, file));\n\t\t\t\tthis.routes.push({\n\t\t\t\t\tpath: routePath,\n\t\t\t\t\tfile,\n\t\t\t\t\ttype,\n\t\t\t\t\tsubFolder: subFolder,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tthis.#sortRoutes();\n\t}\n\n\t/**\n\t * Adds a file route, which can have a standard name (e.g. +page.ts) or any\n\t * name if you pass the type\n\t * @param path The route path\n\t * @param file The file\n\t * @param type The file type (if the file name is non-standard)\n\t */\n\taddRouteFile(\n\t\tpath: string,\n\t\tfile: string,\n\t\ttype?:\n\t\t\t| \"+page\"\n\t\t\t| \"+page.server\"\n\t\t\t| \"+server\"\n\t\t\t| \"_layout\"\n\t\t\t| \"_layout.server\"\n\t\t\t| \"_hook\"\n\t\t\t| \"_hook.server\"\n\t\t\t| \"_error\",\n\t\tsubFolder?: string,\n\t): void {\n\t\tlet routePath = this.#routePath(fpath.join(path, type ?? fpath.basename(file)));\n\t\tlet routeType = type ? this.#routeTypeFromString(type) : this.#routeType(file);\n\t\tif (subFolder !== undefined && !subFolder.startsWith(\"/\")) {\n\t\t\tsubFolder = \"/\" + subFolder;\n\t\t}\n\t\tthis.routes.push({\n\t\t\tpath: routePath,\n\t\t\tfile,\n\t\t\ttype: routeType,\n\t\t\tsubFolder: subFolder,\n\t\t});\n\t\tthis.#sortRoutes();\n\t}\n\n\t#routePath(file: string): string {\n\t\tlet routePath = file\n\t\t\t.replace(/^\\//, \"\")\n\t\t\t.replace(/(\\.ts|\\.js)$/, \"\")\n\t\t\t.replace(/_hook.server$/, \"_hook/~server\")\n\t\t\t.replace(/_layout.server$/, \"_layout/~server\")\n\t\t\t.replace(/\\+page.server$/, \"~server\")\n\t\t\t.replace(/\\+server$/, \"\")\n\t\t\t.replace(/\\+page$/, \"\")\n\t\t\t.replace(/\\/$/, \"\");\n\t\treturn routePath.length > 0 ? `/${routePath}` : \"/\";\n\t}\n\n\t#routeType(file: string): RouteType {\n\t\tlet routePath = file.replace(/^\\//, \"\").replace(/(\\.ts|\\.js)$/, \"\");\n\t\tif (routePath.endsWith(\"+page\")) {\n\t\t\treturn PAGE_ROUTE;\n\t\t} else if (routePath.endsWith(\"+page.server\")) {\n\t\t\treturn PAGE_SERVER_ROUTE;\n\t\t} else if (routePath.endsWith(\"+server\")) {\n\t\t\treturn SERVER_ROUTE;\n\t\t} else if (routePath.endsWith(\"_layout\")) {\n\t\t\treturn LAYOUT_ROUTE;\n\t\t} else if (routePath.endsWith(\"_layout.server\")) {\n\t\t\treturn LAYOUT_SERVER_ROUTE;\n\t\t} else if (routePath.endsWith(\"_hook\")) {\n\t\t\treturn HOOK_ROUTE;\n\t\t} else if (routePath.endsWith(\"_hook.server\")) {\n\t\t\treturn HOOK_SERVER_ROUTE;\n\t\t} else if (routePath.endsWith(\"_error\")) {\n\t\t\treturn ERROR_ROUTE;\n\t\t}\n\t\treturn -1;\n\t}\n\n\t#routeTypeFromString(\n\t\ttype:\n\t\t\t| \"+page\"\n\t\t\t| \"+page.server\"\n\t\t\t| \"+server\"\n\t\t\t| \"_layout\"\n\t\t\t| \"_layout.server\"\n\t\t\t| \"_hook\"\n\t\t\t| \"_hook.server\"\n\t\t\t| \"_error\",\n\t) {\n\t\tswitch (type) {\n\t\t\tcase \"+page\":\n\t\t\t\treturn PAGE_ROUTE;\n\t\t\tcase \"+page.server\":\n\t\t\t\treturn PAGE_SERVER_ROUTE;\n\t\t\tcase \"+server\":\n\t\t\t\treturn SERVER_ROUTE;\n\t\t\tcase \"_layout\":\n\t\t\t\treturn LAYOUT_ROUTE;\n\t\t\tcase \"_layout.server\":\n\t\t\t\treturn LAYOUT_SERVER_ROUTE;\n\t\t\tcase \"_hook\":\n\t\t\t\treturn HOOK_ROUTE;\n\t\t\tcase \"_hook.server\":\n\t\t\t\treturn HOOK_SERVER_ROUTE;\n\t\t\tcase \"_error\":\n\t\t\t\treturn ERROR_ROUTE;\n\t\t}\n\t}\n\n\t// TODO: You could make your site in a single file, like e.g. Hono...\n\t//addPage(path: string, endPoint: PageEndPoint, serverEndPoint?: PageServerEndPoint) {}\n\t//addEndPoint(path: string, endPoint: ServerEndPoint) {}\n\n\t#sortRoutes() {\n\t\tthis.routes = this.routes.sort((a, b) => {\n\t\t\t// Sort [param]s after paths\n\t\t\t// There might be a quicker/easier way to do this\n\t\t\tfor (let i = 0; i < Math.min(a.path.length, b.path.length); i++) {\n\t\t\t\tif (a.path[i] === \"[\" && b.path[i] !== \"[\") {\n\t\t\t\t\treturn 1;\n\t\t\t\t} else if (b.path[i] === \"[\" && a.path[i] !== \"[\") {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else if (a.path[i] === b.path[i]) {\n\t\t\t\t\t// Keep going...\n\t\t\t\t} else {\n\t\t\t\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KAAK,OAAO,IACtC,QAAO;YACG,EAAE,KAAK,OAAO,OAAO,EAAE,KAAK,OAAO,IAC7C,QAAO;YACG,EAAE,KAAK,OAAO,EAAE,KAAK,IAAI,OAGnC,QAAO,EAAE,KAAK,GAAG,cAAc,EAAE,KAAK,GAAG;AAG3C,UAAO,EAAE,KAAK,SAAS,EAAE,KAAK;IAC7B"}
@@ -11,4 +11,4 @@ declare function load(path: string): Promise<boolean>;
11
11
  declare function reload(): Promise<boolean>;
12
12
  //#endregion
13
13
  export { load, reload };
14
- //# sourceMappingURL=nav.d.ts.map
14
+ //# sourceMappingURL=nav.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nav.d.mts","names":[],"sources":["../src/nav/load.ts","../src/nav/reload.ts"],"sourcesContent":[],"mappings":";;;;iBAK8B,IAAA,gBAAoB;;;;;;iBCApB,MAAA,CAAA,GAAU"}
@@ -1,4 +1,4 @@
1
- import { t as $page_default } from "./_page-ef72MjgG.js";
1
+ import { t as $page_default } from "./_page-DBSsnHFG.mjs";
2
2
  import { clearLayoutSlot, fillLayoutSlot, hydrate, mount } from "@torpor/view";
3
3
 
4
4
  //#region src/state/client.ts
@@ -46,7 +46,7 @@ async function formSubmit(e) {
46
46
 
47
47
  //#endregion
48
48
  //#region src/nav/loadData.ts
49
- async function loadData(handler, params, path, newLayoutStack, clientEndPoint, serverEndPoint, prefetch = false) {
49
+ async function loadData(handler, params, path, query, newLayoutStack, clientEndPoint, serverEndPoint, prefetch = false) {
50
50
  let data = {};
51
51
  if (handler.layouts) {
52
52
  let layoutStack = client_default.layoutStack;
@@ -66,20 +66,22 @@ async function loadData(handler, params, path, newLayoutStack, clientEndPoint, s
66
66
  };
67
67
  const layoutEndPoint = (await layout.endPoint())?.default;
68
68
  const layoutServerEndPoint = layout.serverEndPoint && (await layout.serverEndPoint())?.default;
69
- if ((await loadClientAndServerData(stackLayout.data, document.location.origin + layoutPath, params, layoutEndPoint, layoutServerEndPoint))?.ok === false) return;
69
+ if ((await loadClientAndServerData(stackLayout.data, document.location.origin + layoutPath, query, params, layoutEndPoint, layoutServerEndPoint))?.ok === false) return;
70
70
  Object.assign(data, stackLayout.data);
71
71
  newLayoutStack.push(stackLayout);
72
72
  }
73
73
  }
74
74
  }
75
- if ((await loadClientAndServerData(data, document.location.origin + path, params, clientEndPoint, serverEndPoint))?.ok === false) return;
75
+ if ((await loadClientAndServerData(data, document.location.origin + path, query, params, clientEndPoint, serverEndPoint))?.ok === false) return;
76
76
  return data;
77
77
  }
78
- async function loadClientAndServerData(data, location, params, clientEndPoint, serverEndPoint) {
78
+ async function loadClientAndServerData(data, location, query, params, clientEndPoint, serverEndPoint) {
79
79
  let prefetchedData = client_default.prefetchedData;
80
80
  if (clientEndPoint?.load) if (prefetchedData[location]) Object.assign(data, prefetchedData[location]);
81
81
  else {
82
- const clientParams = buildClientParams(new URL(document.location.href), params, data);
82
+ const clientUrl = new URL(document.location.href);
83
+ for (let [name, value] of query) clientUrl.searchParams.append(name, value);
84
+ const clientParams = buildClientParams(clientUrl, params, data);
83
85
  const clientResponse = await clientEndPoint.load(clientParams);
84
86
  if (clientResponse) if (clientResponse.ok) {
85
87
  if (clientResponse.headers.get("Content-Type")?.includes("application/json")) {
@@ -90,15 +92,17 @@ async function loadClientAndServerData(data, location, params, clientEndPoint, s
90
92
  } else return clientResponse;
91
93
  }
92
94
  if (serverEndPoint?.load) {
93
- const serverUrl = location.replace(/\/$/, "") + "/~server";
94
- if (prefetchedData[serverUrl]) Object.assign(data, prefetchedData[serverUrl]);
95
+ const serverLocation = location.replace(/\/$/, "") + "/~server";
96
+ if (prefetchedData[serverLocation]) Object.assign(data, prefetchedData[serverLocation]);
95
97
  else {
98
+ const serverUrl = new URL(serverLocation);
99
+ for (let [name, value] of query) serverUrl.searchParams.append(name, value);
96
100
  const serverResponse = await fetch(serverUrl);
97
101
  if (serverResponse) if (serverResponse.ok) {
98
102
  if (serverResponse.headers.get("Content-Type")?.includes("application/json")) {
99
103
  const serverData = await serverResponse.json();
100
104
  Object.assign(data, serverData);
101
- prefetchedData[serverUrl] = serverData;
105
+ prefetchedData[serverLocation] = serverData;
102
106
  }
103
107
  } else return serverResponse;
104
108
  }
@@ -142,7 +146,7 @@ async function navigate(url, withHydration = false) {
142
146
  }
143
147
  const serverEndPoint = handler.serverEndPoint && (await handler.serverEndPoint())?.default;
144
148
  let newLayoutStack = [];
145
- const data = await loadData(handler, params, path, newLayoutStack, clientEndPoint, serverEndPoint);
149
+ const data = await loadData(handler, params, path, query, newLayoutStack, clientEndPoint, serverEndPoint);
146
150
  let formInput = document.getElementById("t-form-data");
147
151
  let form;
148
152
  if (formInput) {
@@ -206,4 +210,4 @@ async function load(path) {
206
210
 
207
211
  //#endregion
208
212
  export { load, reload };
209
- //# sourceMappingURL=nav.js.map
213
+ //# sourceMappingURL=nav.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nav.mjs","names":["CLIENT_SYMBOL: unique symbol","client: ClientState","client","layoutEndPoint: PageEndPoint | undefined","layoutServerEndPoint: PageServerEndPoint | undefined","client","clientEndPoint: PageEndPoint | undefined","serverEndPoint: PageServerEndPoint | undefined","newLayoutStack: LayoutPath[]","form: Record<string, string> | undefined","$props: Record<string, any>","$page","slots: Record<string, SlotRender> | undefined","slotFunctions: SlotRender[]","parent","layoutEndPoint: PageEndPoint | undefined","$context"],"sources":["../src/state/client.ts","../src/nav/reload.ts","../src/nav/formSubmit.ts","../src/nav/loadData.ts","../src/nav/navigate.ts","../src/nav/load.ts"],"sourcesContent":["import type ClientState from \"../types/ClientState\";\n\nconst CLIENT_SYMBOL: unique symbol = Symbol.for(\"t_client_state\");\n\nconst client: ClientState =\n\t// @ts-ignore\n\t(globalThis[CLIENT_SYMBOL] ??= {\n\t\t// @ts-ignore This will definitely, 100% get set\n\t\trouter: null,\n\t\tlayoutStack: [],\n\t\t// TODO: Probably expire after 30 seconds or something?\n\t\tprefetchedData: {},\n\t});\n\nexport default client;\n","import navigate from \"./navigate\";\n\n/**\n * Reloads data for the currently loaded page and rerenders it.\n */\nexport default async function reload(): Promise<boolean> {\n\tconst url = new URL(document.location.href);\n\treturn await navigate(url);\n}\n","import $page from \"../state/$page\";\nimport load from \"./load\";\nimport reload from \"./reload\";\n\nexport default async function formSubmit(e: SubmitEvent): Promise<void> {\n\t// We'll take it from here\n\te.preventDefault();\n\n\t// Reset $page on submit and link navigation\n\t// TODO: Should we put data in $page.data??\n\t$page.form = undefined;\n\n\t// Perform a POST fetch to the form's action location\n\tconst form = e.target as HTMLFormElement;\n\tconst action = (e.submitter as HTMLButtonElement)?.formAction ?? form.action;\n\tconst options = {\n\t\tbody: new FormData(form),\n\t\tmethod: \"POST\",\n\t\tmode: \"cors\",\n\t\tcredentials: \"same-origin\",\n\t\t// Add a special header which tells the server that we want the raw\n\t\t// error response (if applicable) rather than the reloaded page that you\n\t\t// would get if submitting a page without javascript\n\t\theaders: {\n\t\t\t\"x-torpor-form-submit\": \"\",\n\t\t},\n\t};\n\tconst response = await fetch(\n\t\taction,\n\t\t// @ts-ignore -- don't know what it's complaining about here\n\t\toptions,\n\t);\n\n\tif (response.status === 200 && response.headers.has(\"x-torpor-form-redirect\")) {\n\t\t// TODO: Should do the correct type of redirect e.g. seeOther etc\n\t\tconst redirect = response.headers.get(\"location\")!;\n\t\tawait load(redirect);\n\t\twindow.location.href = redirect;\n\t} else if (\n\t\t(response.status >= 200 && response.status <= 299) ||\n\t\t(response.status >= 400 && response.status <= 499)\n\t) {\n\t\t// Put the response into `$page.form`, and it will be put into `$props` in reload\n\t\tif (response.headers.get(\"content-type\") === \"application/json\") {\n\t\t\t$page.form = await response.json();\n\t\t}\n\t\tawait reload();\n\t}\n}\n","import client from \"../state/client\";\nimport type LayoutPath from \"../types/LayoutPath\";\nimport type PageEndPoint from \"../types/PageEndPoint\";\nimport type PageServerEndPoint from \"../types/PageServerEndPoint\";\nimport type RouteHandler from \"../types/RouteHandler\";\n\nexport default async function loadData(\n\thandler: RouteHandler,\n\tparams: Record<string, string>,\n\tpath: string,\n\tquery: URLSearchParams,\n\tnewLayoutStack: LayoutPath[],\n\tclientEndPoint: PageEndPoint | undefined,\n\tserverEndPoint: PageServerEndPoint | undefined,\n\tprefetch = false,\n): Promise<Record<string, string> | void> {\n\tlet data = {};\n\tif (handler.layouts) {\n\t\tlet layoutStack = client.layoutStack;\n\t\tfor (let [i, layout] of handler.layouts.entries()) {\n\t\t\tlet layoutPath = layout.path;\n\t\t\tfor (let key in params) {\n\t\t\t\tlayoutPath = layoutPath.replace(`[${key}]`, params[key]);\n\t\t\t}\n\t\t\tif (layoutStack.at(i)?.path === layoutPath) {\n\t\t\t\t// We've already loaded this layout, we can just re-use its data and UI\n\t\t\t\tif (!prefetch) {\n\t\t\t\t\tlayoutStack[i].reuse = true;\n\t\t\t\t}\n\t\t\t\tnewLayoutStack[i] = layoutStack[i];\n\t\t\t\tObject.assign(data, layoutStack[i].data);\n\t\t\t} else {\n\t\t\t\tconst stackLayout = { path: layoutPath, data: {}, reuse: false, slotRegion: null };\n\t\t\t\tconst layoutEndPoint: PageEndPoint | undefined = (await layout.endPoint())?.default;\n\t\t\t\tconst layoutServerEndPoint: PageServerEndPoint | undefined =\n\t\t\t\t\tlayout.serverEndPoint && (await layout.serverEndPoint())?.default;\n\t\t\t\tconst layoutResponse = await loadClientAndServerData(\n\t\t\t\t\tstackLayout.data,\n\t\t\t\t\tdocument.location.origin + layoutPath,\n\t\t\t\t\tquery,\n\t\t\t\t\tparams,\n\t\t\t\t\tlayoutEndPoint,\n\t\t\t\t\tlayoutServerEndPoint,\n\t\t\t\t);\n\t\t\t\tif (layoutResponse?.ok === false) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tObject.assign(data, stackLayout.data);\n\t\t\t\tnewLayoutStack.push(stackLayout);\n\t\t\t}\n\t\t}\n\t}\n\tlet endPointResponse = await loadClientAndServerData(\n\t\tdata,\n\t\tdocument.location.origin + path,\n\t\tquery,\n\t\tparams,\n\t\tclientEndPoint,\n\t\tserverEndPoint,\n\t);\n\tif (endPointResponse?.ok === false) {\n\t\treturn;\n\t}\n\treturn data;\n}\n\nasync function loadClientAndServerData(\n\tdata: Record<string, any>,\n\tlocation: string,\n\tquery: URLSearchParams,\n\tparams: Record<string, string>,\n\tclientEndPoint?: PageEndPoint,\n\tserverEndPoint?: PageServerEndPoint,\n): Promise<Response | undefined | void> {\n\tlet prefetchedData = client.prefetchedData;\n\n\tif (clientEndPoint?.load) {\n\t\tif (prefetchedData[location]) {\n\t\t\tObject.assign(data, prefetchedData[location]);\n\t\t} else {\n\t\t\tconst clientUrl = new URL(document.location.href);\n\t\t\tfor (let [name, value] of query) {\n\t\t\t\tclientUrl.searchParams.append(name, value);\n\t\t\t}\n\t\t\tconst clientParams = buildClientParams(clientUrl, params, data);\n\t\t\tconst clientResponse = await clientEndPoint.load(clientParams);\n\t\t\tif (clientResponse) {\n\t\t\t\tif (clientResponse.ok) {\n\t\t\t\t\tif (clientResponse.headers.get(\"Content-Type\")?.includes(\"application/json\")) {\n\t\t\t\t\t\tconst clientData = await clientResponse.json();\n\t\t\t\t\t\tObject.assign(data, clientData);\n\t\t\t\t\t\tprefetchedData[location] = clientData;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn clientResponse;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (serverEndPoint?.load) {\n\t\tconst serverLocation = location.replace(/\\/$/, \"\") + \"/~server\";\n\t\tif (prefetchedData[serverLocation]) {\n\t\t\tObject.assign(data, prefetchedData[serverLocation]);\n\t\t} else {\n\t\t\tconst serverUrl = new URL(serverLocation);\n\t\t\tfor (let [name, value] of query) {\n\t\t\t\tserverUrl.searchParams.append(name, value);\n\t\t\t}\n\t\t\tconst serverResponse = await fetch(serverUrl);\n\t\t\tif (serverResponse) {\n\t\t\t\tif (serverResponse.ok) {\n\t\t\t\t\tif (serverResponse.headers.get(\"Content-Type\")?.includes(\"application/json\")) {\n\t\t\t\t\t\tconst serverData = await serverResponse.json();\n\t\t\t\t\t\tObject.assign(data, serverData);\n\t\t\t\t\t\tprefetchedData[serverLocation] = serverData;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn serverResponse;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction buildClientParams(url: URL, params: Record<string, string>, data: Record<string, any>) {\n\treturn {\n\t\turl,\n\t\tparams,\n\t\tdata,\n\t};\n}\n","import { clearLayoutSlot, fillLayoutSlot, hydrate } from \"@torpor/view\";\nimport { type Component, type SlotRender } from \"@torpor/view\";\nimport { mount } from \"@torpor/view\";\nimport $page from \"../state/$page\";\nimport client from \"../state/client\";\nimport type LayoutPath from \"../types/LayoutPath\";\nimport type PageEndPoint from \"../types/PageEndPoint\";\nimport type PageServerEndPoint from \"../types/PageServerEndPoint\";\nimport formSubmit from \"./formSubmit\";\nimport loadData from \"./loadData\";\n\n// @ts-ignore\nexport default async function navigate(url: URL, withHydration = false): Promise<boolean> {\n\tlet parent = document.getElementById(\"app\");\n\tif (!parent) {\n\t\t// TODO: 500\n\t\tconsole.log(\"500\");\n\t\treturn false;\n\t}\n\n\tconst path = url.pathname;\n\tconst query = url.searchParams;\n\n\t//console.log(`navigating to '${path}'${query.size ? ` with ${query}` : \"\"}`);\n\n\tconst route = client.router.match(path, query);\n\tif (!route) {\n\t\t// TODO: 404\n\t\tconsole.log(\"404\");\n\t\treturn false;\n\t}\n\n\t// Update $page before building the components\n\t$page.url = url;\n\tif (path.endsWith(\"/_error\")) {\n\t\t$page.status = parseInt(query.get(\"status\") ?? \"404\");\n\t\t$page.error = { message: query.get(\"message\") ?? \"\" };\n\t\t// Make it look a bit classier by removing the query\n\t\twindow.history.replaceState({}, \"\", url.toString().split(\"?\")[0]);\n\t} else {\n\t\t$page.status = 200;\n\t}\n\tconst handler = route.handler;\n\tconst params = route.params || {};\n\n\t// There must be a client endpoint with a component\n\tconst clientEndPoint: PageEndPoint | undefined = (await handler.endPoint()).default;\n\tif (!clientEndPoint?.component) {\n\t\t// TODO: 404\n\t\tconsole.log(\"404\");\n\t\treturn false;\n\t}\n\n\t// There may be a server endpoint\n\tconst serverEndPoint: PageServerEndPoint | undefined =\n\t\thandler.serverEndPoint && (await handler.serverEndPoint())?.default;\n\n\tlet newLayoutStack: LayoutPath[] = [];\n\n\t// Pass the data into $props\n\t// TODO: Don't load if this is the first time -- it should have been passed\n\t// to us, somehow...\n\tconst data = await loadData(\n\t\thandler,\n\t\tparams,\n\t\tpath,\n\t\tquery,\n\t\tnewLayoutStack,\n\t\tclientEndPoint,\n\t\tserverEndPoint,\n\t);\n\t// We may have form data in a hidden input -- not sure if this is the best\n\t// way to do it\n\tlet formInput = document.getElementById(\"t-form-data\") as HTMLInputElement;\n\tlet form: Record<string, string> | undefined;\n\tif (formInput) {\n\t\tform = JSON.parse(formInput.value);\n\t\t$page.form = form;\n\t\tformInput.remove();\n\t}\n\tlet $props: Record<string, any> = { data };\n\n\t// We may have form data in $page.form, either from the hidden input\n\t// (above), or added via onformsubmit (below)\n\t$props.form = $page.form;\n\n\t// Add some special context for submitting Forms client-side\n\tconst $context = {\n\t\tTorporBuildContext: { onformsubmit: formSubmit },\n\t};\n\n\tclient.layoutStack.push({ path: route.handler.path, data: {}, reuse: false, slotRegion: null });\n\tclient.layoutStack = newLayoutStack;\n\tlet layoutStack = client.layoutStack;\n\n\t// If there are layouts, work our way upwards, pushing each component into\n\t// the default slot of its parent\n\t// TODO: There's probably a nicer way to do this with reducers or something\n\tlet component = clientEndPoint.component as Component;\n\tlet slots: Record<string, SlotRender> | undefined = undefined;\n\tif (handler.layouts) {\n\t\tlet slotFunctions: SlotRender[] = [];\n\t\t// The last slot function will render the client component\n\t\tslotFunctions[handler.layouts.length] = function clientComponent(parent, anchor) {\n\t\t\tlet i = layoutStack.length - 1;\n\t\t\tlayoutStack[i].slotRegion = fillLayoutSlot(\n\t\t\t\tclientEndPoint.component!,\n\t\t\t\tslotFunctions[i + 1],\n\t\t\t\tparent,\n\t\t\t\tanchor,\n\t\t\t\t$props,\n\t\t\t\t$context,\n\t\t\t);\n\t\t};\n\n\t\t// Each earlier slot function will render a layout\n\t\tfor (let i = handler.layouts.length - 1; i >= 0; i--) {\n\t\t\tconst layoutEndPoint: PageEndPoint | undefined = (await handler.layouts[i].endPoint())\n\t\t\t\t?.default;\n\t\t\tif (layoutEndPoint?.component) {\n\t\t\t\tif (layoutStack[i].reuse) {\n\t\t\t\t\t// Set the parent to add the new content to (from the old\n\t\t\t\t\t// content), clear the range under this point, and set the\n\t\t\t\t\t// component to the slot function within this layout\n\t\t\t\t\tparent = layoutStack[i].slotRegion.startNode.parentNode as HTMLElement;\n\t\t\t\t\tclearLayoutSlot(layoutStack[i].slotRegion);\n\t\t\t\t\tcomponent = slotFunctions[i + 1];\n\t\t\t\t\tbreak;\n\t\t\t\t} else if (i === 0) {\n\t\t\t\t\tcomponent = layoutEndPoint.component as Component;\n\t\t\t\t\tslots = { _: slotFunctions[i + 1] };\n\t\t\t\t} else {\n\t\t\t\t\tslotFunctions[i] = function layoutComponent(parent, anchor, _, $context) {\n\t\t\t\t\t\tlayoutStack[i - 1].slotRegion = fillLayoutSlot(\n\t\t\t\t\t\t\tlayoutEndPoint.component!,\n\t\t\t\t\t\t\tslotFunctions[i + 1],\n\t\t\t\t\t\t\tparent,\n\t\t\t\t\t\t\tanchor,\n\t\t\t\t\t\t\t$props,\n\t\t\t\t\t\t\t$context,\n\t\t\t\t\t\t);\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (withHydration) {\n\t\thydrate(parent, component, $props, slots);\n\t} else {\n\t\ttry {\n\t\t\tmount(parent, component, $props, slots);\n\t\t} catch (error) {\n\t\t\t// TODO: Show a proper Error component\n\t\t\tparent.innerHTML = '<span style=\"color: red\">Script syntax error</span><p>' + error + \"</p>\";\n\t\t\tconsole.log(error);\n\t\t}\n\t}\n\n\t// Reset prefetched data on each navigation\n\tclient.prefetchedData = {};\n\n\treturn true;\n}\n","import navigate from \"./navigate\";\n\n/**\n * Loads and renders the page at the supplied path.\n */\nexport default async function load(path: string): Promise<boolean> {\n\tconst url = new URL(path, document.location.href);\n\treturn await navigate(url);\n}\n"],"mappings":";;;;AAEA,MAAMA,gBAA+B,OAAO,IAAI,iBAAiB;AAEjE,MAAMC,SAEJ,WAAW,mBAAmB;CAE9B,QAAQ;CACR,aAAa,EAAE;CAEf,gBAAgB,EAAE;CAClB;AAEF,qBAAe;;;;;;;ACTf,eAA8B,SAA2B;AAExD,QAAO,MAAM,SADD,IAAI,IAAI,SAAS,SAAS,KAAK,CACjB;;;;;ACH3B,eAA8B,WAAW,GAA+B;AAEvE,GAAE,gBAAgB;AAIlB,eAAM,OAAO;CAGb,MAAM,OAAO,EAAE;CACf,MAAM,SAAU,EAAE,WAAiC,cAAc,KAAK;CACtE,MAAM,UAAU;EACf,MAAM,IAAI,SAAS,KAAK;EACxB,QAAQ;EACR,MAAM;EACN,aAAa;EAIb,SAAS,EACR,wBAAwB,IACxB;EACD;CACD,MAAM,WAAW,MAAM,MACtB,QAEA,QACA;AAED,KAAI,SAAS,WAAW,OAAO,SAAS,QAAQ,IAAI,yBAAyB,EAAE;EAE9E,MAAM,WAAW,SAAS,QAAQ,IAAI,WAAW;AACjD,QAAM,KAAK,SAAS;AACpB,SAAO,SAAS,OAAO;YAEtB,SAAS,UAAU,OAAO,SAAS,UAAU,OAC7C,SAAS,UAAU,OAAO,SAAS,UAAU,KAC7C;AAED,MAAI,SAAS,QAAQ,IAAI,eAAe,KAAK,mBAC5C,eAAM,OAAO,MAAM,SAAS,MAAM;AAEnC,QAAM,QAAQ;;;;;;ACxChB,eAA8B,SAC7B,SACA,QACA,MACA,OACA,gBACA,gBACA,gBACA,WAAW,OAC8B;CACzC,IAAI,OAAO,EAAE;AACb,KAAI,QAAQ,SAAS;EACpB,IAAI,cAAcC,eAAO;AACzB,OAAK,IAAI,CAAC,GAAG,WAAW,QAAQ,QAAQ,SAAS,EAAE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W,UAAU;AAC7C,oBAAgB,YAAY,GAAG,WAAW;AAC1C,gBAAY,cAAc,IAAI;AAC9B;cACU,MAAM,GAAG;AACnB,gBAAY,eAAe;AAC3B,YAAQ,EAAE,GAAG,cAAc,IAAI,IAAI;SAEnC,eAAc,KAAK,SAAS,gBAAgB,UAAQ,QAAQ,GAAG,YAAU;AACxE,gBAAY,IAAI,GAAG,aAAa,eAC/B,eAAe,WACf,cAAc,IAAI,IAClBD,UACA,QACA,QACAE,WACA;;;;AAON,KAAI,cACH,SAAQ,QAAQ,WAAW,QAAQ,MAAM;KAEzC,KAAI;AACH,QAAM,QAAQ,WAAW,QAAQ,MAAM;UAC/B,OAAO;AAEf,SAAO,YAAY,6DAA2D,QAAQ;AACtF,UAAQ,IAAI,MAAM;;AAKpB,gBAAO,iBAAiB,EAAE;AAE1B,QAAO;;;;;;;;AC7JR,eAA8B,KAAK,MAAgC;AAElE,QAAO,MAAM,SADD,IAAI,IAAI,MAAM,SAAS,SAAS,KAAK,CACvB"}
@@ -8,4 +8,4 @@ function pathToRegex(path) {
8
8
 
9
9
  //#endregion
10
10
  export { pathToRegex as t };
11
- //# sourceMappingURL=pathToRegex-BTPkBIYJ.js.map
11
+ //# sourceMappingURL=pathToRegex-TUAMc3zS.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathToRegex-TUAMc3zS.mjs","names":[],"sources":["../src/utils/pathToRegex.ts"],"sourcesContent":["export default function pathToRegex(path: string): RegExp {\n\tconst pattern =\n\t\tpath\n\t\t\t.split(\"/\")\n\t\t\t// Replace `[slug]` with a grouped match so we can pull out params\n\t\t\t.map((p) => {\n\t\t\t\treturn p.replace(/\\[([^/]+?)\\]/, \"(?<$1>[^\\\\/]+?)\");\n\t\t\t})\n\t\t\t.join(\"\\\\/\")\n\t\t\t// Replace globs with regex syntax\n\t\t\t.replaceAll(\"*\", \".*\") +\n\t\t// Ignore trailing slashes -- `/path` should be treated the same as `/path/`\n\t\t\"/*\";\n\treturn new RegExp(`^${pattern}/*$`);\n}\n"],"mappings":";AAAA,SAAwB,YAAY,MAAsB;CACzD,MAAM,UACL,KACE,MAAM,IAAI,CAEV,KAAK,MAAM;AACX,SAAO,EAAE,QAAQ,gBAAgB,kBAAkB;GAClD,CACD,KAAK,MAAM,CAEX,WAAW,KAAK,KAAK,GAEvB;AACD,wBAAO,IAAI,OAAO,IAAI,QAAQ,KAAK"}