@primate/core 0.7.5 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/lib/private/App.d.ts +128 -65
  2. package/lib/private/Bag.d.ts +11 -0
  3. package/lib/private/Bag.js +31 -0
  4. package/lib/private/Flags.d.ts +5 -5
  5. package/lib/private/Flags.js +2 -1
  6. package/lib/private/app/Facade.client.d.ts +20 -0
  7. package/lib/private/app/Facade.client.js +30 -0
  8. package/lib/private/app/{Facade.d.ts → Facade.server.d.ts} +141 -72
  9. package/lib/private/app/{Facade.js → Facade.server.js} +12 -4
  10. package/lib/private/build/App.d.ts +0 -2
  11. package/lib/private/build/App.js +0 -7
  12. package/lib/private/build/client/index.js +29 -27
  13. package/lib/private/build/client/plugin/frontend.js +1 -1
  14. package/lib/private/build/client/plugin/routes.js +1 -1
  15. package/lib/private/build/hook.js +0 -3
  16. package/lib/private/build/server/index.js +5 -18
  17. package/lib/private/build/server/plugin/native-addons.d.ts +1 -1
  18. package/lib/private/build/server/plugin/native-addons.js +1 -1
  19. package/lib/private/build/shared/intercept.d.ts +1 -1
  20. package/lib/private/build/shared/intercept.js +4 -2
  21. package/lib/private/client/create-form.d.ts +13 -9
  22. package/lib/private/client/create-form.js +21 -4
  23. package/lib/private/config/index.d.ts +6 -2
  24. package/lib/private/config/schema.d.ts +28 -21
  25. package/lib/private/config/schema.js +5 -3
  26. package/lib/private/cookie.d.ts +5 -5
  27. package/lib/private/db/errors.d.ts +82 -82
  28. package/lib/private/db/migrate/store.d.ts +2 -2
  29. package/lib/private/db/primary.d.ts +1 -1
  30. package/lib/private/db/sql.d.ts +1 -1
  31. package/lib/private/errors.d.ts +80 -68
  32. package/lib/private/errors.js +23 -1
  33. package/lib/private/frontend.d.ts +7 -7
  34. package/lib/private/frontend.js +7 -10
  35. package/lib/private/i18n/API.d.ts +14 -18
  36. package/lib/private/i18n/config.client.d.ts +7 -0
  37. package/lib/private/i18n/config.client.js +130 -0
  38. package/lib/private/i18n/config.server.d.ts +7 -0
  39. package/lib/private/i18n/{index/server.js → config.server.js} +31 -23
  40. package/lib/private/i18n/constant/COOKIE_NAME.d.ts +1 -1
  41. package/lib/private/i18n/constant/DEFAULT_LOCALE.d.ts +1 -1
  42. package/lib/private/i18n/constant/DEFAULT_PERSIST_MODE.d.ts +1 -1
  43. package/lib/private/i18n/constant/PERSIST_HEADER.d.ts +1 -1
  44. package/lib/private/i18n/constant/PERSIST_METHOD.d.ts +1 -1
  45. package/lib/private/i18n/constant/PERSIST_STORAGE_KEY.d.ts +1 -1
  46. package/lib/private/i18n/index.d.ts +42 -0
  47. package/lib/private/i18n/index.js +6 -0
  48. package/lib/private/i18n/missing.d.ts +5 -0
  49. package/lib/private/i18n/missing.js +38 -0
  50. package/lib/private/i18n/module.js +36 -52
  51. package/lib/private/i18n/schema.d.ts +4 -4
  52. package/lib/private/loader.d.ts +5 -0
  53. package/lib/private/loader.js +28 -0
  54. package/lib/private/logger.d.ts +1 -1
  55. package/lib/private/request/RequestBag.d.ts +12 -13
  56. package/lib/private/request/RequestBag.js +5 -4
  57. package/lib/private/request/RequestView.d.ts +5 -5
  58. package/lib/private/request/RequestView.js +0 -1
  59. package/lib/private/response/view.d.ts +1 -0
  60. package/lib/private/response/view.js +0 -7
  61. package/lib/private/route/Handler.d.ts +1 -1
  62. package/lib/private/route/NarrowedRequest.d.ts +6 -1
  63. package/lib/private/route/Options.d.ts +2 -1
  64. package/lib/private/route/hook.d.ts +1 -2
  65. package/lib/private/route/router.d.ts +9 -9
  66. package/lib/private/route/router.js +9 -0
  67. package/lib/private/route.client.d.ts +20 -4
  68. package/lib/private/route.client.js +7 -3
  69. package/lib/private/route.d.ts +3 -0
  70. package/lib/private/route.js +2 -0
  71. package/lib/private/serve/App.d.ts +2 -13
  72. package/lib/private/serve/App.js +63 -46
  73. package/lib/private/serve/Init.d.ts +0 -3
  74. package/lib/private/server/TAG.d.ts +1 -1
  75. package/lib/private/session/{index.client.d.ts → config.client.d.ts} +1 -1
  76. package/lib/private/session/{index.client.js → config.client.js} +1 -1
  77. package/lib/private/session/config.server.d.ts +15 -0
  78. package/lib/private/session/config.server.js +44 -0
  79. package/lib/private/session/index.d.ts +2 -14
  80. package/lib/private/session/index.js +2 -43
  81. package/lib/private/session/module.js +1 -1
  82. package/lib/private/session/schema.d.ts +5 -5
  83. package/lib/private/store/PrimaryKey.d.ts +1 -1
  84. package/lib/private/store.client.d.ts +2 -0
  85. package/lib/private/store.d.ts +2 -0
  86. package/lib/private/target/Manager.d.ts +2 -0
  87. package/lib/private/target/Manager.js +29 -5
  88. package/lib/private/target/Target.d.ts +2 -0
  89. package/lib/public/i18n.d.ts +3 -0
  90. package/lib/public/{i18n/config.js → i18n.js} +1 -1
  91. package/lib/public/loader.d.ts +2 -0
  92. package/lib/public/loader.js +2 -0
  93. package/lib/public/response.d.ts +1 -1
  94. package/lib/public/{session/config.d.ts → session.d.ts} +1 -1
  95. package/lib/public/{session/config.js → session.js} +1 -1
  96. package/package.json +27 -18
  97. package/lib/private/app/Facade.browser.d.ts +0 -11
  98. package/lib/private/app/Facade.browser.js +0 -19
  99. package/lib/private/build/server/plugin/store.d.ts +0 -4
  100. package/lib/private/build/server/plugin/store.js +0 -25
  101. package/lib/private/build/server/plugin/stores.d.ts +0 -4
  102. package/lib/private/build/server/plugin/stores.js +0 -28
  103. package/lib/private/i18n/index/client.d.ts +0 -9
  104. package/lib/private/i18n/index/client.js +0 -152
  105. package/lib/private/i18n/index/server.d.ts +0 -9
  106. package/lib/private/i18n/symbol/internal.d.ts +0 -3
  107. package/lib/private/i18n/symbol/internal.js +0 -3
  108. package/lib/public/i18n/API.d.ts +0 -2
  109. package/lib/public/i18n/API.js +0 -2
  110. package/lib/public/i18n/Catalogs.d.ts +0 -2
  111. package/lib/public/i18n/Catalogs.js +0 -2
  112. package/lib/public/i18n/ContextData.d.ts +0 -2
  113. package/lib/public/i18n/ContextData.js +0 -2
  114. package/lib/public/i18n/config.d.ts +0 -2
  115. package/lib/public/i18n/locale.d.ts +0 -2
  116. package/lib/public/i18n/locale.js +0 -2
  117. package/lib/public/i18n/sInternal.d.ts +0 -2
  118. package/lib/public/i18n/sInternal.js +0 -2
  119. package/lib/public/route/hook.d.ts +0 -2
  120. package/lib/public/route/hook.js +0 -2
  121. package/lib/public/session/config.client.d.ts +0 -2
  122. package/lib/public/session/config.client.js +0 -2
  123. /package/lib/private/i18n/{index/types.d.ts → types.d.ts} +0 -0
  124. /package/lib/private/i18n/{index/types.js → types.js} +0 -0
