primate 0.37.0 → 0.39.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/bin.js +3 -2
- package/lib/commands/Command.d.ts +4 -0
- package/lib/commands/Command.js +2 -0
- package/lib/commands/build.d.ts +3 -2
- package/lib/commands/build.js +19 -16
- package/lib/commands/dev.d.ts +3 -2
- package/lib/commands/dev.js +4 -2
- package/lib/commands/index.d.ts +1 -4
- package/lib/commands/index.js +2 -5
- package/lib/commands/init.d.ts +3 -1
- package/lib/commands/init.js +57 -51
- package/lib/commands/migrate-apply.d.ts +3 -1
- package/lib/commands/migrate-apply.js +6 -8
- package/lib/commands/migrate-create.d.ts +3 -1
- package/lib/commands/migrate-create.js +10 -12
- package/lib/commands/migrate-status.d.ts +3 -1
- package/lib/commands/migrate-status.js +6 -9
- package/lib/commands/serve.d.ts +3 -1
- package/lib/commands/serve.js +7 -6
- package/lib/public/http/Status.d.ts +65 -1
- package/lib/public/http/Status.js +2 -1
- package/lib/public/i18n.d.ts +2 -0
- package/lib/public/i18n.js +2 -0
- package/lib/public/loader.d.ts +2 -0
- package/lib/public/loader.js +2 -0
- package/lib/public/{db.d.ts → memorydb.d.ts} +1 -1
- package/lib/public/{db.js → memorydb.js} +1 -1
- package/lib/public/response.d.ts +2 -2
- package/lib/public/session.d.ts +2 -0
- package/lib/public/session.js +2 -0
- package/lib/public/store.d.ts +2 -0
- package/lib/public/store.js +2 -0
- package/package.json +16 -14
- package/lib/commands/get-flag.d.ts +0 -2
- package/lib/commands/get-flag.js +0 -5
- package/lib/commands/test.d.ts +0 -3
- package/lib/commands/test.js +0 -132
- package/lib/init.d.ts +0 -3
- package/lib/init.js +0 -9
- package/lib/private/test.d.ts +0 -31
- package/lib/private/test.js +0 -8
- package/lib/public/config/i18n.d.ts +0 -2
- package/lib/public/config/i18n.js +0 -2
- package/lib/public/config/session.d.ts +0 -2
- package/lib/public/config/session.js +0 -2
- package/lib/public/i18n/locale.d.ts +0 -2
- package/lib/public/i18n/locale.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/route/hook.d.ts +0 -2
- package/lib/public/route/hook.js +0 -2
- package/lib/public/s/internal.d.ts +0 -2
- package/lib/public/s/internal.js +0 -2
- package/lib/public/test.d.ts +0 -2
- package/lib/public/test.js +0 -2
package/lib/bin.js
CHANGED
package/lib/commands/build.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
1
|
+
import type Command from "./Command.js";
|
|
2
|
+
declare const command_build: Command;
|
|
3
|
+
export default command_build;
|
|
3
4
|
//# sourceMappingURL=build.d.ts.map
|
package/lib/commands/build.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
+
import core from "@primate/core";
|
|
1
2
|
import build from "@primate/core/build";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import get_flag from "./get-flag.js";
|
|
3
|
+
import Flags from "@primate/core/Flags";
|
|
4
|
+
import cli from "@rcompat/cli";
|
|
5
|
+
import runtime from "@rcompat/runtime";
|
|
6
6
|
function orange(x) {
|
|
7
7
|
return `\x1b[38;2;255;165;0m${x}\x1b[0m`;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
const { name, version
|
|
11
|
-
print(
|
|
12
|
-
const root = await
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
;
|
|
9
|
+
const command_build = async (mode) => {
|
|
10
|
+
const { name, version } = await runtime.packageJSON(import.meta.dirname);
|
|
11
|
+
cli.print(cli.fg.bold(orange((name.toUpperCase()))), orange(version), "\n\n");
|
|
12
|
+
const root = await runtime.projectRoot();
|
|
13
|
+
core.try(async () => {
|
|
14
|
+
const flags = Flags.parse({
|
|
15
|
+
mode: mode,
|
|
16
|
+
target: runtime.flags.try("--target"),
|
|
17
|
+
outdir: runtime.flags.try("--outdir"),
|
|
18
|
+
log: runtime.flags.try("--log"),
|
|
19
|
+
});
|
|
20
|
+
await build(root, flags);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
export default command_build;
|
|
21
24
|
//# sourceMappingURL=build.js.map
|
package/lib/commands/dev.d.ts
CHANGED
package/lib/commands/dev.js
CHANGED
package/lib/commands/index.d.ts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import migrate_create from "./migrate-create.js";
|
|
3
|
-
import serve from "./serve.js";
|
|
4
|
-
export default function run_command(command_flag?: string): typeof build | typeof serve | typeof migrate_create | (() => void);
|
|
1
|
+
export default function run_command(command_flag?: string): import("./Command.js").default;
|
|
5
2
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/commands/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import print from "@rcompat/cli/print";
|
|
1
|
+
import cli from "@rcompat/cli";
|
|
3
2
|
import build from "./build.js";
|
|
4
3
|
import dev from "./dev.js";
|
|
5
4
|
import init from "./init.js";
|
|
@@ -7,20 +6,18 @@ import migrate_apply from "./migrate-apply.js";
|
|
|
7
6
|
import migrate_create from "./migrate-create.js";
|
|
8
7
|
import migrate_status from "./migrate-status.js";
|
|
9
8
|
import serve from "./serve.js";
|
|
10
|
-
import test from "./test.js";
|
|
11
9
|
const commands = {
|
|
12
10
|
build,
|
|
13
11
|
dev,
|
|
14
12
|
init,
|
|
15
13
|
serve,
|
|
16
|
-
test,
|
|
17
14
|
migrate_apply,
|
|
18
15
|
migrate_create,
|
|
19
16
|
migrate_status,
|
|
20
17
|
};
|
|
21
18
|
function unknown(command) {
|
|
22
19
|
return () => {
|
|
23
|
-
print(`Unknown command ${
|
|
20
|
+
cli.print(`Unknown command ${cli.fg.dim(command)}\n`);
|
|
24
21
|
};
|
|
25
22
|
}
|
|
26
23
|
;
|
package/lib/commands/init.d.ts
CHANGED
package/lib/commands/init.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import intro from "@rcompat/cli/prompts/intro";
|
|
4
|
-
import is_cancel from "@rcompat/cli/prompts/is-cancel";
|
|
5
|
-
import multiselect from "@rcompat/cli/prompts/multiselect";
|
|
6
|
-
import outro from "@rcompat/cli/prompts/outro";
|
|
7
|
-
import select from "@rcompat/cli/prompts/select";
|
|
8
|
-
import text from "@rcompat/cli/prompts/text";
|
|
1
|
+
import core from "@primate/core";
|
|
2
|
+
import cli from "@rcompat/cli";
|
|
9
3
|
import fs from "@rcompat/fs";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
4
|
+
import is from "@rcompat/is";
|
|
5
|
+
import runtime_mod from "@rcompat/runtime";
|
|
13
6
|
const FRONTEND_OPTIONS = [
|
|
14
7
|
{ label: "Angular", value: "angular" },
|
|
15
8
|
{ label: "Eta", value: "eta" },
|
|
@@ -29,13 +22,13 @@ const BACKEND_OPTIONS = [
|
|
|
29
22
|
{ label: "Go", value: "go" },
|
|
30
23
|
{ label: "Python", value: "python" },
|
|
31
24
|
{ label: "Ruby", value: "ruby" },
|
|
32
|
-
{ label: "Grain", value: "grain" },
|
|
33
25
|
];
|
|
34
26
|
const DATABASE_OPTIONS = [
|
|
35
27
|
{ label: "SQLite", value: "sqlite" },
|
|
36
28
|
{ label: "PostgreSQL", value: "postgresql" },
|
|
37
29
|
{ label: "MySQL", value: "mysql" },
|
|
38
30
|
{ label: "MongoDB", value: "mongodb" },
|
|
31
|
+
{ label: "Oracle", value: "oracledb" },
|
|
39
32
|
];
|
|
40
33
|
// peer deps per frontend (npm names)
|
|
41
34
|
const FRONTEND_PEER_DEPS = {
|
|
@@ -53,15 +46,23 @@ const FRONTEND_PEER_DEPS = {
|
|
|
53
46
|
vue: ["vue"],
|
|
54
47
|
"webc": [],
|
|
55
48
|
};
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
function abort() {
|
|
50
|
+
return cli.prompt.cancel("Aborted");
|
|
51
|
+
}
|
|
52
|
+
function is_cancel(x) {
|
|
53
|
+
return is.symbol(x) || prompt.isCancel(x);
|
|
54
|
+
}
|
|
55
|
+
const { prompt } = cli;
|
|
56
|
+
const command_init = async () => {
|
|
57
|
+
prompt.intro("Create a new Primate app");
|
|
58
58
|
let directory;
|
|
59
59
|
let target;
|
|
60
|
+
const log = core.logger(runtime_mod.flags.try("--log") ?? "warn");
|
|
60
61
|
while (true) {
|
|
61
|
-
const ans = await text({
|
|
62
|
+
const ans = await prompt.text({
|
|
62
63
|
message: "Directory to create app?", initial: ".",
|
|
63
64
|
});
|
|
64
|
-
if (
|
|
65
|
+
if (is.symbol(ans) || prompt.isCancel(ans))
|
|
65
66
|
return abort();
|
|
66
67
|
target = fs.ref(ans);
|
|
67
68
|
if (await empty(target)) {
|
|
@@ -69,23 +70,23 @@ export default async function init() {
|
|
|
69
70
|
break; // valid directory found, exit loop
|
|
70
71
|
}
|
|
71
72
|
// directory not empty, show error but continue loop
|
|
72
|
-
|
|
73
|
+
log.error("Directory not empty, choose another.");
|
|
73
74
|
}
|
|
74
|
-
const frontends = await multiselect({
|
|
75
|
+
const frontends = await prompt.multiselect({
|
|
75
76
|
message: "Choose frontend (press Enter to skip)",
|
|
76
77
|
options: FRONTEND_OPTIONS,
|
|
77
78
|
initial: [],
|
|
78
79
|
});
|
|
79
|
-
if (
|
|
80
|
+
if (is_cancel(frontends))
|
|
80
81
|
return abort();
|
|
81
|
-
const backends = await multiselect({
|
|
82
|
+
const backends = await prompt.multiselect({
|
|
82
83
|
message: "Choose backend (press Enter to skip)",
|
|
83
84
|
options: BACKEND_OPTIONS,
|
|
84
85
|
initial: [],
|
|
85
86
|
});
|
|
86
|
-
if (
|
|
87
|
+
if (is_cancel(backends))
|
|
87
88
|
return abort();
|
|
88
|
-
const runtime = await select({
|
|
89
|
+
const runtime = await prompt.select({
|
|
89
90
|
message: "Choose runtime",
|
|
90
91
|
options: [
|
|
91
92
|
{ label: "Node", value: "node" },
|
|
@@ -94,17 +95,17 @@ export default async function init() {
|
|
|
94
95
|
],
|
|
95
96
|
initial: 0,
|
|
96
97
|
});
|
|
97
|
-
if (
|
|
98
|
+
if (is_cancel(runtime))
|
|
98
99
|
return abort();
|
|
99
|
-
const dbs = await multiselect({
|
|
100
|
+
const dbs = await prompt.multiselect({
|
|
100
101
|
message: "Choose a database (press Enter to skip)",
|
|
101
102
|
options: DATABASE_OPTIONS,
|
|
102
103
|
initial: [],
|
|
103
104
|
});
|
|
104
|
-
if (
|
|
105
|
+
if (is_cancel(dbs))
|
|
105
106
|
return abort();
|
|
106
107
|
const db = dbs[0];
|
|
107
|
-
const i18n = await select({
|
|
108
|
+
const i18n = await prompt.select({
|
|
108
109
|
message: "Enable i18n?",
|
|
109
110
|
options: [
|
|
110
111
|
{ label: "Yes", value: "yes" },
|
|
@@ -112,10 +113,10 @@ export default async function init() {
|
|
|
112
113
|
],
|
|
113
114
|
initial: 1,
|
|
114
115
|
});
|
|
115
|
-
if (
|
|
116
|
+
if (is_cancel(i18n))
|
|
116
117
|
return abort();
|
|
117
118
|
const with_i18n = i18n === "yes";
|
|
118
|
-
const sessions = await select({
|
|
119
|
+
const sessions = await prompt.select({
|
|
119
120
|
message: "Configure sessions?",
|
|
120
121
|
options: [
|
|
121
122
|
{ label: "Yes", value: "yes" },
|
|
@@ -123,30 +124,30 @@ export default async function init() {
|
|
|
123
124
|
],
|
|
124
125
|
initial: 1,
|
|
125
126
|
});
|
|
126
|
-
if (
|
|
127
|
+
if (is_cancel(sessions))
|
|
127
128
|
return abort();
|
|
128
|
-
const
|
|
129
|
+
const with_sessions = sessions === "yes";
|
|
129
130
|
await target.create();
|
|
130
131
|
await target.join("routes").create();
|
|
131
132
|
await target.join("views").create();
|
|
132
|
-
if (db
|
|
133
|
+
if (is.defined(db))
|
|
133
134
|
await target.join("stores").create();
|
|
134
135
|
// files
|
|
135
136
|
await gitignore(target);
|
|
136
137
|
await tsconfig_json(target, { frontends });
|
|
137
|
-
await app_config(target, { frontends
|
|
138
|
+
await app_config(target, { frontends, backends, runtime });
|
|
138
139
|
if (with_i18n)
|
|
139
140
|
await i18n_config(target);
|
|
140
|
-
if (
|
|
141
|
+
if (with_sessions)
|
|
141
142
|
await session_config(target);
|
|
142
|
-
if (db)
|
|
143
|
+
if (is.defined(db))
|
|
143
144
|
await database_config(target, db);
|
|
144
|
-
await package_json(target, { directory, runtime });
|
|
145
|
-
const packages = compute_packages({ frontends
|
|
145
|
+
await package_json(target, { directory, runtime: runtime });
|
|
146
|
+
const packages = compute_packages({ frontends, backends, db });
|
|
146
147
|
const install = build_install_command(runtime, packages, directory);
|
|
147
|
-
outro(`${
|
|
148
|
+
prompt.outro(`${cli.fg.green("done, now run")} ${cli.fg.dim(install.print)}`);
|
|
148
149
|
process.exit();
|
|
149
|
-
}
|
|
150
|
+
};
|
|
150
151
|
async function empty(directory) {
|
|
151
152
|
try {
|
|
152
153
|
if (!(await directory.exists()))
|
|
@@ -199,14 +200,14 @@ async function i18n_config(root) {
|
|
|
199
200
|
const i18i = root.join("config").join("i18n.ts");
|
|
200
201
|
await en_us.directory.create();
|
|
201
202
|
await i18i.directory.create();
|
|
202
|
-
const locale = `import
|
|
203
|
-
export default locale({
|
|
203
|
+
const locale = `import i18n from "primate/i18n";
|
|
204
|
+
export default i18n.locale({
|
|
204
205
|
hi: "Hello",
|
|
205
206
|
placeheld: "Hello, {name}",
|
|
206
207
|
});`;
|
|
207
208
|
await en_us.write(locale);
|
|
208
209
|
const config = `import en from "#locale/en-US";
|
|
209
|
-
import i18n from "primate/
|
|
210
|
+
import i18n from "primate/i18n";
|
|
210
211
|
|
|
211
212
|
export default i18n({
|
|
212
213
|
defaultLocale: "en-US",
|
|
@@ -219,12 +220,12 @@ export default i18n({
|
|
|
219
220
|
async function session_config(root) {
|
|
220
221
|
const file = root.join("config").join("session.ts");
|
|
221
222
|
await file.directory.create();
|
|
222
|
-
const body = `import session from "primate/
|
|
223
|
+
const body = `import session from "primate/session";
|
|
223
224
|
export default session({});`;
|
|
224
225
|
await file.write(body);
|
|
225
226
|
}
|
|
226
227
|
async function database_config(root, db) {
|
|
227
|
-
const file = root.join("config").join("
|
|
228
|
+
const file = root.join("config").join("db.ts");
|
|
228
229
|
await file.directory.create();
|
|
229
230
|
const ident = to_ident(db);
|
|
230
231
|
const body = `import ${ident} from "@primate/${db}";
|
|
@@ -259,7 +260,9 @@ async function package_json(root, c) {
|
|
|
259
260
|
await pkgFile.writeJSON(pkg);
|
|
260
261
|
}
|
|
261
262
|
function safe(s) {
|
|
262
|
-
return s
|
|
263
|
+
return s
|
|
264
|
+
.trim()
|
|
265
|
+
.toLowerCase().replace(/\s+/g, "-")
|
|
263
266
|
.replace(/[^a-z0-9._-]/g, "") || "primate-app";
|
|
264
267
|
}
|
|
265
268
|
function to_ident(token) {
|
|
@@ -286,7 +289,7 @@ function compute_packages(args) {
|
|
|
286
289
|
for (const b of args.backends)
|
|
287
290
|
deps.add(`@primate/${b}`);
|
|
288
291
|
// database → @primate/<token>, if selected
|
|
289
|
-
if (args.db)
|
|
292
|
+
if (is.defined(args.db))
|
|
290
293
|
deps.add(`@primate/${args.db}`);
|
|
291
294
|
return {
|
|
292
295
|
dependencies: Array.from(deps),
|
|
@@ -336,22 +339,25 @@ function build_install_command(runtime, packages, dir) {
|
|
|
336
339
|
async function tsconfig_json(root, opts) {
|
|
337
340
|
const is_react = opts.frontends.includes("react");
|
|
338
341
|
const is_svelte = opts.frontends.includes("svelte");
|
|
339
|
-
const
|
|
342
|
+
const ts_config = {
|
|
340
343
|
extends: "primate/tsconfig",
|
|
341
344
|
compilerOptions: {
|
|
342
345
|
baseUrl: "${configDir}",
|
|
343
346
|
paths: {
|
|
344
|
-
"#config/*": ["config/*"],
|
|
345
347
|
"#session": ["config/session"],
|
|
348
|
+
"#db": ["config/db"],
|
|
346
349
|
"#i18n": ["config/i18n"],
|
|
350
|
+
"#config/*": ["config/*"],
|
|
347
351
|
"#view/*": ["views/*"],
|
|
348
352
|
"#component/*": ["components/*"],
|
|
353
|
+
"#route/*": ["routes/*"],
|
|
349
354
|
"#store/*": ["stores/*"],
|
|
350
355
|
"#locale/*": ["locales/*"],
|
|
351
356
|
"#static/*": ["static/*"],
|
|
352
357
|
},
|
|
353
358
|
},
|
|
354
359
|
include: [
|
|
360
|
+
"client",
|
|
355
361
|
"config",
|
|
356
362
|
"views",
|
|
357
363
|
"components",
|
|
@@ -359,14 +365,14 @@ async function tsconfig_json(root, opts) {
|
|
|
359
365
|
"stores",
|
|
360
366
|
"locales",
|
|
361
367
|
"static",
|
|
362
|
-
"test",
|
|
363
368
|
],
|
|
364
369
|
exclude: ["node_modules"],
|
|
365
370
|
};
|
|
366
371
|
if (is_react)
|
|
367
|
-
|
|
372
|
+
ts_config.compilerOptions.jsx = "react-jsx";
|
|
368
373
|
if (is_svelte)
|
|
369
|
-
|
|
370
|
-
await root.join("tsconfig.json").writeJSON(
|
|
374
|
+
ts_config.compilerOptions.plugins = [{ name: "@plsp/svelte" }];
|
|
375
|
+
await root.join("tsconfig.json").writeJSON(ts_config);
|
|
371
376
|
}
|
|
377
|
+
export default command_init;
|
|
372
378
|
//# sourceMappingURL=init.js.map
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
+
import core from "@primate/core";
|
|
1
2
|
import migrate from "@primate/core/db/migrate";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
try {
|
|
3
|
+
const command_migrate_apply = async () => {
|
|
4
|
+
core.try(async () => {
|
|
5
5
|
await migrate.apply();
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
log.error(cause);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
6
|
+
});
|
|
7
|
+
};
|
|
11
8
|
;
|
|
9
|
+
export default command_migrate_apply;
|
|
12
10
|
//# sourceMappingURL=migrate-apply.js.map
|
|
@@ -1,23 +1,21 @@
|
|
|
1
|
+
import core from "@primate/core";
|
|
1
2
|
import migrate from "@primate/core/db/migrate";
|
|
2
|
-
import log from "@primate/core/log";
|
|
3
3
|
import error from "@rcompat/error";
|
|
4
|
-
|
|
4
|
+
import runtime from "@rcompat/runtime";
|
|
5
|
+
const name_flag = "--name";
|
|
5
6
|
function create_requires_name_flag() {
|
|
6
|
-
return error.template `migrate:create requires a ${
|
|
7
|
+
return error.template `migrate:create requires a ${name_flag} flag`;
|
|
7
8
|
}
|
|
8
9
|
const errors = error.coded({
|
|
9
10
|
create_requires_name_flag,
|
|
10
11
|
});
|
|
11
|
-
|
|
12
|
-
const name = flags.
|
|
13
|
-
try {
|
|
12
|
+
const command_migrate_create = async () => {
|
|
13
|
+
const name = runtime.flags.try(name_flag);
|
|
14
|
+
core.try(async () => {
|
|
14
15
|
if (name === undefined)
|
|
15
16
|
throw errors.create_requires_name_flag();
|
|
16
17
|
await migrate.create(name);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
;
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export default command_migrate_create;
|
|
23
21
|
//# sourceMappingURL=migrate-create.js.map
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
+
import core from "@primate/core";
|
|
1
2
|
import migrate from "@primate/core/db/migrate";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
try {
|
|
3
|
+
const command_migrate_status = async () => {
|
|
4
|
+
core.try(async () => {
|
|
5
5
|
await migrate.status();
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
;
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
export default command_migrate_status;
|
|
12
9
|
//# sourceMappingURL=migrate-status.js.map
|
package/lib/commands/serve.d.ts
CHANGED
package/lib/commands/serve.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import fs from "@rcompat/fs";
|
|
2
|
-
import
|
|
2
|
+
import runtime from "@rcompat/runtime";
|
|
3
3
|
const load = async () => {
|
|
4
4
|
try {
|
|
5
|
-
return await
|
|
5
|
+
return await runtime.projectRoot();
|
|
6
6
|
}
|
|
7
7
|
catch {
|
|
8
8
|
return fs.resolve();
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
+
const command_serve = async () => {
|
|
12
|
+
const outdir = runtime.flags.try("--outdir") ?? "build";
|
|
13
|
+
return (await load()).join(`./${outdir}/server.js`).import();
|
|
14
|
+
};
|
|
11
15
|
// serve from build directory
|
|
12
|
-
export default
|
|
13
|
-
const dir = get_flag(flags, "dir") ?? "build";
|
|
14
|
-
return (await load()).join(`./${dir}/server.js`).import();
|
|
15
|
-
}
|
|
16
|
+
export default command_serve;
|
|
16
17
|
//# sourceMappingURL=serve.js.map
|
|
@@ -1,2 +1,66 @@
|
|
|
1
|
-
|
|
1
|
+
declare const _default: Readonly<{
|
|
2
|
+
ACCEPTED: 202;
|
|
3
|
+
ALREADY_REPORTED: 208;
|
|
4
|
+
BAD_GATEWAY: 502;
|
|
5
|
+
BAD_REQUEST: 400;
|
|
6
|
+
CONFLICT: 409;
|
|
7
|
+
CONTINUE: 100;
|
|
8
|
+
CREATED: 201;
|
|
9
|
+
EARLY_HINTS: 103;
|
|
10
|
+
EXPECTATION_FAILED: 417;
|
|
11
|
+
FAILED_DEPENDENCY: 424;
|
|
12
|
+
FORBIDDEN: 403;
|
|
13
|
+
FOUND: 302;
|
|
14
|
+
GATEWAY_TIMEOUT: 504;
|
|
15
|
+
GONE: 410;
|
|
16
|
+
HTTP_VERSION_NOT_SUPPORTED: 505;
|
|
17
|
+
IM_A_TEAPOT: 418;
|
|
18
|
+
IM_USED: 226;
|
|
19
|
+
INSUFFICIENT_STORAGE: 507;
|
|
20
|
+
INTERNAL_SERVER_ERROR: 500;
|
|
21
|
+
LENGTH_REQUIRED: 411;
|
|
22
|
+
LOCKED: 423;
|
|
23
|
+
LOOP_DETECTED: 508;
|
|
24
|
+
METHOD_NOT_ALLOWED: 405;
|
|
25
|
+
MISDIRECTED_REQUEST: 421;
|
|
26
|
+
MOVED_PERMANENTLY: 301;
|
|
27
|
+
MULTIPLE_CHOICES: 300;
|
|
28
|
+
NETWORK_AUTHENTICATION_REQUIRED: 511;
|
|
29
|
+
NO_CONTENT: 204;
|
|
30
|
+
NON_AUTHORITATIVE_INFORMATION: 203;
|
|
31
|
+
NOT_ACCEPTABLE: 406;
|
|
32
|
+
NOT_EXTENDED: 510;
|
|
33
|
+
NOT_FOUND: 404;
|
|
34
|
+
NOT_IMPLEMENTED: 501;
|
|
35
|
+
NOT_MODIFIED: 304;
|
|
36
|
+
OK: 200;
|
|
37
|
+
PARTIAL_CONTENT: 206;
|
|
38
|
+
PAYLOAD_TOO_LARGE: 413;
|
|
39
|
+
PAYMENT_REQUIRED: 402;
|
|
40
|
+
PERMANENT_REDIRECT: 308;
|
|
41
|
+
PRECONDITION_FAILED: 412;
|
|
42
|
+
PRECONDITION_REQUIRED: 428;
|
|
43
|
+
PROCESS: 102;
|
|
44
|
+
PROXY_AUTHENTICATION_REQUIRED: 407;
|
|
45
|
+
RANGE_NOT_SATISFIABLE: 416;
|
|
46
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE: 431;
|
|
47
|
+
REQUEST_TIMEOUT: 408;
|
|
48
|
+
RESET_CONTENT: 205;
|
|
49
|
+
SEE_OTHER: 303;
|
|
50
|
+
SERVICE_UNAVAILABLE: 503;
|
|
51
|
+
SWITCH_PROXY: 306;
|
|
52
|
+
SWITCHING_PROTOCOLS: 101;
|
|
53
|
+
TEMPORARY_REDIRECT: 307;
|
|
54
|
+
TOO_EARLY: 425;
|
|
55
|
+
TOO_MANY_REQUESTS: 429;
|
|
56
|
+
UNAUTHORIZED: 401;
|
|
57
|
+
UNAVAILABLE_FOR_LEGAL_REASONS: 451;
|
|
58
|
+
UNPROCESSABLE_ENTITY: 422;
|
|
59
|
+
UNSUPPORTED_MEDIA_TYPE: 415;
|
|
60
|
+
UPGRADE_REQUIRED: 426;
|
|
61
|
+
URI_TOO_LONG: 414;
|
|
62
|
+
USE_PROXY: 305;
|
|
63
|
+
VARIANT_ALSO_NEGOTIATES: 506;
|
|
64
|
+
}>;
|
|
65
|
+
export default _default;
|
|
2
66
|
//# sourceMappingURL=Status.d.ts.map
|
package/lib/public/response.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { ServeApp } from "@primate/core";
|
|
1
|
+
export type { ServeApp, ResponseFunction } from "@primate/core";
|
|
2
2
|
export type { ViewResponse } from "@primate/core/client";
|
|
3
|
-
export { default
|
|
3
|
+
export { default } from "@primate/core/response";
|
|
4
4
|
//# sourceMappingURL=response.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "primate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.0",
|
|
4
4
|
"description": "The universal web framework",
|
|
5
5
|
"homepage": "https://primate.run",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -17,20 +17,20 @@
|
|
|
17
17
|
"/lib/**/*.d.ts",
|
|
18
18
|
"!/**/*.spec.*"
|
|
19
19
|
],
|
|
20
|
-
"bin": "lib/bin.js",
|
|
21
20
|
"types": "lib/index.d.ts",
|
|
22
21
|
"dependencies": {
|
|
23
|
-
"@rcompat/cli": "^0.
|
|
24
|
-
"@rcompat/dict": "^0.
|
|
25
|
-
"@rcompat/error": "^0.
|
|
26
|
-
"@rcompat/fs": "^0.
|
|
27
|
-
"@rcompat/http": "~0.
|
|
28
|
-
"@rcompat/
|
|
29
|
-
"@rcompat/
|
|
30
|
-
"@
|
|
22
|
+
"@rcompat/cli": "^0.24.0",
|
|
23
|
+
"@rcompat/dict": "^0.10.0",
|
|
24
|
+
"@rcompat/error": "^0.8.0",
|
|
25
|
+
"@rcompat/fs": "^0.33.2",
|
|
26
|
+
"@rcompat/http": "~0.30.0",
|
|
27
|
+
"@rcompat/is": "^0.11.0",
|
|
28
|
+
"@rcompat/runtime": "^0.16.0",
|
|
29
|
+
"@rcompat/test": "^0.17.0",
|
|
30
|
+
"@primate/core": "^0.8.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@rcompat/type": "^0.
|
|
33
|
+
"@rcompat/type": "^0.17.0"
|
|
34
34
|
},
|
|
35
35
|
"engines": {
|
|
36
36
|
"node": ">=24"
|
|
@@ -58,9 +58,11 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
|
-
"build": "npm run clean &&
|
|
61
|
+
"build": "npm run clean && tsgo && cp src/app.tsconfig.json lib && cp src/types/app.d.ts lib && cp src/types/index.d.ts lib",
|
|
62
62
|
"clean": "rm -rf ./lib",
|
|
63
|
-
"lint": "eslint ."
|
|
64
|
-
|
|
63
|
+
"lint": "eslint ."
|
|
64
|
+
},
|
|
65
|
+
"bin": {
|
|
66
|
+
"primate": "lib/bin.js"
|
|
65
67
|
}
|
|
66
68
|
}
|
package/lib/commands/get-flag.js
DELETED
package/lib/commands/test.d.ts
DELETED
package/lib/commands/test.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { tests } from "#test";
|
|
2
|
-
import build from "@primate/core/build";
|
|
3
|
-
import color from "@rcompat/cli/color";
|
|
4
|
-
import entries from "@rcompat/dict/entries";
|
|
5
|
-
import fs from "@rcompat/fs";
|
|
6
|
-
import equals from "@rcompat/test/equals";
|
|
7
|
-
import includes from "@rcompat/test/includes";
|
|
8
|
-
import serve from "./serve.js";
|
|
9
|
-
const directory = "test";
|
|
10
|
-
const fetch_options = { redirect: "manual" };
|
|
11
|
-
const first_error = (left, right) => {
|
|
12
|
-
const length = left.length > right.length ? right.length : left.length;
|
|
13
|
-
for (let i = 0; i < length; i++) {
|
|
14
|
-
if (left[i] !== right[i]) {
|
|
15
|
-
return i;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
export default async () => {
|
|
20
|
-
await build(await fs.project.root(), { mode: "testing" });
|
|
21
|
-
const app = (await serve()).default;
|
|
22
|
-
const files = await (await fs.project.root()).join(directory)
|
|
23
|
-
.list({ filter: f => f.path.endsWith(".ts") || f.path.endsWith(".js") });
|
|
24
|
-
// side effects
|
|
25
|
-
await Promise.all(files.map(file => file.import()));
|
|
26
|
-
for (const test of tests) {
|
|
27
|
-
let init;
|
|
28
|
-
let path;
|
|
29
|
-
const route = test.route;
|
|
30
|
-
if (typeof route === "string") {
|
|
31
|
-
path = route;
|
|
32
|
-
init = new Request(`${app.url}${route}`);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
path = route.url.replace(app.url, "");
|
|
36
|
-
init = new Request(route.url, {
|
|
37
|
-
body: route.body,
|
|
38
|
-
// @ts-expect-error nonsense
|
|
39
|
-
duplex: "half",
|
|
40
|
-
headers: route.headers,
|
|
41
|
-
method: route.method,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
const response = await fetch(init, fetch_options);
|
|
45
|
-
const checks = [];
|
|
46
|
-
const mocked_response = {
|
|
47
|
-
body: {
|
|
48
|
-
equals(expected) {
|
|
49
|
-
checks.push(async () => {
|
|
50
|
-
const actual = await (typeof expected === "string"
|
|
51
|
-
? response.text()
|
|
52
|
-
: response.json());
|
|
53
|
-
return [equals(actual, expected), expected, actual];
|
|
54
|
-
});
|
|
55
|
-
},
|
|
56
|
-
includes(expected) {
|
|
57
|
-
checks.push(async () => {
|
|
58
|
-
const actual = await (typeof expected === "string"
|
|
59
|
-
? response.text()
|
|
60
|
-
: response.json());
|
|
61
|
-
const $expected = typeof expected === "string"
|
|
62
|
-
? expected.replaceAll("\n", "").replaceAll(" ", "")
|
|
63
|
-
: expected;
|
|
64
|
-
return [includes(actual, $expected), $expected, actual];
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
headers: {
|
|
69
|
-
get(name) {
|
|
70
|
-
const actual = response.headers.get(name);
|
|
71
|
-
return {
|
|
72
|
-
equals(expected) {
|
|
73
|
-
checks.push(() => {
|
|
74
|
-
return [equals(actual, expected), expected, actual];
|
|
75
|
-
});
|
|
76
|
-
},
|
|
77
|
-
includes(expected) {
|
|
78
|
-
checks.push(() => {
|
|
79
|
-
return [includes(actual, expected), expected, actual];
|
|
80
|
-
});
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
},
|
|
84
|
-
includes(expected) {
|
|
85
|
-
checks.push(() => {
|
|
86
|
-
const actual = Object.fromEntries(response.headers.entries());
|
|
87
|
-
const lowercased = entries(expected)
|
|
88
|
-
.keymap(([key]) => key.toLowerCase()).get();
|
|
89
|
-
return [includes(actual, lowercased), lowercased, actual];
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
status: {
|
|
94
|
-
equals(status) {
|
|
95
|
-
checks.push(() => {
|
|
96
|
-
return [response.status === status, status, response.status];
|
|
97
|
-
});
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
test.tester(mocked_response);
|
|
102
|
-
const results = await Promise.all(checks.map(async (check) => {
|
|
103
|
-
try {
|
|
104
|
-
return await check();
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
console.log(error);
|
|
108
|
-
return [
|
|
109
|
-
false, "()", "test execution failed",
|
|
110
|
-
];
|
|
111
|
-
}
|
|
112
|
-
}));
|
|
113
|
-
const failed = results.find(result => !result[0]);
|
|
114
|
-
const verb = test.verb.toUpperCase();
|
|
115
|
-
if (failed !== undefined) {
|
|
116
|
-
const route_text = typeof test.route === "string"
|
|
117
|
-
? test.route
|
|
118
|
-
: new URL(test.route.url).pathname;
|
|
119
|
-
console.log(color.red(`${verb} ${route_text}`));
|
|
120
|
-
const expected = JSON.stringify(failed[1]);
|
|
121
|
-
const actual = JSON.stringify(failed[2]);
|
|
122
|
-
const n = first_error(expected, actual);
|
|
123
|
-
console.log(`expected: ${expected.slice(0, n)}${color.green(expected[n])}${expected.slice(n + 1)}`);
|
|
124
|
-
console.log(`actual: ${actual.slice(0, n)}${color.red(actual[n])}${actual.slice(n + 1)}`);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
console.log(color.green(`${verb} ${path}`));
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
await app.stop();
|
|
131
|
-
};
|
|
132
|
-
//# sourceMappingURL=test.js.map
|
package/lib/init.d.ts
DELETED
package/lib/init.js
DELETED
package/lib/private/test.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import verbs from "@primate/core/request/verbs";
|
|
2
|
-
import type { Dict, JSONValue } from "@rcompat/type";
|
|
3
|
-
export type Body = JSONValue;
|
|
4
|
-
export type MockedResponse = {
|
|
5
|
-
body: {
|
|
6
|
-
equals(body: Body): void;
|
|
7
|
-
includes(body: Body): void;
|
|
8
|
-
};
|
|
9
|
-
headers: {
|
|
10
|
-
get(header: string): {
|
|
11
|
-
equals(value: string): void;
|
|
12
|
-
includes(value: string): void;
|
|
13
|
-
};
|
|
14
|
-
includes(headers: Dict<string>): void;
|
|
15
|
-
};
|
|
16
|
-
status: {
|
|
17
|
-
equals(status: number): void;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
type Verb = typeof verbs[number];
|
|
21
|
-
type Tester = (response: MockedResponse) => void;
|
|
22
|
-
type Route = string;
|
|
23
|
-
type Test = {
|
|
24
|
-
route: Request | Route;
|
|
25
|
-
tester: Tester;
|
|
26
|
-
verb: Verb;
|
|
27
|
-
};
|
|
28
|
-
export declare const tests: Test[];
|
|
29
|
-
declare const _default: { [K in Verb]: (path: Request | Route, tester: Tester) => void; };
|
|
30
|
-
export default _default;
|
|
31
|
-
//# sourceMappingURL=test.d.ts.map
|
package/lib/private/test.js
DELETED
package/lib/public/orm/key.d.ts
DELETED
package/lib/public/orm/key.js
DELETED
package/lib/public/orm/store.js
DELETED
package/lib/public/route/hook.js
DELETED
package/lib/public/s/internal.js
DELETED
package/lib/public/test.d.ts
DELETED
package/lib/public/test.js
DELETED