very-express 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/.tmp/als-proof.mjs +15 -0
  2. package/.tmp/als-proof2.mjs +9 -0
  3. package/.tmp/gen/out/.env +41 -0
  4. package/.tmp/gen/out/.vex/meta.json +387 -0
  5. package/.tmp/gen/out/Dockerfile +20 -0
  6. package/.tmp/gen/out/README.md +39 -0
  7. package/.tmp/gen/out/package.json +51 -0
  8. package/.tmp/gen/out/public/css/style.css +8 -0
  9. package/.tmp/gen/out/public/js/deleteaccount.js +80 -0
  10. package/.tmp/gen/out/public/js/login.js +59 -0
  11. package/.tmp/gen/out/public/js/logincallback.js +19 -0
  12. package/.tmp/gen/out/public/js/mytokens.js +11 -0
  13. package/.tmp/gen/out/public/js/refreshtokens.js +23 -0
  14. package/.tmp/gen/out/scripts/build.js +39 -0
  15. package/.tmp/gen/out/scripts/oacg-fix.js +83 -0
  16. package/.tmp/gen/out/tsconfig.json +30 -0
  17. package/.tmp/gen/out/tsoa.json +32 -0
  18. package/.tmp/gen/schemas/Project.json +50 -0
  19. package/.tmp/gen/schemas/Session.json +49 -0
  20. package/.tmp/gen/schemas/User.json +81 -0
  21. package/.tmp/gen/schemas/UserAuthProfiles.json +54 -0
  22. package/.tmp/gen/schemas/UserRole.json +40 -0
  23. package/.tmp/gen/schemas/UserTenant.json +39 -0
  24. package/.tmp/gen/vex.config.json +39 -0
  25. package/.tmp/gen0/out/.env +41 -0
  26. package/.tmp/gen0/out/.vex/meta.json +323 -0
  27. package/.tmp/gen0/out/Dockerfile +20 -0
  28. package/.tmp/gen0/out/README.md +39 -0
  29. package/.tmp/gen0/out/package.json +51 -0
  30. package/.tmp/gen0/out/public/css/style.css +8 -0
  31. package/.tmp/gen0/out/public/js/deleteaccount.js +80 -0
  32. package/.tmp/gen0/out/public/js/login.js +59 -0
  33. package/.tmp/gen0/out/public/js/logincallback.js +19 -0
  34. package/.tmp/gen0/out/public/js/mytokens.js +11 -0
  35. package/.tmp/gen0/out/public/js/refreshtokens.js +23 -0
  36. package/.tmp/gen0/out/scripts/build.js +39 -0
  37. package/.tmp/gen0/out/scripts/oacg-fix.js +83 -0
  38. package/.tmp/gen0/out/tsconfig.json +30 -0
  39. package/.tmp/gen0/out/tsoa.json +32 -0
  40. package/.tmp/gen0/schemas/Session.json +49 -0
  41. package/.tmp/gen0/schemas/User.json +81 -0
  42. package/.tmp/gen0/schemas/UserAuthProfiles.json +54 -0
  43. package/.tmp/gen0/schemas/UserRole.json +38 -0
  44. package/.tmp/gen0/vex.config.json +32 -0
  45. package/.tmp/gend/out/.env +41 -0
  46. package/.tmp/gend/out/.vex/meta.json +317 -0
  47. package/.tmp/gend/out/Dockerfile +20 -0
  48. package/.tmp/gend/out/README.md +39 -0
  49. package/.tmp/gend/out/package.json +51 -0
  50. package/.tmp/gend/out/public/css/style.css +8 -0
  51. package/.tmp/gend/out/public/js/deleteaccount.js +80 -0
  52. package/.tmp/gend/out/public/js/login.js +59 -0
  53. package/.tmp/gend/out/public/js/logincallback.js +19 -0
  54. package/.tmp/gend/out/public/js/mytokens.js +11 -0
  55. package/.tmp/gend/out/public/js/refreshtokens.js +23 -0
  56. package/.tmp/gend/out/scripts/build.js +39 -0
  57. package/.tmp/gend/out/scripts/oacg-fix.js +83 -0
  58. package/.tmp/gend/out/tsconfig.json +30 -0
  59. package/.tmp/gend/out/tsoa.json +32 -0
  60. package/.tmp/gend/schemas/Session.json +49 -0
  61. package/.tmp/gend/schemas/User.json +81 -0
  62. package/.tmp/gend/schemas/UserAuthProfiles.json +54 -0
  63. package/.tmp/gend/schemas/UserContact.json +40 -0
  64. package/.tmp/gend/schemas/UserNote.json +27 -0
  65. package/.tmp/gend/vex.config.json +33 -0
  66. package/.tmp/genh/out/.env +41 -0
  67. package/.tmp/genh/out/.vex/meta.json +323 -0
  68. package/.tmp/genh/out/Dockerfile +20 -0
  69. package/.tmp/genh/out/README.md +39 -0
  70. package/.tmp/genh/out/package.json +51 -0
  71. package/.tmp/genh/out/public/css/style.css +8 -0
  72. package/.tmp/genh/out/public/js/deleteaccount.js +80 -0
  73. package/.tmp/genh/out/public/js/login.js +59 -0
  74. package/.tmp/genh/out/public/js/logincallback.js +19 -0
  75. package/.tmp/genh/out/public/js/mytokens.js +11 -0
  76. package/.tmp/genh/out/public/js/refreshtokens.js +23 -0
  77. package/.tmp/genh/out/scripts/build.js +39 -0
  78. package/.tmp/genh/out/scripts/oacg-fix.js +83 -0
  79. package/.tmp/genh/out/tsconfig.json +30 -0
  80. package/.tmp/genh/out/tsoa.json +32 -0
  81. package/.tmp/genh/schemas/Project.json +41 -0
  82. package/.tmp/genh/schemas/Session.json +49 -0
  83. package/.tmp/genh/schemas/User.json +81 -0
  84. package/.tmp/genh/schemas/UserAuthProfiles.json +54 -0
  85. package/.tmp/genh/schemas/UserTenant.json +39 -0
  86. package/.tmp/genh/vex.config.json +34 -0
  87. package/.tmp/gens/out/.env +41 -0
  88. package/.tmp/gens/out/.vex/meta.json +335 -0
  89. package/.tmp/gens/out/Dockerfile +20 -0
  90. package/.tmp/gens/out/README.md +39 -0
  91. package/.tmp/gens/out/package.json +51 -0
  92. package/.tmp/gens/out/public/css/style.css +8 -0
  93. package/.tmp/gens/out/public/js/deleteaccount.js +80 -0
  94. package/.tmp/gens/out/public/js/login.js +59 -0
  95. package/.tmp/gens/out/public/js/logincallback.js +19 -0
  96. package/.tmp/gens/out/public/js/mytokens.js +11 -0
  97. package/.tmp/gens/out/public/js/refreshtokens.js +23 -0
  98. package/.tmp/gens/out/scripts/build.js +39 -0
  99. package/.tmp/gens/out/scripts/oacg-fix.js +83 -0
  100. package/.tmp/gens/out/tsconfig.json +30 -0
  101. package/.tmp/gens/out/tsoa.json +32 -0
  102. package/.tmp/gens/schemas/Session.json +49 -0
  103. package/.tmp/gens/schemas/User.json +81 -0
  104. package/.tmp/gens/schemas/UserAuthProfiles.json +54 -0
  105. package/.tmp/gens/schemas/UserRole.json +38 -0
  106. package/.tmp/gens/vex.config.json +32 -0
  107. package/.tmp/npmtest/package.json +1 -0
  108. package/.tmp/ro-test +0 -0
  109. package/AGENTS.md +4 -3
  110. package/README.md +1 -0
  111. package/dist/index.js +955 -653
  112. package/dist/templates/_middlewares/Authentication.ts +1 -1
  113. package/dist/templates/_middlewares/UserContext.ts +30 -4
  114. package/dist/templates/_services/MongooseRepositoryAdapter.ts +94 -4
  115. package/dist/templates/_services/TypeOrmRepositoryAdapter.ts +92 -17
  116. package/dist/templates/_services/VexDbConnector.ts +36 -1
  117. package/dist/templates/_services/auth/JWTService.ts +13 -2
  118. package/dist/templates/_tenant/TenantScopeContext.ts +56 -0
  119. package/dist/templates/_types/auth.ts +7 -1
  120. package/dist/templates/_types/vex/VexRepository.ts +9 -2
  121. package/dist/templates/tenantJsonSchema/UserTenant.json +33 -0
  122. package/docs/architecture/databaseTargets.md +37 -8
  123. package/docs/architecture/generatorPipeline.md +2 -1
  124. package/docs/features/accountDeletion.md +61 -9
  125. package/docs/features/dataIsolation.md +58 -31
  126. package/docs/features/tenantIsolation.md +147 -0
  127. package/docs/releaseNote/v0-10-0.md +147 -0
  128. package/docs/releaseNote/v0-10-1.md +84 -0
  129. package/docs/vexJsonSchema.md +22 -0
  130. package/package.json +1 -1
  131. package/vitest.config.ts +3 -0