@@ -1,12 +1,30 @@
1
1
  import E from "#errors";
2
- const web = {
3
- name: "web",
2
+ import runtime from "@rcompat/runtime";
3
+ const node = {
4
+ name: "node",
4
5
  runner: () => { },
5
- target: "web",
6
+ target: "node",
7
+ conditions: ["node"],
8
+ externals: ["node:*"],
6
9
  };
10
+ const deno = {
11
+ name: "deno",
12
+ runner: () => { },
13
+ target: "deno",
14
+ conditions: ["deno", "node"],
15
+ externals: ["node:*"],
16
+ };
17
+ const bun = {
18
+ name: "bun",
19
+ runner: () => { },
20
+ target: "bun",
21
+ conditions: ["bun", "node"],
22
+ externals: ["bun:*", "node:*"],
23
+ };
24
+ const TARGETS = [node, deno, bun];
7
25
  export default class TargetManager {
8
- #name = "web";
9
- #targets = [web];
26
+ #name = runtime.name;
27
+ #targets = [...TARGETS];
10
28
  #app;
11
29
  constructor(app) {
12
30
  this.#app = app;
@@ -17,6 +35,12 @@ export default class TargetManager {
17
35
  get target() {
18
36
  return this.get().target;
19
37
  }
38
+ get conditions() {
39
+ return this.get().conditions;
40
+ }
41
+ get externals() {
42
+ return this.get().externals;
43
+ }
20
44
  has(name) {
21
45
  return this.#targets
22
46
  .find(target => target.name === name) !== undefined;
@@ -4,5 +4,7 @@ export default interface Target {
4
4
  name: string;
5
5
  runner: (app: App) => MaybePromise<void>;
6
6
  target: string;
7
+ conditions: string[];
8
+ externals: string[];
7
9
  }
8
10
  //# sourceMappingURL=Target.d.ts.map
@@ -0,0 +1,3 @@
1
+ export type * from "#i18n/index";
2
+ export { default } from "#i18n/index";
3
+ //# sourceMappingURL=i18n.d.ts.map
@@ -1,2 +1,2 @@
1
1
  export { default } from "#i18n/index";
2
- //# sourceMappingURL=config.js.map
2
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1,2 @@
1
+ export { default } from "#loader";
2
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { default } from "#loader";
2
+ //# sourceMappingURL=loader.js.map
@@ -6,7 +6,7 @@ declare const response: {
6
6
  binary: typeof binary;
7
7
  error: typeof error;
8
8
  json: (body: unknown, init?: ResponseInit) => (app: import("./index.js").ServeApp) => import("@rcompat/type").MaybePromise<Response>;
9
- redirect: (location: string, status?: 302 | 301 | 300 | 304 | 308 | 303 | 307) => import("./index.js").ResponseFunction;
9
+ redirect: (location: string, status?: 300 | 301 | 302 | 303 | 304 | 307 | 308) => import("./index.js").ResponseFunction;
10
10
  sse: (body: {
11
11
  close?(): undefined;
12
12
  open(events: {
@@ -1,2 +1,2 @@
1
1
  export { default } from "#session/index";
2
- //# sourceMappingURL=config.d.ts.map
2
+ //# sourceMappingURL=session.d.ts.map
@@ -1,2 +1,2 @@
1
1
  export { default } from "#session/index";
2
- //# sourceMappingURL=config.js.map
2
+ //# sourceMappingURL=session.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/core",
3
- "version": "0.7.5",
3
+ "version": "0.8.1",
4
4
  "description": "The universal web framework",
5
5
  "homepage": "https://primate.run",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",
@@ -22,7 +22,7 @@
22
22
  "@rcompat/cli": "^0.24.0",
23
23
  "@rcompat/crypto": "^0.21.0",
24
24
  "@rcompat/dict": "^0.10.0",
25
- "@rcompat/env": "^0.22.0",
25
+ "@rcompat/env": "^0.22.2",
26
26
  "@rcompat/error": "^0.8.0",
27
27
  "@rcompat/fn": "^0.10.0",
28
28
  "@rcompat/fs": "^0.33.2",
@@ -35,13 +35,32 @@
35
35
  "@rcompat/symbol": "^0.2.0",
36
36
  "@rcompat/type": "^0.17.0",
37
37
  "esbuild": "^0.28.0",
38
- "pema": "^0.7.0"
38
+ "pema": "^0.8.0"
39
39
  },
40
40
  "imports": {
41
- "#i18n/index": {
42
- "@primate/source": "./src/private/i18n/index/client.ts",
43
- "browser": "./lib/private/i18n/index/client.js",
44
- "default": "./lib/private/i18n/index/server.js"
41
+ "#i18n/config": {
42
+ "browser": {
43
+ "@primate/source": "./src/private/i18n/config.client.ts",
44
+ "default": "./lib/private/i18n/config.client.js"
45
+ },
46
+ "@primate/source": "./src/private/i18n/config.server.ts",
47
+ "default": "./lib/private/i18n/config.server.js"
48
+ },
49
+ "#session/config": {
50
+ "browser": {
51
+ "@primate/source": "./src/private/session/config.client.ts",
52
+ "default": "./lib/private/session/config.client.js"
53
+ },
54
+ "@primate/source": "./src/private/session/config.server.ts",
55
+ "default": "./lib/private/session/config.server.js"
56
+ },
57
+ "#app/Facade": {
58
+ "browser": {
59
+ "@primate/source": "./src/private/app/Facade.client.ts",
60
+ "default": "./lib/private/app/Facade.client.js"
61
+ },
62
+ "@primate/source": "./src/private/app/Facade.server.ts",
63
+ "default": "./lib/private/app/Facade.server.js"
45
64
  },
46
65
  "#*": {
47
66
  "@primate/source": "./src/private/*.ts",
@@ -49,11 +68,6 @@
49
68
  }
50
69
  },
51
70
  "exports": {
52
- "./AppFacade": {
53
- "@primate/source": "./src/public/AppFacade.ts",
54
- "browser": "./lib/private/app/Facade.browser.js",
55
- "default": "./lib/public/AppFacade.js"
56
- },
57
71
  "./route": {
58
72
  "types": "./lib/public/route.client.js",
59
73
  "@primate/source": "./src/public/route.ts",
@@ -65,11 +79,6 @@
65
79
  "browser": "./lib/private/response.client.js",
66
80
  "default": "./lib/public/response.js"
67
81
  },
68
- "./session/config": {
69
- "@primate/source": "./src/public/session/config.ts",
70
- "browser": "./lib/public/session/config.client.js",
71
- "default": "./lib/public/session/config.js"
72
- },
73
82
  "./store": {
74
83
  "@primate/source": "./src/public/store.ts",
75
84
  "browser": "./lib/private/store.client.js",
@@ -85,7 +94,7 @@
85
94
  }
86
95
  },
87
96
  "scripts": {
88
- "build": "npm run clean && tsc && cp -a src/private/defaults lib/private",
97
+ "build": "npm run clean && tsgo && cp -a src/private/defaults lib/private",
89
98
  "clean": "rm -rf ./lib",
90
99
  "lint": "eslint .",
91
100
  "test": "npx proby"
@@ -1,11 +0,0 @@
1
- /**
2
- * Browser stub for AppFacade.
3
- * env must never be called in frontend code, ecrets must not leak to clients
4
- */
5
- export default class AppFacade {
6
- config(_path: string): never;
7
- env(_key: string): never;
8
- view(_name: string): never;
9
- get root(): never;
10
- }
11
- //# sourceMappingURL=Facade.browser.d.ts.map
@@ -1,19 +0,0 @@
1
- /**
2
- * Browser stub for AppFacade.
3
- * env must never be called in frontend code, ecrets must not leak to clients
4
- */
5
- export default class AppFacade {
6
- config(_path) {
7
- throw new Error("AppFacade.config() is not available in the browser");
8
- }
9
- env(_key) {
10
- throw new Error("AppFacade.env() is server-only. Do not call env() in frontend/browser code.");
11
- }
12
- view(_name) {
13
- throw new Error("AppFacade.view() is not available in the browser");
14
- }
15
- get root() {
16
- throw new Error("AppFacade.root is not available in the browser");
17
- }
18
- }
19
- //# sourceMappingURL=Facade.browser.js.map
@@ -1,4 +0,0 @@
1
- import type BuildApp from "#build/App";
2
- import type { Plugin } from "esbuild";
3
- export default function plugin_server_store(app: BuildApp): Plugin;
4
- //# sourceMappingURL=store.d.ts.map
@@ -1,25 +0,0 @@
1
- import fs from "@rcompat/fs";
2
- export default function plugin_server_store(app) {
3
- return {
4
- name: "primate/server/store",
5
- setup(build) {
6
- build.onLoad({ filter: /.*/ }, async (args) => {
7
- if (args.namespace !== "file")
8
- return null;
9
- if (!/\.([tj]s)$/.test(args.path))
10
- return null;
11
- const file = fs.ref(args.path);
12
- const stores_root = app.path.stores.path;
13
- if (!file.path.startsWith(stores_root + "/"))
14
- return null;
15
- return {
16
- contents: await file.text(),
17
- loader: args.path.endsWith(".ts") ? "ts" : "js",
18
- resolveDir: file.directory.path,
19
- watchFiles: [file.path],
20
- };
21
- });
22
- },
23
- };
24
- }
25
- //# sourceMappingURL=store.js.map
@@ -1,4 +0,0 @@
1
- import type BuildApp from "#build/App";
2
- import type { Plugin } from "esbuild";
3
- export default function plugin_server_stores(app: BuildApp): Plugin;
4
- //# sourceMappingURL=stores.d.ts.map
@@ -1,28 +0,0 @@
1
- import fs from "@rcompat/fs";
2
- export default function plugin_server_stores(app) {
3
- const base = app.path.stores;
4
- return {
5
- name: "primate/server/stores",
6
- setup(build) {
7
- build.onResolve({ filter: /^app:stores$/ }, () => {
8
- return { path: "stores-virtual", namespace: "primate-stores" };
9
- });
10
- build.onLoad({ filter: /.*/, namespace: "primate-stores" }, async () => {
11
- const files = await base.files({ recursive: true, filter: /\.[jt]s$/ });
12
- const contents = `
13
- const stores = {};
14
- ${files.map((file, i) => {
15
- const bare = fs.webpath(`${file}`
16
- .replace(base.toString(), "")
17
- .replace(/\.[jt]s$/, "").slice(1));
18
- return `import * as store${i} from "${file}";
19
- stores["${bare}"] = store${i}.default;`;
20
- }).join("\n")}
21
- export default stores;
22
- `;
23
- return { contents, loader: "js", resolveDir: app.root.path };
24
- });
25
- },
26
- };
27
- }
28
- //# sourceMappingURL=stores.js.map