@lenne.tech/nest-server 12.0.0 → 12.1.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 (693) hide show
  1. package/.claude/rules/architecture.md +6 -1
  2. package/.claude/rules/better-auth.md +46 -0
  3. package/.claude/rules/configurable-features.md +3 -2
  4. package/.claude/rules/package-management.md +24 -2
  5. package/.claude/rules/persistence.md +100 -0
  6. package/.claude/rules/role-system.md +9 -0
  7. package/.claude/rules/testing.md +116 -18
  8. package/CLAUDE.md +21 -2
  9. package/FRAMEWORK-API.md +6 -4
  10. package/README.md +106 -34
  11. package/dist/core/common/decorators/unified-field.decorator.d.ts +2 -1
  12. package/dist/core/common/decorators/unified-field.decorator.js +4 -1
  13. package/dist/core/common/decorators/unified-field.decorator.js.map +1 -1
  14. package/dist/core/common/filters/mongoose-cast-error.filter.d.ts +7 -5
  15. package/dist/core/common/filters/mongoose-cast-error.filter.js +3 -2
  16. package/dist/core/common/filters/mongoose-cast-error.filter.js.map +1 -1
  17. package/dist/core/common/helpers/db.helper.d.ts +2 -1
  18. package/dist/core/common/helpers/db.helper.js +32 -26
  19. package/dist/core/common/helpers/db.helper.js.map +1 -1
  20. package/dist/core/common/helpers/decorator.helper.d.ts +1 -1
  21. package/dist/core/common/helpers/filter.helper.d.ts +2 -1
  22. package/dist/core/common/helpers/filter.helper.js.map +1 -1
  23. package/dist/core/common/helpers/gridfs.helper.d.ts +4 -4
  24. package/dist/core/common/helpers/gridfs.helper.js +14 -6
  25. package/dist/core/common/helpers/gridfs.helper.js.map +1 -1
  26. package/dist/core/common/helpers/id.helper.d.ts +4 -1
  27. package/dist/core/common/helpers/id.helper.js +10 -4
  28. package/dist/core/common/helpers/id.helper.js.map +1 -1
  29. package/dist/core/common/helpers/model.helper.js +5 -5
  30. package/dist/core/common/helpers/model.helper.js.map +1 -1
  31. package/dist/core/common/helpers/service.helper.js +3 -3
  32. package/dist/core/common/helpers/service.helper.js.map +1 -1
  33. package/dist/core/common/interfaces/server-options.interface.d.ts +18 -2
  34. package/dist/core/common/interfaces/service-options.interface.d.ts +2 -2
  35. package/dist/core/common/models/core-persistence.model.d.ts +1 -2
  36. package/dist/core/common/models/core-persistence.model.js +3 -3
  37. package/dist/core/common/models/core-persistence.model.js.map +1 -1
  38. package/dist/core/common/persistence/core-persistence.lifecycle.d.ts +9 -0
  39. package/dist/core/common/persistence/core-persistence.lifecycle.js +38 -0
  40. package/dist/core/common/persistence/core-persistence.lifecycle.js.map +1 -0
  41. package/dist/core/common/persistence/core-persistence.module.d.ts +9 -0
  42. package/dist/core/common/persistence/core-persistence.module.js +76 -0
  43. package/dist/core/common/persistence/core-persistence.module.js.map +1 -0
  44. package/dist/core/common/persistence/data-source.config.d.ts +33 -0
  45. package/dist/core/common/persistence/data-source.config.js +151 -0
  46. package/dist/core/common/persistence/data-source.config.js.map +1 -0
  47. package/dist/core/common/persistence/data-source.runtime.d.ts +45 -0
  48. package/dist/core/common/persistence/data-source.runtime.js +278 -0
  49. package/dist/core/common/persistence/data-source.runtime.js.map +1 -0
  50. package/dist/core/common/persistence/data-store.interface.d.ts +73 -0
  51. package/dist/core/common/persistence/data-store.interface.js +2 -0
  52. package/dist/core/common/persistence/data-store.interface.js.map +1 -0
  53. package/dist/core/common/persistence/expiry-sweep.d.ts +12 -0
  54. package/dist/core/common/persistence/expiry-sweep.js +55 -0
  55. package/dist/core/common/persistence/expiry-sweep.js.map +1 -0
  56. package/dist/core/common/persistence/id-format.d.ts +3 -0
  57. package/dist/core/common/persistence/id-format.js +21 -0
  58. package/dist/core/common/persistence/id-format.js.map +1 -0
  59. package/dist/core/common/persistence/infrastructure-locks.d.ts +13 -0
  60. package/dist/core/common/persistence/infrastructure-locks.js +35 -0
  61. package/dist/core/common/persistence/infrastructure-locks.js.map +1 -0
  62. package/dist/core/common/persistence/inject-store.decorator.d.ts +1 -0
  63. package/dist/core/common/persistence/inject-store.decorator.js +6 -0
  64. package/dist/core/common/persistence/inject-store.decorator.js.map +1 -0
  65. package/dist/core/common/persistence/lock-store.interface.d.ts +5 -0
  66. package/dist/core/common/persistence/lock-store.interface.js +2 -0
  67. package/dist/core/common/persistence/lock-store.interface.js.map +1 -0
  68. package/dist/core/common/persistence/model-descriptor.interface.d.ts +36 -0
  69. package/dist/core/common/persistence/model-descriptor.interface.js +2 -0
  70. package/dist/core/common/persistence/model-descriptor.interface.js.map +1 -0
  71. package/dist/core/common/persistence/model-metadata.registry.d.ts +14 -0
  72. package/dist/core/common/persistence/model-metadata.registry.js +194 -0
  73. package/dist/core/common/persistence/model-metadata.registry.js.map +1 -0
  74. package/dist/core/common/persistence/mongo/collection-name.d.ts +2 -0
  75. package/dist/core/common/persistence/mongo/collection-name.js +73 -0
  76. package/dist/core/common/persistence/mongo/collection-name.js.map +1 -0
  77. package/dist/core/common/persistence/mongo/declared-schema.view.d.ts +11 -0
  78. package/dist/core/common/persistence/mongo/declared-schema.view.js +292 -0
  79. package/dist/core/common/persistence/mongo/declared-schema.view.js.map +1 -0
  80. package/dist/core/common/persistence/mongo/hex-object-id.d.ts +13 -0
  81. package/dist/core/common/persistence/mongo/hex-object-id.js +54 -0
  82. package/dist/core/common/persistence/mongo/hex-object-id.js.map +1 -0
  83. package/dist/core/common/persistence/mongo/model-declarations.d.ts +35 -0
  84. package/dist/core/common/persistence/mongo/model-declarations.js +80 -0
  85. package/dist/core/common/persistence/mongo/model-declarations.js.map +1 -0
  86. package/dist/core/common/persistence/mongo/mongo-packages.d.ts +15 -0
  87. package/dist/core/common/persistence/mongo/mongo-packages.js +66 -0
  88. package/dist/core/common/persistence/mongo/mongo-packages.js.map +1 -0
  89. package/dist/core/common/persistence/mongo/mongoose-compat.d.ts +22 -0
  90. package/dist/core/common/persistence/mongo/mongoose-compat.js +65 -0
  91. package/dist/core/common/persistence/mongo/mongoose-compat.js.map +1 -0
  92. package/dist/core/common/persistence/mongo/no-mongo-connection.module.d.ts +2 -0
  93. package/dist/core/common/persistence/mongo/no-mongo-connection.module.js +19 -0
  94. package/dist/core/common/persistence/mongo/no-mongo-connection.module.js.map +1 -0
  95. package/dist/core/common/persistence/mongo-lock-store.d.ts +21 -0
  96. package/dist/core/common/persistence/mongo-lock-store.js +72 -0
  97. package/dist/core/common/persistence/mongo-lock-store.js.map +1 -0
  98. package/dist/core/common/persistence/mongoose-data-store.d.ts +33 -0
  99. package/dist/core/common/persistence/mongoose-data-store.js +187 -0
  100. package/dist/core/common/persistence/mongoose-data-store.js.map +1 -0
  101. package/dist/core/common/persistence/neutral-populate.d.ts +6 -0
  102. package/dist/core/common/persistence/neutral-populate.js +72 -0
  103. package/dist/core/common/persistence/neutral-populate.js.map +1 -0
  104. package/dist/core/common/persistence/persisted-model.decorator.d.ts +6 -0
  105. package/dist/core/common/persistence/persisted-model.decorator.js +24 -0
  106. package/dist/core/common/persistence/persisted-model.decorator.js.map +1 -0
  107. package/dist/core/common/persistence/persistence-runtime.registry.d.ts +61 -0
  108. package/dist/core/common/persistence/persistence-runtime.registry.js +47 -0
  109. package/dist/core/common/persistence/persistence-runtime.registry.js.map +1 -0
  110. package/dist/core/common/persistence/persistence.tokens.d.ts +1 -0
  111. package/dist/core/common/persistence/persistence.tokens.js +4 -0
  112. package/dist/core/common/persistence/persistence.tokens.js.map +1 -0
  113. package/dist/core/common/persistence/policies/audit.policy.d.ts +8 -0
  114. package/dist/core/common/persistence/policies/audit.policy.js +37 -0
  115. package/dist/core/common/persistence/policies/audit.policy.js.map +1 -0
  116. package/dist/core/common/persistence/policies/password.policy.d.ts +3 -0
  117. package/dist/core/common/persistence/policies/password.policy.js +46 -0
  118. package/dist/core/common/persistence/policies/password.policy.js.map +1 -0
  119. package/dist/core/common/persistence/policies/role-guard.policy.d.ts +3 -0
  120. package/dist/core/common/persistence/policies/role-guard.policy.js +46 -0
  121. package/dist/core/common/persistence/policies/role-guard.policy.js.map +1 -0
  122. package/dist/core/common/persistence/policies/system-role.policy.d.ts +5 -0
  123. package/dist/core/common/persistence/policies/system-role.policy.js +46 -0
  124. package/dist/core/common/persistence/policies/system-role.policy.js.map +1 -0
  125. package/dist/core/common/persistence/policies/tenant.policy.d.ts +19 -0
  126. package/dist/core/common/persistence/policies/tenant.policy.js +120 -0
  127. package/dist/core/common/persistence/policies/tenant.policy.js.map +1 -0
  128. package/dist/core/common/persistence/routed-model.guard.d.ts +4 -0
  129. package/dist/core/common/persistence/routed-model.guard.js +73 -0
  130. package/dist/core/common/persistence/routed-model.guard.js.map +1 -0
  131. package/dist/core/common/persistence/sql/mysql/mysql-data-store.d.ts +46 -0
  132. package/dist/core/common/persistence/sql/mysql/mysql-data-store.js +350 -0
  133. package/dist/core/common/persistence/sql/mysql/mysql-data-store.js.map +1 -0
  134. package/dist/core/common/persistence/sql/mysql/mysql-executor.d.ts +13 -0
  135. package/dist/core/common/persistence/sql/mysql/mysql-executor.js +194 -0
  136. package/dist/core/common/persistence/sql/mysql/mysql-executor.js.map +1 -0
  137. package/dist/core/common/persistence/sql/mysql/mysql-lock-store.d.ts +11 -0
  138. package/dist/core/common/persistence/sql/mysql/mysql-lock-store.js +55 -0
  139. package/dist/core/common/persistence/sql/mysql/mysql-lock-store.js.map +1 -0
  140. package/dist/core/common/persistence/sql/mysql/mysql-schema.compiler.d.ts +36 -0
  141. package/dist/core/common/persistence/sql/mysql/mysql-schema.compiler.js +288 -0
  142. package/dist/core/common/persistence/sql/mysql/mysql-schema.compiler.js.map +1 -0
  143. package/dist/core/common/persistence/sql/mysql/mysql-schema.migrator.d.ts +19 -0
  144. package/dist/core/common/persistence/sql/mysql/mysql-schema.migrator.js +328 -0
  145. package/dist/core/common/persistence/sql/mysql/mysql-schema.migrator.js.map +1 -0
  146. package/dist/core/common/persistence/sql/mysql/mysql-session.d.ts +13 -0
  147. package/dist/core/common/persistence/sql/mysql/mysql-session.js +85 -0
  148. package/dist/core/common/persistence/sql/mysql/mysql-session.js.map +1 -0
  149. package/dist/core/common/persistence/sql/mysql/mysql-update.compiler.d.ts +9 -0
  150. package/dist/core/common/persistence/sql/mysql/mysql-update.compiler.js +264 -0
  151. package/dist/core/common/persistence/sql/mysql/mysql-update.compiler.js.map +1 -0
  152. package/dist/core/common/persistence/sql/mysql/mysql-where.compiler.d.ts +20 -0
  153. package/dist/core/common/persistence/sql/mysql/mysql-where.compiler.js +519 -0
  154. package/dist/core/common/persistence/sql/mysql/mysql-where.compiler.js.map +1 -0
  155. package/dist/core/common/persistence/sql/postgres/postgres-lock-store.d.ts +11 -0
  156. package/dist/core/common/persistence/sql/postgres/postgres-lock-store.js +44 -0
  157. package/dist/core/common/persistence/sql/postgres/postgres-lock-store.js.map +1 -0
  158. package/dist/core/common/persistence/sql/postgres/postgres-schema.compiler.d.ts +42 -0
  159. package/dist/core/common/persistence/sql/postgres/postgres-schema.compiler.js +220 -0
  160. package/dist/core/common/persistence/sql/postgres/postgres-schema.compiler.js.map +1 -0
  161. package/dist/core/common/persistence/sql/postgres/postgres-schema.migrator.d.ts +12 -0
  162. package/dist/core/common/persistence/sql/postgres/postgres-schema.migrator.js +315 -0
  163. package/dist/core/common/persistence/sql/postgres/postgres-schema.migrator.js.map +1 -0
  164. package/dist/core/common/persistence/sql/postgres/postgres-update.compiler.d.ts +5 -0
  165. package/dist/core/common/persistence/sql/postgres/postgres-update.compiler.js +225 -0
  166. package/dist/core/common/persistence/sql/postgres/postgres-update.compiler.js.map +1 -0
  167. package/dist/core/common/persistence/sql/postgres/postgres-where.compiler.d.ts +13 -0
  168. package/dist/core/common/persistence/sql/postgres/postgres-where.compiler.js +484 -0
  169. package/dist/core/common/persistence/sql/postgres/postgres-where.compiler.js.map +1 -0
  170. package/dist/core/common/persistence/sql/sql-cast.d.ts +2 -0
  171. package/dist/core/common/persistence/sql/sql-cast.js +194 -0
  172. package/dist/core/common/persistence/sql/sql-cast.js.map +1 -0
  173. package/dist/core/common/persistence/sql/sql-data-store.d.ts +79 -0
  174. package/dist/core/common/persistence/sql/sql-data-store.js +592 -0
  175. package/dist/core/common/persistence/sql/sql-data-store.js.map +1 -0
  176. package/dist/core/common/persistence/sql/sql-dialect.d.ts +20 -0
  177. package/dist/core/common/persistence/sql/sql-dialect.js +38 -0
  178. package/dist/core/common/persistence/sql/sql-dialect.js.map +1 -0
  179. package/dist/core/common/persistence/sql/sql-errors.d.ts +17 -0
  180. package/dist/core/common/persistence/sql/sql-errors.js +25 -0
  181. package/dist/core/common/persistence/sql/sql-errors.js.map +1 -0
  182. package/dist/core/common/persistence/sql/sql-executor.factory.d.ts +11 -0
  183. package/dist/core/common/persistence/sql/sql-executor.factory.js +199 -0
  184. package/dist/core/common/persistence/sql/sql-executor.factory.js.map +1 -0
  185. package/dist/core/common/persistence/sql/sql-executor.interface.d.ts +32 -0
  186. package/dist/core/common/persistence/sql/sql-executor.interface.js +2 -0
  187. package/dist/core/common/persistence/sql/sql-executor.interface.js.map +1 -0
  188. package/dist/core/common/persistence/sql/sql-naming.d.ts +15 -0
  189. package/dist/core/common/persistence/sql/sql-naming.js +90 -0
  190. package/dist/core/common/persistence/sql/sql-naming.js.map +1 -0
  191. package/dist/core/common/persistence/sql/sql-schema.shared.d.ts +25 -0
  192. package/dist/core/common/persistence/sql/sql-schema.shared.js +69 -0
  193. package/dist/core/common/persistence/sql/sql-schema.shared.js.map +1 -0
  194. package/dist/core/common/persistence/sql/sql-session.d.ts +6 -0
  195. package/dist/core/common/persistence/sql/sql-session.js +78 -0
  196. package/dist/core/common/persistence/sql/sql-session.js.map +1 -0
  197. package/dist/core/common/persistence/sql/where-shared.d.ts +18 -0
  198. package/dist/core/common/persistence/sql/where-shared.js +93 -0
  199. package/dist/core/common/persistence/sql/where-shared.js.map +1 -0
  200. package/dist/core/common/persistence/store-guards.d.ts +10 -0
  201. package/dist/core/common/persistence/store-guards.js +49 -0
  202. package/dist/core/common/persistence/store-guards.js.map +1 -0
  203. package/dist/core/common/persistence/store-upsert.d.ts +2 -0
  204. package/dist/core/common/persistence/store-upsert.js +20 -0
  205. package/dist/core/common/persistence/store-upsert.js.map +1 -0
  206. package/dist/core/common/persistence/unavailable-store.d.ts +2 -0
  207. package/dist/core/common/persistence/unavailable-store.js +53 -0
  208. package/dist/core/common/persistence/unavailable-store.js.map +1 -0
  209. package/dist/core/common/persistence/unsupported-capability.error.d.ts +3 -0
  210. package/dist/core/common/persistence/unsupported-capability.error.js +4 -0
  211. package/dist/core/common/persistence/unsupported-capability.error.js.map +1 -0
  212. package/dist/core/common/plugins/mongoose-audit-fields.plugin.js +24 -68
  213. package/dist/core/common/plugins/mongoose-audit-fields.plugin.js.map +1 -1
  214. package/dist/core/common/plugins/mongoose-id.plugin.js +3 -0
  215. package/dist/core/common/plugins/mongoose-id.plugin.js.map +1 -1
  216. package/dist/core/common/plugins/mongoose-password.plugin.d.ts +1 -3
  217. package/dist/core/common/plugins/mongoose-password.plugin.js +2 -45
  218. package/dist/core/common/plugins/mongoose-password.plugin.js.map +1 -1
  219. package/dist/core/common/plugins/mongoose-role-guard.plugin.js +5 -46
  220. package/dist/core/common/plugins/mongoose-role-guard.plugin.js.map +1 -1
  221. package/dist/core/common/plugins/mongoose-system-role.plugin.js +2 -43
  222. package/dist/core/common/plugins/mongoose-system-role.plugin.js.map +1 -1
  223. package/dist/core/common/plugins/mongoose-tenant.plugin.js +10 -70
  224. package/dist/core/common/plugins/mongoose-tenant.plugin.js.map +1 -1
  225. package/dist/core/common/scalars/upload.scalar.js +1 -1
  226. package/dist/core/common/scalars/upload.scalar.js.map +1 -1
  227. package/dist/core/common/services/core-cron-jobs.initializer.js +1 -1
  228. package/dist/core/common/services/core-cron-jobs.initializer.js.map +1 -1
  229. package/dist/core/common/services/core-cron-jobs.service.d.ts +1 -0
  230. package/dist/core/common/services/core-cron-jobs.service.js +23 -14
  231. package/dist/core/common/services/core-cron-jobs.service.js.map +1 -1
  232. package/dist/core/common/services/crud.service.d.ts +4 -1
  233. package/dist/core/common/services/crud.service.js +132 -23
  234. package/dist/core/common/services/crud.service.js.map +1 -1
  235. package/dist/core/common/services/model-doc.service.js +1 -1
  236. package/dist/core/common/services/model-doc.service.js.map +1 -1
  237. package/dist/core/common/services/module.service.d.ts +9 -2
  238. package/dist/core/common/services/module.service.js +51 -6
  239. package/dist/core/common/services/module.service.js.map +1 -1
  240. package/dist/core/common/types/field-selection.type.d.ts +1 -1
  241. package/dist/core/common/types/id.type.d.ts +4 -4
  242. package/dist/core/common/types/object-id-like.type.d.ts +3 -0
  243. package/dist/core/common/types/object-id-like.type.js +2 -0
  244. package/dist/core/common/types/object-id-like.type.js.map +1 -0
  245. package/dist/core/common/types/populate-config.type.d.ts +1 -1
  246. package/dist/core/common/types/string-or-object-id.type.d.ts +2 -2
  247. package/dist/core/modules/ai/core-ai.constants.d.ts +4 -0
  248. package/dist/core/modules/ai/core-ai.constants.js +4 -0
  249. package/dist/core/modules/ai/core-ai.constants.js.map +1 -1
  250. package/dist/core/modules/ai/core-ai.module.js +21 -17
  251. package/dist/core/modules/ai/core-ai.module.js.map +1 -1
  252. package/dist/core/modules/ai/models/core-ai-budget-limit.model.d.ts +2 -92
  253. package/dist/core/modules/ai/models/core-ai-budget-limit.model.js +1 -1
  254. package/dist/core/modules/ai/models/core-ai-budget-limit.model.js.map +1 -1
  255. package/dist/core/modules/ai/models/core-ai-connection-preference.model.d.ts +2 -87
  256. package/dist/core/modules/ai/models/core-ai-connection-preference.model.js +1 -1
  257. package/dist/core/modules/ai/models/core-ai-connection-preference.model.js.map +1 -1
  258. package/dist/core/modules/ai/models/core-ai-connection.model.d.ts +2 -177
  259. package/dist/core/modules/ai/models/core-ai-connection.model.js +1 -1
  260. package/dist/core/modules/ai/models/core-ai-connection.model.js.map +1 -1
  261. package/dist/core/modules/ai/models/core-ai-conversation.model.d.ts +2 -92
  262. package/dist/core/modules/ai/models/core-ai-conversation.model.js +3 -4
  263. package/dist/core/modules/ai/models/core-ai-conversation.model.js.map +1 -1
  264. package/dist/core/modules/ai/models/core-ai-interaction.model.d.ts +2 -120
  265. package/dist/core/modules/ai/models/core-ai-interaction.model.js +2 -3
  266. package/dist/core/modules/ai/models/core-ai-interaction.model.js.map +1 -1
  267. package/dist/core/modules/ai/models/core-ai-mcp-oauth.models.d.ts +3 -0
  268. package/dist/core/modules/ai/models/core-ai-mcp-oauth.models.js +21 -0
  269. package/dist/core/modules/ai/models/core-ai-mcp-oauth.models.js.map +1 -0
  270. package/dist/core/modules/ai/models/core-ai-mode.model.d.ts +2 -102
  271. package/dist/core/modules/ai/models/core-ai-mode.model.js +1 -1
  272. package/dist/core/modules/ai/models/core-ai-mode.model.js.map +1 -1
  273. package/dist/core/modules/ai/models/core-ai-prompt-hint.model.d.ts +2 -97
  274. package/dist/core/modules/ai/models/core-ai-prompt-hint.model.js +1 -1
  275. package/dist/core/modules/ai/models/core-ai-prompt-hint.model.js.map +1 -1
  276. package/dist/core/modules/ai/models/core-ai-prompt.model.d.ts +2 -112
  277. package/dist/core/modules/ai/models/core-ai-prompt.model.js +1 -1
  278. package/dist/core/modules/ai/models/core-ai-prompt.model.js.map +1 -1
  279. package/dist/core/modules/ai/models/core-ai-slot.model.d.ts +2 -112
  280. package/dist/core/modules/ai/models/core-ai-slot.model.js +1 -1
  281. package/dist/core/modules/ai/models/core-ai-slot.model.js.map +1 -1
  282. package/dist/core/modules/ai/models/core-ai-tool-grant.model.d.ts +2 -97
  283. package/dist/core/modules/ai/models/core-ai-tool-grant.model.js +1 -1
  284. package/dist/core/modules/ai/models/core-ai-tool-grant.model.js.map +1 -1
  285. package/dist/core/modules/ai/models/core-ai-tool-policy.model.d.ts +2 -103
  286. package/dist/core/modules/ai/models/core-ai-tool-policy.model.js +1 -1
  287. package/dist/core/modules/ai/models/core-ai-tool-policy.model.js.map +1 -1
  288. package/dist/core/modules/ai/services/core-ai-budget.service.d.ts +3 -1
  289. package/dist/core/modules/ai/services/core-ai-budget.service.js +15 -5
  290. package/dist/core/modules/ai/services/core-ai-budget.service.js.map +1 -1
  291. package/dist/core/modules/ai/services/core-ai-connection-preference.service.d.ts +1 -1
  292. package/dist/core/modules/ai/services/core-ai-connection-preference.service.js +6 -10
  293. package/dist/core/modules/ai/services/core-ai-connection-preference.service.js.map +1 -1
  294. package/dist/core/modules/ai/services/core-ai-connection.service.d.ts +1 -1
  295. package/dist/core/modules/ai/services/core-ai-connection.service.js +20 -42
  296. package/dist/core/modules/ai/services/core-ai-connection.service.js.map +1 -1
  297. package/dist/core/modules/ai/services/core-ai-conversation.service.d.ts +1 -1
  298. package/dist/core/modules/ai/services/core-ai-conversation.service.js +28 -29
  299. package/dist/core/modules/ai/services/core-ai-conversation.service.js.map +1 -1
  300. package/dist/core/modules/ai/services/core-ai-interaction.service.d.ts +1 -1
  301. package/dist/core/modules/ai/services/core-ai-interaction.service.js +3 -4
  302. package/dist/core/modules/ai/services/core-ai-interaction.service.js.map +1 -1
  303. package/dist/core/modules/ai/services/core-ai-mcp-oauth.service.d.ts +8 -0
  304. package/dist/core/modules/ai/services/core-ai-mcp-oauth.service.js +70 -18
  305. package/dist/core/modules/ai/services/core-ai-mcp-oauth.service.js.map +1 -1
  306. package/dist/core/modules/ai/services/core-ai-mode.service.d.ts +1 -1
  307. package/dist/core/modules/ai/services/core-ai-mode.service.js +3 -7
  308. package/dist/core/modules/ai/services/core-ai-mode.service.js.map +1 -1
  309. package/dist/core/modules/ai/services/core-ai-prompt-hint.service.d.ts +8 -1
  310. package/dist/core/modules/ai/services/core-ai-prompt-hint.service.js +32 -26
  311. package/dist/core/modules/ai/services/core-ai-prompt-hint.service.js.map +1 -1
  312. package/dist/core/modules/ai/services/core-ai-prompt.service.d.ts +1 -1
  313. package/dist/core/modules/ai/services/core-ai-prompt.service.js +10 -13
  314. package/dist/core/modules/ai/services/core-ai-prompt.service.js.map +1 -1
  315. package/dist/core/modules/ai/services/core-ai-slot.service.d.ts +1 -1
  316. package/dist/core/modules/ai/services/core-ai-slot.service.js +14 -25
  317. package/dist/core/modules/ai/services/core-ai-slot.service.js.map +1 -1
  318. package/dist/core/modules/ai/services/core-ai-tool-grant.service.d.ts +1 -1
  319. package/dist/core/modules/ai/services/core-ai-tool-grant.service.js +6 -18
  320. package/dist/core/modules/ai/services/core-ai-tool-grant.service.js.map +1 -1
  321. package/dist/core/modules/ai/services/core-ai-tool-policy.service.d.ts +1 -1
  322. package/dist/core/modules/ai/services/core-ai-tool-policy.service.js +4 -8
  323. package/dist/core/modules/ai/services/core-ai-tool-policy.service.js.map +1 -1
  324. package/dist/core/modules/api-token/core-api-token.model.js +1 -1
  325. package/dist/core/modules/api-token/core-api-token.model.js.map +1 -1
  326. package/dist/core/modules/api-token/core-api-token.module.js +3 -2
  327. package/dist/core/modules/api-token/core-api-token.module.js.map +1 -1
  328. package/dist/core/modules/api-token/core-api-token.service.d.ts +8 -2
  329. package/dist/core/modules/api-token/core-api-token.service.js +106 -39
  330. package/dist/core/modules/api-token/core-api-token.service.js.map +1 -1
  331. package/dist/core/modules/auth/core-auth.module.js +2 -0
  332. package/dist/core/modules/auth/core-auth.module.js.map +1 -1
  333. package/dist/core/modules/auth/guards/legacy-auth-rate-limit.guard.js +1 -2
  334. package/dist/core/modules/auth/guards/legacy-auth-rate-limit.guard.js.map +1 -1
  335. package/dist/core/modules/auth/guards/role-guard.token.d.ts +1 -0
  336. package/dist/core/modules/auth/guards/role-guard.token.js +2 -0
  337. package/dist/core/modules/auth/guards/role-guard.token.js.map +1 -0
  338. package/dist/core/modules/auth/services/core-auth.service.js +4 -2
  339. package/dist/core/modules/auth/services/core-auth.service.js.map +1 -1
  340. package/dist/core/modules/better-auth/better-auth-sql.helper.d.ts +6 -0
  341. package/dist/core/modules/better-auth/better-auth-sql.helper.js +113 -0
  342. package/dist/core/modules/better-auth/better-auth-sql.helper.js.map +1 -0
  343. package/dist/core/modules/better-auth/better-auth-token.service.d.ts +3 -1
  344. package/dist/core/modules/better-auth/better-auth-token.service.js +15 -24
  345. package/dist/core/modules/better-auth/better-auth-token.service.js.map +1 -1
  346. package/dist/core/modules/better-auth/better-auth.config.d.ts +7 -0
  347. package/dist/core/modules/better-auth/better-auth.config.js +16 -5
  348. package/dist/core/modules/better-auth/better-auth.config.js.map +1 -1
  349. package/dist/core/modules/better-auth/better-auth.types.d.ts +1 -1
  350. package/dist/core/modules/better-auth/core-better-auth-api.middleware.d.ts +1 -0
  351. package/dist/core/modules/better-auth/core-better-auth-api.middleware.js +6 -1
  352. package/dist/core/modules/better-auth/core-better-auth-api.middleware.js.map +1 -1
  353. package/dist/core/modules/better-auth/core-better-auth-challenge.service.js +30 -15
  354. package/dist/core/modules/better-auth/core-better-auth-challenge.service.js.map +1 -1
  355. package/dist/core/modules/better-auth/core-better-auth-mongo.users.d.ts +10 -0
  356. package/dist/core/modules/better-auth/core-better-auth-mongo.users.js +24 -0
  357. package/dist/core/modules/better-auth/core-better-auth-mongo.users.js.map +1 -0
  358. package/dist/core/modules/better-auth/core-better-auth-sql.registry.d.ts +3 -0
  359. package/dist/core/modules/better-auth/core-better-auth-sql.registry.js +8 -0
  360. package/dist/core/modules/better-auth/core-better-auth-sql.registry.js.map +1 -0
  361. package/dist/core/modules/better-auth/core-better-auth-sql.store.d.ts +71 -0
  362. package/dist/core/modules/better-auth/core-better-auth-sql.store.js +190 -0
  363. package/dist/core/modules/better-auth/core-better-auth-sql.store.js.map +1 -0
  364. package/dist/core/modules/better-auth/core-better-auth-user.mapper.d.ts +24 -1
  365. package/dist/core/modules/better-auth/core-better-auth-user.mapper.js +308 -32
  366. package/dist/core/modules/better-auth/core-better-auth-user.mapper.js.map +1 -1
  367. package/dist/core/modules/better-auth/core-better-auth.module.d.ts +2 -0
  368. package/dist/core/modules/better-auth/core-better-auth.module.js +54 -32
  369. package/dist/core/modules/better-auth/core-better-auth.module.js.map +1 -1
  370. package/dist/core/modules/better-auth/core-better-auth.service.d.ts +7 -2
  371. package/dist/core/modules/better-auth/core-better-auth.service.js +61 -9
  372. package/dist/core/modules/better-auth/core-better-auth.service.js.map +1 -1
  373. package/dist/core/modules/file/core-file-info.model.d.ts +1 -2
  374. package/dist/core/modules/file/core-file-info.model.js +2 -2
  375. package/dist/core/modules/file/core-file-info.model.js.map +1 -1
  376. package/dist/core/modules/file/core-file.service.d.ts +5 -3
  377. package/dist/core/modules/file/core-file.service.js +16 -9
  378. package/dist/core/modules/file/core-file.service.js.map +1 -1
  379. package/dist/core/modules/file/file-metadata.helper.d.ts +1 -1
  380. package/dist/core/modules/file/file-metadata.helper.js +2 -2
  381. package/dist/core/modules/file/file-metadata.helper.js.map +1 -1
  382. package/dist/core/modules/file/file-metadata.models.d.ts +35 -0
  383. package/dist/core/modules/file/file-metadata.models.js +20 -0
  384. package/dist/core/modules/file/file-metadata.models.js.map +1 -0
  385. package/dist/core/modules/file/file-metadata.store.d.ts +6 -0
  386. package/dist/core/modules/file/file-metadata.store.js +77 -0
  387. package/dist/core/modules/file/file-metadata.store.js.map +1 -0
  388. package/dist/core/modules/file/file-storage.helper.d.ts +1 -0
  389. package/dist/core/modules/file/file-storage.helper.js +34 -0
  390. package/dist/core/modules/file/file-storage.helper.js.map +1 -1
  391. package/dist/core/modules/file/filesystem-file.helper.d.ts +1 -1
  392. package/dist/core/modules/file/filesystem-file.helper.js +4 -4
  393. package/dist/core/modules/file/filesystem-file.helper.js.map +1 -1
  394. package/dist/core/modules/file/s3-file.helper.d.ts +1 -1
  395. package/dist/core/modules/file/s3-file.helper.js +5 -5
  396. package/dist/core/modules/file/s3-file.helper.js.map +1 -1
  397. package/dist/core/modules/health-check/core-health-check.module.js +12 -2
  398. package/dist/core/modules/health-check/core-health-check.module.js.map +1 -1
  399. package/dist/core/modules/health-check/core-health-check.service.d.ts +4 -3
  400. package/dist/core/modules/health-check/core-health-check.service.js +26 -5
  401. package/dist/core/modules/health-check/core-health-check.service.js.map +1 -1
  402. package/dist/core/modules/hub/core-hub.controller.d.ts +1 -0
  403. package/dist/core/modules/hub/core-hub.controller.js +10 -0
  404. package/dist/core/modules/hub/core-hub.controller.js.map +1 -1
  405. package/dist/core/modules/hub/core-hub.service.js +1 -1
  406. package/dist/core/modules/hub/core-hub.service.js.map +1 -1
  407. package/dist/core/modules/hub/helpers/hub-client-js.helper.js +23 -0
  408. package/dist/core/modules/hub/helpers/hub-client-js.helper.js.map +1 -1
  409. package/dist/core/modules/hub/hub-action-messages.d.ts +2 -0
  410. package/dist/core/modules/hub/hub-action-messages.js +2 -0
  411. package/dist/core/modules/hub/hub-action-messages.js.map +1 -1
  412. package/dist/core/modules/hub/hub-nav.js +1 -0
  413. package/dist/core/modules/hub/hub-nav.js.map +1 -1
  414. package/dist/core/modules/hub/interfaces/hub-panels.interface.d.ts +17 -1
  415. package/dist/core/modules/hub/services/core-hub-db.service.d.ts +6 -1
  416. package/dist/core/modules/hub/services/core-hub-db.service.js +16 -14
  417. package/dist/core/modules/hub/services/core-hub-db.service.js.map +1 -1
  418. package/dist/core/modules/hub/services/core-hub-migrations.service.d.ts +5 -0
  419. package/dist/core/modules/hub/services/core-hub-migrations.service.js +74 -1
  420. package/dist/core/modules/hub/services/core-hub-migrations.service.js.map +1 -1
  421. package/dist/core/modules/hub/services/core-hub-sources.service.d.ts +2 -1
  422. package/dist/core/modules/hub/services/core-hub-sources.service.js +32 -0
  423. package/dist/core/modules/hub/services/core-hub-sources.service.js.map +1 -1
  424. package/dist/core/modules/hub/services/hub-query-profiler.service.js +1 -1
  425. package/dist/core/modules/hub/services/hub-query-profiler.service.js.map +1 -1
  426. package/dist/core/modules/migrate/cli/migrate-cli.d.ts +2 -0
  427. package/dist/core/modules/migrate/cli/migrate-cli.js +35 -1
  428. package/dist/core/modules/migrate/cli/migrate-cli.js.map +1 -1
  429. package/dist/core/modules/migrate/index.d.ts +3 -0
  430. package/dist/core/modules/migrate/index.js +3 -0
  431. package/dist/core/modules/migrate/index.js.map +1 -1
  432. package/dist/core/modules/migrate/migration-runner.d.ts +2 -2
  433. package/dist/core/modules/migrate/migration-runner.js.map +1 -1
  434. package/dist/core/modules/migrate/migration-state-store.interface.d.ts +16 -0
  435. package/dist/core/modules/migrate/migration-state-store.interface.js +2 -0
  436. package/dist/core/modules/migrate/migration-state-store.interface.js.map +1 -0
  437. package/dist/core/modules/migrate/migration.helper.d.ts +3 -2
  438. package/dist/core/modules/migrate/migration.helper.js +21 -6
  439. package/dist/core/modules/migrate/migration.helper.js.map +1 -1
  440. package/dist/core/modules/migrate/mongo-state-store.d.ts +5 -12
  441. package/dist/core/modules/migrate/mongo-state-store.js +30 -24
  442. package/dist/core/modules/migrate/mongo-state-store.js.map +1 -1
  443. package/dist/core/modules/migrate/sql-migration.helper.d.ts +4 -0
  444. package/dist/core/modules/migrate/sql-migration.helper.js +34 -0
  445. package/dist/core/modules/migrate/sql-migration.helper.js.map +1 -0
  446. package/dist/core/modules/migrate/sql-state-store.d.ts +24 -0
  447. package/dist/core/modules/migrate/sql-state-store.js +129 -0
  448. package/dist/core/modules/migrate/sql-state-store.js.map +1 -0
  449. package/dist/core/modules/system-setup/core-system-setup.service.d.ts +8 -0
  450. package/dist/core/modules/system-setup/core-system-setup.service.js +41 -25
  451. package/dist/core/modules/system-setup/core-system-setup.service.js.map +1 -1
  452. package/dist/core/modules/tenant/core-tenant-member.model.js +1 -1
  453. package/dist/core/modules/tenant/core-tenant-member.model.js.map +1 -1
  454. package/dist/core/modules/tenant/core-tenant-member.store.d.ts +2 -0
  455. package/dist/core/modules/tenant/core-tenant-member.store.js +6 -0
  456. package/dist/core/modules/tenant/core-tenant-member.store.js.map +1 -0
  457. package/dist/core/modules/tenant/core-tenant.guard.d.ts +8 -3
  458. package/dist/core/modules/tenant/core-tenant.guard.js +57 -28
  459. package/dist/core/modules/tenant/core-tenant.guard.js.map +1 -1
  460. package/dist/core/modules/tenant/core-tenant.module.js +3 -2
  461. package/dist/core/modules/tenant/core-tenant.module.js.map +1 -1
  462. package/dist/core/modules/tenant/core-tenant.service.d.ts +3 -1
  463. package/dist/core/modules/tenant/core-tenant.service.js +48 -28
  464. package/dist/core/modules/tenant/core-tenant.service.js.map +1 -1
  465. package/dist/core/modules/tus/core-tus.service.d.ts +1 -1
  466. package/dist/core/modules/tus/core-tus.service.js +8 -7
  467. package/dist/core/modules/tus/core-tus.service.js.map +1 -1
  468. package/dist/core/modules/tus/tus.module.js +1 -1
  469. package/dist/core/modules/tus/tus.module.js.map +1 -1
  470. package/dist/core/modules/user/core-user.model.d.ts +1 -1
  471. package/dist/core/modules/user/core-user.model.js +1 -1
  472. package/dist/core/modules/user/core-user.model.js.map +1 -1
  473. package/dist/core/modules/user/core-user.service.d.ts +3 -1
  474. package/dist/core/modules/user/core-user.service.js +71 -16
  475. package/dist/core/modules/user/core-user.service.js.map +1 -1
  476. package/dist/core.module.js +39 -5
  477. package/dist/core.module.js.map +1 -1
  478. package/dist/index.d.ts +26 -0
  479. package/dist/index.js +26 -0
  480. package/dist/index.js.map +1 -1
  481. package/dist/server/common/models/persistence.model.d.ts +1 -1
  482. package/dist/server/common/models/persistence.model.js +3 -3
  483. package/dist/server/common/models/persistence.model.js.map +1 -1
  484. package/dist/server/modules/file/file-info.model.d.ts +1 -77
  485. package/dist/server/modules/file/file-info.model.js +1 -1
  486. package/dist/server/modules/file/file-info.model.js.map +1 -1
  487. package/dist/server/modules/file/file.service.js +1 -1
  488. package/dist/server/modules/file/file.service.js.map +1 -1
  489. package/dist/server/modules/user/user.model.d.ts +2 -186
  490. package/dist/server/modules/user/user.model.js +4 -5
  491. package/dist/server/modules/user/user.model.js.map +1 -1
  492. package/dist/server/modules/user/user.module.js +4 -3
  493. package/dist/server/modules/user/user.module.js.map +1 -1
  494. package/dist/server/modules/user/user.service.d.ts +1 -1
  495. package/dist/server/modules/user/user.service.js +5 -8
  496. package/dist/server/modules/user/user.service.js.map +1 -1
  497. package/dist/test/test.helper.js +2 -2
  498. package/dist/test/test.helper.js.map +1 -1
  499. package/dist/types/graphql-upload.d.ts +10 -7
  500. package/docs/REQUEST-LIFECYCLE.md +6 -3
  501. package/docs/choosing-a-database.md +107 -0
  502. package/docs/native-driver-security.md +29 -0
  503. package/docs/security-overrides.md +15 -6
  504. package/migration-guides/12.0.x-to-12.1.x.md +255 -0
  505. package/package.json +75 -29
  506. package/src/core/common/decorators/unified-field.decorator.ts +11 -1
  507. package/src/core/common/filters/mongoose-cast-error.filter.ts +12 -6
  508. package/src/core/common/helpers/db.helper.ts +40 -25
  509. package/src/core/common/helpers/decorator.helper.ts +1 -1
  510. package/src/core/common/helpers/filter.helper.ts +2 -1
  511. package/src/core/common/helpers/gridfs.helper.ts +28 -9
  512. package/src/core/common/helpers/id.helper.ts +21 -4
  513. package/src/core/common/helpers/model.helper.ts +5 -6
  514. package/src/core/common/helpers/service.helper.ts +3 -3
  515. package/src/core/common/interfaces/server-options.interface.ts +118 -10
  516. package/src/core/common/interfaces/service-options.interface.ts +2 -2
  517. package/src/core/common/models/core-persistence.model.ts +3 -3
  518. package/src/core/common/persistence/core-persistence.lifecycle.ts +47 -0
  519. package/src/core/common/persistence/core-persistence.module.ts +109 -0
  520. package/src/core/common/persistence/data-source.config.ts +271 -0
  521. package/src/core/common/persistence/data-source.runtime.ts +351 -0
  522. package/src/core/common/persistence/data-store.interface.ts +155 -0
  523. package/src/core/common/persistence/expiry-sweep.ts +105 -0
  524. package/src/core/common/persistence/id-format.ts +43 -0
  525. package/src/core/common/persistence/infrastructure-locks.ts +66 -0
  526. package/src/core/common/persistence/inject-store.decorator.ts +16 -0
  527. package/src/core/common/persistence/lock-store.interface.ts +17 -0
  528. package/src/core/common/persistence/model-descriptor.interface.ts +90 -0
  529. package/src/core/common/persistence/model-metadata.registry.ts +285 -0
  530. package/src/core/common/persistence/mongo/collection-name.ts +87 -0
  531. package/src/core/common/persistence/mongo/declared-schema.view.ts +378 -0
  532. package/src/core/common/persistence/mongo/hex-object-id.ts +75 -0
  533. package/src/core/common/persistence/mongo/model-declarations.ts +135 -0
  534. package/src/core/common/persistence/mongo/mongo-packages.ts +130 -0
  535. package/src/core/common/persistence/mongo/mongoose-compat.ts +129 -0
  536. package/src/core/common/persistence/mongo/no-mongo-connection.module.ts +18 -0
  537. package/src/core/common/persistence/mongo-lock-store.ts +121 -0
  538. package/src/core/common/persistence/mongoose-data-store.ts +232 -0
  539. package/src/core/common/persistence/neutral-populate.ts +98 -0
  540. package/src/core/common/persistence/persisted-model.decorator.ts +61 -0
  541. package/src/core/common/persistence/persistence-runtime.registry.ts +152 -0
  542. package/src/core/common/persistence/persistence.tokens.ts +9 -0
  543. package/src/core/common/persistence/policies/audit.policy.ts +80 -0
  544. package/src/core/common/persistence/policies/password.policy.ts +69 -0
  545. package/src/core/common/persistence/policies/role-guard.policy.ts +74 -0
  546. package/src/core/common/persistence/policies/system-role.policy.ts +90 -0
  547. package/src/core/common/persistence/policies/tenant.policy.ts +245 -0
  548. package/src/core/common/persistence/routed-model.guard.ts +107 -0
  549. package/src/core/common/persistence/sql/mysql/mysql-data-store.ts +503 -0
  550. package/src/core/common/persistence/sql/mysql/mysql-executor.ts +281 -0
  551. package/src/core/common/persistence/sql/mysql/mysql-lock-store.ts +87 -0
  552. package/src/core/common/persistence/sql/mysql/mysql-schema.compiler.ts +424 -0
  553. package/src/core/common/persistence/sql/mysql/mysql-schema.migrator.ts +453 -0
  554. package/src/core/common/persistence/sql/mysql/mysql-session.ts +131 -0
  555. package/src/core/common/persistence/sql/mysql/mysql-update.compiler.ts +379 -0
  556. package/src/core/common/persistence/sql/mysql/mysql-where.compiler.ts +686 -0
  557. package/src/core/common/persistence/sql/postgres/postgres-lock-store.ts +76 -0
  558. package/src/core/common/persistence/sql/postgres/postgres-schema.compiler.ts +328 -0
  559. package/src/core/common/persistence/sql/postgres/postgres-schema.migrator.ts +448 -0
  560. package/src/core/common/persistence/sql/postgres/postgres-update.compiler.ts +310 -0
  561. package/src/core/common/persistence/sql/postgres/postgres-where.compiler.ts +638 -0
  562. package/src/core/common/persistence/sql/sql-cast.ts +227 -0
  563. package/src/core/common/persistence/sql/sql-data-store.ts +762 -0
  564. package/src/core/common/persistence/sql/sql-dialect.ts +85 -0
  565. package/src/core/common/persistence/sql/sql-errors.ts +49 -0
  566. package/src/core/common/persistence/sql/sql-executor.factory.ts +282 -0
  567. package/src/core/common/persistence/sql/sql-executor.interface.ts +57 -0
  568. package/src/core/common/persistence/sql/sql-naming.ts +133 -0
  569. package/src/core/common/persistence/sql/sql-schema.shared.ts +105 -0
  570. package/src/core/common/persistence/sql/sql-session.ts +158 -0
  571. package/src/core/common/persistence/sql/where-shared.ts +118 -0
  572. package/src/core/common/persistence/store-guards.ts +73 -0
  573. package/src/core/common/persistence/store-upsert.ts +36 -0
  574. package/src/core/common/persistence/unavailable-store.ts +63 -0
  575. package/src/core/common/persistence/unsupported-capability.error.ts +7 -0
  576. package/src/core/common/plugins/mongoose-audit-fields.plugin.ts +33 -74
  577. package/src/core/common/plugins/mongoose-id.plugin.ts +9 -0
  578. package/src/core/common/plugins/mongoose-password.plugin.ts +6 -62
  579. package/src/core/common/plugins/mongoose-role-guard.plugin.ts +11 -63
  580. package/src/core/common/plugins/mongoose-system-role.plugin.ts +7 -78
  581. package/src/core/common/plugins/mongoose-tenant.plugin.ts +23 -144
  582. package/src/core/common/scalars/upload.scalar.ts +8 -3
  583. package/src/core/common/services/core-cron-jobs.initializer.ts +1 -1
  584. package/src/core/common/services/core-cron-jobs.service.ts +33 -22
  585. package/src/core/common/services/crud.service.ts +166 -35
  586. package/src/core/common/services/model-doc.service.ts +1 -1
  587. package/src/core/common/services/module.service.ts +78 -6
  588. package/src/core/common/types/field-selection.type.ts +1 -1
  589. package/src/core/common/types/id.type.ts +2 -2
  590. package/src/core/common/types/object-id-like.type.ts +11 -0
  591. package/src/core/common/types/populate-config.type.ts +1 -1
  592. package/src/core/common/types/string-or-object-id.type.ts +2 -2
  593. package/src/core/modules/ai/README.md +15 -2
  594. package/src/core/modules/ai/core-ai.constants.ts +10 -0
  595. package/src/core/modules/ai/core-ai.module.ts +32 -17
  596. package/src/core/modules/ai/models/core-ai-budget-limit.model.ts +2 -2
  597. package/src/core/modules/ai/models/core-ai-connection-preference.model.ts +2 -2
  598. package/src/core/modules/ai/models/core-ai-connection.model.ts +2 -2
  599. package/src/core/modules/ai/models/core-ai-conversation.model.ts +8 -4
  600. package/src/core/modules/ai/models/core-ai-interaction.model.ts +3 -3
  601. package/src/core/modules/ai/models/core-ai-mcp-oauth.models.ts +46 -0
  602. package/src/core/modules/ai/models/core-ai-mode.model.ts +2 -2
  603. package/src/core/modules/ai/models/core-ai-prompt-hint.model.ts +2 -2
  604. package/src/core/modules/ai/models/core-ai-prompt.model.ts +2 -2
  605. package/src/core/modules/ai/models/core-ai-slot.model.ts +2 -2
  606. package/src/core/modules/ai/models/core-ai-tool-grant.model.ts +2 -2
  607. package/src/core/modules/ai/models/core-ai-tool-policy.model.ts +2 -2
  608. package/src/core/modules/ai/services/core-ai-budget.service.ts +22 -4
  609. package/src/core/modules/ai/services/core-ai-connection-preference.service.ts +6 -13
  610. package/src/core/modules/ai/services/core-ai-connection.service.ts +34 -44
  611. package/src/core/modules/ai/services/core-ai-conversation.service.ts +31 -29
  612. package/src/core/modules/ai/services/core-ai-interaction.service.ts +3 -3
  613. package/src/core/modules/ai/services/core-ai-mcp-oauth.service.ts +93 -20
  614. package/src/core/modules/ai/services/core-ai-mode.service.ts +3 -6
  615. package/src/core/modules/ai/services/core-ai-prompt-hint.service.ts +43 -26
  616. package/src/core/modules/ai/services/core-ai-prompt.service.ts +15 -12
  617. package/src/core/modules/ai/services/core-ai-slot.service.ts +20 -24
  618. package/src/core/modules/ai/services/core-ai-tool-grant.service.ts +17 -27
  619. package/src/core/modules/ai/services/core-ai-tool-policy.service.ts +7 -10
  620. package/src/core/modules/api-token/core-api-token.model.ts +1 -1
  621. package/src/core/modules/api-token/core-api-token.module.ts +4 -2
  622. package/src/core/modules/api-token/core-api-token.service.ts +118 -43
  623. package/src/core/modules/auth/core-auth.module.ts +2 -0
  624. package/src/core/modules/auth/guards/legacy-auth-rate-limit.guard.ts +4 -3
  625. package/src/core/modules/auth/guards/role-guard.token.ts +7 -0
  626. package/src/core/modules/auth/services/core-auth.service.ts +16 -2
  627. package/src/core/modules/better-auth/INTEGRATION-CHECKLIST.md +1 -1
  628. package/src/core/modules/better-auth/README.md +10 -1
  629. package/src/core/modules/better-auth/better-auth-sql.helper.ts +191 -0
  630. package/src/core/modules/better-auth/better-auth-token.service.ts +26 -35
  631. package/src/core/modules/better-auth/better-auth.config.ts +43 -7
  632. package/src/core/modules/better-auth/better-auth.types.ts +1 -1
  633. package/src/core/modules/better-auth/core-better-auth-api.middleware.ts +13 -1
  634. package/src/core/modules/better-auth/core-better-auth-challenge.service.ts +36 -18
  635. package/src/core/modules/better-auth/core-better-auth-mongo.users.ts +35 -0
  636. package/src/core/modules/better-auth/core-better-auth-sql.registry.ts +20 -0
  637. package/src/core/modules/better-auth/core-better-auth-sql.store.ts +309 -0
  638. package/src/core/modules/better-auth/core-better-auth-user.mapper.ts +418 -40
  639. package/src/core/modules/better-auth/core-better-auth.module.ts +71 -35
  640. package/src/core/modules/better-auth/core-better-auth.service.ts +81 -12
  641. package/src/core/modules/file/README.md +16 -3
  642. package/src/core/modules/file/core-file-info.model.ts +2 -2
  643. package/src/core/modules/file/core-file.service.ts +27 -18
  644. package/src/core/modules/file/file-metadata.helper.ts +7 -3
  645. package/src/core/modules/file/file-metadata.models.ts +44 -0
  646. package/src/core/modules/file/file-metadata.store.ts +109 -0
  647. package/src/core/modules/file/file-storage.helper.ts +47 -2
  648. package/src/core/modules/file/filesystem-file.helper.ts +11 -8
  649. package/src/core/modules/file/s3-file.helper.ts +11 -7
  650. package/src/core/modules/health-check/core-health-check.module.ts +16 -2
  651. package/src/core/modules/health-check/core-health-check.service.ts +25 -3
  652. package/src/core/modules/hub/README.md +20 -11
  653. package/src/core/modules/hub/core-hub.controller.ts +5 -0
  654. package/src/core/modules/hub/core-hub.service.ts +1 -1
  655. package/src/core/modules/hub/helpers/hub-client-js.helper.ts +23 -0
  656. package/src/core/modules/hub/hub-action-messages.ts +6 -0
  657. package/src/core/modules/hub/hub-nav.ts +1 -0
  658. package/src/core/modules/hub/interfaces/hub-panels.interface.ts +8 -1
  659. package/src/core/modules/hub/services/core-hub-db.service.ts +35 -17
  660. package/src/core/modules/hub/services/core-hub-migrations.service.ts +96 -2
  661. package/src/core/modules/hub/services/core-hub-sources.service.ts +47 -1
  662. package/src/core/modules/hub/services/hub-query-profiler.service.ts +1 -1
  663. package/src/core/modules/migrate/README.md +54 -0
  664. package/src/core/modules/migrate/cli/migrate-cli.ts +44 -3
  665. package/src/core/modules/migrate/index.ts +3 -0
  666. package/src/core/modules/migrate/migration-runner.ts +3 -2
  667. package/src/core/modules/migrate/migration-state-store.interface.ts +24 -0
  668. package/src/core/modules/migrate/migration.helper.ts +35 -10
  669. package/src/core/modules/migrate/mongo-state-store.ts +64 -65
  670. package/src/core/modules/migrate/sql-migration.helper.ts +48 -0
  671. package/src/core/modules/migrate/sql-state-store.ts +198 -0
  672. package/src/core/modules/system-setup/README.md +14 -2
  673. package/src/core/modules/system-setup/core-system-setup.service.ts +77 -45
  674. package/src/core/modules/tenant/README.md +9 -2
  675. package/src/core/modules/tenant/core-tenant-member.model.ts +1 -1
  676. package/src/core/modules/tenant/core-tenant-member.store.ts +13 -0
  677. package/src/core/modules/tenant/core-tenant.guard.ts +77 -24
  678. package/src/core/modules/tenant/core-tenant.module.ts +6 -3
  679. package/src/core/modules/tenant/core-tenant.service.ts +59 -42
  680. package/src/core/modules/tus/core-tus.service.ts +11 -12
  681. package/src/core/modules/tus/tus.module.ts +1 -1
  682. package/src/core/modules/user/core-user.model.ts +2 -2
  683. package/src/core/modules/user/core-user.service.ts +98 -20
  684. package/src/core.module.ts +60 -5
  685. package/src/index.ts +26 -0
  686. package/src/server/common/models/persistence.model.ts +4 -4
  687. package/src/server/modules/file/file-info.model.ts +1 -1
  688. package/src/server/modules/file/file.service.ts +1 -1
  689. package/src/server/modules/user/user.model.ts +10 -5
  690. package/src/server/modules/user/user.module.ts +9 -3
  691. package/src/server/modules/user/user.service.ts +9 -11
  692. package/src/test/test.helper.ts +2 -2
  693. package/src/types/graphql-upload.d.ts +10 -7
