@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/dist/state.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/state.ts","../src/state/$page.ts"],"sourcesContent":["import $page from \"./state/$page\";\n\nexport { $page };\n","import { $watch } from \"@torpor/view\";\nimport Page from \"./Page\";\n\nconst $page: Page = $watch(\n\t{\n\t\tstatus: 404,\n\t\turl: new URL(\"http://localhost\"),\n\t\terror: {\n\t\t\tmessage: \"\",\n\t\t},\n\t},\n\t{ shallow: true },\n);\n\nexport default $page;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAuB;AAGvB,IAAM,YAAc;AAAA,EACnB;AAAA,IACC,QAAQ;AAAA,IACR,KAAK,IAAI,IAAI,kBAAkB;AAAA,IAC/B,OAAO;AAAA,MACN,SAAS;AAAA,IACV;AAAA,EACD;AAAA,EACA,EAAE,SAAS,KAAK;AACjB;AAEA,IAAO,eAAQ;","names":[]}
|
package/dist/state.d.cts
DELETED
package/dist/state.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/test.cjs
DELETED
|
@@ -1,538 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/test.ts
|
|
31
|
-
var test_exports = {};
|
|
32
|
-
__export(test_exports, {
|
|
33
|
-
runTest: () => runTest
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(test_exports);
|
|
36
|
-
|
|
37
|
-
// src/test/runTest.ts
|
|
38
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
39
|
-
|
|
40
|
-
// src/response/response.ts
|
|
41
|
-
function response(status, body) {
|
|
42
|
-
let headers = void 0;
|
|
43
|
-
if (body) {
|
|
44
|
-
if (typeof body === "object") {
|
|
45
|
-
headers = { "content-type": "application/json" };
|
|
46
|
-
body = JSON.stringify(body);
|
|
47
|
-
} else {
|
|
48
|
-
headers = { "content-type": "text/plain" };
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return new Response(body, {
|
|
52
|
-
status,
|
|
53
|
-
headers
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// src/response/notFound.ts
|
|
58
|
-
function notFound(body) {
|
|
59
|
-
return response(404, body ?? "Not found");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// src/response/ok.ts
|
|
63
|
-
function ok(body) {
|
|
64
|
-
return response(200, body);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// src/response/transfer.ts
|
|
68
|
-
function transfer(status, location) {
|
|
69
|
-
return new Response(null, {
|
|
70
|
-
status,
|
|
71
|
-
headers: {
|
|
72
|
-
location
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// src/response/seeOther.ts
|
|
78
|
-
function seeOther(location) {
|
|
79
|
-
return transfer(303, location);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// src/server/CookieHelper.ts
|
|
83
|
-
var import_cookie = require("cookie");
|
|
84
|
-
var CookieHelper = class {
|
|
85
|
-
request;
|
|
86
|
-
cookies = /* @__PURE__ */ new Map();
|
|
87
|
-
constructor(request) {
|
|
88
|
-
this.request = request;
|
|
89
|
-
}
|
|
90
|
-
get(name) {
|
|
91
|
-
if (this.cookies.has(name)) {
|
|
92
|
-
return (0, import_cookie.parse)(this.cookies.get(name))[name];
|
|
93
|
-
}
|
|
94
|
-
const header = this.request.headers.get("cookie");
|
|
95
|
-
return (0, import_cookie.parse)(header ?? "")[name];
|
|
96
|
-
}
|
|
97
|
-
set(name, value, options) {
|
|
98
|
-
options ??= {};
|
|
99
|
-
options.httpOnly ??= true;
|
|
100
|
-
options.secure ??= true;
|
|
101
|
-
options.sameSite ??= "lax";
|
|
102
|
-
this.cookies.set(name, (0, import_cookie.serialize)(name, value, options));
|
|
103
|
-
}
|
|
104
|
-
delete(name, options) {
|
|
105
|
-
options ??= {};
|
|
106
|
-
options.expires = /* @__PURE__ */ new Date(0);
|
|
107
|
-
this.cookies.set(name, (0, import_cookie.serialize)(name, "", options));
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// src/server/HeaderHelper.ts
|
|
112
|
-
var HeaderHelper = class {
|
|
113
|
-
request;
|
|
114
|
-
headers = /* @__PURE__ */ new Map();
|
|
115
|
-
constructor(request) {
|
|
116
|
-
this.request = request;
|
|
117
|
-
}
|
|
118
|
-
get(name) {
|
|
119
|
-
if (this.headers.has(name)) {
|
|
120
|
-
return this.headers.get(name);
|
|
121
|
-
}
|
|
122
|
-
return this.request.headers.get(name) ?? void 0;
|
|
123
|
-
}
|
|
124
|
-
set(name, value) {
|
|
125
|
-
this.headers.set(name, value);
|
|
126
|
-
}
|
|
127
|
-
delete(name) {
|
|
128
|
-
this.headers.delete(name);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// src/server/ServerEvent.ts
|
|
133
|
-
var ServerEvent = class {
|
|
134
|
-
request;
|
|
135
|
-
response;
|
|
136
|
-
// TODO: Should we cast types??
|
|
137
|
-
params;
|
|
138
|
-
adapter;
|
|
139
|
-
cookies;
|
|
140
|
-
headers;
|
|
141
|
-
constructor(request, params) {
|
|
142
|
-
this.request = request;
|
|
143
|
-
this.params = params;
|
|
144
|
-
this.cookies = new CookieHelper(request);
|
|
145
|
-
this.headers = new HeaderHelper(request);
|
|
146
|
-
this.adapter = globalThis.adapter;
|
|
147
|
-
}
|
|
148
|
-
addHeaders() {
|
|
149
|
-
if (!this.response) {
|
|
150
|
-
throw new Error("Response not created yet");
|
|
151
|
-
}
|
|
152
|
-
for (let cookie of this.cookies.cookies.values()) {
|
|
153
|
-
this.response.headers.append("set-cookie", cookie);
|
|
154
|
-
}
|
|
155
|
-
for (let header of this.headers.headers.entries()) {
|
|
156
|
-
this.response.headers.append(header[0], header[1]);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
// src/site/pathToRegex.ts
|
|
162
|
-
function pathToRegex(path2) {
|
|
163
|
-
const pattern = path2.split("/").map((p) => {
|
|
164
|
-
return p.replace(/\[([^\/]+?)\]/, "(?<$1>[^\\/]+?)");
|
|
165
|
-
}).join("\\/").replaceAll("*", ".*") + // Ignore trailing slashes -- `/path` should be treated the same as `/path/`
|
|
166
|
-
"/*";
|
|
167
|
-
return new RegExp(`^${pattern}/*$`);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// src/site/Router.ts
|
|
171
|
-
var Router = class {
|
|
172
|
-
routes = [];
|
|
173
|
-
constructor() {
|
|
174
|
-
}
|
|
175
|
-
//add(path: string, file: string) {
|
|
176
|
-
// // TODO: Call the specific addX method based on the file path
|
|
177
|
-
// this.addPage(route, file);
|
|
178
|
-
//}
|
|
179
|
-
addPages(routes) {
|
|
180
|
-
for (let r of routes) {
|
|
181
|
-
this.routes.push(
|
|
182
|
-
new Route(r.path, {
|
|
183
|
-
path: r.path,
|
|
184
|
-
type: r.type,
|
|
185
|
-
endPoint: r.endPoint
|
|
186
|
-
})
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
this.#sortRoutes();
|
|
190
|
-
return this;
|
|
191
|
-
}
|
|
192
|
-
// TODO: Allow calling with the endpoint itself, so that you can setup an app with no scaffold
|
|
193
|
-
addPage(path2, type, endPoint) {
|
|
194
|
-
this.routes.push(
|
|
195
|
-
new Route(path2, {
|
|
196
|
-
path: path2,
|
|
197
|
-
type,
|
|
198
|
-
endPoint
|
|
199
|
-
})
|
|
200
|
-
);
|
|
201
|
-
this.#sortRoutes();
|
|
202
|
-
return this;
|
|
203
|
-
}
|
|
204
|
-
/*
|
|
205
|
-
loadPage(ev: ServerEvent, file: string): Response {
|
|
206
|
-
let page = this.pages.get(file);
|
|
207
|
-
if (!page) {
|
|
208
|
-
page = {};
|
|
209
|
-
this.pages.set(file, page);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
*/
|
|
213
|
-
match(path2, query) {
|
|
214
|
-
for (let route of this.routes) {
|
|
215
|
-
let match = path2.match(route.regex);
|
|
216
|
-
if (match) {
|
|
217
|
-
if (!route.handler.loaded) {
|
|
218
|
-
this.#loadHandler(route.handler, route.path);
|
|
219
|
-
}
|
|
220
|
-
return {
|
|
221
|
-
handler: route.handler,
|
|
222
|
-
params: match.groups,
|
|
223
|
-
query
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
console.log(`not found: '${path2}'`);
|
|
228
|
-
}
|
|
229
|
-
#loadHandler(handler, path2) {
|
|
230
|
-
handler.layouts = this.#findLayouts(path2);
|
|
231
|
-
handler.serverEndPoint = this.#findServer(path2);
|
|
232
|
-
handler.serverHook = this.#findServerHook(path2);
|
|
233
|
-
}
|
|
234
|
-
#findLayouts(path2) {
|
|
235
|
-
let layouts = [];
|
|
236
|
-
let parts = path2.replace(/\/~server$/, "").split("/");
|
|
237
|
-
let basePath = "";
|
|
238
|
-
for (let i = 0; i < parts.length; i++) {
|
|
239
|
-
if (i > 0) {
|
|
240
|
-
basePath += "/" + parts[i];
|
|
241
|
-
}
|
|
242
|
-
const layoutPath = basePath + "/_layout";
|
|
243
|
-
const layoutRoute = this.routes.find((r) => r.path === layoutPath);
|
|
244
|
-
if (layoutRoute) {
|
|
245
|
-
layouts.push({
|
|
246
|
-
path: layoutPath,
|
|
247
|
-
endPoint: layoutRoute.handler.endPoint,
|
|
248
|
-
serverEndPoint: this.#findServer(layoutPath)
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return layouts.length ? layouts : void 0;
|
|
253
|
-
}
|
|
254
|
-
#findServer(path2) {
|
|
255
|
-
const serverPath = path2.replace(/\/$/, "") + "/~server";
|
|
256
|
-
const serverRoute = this.routes.find((r) => r.path === serverPath);
|
|
257
|
-
return serverRoute && serverRoute.handler.endPoint;
|
|
258
|
-
}
|
|
259
|
-
#findServerHook(path2) {
|
|
260
|
-
let serverHookPath = "/_hook/~server";
|
|
261
|
-
if (path2.startsWith("/api/")) {
|
|
262
|
-
serverHookPath = "/api" + serverHookPath;
|
|
263
|
-
}
|
|
264
|
-
const serverHookRoute = this.routes.find((r) => r.path === serverHookPath);
|
|
265
|
-
return serverHookRoute && serverHookRoute.handler.endPoint;
|
|
266
|
-
}
|
|
267
|
-
// HACK: We're doing this here as well as in Site, so that you can use the
|
|
268
|
-
// Router externally without Site
|
|
269
|
-
#sortRoutes() {
|
|
270
|
-
this.routes = this.routes.sort((a, b) => {
|
|
271
|
-
for (let i = 0; i < Math.min(a.path.length, b.path.length); i++) {
|
|
272
|
-
if (a.path[i] === "[" && b.path[i] !== "[") {
|
|
273
|
-
return 1;
|
|
274
|
-
} else if (b.path[i] === "[" && a.path[i] !== "[") {
|
|
275
|
-
return -1;
|
|
276
|
-
} else if (a.path[i] === b.path[i]) {
|
|
277
|
-
} else {
|
|
278
|
-
return a.path[i].localeCompare(b.path[i]);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
return a.path.length - b.path.length;
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
var Route = class {
|
|
286
|
-
path;
|
|
287
|
-
regex;
|
|
288
|
-
handler;
|
|
289
|
-
constructor(path2, handler) {
|
|
290
|
-
this.path = path2;
|
|
291
|
-
this.regex = pathToRegex(path2);
|
|
292
|
-
this.handler = handler;
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
// src/state/$page.ts
|
|
297
|
-
var import_view = require("@torpor/view");
|
|
298
|
-
var $page = (0, import_view.$watch)(
|
|
299
|
-
{
|
|
300
|
-
status: 404,
|
|
301
|
-
url: new URL("http://localhost"),
|
|
302
|
-
error: {
|
|
303
|
-
message: ""
|
|
304
|
-
}
|
|
305
|
-
},
|
|
306
|
-
{ shallow: true }
|
|
307
|
-
);
|
|
308
|
-
var page_default = $page;
|
|
309
|
-
|
|
310
|
-
// src/types/RouteType.ts
|
|
311
|
-
var PAGE_ROUTE = 0;
|
|
312
|
-
var PAGE_SERVER_ROUTE = 1;
|
|
313
|
-
var SERVER_ROUTE = 3;
|
|
314
|
-
var LAYOUT_ROUTE = 4;
|
|
315
|
-
var LAYOUT_SERVER_ROUTE = 5;
|
|
316
|
-
var HOOK_ROUTE = 6;
|
|
317
|
-
var HOOK_SERVER_ROUTE = 7;
|
|
318
|
-
|
|
319
|
-
// src/test/runTest.ts
|
|
320
|
-
async function runTest(site, route, ev) {
|
|
321
|
-
if (!route.startsWith("/")) route += "/";
|
|
322
|
-
if (!ev) {
|
|
323
|
-
const req = new Request(`http://localhost${route}`);
|
|
324
|
-
ev = new ServerEvent(req);
|
|
325
|
-
}
|
|
326
|
-
const router = new Router();
|
|
327
|
-
router.addPages(
|
|
328
|
-
site.routes.map((r) => ({
|
|
329
|
-
path: r.path,
|
|
330
|
-
type: r.type,
|
|
331
|
-
endPoint: () => import(
|
|
332
|
-
/* @vite-ignore */
|
|
333
|
-
import_node_path.default.join(site.root, r.file)
|
|
334
|
-
)
|
|
335
|
-
}))
|
|
336
|
-
);
|
|
337
|
-
return await load(router, ev, "%COMPONENT_HTML%");
|
|
338
|
-
}
|
|
339
|
-
async function load(router, ev, template) {
|
|
340
|
-
const url = new URL(ev.request.url);
|
|
341
|
-
const path2 = url.pathname;
|
|
342
|
-
const query = url.searchParams;
|
|
343
|
-
const route = router.match(path2, query);
|
|
344
|
-
if (!route) {
|
|
345
|
-
return notFound();
|
|
346
|
-
}
|
|
347
|
-
page_default.url = url;
|
|
348
|
-
const handler = route.handler;
|
|
349
|
-
const params = route.params || {};
|
|
350
|
-
switch (handler.type) {
|
|
351
|
-
case PAGE_ROUTE:
|
|
352
|
-
case LAYOUT_ROUTE: {
|
|
353
|
-
if (ev.request.method === "GET") {
|
|
354
|
-
return await loadView(ev, url, handler, params, template);
|
|
355
|
-
} else if (ev.request.method === "POST") {
|
|
356
|
-
return await runAction(ev, url, handler, params, query);
|
|
357
|
-
}
|
|
358
|
-
break;
|
|
359
|
-
}
|
|
360
|
-
case PAGE_SERVER_ROUTE:
|
|
361
|
-
case LAYOUT_SERVER_ROUTE: {
|
|
362
|
-
if (ev.request.method === "GET") {
|
|
363
|
-
return await loadData(ev, url, handler, "load", params);
|
|
364
|
-
}
|
|
365
|
-
break;
|
|
366
|
-
}
|
|
367
|
-
case SERVER_ROUTE: {
|
|
368
|
-
const functionName = ev.request.method.toLowerCase().replace("delete", "del");
|
|
369
|
-
return await loadData(ev, url, handler, functionName, params);
|
|
370
|
-
}
|
|
371
|
-
case HOOK_ROUTE:
|
|
372
|
-
case HOOK_SERVER_ROUTE: {
|
|
373
|
-
break;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return notFound();
|
|
377
|
-
}
|
|
378
|
-
async function loadData(ev, url, handler, functionName, params) {
|
|
379
|
-
const serverEndPoint = (await handler.endPoint()).default;
|
|
380
|
-
if (serverEndPoint && serverEndPoint[functionName]) {
|
|
381
|
-
const serverParams = buildServerParams(ev, url, params);
|
|
382
|
-
if (handler.serverHook) {
|
|
383
|
-
const serverHook = (await handler.serverHook()).default;
|
|
384
|
-
if (serverHook?.handle) {
|
|
385
|
-
await serverHook.handle(serverParams);
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
const result = await serverEndPoint[functionName](serverParams);
|
|
389
|
-
return result || ok();
|
|
390
|
-
}
|
|
391
|
-
return notFound();
|
|
392
|
-
}
|
|
393
|
-
async function loadView(ev, url, handler, params, template) {
|
|
394
|
-
const clientEndPoint = (await handler.endPoint()).default;
|
|
395
|
-
if (!clientEndPoint?.component) {
|
|
396
|
-
return notFound();
|
|
397
|
-
}
|
|
398
|
-
const serverEndPoint = handler.serverEndPoint && (await handler.serverEndPoint())?.default;
|
|
399
|
-
const serverParams = buildServerParams(ev, url, params);
|
|
400
|
-
if (handler.serverHook) {
|
|
401
|
-
const serverHook = (await handler.serverHook()).default;
|
|
402
|
-
if (serverHook?.handle) {
|
|
403
|
-
await serverHook.handle(serverParams);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
let data = {};
|
|
407
|
-
if (handler.layouts) {
|
|
408
|
-
for (let layout of handler.layouts) {
|
|
409
|
-
const layoutEndPoint = (await layout.endPoint())?.default;
|
|
410
|
-
const layoutServerEndPoint = layout.serverEndPoint && (await layout.serverEndPoint())?.default;
|
|
411
|
-
const layoutResponse = await loadClientAndServerData(
|
|
412
|
-
url,
|
|
413
|
-
params,
|
|
414
|
-
serverParams,
|
|
415
|
-
data,
|
|
416
|
-
layoutEndPoint,
|
|
417
|
-
layoutServerEndPoint
|
|
418
|
-
);
|
|
419
|
-
if (layoutResponse?.ok === false) {
|
|
420
|
-
return layoutResponse;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
let endPointResponse = await loadClientAndServerData(
|
|
425
|
-
url,
|
|
426
|
-
params,
|
|
427
|
-
serverParams,
|
|
428
|
-
data,
|
|
429
|
-
clientEndPoint,
|
|
430
|
-
serverEndPoint
|
|
431
|
-
);
|
|
432
|
-
if (endPointResponse?.ok === false) {
|
|
433
|
-
return endPointResponse;
|
|
434
|
-
}
|
|
435
|
-
let $props = { data };
|
|
436
|
-
let component = clientEndPoint.component;
|
|
437
|
-
let slots = void 0;
|
|
438
|
-
if (handler.layouts) {
|
|
439
|
-
let slotFunctions = [];
|
|
440
|
-
slotFunctions[handler.layouts.length] = (_, context) => clientEndPoint.component($props, context);
|
|
441
|
-
for (let i = handler.layouts.length - 1; i >= 0; i--) {
|
|
442
|
-
const layoutEndPoint = (await handler.layouts[i].endPoint())?.default;
|
|
443
|
-
if (layoutEndPoint?.component) {
|
|
444
|
-
if (i === 0) {
|
|
445
|
-
component = layoutEndPoint.component;
|
|
446
|
-
slots = { _: slotFunctions[i + 1] };
|
|
447
|
-
} else {
|
|
448
|
-
slotFunctions[i] = (_, context) => layoutEndPoint.component($props, context, {
|
|
449
|
-
_: slotFunctions[i + 1]
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
let html;
|
|
456
|
-
try {
|
|
457
|
-
html = component($props, void 0, slots);
|
|
458
|
-
html = template.replace("%COMPONENT_HTML%", html);
|
|
459
|
-
} catch (error) {
|
|
460
|
-
html = '<span style="color: red">Script syntax error</span><p>' + error + "</p>";
|
|
461
|
-
console.log(error);
|
|
462
|
-
}
|
|
463
|
-
return new Response(html, {
|
|
464
|
-
status: 200,
|
|
465
|
-
headers: {
|
|
466
|
-
"Content-Type": "text/html"
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
async function runAction(ev, url, handler, params, query) {
|
|
471
|
-
const actionName = (Array.from(query.keys())[0] || "default").replace(/^\//, "");
|
|
472
|
-
const serverEndPoint = handler.serverEndPoint && (await handler.serverEndPoint()).default;
|
|
473
|
-
if (serverEndPoint?.actions) {
|
|
474
|
-
const action = serverEndPoint.actions[actionName];
|
|
475
|
-
if (action) {
|
|
476
|
-
const serverParams = buildServerParams(ev, url, params);
|
|
477
|
-
if (handler.serverHook) {
|
|
478
|
-
const serverHook = (await handler.serverHook()).default;
|
|
479
|
-
if (serverHook?.handle) {
|
|
480
|
-
await serverHook.handle(serverParams);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
const result = await action(serverParams);
|
|
484
|
-
return result || seeOther(url.pathname);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
return notFound();
|
|
488
|
-
}
|
|
489
|
-
async function loadClientAndServerData(url, params, serverParams, data, clientEndPoint, serverEndPoint) {
|
|
490
|
-
if (clientEndPoint?.load) {
|
|
491
|
-
const clientParams = buildClientParams(url, data, params);
|
|
492
|
-
const clientResponse = await clientEndPoint.load(clientParams);
|
|
493
|
-
if (clientResponse) {
|
|
494
|
-
if (clientResponse.ok) {
|
|
495
|
-
if (clientResponse.headers.get("Content-Type")?.includes("application/json")) {
|
|
496
|
-
Object.assign(data, await clientResponse.json());
|
|
497
|
-
}
|
|
498
|
-
} else {
|
|
499
|
-
return clientResponse;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
if (serverEndPoint?.load) {
|
|
504
|
-
const serverResponse = await serverEndPoint.load(serverParams);
|
|
505
|
-
if (serverResponse) {
|
|
506
|
-
if (serverResponse.ok) {
|
|
507
|
-
if (serverResponse.headers.get("Content-Type")?.includes("application/json")) {
|
|
508
|
-
Object.assign(data, await serverResponse.json());
|
|
509
|
-
}
|
|
510
|
-
} else {
|
|
511
|
-
return serverResponse;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
function buildClientParams(url, params, data) {
|
|
517
|
-
return {
|
|
518
|
-
url,
|
|
519
|
-
params,
|
|
520
|
-
data
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
function buildServerParams(ev, url, params) {
|
|
524
|
-
return {
|
|
525
|
-
url,
|
|
526
|
-
params,
|
|
527
|
-
appData: {},
|
|
528
|
-
request: ev.request,
|
|
529
|
-
cookies: ev.cookies,
|
|
530
|
-
headers: ev.headers,
|
|
531
|
-
adapter: ev.adapter
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
535
|
-
0 && (module.exports = {
|
|
536
|
-
runTest
|
|
537
|
-
});
|
|
538
|
-
//# sourceMappingURL=test.cjs.map
|
package/dist/test.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/test.ts","../src/test/runTest.ts","../src/response/response.ts","../src/response/notFound.ts","../src/response/ok.ts","../src/response/transfer.ts","../src/response/seeOther.ts","../src/server/CookieHelper.ts","../src/server/HeaderHelper.ts","../src/server/ServerEvent.ts","../src/site/pathToRegex.ts","../src/site/Router.ts","../src/state/$page.ts","../src/types/RouteType.ts"],"sourcesContent":["import runTest from \"./test/runTest\";\n\nexport { runTest };\n","import { type ServerComponent, type ServerSlotRender } from \"@torpor/view\";\nimport path from \"node:path\";\nimport notFound from \"../response/notFound.ts\";\nimport ok from \"../response/ok.ts\";\nimport seeOther from \"../response/seeOther.ts\";\nimport ServerEvent from \"../server/ServerEvent.ts\";\nimport Router from \"../site/Router.ts\";\nimport Site from \"../site/Site\";\nimport $page from \"../state/$page.ts\";\nimport type PageEndPoint from \"../types/PageEndPoint.ts\";\nimport type PageServerEndPoint from \"../types/PageServerEndPoint.ts\";\nimport RouteHandler from \"../types/RouteHandler.ts\";\nimport {\n\tHOOK_ROUTE,\n\tHOOK_SERVER_ROUTE,\n\tLAYOUT_ROUTE,\n\tLAYOUT_SERVER_ROUTE,\n\tPAGE_ROUTE,\n\tPAGE_SERVER_ROUTE,\n\tSERVER_ROUTE,\n} from \"../types/RouteType\";\nimport type ServerEndPoint from \"../types/ServerEndPoint.ts\";\nimport type ServerHook from \"../types/ServerHook.ts\";\nimport type ServerLoadEvent from \"../types/ServerLoadEvent.ts\";\n\n/**\n * Runs a site route in test mode\n * @param site The site configuration, with routing configured\n * @param route The route path e.g. `/home`\n * @param ev An optional ServerEvent, which you can use to set test cookies and headers\n * @returns An HTTP response containing the requested data, HTML, or error status\n */\nexport default async function runTest(\n\tsite: Site,\n\troute: string,\n\tev?: ServerEvent,\n): Promise<Response> {\n\tif (!route.startsWith(\"/\")) route += \"/\";\n\tif (!ev) {\n\t\tconst req = new Request(`http://localhost${route}`);\n\t\tev = new ServerEvent(req);\n\t}\n\n\t// Build the router from the Site object created by the user\n\tconst router = new Router();\n\trouter.addPages(\n\t\tsite.routes.map((r) => ({\n\t\t\tpath: r.path,\n\t\t\ttype: r.type,\n\t\t\tendPoint: () => import(/* @vite-ignore */ path.join(site.root, r.file)),\n\t\t})),\n\t);\n\n\treturn await load(router, ev, \"%COMPONENT_HTML%\");\n}\n\n// HACK: This is a copy of serverEntry\n// TODO: Make it shared instead!\nasync function load(router: Router, ev: ServerEvent, template: string): Promise<Response> {\n\t//const url = new URL(`http://${process.env.HOST ?? \"localhost\"}${ev.request.url}`);\n\tconst url = new URL(ev.request.url);\n\tconst path = url.pathname;\n\tconst query = url.searchParams;\n\n\t//console.log(`handling ${ev.request.method} for '${path}'${query.size ? ` with ${query}` : \"\"}`);\n\n\tconst route = router.match(path, query);\n\tif (!route) {\n\t\treturn notFound();\n\t}\n\n\t// Update $page before building the components\n\t// TODO: Find somewhere better to put this\n\t$page.url = url;\n\n\tconst handler = route.handler;\n\tconst params = route.params || {};\n\n\t// TODO: Hit the server hook out here\n\t// We could maybe set data loading up as middleware on a route??????\n\n\tswitch (handler.type) {\n\t\tcase PAGE_ROUTE:\n\t\tcase LAYOUT_ROUTE: {\n\t\t\t// It's a /+page.ts or /_layout.ts endpoint\n\t\t\tif (ev.request.method === \"GET\") {\n\t\t\t\treturn await loadView(ev, url, handler, params, template);\n\t\t\t} else if (ev.request.method === \"POST\") {\n\t\t\t\treturn await runAction(ev, url, handler, params, query);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase PAGE_SERVER_ROUTE:\n\t\tcase LAYOUT_SERVER_ROUTE: {\n\t\t\t// It's a /+page.server.ts or /_layout.server.ts endpoint\n\t\t\tif (ev.request.method === \"GET\") {\n\t\t\t\treturn await loadData(ev, url, handler, \"load\", params);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase SERVER_ROUTE: {\n\t\t\t// It's a /+server.ts endpoint\n\t\t\tconst functionName = ev.request.method.toLowerCase().replace(\"delete\", \"del\");\n\t\t\treturn await loadData(ev, url, handler, functionName, params);\n\t\t}\n\t\tcase HOOK_ROUTE:\n\t\tcase HOOK_SERVER_ROUTE: {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn notFound();\n}\n\nasync function loadData(\n\tev: ServerEvent,\n\turl: URL,\n\thandler: RouteHandler,\n\tfunctionName: string,\n\tparams: Record<string, string>,\n) {\n\tconst serverEndPoint: ServerEndPoint | undefined = (await handler.endPoint()).default;\n\tif (serverEndPoint && serverEndPoint[functionName]) {\n\t\tconst serverParams = buildServerParams(ev, url, params);\n\n\t\tif (handler.serverHook) {\n\t\t\tconst serverHook: ServerHook | undefined = (await handler.serverHook()).default;\n\t\t\tif (serverHook?.handle) {\n\t\t\t\tawait serverHook.handle(serverParams);\n\t\t\t}\n\t\t}\n\n\t\tconst result = await serverEndPoint[functionName](serverParams);\n\n\t\t// If there was no response returned from load (such as errors or a\n\t\t// redirect), send an ok response\n\t\treturn result || ok();\n\t}\n\n\treturn notFound();\n}\n\nasync function loadView(\n\tev: ServerEvent,\n\turl: URL,\n\thandler: RouteHandler,\n\tparams: Record<string, string>,\n\ttemplate: string,\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\treturn notFound();\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\t// Maybe hit the server hook\n\tconst serverParams = buildServerParams(ev, url, params);\n\tif (handler.serverHook) {\n\t\tconst serverHook: ServerHook | undefined = (await handler.serverHook()).default;\n\t\tif (serverHook?.handle) {\n\t\t\tawait serverHook.handle(serverParams);\n\t\t}\n\t}\n\n\t// Pass the data into $props\n\t// TODO: Promise.all\n\t// NOTE: We're loading data from top to bottom, overriding as we go, and I'm not sure if this is the best way to go\n\tlet data = {};\n\tif (handler.layouts) {\n\t\tfor (let layout of handler.layouts) {\n\t\t\tconst layoutEndPoint: PageEndPoint | undefined = (await layout.endPoint())?.default;\n\t\t\tconst layoutServerEndPoint: PageServerEndPoint | undefined =\n\t\t\t\tlayout.serverEndPoint && (await layout.serverEndPoint())?.default;\n\t\t\tconst layoutResponse = await loadClientAndServerData(\n\t\t\t\turl,\n\t\t\t\tparams,\n\t\t\t\tserverParams,\n\t\t\t\tdata,\n\t\t\t\tlayoutEndPoint,\n\t\t\t\tlayoutServerEndPoint,\n\t\t\t);\n\t\t\tif (layoutResponse?.ok === false) {\n\t\t\t\treturn layoutResponse;\n\t\t\t}\n\t\t}\n\t}\n\tlet endPointResponse = await loadClientAndServerData(\n\t\turl,\n\t\tparams,\n\t\tserverParams,\n\t\tdata,\n\t\tclientEndPoint,\n\t\tserverEndPoint,\n\t);\n\tif (endPointResponse?.ok === false) {\n\t\treturn endPointResponse;\n\t}\n\tlet $props: Record<string, any> = { data };\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: Also handle layout server data\n\t// TODO: There's probably a nicer way to do this with reducers or something\n\t// TODO: Re-use parent layouts\n\tlet component = clientEndPoint.component as ServerComponent;\n\tlet slots: Record<string, ServerSlotRender> | undefined = undefined;\n\tif (handler.layouts) {\n\t\tlet slotFunctions: ServerSlotRender[] = [];\n\t\tslotFunctions[handler.layouts.length] = (_, context) =>\n\t\t\t(clientEndPoint.component as ServerComponent)($props, context);\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 (i === 0) {\n\t\t\t\t\tcomponent = layoutEndPoint.component as ServerComponent;\n\t\t\t\t\tslots = { _: slotFunctions[i + 1] };\n\t\t\t\t} else {\n\t\t\t\t\tslotFunctions[i] = (_, context) =>\n\t\t\t\t\t\t(layoutEndPoint.component as ServerComponent)($props, context, {\n\t\t\t\t\t\t\t_: slotFunctions[i + 1],\n\t\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tlet html;\n\ttry {\n\t\thtml = component($props, undefined, slots);\n\t\thtml = template.replace(\"%COMPONENT_HTML%\", html);\n\t} catch (error) {\n\t\t// TODO: Show a proper Error component\n\t\thtml = '<span style=\"color: red\">Script syntax error</span><p>' + error + \"</p>\";\n\t\tconsole.log(error);\n\t}\n\n\treturn new Response(html, {\n\t\tstatus: 200,\n\t\theaders: {\n\t\t\t\"Content-Type\": \"text/html\",\n\t\t},\n\t});\n}\n\nasync function runAction(\n\tev: ServerEvent,\n\turl: URL,\n\thandler: RouteHandler,\n\tparams: Record<string, string>,\n\tquery: URLSearchParams,\n) {\n\tconst actionName = (Array.from(query.keys())[0] || \"default\").replace(/^\\//, \"\");\n\tconst serverEndPoint: PageServerEndPoint | undefined =\n\t\thandler.serverEndPoint && (await handler.serverEndPoint()).default;\n\tif (serverEndPoint?.actions) {\n\t\tconst action = serverEndPoint.actions[actionName];\n\t\tif (action) {\n\t\t\t// TODO: form.errors etc\n\t\t\tconst serverParams = buildServerParams(ev, url, params);\n\n\t\t\tif (handler.serverHook) {\n\t\t\t\tconst serverHook: ServerHook | undefined = (await handler.serverHook()).default;\n\t\t\t\tif (serverHook?.handle) {\n\t\t\t\t\tawait serverHook.handle(serverParams);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst result = await action(serverParams); // <--\n\n\t\t\t// If there was no response returned from the action (such as errors\n\t\t\t// or a redirect), reload the page by redirecting\n\t\t\treturn result || seeOther(url.pathname);\n\t\t}\n\t}\n\n\treturn notFound();\n}\n\nasync function loadClientAndServerData(\n\turl: URL,\n\tparams: Record<string, string>,\n\tserverParams: ServerLoadEvent,\n\tdata: Record<string, any>,\n\tclientEndPoint?: PageEndPoint,\n\tserverEndPoint?: PageServerEndPoint,\n) {\n\tif (clientEndPoint?.load) {\n\t\tconst clientParams = buildClientParams(url, data, params);\n\t\tconst clientResponse = await clientEndPoint.load(clientParams);\n\t\tif (clientResponse) {\n\t\t\tif (clientResponse.ok) {\n\t\t\t\tif (clientResponse.headers.get(\"Content-Type\")?.includes(\"application/json\")) {\n\t\t\t\t\tObject.assign(data, await clientResponse.json());\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn clientResponse;\n\t\t\t}\n\t\t}\n\t}\n\tif (serverEndPoint?.load) {\n\t\tconst serverResponse = await serverEndPoint.load(serverParams);\n\t\tif (serverResponse) {\n\t\t\tif (serverResponse.ok) {\n\t\t\t\tif (serverResponse.headers.get(\"Content-Type\")?.includes(\"application/json\")) {\n\t\t\t\t\tObject.assign(data, await serverResponse.json());\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn serverResponse;\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\nfunction buildServerParams(\n\tev: ServerEvent,\n\turl: URL,\n\tparams: Record<string, string>,\n): ServerLoadEvent {\n\treturn {\n\t\turl,\n\t\tparams,\n\t\tappData: {},\n\t\trequest: ev.request,\n\t\tcookies: ev.cookies,\n\t\theaders: ev.headers,\n\t\tadapter: ev.adapter,\n\t};\n}\n","/**\n * Creates a response with the supplied status code and optional body.\n *\n * If the body is an object, it will be converted to JSON and the content-type\n * header set to \"application/json\". Otherwise, if the body is a string, the\n * content-type header will be set to \"text/plain\".\n */\nexport default function response(status: number, body?: object | string): Response {\n\tlet headers: Record<string, string> | undefined = undefined;\n\tif (body) {\n\t\tif (typeof body === \"object\") {\n\t\t\theaders = { \"content-type\": \"application/json\" };\n\t\t\tbody = JSON.stringify(body);\n\t\t} else {\n\t\t\theaders = { \"content-type\": \"text/plain\" };\n\t\t}\n\t}\n\treturn new Response(body, {\n\t\tstatus,\n\t\theaders,\n\t});\n}\n","import response from \"./response\";\n\n/**\n * 404 Not Found\n *\n * The server cannot find the requested resource. In the browser, this means the\n * URL is not recognized. In an API, this can also mean that the endpoint is\n * valid but the resource itself does not exist. Servers may also send this\n * response instead of 403 Forbidden to hide the existence of a resource from an\n * unauthorized client. This response code is probably the most well known due\n * to its frequent occurrence on the web.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404\n */\nexport default function notFound(body?: object | string): Response {\n\treturn response(404, body ?? \"Not found\");\n}\n","import response from \"./response\";\n\n/**\n * 200 OK\n *\n * The request succeeded. The result meaning of \"success\" depends on the HTTP\n * method:\n * - GET: The resource has been fetched and transmitted in the message body.\n * - HEAD: The representation headers are included in the response without any\n * message body.\n * - PUT or POST: The resource describing the result of the action is\n * transmitted in the message body.\n * - TRACE: The message body contains the request message as received by the\n * server.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200\n */\nexport default function ok(body?: object | string): Response {\n\treturn response(200, body);\n}\n","/**\n * Creates a redirect response with the supplied status code.\n */\nexport default function transfer(\n\tstatus: 300 | 301 | 302 | 303 | 304 | 307 | 308,\n\tlocation: string,\n): Response {\n\treturn new Response(null, {\n\t\tstatus,\n\t\theaders: {\n\t\t\tlocation,\n\t\t},\n\t});\n}\n","import transfer from \"./transfer\";\n\n/**\n * 303 See Other\n *\n * The server sent this response to direct the client to get the requested\n * resource at another URI with a GET request.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303\n */\nexport default function seeOther(location: string): Response {\n\treturn transfer(303, location);\n}\n","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;\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","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","import type LayoutHandler from \"../types/LayoutHandler\";\nimport type ManifestRoute from \"../types/ManifestRoute\";\nimport type RouteHandler from \"../types/RouteHandler\";\nimport pathToRegex from \"./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\ntype Match = {\n\thandler: RouteHandler;\n\tparams?: Record<string, string>;\n\tquery: URLSearchParams;\n};\n","import { $watch } from \"@torpor/view\";\nimport Page from \"./Page\";\n\nconst $page: Page = $watch(\n\t{\n\t\tstatus: 404,\n\t\turl: new URL(\"http://localhost\"),\n\t\terror: {\n\t\t\tmessage: \"\",\n\t\t},\n\t},\n\t{ shallow: true },\n);\n\nexport default $page;\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,uBAAiB;;;ACMF,SAAR,SAA0B,QAAgB,MAAkC;AAClF,MAAI,UAA8C;AAClD,MAAI,MAAM;AACT,QAAI,OAAO,SAAS,UAAU;AAC7B,gBAAU,EAAE,gBAAgB,mBAAmB;AAC/C,aAAO,KAAK,UAAU,IAAI;AAAA,IAC3B,OAAO;AACN,gBAAU,EAAE,gBAAgB,aAAa;AAAA,IAC1C;AAAA,EACD;AACA,SAAO,IAAI,SAAS,MAAM;AAAA,IACzB;AAAA,IACA;AAAA,EACD,CAAC;AACF;;;ACPe,SAAR,SAA0B,M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AS,GAAG;AAAA,IACZ,SAAS,GAAG;AAAA,EACb;AACD;","names":["path","path","path"]}
|
package/dist/test.d.cts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { a as ServerEvent } from './Server-BC_dixZQ.cjs';
|
|
2
|
-
import { S as Site } from './Site-BXX-S541.cjs';
|
|
3
|
-
import 'cookie';
|
|
4
|
-
import 'vite';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Runs a site route in test mode
|
|
8
|
-
* @param site The site configuration, with routing configured
|
|
9
|
-
* @param route The route path e.g. `/home`
|
|
10
|
-
* @param ev An optional ServerEvent, which you can use to set test cookies and headers
|
|
11
|
-
* @returns An HTTP response containing the requested data, HTML, or error status
|
|
12
|
-
*/
|
|
13
|
-
declare function runTest(site: Site, route: string, ev?: ServerEvent): Promise<Response>;
|
|
14
|
-
|
|
15
|
-
export { runTest };
|
package/src/response/moved.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import transfer from "./transfer";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 308 Permanent Redirect
|
|
5
|
-
*
|
|
6
|
-
* This means that the resource is now permanently located at another URI,
|
|
7
|
-
* specified by the Location: HTTP Response header. This has the same semantics
|
|
8
|
-
* as the 301 Moved Permanently HTTP response code, with the exception that the
|
|
9
|
-
* user agent must not change the HTTP method used: if a POST was used in the
|
|
10
|
-
* first request, a POST must be used in the second request.
|
|
11
|
-
*
|
|
12
|
-
* See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308
|
|
13
|
-
*/
|
|
14
|
-
export default function moved(location: string): Response {
|
|
15
|
-
return transfer(308, location);
|
|
16
|
-
}
|
package/src/response/redirect.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import transfer from "./transfer";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 307 Temporary Redirect
|
|
5
|
-
*
|
|
6
|
-
* The server sends this response to direct the client to get the requested
|
|
7
|
-
* resource at another URI with the same method that was used in the prior
|
|
8
|
-
* request. This has the same semantics as the 302 Found HTTP response code,
|
|
9
|
-
* with the exception that the user agent must not change the HTTP method used:
|
|
10
|
-
* if a POST was used in the first request, a POST must be used in the second
|
|
11
|
-
* request.
|
|
12
|
-
*
|
|
13
|
-
* See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307
|
|
14
|
-
*/
|
|
15
|
-
export default function redirect(location: string): Response {
|
|
16
|
-
return transfer(307, location);
|
|
17
|
-
}
|