@@ -0,0 +1,84 @@
1
+ # v0.10.1
2
+
3
+ ## Transaction entry owned by the DB layer
4
+
5
+ Business code can run several writes in one transaction without touching the TypeORM manager:
6
+
7
+ ```ts
8
+ await vexDb.transaction(async (tx) => {
9
+ const orderRepo = tx.getRepository(OrderEntity);
10
+ await orderRepo.create({ ... });
11
+ });
12
+ ```
13
+
14
+ - `tx` only exposes `getRepository`; the manager and the data source are not reachable.
15
+ - Returned repositories are the normal adapters, so isolation, audit stamping and fail-closed
16
+ checks behave exactly as they do outside a transaction.
17
+ - Throwing inside the callback rolls the whole transaction back.
18
+ - Nested calls throw `nested transaction is not supported` instead of silently opening a second
19
+ transaction.
20
+ - The mongo target throws `VexDb.transaction is only available for the SQL target`.
21
+
22
+ `vexDb.dataSource` is now private. `VexDbConnector` is the only place that reads it.
23
+
24
+ ### `VexRepository.save`
25
+
26
+ `save` is the upsert-shaped write the transaction callback exposes:
27
+
28
+ | Payload | Behaviour |
29
+ | --- | --- |
30
+ | no `_id` | insert, with the normal create-phase audit fields and isolation stamping |
31
+ | with `_id` | update that row; a row outside the caller's isolation is a `404` |
32
+
33
+ Isolation fields are stripped before the write, so `save` cannot move a row to another tenant or
34
+ owner. Both adapters implement it.
35
+
36
+ ## `tenant.scope`
37
+
38
+ The tenant middleware applies to every route by default. A deployment whose browser-facing paths
39
+ cannot send the tenant header narrows it:
40
+
41
+ ```jsonc
42
+ "tenant": {
43
+ "enable": true,
44
+ "IsolationMode": "preSelect",
45
+ "scope": ["/api"]
46
+ }
47
+ ```
48
+
49
+ - Prefix match on `req.path`, boundary-aware: `/api` matches `/api/...` but not `/apix`.
50
+ - Omitted → every route (the previous behaviour).
51
+ - An entry must start with `/`; an empty list is rejected at generation time.
52
+ - `/hello` stays exempt.
53
+
54
+ In `preSelect`, `scope` must cover the auth routes used by the client (normally `/api` or
55
+ `/api/auth`): login reads the tenant captured by the middleware.
56
+
57
+ Tenant existence is not checked by the middleware. It validates the UUID only; whether the tenant
58
+ exists, is disabled or was deleted is the application's lookup, whose normal answer is `404`.
59
+
60
+ ## Generated output
61
+
62
+ | File | Change |
63
+ | --- | --- |
64
+ | `_services/VexDbConnector.gen.ts` | `transaction`, private `dataSource` |
65
+ | `_services/TypeOrmRepositoryAdapter.gen.ts` | `save`, transaction-scoped repository support |
66
+ | `_services/MongooseRepositoryAdapter.gen.ts` | `save` (transactions throw) |
67
+ | `_types/vex/VexRepository.gen.ts` | `save` |
68
+ | `_middlewares/TenantScope.gen.ts` | `scope` guard when `tenant.scope` is set |
69
+
70
+ ## Migration
71
+
72
+ 1. Re-run the generator.
73
+ 2. Replace any `vexDb.dataSource.transaction(async (manager) => ...)` with
74
+ `vexDb.transaction(async (tx) => ...)`; `manager.getRepository(...)` becomes
75
+ `tx.getRepository(...)`.
76
+ 3. `dataSource` is private, so direct reads no longer compile. This is intended: the transaction
77
+ handle is the supported boundary.
78
+ 4. `tenant` config without `scope` keeps the previous routing behaviour.
79
+
80
+ ## Tests
81
+
82
+ `npm test` covers the generated shapes and the unchanged default. `npm run test:e2e` runs a probe
83
+ inside a generated app against Postgres: tenant stamping inside a transaction, fail-closed `403`
84
+ without a tenant, rollback of every write on throw, and the nested-call rejection.
@@ -26,6 +26,8 @@ Each `.json` file defines one REST resource. Filename must match `x-documentConf
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
28
  | `uniqueIndex` | `array<array<string>>` | no | Compound unique index definitions, e.g. `[["email"], ["userId","role"]]`. |
29
+ | `isolation` | `array<object>` | no | Query terms the repository adds to every read and write. `{ field, source, onMissing }` — see [isolation rules](#isolation-rules). |
30
+ | `dataIsolation` | `object` | no | Legacy single-field form: `{ "field": "ownerId" }`. Normalized into `isolation`. |
29
31
 
30
32
  ### `methods` values
31
33
 
@@ -38,6 +40,26 @@ Each `.json` file defines one REST resource. Filename must match `x-documentConf
38
40
  | `patch` | `PATCH /:id` | Partial update |