@@ -0,0 +1,107 @@
1
+ # Choosing a database
2
+
3
+ Since 12.1.0 a `@lenne.tech/nest-server` project stores its data in **MongoDB** (the default), in **PostgreSQL**, in
4
+ **MySQL 8.4 / MariaDB 11.8**, or in several of them, model by model. The framework's own modules (users, tenants, API
5
+ tokens, AI, file metadata, locks, migrations) run on each, behind one `CrudService` and one security pipeline;
6
+ Better-Auth runs on MongoDB and PostgreSQL. This document is the decision
7
+ procedure — for a developer starting a project and for an AI agent asked to set one up. Configuration details are in
8
+ `.claude/rules/configurable-features.md` (row "Data Sources"); the code rules in `.claude/rules/persistence.md`.
9
+
10
+ ## The procedure
11
+
12
+ Work through the steps in order; the first one that decides, decides.
13
+
14
+ 1. **An external requirement wins.** The customer's operations team runs one database, a hosting contract names one,
15
+ an existing system the project must read is one: take that database. Nothing below outweighs it.
16
+ 2. **PostgreSQL** when the data is relational or reported on — accounting, invoices, bookings, inventory,
17
+ anything with joins, sums across records or reports a finance team reads — or when **tenant isolation must be
18
+ enforced by the database itself**. On PostgreSQL every tenant-scoped table carries forced row-level security, so
19
+ a query that forgets its tenant returns nothing instead of every tenant's rows; MongoDB has the framework's two
20
+ application layers only.
21
+ 3. **MongoDB** (the default) for document-shaped data — nested content, free-form attributes, structures that change
22
+ per customer — and whenever the signals above are absent. An existing MongoDB project stays on MongoDB: moving
23
+ databases is a data migration, not a configuration change.
24
+ 4. **Both (hybrid)** only with a concrete reason, written down: e.g. the finance models in PostgreSQL while the
25
+ content stays in MongoDB. The cost is real — two databases to run, back up and monitor, no transaction across
26
+ them, references across them resolved in the application. Route per model with `database.models`.
27
+ 5. **MySQL / MariaDB** only when required by step 1. What a project gives up there, and has to write into its own
28
+ documentation:
29
+ - **Tenant isolation lives in the application only.** Neither database has row-level security: the store's
30
+ policies keep tenants apart, and a query through `store.native()`, `store.raw()` or a connection of the project's
31
+ own reaches every tenant's rows unless it filters by `tenantId` itself. The boot says so once per source. A
32
+ trigger-based write guard was measured and not built: it cost up to half of MariaDB's write throughput and left
33
+ the native read open.
34
+ - **Better-Auth does not run there yet:** keep the user model (`users`) on PostgreSQL or MongoDB
35
+ (`database.models`), or sign in through the legacy endpoints only. The boot refuses the combination.
36
+ - **An indexed text field holds at most 255 characters** (a longer value is refused with 400); every other text is
37
+ unbounded. Indexing an existing text field later is a type change, i.e. a reviewed migration.
38
+ - **Schema changes are not transactional:** MySQL commits every DDL statement on its own, so a failed change leaves
39
+ the statements before it applied; the next boot completes the rest.
40
+ 6. **No database** (`database: false`) for a stateless service: a gateway, a renderer, a worker that only talks to
41
+ other APIs.
42
+
43
+ When the signals are ambiguous, **ask** — and record the decision (database, SQL engine, date, reason) in the
44
+ project's `CLAUDE.md`, so the next developer or agent does not re-decide it.
45
+
46
+ ## The SQL engine
47
+
48
+ On every SQL database the framework compiles every query itself; the engine only carries the statements, so the
49
+ choice does not change behaviour, tables or security — switching later is configuration only (`database.sqlEngine`).
50
+ All three engines run on PostgreSQL, MySQL and MariaDB.
51
+
52
+ | Engine | When |
53
+ |---|---|
54
+ | **TypeORM** (default) | unless the team asks for another — the widest ecosystem |
55
+ | **Kysely** | the team writes typed SQL by hand in its own code and wants the builder it knows |
56
+ | **Drizzle** | the team already uses Drizzle elsewhere (pinned to an exact release candidate until 1.0 GA) |
57
+
58
+ Each engine is an optional peer dependency installed together with the database's driver (`pg`, or `mysql2` for MySQL
59
+ and MariaDB). Project code that uses an engine's native API (`store.native()`) is the one part that does not move with a
60
+ switch.
61
+
62
+ ## What a project installs
63
+
64
+ | Database | Packages |
65
+ |---|---|
66
+ | MongoDB | `mongoose`, `@nestjs/mongoose`, `mongodb` (optional peers since 12.1.0 — the starter declares them) |
67
+ | PostgreSQL | `pg` plus the engine (`typeorm`, `kysely` or `drizzle-orm`) — and **none** of MongoDB's packages (npm mode; a vendor-mode project keeps the three as `devDependencies`, because the vendored core imports their types) |
68
+ | MySQL / MariaDB | `mysql2` plus the engine — the same rule for MongoDB's packages as on PostgreSQL |
69
+
70
+ In **vendor mode** the core is the project's own source, and TypeScript resolves every package it names in an
71
+ `import()` — whatever database the project uses. A vendor project therefore declares `pg` (with `@types/pg`), `mysql2`,
72
+ `typeorm`, `kysely` and `drizzle-orm` (at least as `devDependencies`), or its build fails with TS2307. At runtime it loads only
73
+ what its configuration uses.
74
+ | Several | the sets combined |
75
+
76
+ A project on PostgreSQL alone declares its models with the framework's own decorators, imported from
77
+ `@lenne.tech/nest-server` rather than `@nestjs/mongoose` (`Schema`, `Prop`, `SchemaFactory`, `InjectModel`), and
78
+ registers them with `CorePersistenceModule.forFeature()`. The same file works on MongoDB unchanged.
79
+
80
+ ## Configuration in one line each
81
+
82
+ ```typescript
83
+ // MongoDB (default) — nothing to configure beyond `mongoose`
84
+ mongoose: { uri: 'mongodb://127.0.0.1/project' }
85
+
86
+ // PostgreSQL: the application role, and the owner role that migrates the schema
87
+ database: { url: 'postgres://app@db/project', ownerUrl: 'postgres://owner@db/project', sqlEngine: 'typeorm' }
88
+
89
+ // MySQL 8.4 or MariaDB 11.8: the scheme names the server (mysql:// or mariadb://)
90
+ database: { url: 'mysql://app@db/project', ownerUrl: 'mysql://owner@db/project' }
91
+
92
+ // Hybrid: PostgreSQL by default, these models in the project's MongoDB
93
+ database: { url: 'postgres://app@db/project', ownerUrl: '…', models: { Article: 'mongoose' } },
94
+ mongoose: { uri: 'mongodb://127.0.0.1/project' }
95
+
96
+ // No database
97
+ database: false
98
+ ```
99
+
100
+ PostgreSQL always runs with **two roles**: the owner creates and migrates the schema, the application role owns
101
+ nothing and has neither superuser nor `BYPASSRLS` — the boot refuses an application role that could bypass row-level
102
+ security. PostgreSQL 15 or newer.
103
+
104
+ MySQL and MariaDB run with **two accounts** too: the owner creates and migrates the schema and grants the application
105
+ account `SELECT, INSERT, UPDATE, DELETE` on the database once; the boot refuses an application account that may alter,
106
+ drop, index, trigger or grant — without row-level security, the tables and their constraints are what the store's
107
+ policies rely on. MySQL 8.4 / MariaDB 11.8 or newer, and the URL's scheme must name the server it reaches.
@@ -135,6 +135,31 @@ this.getNativeConnection(''); // throws Error
135
135
 
