primate 0.35.1 → 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.
Files changed (46) hide show
  1. package/lib/app.tsconfig.json +4 -1
  2. package/lib/commands/init.js +14 -16
  3. package/lib/commands/serve.js +3 -4
  4. package/lib/commands/test.js +10 -11
  5. package/lib/index.d.ts +10 -0
  6. package/lib/init.js +7 -5
  7. package/lib/private/test.d.ts +1 -2
  8. package/lib/public/AppFacade.d.ts +2 -0
  9. package/lib/public/AppFacade.js +2 -0
  10. package/lib/public/db.d.ts +4 -0
  11. package/lib/public/db.js +3 -0
  12. package/lib/public/orm/key.d.ts +2 -0
  13. package/lib/public/orm/key.js +2 -0
  14. package/lib/public/orm/relation.d.ts +2 -0
  15. package/lib/public/orm/relation.js +2 -0
  16. package/lib/public/orm/store.d.ts +4 -0
  17. package/lib/public/orm/store.js +3 -0
  18. package/lib/public/orm/wrap.d.ts +2 -0
  19. package/lib/public/orm/wrap.js +2 -0
  20. package/lib/public/request.d.ts +2 -0
  21. package/lib/public/request.js +2 -0
  22. package/lib/public/response.d.ts +2 -21
  23. package/lib/public/response.js +1 -18
  24. package/lib/public/route/hook.d.ts +2 -0
  25. package/lib/public/route/hook.js +2 -0
  26. package/lib/runtime/FileRef.d.ts +2 -1
  27. package/lib/runtime/FileRef.js +3 -1
  28. package/package.json +22 -21
  29. package/lib/public/RequestFacade.d.ts +0 -2
  30. package/lib/public/RequestFacade.js +0 -2
  31. package/lib/public/database/Store.d.ts +0 -2
  32. package/lib/public/database/Store.js +0 -2
  33. package/lib/public/database/default.d.ts +0 -2
  34. package/lib/public/database/default.js +0 -2
  35. package/lib/public/database/wrap.d.ts +0 -2
  36. package/lib/public/database/wrap.js +0 -2
  37. package/lib/public/fs/FileRef.d.ts +0 -2
  38. package/lib/public/fs/FileRef.js +0 -2
  39. package/lib/public/pema.d.ts +0 -2
  40. package/lib/public/pema.js +0 -2
  41. package/lib/public/request/Facade.d.ts +0 -2
  42. package/lib/public/request/Facade.js +0 -2
  43. package/lib/public/store.d.ts +0 -4
  44. package/lib/public/store.js +0 -3
  45. package/lib/public/wasm/instantiate.d.ts +0 -2
  46. package/lib/public/wasm/instantiate.js +0 -2
@@ -9,6 +9,9 @@
9
9
  "skipLibCheck": true,
10
10
  "erasableSyntaxOnly": true,
11
11
  "exactOptionalPropertyTypes": true,
12
- "allowImportingTsExtensions": true
12
+ "allowImportingTsExtensions": true,
13
+ "types": [
14
+ "primate"
15
+ ]
13
16
  }
14
17
  }
@@ -1,5 +1,4 @@
1
- import dim from "@rcompat/cli/color/dim";
2
- import green from "@rcompat/cli/color/green";
1
+ import color from "@rcompat/cli/color";
3
2
  import cancel from "@rcompat/cli/prompts/cancel";
4
3
  import intro from "@rcompat/cli/prompts/intro";
5
4
  import is_cancel from "@rcompat/cli/prompts/is-cancel";
@@ -7,7 +6,7 @@ import multiselect from "@rcompat/cli/prompts/multiselect";
7
6
  import outro from "@rcompat/cli/prompts/outro";
8
7
  import select from "@rcompat/cli/prompts/select";
9
8
  import text from "@rcompat/cli/prompts/text";
10
- import FileRef from "@rcompat/fs/FileRef";
9
+ import fs from "@rcompat/fs";
11
10
  function abort() {
12
11
  return cancel("Aborted");
13
12
  }
@@ -37,7 +36,6 @@ const DATABASE_OPTIONS = [
37
36
  { label: "PostgreSQL", value: "postgresql" },
38
37
  { label: "MySQL", value: "mysql" },
39
38
  { label: "MongoDB", value: "mongodb" },
40
- { label: "SurrealDB", value: "surrealdb" },
41
39
  ];
42
40
  // peer deps per frontend (npm names)
43
41
  const FRONTEND_PEER_DEPS = {
@@ -65,7 +63,7 @@ export default async function init() {
65
63
  });
66
64
  if (typeof ans === "symbol" || is_cancel(ans))
67
65
  return abort();
