@primate/core 0.3.4 → 0.4.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 +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 +90 -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 +7 -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,21 +1,17 @@
|
|
|
1
1
|
import fail from "#fail";
|
|
2
|
-
import bundle from "#frontend/bundle-server";
|
|
3
2
|
import inline from "#inline";
|
|
4
3
|
import location from "#location";
|
|
5
4
|
import Module from "#Module";
|
|
6
|
-
import assert from "@rcompat/assert";
|
|
7
5
|
import map from "@rcompat/async/map";
|
|
8
6
|
import hash from "@rcompat/crypto/hash";
|
|
9
7
|
import FileRef from "@rcompat/fs/FileRef";
|
|
10
8
|
import APPLICATION_JSON from "@rcompat/http/mime/application/json";
|
|
11
9
|
import Status from "@rcompat/http/Status";
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
async function normalize(path) {
|
|
18
|
-
return `p_${await hash(path)}`;
|
|
10
|
+
import p from "pema";
|
|
11
|
+
async function normalize(path, frontend) {
|
|
12
|
+
const file = new FileRef(path);
|
|
13
|
+
const basename = path.slice(0, -file.fullExtension.length);
|
|
14
|
+
return `p_${await hash(`${basename}.${frontend}`)}`;
|
|
19
15
|
}
|
|
20
16
|
export default class FrontendModule extends Module {
|
|
21
17
|
#options;
|
|
@@ -24,10 +20,11 @@ export default class FrontendModule extends Module {
|
|
|
24
20
|
compile = {};
|
|
25
21
|
css;
|
|
26
22
|
conditions = [];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
#mode = "development";
|
|
24
|
+
static schema = p({
|
|
25
|
+
fileExtensions: p.array(p.string).optional(),
|
|
26
|
+
spa: p.boolean.default(true),
|
|
27
|
+
ssr: p.boolean.default(true),
|
|
31
28
|
});
|
|
32
29
|
static options = FrontendModule.schema.infer;
|
|
33
30
|
static input = FrontendModule.schema.input;
|
|
@@ -45,12 +42,14 @@ export default class FrontendModule extends Module {
|
|
|
45
42
|
return `root_${this.name}`;
|
|
46
43
|
}
|
|
47
44
|
get ssr() {
|
|
48
|
-
return this.#options.ssr;
|
|
45
|
+
return this.#options.ssr && (this.#mode !== "development" || !this.client);
|
|
49
46
|
}
|
|
50
47
|
get spa() {
|
|
51
48
|
return this.#options.spa;
|
|
52
49
|
}
|
|
53
50
|
#load(name, props, app) {
|
|
51
|
+
if (!this.ssr)
|
|
52
|
+
return { view: null, name, props };
|
|
54
53
|
const view = app.loadView(name);
|
|
55
54
|
return { view, name, props };
|
|
56
55
|
}
|
|
@@ -76,7 +75,7 @@ export default class FrontendModule extends Module {
|
|
|
76
75
|
};
|
|
77
76
|
}
|
|
78
77
|
normalize(name) {
|
|
79
|
-
return normalize(name);
|
|
78
|
+
return normalize(name, this.name);
|
|
80
79
|
}
|
|
81
80
|
respond = (view, props = {}, options = {}) => async (app, { as_layout, layouts = [] } = {}, request) => {
|
|
82
81
|
if (as_layout) {
|
|
@@ -96,15 +95,16 @@ export default class FrontendModule extends Module {
|
|
|
96
95
|
};
|
|
97
96
|
const $props = this.layouts
|
|
98
97
|
? {
|
|
99
|
-
views: await map(views, ({ name }) => normalize(name)),
|
|
98
|
+
views: await map(views, ({ name }) => this.normalize(name)),
|
|
100
99
|
props: views.map(c => c.props),
|
|
101
100
|
request: $request,
|
|
102
101
|
}
|
|
103
102
|
: { props, request: $request };
|
|
104
103
|
const client = {
|
|
105
|
-
view: this.layouts ? "root" : await normalize(view),
|
|
104
|
+
view: this.layouts ? "root" : await this.normalize(view),
|
|
106
105
|
spa: this.spa,
|
|
107
106
|
ssr: this.ssr,
|
|
107
|
+
mode: app.mode,
|
|
108
108
|
...$props,
|
|
109
109
|
};
|
|
110
110
|
if (this.spa && request.headers.get("Accept") === APPLICATION_JSON) {
|
|
@@ -119,10 +119,14 @@ export default class FrontendModule extends Module {
|
|
|
119
119
|
status: options.status ?? Status.OK,
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
|
+
if (!this.ssr) {
|
|
123
|
+
const { head } = await this.#render({ view: null, props: {} }, client, app);
|
|
124
|
+
return app.view({ body: "<div id=\"app\"></div>", head, ...options });
|
|
125
|
+
}
|
|
122
126
|
try {
|
|
123
127
|
const server = this.layouts
|
|
124
128
|
? {
|
|
125
|
-
view: app.loadView(
|
|
129
|
+
view: app.loadView(this.rootname),
|
|
126
130
|
props: {
|
|
127
131
|
views: views.map(c => c.view),
|
|
128
132
|
props: views.map(c => c.props),
|
|
@@ -149,14 +153,16 @@ export default class FrontendModule extends Module {
|
|
|
149
153
|
publish(app) {
|
|
150
154
|
if (this.compile.client) {
|
|
151
155
|
const { compile, css, fileExtensions, name, root, conditions } = this;
|
|
156
|
+
const _normalize = this.normalize.bind(this);
|
|
152
157
|
if (this.client) {
|
|
153
|
-
app.frontends.set(name, fileExtensions);
|
|
158
|
+
app.frontends.set(name, [...fileExtensions]);
|
|
154
159
|
conditions.forEach(condition => app.conditions.add(condition));
|
|
155
160
|
}
|
|
156
|
-
app.
|
|
161
|
+
app.plugin("client", {
|
|
157
162
|
name,
|
|
158
163
|
setup(build) {
|
|
159
164
|
const resolveDir = app.root.path;
|
|
165
|
+
const css_cache = new Map();
|
|
160
166
|
if (root !== undefined) {
|
|
161
167
|
const filter = new RegExp(`^${name}:root`);
|
|
162
168
|
build.onResolve({ filter }, ({ path }) => {
|
|
@@ -168,14 +174,12 @@ export default class FrontendModule extends Module {
|
|
|
168
174
|
});
|
|
169
175
|
}
|
|
170
176
|
if (css !== undefined) {
|
|
171
|
-
build.onResolve({ filter: css
|
|
172
|
-
return { namespace: `${name}css
|
|
177
|
+
build.onResolve({ filter: new RegExp(`^${name}:css:`) }, args => {
|
|
178
|
+
return { path: args.path, namespace: `${name}-css` };
|
|
173
179
|
});
|
|
174
|
-
build.onLoad({ filter: css
|
|
175
|
-
const contents =
|
|
176
|
-
return contents
|
|
177
|
-
? { contents, loader: "css", resolveDir: resolveDir }
|
|
178
|
-
: null;
|
|
180
|
+
build.onLoad({ filter: /.*/, namespace: `${name}-css` }, args => {
|
|
181
|
+
const contents = css_cache.get(args.path);
|
|
182
|
+
return contents ? { contents, loader: "css" } : null;
|
|
179
183
|
});
|
|
180
184
|
}
|
|
181
185
|
const views_filter = new RegExp(`^${name}:views`);
|
|
@@ -189,7 +193,7 @@ export default class FrontendModule extends Module {
|
|
|
189
193
|
let contents = "";
|
|
190
194
|
for (const view of views) {
|
|
191
195
|
const { path } = view.debase(views_base, "/");
|
|
192
|
-
contents += `export { default as ${await
|
|
196
|
+
contents += `export { default as ${await _normalize(path)} }
|
|
193
197
|
from "#view/${path}";\n`;
|
|
194
198
|
}
|
|
195
199
|
return { contents, resolveDir: app.root.path };
|
|
@@ -197,16 +201,16 @@ export default class FrontendModule extends Module {
|
|
|
197
201
|
const filter = new RegExp(`(${fileExtensions.map(e => e.replace(".", "\\.")).join("|")})$`);
|
|
198
202
|
build.onLoad({ filter }, async (args) => {
|
|
199
203
|
const file = new FileRef(args.path);
|
|
200
|
-
//
|
|
204
|
+
// compile file to JavaScript and potentially CSS
|
|
201
205
|
const compiled = await compile.client(await file.text(), file, false);
|
|
202
206
|
let contents = compiled.js;
|
|
203
207
|
if (css
|
|
204
208
|
&& compiled.css !== null
|
|
205
209
|
&& compiled.css !== undefined
|
|
206
210
|
&& compiled.css !== "") {
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
contents += `\nimport "${
|
|
211
|
+
const css_path = `${name}:css:${args.path}`;
|
|
212
|
+
css_cache.set(css_path, compiled.css);
|
|
213
|
+
contents += `\nimport "${css_path}";`;
|
|
210
214
|
}
|
|
211
215
|
return { contents };
|
|
212
216
|
});
|
|
@@ -215,35 +219,28 @@ export default class FrontendModule extends Module {
|
|
|
215
219
|
}
|
|
216
220
|
}
|
|
217
221
|
init(app, next) {
|
|
222
|
+
this.#mode = app.mode;
|
|
223
|
+
return next(app);
|
|
224
|
+
}
|
|
225
|
+
prebuild(app) {
|
|
218
226
|
this.fileExtensions.forEach(e => {
|
|
219
227
|
app.bind(e, async (file, { context }) => {
|
|
220
|
-
|
|
228
|
+
if (context === "views" && !this.ssr)
|
|
229
|
+
return "";
|
|
230
|
+
// production: just compile to JS, don't bundle yet
|
|
221
231
|
if (this.compile.server) {
|
|
222
|
-
|
|
223
|
-
const bundled = await bundle({
|
|
224
|
-
code,
|
|
225
|
-
source: file,
|
|
226
|
-
root: app.root,
|
|
227
|
-
extensions: this.fileExtensions,
|
|
228
|
-
compile: async (s, f) => this.compile.server(s, f),
|
|
229
|
-
bundle: app.config("bundle"),
|
|
230
|
-
conditions: [...app.conditions],
|
|
231
|
-
});
|
|
232
|
-
return bundled;
|
|
232
|
+
return await this.compile.server(await file.text(), file);
|
|
233
233
|
}
|
|
234
234
|
return await file.text();
|
|
235
235
|
});
|
|
236
236
|
});
|
|
237
|
-
return next(app);
|
|
238
237
|
}
|
|
239
238
|
async build(app, next) {
|
|
239
|
+
this.prebuild(app);
|
|
240
240
|
// compile root server
|
|
241
241
|
if (this.root !== undefined && this.compile.server !== undefined) {
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
const path = app.runpath(location.server, filename);
|
|
245
|
-
await path.write(root);
|
|
246
|
-
app.addRoot(path);
|
|
242
|
+
const source = await this.compile.server(this.root.create(app.depth(), app.i18n_active));
|
|
243
|
+
app.addRoot(this.rootname, source);
|
|
247
244
|
}
|
|
248
245
|
this.publish(app);
|
|
249
246
|
return next(app);
|
|
@@ -4,7 +4,7 @@ import type NextHandle from "#module/NextHandle";
|
|
|
4
4
|
import type NextRoute from "#module/NextRoute";
|
|
5
5
|
import type NextServe from "#module/NextServe";
|
|
6
6
|
import type RequestFacade from "#request/RequestFacade";
|
|
7
|
-
import type ServeApp from "#
|
|
7
|
+
import type ServeApp from "#serve/App";
|
|
8
8
|
export default class I18NModule extends Module {
|
|
9
9
|
#private;
|
|
10
10
|
name: string;
|
|
@@ -70,7 +70,7 @@ export default class I18NModule extends Module {
|
|
|
70
70
|
headers: {
|
|
71
71
|
"Content-Length": String(0),
|
|
72
72
|
},
|
|
73
|
-
status: Status.NO_CONTENT
|
|
73
|
+
status: Status.NO_CONTENT,
|
|
74
74
|
});
|
|
75
75
|
// only accept configured locales
|
|
76
76
|
if (!this.#configured(requested))
|
|
@@ -78,7 +78,7 @@ export default class I18NModule extends Module {
|
|
|
78
78
|
headers: {
|
|
79
79
|
"Content-Length": String(0),
|
|
80
80
|
},
|
|
81
|
-
status: Status.NO_CONTENT
|
|
81
|
+
status: Status.NO_CONTENT,
|
|
82
82
|
});
|
|
83
83
|
const header = cookie(COOKIE_NAME, requested, {
|
|
84
84
|
secure: this.#secure,
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
readonly app_html: "app.html";
|
|
3
|
-
readonly build: "build";
|
|
4
3
|
readonly client: "client";
|
|
5
|
-
readonly lib: "lib";
|
|
6
|
-
readonly components: "components";
|
|
7
4
|
readonly config: "config";
|
|
8
5
|
readonly error_html: "error.html";
|
|
9
|
-
readonly modules: "modules";
|
|
10
6
|
readonly pages: "pages";
|
|
11
7
|
readonly routes: "routes";
|
|
12
|
-
readonly server: "server";
|
|
13
8
|
readonly static: "static";
|
|
14
9
|
readonly stores: "stores";
|
|
15
10
|
readonly locales: "locales";
|
|
16
11
|
readonly views: "views";
|
|
17
|
-
readonly hooks: "hooks";
|
|
18
12
|
};
|
|
19
13
|
export default _default;
|
|
20
14
|
//# sourceMappingURL=location.d.ts.map
|
package/lib/private/location.js
CHANGED
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
// default rendering template
|
|
3
3
|
app_html: "app.html",
|
|
4
|
-
// build environment
|
|
5
|
-
build: "build",
|
|
6
4
|
// client build
|
|
7
5
|
client: "client",
|
|
8
|
-
// component library
|
|
9
|
-
lib: "lib",
|
|
10
|
-
// renderable components
|
|
11
|
-
components: "components",
|
|
12
6
|
// config
|
|
13
7
|
config: "config",
|
|
14
8
|
// error rendering template
|
|
15
9
|
error_html: "error.html",
|
|
16
|
-
// custom modules
|
|
17
|
-
modules: "modules",
|
|
18
10
|
// HTML pages
|
|
19
11
|
pages: "pages",
|
|
20
12
|
// hierarchical routes
|
|
21
13
|
routes: "routes",
|
|
22
|
-
// server build
|
|
23
|
-
server: "server",
|
|
24
14
|
// static assets
|
|
25
15
|
static: "static",
|
|
26
16
|
// stores
|
|
@@ -29,7 +19,5 @@ export default {
|
|
|
29
19
|
locales: "locales",
|
|
30
20
|
// views
|
|
31
21
|
views: "views",
|
|
32
|
-
// hooks
|
|
33
|
-
hooks: "hooks",
|
|
34
22
|
};
|
|
35
23
|
//# sourceMappingURL=location.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import fail from "#fail";
|
|
2
|
+
import log from "#log";
|
|
3
|
+
async function resolve(root, config_paths) {
|
|
4
|
+
const tsconfig_path = root.join("tsconfig.json");
|
|
5
|
+
if (await tsconfig_path.exists()) {
|
|
6
|
+
try {
|
|
7
|
+
let text = await tsconfig_path.text();
|
|
8
|
+
// strip JSONC features
|
|
9
|
+
text = text
|
|
10
|
+
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
11
|
+
.replace(/\/\/.*/g, "")
|
|
12
|
+
.replace(/,(\s*[}\]])/g, "$1");
|
|
13
|
+
const config = JSON.parse(text);
|
|
14
|
+
const ts_paths = config.compilerOptions?.paths ?? {};
|
|
15
|
+
if (config_paths !== undefined && Object.keys(ts_paths).length > 0) {
|
|
16
|
+
return fail("tsconfig.json exists with paths, remove config paths");
|
|
17
|
+
}
|
|
18
|
+
// merge with defaults (user paths override)
|
|
19
|
+
return { ...ts_paths };
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
log.warn("Failed to parse tsconfig.json, falling back to config");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (config_paths !== undefined)
|
|
26
|
+
return config_paths;
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
export default resolve;
|
|
30
|
+
//# sourceMappingURL=paths.js.map
|
package/lib/private/reducer.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type App from "#App";
|
|
2
|
-
import type BuildApp from "#
|
|
2
|
+
import type BuildApp from "#build/App";
|
|
3
3
|
import type Module from "#Module";
|
|
4
4
|
import type RequestFacade from "#request/RequestFacade";
|
|
5
5
|
import type ResponseLike from "#response/ResponseLike";
|
|
6
|
-
import type ServeApp from "#
|
|
6
|
+
import type ServeApp from "#serve/App";
|
|
7
7
|
type HookInput = {
|
|
8
8
|
build: BuildApp;
|
|
9
9
|
handle: RequestFacade;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import log from "#log";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import response_error from "#response/error";
|
|
3
|
+
import response_json from "#response/json";
|
|
4
4
|
import respond from "#response/respond";
|
|
5
5
|
import guard from "#route/guard";
|
|
6
6
|
import Status from "@rcompat/http/Status";
|
|
7
7
|
import ParseError from "pema/ParseError";
|
|
8
8
|
async function reducer(hooks, request) {
|
|
9
9
|
const [first, ...rest] = hooks;
|
|
10
|
-
if (rest.length === 0)
|
|
10
|
+
if (rest.length === 0)
|
|
11
11
|
return await first(request, _ => new Response());
|
|
12
|
-
}
|
|
13
|
-
;
|
|
14
12
|
return await first(request, _ => reducer(rest, _));
|
|
15
13
|
}
|
|
16
14
|
;
|
|
@@ -30,7 +28,7 @@ export default async function (app, partial_request) {
|
|
|
30
28
|
try {
|
|
31
29
|
const route = await app.route(partial_request);
|
|
32
30
|
if (route === undefined) {
|
|
33
|
-
return
|
|
31
|
+
return response_error()(app, {}, partial_request);
|
|
34
32
|
}
|
|
35
33
|
const { errors, guards, handler, layouts } = route;
|
|
36
34
|
errorRoute = errors[0];
|
|
@@ -45,7 +43,7 @@ export default async function (app, partial_request) {
|
|
|
45
43
|
catch (error) {
|
|
46
44
|
const request = partial_request;
|
|
47
45
|
if (error instanceof ParseError) {
|
|
48
|
-
return
|
|
46
|
+
return response_json(error.toJSON(), { status: Status.BAD_REQUEST })(app);
|
|
49
47
|
}
|
|
50
48
|
log.error(error);
|
|
51
49
|
// the +error.js page itself could fail
|
|
@@ -53,7 +51,7 @@ export default async function (app, partial_request) {
|
|
|
53
51
|
return respond(await errorRoute(request))(app, {}, request);
|
|
54
52
|
}
|
|
55
53
|
catch {
|
|
56
|
-
return
|
|
54
|
+
return response_error()(app, {}, request);
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
57
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type View from "#frontend/View";
|
|
2
2
|
import type RequestFacade from "#request/RequestFacade";
|
|
3
|
-
import type ServeApp from "#
|
|
3
|
+
import type ServeApp from "#serve/App";
|
|
4
4
|
import type Dict from "@rcompat/type/Dict";
|
|
5
5
|
import type MaybePromise from "@rcompat/type/MaybePromise";
|
|
6
6
|
type ResponseFunction = (app: ServeApp, transfer: Dict, request: RequestFacade) => MaybePromise<View | null | Response | undefined>;
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* @param options response options
|
|
5
5
|
* @return Response rendering function
|
|
6
6
|
*/
|
|
7
|
-
declare const _default: (body: unknown, init?: ResponseInit) => (app: import("../
|
|
7
|
+
declare const _default: (body: unknown, init?: ResponseInit) => (app: import("../serve/App.js").default) => import("@rcompat/type/MaybePromise").default<Response>;
|
|
8
8
|
export default _default;
|
|
9
9
|
//# sourceMappingURL=json.d.ts.map
|
|
@@ -10,6 +10,6 @@ type Body = {
|
|
|
10
10
|
* @param options response options
|
|
11
11
|
* @return Response rendering function
|
|
12
12
|
*/
|
|
13
|
-
declare const _default: (body: Body, init?: ResponseInit) => (app: import("../
|
|
13
|
+
declare const _default: (body: Body, init?: ResponseInit) => (app: import("../serve/App.js").default) => import("@rcompat/type/MaybePromise").default<Response>;
|
|
14
14
|
export default _default;
|
|
15
15
|
//# sourceMappingURL=sse.d.ts.map
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* @param options response options
|
|
5
5
|
* @return Response rendering function
|
|
6
6
|
*/
|
|
7
|
-
declare const _default: (body: string, init?: ResponseInit) => (app: import("../
|
|
7
|
+
declare const _default: (body: string, init?: ResponseInit) => (app: import("../serve/App.js").default) => import("@rcompat/type/MaybePromise").default<Response>;
|
|
8
8
|
export default _default;
|
|
9
9
|
//# sourceMappingURL=text.d.ts.map
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* @return Response rendering function
|
|
8
|
-
*/
|
|
9
|
-
declare const view: ViewResponse;
|
|
1
|
+
import type ViewOptions from "#frontend/ViewOptions";
|
|
2
|
+
import type Dict from "@rcompat/type/Dict";
|
|
3
|
+
import type ResponseFunction from "./ResponseFunction.js";
|
|
4
|
+
declare function view<Props>(component: (props: Props) => any, props: Props, options?: ViewOptions): ResponseFunction;
|
|
5
|
+
declare function view(component: () => any, props?: Dict, options?: ViewOptions): ResponseFunction;
|
|
6
|
+
declare function view(name: string, props?: Dict, options?: ViewOptions): ResponseFunction;
|
|
10
7
|
export default view;
|
|
11
8
|
//# sourceMappingURL=view.d.ts.map
|
|
@@ -9,7 +9,6 @@ const backmap = {
|
|
|
9
9
|
htmx: "htmx",
|
|
10
10
|
marko: "marko",
|
|
11
11
|
md: "markdown",
|
|
12
|
-
poly: "poly",
|
|
13
12
|
solid: "solid",
|
|
14
13
|
svelte: "svelte",
|
|
15
14
|
voby: "voby",
|
|
@@ -24,7 +23,7 @@ function no_frontend(view) {
|
|
|
24
23
|
const error = "No frontend for {0}";
|
|
25
24
|
const fix = hasPkg ? ", did you configure {1}?" : "";
|
|
26
25
|
const pkgname = hasPkg ? `@primate/${backmap[extension]}` : "";
|
|
27
|
-
|
|
26
|
+
return fail(`${error}${fix}`, view, pkgname);
|
|
28
27
|
}
|
|
29
28
|
/**
|
|
30
29
|
* Render a view component using a frontend for the given filename extension
|
|
@@ -33,11 +32,16 @@ function no_frontend(view) {
|
|
|
33
32
|
* @param options rendering options
|
|
34
33
|
* @return Response rendering function
|
|
35
34
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
function view(name, props, options) {
|
|
36
|
+
const _name = name;
|
|
37
|
+
return async (app, transfer, request) => {
|
|
38
|
+
const found_view = extensions
|
|
39
|
+
.map(extension => app.frontends[new FileRef(_name)[extension]])
|
|
40
|
+
.find(extension => extension !== undefined)?.(_name, props, options)(app, transfer, request);
|
|
41
|
+
if (found_view !== undefined)
|
|
42
|
+
return found_view;
|
|
43
|
+
throw no_frontend(_name);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
42
46
|
export default view;
|
|
43
47
|
//# sourceMappingURL=view.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type ServeApp from "#
|
|
1
|
+
import type ServeApp from "#serve/App";
|
|
2
2
|
import type MaybePromise from "@rcompat/type/MaybePromise";
|
|
3
3
|
declare const _default: <T>(mime: string, mapper: (input: T) => BodyInit) => (body: T, init?: ResponseInit) => (app: ServeApp) => MaybePromise<Response>;
|
|
4
4
|
export default _default;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type Verb from "#request/Verb";
|
|
2
2
|
import type RouteHandler from "#route/Handler";
|
|
3
3
|
import type RouteOptions from "#route/Options";
|
|
4
|
+
export declare const routes: string[];
|
|
4
5
|
declare class Router {
|
|
5
6
|
#private;
|
|
6
7
|
push(route: string): void;
|
|
@@ -8,11 +9,11 @@ declare class Router {
|
|
|
8
9
|
get active(): string | undefined;
|
|
9
10
|
add(verb: Verb, handler: RouteHandler, options?: RouteOptions): void;
|
|
10
11
|
get(path: string): {
|
|
11
|
-
|
|
12
|
+
head?: {
|
|
12
13
|
handler: RouteHandler;
|
|
13
14
|
options: RouteOptions;
|
|
14
15
|
} | undefined;
|
|
15
|
-
|
|
16
|
+
options?: {
|
|
16
17
|
handler: RouteHandler;
|
|
17
18
|
options: RouteOptions;
|
|
18
19
|
} | undefined;
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import assert from "@rcompat/assert";
|
|
2
2
|
import is from "@rcompat/assert/is";
|
|
3
3
|
import maybe from "@rcompat/assert/maybe";
|
|
4
|
+
const stack = [];
|
|
5
|
+
export const routes = stack;
|
|
4
6
|
class Router {
|
|
5
7
|
#routes = {};
|
|
6
|
-
#stack = [];
|
|
7
8
|
push(route) {
|
|
8
|
-
|
|
9
|
+
stack.push(route);
|
|
9
10
|
}
|
|
10
11
|
pop() {
|
|
11
|
-
|
|
12
|
+
stack.pop();
|
|
12
13
|
}
|
|
13
14
|
get active() {
|
|
14
|
-
return
|
|
15
|
+
return stack.at(-1);
|
|
15
16
|
}
|
|
16
17
|
add(verb, handler, options = {}) {
|
|
17
18
|
assert(this.active !== undefined);
|