@primate/core 0.5.0 → 0.6.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 (297) hide show
  1. package/lib/private/App.d.ts +263 -26
  2. package/lib/private/App.js +42 -14
  3. package/lib/private/Flags.d.ts +8 -4
  4. package/lib/private/Module.d.ts +4 -16
  5. package/lib/private/Module.js +1 -17
  6. package/lib/private/app/EnvSchema.d.ts +5 -0
  7. package/lib/private/app/EnvSchema.js +2 -0
  8. package/lib/private/app/Facade.browser.d.ts +11 -0
  9. package/lib/private/app/Facade.browser.js +19 -0
  10. package/lib/private/app/Facade.d.ts +272 -27
  11. package/lib/private/app/Facade.js +23 -0
  12. package/lib/private/build/client/index.js +8 -3
  13. package/lib/private/build/client/plugin/app-request.d.ts +4 -0
  14. package/lib/private/build/client/plugin/app-request.js +19 -0
  15. package/lib/private/build/client/plugin/view.d.ts +4 -0
  16. package/lib/private/build/client/plugin/view.js +13 -0
  17. package/lib/private/build/hook.d.ts +1 -2
  18. package/lib/private/build/hook.js +21 -16
  19. package/lib/private/build/index.d.ts +2 -1
  20. package/lib/private/build/index.js +20 -21
  21. package/lib/private/build/server/index.js +7 -9
  22. package/lib/private/build/server/plugin/app-request.d.ts +4 -0
  23. package/lib/private/build/server/plugin/app-request.js +19 -0
  24. package/lib/private/build/server/plugin/assets.js +1 -1
  25. package/lib/private/build/server/plugin/live-reload.js +9 -9
  26. package/lib/private/build/server/plugin/native-addons.js +4 -7
  27. package/lib/private/build/server/plugin/route.js +2 -2
  28. package/lib/private/build/server/plugin/store.js +9 -31
  29. package/lib/private/build/server/plugin/stores.js +11 -7
  30. package/lib/private/build/server/plugin/view.js +1 -1
  31. package/lib/private/build/shared/plugin/app-request.d.ts +4 -0
  32. package/lib/private/build/shared/plugin/app-request.js +19 -0
  33. package/lib/private/client/Data.d.ts +3 -2
  34. package/lib/private/{frontend → client}/Render.d.ts +1 -1
  35. package/lib/private/{frontend → client}/ViewResponse.d.ts +1 -1
  36. package/lib/private/client/app.js +1 -2
  37. package/lib/private/client/boot.d.ts +5 -0
  38. package/lib/private/client/boot.js +64 -0
  39. package/lib/private/client/create-form.d.ts +1 -0
  40. package/lib/private/client/create-form.js +19 -20
  41. package/lib/private/client/extract-issues.js +2 -1
  42. package/lib/private/client/http.d.ts +13 -0
  43. package/lib/private/client/http.js +57 -0
  44. package/lib/private/client/index.d.ts +23 -0
  45. package/lib/private/client/index.js +16 -0
  46. package/lib/private/client/navigate.d.ts +13 -0
  47. package/lib/private/client/navigate.js +67 -0
  48. package/lib/private/client/root.d.ts +9 -0
  49. package/lib/private/client/root.js +11 -0
  50. package/lib/private/client/submit.d.ts +2 -0
  51. package/lib/private/client/submit.js +41 -0
  52. package/lib/private/config/index.d.ts +7 -2
  53. package/lib/private/config/index.js +3 -2
  54. package/lib/private/config/schema.d.ts +82 -26
  55. package/lib/private/config/schema.js +17 -4
  56. package/lib/private/cookie.d.ts +12 -6
  57. package/lib/private/db/DB.d.ts +21 -5
  58. package/lib/private/db/DB.js +1 -0
  59. package/lib/private/db/MemoryDB.d.ts +2 -4
  60. package/lib/private/db/MemoryDB.js +40 -22
  61. package/lib/private/db/common.d.ts +7 -0
  62. package/lib/private/db/common.js +31 -0
  63. package/lib/private/db/errors.d.ts +104 -0
  64. package/lib/private/db/errors.js +237 -0
  65. package/lib/private/db/migrate/apply.d.ts +2 -0
  66. package/lib/private/db/migrate/apply.js +32 -0
  67. package/lib/private/db/migrate/bundle.d.ts +3 -0
  68. package/lib/private/db/migrate/bundle.js +22 -0
  69. package/lib/private/db/migrate/create.d.ts +2 -0
  70. package/lib/private/db/migrate/create.js +154 -0
  71. package/lib/private/db/migrate/index.d.ts +10 -0
  72. package/lib/private/db/migrate/index.js +6 -0
  73. package/lib/private/db/migrate/status.d.ts +2 -0
  74. package/lib/private/db/migrate/status.js +38 -0
  75. package/lib/private/db/migrate/store.d.ts +5 -0
  76. package/lib/private/db/migrate/store.js +33 -0
  77. package/lib/private/db/sql.js +3 -3
  78. package/lib/private/db/test.js +461 -95
  79. package/lib/private/errors.d.ts +88 -0
  80. package/lib/private/errors.js +211 -0
  81. package/lib/private/frontend.d.ts +72 -0
  82. package/lib/private/frontend.js +245 -0
  83. package/lib/private/i18n/Formatter.js +2 -2
  84. package/lib/private/i18n/errors.d.ts +16 -0
  85. package/lib/private/i18n/errors.js +27 -0
  86. package/lib/private/i18n/module.d.ts +3 -0
  87. package/lib/private/i18n/module.js +115 -0
  88. package/lib/private/i18n/schema.d.ts +10 -5
  89. package/lib/private/i18n/validate.js +5 -7
  90. package/lib/private/index.d.ts +14 -0
  91. package/lib/private/index.js +2 -0
  92. package/lib/private/log.js +6 -5
  93. package/lib/private/module/Setup.d.ts +21 -0
  94. package/lib/private/module/Setup.js +2 -0
  95. package/lib/private/module/create.d.ts +16 -0
  96. package/lib/private/module/create.js +28 -0
  97. package/lib/private/orm/ExtractSchema.d.ts +9 -0
  98. package/lib/private/orm/ExtractSchema.js +2 -0
  99. package/lib/private/orm/ForeignKey.d.ts +5 -2
  100. package/lib/private/orm/ForeignKey.js +3 -0
  101. package/lib/private/orm/PrimaryKey.d.ts +5 -3
  102. package/lib/private/orm/PrimaryKey.js +9 -6
  103. package/lib/private/orm/StoreInput.d.ts +10 -0
  104. package/lib/private/orm/StoreInput.js +2 -0
  105. package/lib/private/orm/key.d.ts +6 -6
  106. package/lib/private/orm/key.js +7 -3
  107. package/lib/private/orm/parse.d.ts +5 -4
  108. package/lib/private/orm/parse.js +2 -2
  109. package/lib/private/orm/relation.d.ts +2 -2
  110. package/lib/private/orm/{Store.d.ts → store.d.ts} +33 -17
  111. package/lib/private/orm/{Store.js → store.js} +91 -67
  112. package/lib/private/paths.js +3 -3
  113. package/lib/private/request/RequestBag.d.ts +4 -0
  114. package/lib/private/request/RequestBag.js +5 -2
  115. package/lib/private/request/RequestBody.d.ts +6 -9
  116. package/lib/private/request/RequestBody.js +49 -54
  117. package/lib/private/request/RequestFacade.d.ts +3 -8
  118. package/lib/private/request/RequestPublic.d.ts +9 -0
  119. package/lib/private/request/RequestPublic.js +2 -0
  120. package/lib/private/request/RequestView.d.ts +11 -0
  121. package/lib/private/request/RequestView.js +3 -0
  122. package/lib/private/request/handle.d.ts +4 -0
  123. package/lib/private/request/handle.js +18 -0
  124. package/lib/private/request/parse.js +1 -0
  125. package/lib/private/request/route.js +8 -9
  126. package/lib/private/request/router.js +21 -49
  127. package/lib/private/request/storage.d.ts +4 -0
  128. package/lib/private/request/storage.js +5 -0
  129. package/lib/private/response/ResponseFunction.d.ts +1 -1
  130. package/lib/private/response/binary.js +1 -1
  131. package/lib/private/response/error.d.ts +1 -1
  132. package/lib/private/response/error.js +1 -1
  133. package/lib/private/response/json.d.ts +1 -1
  134. package/lib/private/response/json.js +1 -1
  135. package/lib/private/response/redirect.d.ts +5 -5
  136. package/lib/private/response/redirect.js +8 -9
  137. package/lib/private/response/respond.js +9 -7
  138. package/lib/private/response/sse.d.ts +1 -1
  139. package/lib/private/response/sse.js +1 -1
  140. package/lib/private/response/text.d.ts +1 -1
  141. package/lib/private/response/text.js +1 -1
  142. package/lib/private/response/view.d.ts +1 -1
  143. package/lib/private/response/view.js +6 -13
  144. package/lib/private/response/ws.d.ts +1 -1
  145. package/lib/private/route/router.d.ts +3 -3
  146. package/lib/private/route/router.js +7 -10
  147. package/lib/private/serve/App.d.ts +6 -7
  148. package/lib/private/serve/App.js +52 -43
  149. package/lib/private/serve/Init.d.ts +2 -2
  150. package/lib/private/serve/dev-module.d.ts +2 -0
  151. package/lib/private/serve/dev-module.js +34 -0
  152. package/lib/private/serve/hook.d.ts +1 -2
  153. package/lib/private/serve/hook.js +2 -3
  154. package/lib/private/serve/index.d.ts +1 -1
  155. package/lib/private/serve/index.js +32 -2
  156. package/lib/private/server/TAG.d.ts +3 -0
  157. package/lib/private/server/TAG.js +2 -0
  158. package/lib/private/server/index.d.ts +5 -0
  159. package/lib/private/server/index.js +6 -0
  160. package/lib/private/session/SessionHandle.js +2 -1
  161. package/lib/private/session/index.d.ts +1 -1
  162. package/lib/private/session/module.d.ts +3 -0
  163. package/lib/private/session/module.js +114 -0
  164. package/lib/private/session/schema.d.ts +17 -9
  165. package/lib/private/session/schema.js +9 -5
  166. package/lib/private/target/Manager.js +6 -12
  167. package/lib/public/client.d.ts +2 -13
  168. package/lib/public/client.js +1 -9
  169. package/lib/public/db/errors.d.ts +2 -0
  170. package/lib/public/db/errors.js +2 -0
  171. package/lib/public/db/migrate.d.ts +2 -0
  172. package/lib/public/db/migrate.js +2 -0
  173. package/lib/public/db.d.ts +3 -3
  174. package/lib/public/frontend.d.ts +3 -0
  175. package/lib/public/frontend.js +2 -0
  176. package/lib/public/index.d.ts +2 -0
  177. package/lib/public/index.js +2 -0
  178. package/lib/public/orm/store.d.ts +2 -0
  179. package/lib/public/orm/store.js +2 -0
  180. package/lib/public/request/server.d.ts +5 -0
  181. package/lib/public/request/server.js +7 -0
  182. package/lib/public/response.d.ts +4 -4
  183. package/lib/public/server.d.ts +3 -0
  184. package/lib/public/server.js +2 -0
  185. package/package.json +30 -25
  186. package/lib/private/AppError.d.ts +0 -4
  187. package/lib/private/AppError.js +0 -8
  188. package/lib/private/backend/Module.d.ts +0 -18
  189. package/lib/private/backend/Module.js +0 -19
  190. package/lib/private/backend/TAG.d.ts +0 -3
  191. package/lib/private/backend/TAG.js +0 -2
  192. package/lib/private/build/server/plugin/db-default.d.ts +0 -4
  193. package/lib/private/build/server/plugin/db-default.js +0 -45
  194. package/lib/private/build/server/plugin/store-wrap.d.ts +0 -4
  195. package/lib/private/build/server/plugin/store-wrap.js +0 -33
  196. package/lib/private/client/spa/index.d.ts +0 -6
  197. package/lib/private/client/spa/index.js +0 -200
  198. package/lib/private/db/error.d.ts +0 -81
  199. package/lib/private/db/error.js +0 -199
  200. package/lib/private/db/symbol/wrap.d.ts +0 -3
  201. package/lib/private/db/symbol/wrap.js +0 -2
  202. package/lib/private/fail.d.ts +0 -3
  203. package/lib/private/fail.js +0 -5
  204. package/lib/private/frontend/Module.d.ts +0 -62
  205. package/lib/private/frontend/Module.js +0 -255
  206. package/lib/private/i18n/Module.d.ts +0 -16
  207. package/lib/private/i18n/Module.js +0 -133
  208. package/lib/private/module/BuildHook.d.ts +0 -5
  209. package/lib/private/module/BuildHook.js +0 -2
  210. package/lib/private/module/NextBuild.d.ts +0 -5
  211. package/lib/private/module/NextBuild.js +0 -2
  212. package/lib/private/module/NextServe.d.ts +0 -5
  213. package/lib/private/module/NextServe.js +0 -2
  214. package/lib/private/orm/Set.d.ts +0 -11
  215. package/lib/private/orm/Set.js +0 -2
  216. package/lib/private/orm/foreign.d.ts +0 -4
  217. package/lib/private/orm/foreign.js +0 -5
  218. package/lib/private/orm/primary.d.ts +0 -5
  219. package/lib/private/orm/primary.js +0 -5
  220. package/lib/private/orm/types.d.ts +0 -18
  221. package/lib/private/orm/types.js +0 -2
  222. package/lib/private/orm/wrap.d.ts +0 -5
  223. package/lib/private/orm/wrap.js +0 -5
  224. package/lib/private/reducer.d.ts +0 -24
  225. package/lib/private/reducer.js +0 -10
  226. package/lib/private/serve/module/Dev.d.ts +0 -11
  227. package/lib/private/serve/module/Dev.js +0 -32
  228. package/lib/private/serve/module/Handle.d.ts +0 -10
  229. package/lib/private/serve/module/Handle.js +0 -15
  230. package/lib/private/session/SessionModule.d.ts +0 -14
  231. package/lib/private/session/SessionModule.js +0 -122
  232. package/lib/public/App.d.ts +0 -2
  233. package/lib/public/App.js +0 -2
  234. package/lib/public/AppError.d.ts +0 -2
  235. package/lib/public/AppError.js +0 -2
  236. package/lib/public/BuildApp.d.ts +0 -2
  237. package/lib/public/BuildApp.js +0 -2
  238. package/lib/public/BuildHook.d.ts +0 -2
  239. package/lib/public/BuildHook.js +0 -2
  240. package/lib/public/Mode.d.ts +0 -2
  241. package/lib/public/Mode.js +0 -2
  242. package/lib/public/Module.d.ts +0 -2
  243. package/lib/public/Module.js +0 -2
  244. package/lib/public/Next.d.ts +0 -2
  245. package/lib/public/Next.js +0 -2
  246. package/lib/public/NextBuild.d.ts +0 -2
  247. package/lib/public/NextBuild.js +0 -2
  248. package/lib/public/NextHandle.d.ts +0 -2
  249. package/lib/public/NextHandle.js +0 -2
  250. package/lib/public/NextRoute.d.ts +0 -3
  251. package/lib/public/NextRoute.js +0 -2
  252. package/lib/public/NextServe.d.ts +0 -2
  253. package/lib/public/NextServe.js +0 -2
  254. package/lib/public/ServeApp.d.ts +0 -2
  255. package/lib/public/ServeApp.js +0 -2
  256. package/lib/public/Target.d.ts +0 -2
  257. package/lib/public/Target.js +0 -2
  258. package/lib/public/backend/Module.d.ts +0 -2
  259. package/lib/public/backend/Module.js +0 -2
  260. package/lib/public/backend/TAG.d.ts +0 -2
  261. package/lib/public/backend/TAG.js +0 -2
  262. package/lib/public/client/Data.d.ts +0 -2
  263. package/lib/public/client/Data.js +0 -2
  264. package/lib/public/client/spa.d.ts +0 -2
  265. package/lib/public/client/spa.js +0 -2
  266. package/lib/public/db/error.d.ts +0 -2
  267. package/lib/public/db/error.js +0 -2
  268. package/lib/public/fail.d.ts +0 -2
  269. package/lib/public/fail.js +0 -2
  270. package/lib/public/frontend/Module.d.ts +0 -2
  271. package/lib/public/frontend/Module.js +0 -2
  272. package/lib/public/frontend/Publish.d.ts +0 -2
  273. package/lib/public/frontend/Publish.js +0 -2
  274. package/lib/public/frontend/Render.d.ts +0 -2
  275. package/lib/public/frontend/Render.js +0 -2
  276. package/lib/public/frontend/ViewResponse.d.ts +0 -2
  277. package/lib/public/frontend/ViewResponse.js +0 -2
  278. package/lib/public/orm/Store.d.ts +0 -2
  279. package/lib/public/orm/Store.js +0 -2
  280. package/lib/public/orm/wrap.d.ts +0 -2
  281. package/lib/public/orm/wrap.js +0 -2
  282. package/lib/public/request.d.ts +0 -4
  283. package/lib/public/request.js +0 -2
  284. /package/lib/private/{frontend → client}/Publish.d.ts +0 -0
  285. /package/lib/private/{frontend → client}/Publish.js +0 -0
  286. /package/lib/private/{frontend → client}/Render.js +0 -0
  287. /package/lib/private/{frontend → client}/ServerData.d.ts +0 -0
  288. /package/lib/private/{frontend → client}/ServerData.js +0 -0
  289. /package/lib/private/{frontend → client}/ServerView.d.ts +0 -0
  290. /package/lib/private/{frontend → client}/ServerView.js +0 -0
  291. /package/lib/private/{frontend → client}/View.d.ts +0 -0
  292. /package/lib/private/{frontend → client}/View.js +0 -0
  293. /package/lib/private/{frontend → client}/ViewOptions.d.ts +0 -0
  294. /package/lib/private/{frontend → client}/ViewOptions.js +0 -0
  295. /package/lib/private/{frontend → client}/ViewResponse.js +0 -0
  296. /package/lib/private/client/{spa/storage.d.ts → storage.d.ts} +0 -0
  297. /package/lib/private/client/{spa/storage.js → storage.js} +0 -0
