@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,10 +1,12 @@
1
+ import type EnvSchema from "#app/EnvSchema";
2
+ import type ServerView from "#client/ServerView";
1
3
  import type Config from "#config/Config";
2
- import type ServerView from "#frontend/ServerView";
3
4
  import type ServeApp from "#serve/App";
5
+ import type { ObjectType } from "pema";
4
6
  declare const s_attach: unique symbol;
5
7
  declare const s_config: unique symbol;
6
8
  export { s_attach, s_config };
7
- export default class AppFacade {
9
+ export default class AppFacade<T extends EnvSchema = EnvSchema> {
8
10
  #private;
9
11
  constructor(config: Config);
10
12
  [s_attach](app: ServeApp): void;
@@ -27,14 +29,25 @@ export default class AppFacade {
27
29
  host: string | undefined;
28
30
  port: number | undefined;
29
31
  };
30
- modules: import("../Module.js").default[] | undefined;
32
+ db: {
33
+ migrations: {
34
+ table: string;
35
+ db: import("../db/DB.js").default;
36
+ } | undefined;
37
+ };
38
+ env: {
39
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
40
+ [x: string]: unknown;
41
+ }> | undefined;
42
+ };
43
+ modules: import("../Module.js").default[];
31
44
  request: {
32
45
  body: {
33
46
  parse: boolean;
34
47
  };
35
48
  };
36
49
  };
