@primate/core 0.5.0 → 0.6.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/lib/private/App.d.ts +263 -26
- package/lib/private/App.js +42 -14
- package/lib/private/Flags.d.ts +8 -4
- package/lib/private/Module.d.ts +4 -16
- package/lib/private/Module.js +1 -17
- package/lib/private/app/EnvSchema.d.ts +5 -0
- package/lib/private/app/EnvSchema.js +2 -0
- package/lib/private/app/Facade.browser.d.ts +11 -0
- package/lib/private/app/Facade.browser.js +19 -0
- package/lib/private/app/Facade.d.ts +272 -27
- package/lib/private/app/Facade.js +23 -0
- package/lib/private/build/client/index.js +8 -3
- package/lib/private/build/client/plugin/app-request.d.ts +4 -0
- package/lib/private/build/client/plugin/app-request.js +19 -0
- package/lib/private/build/client/plugin/view.d.ts +4 -0
- package/lib/private/build/client/plugin/view.js +13 -0
- package/lib/private/build/hook.d.ts +1 -2
- package/lib/private/build/hook.js +21 -16
- package/lib/private/build/index.d.ts +2 -1
- package/lib/private/build/index.js +20 -21
- package/lib/private/build/server/index.js +7 -9
- package/lib/private/build/server/plugin/app-request.d.ts +4 -0
- package/lib/private/build/server/plugin/app-request.js +19 -0
- package/lib/private/build/server/plugin/assets.js +1 -1
- package/lib/private/build/server/plugin/live-reload.js +9 -9
- package/lib/private/build/server/plugin/native-addons.js +4 -7
- package/lib/private/build/server/plugin/route.js +2 -2
- package/lib/private/build/server/plugin/store.js +9 -31
- package/lib/private/build/server/plugin/stores.js +11 -7
- package/lib/private/build/server/plugin/view.js +1 -1
- package/lib/private/build/shared/plugin/app-request.d.ts +4 -0
- package/lib/private/build/shared/plugin/app-request.js +19 -0
- package/lib/private/client/Data.d.ts +3 -2
- package/lib/private/{frontend → client}/Render.d.ts +1 -1
- package/lib/private/{frontend → client}/ViewResponse.d.ts +1 -1
- package/lib/private/client/app.js +1 -2
- package/lib/private/client/boot.d.ts +5 -0
- package/lib/private/client/boot.js +64 -0
- package/lib/private/client/create-form.d.ts +1 -0
- package/lib/private/client/create-form.js +19 -20
- package/lib/private/client/extract-issues.js +2 -1
- package/lib/private/client/http.d.ts +13 -0
- package/lib/private/client/http.js +57 -0
- package/lib/private/client/index.d.ts +23 -0
- package/lib/private/client/index.js +16 -0
- package/lib/private/client/navigate.d.ts +13 -0
- package/lib/private/client/navigate.js +67 -0
- package/lib/private/client/root.d.ts +9 -0
- package/lib/private/client/root.js +11 -0
- package/lib/private/client/submit.d.ts +2 -0
- package/lib/private/client/submit.js +41 -0
- package/lib/private/config/index.d.ts +7 -2
- package/lib/private/config/index.js +3 -2
- package/lib/private/config/schema.d.ts +82 -26
- package/lib/private/config/schema.js +17 -4
- package/lib/private/cookie.d.ts +12 -6
- package/lib/private/db/DB.d.ts +21 -5
- package/lib/private/db/DB.js +1 -0
- package/lib/private/db/MemoryDB.d.ts +2 -4
- package/lib/private/db/MemoryDB.js +40 -22
- package/lib/private/db/common.d.ts +7 -0
- package/lib/private/db/common.js +31 -0
- package/lib/private/db/errors.d.ts +104 -0
- package/lib/private/db/errors.js +237 -0
- package/lib/private/db/migrate/apply.d.ts +2 -0
- package/lib/private/db/migrate/apply.js +32 -0
- package/lib/private/db/migrate/bundle.d.ts +3 -0
- package/lib/private/db/migrate/bundle.js +22 -0
- package/lib/private/db/migrate/create.d.ts +2 -0
- package/lib/private/db/migrate/create.js +154 -0
- package/lib/private/db/migrate/index.d.ts +10 -0
- package/lib/private/db/migrate/index.js +6 -0
- package/lib/private/db/migrate/status.d.ts +2 -0
- package/lib/private/db/migrate/status.js +38 -0
- package/lib/private/db/migrate/store.d.ts +5 -0
- package/lib/private/db/migrate/store.js +33 -0
- package/lib/private/db/sql.js +3 -3
- package/lib/private/db/test.js +461 -95
- package/lib/private/errors.d.ts +88 -0
- package/lib/private/errors.js +211 -0
- package/lib/private/frontend.d.ts +72 -0
- package/lib/private/frontend.js +245 -0
- package/lib/private/i18n/Formatter.js +2 -2
- package/lib/private/i18n/errors.d.ts +16 -0
- package/lib/private/i18n/errors.js +27 -0
- package/lib/private/i18n/module.d.ts +3 -0
- package/lib/private/i18n/module.js +115 -0
- package/lib/private/i18n/schema.d.ts +10 -5
- package/lib/private/i18n/validate.js +5 -7
- package/lib/private/index.d.ts +14 -0
- package/lib/private/index.js +2 -0
- package/lib/private/log.js +6 -5
- package/lib/private/module/Setup.d.ts +21 -0
- package/lib/private/module/Setup.js +2 -0
- package/lib/private/module/create.d.ts +16 -0
- package/lib/private/module/create.js +28 -0
- package/lib/private/orm/ExtractSchema.d.ts +9 -0
- package/lib/private/orm/ExtractSchema.js +2 -0
- package/lib/private/orm/ForeignKey.d.ts +5 -2
- package/lib/private/orm/ForeignKey.js +3 -0
- package/lib/private/orm/PrimaryKey.d.ts +5 -3
- package/lib/private/orm/PrimaryKey.js +9 -6
- package/lib/private/orm/StoreInput.d.ts +10 -0
- package/lib/private/orm/StoreInput.js +2 -0
- package/lib/private/orm/key.d.ts +6 -6
- package/lib/private/orm/key.js +7 -3
- package/lib/private/orm/parse.d.ts +5 -4
- package/lib/private/orm/parse.js +2 -2
- package/lib/private/orm/relation.d.ts +2 -2
- package/lib/private/orm/{Store.d.ts → store.d.ts} +33 -17
- package/lib/private/orm/{Store.js → store.js} +91 -67
- package/lib/private/paths.js +3 -3
- package/lib/private/request/RequestBag.d.ts +4 -0
- package/lib/private/request/RequestBag.js +5 -2
- package/lib/private/request/RequestBody.d.ts +6 -9
- package/lib/private/request/RequestBody.js +49 -54
- package/lib/private/request/RequestFacade.d.ts +3 -8
- package/lib/private/request/RequestPublic.d.ts +9 -0
- package/lib/private/request/RequestPublic.js +2 -0
- package/lib/private/request/RequestView.d.ts +11 -0
- package/lib/private/request/RequestView.js +3 -0
- package/lib/private/request/handle.d.ts +4 -0
- package/lib/private/request/handle.js +18 -0
- package/lib/private/request/parse.js +1 -0
- package/lib/private/request/route.js +8 -9
- package/lib/private/request/router.js +21 -49
- package/lib/private/request/storage.d.ts +4 -0
- package/lib/private/request/storage.js +5 -0
- package/lib/private/response/ResponseFunction.d.ts +1 -1
- package/lib/private/response/binary.js +1 -1
- package/lib/private/response/error.d.ts +1 -1
- package/lib/private/response/error.js +1 -1
- package/lib/private/response/json.d.ts +1 -1
- package/lib/private/response/json.js +1 -1
- package/lib/private/response/redirect.d.ts +5 -5
- package/lib/private/response/redirect.js +8 -9
- package/lib/private/response/respond.js +9 -7
- package/lib/private/response/sse.d.ts +1 -1
- package/lib/private/response/sse.js +1 -1
- package/lib/private/response/text.d.ts +1 -1
- package/lib/private/response/text.js +1 -1
- package/lib/private/response/view.d.ts +1 -1
- package/lib/private/response/view.js +6 -13
- package/lib/private/response/ws.d.ts +1 -1
- package/lib/private/route/router.d.ts +3 -3
- package/lib/private/route/router.js +7 -10
- package/lib/private/serve/App.d.ts +6 -7
- package/lib/private/serve/App.js +52 -43
- package/lib/private/serve/Init.d.ts +2 -2
- package/lib/private/serve/dev-module.d.ts +2 -0
- package/lib/private/serve/dev-module.js +34 -0
- package/lib/private/serve/hook.d.ts +1 -2
- package/lib/private/serve/hook.js +2 -3
- package/lib/private/serve/index.d.ts +1 -1
- package/lib/private/serve/index.js +32 -2
- package/lib/private/server/TAG.d.ts +3 -0
- package/lib/private/server/TAG.js +2 -0
- package/lib/private/server/index.d.ts +5 -0
- package/lib/private/server/index.js +6 -0
- package/lib/private/session/SessionHandle.js +2 -1
- package/lib/private/session/index.d.ts +1 -1
- package/lib/private/session/module.d.ts +3 -0
- package/lib/private/session/module.js +114 -0
- package/lib/private/session/schema.d.ts +17 -9
- package/lib/private/session/schema.js +9 -5
- package/lib/private/target/Manager.js +6 -12
- package/lib/public/client.d.ts +2 -13
- package/lib/public/client.js +1 -9
- package/lib/public/db/errors.d.ts +2 -0
- package/lib/public/db/errors.js +2 -0
- package/lib/public/db/migrate.d.ts +2 -0
- package/lib/public/db/migrate.js +2 -0
- package/lib/public/db.d.ts +3 -3
- package/lib/public/frontend.d.ts +3 -0
- package/lib/public/frontend.js +2 -0
- package/lib/public/index.d.ts +2 -0
- package/lib/public/index.js +2 -0
- package/lib/public/orm/store.d.ts +2 -0
- package/lib/public/orm/store.js +2 -0
- package/lib/public/request/server.d.ts +5 -0
- package/lib/public/request/server.js +7 -0
- package/lib/public/response.d.ts +4 -4
- package/lib/public/server.d.ts +3 -0
- package/lib/public/server.js +2 -0
- package/package.json +30 -25
- package/lib/private/AppError.d.ts +0 -4
- package/lib/private/AppError.js +0 -8
- package/lib/private/backend/Module.d.ts +0 -18
- package/lib/private/backend/Module.js +0 -19
- package/lib/private/backend/TAG.d.ts +0 -3
- package/lib/private/backend/TAG.js +0 -2
- package/lib/private/build/server/plugin/db-default.d.ts +0 -4
- package/lib/private/build/server/plugin/db-default.js +0 -45
- package/lib/private/build/server/plugin/store-wrap.d.ts +0 -4
- package/lib/private/build/server/plugin/store-wrap.js +0 -33
- package/lib/private/client/spa/index.d.ts +0 -6
- package/lib/private/client/spa/index.js +0 -200
- package/lib/private/db/error.d.ts +0 -81
- package/lib/private/db/error.js +0 -199
- package/lib/private/db/symbol/wrap.d.ts +0 -3
- package/lib/private/db/symbol/wrap.js +0 -2
- package/lib/private/fail.d.ts +0 -3
- package/lib/private/fail.js +0 -5
- package/lib/private/frontend/Module.d.ts +0 -62
- package/lib/private/frontend/Module.js +0 -255
- package/lib/private/i18n/Module.d.ts +0 -16
- package/lib/private/i18n/Module.js +0 -133
- package/lib/private/module/BuildHook.d.ts +0 -5
- package/lib/private/module/BuildHook.js +0 -2
- package/lib/private/module/NextBuild.d.ts +0 -5
- package/lib/private/module/NextBuild.js +0 -2
- package/lib/private/module/NextServe.d.ts +0 -5
- package/lib/private/module/NextServe.js +0 -2
- package/lib/private/orm/Set.d.ts +0 -11
- package/lib/private/orm/Set.js +0 -2
- package/lib/private/orm/foreign.d.ts +0 -4
- package/lib/private/orm/foreign.js +0 -5
- package/lib/private/orm/primary.d.ts +0 -5
- package/lib/private/orm/primary.js +0 -5
- package/lib/private/orm/types.d.ts +0 -18
- package/lib/private/orm/types.js +0 -2
- package/lib/private/orm/wrap.d.ts +0 -5
- package/lib/private/orm/wrap.js +0 -5
- package/lib/private/reducer.d.ts +0 -24
- package/lib/private/reducer.js +0 -10
- package/lib/private/serve/module/Dev.d.ts +0 -11
- package/lib/private/serve/module/Dev.js +0 -32
- package/lib/private/serve/module/Handle.d.ts +0 -10
- package/lib/private/serve/module/Handle.js +0 -15
- package/lib/private/session/SessionModule.d.ts +0 -14
- package/lib/private/session/SessionModule.js +0 -122
- package/lib/public/App.d.ts +0 -2
- package/lib/public/App.js +0 -2
- package/lib/public/AppError.d.ts +0 -2
- package/lib/public/AppError.js +0 -2
- package/lib/public/BuildApp.d.ts +0 -2
- package/lib/public/BuildApp.js +0 -2
- package/lib/public/BuildHook.d.ts +0 -2
- package/lib/public/BuildHook.js +0 -2
- package/lib/public/Mode.d.ts +0 -2
- package/lib/public/Mode.js +0 -2
- package/lib/public/Module.d.ts +0 -2
- package/lib/public/Module.js +0 -2
- package/lib/public/Next.d.ts +0 -2
- package/lib/public/Next.js +0 -2
- package/lib/public/NextBuild.d.ts +0 -2
- package/lib/public/NextBuild.js +0 -2
- package/lib/public/NextHandle.d.ts +0 -2
- package/lib/public/NextHandle.js +0 -2
- package/lib/public/NextRoute.d.ts +0 -3
- package/lib/public/NextRoute.js +0 -2
- package/lib/public/NextServe.d.ts +0 -2
- package/lib/public/NextServe.js +0 -2
- package/lib/public/ServeApp.d.ts +0 -2
- package/lib/public/ServeApp.js +0 -2
- package/lib/public/Target.d.ts +0 -2
- package/lib/public/Target.js +0 -2
- package/lib/public/backend/Module.d.ts +0 -2
- package/lib/public/backend/Module.js +0 -2
- package/lib/public/backend/TAG.d.ts +0 -2
- package/lib/public/backend/TAG.js +0 -2
- package/lib/public/client/Data.d.ts +0 -2
- package/lib/public/client/Data.js +0 -2
- package/lib/public/client/spa.d.ts +0 -2
- package/lib/public/client/spa.js +0 -2
- package/lib/public/db/error.d.ts +0 -2
- package/lib/public/db/error.js +0 -2
- package/lib/public/fail.d.ts +0 -2
- package/lib/public/fail.js +0 -2
- package/lib/public/frontend/Module.d.ts +0 -2
- package/lib/public/frontend/Module.js +0 -2
- package/lib/public/frontend/Publish.d.ts +0 -2
- package/lib/public/frontend/Publish.js +0 -2
- package/lib/public/frontend/Render.d.ts +0 -2
- package/lib/public/frontend/Render.js +0 -2
- package/lib/public/frontend/ViewResponse.d.ts +0 -2
- package/lib/public/frontend/ViewResponse.js +0 -2
- package/lib/public/orm/Store.d.ts +0 -2
- package/lib/public/orm/Store.js +0 -2
- package/lib/public/orm/wrap.d.ts +0 -2
- package/lib/public/orm/wrap.js +0 -2
- package/lib/public/request.d.ts +0 -4
- package/lib/public/request.js +0 -2
- /package/lib/private/{frontend → client}/Publish.d.ts +0 -0
- /package/lib/private/{frontend → client}/Publish.js +0 -0
- /package/lib/private/{frontend → client}/Render.js +0 -0
- /package/lib/private/{frontend → client}/ServerData.d.ts +0 -0
- /package/lib/private/{frontend → client}/ServerData.js +0 -0
- /package/lib/private/{frontend → client}/ServerView.d.ts +0 -0
- /package/lib/private/{frontend → client}/ServerView.js +0 -0
- /package/lib/private/{frontend → client}/View.d.ts +0 -0
- /package/lib/private/{frontend → client}/View.js +0 -0
- /package/lib/private/{frontend → client}/ViewOptions.d.ts +0 -0
- /package/lib/private/{frontend → client}/ViewOptions.js +0 -0
- /package/lib/private/{frontend → client}/ViewResponse.js +0 -0
- /package/lib/private/client/{spa/storage.d.ts → storage.d.ts} +0 -0
- /package/lib/private/client/{spa/storage.js → storage.js} +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import log from "#log";
|
|
2
|
+
import create from "#module/create";
|
|
3
|
+
import c from "@rcompat/cli/color";
|
|
4
|
+
function pass(address, request) {
|
|
5
|
+
return fetch(address, {
|
|
6
|
+
body: request.body,
|
|
7
|
+
duplex: "half",
|
|
8
|
+
headers: request.headers,
|
|
9
|
+
method: request.method,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export default function dev() {
|
|
13
|
+
let paths;
|
|
14
|
+
let reload;
|
|
15
|
+
return create({
|
|
16
|
+
name: "builtin/dev",
|
|
17
|
+
setup({ onServe, onHandle }) {
|
|
18
|
+
onServe(app => {
|
|
19
|
+
const { host, port } = app.livereload;
|
|
20
|
+
const assets = app.assets.map(asset => asset.src);
|
|
21
|
+
reload = `http://${host}:${port}`;
|
|
22
|
+
paths = ["/esbuild"].concat(assets);
|
|
23
|
+
log.print(`↻ live reload ${c.dim(reload)}\n`);
|
|
24
|
+
});
|
|
25
|
+
onHandle((request, next) => {
|
|
26
|
+
const { pathname } = new URL(request.url);
|
|
27
|
+
return paths.includes(pathname)
|
|
28
|
+
? pass(`${reload}${pathname}`, request.original)
|
|
29
|
+
: next(request);
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=dev-module.js.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export default async function run_serve_hooks(app) {
|
|
2
|
+
await app.serve_hooks(app);
|
|
3
3
|
await app.start();
|
|
4
4
|
return app;
|
|
5
5
|
}
|
|
6
|
-
export default async (app) => post(await reducer(app.modules, app, "serve"));
|
|
7
6
|
//# sourceMappingURL=hook.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ServeApp from "#serve/App";
|
|
2
2
|
import type ServeInit from "#serve/Init";
|
|
3
|
-
declare const _default: (root: string, options: ServeInit) => Promise<ServeApp>;
|
|
3
|
+
declare const _default: (root: string, options: ServeInit) => Promise<ServeApp | undefined>;
|
|
4
4
|
export default _default;
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,10 +1,40 @@
|
|
|
1
|
-
import { s_attach } from "#app/Facade";
|
|
1
|
+
import { s_attach, s_config } from "#app/Facade";
|
|
2
|
+
import E from "#db/errors";
|
|
3
|
+
import log from "#log";
|
|
4
|
+
import key from "#orm/key";
|
|
5
|
+
import store from "#orm/store";
|
|
2
6
|
import ServeApp from "#serve/App";
|
|
3
7
|
import serve_hook from "#serve/hook";
|
|
8
|
+
import p from "pema";
|
|
4
9
|
export default async (root, options) => {
|
|
5
10
|
const facade = options.facade;
|
|
6
11
|
const app = await new ServeApp(root, options).init();
|
|
7
12
|
facade[s_attach](app);
|
|
8
|
-
|
|
13
|
+
const config = facade[s_config];
|
|
14
|
+
const migrations = config.db.migrations;
|
|
15
|
+
try {
|
|
16
|
+
if (migrations !== undefined) {
|
|
17
|
+
const { table, db } = migrations;
|
|
18
|
+
const Migration = store({
|
|
19
|
+
name: table,
|
|
20
|
+
db,
|
|
21
|
+
schema: {
|
|
22
|
+
id: key.primary(p.u16, { generate: false }),
|
|
23
|
+
applied: p.date,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
await Migration.table.create();
|
|
27
|
+
const last = await Migration.find({ limit: 1, sort: { id: "desc" } });
|
|
28
|
+
const last_id = last.length === 0 ? 0 : last[0].id;
|
|
29
|
+
const build_json = app.root.join("build.json");
|
|
30
|
+
const { migration_version } = await build_json.json();
|
|
31
|
+
if (last_id < migration_version)
|
|
32
|
+
throw E.unapplied_migrations();
|
|
33
|
+
}
|
|
34
|
+
return serve_hook(app);
|
|
35
|
+
}
|
|
36
|
+
catch (cause) {
|
|
37
|
+
log.error(cause);
|
|
38
|
+
}
|
|
9
39
|
};
|
|
10
40
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import E from "#errors";
|
|
1
2
|
import kSerialize from "#session/k-serialize";
|
|
2
3
|
import assert from "@rcompat/assert";
|
|
3
4
|
import is from "@rcompat/is";
|
|
@@ -11,7 +12,7 @@ export default class SessionHandle {
|
|
|
11
12
|
assert.maybe.dict(data);
|
|
12
13
|
assert.maybe.object(schema);
|
|
13
14
|
assert.maybe.function(schema?.parse);
|
|
14
|
-
assert.true((id === undefined) === (data === undefined),
|
|
15
|
+
assert.true((id === undefined) === (data === undefined), E.session_id_data());
|
|
15
16
|
this.#id = id;
|
|
16
17
|
this.#data = data;
|
|
17
18
|
this.#schema = schema?.parse
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import E from "#errors";
|
|
2
|
+
import create from "#module/create";
|
|
3
|
+
import kSerialize from "#session/k-serialize";
|
|
4
|
+
import SessionHandle from "#session/SessionHandle";
|
|
5
|
+
import storage from "#session/storage";
|
|
6
|
+
import p from "pema";
|
|
7
|
+
function cookie(name, value, options) {
|
|
8
|
+
const parts = [`${name}=${value}`];
|
|
9
|
+
parts.push(`Path=${options.path}`);
|
|
10
|
+
parts.push(`SameSite=${options.sameSite}`);
|
|
11
|
+
if (options.maxAge !== undefined)
|
|
12
|
+
parts.push(`Max-Age=${options.maxAge}`);
|
|
13
|
+
if (options.httpOnly)
|
|
14
|
+
parts.push("HttpOnly");
|
|
15
|
+
if (options.secure)
|
|
16
|
+
parts.push("Secure");
|
|
17
|
+
return parts.join("; ");
|
|
18
|
+
}
|
|
19
|
+
;
|
|
20
|
+
export default function session_module(config) {
|
|
21
|
+
let secure;
|
|
22
|
+
const store = config.store;
|
|
23
|
+
const props = store.type.properties;
|
|
24
|
+
if (!("session_id" in props))
|
|
25
|
+
throw E.session_missing_id();
|
|
26
|
+
try {
|
|
27
|
+
props.session_id.parse(crypto.randomUUID());
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
throw E.session_id_string();
|
|
31
|
+
}
|
|
32
|
+
return create({
|
|
33
|
+
name: "builtin/session",
|
|
34
|
+
setup({ onServe, onHandle }) {
|
|
35
|
+
onServe(async (app) => {
|
|
36
|
+
secure = app.secure;
|
|
37
|
+
await store.table.create();
|
|
38
|
+
});
|
|
39
|
+
onHandle(async (request, next) => {
|
|
40
|
+
const { name, ...cookie_config } = config.cookie;
|
|
41
|
+
const sid = request.cookies.try(name);
|
|
42
|
+
// Look up session by session_id
|
|
43
|
+
const existing = sid !== undefined
|
|
44
|
+
? await store.find({ where: { session_id: sid }, limit: 1 })
|
|
45
|
+
: [];
|
|
46
|
+
const exists = existing.length > 0;
|
|
47
|
+
let data = undefined;
|
|
48
|
+
let db_id = undefined;
|
|
49
|
+
if (exists) {
|
|
50
|
+
const record = existing[0];
|
|
51
|
+
const { id: _id, session_id: _sid, ...rest } = record;
|
|
52
|
+
data = rest;
|
|
53
|
+
db_id = _id;
|
|
54
|
+
}
|
|
55
|
+
const session_type = p.omit(store.type, "id", "session_id");
|
|
56
|
+
const session = new SessionHandle(sid, data, session_type);
|
|
57
|
+
const response = await new Promise((resolve, reject) => {
|
|
58
|
+
storage().run(session, async () => {
|
|
59
|
+
try {
|
|
60
|
+
resolve(await next(request));
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
reject(e);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
const snap = session[kSerialize]();
|
|
68
|
+
// no cookie coming in, no session created
|
|
69
|
+
if (sid === undefined && !snap.exists)
|
|
70
|
+
return response;
|
|
71
|
+
const options = { ...cookie_config, secure };
|
|
72
|
+
// no session existed -> either create or noop
|
|
73
|
+
if (!exists) {
|
|
74
|
+
if (!snap.exists) {
|
|
75
|
+
// stale cookie -> clear
|
|
76
|
+
if (sid !== undefined) {
|
|
77
|
+
response.headers.append("set-cookie", cookie(name, "", {
|
|
78
|
+
...options, maxAge: 0,
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
return response;
|
|
82
|
+
}
|
|
83
|
+
// create new session
|
|
84
|
+
await store.insert({ session_id: snap.id, ...snap.data });
|
|
85
|
+
response.headers.append("set-cookie", cookie(name, snap.id, options));
|
|
86
|
+
return response;
|
|
87
|
+
}
|
|
88
|
+
// from here: session existed (db_id is defined)
|
|
89
|
+
// fast-path: session exists, same id and not dirty -> noop
|
|
90
|
+
if (snap.exists && snap.id === sid && !snap.dirty)
|
|
91
|
+
return response;
|
|
92
|
+
// current absent -> destroy + clear cookie
|
|
93
|
+
if (!snap.exists) {
|
|
94
|
+
await store.delete(db_id);
|
|
95
|
+
response.headers.append("set-cookie", cookie(name, "", {
|
|
96
|
+
...options, maxAge: 0,
|
|
97
|
+
}));
|
|
98
|
+
return response;
|
|
99
|
+
}
|
|
100
|
+
// session recreated in route -> destroy old, create new, set cookie
|
|
101
|
+
if (snap.id !== sid) {
|
|
102
|
+
await store.delete(db_id);
|
|
103
|
+
await store.insert({ session_id: snap.id, ...snap.data });
|
|
104
|
+
response.headers.append("set-cookie", cookie(name, snap.id, options));
|
|
105
|
+
return response;
|
|
106
|
+
}
|
|
107
|
+
// dirty -> replace session contents
|
|
108
|
+
await store.update(db_id, { set: snap.data });
|
|
109
|
+
return response;
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import Store from "#orm/
|
|
2
|
-
declare const _default: import("pema").ObjectType<{
|
|
3
|
-
cookie:
|
|
4
|
-
httpOnly: import("pema").DefaultType<import("pema").BooleanType, true>;
|
|
5
|
-
name: import("pema").DefaultType<import("pema").StringType, "session_id">;
|
|
6
|
-
path: import("pema").DefaultType<import("pema").StringType, "/">;
|
|
7
|
-
sameSite: import("pema").DefaultType<import("pema").UnionType<[import("pema").LiteralType<"Strict">, import("pema").LiteralType<"Lax">, import("pema").LiteralType<"None">]>, "Lax" | "None" | "Strict">;
|
|
8
|
-
}
|
|
9
|
-
store: import("pema").DefaultType<import("pema").ConstructorType<typeof Store>, Store<import("../orm/
|
|
1
|
+
import { Store } from "#orm/store";
|
|
2
|
+
declare const _default: import("pema").ObjectType<import("pema").NormalizeSchemaObject<{
|
|
3
|
+
readonly cookie: {
|
|
4
|
+
readonly httpOnly: import("pema").DefaultType<import("pema").BooleanType, true>;
|
|
5
|
+
readonly name: import("pema").DefaultType<import("pema").StringType, "session_id">;
|
|
6
|
+
readonly path: import("pema").DefaultType<import("pema").StringType, "/">;
|
|
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
|
+
};
|
|
9
|
+
readonly store: import("pema").DefaultType<import("pema").ConstructorType<typeof Store>, Store<import("../orm/StoreInput.js").default, import("@rcompat/type").Dict<import("../orm/relation.js").Relation>>>;
|
|
10
|
+
}>, {
|
|
11
|
+
cookie: {
|
|
12
|
+
httpOnly: boolean;
|
|
13
|
+
name: string;
|
|
14
|
+
path: string;
|
|
15
|
+
sameSite: "Lax" | "None" | "Strict";
|
|
16
|
+
};
|
|
17
|
+
store: Store<import("../orm/StoreInput.js").default, import("@rcompat/type").Dict<import("../orm/relation.js").Relation>>;
|
|
10
18
|
}>;
|
|
11
19
|
export default _default;
|
|
12
20
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import MemoryDB from "#db/MemoryDB";
|
|
2
2
|
import key from "#orm/key";
|
|
3
|
-
import Store from "#orm/
|
|
3
|
+
import store, { Store } from "#orm/store";
|
|
4
4
|
import p from "pema";
|
|
5
5
|
export default p({
|
|
6
6
|
cookie: {
|
|
@@ -10,10 +10,14 @@ export default p({
|
|
|
10
10
|
sameSite: p.union("Strict", "Lax", "None").default("Lax"),
|
|
11
11
|
},
|
|
12
12
|
store: p.constructor(Store).default(() => {
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
return store({
|
|
14
|
+
schema: {
|
|
15
|
+
id: key.primary(p.uuid),
|
|
16
|
+
session_id: p.uuid,
|
|
17
|
+
},
|
|
18
|
+
db: new MemoryDB(),
|
|
19
|
+
name: "session",
|
|
20
|
+
});
|
|
17
21
|
}),
|
|
18
22
|
});
|
|
19
23
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import E from "#errors";
|
|
2
2
|
const web = {
|
|
3
3
|
name: "web",
|
|
4
4
|
runner: () => { },
|
|
@@ -25,20 +25,14 @@ export default class TargetManager {
|
|
|
25
25
|
return this.#targets.find(target => target.name === this.#name);
|
|
26
26
|
}
|
|
27
27
|
set(name) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
message += "\n - add {2} for more targets";
|
|
32
|
-
}
|
|
33
|
-
const targets = this.#targets.map(p => p.name).join(", ");
|
|
34
|
-
throw fail(message, name, targets, "@primate/native");
|
|
35
|
-
}
|
|
28
|
+
const targets = this.#targets;
|
|
29
|
+
if (!this.has(name))
|
|
30
|
+
throw E.target_missing(name, targets.map(p => p.name));
|
|
36
31
|
this.#name = name;
|
|
37
32
|
}
|
|
38
33
|
add(target) {
|
|
39
|
-
if (this.has(target.name))
|
|
40
|
-
throw
|
|
41
|
-
}
|
|
34
|
+
if (this.has(target.name))
|
|
35
|
+
throw E.target_duplicate(target.name);
|
|
42
36
|
this.#targets.push(target);
|
|
43
37
|
}
|
|
44
38
|
async run() {
|
package/lib/public/client.d.ts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import validateField from "#client/validate-field";
|
|
4
|
-
import type ValidateInit from "#client/ValidateInit";
|
|
5
|
-
import type ValidateUpdater from "#client/ValidateUpdater";
|
|
6
|
-
import type ValidationError from "#client/ValidationError";
|
|
7
|
-
declare const client: {
|
|
8
|
-
createForm: typeof createForm;
|
|
9
|
-
validateField: typeof validateField;
|
|
10
|
-
toValidated: typeof toValidated;
|
|
11
|
-
};
|
|
12
|
-
export default client;
|
|
13
|
-
export type { FormInit, FormView, ValidateInit, ValidateUpdater, ValidationError, };
|
|
1
|
+
export type * from "#client/index";
|
|
2
|
+
export { default } from "#client/index";
|
|
14
3
|
//# sourceMappingURL=client.d.ts.map
|
package/lib/public/client.js
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import toValidated from "#client/to-validated";
|
|
3
|
-
import validateField from "#client/validate-field";
|
|
4
|
-
const client = {
|
|
5
|
-
createForm, // headless form controller
|
|
6
|
-
validateField, // low-level single-value transport
|
|
7
|
-
toValidated, // adapter to create field stores/hooks
|
|
8
|
-
};
|
|
9
|
-
export default client;
|
|
1
|
+
export { default } from "#client/index";
|
|
10
2
|
//# sourceMappingURL=client.js.map
|
package/lib/public/db.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export type { default as As } from "#db/As";
|
|
2
2
|
export type { default as DataDict } from "#db/DataDict";
|
|
3
|
-
export type { default as DB } from "#db/DB";
|
|
3
|
+
export type { default as DB, Schema } from "#db/DB";
|
|
4
4
|
export type { default as PK } from "#db/PK";
|
|
5
|
+
export type { default as ReadArgs } from "#db/ReadArgs";
|
|
6
|
+
export type { default as ReadRelationsArgs } from "#db/ReadRelationsArgs";
|
|
5
7
|
export type { default as Sort } from "#db/Sort";
|
|
6
8
|
export type { default as TypeMap } from "#db/TypeMap";
|
|
7
9
|
export type { default as Types } from "#db/Types";
|
|
8
10
|
export type { default as With } from "#db/With";
|
|
9
|
-
export type { default as ReadArgs } from "#db/ReadArgs";
|
|
10
|
-
export type { default as ReadRelationsArgs } from "#db/ReadRelationsArgs";
|
|
11
11
|
export { default } from "#db/common";
|
|
12
12
|
//# sourceMappingURL=db.d.ts.map
|
package/lib/public/response.d.ts
CHANGED
|
@@ -6,17 +6,17 @@ export type { default as ResponseLike } from "#response/ResponseLike";
|
|
|
6
6
|
declare const _default: {
|
|
7
7
|
binary: typeof binary;
|
|
8
8
|
error: typeof error;
|
|
9
|
-
json: (body: unknown, init?: ResponseInit) => (app: import("./
|
|
9
|
+
json: (body: unknown, init?: ResponseInit) => (app: import("./index.js").ServeApp) => import("@rcompat/type").MaybePromise<Response>;
|
|
10
10
|
redirect: (location: string, status?: 302 | 301 | 300 | 304 | 308 | 303 | 307) => import("#response/ResponseFunction").default;
|
|
11
11
|
sse: (body: {
|
|
12
12
|
close?(): undefined;
|
|
13
13
|
open(events: {
|
|
14
14
|
send(name: string, data: unknown): undefined;
|
|
15
15
|
}): undefined;
|
|
16
|
-
}, init?: ResponseInit) => (app: import("./
|
|
17
|
-
text: (body: string, init?: ResponseInit) => (app: import("./
|
|
16
|
+
}, init?: ResponseInit) => (app: import("./index.js").ServeApp) => import("@rcompat/type").MaybePromise<Response>;
|
|
17
|
+
text: (body: string, init?: ResponseInit) => (app: import("./index.js").ServeApp) => import("@rcompat/type").MaybePromise<Response>;
|
|
18
18
|
view: typeof view;
|
|
19
|
-
ws: (actions: import("@rcompat/http
|
|
19
|
+
ws: (actions: import("@rcompat/http").Actions) => import("#response/ResponseFunction").default;
|
|
20
20
|
};
|
|
21
21
|
export default _default;
|
|
22
22
|
//# sourceMappingURL=response.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "The universal web framework",
|
|
5
5
|
"homepage": "https://primate.run",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -18,49 +18,54 @@
|
|
|
18
18
|
"!/**/*.spec.*"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@rcompat/
|
|
22
|
-
"@rcompat/
|
|
23
|
-
"@rcompat/
|
|
24
|
-
"@rcompat/
|
|
25
|
-
"@rcompat/
|
|
26
|
-
"@rcompat/
|
|
27
|
-
"@rcompat/
|
|
28
|
-
"@rcompat/
|
|
29
|
-
"@rcompat/
|
|
30
|
-
"@rcompat/
|
|
31
|
-
"@rcompat/
|
|
32
|
-
"@rcompat/
|
|
33
|
-
"@rcompat/
|
|
34
|
-
"@rcompat/
|
|
35
|
-
"
|
|
36
|
-
"
|
|
21
|
+
"@rcompat/assert": "^0.8.1",
|
|
22
|
+
"@rcompat/cli": "^0.18.1",
|
|
23
|
+
"@rcompat/crypto": "^0.16.1",
|
|
24
|
+
"@rcompat/dict": "^0.5.1",
|
|
25
|
+
"@rcompat/env": "^0.17.2",
|
|
26
|
+
"@rcompat/error": "^0.3.1",
|
|
27
|
+
"@rcompat/fn": "^0.5.1",
|
|
28
|
+
"@rcompat/fs": "^0.28.1",
|
|
29
|
+
"@rcompat/http": "^0.25.1",
|
|
30
|
+
"@rcompat/io": "^0.5.1",
|
|
31
|
+
"@rcompat/is": "^0.6.1",
|
|
32
|
+
"@rcompat/kv": "^0.8.1",
|
|
33
|
+
"@rcompat/runtime": "^0.11.1",
|
|
34
|
+
"@rcompat/string": "^0.16.1",
|
|
35
|
+
"@rcompat/type": "^0.11.1",
|
|
36
|
+
"esbuild": "^0.28.0",
|
|
37
|
+
"pema": "^0.6.0"
|
|
37
38
|
},
|
|
38
39
|
"imports": {
|
|
39
40
|
"#i18n/index": {
|
|
40
|
-
"
|
|
41
|
+
"@primate/source": "./src/private/i18n/index/client.ts",
|
|
41
42
|
"browser": "./lib/private/i18n/index/client.js",
|
|
42
43
|
"default": "./lib/private/i18n/index/server.js"
|
|
43
44
|
},
|
|
44
45
|
"#*": {
|
|
45
|
-
"
|
|
46
|
+
"@primate/source": "./src/private/*.ts",
|
|
46
47
|
"default": "./lib/private/*.js"
|
|
47
48
|
}
|
|
48
49
|
},
|
|
49
50
|
"exports": {
|
|
50
|
-
"./
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
51
|
+
"./AppFacade": {
|
|
52
|
+
"@primate/source": "./src/public/AppFacade.ts",
|
|
53
|
+
"browser": "./lib/private/app/Facade.browser.js",
|
|
54
|
+
"default": "./lib/public/AppFacade.js"
|
|
54
55
|
},
|
|
55
56
|
"./*": {
|
|
56
|
-
"
|
|
57
|
+
"@primate/source": "./src/public/*.ts",
|
|
57
58
|
"default": "./lib/public/*.js"
|
|
59
|
+
},
|
|
60
|
+
".": {
|
|
61
|
+
"@primate/source": "./src/public/index.ts",
|
|
62
|
+
"default": "./lib/public/index.js"
|
|
58
63
|
}
|
|
59
64
|
},
|
|
60
65
|
"scripts": {
|
|
61
66
|
"build": "npm run clean && tsc && cp -a src/private/defaults lib/private",
|
|
62
67
|
"clean": "rm -rf ./lib",
|
|
63
68
|
"lint": "eslint .",
|
|
64
|
-
"test": "
|
|
69
|
+
"test": "npx proby"
|
|
65
70
|
}
|
|
66
71
|
}
|
package/lib/private/AppError.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import Module from "#Module";
|
|
2
|
-
export default abstract class BackendModule extends Module {
|
|
3
|
-
#private;
|
|
4
|
-
abstract defaultExtension: string;
|
|
5
|
-
static schema: import("pema").ObjectType<{
|
|
6
|
-
fileExtension: import("pema").OptionalType<import("pema").StringType>;
|
|
7
|
-
}>;
|
|
8
|
-
static options: {
|
|
9
|
-
fileExtension: string | undefined;
|
|
10
|
-
};
|
|
11
|
-
static input: {
|
|
12
|
-
fileExtension?: string | undefined;
|
|
13
|
-
} | undefined;
|
|
14
|
-
constructor(options?: typeof BackendModule.schema.input);
|
|
15
|
-
get fileExtension(): string;
|
|
16
|
-
get package(): string;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=Module.d.ts.map
|