very-express 0.10.2 → 0.11.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.

Potentially problematic release.


This version of very-express might be problematic. Click here for more details.

Files changed (266) hide show
  1. package/.tmp/_body.txt +1 -0
  2. package/.tmp/_idx.txt +1 -0
  3. package/.tmp/_token.txt +1 -0
  4. package/.tmp/check-a/app/.vex/meta.json +216 -0
  5. package/.tmp/check-a/app/Dockerfile +20 -0
  6. package/.tmp/check-a/app/README.md +39 -0
  7. package/.tmp/check-a/app/public/css/style.css +8 -0
  8. package/.tmp/check-a/app/public/js/deleteaccount.js +80 -0
  9. package/.tmp/check-a/app/public/js/login.js +59 -0
  10. package/.tmp/check-a/app/public/js/logincallback.js +19 -0
  11. package/.tmp/check-a/app/public/js/mytokens.js +11 -0
  12. package/.tmp/check-a/app/public/js/refreshtokens.js +23 -0
  13. package/.tmp/check-a/app/scripts/build.js +39 -0
  14. package/.tmp/check-a/app/scripts/oacg-fix.js +83 -0
  15. package/.tmp/check-a/app/tsconfig.json +30 -0
  16. package/.tmp/check-a/schemas/Project.json +41 -0
  17. package/.tmp/check-a/schemas/Session.json +49 -0
  18. package/.tmp/check-a/schemas/UserAuthProfiles.json +54 -0
  19. package/.tmp/check-a/vex.config.json +26 -0
  20. package/.tmp/check-b/app/.env +41 -0
  21. package/.tmp/check-b/app/.vex/meta.json +219 -0
  22. package/.tmp/check-b/app/Dockerfile +20 -0
  23. package/.tmp/check-b/app/README.md +39 -0
  24. package/.tmp/check-b/app/package.json +51 -0
  25. package/.tmp/check-b/app/public/css/style.css +8 -0
  26. package/.tmp/check-b/app/public/js/deleteaccount.js +80 -0
  27. package/.tmp/check-b/app/public/js/login.js +59 -0
  28. package/.tmp/check-b/app/public/js/logincallback.js +19 -0
  29. package/.tmp/check-b/app/public/js/mytokens.js +11 -0
  30. package/.tmp/check-b/app/public/js/refreshtokens.js +23 -0
  31. package/.tmp/check-b/app/scripts/build.js +39 -0
  32. package/.tmp/check-b/app/scripts/oacg-fix.js +83 -0
  33. package/.tmp/check-b/app/tsconfig.json +30 -0
  34. package/.tmp/check-b/app/tsoa.json +32 -0
  35. package/.tmp/check-b/schemas/Project.json +41 -0
  36. package/.tmp/check-b/vex.config.json +30 -0
  37. package/.tmp/check-c/app/.env +41 -0
  38. package/.tmp/check-c/app/.vex/meta.json +231 -0
  39. package/.tmp/check-c/app/Dockerfile +20 -0
  40. package/.tmp/check-c/app/README.md +39 -0
  41. package/.tmp/check-c/app/package.json +51 -0
  42. package/.tmp/check-c/app/public/css/style.css +8 -0
  43. package/.tmp/check-c/app/public/js/deleteaccount.js +80 -0
  44. package/.tmp/check-c/app/public/js/login.js +59 -0
  45. package/.tmp/check-c/app/public/js/logincallback.js +19 -0
  46. package/.tmp/check-c/app/public/js/mytokens.js +11 -0
  47. package/.tmp/check-c/app/public/js/refreshtokens.js +23 -0
  48. package/.tmp/check-c/app/scripts/build.js +39 -0
  49. package/.tmp/check-c/app/scripts/oacg-fix.js +83 -0
  50. package/.tmp/check-c/app/tsconfig.json +30 -0
  51. package/.tmp/check-c/app/tsoa.json +32 -0
  52. package/.tmp/check-c/schemas/Project.json +41 -0
  53. package/.tmp/check-c/schemas/User.json +81 -0
  54. package/.tmp/check-c/vex.config.json +30 -0
  55. package/.tmp/demo-project/vex.config.json +43 -0
  56. package/.tmp/demo-project2/vex.config.json +43 -0
  57. package/.tmp/demo-schemas/Client.json +65 -0
  58. package/.tmp/demo-schemas/FnbOrder.json +33 -0
  59. package/.tmp/demo-schemas/Job.json +86 -0
  60. package/.tmp/demo-schemas/KernelEvent.json +29 -0
  61. package/.tmp/demo-schemas/Package.json +77 -0
  62. package/.tmp/demo-schemas/Session.json +49 -0
  63. package/.tmp/demo-schemas/Tenant.json +22 -0
  64. package/.tmp/demo-schemas/User.json +81 -0
  65. package/.tmp/demo-schemas/UserAuthProfiles.json +54 -0
  66. package/.tmp/demo-schemas/UserContact.json +76 -0
  67. package/.tmp/demo-schemas/UserRole.json +40 -0
  68. package/.tmp/demo-schemas/UserTenant.json +39 -0
  69. package/.tmp/demo-schemas2/Client.json +65 -0
  70. package/.tmp/demo-schemas2/FnbOrder.json +33 -0
  71. package/.tmp/demo-schemas2/Job.json +86 -0
  72. package/.tmp/demo-schemas2/KernelEvent.json +29 -0
  73. package/.tmp/demo-schemas2/Package.json +77 -0
  74. package/.tmp/demo-schemas2/Session.json +49 -0
  75. package/.tmp/demo-schemas2/Tenant.json +22 -0
  76. package/.tmp/demo-schemas2/User.json +81 -0
  77. package/.tmp/demo-schemas2/UserAuthProfiles.json +54 -0
  78. package/.tmp/demo-schemas2/UserContact.json +76 -0
  79. package/.tmp/demo-schemas2/UserRole.json +40 -0
  80. package/.tmp/demo-schemas2/UserTenant.json +39 -0
  81. package/.tmp/e2e-db.url +1 -0
  82. package/.tmp/nouser/out/.env +41 -0
  83. package/.tmp/nouser/out/.vex/meta.json +323 -0
  84. package/.tmp/nouser/out/Dockerfile +20 -0
  85. package/.tmp/nouser/out/README.md +39 -0
  86. package/.tmp/nouser/out/package.json +51 -0
  87. package/.tmp/nouser/out/public/css/style.css +8 -0
  88. package/.tmp/nouser/out/public/js/deleteaccount.js +80 -0
  89. package/.tmp/nouser/out/public/js/login.js +59 -0
  90. package/.tmp/nouser/out/public/js/logincallback.js +19 -0
  91. package/.tmp/nouser/out/public/js/mytokens.js +11 -0
  92. package/.tmp/nouser/out/public/js/refreshtokens.js +23 -0
  93. package/.tmp/nouser/out/scripts/build.js +39 -0
  94. package/.tmp/nouser/out/scripts/oacg-fix.js +83 -0
  95. package/.tmp/nouser/out/tsconfig.json +30 -0
  96. package/.tmp/nouser/out/tsoa.json +32 -0
  97. package/.tmp/nouser/schemas/Project.json +41 -0
  98. package/.tmp/nouser/schemas/Session.json +49 -0
  99. package/.tmp/nouser/schemas/User.json +81 -0
  100. package/.tmp/nouser/schemas/UserAuthProfiles.json +54 -0
  101. package/.tmp/nouser/schemas/UserTenant.json +39 -0
  102. package/.tmp/nouser/vex.config.json +34 -0
  103. package/.tmp/npm-test-after-fix.log +217 -0
  104. package/.tmp/npm-test-final.log +165 -0
  105. package/.tmp/npm-test-final2.log +163 -0
  106. package/.tmp/npm-test-recheck.log +192 -0
  107. package/.tmp/npm-test-update.log +164 -0
  108. package/.tmp/npm-test.log +166 -0
  109. package/.tmp/output-build-after-fix.log +8 -0
  110. package/.tmp/output-build-baseline.log +8 -0
  111. package/.tmp/output-build-canonical.log +8 -0
  112. package/.tmp/output-build-final2.log +8 -0
  113. package/.tmp/output-build-reapply.log +8 -0
  114. package/.tmp/output-build.log +8 -0
  115. package/.tmp/output.env.bak +34 -0
  116. package/.tmp/probe_body.txt +1 -0
  117. package/.tmp/provision-e2e-db.js +41 -0
  118. package/.tmp/retry-nodestroy.log +18 -0
  119. package/.tmp/retry-recovery-final2.log +8 -0
  120. package/.tmp/retry-recovery-reapply.log +8 -0
  121. package/.tmp/retry-recovery.js +38 -0
  122. package/.tmp/run-e2e-single.js +21 -0
  123. package/.tmp/run-e2e.js +18 -0
  124. package/.tmp/verify-noauth/app/.env +41 -0
  125. package/.tmp/verify-noauth/app/.vex/meta.json +333 -0
  126. package/.tmp/verify-noauth/app/Dockerfile +20 -0
  127. package/.tmp/verify-noauth/app/README.md +39 -0
  128. package/.tmp/verify-noauth/app/package.json +51 -0
  129. package/.tmp/verify-noauth/app/public/css/style.css +8 -0
  130. package/.tmp/verify-noauth/app/public/js/deleteaccount.js +80 -0
  131. package/.tmp/verify-noauth/app/public/js/login.js +59 -0
  132. package/.tmp/verify-noauth/app/public/js/logincallback.js +19 -0
  133. package/.tmp/verify-noauth/app/public/js/mytokens.js +11 -0
  134. package/.tmp/verify-noauth/app/public/js/refreshtokens.js +23 -0
  135. package/.tmp/verify-noauth/app/scripts/build.js +39 -0
  136. package/.tmp/verify-noauth/app/scripts/oacg-fix.js +83 -0
  137. package/.tmp/verify-noauth/app/tsconfig.json +30 -0
  138. package/.tmp/verify-noauth/app/tsoa.json +32 -0
  139. package/.tmp/verify-noauth/schemas/Project.json +41 -0
  140. package/.tmp/verify-noauth/schemas/Session.json +49 -0
  141. package/.tmp/verify-noauth/schemas/User.json +81 -0
  142. package/.tmp/verify-noauth/schemas/UserAuthProfiles.json +54 -0
  143. package/.tmp/verify-noauth/schemas/UserTenant.json +39 -0
  144. package/.tmp/verify-noauth/vex.config.json +33 -0
  145. package/.tmp/verify-noauth-rbac/app/.env +41 -0
  146. package/.tmp/verify-noauth-rbac/app/.vex/meta.json +273 -0
  147. package/.tmp/verify-noauth-rbac/app/Dockerfile +20 -0
  148. package/.tmp/verify-noauth-rbac/app/README.md +39 -0
  149. package/.tmp/verify-noauth-rbac/app/package.json +51 -0
  150. package/.tmp/verify-noauth-rbac/app/public/css/style.css +8 -0
  151. package/.tmp/verify-noauth-rbac/app/public/js/deleteaccount.js +80 -0
  152. package/.tmp/verify-noauth-rbac/app/public/js/login.js +59 -0
  153. package/.tmp/verify-noauth-rbac/app/public/js/logincallback.js +19 -0
  154. package/.tmp/verify-noauth-rbac/app/public/js/mytokens.js +11 -0
  155. package/.tmp/verify-noauth-rbac/app/public/js/refreshtokens.js +23 -0
  156. package/.tmp/verify-noauth-rbac/app/scripts/build.js +39 -0
  157. package/.tmp/verify-noauth-rbac/app/scripts/oacg-fix.js +83 -0
  158. package/.tmp/verify-noauth-rbac/app/tsconfig.json +30 -0
  159. package/.tmp/verify-noauth-rbac/app/tsoa.json +32 -0
  160. package/.tmp/verify-noauth-rbac/schemas/Project.json +41 -0
  161. package/.tmp/verify-noauth-rbac/schemas/User.json +81 -0
  162. package/.tmp/verify-noauth-rbac/schemas/UserRole.json +38 -0
  163. package/.tmp/verify-noauth-rbac/vex.config.json +36 -0
  164. package/.tmp/verify.sh +103 -0
  165. package/.tmp/verify2.sh +103 -0
  166. package/.tmp/vex-gen-after-fix.log +221 -0
  167. package/.tmp/vex-gen-baseline.log +221 -0
  168. package/.tmp/vex-gen-canonical.log +221 -0
  169. package/.tmp/vex-gen-final.log +220 -0
  170. package/.tmp/vex-gen-final2.log +221 -0
  171. package/.tmp/vex-gen-reapply.log +221 -0
  172. package/.tmp/vex-gen.log +220 -0
  173. package/.tmp/vex-run-after-fix.log +3 -0
  174. package/.tmp/vex-run-baseline.log +11 -0
  175. package/.tmp/vex-run-before-fix.log +11 -0
  176. package/.tmp/vex-run-canonical.log +3 -0
  177. package/.tmp/vex-run-final2.log +3 -0
  178. package/.tmp/vex-run.log +3 -0
  179. package/.tmp/vo/app/.env +41 -0
  180. package/.tmp/vo/app/.vex/meta.json +231 -0
  181. package/.tmp/vo/app/Dockerfile +20 -0
  182. package/.tmp/vo/app/README.md +39 -0
  183. package/.tmp/vo/app/package.json +51 -0
  184. package/.tmp/vo/app/public/css/style.css +8 -0
  185. package/.tmp/vo/app/public/js/deleteaccount.js +80 -0
  186. package/.tmp/vo/app/public/js/login.js +59 -0
  187. package/.tmp/vo/app/public/js/logincallback.js +19 -0
  188. package/.tmp/vo/app/public/js/mytokens.js +11 -0
  189. package/.tmp/vo/app/public/js/refreshtokens.js +23 -0
  190. package/.tmp/vo/app/scripts/build.js +39 -0
  191. package/.tmp/vo/app/scripts/oacg-fix.js +83 -0
  192. package/.tmp/vo/app/tsconfig.json +30 -0
  193. package/.tmp/vo/app/tsoa.json +32 -0
  194. package/.tmp/vo/schemas/Project.json +41 -0
  195. package/.tmp/vo/vex.config.json +33 -0
  196. package/.tmp/vo-bad1/app/.env +41 -0
  197. package/.tmp/vo-bad1/app/.vex/meta.json +237 -0
  198. package/.tmp/vo-bad1/app/Dockerfile +20 -0
  199. package/.tmp/vo-bad1/app/README.md +39 -0
  200. package/.tmp/vo-bad1/app/package.json +51 -0
  201. package/.tmp/vo-bad1/app/public/css/style.css +8 -0
  202. package/.tmp/vo-bad1/app/public/js/deleteaccount.js +80 -0
  203. package/.tmp/vo-bad1/app/public/js/login.js +59 -0
  204. package/.tmp/vo-bad1/app/public/js/logincallback.js +19 -0
  205. package/.tmp/vo-bad1/app/public/js/mytokens.js +11 -0
  206. package/.tmp/vo-bad1/app/public/js/refreshtokens.js +23 -0
  207. package/.tmp/vo-bad1/app/scripts/build.js +39 -0
  208. package/.tmp/vo-bad1/app/scripts/oacg-fix.js +83 -0
  209. package/.tmp/vo-bad1/app/tsconfig.json +30 -0
  210. package/.tmp/vo-bad1/app/tsoa.json +32 -0
  211. package/.tmp/vo-bad1/schemas/Project.json +41 -0
  212. package/.tmp/vo-bad1/vex.config.json +33 -0
  213. package/.tmp/vo-bad2/app/.env +41 -0
  214. package/.tmp/vo-bad2/app/.vex/meta.json +237 -0
  215. package/.tmp/vo-bad2/app/Dockerfile +20 -0
  216. package/.tmp/vo-bad2/app/README.md +39 -0
  217. package/.tmp/vo-bad2/app/package.json +51 -0
  218. package/.tmp/vo-bad2/app/public/css/style.css +8 -0
  219. package/.tmp/vo-bad2/app/public/js/deleteaccount.js +80 -0
  220. package/.tmp/vo-bad2/app/public/js/login.js +59 -0
  221. package/.tmp/vo-bad2/app/public/js/logincallback.js +19 -0
  222. package/.tmp/vo-bad2/app/public/js/mytokens.js +11 -0
  223. package/.tmp/vo-bad2/app/public/js/refreshtokens.js +23 -0
  224. package/.tmp/vo-bad2/app/scripts/build.js +39 -0
  225. package/.tmp/vo-bad2/app/scripts/oacg-fix.js +83 -0
  226. package/.tmp/vo-bad2/app/tsconfig.json +30 -0
  227. package/.tmp/vo-bad2/app/tsoa.json +32 -0
  228. package/.tmp/vo-bad2/schemas/Project.json +41 -0
  229. package/.tmp/vo-bad2/vex.config.json +39 -0
  230. package/.tmp/vo-bad3/app/.env +41 -0
  231. package/.tmp/vo-bad3/app/.vex/meta.json +237 -0
  232. package/.tmp/vo-bad3/app/Dockerfile +20 -0
  233. package/.tmp/vo-bad3/app/README.md +39 -0
  234. package/.tmp/vo-bad3/app/package.json +51 -0
  235. package/.tmp/vo-bad3/app/public/css/style.css +8 -0
  236. package/.tmp/vo-bad3/app/public/js/deleteaccount.js +80 -0
  237. package/.tmp/vo-bad3/app/public/js/login.js +59 -0
  238. package/.tmp/vo-bad3/app/public/js/logincallback.js +19 -0
  239. package/.tmp/vo-bad3/app/public/js/mytokens.js +11 -0
  240. package/.tmp/vo-bad3/app/public/js/refreshtokens.js +23 -0
  241. package/.tmp/vo-bad3/app/scripts/build.js +39 -0
  242. package/.tmp/vo-bad3/app/scripts/oacg-fix.js +83 -0
  243. package/.tmp/vo-bad3/app/tsconfig.json +30 -0
  244. package/.tmp/vo-bad3/app/tsoa.json +32 -0
  245. package/.tmp/vo-bad3/schemas/Project.json +41 -0
  246. package/.tmp/vo-bad3/vex.config.json +33 -0
  247. package/dist/index.js +1156 -698
  248. package/dist/templates/_middlewares/UserContext.ts +1 -1
  249. package/dist/templates/_routes/FirebaseAuthUI.gen.ts +2 -2
  250. package/dist/templates/_routes/{LoginUI.ts → StarterUI.ts} +122 -8
  251. package/dist/templates/_utils/hash.ts +9 -4
  252. package/dist/templates/tenantJsonSchema/Tenant.json +22 -0
  253. package/docs/appGenerated/auth.md +50 -0
  254. package/docs/architecture/databaseTargets.md +23 -2
  255. package/docs/architecture/templates.md +7 -0
  256. package/docs/features/accountDeletion.md +5 -4
  257. package/docs/features/auditFields.md +2 -2
  258. package/docs/features/tenantIsolation.md +108 -15
  259. package/docs/releaseNote/v0-10-3.md +61 -0
  260. package/docs/releaseNote/v0-10-4.md +102 -0
  261. package/docs/releaseNote/v0-11-0.md +82 -0
  262. package/docs/vexJsonSchema.md +34 -1
  263. package/package.json +1 -1
  264. package/vex.config.json +6 -1
  265. package/dist/templates/_services/VexDbConnector.ts +0 -188
  266. package/dist/templates/_tenant/TenantScopeContext.ts +0 -56