136
136
  ---
137
137
 
138
+ ## Native access on PostgreSQL (12.1.0+)
139
+
140
+ On a model routed to PostgreSQL there is no Mongoose model and no native collection: `getNativeCollection()` /
141
+ `getNativeConnection()` refuse, and so does every Mongoose data method of the model (`routed-model.guard.ts`). The data
142
+ store has the two native tiers instead, with the same mandatory, logged reason:
143
+
144
+ | Tier | API | What still protects the data |
145
+ |---|---|---|
146
+ | 2 | `this.dataStore.native(reason)` — the engine's own API (TypeORM `EntityManager`, Kysely, Drizzle), bound to the store's transaction | row-level security (same connection, tenant scope set), HTTP interceptors |
147
+ | 3 | `this.dataStore.raw(reason)` — raw SQL on that connection | row-level security, HTTP interceptors |
148
+
149
+ The framework's before-layer policies (tenant stamping, audit fields, password hashing, role guard, system roles) do
150
+ **not** run on tiers 2 and 3 — exactly as the Mongoose plugins do not run on the native MongoDB driver. Row-level
151
+ security does: a query without a tenant scope on a tenant-scoped table fails (42501 → 403) instead of reading every
152
+ tenant. Parameters only; a table or column name never comes from user input.
153
+
154
+ **On MySQL and MariaDB there is no row-level security** — tiers 2 and 3 have nothing below them but the HTTP
155
+ interceptors. A native or raw query on a tenant-scoped table reaches every tenant's rows unless it filters by
156
+ `tenantId` itself, and a native write is not stamped with a tenant. The boot warns once per source; the persistence
157
+ matrix asserts the difference (`native-api-tenant-refused`, DIFFERENT-BY-DESIGN for those columns).
158
+
159
+ Rules for all of it: `.claude/rules/persistence.md` → "Native access in three tiers".
160
+
161
+ ---
162
+
138
163
  ## Review Checklist