37
- 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<{
50
+ 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<{
38
51
  http: {
39
52
  csp: Record<string, string[]> | undefined;
40
53
  headers: Record<string, string> | undefined;
@@ -53,7 +66,18 @@ export default class AppFacade {
53
66
  host: string | undefined;
54
67
  port: number | undefined;
55
68
  };
56
- modules: import("../Module.js").default[] | undefined;
69
+ db: {
70
+ migrations: {
71
+ table: string;
72
+ db: import("../db/DB.js").default;
73
+ } | undefined;
74
+ };
75
+ env: {
76
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
77
+ [x: string]: unknown;
78
+ }> | undefined;
79
+ };
80
+ modules: import("../Module.js").default[];
57
81
  request: {
58
82
  body: {
59
83
  parse: boolean;
@@ -78,7 +102,18 @@ export default class AppFacade {
78
102
  host: string | undefined;
79
103
  port: number | undefined;
80
104
  };
81
- modules: import("../Module.js").default[] | undefined;
105
+ db: {
106
+ migrations: {
107
+ table: string;
108
+ db: import("../db/DB.js").default;
109
+ } | undefined;
110
+ };
111
+ env: {
112
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
113
+ [x: string]: unknown;
114
+ }> | undefined;
115
+ };
116
+ modules: import("../Module.js").default[];
82
117
  request: {
83
118
  body: {
84
119
  parse: boolean;
@@ -103,7 +138,18 @@ export default class AppFacade {
103
138
  host: string | undefined;
104
139
  port: number | undefined;
105
140
  };
106
- modules: import("../Module.js").default[] | undefined;
141
+ db: {
142
+ migrations: {
143
+ table: string;
144
+ db: import("../db/DB.js").default;
145
+ } | undefined;
146
+ };
147
+ env: {
148
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
149
+ [x: string]: unknown;
150
+ }> | undefined;
151
+ };
152
+ modules: import("../Module.js").default[];
107
153
  request: {
108
154
  body: {
109
155
  parse: boolean;
@@ -128,7 +174,18 @@ export default class AppFacade {
128
174
  host: string | undefined;
129
175
  port: number | undefined;
130
176
  };
131
- modules: import("../Module.js").default[] | undefined;
177
+ db: {
178
+ migrations: {
179
+ table: string;
180
+ db: import("../db/DB.js").default;
181
+ } | undefined;
182
+ };
183
+ env: {
184
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
185
+ [x: string]: unknown;
186
+ }> | undefined;
187
+ };
188
+ modules: import("../Module.js").default[];
132
189
  request: {
133
190
  body: {
134
191
  parse: boolean;
@@ -153,7 +210,18 @@ export default class AppFacade {
153
210
  host: string | undefined;
154
211
  port: number | undefined;
155
212
  };
156
- modules: import("../Module.js").default[] | undefined;
213
+ db: {
214
+ migrations: {
215
+ table: string;
216
+ db: import("../db/DB.js").default;
217
+ } | undefined;
218
+ };
219
+ env: {
220
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
221
+ [x: string]: unknown;
222
+ }> | undefined;
223
+ };
224
+ modules: import("../Module.js").default[];
157
225
  request: {
158
226
  body: {
159
227
  parse: boolean;
@@ -178,7 +246,18 @@ export default class AppFacade {
178
246
  host: string | undefined;
179
247
  port: number | undefined;
180
248
  };
181
- modules: import("../Module.js").default[] | undefined;
249
+ db: {
250
+ migrations: {
251
+ table: string;
252
+ db: import("../db/DB.js").default;
253
+ } | undefined;
254
+ };
255
+ env: {
256
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
257
+ [x: string]: unknown;
258
+ }> | undefined;
259
+ };
260
+ modules: import("../Module.js").default[];
182
261
  request: {
183
262
  body: {
184
263
  parse: boolean;
@@ -203,7 +282,18 @@ export default class AppFacade {
203
282
  host: string | undefined;
204
283
  port: number | undefined;
205
284
  };
206
- modules: import("../Module.js").default[] | undefined;
285
+ db: {
286
+ migrations: {
287
+ table: string;
288
+ db: import("../db/DB.js").default;
289
+ } | undefined;
290
+ };
291
+ env: {
292
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
293
+ [x: string]: unknown;
294
+ }> | undefined;
295
+ };
296
+ modules: import("../Module.js").default[];
207
297
  request: {
208
298
  body: {
209
299
  parse: boolean;
@@ -228,7 +318,18 @@ export default class AppFacade {
228
318
  host: string | undefined;
229
319
  port: number | undefined;
230
320
  };
231
- modules: import("../Module.js").default[] | undefined;
321
+ db: {
322
+ migrations: {
323
+ table: string;
324
+ db: import("../db/DB.js").default;
325
+ } | undefined;
326
+ };
327
+ env: {
328
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
329
+ [x: string]: unknown;
330
+ }> | undefined;
331
+ };
332
+ modules: import("../Module.js").default[];
232
333
  request: {
233
334
  body: {
234
335
  parse: boolean;
@@ -253,7 +354,18 @@ export default class AppFacade {
253
354
  host: string | undefined;
254
355
  port: number | undefined;
255
356
  };
256
- modules: import("../Module.js").default[] | undefined;
357
+ db: {
358
+ migrations: {
359
+ table: string;
360
+ db: import("../db/DB.js").default;
361
+ } | undefined;
362
+ };
363
+ env: {
364
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
365
+ [x: string]: unknown;
366
+ }> | undefined;
367
+ };
368
+ modules: import("../Module.js").default[];
257
369
  request: {
258
370
  body: {
259
371
  parse: boolean;
@@ -278,7 +390,18 @@ export default class AppFacade {
278
390
  host: string | undefined;
279
391
  port: number | undefined;
280
392
  };
281
- modules: import("../Module.js").default[] | undefined;
393
+ db: {
394
+ migrations: {
395
+ table: string;
396
+ db: import("../db/DB.js").default;
397
+ } | undefined;
398
+ };
399
+ env: {
400
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
401
+ [x: string]: unknown;
402
+ }> | undefined;
403
+ };
404
+ modules: import("../Module.js").default[];
282
405
  request: {
283
406
  body: {
284
407
  parse: boolean;
@@ -303,7 +426,18 @@ export default class AppFacade {
303
426
  host: string | undefined;
304
427
  port: number | undefined;
305
428
  };
306
- modules: import("../Module.js").default[] | undefined;
429
+ db: {
430
+ migrations: {
431
+ table: string;
432
+ db: import("../db/DB.js").default;
433
+ } | undefined;
434
+ };
435
+ env: {
436
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
437
+ [x: string]: unknown;
438
+ }> | undefined;
439
+ };
440
+ modules: import("../Module.js").default[];
307
441
  request: {
308
442
  body: {
309
443
  parse: boolean;
@@ -328,7 +462,18 @@ export default class AppFacade {
328
462
  host: string | undefined;
329
463
  port: number | undefined;
330
464
  };
331
- modules: import("../Module.js").default[] | undefined;
465
+ db: {
466
+ migrations: {
467
+ table: string;
468
+ db: import("../db/DB.js").default;
469
+ } | undefined;
470
+ };
471
+ env: {
472
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
473
+ [x: string]: unknown;
474
+ }> | undefined;
475
+ };
476
+ modules: import("../Module.js").default[];
332
477
  request: {
333
478
  body: {
334
479
  parse: boolean;
@@ -353,7 +498,18 @@ export default class AppFacade {
353
498
  host: string | undefined;
354
499
  port: number | undefined;
355
500
  };
356
- modules: import("../Module.js").default[] | undefined;
501
+ db: {
502
+ migrations: {
503
+ table: string;
504
+ db: import("../db/DB.js").default;
505
+ } | undefined;
506
+ };
507
+ env: {
508
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
509
+ [x: string]: unknown;
510
+ }> | undefined;
511
+ };
512
+ modules: import("../Module.js").default[];
357
513
  request: {
358
514
  body: {
359
515
  parse: boolean;
@@ -378,7 +534,18 @@ export default class AppFacade {
378
534
  host: string | undefined;
379
535
  port: number | undefined;
380
536
  };
381
- modules: import("../Module.js").default[] | undefined;
537
+ db: {
538
+ migrations: {
539
+ table: string;
540
+ db: import("../db/DB.js").default;
541
+ } | undefined;
542
+ };
543
+ env: {
544
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
545
+ [x: string]: unknown;
546
+ }> | undefined;
547
+ };
548
+ modules: import("../Module.js").default[];
382
549
  request: {
383
550
  body: {
384
551
  parse: boolean;
@@ -403,7 +570,18 @@ export default class AppFacade {
403
570
  host: string | undefined;
404
571
  port: number | undefined;
405
572
  };
406
- modules: import("../Module.js").default[] | undefined;
573
+ db: {
574
+ migrations: {
575
+ table: string;
576
+ db: import("../db/DB.js").default;
577
+ } | undefined;
578
+ };
579
+ env: {
580
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
581
+ [x: string]: unknown;
582
+ }> | undefined;
583
+ };
584
+ modules: import("../Module.js").default[];
407
585
  request: {
408
586
  body: {
409
587
  parse: boolean;
@@ -428,7 +606,18 @@ export default class AppFacade {
428
606
  host: string | undefined;
429
607
  port: number | undefined;
430
608
  };
431
- modules: import("../Module.js").default[] | undefined;
609
+ db: {
610
+ migrations: {
611
+ table: string;
612
+ db: import("../db/DB.js").default;
613
+ } | undefined;
614
+ };
615
+ env: {
616
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
617
+ [x: string]: unknown;
618
+ }> | undefined;
619
+ };
620
+ modules: import("../Module.js").default[];
432
621
  request: {
433
622
  body: {
434
623
  parse: boolean;
@@ -453,7 +642,18 @@ export default class AppFacade {
453
642
  host: string | undefined;
454
643
  port: number | undefined;
455
644
  };
456
- modules: import("../Module.js").default[] | undefined;
645
+ db: {
646
+ migrations: {
647
+ table: string;
648
+ db: import("../db/DB.js").default;
649
+ } | undefined;
650
+ };
651
+ env: {
652
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
653
+ [x: string]: unknown;
654
+ }> | undefined;
655
+ };
656
+ modules: import("../Module.js").default[];
457
657
  request: {
458
658
  body: {
459
659
  parse: boolean;
@@ -478,7 +678,18 @@ export default class AppFacade {
478
678
  host: string | undefined;
479
679
  port: number | undefined;
480
680
  };
481
- modules: import("../Module.js").default[] | undefined;
681
+ db: {
682
+ migrations: {
683
+ table: string;
684
+ db: import("../db/DB.js").default;
685
+ } | undefined;
686
+ };
687
+ env: {
688
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
689
+ [x: string]: unknown;
690
+ }> | undefined;
691
+ };
692
+ modules: import("../Module.js").default[];
482
693
  request: {
483
694
  body: {
484
695
  parse: boolean;
@@ -503,7 +714,18 @@ export default class AppFacade {
503
714
  host: string | undefined;
504
715
  port: number | undefined;
505
716
  };
506
- modules: import("../Module.js").default[] | undefined;
717
+ db: {
718
+ migrations: {
719
+ table: string;
720
+ db: import("../db/DB.js").default;
721
+ } | undefined;
722
+ };
723
+ env: {
724
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
725
+ [x: string]: unknown;
726
+ }> | undefined;
727
+ };
728
+ modules: import("../Module.js").default[];
507
729
  request: {
508
730
  body: {
509
731
  parse: boolean;
@@ -528,13 +750,24 @@ export default class AppFacade {
528
750
  host: string | undefined;
529
751
  port: number | undefined;
530
752
  };
531
- modules: import("../Module.js").default[] | undefined;
753
+ db: {
754
+ migrations: {
755
+ table: string;
756
+ db: import("../db/DB.js").default;
757
+ } | undefined;
758
+ };
759
+ env: {
760
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
761
+ [x: string]: unknown;
762
+ }> | undefined;
763
+ };
764
+ modules: import("../Module.js").default[];
532
765
  request: {
533
766
  body: {
534
767
  parse: boolean;
535
768
  };
536
769
  };
537
- }[P1] & undefined) : undefined : P extends "http" | "livereload" | "request" | "modules" ? {
770
+ }[P1] & undefined) : undefined : P extends "http" | "livereload" | "db" | "env" | "request" | "modules" ? {
538
771
  http: {
539
772
  csp: Record<string, string[]> | undefined;
540
773
  headers: Record<string, string> | undefined;
@@ -553,14 +786,26 @@ export default class AppFacade {
553
786
  host: string | undefined;
554
787
  port: number | undefined;
555
788
  };
556
- modules: import("../Module.js").default[] | undefined;
789
+ db: {
790
+ migrations: {
791
+ table: string;
792
+ db: import("../db/DB.js").default;
793
+ } | undefined;
794
+ };
795
+ env: {
796
+ schema: ObjectType<import("@rcompat/dict").Dict<import("pema").Parsed<unknown>>, {
797
+ [x: string]: unknown;
798
+ }> | undefined;
799
+ };
800
+ modules: import("../Module.js").default[];
557
801
  request: {
558
802
  body: {
559
803
  parse: boolean;
560
804
  };
561
805
  };
562
806
  }[P] : undefined;
563
- view<T = ServerView>(name: string): T;
807
+ env<K extends keyof T>(key: K): T[K]["infer"];
808
+ view<SV = ServerView>(name: string): SV;
564
809
  get root(): import("@rcompat/fs").FileRef;
565
810
  }
566
811
  //# sourceMappingURL=Facade.d.ts.map
@@ -1,15 +1,30 @@
1
+ import E from "#errors";
1
2
  import dict from "@rcompat/dict";
3
+ import env from "@rcompat/env";
4
+ import ParseError from "pema/ParseError";
2
5
  const s_attach = Symbol("attach");
3
6
  const s_config = Symbol("config");
4
7
  export { s_attach, s_config };
5
8
  export default class AppFacade {
6
9
  #config;
7
10
  #app;
11
+ #env;
8
12
  constructor(config) {
9
13
  this.#config = config;
10
14
  }
11
15
  [s_attach](app) {
12
16
  this.#app = app;
17
+ const schema = this.#config.env.schema;
18
+ if (schema !== undefined) {
19
+ try {
20
+ this.#env = schema.coerce(env.toJSON());
21
+ }
22
+ catch (error) {
23
+ if (ParseError.is(error))
24
+ throw E.env_invalid_schema(error);
25
+ throw error;
26
+ }
27
+ }
13
28
  }
14
29
  get [s_config]() {
15
30
  return this.#config;
@@ -17,6 +32,14 @@ export default class AppFacade {
17
32
  config(path) {
18
33
  return dict.get(this.#config, path);
19
34
  }
35
+ env(key) {
36
+ if (this.#env !== undefined) {
37
+ if (!(key in this.#env))
38
+ throw E.env_missing_key(key);
39
+ return this.#env[key];
40
+ }
41
+ return env.get(key);
42
+ }
20
43
  get #with() {
21
44
  if (!this.#app)
22
45
  throw new Error("ServeApp not bound yet (used too early)");
@@ -2,6 +2,8 @@ import plugin_alias from "#build/client/plugin/alias";
2
2
  import plugin_entrypoint from "#build/client/plugin/entrypoint";
3
3
  import plugin_frontend from "#build/client/plugin/frontend";
4
4
  import plugin_server_stamp from "#build/client/plugin/server-stamp";
5
+ import plugin_view from "#build/client/plugin/view";
6
+ import plugin_app_request from "#build/shared/plugin/app-request";
5
7
  import location from "#location";
6
8
  import * as esbuild from "esbuild";
7
9
  const write_bootstrap = async (app, mode) => {
@@ -34,8 +36,8 @@ const write_bootstrap = async (app, mode) => {
34
36
  views,
35
37
  pages,
36
38
  mode: "${mode}",
37
- session_config,
38
- i18n_config,
39
+ session: session_config,
40
+ i18n: i18n_config,
39
41
  target: "${app.target.name}",
40
42
  });
41
43
 
@@ -46,6 +48,8 @@ const write_bootstrap = async (app, mode) => {
46
48
  export default async function build_client(app) {
47
49
  app.plugin("client", plugin_frontend(app));
48
50
  app.plugin("client", plugin_alias(app));
51
+ app.plugin("client", plugin_view(app));
52
+ app.plugin("client", plugin_app_request(app));
49
53
  app.plugin("client", plugin_server_stamp(app));
50
54
  app.plugin("client", plugin_entrypoint(app));
51
55
  const imports = await app.path.static.files({
@@ -57,6 +61,7 @@ export default async function build_client(app) {
57
61
  app.entrypoint(`import "./${location.static}${src}";`);
58
62
  });
59
63
  app.entrypoint("import \"primate/client/app\";");
64
+ const tsconfig = app.root.join("tsconfig.json");
60
65
  const conditions = app.conditions.values();
61
66
  const build_options = {
62
67
  plugins: app.plugins("client"),
@@ -64,7 +69,7 @@ export default async function build_client(app) {
64
69
  entryPoints: ["app:client"],
65
70
  conditions: ["style", "browser", "default", "module", ...conditions],
66
71
  resolveExtensions: [".ts", ".js", ...app.frontendExtensions],
67
- tsconfig: app.root.join("tsconfig.json").path,
72
+ ...await tsconfig.exists() ? { tsconfig: tsconfig.path } : {},
68
73
  bundle: true,
69
74
  format: "esm",
70
75
  };
@@ -0,0 +1,4 @@
1
+ import type BuildApp from "#build/App";
2
+ import type { Plugin } from "esbuild";
3
+ export default function plugin_client_request(app: BuildApp): Plugin;
4
+ //# sourceMappingURL=app-request.d.ts.map
@@ -0,0 +1,19 @@
1
+ export default function plugin_client_request(app) {
2
+ return {
3
+ name: "primate/client/app/request",
4
+ setup(build) {
5
+ build.onResolve({ filter: /^app:request$/ }, ({ importer }) => {
6
+ const frontend = [...app.frontends.entries()]
7
+ .find(([, exts]) => exts.some(ext => importer.endsWith(ext)));
8
+ return frontend !== undefined
9
+ ? { namespace: "request", path: frontend[0] }
10
+ : undefined;
11
+ });
12
+ build.onLoad({ filter: /.*/, namespace: "request" }, async ({ path }) => {
13
+ const contents = `export { default } from "@primate/${path}/request";`;
14
+ return { contents, resolveDir: app.root.path };
15
+ });
16
+ },
17
+ };
18
+ }
19
+ //# sourceMappingURL=app-request.js.map
@@ -0,0 +1,4 @@
1
+ import type BuildApp from "#build/App";
2
+ import type { Plugin } from "esbuild";
3
+ export default function plugin_client_view(app: BuildApp): Plugin;
4
+ //# sourceMappingURL=view.d.ts.map
@@ -0,0 +1,13 @@
1
+ import location from "#location";
2
+ export default function plugin_client_view(app) {
3
+ return {
4
+ name: "primate/client/view",
5
+ setup(build) {
6
+ build.onResolve({ filter: /^view:/ }, args => {
7
+ const name = args.path.slice("view:".length);
8
+ return { path: app.root.join(location.views, name).path };
9
+ });
10
+ },
11
+ };
12
+ }
13
+ //# sourceMappingURL=view.js.map
@@ -1,4 +1,3 @@
1
1
  import type BuildApp from "#build/App";
2
- declare const _default: (app: BuildApp) => Promise<BuildApp>;
3
- export default _default;
2
+ export default function run_build_hooks(app: BuildApp): Promise<BuildApp>;
4
3
  //# sourceMappingURL=hook.d.ts.map
@@ -1,9 +1,8 @@
1
1
  import build_client from "#build/client/index";
2
2
  import build_server from "#build/server/index";
3
- import fail from "#fail";
3
+ import E from "#errors";
4
4
  import location from "#location";
5
5
  import log from "#log";
6
- import reducer from "#reducer";
7
6
  import $router from "#request/router";
8
7
  import s_layout_depth from "#symbol/layout-depth";
9
8
  import c from "@rcompat/cli/color";
@@ -11,22 +10,16 @@ import fs from "@rcompat/fs";
11
10
  const core_pkg = await fs.project.package(import.meta.dirname);
12
11
  const { version } = await core_pkg.json();
13
12
  async function pre(app) {
14
- const dot_primate = app.path.build.join(".primate");
15
- if (await app.path.build.exists() && !await dot_primate.exists()) {
16
- const message = "{0} exists but does not contain a previous build";
17
- throw fail(message, app.path.build.path);
13
+ const build_json = app.path.build.join("build.json");
14
+ const build_path = app.path.build;
15
+ if (await build_path.exists() && !await build_json.exists()) {
16
+ throw E.build_previous_build_exists(build_path);
18
17
  }
19
- // remove build directory if exists
20
18
  await app.path.build.remove();
21
19
  await app.path.build.create();
22
- // touch a .primate file to indicate this is a Primate build directory
23
- await dot_primate.write(version);
24
20
  await app.runpath(location.client).create();
25
21
  const stamp = app.runpath("client", "server-stamp.js");
26
22
  await stamp.write("export default 0;\n");
27
- // this has to occur before post, so that layout depth is available for
28
- // compiling root views
29
- // bindings should have been registered during `init`
30
23
  const router = await $router(app.path.routes, app.extensions);
31
24
  app.set(s_layout_depth, router.depth("layout"));
32
25
  const i18n_ts = app.path.config.join("i18n.ts");
@@ -35,16 +28,28 @@ async function pre(app) {
35
28
  const session_ts = app.path.config.join("session.ts");
36
29
  const session_js = app.path.config.join("session.js");
37
30
  app.session_active = await session_ts.exists() || await session_js.exists();
38
- return app;
39
31
  }
40
- ;
41
32
  async function post(app) {
42
33
  await build_client(app);
43
34
  await build_server(app);
35
+ // write build.json with version and migration_version
36
+ const migrations_dir = app.root.join("migrations");
37
+ let migration_version = 0;
38
+ if (await migrations_dir.exists()) {
39
+ const files = await migrations_dir.files({ filter: /\d+-.*\.[jt]s$/ });
40
+ migration_version = files.length === 0 ? 0 : Math.max(...files.map(f => parseInt(f.name.split("-")[0])));
41
+ }
42
+ await app.path.build.join("build.json").writeJSON({
43
+ version,
44
+ migration_version,
45
+ });
44
46
  log.print(`✓ build path ${c.dim(app.path.build.path)}\n`);
45
47
  app.cleanup();
46
48
  return app;
47
49
  }
48
- ;
49
- export default async (app) => post(await reducer(app.modules, await pre(app), "build"));
50
+ export default async function run_build_hooks(app) {
51
+ await pre(app);
52
+ await app.build_hooks(app);
53
+ return post(app);
54
+ }
50
55
  //# sourceMappingURL=hook.js.map