@@ -0,0 +1,61 @@
1
+ # v0.10.3
2
+
3
+ ## Unique constraint names include the table
4
+
5
+ PostgreSQL requires a constraint name to be unique inside a schema, not inside one table. The
6
+ generated `@Unique` name carried the columns only:
7
+
8
+ ```ts
9
+ @Unique('unique_tenantId_code', ['tenantId', 'code'])
10
+ ```
11
+
12
+ Two documents declaring `"uniqueIndex": [["tenantId", "code"]]` therefore emitted the same
13
+ constraint name, and the app failed at startup with:
14
+
15
+ ```
16
+ relation "unique_tenantId_code" already exists
17
+ ```
18
+
19
+ The name now includes the table:
20
+
21
+ ```ts
22
+ @Entity("branch")
23
+ @Unique('unique_branch_tenantId_code', ['tenantId', 'code'])
24
+ ```
25
+
26
+ | Document | Table | Constraint |
27
+ | --- | --- | --- |
28
+ | `Branch` | `branch` | `unique_branch_tenantId_code` |
29
+ | `AdminRole` | `adminrole` | `unique_adminrole_tenantId_code` |
30
+
31
+ The table name is the one the entity already carries (`documentName.toLowerCase()`), so the
32
+ constraint stays stable when a document is renamed.
33
+
34
+ ## Migration
35
+
36
+ 1. Re-run the generator.
37
+ 2. A fresh database needs nothing else.
38
+ 3. An existing database keeps the old constraint names. TypeORM compares constraints by name, so
39
+ `SQL_SYNCHRONIZE=true` drops and recreates them on the next start. Without synchronize, rename
40
+ them by hand:
41
+
42
+ ```sql
43
+ ALTER TABLE "branch" RENAME CONSTRAINT "unique_tenantId_code" TO "unique_branch_tenantId_code";
44
+ ```
45
+
46
+ A database that already failed to start holds no table for the second document; create the table
47
+ after the rename.
48
+
49
+ ## Generated output
50
+
51
+ | File | Change |
52
+ | --- | --- |
53
+ | `_models/{Document}Model.gen.ts` | `@Unique` name now `unique_<table>_<columns>` |
54
+
55
+ Every SQL scenario's golden output changes.
56
+
57
+ ## Tests
58
+
59
+ `npm test` covers the new names across the golden scenarios. The collision itself is checked against
60
+ PostgreSQL: two generated entities that declare the same column set synchronize into one schema, and
61
+ a pair of hand-built entities with a shared constraint name reproduces the original error.
@@ -0,0 +1,102 @@
1
+ # v0.10.4
2
+
3
+ ## Auth templates follow the auth switch
4
+
5
+ An app with no auth method (`auth.localAuth`, every OAuth provider and `auth.firebase` off) used to
6
+ receive the whole auth stack anyway: `Authentication.middleware`, `JWTService`, the login page, the
7
+ OAuth runtime, and the `User` / `UserAuthProfiles` / `Session` schemas. None of it could run, and the
8
+ three schemas became tables the app never touched.
9
+
10
+ Those templates are now copied only when an auth method is on. `cleanupStaleFiles` removes them from
11
+ an app generated with auth on and re-generated with it off.
12
+
13
+ ## `app.useUserSchema` owns the built-in `User` document
14
+
15
+ `User.json` is copied only when `app.useUserSchema` is `true` (the default). With `false` the
16
+ generator writes nothing:
17
+
18
+ - a `User.json` already in `jsonSchemaDir` stays untouched and is generated like any other document;
19
+ - a project without one emits no `User` table, no `/user` routes and no file that names
20
+ `UserModel`.
21
+
22
+ `app.useUserSchema` governs the template only. It never deletes or rewrites a file in
23
+ `jsonSchemaDir`.
24
+
25
+ ## Auth and RBAC require a `User` document
26
+
27
+ Auth reads the account row through `UserModel`; `UserRole` declares a foreign key to it. A project
28
+ that enables either feature without a document named `User` now stops at generation time:
29
+
30
+ ```
31
+ authentication needs a document named "User", and this project has none.
32
+ Set "app.useUserSchema" to true to generate the built-in one, or add your own User.json.
33
+ ```
34
+
35
+ The check runs before foreign keys resolve, so the failure names the document instead of surfacing
36
+ as a relation builder error. `RBAC` is named in the message when `useRBAC` is the reason.
37
+
38
+ ## `auth.verifyOnly`
39
+
40
+ New mode for a service that serves business routes and validates tokens minted by another vex app:
41
+
42
+ ```jsonc
43
+ "auth": { "localAuth": false, "verifyOnly": true }
44
+ ```
45
+
46
+ | | Sign-in app | Verify-only app |
47
+ | --- | --- | --- |
48
+ | `Authentication.gen.ts` | verifies the token, then reads the account row | verifies the token only |
49
+ | `JWTService.gen.ts` | mints and verifies, owns sessions | `verifyToken` only |
50
+ | `AuthController`, `/login`, OAuth routes | yes | no |
51
+ | `User`, `UserAuthProfiles`, `Session` | yes | no |
52
+ | `AccountStateGuard.gen.ts` | reads the identity row | constant `true` |
53
+
54
+ `JWT_SECRET0..9` and `JWT_ALGORITHM` must match the app that signs. Clients send `Authorization`
55
+ and `X-Auth-Index` as usual. Identity arrives as the `vexUserId` claim, so `onCreateUserId`,
56
+ `onUpdateUserId` and `source: "user._id"` isolation work.
57
+
58
+ Rejected combinations, each a config error that names the conflict:
59
+
60
+ | Combination | Reason |
61
+ | --- | --- |
62
+ | `verifyOnly` with a sign-in method | one app signs in, the other only verifies |
63
+ | `verifyOnly` with `useRBAC` | role assignments live in the local `UserRole` table |
64
+ | `verifyOnly` with `tenant.IsolationMode: "option"` | selecting a tenant mints a token |
65
+
66
+ Revocation is bounded by token lifetime: a verify-only app owns no account row to check.
67
+
68
+ ## Tenant membership follows auth
69
+
70
+ `UserTenant`, `TenantService` and `TenantController` are emitted when the tenant module links
71
+ accounts, which requires an auth method. Isolation itself does not: `TenantScope`,
72
+ `TenantScopeContext` and every `user.tenantId` rule are emitted from `tenant.enable` alone, and work
73
+ with no auth and no account document.
74
+
75
+ ## Generated output
76
+
77
+ | File | Change |
78
+ | --- | --- |
79
+ | `_middlewares/Authentication.gen.ts` | emitted with any auth method; verify-only variant reads no account row |
80
+ | `_services/auth/JWTService.gen.ts` | emitted with any auth method; verify-only variant has `verifyToken` only |
81
+ | `_services/auth/AccountStateGuard.gen.ts` | no-op in verify-only |
82
+ | `_middlewares/tsoaAuthentication.gen.ts` | unchanged |
83
+ | `_routes/LoginUI.gen.ts`, `_routes/oauth/*`, `_services/oauth/*`, `_types/auth.gen.ts` | emitted only with a sign-in method |
84
+ | `_controllers/{Document}Controller.gen.ts` | `@Security` and `Authentication.middleware` when a token is verified |
85
+ | `_utils/hash.gen.ts` | no longer imports the `User` type |
86
+
87
+ ## Migration
88
+
89
+ 1. Re-run the generator.
90
+ 2. An app that keeps auth off and `app.useUserSchema: false` keeps any `User.json`, `Session.json`,
91
+ `UserAuthProfiles.json` or `UserTenant.json` already in `jsonSchemaDir`. Each one still produces a
92
+ document and a table; delete the unused files to drop them.
93
+ 3. A project with auth or RBAC on and no `User.json` must set `app.useUserSchema: true` or add its
94
+ own schema before the first run of this version.
95
+
96
+ ## Tests
97
+
98
+ New golden scenarios: `sql-tenant-header-nouser` (auth off, `useUserSchema: false`) and
99
+ `sql-verify-only` (verify-only with tenant `preSelect`). New unit tests: `test/unit/authDocuments.test.ts`
100
+ for the missing-`User` check and `test/unit/verifyOnly.test.ts` for the mode's predicates and config
101
+ validation. `test/e2e/compile.test.ts` adds `tenant-preSelect-auth-off-nouser` and
102
+ `tenant-preSelect-verify-only` to the compile matrix.
@@ -0,0 +1,82 @@
1
+ # v0.11.0
2
+
3
+ ## Changes
4
+
5
+ - Add `x-documentConfig.schema` to place one document's table in a named PostgreSQL schema.
6
+ - Generate `_types/SchemaName.gen.ts` with the union of the declared schemas and the same values as the runtime list `vexDbSchemas`.
7
+ - Create every declared schema at generated-app startup, before TypeORM synchronize builds the tables.
8
+ - Warn at generation time when a foreign key points at a document in another schema, and when a non-SQL target declares `schema`.
9
+ - Reject a `schema` value that is not a plain PostgreSQL identifier.
10
+
11
+ ## Named schemas
12
+
13
+ A document puts its table in a named schema with one key:
14
+
15
+ ```jsonc
16
+ "x-documentConfig": {
17
+ "documentName": "Task",
18
+ "schema": "kernel",
19
+ "methods": ["get", "getList"]
20
+ }
21
+ ```
22
+
23
+ The entity carries both the schema and the table name:
24
+
25
+ ```ts
26
+ @Entity({ schema: vexDbSchemas.kernel, name: "task" })
27
+ ```
28
+
29
+ Documents without the key stay in `public` and keep the bare decorator `@Entity("task")`.
30
+
31
+ `schema` accepts `^[A-Za-z_][A-Za-z0-9_]*$`. Generation stops on any other value: the name is
32
+ interpolated into `CREATE SCHEMA IF NOT EXISTS` in the generated app.
33
+
34
+ Two limits:
35
+
36
+ - Foreign keys across schemas are not supported. Generation warns when a relation resolves to a
37
+ document in a different schema.
38
+ - `dbType: "mongo"` ignores the key. Generation warns.
39
+
40
+ ## Startup order
41
+
42
+ TypeORM `synchronize` creates tables but never a schema, so the generated connector creates the
43
+ declared schemas first:
44
+
45
+ 1. connect and `initialize()` with `synchronize: false`
46
+ 2. `CREATE SCHEMA IF NOT EXISTS` for every value in `vexDbSchemas`
47
+ 3. `synchronize()` when `SQL_SYNCHRONIZE=true`
48
+
49
+ `public` is never created: PostgreSQL already has it. A project that declares no schema emits the
50
+ connector without steps 2 and 3, and synchronize keeps running inside `initialize()`.
51
+
52
+ ## Generated output
53
+
54
+ | File | Change |
55
+ | --- | --- |
56
+ | `_models/{Document}Model.gen.ts` | `@Entity({ schema: vexDbSchemas.<schema>, name: "<table>" })` when the document declares one |
57
+ | `_types/SchemaName.gen.ts` | new; union type plus `vexDbSchemas`, written only when a document declares a schema |
58
+ | `_services/VexDbConnector.gen.ts` | schema creation and the explicit `synchronize()` call; emitted from a function template |
59
+
60
+ Every other generated file is unchanged, and so is the output of a project that declares no schema.
61
+
62
+ ## Migration
63
+
64
+ 1. Re-run the generator.
65
+ 2. A fresh database needs nothing: the app creates the schemas at startup.
66
+ 3. An existing database keeps the tables where they are. Adding `schema` to a document moves its
67
+ table, so copy the rows across before the first start with the new value:
68
+
69
+ ```sql
70
+ CREATE SCHEMA IF NOT EXISTS "kernel";
71
+ ALTER TABLE "public"."task" SET SCHEMA "kernel";
72
+ ```
73
+
74
+ 4. Without `SQL_SYNCHRONIZE`, create the schemas yourself; the app never runs DDL in that mode.
75
+
76
+ ## Tests
77
+
78
+ `npm test` covers the decorator branch, the schema list, the rejected names and the mongo warning.
79
+ The scenario `sql-schema-specified` pins three documents in `kernel`, `fnb` and `accounting`,
80
+ including the generated `SchemaName.gen.ts` and the connector that creates them.
81
+
82
+ Every other golden file is unchanged.
@@ -25,9 +25,10 @@ Each `.json` file defines one REST resource. Filename must match `x-documentConf
25
25
  | --- | --- | --- | --- |
26
26
  | `documentName` | `string` | yes | Resource name. Must match filename (e.g. `User.json` → `"User"`). Used as collection name, controller class, route prefix. |
27
27
  | `methods` | `array<schemaMethod>` | yes | REST methods to generate. See values below. |
28
- | `uniqueIndex` | `array<array<string>>` | no | Compound unique index definitions, e.g. `[["email"], ["userId","role"]]`. |
28
+ | `uniqueIndex` | `array<array<string>>` | no | Compound unique index definitions, e.g. `[["email"], ["userId","role"]]`. The SQL entity names the constraint `unique_<table>_<columns>`, so two documents may declare the same column set. |
29
29
  | `isolation` | `array<object>` | no | Query terms the repository adds to every read and write. `{ field, source, onMissing }` — see [isolation rules](#isolation-rules). |
30
30
  | `dataIsolation` | `object` | no | Legacy single-field form: `{ "field": "ownerId" }`. Normalized into `isolation`. |
31
+ | `schema` | `string` | no | PostgreSQL schema the table is created in. Defaults to `public`. SQL target only. See [named schemas](#named-schemas). |
31
32
 
32
33
  ### `methods` values
33
34
 
@@ -60,6 +61,38 @@ the request payload, stripped from caller data, and stamped from the request con
60
61
  See [`docs/features/dataIsolation.md`](features/dataIsolation.md) and
61
62
  [`docs/features/tenantIsolation.md`](features/tenantIsolation.md).
62
63
 
64
+ ### Named schemas
65
+
66
+ `schema` places one document's table in a named PostgreSQL schema. The value is a plain
67
+ identifier (`^[A-Za-z_][A-Za-z0-9_]*$`); anything else stops generation.
68
+
69
+ ```jsonc
70
+ "x-documentConfig": {
71
+ "documentName": "Task",
72
+ "schema": "kernel",
73
+ "methods": ["get", "getList"]
74
+ }
75
+ ```
76
+
77
+ The generated entity carries both the schema and the table name:
78
+
79
+ ```ts
80
+ @Entity({ schema: vexDbSchemas.kernel, name: "task" })
81
+ ```
82
+
83
+ Consequences:
84
+
85
+ - The generated app creates every declared schema at startup (`CREATE SCHEMA IF NOT EXISTS`) before
86
+ TypeORM synchronize builds tables, so a fresh database needs no manual step. `public` is never
87
+ created: PostgreSQL already has it.
88
+ - `_types/SchemaName.gen.ts` holds the union of every declared schema and the same values as the
89
+ runtime list `vexDbSchemas`. It is written only when at least one document declares one.
90
+ - A document without `schema` stays in `public`, and its entity keeps the bare table decorator
91
+ `@Entity("task")`.
92
+ - Foreign keys are not supported across schemas. Generation warns when a relation points at a
93
+ document in a different schema.
94
+ - `dbType: "mongo"` ignores the key; generation warns.
95
+
63
96
  ---
64
97
 
65
98
  ## Property fields
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "very-express",
3
- "version": "0.10.2",
3
+ "version": "0.11.0",
4
4
  "description": "based on json schema and openapi, generate Express RestApi server with mongoDb ",
5
5
  "author": "Justin26l",
6
6
  "license": "MIT",
package/vex.config.json CHANGED
@@ -20,7 +20,8 @@
20
20
  "oauthProviders": {
21
21
  "google": false,
22
22
  "github": false
23
- }
23
+ },
24
+ "verifyOnly": false
24
25
  },
25
26
  "useRBAC": {
26
27
  "roles": [
@@ -30,6 +31,10 @@
30
31
  ],
31
32
  "default": "admin"
32
33
  },
34
+ "tenant": {
35
+ "enable": true,
36
+ "IsolationMode": "single"
37
+ },
33
38
  "generator": {
34
39
  "commitBeforeGenerate": false,
35
40
  "disableVersionLabel": false
@@ -1,188 +0,0 @@
1
- // {{headerComment}}
2
- import { Request, Response, NextFunction } from "express";
3
- import { AsyncLocalStorage } from "async_hooks";
4
- import { DataSource, EntityTarget, ObjectLiteral } from "typeorm";
5
- import mongoose from "mongoose";
6
- import { VexRepository } from "../_types/vex";
7
- import { TypeOrmRepositoryAdapter } from "./TypeOrmRepositoryAdapter.gen";
8
- import utils from "./../_utils";
9
-
10
- /** The only surface a transaction callback gets. It never exposes the TypeORM manager. */
11
- export interface VexTransaction {
12
- getRepository<T extends ObjectLiteral>(target: EntityTarget<T>): VexRepository<T>;
13
- }
14
-
15
- export class VexDbConnector {
16
- private sqlUrl: string;
17
- private sqlCa: string;
18
- private mongoUrl: string;
19
- private recordAccessLog: boolean = false;
20
-
21
- private dataSource?: DataSource;
22
- private transactionScope = new AsyncLocalStorage<boolean>();
23
-
24
- constructor(options: {
25
- sqlUrl?: string;
26
- sqlCa?: string;
27
- mongoUrl?: string;
28
- recordAccessLog?: boolean;
29
- }) {
30
- this.sqlUrl = options.sqlUrl || "";
31
- this.sqlCa = options.sqlCa || "";
32
- this.mongoUrl = options.mongoUrl || "";
33
- this.recordAccessLog = options.recordAccessLog || false;
34
- this.middleware = this.middleware.bind(this);
35
- this.transaction = this.transaction.bind(this);
36
- }
37
-
38
- /**
39
- * Run `fn` in one database transaction. Throwing inside `fn` rolls everything back.
40
- *
41
- * Repositories come from the transaction's own manager, but the callback only receives
42
- * `getRepository`: handing out the manager would let call sites take the raw repository and
43
- * bypass isolation, audit stamping and fail-closed checks.
44
- *
45
- * Isolation reads `UserContext` from AsyncLocalStorage, so it applies inside the callback
46
- * unchanged. Nested calls are rejected rather than silently opening a second transaction.
47
- */
48
- async transaction<T>(fn: (tx: VexTransaction) => Promise<T>): Promise<T> {
49
- if (!this.sqlUrl) {
50
- throw new Error("VexDb.transaction is only available for the SQL target");
51
- }
52
- if (!this.dataSource) {
53
- throw new Error("SQL DataSource not initialized");
54
- }
55
- if (this.transactionScope.getStore()) {
56
- throw new Error("nested transaction is not supported");
57
- }
58
-
59
- return this.dataSource.transaction((manager) => this.transactionScope.run(true, () => fn({
60
- getRepository: <E extends ObjectLiteral>(target: EntityTarget<E>): VexRepository<E> =>
61
- new TypeOrmRepositoryAdapter<E & ObjectLiteral>(manager.getRepository(target)),
62
- })));
63
- }
64
-
65
- connect(): void {
66
- if (this.sqlUrl) this.connectSql();
67
- if (this.mongoUrl) this.connectMongo();
68
- }
69
-
70
- close(): void {
71
- if (this.sqlUrl) this.closeSql();
72
- if (this.mongoUrl) this.closeMongo();
73
- }
74
-
75
- connectSql(): void {
76
- utils.log.infoSql("Connecting to SQL DB (TypeORM)...");
77
- const sqlUrl = new URL(this.sqlUrl);
78
-
79
- const ca = !this.sqlCa ? undefined : this.sqlCa.startsWith("-----BEGIN") ? this.sqlCa : Buffer.from(this.sqlCa, "base64").toString("utf8");
80
- const insecure = (process.env.SQL_INSECURE_TLS || "").toLowerCase() === "true";
81
- const sslRequired = sqlUrl.searchParams.get("sslmode") === "require";
82
- const ssl = sslRequired ?
83
- {
84
- rejectUnauthorized: insecure ? false : true,
85
- ca,
86
- } :
87
- undefined;
88
-
89
- const ds = new DataSource({
90
- type: "postgres",
91
- host: sqlUrl.hostname,
92
- port: Number(sqlUrl.port) || 5432,
93
- username: sqlUrl.username,
94
- password: sqlUrl.password,
95
- database: sqlUrl.pathname.slice(1),
96
- ssl,
97
- synchronize: (process.env.SQL_SYNCHRONIZE || "").toLowerCase() === "true",
98
- logging: false,
99
- entities: [__dirname + "/../_models/*.gen.{ts,js}"],
100
- migrations: [],
101
- });
102
-
103
- const connectWithRetry = (retryTime = 10): void => {
104
- ds.initialize()
105
- .then(() => {
106
- this.dataSource = ds;
107
- utils.log.infoSql("TypeORM DataSource initialized");
108
- })
109
- .catch((err) => {
110
- utils.log.errorSql(`Failed to initialize TypeORM, retrying in ${retryTime}s`, err);
111
- setTimeout(() => connectWithRetry(retryTime), retryTime * 1000);
112
- });
113
- };
114
-
115
- connectWithRetry(10);
116
- }
117
-
118
- closeSql(): void {
119
- if (this.dataSource?.isInitialized) {
120
- this.dataSource.destroy()
121
- .then(() => utils.log.infoSql("TypeORM DataSource closed"))
122
- .catch((err) => utils.log.errorSql("Error closing TypeORM DataSource", err));
123
- }
124
- }
125
-
126
- // TODO: complete mongoose support
127
- connectMongo(): void {
128
- console.warn("VeryExpress unified db adapter (MongooseRepositoryAdapter) for Mongodb are under development, use with caution. Contribute to \"https://github.com/Justin26l/VeryExpress\"");
129
- utils.log.infoMongo("Connecting to MongoDB (Driver: Mongoose)...");
130
- const connectWithRetry = (retryTime = 10): void => {
131
- mongoose.connect(this.mongoUrl)
132
- .then(() => utils.log.infoMongo("Mongoose connected"))
133
- .catch((err) => {
134
- utils.log.errorMongo(`Failed to connect Mongoose, retrying in ${retryTime}s`, err);
135
- setTimeout(() => connectWithRetry(retryTime), retryTime * 1000);
136
- });
137
- };
138
- connectWithRetry(10);
139
- }
140
-
141
- closeMongo(): void {
142
- console.warn("VeryExpress unified db adapter (MongooseRepositoryAdapter) for Mongodb are under development, use with caution. Contribute to \"https://github.com/Justin26l/VeryExpress\"");
143
- mongoose.disconnect()
144
- .then(() => utils.log.infoMongo("Mongoose disconnected"))
145
- .catch((err) => utils.log.errorMongo("Error disconnecting Mongoose", err));
146
- }
147
-
148
- getRepository<T extends ObjectLiteral>(target: EntityTarget<T>): VexRepository<T>;
149
- getRepository<T>(target: EntityTarget<ObjectLiteral> | any): VexRepository<T> {
150
- if (target?.schema && target?.modelName) {
151
- console.warn("VeryExpress unified db adapter (MongooseRepositoryAdapter) for Mongodb are under development, use with caution. Contribute to \"https://github.com/Justin26l/VeryExpress\"");
152
- }
153
- if (!this.dataSource) throw new Error("SQL DataSource not initialized");
154
- return new TypeOrmRepositoryAdapter<T & ObjectLiteral>(this.dataSource.getRepository(target));
155
- }
156
-
157
- async middleware(req: Request, res: Response, next: NextFunction): Promise<void> {
158
- try {
159
- if (this.sqlUrl && (!this.dataSource || !this.dataSource.isInitialized)) {
160
- utils.response.send(res, 503, { code: utils.response.code.DB_CONN_ERR });
161
- return;
162
- }
163
-
164
- if (this.recordAccessLog && this.dataSource?.isInitialized) {
165
- const logEntry = {
166
- timestamp: new Date().getTime(),
167
- ipa: req.socket.remoteAddress || req.headers["x-forwarded-for"],
168
- method: req.method,
169
- url: req.url.split("?")[0],
170
- headers: JSON.stringify(req.headers),
171
- query: JSON.stringify(req.query),
172
- };
173
- try {
174
- await this.dataSource.getRepository("AccessLog").save(logEntry);
175
- }
176
- catch { /* table may not exist */ }
177
- }
178
-
179
- next();
180
- }
181
- catch (err: unknown) {
182
- utils.response.send(res, 500, { code: utils.response.code.DB_CONN_ERR });
183
- return;
184
- }
185
- }
186
- }
187
-
188
- export default VexDbConnector;
@@ -1,56 +0,0 @@
1
- // {{headerComment}}
2
-
3
- export type TenantIsolationMode = "preSelect" | "option";
4
-
5
- export type TenantError =
6
- | "missing-header"
7
- | "invalid-tenant"
8
- | "missing-claim"
9
- | "invalid-claim";
10
-
11
- export interface TenantDecision {
12
- tenantId?: string;
13
- error?: TenantError;
14
- }
15
-
16
- const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
17
-
18
- /** Tenant ids are UUIDs everywhere: header, claim and the UserTenant table. */
19
- export function isTenantId(value: unknown): value is string {
20
- return typeof value === "string" && UUID_PATTERN.test(value);
21
- }
22
-
23
- /**
24
- * Decide the tenant of a request.
25
- *
26
- * `preSelect` — the app build is bound to one tenant: the header is required and is the only
27
- * source; a token claim is not used.
28
- *
29
- * `option` — the user logs in first and then selects a tenant. A token that carries the
30
- * `tenantId` claim decides; a token without one is rejected. A request with no token is a
31
- * guest, and the header identifies the tenant for public endpoints.
32
- *
33
- * `tokenData` is absent on the L0 pass because authentication has not run yet.
34
- */
35
- export function resolveTenantContext(
36
- mode: TenantIsolationMode,
37
- tokenData: Record<string, unknown> | undefined,
38
- headerTenantId: string | undefined,
39
- ): TenantDecision {
40
- if (mode === "preSelect") {
41
- if (!headerTenantId) return { error: "missing-header" };
42
- if (!isTenantId(headerTenantId)) return { error: "invalid-tenant" };
43
- return { tenantId: headerTenantId };
44
- }
45
-
46
- if (tokenData) {
47
- const claimed = tokenData.tenantId;
48
- if (claimed === undefined || claimed === "") return { error: "missing-claim" };
49
- if (!isTenantId(claimed)) return { error: "invalid-claim" };
50
- return { tenantId: claimed };
51
- }
52
-
53
- if (!headerTenantId) return {};
54
- if (!isTenantId(headerTenantId)) return { error: "invalid-tenant" };
55
- return { tenantId: headerTenantId };
56
- }