@torpor/build 0.1.34 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/dist/RouteType-g8Ce5gOd.js +107 -0
- package/dist/RouteType-g8Ce5gOd.js.map +1 -0
- package/dist/Server-CSpY_-Ba.d.ts +78 -0
- package/dist/Server-CSpY_-Ba.d.ts.map +1 -0
- package/dist/ServerEvent-2-CnAy1W.js +74 -0
- package/dist/ServerEvent-2-CnAy1W.js.map +1 -0
- package/dist/Site-D4x1l0p5.d.ts +67 -0
- package/dist/Site-D4x1l0p5.d.ts.map +1 -0
- package/dist/_page-CsdPubw4.js +33 -0
- package/dist/_page-CsdPubw4.js.map +1 -0
- package/dist/bin/index.d.ts +1 -1
- package/dist/bin/index.js +14 -19
- package/dist/bin/index.js.map +1 -1
- package/dist/connectMiddleware-DbLj0St1.js +252 -0
- package/dist/connectMiddleware-DbLj0St1.js.map +1 -0
- package/dist/index.d.ts +191 -182
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +109 -145
- package/dist/index.js.map +1 -1
- package/dist/nav.d.ts +14 -0
- package/dist/nav.d.ts.map +1 -0
- package/dist/nav.js +184 -0
- package/dist/nav.js.map +1 -0
- package/dist/pathToRegex-CTgx7hQP.js +11 -0
- package/dist/pathToRegex-CTgx7hQP.js.map +1 -0
- package/dist/response-D-XpIuMH.js +307 -0
- package/dist/response-D-XpIuMH.js.map +1 -0
- package/dist/response.d.ts +336 -151
- package/dist/response.d.ts.map +1 -0
- package/dist/response.js +4 -37
- package/dist/run-CNdaKSPR.js +331 -0
- package/dist/run-CNdaKSPR.js.map +1 -0
- package/dist/run.d.ts +11 -8
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +8 -18
- package/dist/seeOther-BmehiI4C.js +110 -0
- package/dist/seeOther-BmehiI4C.js.map +1 -0
- package/dist/server.d.ts +12 -11
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +5 -18
- package/dist/state.d.ts +14 -10
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +3 -7
- package/dist/test.d.ts +12 -11
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +152 -225
- package/dist/test.js.map +1 -1
- package/package.json +25 -29
- package/src/bin/index.ts +9 -11
- package/src/index.ts +3 -0
- package/src/nav/load.ts +9 -0
- package/src/nav/loadData.ts +121 -0
- package/src/nav/navigate.ts +154 -0
- package/src/nav/reload.ts +9 -0
- package/src/nav.ts +4 -0
- package/src/response/badRequest.ts +9 -4
- package/src/response/created.ts +10 -3
- package/src/response/forbidden.ts +11 -4
- package/src/response/found.ts +30 -0
- package/src/response/methodNotAllowed.ts +8 -4
- package/src/response/movedPermanently.ts +25 -0
- package/src/response/notFound.ts +14 -7
- package/src/response/notModified.ts +24 -4
- package/src/response/ok.ts +19 -10
- package/src/response/permanentRedirect.ts +30 -0
- package/src/response/seeOther.ts +9 -3
- package/src/response/serverError.ts +14 -2
- package/src/response/temporaryRedirect.ts +31 -0
- package/src/response/unauthorized.ts +11 -4
- package/src/response/unprocessable.ts +8 -2
- package/src/response.ts +8 -4
- package/src/run/prepareTemplate.ts +32 -0
- package/src/{site → run}/run.ts +1 -1
- package/src/{site → run}/runBuild.ts +2 -2
- package/src/{site → run}/runDev.ts +2 -2
- package/src/{site → run}/runPreview.ts +12 -2
- package/src/run.ts +4 -4
- package/src/server/Routerx.ts +3 -3
- package/src/server/Server.ts +3 -3
- package/src/server/ServerEvent.ts +1 -1
- package/src/server/connect/bufferToArrayBuffer.ts +8 -0
- package/src/server/connect/connectMiddleware.ts +4 -2
- package/src/server/connect/nodeMessageToNodeResponse.ts +2 -2
- package/src/server/types/ServerFunction.ts +3 -1
- package/src/site/Router.ts +3 -3
- package/src/site/clientEntry.ts +40 -273
- package/src/site/defaultAdapter.ts +1 -1
- package/src/site/serverEntry.ts +86 -50
- package/src/state/$page.ts +3 -12
- package/src/state/client.ts +6 -0
- package/src/state/internal.ts +45 -0
- package/src/test/runTest.ts +4 -4
- package/src/types/Adapter.ts +2 -4
- package/src/types/ClientState.ts +8 -0
- package/src/types/InternalState.ts +7 -0
- package/src/types/LayoutHandler.ts +2 -4
- package/src/types/LayoutPath.ts +10 -0
- package/src/types/ManifestRoute.ts +2 -4
- package/src/types/PageEndPoint.ts +5 -5
- package/src/types/PageLoadEvent.ts +2 -4
- package/src/types/PageServerAction.ts +1 -1
- package/src/types/PageServerEndPoint.ts +2 -4
- package/src/types/PageServerLoad.ts +1 -1
- package/src/types/PageState.ts +8 -0
- package/src/types/RouteHandler.ts +2 -4
- package/src/types/RouteLayoutHandler.ts +2 -4
- package/src/types/RouteMatchResult.ts +2 -4
- package/src/types/ServerHook.ts +3 -7
- package/src/types/ServerLoadEvent.ts +2 -4
- package/src/types/ServerRequest.ts +1 -1
- package/src/{site → utils}/pathToRegex.ts +1 -1
- package/{tsup.config.ts → tsdown.config.ts} +3 -4
- package/dist/Server-BC_dixZQ.d.cts +0 -71
- package/dist/Server-BC_dixZQ.d.ts +0 -71
- package/dist/Site-4tGiw2-I.d.ts +0 -63
- package/dist/Site-BXX-S541.d.cts +0 -63
- package/dist/bin/index.cjs +0 -755
- package/dist/bin/index.cjs.map +0 -1
- package/dist/bin/index.d.cts +0 -1
- package/dist/chunk-565UOT3F.js +0 -18
- package/dist/chunk-565UOT3F.js.map +0 -1
- package/dist/chunk-B2UNTYN5.js +0 -68
- package/dist/chunk-B2UNTYN5.js.map +0 -1
- package/dist/chunk-KKFND4HK.js +0 -85
- package/dist/chunk-KKFND4HK.js.map +0 -1
- package/dist/chunk-LO7P2LJE.js +0 -278
- package/dist/chunk-LO7P2LJE.js.map +0 -1
- package/dist/chunk-PTVHEJZ5.js +0 -152
- package/dist/chunk-PTVHEJZ5.js.map +0 -1
- package/dist/chunk-RHDSM5GS.js +0 -357
- package/dist/chunk-RHDSM5GS.js.map +0 -1
- package/dist/chunk-SJVHHGVW.js +0 -13
- package/dist/chunk-SJVHHGVW.js.map +0 -1
- package/dist/chunk-WVXAN4IV.js +0 -50
- package/dist/chunk-WVXAN4IV.js.map +0 -1
- package/dist/index.cjs +0 -322
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -199
- package/dist/metafile-cjs.json +0 -1
- package/dist/metafile-esm.json +0 -1
- package/dist/response.cjs +0 -150
- package/dist/response.cjs.map +0 -1
- package/dist/response.d.cts +0 -166
- package/dist/response.js.map +0 -1
- package/dist/run.cjs +0 -764
- package/dist/run.cjs.map +0 -1
- package/dist/run.d.cts +0 -14
- package/dist/run.js.map +0 -1
- package/dist/server.cjs +0 -390
- package/dist/server.cjs.map +0 -1
- package/dist/server.d.cts +0 -17
- package/dist/server.js.map +0 -1
- package/dist/state.cjs +0 -44
- package/dist/state.cjs.map +0 -1
- package/dist/state.d.cts +0 -11
- package/dist/state.js.map +0 -1
- package/dist/test.cjs +0 -538
- package/dist/test.cjs.map +0 -1
- package/dist/test.d.cts +0 -15
- package/src/response/moved.ts +0 -16
- package/src/response/redirect.ts +0 -17
- package/src/site/prepareTemplate.ts +0 -20
- package/src/state/Page.ts +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
# @torpor/build
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 51dbba7: Chore: drop CJS build and go ESM only
|
|
8
|
+
- 62b0d2e: !Edit: renamed responses and updated documentation
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- bbdc8d3: Feat: return form errors from the server
|
|
13
|
+
- e1ae2bb: Feat: load and reload methods for navigation
|
|
14
|
+
- Updated dependencies [be98b35]
|
|
15
|
+
- Updated dependencies [51dbba7]
|
|
16
|
+
- Updated dependencies [2298a87]
|
|
17
|
+
- Updated dependencies [3a8431a]
|
|
18
|
+
- Updated dependencies [eb58d37]
|
|
19
|
+
- Updated dependencies [e0637be]
|
|
20
|
+
- Updated dependencies [9fcc613]
|
|
21
|
+
- Updated dependencies [f5f84e6]
|
|
22
|
+
- Updated dependencies [6cc57ff]
|
|
23
|
+
- Updated dependencies [c4f9d18]
|
|
24
|
+
- Updated dependencies [5598bc9]
|
|
25
|
+
- Updated dependencies [18f1ccf]
|
|
26
|
+
- Updated dependencies [c2b5c02]
|
|
27
|
+
- Updated dependencies [91d1536]
|
|
28
|
+
- Updated dependencies [4dc16df]
|
|
29
|
+
- Updated dependencies [543b229]
|
|
30
|
+
- Updated dependencies [3cf3ae6]
|
|
31
|
+
- @torpor/view@0.3.0
|
|
32
|
+
- @torpor/unplugin@0.2.0
|
|
33
|
+
|
|
34
|
+
## 0.2.0
|
|
35
|
+
|
|
36
|
+
### Minor Changes
|
|
37
|
+
|
|
38
|
+
- b716d5c: Feat: inline styles during SSR
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- a4f2573: Fix: reload the page on successful form submit
|
|
43
|
+
- 67e6ca6: Fix: don't intercept external links
|
|
44
|
+
- Updated dependencies [c38f914]
|
|
45
|
+
- Updated dependencies [995d950]
|
|
46
|
+
- Updated dependencies [b716d5c]
|
|
47
|
+
- Updated dependencies [014bda0]
|
|
48
|
+
- @torpor/view@0.2.0
|
|
49
|
+
- @torpor/unplugin@0.1.17
|
|
50
|
+
|
|
3
51
|
## 0.1.34
|
|
4
52
|
|
|
5
53
|
### Patch Changes
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { pathToRegex } from "./pathToRegex-CTgx7hQP.js";
|
|
2
|
+
|
|
3
|
+
//#region src/site/Router.ts
|
|
4
|
+
/**
|
|
5
|
+
* A router that handles file routes with layouts, hooks, etc.
|
|
6
|
+
*/
|
|
7
|
+
var Router = class {
|
|
8
|
+
routes = [];
|
|
9
|
+
constructor() {}
|
|
10
|
+
addPages(routes) {
|
|
11
|
+
for (let r of routes) this.routes.push(new Route(r.path, {
|
|
12
|
+
path: r.path,
|
|
13
|
+
type: r.type,
|
|
14
|
+
endPoint: r.endPoint
|
|
15
|
+
}));
|
|
16
|
+
this.#sortRoutes();
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
addPage(path, type, endPoint) {
|
|
20
|
+
this.routes.push(new Route(path, {
|
|
21
|
+
path,
|
|
22
|
+
type,
|
|
23
|
+
endPoint
|
|
24
|
+
}));
|
|
25
|
+
this.#sortRoutes();
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
match(path, query) {
|
|
29
|
+
for (let route of this.routes) {
|
|
30
|
+
let match = path.match(route.regex);
|
|
31
|
+
if (match) {
|
|
32
|
+
if (!route.handler.loaded) this.#loadHandler(route.handler, route.path);
|
|
33
|
+
return {
|
|
34
|
+
handler: route.handler,
|
|
35
|
+
params: match.groups,
|
|
36
|
+
query
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
console.log(`not found: '${path}'`);
|
|
41
|
+
}
|
|
42
|
+
#loadHandler(handler, path) {
|
|
43
|
+
handler.layouts = this.#findLayouts(path);
|
|
44
|
+
handler.serverEndPoint = this.#findServer(path);
|
|
45
|
+
handler.serverHook = this.#findServerHook(path);
|
|
46
|
+
}
|
|
47
|
+
#findLayouts(path) {
|
|
48
|
+
let layouts = [];
|
|
49
|
+
let parts = path.replace(/\/~server$/, "").split("/");
|
|
50
|
+
let basePath = "";
|
|
51
|
+
for (let i = 0; i < parts.length; i++) {
|
|
52
|
+
if (i > 0) basePath += "/" + parts[i];
|
|
53
|
+
const layoutPath = basePath + "/_layout";
|
|
54
|
+
const layoutRoute = this.routes.find((r) => r.path === layoutPath);
|
|
55
|
+
if (layoutRoute) layouts.push({
|
|
56
|
+
path: layoutPath,
|
|
57
|
+
endPoint: layoutRoute.handler.endPoint,
|
|
58
|
+
serverEndPoint: this.#findServer(layoutPath)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return layouts.length ? layouts : void 0;
|
|
62
|
+
}
|
|
63
|
+
#findServer(path) {
|
|
64
|
+
const serverPath = path.replace(/\/$/, "") + "/~server";
|
|
65
|
+
const serverRoute = this.routes.find((r) => r.path === serverPath);
|
|
66
|
+
return serverRoute && serverRoute.handler.endPoint;
|
|
67
|
+
}
|
|
68
|
+
#findServerHook(path) {
|
|
69
|
+
let serverHookPath = "/_hook/~server";
|
|
70
|
+
if (path.startsWith("/api/")) serverHookPath = "/api" + serverHookPath;
|
|
71
|
+
const serverHookRoute = this.routes.find((r) => r.path === serverHookPath);
|
|
72
|
+
return serverHookRoute && serverHookRoute.handler.endPoint;
|
|
73
|
+
}
|
|
74
|
+
#sortRoutes() {
|
|
75
|
+
this.routes = this.routes.sort((a, b) => {
|
|
76
|
+
for (let i = 0; i < Math.min(a.path.length, b.path.length); i++) if (a.path[i] === "[" && b.path[i] !== "[") return 1;
|
|
77
|
+
else if (b.path[i] === "[" && a.path[i] !== "[") return -1;
|
|
78
|
+
else if (a.path[i] === b.path[i]) {} else return a.path[i].localeCompare(b.path[i]);
|
|
79
|
+
return a.path.length - b.path.length;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var Route = class {
|
|
84
|
+
path;
|
|
85
|
+
regex;
|
|
86
|
+
handler;
|
|
87
|
+
constructor(path, handler) {
|
|
88
|
+
this.path = path;
|
|
89
|
+
this.regex = pathToRegex(path);
|
|
90
|
+
this.handler = handler;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/types/RouteType.ts
|
|
96
|
+
const PAGE_ROUTE = 0;
|
|
97
|
+
const PAGE_SERVER_ROUTE = 1;
|
|
98
|
+
const SERVER_ROUTE = 3;
|
|
99
|
+
const LAYOUT_ROUTE = 4;
|
|
100
|
+
const LAYOUT_SERVER_ROUTE = 5;
|
|
101
|
+
const HOOK_ROUTE = 6;
|
|
102
|
+
const HOOK_SERVER_ROUTE = 7;
|
|
103
|
+
const ERROR_ROUTE = 8;
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
export { ERROR_ROUTE, HOOK_ROUTE, HOOK_SERVER_ROUTE, LAYOUT_ROUTE, LAYOUT_SERVER_ROUTE, PAGE_ROUTE, PAGE_SERVER_ROUTE, Router, SERVER_ROUTE };
|
|
107
|
+
//# sourceMappingURL=RouteType-g8Ce5gOd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RouteType-g8Ce5gOd.js","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}),\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>): 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}),\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): Match | 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\n\t\tconsole.log(`not found: '${path}'`);\n\t}\n\n\t#loadHandler(handler: RouteHandler, path: string) {\n\t\thandler.layouts = this.#findLayouts(path);\n\t\thandler.serverEndPoint = this.#findServer(path);\n\t\thandler.serverHook = this.#findServerHook(path);\n\t}\n\n\t#findLayouts(path: string): 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) {\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(path: string): (() => Promise<any>) | undefined {\n\t\t// TODO: Should this be a collection, like layouts?\n\t\tlet serverHookPath = \"/_hook/~server\";\n\t\t// HACK: Generalise this\n\t\tif (path.startsWith(\"/api/\")) {\n\t\t\tserverHookPath = \"/api\" + 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 Match {\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":"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"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { SerializeOptions } from "cookie";
|
|
2
|
+
|
|
3
|
+
//#region src/server/CookieHelper.d.ts
|
|
4
|
+
declare class CookieHelper {
|
|
5
|
+
request: Request;
|
|
6
|
+
cookies: Map<string, string>;
|
|
7
|
+
constructor(request: Request);
|
|
8
|
+
get(name: string): string | undefined;
|
|
9
|
+
set(name: string, value: string, options?: SerializeOptions): void;
|
|
10
|
+
delete(name: string, options?: SerializeOptions): void;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/server/HeaderHelper.d.ts
|
|
14
|
+
declare class HeaderHelper {
|
|
15
|
+
request: Request;
|
|
16
|
+
headers: Map<string, string>;
|
|
17
|
+
constructor(request: Request);
|
|
18
|
+
get(name: string): string | undefined;
|
|
19
|
+
set(name: string, value: string): void;
|
|
20
|
+
delete(name: string): void;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/server/ServerEvent.d.ts
|
|
24
|
+
declare class ServerEvent {
|
|
25
|
+
request: Request;
|
|
26
|
+
response: Response | undefined | void;
|
|
27
|
+
params?: Record<string, string>;
|
|
28
|
+
adapter: any;
|
|
29
|
+
cookies: CookieHelper;
|
|
30
|
+
headers: HeaderHelper;
|
|
31
|
+
constructor(request: Request, params?: Record<string, string>);
|
|
32
|
+
addHeaders(): void;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/server/types/MiddlewareFunction.d.ts
|
|
36
|
+
type MiddlewareFunction = (ev: ServerEvent, next: () => void | Promise<void>) => void | Promise<void>;
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/server/types/ServerFunction.d.ts
|
|
39
|
+
type ServerFunction = (e: ServerEvent) => Response | undefined | void | Promise<Response | undefined | void>;
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/server/Server.d.ts
|
|
42
|
+
/**
|
|
43
|
+
* A Fetch API Request/Response server.
|
|
44
|
+
*/
|
|
45
|
+
declare class Server {
|
|
46
|
+
#private;
|
|
47
|
+
routes: RouteHandler[];
|
|
48
|
+
middleware: MiddlewareFunction[];
|
|
49
|
+
constructor();
|
|
50
|
+
/**
|
|
51
|
+
* The standard Fetch API method that should work in any runtime (including
|
|
52
|
+
* Node with polyfills).
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
56
|
+
/**
|
|
57
|
+
* Adds a server function at a route path.
|
|
58
|
+
* @param path The route path pattern.
|
|
59
|
+
* @param fn The function to call when the pattern is matched.
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
add(path: string, fn: ServerFunction): Server;
|
|
63
|
+
match(path: string): Match | undefined;
|
|
64
|
+
use(...fn: MiddlewareFunction[]): Server;
|
|
65
|
+
}
|
|
66
|
+
declare class RouteHandler {
|
|
67
|
+
path: string;
|
|
68
|
+
regex: RegExp;
|
|
69
|
+
fn: ServerFunction;
|
|
70
|
+
constructor(path: string, fn: ServerFunction);
|
|
71
|
+
}
|
|
72
|
+
interface Match {
|
|
73
|
+
fn: ServerFunction;
|
|
74
|
+
params?: Record<string, string>;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { CookieHelper, HeaderHelper, MiddlewareFunction, Server, ServerEvent };
|
|
78
|
+
//# sourceMappingURL=Server-CSpY_-Ba.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Server-CSpY_-Ba.d.ts","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,MAAA,CAAA;EAAA,WAAA,CAAA,OAAA,EAIC,OAJD;UACX,EAAA,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA;UACA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAgBkC,gBAhBlC,CAAA,EAAA,IAAA;QAEY,CAAA,IAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAuBU,gBAvBV,CAAA,EAAA,IAAA;;;;cCND,YAAA;WACX;WACA;EDFyC,WAE9B,CAAA,OAAA,ECEC,ODFD;EAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA;UACX,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA,CAAA,EAAA,IAAA;QACA,CAAA,IAAA,EAAA,MAAA,CAAA,EAAA,IAAA;;;;cEDW,WAAA;EFH8B,OAE9B,EEEX,OFFW;EAAA,QAAA,EEGV,QFHU,GAAA,SAAA,GAAA,IAAA;QACX,CAAA,EEIA,MFJA,CAAA,MAAA,EAAA,MAAA,CAAA;SACA,EAAA,GAAA;SAEY,EEKZ,YFLY;SAcsB,EERlC,YFQkC;aASZ,CAAA,OAAA,EEfV,OFeU,EAAA,MAAA,CAAA,EEfQ,MFeR,CAAA,MAAA,EAAA,MAAA,CAAA;EAAA,UAAA,CAAA,CAAA,EAAA,IAAA;;;;KG3B3B,kBAAA,QACA,gCACe,yBACR;;;KCHP,cAAA,OACD,gBACC,8BAA8B,QAAQ;;;;AJJQ;;AAGzC,cKOW,MAAA,CLPX;UACA;QAEY,EKMb,YLNa,EAAA;YAcsB,EKN/B,kBLM+B,EAAA;aASZ,CAAA;EAAA;;;;;EC7BX,KAAA,EAAA,CAAA,KAAA,EI0BE,WJ1BF,GI0BgB,GJ1BhB,EAAA,IAAA,CAAA,EI0B4B,WJ1B5B,EAAA,GI0B0C,OJ1B1C,CI0BkD,QJ1BlD,CAAA;;;;;;;wBIsEE,iBAAiB;EHrEf,KAEJ,CAAA,IAAA,EAAA,MAAA,CAAA,EGyEC,KHzED,GAAA,SAAA;EAAA,GAAA,CAAA,GAAA,EAAA,EGwFT,kBHxFS,EAAA,CAAA,EGwFc,MHxFd;;cGiHf,YAAA,CH/GK;QAED,MAAA;SG+GF,MH3GE;MG4GL,cH3GK;aAEY,CAAA,IAAA,EAAA,MAAA,EAAA,EAAA,EG2GS,cH3GT;;UG8HZ,KAAA,CH9H8B;MG+HnC;WACK"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { parse, serialize } from "cookie";
|
|
2
|
+
|
|
3
|
+
//#region src/server/CookieHelper.ts
|
|
4
|
+
var CookieHelper = class {
|
|
5
|
+
request;
|
|
6
|
+
cookies = /* @__PURE__ */ new Map();
|
|
7
|
+
constructor(request) {
|
|
8
|
+
this.request = request;
|
|
9
|
+
}
|
|
10
|
+
get(name) {
|
|
11
|
+
if (this.cookies.has(name)) return parse(this.cookies.get(name))[name];
|
|
12
|
+
const header = this.request.headers.get("cookie");
|
|
13
|
+
return parse(header ?? "")[name];
|
|
14
|
+
}
|
|
15
|
+
set(name, value, options) {
|
|
16
|
+
options ??= {};
|
|
17
|
+
options.httpOnly ??= true;
|
|
18
|
+
options.secure ??= true;
|
|
19
|
+
options.sameSite ??= "lax";
|
|
20
|
+
this.cookies.set(name, serialize(name, value, options));
|
|
21
|
+
}
|
|
22
|
+
delete(name, options) {
|
|
23
|
+
options ??= {};
|
|
24
|
+
options.expires = /* @__PURE__ */ new Date(0);
|
|
25
|
+
this.cookies.set(name, serialize(name, "", options));
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/server/HeaderHelper.ts
|
|
31
|
+
var HeaderHelper = class {
|
|
32
|
+
request;
|
|
33
|
+
headers = /* @__PURE__ */ new Map();
|
|
34
|
+
constructor(request) {
|
|
35
|
+
this.request = request;
|
|
36
|
+
}
|
|
37
|
+
get(name) {
|
|
38
|
+
if (this.headers.has(name)) return this.headers.get(name);
|
|
39
|
+
return this.request.headers.get(name) ?? void 0;
|
|
40
|
+
}
|
|
41
|
+
set(name, value) {
|
|
42
|
+
this.headers.set(name, value);
|
|
43
|
+
}
|
|
44
|
+
delete(name) {
|
|
45
|
+
this.headers.delete(name);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/server/ServerEvent.ts
|
|
51
|
+
var ServerEvent = class {
|
|
52
|
+
request;
|
|
53
|
+
response;
|
|
54
|
+
params;
|
|
55
|
+
adapter;
|
|
56
|
+
cookies;
|
|
57
|
+
headers;
|
|
58
|
+
constructor(request, params) {
|
|
59
|
+
this.request = request;
|
|
60
|
+
this.params = params;
|
|
61
|
+
this.cookies = new CookieHelper(request);
|
|
62
|
+
this.headers = new HeaderHelper(request);
|
|
63
|
+
this.adapter = globalThis.adapter;
|
|
64
|
+
}
|
|
65
|
+
addHeaders() {
|
|
66
|
+
if (!this.response) throw new Error("Response not created yet");
|
|
67
|
+
for (let cookie of this.cookies.cookies.values()) this.response.headers.append("set-cookie", cookie);
|
|
68
|
+
for (let header of this.headers.headers.entries()) this.response.headers.append(header[0], header[1]);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { CookieHelper, HeaderHelper, ServerEvent };
|
|
74
|
+
//# sourceMappingURL=ServerEvent-2-CnAy1W.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerEvent-2-CnAy1W.js","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"],"mappings":";;;AAEA,IAAqB,eAArB,MAAkC;CACjC;CACA,0BAA+B,IAAI,KAAK;CAExC,YAAY,SAAkB;AAC7B,OAAK,UAAU;;CAGhB,IAAI,MAAkC;AAErC,MAAI,KAAK,QAAQ,IAAI,KAAK,CACzB,QAAO,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAE,CAAC;EAGvC,MAAM,SAAS,KAAK,QAAQ,QAAQ,IAAI,SAAS;AACjD,SAAO,MAAM,UAAU,GAAG,CAAC;;CAG5B,IAAI,MAAc,OAAe,SAAkC;AAElE,cAAY,EAAE;AACd,UAAQ,aAAa;AACrB,UAAQ,WAAW;AACnB,UAAQ,aAAa;AACrB,OAAK,QAAQ,IAAI,MAAM,UAAU,MAAM,OAAO,QAAQ,CAAC;;CAGxD,OAAO,MAAc,SAAkC;AAEtD,cAAY,EAAE;AACd,UAAQ,0BAAU,IAAI,KAAK,EAAE;AAC7B,OAAK,QAAQ,IAAI,MAAM,UAAU,MAAM,IAAI,QAAQ,CAAC;;;;;;ACjCtD,IAAqB,eAArB,MAAkC;CACjC;CACA,0BAA+B,IAAI,KAAK;CAExC,YAAY,SAAkB;AAC7B,OAAK,UAAU;;CAGhB,IAAI,MAAkC;AAErC,MAAI,KAAK,QAAQ,IAAI,KAAK,CACzB,QAAO,KAAK,QAAQ,IAAI,KAAK;AAG9B,SAAO,KAAK,QAAQ,QAAQ,IAAI,KAAK,IAAI;;CAG1C,IAAI,MAAc,OAAqB;AACtC,OAAK,QAAQ,IAAI,MAAM,MAAM;;CAG9B,OAAO,MAAoB;AAC1B,OAAK,QAAQ,OAAO,KAAK;;;;;;ACnB3B,IAAqB,cAArB,MAAiC;CAChC;CACA;CAEA;CAEA;CAEA;CACA;CAEA,YAAY,SAAkB,QAAiC;AAC9D,OAAK,UAAU;AACf,OAAK,SAAS;AACd,OAAK,UAAU,IAAI,aAAa,QAAQ;AACxC,OAAK,UAAU,IAAI,aAAa,QAAQ;AAIxC,OAAK,UAAU,WAAW;;CAG3B,aAAmB;AAClB,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"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Server } from "./Server-CSpY_-Ba.js";
|
|
2
|
+
import { Plugin, UserConfig } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/types/Adapter.d.ts
|
|
5
|
+
interface Adapter {
|
|
6
|
+
prebuild?: (site: Site) => Promise<void> | void;
|
|
7
|
+
postbuild?: (site: Site) => Promise<void> | void;
|
|
8
|
+
serve: (server: Server, site: Site) => void;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/types/RouteType.d.ts
|
|
12
|
+
declare const PAGE_ROUTE = 0;
|
|
13
|
+
declare const PAGE_SERVER_ROUTE = 1;
|
|
14
|
+
declare const SERVER_ROUTE = 3;
|
|
15
|
+
declare const LAYOUT_ROUTE = 4;
|
|
16
|
+
declare const LAYOUT_SERVER_ROUTE = 5;
|
|
17
|
+
declare const HOOK_ROUTE = 6;
|
|
18
|
+
declare const HOOK_SERVER_ROUTE = 7;
|
|
19
|
+
declare const ERROR_ROUTE = 8;
|
|
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
|
+
//#endregion
|
|
22
|
+
//#region src/site/Site.d.ts
|
|
23
|
+
/**
|
|
24
|
+
* The Site class contains the information necessary to setup a @torpor/build
|
|
25
|
+
* site, including routes, plugins, and options.
|
|
26
|
+
*/
|
|
27
|
+
declare class Site {
|
|
28
|
+
#private;
|
|
29
|
+
root: string;
|
|
30
|
+
routes: {
|
|
31
|
+
path: string;
|
|
32
|
+
file: string;
|
|
33
|
+
type: RouteType;
|
|
34
|
+
}[];
|
|
35
|
+
plugins: Plugin[];
|
|
36
|
+
adapter: Adapter;
|
|
37
|
+
/**
|
|
38
|
+
* Extra inputs, as absolute file paths, that will be compiled with the
|
|
39
|
+
* output. What you do with them after that is up to you. File paths ending
|
|
40
|
+
* with server.ts/js will only be compiled with the server output
|
|
41
|
+
*/
|
|
42
|
+
inputs: string[];
|
|
43
|
+
/**
|
|
44
|
+
* Vite config options to merge with the standard Torpor build options.
|
|
45
|
+
* `plugins` and `build.rollupOptions.input` will be overridden, so you
|
|
46
|
+
* should set `Site.plugins` and `Site.inputs` instead. Other options may be
|
|
47
|
+
* overridden or incompatible, so experimentation may be required
|
|
48
|
+
*/
|
|
49
|
+
viteConfig?: UserConfig;
|
|
50
|
+
constructor();
|
|
51
|
+
/**
|
|
52
|
+
* Adds a folder of routes, based on the names of the files in the folder
|
|
53
|
+
* @param folder The folder containing the routes
|
|
54
|
+
*/
|
|
55
|
+
addRouteFolder(folder: string): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Adds a file route, which can have a standard name (e.g. +page.ts) or any
|
|
58
|
+
* name if you pass the type
|
|
59
|
+
* @param path The route path
|
|
60
|
+
* @param file The file
|
|
61
|
+
* @param type The file type (if the file name is non-standard)
|
|
62
|
+
*/
|
|
63
|
+
addRouteFile(path: string, file: string, type?: "+page" | "+page.server" | "+server" | "_layout" | "_layout.server" | "_hook" | "_hook.server" | "_error"): void;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { Adapter, Site };
|
|
67
|
+
//# sourceMappingURL=Site-D4x1l0p5.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Site-D4x1l0p5.d.ts","names":[],"sources":["../src/types/Adapter.ts","../src/types/RouteType.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;EAAA,KAAA,EAAA,CAAA,MAAA,EAGR,MAHQ,EAAA,IAAA,EAGM,IAHN,EAAA,GAAA,IAAA;;;;cCHZ,UAAA;cACA,iBAAA;cACA,YAAA;cACA,YAAA;ADAY,cCCZ,mBAAA,GDDY,CAAA;AAAA,cCEZ,UAAA,GDFY,CAAA;AACN,cCEN,iBAAA,GDFM,CAAA;AAAS,cCGf,WAAA,GDHe,CAAA;AACR,KCIR,SAAA,GDJQ,OCKV,UDLU,GAAA,OCMV,iBDNU,GAAA,OCOV,YDPU,GAAA,OCQV,YDRU,GAAA,OCSV,mBDTU,GAAA,OCUV,UDVU,GAAA,OCWV,iBDXU,GAAA,OCYV,WDZU,GAAA,CAAA,CAAA;;;;AAJH;;;AAGW,cEuBP,IAAA,CFvBO;UACR;QAAS,MAAA;QACZ,EAAA;UAAc,MAAA;IAAA,IAAA,EAAA,MAAA;UEuBc;;WAKnC;EDlCV,OAAa,ECoCH,ODpCG;EACb;AACA;AACA;AACA;AACA;EACA,MAAa,EAAA,MAAA,EAAA;EACb;AAEA;;;;;YAIU,CAAA,ECoCI,UDpCJ;aACA,CAAA;;;;;kCC6C6B;;;AA5ChC;;;;;cAkCO,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,CAAA,EAAA,IAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { $watch } from "@torpor/view";
|
|
2
|
+
|
|
3
|
+
//#region src/state/internal.ts
|
|
4
|
+
const INTERNAL_GLOBAL = Symbol.for("torpor-internal");
|
|
5
|
+
function internal() {
|
|
6
|
+
if (globalThis[INTERNAL_GLOBAL] === void 0) {
|
|
7
|
+
const $page$1 = $watch({
|
|
8
|
+
status: 404,
|
|
9
|
+
url: new URL("http://localhost"),
|
|
10
|
+
form: {},
|
|
11
|
+
error: { message: "" }
|
|
12
|
+
}, { shallow: true });
|
|
13
|
+
const client = {
|
|
14
|
+
router: null,
|
|
15
|
+
layoutStack: [],
|
|
16
|
+
prefetchedData: {}
|
|
17
|
+
};
|
|
18
|
+
globalThis[INTERNAL_GLOBAL] = {
|
|
19
|
+
$page: $page$1,
|
|
20
|
+
client
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return globalThis[INTERNAL_GLOBAL];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/state/$page.ts
|
|
28
|
+
const $page = internal().$page;
|
|
29
|
+
var $page_default = $page;
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { $page_default, internal };
|
|
33
|
+
//# sourceMappingURL=_page-CsdPubw4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_page-CsdPubw4.js","names":["INTERNAL_GLOBAL: unique symbol","$page: PageState","client: ClientState","$page: PageState"],"sources":["../src/state/internal.ts","../src/state/$page.ts"],"sourcesContent":["import { $watch } from \"@torpor/view\";\nimport type ClientState from \"../types/ClientState\";\nimport type InternalState from \"../types/InternalState\";\nimport type PageState from \"../types/PageState\";\n\n// Do a weird little dance to ensure that everyone has the same $page and\n// client, regardless of if they are entering via serverEntry/clientEntry or the\n// built library. There may be an easier way to do this!\n\nconst INTERNAL_GLOBAL: unique symbol = Symbol.for(\"torpor-internal\");\n\nexport default function internal(): InternalState {\n\t// @ts-ignore\n\tif (globalThis[INTERNAL_GLOBAL] === undefined) {\n\t\t// TODO: Should use the SSR $watch if entering via serverEntry\n\t\tconst $page: PageState = $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: {},\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\t\tconst client: ClientState = {\n\t\t\t// @ts-ignore This will definitely, 100% get set\n\t\t\trouter: null,\n\t\t\tlayoutStack: [],\n\t\t\t// TODO: Probably expire after 30 seconds or something?\n\t\t\tprefetchedData: {},\n\t\t};\n\n\t\t// @ts-ignore\n\t\tglobalThis[INTERNAL_GLOBAL] = {\n\t\t\t$page,\n\t\t\tclient,\n\t\t} satisfies InternalState;\n\t}\n\t// @ts-ignore\n\treturn globalThis[INTERNAL_GLOBAL] as InternalState;\n}\n","import type PageState from \"../types/PageState\";\nimport internal from \"./internal\";\n\nconst $page: PageState = internal().$page;\n\nexport default $page;\n"],"mappings":";;;AASA,MAAMA,kBAAiC,OAAO,IAAI,kBAAkB;AAEpE,SAAwB,WAA0B;AAEjD,KAAI,WAAW,qBAAqB,QAAW;EAE9C,MAAMC,UAAmB,OACxB;GACC,QAAQ;GACR,KAAK,IAAI,IAAI,mBAAmB;GAChC,MAAM,EAAE;GACR,OAAO,EACN,SAAS,IACT;GACD,EACD,EACC,SAAS,MACT,CACD;EACD,MAAMC,SAAsB;GAE3B,QAAQ;GACR,aAAa,EAAE;GAEf,gBAAgB,EAAE;GAClB;AAGD,aAAW,mBAAmB;GAC7B;GACA;GACA;;AAGF,QAAO,WAAW;;;;;ACxCnB,MAAMC,QAAmB,UAAU,CAAC;AAEpC,oBAAe"}
|
package/dist/bin/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export { };
|
package/dist/bin/index.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import "../
|
|
6
|
-
import "../
|
|
7
|
-
import "../
|
|
8
|
-
import "../chunk-KKFND4HK.js";
|
|
9
|
-
import "../chunk-SJVHHGVW.js";
|
|
2
|
+
import "../pathToRegex-CTgx7hQP.js";
|
|
3
|
+
import "../seeOther-BmehiI4C.js";
|
|
4
|
+
import "../response-D-XpIuMH.js";
|
|
5
|
+
import { run } from "../run-CNdaKSPR.js";
|
|
6
|
+
import "../ServerEvent-2-CnAy1W.js";
|
|
7
|
+
import "../connectMiddleware-DbLj0St1.js";
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
await run(workingDir, "preview");
|
|
20
|
-
}
|
|
21
|
-
})();
|
|
9
|
+
//#region src/bin/index.ts
|
|
10
|
+
const workingDir = process.cwd();
|
|
11
|
+
if (process.argv.includes("--dev")) await run(workingDir, "dev");
|
|
12
|
+
else if (process.argv.includes("--build")) await run(workingDir, "build");
|
|
13
|
+
else if (process.argv.includes("--preview")) await run(workingDir, "preview");
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { };
|
|
22
17
|
//# sourceMappingURL=index.js.map
|
package/dist/bin/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bin/index.ts"],"sourcesContent":["#! /usr/bin/env node\nimport run from \"../
|
|
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"}
|