@primate/core 0.3.4 → 0.4.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 +5 -19
- package/lib/private/App.js +13 -75
- package/lib/private/Binder.d.ts +1 -3
- package/lib/private/Flags.d.ts +7 -0
- package/lib/private/Flags.js +7 -0
- package/lib/private/Module.d.ts +2 -2
- package/lib/private/backend/TAG.d.ts +1 -1
- package/lib/private/backend/TAG.js +1 -1
- package/lib/private/build/App.d.ts +34 -0
- package/lib/private/build/App.js +103 -0
- package/lib/private/build/client/index.d.ts +3 -0
- package/lib/private/build/client/index.js +95 -0
- package/lib/private/build/client/plugin/alias.d.ts +4 -0
- package/lib/private/build/client/plugin/alias.js +12 -0
- package/lib/private/build/client/plugin/entrypoint.d.ts +4 -0
- package/lib/private/build/client/plugin/entrypoint.js +15 -0
- package/lib/private/build/client/plugin/frontend.d.ts +4 -0
- package/lib/private/build/client/plugin/frontend.js +15 -0
- package/lib/private/build/client/plugin/server-stamp.d.ts +4 -0
- package/lib/private/build/client/plugin/server-stamp.js +14 -0
- package/lib/private/build/client/reload.d.ts +7 -0
- package/lib/private/build/client/reload.js +6 -0
- package/lib/private/{hook/build.d.ts → build/hook.d.ts} +2 -2
- package/lib/private/build/hook.js +49 -0
- package/lib/private/build/index.d.ts +4 -0
- package/lib/private/{build.js → build/index.js} +7 -5
- package/lib/private/build/server/index.d.ts +3 -0
- package/lib/private/build/server/index.js +89 -0
- package/lib/private/build/server/plugin/assets.d.ts +4 -0
- package/lib/private/build/server/plugin/assets.js +67 -0
- package/lib/private/build/server/plugin/config.d.ts +4 -0
- package/lib/private/build/server/plugin/config.js +43 -0
- package/lib/private/build/server/plugin/database-default.d.ts +4 -0
- package/lib/private/build/server/plugin/database-default.js +48 -0
- package/lib/private/build/server/plugin/frontend.d.ts +4 -0
- package/lib/private/build/server/plugin/frontend.js +21 -0
- package/lib/private/build/server/plugin/hot-reload.d.ts +4 -0
- package/lib/private/build/server/plugin/hot-reload.js +36 -0
- package/lib/private/build/server/plugin/native-addons.d.ts +4 -0
- package/lib/private/build/server/plugin/native-addons.js +55 -0
- package/lib/private/build/server/plugin/node-imports.d.ts +4 -0
- package/lib/private/build/server/plugin/node-imports.js +32 -0
- package/lib/private/build/server/plugin/requires.d.ts +4 -0
- package/lib/private/build/server/plugin/requires.js +30 -0
- package/lib/private/build/server/plugin/roots.d.ts +4 -0
- package/lib/private/build/server/plugin/roots.js +18 -0
- package/lib/private/build/server/plugin/route.d.ts +4 -0
- package/lib/private/build/server/plugin/route.js +56 -0
- package/lib/private/build/server/plugin/store-wrap.d.ts +4 -0
- package/lib/private/build/server/plugin/store-wrap.js +33 -0
- package/lib/private/build/server/plugin/store.d.ts +4 -0
- package/lib/private/build/server/plugin/store.js +47 -0
- package/lib/private/build/server/plugin/stores.d.ts +4 -0
- package/lib/private/build/server/plugin/stores.js +25 -0
- package/lib/private/build/server/plugin/view.d.ts +4 -0
- package/lib/private/build/server/plugin/view.js +64 -0
- package/lib/private/build/server/plugin/views.d.ts +4 -0
- package/lib/private/build/server/plugin/views.js +36 -0
- package/lib/private/build/server/plugin/virtual-pages.d.ts +4 -0
- package/lib/private/build/server/plugin/virtual-pages.js +41 -0
- package/lib/private/build/server/plugin/virtual-routes.d.ts +4 -0
- package/lib/private/build/server/plugin/virtual-routes.js +46 -0
- package/lib/private/build/server/plugin/wasm.d.ts +4 -0
- package/lib/private/build/server/plugin/wasm.js +36 -0
- package/lib/private/client/Data.d.ts +2 -0
- package/lib/private/client/app.js +4 -1
- package/lib/private/config/index.d.ts +0 -2
- package/lib/private/config/schema.d.ts +4 -6
- package/lib/private/config/schema.js +9 -19
- package/lib/private/database/Store.d.ts +4 -1
- package/lib/private/database/Store.js +8 -2
- package/lib/private/database/test.js +8 -8
- package/lib/private/frontend/Module.d.ts +4 -3
- package/lib/private/frontend/Module.js +47 -50
- package/lib/private/frontend/Publish.d.ts +1 -1
- package/lib/private/i18n/Module.d.ts +1 -1
- package/lib/private/i18n/Module.js +2 -2
- package/lib/private/location.d.ts +0 -6
- package/lib/private/location.js +0 -12
- package/lib/private/module/BuildHook.d.ts +1 -1
- package/lib/private/module/NextBuild.d.ts +1 -1
- package/lib/private/module/NextServe.d.ts +1 -1
- package/lib/private/paths.d.ts +5 -0
- package/lib/private/paths.js +30 -0
- package/lib/private/reducer.d.ts +2 -2
- package/lib/private/request/route.d.ts +1 -1
- package/lib/private/request/route.js +6 -8
- package/lib/private/response/ResponseFunction.d.ts +1 -1
- package/lib/private/response/binary.d.ts +1 -1
- package/lib/private/response/json.d.ts +1 -1
- package/lib/private/response/sse.d.ts +1 -1
- package/lib/private/response/text.d.ts +1 -1
- package/lib/private/response/view.d.ts +6 -9
- package/lib/private/response/view.js +12 -8
- package/lib/private/response.d.ts +1 -1
- package/lib/private/route/router.d.ts +3 -2
- package/lib/private/route/router.js +5 -4
- package/lib/private/{ServeApp.d.ts → serve/App.d.ts} +5 -22
- package/lib/private/{ServeApp.js → serve/App.js} +106 -35
- package/lib/private/{ServeInit.d.ts → serve/Init.d.ts} +16 -12
- package/lib/private/serve/Init.js +2 -0
- package/lib/private/{hook/serve.d.ts → serve/hook.d.ts} +2 -2
- package/lib/private/{hook/serve.js → serve/hook.js} +1 -1
- package/lib/private/serve/index.d.ts +5 -0
- package/lib/private/serve/index.js +6 -0
- package/lib/private/{builtin/DevModule.d.ts → serve/module/Dev.d.ts} +2 -2
- package/lib/private/{builtin/DevModule.js → serve/module/Dev.js} +4 -6
- package/lib/private/{builtin/HandleModule.d.ts → serve/module/Handle.d.ts} +2 -2
- package/lib/private/{builtin/HandleModule.js → serve/module/Handle.js} +2 -2
- package/lib/private/session/SessionModule.d.ts +3 -2
- package/lib/private/session/SessionModule.js +47 -24
- package/lib/private/session/index.d.ts +11 -8
- package/lib/private/session/index.js +5 -3
- package/lib/private/session/schema.d.ts +2 -4
- package/lib/private/session/schema.js +14 -16
- package/lib/private/target/Manager.js +5 -1
- package/lib/private/wasm/instantiate.js +2 -2
- package/lib/public/BuildApp.d.ts +1 -1
- package/lib/public/BuildApp.js +1 -1
- package/lib/public/Flags.d.ts +2 -0
- package/lib/public/Flags.js +2 -0
- package/lib/public/ServeApp.d.ts +1 -1
- package/lib/public/ServeApp.js +1 -1
- package/lib/public/build.d.ts +1 -1
- package/lib/public/build.js +1 -1
- package/lib/public/serve.d.ts +1 -1
- package/lib/public/serve.js +1 -1
- package/package.json +6 -7
- package/lib/private/BindingContext.d.ts +0 -3
- package/lib/private/BindingContext.js +0 -2
- package/lib/private/BuildApp.d.ts +0 -31
- package/lib/private/BuildApp.js +0 -130
- package/lib/private/Loader.d.ts +0 -17
- package/lib/private/Loader.js +0 -47
- package/lib/private/ServeInit.js +0 -2
- package/lib/private/build.d.ts +0 -4
- package/lib/private/config/config/app.d.ts +0 -3
- package/lib/private/config/config/app.js +0 -3
- package/lib/private/config/config/database/index.d.ts +0 -3
- package/lib/private/config/config/database/index.js +0 -3
- package/lib/private/config/config/session.d.ts +0 -3
- package/lib/private/config/config/session.js +0 -3
- package/lib/private/frontend/bundle-server.d.ts +0 -13
- package/lib/private/frontend/bundle-server.js +0 -48
- package/lib/private/hook/build.js +0 -260
- package/lib/private/serve.d.ts +0 -5
- package/lib/private/serve.js +0 -8
- package/lib/private/session/InMemoryManager.d.ts +0 -9
- package/lib/private/session/InMemoryManager.js +0 -23
- package/lib/private/session/Manager.d.ts +0 -9
- package/lib/private/session/Manager.js +0 -4
- package/lib/private/target/web.d.ts +0 -4
- package/lib/private/target/web.js +0 -58
- package/lib/public/Loader.d.ts +0 -2
- package/lib/public/Loader.js +0 -2
- package/lib/public/session/Manager.d.ts +0 -2
- package/lib/public/session/Manager.js +0 -2
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import constructor from "pema/constructor";
|
|
6
|
-
import pure from "pema/pure";
|
|
7
|
-
import string from "pema/string";
|
|
8
|
-
import union from "pema/union";
|
|
9
|
-
export default pema({
|
|
1
|
+
import InMemoryDatabase from "#database/InMemoryDatabase";
|
|
2
|
+
import Store from "#database/Store";
|
|
3
|
+
import p from "pema";
|
|
4
|
+
export default p({
|
|
10
5
|
cookie: {
|
|
11
|
-
httpOnly: boolean.default(true),
|
|
12
|
-
name: string.default("session_id"),
|
|
13
|
-
path: string.startsWith("/").default("/"),
|
|
14
|
-
sameSite: union("Strict", "Lax", "None").default("Lax"),
|
|
6
|
+
httpOnly: p.boolean.default(true),
|
|
7
|
+
name: p.string.default("session_id"),
|
|
8
|
+
path: p.string.startsWith("/").default("/"),
|
|
9
|
+
sameSite: p.union("Strict", "Lax", "None").default("Lax"),
|
|
15
10
|
},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
store: p.constructor(Store).default(() => {
|
|
12
|
+
return new Store({
|
|
13
|
+
id: p.primary,
|
|
14
|
+
session_id: p.string.uuid(),
|
|
15
|
+
}, { database: new InMemoryDatabase(), name: "session" });
|
|
16
|
+
}),
|
|
19
17
|
});
|
|
20
18
|
//# sourceMappingURL=schema.js.map
|
|
@@ -299,8 +299,8 @@ const instantiate = async (args) => {
|
|
|
299
299
|
if (!stores.has(id))
|
|
300
300
|
return STORE_NOT_FOUND_ERROR;
|
|
301
301
|
const store = stores.get(id);
|
|
302
|
-
await store.
|
|
303
|
-
await store.
|
|
302
|
+
await store.collection.delete();
|
|
303
|
+
await store.collection.create();
|
|
304
304
|
return STORE_OPERATION_SUCCESS;
|
|
305
305
|
}, storeOperationNotSupported);
|
|
306
306
|
/**
|
package/lib/public/BuildApp.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "#
|
|
1
|
+
export { default } from "#build/App";
|
|
2
2
|
//# sourceMappingURL=BuildApp.d.ts.map
|
package/lib/public/BuildApp.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "#
|
|
1
|
+
export { default } from "#build/App";
|
|
2
2
|
//# sourceMappingURL=BuildApp.js.map
|
package/lib/public/ServeApp.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "#
|
|
1
|
+
export { default } from "#serve/App";
|
|
2
2
|
//# sourceMappingURL=ServeApp.d.ts.map
|
package/lib/public/ServeApp.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "#
|
|
1
|
+
export { default } from "#serve/App";
|
|
2
2
|
//# sourceMappingURL=ServeApp.js.map
|
package/lib/public/build.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "#build";
|
|
1
|
+
export { default } from "#build/index";
|
|
2
2
|
//# sourceMappingURL=build.d.ts.map
|
package/lib/public/build.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "#build";
|
|
1
|
+
export { default } from "#build/index";
|
|
2
2
|
//# sourceMappingURL=build.js.map
|
package/lib/public/serve.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "#serve";
|
|
1
|
+
export { default } from "#serve/index";
|
|
2
2
|
//# sourceMappingURL=serve.d.ts.map
|
package/lib/public/serve.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "#serve";
|
|
1
|
+
export { default } from "#serve/index";
|
|
2
2
|
//# sourceMappingURL=serve.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "The universal web framework",
|
|
5
5
|
"homepage": "https://primate.run",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -21,18 +21,17 @@
|
|
|
21
21
|
"@rcompat/assert": "^0.3.1",
|
|
22
22
|
"@rcompat/async": "^0.9.0",
|
|
23
23
|
"@rcompat/bufferview": "^0.3.0",
|
|
24
|
-
"@rcompat/build": "^0.14.0",
|
|
25
24
|
"@rcompat/cli": "^0.11.3",
|
|
26
|
-
"@rcompat/crypto": "^0.
|
|
27
|
-
"@rcompat/fs": "^0.
|
|
25
|
+
"@rcompat/crypto": "^0.11.0",
|
|
26
|
+
"@rcompat/fs": "^0.22.3",
|
|
28
27
|
"@rcompat/function": "^0.9.0",
|
|
29
|
-
"@rcompat/http": "^0.
|
|
28
|
+
"@rcompat/http": "^0.16.0",
|
|
30
29
|
"@rcompat/kv": "^0.3.0",
|
|
31
|
-
"@rcompat/package": "^0.22.0",
|
|
32
30
|
"@rcompat/record": "^0.9.1",
|
|
31
|
+
"@rcompat/runtime": "^0.6.0",
|
|
33
32
|
"@rcompat/string": "^0.10.1",
|
|
34
33
|
"@rcompat/type": "^0.6.1",
|
|
35
|
-
"pema": "^0.
|
|
34
|
+
"pema": "^0.4.0"
|
|
36
35
|
},
|
|
37
36
|
"type": "module",
|
|
38
37
|
"imports": {
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import App from "#App";
|
|
2
|
-
import type BindingContext from "#BindingContext";
|
|
3
|
-
import Build from "@rcompat/build";
|
|
4
|
-
import type FileRef from "@rcompat/fs/FileRef";
|
|
5
|
-
import type MaybePromise from "@rcompat/type/MaybePromise";
|
|
6
|
-
type Loader = (source: string, file: FileRef) => MaybePromise<string>;
|
|
7
|
-
type Resolver = (basename: string, file: FileRef) => string;
|
|
8
|
-
export default class BuildApp extends App {
|
|
9
|
-
#private;
|
|
10
|
-
frontends: Map<string, string[]>;
|
|
11
|
-
conditions: Set<string>;
|
|
12
|
-
buildInit(): Promise<void>;
|
|
13
|
-
get id(): string;
|
|
14
|
-
get frontendExtensions(): string[];
|
|
15
|
-
get build(): Build;
|
|
16
|
-
get server_build(): string[];
|
|
17
|
-
addRoot(root: FileRef): void;
|
|
18
|
-
get roots(): FileRef[];
|
|
19
|
-
done(fn: () => void): void;
|
|
20
|
-
cleanup(): void;
|
|
21
|
-
export(code: string): void;
|
|
22
|
-
compile(directory: FileRef, context: BindingContext, options?: {
|
|
23
|
-
loader?: Loader;
|
|
24
|
-
resolver?: Resolver;
|
|
25
|
-
}): Promise<void>;
|
|
26
|
-
depth(): number;
|
|
27
|
-
get i18n_active(): boolean;
|
|
28
|
-
set i18n_active(active: boolean);
|
|
29
|
-
}
|
|
30
|
-
export {};
|
|
31
|
-
//# sourceMappingURL=BuildApp.d.ts.map
|
package/lib/private/BuildApp.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import App from "#App";
|
|
2
|
-
import build from "#hook/build";
|
|
3
|
-
import location from "#location";
|
|
4
|
-
import log from "#log";
|
|
5
|
-
import s_layout_depth from "#symbol/layout-depth";
|
|
6
|
-
import Build from "@rcompat/build";
|
|
7
|
-
import cache from "@rcompat/kv/cache";
|
|
8
|
-
const s = Symbol("primate.Build");
|
|
9
|
-
export default class BuildApp extends App {
|
|
10
|
-
frontends = new Map();
|
|
11
|
-
conditions = new Set();
|
|
12
|
-
#postbuild = [];
|
|
13
|
-
#roots = [];
|
|
14
|
-
#server_build = ["route"];
|
|
15
|
-
#id = crypto.randomUUID().slice(0, 8);
|
|
16
|
-
#i18n_active = false;
|
|
17
|
-
async buildInit() {
|
|
18
|
-
log.system("starting {0} build in {1} mode", this.target.name, this.mode);
|
|
19
|
-
await build(this);
|
|
20
|
-
}
|
|
21
|
-
get id() {
|
|
22
|
-
return this.#id;
|
|
23
|
-
}
|
|
24
|
-
get frontendExtensions() {
|
|
25
|
-
return [...this.frontends.values()].flat();
|
|
26
|
-
}
|
|
27
|
-
get build() {
|
|
28
|
-
const extensions = this.frontendExtensions;
|
|
29
|
-
const conditions = this.conditions.values();
|
|
30
|
-
return cache.get(s, () => new Build({
|
|
31
|
-
...(this.config("build")),
|
|
32
|
-
outdir: this.runpath(location.client).path,
|
|
33
|
-
stdin: {
|
|
34
|
-
contents: "",
|
|
35
|
-
resolveDir: this.root.path,
|
|
36
|
-
},
|
|
37
|
-
conditions: ["style", "browser", "default", "module", ...conditions],
|
|
38
|
-
resolveExtensions: [".ts", ".js", ...extensions],
|
|
39
|
-
tsconfigRaw: {
|
|
40
|
-
compilerOptions: {
|
|
41
|
-
baseUrl: "${configDir}",
|
|
42
|
-
paths: {
|
|
43
|
-
"#view/*": [
|
|
44
|
-
"views/*", ...extensions.map(e => `views/*${e}`),
|
|
45
|
-
],
|
|
46
|
-
"#component/*": [
|
|
47
|
-
"components/*", ...extensions.map(e => `components/*${e}`),
|
|
48
|
-
],
|
|
49
|
-
"#static/*": ["./static/*.js", "./static/*.ts"],
|
|
50
|
-
"#i18n": ["config/i18n.ts", "config/i18n.js"],
|
|
51
|
-
"#store/*": ["stores/*"],
|
|
52
|
-
"#locale/*": ["locales/*"],
|
|
53
|
-
"#config/*": ["config/*"],
|
|
54
|
-
"#session": ["config/session.ts", "config/session.js"],
|
|
55
|
-
"#database": [
|
|
56
|
-
"config/database/index.ts",
|
|
57
|
-
"config/database/index.js",
|
|
58
|
-
"config/database/default.ts",
|
|
59
|
-
"config/database/default.js",
|
|
60
|
-
],
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
}, this.mode === "development" ? "development" : "production"));
|
|
65
|
-
}
|
|
66
|
-
get server_build() {
|
|
67
|
-
return this.#server_build;
|
|
68
|
-
}
|
|
69
|
-
addRoot(root) {
|
|
70
|
-
this.#roots.push(root);
|
|
71
|
-
}
|
|
72
|
-
get roots() {
|
|
73
|
-
return [...this.#roots];
|
|
74
|
-
}
|
|
75
|
-
done(fn) {
|
|
76
|
-
this.#postbuild.push(fn);
|
|
77
|
-
}
|
|
78
|
-
cleanup() {
|
|
79
|
-
this.#postbuild.forEach(fn => fn());
|
|
80
|
-
}
|
|
81
|
-
export(code) {
|
|
82
|
-
this.build.export(code);
|
|
83
|
-
}
|
|
84
|
-
async compile(directory, context, options = {}) {
|
|
85
|
-
if (!await directory.exists())
|
|
86
|
-
return;
|
|
87
|
-
const files = await directory.collect(({ path }) => this.extensions.some(e => path.endsWith(e)) && !path.endsWith(".d.ts"));
|
|
88
|
-
for (const file of files) {
|
|
89
|
-
await this.#compileFile(file, context, directory, options);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
async #compileFile(file, context, directory, options) {
|
|
93
|
-
const binder = this.binder(file);
|
|
94
|
-
if (binder === undefined) {
|
|
95
|
-
log.info("no binder found for {0}", file.path);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
// call the binder to compile
|
|
99
|
-
const compiled = await binder(file, {
|
|
100
|
-
build: { id: this.id, stage: this.runpath("stage") },
|
|
101
|
-
context,
|
|
102
|
-
});
|
|
103
|
-
if (!compiled) {
|
|
104
|
-
log.info("binder returned empty output for {0}", file.path);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
// apply loader if provided
|
|
108
|
-
const transformed = options.loader
|
|
109
|
-
? await options.loader(compiled, file)
|
|
110
|
-
: compiled;
|
|
111
|
-
const basename = this.basename(file, directory);
|
|
112
|
-
const resolved = options.resolver
|
|
113
|
-
? options.resolver(basename, file)
|
|
114
|
-
: basename;
|
|
115
|
-
const target = this.runpath(context, `${resolved}.js`);
|
|
116
|
-
// write to final location
|
|
117
|
-
await target.directory.create({ recursive: true });
|
|
118
|
-
await target.write(transformed);
|
|
119
|
-
}
|
|
120
|
-
depth() {
|
|
121
|
-
return this.get(s_layout_depth);
|
|
122
|
-
}
|
|
123
|
-
get i18n_active() {
|
|
124
|
-
return this.#i18n_active;
|
|
125
|
-
}
|
|
126
|
-
set i18n_active(active) {
|
|
127
|
-
this.#i18n_active = active;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
//# sourceMappingURL=BuildApp.js.map
|
package/lib/private/Loader.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import FileRef from "@rcompat/fs/FileRef";
|
|
2
|
-
import type Dict from "@rcompat/type/Dict";
|
|
3
|
-
type Init = {
|
|
4
|
-
pages: Dict<string>;
|
|
5
|
-
rootfile: string;
|
|
6
|
-
static_root: string;
|
|
7
|
-
};
|
|
8
|
-
export default class Loader {
|
|
9
|
-
#private;
|
|
10
|
-
constructor(init: Init);
|
|
11
|
-
get static_root(): string;
|
|
12
|
-
page(name?: string): string;
|
|
13
|
-
asset(file: FileRef): Promise<Response>;
|
|
14
|
-
serve(pathname: string): Promise<Response | undefined>;
|
|
15
|
-
}
|
|
16
|
-
export {};
|
|
17
|
-
//# sourceMappingURL=Loader.d.ts.map
|
package/lib/private/Loader.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import location from "#location";
|
|
2
|
-
import FileRef from "@rcompat/fs/FileRef";
|
|
3
|
-
import Status from "@rcompat/http/Status";
|
|
4
|
-
import resolve from "@rcompat/http/mime/extension/resolve";
|
|
5
|
-
export default class Loader {
|
|
6
|
-
#init;
|
|
7
|
-
#root;
|
|
8
|
-
constructor(init) {
|
|
9
|
-
this.#init = init;
|
|
10
|
-
this.#root = new FileRef(init.rootfile).join("..");
|
|
11
|
-
}
|
|
12
|
-
get static_root() {
|
|
13
|
-
return this.#init.static_root;
|
|
14
|
-
}
|
|
15
|
-
get #pages() {
|
|
16
|
-
return this.#init.pages;
|
|
17
|
-
}
|
|
18
|
-
page(name) {
|
|
19
|
-
if (name === undefined || !(name in this.#pages)) {
|
|
20
|
-
return this.#pages[location.app_html];
|
|
21
|
-
}
|
|
22
|
-
return this.#pages[name];
|
|
23
|
-
}
|
|
24
|
-
async asset(file) {
|
|
25
|
-
return new Response(file.stream(), {
|
|
26
|
-
headers: {
|
|
27
|
-
"Content-Type": resolve(file.name),
|
|
28
|
-
"Content-Length": String(await file.byteLength()),
|
|
29
|
-
},
|
|
30
|
-
status: Status.OK,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
async serve(pathname) {
|
|
34
|
-
const client_file = this.#root.join(`client/${pathname}`);
|
|
35
|
-
if (await client_file.isFile()) {
|
|
36
|
-
return await this.asset(client_file);
|
|
37
|
-
}
|
|
38
|
-
if (pathname.startsWith(this.static_root)) {
|
|
39
|
-
const assetname = pathname.slice(this.static_root.length);
|
|
40
|
-
const static_file = this.#root.join(`static/${assetname}`);
|
|
41
|
-
if (await static_file.isFile()) {
|
|
42
|
-
return await this.asset(static_file);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=Loader.js.map
|
package/lib/private/ServeInit.js
DELETED
package/lib/private/build.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import FileRef from "@rcompat/fs/FileRef";
|
|
2
|
-
type Init = {
|
|
3
|
-
code: string;
|
|
4
|
-
source: FileRef;
|
|
5
|
-
root: FileRef;
|
|
6
|
-
extensions: string[];
|
|
7
|
-
compile: (src: string, file?: FileRef) => Promise<string>;
|
|
8
|
-
bundle: string[];
|
|
9
|
-
conditions: string[];
|
|
10
|
-
};
|
|
11
|
-
export default function bundle_server(init: Init): Promise<string>;
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=bundle-server.d.ts.map
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import FileRef from "@rcompat/fs/FileRef";
|
|
2
|
-
import * as esbuild from "esbuild";
|
|
3
|
-
export default async function bundle_server(init) {
|
|
4
|
-
const { code, source, root, extensions, compile, bundle } = init;
|
|
5
|
-
const filter = new RegExp(`(${extensions.map(e => e.replace(".", "\\.")).join("|")})$`);
|
|
6
|
-
const plugin = {
|
|
7
|
-
name: "primate/bundle/server",
|
|
8
|
-
setup(build) {
|
|
9
|
-
// compile non-JS sources to JS
|
|
10
|
-
build.onLoad({ filter }, async (args) => {
|
|
11
|
-
const file = new FileRef(args.path);
|
|
12
|
-
const src = await file.text();
|
|
13
|
-
const contents = await compile(src, file);
|
|
14
|
-
return { contents, loader: "js", resolveDir: file.directory.path };
|
|
15
|
-
});
|
|
16
|
-
// externalise anything not relative nor "#view/"
|
|
17
|
-
build.onResolve({ filter: /.*/ }, args => {
|
|
18
|
-
const p = args.path;
|
|
19
|
-
const relative = p.startsWith("./") || p.startsWith("../");
|
|
20
|
-
const views = p.startsWith("#view/");
|
|
21
|
-
if (!relative && !views && !bundle.includes(p))
|
|
22
|
-
return { path: p, external: true };
|
|
23
|
-
return null;
|
|
24
|
-
});
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
const result = await esbuild.build({
|
|
28
|
-
absWorkingDir: root.path,
|
|
29
|
-
tsconfig: root.join("tsconfig.json").path,
|
|
30
|
-
bundle: true,
|
|
31
|
-
write: false,
|
|
32
|
-
platform: "node",
|
|
33
|
-
format: "esm",
|
|
34
|
-
target: "esnext",
|
|
35
|
-
conditions: ["node", "default", ...init.conditions],
|
|
36
|
-
resolveExtensions: [".ts", ".js", ...extensions],
|
|
37
|
-
plugins: [plugin],
|
|
38
|
-
stdin: {
|
|
39
|
-
contents: code,
|
|
40
|
-
sourcefile: source.path,
|
|
41
|
-
resolveDir: source.directory.path,
|
|
42
|
-
loader: "js",
|
|
43
|
-
},
|
|
44
|
-
logLevel: "silent",
|
|
45
|
-
});
|
|
46
|
-
return result.outputFiles[0].text;
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=bundle-server.js.map
|