139
164
 
140
165
  When reviewing code (manual or AI), check for `.collection.` and `.db.collection(`:
@@ -150,4 +175,8 @@ When reviewing code (manual or AI), check for `.collection.` and `.db.collection
150
175
  → Are data being written?
151
176
  YES → Verify tenantId/audit is set manually.
152
177
  NO → Allowed (read-only).
178
+
179
+ 3. Is it store.native() / store.raw() on a MySQL or MariaDB source, on a tenant-scoped table?
180
+ → Every statement filters by tenantId (read) or sets it (write) itself — the database does not.
181
+ MISSING → Security violation: the query reaches every tenant. Use the store (tier 1).
153
182
  ```
@@ -18,8 +18,16 @@ used to **exact-pin**, to a vulnerable version:
18
18
  |---------|----------|------------------------------------------|
19
19
  | `ws` | [GHSA-96hv-2xvq-fx4p](https://github.com/advisories/GHSA-96hv-2xvq-fx4p) — high: memory-exhaustion DoS + uninitialized memory disclosure. Patched `>=8.21.0` | Older `@nestjs/graphql` releases declare `"ws": "8.20.1"` — an **exact pin**, not a caret. 13.4.5 pins `8.21.3`; 14.0.3, the version this framework declares since 12.0.0, pins `8.22.0` |
20
20
  | `js-yaml` | [GHSA-pm4m-ph32-ghv5](https://github.com/advisories/GHSA-pm4m-ph32-ghv5) — high: exponential parsing time in flow collections (DoS), patched `>=5.2.2`; [GHSA-r3ph-w7gj-g6xm](https://github.com/advisories/GHSA-r3ph-w7gj-g6xm) — moderate: `maxTotalMergeKeys` does not bound CPU use for empty merge sources, covers `<=5.4.0`, patched `>=5.4.1` (published 2026-09-29) | `@nestjs/swagger` declares js-yaml as an **exact pin**, the same shape as the `ws` case: older releases `5.2.1`, 11.4.7 — the newest 11.x — `5.3.0`, which no 11.x update moves, so the entry is **load-bearing on @nestjs/swagger 11**. 12.0.3, the version this framework declares since 12.0.0, pins `5.5.0`, which clears both advisories: on @nestjs/swagger 12 the entry is inert |
21
- | `@graphql-tools/utils` | [GHSA-7mx3-vvmw-hjmv](https://github.com/advisories/GHSA-7mx3-vvmw-hjmv) — high: prototype pollution in `mergeDeep`, which runs while the GraphQL schema is assembled. Covers `<=12.0.0`, patched `>=12.0.1` (added 2026-10-06); [GHSA-c4qx-w738-7hr3](https://github.com/advisories/GHSA-c4qx-w738-7hr3) — high: prototype pollution in `mergeIncrementalResult` via non-primitive path segments. Covers `>=10.10.1 <=12.0.1`, patched `>=12.0.2` (published 2026-10-22) | `@nestjs/graphql` declares utils as an **exact pin**: 13.4.5 — the newest 13.x — `12.0.0`, and 14.0.3, the version this framework declares since 12.0.0, `12.0.1`. 12.0.1 clears the first advisory and is covered by the second, so **this entry is load-bearing on both majors**. `@apollo/server` reaches utils too, through `@graphql-tools/schema` / `merge` — and in a lockfile that still holds schema 10.0.x (resolved before 2026-08-12), as **utils 11.x**: vulnerable too, with no 11.x fix, and outside the override key. Lift it with `pnpm update --depth Infinity @graphql-tools/schema @graphql-tools/merge`; the current releases request utils `^12.1.0`, which needs Node >=22.15 — the framework's own floor since 11.42.10 |
22
- | `multer` | [GHSA-wc9g-mqfw-jrwm](https://github.com/advisories/GHSA-wc9g-mqfw-jrwm), [GHSA-535w-7cp7-47q4](https://github.com/advisories/GHSA-535w-7cp7-47q4), [GHSA-qfvm-cv95-jqjf](https://github.com/advisories/GHSA-qfvm-cv95-jqjf) — high: DoS via crafted multipart input; [GHSA-qvfw-j98x-7q72](https://github.com/advisories/GHSA-qvfw-j98x-7q72) — low: file size limit bypass. Patched `>=2.3.0`; [GHSA-q7qp-rjg7-q26m](https://github.com/advisories/GHSA-q7qp-rjg7-q26m) — high: DoS via a pending asynchronous `fileFilter` after request teardown. Covers `>=2.0.0 <2.5.0`, patched `>=2.5.0` (published 2026-10-22) | `@nestjs/platform-express` declares multer as an **exact pin**: up to 11.2.5 `2.2.0`, 11.2.6 / 11.2.7 `2.4.0`, and so does 12.2.0 — the version this framework declares since 12.0.0, and the newest 12.x. 2.4.0 is covered by GHSA-q7qp-rjg7-q26m, so **this entry is load-bearing again**. A direct `multer` dependency does not move the pin: you get both copies, and FileInterceptor uses the vulnerable one |
21
+ | `@graphql-tools/utils` | [GHSA-7mx3-vvmw-hjmv](https://github.com/advisories/GHSA-7mx3-vvmw-hjmv) — high: prototype pollution in `mergeDeep`, which runs while the GraphQL schema is assembled. Covers `<=12.0.0`, patched `>=12.0.1` (added 2026-10-06); [GHSA-c4qx-w738-7hr3](https://github.com/advisories/GHSA-c4qx-w738-7hr3) — high: prototype pollution in `mergeIncrementalResult` via non-primitive path segments. Covers `>=10.10.1 <=12.0.1`, patched `>=12.0.2` (published 2026-10-22) | `@nestjs/graphql` declares utils as an **exact pin**: 13.4.5 — the newest 13.x — `12.0.0`, and 14.0.3, the version this framework declares since 12.0.0, `12.0.1`. 12.0.1 clears the first advisory and is covered by the second, so **this entry is load-bearing on 13.x and on 14.0.x**. 14.1.0, the version this framework declares since 12.1.0, pins `12.1.0`, which clears both: there the entry is inert. `@apollo/server` reaches utils too, through `@graphql-tools/schema` / `merge` — and in a lockfile that still holds schema 10.0.x (resolved before 2026-08-12), as **utils 11.x**: vulnerable too, with no 11.x fix, and outside the override key. Lift it with `pnpm update --depth Infinity @graphql-tools/schema @graphql-tools/merge`; the current releases request utils `^12.1.0`, which needs Node >=22.15 — the framework's own floor since 11.42.10 |
22
+ | `multer` | [GHSA-wc9g-mqfw-jrwm](https://github.com/advisories/GHSA-wc9g-mqfw-jrwm), [GHSA-535w-7cp7-47q4](https://github.com/advisories/GHSA-535w-7cp7-47q4), [GHSA-qfvm-cv95-jqjf](https://github.com/advisories/GHSA-qfvm-cv95-jqjf) — high: DoS via crafted multipart input; [GHSA-qvfw-j98x-7q72](https://github.com/advisories/GHSA-qvfw-j98x-7q72) — low: file size limit bypass. Patched `>=2.3.0`; [GHSA-q7qp-rjg7-q26m](https://github.com/advisories/GHSA-q7qp-rjg7-q26m) — high: DoS via a pending asynchronous `fileFilter` after request teardown. Covers `>=2.0.0 <2.5.0`, patched `>=2.5.0` (published 2026-10-22) | `@nestjs/platform-express` declares multer as an **exact pin**: up to 11.2.5 `2.2.0`, 11.2.6 / 11.2.7 `2.4.0`, and so does 12.2.0, the version this framework declared in 12.0.x. 2.4.0 is covered by GHSA-q7qp-rjg7-q26m, so **this entry is load-bearing up to @nestjs/platform-express 12.2.0**. 12.3.2, the version this framework declares since 12.1.0, pins `2.5.0`: there the entry is inert. A direct `multer` dependency does not move the pin: you get both copies, and FileInterceptor uses the vulnerable one |
23
+
24
+ **Status since 12.1.0** (verified 2026-10-29): with the `@nestjs/*` versions this framework declares, **no
25
+ entry is needed**. `@nestjs/platform-express` 12.3.2 pins `multer` 2.5.0 and `@nestjs/graphql` 14.1.0 pins
26
+ `@graphql-tools/utils` 12.1.0, both past their advisories, and nest-server's own `overrides:` block is empty:
27
+ a fresh resolve of its tree with and without the two entries below yields the same packages and the same
28
+ audit. Raise your project's `@nestjs/*` pins to the framework's (`pnpm run update` does it), then remove both
29
+ entries — an inert entry is not insurance, `pnpm audit` reports a regression the day it happens. Keep them
30
+ only while your project still pins `@nestjs/platform-express` below 12.3.2 or `@nestjs/graphql` below 14.1.0.
23
31
 
24
32
  **Status since 12.0.0** (`@nestjs/*` 12, verified 2026-10-24): `multer` is load-bearing again
25
33
  (GHSA-q7qp-rjg7-q26m covers the `2.4.0` that `@nestjs/platform-express` 12.2.0 pins) and so is
@@ -54,8 +62,9 @@ entries. None of them is optional in practice.
54
62
  ## The fix
55
63
 
56
64
  Add this to your project's `pnpm-workspace.yaml` (pnpm 11+; in pnpm 10 and earlier it lives under
57
- `pnpm.overrides` in `package.json`). On nest-server **12.x** these two entries are all it takes — a fresh
58
- resolve of nest-server 12.0.0's own tree with and without every other former entry audits identically:
65
+ `pnpm.overrides` in `package.json`). On nest-server **12.0.x** these two entries are all it takes — a fresh
66
+ resolve of nest-server 12.0.0's own tree with and without every other former entry audits identically. On
67
+ **12.1.x** neither is needed once your `@nestjs/*` pins match the framework's (see "Status since 12.1.0"):
59
68
 
60
69
  ```yaml
61
70
  overrides:
@@ -63,7 +72,7 @@ overrides:
63
72
  # patched >=2.3.0), 2.4.0 in 11.2.6 / 11.2.7 / 12.2.0 — GHSA-q7qp-rjg7-q26m (high, patched >=2.5.0).
64
73
  # LOAD-BEARING again since nest-server 12.0.0: the key must reach the exact 2.4.0 pin.
65
74
  # Keep the target in LOCKSTEP with the multer version @lenne.tech/nest-server declares (2.5.0 since 12.0.0).
66
- # Remove once @nestjs/platform-express pins >=2.5.0 itself.
75
+ # Remove once @nestjs/platform-express pins >=2.5.0 itself — 12.3.2 does (nest-server 12.1.0).
67
76
  'multer@>=2.0.0 <2.5.0': '2.5.0'
68
77
 
69
78
  # @nestjs/graphql exact-pins @graphql-tools/utils — 13.4.5: 12.0.0 (GHSA-7mx3-vvmw-hjmv, high, patched
@@ -76,7 +85,7 @@ overrides:
76
85
  # below 22.15 has no patched utils at all — raise Node.
77
86
  # Does NOT reach a utils 11.x pulled in by an older @graphql-tools/schema 10.0.x — refresh that one instead:
78
87
  # pnpm update --depth Infinity @graphql-tools/schema @graphql-tools/merge
79
- # Remove once @nestjs/graphql pins >=12.0.2 in the major you use.
88
+ # Remove once @nestjs/graphql pins >=12.0.2 in the major you use — 14.1.0 does (nest-server 12.1.0).
80
89
  '@graphql-tools/utils@>=12.0.0 <12.1.0': '12.1.0'
81
90
  ```
82
91
 
@@ -0,0 +1,255 @@
1
+ # Migration Guide: 12.0.x → 12.1.x
2
+
3
+ ## This MINOR contains breaking changes
4
+
5
+ Per `.claude/rules/versioning.md` the MAJOR digit mirrors NestJS, so a breaking change ships as a MINOR. 12.1.0 is
6
+ one: **`mongoose`, `@nestjs/mongoose` and `mongodb` become optional peer dependencies** (§2). A MongoDB project keeps
7
+ working once it declares them itself — which a starter-based project already does for two of the three.
8
+
9
+ 12.1.0 makes the framework **database-agnostic**: a project keeps its data in MongoDB (the default, unchanged), in
10
+ **PostgreSQL**, in **MySQL 8.4 / MariaDB 11.8** (§7), or in several of them, model by model. The framework's own
11
+ modules — users, Better-Auth, tenants, API tokens, the AI module, file metadata, locks, migrations, health check, Hub —
12
+ run on MongoDB and PostgreSQL behind one `CrudService` and one security pipeline, and the whole e2e suite runs on both;
13
+ on MySQL and MariaDB everything but Better-Auth runs, proven by the parity matrices. A project that stays on MongoDB changes nothing but
14
+ its dependency list.
15
+
16
+ ## Overview
17
+
18
+ | Category | Details |
19
+ |---|---|
20
+ | **Breaking Changes** | `mongoose`, `@nestjs/mongoose`, `mongodb` are optional peers — declare them (§2). `CorePersistenceModule.forFeature()` provides the model tokens itself instead of importing `MongooseModule` (§6). A `database` URL without explicit `mongoose` config no longer opens the fallback MongoDB connection (§5). `graphql-upload` 17.1.0: an import of `graphql-upload/*.js` in project code stops working (§8) |
21
+ | **New Features** | PostgreSQL data sources with TypeORM, Kysely or Drizzle (§3); MySQL 8.4 / MariaDB 11.8 data sources on the same three engines (§7); per-model routing (`database.models`, `@PersistedModel`); the data store port (`DataStore`, `@InjectStore()`); Better-Auth on PostgreSQL; framework-owned schema evolution and SQL migrations (§4); model decorators usable without MongoDB (`Schema`, `Prop`, `SchemaFactory`, `InjectModel` from `@lenne.tech/nest-server`) (§2); `findAndCount({ samples })` on SQL |
22
+ | **Bugfixes** | Found while making every suite pass on both databases, all fixed on MongoDB too: a legacy logout kept the device's refresh token; with legacy JWTs and `multiTenancy` the tenant guard answered every tenant route with 401; the passkey challenge cookie was looked up under the wrong name; the system-setup refusal log names the claim's real location. Also: the legacy REST rate limit counted `/auth/signin?n=1`, `?n=2`, … in separate buckets and never stopped password guessing; it is keyed on the route handler now (also in 11.43.4). The fixes for `distinct()` over ObjectId fields and for first/last names lost at an IAM sign-in ship with this release too |
23
+ | **Migration Effort** | MongoDB project: add three dependencies and raise the `@nestjs/*` pins (§8). PostgreSQL: a new project or a data move — see §3 |
24
+
25
+ ## Quick Migration (a MongoDB project)
26
+
27
+ ```bash
28
+ # npm mode: raise the framework and declare MongoDB's libraries yourself
29
+ pnpm add @lenne.tech/nest-server@12.1.0 mongoose@9.11.4 @nestjs/mongoose@12.0.0 mongodb@7.7.0
30
+
31
+ # raise the @nestjs/* pins to the ones this release is tested with (§8); a starter-based project: pnpm run update
32
+ pnpm run build
33
+ pnpm test
34
+ ```
35
+
36
+ Use the versions this release's `package.json` lists under `devDependencies` — they are the ones it is tested with.
37
+
38
+ **Vendor mode** (`src/core/` copied into the project): the vendored core names every SQL package in an `import()`,
39
+ which TypeScript resolves whatever database the project uses. Declare them, at least as `devDependencies`, or the
40
+ build fails with TS2307 — `mysql2` is new in this release:
41
+
42
+ ```bash
43
+ pnpm add -D pg@8.23.1 @types/pg@8.23.1 mysql2@3.24.6 typeorm@1.1.2 kysely@0.29.7 drizzle-orm@1.0.0-rc.5
44
+ ```
45
+
46
+ A starter-based project already declares `mongoose` and `@nestjs/mongoose` in `dependencies`; **move `mongodb` from
47
+ `devDependencies` to `dependencies`**, because Better-Auth's MongoDB adapter loads it at runtime.
48
+
49
+ ## 1. What changes for a MongoDB project
50
+
51
+ Nothing in behaviour. Every MongoDB code path is the one 12.0 ran: Mongoose models, the five Mongoose plugins, GridFS,
52
+ the 12.0 lock documents (an old and a new replica share them in a rolling deploy), the native collections. The new
53
+ security layer below the plugins — the **tenant row check**, which refuses a read result containing another tenant's
54
+ row with 403 — only refuses rows the tenant filter would already have removed, so a correct path never meets it.
55
+
56
+ ## 2. MongoDB's libraries are optional peers
57
+
58
+ `@lenne.tech/nest-server` no longer installs `mongoose`, `@nestjs/mongoose` and `mongodb`. A project that keeps data in
59
+ MongoDB declares them (Quick Migration above); one on PostgreSQL alone installs none of them, and the framework loads,
60
+ boots and runs without them — proven on every release by `pnpm run check:without-mongodb` against the build. A
61
+ vendor-mode project on PostgreSQL keeps the three as `devDependencies`: the vendored core is compiled as the project's
62
+ own source and imports their types, so `tsc` needs them, while the running server loads none of them.
63
+
64
+ What a missing package looks like: a named `MongoPackagesMissingError` at boot, saying which feature needs MongoDB
65
+ (the `mongoose` configuration, GridFS, Better-Auth on MongoDB, a MongoDB migration) and what to install. Only one of
66
+ `mongoose` / `@nestjs/mongoose` installed is refused the same way.
67
+
68
+ **Model files.** A project that wants its models to work on either database imports the decorators from the framework
69
+ instead of `@nestjs/mongoose` — same names, same options:
70
+
71
+ ```typescript
72
+ // Before (MongoDB only)
73
+ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
74
+ // After (MongoDB and PostgreSQL)
75
+ import { Prop, Schema, SchemaFactory } from '@lenne.tech/nest-server';
76
+ ```
77
+
78
+ Where Mongoose is installed they apply `@nestjs/mongoose`'s decorators exactly as before; where it is not, they record
79
+ the declaration, and the framework builds the same model description from it. Also available: `InjectModel`,
80
+ `InjectConnection`, `getModelToken`, `getConnectionToken`, `raw`, `createSchema` (an inline schema), `objectIdType()`
81
+ (the ObjectId field type), `newObjectId()`, `isValidObjectId()`. Free-form fields are declared `{ type: Object }`
82
+ (Mongoose stores that as `Mixed`) rather than `Schema.Types.Mixed`.
83
+
84
+ `@InjectConnection()` receives `null` where no MongoDB is configured.
85
+
86
+ ## 3. PostgreSQL
87
+
88
+ ```typescript
89
+ // config.env.ts
90
+ database: {
91
+ url: 'postgres://app_role@db/project', // the application role: owns nothing, no BYPASSRLS
92
+ ownerUrl: 'postgres://owner_role@db/project', // owns the schema, migrates it at boot
93
+ sqlEngine: 'typeorm', // or 'kysely' / 'drizzle'
94
+ },
95
+ ```
96
+
97
+ ```bash
98
+ pnpm add pg typeorm # or kysely / drizzle-orm@1.0.0-rc.5 — optional peers
99
+ ```
100
+
101
+ - **Only models registered with `CorePersistenceModule.forFeature()` are routed.** The framework's own models are; a
102
+ project's models move by replacing `MongooseModule.forFeature([...])` with `CorePersistenceModule.forFeature([...])`
103
+ (same definitions). A model registered with `MongooseModule.forFeature()` stays on MongoDB.
104
+ - **Per-model routing:** `database.models: { Article: 'mongoose' }` keeps a model in the project's MongoDB (configure
105
+ `mongoose` explicitly — it becomes the source `mongoose`), `@PersistedModel({ dataSource })` declares it in code.
106
+ - **Better-Auth follows the user model.** With the user model on PostgreSQL, Better-Auth runs there too: one `users`
107
+ row per user, its tables in snake_case. Nothing is copied from MongoDB — moving existing users is a data migration.
108
+ - **Tenant isolation in the database.** Every tenant-scoped table gets forced row-level security; a query without a
109
+ tenant scope fails (403) instead of reading every tenant. The application role must not be superuser, have
110
+ `BYPASSRLS`, own a framework table or be allowed to `TRUNCATE` one — the boot refuses it.
111
+ - **PostgreSQL 15+** (unique indexes are `NULLS NOT DISTINCT`, as MongoDB treats missing values).
112
+ - **Health check:** with `healthCheck.configs.database` every SQL source answers as `<key>:<source>`.
113
+ - **Hub:** a Persistence panel shows each model's source; the Migrations panel reads `lt_migrations`.
114
+
115
+ Choosing between the databases: `docs/choosing-a-database.md`.
116
+
117
+ ## 4. Schema evolution and SQL migrations
118
+
119
+ The framework creates and evolves the tables from the model descriptions at boot, as the owner role: new tables,
120
+ columns, indexes and grants are applied automatically. A change that could lose or reject data — a type change, a new
121
+ unique index, a rename collision, a table losing tenant isolation — stops the boot with the suggested statements:
122
+
123
+ ```bash
124
+ migrate create <name> --sql # a migration that runs SQL (runSqlMigration())
125
+ ```
126
+
127
+ `@UnifiedField({ renamedFrom: 'oldName' })` declares a renamed field. The migration state lives in `lt_migrations`
128
+ (`createMigrationStore(<owner URL>)`); the Hub refuses to run migrations while that table is empty and the MongoDB
129
+ collection still lists applied ones (a `migrate.js` still writing MongoDB).
130
+
131
+ ## 5. A `database` URL without `mongoose` configuration opens no MongoDB
132
+
133
+ Until 12.0, `CoreModule.forRoot()` merged a fallback `mongoose.uri` (`mongodb://localhost/nest-server-default`) into
134
+ every configuration and connected to it, whatever `database` said. Since 12.1.0 MongoDB is connected only when a source
135
+ uses it: `mongoose` configured explicitly, or `database` naming MongoDB, or `database` absent (today's single MongoDB).
136
+ A project that set `database` to PostgreSQL **and relied on the implicit fallback** for models registered with
137
+ `MongooseModule.forFeature()` configures `mongoose` explicitly — those models were on a database nobody configured.
138
+
139
+ ## 6. `CorePersistenceModule.forFeature()` provides the model tokens itself
140
+
141
+ It used to import `MongooseModule.forFeature()`. It now registers the same providers itself (the shape `@nestjs/mongoose`
142
+ uses: `connection.model(name, schema, collection)`, discriminators included) and exports `getModelToken(name)` plus the
143
+ store token. `@InjectModel()` keeps resolving. Without a MongoDB connection the model token is a stand-in whose data
144
+ methods refuse with a named error — a `CrudService` runs on the routed store either way. A test module that relied on
145
+ the re-exported `MongooseModule` imports `MongooseModule.forRoot()` itself, as before.
146
+
147
+ ## 7. MySQL and MariaDB
148
+
149
+ ```typescript
150
+ // config.env.ts — the scheme names the server the URL reaches: mysql:// or mariadb://
151
+ database: {
152
+ url: 'mysql://app_account@db/project', // the application account: SELECT, INSERT, UPDATE, DELETE only
153
+ ownerUrl: 'mysql://owner_account@db/project', // creates and migrates the schema, grants the application account
154
+ sqlEngine: 'typeorm', // or 'kysely' / 'drizzle'
155
+ },
156
+ ```
157
+
158
+ ```bash
159
+ pnpm add mysql2 typeorm # or kysely / drizzle-orm@1.0.0-rc.5 — optional peers
160
+ ```
161
+
162
+ The same models, routing and store as on PostgreSQL (§3, §4). What differs, and belongs in the project's own
163
+ documentation:
164
+
165
+ - **No row-level security.** Tenant isolation is the store's (the before-layer and the row check after every read).
166
+ A query through `store.native()`, `store.raw()` or a connection of the project's own reaches every tenant's rows
167
+ unless it filters by `tenantId` itself; the boot warns once per source.
168
+ - **Better-Auth is refused at boot** while the user model (`users`) lives on MySQL / MariaDB. Keep it on PostgreSQL or
169
+ MongoDB (`database.models: { User: '<source>' }`), or sign in through the legacy endpoints only.
170
+ - **An indexed text field holds at most 255 characters** (a longer value answers 400). Indexing an existing text field
171
+ later is a type change — a reviewed SQL migration. A lookup index over four or more text fields indexes a prefix of
172
+ each; such a unique index is refused.
173
+ - **Updates:** two operators on one path, or on a path and a path inside it, are refused — MongoDB's own rule.
174
+ - **Unique indexes:** a missing value counts as a value, as on MongoDB; a sparse unique index (or a partial one on
175
+ "field exists") lets records without the value through. Any other partial unique index stops the boot — MySQL has
176
+ no partial indexes, and a uniqueness checked nowhere must not look like one that holds.
177
+ - **Schema runs are not transactional:** MySQL commits every DDL statement on its own. A failed change leaves the
178
+ statements before it applied and names the one that failed; the next boot completes the rest. The same holds for
179
+ `runSqlMigration()` — write such a migration so it can run again.
180
+ - **The application account** may only read and write rows; the boot refuses one that may alter, drop, index, trigger
181
+ or grant, a server older than MySQL 8.4 / MariaDB 11.8, and a scheme that names the other server.
182
+ - Leases, migration state (`createMigrationStore(<owner URL>)`), the expiry sweep, health check and Hub work as on
183
+ PostgreSQL.
184
+
185
+ ## 8. Dependency pins, graphql-upload 17, overrides that can go
186
+
187
+ **Pins.** A project pins the NestJS packages exactly, so raise the ones this release is tested with. In a
188
+ starter-based project `pnpm run update` does it; it raises pins the project already declares and adds none.
189
+
190
+ | Section | Package | Version |
191
+ |---|---|---|
192
+ | `dependencies` | `@nestjs/common`, `@nestjs/core`, `@nestjs/platform-express` | 12.3.2 |
193
+ | `dependencies` | `@nestjs/graphql` | 14.1.0 |
194
+ | `dependencies` | `@nestjs/apollo` (if the project declares it) | 14.1.1 |
195
+ | `dependencies` | `@nestjs/swagger` | 12.0.5 |
196
+ | `devDependencies` | `@nestjs/testing` (must match `@nestjs/common`) | 12.3.2 |
197
+ | `devDependencies` | `@nestjs/cli` | 12.0.11 |
198
+ | `devDependencies` | `@nestjs/schematics` | 12.0.12 |
199
+
200
+ **graphql-upload 17.1.0** (from 15.0.2, as the 12.0 guide announced). graphql-upload 16+ is an ES module that
201
+ exports only `.mjs` deep paths. A project that takes the scalar from the framework
202
+ (`import { GraphQLUpload } from '@lenne.tech/nest-server'`, 12.0 guide §13) changes nothing. One that still
203
+ imports `graphql-upload/GraphQLUpload.js` from a `graphql-upload` dependency of its own switches to the framework
204
+ export now and removes that dependency: with two copies, the scalar refuses every upload as `Upload value invalid.`
205
+ In **vendor mode** the core imports `graphql-upload/GraphQLUpload.mjs` and `graphql-upload/graphqlUploadExpress.mjs`,
206
+ so the project's `graphql-upload` dependency must be 17.1.0, and the core's `graphql-upload.d.ts` declares only those
207
+ two paths.
208
+
209
+ **Overrides that can go.** 12.0 asked projects to mirror two security overrides (`docs/security-overrides.md`):
210
+ `@graphql-tools/utils` and `multer`. `@nestjs/graphql` 14.1.0 and `@nestjs/platform-express` 12.3.2 pin the patched
211
+ versions themselves, so once the pins above are raised both entries change nothing; remove them and confirm with
212
+ `pnpm audit`. Keep them only while the project pins `@nestjs/graphql` below 14.1.0 or `@nestjs/platform-express`
213
+ below 12.3.2. A `peerDependencyRules.allowedVersions` entry for `@types/express` under graphql-upload goes too:
214
+ graphql-upload 17 accepts `@types/express` 4 and 5.
215
+
216
+ ## Compatibility Notes
217
+
218
+ | Pattern | Status |
219
+ |---|---|
220
+ | Services extending `CrudService` with `@InjectModel()` | Compatible — the service follows its model's store |
221
+ | Direct `this.mainDbModel.find(…)` on a model routed to SQL | Refused with a named error; use `this.dataStore` |
222
+ | `Model.create()` / `findByIdAndUpdate().lean()` in hot paths (MongoDB) | Compatible; the store (`this.dataStore.insert()` / `updateById()`) is the neutral fast path |
223
+ | `getNativeCollection(reason)` / `getNativeConnection(reason)` | MongoDB only; on SQL `store.native(reason)` / `store.raw(reason)` (RLS still binds) |
224
+ | Custom Mongoose plugins on the connection | MongoDB only; their logic does not run on a SQL store |
225
+ | GridFS (`file.storage: 'gridfs'`) | MongoDB only; on a SQL default source the derived driver is `filesystem` (or `s3`) |
226
+ | `@nestjs/mongoose` decorators in project models | Compatible on MongoDB; switch to the framework's exports for PostgreSQL |
227
+
228
+ ## Troubleshooting
229
+
230
+ | Symptom | Cause | Fix |
231
+ |---|---|---|
232
+ | `MongoPackagesMissingError: … needs MongoDB, and its libraries are not installed` | A MongoDB feature is configured, the peers are missing | Install `mongoose`, `@nestjs/mongoose`, `mongodb` (Quick Migration) |
233
+ | `SchemaMigrationRequiredError` at boot | A schema change needs review | Write the suggested statements into `migrate create <name> --sql`, run it |
234
+ | Boot refuses the application role | Superuser, `BYPASSRLS`, owner of a framework table, or `TRUNCATE` right | Use a role that owns nothing; the owner goes into `ownerUrl` |
235
+ | `X.find() reaches MongoDB, but X is stored on postgres` | Code calls the Mongoose model of a model routed to SQL | Use `this.dataStore` / `@InjectStore()` |
236
+ | 403 on a tenant read on PostgreSQL | No tenant scope for a tenant-scoped table (RLS) | Run inside a request with a tenant, or as system work (`RequestContext.runWithBypassTenantGuard()`) |
237
+ | `Better-Auth cannot run on MySQL yet` at boot | The user model is routed to a MySQL / MariaDB source | Route `User` to PostgreSQL or MongoDB, or switch Better-Auth off |
238
+ | `The application account … holds ALTER, …` at boot | `database.url` connects as an account with schema rights | Connect as a DML-only account; the owner goes into `ownerUrl` |
239
+ | `Updating the path "…" would create a conflict` on MySQL | Two update operators on one path | One operator per path, as on MongoDB |
240
+ | 400 `a value is longer than its column allows` on MySQL | A text field in an index got more than 255 characters | Shorten the value, or leave the field out of the index |
241
+ | `ERR_PACKAGE_PATH_NOT_EXPORTED: … './GraphQLUpload.js'` (or TS2307 on that path) | Project code imports `graphql-upload/*.js` and reached the framework's graphql-upload, now 17 | `import { GraphQLUpload } from '@lenne.tech/nest-server'` (§8) |
242
+
243
+ ## Module Documentation
244
+
245
+ - `docs/choosing-a-database.md` — which database, which engine
246
+ - `.claude/rules/persistence.md` — code rules (store, native tiers, optional MongoDB, hot paths)
247
+ - `.claude/rules/configurable-features.md` — row "Data Sources" (every option)
248
+ - `.claude/rules/better-auth.md` §11 — Better-Auth on a SQL source
249
+ - `src/core/modules/migrate/README.md` — SQL migrations and the state store
250
+ - `src/core/modules/system-setup/README.md` — the setup claim on PostgreSQL
251
+
252
+ ## References
253
+
254
+ - Plan and decisions: `.claude/plans/db-agnostic/PLAN.md` (framework repository)
255
+ - Reference project: [nest-server-starter](https://github.com/lenneTech/nest-server-starter)