primate 0.35.0 → 0.36.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.tsconfig.json +4 -1
- package/lib/commands/init.js +40 -48
- package/lib/commands/serve.js +3 -4
- package/lib/commands/test.js +10 -11
- package/lib/index.d.ts +10 -0
- package/lib/init.js +7 -5
- package/lib/private/test.d.ts +1 -2
- package/lib/public/AppFacade.d.ts +2 -0
- package/lib/public/AppFacade.js +2 -0
- package/lib/public/db.d.ts +4 -0
- package/lib/public/db.js +3 -0
- package/lib/public/orm/key.d.ts +2 -0
- package/lib/public/orm/key.js +2 -0
- package/lib/public/orm/relation.d.ts +2 -0
- package/lib/public/orm/relation.js +2 -0
- package/lib/public/orm/store.d.ts +4 -0
- package/lib/public/orm/store.js +3 -0
- package/lib/public/orm/wrap.d.ts +2 -0
- package/lib/public/orm/wrap.js +2 -0
- package/lib/public/request.d.ts +2 -0
- package/lib/public/request.js +2 -0
- package/lib/public/response.d.ts +2 -21
- package/lib/public/response.js +1 -18
- package/lib/public/route/hook.d.ts +2 -0
- package/lib/public/route/hook.js +2 -0
- package/lib/runtime/FileRef.d.ts +2 -1
- package/lib/runtime/FileRef.js +3 -1
- package/package.json +22 -21
- package/lib/public/RequestFacade.d.ts +0 -2
- package/lib/public/RequestFacade.js +0 -2
- package/lib/public/database/Store.d.ts +0 -2
- package/lib/public/database/Store.js +0 -2
- package/lib/public/database/default.d.ts +0 -2
- package/lib/public/database/default.js +0 -2
- package/lib/public/database/wrap.d.ts +0 -2
- package/lib/public/database/wrap.js +0 -2
- package/lib/public/fs/FileRef.d.ts +0 -2
- package/lib/public/fs/FileRef.js +0 -2
- package/lib/public/pema.d.ts +0 -2
- package/lib/public/pema.js +0 -2
- package/lib/public/request/Facade.d.ts +0 -2
- package/lib/public/request/Facade.js +0 -2
- package/lib/public/store.d.ts +0 -4
- package/lib/public/store.js +0 -3
- package/lib/public/wasm/instantiate.d.ts +0 -2
- package/lib/public/wasm/instantiate.js +0 -2
package/lib/app.tsconfig.json
CHANGED
package/lib/commands/init.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import color from "@rcompat/cli/color";
|
|
1
2
|
import cancel from "@rcompat/cli/prompts/cancel";
|
|
2
3
|
import intro from "@rcompat/cli/prompts/intro";
|
|
3
4
|
import is_cancel from "@rcompat/cli/prompts/is-cancel";
|
|
@@ -5,8 +6,7 @@ import multiselect from "@rcompat/cli/prompts/multiselect";
|
|
|
5
6
|
import outro from "@rcompat/cli/prompts/outro";
|
|
6
7
|
import select from "@rcompat/cli/prompts/select";
|
|
7
8
|
import text from "@rcompat/cli/prompts/text";
|
|
8
|
-
import
|
|
9
|
-
import dedent from "@rcompat/string/dedent";
|
|
9
|
+
import fs from "@rcompat/fs";
|
|
10
10
|
function abort() {
|
|
11
11
|
return cancel("Aborted");
|
|
12
12
|
}
|
|
@@ -36,7 +36,6 @@ const DATABASE_OPTIONS = [
|
|
|
36
36
|
{ label: "PostgreSQL", value: "postgresql" },
|
|
37
37
|
{ label: "MySQL", value: "mysql" },
|
|
38
38
|
{ label: "MongoDB", value: "mongodb" },
|
|
39
|
-
{ label: "SurrealDB", value: "surrealdb" },
|
|
40
39
|
];
|
|
41
40
|
// peer deps per frontend (npm names)
|
|
42
41
|
const FRONTEND_PEER_DEPS = {
|
|
@@ -64,7 +63,7 @@ export default async function init() {
|
|
|
64
63
|
});
|
|
65
64
|
if (typeof ans === "symbol" || is_cancel(ans))
|
|
66
65
|
return abort();
|
|
67
|
-
target =
|
|
66
|
+
target = fs.ref(ans);
|
|
68
67
|
if (await empty(target)) {
|
|
69
68
|
directory = ans;
|
|
70
69
|
break; // valid directory found, exit loop
|
|
@@ -127,11 +126,11 @@ export default async function init() {
|
|
|
127
126
|
if (typeof sessions === "symbol" || is_cancel(sessions))
|
|
128
127
|
return abort();
|
|
129
128
|
const withSessions = sessions === "yes";
|
|
130
|
-
await target.create(
|
|
131
|
-
await target.join("routes").create(
|
|
132
|
-
await target.join("views").create(
|
|
129
|
+
await target.create();
|
|
130
|
+
await target.join("routes").create();
|
|
131
|
+
await target.join("views").create();
|
|
133
132
|
if (db !== undefined)
|
|
134
|
-
await target.join("stores").create(
|
|
133
|
+
await target.join("stores").create();
|
|
135
134
|
// files
|
|
136
135
|
await gitignore(target);
|
|
137
136
|
await tsconfig_json(target, { frontends });
|
|
@@ -145,10 +144,7 @@ export default async function init() {
|
|
|
145
144
|
await package_json(target, { directory, runtime });
|
|
146
145
|
const packages = compute_packages({ frontends: frontends, backends: backends, db });
|
|
147
146
|
const install = build_install_command(runtime, packages, directory);
|
|
148
|
-
outro(
|
|
149
|
-
"Done, now run",
|
|
150
|
-
`\n ${install.print}`,
|
|
151
|
-
].join("\n"));
|
|
147
|
+
outro(`${color.green("done, now run")} ${color.dim(install.print)}`);
|
|
152
148
|
process.exit();
|
|
153
149
|
}
|
|
154
150
|
async function empty(directory) {
|
|
@@ -164,7 +160,7 @@ async function empty(directory) {
|
|
|
164
160
|
}
|
|
165
161
|
async function gitignore(root) {
|
|
166
162
|
const gi = root.join(".gitignore");
|
|
167
|
-
await gi.directory.create(
|
|
163
|
+
await gi.directory.create();
|
|
168
164
|
const content = [
|
|
169
165
|
"node_modules",
|
|
170
166
|
"build",
|
|
@@ -181,7 +177,7 @@ async function gitignore(root) {
|
|
|
181
177
|
}
|
|
182
178
|
async function app_config(root, c) {
|
|
183
179
|
const config = root.join("config").join("app.ts");
|
|
184
|
-
await config.directory.create(
|
|
180
|
+
await config.directory.create();
|
|
185
181
|
const frontend_imports = c.frontends
|
|
186
182
|
.map((f) => `import ${to_ident(f)} from "@primate/${f}";`)
|
|
187
183
|
.join("\n");
|
|
@@ -192,16 +188,15 @@ async function app_config(root, c) {
|
|
|
192
188
|
...c.frontends.map((f) => `${to_ident(f)}()`),
|
|
193
189
|
...c.backends.map((b) => `${to_ident(b)}()`),
|
|
194
190
|
];
|
|
195
|
-
const body =
|
|
196
|
-
|
|
197
|
-
|
|
191
|
+
const body = `import config from "primate/config";
|
|
192
|
+
${frontend_imports}
|
|
193
|
+
${backend_imports}
|
|
198
194
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
`;
|
|
195
|
+
export default config({
|
|
196
|
+
modules: [
|
|
197
|
+
${modules.join(",\n ")}
|
|
198
|
+
],
|
|
199
|
+
});`;
|
|
205
200
|
await config.write(body);
|
|
206
201
|
}
|
|
207
202
|
// i18n scaffold: config + a default locale file
|
|
@@ -209,42 +204,38 @@ async function i18n_config(root) {
|
|
|
209
204
|
const locales = root.join("locales");
|
|
210
205
|
const en_us = locales.join("en-US.ts");
|
|
211
206
|
const i18i = root.join("config").join("i18n.ts");
|
|
212
|
-
await en_us.directory.create(
|
|
213
|
-
await i18i.directory.create(
|
|
214
|
-
const locale =
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
`;
|
|
207
|
+
await en_us.directory.create();
|
|
208
|
+
await i18i.directory.create();
|
|
209
|
+
const locale = `import locale from "primate/i18n/locale";
|
|
210
|
+
export default locale({
|
|
211
|
+
hi: "Hello",
|
|
212
|
+
placeheld: "Hello, {name}",
|
|
213
|
+
});`;
|
|
220
214
|
await en_us.write(locale);
|
|
221
|
-
const config =
|
|
222
|
-
|
|
215
|
+
const config = `import en from "#locale/en-US";
|
|
216
|
+
import i18n from "primate/config/i18n";
|
|
223
217
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
`;
|
|
218
|
+
export default i18n({
|
|
219
|
+
defaultLocale: "en-US",
|
|
220
|
+
locales: {
|
|
221
|
+
"en-US": en,
|
|
222
|
+
},
|
|
223
|
+
});`;
|
|
231
224
|
await i18i.write(config);
|
|
232
225
|
}
|
|
233
226
|
async function session_config(root) {
|
|
234
227
|
const file = root.join("config").join("session.ts");
|
|
235
|
-
await file.directory.create(
|
|
236
|
-
const body =
|
|
237
|
-
|
|
238
|
-
`;
|
|
228
|
+
await file.directory.create();
|
|
229
|
+
const body = `import session from "primate/config/session";
|
|
230
|
+
export default session({});`;
|
|
239
231
|
await file.write(body);
|
|
240
232
|
}
|
|
241
233
|
async function database_config(root, db) {
|
|
242
234
|
const file = root.join("config").join("database").join("index.ts");
|
|
243
|
-
await file.directory.create(
|
|
235
|
+
await file.directory.create();
|
|
244
236
|
const ident = to_ident(db);
|
|
245
|
-
const body =
|
|
246
|
-
|
|
247
|
-
`;
|
|
237
|
+
const body = `import ${ident} from "@primate/${db}";
|
|
238
|
+
export default ${ident}();`;
|
|
248
239
|
await file.write(body);
|
|
249
240
|
}
|
|
250
241
|
async function package_json(root, c) {
|
|
@@ -355,6 +346,7 @@ async function tsconfig_json(root, opts) {
|
|
|
355
346
|
const tsconfig = {
|
|
356
347
|
extends: "primate/tsconfig",
|
|
357
348
|
compilerOptions: {
|
|
349
|
+
baseUrl: "${configDir}",
|
|
358
350
|
paths: {
|
|
359
351
|
"#config/*": ["config/*"],
|
|
360
352
|
"#session": ["config/session"],
|
package/lib/commands/serve.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import root from "@rcompat/fs/project/root";
|
|
1
|
+
import fs from "@rcompat/fs";
|
|
3
2
|
import get_flag from "./get-flag.js";
|
|
4
3
|
const load = async () => {
|
|
5
4
|
try {
|
|
6
|
-
return await root();
|
|
5
|
+
return await fs.project.root();
|
|
7
6
|
}
|
|
8
7
|
catch {
|
|
9
|
-
return
|
|
8
|
+
return fs.resolve();
|
|
10
9
|
}
|
|
11
10
|
};
|
|
12
11
|
// serve from build directory
|
package/lib/commands/test.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { tests } from "#test";
|
|
2
2
|
import build from "@primate/core/build";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import entries from "@rcompat/record/entries";
|
|
3
|
+
import color from "@rcompat/cli/color";
|
|
4
|
+
import entries from "@rcompat/dict/entries";
|
|
5
|
+
import fs from "@rcompat/fs";
|
|
7
6
|
import equals from "@rcompat/test/equals";
|
|
8
7
|
import includes from "@rcompat/test/includes";
|
|
9
8
|
import serve from "./serve.js";
|
|
@@ -20,8 +19,8 @@ const first_error = (left, right) => {
|
|
|
20
19
|
export default async () => {
|
|
21
20
|
await build({ mode: "testing" });
|
|
22
21
|
const app = (await serve()).default;
|
|
23
|
-
const files = await (await root()).join(directory)
|
|
24
|
-
.list(
|
|
22
|
+
const files = await (await fs.project.root()).join(directory)
|
|
23
|
+
.list({ filter: f => f.path.endsWith(".ts") || f.path.endsWith(".js") });
|
|
25
24
|
// side effects
|
|
26
25
|
await Promise.all(files.map(file => file.import()));
|
|
27
26
|
for (const test of tests) {
|
|
@@ -114,18 +113,18 @@ export default async () => {
|
|
|
114
113
|
const failed = results.find(result => !result[0]);
|
|
115
114
|
const verb = test.verb.toUpperCase();
|
|
116
115
|
if (failed !== undefined) {
|
|
117
|
-
const
|
|
116
|
+
const route_text = typeof test.route === "string"
|
|
118
117
|
? test.route
|
|
119
118
|
: new URL(test.route.url).pathname;
|
|
120
|
-
console.log(red(`${verb} ${
|
|
119
|
+
console.log(color.red(`${verb} ${route_text}`));
|
|
121
120
|
const expected = JSON.stringify(failed[1]);
|
|
122
121
|
const actual = JSON.stringify(failed[2]);
|
|
123
122
|
const n = first_error(expected, actual);
|
|
124
|
-
console.log(`expected: ${expected.slice(0, n)}${green(expected[n])}${expected.slice(n + 1)}`);
|
|
125
|
-
console.log(`actual: ${actual.slice(0, n)}${red(actual[n])}${actual.slice(n + 1)}`);
|
|
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)}`);
|
|
126
125
|
}
|
|
127
126
|
else {
|
|
128
|
-
console.log(green(`${verb} ${path}`));
|
|
127
|
+
console.log(color.green(`${verb} ${path}`));
|
|
129
128
|
}
|
|
130
129
|
}
|
|
131
130
|
await app.stop();
|
package/lib/index.d.ts
ADDED
package/lib/init.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import bold from "@rcompat/cli/color/bold";
|
|
1
|
+
import c from "@rcompat/cli/color";
|
|
3
2
|
import print from "@rcompat/cli/print";
|
|
4
|
-
import
|
|
3
|
+
import fs from "@rcompat/fs";
|
|
5
4
|
import find from "./commands/index.js";
|
|
5
|
+
function orange(x) {
|
|
6
|
+
return `\x1b[38;2;255;165;0m${x}\x1b[0m`;
|
|
7
|
+
}
|
|
6
8
|
export default async (...args) => {
|
|
7
9
|
const [command, ...flags] = args;
|
|
8
|
-
const { name, version, } = await (await
|
|
9
|
-
print(
|
|
10
|
+
const { name, version, } = await (await fs.project.package(import.meta.dirname)).json();
|
|
11
|
+
print(c.bold(orange((name.toUpperCase()))), orange(version), "\n\n");
|
|
10
12
|
find(command)(flags);
|
|
11
13
|
};
|
|
12
14
|
//# sourceMappingURL=init.js.map
|
package/lib/private/test.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import verbs from "@primate/core/request/verbs";
|
|
2
|
-
import type Dict from "@rcompat/type
|
|
3
|
-
import type JSONValue from "@rcompat/type/JSONValue";
|
|
2
|
+
import type { Dict, JSONValue } from "@rcompat/type";
|
|
4
3
|
export type Body = JSONValue;
|
|
5
4
|
export type MockedResponse = {
|
|
6
5
|
body: {
|
package/lib/public/db.js
ADDED
package/lib/public/response.d.ts
CHANGED
|
@@ -1,23 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import error from "@primate/core/response/error";
|
|
3
|
-
import view from "@primate/core/response/view";
|
|
4
|
-
export type { default as ViewResponse } from "@primate/core/frontend/ViewResponse";
|
|
5
|
-
export type { default as ResponseFunction } from "@primate/core/response/ResponseFunction";
|
|
1
|
+
export type { default as ViewResponse, } from "@primate/core/frontend/ViewResponse";
|
|
6
2
|
export type { default as ServeApp } from "@primate/core/ServeApp";
|
|
7
|
-
|
|
8
|
-
binary: typeof binary;
|
|
9
|
-
error: typeof error;
|
|
10
|
-
json: (body: unknown, init?: ResponseInit) => (app: import("@primate/core/ServeApp").default) => import("@rcompat/type/MaybePromise").default<Response>;
|
|
11
|
-
redirect: (location: string, status?: 302 | 301 | 300 | 304 | 308 | 303 | 307) => import("@primate/core/response/ResponseFunction").default;
|
|
12
|
-
sse: (body: {
|
|
13
|
-
close?(): undefined;
|
|
14
|
-
open(events: {
|
|
15
|
-
send(name: string, data: unknown): undefined;
|
|
16
|
-
}): undefined;
|
|
17
|
-
}, init?: ResponseInit) => (app: import("@primate/core/ServeApp").default) => import("@rcompat/type/MaybePromise").default<Response>;
|
|
18
|
-
text: (body: string, init?: ResponseInit) => (app: import("@primate/core/ServeApp").default) => import("@rcompat/type/MaybePromise").default<Response>;
|
|
19
|
-
view: typeof view;
|
|
20
|
-
ws: (actions: import("@rcompat/http/Actions").default) => import("@primate/core/response/ResponseFunction").default;
|
|
21
|
-
};
|
|
22
|
-
export default _default;
|
|
3
|
+
export { default, type ResponseFunction } from "@primate/core/response";
|
|
23
4
|
//# sourceMappingURL=response.d.ts.map
|
package/lib/public/response.js
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import error from "@primate/core/response/error";
|
|
3
|
-
import json from "@primate/core/response/json";
|
|
4
|
-
import redirect from "@primate/core/response/redirect";
|
|
5
|
-
import sse from "@primate/core/response/sse";
|
|
6
|
-
import text from "@primate/core/response/text";
|
|
7
|
-
import view from "@primate/core/response/view";
|
|
8
|
-
import ws from "@primate/core/response/ws";
|
|
9
|
-
export default {
|
|
10
|
-
binary,
|
|
11
|
-
error,
|
|
12
|
-
json,
|
|
13
|
-
redirect,
|
|
14
|
-
sse,
|
|
15
|
-
text,
|
|
16
|
-
view,
|
|
17
|
-
ws,
|
|
18
|
-
};
|
|
1
|
+
export { default } from "@primate/core/response";
|
|
19
2
|
//# sourceMappingURL=response.js.map
|
package/lib/runtime/FileRef.d.ts
CHANGED
package/lib/runtime/FileRef.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "primate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"description": "The universal web framework",
|
|
5
5
|
"homepage": "https://primate.run",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/primate-run/primate",
|
|
12
|
+
"directory": "packages/primate"
|
|
13
|
+
},
|
|
8
14
|
"files": [
|
|
9
15
|
"/lib/app.tsconfig.json",
|
|
10
16
|
"/lib/**/*.js",
|
|
@@ -12,37 +18,32 @@
|
|
|
12
18
|
"!/**/*.spec.*"
|
|
13
19
|
],
|
|
14
20
|
"bin": "lib/bin.js",
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
21
|
+
"types": "lib/index.d.ts",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@rcompat/args": "^0.11.0",
|
|
24
|
+
"@rcompat/cli": "^0.14.0",
|
|
25
|
+
"@rcompat/dict": "^0.3.1",
|
|
26
|
+
"@rcompat/fs": "^0.25.2",
|
|
27
|
+
"@rcompat/http": "~0.21.0",
|
|
28
|
+
"@rcompat/test": "^0.8.3",
|
|
29
|
+
"@primate/core": "^0.5.0"
|
|
19
30
|
},
|
|
20
31
|
"devDependencies": {
|
|
21
|
-
"@rcompat/
|
|
22
|
-
"pema": "^0.4.0"
|
|
23
|
-
},
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"@rcompat/args": "^0.8.0",
|
|
26
|
-
"@rcompat/cli": "^0.11.3",
|
|
27
|
-
"@rcompat/fs": "^0.22.3",
|
|
28
|
-
"@rcompat/http": "~0.16.0",
|
|
29
|
-
"@rcompat/runtime": "^0.6.0",
|
|
30
|
-
"@rcompat/string": "^0.10.0",
|
|
31
|
-
"@rcompat/test": "^0.5.0",
|
|
32
|
-
"@primate/core": "^0.4.0"
|
|
32
|
+
"@rcompat/type": "^0.9.0"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
35
|
"node": ">=20"
|
|
36
36
|
},
|
|
37
|
-
"type": "module",
|
|
38
37
|
"imports": {
|
|
39
38
|
"#*": {
|
|
40
39
|
"apekit": "./src/private/*.ts",
|
|
41
40
|
"default": "./lib/private/*.js"
|
|
42
|
-
}
|
|
43
|
-
"#runtime/FileRef": "@rcompat/fs/FileRef"
|
|
41
|
+
}
|
|
44
42
|
},
|
|
45
43
|
"exports": {
|
|
44
|
+
".": {
|
|
45
|
+
"types": "./lib/index.d.ts"
|
|
46
|
+
},
|
|
46
47
|
"./tsconfig": "./lib/app.tsconfig.json",
|
|
47
48
|
"./runtime/*": {
|
|
48
49
|
"apekit": "./src/runtime/*.ts",
|
|
@@ -58,7 +59,7 @@
|
|
|
58
59
|
}
|
|
59
60
|
},
|
|
60
61
|
"scripts": {
|
|
61
|
-
"build": "npm run clean && tsc && cp src/app.tsconfig.json lib",
|
|
62
|
+
"build": "npm run clean && tsc && cp src/{app.tsconfig.json,index.d.ts} lib",
|
|
62
63
|
"clean": "rm -rf ./lib",
|
|
63
64
|
"lint": "eslint ."
|
|
64
65
|
}
|
package/lib/public/fs/FileRef.js
DELETED
package/lib/public/pema.d.ts
DELETED
package/lib/public/pema.js
DELETED
package/lib/public/store.d.ts
DELETED
package/lib/public/store.js
DELETED