primate 0.36.0 → 0.38.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/app.d.ts +10 -0
- package/lib/bin.js +4 -3
- 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 +21 -10
- 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 +39 -8
- package/lib/commands/init.d.ts +3 -1
- package/lib/commands/init.js +48 -51
- package/lib/commands/migrate-apply.d.ts +4 -0
- package/lib/commands/migrate-apply.js +10 -0
- package/lib/commands/migrate-create.d.ts +4 -0
- package/lib/commands/migrate-create.js +21 -0
- package/lib/commands/migrate-status.d.ts +4 -0
- package/lib/commands/migrate-status.js +9 -0
- package/lib/commands/serve.d.ts +3 -1
- package/lib/commands/serve.js +7 -6
- package/lib/index.d.ts +2 -9
- package/lib/public/build.d.ts +2 -0
- package/lib/public/build.js +2 -0
- package/lib/public/http/Status.d.ts +65 -1
- package/lib/public/http/Status.js +2 -1
- package/lib/public/index.d.ts +2 -0
- package/lib/public/index.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/request.d.ts +1 -1
- package/lib/public/response.d.ts +3 -3
- package/lib/public/store.d.ts +2 -0
- package/lib/public/store.js +2 -0
- package/package.json +21 -21
- 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 -14
- package/lib/private/test.d.ts +0 -31
- package/lib/private/test.js +0 -8
- package/lib/public/Module.d.ts +0 -2
- package/lib/public/Module.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 -4
- package/lib/public/orm/store.js +0 -3
- package/lib/public/orm/wrap.d.ts +0 -2
- package/lib/public/orm/wrap.js +0 -2
- package/lib/public/test.d.ts +0 -2
- package/lib/public/test.js +0 -2
- package/lib/runtime/FileRef.d.ts +0 -3
- package/lib/runtime/FileRef.js +0 -4
package/lib/app.d.ts
ADDED
package/lib/bin.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
2
|
+
import runtime from "@rcompat/runtime";
|
|
3
|
+
import find from "./commands/index.js";
|
|
4
|
+
const [command] = runtime.args;
|
|
5
|
+
find(command)();
|
|
5
6
|
//# sourceMappingURL=bin.js.map
|
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,13 +1,24 @@
|
|
|
1
|
+
import core from "@primate/core";
|
|
1
2
|
import build from "@primate/core/build";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
target: get_flag(flags, "target"),
|
|
8
|
-
dir: get_flag(flags, "dir"),
|
|
9
|
-
};
|
|
10
|
-
return build(build_flags);
|
|
3
|
+
import Flags from "@primate/core/Flags";
|
|
4
|
+
import cli from "@rcompat/cli";
|
|
5
|
+
import runtime from "@rcompat/runtime";
|
|
6
|
+
function orange(x) {
|
|
7
|
+
return `\x1b[38;2;255;165;0m${x}\x1b[0m`;
|
|
11
8
|
}
|
|
12
|
-
|
|
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;
|
|
13
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 { default as serve } from "./serve.js";
|
|
3
|
-
declare const _default: (name: string) => typeof build | typeof serve;
|
|
4
|
-
export default _default;
|
|
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,13 +1,44 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
1
|
+
import cli from "@rcompat/cli";
|
|
2
|
+
import build from "./build.js";
|
|
3
|
+
import dev from "./dev.js";
|
|
4
|
+
import init from "./init.js";
|
|
5
|
+
import migrate_apply from "./migrate-apply.js";
|
|
6
|
+
import migrate_create from "./migrate-create.js";
|
|
7
|
+
import migrate_status from "./migrate-status.js";
|
|
8
|
+
import serve from "./serve.js";
|
|
9
|
+
const commands = {
|
|
7
10
|
build,
|
|
8
11
|
dev,
|
|
9
12
|
init,
|
|
10
13
|
serve,
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
migrate_apply,
|
|
15
|
+
migrate_create,
|
|
16
|
+
migrate_status,
|
|
17
|
+
};
|
|
18
|
+
function unknown(command) {
|
|
19
|
+
return () => {
|
|
20
|
+
cli.print(`Unknown command ${cli.fg.dim(command)}\n`);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
;
|
|
24
|
+
function in_commands(command) {
|
|
25
|
+
return Object.keys(commands).find(key => key === command || key.startsWith(command)) !== undefined;
|
|
26
|
+
}
|
|
27
|
+
export default function run_command(command_flag = "") {
|
|
28
|
+
const [command, action = ""] = command_flag.trim().split(":");
|
|
29
|
+
if (command === "")
|
|
30
|
+
return dev;
|
|
31
|
+
if (in_commands(command)) {
|
|
32
|
+
if (action === "")
|
|
33
|
+
return commands[command];
|
|
34
|
+
else {
|
|
35
|
+
const subcommand = `${command}_${action}`;
|
|
36
|
+
if (in_commands(subcommand))
|
|
37
|
+
return commands[subcommand];
|
|
38
|
+
return unknown(subcommand.replace("_", ":"));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return unknown(command);
|
|
42
|
+
}
|
|
43
|
+
;
|
|
13
44
|
//# sourceMappingURL=index.js.map
|
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()))
|
|
@@ -164,13 +165,7 @@ async function gitignore(root) {
|
|
|
164
165
|
const content = [
|
|
165
166
|
"node_modules",
|
|
166
167
|
"build",
|
|
167
|
-
"dist",
|
|
168
|
-
".DS_Store",
|
|
169
168
|
"*.log",
|
|
170
|
-
"npm-debug.log*",
|
|
171
|
-
"yarn-debug.log*",
|
|
172
|
-
"yarn-error.log*",
|
|
173
|
-
"pnpm-debug.log*",
|
|
174
169
|
"",
|
|
175
170
|
].join("\n");
|
|
176
171
|
await gi.write(content);
|
|
@@ -191,7 +186,6 @@ async function app_config(root, c) {
|
|
|
191
186
|
const body = `import config from "primate/config";
|
|
192
187
|
${frontend_imports}
|
|
193
188
|
${backend_imports}
|
|
194
|
-
|
|
195
189
|
export default config({
|
|
196
190
|
modules: [
|
|
197
191
|
${modules.join(",\n ")}
|
|
@@ -266,7 +260,9 @@ async function package_json(root, c) {
|
|
|
266
260
|
await pkgFile.writeJSON(pkg);
|
|
267
261
|
}
|
|
268
262
|
function safe(s) {
|
|
269
|
-
return s
|
|
263
|
+
return s
|
|
264
|
+
.trim()
|
|
265
|
+
.toLowerCase().replace(/\s+/g, "-")
|
|
270
266
|
.replace(/[^a-z0-9._-]/g, "") || "primate-app";
|
|
271
267
|
}
|
|
272
268
|
function to_ident(token) {
|
|
@@ -293,7 +289,7 @@ function compute_packages(args) {
|
|
|
293
289
|
for (const b of args.backends)
|
|
294
290
|
deps.add(`@primate/${b}`);
|
|
295
291
|
// database → @primate/<token>, if selected
|
|
296
|
-
if (args.db)
|
|
292
|
+
if (is.defined(args.db))
|
|
297
293
|
deps.add(`@primate/${args.db}`);
|
|
298
294
|
return {
|
|
299
295
|
dependencies: Array.from(deps),
|
|
@@ -343,7 +339,7 @@ function build_install_command(runtime, packages, dir) {
|
|
|
343
339
|
async function tsconfig_json(root, opts) {
|
|
344
340
|
const is_react = opts.frontends.includes("react");
|
|
345
341
|
const is_svelte = opts.frontends.includes("svelte");
|
|
346
|
-
const
|
|
342
|
+
const ts_config = {
|
|
347
343
|
extends: "primate/tsconfig",
|
|
348
344
|
compilerOptions: {
|
|
349
345
|
baseUrl: "${configDir}",
|
|
@@ -371,9 +367,10 @@ async function tsconfig_json(root, opts) {
|
|
|
371
367
|
exclude: ["node_modules"],
|
|
372
368
|
};
|
|
373
369
|
if (is_react)
|
|
374
|
-
|
|
370
|
+
ts_config.compilerOptions.jsx = "react-jsx";
|
|
375
371
|
if (is_svelte)
|
|
376
|
-
|
|
377
|
-
await root.join("tsconfig.json").writeJSON(
|
|
372
|
+
ts_config.compilerOptions.plugins = [{ name: "@plsp/svelte" }];
|
|
373
|
+
await root.join("tsconfig.json").writeJSON(ts_config);
|
|
378
374
|
}
|
|
375
|
+
export default command_init;
|
|
379
376
|
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import core from "@primate/core";
|
|
2
|
+
import migrate from "@primate/core/db/migrate";
|
|
3
|
+
const command_migrate_apply = async () => {
|
|
4
|
+
core.try(async () => {
|
|
5
|
+
await migrate.apply();
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
;
|
|
9
|
+
export default command_migrate_apply;
|
|
10
|
+
//# sourceMappingURL=migrate-apply.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import core from "@primate/core";
|
|
2
|
+
import migrate from "@primate/core/db/migrate";
|
|
3
|
+
import error from "@rcompat/error";
|
|
4
|
+
import runtime from "@rcompat/runtime";
|
|
5
|
+
const name_flag = "--name";
|
|
6
|
+
function create_requires_name_flag() {
|
|
7
|
+
return error.template `migrate:create requires a ${name_flag} flag`;
|
|
8
|
+
}
|
|
9
|
+
const errors = error.coded({
|
|
10
|
+
create_requires_name_flag,
|
|
11
|
+
});
|
|
12
|
+
const command_migrate_create = async () => {
|
|
13
|
+
const name = runtime.flags.try(name_flag);
|
|
14
|
+
core.try(async () => {
|
|
15
|
+
if (name === undefined)
|
|
16
|
+
throw errors.create_requires_name_flag();
|
|
17
|
+
await migrate.create(name);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export default command_migrate_create;
|
|
21
|
+
//# sourceMappingURL=migrate-create.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import core from "@primate/core";
|
|
2
|
+
import migrate from "@primate/core/db/migrate";
|
|
3
|
+
const command_migrate_status = async () => {
|
|
4
|
+
core.try(async () => {
|
|
5
|
+
await migrate.status();
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
export default command_migrate_status;
|
|
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
|
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
const views: [string, Record<string, unknown>][];
|
|
3
|
-
export default views;
|
|
4
|
-
}
|
|
1
|
+
import "./app.d.ts";
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
import type AppFacade from "primate/AppFacade";
|
|
8
|
-
const facade: AppFacade;
|
|
9
|
-
export default facade;
|
|
10
|
-
}
|
|
3
|
+
export type * from "./public/index";
|
|
@@ -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/request.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export type { RequestFacade } from "@primate/core";
|
|
2
2
|
//# sourceMappingURL=request.d.ts.map
|
package/lib/public/response.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
export type {
|
|
3
|
-
export { default
|
|
1
|
+
export type { ServeApp, ResponseFunction } from "@primate/core";
|
|
2
|
+
export type { ViewResponse } from "@primate/core/client";
|
|
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.38.0",
|
|
4
4
|
"description": "The universal web framework",
|
|
5
5
|
"homepage": "https://primate.run",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -20,46 +20,46 @@
|
|
|
20
20
|
"bin": "lib/bin.js",
|
|
21
21
|
"types": "lib/index.d.ts",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@rcompat/
|
|
24
|
-
"@rcompat/
|
|
25
|
-
"@rcompat/
|
|
26
|
-
"@rcompat/fs": "^0.
|
|
27
|
-
"@rcompat/http": "~0.
|
|
28
|
-
"@rcompat/
|
|
29
|
-
"@
|
|
23
|
+
"@rcompat/cli": "^0.24.0",
|
|
24
|
+
"@rcompat/dict": "^0.10.0",
|
|
25
|
+
"@rcompat/error": "^0.8.0",
|
|
26
|
+
"@rcompat/fs": "^0.33.2",
|
|
27
|
+
"@rcompat/http": "~0.30.0",
|
|
28
|
+
"@rcompat/is": "^0.11.0",
|
|
29
|
+
"@rcompat/runtime": "^0.16.0",
|
|
30
|
+
"@rcompat/test": "^0.17.0",
|
|
31
|
+
"@primate/core": "^0.7.0"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
32
|
-
"@rcompat/type": "^0.
|
|
34
|
+
"@rcompat/type": "^0.17.0"
|
|
33
35
|
},
|
|
34
36
|
"engines": {
|
|
35
|
-
"node": ">=
|
|
37
|
+
"node": ">=24"
|
|
36
38
|
},
|
|
37
39
|
"imports": {
|
|
38
40
|
"#*": {
|
|
39
|
-
"
|
|
41
|
+
"@primate/source": "./src/private/*.ts",
|
|
40
42
|
"default": "./lib/private/*.js"
|
|
41
43
|
}
|
|
42
44
|
},
|
|
43
45
|
"exports": {
|
|
44
|
-
".": {
|
|
45
|
-
"types": "./lib/index.d.ts"
|
|
46
|
-
},
|
|
47
46
|
"./tsconfig": "./lib/app.tsconfig.json",
|
|
48
|
-
"./runtime/*": {
|
|
49
|
-
"apekit": "./src/runtime/*.ts",
|
|
50
|
-
"default": "./lib/runtime/*.js"
|
|
51
|
-
},
|
|
52
47
|
"./http/*": {
|
|
53
|
-
"
|
|
48
|
+
"@primate/source": "./src/public/http/*.ts",
|
|
54
49
|
"default": "./lib/public/http/*.js"
|
|
55
50
|
},
|
|
56
51
|
"./*": {
|
|
57
|
-
"
|
|
52
|
+
"@primate/source": "./src/public/*.ts",
|
|
58
53
|
"default": "./lib/public/*.js"
|
|
54
|
+
},
|
|
55
|
+
".": {
|
|
56
|
+
"types": "./lib/index.d.ts",
|
|
57
|
+
"@primate/source": "./src/public/index.ts",
|
|
58
|
+
"default": "./lib/public/index.js"
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
|
-
"build": "npm run clean && tsc && cp src/
|
|
62
|
+
"build": "npm run clean && tsc && cp src/app.tsconfig.json lib && cp src/types/app.d.ts lib && cp src/types/index.d.ts lib",
|
|
63
63
|
"clean": "rm -rf ./lib",
|
|
64
64
|
"lint": "eslint ."
|
|
65
65
|
}
|
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({ 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
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import c from "@rcompat/cli/color";
|
|
2
|
-
import print from "@rcompat/cli/print";
|
|
3
|
-
import fs from "@rcompat/fs";
|
|
4
|
-
import find from "./commands/index.js";
|
|
5
|
-
function orange(x) {
|
|
6
|
-
return `\x1b[38;2;255;165;0m${x}\x1b[0m`;
|
|
7
|
-
}
|
|
8
|
-
export default async (...args) => {
|
|
9
|
-
const [command, ...flags] = args;
|
|
10
|
-
const { name, version, } = await (await fs.project.package(import.meta.dirname)).json();
|
|
11
|
-
print(c.bold(orange((name.toUpperCase()))), orange(version), "\n\n");
|
|
12
|
-
find(command)(flags);
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=init.js.map
|
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/Module.d.ts
DELETED
package/lib/public/Module.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/orm/wrap.d.ts
DELETED
package/lib/public/orm/wrap.js
DELETED
package/lib/public/test.d.ts
DELETED
package/lib/public/test.js
DELETED
package/lib/runtime/FileRef.d.ts
DELETED
package/lib/runtime/FileRef.js
DELETED