@primate/core 0.6.3 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/private/App.d.ts +76 -149
- package/lib/private/App.js +22 -6
- package/lib/private/Flags.d.ts +5 -3
- package/lib/private/Flags.js +4 -2
- package/lib/private/app/Facade.d.ts +77 -156
- package/lib/private/app/Facade.js +4 -1
- package/lib/private/build/App.d.ts +4 -2
- package/lib/private/build/App.js +13 -4
- package/lib/private/build/client/index.js +24 -10
- package/lib/private/build/client/plugin/routes.d.ts +4 -0
- package/lib/private/build/client/plugin/routes.js +77 -0
- package/lib/private/build/hook.js +14 -6
- package/lib/private/build/index.d.ts +3 -2
- package/lib/private/build/index.js +9 -15
- package/lib/private/build/preclient/index.d.ts +3 -0
- package/lib/private/build/preclient/index.js +69 -0
- package/lib/private/build/preclient/plugin/routes.d.ts +4 -0
- package/lib/private/build/preclient/plugin/routes.js +44 -0
- package/lib/private/build/server/index.js +8 -5
- package/lib/private/build/server/plugin/assets.js +3 -3
- package/lib/private/build/server/plugin/native-addons.js +6 -8
- package/lib/private/build/server/plugin/node-imports.js +5 -7
- package/lib/private/build/server/plugin/route-client.d.ts +4 -0
- package/lib/private/build/server/plugin/route-client.js +111 -0
- package/lib/private/build/server/plugin/route.js +3 -10
- package/lib/private/build/server/plugin/virtual-pages.js +3 -3
- package/lib/private/build/server/plugin/virtual-routes.d.ts +2 -1
- package/lib/private/build/server/plugin/virtual-routes.js +27 -8
- package/lib/private/build/server/plugin/wasm.js +3 -2
- package/lib/private/build/shared/intercept.d.ts +4 -0
- package/lib/private/build/shared/intercept.js +29 -0
- package/lib/private/client/Data.d.ts +1 -1
- package/lib/private/client/boot.js +2 -2
- package/lib/private/client/create-form.d.ts +11 -1
- package/lib/private/client/create-form.js +21 -3
- package/lib/private/client/index.d.ts +2 -2
- package/lib/private/client/navigate.d.ts +1 -0
- package/lib/private/client/navigate.js +7 -6
- package/lib/private/client/submit.d.ts +2 -1
- package/lib/private/client/submit.js +8 -7
- package/lib/private/client/{http.d.ts → transport.d.ts} +3 -3
- package/lib/private/client/{http.js → transport.js} +7 -9
- package/lib/private/config/schema.d.ts +5 -13
- package/lib/private/config/schema.js +1 -5
- package/lib/private/db/DB.d.ts +3 -1
- package/lib/private/db/MemoryDB.d.ts +5 -2
- package/lib/private/db/MemoryDB.js +33 -19
- package/lib/private/db/SQLDB.d.ts +23 -0
- package/lib/private/db/SQLDB.js +2 -0
- package/lib/private/db/errors.d.ts +74 -7
- package/lib/private/db/errors.js +31 -7
- package/lib/private/db/migrate/apply.js +8 -9
- package/lib/private/db/migrate/bundle.js +2 -2
- package/lib/private/db/migrate/create.js +18 -20
- package/lib/private/db/migrate/status.js +9 -10
- package/lib/private/db/migrate/store.d.ts +3 -3
- package/lib/private/db/migrate/store.js +5 -5
- package/lib/private/db/test.js +256 -115
- package/lib/private/db/testSQL.d.ts +50 -0
- package/lib/private/db/testSQL.js +196 -0
- package/lib/private/errors.d.ts +66 -9
- package/lib/private/errors.js +37 -16
- package/lib/private/frontend.d.ts +4 -4
- package/lib/private/frontend.js +11 -8
- package/lib/private/i18n/errors.d.ts +7 -1
- package/lib/private/i18n/errors.js +1 -1
- package/lib/private/i18n/index/types.d.ts +1 -1
- package/lib/private/i18n/locale.d.ts +1 -1
- package/lib/private/i18n/module.js +6 -5
- package/lib/private/index.d.ts +10 -2
- package/lib/private/index.js +13 -1
- package/lib/private/logger.d.ts +24 -0
- package/lib/private/logger.js +66 -0
- package/lib/private/module/Setup.d.ts +3 -0
- package/lib/private/module/create.d.ts +2 -1
- package/lib/private/module/create.js +4 -0
- package/lib/private/paths.d.ts +2 -3
- package/lib/private/paths.js +6 -12
- package/lib/private/request/ContentType.d.ts +3 -0
- package/lib/private/request/ContentType.js +2 -0
- package/lib/private/request/RequestBag.d.ts +2 -18
- package/lib/private/request/RequestBag.js +4 -16
- package/lib/private/request/RequestBody.d.ts +20 -28
- package/lib/private/request/RequestBody.js +63 -86
- package/lib/private/request/RequestFacade.d.ts +2 -2
- package/lib/private/request/handle.js +2 -2
- package/lib/private/request/parse.js +2 -4
- package/lib/private/request/route.js +15 -8
- package/lib/private/response/binary.d.ts +2 -2
- package/lib/private/response/binary.js +6 -6
- package/lib/private/response/error.js +6 -2
- package/lib/private/response/json.js +2 -2
- package/lib/private/response/null.d.ts +3 -0
- package/lib/private/response/null.js +6 -0
- package/lib/private/response/redirect.js +4 -3
- package/lib/private/response/respond.js +4 -4
- package/lib/private/response/sse.js +2 -2
- package/lib/private/response/text.js +2 -2
- package/lib/private/route/ContentTypeMap.d.ts +10 -0
- package/lib/private/route/ContentTypeMap.js +2 -0
- package/lib/private/route/Handler.d.ts +3 -2
- package/lib/private/route/NarrowedRequest.d.ts +23 -0
- package/lib/private/route/NarrowedRequest.js +2 -0
- package/lib/private/route/Options.d.ts +6 -1
- package/lib/private/route/Path.d.ts +2 -2
- package/lib/private/route/hook.d.ts +3 -1
- package/lib/private/route/hook.js +1 -2
- package/lib/private/route/router.d.ts +7 -11
- package/lib/private/route/router.js +13 -20
- package/lib/private/route.client.d.ts +36 -0
- package/lib/private/route.client.js +8 -0
- package/lib/private/route.d.ts +21 -5
- package/lib/private/route.js +21 -5
- package/lib/private/serve/App.d.ts +1 -2
- package/lib/private/serve/App.js +64 -58
- package/lib/private/serve/Init.d.ts +2 -0
- package/lib/private/serve/dev-module.js +2 -3
- package/lib/private/serve/index.js +5 -6
- package/lib/private/server/TAG.d.ts +1 -1
- package/lib/private/server/TAG.js +1 -1
- package/lib/private/session/index.d.ts +1 -1
- package/lib/private/session/index.js +3 -2
- package/lib/private/session/module.js +3 -3
- package/lib/private/session/schema.d.ts +3 -3
- package/lib/private/session/schema.js +4 -3
- package/lib/private/store/ExtractRelation.d.ts +7 -0
- package/lib/private/store/ExtractRelation.js +2 -0
- package/lib/private/store/ExtractSchema.d.ts +10 -0
- package/lib/private/{orm → store}/ForeignKey.d.ts +1 -1
- package/lib/private/store/Init.d.ts +13 -0
- package/lib/private/store/Init.js +2 -0
- package/lib/private/{orm/store.d.ts → store/Store.d.ts} +50 -50
- package/lib/private/{orm/store.js → store/Store.js} +163 -107
- package/lib/private/store/StoreInput.d.ts +11 -0
- package/lib/private/store/key.d.ts +8 -0
- package/lib/private/store/key.js +8 -0
- package/lib/private/{orm → store}/parse.d.ts +3 -3
- package/lib/private/{orm → store}/parse.js +7 -2
- package/lib/private/store/relation.d.ts +29 -0
- package/lib/private/store/relation.js +26 -0
- package/lib/private/store.d.ts +24 -0
- package/lib/private/store.js +10 -0
- package/lib/public/db/errors.d.ts +1 -1
- package/lib/public/db/errors.js +1 -1
- package/lib/public/db/testSQL.d.ts +2 -0
- package/lib/public/db/testSQL.js +2 -0
- package/lib/public/db.d.ts +1 -0
- package/lib/public/index.d.ts +1 -0
- package/lib/public/index.js +1 -1
- package/lib/public/response.d.ts +6 -6
- package/lib/public/response.js +4 -1
- package/lib/public/route.client.d.ts +2 -0
- package/lib/public/route.client.js +2 -0
- package/lib/public/store.d.ts +2 -0
- package/lib/public/store.js +2 -0
- package/package.json +24 -17
- package/lib/private/bye.d.ts +0 -3
- package/lib/private/bye.js +0 -4
- package/lib/private/log.d.ts +0 -20
- package/lib/private/log.js +0 -47
- package/lib/private/orm/ExtractSchema.d.ts +0 -9
- package/lib/private/orm/StoreInput.d.ts +0 -10
- package/lib/private/orm/key.d.ts +0 -8
- package/lib/private/orm/key.js +0 -8
- package/lib/private/orm/relation.d.ts +0 -43
- package/lib/private/orm/relation.js +0 -26
- package/lib/private/request/Verb.d.ts +0 -4
- package/lib/private/request/Verb.js +0 -2
- package/lib/private/request/verbs.d.ts +0 -3
- package/lib/private/request/verbs.js +0 -12
- package/lib/private/route/wrap.d.ts +0 -2
- package/lib/private/route/wrap.js +0 -12
- package/lib/public/log.d.ts +0 -2
- package/lib/public/log.js +0 -2
- package/lib/public/orm/key.d.ts +0 -2
- package/lib/public/orm/key.js +0 -2
- package/lib/public/orm/relation.d.ts +0 -2
- package/lib/public/orm/relation.js +0 -2
- package/lib/public/orm/store.d.ts +0 -2
- package/lib/public/orm/store.js +0 -2
- package/lib/public/request/verbs.d.ts +0 -2
- package/lib/public/request/verbs.js +0 -2
- /package/lib/private/{orm → store}/ExtractSchema.js +0 -0
- /package/lib/private/{orm → store}/ForeignKey.js +0 -0
- /package/lib/private/{orm → store}/PrimaryKey.d.ts +0 -0
- /package/lib/private/{orm → store}/PrimaryKey.js +0 -0
- /package/lib/private/{orm → store}/StoreInput.js +0 -0
package/lib/private/serve/App.js
CHANGED
|
@@ -4,12 +4,11 @@ import E from "#errors";
|
|
|
4
4
|
import hash from "#hash";
|
|
5
5
|
import i18n_module from "#i18n/module";
|
|
6
6
|
import location from "#location";
|
|
7
|
-
import log from "#log";
|
|
8
7
|
import create from "#module/create";
|
|
9
8
|
import handle from "#request/handle";
|
|
10
9
|
import parse from "#request/parse";
|
|
11
10
|
import RequestBag from "#request/RequestBag";
|
|
12
|
-
import
|
|
11
|
+
import { BodyPatch } from "#request/RequestBody";
|
|
13
12
|
import route from "#request/route";
|
|
14
13
|
import request_storage from "#request/storage";
|
|
15
14
|
import router from "#route/router";
|
|
@@ -19,7 +18,7 @@ import tags from "#tags";
|
|
|
19
18
|
import assert from "@rcompat/assert";
|
|
20
19
|
import fs from "@rcompat/fs";
|
|
21
20
|
import FileRouter from "@rcompat/fs/FileRouter";
|
|
22
|
-
import
|
|
21
|
+
import http from "@rcompat/http";
|
|
23
22
|
import serve from "@rcompat/http/serve";
|
|
24
23
|
import is from "@rcompat/is";
|
|
25
24
|
import utf8 from "@rcompat/string/utf8";
|
|
@@ -50,6 +49,13 @@ const render_head = (assets, head) => {
|
|
|
50
49
|
: tags.script({ code, inline, integrity, src, type })).join("\n")).concat("\n", head ?? "");
|
|
51
50
|
};
|
|
52
51
|
const s_http = Symbol("s_http");
|
|
52
|
+
const content_type_method = {
|
|
53
|
+
"application/json": "json",
|
|
54
|
+
"text/plain": "text",
|
|
55
|
+
"application/x-www-form-urlencoded": "form",
|
|
56
|
+
"multipart/form-data": "multipart",
|
|
57
|
+
"application/octet-stream": "blob",
|
|
58
|
+
};
|
|
53
59
|
;
|
|
54
60
|
export default class ServeApp extends App {
|
|
55
61
|
#init;
|
|
@@ -68,21 +74,22 @@ export default class ServeApp extends App {
|
|
|
68
74
|
super(dir, init.facade[s_config], {
|
|
69
75
|
mode: init.mode,
|
|
70
76
|
target: init.target,
|
|
71
|
-
|
|
77
|
+
outdir: dir.path,
|
|
78
|
+
log: init.log,
|
|
72
79
|
});
|
|
73
80
|
this.#init = init;
|
|
74
81
|
this.#views = Object.fromEntries(init.views ?? []);
|
|
75
82
|
this.#stores = Object.fromEntries((init.stores?.map(([k, s]) => [k, s.default])) ?? []);
|
|
76
83
|
this.#serve_assets = init.assets;
|
|
77
84
|
this.#pages = init.pages;
|
|
78
|
-
const
|
|
85
|
+
const http_config = this.#init.facade[s_config].http;
|
|
79
86
|
this.#i18n_config = init.i18n;
|
|
80
87
|
this.set(s_http, {
|
|
81
|
-
host:
|
|
82
|
-
port:
|
|
88
|
+
host: http_config.host,
|
|
89
|
+
port: http_config.port,
|
|
83
90
|
ssl: this.secure ? {
|
|
84
|
-
cert: this.root.join(
|
|
85
|
-
key: this.root.join(
|
|
91
|
+
cert: this.root.join(http_config.ssl.cert),
|
|
92
|
+
key: this.root.join(http_config.ssl.key),
|
|
86
93
|
} : {},
|
|
87
94
|
});
|
|
88
95
|
this.#router = FileRouter.init({
|
|
@@ -123,19 +130,9 @@ export default class ServeApp extends App {
|
|
|
123
130
|
},
|
|
124
131
|
}));
|
|
125
132
|
}
|
|
126
|
-
;
|
|
127
|
-
get secure() {
|
|
128
|
-
const ssl = this.config("http.ssl");
|
|
129
|
-
return ssl.key !== undefined && ssl.cert !== undefined;
|
|
130
|
-
}
|
|
131
133
|
get assets() {
|
|
132
134
|
return this.#assets;
|
|
133
135
|
}
|
|
134
|
-
get url() {
|
|
135
|
-
const { host, port } = this.config("http");
|
|
136
|
-
return `http${this.secure ? "s" : ""}://${host}:${port}`;
|
|
137
|
-
}
|
|
138
|
-
;
|
|
139
136
|
get router() {
|
|
140
137
|
return this.#router;
|
|
141
138
|
}
|
|
@@ -152,11 +149,11 @@ export default class ServeApp extends App {
|
|
|
152
149
|
const f = fs.ref(name).path;
|
|
153
150
|
const frontends = Object.keys(this.frontends);
|
|
154
151
|
const extension = frontends.find(client => f.endsWith(client));
|
|
155
|
-
const base = extension
|
|
152
|
+
const base = is.undefined(extension) ? name : f.slice(0, -extension.length);
|
|
156
153
|
const view = this.#views[base];
|
|
157
|
-
if (view
|
|
154
|
+
if (is.undefined(view))
|
|
158
155
|
throw E.view_missing(name);
|
|
159
|
-
if (view.default
|
|
156
|
+
if (is.undefined(view.default))
|
|
160
157
|
throw E.view_missing_default_export(name);
|
|
161
158
|
return view.default;
|
|
162
159
|
}
|
|
@@ -174,7 +171,7 @@ export default class ServeApp extends App {
|
|
|
174
171
|
render(content) {
|
|
175
172
|
const { body, head, page, partial, placeholders = {} } = content;
|
|
176
173
|
["body", "head"].forEach(key => assert.undefined(placeholders[key]));
|
|
177
|
-
return partial ? body : Object.entries(placeholders)
|
|
174
|
+
return partial === true ? body : Object.entries(placeholders)
|
|
178
175
|
// replace given placeholders, defaulting to ""
|
|
179
176
|
.reduce((rendered, [key, value]) => rendered
|
|
180
177
|
.replaceAll(`%${key}%`, value?.toString() ?? ""), this.page(page))
|
|
@@ -190,12 +187,12 @@ export default class ServeApp extends App {
|
|
|
190
187
|
respond(body, init) {
|
|
191
188
|
const { headers, status } = p({
|
|
192
189
|
headers: p.dict(),
|
|
193
|
-
status: p.uint.values(Status).default(Status.OK),
|
|
190
|
+
status: p.uint.values(http.Status).default(http.Status.OK),
|
|
194
191
|
}).parse(init);
|
|
195
192
|
const body_length = this.body_length(body);
|
|
196
193
|
return new Response(body, {
|
|
197
194
|
headers: {
|
|
198
|
-
"Content-Type": MIME.TEXT_HTML,
|
|
195
|
+
"Content-Type": http.MIME.TEXT_HTML,
|
|
199
196
|
...this.headers(),
|
|
200
197
|
...body_length ? {
|
|
201
198
|
...headers, "Content-Length": String(body_length),
|
|
@@ -206,14 +203,14 @@ export default class ServeApp extends App {
|
|
|
206
203
|
;
|
|
207
204
|
view(options) {
|
|
208
205
|
// split render and respond options
|
|
209
|
-
const { headers = {}, status = Status.OK, statusText, ...rest } = options;
|
|
206
|
+
const { headers = {}, status = http.Status.OK, statusText, ...rest } = options;
|
|
210
207
|
return this.respond(this.render(rest), { headers, status });
|
|
211
208
|
}
|
|
212
209
|
;
|
|
213
210
|
media(content_type, response = {}) {
|
|
214
211
|
return {
|
|
215
212
|
headers: { ...response.headers, "Content-Type": content_type },
|
|
216
|
-
status: response.status ?? Status.OK,
|
|
213
|
+
status: response.status ?? http.Status.OK,
|
|
217
214
|
};
|
|
218
215
|
}
|
|
219
216
|
;
|
|
@@ -251,13 +248,13 @@ export default class ServeApp extends App {
|
|
|
251
248
|
return this.#pages[page_name];
|
|
252
249
|
}
|
|
253
250
|
async #try_serve(ref) {
|
|
254
|
-
if (await ref.exists() && await ref.
|
|
251
|
+
if (await ref.exists() && await ref.type() === "file") {
|
|
255
252
|
return new Response(ref.stream(), {
|
|
256
253
|
headers: {
|
|
257
|
-
"Content-Type":
|
|
254
|
+
"Content-Type": http.toMIME(ref.name),
|
|
258
255
|
"Content-Length": String(await ref.size()),
|
|
259
256
|
},
|
|
260
|
-
status: Status.OK,
|
|
257
|
+
status: http.Status.OK,
|
|
261
258
|
});
|
|
262
259
|
}
|
|
263
260
|
}
|
|
@@ -278,7 +275,7 @@ export default class ServeApp extends App {
|
|
|
278
275
|
}
|
|
279
276
|
const assets = this.#serve_assets;
|
|
280
277
|
const asset = assets.client[pathname] ?? assets.static[pathname];
|
|
281
|
-
if (asset
|
|
278
|
+
if (is.undefined(asset))
|
|
282
279
|
return undefined;
|
|
283
280
|
const binary = atob(asset.data);
|
|
284
281
|
const bytes = new Uint8Array(binary.length);
|
|
@@ -290,7 +287,7 @@ export default class ServeApp extends App {
|
|
|
290
287
|
"Content-Type": asset.mime,
|
|
291
288
|
"Content-Length": String(bytes.length),
|
|
292
289
|
},
|
|
293
|
-
status: Status.OK,
|
|
290
|
+
status: http.Status.OK,
|
|
294
291
|
});
|
|
295
292
|
}
|
|
296
293
|
async start() {
|
|
@@ -334,13 +331,13 @@ export default class ServeApp extends App {
|
|
|
334
331
|
return await handle(this, parse(request));
|
|
335
332
|
}
|
|
336
333
|
catch (error) {
|
|
337
|
-
log.error(error);
|
|
334
|
+
this.log.error(error);
|
|
338
335
|
return new Response(null, {
|
|
339
336
|
headers: {
|
|
340
337
|
"Content-Length": String(0),
|
|
341
338
|
"Cache-Control": "no-cache",
|
|
342
339
|
},
|
|
343
|
-
status: Status.INTERNAL_SERVER_ERROR,
|
|
340
|
+
status: http.Status.INTERNAL_SERVER_ERROR,
|
|
344
341
|
});
|
|
345
342
|
}
|
|
346
343
|
}, {
|
|
@@ -350,55 +347,64 @@ export default class ServeApp extends App {
|
|
|
350
347
|
function bright(x) {
|
|
351
348
|
return `\x1b[38;2;0;200;255m${x}\x1b[0m`;
|
|
352
349
|
}
|
|
353
|
-
log.print
|
|
350
|
+
this.log.print `» app url ${bright(this.url)}\n`;
|
|
354
351
|
}
|
|
355
352
|
;
|
|
356
353
|
stop() {
|
|
357
354
|
this.#server.stop();
|
|
358
|
-
log.system
|
|
355
|
+
this.log.system `stopped ${this.url}`;
|
|
359
356
|
}
|
|
360
357
|
;
|
|
361
358
|
upgrade(request, actions) {
|
|
362
359
|
return this.#server.upgrade(request, actions);
|
|
363
360
|
}
|
|
364
361
|
async route(request) {
|
|
365
|
-
const
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
return;
|
|
362
|
+
const pathname = normalize(request.url.pathname);
|
|
363
|
+
const matched = this.router.match(request.original);
|
|
364
|
+
if (is.undefined(matched)) {
|
|
365
|
+
this.log.trace `no ${request.method} route to ${pathname}`;
|
|
366
|
+
return undefined;
|
|
371
367
|
}
|
|
372
|
-
const
|
|
373
|
-
const specials =
|
|
368
|
+
const method = request.method.toLowerCase();
|
|
369
|
+
const specials = matched.specials;
|
|
374
370
|
const errors = (specials.error ?? [])
|
|
375
|
-
.map(v => router.get(v)[
|
|
371
|
+
.map(v => router.get(v)[method]?.handler)
|
|
376
372
|
.filter(Boolean)
|
|
377
373
|
.toReversed();
|
|
378
374
|
const layouts = (specials.layout ?? [])
|
|
379
|
-
.map(v => router.get(v)[
|
|
375
|
+
.map(v => router.get(v)[method]?.handler)
|
|
380
376
|
.filter(Boolean)
|
|
381
377
|
.toReversed();
|
|
382
378
|
const hooks = (specials.hook ?? [])
|
|
383
379
|
.toReversed()
|
|
384
380
|
.flatMap(v => router.getHooks(v));
|
|
385
|
-
const
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
381
|
+
const methods = router.get(matched.path);
|
|
382
|
+
const is_head = method === "head";
|
|
383
|
+
const actual_method = is_head && is.undefined(methods.head) ? "get" : method;
|
|
384
|
+
const route_path = methods[actual_method];
|
|
385
|
+
if (is.undefined(route_path)) {
|
|
386
|
+
this.log.trace `${matched.path} has no method ${method}`;
|
|
387
|
+
return undefined;
|
|
388
|
+
}
|
|
389
389
|
const handler = route_path.handler;
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
390
|
+
const { contentType, body } = route_path.options;
|
|
391
|
+
if (contentType !== undefined) {
|
|
392
|
+
const raw = request.headers.try("content-type") ?? "";
|
|
393
|
+
const actual = raw.split(";")[0].trim().toLowerCase();
|
|
394
|
+
if (actual !== contentType) {
|
|
395
|
+
throw E.request_content_type_mismatch(contentType, actual);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
394
398
|
const refined = Object.assign(Object.create(request), {
|
|
395
|
-
|
|
396
|
-
path: new RequestBag(route.params, "path", {
|
|
399
|
+
path: new RequestBag(matched.params, "path", {
|
|
397
400
|
normalize: k => k.toLowerCase(),
|
|
398
|
-
raw: url.pathname,
|
|
401
|
+
raw: request.url.pathname,
|
|
399
402
|
}),
|
|
403
|
+
...(body !== undefined && contentType !== undefined
|
|
404
|
+
? { body: request.body[BodyPatch]({ contentType, schema: body }) }
|
|
405
|
+
: {}),
|
|
400
406
|
});
|
|
401
|
-
return { errors, hooks, layouts, handler, request: refined };
|
|
407
|
+
return { errors, hooks, layouts, handler, request: refined, is_head };
|
|
402
408
|
}
|
|
403
409
|
}
|
|
404
410
|
//# sourceMappingURL=App.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type AppFacade from "#app/Facade";
|
|
2
2
|
import type I18NConfig from "#i18n/Config";
|
|
3
|
+
import type { Schema as LogSchema } from "#logger";
|
|
3
4
|
import type Mode from "#Mode";
|
|
4
5
|
import type SessionConfig from "#session/Config";
|
|
5
6
|
import type { Dict } from "@rcompat/type";
|
|
@@ -25,6 +26,7 @@ type ServeInit = {
|
|
|
25
26
|
}][];
|
|
26
27
|
mode: Mode;
|
|
27
28
|
target: string;
|
|
29
|
+
log: typeof LogSchema.infer;
|
|
28
30
|
pages: Dict<string>;
|
|
29
31
|
session?: SessionConfig;
|
|
30
32
|
i18n?: I18NConfig;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import log from "#log";
|
|
2
1
|
import create from "#module/create";
|
|
3
|
-
import
|
|
2
|
+
import cli from "@rcompat/cli";
|
|
4
3
|
function pass(address, request) {
|
|
5
4
|
return fetch(address, {
|
|
6
5
|
body: request.body,
|
|
@@ -20,7 +19,7 @@ export default function dev() {
|
|
|
20
19
|
const assets = app.assets.map(asset => asset.src);
|
|
21
20
|
reload = `http://${host}:${port}`;
|
|
22
21
|
paths = ["/esbuild"].concat(assets);
|
|
23
|
-
log.print
|
|
22
|
+
app.log.print `↻ live reload ${cli.fg.dim(reload)}\n`;
|
|
24
23
|
});
|
|
25
24
|
onHandle((request, next) => {
|
|
26
25
|
const { pathname } = new URL(request.url);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { s_attach, s_config } from "#app/Facade";
|
|
2
2
|
import E from "#db/errors";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import store from "#orm/store";
|
|
3
|
+
import key from "#store/key";
|
|
4
|
+
import store from "#store";
|
|
6
5
|
import ServeApp from "#serve/App";
|
|
7
6
|
import serve_hook from "#serve/hook";
|
|
8
7
|
import p from "pema";
|
|
@@ -16,14 +15,14 @@ export default async (root, options) => {
|
|
|
16
15
|
if (migrations !== undefined) {
|
|
17
16
|
const { table, db } = migrations;
|
|
18
17
|
const Migration = store({
|
|
19
|
-
|
|
18
|
+
table,
|
|
20
19
|
db,
|
|
21
20
|
schema: {
|
|
22
21
|
id: key.primary(p.u16, { generate: false }),
|
|
23
22
|
applied: p.date,
|
|
24
23
|
},
|
|
25
24
|
});
|
|
26
|
-
await Migration.
|
|
25
|
+
await Migration.create();
|
|
27
26
|
const last = await Migration.find({ limit: 1, sort: { id: "desc" } });
|
|
28
27
|
const last_id = last.length === 0 ? 0 : last[0].id;
|
|
29
28
|
const build_json = app.root.join("build.json");
|
|
@@ -34,7 +33,7 @@ export default async (root, options) => {
|
|
|
34
33
|
return serve_hook(app);
|
|
35
34
|
}
|
|
36
35
|
catch (cause) {
|
|
37
|
-
log.error(cause);
|
|
36
|
+
app.log.error(cause);
|
|
38
37
|
}
|
|
39
38
|
};
|
|
40
39
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export default "0.
|
|
1
|
+
export default "0.6";
|
|
2
2
|
//# sourceMappingURL=TAG.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Store } from "#orm/store";
|
|
2
1
|
import configSchema from "#session/schema";
|
|
3
2
|
import type SessionFacade from "#session/SessionFacade";
|
|
3
|
+
import type Store from "#store/Store";
|
|
4
4
|
import type { InferStore, StoreSchema } from "pema";
|
|
5
5
|
type ConfigInput = typeof configSchema.input;
|
|
6
6
|
type X<T> = {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import E from "#errors";
|
|
1
2
|
import configSchema from "#session/schema";
|
|
2
3
|
import local_storage from "#session/storage";
|
|
3
4
|
import s_config from "#symbol/config";
|
|
@@ -8,8 +9,8 @@ export default function session(config) {
|
|
|
8
9
|
const storage = local_storage();
|
|
9
10
|
const current = () => {
|
|
10
11
|
const s = storage.getStore();
|
|
11
|
-
if (
|
|
12
|
-
throw
|
|
12
|
+
if (s === undefined)
|
|
13
|
+
throw E.session_handle_unavailable();
|
|
13
14
|
return s;
|
|
14
15
|
};
|
|
15
16
|
const facade = {
|
|
@@ -20,7 +20,7 @@ function cookie(name, value, options) {
|
|
|
20
20
|
export default function session_module(config) {
|
|
21
21
|
let secure;
|
|
22
22
|
const store = config.store;
|
|
23
|
-
const props = store.
|
|
23
|
+
const props = store.schema.properties;
|
|
24
24
|
if (!("session_id" in props))
|
|
25
25
|
throw E.session_missing_id();
|
|
26
26
|
try {
|
|
@@ -34,7 +34,7 @@ export default function session_module(config) {
|
|
|
34
34
|
setup({ onServe, onHandle }) {
|
|
35
35
|
onServe(async (app) => {
|
|
36
36
|
secure = app.secure;
|
|
37
|
-
await store.
|
|
37
|
+
await store.create();
|
|
38
38
|
});
|
|
39
39
|
onHandle(async (request, next) => {
|
|
40
40
|
const { name, ...cookie_config } = config.cookie;
|
|
@@ -52,7 +52,7 @@ export default function session_module(config) {
|
|
|
52
52
|
data = rest;
|
|
53
53
|
db_id = _id;
|
|
54
54
|
}
|
|
55
|
-
const session_type = p.omit(store.
|
|
55
|
+
const session_type = p.omit(store.schema, "id", "session_id");
|
|
56
56
|
const session = new SessionHandle(sid, data, session_type);
|
|
57
57
|
const response = await new Promise((resolve, reject) => {
|
|
58
58
|
storage().run(session, async () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Store from "#store/Store";
|
|
2
2
|
declare const _default: import("pema").ObjectType<import("pema").NormalizeSchemaObject<{
|
|
3
3
|
readonly cookie: {
|
|
4
4
|
readonly httpOnly: import("pema").DefaultType<import("pema").BooleanType, true>;
|
|
@@ -6,7 +6,7 @@ declare const _default: import("pema").ObjectType<import("pema").NormalizeSchema
|
|
|
6
6
|
readonly path: import("pema").DefaultType<import("pema").StringType, "/">;
|
|
7
7
|
readonly sameSite: import("pema").DefaultType<import("pema").UnionType<[import("pema").LiteralType<"Strict">, import("pema").LiteralType<"Lax">, import("pema").LiteralType<"None">]>, "Lax" | "None" | "Strict">;
|
|
8
8
|
};
|
|
9
|
-
readonly store: import("pema").DefaultType<import("pema").ConstructorType<typeof Store>, Store<import("../
|
|
9
|
+
readonly store: import("pema").DefaultType<import("pema").ConstructorType<typeof Store>, Store<import("../store/StoreInput.js").default, string>>;
|
|
10
10
|
}>, {
|
|
11
11
|
cookie: {
|
|
12
12
|
httpOnly: boolean;
|
|
@@ -14,7 +14,7 @@ declare const _default: import("pema").ObjectType<import("pema").NormalizeSchema
|
|
|
14
14
|
path: string;
|
|
15
15
|
sameSite: "Lax" | "None" | "Strict";
|
|
16
16
|
};
|
|
17
|
-
store: Store<import("../
|
|
17
|
+
store: Store<import("../store/StoreInput.js").default, string>;
|
|
18
18
|
}>;
|
|
19
19
|
export default _default;
|
|
20
20
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import MemoryDB from "#db/MemoryDB";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import store from "#store";
|
|
3
|
+
import Store from "#store/Store";
|
|
4
|
+
import key from "#store/key";
|
|
4
5
|
import p from "pema";
|
|
5
6
|
export default p({
|
|
6
7
|
cookie: {
|
|
@@ -16,7 +17,7 @@ export default p({
|
|
|
16
17
|
session_id: p.uuid,
|
|
17
18
|
},
|
|
18
19
|
db: new MemoryDB(),
|
|
19
|
-
|
|
20
|
+
table: "session",
|
|
20
21
|
});
|
|
21
22
|
}),
|
|
22
23
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type StoreInput from "#store/StoreInput";
|
|
2
|
+
import type { ManyRelation, OneRelation } from "#store/relation";
|
|
3
|
+
type ExtractRelations<T extends StoreInput> = {
|
|
4
|
+
[K in keyof T as T[K] extends OneRelation<string, string> | ManyRelation<string, string> ? K : never]: T[K] extends OneRelation<string, string> | ManyRelation<string, string> ? T[K] : never;
|
|
5
|
+
};
|
|
6
|
+
export type { ExtractRelations as default };
|
|
7
|
+
//# sourceMappingURL=ExtractRelation.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type ForeignKey from "#store/ForeignKey";
|
|
2
|
+
import type PrimaryKey from "#store/PrimaryKey";
|
|
3
|
+
import type { ManyRelation, OneRelation } from "#store/relation";
|
|
4
|
+
import type StoreInput from "#store/StoreInput";
|
|
5
|
+
import type { DataKey, Storable } from "pema";
|
|
6
|
+
type ExtractSchema<T extends StoreInput> = {
|
|
7
|
+
[K in keyof T as T[K] extends OneRelation<string, string> | ManyRelation<string, string> ? never : K]: T[K] extends PrimaryKey<infer P> ? P : T[K] extends ForeignKey<infer P> ? P : T[K] extends Storable<DataKey> ? T[K] : never;
|
|
8
|
+
};
|
|
9
|
+
export type { ExtractSchema as default };
|
|
10
|
+
//# sourceMappingURL=ExtractSchema.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AllowedPKType } from "#
|
|
1
|
+
import type { AllowedPKType } from "#store/PrimaryKey";
|
|
2
2
|
import type { OptionalType } from "pema";
|
|
3
3
|
export type AllowedFKType = AllowedPKType | OptionalType<AllowedPKType>;
|
|
4
4
|
export default class ForeignKey<T extends AllowedFKType> {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type DB from "#db/DB";
|
|
2
|
+
import type StoreInput from "#store/StoreInput";
|
|
3
|
+
import type { Dict } from "@rcompat/type";
|
|
4
|
+
type Init<S extends StoreInput, N extends string> = {
|
|
5
|
+
table: N;
|
|
6
|
+
db: DB;
|
|
7
|
+
id?: symbol;
|
|
8
|
+
schema: S;
|
|
9
|
+
migrate?: boolean;
|
|
10
|
+
extend?: Dict;
|
|
11
|
+
};
|
|
12
|
+
export type { Init as default };
|
|
13
|
+
//# sourceMappingURL=Init.d.ts.map
|