68
- target = new FileRef(ans);
66
+ target = fs.ref(ans);
69
67
  if (await empty(target)) {
70
68
  directory = ans;
71
69
  break; // valid directory found, exit loop
@@ -128,11 +126,11 @@ export default async function init() {
128
126
  if (typeof sessions === "symbol" || is_cancel(sessions))
129
127
  return abort();
130
128
  const withSessions = sessions === "yes";
131
- await target.create({ recursive: true });
132
- await target.join("routes").create({ recursive: true });
133
- await target.join("views").create({ recursive: true });
129
+ await target.create();
130
+ await target.join("routes").create();
131
+ await target.join("views").create();
134
132
  if (db !== undefined)
135
- await target.join("stores").create({ recursive: true });
133
+ await target.join("stores").create();
136
134
  // files
137
135
  await gitignore(target);
138
136
  await tsconfig_json(target, { frontends });
@@ -146,7 +144,7 @@ export default async function init() {
146
144
  await package_json(target, { directory, runtime });
147
145
  const packages = compute_packages({ frontends: frontends, backends: backends, db });
148
146
  const install = build_install_command(runtime, packages, directory);
149
- outro(`${green("done, now run")} ${dim(install.print)}`);
147
+ outro(`${color.green("done, now run")} ${color.dim(install.print)}`);
150
148
  process.exit();
151
149
  }
152
150
  async function empty(directory) {
@@ -162,7 +160,7 @@ async function empty(directory) {
162
160
  }
163
161
  async function gitignore(root) {
164
162
  const gi = root.join(".gitignore");
165
- await gi.directory.create({ recursive: true });
163
+ await gi.directory.create();
166
164
  const content = [
167
165
  "node_modules",
168
166
  "build",
@@ -179,7 +177,7 @@ async function gitignore(root) {
179
177
  }
180
178
  async function app_config(root, c) {
181
179
  const config = root.join("config").join("app.ts");
182
- await config.directory.create({ recursive: true });
180
+ await config.directory.create();
183
181
  const frontend_imports = c.frontends
184
182
  .map((f) => `import ${to_ident(f)} from "@primate/${f}";`)
185
183
  .join("\n");
@@ -206,8 +204,8 @@ async function i18n_config(root) {
206
204
  const locales = root.join("locales");
207
205
  const en_us = locales.join("en-US.ts");
208
206
  const i18i = root.join("config").join("i18n.ts");
209
- await en_us.directory.create({ recursive: true });
210
- await i18i.directory.create({ recursive: true });
207
+ await en_us.directory.create();
208
+ await i18i.directory.create();
211
209
  const locale = `import locale from "primate/i18n/locale";
212
210
  export default locale({
213
211
  hi: "Hello",
@@ -227,14 +225,14 @@ export default i18n({
227
225
  }
228
226
  async function session_config(root) {
229
227
  const file = root.join("config").join("session.ts");
230
- await file.directory.create({ recursive: true });
228
+ await file.directory.create();
231
229
  const body = `import session from "primate/config/session";
232
230
  export default session({});`;
233
231
  await file.write(body);
234
232
  }
235
233
  async function database_config(root, db) {
236
234
  const file = root.join("config").join("database").join("index.ts");
237
- await file.directory.create({ recursive: true });
235
+ await file.directory.create();
238
236
  const ident = to_ident(db);
239
237
  const body = `import ${ident} from "@primate/${db}";
240
238
  export default ${ident}();`;
@@ -1,12 +1,11 @@
1
- import FileRef from "@rcompat/fs/FileRef";
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 FileRef.resolve();
8
+ return fs.resolve();
10
9
  }
11
10
  };
12
11
  // serve from build directory
@@ -1,9 +1,8 @@
1
1
  import { tests } from "#test";
2
2
  import build from "@primate/core/build";
3
- import green from "@rcompat/cli/color/green";
4
- import red from "@rcompat/cli/color/red";
5
- import root from "@rcompat/fs/project/root";
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(({ path }) => path.endsWith(".ts") || path.endsWith(".js"));
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 routeText = typeof test.route === "string"
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} ${routeText}`));
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
@@ -0,0 +1,10 @@
1
+ declare module "app:views" {
2
+ const views: [string, Record<string, unknown>][];
3
+ export default views;
4
+ }
5
+
6
+ declare module "$:app" {
7
+ import type AppFacade from "primate/AppFacade";
8
+ const facade: AppFacade;
9
+ export default facade;
10
+ }
package/lib/init.js CHANGED
@@ -1,12 +1,14 @@
1
- import blue from "@rcompat/cli/color/blue";
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 pkg from "@rcompat/fs/project/package";
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 pkg(import.meta.url)).json();
9
- print(blue(bold(name)), blue(version), "\n");
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
@@ -1,6 +1,5 @@
1
1
  import verbs from "@primate/core/request/verbs";
2
- import type Dict from "@rcompat/type/Dict";
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: {
@@ -0,0 +1,2 @@
1
+ export type { default } from "@primate/core/AppFacade";
2
+ //# sourceMappingURL=AppFacade.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=AppFacade.js.map
@@ -0,0 +1,4 @@
1
+ import MemoryDB from "@primate/core/db/MemoryDB";
2
+ declare const _default: () => MemoryDB;
3
+ export default _default;
4
+ //# sourceMappingURL=db.d.ts.map
@@ -0,0 +1,3 @@
1
+ import MemoryDB from "@primate/core/db/MemoryDB";
2
+ export default () => new MemoryDB();
3
+ //# sourceMappingURL=db.js.map
@@ -0,0 +1,2 @@
1
+ export { default } from "@primate/core/orm/key";
2
+ //# sourceMappingURL=key.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { default } from "@primate/core/orm/key";
2
+ //# sourceMappingURL=key.js.map
@@ -0,0 +1,2 @@
1
+ export { default } from "@primate/core/orm/relation";
2
+ //# sourceMappingURL=relation.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { default } from "@primate/core/orm/relation";
2
+ //# sourceMappingURL=relation.js.map
@@ -0,0 +1,4 @@
1
+ import Store from "@primate/core/orm/Store";
2
+ declare const _default: typeof Store.new;
3
+ export default _default;
4
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1,3 @@
1
+ import Store from "@primate/core/orm/Store";
2
+ export default Store.new;
3
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1,2 @@
1
+ export { default } from "@primate/core/orm/wrap";
2
+ //# sourceMappingURL=wrap.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { default } from "@primate/core/orm/wrap";
2
+ //# sourceMappingURL=wrap.js.map
@@ -0,0 +1,2 @@
1
+ export { type RequestFacade } from "@primate/core/request";
2
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=request.js.map
@@ -1,23 +1,4 @@
1
- import binary from "@primate/core/response/binary";
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
- declare const _default: {
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
@@ -1,19 +1,2 @@
1
- import binary from "@primate/core/response/binary";
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
@@ -0,0 +1,2 @@
1
+ export { default } from "@primate/core/route/hook";
2
+ //# sourceMappingURL=hook.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { default } from "@primate/core/route/hook";
2
+ //# sourceMappingURL=hook.js.map
@@ -1,2 +1,3 @@
1
- export { default } from "#runtime/FileRef";
1
+ declare const FileRef: typeof import("@rcompat/fs").FileRef;
2
+ export { FileRef as default };
2
3
  //# sourceMappingURL=FileRef.d.ts.map
@@ -1,2 +1,4 @@
1
- export { default } from "#runtime/FileRef";
1
+ import fs from "@rcompat/fs";
2
+ const FileRef = fs.FileRef;
3
+ export { FileRef as default };
2
4
  //# sourceMappingURL=FileRef.js.map
package/package.json CHANGED
@@ -1,10 +1,16 @@
1
1
  {
2
2
  "name": "primate",
3
- "version": "0.35.1",
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
- "repository": {
16
- "type": "git",
17
- "url": "https://github.com/primate-run/primate",
18
- "directory": "packages/primate"
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/record": "^0.9.1",
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.4"
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
  }
@@ -1,2 +0,0 @@
1
- export { default } from "@primate/core/request/RequestFacade";
2
- //# sourceMappingURL=RequestFacade.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=RequestFacade.js.map
@@ -1,2 +0,0 @@
1
- export { default } from "@primate/core/database/Store";
2
- //# sourceMappingURL=Store.d.ts.map
@@ -1,2 +0,0 @@
1
- export { default } from "@primate/core/database/Store";
2
- //# sourceMappingURL=Store.js.map
@@ -1,2 +0,0 @@
1
- export { default } from "@primate/core/database/InMemoryDatabase";
2
- //# sourceMappingURL=default.d.ts.map
@@ -1,2 +0,0 @@
1
- export { default } from "@primate/core/database/InMemoryDatabase";
2
- //# sourceMappingURL=default.js.map
@@ -1,2 +0,0 @@
1
- export { default } from "@primate/core/database/wrap";
2
- //# sourceMappingURL=wrap.d.ts.map
@@ -1,2 +0,0 @@
1
- export { default } from "@primate/core/database/wrap";
2
- //# sourceMappingURL=wrap.js.map
@@ -1,2 +0,0 @@
1
- export { default } from "@rcompat/fs/FileRef";
2
- //# sourceMappingURL=FileRef.d.ts.map
@@ -1,2 +0,0 @@
1
- export { default } from "@rcompat/fs/FileRef";
2
- //# sourceMappingURL=FileRef.js.map
@@ -1,2 +0,0 @@
1
- export { default } from "pema";
2
- //# sourceMappingURL=pema.d.ts.map
@@ -1,2 +0,0 @@
1
- export { default } from "pema";
2
- //# sourceMappingURL=pema.js.map
@@ -1,2 +0,0 @@
1
- export { default } from "@primate/core/request/RequestFacade";
2
- //# sourceMappingURL=Facade.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Facade.js.map
@@ -1,4 +0,0 @@
1
- import Store from "@primate/core/database/Store";
2
- declare const _default: typeof Store.new;
3
- export default _default;
4
- //# sourceMappingURL=store.d.ts.map
@@ -1,3 +0,0 @@
1
- import Store from "@primate/core/database/Store";
2
- export default Store.new;
3
- //# sourceMappingURL=store.js.map
@@ -1,2 +0,0 @@
1
- export { default } from "@primate/core/wasm/instantiate";
2
- //# sourceMappingURL=instantiate.d.ts.map
@@ -1,2 +0,0 @@
1
- export { default } from "@primate/core/wasm/instantiate";
2
- //# sourceMappingURL=instantiate.js.map