@@ -1,13 +1,20 @@
1
+ import type BuildApp from "#build/App";
1
2
  import type Config from "#config/Config";
2
3
  import type Flags from "#Flags";
3
4
  import type Mode from "#Mode";
4
- import type Module from "#Module";
5
+ import type { Created } from "#module/create";
6
+ import type ServeApp from "#serve/App";
5
7
  import TargetManager from "#target/Manager";
6
8
  import type { FileRef } from "@rcompat/fs";
7
9
  export default class App {
8
10
  #private;
9
11
  constructor(root: FileRef, config: Config, flags: typeof Flags.infer);
10
- init(): Promise<App>;
12
+ init(): Promise<this>;
13
+ register(created: Created): void;
14
+ build_hooks(app: BuildApp): Promise<BuildApp>;
15
+ serve_hooks(app: ServeApp): Promise<ServeApp>;
16
+ get handle_hooks(): import("./index.js").HandleHook[];
17
+ get route_hooks(): import("./index.js").RouteHook[];
11
18
  get location(): {
12
19
  app_html: "app.html";
13
20
  client: "client";
@@ -37,14 +44,13 @@ export default class App {
37
44
  build: FileRef;
38
45
  };
39
46
  get mode(): Mode;
40
- get modules(): Module[];
41
47
  get livereload(): {
42
48
  host: string;
43
49
  port: number;
44
50
  };
45
51
  get<T>(key: symbol): T;
46
52
  set(key: symbol, value: unknown): void;
47
- config<P extends string>(path: P): P extends `${infer P1}.${infer Rest}` ? P1 extends "http" | "livereload" | "request" | "modules" ? (Rest extends `${infer P1}.${infer Rest}` ? P1 extends keyof Exclude<{
53
+ config<P extends string>(path: P): P extends `${infer P1}.${infer Rest}` ? P1 extends "http" | "livereload" | "db" | "env" | "request" | "modules" ? (Rest extends `${infer P1}.${infer Rest}` ? P1 extends keyof Exclude<{
48
54
  http: {
49
55
  csp: Record<string, string[]> | undefined;
50
56
  headers: Record<string, string> | undefined;
@@ -63,7 +69,18 @@ export default class App {
63
69
  host: string | undefined;
64
70
  port: number | undefined;
65
71
  };
66
- modules: Module[] | undefined;
72
+ db: {
73
+ migrations: {
74
+ table: string;
75
+ db: import("./db/DB.js").default;
76
+ } | undefined;
77
+ };
78
+ env: {
79
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
80
+ [x: string]: unknown;
81
+ }> | undefined;
82
+ };
83
+ modules: import("./Module.js").default[];
67
84
  request: {
68
85
  body: {
69
86
  parse: boolean;
@@ -88,7 +105,18 @@ export default class App {
88
105
  host: string | undefined;
89
106
  port: number | undefined;
90
107
  };
91
- modules: Module[] | undefined;
108
+ db: {
109
+ migrations: {
110
+ table: string;
111
+ db: import("./db/DB.js").default;
112
+ } | undefined;
113
+ };
114
+ env: {
115
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
116
+ [x: string]: unknown;
117
+ }> | undefined;
118
+ };
119
+ modules: import("./Module.js").default[];
92
120
  request: {
93
121
  body: {
94
122
  parse: boolean;
@@ -113,7 +141,18 @@ export default class App {
113
141
  host: string | undefined;
114
142
  port: number | undefined;
115
143
  };
116
- modules: Module[] | undefined;
144
+ db: {
145
+ migrations: {
146
+ table: string;
147
+ db: import("./db/DB.js").default;
148
+ } | undefined;
149
+ };
150
+ env: {
151
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
152
+ [x: string]: unknown;
153
+ }> | undefined;
154
+ };
155
+ modules: import("./Module.js").default[];
117
156
  request: {
118
157
  body: {
119
158
  parse: boolean;
@@ -138,7 +177,18 @@ export default class App {
138
177
  host: string | undefined;
139
178
  port: number | undefined;
140
179
  };
141
- modules: Module[] | undefined;
180
+ db: {
181
+ migrations: {
182
+ table: string;
183
+ db: import("./db/DB.js").default;
184
+ } | undefined;
185
+ };
186
+ env: {
187
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
188
+ [x: string]: unknown;
189
+ }> | undefined;
190
+ };
191
+ modules: import("./Module.js").default[];
142
192
  request: {
143
193
  body: {
144
194
  parse: boolean;
@@ -163,7 +213,18 @@ export default class App {
163
213
  host: string | undefined;
164
214
  port: number | undefined;
165
215
  };
166
- modules: Module[] | undefined;
216
+ db: {
217
+ migrations: {
218
+ table: string;
219
+ db: import("./db/DB.js").default;
220
+ } | undefined;
221
+ };
222
+ env: {
223
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
224
+ [x: string]: unknown;
225
+ }> | undefined;
226
+ };
227
+ modules: import("./Module.js").default[];
167
228
  request: {
168
229
  body: {
169
230
  parse: boolean;
@@ -188,7 +249,18 @@ export default class App {
188
249
  host: string | undefined;
189
250
  port: number | undefined;
190
251
  };
191
- modules: Module[] | undefined;
252
+ db: {
253
+ migrations: {
254
+ table: string;
255
+ db: import("./db/DB.js").default;
256
+ } | undefined;
257
+ };
258
+ env: {
259
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
260
+ [x: string]: unknown;
261
+ }> | undefined;
262
+ };
263
+ modules: import("./Module.js").default[];
192
264
  request: {
193
265
  body: {
194
266
  parse: boolean;
@@ -213,7 +285,18 @@ export default class App {
213
285
  host: string | undefined;
214
286
  port: number | undefined;
215
287
  };
216
- modules: Module[] | undefined;
288
+ db: {
289
+ migrations: {
290
+ table: string;
291
+ db: import("./db/DB.js").default;
292
+ } | undefined;
293
+ };
294
+ env: {
295
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
296
+ [x: string]: unknown;
297
+ }> | undefined;
298
+ };
299
+ modules: import("./Module.js").default[];
217
300
  request: {
218
301
  body: {
219
302
  parse: boolean;
@@ -238,7 +321,18 @@ export default class App {
238
321
  host: string | undefined;
239
322
  port: number | undefined;
240
323
  };
241
- modules: Module[] | undefined;
324
+ db: {
325
+ migrations: {
326
+ table: string;
327
+ db: import("./db/DB.js").default;
328
+ } | undefined;
329
+ };
330
+ env: {
331
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
332
+ [x: string]: unknown;
333
+ }> | undefined;
334
+ };
335
+ modules: import("./Module.js").default[];
242
336
  request: {
243
337
  body: {
244
338
  parse: boolean;
@@ -263,7 +357,18 @@ export default class App {
263
357
  host: string | undefined;
264
358
  port: number | undefined;
265
359
  };
266
- modules: Module[] | undefined;
360
+ db: {
361
+ migrations: {
362
+ table: string;
363
+ db: import("./db/DB.js").default;
364
+ } | undefined;
365
+ };
366
+ env: {
367
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
368
+ [x: string]: unknown;
369
+ }> | undefined;
370
+ };
371
+ modules: import("./Module.js").default[];
267
372
  request: {
268
373
  body: {
269
374
  parse: boolean;
@@ -288,7 +393,18 @@ export default class App {
288
393
  host: string | undefined;
289
394
  port: number | undefined;
290
395
  };
291
- modules: Module[] | undefined;
396
+ db: {
397
+ migrations: {
398
+ table: string;
399
+ db: import("./db/DB.js").default;
400
+ } | undefined;
401
+ };
402
+ env: {
403
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
404
+ [x: string]: unknown;
405
+ }> | undefined;
406
+ };
407
+ modules: import("./Module.js").default[];
292
408
  request: {
293
409
  body: {
294
410
  parse: boolean;
@@ -313,7 +429,18 @@ export default class App {
313
429
  host: string | undefined;
314
430
  port: number | undefined;
315
431
  };
316
- modules: Module[] | undefined;
432
+ db: {
433
+ migrations: {
434
+ table: string;
435
+ db: import("./db/DB.js").default;
436
+ } | undefined;
437
+ };
438
+ env: {
439
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
440
+ [x: string]: unknown;
441
+ }> | undefined;
442
+ };
443
+ modules: import("./Module.js").default[];
317
444
  request: {
318
445
  body: {
319
446
  parse: boolean;
@@ -338,7 +465,18 @@ export default class App {
338
465
  host: string | undefined;
339
466
  port: number | undefined;
340
467
  };
341
- modules: Module[] | undefined;
468
+ db: {
469
+ migrations: {
470
+ table: string;
471
+ db: import("./db/DB.js").default;
472
+ } | undefined;
473
+ };
474
+ env: {
475
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
476
+ [x: string]: unknown;
477
+ }> | undefined;
478
+ };
479
+ modules: import("./Module.js").default[];
342
480
  request: {
343
481
  body: {
344
482
  parse: boolean;
@@ -363,7 +501,18 @@ export default class App {
363
501
  host: string | undefined;
364
502
  port: number | undefined;
365
503
  };
366
- modules: Module[] | undefined;
504
+ db: {
505
+ migrations: {
506
+ table: string;
507
+ db: import("./db/DB.js").default;
508
+ } | undefined;
509
+ };
510
+ env: {
511
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
512
+ [x: string]: unknown;
513
+ }> | undefined;
514
+ };
515
+ modules: import("./Module.js").default[];
367
516
  request: {
368
517
  body: {
369
518
  parse: boolean;
@@ -388,7 +537,18 @@ export default class App {
388
537
  host: string | undefined;
389
538
  port: number | undefined;
390
539
  };
391
- modules: Module[] | undefined;
540
+ db: {
541
+ migrations: {
542
+ table: string;
543
+ db: import("./db/DB.js").default;
544
+ } | undefined;
545
+ };
546
+ env: {
547
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
548
+ [x: string]: unknown;
549
+ }> | undefined;
550
+ };
551
+ modules: import("./Module.js").default[];
392
552
  request: {
393
553
  body: {
394
554
  parse: boolean;
@@ -413,7 +573,18 @@ export default class App {
413
573
  host: string | undefined;
414
574
  port: number | undefined;
415
575
  };
416
- modules: Module[] | undefined;
576
+ db: {
577
+ migrations: {
578
+ table: string;
579
+ db: import("./db/DB.js").default;
580
+ } | undefined;
581
+ };
582
+ env: {
583
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
584
+ [x: string]: unknown;
585
+ }> | undefined;
586
+ };
587
+ modules: import("./Module.js").default[];
417
588
  request: {
418
589
  body: {
419
590
  parse: boolean;
@@ -438,7 +609,18 @@ export default class App {
438
609
  host: string | undefined;
439
610
  port: number | undefined;
440
611
  };
441
- modules: Module[] | undefined;
612
+ db: {
613
+ migrations: {
614
+ table: string;
615
+ db: import("./db/DB.js").default;
616
+ } | undefined;
617
+ };
618
+ env: {
619
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
620
+ [x: string]: unknown;
621
+ }> | undefined;
622
+ };
623
+ modules: import("./Module.js").default[];
442
624
  request: {
443
625
  body: {
444
626
  parse: boolean;
@@ -463,7 +645,18 @@ export default class App {
463
645
  host: string | undefined;
464
646
  port: number | undefined;
465
647
  };
466
- modules: Module[] | undefined;
648
+ db: {
649
+ migrations: {
650
+ table: string;
651
+ db: import("./db/DB.js").default;
652
+ } | undefined;
653
+ };
654
+ env: {
655
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
656
+ [x: string]: unknown;
657
+ }> | undefined;
658
+ };
659
+ modules: import("./Module.js").default[];
467
660
  request: {
468
661
  body: {
469
662
  parse: boolean;
@@ -488,7 +681,18 @@ export default class App {
488
681
  host: string | undefined;
489
682
  port: number | undefined;
490
683
  };
491
- modules: Module[] | undefined;
684
+ db: {
685
+ migrations: {
686
+ table: string;
687
+ db: import("./db/DB.js").default;
688
+ } | undefined;
689
+ };
690
+ env: {
691
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
692
+ [x: string]: unknown;
693
+ }> | undefined;
694
+ };
695
+ modules: import("./Module.js").default[];
492
696
  request: {
493
697
  body: {
494
698
  parse: boolean;
@@ -513,7 +717,18 @@ export default class App {
513
717
  host: string | undefined;
514
718
  port: number | undefined;
515
719
  };
516
- modules: Module[] | undefined;
720
+ db: {
721
+ migrations: {
722
+ table: string;
723
+ db: import("./db/DB.js").default;
724
+ } | undefined;
725
+ };
726
+ env: {
727
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
728
+ [x: string]: unknown;
729
+ }> | undefined;
730
+ };
731
+ modules: import("./Module.js").default[];
517
732
  request: {
518
733
  body: {
519
734
  parse: boolean;
@@ -538,13 +753,24 @@ export default class App {
538
753
  host: string | undefined;
539
754
  port: number | undefined;
540
755
  };
541
- modules: Module[] | undefined;
756
+ db: {
757
+ migrations: {
758
+ table: string;
759
+ db: import("./db/DB.js").default;
760
+ } | undefined;
761
+ };
762
+ env: {
763
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
764
+ [x: string]: unknown;
765
+ }> | undefined;
766
+ };
767
+ modules: import("./Module.js").default[];
542
768
  request: {
543
769
  body: {
544
770
  parse: boolean;
545
771
  };
546
772
  };
547
- }[P1] & undefined) : undefined : P extends "http" | "livereload" | "request" | "modules" ? {
773
+ }[P1] & undefined) : undefined : P extends "http" | "livereload" | "db" | "env" | "request" | "modules" ? {
548
774
  http: {
549
775
  csp: Record<string, string[]> | undefined;
550
776
  headers: Record<string, string> | undefined;
@@ -563,7 +789,18 @@ export default class App {
563
789
  host: string | undefined;
564
790
  port: number | undefined;
565
791
  };
566
- modules: Module[] | undefined;
792
+ db: {
793
+ migrations: {
794
+ table: string;
795
+ db: import("./db/DB.js").default;
796
+ } | undefined;
797
+ };
798
+ env: {
799
+ schema: import("pema").ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
800
+ [x: string]: unknown;
801
+ }> | undefined;
802
+ };
803
+ modules: import("./Module.js").default[];
567
804
  request: {
568
805
  body: {
569
806
  parse: boolean;
@@ -1,27 +1,34 @@
1
- import fail from "#fail";
1
+ import E from "#errors";
2
2
  import location from "#location";
3
- import reducer from "#reducer";
3
+ import create from "#module/create";
4
4
  import TargetManager from "#target/Manager";
5
5
  import dict from "@rcompat/dict";
6
6
  import entries from "@rcompat/dict/entries";
7
7
  import p from "pema";
8
- const doubled = (set) => set.find((part, i, array) => array.filter((_, j) => i !== j).includes(part)) ?? "";
9
8
  export default class App {
10
9
  #path;
11
10
  #root;
12
11
  #config;
13
- #modules;
12
+ #hooks = {
13
+ init: [],
14
+ build: [],
15
+ serve: [],
16
+ handle: [],
17
+ route: [],
18
+ };
19
+ #module_names = new Set();
14
20
  #kv = new Map();
15
21
  #mode;
16
22
  #target;
17
23
  #target_name;
18
24
  constructor(root, config, flags) {
19
25
  if (Object.values(location).includes(flags.dir)) {
20
- throw fail("cannot build to {0} - reserved directory", flags.dir);
26
+ throw E.app_reserved_directory(flags.dir);
21
27
  }
22
28
  this.#root = root;
23
29
  this.#config = config;
24
- this.#modules = config.modules?.flat(10) ?? [];
30
+ for (const module of config.modules)
31
+ this.register(create(module));
25
32
  this.#path = entries({
26
33
  ...location,
27
34
  build: flags.dir,
@@ -31,14 +38,38 @@ export default class App {
31
38
  this.#target_name = flags.target;
32
39
  }
33
40
  async init() {
34
- const names = this.#modules.map(({ name }) => name);
35
- if (new Set(names).size !== this.#modules.length) {
36
- throw fail("module {0} loaded twice", doubled(names));
37
- }
38
- const app = await reducer(this.#modules, this, "init");
41
+ for (const hook of this.#hooks.init)
42
+ await hook(this);
39
43
  this.#target.set(this.#target_name);
44
+ return this;
45
+ }
46
+ register(created) {
47
+ if (this.#module_names.has(created.name)) {
48
+ throw E.app_duplicate_module(created.name);
49
+ }
50
+ this.#module_names.add(created.name);
51
+ this.#hooks.init.push(...created.hooks.init);
52
+ this.#hooks.build.push(...created.hooks.build);
53
+ this.#hooks.serve.push(...created.hooks.serve);
54
+ this.#hooks.handle.push(...created.hooks.handle);
55
+ this.#hooks.route.push(...created.hooks.route);
56
+ }
57
+ async build_hooks(app) {
58
+ for (const hook of this.#hooks.build)
59
+ await hook(app);
40
60
  return app;
41
61
  }
62
+ async serve_hooks(app) {
63
+ for (const hook of this.#hooks.serve)
64
+ await hook(app);
65
+ return app;
66
+ }
67
+ get handle_hooks() {
68
+ return [...this.#hooks.handle];
69
+ }
70
+ get route_hooks() {
71
+ return [...this.#hooks.route];
72
+ }
42
73
  get location() {
43
74
  return { ...location };
44
75
  }
@@ -54,9 +85,6 @@ export default class App {
54
85
  get mode() {
55
86
  return this.#mode;
56
87
  }
57
- get modules() {
58
- return [...this.#modules];
59
- }
60
88
  get livereload() {
61
89
  const { host = this.config("http.host"), port = p.uint.port().parse(this.config("http.port") - 1), } = this.config("livereload");
62
90
  return { host, port };
@@ -1,7 +1,11 @@
1
- declare const _default: import("pema").ObjectType<{
2
- mode: import("pema").UnionType<[import("pema").LiteralType<"production">, import("pema").LiteralType<"development">, import("pema").LiteralType<"testing">]>;
3
- target: import("pema").DefaultType<import("pema").StringType, "web">;
4
- dir: import("pema").DefaultType<import("pema").StringType, "build">;
1
+ declare const _default: import("pema").ObjectType<import("pema").NormalizeSchemaObject<{
2
+ readonly mode: import("pema").UnionType<[import("pema").LiteralType<"production">, import("pema").LiteralType<"development">, import("pema").LiteralType<"testing">]>;
3
+ readonly target: import("pema").DefaultType<import("pema").StringType, "web">;
4
+ readonly dir: import("pema").DefaultType<import("pema").StringType, "build">;
5
+ }>, {
6
+ mode: "development" | "production" | "testing";
7
+ target: string;
8
+ dir: string;
5
9
  }>;
6
10
  export default _default;
7
11
  //# sourceMappingURL=Flags.d.ts.map
@@ -1,18 +1,6 @@
1
- import type App from "#App";
2
- import type BuildApp from "#build/App";
3
- import type Next from "#module/Next";
4
- import type NextBuild from "#module/NextBuild";
5
- import type NextHandle from "#module/NextHandle";
6
- import type NextRoute from "#module/NextRoute";
7
- import type NextServe from "#module/NextServe";
8
- import type RequestFacade from "#request/RequestFacade";
9
- import type ServeApp from "#serve/App";
10
- export default abstract class Module {
11
- abstract get name(): string;
12
- init<T extends App>(app: T, next: Next<T>): import("@rcompat/type").MaybePromise<T>;
13
- build(app: BuildApp, next: NextBuild): import("@rcompat/type").MaybePromise<BuildApp>;
14
- serve(app: ServeApp, next: NextServe): import("@rcompat/type").MaybePromise<ServeApp>;
15
- handle(request: RequestFacade, next: NextHandle): import("@rcompat/type").MaybePromise<Response>;
16
- route(request: RequestFacade, next: NextRoute): import("@rcompat/type").MaybePromise<import("./response/ResponseLike.js").default>;
1
+ import type Setup from "#module/Setup";
2
+ export default interface Module {
3
+ name: string;
4
+ setup(setup: Setup): void;
17
5
  }
18
6
  //# sourceMappingURL=Module.d.ts.map
@@ -1,18 +1,2 @@
1
- export default class Module {
2
- init(app, next) {
3
- return next(app);
4
- }
5
- build(app, next) {
6
- return next(app);
7
- }
8
- serve(app, next) {
9
- return next(app);
10
- }
11
- handle(request, next) {
12
- return next(request);
13
- }
14
- route(request, next) {
15
- return next(request);
16
- }
17
- }
1
+ export {};
18
2
  //# sourceMappingURL=Module.js.map
@@ -0,0 +1,5 @@
1
+ import type { Dict } from "@rcompat/type";
2
+ import type { Parsed } from "pema";
3
+ type EnvSchema = Dict<Parsed<unknown>>;
4
+ export type { EnvSchema as default };
5
+ //# sourceMappingURL=EnvSchema.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=EnvSchema.js.map
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,19 @@
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