39
41
  | `delete` | `DELETE /:id` | Delete document |
40
42
 
43
+ ### Isolation rules
44
+
45
+ ```jsonc
46
+ "isolation": [
47
+ { "field": "tenantId", "source": "user.tenantId", "onMissing": "deny" },
48
+ { "field": "ownerId", "source": "user._id", "onMissing": "skip" }
49
+ ]
50
+ ```
51
+
52
+ | Key | Values |
53
+ | --- | --- |
54
+ | `field` | a `string` property of the document |
55
+ | `source` | `user._id` (authenticated user) or `user.tenantId` (verified tenant) |
56
+ | `onMissing` | `skip` (no term) or `deny` (`403`). Default: `skip` for `user._id`, `deny` for `user.tenantId` |
57
+
58
+ `user.tenantId` requires `vex.config.tenant.enable`. The rule's field is server-managed: it is omitted from
59
+ the request payload, stripped from caller data, and stamped from the request context on create.
60
+ See [`docs/features/dataIsolation.md`](features/dataIsolation.md) and
61
+ [`docs/features/tenantIsolation.md`](features/tenantIsolation.md).
62
+
41
63
  ---
42
64
 
43
65
  ## Property fields
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "very-express",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
4
4
  "description": "based on json schema and openapi, generate Express RestApi server with mongoDb ",
5
5
  "author": "Justin26l",
6
6
  "license": "MIT",
package/vitest.config.ts CHANGED
@@ -14,5 +14,8 @@ export default defineConfig({
14
14
  // golden scenarios spawn a full generation each; give them room
15
15
  testTimeout: 120_000,
16
16
  hookTimeout: 120_000,
17
+ // The e2e suites share one generated app directory and one port, so files must not run
18
+ // in parallel with each other.
19
+ fileParallelism: false,
17
20
  },
18
21
  });