@venizia/ignis-connectors 0.4.7 → 0.4.8-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 (480) hide show
  1. package/dist/esm/common/driver-data-source.js.map +1 -1
  2. package/dist/esm/common/internal/echo.js.map +1 -1
  3. package/dist/esm/common/scope-filter.d.ts +9 -0
  4. package/dist/esm/common/scope-filter.js +79 -3
  5. package/dist/esm/common/scope-filter.js.map +1 -1
  6. package/dist/esm/http/common/types.d.ts +8 -0
  7. package/dist/esm/http/common/types.js.map +1 -1
  8. package/dist/esm/http/common/wire.js.map +1 -1
  9. package/dist/esm/http/datasource.js.map +1 -1
  10. package/dist/esm/http/repository.d.ts +5 -1
  11. package/dist/esm/http/repository.js.map +1 -1
  12. package/dist/esm/relational/core/datasources/base.js.map +1 -1
  13. package/dist/esm/relational/core/datasources/common/types.d.ts +1 -0
  14. package/dist/esm/relational/core/datasources/common/types.js.map +1 -1
  15. package/dist/esm/relational/core/datasources/relation-pairing.js.map +1 -1
  16. package/dist/esm/relational/core/datasources/transaction-lifecycle.d.ts +2 -0
  17. package/dist/esm/relational/core/datasources/transaction-lifecycle.js +1 -0
  18. package/dist/esm/relational/core/datasources/transaction-lifecycle.js.map +1 -1
  19. package/dist/esm/relational/core/migrations/runner.d.ts +6 -1
  20. package/dist/esm/relational/core/migrations/runner.js.map +1 -1
  21. package/dist/esm/relational/core/models/base.js.map +1 -1
  22. package/dist/esm/relational/core/models/common/types.d.ts +10 -0
  23. package/dist/esm/relational/core/models/common/types.js +1 -0
  24. package/dist/esm/relational/core/models/common/types.js.map +1 -1
  25. package/dist/esm/relational/core/models/enrichers/audit-user.js.map +1 -1
  26. package/dist/esm/relational/core/models/factory.d.ts +14 -0
  27. package/dist/esm/relational/core/models/factory.js +14 -0
  28. package/dist/esm/relational/core/models/factory.js.map +1 -1
  29. package/dist/esm/relational/core/models/relations.d.ts +1 -0
  30. package/dist/esm/relational/core/models/relations.js +1 -0
  31. package/dist/esm/relational/core/models/relations.js.map +1 -1
  32. package/dist/esm/relational/core/repositories/common/executor.d.ts +8 -0
  33. package/dist/esm/relational/core/repositories/common/executor.js.map +1 -1
  34. package/dist/esm/relational/core/repositories/common/index.d.ts +0 -1
  35. package/dist/esm/relational/core/repositories/common/index.js +0 -1
  36. package/dist/esm/relational/core/repositories/common/index.js.map +1 -1
  37. package/dist/esm/relational/core/repositories/common/scope-through.d.ts +39 -0
  38. package/dist/esm/relational/core/repositories/common/scope-through.js +86 -0
  39. package/dist/esm/relational/core/repositories/common/scope-through.js.map +1 -0
  40. package/dist/esm/relational/core/repositories/common/scope-write-guard.d.ts +18 -5
  41. package/dist/esm/relational/core/repositories/common/scope-write-guard.js +34 -9
  42. package/dist/esm/relational/core/repositories/common/scope-write-guard.js.map +1 -1
  43. package/dist/esm/relational/core/repositories/common/shared.js.map +1 -1
  44. package/dist/esm/relational/core/repositories/common/types.d.ts +28 -1
  45. package/dist/esm/relational/core/repositories/common/types.js.map +1 -1
  46. package/dist/esm/relational/core/repositories/core/base.d.ts +20 -7
  47. package/dist/esm/relational/core/repositories/core/base.js +62 -5
  48. package/dist/esm/relational/core/repositories/core/base.js.map +1 -1
  49. package/dist/esm/relational/core/repositories/core/persistable.d.ts +120 -2
  50. package/dist/esm/relational/core/repositories/core/persistable.js +66 -6
  51. package/dist/esm/relational/core/repositories/core/persistable.js.map +1 -1
  52. package/dist/esm/relational/core/repositories/core/readable.d.ts +61 -2
  53. package/dist/esm/relational/core/repositories/core/readable.js +48 -2
  54. package/dist/esm/relational/core/repositories/core/readable.js.map +1 -1
  55. package/dist/esm/relational/core/repositories/core/soft-deletable.d.ts +39 -1
  56. package/dist/esm/relational/core/repositories/core/soft-deletable.js +49 -6
  57. package/dist/esm/relational/core/repositories/core/soft-deletable.js.map +1 -1
  58. package/dist/esm/relational/core/repositories/dialect/filter.d.ts +35 -5
  59. package/dist/esm/relational/core/repositories/dialect/filter.js +72 -17
  60. package/dist/esm/relational/core/repositories/dialect/filter.js.map +1 -1
  61. package/dist/esm/relational/core/repositories/dialect/internal/json-utils.d.ts +1 -0
  62. package/dist/esm/relational/core/repositories/dialect/internal/json-utils.js +1 -0
  63. package/dist/esm/relational/core/repositories/dialect/internal/json-utils.js.map +1 -1
  64. package/dist/esm/relational/core/repositories/dialect/query-operators.d.ts +35 -0
  65. package/dist/esm/relational/core/repositories/dialect/query-operators.js +80 -0
  66. package/dist/esm/relational/core/repositories/dialect/query-operators.js.map +1 -0
  67. package/dist/esm/relational/core/repositories/dialect/relations/create.d.ts +1 -0
  68. package/dist/esm/relational/core/repositories/dialect/relations/create.js +1 -0
  69. package/dist/esm/relational/core/repositories/dialect/relations/create.js.map +1 -1
  70. package/dist/esm/relational/core/repositories/dialect/relations/one.js.map +1 -1
  71. package/dist/esm/relational/core/repositories/sqls/recursive-tree.d.ts +2 -0
  72. package/dist/esm/relational/core/repositories/sqls/recursive-tree.js.map +1 -1
  73. package/dist/esm/relational/postgres/datasources/abstract.js.map +1 -1
  74. package/dist/esm/relational/postgres/datasources/base.d.ts +21 -0
  75. package/dist/esm/relational/postgres/datasources/base.js +21 -0
  76. package/dist/esm/relational/postgres/datasources/base.js.map +1 -1
  77. package/dist/esm/relational/postgres/datasources/common/types.d.ts +3 -0
  78. package/dist/esm/relational/postgres/datasources/common/types.js +1 -0
  79. package/dist/esm/relational/postgres/datasources/common/types.js.map +1 -1
  80. package/dist/esm/relational/postgres/drivers/node-postgres.d.ts +1 -0
  81. package/dist/esm/relational/postgres/drivers/node-postgres.js +1 -0
  82. package/dist/esm/relational/postgres/drivers/node-postgres.js.map +1 -1
  83. package/dist/esm/relational/postgres/drivers/pglite.js.map +1 -1
  84. package/dist/esm/relational/postgres/drivers/postgres-js.d.ts +1 -0
  85. package/dist/esm/relational/postgres/drivers/postgres-js.js +1 -0
  86. package/dist/esm/relational/postgres/drivers/postgres-js.js.map +1 -1
  87. package/dist/esm/relational/postgres/models/common/columns.js.map +1 -1
  88. package/dist/esm/relational/postgres/models/common/types/enrichers.d.ts +26 -1
  89. package/dist/esm/relational/postgres/models/common/types/enrichers.js.map +1 -1
  90. package/dist/esm/relational/postgres/models/common/types/table.d.ts +8 -0
  91. package/dist/esm/relational/postgres/models/common/types/table.js.map +1 -1
  92. package/dist/esm/relational/postgres/models/enrichers/data-type.enricher.d.ts +1 -0
  93. package/dist/esm/relational/postgres/models/enrichers/data-type.enricher.js +1 -0
  94. package/dist/esm/relational/postgres/models/enrichers/data-type.enricher.js.map +1 -1
  95. package/dist/esm/relational/postgres/models/enrichers/id.enricher.d.ts +16 -0
  96. package/dist/esm/relational/postgres/models/enrichers/id.enricher.js +15 -0
  97. package/dist/esm/relational/postgres/models/enrichers/id.enricher.js.map +1 -1
  98. package/dist/esm/relational/postgres/models/enrichers/principal.enricher.d.ts +1 -0
  99. package/dist/esm/relational/postgres/models/enrichers/principal.enricher.js +1 -0
  100. package/dist/esm/relational/postgres/models/enrichers/principal.enricher.js.map +1 -1
  101. package/dist/esm/relational/postgres/models/enrichers/tz.enricher.d.ts +18 -0
  102. package/dist/esm/relational/postgres/models/enrichers/tz.enricher.js +17 -0
  103. package/dist/esm/relational/postgres/models/enrichers/tz.enricher.js.map +1 -1
  104. package/dist/esm/relational/postgres/models/enrichers/user-audit.enricher.d.ts +2 -0
  105. package/dist/esm/relational/postgres/models/enrichers/user-audit.enricher.js +1 -0
  106. package/dist/esm/relational/postgres/models/enrichers/user-audit.enricher.js.map +1 -1
  107. package/dist/esm/relational/postgres/repositories/dialect/internal/json-path.js.map +1 -1
  108. package/dist/esm/relational/postgres/repositories/dialect/query.d.ts +9 -9
  109. package/dist/esm/relational/postgres/repositories/dialect/query.js +4 -60
  110. package/dist/esm/relational/postgres/repositories/dialect/query.js.map +1 -1
  111. package/dist/esm/relational/postgres/repositories/dialect/update.js.map +1 -1
  112. package/dist/esm/relational/postgres/repositories/executor.d.ts +1 -0
  113. package/dist/esm/relational/postgres/repositories/executor.js +3 -0
  114. package/dist/esm/relational/postgres/repositories/executor.js.map +1 -1
  115. package/dist/esm/relational/postgres/supabase/pooler.d.ts +3 -0
  116. package/dist/esm/relational/postgres/supabase/pooler.js +1 -0
  117. package/dist/esm/relational/postgres/supabase/pooler.js.map +1 -1
  118. package/dist/esm/relational/postgres/supabase/rls.d.ts +1 -0
  119. package/dist/esm/relational/postgres/supabase/rls.js +1 -0
  120. package/dist/esm/relational/postgres/supabase/rls.js.map +1 -1
  121. package/dist/esm/relational/sqlite/datasources/abstract.js.map +1 -1
  122. package/dist/esm/relational/sqlite/datasources/common/types.d.ts +1 -0
  123. package/dist/esm/relational/sqlite/datasources/common/types.js.map +1 -1
  124. package/dist/esm/relational/sqlite/drivers/libsql.js.map +1 -1
  125. package/dist/esm/relational/sqlite/models/common/types/enrichers.d.ts +23 -2
  126. package/dist/esm/relational/sqlite/models/common/types/enrichers.js.map +1 -1
  127. package/dist/esm/relational/sqlite/models/common/types/table.d.ts +8 -0
  128. package/dist/esm/relational/sqlite/models/common/types/table.js.map +1 -1
  129. package/dist/esm/relational/sqlite/models/enrichers/data-type.enricher.d.ts +1 -0
  130. package/dist/esm/relational/sqlite/models/enrichers/data-type.enricher.js +1 -0
  131. package/dist/esm/relational/sqlite/models/enrichers/data-type.enricher.js.map +1 -1
  132. package/dist/esm/relational/sqlite/models/enrichers/id.enricher.d.ts +2 -0
  133. package/dist/esm/relational/sqlite/models/enrichers/id.enricher.js +1 -0
  134. package/dist/esm/relational/sqlite/models/enrichers/id.enricher.js.map +1 -1
  135. package/dist/esm/relational/sqlite/models/enrichers/principal.enricher.d.ts +1 -0
  136. package/dist/esm/relational/sqlite/models/enrichers/principal.enricher.js +1 -0
  137. package/dist/esm/relational/sqlite/models/enrichers/principal.enricher.js.map +1 -1
  138. package/dist/esm/relational/sqlite/models/enrichers/tz.enricher.d.ts +2 -0
  139. package/dist/esm/relational/sqlite/models/enrichers/tz.enricher.js +1 -0
  140. package/dist/esm/relational/sqlite/models/enrichers/tz.enricher.js.map +1 -1
  141. package/dist/esm/relational/sqlite/models/enrichers/user-audit.enricher.d.ts +2 -0
  142. package/dist/esm/relational/sqlite/models/enrichers/user-audit.enricher.js +1 -0
  143. package/dist/esm/relational/sqlite/models/enrichers/user-audit.enricher.js.map +1 -1
  144. package/dist/esm/relational/sqlite/repositories/dialect/internal/json-path.js.map +1 -1
  145. package/dist/esm/relational/sqlite/repositories/dialect/query.d.ts +9 -9
  146. package/dist/esm/relational/sqlite/repositories/dialect/query.js +6 -63
  147. package/dist/esm/relational/sqlite/repositories/dialect/query.js.map +1 -1
  148. package/dist/esm/relational/sqlite/repositories/dialect/update.js.map +1 -1
  149. package/dist/esm/relational/sqlite/repositories/executor.d.ts +1 -0
  150. package/dist/esm/relational/sqlite/repositories/executor.js +1 -0
  151. package/dist/esm/relational/sqlite/repositories/executor.js.map +1 -1
  152. package/dist/esm/search/core/connector.d.ts +7 -0
  153. package/dist/esm/search/core/connector.js +1 -0
  154. package/dist/esm/search/core/connector.js.map +1 -1
  155. package/dist/esm/search/core/controllers/abstract.js.map +1 -1
  156. package/dist/esm/search/core/controllers/factory.js.map +1 -1
  157. package/dist/esm/search/core/controllers/scope.js.map +1 -1
  158. package/dist/esm/search/core/datasources/base.js.map +1 -1
  159. package/dist/esm/search/core/datasources/common/types.d.ts +6 -1
  160. package/dist/esm/search/core/datasources/common/types.js.map +1 -1
  161. package/dist/esm/search/core/internal/search-connector-internal.js.map +1 -1
  162. package/dist/esm/search/core/models/base.js.map +1 -1
  163. package/dist/esm/search/core/models/common/constants.d.ts +2 -0
  164. package/dist/esm/search/core/models/common/constants.js.map +1 -1
  165. package/dist/esm/search/core/models/common/types/collection.d.ts +2 -0
  166. package/dist/esm/search/core/models/common/types/collection.js.map +1 -1
  167. package/dist/esm/search/core/models/common/types/document.d.ts +3 -1
  168. package/dist/esm/search/core/models/common/types/document.js.map +1 -1
  169. package/dist/esm/search/core/models/common/types/embedding.d.ts +1 -0
  170. package/dist/esm/search/core/models/common/types/embedding.js.map +1 -1
  171. package/dist/esm/search/core/models/common/types/field.d.ts +8 -1
  172. package/dist/esm/search/core/models/common/types/field.js.map +1 -1
  173. package/dist/esm/search/core/models/define-search-collection.d.ts +2 -0
  174. package/dist/esm/search/core/models/define-search-collection.js +11 -1
  175. package/dist/esm/search/core/models/define-search-collection.js.map +1 -1
  176. package/dist/esm/search/core/models/zod-derivation.d.ts +3 -1
  177. package/dist/esm/search/core/models/zod-derivation.js +9 -3
  178. package/dist/esm/search/core/models/zod-derivation.js.map +1 -1
  179. package/dist/esm/search/core/repositories/common/constants.d.ts +5 -0
  180. package/dist/esm/search/core/repositories/common/constants.js +1 -0
  181. package/dist/esm/search/core/repositories/common/constants.js.map +1 -1
  182. package/dist/esm/search/core/repositories/common/dialect-helpers.d.ts +5 -1
  183. package/dist/esm/search/core/repositories/common/dialect-helpers.js +8 -4
  184. package/dist/esm/search/core/repositories/common/dialect-helpers.js.map +1 -1
  185. package/dist/esm/search/core/repositories/common/query-params.d.ts +1 -0
  186. package/dist/esm/search/core/repositories/common/query-params.js +1 -0
  187. package/dist/esm/search/core/repositories/common/query-params.js.map +1 -1
  188. package/dist/esm/search/core/repositories/common/types.d.ts +2 -0
  189. package/dist/esm/search/core/repositories/common/types.js.map +1 -1
  190. package/dist/esm/search/core/repositories/core/base.d.ts +21 -3
  191. package/dist/esm/search/core/repositories/core/base.js +41 -6
  192. package/dist/esm/search/core/repositories/core/base.js.map +1 -1
  193. package/dist/esm/search/core/repositories/core/persistable.d.ts +1 -1
  194. package/dist/esm/search/core/repositories/core/persistable.js +7 -7
  195. package/dist/esm/search/core/repositories/core/persistable.js.map +1 -1
  196. package/dist/esm/search/core/repositories/core/readable.d.ts +3 -3
  197. package/dist/esm/search/core/repositories/core/readable.js +10 -10
  198. package/dist/esm/search/core/repositories/core/readable.js.map +1 -1
  199. package/dist/esm/search/meilisearch/common/types.d.ts +15 -2
  200. package/dist/esm/search/meilisearch/common/types.js.map +1 -1
  201. package/dist/esm/search/meilisearch/compiler.d.ts +1 -0
  202. package/dist/esm/search/meilisearch/compiler.js +1 -0
  203. package/dist/esm/search/meilisearch/compiler.js.map +1 -1
  204. package/dist/esm/search/meilisearch/connector.js.map +1 -1
  205. package/dist/esm/search/meilisearch/internal/connector-internal.js.map +1 -1
  206. package/dist/esm/search/meilisearch/repositories/dialect/query-dialect.js +4 -2
  207. package/dist/esm/search/meilisearch/repositories/dialect/query-dialect.js.map +1 -1
  208. package/dist/esm/search/typesense/common/constants.d.ts +4 -0
  209. package/dist/esm/search/typesense/common/constants.js +2 -0
  210. package/dist/esm/search/typesense/common/constants.js.map +1 -1
  211. package/dist/esm/search/typesense/common/types/client.d.ts +2 -0
  212. package/dist/esm/search/typesense/common/types/client.js.map +1 -1
  213. package/dist/esm/search/typesense/common/types/options.d.ts +8 -1
  214. package/dist/esm/search/typesense/common/types/options.js.map +1 -1
  215. package/dist/esm/search/typesense/common/types/schema.d.ts +4 -0
  216. package/dist/esm/search/typesense/common/types/schema.js.map +1 -1
  217. package/dist/esm/search/typesense/common/types/search.d.ts +6 -0
  218. package/dist/esm/search/typesense/common/types/search.js.map +1 -1
  219. package/dist/esm/search/typesense/compiler.d.ts +1 -0
  220. package/dist/esm/search/typesense/compiler.js +1 -0
  221. package/dist/esm/search/typesense/compiler.js.map +1 -1
  222. package/dist/esm/search/typesense/connector.d.ts +3 -1
  223. package/dist/esm/search/typesense/connector.js.map +1 -1
  224. package/dist/esm/search/typesense/internal/connector-internal.js.map +1 -1
  225. package/dist/esm/search/typesense/internal/guards.js.map +1 -1
  226. package/dist/esm/search/typesense/internal/mappers.js.map +1 -1
  227. package/dist/esm/search/typesense/internal/pagination-windows.js.map +1 -1
  228. package/dist/esm/search/typesense/repositories/common/types.d.ts +19 -0
  229. package/dist/esm/search/typesense/repositories/common/types.js.map +1 -1
  230. package/dist/esm/search/typesense/repositories/dialect/query-dialect.js +69 -15
  231. package/dist/esm/search/typesense/repositories/dialect/query-dialect.js.map +1 -1
  232. package/dist/esm/testing/index.d.ts +1 -0
  233. package/dist/esm/testing/index.js +1 -0
  234. package/dist/esm/testing/index.js.map +1 -1
  235. package/dist/esm/testing/repository-double.d.ts +25 -0
  236. package/dist/esm/testing/repository-double.js +24 -0
  237. package/dist/esm/testing/repository-double.js.map +1 -0
  238. package/dist/esm/testing/transaction-double.d.ts +3 -0
  239. package/dist/esm/testing/transaction-double.js.map +1 -1
  240. package/package.json +7 -6
  241. package/dist/esm/common/driver-data-source.d.ts.map +0 -1
  242. package/dist/esm/common/driver.d.ts.map +0 -1
  243. package/dist/esm/common/index.d.ts.map +0 -1
  244. package/dist/esm/common/internal/echo.d.ts.map +0 -1
  245. package/dist/esm/common/internal/index.d.ts.map +0 -1
  246. package/dist/esm/common/internal/record.d.ts.map +0 -1
  247. package/dist/esm/common/scope-filter.d.ts.map +0 -1
  248. package/dist/esm/http/common/constants.d.ts.map +0 -1
  249. package/dist/esm/http/common/readers.d.ts.map +0 -1
  250. package/dist/esm/http/common/types.d.ts.map +0 -1
  251. package/dist/esm/http/common/wire.d.ts.map +0 -1
  252. package/dist/esm/http/datasource.d.ts.map +0 -1
  253. package/dist/esm/http/index.d.ts.map +0 -1
  254. package/dist/esm/http/repository.d.ts.map +0 -1
  255. package/dist/esm/index.d.ts.map +0 -1
  256. package/dist/esm/raw-sql/common/index.d.ts.map +0 -1
  257. package/dist/esm/raw-sql/common/types.d.ts.map +0 -1
  258. package/dist/esm/raw-sql/datasource.d.ts.map +0 -1
  259. package/dist/esm/raw-sql/index.d.ts.map +0 -1
  260. package/dist/esm/raw-sql/repository.d.ts.map +0 -1
  261. package/dist/esm/relational/core/datasources/abstract.d.ts.map +0 -1
  262. package/dist/esm/relational/core/datasources/base.d.ts.map +0 -1
  263. package/dist/esm/relational/core/datasources/common/guards.d.ts.map +0 -1
  264. package/dist/esm/relational/core/datasources/common/index.d.ts.map +0 -1
  265. package/dist/esm/relational/core/datasources/common/types.d.ts.map +0 -1
  266. package/dist/esm/relational/core/datasources/index.d.ts.map +0 -1
  267. package/dist/esm/relational/core/datasources/relation-pairing.d.ts.map +0 -1
  268. package/dist/esm/relational/core/datasources/transaction-lifecycle.d.ts.map +0 -1
  269. package/dist/esm/relational/core/drivers/driver.d.ts.map +0 -1
  270. package/dist/esm/relational/core/drivers/index.d.ts.map +0 -1
  271. package/dist/esm/relational/core/index.d.ts.map +0 -1
  272. package/dist/esm/relational/core/migrations/index.d.ts.map +0 -1
  273. package/dist/esm/relational/core/migrations/runner.d.ts.map +0 -1
  274. package/dist/esm/relational/core/models/base.d.ts.map +0 -1
  275. package/dist/esm/relational/core/models/common/constants.d.ts.map +0 -1
  276. package/dist/esm/relational/core/models/common/index.d.ts.map +0 -1
  277. package/dist/esm/relational/core/models/common/types.d.ts.map +0 -1
  278. package/dist/esm/relational/core/models/enrichers/audit-user.d.ts.map +0 -1
  279. package/dist/esm/relational/core/models/enrichers/index.d.ts.map +0 -1
  280. package/dist/esm/relational/core/models/factory.d.ts.map +0 -1
  281. package/dist/esm/relational/core/models/index.d.ts.map +0 -1
  282. package/dist/esm/relational/core/models/relations.d.ts.map +0 -1
  283. package/dist/esm/relational/core/repositories/common/constants.d.ts +0 -11
  284. package/dist/esm/relational/core/repositories/common/constants.d.ts.map +0 -1
  285. package/dist/esm/relational/core/repositories/common/constants.js +0 -10
  286. package/dist/esm/relational/core/repositories/common/constants.js.map +0 -1
  287. package/dist/esm/relational/core/repositories/common/executor.d.ts.map +0 -1
  288. package/dist/esm/relational/core/repositories/common/index.d.ts.map +0 -1
  289. package/dist/esm/relational/core/repositories/common/scope-filter.d.ts.map +0 -1
  290. package/dist/esm/relational/core/repositories/common/scope-write-guard.d.ts.map +0 -1
  291. package/dist/esm/relational/core/repositories/common/shared.d.ts.map +0 -1
  292. package/dist/esm/relational/core/repositories/common/types.d.ts.map +0 -1
  293. package/dist/esm/relational/core/repositories/core/base.d.ts.map +0 -1
  294. package/dist/esm/relational/core/repositories/core/default.d.ts.map +0 -1
  295. package/dist/esm/relational/core/repositories/core/index.d.ts.map +0 -1
  296. package/dist/esm/relational/core/repositories/core/persistable.d.ts.map +0 -1
  297. package/dist/esm/relational/core/repositories/core/readable.d.ts.map +0 -1
  298. package/dist/esm/relational/core/repositories/core/soft-deletable.d.ts.map +0 -1
  299. package/dist/esm/relational/core/repositories/dialect/filter.d.ts.map +0 -1
  300. package/dist/esm/relational/core/repositories/dialect/index.d.ts.map +0 -1
  301. package/dist/esm/relational/core/repositories/dialect/internal/index.d.ts.map +0 -1
  302. package/dist/esm/relational/core/repositories/dialect/internal/json-utils.d.ts.map +0 -1
  303. package/dist/esm/relational/core/repositories/dialect/internal/subquery.d.ts.map +0 -1
  304. package/dist/esm/relational/core/repositories/dialect/relations/common/constants.d.ts.map +0 -1
  305. package/dist/esm/relational/core/repositories/dialect/relations/common/index.d.ts.map +0 -1
  306. package/dist/esm/relational/core/repositories/dialect/relations/common/types.d.ts.map +0 -1
  307. package/dist/esm/relational/core/repositories/dialect/relations/create.d.ts.map +0 -1
  308. package/dist/esm/relational/core/repositories/dialect/relations/index.d.ts.map +0 -1
  309. package/dist/esm/relational/core/repositories/dialect/relations/many.d.ts.map +0 -1
  310. package/dist/esm/relational/core/repositories/dialect/relations/one.d.ts.map +0 -1
  311. package/dist/esm/relational/core/repositories/dialect/update.d.ts.map +0 -1
  312. package/dist/esm/relational/core/repositories/index.d.ts.map +0 -1
  313. package/dist/esm/relational/core/repositories/sqls/index.d.ts.map +0 -1
  314. package/dist/esm/relational/core/repositories/sqls/recursive-tree.d.ts.map +0 -1
  315. package/dist/esm/relational/postgres/datasources/abstract.d.ts.map +0 -1
  316. package/dist/esm/relational/postgres/datasources/base.d.ts.map +0 -1
  317. package/dist/esm/relational/postgres/datasources/common/guards.d.ts.map +0 -1
  318. package/dist/esm/relational/postgres/datasources/common/index.d.ts.map +0 -1
  319. package/dist/esm/relational/postgres/datasources/common/types.d.ts.map +0 -1
  320. package/dist/esm/relational/postgres/datasources/index.d.ts.map +0 -1
  321. package/dist/esm/relational/postgres/drivers/driver.d.ts.map +0 -1
  322. package/dist/esm/relational/postgres/drivers/index.d.ts.map +0 -1
  323. package/dist/esm/relational/postgres/drivers/node-postgres.d.ts.map +0 -1
  324. package/dist/esm/relational/postgres/drivers/pglite.d.ts.map +0 -1
  325. package/dist/esm/relational/postgres/drivers/postgres-js.d.ts.map +0 -1
  326. package/dist/esm/relational/postgres/index.d.ts.map +0 -1
  327. package/dist/esm/relational/postgres/models/base.d.ts.map +0 -1
  328. package/dist/esm/relational/postgres/models/common/columns.d.ts.map +0 -1
  329. package/dist/esm/relational/postgres/models/common/constants.d.ts.map +0 -1
  330. package/dist/esm/relational/postgres/models/common/index.d.ts.map +0 -1
  331. package/dist/esm/relational/postgres/models/common/types/enrichers.d.ts.map +0 -1
  332. package/dist/esm/relational/postgres/models/common/types/index.d.ts.map +0 -1
  333. package/dist/esm/relational/postgres/models/common/types/table.d.ts.map +0 -1
  334. package/dist/esm/relational/postgres/models/enrichers/data-type.enricher.d.ts.map +0 -1
  335. package/dist/esm/relational/postgres/models/enrichers/id.enricher.d.ts.map +0 -1
  336. package/dist/esm/relational/postgres/models/enrichers/index.d.ts.map +0 -1
  337. package/dist/esm/relational/postgres/models/enrichers/principal.enricher.d.ts.map +0 -1
  338. package/dist/esm/relational/postgres/models/enrichers/tz.enricher.d.ts.map +0 -1
  339. package/dist/esm/relational/postgres/models/enrichers/user-audit.enricher.d.ts.map +0 -1
  340. package/dist/esm/relational/postgres/models/index.d.ts.map +0 -1
  341. package/dist/esm/relational/postgres/repositories/common/index.d.ts.map +0 -1
  342. package/dist/esm/relational/postgres/repositories/common/shared.d.ts.map +0 -1
  343. package/dist/esm/relational/postgres/repositories/common/types.d.ts.map +0 -1
  344. package/dist/esm/relational/postgres/repositories/core/base.d.ts.map +0 -1
  345. package/dist/esm/relational/postgres/repositories/core/default.d.ts.map +0 -1
  346. package/dist/esm/relational/postgres/repositories/core/index.d.ts.map +0 -1
  347. package/dist/esm/relational/postgres/repositories/core/persistable.d.ts.map +0 -1
  348. package/dist/esm/relational/postgres/repositories/core/readable.d.ts.map +0 -1
  349. package/dist/esm/relational/postgres/repositories/core/soft-deletable.d.ts.map +0 -1
  350. package/dist/esm/relational/postgres/repositories/dialect/filter.d.ts.map +0 -1
  351. package/dist/esm/relational/postgres/repositories/dialect/index.d.ts.map +0 -1
  352. package/dist/esm/relational/postgres/repositories/dialect/internal/index.d.ts.map +0 -1
  353. package/dist/esm/relational/postgres/repositories/dialect/internal/json-path.d.ts.map +0 -1
  354. package/dist/esm/relational/postgres/repositories/dialect/query-dialect.d.ts.map +0 -1
  355. package/dist/esm/relational/postgres/repositories/dialect/query.d.ts.map +0 -1
  356. package/dist/esm/relational/postgres/repositories/dialect/relation.d.ts.map +0 -1
  357. package/dist/esm/relational/postgres/repositories/dialect/update.d.ts.map +0 -1
  358. package/dist/esm/relational/postgres/repositories/executor.d.ts.map +0 -1
  359. package/dist/esm/relational/postgres/repositories/index.d.ts.map +0 -1
  360. package/dist/esm/relational/postgres/supabase/index.d.ts.map +0 -1
  361. package/dist/esm/relational/postgres/supabase/pooler.d.ts.map +0 -1
  362. package/dist/esm/relational/postgres/supabase/rls.d.ts.map +0 -1
  363. package/dist/esm/relational/sqlite/datasources/abstract.d.ts.map +0 -1
  364. package/dist/esm/relational/sqlite/datasources/base.d.ts.map +0 -1
  365. package/dist/esm/relational/sqlite/datasources/common/index.d.ts.map +0 -1
  366. package/dist/esm/relational/sqlite/datasources/common/types.d.ts.map +0 -1
  367. package/dist/esm/relational/sqlite/datasources/index.d.ts.map +0 -1
  368. package/dist/esm/relational/sqlite/drivers/driver.d.ts.map +0 -1
  369. package/dist/esm/relational/sqlite/drivers/index.d.ts.map +0 -1
  370. package/dist/esm/relational/sqlite/drivers/libsql.d.ts.map +0 -1
  371. package/dist/esm/relational/sqlite/index.d.ts.map +0 -1
  372. package/dist/esm/relational/sqlite/models/base.d.ts.map +0 -1
  373. package/dist/esm/relational/sqlite/models/common/columns.d.ts.map +0 -1
  374. package/dist/esm/relational/sqlite/models/common/index.d.ts.map +0 -1
  375. package/dist/esm/relational/sqlite/models/common/types/enrichers.d.ts.map +0 -1
  376. package/dist/esm/relational/sqlite/models/common/types/index.d.ts.map +0 -1
  377. package/dist/esm/relational/sqlite/models/common/types/table.d.ts.map +0 -1
  378. package/dist/esm/relational/sqlite/models/enrichers/data-type.enricher.d.ts.map +0 -1
  379. package/dist/esm/relational/sqlite/models/enrichers/id.enricher.d.ts.map +0 -1
  380. package/dist/esm/relational/sqlite/models/enrichers/index.d.ts.map +0 -1
  381. package/dist/esm/relational/sqlite/models/enrichers/principal.enricher.d.ts.map +0 -1
  382. package/dist/esm/relational/sqlite/models/enrichers/tz.enricher.d.ts.map +0 -1
  383. package/dist/esm/relational/sqlite/models/enrichers/user-audit.enricher.d.ts.map +0 -1
  384. package/dist/esm/relational/sqlite/models/index.d.ts.map +0 -1
  385. package/dist/esm/relational/sqlite/repositories/common/index.d.ts.map +0 -1
  386. package/dist/esm/relational/sqlite/repositories/common/types.d.ts.map +0 -1
  387. package/dist/esm/relational/sqlite/repositories/core/base.d.ts.map +0 -1
  388. package/dist/esm/relational/sqlite/repositories/core/default.d.ts.map +0 -1
  389. package/dist/esm/relational/sqlite/repositories/core/index.d.ts.map +0 -1
  390. package/dist/esm/relational/sqlite/repositories/core/persistable.d.ts.map +0 -1
  391. package/dist/esm/relational/sqlite/repositories/core/readable.d.ts.map +0 -1
  392. package/dist/esm/relational/sqlite/repositories/core/soft-deletable.d.ts.map +0 -1
  393. package/dist/esm/relational/sqlite/repositories/dialect/filter.d.ts.map +0 -1
  394. package/dist/esm/relational/sqlite/repositories/dialect/index.d.ts.map +0 -1
  395. package/dist/esm/relational/sqlite/repositories/dialect/internal/index.d.ts.map +0 -1
  396. package/dist/esm/relational/sqlite/repositories/dialect/internal/json-path.d.ts.map +0 -1
  397. package/dist/esm/relational/sqlite/repositories/dialect/query-dialect.d.ts.map +0 -1
  398. package/dist/esm/relational/sqlite/repositories/dialect/query.d.ts.map +0 -1
  399. package/dist/esm/relational/sqlite/repositories/dialect/update.d.ts.map +0 -1
  400. package/dist/esm/relational/sqlite/repositories/executor.d.ts.map +0 -1
  401. package/dist/esm/relational/sqlite/repositories/index.d.ts.map +0 -1
  402. package/dist/esm/search/core/common/errors.d.ts.map +0 -1
  403. package/dist/esm/search/core/common/index.d.ts.map +0 -1
  404. package/dist/esm/search/core/connector.d.ts.map +0 -1
  405. package/dist/esm/search/core/controllers/abstract.d.ts.map +0 -1
  406. package/dist/esm/search/core/controllers/factory.d.ts.map +0 -1
  407. package/dist/esm/search/core/controllers/index.d.ts.map +0 -1
  408. package/dist/esm/search/core/controllers/scope.d.ts.map +0 -1
  409. package/dist/esm/search/core/datasources/abstract.d.ts.map +0 -1
  410. package/dist/esm/search/core/datasources/base.d.ts.map +0 -1
  411. package/dist/esm/search/core/datasources/common/index.d.ts.map +0 -1
  412. package/dist/esm/search/core/datasources/common/types.d.ts.map +0 -1
  413. package/dist/esm/search/core/datasources/guards.d.ts.map +0 -1
  414. package/dist/esm/search/core/datasources/index.d.ts.map +0 -1
  415. package/dist/esm/search/core/index.d.ts.map +0 -1
  416. package/dist/esm/search/core/internal/index.d.ts.map +0 -1
  417. package/dist/esm/search/core/internal/search-connector-internal.d.ts.map +0 -1
  418. package/dist/esm/search/core/models/base.d.ts.map +0 -1
  419. package/dist/esm/search/core/models/common/constants.d.ts.map +0 -1
  420. package/dist/esm/search/core/models/common/index.d.ts.map +0 -1
  421. package/dist/esm/search/core/models/common/types/collection.d.ts.map +0 -1
  422. package/dist/esm/search/core/models/common/types/document.d.ts.map +0 -1
  423. package/dist/esm/search/core/models/common/types/embedding.d.ts.map +0 -1
  424. package/dist/esm/search/core/models/common/types/field.d.ts.map +0 -1
  425. package/dist/esm/search/core/models/common/types/index.d.ts.map +0 -1
  426. package/dist/esm/search/core/models/define-search-collection.d.ts.map +0 -1
  427. package/dist/esm/search/core/models/index.d.ts.map +0 -1
  428. package/dist/esm/search/core/models/zod-derivation.d.ts.map +0 -1
  429. package/dist/esm/search/core/repositories/common/constants.d.ts.map +0 -1
  430. package/dist/esm/search/core/repositories/common/dialect-helpers.d.ts.map +0 -1
  431. package/dist/esm/search/core/repositories/common/index.d.ts.map +0 -1
  432. package/dist/esm/search/core/repositories/common/query-params.d.ts.map +0 -1
  433. package/dist/esm/search/core/repositories/common/types.d.ts.map +0 -1
  434. package/dist/esm/search/core/repositories/core/base.d.ts.map +0 -1
  435. package/dist/esm/search/core/repositories/core/default.d.ts.map +0 -1
  436. package/dist/esm/search/core/repositories/core/guards.d.ts.map +0 -1
  437. package/dist/esm/search/core/repositories/core/index.d.ts.map +0 -1
  438. package/dist/esm/search/core/repositories/core/persistable.d.ts.map +0 -1
  439. package/dist/esm/search/core/repositories/core/readable.d.ts.map +0 -1
  440. package/dist/esm/search/core/repositories/index.d.ts.map +0 -1
  441. package/dist/esm/search/meilisearch/common/index.d.ts.map +0 -1
  442. package/dist/esm/search/meilisearch/common/types.d.ts.map +0 -1
  443. package/dist/esm/search/meilisearch/compiler.d.ts.map +0 -1
  444. package/dist/esm/search/meilisearch/connector.d.ts.map +0 -1
  445. package/dist/esm/search/meilisearch/datasources/datasource.d.ts.map +0 -1
  446. package/dist/esm/search/meilisearch/datasources/index.d.ts.map +0 -1
  447. package/dist/esm/search/meilisearch/index.d.ts.map +0 -1
  448. package/dist/esm/search/meilisearch/internal/connector-internal.d.ts.map +0 -1
  449. package/dist/esm/search/meilisearch/internal/index.d.ts.map +0 -1
  450. package/dist/esm/search/meilisearch/repositories/common/index.d.ts.map +0 -1
  451. package/dist/esm/search/meilisearch/repositories/common/types.d.ts.map +0 -1
  452. package/dist/esm/search/meilisearch/repositories/dialect/index.d.ts.map +0 -1
  453. package/dist/esm/search/meilisearch/repositories/dialect/query-dialect.d.ts.map +0 -1
  454. package/dist/esm/search/meilisearch/repositories/index.d.ts.map +0 -1
  455. package/dist/esm/search/typesense/common/constants.d.ts.map +0 -1
  456. package/dist/esm/search/typesense/common/index.d.ts.map +0 -1
  457. package/dist/esm/search/typesense/common/types/client.d.ts.map +0 -1
  458. package/dist/esm/search/typesense/common/types/index.d.ts.map +0 -1
  459. package/dist/esm/search/typesense/common/types/options.d.ts.map +0 -1
  460. package/dist/esm/search/typesense/common/types/schema.d.ts.map +0 -1
  461. package/dist/esm/search/typesense/common/types/search.d.ts.map +0 -1
  462. package/dist/esm/search/typesense/compiler.d.ts.map +0 -1
  463. package/dist/esm/search/typesense/connector.d.ts.map +0 -1
  464. package/dist/esm/search/typesense/controllers/index.d.ts.map +0 -1
  465. package/dist/esm/search/typesense/datasources/datasource.d.ts.map +0 -1
  466. package/dist/esm/search/typesense/datasources/index.d.ts.map +0 -1
  467. package/dist/esm/search/typesense/index.d.ts.map +0 -1
  468. package/dist/esm/search/typesense/internal/connector-internal.d.ts.map +0 -1
  469. package/dist/esm/search/typesense/internal/guards.d.ts.map +0 -1
  470. package/dist/esm/search/typesense/internal/index.d.ts.map +0 -1
  471. package/dist/esm/search/typesense/internal/mappers.d.ts.map +0 -1
  472. package/dist/esm/search/typesense/internal/outcomes.d.ts.map +0 -1
  473. package/dist/esm/search/typesense/internal/pagination-windows.d.ts.map +0 -1
  474. package/dist/esm/search/typesense/repositories/common/index.d.ts.map +0 -1
  475. package/dist/esm/search/typesense/repositories/common/types.d.ts.map +0 -1
  476. package/dist/esm/search/typesense/repositories/dialect/index.d.ts.map +0 -1
  477. package/dist/esm/search/typesense/repositories/dialect/query-dialect.d.ts.map +0 -1
  478. package/dist/esm/search/typesense/repositories/index.d.ts.map +0 -1
  479. package/dist/esm/testing/index.d.ts.map +0 -1
  480. package/dist/esm/testing/transaction-double.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"repository.js","sourceRoot":"","sources":["../../../src/http/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAA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AC;IAC/D,CAAC;CACF","sourcesContent":["import { HttpReadShapes } from './common/constants';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type {\n IDeletableRepository,\n IReadableRepository,\n IUpdatableRepository,\n TCount,\n TDataWithRange,\n TByIdFilter,\n TFields,\n TFilter,\n TRow,\n TSchemaType,\n TWhere,\n} from '@venizia/ignis-kernel/repository';\nimport { AbstractEntity, DataRangeUtility } from '@venizia/ignis-kernel/repository';\nimport type { TSearchInput } from '../search/core/repositories/common/constants';\nimport type {\n IHttpCallOptions,\n IHttpSearchResult,\n IHttpWriteResult,\n THttpExtraQuery,\n TExtraRequest,\n TExtraResult,\n} from './common/types';\nimport type { HttpDataSource } from './datasource';\n\n/**\n * What a repository call takes. Only `headers` and `signal` cross HTTP; the shared repository\n * options (`transaction`, `log`, ...) are accepted for the common contract and have no effect.\n */\nexport type THttpRepositoryOptions = NonNullable<\n Parameters<IReadableRepository['existsWith']>[0]['options']\n> &\n IHttpCallOptions;\n\n/** A remote resource has a name but no local schema. */\nexport class HttpResourceEntity extends AbstractEntity {\n getSchema<T = unknown>(_opts: { type: TSchemaType }): T {\n return {} as T;\n }\n}\n\n/**\n * One remote resource, read and written through the IGNIS CRUD routes, in the `@venizia/ignis-filter`\n * vocabulary. `P` is what a write sends - a partial row by default, since the server fills ids and\n * defaults. There is no `createAll`: the IGNIS REST contract has no bulk-create route.\n */\nexport class HttpRepository<E extends object = AnyType, P extends object = Partial<E>>\n implements\n IReadableRepository<E, THttpRepositoryOptions>,\n IUpdatableRepository<E, P, THttpRepositoryOptions>,\n IDeletableRepository<E, THttpRepositoryOptions>\n{\n dataSource: HttpDataSource;\n entity: AbstractEntity;\n\n protected resource: string;\n /** A count route, if the API has one. Absent, the total comes from `Content-Range`. */\n protected countPath?: string;\n /** The segment after the resource that names the IGNIS find-one route. Absent, `findOne` asks the list route for one row. */\n protected findOnePath?: string;\n /** The page size `find` asks for when its filter names no limit. Absent, the server's own default applies. */\n protected defaultLimit?: number;\n /** The segment after the resource that names the IGNIS search route. */\n protected searchPath: string;\n\n constructor(opts: {\n dataSource: HttpDataSource;\n resource: string;\n countPath?: string;\n findOnePath?: string;\n defaultLimit?: number;\n searchPath?: string;\n }) {\n const { defaultLimit } = opts;\n\n if (defaultLimit !== undefined && !(Number.isInteger(defaultLimit) && defaultLimit > 0)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${opts.resource}] defaultLimit must be a positive integer | Got ${defaultLimit}`,\n });\n }\n\n this.dataSource = opts.dataSource;\n this.resource = opts.resource;\n this.countPath = opts.countPath;\n this.findOnePath = opts.findOnePath;\n this.defaultLimit = defaultLimit;\n this.searchPath = opts.searchPath ?? 'search';\n this.entity = new HttpResourceEntity({ name: opts.resource });\n }\n\n getEntity(): AbstractEntity {\n return this.entity;\n }\n\n /**\n * The query string of a read: the caller's extra `query` with the call's own `params` (`filter`,\n * `where`) over it. `method` names the repository verb, so a subclass can reshape one route - a\n * keyword into the object its server reads - and leave the others.\n */\n protected buildQuery(opts: {\n method: string;\n query?: THttpExtraQuery;\n params: Record<string, unknown>;\n }): Record<string, unknown> {\n return { ...opts.query, ...opts.params };\n }\n\n /** The filter `find` sends: the caller's, with `defaultLimit` filled in when it names no limit. */\n protected resolveFindFilter(opts: { filter?: TFilter<E> }): TFilter<E> {\n const filter = opts.filter ?? {};\n\n return this.defaultLimit === undefined || filter.limit !== undefined\n ? filter\n : { ...filter, limit: this.defaultLimit };\n }\n\n /** `<resource>/<searchPath>`; override to move the route. */\n protected getSearchPaths(): Array<string> {\n return [this.resource, this.searchPath];\n }\n\n /** No header and an unreadable one (`/*`) have different fixes, so different messages. */\n protected getMissingTotalError(opts: {\n method: string;\n contentRange?: string;\n noHeader: string;\n }) {\n const { method, contentRange, noHeader } = opts;\n const message = contentRange\n ? `Content-Range \"${contentRange}\" carries no readable total - an unknown \"/*\" or an unparseable value. Check the server's count query.`\n : noHeader;\n\n return getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${this.resource}][${method}] ${message}`,\n });\n }\n\n /** From `Content-Range`, or `countPath`. No total throws rather than reporting the page size. */\n async count(opts: {\n where: TWhere<E>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<TCount> {\n if (this.countPath) {\n const rs = await this.dataSource.read<{ count: number }>({\n paths: [this.resource, this.countPath],\n query: this.buildQuery({\n method: 'count',\n query: opts.query,\n params: { where: opts.where },\n }),\n shape: HttpReadShapes.ONE,\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n const counted = rs.data?.count;\n if (typeof counted !== 'number' || !Number.isFinite(counted)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${this.resource}][count] The count route answered no numeric count - answering 0 would read as an empty table. Body: ${JSON.stringify(rs.data)?.slice(0, 120)}`,\n });\n }\n\n return { count: counted };\n }\n\n const rs = await this.dataSource.read<Array<E>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'count',\n query: opts.query,\n params: { filter: { where: opts.where, limit: 1 } },\n }),\n // Rows alone: a default extra would be computed and thrown away on every count or probe.\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n if (!rs.hasRange) {\n throw this.getMissingTotalError({\n method: 'count',\n contentRange: rs.contentRange,\n noHeader: `The response carried no Content-Range, so there is no total to report - answering with the page size would claim ${rs.dataLength}. Cross-origin, the server must list Content-Range in Access-Control-Expose-Headers; otherwise give this repository a countPath if the API publishes a count route.`,\n });\n }\n\n return { count: rs.total ?? 0 };\n }\n\n async existsWith(opts: {\n where: TWhere<E>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<boolean> {\n const rs = await this.dataSource.read<Array<E>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'existsWith',\n query: opts.query,\n params: { filter: { where: opts.where, limit: 1 } },\n }),\n // Rows alone: a default extra would be computed and thrown away on every count or probe.\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return rs.dataLength > 0;\n }\n\n /** With `extra`: what the route answered beside the rows, typed by what was asked for. */\n async find<\n R = unknown,\n const Extra extends TExtraRequest = TExtraRequest,\n const F extends TFields<E> = TFields<E>,\n >(opts: {\n filter: TFilter<E, F>;\n query?: THttpExtraQuery;\n options: THttpRepositoryOptions & { shouldQueryRange: true; extra: Extra };\n }): Promise<TDataWithRange<TRow<E, R, F>> & { extra: TExtraResult<Extra> }>;\n async find<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter: TFilter<E, F>;\n query?: THttpExtraQuery;\n options: THttpRepositoryOptions & { shouldQueryRange: true };\n }): Promise<TDataWithRange<TRow<E, R, F>>>;\n async find<\n R = unknown,\n const Extra extends TExtraRequest = TExtraRequest,\n const F extends TFields<E> = TFields<E>,\n >(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options: THttpRepositoryOptions & { extra: Extra };\n }): Promise<{ data: Array<TRow<E, R, F>>; extra: TExtraResult<Extra> }>;\n async find<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<Array<TRow<E, R, F>>>;\n /** `extra` or the range decided at run time: the caller narrows the union. */\n async find<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions & { shouldQueryRange?: boolean; extra?: TExtraRequest };\n }): Promise<\n | Array<TRow<E, R, F>>\n | TDataWithRange<TRow<E, R, F>>\n | { data: Array<TRow<E, R, F>>; extra: TExtraResult<TExtraRequest> }\n >;\n async find<R = E>(opts: {\n filter?: TFilter<E>;\n query?: THttpExtraQuery;\n options?: AnyType;\n }): Promise<Array<R> | TDataWithRange<R> | { data: Array<R>; extra?: Record<string, unknown> }> {\n const filter = this.resolveFindFilter({ filter: opts.filter });\n const rs = await this.dataSource.read<Array<R>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'find',\n query: opts.query,\n params: { filter },\n }),\n extra: opts.options?.extra,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n const data = rs.data ?? [];\n\n if (!opts.options?.shouldQueryRange) {\n return opts.options?.extra ? { data, extra: rs.extra ?? {} } : data;\n }\n\n if (!rs.hasRange) {\n throw this.getMissingTotalError({\n method: 'find',\n contentRange: rs.contentRange,\n noHeader: `A range was asked for and the response carried no Content-Range. Deriving it from the page would report ${data.length} as the total. Cross-origin, the server must list Content-Range in Access-Control-Expose-Headers.`,\n });\n }\n\n return {\n data,\n // An empty page names no start: take it from the filter, as the server did.\n range: DataRangeUtility.buildDataRange({\n skip: rs.skip ?? filter.skip,\n offset: filter.offset,\n dataLength: data.length,\n total: rs.total ?? 0,\n }),\n // Asked for, `extra` is always there - empty when the route offered none.\n ...(opts.options?.extra ? { extra: rs.extra ?? {} } : {}),\n };\n }\n\n async findOne<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<TRow<E, R, F> | null> {\n if (this.findOnePath) {\n const one = await this.dataSource.read<TRow<E, R, F> | null>({\n paths: [this.resource, this.findOnePath],\n query: this.buildQuery({\n method: 'findOne',\n query: opts.query,\n params: { filter: opts.filter ?? {} },\n }),\n shape: HttpReadShapes.ONE,\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n return one.data ?? null;\n }\n\n const rs = await this.dataSource.read<Array<TRow<E, R, F>>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'findOne',\n query: opts.query,\n params: { filter: { ...(opts.filter ?? {}), limit: 1 } },\n }),\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n return rs.data?.[0] ?? null;\n }\n\n /** The server answers `null`, never 404, for a missing id. A `where` would be replaced by the id. */\n async findById<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n id: string | number;\n filter?: TByIdFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<TRow<E, R, F> | null> {\n const rs = await this.dataSource.read<TRow<E, R, F>>({\n paths: this.getIdPaths({ id: opts.id }),\n query: this.buildQuery({\n method: 'findById',\n query: opts.query,\n params: { filter: opts.filter ?? {} },\n }),\n shape: HttpReadShapes.ONE,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return rs.data ?? null;\n }\n\n /**\n * POST `<resource>/search`, the IGNIS search route: `input` is its body (a keyword, semantic, hybrid\n * or raw search), the answer its `{ found, isFoundExact, hits }`. `found` is the total - there is no\n * count route for a search, and `isFoundExact` says when it is an estimate.\n */\n async search<R extends object = E>(opts: {\n input: TSearchInput;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<IHttpSearchResult<R>> {\n const rs = await this.dataSource.read<IHttpSearchResult<R> | null>({\n paths: this.getSearchPaths(),\n method: HTTP.Methods.POST,\n body: opts.input,\n query: this.buildQuery({ method: 'search', query: opts.query, params: {} }),\n shape: HttpReadShapes.ONE,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n const answer = rs.data;\n if (!answer || typeof answer.found !== 'number' || !Array.isArray(answer.hits)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.BadGateway,\n message: `[${this.resource}][search] The search route answered no { found, hits } envelope - answering an empty page would read as no match. Body: ${JSON.stringify(answer)?.slice(0, 120)}`,\n });\n }\n\n return answer;\n }\n\n /**\n * `<resource>/<id>`, the id encoded: an id carrying `/` or `?` would otherwise name another route.\n * An empty, `.` or `..` id is refused: a URL resolves it, encoded or not, to `/<resource>/` or the\n * parent - a router or proxy that ignores the trailing slash then serves the list or bulk route.\n */\n protected getIdPaths(opts: { id: string | number }): Array<string> {\n const id = String(opts.id);\n\n if (id === '' || id === '.' || id === '..') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: `[${this.resource}] Invalid id '${id}' | An empty, '.' or '..' id names another route`,\n });\n }\n\n return [this.resource, encodeURIComponent(id)];\n }\n\n /** What a call adds to its request: headers and an abort signal. Every other option stays local. */\n protected toCallOptions(opts: { options?: THttpRepositoryOptions }): IHttpCallOptions {\n return { headers: opts.options?.headers, signal: opts.options?.signal };\n }\n\n /** The IGNIS bulk routes answer an empty `where` with a 400; refused here before a request is spent. */\n protected assertBulkWhere(opts: { method: string; where?: TWhere<E> }): TWhere<E> {\n const { method, where } = opts;\n\n if (!where || Object.keys(where).length === 0) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: `[${this.resource}][${method}] where is required for a bulk write | The IGNIS bulk routes refuse an empty where, and force cannot cross HTTP`,\n });\n }\n\n return where;\n }\n\n /** The server always answers the rows; `shouldReturn: false` drops them here, as a database repository would not fetch them. */\n protected toWriteResult<R>(opts: {\n result: IHttpWriteResult<R>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): TCount & { data: R | null } {\n const { result, options } = opts;\n return { count: result.count, data: options?.shouldReturn === false ? null : result.data };\n }\n\n /** POST `/<resource>`. */\n async create<R = E>(opts: {\n data: P;\n options?: THttpRepositoryOptions & { shouldReturn?: true };\n }): Promise<TCount & { data: R }> {\n const result = await this.dataSource.write<R>({\n paths: [this.resource],\n method: HTTP.Methods.POST,\n body: opts.data,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return { count: result.count, data: result.data };\n }\n\n async updateById(opts: {\n id: string | number;\n data: Partial<P>;\n options: THttpRepositoryOptions & { shouldReturn: false };\n }): Promise<TCount & { data: undefined | null }>;\n async updateById<R = E>(opts: {\n id: string | number;\n data: Partial<P>;\n options?: THttpRepositoryOptions & { shouldReturn?: true };\n }): Promise<TCount & { data: R }>;\n /** PATCH `/<resource>/<id>`. */\n async updateById<R = E>(opts: {\n id: string | number;\n data: Partial<P>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const result = await this.dataSource.write<R>({\n paths: this.getIdPaths({ id: opts.id }),\n method: HTTP.Methods.PATCH,\n body: opts.data,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n\n async updateAll(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async updateAll<R = E>(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** PATCH `/<resource>`, the `where` in the body beside the data - a long id list outgrows a URL. */\n async updateAll(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.patchWhere({ ...opts, method: 'updateAll' });\n }\n\n async updateBy(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async updateBy<R = E>(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** Alias for `updateAll`. */\n async updateBy(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.patchWhere({ ...opts, method: 'updateBy' });\n }\n\n protected async patchWhere(opts: {\n method: string;\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const where = this.assertBulkWhere({ method: opts.method, where: opts.where });\n\n const result = await this.dataSource.write<Array<E>>({\n paths: [this.resource],\n method: HTTP.Methods.PATCH,\n body: { ...opts.data, where },\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n\n async deleteById(opts: {\n id: string | number;\n options: THttpRepositoryOptions & { shouldReturn: false };\n }): Promise<TCount & { data: undefined | null }>;\n async deleteById<R = E>(opts: {\n id: string | number;\n options?: THttpRepositoryOptions & { shouldReturn?: true };\n }): Promise<TCount & { data: R }>;\n /** DELETE `/<resource>/<id>`. */\n async deleteById<R = E>(opts: {\n id: string | number;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const result = await this.dataSource.write<R>({\n paths: this.getIdPaths({ id: opts.id }),\n method: HTTP.Methods.DELETE,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n\n async deleteAll(opts: {\n where?: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async deleteAll<R = E>(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** DELETE `/<resource>`, the `where` in the body. */\n async deleteAll(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.deleteWhere({ ...opts, method: 'deleteAll' });\n }\n\n async deleteBy(opts: {\n where?: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async deleteBy<R = E>(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** Alias for `deleteAll`. */\n async deleteBy(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.deleteWhere({ ...opts, method: 'deleteBy' });\n }\n\n protected async deleteWhere(opts: {\n method: string;\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const where = this.assertBulkWhere({ method: opts.method, where: opts.where });\n\n const result = await this.dataSource.write<Array<E>>({\n paths: [this.resource],\n method: HTTP.Methods.DELETE,\n body: { where },\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n}\n"]}
1
+ {"version":3,"file":"repository.js","sourceRoot":"","sources":["../../../src/http/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAcvD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAqBpF,wDAAwD;AACxD,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IACpD,SAAS,CAAc,KAA4B;QACjD,OAAO,EAAO,CAAC;IACjB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,cAAc;IAuBzB,YAAY,IAOX;QACC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;QAE9B,IAAI,YAAY,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,YAAY,GAAG,CAAC,CAAC,EAAE,CAAC;YACxF,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,IAAI,IAAI,CAAC,QAAQ,mDAAmD,YAAY,EAAE;aAC5F,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,IAAI,C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,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAE/E,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAW;YACnD,KAAK,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC;YACtB,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;YAC3B,IAAI,EAAE,EAAE,KAAK,EAAE;YACf,GAAG,IAAI,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;SACjD,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC/D,CAAC;CACF","sourcesContent":["import { HttpReadShapes } from './common/constants';\nimport type { AnyType } from '@venizia/ignis-helpers/common';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type {\n IDeletableRepository,\n IReadableRepository,\n IUpdatableRepository,\n TCount,\n TDataWithRange,\n TByIdFilter,\n TFields,\n TFilter,\n TRow,\n TSchemaType,\n TWhere,\n} from '@venizia/ignis-kernel/repository';\nimport { AbstractEntity, DataRangeUtility } from '@venizia/ignis-kernel/repository';\nimport type { TSearchInput } from '../search/core/repositories/common/constants';\nimport type {\n IHttpCallOptions,\n IHttpSearchResult,\n IHttpWriteResult,\n THttpExtraQuery,\n TExtraRequest,\n TExtraResult,\n} from './common/types';\nimport type { HttpDataSource } from './datasource';\n\n/**\n * What a repository call takes. Only `headers` and `signal` cross HTTP; the shared repository\n * options (`transaction`, `log`, ...) are accepted for the common contract and have no effect.\n */\nexport type THttpRepositoryOptions = NonNullable<\n Parameters<IReadableRepository['existsWith']>[0]['options']\n> &\n IHttpCallOptions;\n\n/** A remote resource has a name but no local schema. */\nexport class HttpResourceEntity extends AbstractEntity {\n getSchema<T = unknown>(_opts: { type: TSchemaType }): T {\n return {} as T;\n }\n}\n\n/**\n * One remote resource, read and written through the IGNIS CRUD routes, in the `@venizia/ignis-filter`\n * vocabulary. `P` is what a write sends - a partial row by default, since the server fills ids and\n * defaults. There is no `createAll`: the IGNIS REST contract has no bulk-create route.\n */\nexport class HttpRepository<E extends object = AnyType, P extends object = Partial<E>>\n implements\n IReadableRepository<E, THttpRepositoryOptions>,\n IUpdatableRepository<E, P, THttpRepositoryOptions>,\n IDeletableRepository<E, THttpRepositoryOptions>\n{\n dataSource: HttpDataSource;\n entity: AbstractEntity;\n\n protected resource: string;\n /** A count route, if the API has one. Absent, the total comes from `Content-Range`. */\n protected countPath?: string;\n /** The segment after the resource that names the IGNIS find-one route. Absent, `findOne` asks the list route for one row. */\n protected findOnePath?: string;\n /** The page size `find` asks for when its filter names no limit. Absent, the server's own default applies. */\n protected defaultLimit?: number;\n /**\n * The segment after the resource that names the IGNIS search route.\n *\n * @default 'search'\n */\n protected searchPath: string;\n\n constructor(opts: {\n dataSource: HttpDataSource;\n resource: string;\n countPath?: string;\n findOnePath?: string;\n defaultLimit?: number;\n searchPath?: string;\n }) {\n const { defaultLimit } = opts;\n\n if (defaultLimit !== undefined && !(Number.isInteger(defaultLimit) && defaultLimit > 0)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${opts.resource}] defaultLimit must be a positive integer | Got ${defaultLimit}`,\n });\n }\n\n this.dataSource = opts.dataSource;\n this.resource = opts.resource;\n this.countPath = opts.countPath;\n this.findOnePath = opts.findOnePath;\n this.defaultLimit = defaultLimit;\n this.searchPath = opts.searchPath ?? 'search';\n this.entity = new HttpResourceEntity({ name: opts.resource });\n }\n\n getEntity(): AbstractEntity {\n return this.entity;\n }\n\n /**\n * The query string of a read: the caller's extra `query` with the call's own `params` (`filter`,\n * `where`) over it. `method` names the repository verb, so a subclass can reshape one route - a\n * keyword into the object its server reads - and leave the others.\n */\n protected buildQuery(opts: {\n method: string;\n query?: THttpExtraQuery;\n params: Record<string, unknown>;\n }): Record<string, unknown> {\n return { ...opts.query, ...opts.params };\n }\n\n /** The filter `find` sends: the caller's, with `defaultLimit` filled in when it names no limit. */\n protected resolveFindFilter(opts: { filter?: TFilter<E> }): TFilter<E> {\n const filter = opts.filter ?? {};\n\n return this.defaultLimit === undefined || filter.limit !== undefined\n ? filter\n : { ...filter, limit: this.defaultLimit };\n }\n\n /** `<resource>/<searchPath>`; override to move the route. */\n protected getSearchPaths(): Array<string> {\n return [this.resource, this.searchPath];\n }\n\n /** No header and an unreadable one (`/*`) have different fixes, so different messages. */\n protected getMissingTotalError(opts: {\n method: string;\n contentRange?: string;\n noHeader: string;\n }) {\n const { method, contentRange, noHeader } = opts;\n const message = contentRange\n ? `Content-Range \"${contentRange}\" carries no readable total - an unknown \"/*\" or an unparseable value. Check the server's count query.`\n : noHeader;\n\n return getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${this.resource}][${method}] ${message}`,\n });\n }\n\n /** From `Content-Range`, or `countPath`. No total throws rather than reporting the page size. */\n async count(opts: {\n where: TWhere<E>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<TCount> {\n if (this.countPath) {\n const rs = await this.dataSource.read<{ count: number }>({\n paths: [this.resource, this.countPath],\n query: this.buildQuery({\n method: 'count',\n query: opts.query,\n params: { where: opts.where },\n }),\n shape: HttpReadShapes.ONE,\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n const counted = rs.data?.count;\n\n if (typeof counted !== 'number' || !Number.isFinite(counted)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[${this.resource}][count] The count route answered no numeric count - answering 0 would read as an empty table. Body: ${JSON.stringify(rs.data)?.slice(0, 120)}`,\n });\n }\n\n return { count: counted };\n }\n\n const rs = await this.dataSource.read<Array<E>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'count',\n query: opts.query,\n params: { filter: { where: opts.where, limit: 1 } },\n }),\n // Rows alone: a default extra would be computed and thrown away on every count or probe.\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n if (!rs.hasRange) {\n throw this.getMissingTotalError({\n method: 'count',\n contentRange: rs.contentRange,\n noHeader: `The response carried no Content-Range, so there is no total to report - answering with the page size would claim ${rs.dataLength}. Cross-origin, the server must list Content-Range in Access-Control-Expose-Headers; otherwise give this repository a countPath if the API publishes a count route.`,\n });\n }\n\n return { count: rs.total ?? 0 };\n }\n\n async existsWith(opts: {\n where: TWhere<E>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<boolean> {\n const rs = await this.dataSource.read<Array<E>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'existsWith',\n query: opts.query,\n params: { filter: { where: opts.where, limit: 1 } },\n }),\n // Rows alone: a default extra would be computed and thrown away on every count or probe.\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return rs.dataLength > 0;\n }\n\n /** With `extra`: what the route answered beside the rows, typed by what was asked for. */\n async find<\n R = unknown,\n const Extra extends TExtraRequest = TExtraRequest,\n const F extends TFields<E> = TFields<E>,\n >(opts: {\n filter: TFilter<E, F>;\n query?: THttpExtraQuery;\n options: THttpRepositoryOptions & { shouldQueryRange: true; extra: Extra };\n }): Promise<TDataWithRange<TRow<E, R, F>> & { extra: TExtraResult<Extra> }>;\n async find<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter: TFilter<E, F>;\n query?: THttpExtraQuery;\n options: THttpRepositoryOptions & { shouldQueryRange: true };\n }): Promise<TDataWithRange<TRow<E, R, F>>>;\n async find<\n R = unknown,\n const Extra extends TExtraRequest = TExtraRequest,\n const F extends TFields<E> = TFields<E>,\n >(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options: THttpRepositoryOptions & { extra: Extra };\n }): Promise<{ data: Array<TRow<E, R, F>>; extra: TExtraResult<Extra> }>;\n async find<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<Array<TRow<E, R, F>>>;\n /** `extra` or the range decided at run time: the caller narrows the union. */\n async find<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions & { shouldQueryRange?: boolean; extra?: TExtraRequest };\n }): Promise<\n | Array<TRow<E, R, F>>\n | TDataWithRange<TRow<E, R, F>>\n | { data: Array<TRow<E, R, F>>; extra: TExtraResult<TExtraRequest> }\n >;\n async find<R = E>(opts: {\n filter?: TFilter<E>;\n query?: THttpExtraQuery;\n options?: AnyType;\n }): Promise<Array<R> | TDataWithRange<R> | { data: Array<R>; extra?: Record<string, unknown> }> {\n const filter = this.resolveFindFilter({ filter: opts.filter });\n const rs = await this.dataSource.read<Array<R>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'find',\n query: opts.query,\n params: { filter },\n }),\n extra: opts.options?.extra,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n const data = rs.data ?? [];\n\n if (!opts.options?.shouldQueryRange) {\n return opts.options?.extra ? { data, extra: rs.extra ?? {} } : data;\n }\n\n if (!rs.hasRange) {\n throw this.getMissingTotalError({\n method: 'find',\n contentRange: rs.contentRange,\n noHeader: `A range was asked for and the response carried no Content-Range. Deriving it from the page would report ${data.length} as the total. Cross-origin, the server must list Content-Range in Access-Control-Expose-Headers.`,\n });\n }\n\n return {\n data,\n // An empty page names no start: take it from the filter, as the server did.\n range: DataRangeUtility.buildDataRange({\n skip: rs.skip ?? filter.skip,\n offset: filter.offset,\n dataLength: data.length,\n total: rs.total ?? 0,\n }),\n // Asked for, `extra` is always there - empty when the route offered none.\n ...(opts.options?.extra ? { extra: rs.extra ?? {} } : {}),\n };\n }\n\n async findOne<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n filter?: TFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<TRow<E, R, F> | null> {\n if (this.findOnePath) {\n const one = await this.dataSource.read<TRow<E, R, F> | null>({\n paths: [this.resource, this.findOnePath],\n query: this.buildQuery({\n method: 'findOne',\n query: opts.query,\n params: { filter: opts.filter ?? {} },\n }),\n shape: HttpReadShapes.ONE,\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return one.data ?? null;\n }\n\n const rs = await this.dataSource.read<Array<TRow<E, R, F>>>({\n paths: [this.resource],\n query: this.buildQuery({\n method: 'findOne',\n query: opts.query,\n params: { filter: { ...(opts.filter ?? {}), limit: 1 } },\n }),\n isEveryDefaultOff: true,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return rs.data?.[0] ?? null;\n }\n\n /** The server answers `null`, never 404, for a missing id. A `where` would be replaced by the id. */\n async findById<R = unknown, const F extends TFields<E> = TFields<E>>(opts: {\n id: string | number;\n filter?: TByIdFilter<E, F>;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<TRow<E, R, F> | null> {\n const rs = await this.dataSource.read<TRow<E, R, F>>({\n paths: this.getIdPaths({ id: opts.id }),\n query: this.buildQuery({\n method: 'findById',\n query: opts.query,\n params: { filter: opts.filter ?? {} },\n }),\n shape: HttpReadShapes.ONE,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return rs.data ?? null;\n }\n\n /**\n * POST `<resource>/search`, the IGNIS search route: `input` is its body (a keyword, semantic, hybrid\n * or raw search), the answer its `{ found, isFoundExact, hits }`. `found` is the total - there is no\n * count route for a search, and `isFoundExact` says when it is an estimate.\n */\n async search<R extends object = E>(opts: {\n input: TSearchInput;\n query?: THttpExtraQuery;\n options?: THttpRepositoryOptions;\n }): Promise<IHttpSearchResult<R>> {\n const rs = await this.dataSource.read<IHttpSearchResult<R> | null>({\n paths: this.getSearchPaths(),\n method: HTTP.Methods.POST,\n body: opts.input,\n query: this.buildQuery({ method: 'search', query: opts.query, params: {} }),\n shape: HttpReadShapes.ONE,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n const answer = rs.data;\n\n if (!answer || typeof answer.found !== 'number' || !Array.isArray(answer.hits)) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.BadGateway,\n message: `[${this.resource}][search] The search route answered no { found, hits } envelope - answering an empty page would read as no match. Body: ${JSON.stringify(answer)?.slice(0, 120)}`,\n });\n }\n\n return answer;\n }\n\n /**\n * `<resource>/<id>`, the id encoded: an id carrying `/` or `?` would otherwise name another route.\n * An empty, `.` or `..` id is refused: a URL resolves it, encoded or not, to `/<resource>/` or the\n * parent - a router or proxy that ignores the trailing slash then serves the list or bulk route.\n */\n protected getIdPaths(opts: { id: string | number }): Array<string> {\n const id = String(opts.id);\n\n if (id === '' || id === '.' || id === '..') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: `[${this.resource}] Invalid id '${id}' | An empty, '.' or '..' id names another route`,\n });\n }\n\n return [this.resource, encodeURIComponent(id)];\n }\n\n /** What a call adds to its request: headers and an abort signal. Every other option stays local. */\n protected toCallOptions(opts: { options?: THttpRepositoryOptions }): IHttpCallOptions {\n return { headers: opts.options?.headers, signal: opts.options?.signal };\n }\n\n /** The IGNIS bulk routes answer an empty `where` with a 400; refused here before a request is spent. */\n protected assertBulkWhere(opts: { method: string; where?: TWhere<E> }): TWhere<E> {\n const { method, where } = opts;\n\n if (!where || Object.keys(where).length === 0) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n message: `[${this.resource}][${method}] where is required for a bulk write | The IGNIS bulk routes refuse an empty where, and force cannot cross HTTP`,\n });\n }\n\n return where;\n }\n\n /** The server always answers the rows; `shouldReturn: false` drops them here, as a database repository would not fetch them. */\n protected toWriteResult<R>(opts: {\n result: IHttpWriteResult<R>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): TCount & { data: R | null } {\n const { result, options } = opts;\n\n return { count: result.count, data: options?.shouldReturn === false ? null : result.data };\n }\n\n /** POST `/<resource>`. */\n async create<R = E>(opts: {\n data: P;\n options?: THttpRepositoryOptions & { shouldReturn?: true };\n }): Promise<TCount & { data: R }> {\n const result = await this.dataSource.write<R>({\n paths: [this.resource],\n method: HTTP.Methods.POST,\n body: opts.data,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return { count: result.count, data: result.data };\n }\n\n async updateById(opts: {\n id: string | number;\n data: Partial<P>;\n options: THttpRepositoryOptions & { shouldReturn: false };\n }): Promise<TCount & { data: undefined | null }>;\n async updateById<R = E>(opts: {\n id: string | number;\n data: Partial<P>;\n options?: THttpRepositoryOptions & { shouldReturn?: true };\n }): Promise<TCount & { data: R }>;\n /** PATCH `/<resource>/<id>`. */\n async updateById<R = E>(opts: {\n id: string | number;\n data: Partial<P>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const result = await this.dataSource.write<R>({\n paths: this.getIdPaths({ id: opts.id }),\n method: HTTP.Methods.PATCH,\n body: opts.data,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n\n async updateAll(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async updateAll<R = E>(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** PATCH `/<resource>`, the `where` in the body beside the data - a long id list outgrows a URL. */\n async updateAll(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.patchWhere({ ...opts, method: 'updateAll' });\n }\n\n async updateBy(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async updateBy<R = E>(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** Alias for `updateAll`. */\n async updateBy(opts: {\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.patchWhere({ ...opts, method: 'updateBy' });\n }\n\n protected async patchWhere(opts: {\n method: string;\n data: Partial<P>;\n where: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const where = this.assertBulkWhere({ method: opts.method, where: opts.where });\n\n const result = await this.dataSource.write<Array<E>>({\n paths: [this.resource],\n method: HTTP.Methods.PATCH,\n body: { ...opts.data, where },\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n\n async deleteById(opts: {\n id: string | number;\n options: THttpRepositoryOptions & { shouldReturn: false };\n }): Promise<TCount & { data: undefined | null }>;\n async deleteById<R = E>(opts: {\n id: string | number;\n options?: THttpRepositoryOptions & { shouldReturn?: true };\n }): Promise<TCount & { data: R }>;\n /** DELETE `/<resource>/<id>`. */\n async deleteById<R = E>(opts: {\n id: string | number;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const result = await this.dataSource.write<R>({\n paths: this.getIdPaths({ id: opts.id }),\n method: HTTP.Methods.DELETE,\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n\n async deleteAll(opts: {\n where?: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async deleteAll<R = E>(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** DELETE `/<resource>`, the `where` in the body. */\n async deleteAll(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.deleteWhere({ ...opts, method: 'deleteAll' });\n }\n\n async deleteBy(opts: {\n where?: TWhere<E>;\n options: THttpRepositoryOptions & { shouldReturn: false; force?: boolean };\n }): Promise<TCount & { data: undefined | null }>;\n async deleteBy<R = E>(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: true; force?: boolean };\n }): Promise<TCount & { data: Array<R> | null }>;\n /** Alias for `deleteAll`. */\n async deleteBy(opts: {\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean; force?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n return this.deleteWhere({ ...opts, method: 'deleteBy' });\n }\n\n protected async deleteWhere(opts: {\n method: string;\n where?: TWhere<E>;\n options?: THttpRepositoryOptions & { shouldReturn?: boolean };\n }): Promise<TCount & { data: AnyType }> {\n const where = this.assertBulkWhere({ method: opts.method, where: opts.where });\n\n const result = await this.dataSource.write<Array<E>>({\n paths: [this.resource],\n method: HTTP.Methods.DELETE,\n body: { where },\n ...this.toCallOptions({ options: opts.options }),\n });\n\n return this.toWriteResult({ result, options: opts.options });\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../../src/relational/core/datasources/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAyB,MAAM,uBAAuB,CAAC;AAGvF,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,kGAAkG;AAClG,oHAAoH;AACpH,mGAAmG;AACnG,oGAAoG;AACpG,mEAAmE;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yDAAyD,CAA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E,IAAI,EAAE,CAAC;IAChC,CAAC;IAEQ,KAAK,CAAC,gBAAgB,CAC7B,IAAoC;QAEpC,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACpC,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAEtE,IAAI,CAAC;YACH,MAAM,UAAU,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;YAE5F,oLAAoL;YACpL,UAAU,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YACtC,MAAM,KAAK,CAAC;QACd,CAAC;QAED,OAAO,IAAI,qBAAqB,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;IACrE,CAAC;CAIF;AAED,mGAAmG;AACnG,mGAAmG;AACnG,0EAA0E;AAC1E,uBAAuB,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,gBAAgB,CAAC,MAA0B,EAAE,CAAC,CAAC","sourcesContent":["import { MetadataRegistry } from '@venizia/ignis-kernel';\nimport { RelationBuilderRegistry, type TRelationBuilder } from '@venizia/ignis-kernel';\nimport type { TClass } from '@venizia/ignis-helpers/common';\nimport type { ILogger } from '@venizia/ignis-helpers/core';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { IDataSource, TAnyDataSourceSchema } from '@venizia/ignis-kernel';\n// Deep import, not a barrel: `discoverSchema()` below is the only production call site that needs\n// `RelationsFactory.create`, so the install runs from here rather than `dialect/relations/create.ts` - nothing else\n// value-imports that file's `RelationsFactory` export, and a `sideEffects: false` bundler drops an\n// unused export's module body even when it is reachable through a barrel `export *` chain (verified\n// with `bun build --target=browser`, the tool `make purity` uses).\nimport { RelationsFactory } from '@/relational/core/repositories/dialect/relations/create';\nimport type { IRelationalConnection } from '@/relational/core/drivers';\nimport { AbstractRelationalDataSource } from './abstract';\nimport type { IRelationalTransaction, TRelationalTransactionOptions } from './common';\nimport { RelationPairing } from './relation-pairing';\nimport type { ITransactionEnd } from './transaction-lifecycle';\nimport { TransactionLifecycle } from './transaction-lifecycle';\n\n/** The handle `beginTransaction()` returns: the shared end rules over one acquired connection. On a failed end the connection is discarded rather than pooled - the next borrower would inherit an open transaction - and the error rethrown: a caller must never believe a failed COMMIT succeeded. */\nclass ConnectionTransaction<TConnector>\n extends TransactionLifecycle\n implements IRelationalTransaction<TConnector>\n{\n readonly connector: TConnector;\n\n // ES-private so a logged, spread or serialised handle never reaches the datasource settings. The datasource, not its logger: the logger is read only when an end fails or is a no-op.\n readonly #dataSource: { readonly logger: ILogger };\n readonly #connection: IRelationalConnection<TConnector>;\n\n constructor(opts: {\n dataSource: { readonly logger: ILogger };\n connection: IRelationalConnection<TConnector>;\n }) {\n super();\n\n this.#dataSource = opts.dataSource;\n this.#connection = opts.connection;\n this.connector = opts.connection.connector;\n }\n\n protected override executeEnd(opts: { end: ITransactionEnd }): Promise<unknown> {\n return this.#connection.execute({ statement: opts.end.statement });\n }\n\n protected override onEnded(): void {\n this.#connection.release();\n }\n\n protected override onEndFailed(opts: { end: ITransactionEnd; error: unknown }): void {\n const { end, error } = opts;\n\n this.#dataSource.logger\n .for(end.verb)\n .error('Failed to %s transaction | Error: %s', end.statement, error);\n this.#connection.release({ destroy: true });\n }\n\n protected override onRollbackAfterFailure(): void {\n this.#dataSource.logger\n .for('rollback')\n .debug('Rollback after a failure-ended transaction - no-op, already torn down');\n }\n}\n\n/** Base DataSource with schema auto-discovery from registered repositories. */\nexport abstract class BaseRelationalDataSource<\n Settings extends object = {},\n Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,\n ConfigurableOptions extends object = {},\n Client = unknown,\n TConnector = unknown,\n> extends AbstractRelationalDataSource<Settings, Schema, ConfigurableOptions, Client, TConnector> {\n constructor(opts: { name: string; config: Settings; schema?: Schema }) {\n super({ scope: opts.name });\n\n this.name = opts.name;\n this.settings = opts.config;\n\n if (opts.schema) {\n this.schema = opts.schema;\n }\n }\n\n /** Auto-discovers schema from repositories if not manually provided. */\n override getSchema(): Schema {\n this.schema ??= this.discoverSchema();\n return this.schema;\n }\n\n protected discoverSchema(): Schema {\n const registry = MetadataRegistry.getInstance();\n const metadata = registry.getDataSourceMetadata({ target: this.constructor });\n\n if (metadata?.autoDiscovery === false) {\n this.logger.for(this.discoverSchema.name).debug('Auto-discovery disabled for %s', this.name);\n return {} as Schema;\n }\n\n const { schema, relations } = registry.buildSchema({\n dataSource: this.constructor as TClass<IDataSource>,\n });\n\n const models = Object.keys(schema);\n this.logger\n .for(this.discoverSchema.name)\n .debug(\n 'Detected model(s) | Name: %s | Count: %s | Models: %j',\n this.name,\n models.length,\n models,\n );\n\n const discovered = { ...schema, ...relations };\n\n // An inverse one() nothing pairs fails here; any other relation drizzle cannot pair is only\n // reported, so a model set that boots today keeps booting, and its first query still throws.\n const { unpaired, outside } = RelationPairing.inspect({\n dataSource: this.constructor.name,\n schema: discovered,\n });\n const fatal = unpaired.find((item) =>\n RelationPairing.isInverseOne({ relation: item.relation }),\n );\n if (fatal) {\n throw getError({ message: fatal.message });\n }\n\n const logger = this.logger.for(this.discoverSchema.name);\n for (const item of unpaired) {\n logger.warn(item.message);\n }\n if (outside.length > 0) {\n logger.debug(RelationPairing.describeOutside({ outside }));\n }\n\n // buildSchema() is shared by every connector so it returns Record<string, unknown>; the cast narrows back to the Drizzle schema shape.\n return discovered as Schema;\n }\n\n hasDiscoverableModels(): boolean {\n const registry = MetadataRegistry.getInstance();\n return registry.hasModels({ dataSource: this.constructor as TClass<IDataSource> });\n }\n\n override getCapabilities() {\n return { transactions: true };\n }\n\n override async beginTransaction(\n opts?: TRelationalTransactionOptions,\n ): Promise<IRelationalTransaction<TConnector>> {\n const driver = this.resolveDriver();\n const connection = await driver.acquire({ schema: this.getSchema() });\n\n try {\n await connection.execute({ statement: this.buildBeginStatement(opts) });\n } catch (error) {\n this.logger.for('beginTransaction').error('Failed to BEGIN transaction | Error: %s', error);\n\n // No caller ever receives a handle to release this connection, so leaking it exhausts the pool; destroyed rather than pooled because session state after a failed BEGIN is unknown.\n connection.release({ destroy: true });\n throw error;\n }\n\n return new ConnectionTransaction({ dataSource: this, connection });\n }\n\n /** The engine's own BEGIN. Postgres interpolates an isolation level; SQLite has none and uses `BEGIN IMMEDIATE`. Never parameterized - `BEGIN ... ISOLATION LEVEL $1` is not valid SQL. */\n protected abstract buildBeginStatement(opts?: TRelationalTransactionOptions): string;\n}\n\n// Runs once this module loads. Every engine (postgres, sqlite) extends `BaseRelationalDataSource`,\n// and `discoverSchema()` above is the sole caller of `resolveModelRelations()`, so this is the one\n// place guaranteed to load whenever relation building is actually needed.\nRelationBuilderRegistry.set({ builder: RelationsFactory.create as TRelationBuilder });\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../../src/relational/core/datasources/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAyB,MAAM,uBAAuB,CAAC;AAGvF,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,kGAAkG;AAClG,oHAAoH;AACpH,mGAAmG;AACnG,oGAAoG;AACpG,mEAAmE;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yDAAyD,CAAC;AAE3F,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,wSAA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CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAEtE,IAAI,CAAC;YACH,MAAM,UAAU,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;YAE5F,oLAAoL;YACpL,UAAU,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YACtC,MAAM,KAAK,CAAC;QACd,CAAC;QAED,OAAO,IAAI,qBAAqB,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;IACrE,CAAC;CAIF;AAED,mGAAmG;AACnG,mGAAmG;AACnG,0EAA0E;AAC1E,uBAAuB,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,gBAAgB,CAAC,MAA0B,EAAE,CAAC,CAAC","sourcesContent":["import { MetadataRegistry } from '@venizia/ignis-kernel';\nimport { RelationBuilderRegistry, type TRelationBuilder } from '@venizia/ignis-kernel';\nimport type { TClass } from '@venizia/ignis-helpers/common';\nimport type { ILogger } from '@venizia/ignis-helpers/core';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { IDataSource, TAnyDataSourceSchema } from '@venizia/ignis-kernel';\n// Deep import, not a barrel: `discoverSchema()` below is the only production call site that needs\n// `RelationsFactory.create`, so the install runs from here rather than `dialect/relations/create.ts` - nothing else\n// value-imports that file's `RelationsFactory` export, and a `sideEffects: false` bundler drops an\n// unused export's module body even when it is reachable through a barrel `export *` chain (verified\n// with `bun build --target=browser`, the tool `make purity` uses).\nimport { RelationsFactory } from '@/relational/core/repositories/dialect/relations/create';\nimport type { IRelationalConnection } from '@/relational/core/drivers';\nimport { AbstractRelationalDataSource } from './abstract';\nimport type { IRelationalTransaction, TRelationalTransactionOptions } from './common';\nimport { RelationPairing } from './relation-pairing';\nimport type { ITransactionEnd } from './transaction-lifecycle';\nimport { TransactionLifecycle } from './transaction-lifecycle';\n\n/** The handle `beginTransaction()` returns: the shared end rules over one acquired connection. On a failed end the connection is discarded rather than pooled - the next borrower would inherit an open transaction - and the error rethrown: a caller must never believe a failed COMMIT succeeded. */\nclass ConnectionTransaction<TConnector>\n extends TransactionLifecycle\n implements IRelationalTransaction<TConnector>\n{\n readonly connector: TConnector;\n\n // ES-private so a logged, spread or serialised handle never reaches the datasource settings. The datasource, not its logger: the logger is read only when an end fails or is a no-op.\n readonly #dataSource: { readonly logger: ILogger };\n readonly #connection: IRelationalConnection<TConnector>;\n\n constructor(opts: {\n dataSource: { readonly logger: ILogger };\n connection: IRelationalConnection<TConnector>;\n }) {\n super();\n\n this.#dataSource = opts.dataSource;\n this.#connection = opts.connection;\n this.connector = opts.connection.connector;\n }\n\n protected override executeEnd(opts: { end: ITransactionEnd }): Promise<unknown> {\n return this.#connection.execute({ statement: opts.end.statement });\n }\n\n protected override onEnded(): void {\n this.#connection.release();\n }\n\n protected override onEndFailed(opts: { end: ITransactionEnd; error: unknown }): void {\n const { end, error } = opts;\n\n this.#dataSource.logger\n .for(end.verb)\n .error('Failed to %s transaction | Error: %s', end.statement, error);\n this.#connection.release({ destroy: true });\n }\n\n protected override onRollbackAfterFailure(): void {\n this.#dataSource.logger\n .for('rollback')\n .debug('Rollback after a failure-ended transaction - no-op, already torn down');\n }\n}\n\n/** Base DataSource with schema auto-discovery from registered repositories. */\nexport abstract class BaseRelationalDataSource<\n Settings extends object = {},\n Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,\n ConfigurableOptions extends object = {},\n Client = unknown,\n TConnector = unknown,\n> extends AbstractRelationalDataSource<Settings, Schema, ConfigurableOptions, Client, TConnector> {\n constructor(opts: { name: string; config: Settings; schema?: Schema }) {\n super({ scope: opts.name });\n\n this.name = opts.name;\n this.settings = opts.config;\n\n if (opts.schema) {\n this.schema = opts.schema;\n }\n }\n\n /** Auto-discovers schema from repositories if not manually provided. */\n override getSchema(): Schema {\n this.schema ??= this.discoverSchema();\n\n return this.schema;\n }\n\n protected discoverSchema(): Schema {\n const registry = MetadataRegistry.getInstance();\n const metadata = registry.getDataSourceMetadata({ target: this.constructor });\n\n if (metadata?.autoDiscovery === false) {\n this.logger.for(this.discoverSchema.name).debug('Auto-discovery disabled for %s', this.name);\n\n return {} as Schema;\n }\n\n const { schema, relations } = registry.buildSchema({\n dataSource: this.constructor as TClass<IDataSource>,\n });\n\n const models = Object.keys(schema);\n this.logger\n .for(this.discoverSchema.name)\n .debug(\n 'Detected model(s) | Name: %s | Count: %s | Models: %j',\n this.name,\n models.length,\n models,\n );\n\n const discovered = { ...schema, ...relations };\n\n // An inverse one() nothing pairs fails here; any other relation drizzle cannot pair is only\n // reported, so a model set that boots today keeps booting, and its first query still throws.\n const { unpaired, outside } = RelationPairing.inspect({\n dataSource: this.constructor.name,\n schema: discovered,\n });\n const fatal = unpaired.find((item) =>\n RelationPairing.isInverseOne({ relation: item.relation }),\n );\n\n if (fatal) {\n throw getError({ message: fatal.message });\n }\n\n const logger = this.logger.for(this.discoverSchema.name);\n\n for (const item of unpaired) {\n logger.warn(item.message);\n }\n\n if (outside.length > 0) {\n logger.debug(RelationPairing.describeOutside({ outside }));\n }\n\n // buildSchema() is shared by every connector so it returns Record<string, unknown>; the cast narrows back to the Drizzle schema shape.\n return discovered as Schema;\n }\n\n hasDiscoverableModels(): boolean {\n const registry = MetadataRegistry.getInstance();\n\n return registry.hasModels({ dataSource: this.constructor as TClass<IDataSource> });\n }\n\n override getCapabilities() {\n return { transactions: true };\n }\n\n override async beginTransaction(\n opts?: TRelationalTransactionOptions,\n ): Promise<IRelationalTransaction<TConnector>> {\n const driver = this.resolveDriver();\n const connection = await driver.acquire({ schema: this.getSchema() });\n\n try {\n await connection.execute({ statement: this.buildBeginStatement(opts) });\n } catch (error) {\n this.logger.for('beginTransaction').error('Failed to BEGIN transaction | Error: %s', error);\n\n // No caller ever receives a handle to release this connection, so leaking it exhausts the pool; destroyed rather than pooled because session state after a failed BEGIN is unknown.\n connection.release({ destroy: true });\n throw error;\n }\n\n return new ConnectionTransaction({ dataSource: this, connection });\n }\n\n /** The engine's own BEGIN. Postgres interpolates an isolation level; SQLite has none and uses `BEGIN IMMEDIATE`. Never parameterized - `BEGIN ... ISOLATION LEVEL $1` is not valid SQL. */\n protected abstract buildBeginStatement(opts?: TRelationalTransactionOptions): string;\n}\n\n// Runs once this module loads. Every engine (postgres, sqlite) extends `BaseRelationalDataSource`,\n// and `discoverSchema()` above is the sole caller of `resolveModelRelations()`, so this is the one\n// place guaranteed to load whenever relation building is actually needed.\nRelationBuilderRegistry.set({ builder: RelationsFactory.create as TRelationBuilder });\n"]}
@@ -3,6 +3,7 @@ import type { IRelationalQueryDialect, IRelationalQueryExecutor } from '../../re
3
3
  import type { ValueOrPromise } from '@venizia/ignis-helpers/common';
4
4
  /** Neutral SQL transaction options; each engine adds its own knobs. An alias, not an empty `interface ... extends`, which `@typescript-eslint/no-empty-object-type` rejects. */
5
5
  export type TRelationalTransactionOptions = ITransactionOptions;
6
+ /** Transaction handle for a SQL datasource: `connector` runs queries inside the transaction, `commit()` and `rollback()` end it. */
6
7
  export interface IRelationalTransaction<TConnector> extends ITransaction {
7
8
  /** Bound to the transaction's own connection, whichever driver acquired it. */
8
9
  connector: TConnector;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/relational/core/datasources/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AbstractDataSource,\n ITransaction,\n ITransactionOptions,\n TAnyDataSourceSchema,\n} from '@venizia/ignis-kernel';\nimport type {\n IRelationalQueryDialect,\n IRelationalQueryExecutor,\n} from '@/relational/core/repositories/common';\nimport type { ValueOrPromise } from '@venizia/ignis-helpers/common';\n\n/** Neutral SQL transaction options; each engine adds its own knobs. An alias, not an empty `interface ... extends`, which `@typescript-eslint/no-empty-object-type` rejects. */\nexport type TRelationalTransactionOptions = ITransactionOptions;\n\nexport interface IRelationalTransaction<TConnector> extends ITransaction {\n /** Bound to the transaction's own connection, whichever driver acquired it. */\n connector: TConnector;\n\n /** Throws if COMMIT fails, per {@link ITransaction.commit}. The connection is discarded where the driver supports it (node-postgres `release(error)`); postgres-js has no destroy semantics, so a poisoned connection returns to its pool. */\n commit(): Promise<void>;\n\n /** Throws if ROLLBACK fails (same connection-discard caveat as {@link commit}) - but is a silent no-op after the transaction already ended BY FAILURE, keeping `catch (error) { await transaction.rollback(); throw error; }` safe. */\n rollback(): Promise<void>;\n}\n\n/** SQL-branch contract, engine-free. Extends `AbstractDataSource` itself, not just `IDataSource`, so repositories can narrow safely. `getConnectionString()` is app-implemented and never called by the framework - an embedded engine with no URL returns its data directory. */\nexport interface IRelationalDataSource<\n Settings extends object = {},\n Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,\n ConfigurableOptions extends object = {},\n Client = unknown,\n TConnector = unknown,\n> extends AbstractDataSource<Settings, Schema, ConfigurableOptions> {\n connector: TConnector;\n\n getConnectionString(): ValueOrPromise<string>;\n getConnector(): TConnector;\n getClient(): Client;\n getQueryDialect(): IRelationalQueryDialect;\n getQueryExecutor(): IRelationalQueryExecutor<TConnector>;\n beginTransaction(\n opts?: TRelationalTransactionOptions,\n ): Promise<IRelationalTransaction<TConnector>>;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/relational/core/datasources/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AbstractDataSource,\n ITransaction,\n ITransactionOptions,\n TAnyDataSourceSchema,\n} from '@venizia/ignis-kernel';\nimport type {\n IRelationalQueryDialect,\n IRelationalQueryExecutor,\n} from '@/relational/core/repositories/common';\nimport type { ValueOrPromise } from '@venizia/ignis-helpers/common';\n\n/** Neutral SQL transaction options; each engine adds its own knobs. An alias, not an empty `interface ... extends`, which `@typescript-eslint/no-empty-object-type` rejects. */\nexport type TRelationalTransactionOptions = ITransactionOptions;\n\n/** Transaction handle for a SQL datasource: `connector` runs queries inside the transaction, `commit()` and `rollback()` end it. */\nexport interface IRelationalTransaction<TConnector> extends ITransaction {\n /** Bound to the transaction's own connection, whichever driver acquired it. */\n connector: TConnector;\n\n /** Throws if COMMIT fails, per {@link ITransaction.commit}. The connection is discarded where the driver supports it (node-postgres `release(error)`); postgres-js has no destroy semantics, so a poisoned connection returns to its pool. */\n commit(): Promise<void>;\n\n /** Throws if ROLLBACK fails (same connection-discard caveat as {@link commit}) - but is a silent no-op after the transaction already ended BY FAILURE, keeping `catch (error) { await transaction.rollback(); throw error; }` safe. */\n rollback(): Promise<void>;\n}\n\n/** SQL-branch contract, engine-free. Extends `AbstractDataSource` itself, not just `IDataSource`, so repositories can narrow safely. `getConnectionString()` is app-implemented and never called by the framework - an embedded engine with no URL returns its data directory. */\nexport interface IRelationalDataSource<\n Settings extends object = {},\n Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,\n ConfigurableOptions extends object = {},\n Client = unknown,\n TConnector = unknown,\n> extends AbstractDataSource<Settings, Schema, ConfigurableOptions> {\n connector: TConnector;\n\n getConnectionString(): ValueOrPromise<string>;\n getConnector(): TConnector;\n getClient(): Client;\n getQueryDialect(): IRelationalQueryDialect;\n getQueryExecutor(): IRelationalQueryExecutor<TConnector>;\n beginTransaction(\n opts?: TRelationalTransactionOptions,\n ): Promise<IRelationalTransaction<TConnector>>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"relation-pairing.js","sourceRoot":"","sources":["../../../../../src/relational/core/datasources/relation-pairing.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,6BAA6B,EAC7B,YAAY,EACZ,kBAAkB,EAClB,EAAE,EACF,IAAI,EACJ,iBAAiB,EACjB,GAAG,GACJ,MAAM,aAAa,CAAC;AAiBrB;;;;;GAKG;AACH,M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E;qBACnL,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;IAC/B,CAAC;IAED,gGAAgG;IAChG,MAAM,CAAC,YAAY,CAAC,IAA4B;QAC9C,OAAO,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IACzD,CAAC;IAED,sEAAsE;IACtE,MAAM,CAAC,eAAe,CAAC,IAAgC;QACrD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QACzB,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,kBAAkB,CAAC;QAC/F,OAAO,GAAG,KAAK,wCAAwC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,4FAA4F,CAAC;IACxK,CAAC;IAED,8EAA8E;IACtE,MAAM,CAAC,iBAAiB,CAAC,IAIhC;QACC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAE1C,IAAI,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC;YACvB,OAAO,qCAAqC,MAAM,YAAY,QAAQ,CAAC,YAAY,+FAA+F,MAAM,wBAAwB,MAAM,oEAAoE,CAAC;QAC7R,CAAC;QACD,OAAO,IAAI,MAAM,iGAAiG,MAAM,sDAAsD,MAAM,gDAAgD,CAAC;IACvO,CAAC;CACF","sourcesContent":["import {\n createTableRelationsHelpers,\n extractTablesRelationalConfig,\n getTableName,\n getTableUniqueName,\n is,\n Many,\n normalizeRelation,\n One,\n} from 'drizzle-orm';\nimport type { Relation } from 'drizzle-orm';\n\n/** A relation drizzle cannot pair, with the message that names it and its fix. */\ninterface IUnpairedRelation {\n relation: Relation;\n message: string;\n}\n\n/** What a datasource's schema discovery learns about its relations. */\ninterface IRelationPairingReport {\n /** Relations drizzle cannot pair, though their target has a model on the datasource. */\n unpaired: Array<IUnpairedRelation>;\n /** `Entity.relation -> Table` for each relation whose table has no model on the datasource. */\n outside: Array<string>;\n}\n\n/**\n * Pairs every relation the way drizzle does on the first query that includes it, so schema\n * discovery can report - or refuse - what that query would hit. A relation whose table has no\n * model on the datasource is kept apart: a datasource that carries a subset of models on purpose\n * is a normal shape, not a defect.\n */\nexport class RelationPairing {\n static inspect(opts: {\n dataSource: string;\n schema: Record<string, unknown>;\n }): IRelationPairingReport {\n const { dataSource, schema } = opts;\n const { tables, tableNamesMap } = extractTablesRelationalConfig(\n schema,\n createTableRelationsHelpers,\n );\n\n const unpaired: Array<IUnpairedRelation> = [];\n const outside: Array<string> = [];\n\n for (const [entity, table] of Object.entries(tables)) {\n for (const [name, relation] of Object.entries(table.relations)) {\n const target = tableNamesMap[getTableUniqueName(relation.referencedTable)];\n if (!target) {\n outside.push(`${entity}.${name} -> ${getTableName(relation.referencedTable)}`);\n continue;\n }\n\n try {\n normalizeRelation(tables, tableNamesMap, relation);\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n unpaired.push({\n relation,\n message: `[${dataSource}][discoverSchema] Cannot resolve relation '${name}' on entity '${entity}': ${reason} | ${RelationPairing.buildUnpairedHint({ entity, target, relation })}`,\n });\n }\n }\n }\n\n return { unpaired, outside };\n }\n\n /** An inverse one() - no fields of its own - exists only through the relation that pairs it. */\n static isInverseOne(opts: { relation: Relation }): boolean {\n return is(opts.relation, One) && !opts.relation.config;\n }\n\n /** One line for every relation that points outside the datasource. */\n static describeOutside(opts: { outside: Array<string> }): string {\n const { outside } = opts;\n const count = outside.length === 1 ? '1 relation points' : `${outside.length} relations point`;\n return `${count} to a table outside this datasource: ${outside.join(', ')} | A query that includes one fails here; bind that model to this datasource if you need it`;\n }\n\n /** The fix for a relation drizzle cannot pair, in the entities' own names. */\n private static buildUnpairedHint(opts: {\n entity: string;\n target: string;\n relation: Relation;\n }): string {\n const { entity, target, relation } = opts;\n\n if (is(relation, Many)) {\n return `A many() pairs with the one() on '${target}' named '${relation.relationName}' - a one() is named by its key, or by its relationName if it sets one | Add that one() on '${target}', pointing back to '${entity}', or set relationName here to the name of the one() already there`;\n }\n return `'${target}' holds the foreign key, so this one() pairs with the one relation there that points back to '${entity}' - there must be exactly one | Add that one() on '${target}', or write fields and references on this side`;\n }\n}\n"]}
1
+ {"version":3,"file":"relation-pairing.js","sourceRoot":"","sources":["../../../../../src/relational/core/datasources/relation-pairing.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,6BAA6B,EAC7B,YAAY,EACZ,kBAAkB,EAClB,EAAE,EACF,IAAI,EACJ,iBAAiB,EACjB,GAAG,GACJ,MAAM,aAAa,CAAC;AAiBrB;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IAC1B,MAAM,CAAC,OAAO,CAAC,IAGd;QACC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACpC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,6BAA6B,CAC7D,MAAM,EACN,2BAA2B,CAC5B,CAAC;QAEF,MAAM,QAAQ,GAA6B,EAAE,CAAC;QAC9C,MAAM,OAAO,GAAkB,EAAE,CAAC;QAElC,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACrD,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC/D,MAAM,MAAM,GAAG,aAAa,CAAC,kBAAkB,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC;gBAE3E,IAAI,CAAC,MAAM,EAAE,CAAC;oBACZ,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,IAAI,OAAO,YAAY,CA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E,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAE1C,IAAI,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC;YACvB,OAAO,qCAAqC,MAAM,YAAY,QAAQ,CAAC,YAAY,+FAA+F,MAAM,wBAAwB,MAAM,oEAAoE,CAAC;QAC7R,CAAC;QAED,OAAO,IAAI,MAAM,iGAAiG,MAAM,sDAAsD,MAAM,gDAAgD,CAAC;IACvO,CAAC;CACF","sourcesContent":["import {\n createTableRelationsHelpers,\n extractTablesRelationalConfig,\n getTableName,\n getTableUniqueName,\n is,\n Many,\n normalizeRelation,\n One,\n} from 'drizzle-orm';\nimport type { Relation } from 'drizzle-orm';\n\n/** A relation drizzle cannot pair, with the message that names it and its fix. */\ninterface IUnpairedRelation {\n relation: Relation;\n message: string;\n}\n\n/** What a datasource's schema discovery learns about its relations. */\ninterface IRelationPairingReport {\n /** Relations drizzle cannot pair, though their target has a model on the datasource. */\n unpaired: Array<IUnpairedRelation>;\n /** `Entity.relation -> Table` for each relation whose table has no model on the datasource. */\n outside: Array<string>;\n}\n\n/**\n * Pairs every relation the way drizzle does on the first query that includes it, so schema\n * discovery can report - or refuse - what that query would hit. A relation whose table has no\n * model on the datasource is kept apart: a datasource that carries a subset of models on purpose\n * is a normal shape, not a defect.\n */\nexport class RelationPairing {\n static inspect(opts: {\n dataSource: string;\n schema: Record<string, unknown>;\n }): IRelationPairingReport {\n const { dataSource, schema } = opts;\n const { tables, tableNamesMap } = extractTablesRelationalConfig(\n schema,\n createTableRelationsHelpers,\n );\n\n const unpaired: Array<IUnpairedRelation> = [];\n const outside: Array<string> = [];\n\n for (const [entity, table] of Object.entries(tables)) {\n for (const [name, relation] of Object.entries(table.relations)) {\n const target = tableNamesMap[getTableUniqueName(relation.referencedTable)];\n\n if (!target) {\n outside.push(`${entity}.${name} -> ${getTableName(relation.referencedTable)}`);\n continue;\n }\n\n try {\n normalizeRelation(tables, tableNamesMap, relation);\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n unpaired.push({\n relation,\n message: `[${dataSource}][discoverSchema] Cannot resolve relation '${name}' on entity '${entity}': ${reason} | ${RelationPairing.buildUnpairedHint({ entity, target, relation })}`,\n });\n }\n }\n }\n\n return { unpaired, outside };\n }\n\n /** An inverse one() - no fields of its own - exists only through the relation that pairs it. */\n static isInverseOne(opts: { relation: Relation }): boolean {\n return is(opts.relation, One) && !opts.relation.config;\n }\n\n /** One line for every relation that points outside the datasource. */\n static describeOutside(opts: { outside: Array<string> }): string {\n const { outside } = opts;\n const count = outside.length === 1 ? '1 relation points' : `${outside.length} relations point`;\n\n return `${count} to a table outside this datasource: ${outside.join(', ')} | A query that includes one fails here; bind that model to this datasource if you need it`;\n }\n\n /** The fix for a relation drizzle cannot pair, in the entities' own names. */\n private static buildUnpairedHint(opts: {\n entity: string;\n target: string;\n relation: Relation;\n }): string {\n const { entity, target, relation } = opts;\n\n if (is(relation, Many)) {\n return `A many() pairs with the one() on '${target}' named '${relation.relationName}' - a one() is named by its key, or by its relationName if it sets one | Add that one() on '${target}', pointing back to '${entity}', or set relationName here to the name of the one() already there`;\n }\n\n return `'${target}' holds the foreign key, so this one() pairs with the one relation there that points back to '${entity}' - there must be exactly one | Add that one() on '${target}', or write fields and references on this side`;\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import type { TConstValue } from '@venizia/ignis-helpers/common';
2
2
  import type { ITransaction } from '@venizia/ignis-kernel';
3
+ /** Lifecycle states of a transaction handle: `ACTIVE` until it ends as `COMMITTED`, `ROLLED_BACK` or `FAILED`. */
3
4
  export declare class TransactionStates {
4
5
  static readonly ACTIVE = "ACTIVE";
5
6
  static readonly COMMITTED = "COMMITTED";
@@ -8,6 +9,7 @@ export declare class TransactionStates {
8
9
  static readonly SCHEME_SET: Set<string>;
9
10
  static isValid(value: string): boolean;
10
11
  }
12
+ /** One of the {@link TransactionStates} values. */
11
13
  export type TTransactionState = TConstValue<typeof TransactionStates>;
12
14
  /** Registry symbol, not a module-private one: two installed copies of this package (two versions in one tree) each load their own copy of this class, and a handle from one must still be read by the other. */
13
15
  export declare const TRANSACTION_STATE_KEY: unique symbol;
@@ -1,4 +1,5 @@
1
1
  import { getError } from '@venizia/ignis-helpers/core';
2
+ /** Lifecycle states of a transaction handle: `ACTIVE` until it ends as `COMMITTED`, `ROLLED_BACK` or `FAILED`. */
2
3
  export class TransactionStates {
3
4
  static { this.ACTIVE = 'ACTIVE'; }
4
5
  static { this.COMMITTED = 'COMMITTED'; }
@@ -1 +1 @@
1
- {"version":3,"file":"transaction-lifecycle.js","sourceRoot":"","sources":["../../../../../src/relational/core/datasources/transaction-lifecycle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGvD,MAAM,OAAO,iBAAiB;aACZ,WAAM,GAAG,QAAQ,CAAC;aAClB,cAAS,GAAG,WAAW,CAAC;aACxB,gBAAW,GAAG,aAAa,CAAC;aAC5B,WAAM,GAAG,QAAQ,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAC;QACnC,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,MAAM;KACZ,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAKH,gNAAgN;AAChN,MAAM,CAAC,MAAM,qBAAqB,GAAkB,MAAM,CAAC,GAAG,CAC5D,6CAA6C,CAC9C,CAAC;AAQF;;;;GAIG;AACH,MAAM,OAAgB,oBAAoB;IAA1C;QAuBE,0GAA0G;QAC1G,WAAM,GAAsB,iBAAiB,CAAC,MAAM,CAAC;QAerD,yFAAyF;QAChF,WAAM,GAAG,GAAkB,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,oBAAoB,CAAC,MAAM,EAAE,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AAiB,CAAC,MAAM,IAAI,GAAG,KAAK,oBAAoB,CAAC,QAAQ,EAAE,CAAC;gBACtF,IAAI,CAAC,sBAAsB,EAAE,CAAC;gBAC9B,OAAO;YACT,CAAC;YAED,MAAM,QAAQ,CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,CAAC,IAAI,6BAA6B,EAAE,CAAC,CAAC;QACtF,CAAC;QAED,8JAA8J;QAC9J,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC;QAE7B,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;YACjC,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC;YACvC,MAAM,KAAK,CAAC;QACd,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACxB,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { ITransaction } from '@venizia/ignis-kernel';\n\nexport class TransactionStates {\n static readonly ACTIVE = 'ACTIVE';\n static readonly COMMITTED = 'COMMITTED';\n static readonly ROLLED_BACK = 'ROLLED_BACK';\n static readonly FAILED = 'FAILED';\n\n static readonly SCHEME_SET = new Set([\n this.ACTIVE,\n this.COMMITTED,\n this.ROLLED_BACK,\n this.FAILED,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\nexport type TTransactionState = TConstValue<typeof TransactionStates>;\n\n/** Registry symbol, not a module-private one: two installed copies of this package (two versions in one tree) each load their own copy of this class, and a handle from one must still be read by the other. */\nexport const TRANSACTION_STATE_KEY: unique symbol = Symbol.for(\n '@venizia/ignis-connectors/transaction-state',\n);\n\nexport interface ITransactionEnd {\n verb: string;\n statement: string;\n endedState: TTransactionState;\n}\n\n/**\n * The end-of-transaction rules every handle shares, the real one and the test double alike: the\n * first commit() or rollback() wins, a second end throws, and rollback() after a failed end is a\n * no-op. A subclass supplies only the statement and what happens around it.\n */\nexport abstract class TransactionLifecycle implements ITransaction {\n private static readonly COMMIT: ITransactionEnd = {\n verb: 'commit',\n statement: 'COMMIT',\n endedState: TransactionStates.COMMITTED,\n };\n\n private static readonly ROLLBACK: ITransactionEnd = {\n verb: 'rollback',\n statement: 'ROLLBACK',\n endedState: TransactionStates.ROLLED_BACK,\n };\n\n /** True only for a handle built on `TransactionLifecycle`, from either build, that ended by COMMIT. */\n static isCommitted(opts: { transaction: object }): boolean {\n const { transaction } = opts;\n\n return (\n TRANSACTION_STATE_KEY in transaction &&\n transaction[TRANSACTION_STATE_KEY] === TransactionStates.COMMITTED\n );\n }\n\n // ES-private, not TS-private: a handle that is logged, spread or serialised must not carry its internals.\n #state: TTransactionState = TransactionStates.ACTIVE;\n\n /** Symbol-keyed so the state stays off the handle's string-keyed surface. */\n get [TRANSACTION_STATE_KEY](): TTransactionState {\n return this.#state;\n }\n\n get isActive(): boolean {\n return this.#state === TransactionStates.ACTIVE;\n }\n\n protected get lifecycleState(): TTransactionState {\n return this.#state;\n }\n\n // Own properties, not prototype methods, so a detached `transaction.commit` still works.\n readonly commit = (): Promise<void> => this.end({ end: TransactionLifecycle.COMMIT });\n readonly rollback = (): Promise<void> => this.end({ end: TransactionLifecycle.ROLLBACK });\n\n /** Runs the end statement. Called at most once per transaction, after the state has left ACTIVE. */\n protected abstract executeEnd(opts: { end: ITransactionEnd }): Promise<unknown>;\n\n protected onEnded(_opts: { end: ITransactionEnd }): void {}\n\n protected onEndFailed(_opts: { end: ITransactionEnd; error: unknown }): void {}\n\n protected onRollbackAfterFailure(): void {}\n\n private async end(opts: { end: ITransactionEnd }): Promise<void> {\n const { end } = opts;\n\n if (this.#state !== TransactionStates.ACTIVE) {\n // After a FAILED end the transaction is already torn down, so rollback is satisfied by construction - throwing here would replace the caller's original error in `catch { await tx.rollback(); throw error; }`.\n if (this.#state === TransactionStates.FAILED && end === TransactionLifecycle.ROLLBACK) {\n this.onRollbackAfterFailure();\n return;\n }\n\n throw getError({ message: `[Transaction][${end.verb}] Transaction already ended` });\n }\n\n // Left ACTIVE BEFORE the await: commit racing rollback would otherwise both pass the guard, issue two end statements, and double-release the same connection.\n this.#state = end.endedState;\n\n try {\n await this.executeEnd({ end });\n } catch (error) {\n this.onEndFailed({ end, error });\n this.#state = TransactionStates.FAILED;\n throw error;\n }\n\n this.onEnded({ end });\n }\n}\n"]}
1
+ {"version":3,"file":"transaction-lifecycle.js","sourceRoot":"","sources":["../../../../../src/relational/core/datasources/transaction-lifecycle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGvD,kHAAkH;AAClH,MAAM,OAAO,iBAAiB;aACZ,WAAM,GAAG,QAAQ,CAAC;aAClB,cAAS,GAAG,WAAW,CAAC;aACxB,gBAAW,GAAG,aAAa,CAAC;aAC5B,WAAM,GAAG,QAAQ,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAC;QACnC,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,MAAM;KACZ,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAMH,gNAAgN;AAChN,MAAM,CAAC,MAAM,qBAAqB,GAAkB,MAAM,CAAC,GAAG,CAC5D,6CAA6C,CAC9C,CAAC;AAQF;;;;GAIG;AACH,MAAM,OAAgB,oBAAoB;IAA1C;QAuBE,0GAA0G;QAC1G,WAAM,GAAsB,iBAAiB,CAAC,MAAM,CAAC;QAerD,yFAAyF;QAChF,WAAM,GAAG,GAAkB,EAAE,CAAC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AM,EAAE,CAAC;YAC7C,gNAAgN;YAChN,IAAI,IAAI,CAAC,MAAM,KAAK,iBAAiB,CAAC,MAAM,IAAI,GAAG,KAAK,oBAAoB,CAAC,QAAQ,EAAE,CAAC;gBACtF,IAAI,CAAC,sBAAsB,EAAE,CAAC;gBAE9B,OAAO;YACT,CAAC;YAED,MAAM,QAAQ,CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,CAAC,IAAI,6BAA6B,EAAE,CAAC,CAAC;QACtF,CAAC;QAED,8JAA8J;QAC9J,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC;QAE7B,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;YACjC,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC;YACvC,MAAM,KAAK,CAAC;QACd,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACxB,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { ITransaction } from '@venizia/ignis-kernel';\n\n/** Lifecycle states of a transaction handle: `ACTIVE` until it ends as `COMMITTED`, `ROLLED_BACK` or `FAILED`. */\nexport class TransactionStates {\n static readonly ACTIVE = 'ACTIVE';\n static readonly COMMITTED = 'COMMITTED';\n static readonly ROLLED_BACK = 'ROLLED_BACK';\n static readonly FAILED = 'FAILED';\n\n static readonly SCHEME_SET = new Set([\n this.ACTIVE,\n this.COMMITTED,\n this.ROLLED_BACK,\n this.FAILED,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** One of the {@link TransactionStates} values. */\nexport type TTransactionState = TConstValue<typeof TransactionStates>;\n\n/** Registry symbol, not a module-private one: two installed copies of this package (two versions in one tree) each load their own copy of this class, and a handle from one must still be read by the other. */\nexport const TRANSACTION_STATE_KEY: unique symbol = Symbol.for(\n '@venizia/ignis-connectors/transaction-state',\n);\n\nexport interface ITransactionEnd {\n verb: string;\n statement: string;\n endedState: TTransactionState;\n}\n\n/**\n * The end-of-transaction rules every handle shares, the real one and the test double alike: the\n * first commit() or rollback() wins, a second end throws, and rollback() after a failed end is a\n * no-op. A subclass supplies only the statement and what happens around it.\n */\nexport abstract class TransactionLifecycle implements ITransaction {\n private static readonly COMMIT: ITransactionEnd = {\n verb: 'commit',\n statement: 'COMMIT',\n endedState: TransactionStates.COMMITTED,\n };\n\n private static readonly ROLLBACK: ITransactionEnd = {\n verb: 'rollback',\n statement: 'ROLLBACK',\n endedState: TransactionStates.ROLLED_BACK,\n };\n\n /** True only for a handle built on `TransactionLifecycle`, from either build, that ended by COMMIT. */\n static isCommitted(opts: { transaction: object }): boolean {\n const { transaction } = opts;\n\n return (\n TRANSACTION_STATE_KEY in transaction &&\n transaction[TRANSACTION_STATE_KEY] === TransactionStates.COMMITTED\n );\n }\n\n // ES-private, not TS-private: a handle that is logged, spread or serialised must not carry its internals.\n #state: TTransactionState = TransactionStates.ACTIVE;\n\n /** Symbol-keyed so the state stays off the handle's string-keyed surface. */\n get [TRANSACTION_STATE_KEY](): TTransactionState {\n return this.#state;\n }\n\n get isActive(): boolean {\n return this.#state === TransactionStates.ACTIVE;\n }\n\n protected get lifecycleState(): TTransactionState {\n return this.#state;\n }\n\n // Own properties, not prototype methods, so a detached `transaction.commit` still works.\n readonly commit = (): Promise<void> => this.end({ end: TransactionLifecycle.COMMIT });\n readonly rollback = (): Promise<void> => this.end({ end: TransactionLifecycle.ROLLBACK });\n\n /** Runs the end statement. Called at most once per transaction, after the state has left ACTIVE. */\n protected abstract executeEnd(opts: { end: ITransactionEnd }): Promise<unknown>;\n\n protected onEnded(_opts: { end: ITransactionEnd }): void {}\n\n protected onEndFailed(_opts: { end: ITransactionEnd; error: unknown }): void {}\n\n protected onRollbackAfterFailure(): void {}\n\n private async end(opts: { end: ITransactionEnd }): Promise<void> {\n const { end } = opts;\n\n if (this.#state !== TransactionStates.ACTIVE) {\n // After a FAILED end the transaction is already torn down, so rollback is satisfied by construction - throwing here would replace the caller's original error in `catch { await tx.rollback(); throw error; }`.\n if (this.#state === TransactionStates.FAILED && end === TransactionLifecycle.ROLLBACK) {\n this.onRollbackAfterFailure();\n\n return;\n }\n\n throw getError({ message: `[Transaction][${end.verb}] Transaction already ended` });\n }\n\n // Left ACTIVE BEFORE the await: commit racing rollback would otherwise both pass the guard, issue two end statements, and double-release the same connection.\n this.#state = end.endedState;\n\n try {\n await this.executeEnd({ end });\n } catch (error) {\n this.onEndFailed({ end, error });\n this.#state = TransactionStates.FAILED;\n throw error;\n }\n\n this.onEnded({ end });\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { BaseHelper } from '@venizia/ignis-helpers/core';
2
2
  import type { IRelationalDriver } from '../drivers/index.js';
3
+ /** One migration to apply. `sql` may hold several statements separated by `--> statement-breakpoint`, as `drizzle-kit generate` writes them. */
3
4
  export interface IMigration {
4
5
  /** Ledger key. Never rewrite an applied one - see the hashing note on {@link RelationalMigrationRunner}. */
5
6
  name: string;
@@ -36,7 +37,11 @@ export declare class RelationalMigrationRunner extends BaseHelper {
36
37
  private isSessionPoisoned;
37
38
  constructor(opts: {
38
39
  driver: IRelationalDriver<unknown>;
39
- /** Defaults to `ignis_migrations`. Validated like a migration name. */
40
+ /**
41
+ * The table that records applied migrations. Validated like a migration name.
42
+ *
43
+ * @default 'ignis_migrations'
44
+ */
40
45
  ledgerTable?: string;
41
46
  scope?: string;
42
47
  });
@@ -1 +1 @@
1
- {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../../../src/relational/core/migrations/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC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EAAE,CAAC;gBACvB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;gBAC9B,IAAI,CAAC,MAAM;qBACR,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;qBACvB,KAAK,CAAC,wCAAwC,EAAE,SAAS,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;YACpF,CAAC;YAED,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF","sourcesContent":["import { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport type { IRelationalDriver } from '../drivers';\n\nexport interface IMigration {\n /** Ledger key. Never rewrite an applied one - see the hashing note on {@link RelationalMigrationRunner}. */\n name: string;\n sql: string;\n}\n\n/** A name safe to embed as a SQL literal, checked rather than escaped - see {@link RelationalMigrationRunner.assertSafeName}. */\nconst SAFE_MIGRATION_NAME = /^[A-Za-z0-9._-]+$/;\n\nconst DEFAULT_LEDGER_TABLE = 'ignis_migrations';\n\n/** What `drizzle-kit generate` writes between statements in a single `.sql` file. */\nconst STATEMENT_BREAKPOINT = '--> statement-breakpoint';\n\n/**\n * Applies every migration not already in the ledger, each with its ledger row, in ONE transaction.\n *\n * Exists because Drizzle's own migrator cannot run everywhere: `drizzle-orm/*\\/migrator` reads the\n * migration folder through `node:fs`, so it resolves to nothing in a browser. This runs off a driver\n * connection instead, which every engine already implements.\n *\n * The property that matters is that the DDL and its ledger row commit together. Run as two\n * statements they would not: a bare `exec` commits when it returns, so a process killed between\n * them leaves the table present and the ledger empty, and the next boot re-runs a bare\n * `CREATE TABLE` and dies with `already exists` from then on. In a browser that window lands on the\n * FIRST visit, while the page is still fetching WASM - the likeliest moment for a user to close the\n * tab. A storage-quota failure on the INSERT does the same.\n *\n * TWO LIMITS THE TRANSACTION AND THE MINIMAL LEDGER IMPOSE, both deliberate:\n *\n * 1. Postgres refuses some DDL inside a transaction block, so a migration may not contain\n * `CREATE INDEX CONCURRENTLY` - which Drizzle emits for any `.concurrently()` index. Measured: it\n * fails with `CREATE INDEX CONCURRENTLY cannot run inside a transaction block`, while a bare\n * `exec` accepts it. Atomicity is worth more than a concurrent index build.\n * 2. The ledger keys on the NAME and stores no content hash, so editing an already-applied migration\n * is silently skipped rather than reported. Drizzle's own migrator hashes for this reason. Add a\n * migration; never rewrite one.\n */\nexport class RelationalMigrationRunner extends BaseHelper {\n private readonly driver: IRelationalDriver<unknown>;\n private readonly ledgerTable: string;\n\n /** Set when a ROLLBACK itself fails, so the connection is destroyed rather than pooled. */\n private isSessionPoisoned = false;\n\n constructor(opts: {\n driver: IRelationalDriver<unknown>;\n /** Defaults to `ignis_migrations`. Validated like a migration name. */\n ledgerTable?: string;\n scope?: string;\n }) {\n super({ scope: opts.scope ?? RelationalMigrationRunner.name });\n\n this.driver = opts.driver;\n this.ledgerTable = RelationalMigrationRunner.assertSafeName({\n value: opts.ledgerTable ?? DEFAULT_LEDGER_TABLE,\n field: 'ledgerTable',\n });\n }\n\n /**\n * Placeholder syntax is not portable (`$1` on Postgres, `?` on SQLite), so the ledger name is\n * embedded as a literal rather than bound. That is only safe because it is checked first: these\n * names are authored in code, never taken from a request, and anything outside the character set\n * is refused rather than escaped. Escaping is what gets this wrong; refusing cannot.\n */\n private static assertSafeName(opts: { value: string; field: string }): string {\n const { value, field } = opts;\n\n if (!SAFE_MIGRATION_NAME.test(value)) {\n throw getError({\n message: `[RelationalMigrationRunner] Unsafe ${field} | value: ${value} | allowed: letters, digits, '.', '_', '-'`,\n });\n }\n\n return value;\n }\n\n /** Splits on `drizzle-kit`'s own breakpoint marker; a hand-written single-statement migration has none and comes back whole. */\n static splitStatements(opts: { sql: string }): Array<string> {\n return opts.sql\n .split(STATEMENT_BREAKPOINT)\n .map((statement) => statement.trim())\n .filter((statement) => statement.length > 0);\n }\n\n async run(opts: { migrations: ReadonlyArray<IMigration> }): Promise<void> {\n const { migrations } = opts;\n const logger = this.logger.for(this.run.name);\n\n for (const migration of migrations) {\n RelationalMigrationRunner.assertSafeName({ value: migration.name, field: 'migration name' });\n }\n\n const connection = await this.driver.acquire({ schema: {} });\n\n try {\n // Idempotent and outside any transaction on purpose: it carries no data, so re-running it\n // after an interrupted boot is a no-op rather than a conflict.\n await connection.execute({\n statement: `CREATE TABLE IF NOT EXISTS \"${this.ledgerTable}\" (\"name\" text PRIMARY KEY NOT NULL)`,\n });\n\n const applied = await connection.query<{ name: string }>({\n statement: `SELECT \"name\" FROM \"${this.ledgerTable}\"`,\n });\n const appliedNames = new Set(applied.map((row) => row.name));\n\n for (const migration of migrations) {\n if (appliedNames.has(migration.name)) {\n logger.info('Migration already applied, skipping | name: %s', migration.name);\n continue;\n }\n\n await this.applyOne({ connection, migration });\n logger.info('Applied migration | name: %s', migration.name);\n }\n } finally {\n connection.release({ destroy: this.isSessionPoisoned });\n }\n }\n\n /** BEGIN/COMMIT written here rather than through `beginTransaction()`: that acquires its OWN connection, and the ledger read above has to see the same session on a single-connection engine. */\n private async applyOne(opts: {\n connection: Awaited<ReturnType<IRelationalDriver<unknown>['acquire']>>;\n migration: IMigration;\n }): Promise<void> {\n const { connection, migration } = opts;\n\n await connection.execute({ statement: 'BEGIN' });\n\n try {\n // One statement per call: only some clients accept a multi-statement string (PGlite's `exec`\n // does, its `query` does not), and `drizzle-kit` already marks the boundaries for us.\n const statements = RelationalMigrationRunner.splitStatements({ sql: migration.sql });\n for (const statement of statements) {\n await connection.execute({ statement });\n }\n\n await connection.execute({\n statement: `INSERT INTO \"${this.ledgerTable}\" (\"name\") VALUES ('${migration.name}')`,\n });\n await connection.execute({ statement: 'COMMIT' });\n } catch (error) {\n this.logger\n .for(this.applyOne.name)\n .error('Migration failed, rolling back | name: %s | error: %s', migration.name, error);\n\n // A FAILED rollback leaves the session inside a transaction. Returning that connection to\n // the pool hands the next borrower an aborted session - the driver contract says such a\n // connection must be destroyed, and the datasource teardown already does exactly that.\n try {\n await connection.execute({ statement: 'ROLLBACK' });\n } catch (rollbackError) {\n this.isSessionPoisoned = true;\n this.logger\n .for(this.applyOne.name)\n .error('Rollback failed | name: %s | error: %s', migration.name, rollbackError);\n }\n\n throw error;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../../../src/relational/core/migrations/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAUnE,iIAAiI;AACjI,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AAEhD,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AAEhD,qFAAqF;AACrF,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,yBAA0B,SAAQ,UAAU;IAOvD,YAAY,IASX;QACC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,yBAAyB,CAAC,IAAI,EAAE,CAAC,CAAC;QAbjE,2FAA2F;QACnF,sBAAiB,GAAG,KAAK,CAAC;QAchC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,WAAW,GAAG,yBAAyB,CAAC,cAAc,CAAC;YAC1D,KAAK,EAAE,IAAI,CAAC,WAAW,IAAI,oBAAoB;YAC/C,KAAK,EAAE,aAAa;SACrB,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,cAAc,CAAC,IAAsC;QAClE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAE9B,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,sCAAsC,KAAK,aAAa,KAAK,4CAA4C;aACnH,CAAC,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,gIAAgI;IAChI,MAAM,CAAC,eAAe,CAAC,IAAqB;QAC1C,OAAO,IAAI,CAAC,GAAG;aAC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,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAEzF,0FAA0F;YAC1F,wFAAwF;YACxF,uFAAuF;YACvF,IAAI,CAAC;gBACH,MAAM,UAAU,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;YACtD,CAAC;YAAC,OAAO,aAAa,EAAE,CAAC;gBACvB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;gBAC9B,IAAI,CAAC,MAAM;qBACR,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;qBACvB,KAAK,CAAC,wCAAwC,EAAE,SAAS,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;YACpF,CAAC;YAED,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF","sourcesContent":["import { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport type { IRelationalDriver } from '../drivers';\n\n/** One migration to apply. `sql` may hold several statements separated by `--> statement-breakpoint`, as `drizzle-kit generate` writes them. */\nexport interface IMigration {\n /** Ledger key. Never rewrite an applied one - see the hashing note on {@link RelationalMigrationRunner}. */\n name: string;\n sql: string;\n}\n\n/** A name safe to embed as a SQL literal, checked rather than escaped - see {@link RelationalMigrationRunner.assertSafeName}. */\nconst SAFE_MIGRATION_NAME = /^[A-Za-z0-9._-]+$/;\n\nconst DEFAULT_LEDGER_TABLE = 'ignis_migrations';\n\n/** What `drizzle-kit generate` writes between statements in a single `.sql` file. */\nconst STATEMENT_BREAKPOINT = '--> statement-breakpoint';\n\n/**\n * Applies every migration not already in the ledger, each with its ledger row, in ONE transaction.\n *\n * Exists because Drizzle's own migrator cannot run everywhere: `drizzle-orm/*\\/migrator` reads the\n * migration folder through `node:fs`, so it resolves to nothing in a browser. This runs off a driver\n * connection instead, which every engine already implements.\n *\n * The property that matters is that the DDL and its ledger row commit together. Run as two\n * statements they would not: a bare `exec` commits when it returns, so a process killed between\n * them leaves the table present and the ledger empty, and the next boot re-runs a bare\n * `CREATE TABLE` and dies with `already exists` from then on. In a browser that window lands on the\n * FIRST visit, while the page is still fetching WASM - the likeliest moment for a user to close the\n * tab. A storage-quota failure on the INSERT does the same.\n *\n * TWO LIMITS THE TRANSACTION AND THE MINIMAL LEDGER IMPOSE, both deliberate:\n *\n * 1. Postgres refuses some DDL inside a transaction block, so a migration may not contain\n * `CREATE INDEX CONCURRENTLY` - which Drizzle emits for any `.concurrently()` index. Measured: it\n * fails with `CREATE INDEX CONCURRENTLY cannot run inside a transaction block`, while a bare\n * `exec` accepts it. Atomicity is worth more than a concurrent index build.\n * 2. The ledger keys on the NAME and stores no content hash, so editing an already-applied migration\n * is silently skipped rather than reported. Drizzle's own migrator hashes for this reason. Add a\n * migration; never rewrite one.\n */\nexport class RelationalMigrationRunner extends BaseHelper {\n private readonly driver: IRelationalDriver<unknown>;\n private readonly ledgerTable: string;\n\n /** Set when a ROLLBACK itself fails, so the connection is destroyed rather than pooled. */\n private isSessionPoisoned = false;\n\n constructor(opts: {\n driver: IRelationalDriver<unknown>;\n /**\n * The table that records applied migrations. Validated like a migration name.\n *\n * @default 'ignis_migrations'\n */\n ledgerTable?: string;\n scope?: string;\n }) {\n super({ scope: opts.scope ?? RelationalMigrationRunner.name });\n\n this.driver = opts.driver;\n this.ledgerTable = RelationalMigrationRunner.assertSafeName({\n value: opts.ledgerTable ?? DEFAULT_LEDGER_TABLE,\n field: 'ledgerTable',\n });\n }\n\n /**\n * Placeholder syntax is not portable (`$1` on Postgres, `?` on SQLite), so the ledger name is\n * embedded as a literal rather than bound. That is only safe because it is checked first: these\n * names are authored in code, never taken from a request, and anything outside the character set\n * is refused rather than escaped. Escaping is what gets this wrong; refusing cannot.\n */\n private static assertSafeName(opts: { value: string; field: string }): string {\n const { value, field } = opts;\n\n if (!SAFE_MIGRATION_NAME.test(value)) {\n throw getError({\n message: `[RelationalMigrationRunner] Unsafe ${field} | value: ${value} | allowed: letters, digits, '.', '_', '-'`,\n });\n }\n\n return value;\n }\n\n /** Splits on `drizzle-kit`'s own breakpoint marker; a hand-written single-statement migration has none and comes back whole. */\n static splitStatements(opts: { sql: string }): Array<string> {\n return opts.sql\n .split(STATEMENT_BREAKPOINT)\n .map((statement) => statement.trim())\n .filter((statement) => statement.length > 0);\n }\n\n async run(opts: { migrations: ReadonlyArray<IMigration> }): Promise<void> {\n const { migrations } = opts;\n const logger = this.logger.for(this.run.name);\n\n for (const migration of migrations) {\n RelationalMigrationRunner.assertSafeName({ value: migration.name, field: 'migration name' });\n }\n\n const connection = await this.driver.acquire({ schema: {} });\n\n try {\n // Idempotent and outside any transaction on purpose: it carries no data, so re-running it\n // after an interrupted boot is a no-op rather than a conflict.\n await connection.execute({\n statement: `CREATE TABLE IF NOT EXISTS \"${this.ledgerTable}\" (\"name\" text PRIMARY KEY NOT NULL)`,\n });\n\n const applied = await connection.query<{ name: string }>({\n statement: `SELECT \"name\" FROM \"${this.ledgerTable}\"`,\n });\n const appliedNames = new Set(applied.map((row) => row.name));\n\n for (const migration of migrations) {\n if (appliedNames.has(migration.name)) {\n logger.info('Migration already applied, skipping | name: %s', migration.name);\n continue;\n }\n\n await this.applyOne({ connection, migration });\n logger.info('Applied migration | name: %s', migration.name);\n }\n } finally {\n connection.release({ destroy: this.isSessionPoisoned });\n }\n }\n\n /** BEGIN/COMMIT written here rather than through `beginTransaction()`: that acquires its OWN connection, and the ledger read above has to see the same session on a single-connection engine. */\n private async applyOne(opts: {\n connection: Awaited<ReturnType<IRelationalDriver<unknown>['acquire']>>;\n migration: IMigration;\n }): Promise<void> {\n const { connection, migration } = opts;\n\n await connection.execute({ statement: 'BEGIN' });\n\n try {\n // One statement per call: only some clients accept a multi-statement string (PGlite's `exec`\n // does, its `query` does not), and `drizzle-kit` already marks the boundaries for us.\n const statements = RelationalMigrationRunner.splitStatements({ sql: migration.sql });\n\n for (const statement of statements) {\n await connection.execute({ statement });\n }\n\n await connection.execute({\n statement: `INSERT INTO \"${this.ledgerTable}\" (\"name\") VALUES ('${migration.name}')`,\n });\n await connection.execute({ statement: 'COMMIT' });\n } catch (error) {\n this.logger\n .for(this.applyOne.name)\n .error('Migration failed, rolling back | name: %s | error: %s', migration.name, error);\n\n // A FAILED rollback leaves the session inside a transaction. Returning that connection to\n // the pool hands the next borrower an aborted session - the driver contract says such a\n // connection must be destroyed, and the datasource teardown already does exactly that.\n try {\n await connection.execute({ statement: 'ROLLBACK' });\n } catch (rollbackError) {\n this.isSessionPoisoned = true;\n this.logger\n .for(this.applyOne.name)\n .error('Rollback failed | name: %s | error: %s', migration.name, rollbackError);\n }\n\n throw error;\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../../src/relational/core/models/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,8CAA8C;AAC9C,IAAI,aAAiE,CAAC;AACtE,MAAM,gBAAgB,GAAG,GAA2C,EAAE,CACpE,CAAC,aAAa,KAAK,mBAAmB,EAAE,CAAC,CAAC;AAE5C,gGAAgG;AAChG,MAAM,OAAO,oBACX,SAAQ,cAAc;IAgBtB,YAAY,IAAyC;QACnD,MAAM,IAAI,GAAG,GAAG,CAAC,MAAqC,CAAC;QACvD,MAAM,IAAI,GAAG,IAAI,EAAE,IAAI,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI,CAAC;QAExD,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAEhB,IAAI,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,IAAK,IAAI,C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,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE;iBACzI,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { TIdSchemaType, TSchemaType } from '@venizia/ignis-kernel';\nimport { AbstractEntity, SchemaTypes } from '@venizia/ignis-kernel';\nimport type { TRelationConfig } from '@/relational/core/repositories/common';\nimport type { TValueOrResolver } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { createSchemaFactory } from 'drizzle-zod';\nimport type { Column, Table } from 'drizzle-orm';\nimport { getTableColumns } from 'drizzle-orm';\nimport type { IEntity, TTableInsert, TTableObject, TTableSchemaWithId } from './common';\nimport { RelationalEntityUtility } from './common';\nimport { AuditFields } from './common/constants';\n\n/** Lazy singleton, shared by every entity. */\nlet schemaFactory: ReturnType<typeof createSchemaFactory> | undefined;\nconst getSchemaFactory = (): ReturnType<typeof createSchemaFactory> =>\n (schemaFactory ??= createSchemaFactory());\n\n/** Base entity with Drizzle ORM support. Supports static schema or constructor-based schema. */\nexport class BaseRelationalEntity<Schema extends TTableSchemaWithId = TTableSchemaWithId>\n extends AbstractEntity\n implements IEntity<Schema>\n{\n schema: Schema;\n\n // Phantom type carriers (no runtime value; `declare` emits nothing).\n declare readonly $inferData?: TTableObject<Schema>;\n declare readonly $inferPersist?: TTableInsert<Schema>;\n\n static TABLE_NAME?: string;\n static AUTHORIZATION_SUBJECT?: string;\n\n /** A carrier, deliberately widened to `Table`: a factory-built entity knows its table precisely, and a narrower static would reject that precise type. The CONTRACT stays on the instance, typed `Schema`. */\n static schema: Table;\n static relations?: TValueOrResolver<Array<TRelationConfig>>;\n\n constructor(opts?: { name?: string; schema?: Schema }) {\n const ctor = new.target as typeof BaseRelationalEntity;\n const name = opts?.name ?? ctor.TABLE_NAME ?? ctor.name;\n\n super({ name });\n\n this.schema = opts?.schema ?? (ctor.schema as Schema);\n }\n\n /** Maps the schema's id column's Drizzle `dataType` to 'number' (serial/integer) or 'string' (everything else, including bigint/unknown). */\n override getIdType(): TIdSchemaType {\n return RelationalEntityUtility.getIdType({ entity: this.schema }) === 'number'\n ? 'number'\n : 'string';\n }\n\n /** The audit keys whose column carries a default or `$onUpdate`; an audit column with neither is left to the client. */\n override getServerStampedKeys(): string[] {\n const columns: Record<string, Column | undefined> = getTableColumns(this.schema);\n\n return [...AuditFields.SCHEME_SET].filter((key) => {\n const column = columns[key];\n return column !== undefined && (column.hasDefault || column.onUpdateFn !== undefined);\n });\n }\n\n getSchema<T = unknown>(opts: { type: TSchemaType }): T {\n const factory = getSchemaFactory();\n\n switch (opts.type) {\n case SchemaTypes.CREATE: {\n return factory.createInsertSchema(this.schema) as T;\n }\n case SchemaTypes.UPDATE: {\n return factory.createUpdateSchema(this.schema) as T;\n }\n case SchemaTypes.SELECT: {\n return factory.createSelectSchema(this.schema) as T;\n }\n default: {\n throw getError({\n message: `[getSchema] Invalid schema type | type: ${opts.type} | valid: ${[SchemaTypes.SELECT, SchemaTypes.UPDATE, SchemaTypes.CREATE]}`,\n });\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../../src/relational/core/models/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,8CAA8C;AAC9C,IAAI,aAAiE,CAAC;AACtE,MAAM,gBAAgB,GAAG,GAA2C,EAAE,CACpE,CAAC,aAAa,KAAK,mBAAmB,EAAE,CAAC,CAAC;AAE5C,gGAAg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AAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAM,CAAC;YACtD,CAAC;YACD,KAAK,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;gBACxB,OAAO,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAM,CAAC;YACtD,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,QAAQ,CAAC;oBACb,OAAO,EAAE,2CAA2C,IAAI,CAAC,IAAI,aAAa,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE;iBACzI,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { TIdSchemaType, TSchemaType } from '@venizia/ignis-kernel';\nimport { AbstractEntity, SchemaTypes } from '@venizia/ignis-kernel';\nimport type { TRelationConfig } from '@/relational/core/repositories/common';\nimport type { TValueOrResolver } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { createSchemaFactory } from 'drizzle-zod';\nimport type { Column, Table } from 'drizzle-orm';\nimport { getTableColumns } from 'drizzle-orm';\nimport type { IEntity, TTableInsert, TTableObject, TTableSchemaWithId } from './common';\nimport { RelationalEntityUtility } from './common';\nimport { AuditFields } from './common/constants';\n\n/** Lazy singleton, shared by every entity. */\nlet schemaFactory: ReturnType<typeof createSchemaFactory> | undefined;\nconst getSchemaFactory = (): ReturnType<typeof createSchemaFactory> =>\n (schemaFactory ??= createSchemaFactory());\n\n/** Base entity with Drizzle ORM support. Supports static schema or constructor-based schema. */\nexport class BaseRelationalEntity<Schema extends TTableSchemaWithId = TTableSchemaWithId>\n extends AbstractEntity\n implements IEntity<Schema>\n{\n schema: Schema;\n\n // Phantom type carriers (no runtime value; `declare` emits nothing).\n declare readonly $inferData?: TTableObject<Schema>;\n declare readonly $inferPersist?: TTableInsert<Schema>;\n\n static TABLE_NAME?: string;\n static AUTHORIZATION_SUBJECT?: string;\n\n /** A carrier, deliberately widened to `Table`: a factory-built entity knows its table precisely, and a narrower static would reject that precise type. The CONTRACT stays on the instance, typed `Schema`. */\n static schema: Table;\n static relations?: TValueOrResolver<Array<TRelationConfig>>;\n\n constructor(opts?: { name?: string; schema?: Schema }) {\n const ctor = new.target as typeof BaseRelationalEntity;\n const name = opts?.name ?? ctor.TABLE_NAME ?? ctor.name;\n\n super({ name });\n\n this.schema = opts?.schema ?? (ctor.schema as Schema);\n }\n\n /** Maps the schema's id column's Drizzle `dataType` to 'number' (serial/integer) or 'string' (everything else, including bigint/unknown). */\n override getIdType(): TIdSchemaType {\n return RelationalEntityUtility.getIdType({ entity: this.schema }) === 'number'\n ? 'number'\n : 'string';\n }\n\n /** The audit keys whose column carries a default or `$onUpdate`; an audit column with neither is left to the client. */\n override getServerStampedKeys(): string[] {\n const columns: Record<string, Column | undefined> = getTableColumns(this.schema);\n\n return [...AuditFields.SCHEME_SET].filter((key) => {\n const column = columns[key];\n\n return column !== undefined && (column.hasDefault || column.onUpdateFn !== undefined);\n });\n }\n\n getSchema<T = unknown>(opts: { type: TSchemaType }): T {\n const factory = getSchemaFactory();\n\n switch (opts.type) {\n case SchemaTypes.CREATE: {\n return factory.createInsertSchema(this.schema) as T;\n }\n case SchemaTypes.UPDATE: {\n return factory.createUpdateSchema(this.schema) as T;\n }\n case SchemaTypes.SELECT: {\n return factory.createSelectSchema(this.schema) as T;\n }\n default: {\n throw getError({\n message: `[getSchema] Invalid schema type | type: ${opts.type} | valid: ${[SchemaTypes.SELECT, SchemaTypes.UPDATE, SchemaTypes.CREATE]}`,\n });\n }\n }\n }\n}\n"]}
@@ -3,10 +3,13 @@ import { type RelationTypes } from '@venizia/ignis-kernel';
3
3
  import type { TRelationConfig } from '../../repositories/common/index.js';
4
4
  import type { TValueOrResolver } from '@venizia/ignis-helpers/common';
5
5
  import type { AnyColumn, ColumnBuilderBase, IsPrimaryKey, NotNull, Table, TableConfig } from 'drizzle-orm';
6
+ /** A single Drizzle column builder, whatever the engine. */
6
7
  export type TColumnDefinition = ColumnBuilderBase;
8
+ /** A map of field names to column builders. */
7
9
  export type TColumnDefinitions = {
8
10
  [field: string | symbol]: TColumnDefinition;
9
11
  };
12
+ /** Marks the column builder `T` as a not-null primary key. */
10
13
  export type TPrimaryKey<T extends TColumnDefinition> = IsPrimaryKey<NotNull<T>>;
11
14
  /** Any Drizzle column whose runtime value is a valid entity id. Drizzle's root `AnyColumn<TPartial>` is the exact dialect-free twin of `AnyPgColumn<TPartial>`, so this does not widen the bound. */
12
15
  export type TIdColumn = AnyColumn<{
@@ -16,9 +19,13 @@ export type TIdColumn = AnyColumn<{
16
19
  export type TTableSchemaWithId<TC extends TableConfig = TableConfig> = Table<TC> & {
17
20
  id: TIdColumn;
18
21
  };
22
+ /** The row shape a select returns for the table `T`. */
19
23
  export type TTableObject<T extends TTableSchemaWithId> = T['$inferSelect'];
24
+ /** The row shape an insert takes for the table `T`. */
20
25
  export type TTableInsert<T extends TTableSchemaWithId> = T['$inferInsert'];
26
+ /** The type of the `id` column of the table `T`. */
21
27
  export type TGetIdType<T extends TTableSchemaWithId> = TTableObject<T>['id'];
28
+ /** Helpers for reading facts off an entity table schema. */
22
29
  export declare class RelationalEntityUtility {
23
30
  static getIdType<T extends TTableSchemaWithId>(opts: {
24
31
  entity: T;
@@ -34,16 +41,19 @@ export interface IEntity<Schema extends TTableSchemaWithId = TTableSchemaWithId>
34
41
  export type TRelationMetadata<Type extends TRelationConfig['type']> = Extract<TRelationConfig, {
35
42
  type: Type;
36
43
  }>['metadata'];
44
+ /** A to-many relation to `schema`, as built by `many()`; `metadata` is the Drizzle relation options. */
37
45
  export interface IManyRelation<Schema extends TTableSchemaWithId = TTableSchemaWithId> {
38
46
  type: typeof RelationTypes.MANY;
39
47
  schema: Schema;
40
48
  metadata?: TRelationMetadata<typeof RelationTypes.MANY>;
41
49
  }
50
+ /** A to-one relation to `schema`, as built by `one()`; `metadata` is the Drizzle relation options. */
42
51
  export interface IOneRelation<Schema extends TTableSchemaWithId = TTableSchemaWithId> {
43
52
  type: typeof RelationTypes.ONE;
44
53
  schema: Schema;
45
54
  metadata?: TRelationMetadata<typeof RelationTypes.ONE>;
46
55
  }
56
+ /** A relation declared with `many()` or `one()`, before its name is attached. */
47
57
  export type TRelationDefinition = IManyRelation | IOneRelation;
48
58
  /**
49
59
  * Relations keyed by name. Each points at a SCHEMA, never at another entity: an entity reference
@@ -1,3 +1,4 @@
1
+ /** Helpers for reading facts off an entity table schema. */
1
2
  export class RelationalEntityUtility {
2
3
  static getIdType(opts) {
3
4
  return opts.entity?.id?.dataType ?? 'unknown';
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/relational/core/models/common/types.ts"],"names":[],"mappings":"AA+BA,MAAM,OAAO,uBAAuB;IAClC,MAAM,CAAC,SAAS,CAA+B,IAAmB;QAChE,OAAO,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,QAAQ,IAAI,SAAS,CAAC;IAChD,CAAC;CACF","sourcesContent":["import type { IdType } from '@venizia/ignis-kernel';\nimport { type RelationTypes } from '@venizia/ignis-kernel';\nimport type { TRelationConfig } from '@/relational/core/repositories/common';\nimport type { TValueOrResolver } from '@venizia/ignis-helpers/common';\nimport type {\n AnyColumn,\n ColumnBuilderBase,\n IsPrimaryKey,\n NotNull,\n Table,\n TableConfig,\n} from 'drizzle-orm';\n\nexport type TColumnDefinition = ColumnBuilderBase;\nexport type TColumnDefinitions = {\n [field: string | symbol]: TColumnDefinition;\n};\nexport type TPrimaryKey<T extends TColumnDefinition> = IsPrimaryKey<NotNull<T>>;\n\n/** Any Drizzle column whose runtime value is a valid entity id. Drizzle's root `AnyColumn<TPartial>` is the exact dialect-free twin of `AnyPgColumn<TPartial>`, so this does not widen the bound. */\nexport type TIdColumn = AnyColumn<{ data: IdType }>;\n\n/** The engine-neutral bound. `PgTable` and `SQLiteTable` both extend `Table`, and `Table` carries `$inferSelect` / `$inferInsert`. */\nexport type TTableSchemaWithId<TC extends TableConfig = TableConfig> = Table<TC> & {\n id: TIdColumn;\n};\n\nexport type TTableObject<T extends TTableSchemaWithId> = T['$inferSelect'];\nexport type TTableInsert<T extends TTableSchemaWithId> = T['$inferInsert'];\nexport type TGetIdType<T extends TTableSchemaWithId> = TTableObject<T>['id'];\n\nexport class RelationalEntityUtility {\n static getIdType<T extends TTableSchemaWithId>(opts: { entity: T }) {\n return opts.entity?.id?.dataType ?? 'unknown';\n }\n}\n\n/** Static schema + relations contract every entity model implements. */\nexport interface IEntity<Schema extends TTableSchemaWithId = TTableSchemaWithId> {\n TABLE_NAME?: string;\n schema: Schema;\n relations?: TValueOrResolver<Array<TRelationConfig>>;\n}\n\n/** The drizzle relation options for a given relation type, as its helper declares them. */\nexport type TRelationMetadata<Type extends TRelationConfig['type']> = Extract<\n TRelationConfig,\n { type: Type }\n>['metadata'];\n\nexport interface IManyRelation<Schema extends TTableSchemaWithId = TTableSchemaWithId> {\n type: typeof RelationTypes.MANY;\n schema: Schema;\n metadata?: TRelationMetadata<typeof RelationTypes.MANY>;\n}\n\nexport interface IOneRelation<Schema extends TTableSchemaWithId = TTableSchemaWithId> {\n type: typeof RelationTypes.ONE;\n schema: Schema;\n metadata?: TRelationMetadata<typeof RelationTypes.ONE>;\n}\n\nexport type TRelationDefinition = IManyRelation | IOneRelation;\n\n/**\n * Relations keyed by name. Each points at a SCHEMA, never at another entity: an entity reference\n * across two files that import each other collapses to `any` under TS7022, silently.\n */\nexport type TRelationDefinitions = Record<string, TRelationDefinition>;\n\n/**\n * The entity shape {@link TEntityObject} reads: a class whose instances carry their row type, plus\n * its relations. The row is read off the INSTANCE - the class's static `schema` is widened to\n * `Table` on the base, and a row read through it would take `Table`'s index signature and let\n * every unknown key through.\n */\nexport interface IDefinedEntity<Relations extends TRelationDefinitions = TRelationDefinitions> {\n new (...args: never): { $inferData?: unknown };\n /** Undefined when the entity declares no relations. */\n relationDefinitions: Relations | undefined;\n}\n\ntype TRowOf<Entity> = Entity extends new (...args: never) => { $inferData?: infer Row }\n ? NonNullable<Row>\n : never;\n\ntype TDefinitionsOf<Entity extends IDefinedEntity> = NonNullable<Entity['relationDefinitions']>;\n\n/** A row of the entity plus its relations, so a relation is declared once instead of twice. */\nexport type TEntityObject<Entity extends IDefinedEntity> = TRowOf<Entity> & {\n [Name in keyof TDefinitionsOf<Entity>]?: TDefinitionsOf<Entity>[Name] extends {\n type: typeof RelationTypes.MANY;\n }\n ? Array<TTableObject<TDefinitionsOf<Entity>[Name]['schema']>>\n : TTableObject<TDefinitionsOf<Entity>[Name]['schema']>;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/relational/core/models/common/types.ts"],"names":[],"mappings":"AAqCA,4DAA4D;AAC5D,MAAM,OAAO,uBAAuB;IAClC,MAAM,CAAC,SAAS,CAA+B,IAAmB;QAChE,OAAO,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,QAAQ,IAAI,SAAS,CAAC;IAChD,CAAC;CACF","sourcesContent":["import type { IdType } from '@venizia/ignis-kernel';\nimport { type RelationTypes } from '@venizia/ignis-kernel';\nimport type { TRelationConfig } from '@/relational/core/repositories/common';\nimport type { TValueOrResolver } from '@venizia/ignis-helpers/common';\nimport type {\n AnyColumn,\n ColumnBuilderBase,\n IsPrimaryKey,\n NotNull,\n Table,\n TableConfig,\n} from 'drizzle-orm';\n\n/** A single Drizzle column builder, whatever the engine. */\nexport type TColumnDefinition = ColumnBuilderBase;\n/** A map of field names to column builders. */\nexport type TColumnDefinitions = {\n [field: string | symbol]: TColumnDefinition;\n};\n/** Marks the column builder `T` as a not-null primary key. */\nexport type TPrimaryKey<T extends TColumnDefinition> = IsPrimaryKey<NotNull<T>>;\n\n/** Any Drizzle column whose runtime value is a valid entity id. Drizzle's root `AnyColumn<TPartial>` is the exact dialect-free twin of `AnyPgColumn<TPartial>`, so this does not widen the bound. */\nexport type TIdColumn = AnyColumn<{ data: IdType }>;\n\n/** The engine-neutral bound. `PgTable` and `SQLiteTable` both extend `Table`, and `Table` carries `$inferSelect` / `$inferInsert`. */\nexport type TTableSchemaWithId<TC extends TableConfig = TableConfig> = Table<TC> & {\n id: TIdColumn;\n};\n\n/** The row shape a select returns for the table `T`. */\nexport type TTableObject<T extends TTableSchemaWithId> = T['$inferSelect'];\n/** The row shape an insert takes for the table `T`. */\nexport type TTableInsert<T extends TTableSchemaWithId> = T['$inferInsert'];\n/** The type of the `id` column of the table `T`. */\nexport type TGetIdType<T extends TTableSchemaWithId> = TTableObject<T>['id'];\n\n/** Helpers for reading facts off an entity table schema. */\nexport class RelationalEntityUtility {\n static getIdType<T extends TTableSchemaWithId>(opts: { entity: T }) {\n return opts.entity?.id?.dataType ?? 'unknown';\n }\n}\n\n/** Static schema + relations contract every entity model implements. */\nexport interface IEntity<Schema extends TTableSchemaWithId = TTableSchemaWithId> {\n TABLE_NAME?: string;\n schema: Schema;\n relations?: TValueOrResolver<Array<TRelationConfig>>;\n}\n\n/** The drizzle relation options for a given relation type, as its helper declares them. */\nexport type TRelationMetadata<Type extends TRelationConfig['type']> = Extract<\n TRelationConfig,\n { type: Type }\n>['metadata'];\n\n/** A to-many relation to `schema`, as built by `many()`; `metadata` is the Drizzle relation options. */\nexport interface IManyRelation<Schema extends TTableSchemaWithId = TTableSchemaWithId> {\n type: typeof RelationTypes.MANY;\n schema: Schema;\n metadata?: TRelationMetadata<typeof RelationTypes.MANY>;\n}\n\n/** A to-one relation to `schema`, as built by `one()`; `metadata` is the Drizzle relation options. */\nexport interface IOneRelation<Schema extends TTableSchemaWithId = TTableSchemaWithId> {\n type: typeof RelationTypes.ONE;\n schema: Schema;\n metadata?: TRelationMetadata<typeof RelationTypes.ONE>;\n}\n\n/** A relation declared with `many()` or `one()`, before its name is attached. */\nexport type TRelationDefinition = IManyRelation | IOneRelation;\n\n/**\n * Relations keyed by name. Each points at a SCHEMA, never at another entity: an entity reference\n * across two files that import each other collapses to `any` under TS7022, silently.\n */\nexport type TRelationDefinitions = Record<string, TRelationDefinition>;\n\n/**\n * The entity shape {@link TEntityObject} reads: a class whose instances carry their row type, plus\n * its relations. The row is read off the INSTANCE - the class's static `schema` is widened to\n * `Table` on the base, and a row read through it would take `Table`'s index signature and let\n * every unknown key through.\n */\nexport interface IDefinedEntity<Relations extends TRelationDefinitions = TRelationDefinitions> {\n new (...args: never): { $inferData?: unknown };\n /** Undefined when the entity declares no relations. */\n relationDefinitions: Relations | undefined;\n}\n\ntype TRowOf<Entity> = Entity extends new (...args: never) => { $inferData?: infer Row }\n ? NonNullable<Row>\n : never;\n\ntype TDefinitionsOf<Entity extends IDefinedEntity> = NonNullable<Entity['relationDefinitions']>;\n\n/** A row of the entity plus its relations, so a relation is declared once instead of twice. */\nexport type TEntityObject<Entity extends IDefinedEntity> = TRowOf<Entity> & {\n [Name in keyof TDefinitionsOf<Entity>]?: TDefinitionsOf<Entity>[Name] extends {\n type: typeof RelationTypes.MANY;\n }\n ? Array<TTableObject<TDefinitionsOf<Entity>[Name]['schema']>>\n : TTableObject<TDefinitionsOf<Entity>[Name]['schema']>;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"audit-user.js","sourceRoot":"","sources":["../../../../../../src/relational/core/models/enrichers/audit-user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/E;;;;;;;;;;GAUG;AACH,MAAM,OAAO,iBAAiB;IAC5B,MAAM,CAAC,kBAAkB,CAAI,IAAsD;QACjF,MAAM,OAAO,GAAG,sBAAsB,CAAC,OAAO,EAAE,CAAC;QACjD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;gBACzB,MAAM,QAAQ,CAAC;oBACb,OAAO,EAAE,6EAA6E,IAAI,CAAC,WAAW,sBAAsB,IAAI,CAAC,cAAc,EAAE;iBAClJ,CAAC,CAAC;YACL,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QACzD,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACpC,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,8EAA8E,IAAI,CAAC,WAAW,sBAAsB,IAAI,CAAC,cAAc,cAAc,MAAM,EAAE;aACvK,CAAC,CAAC;QACL,CAAC;QAED,OAAQ,MAAY,IAAI,IAAI,CAAC;IAC/B,CAAC;CACF","sourcesContent":["import { getError } from '@venizia/ignis-helpers/core';\nimport { Authentication, RequestContextRegistry } from '@venizia/ignis-kernel';\n\n/**\n * Who to stamp on `created_by` / `modified_by`. Engine-neutral on purpose: the column BUILDERS\n * differ per dialect, this decision does not, and it was byte-identical in the postgres and sqlite\n * enrichers - so every review of this security-adjacent path had to happen twice.\n *\n * CAUTION: fire-and-forget promises may run outside async context, losing AUDIT_USER_ID.\n *\n * The context comes from the registry, never from `hono/context-storage` directly: that module\n * constructs an `AsyncLocalStorage` in its own body, which is a `TypeError` at import in a browser.\n * A host with no resolver installed reports \"no request context\" - the first branch below.\n */\nexport class AuditUserResolver {\n static resolveAuditUserId<T>(opts: { allowAnonymous: boolean; columnField: string }): T | null {\n const context = RequestContextRegistry.resolve();\n if (!context) {\n if (!opts.allowAnonymous) {\n throw getError({\n message: `[getCurrentUserId] Invalid request context to identify user | columnName: ${opts.columnField} | allowAnonymous: ${opts.allowAnonymous}`,\n });\n }\n\n return null;\n }\n\n const userId = context.get(Authentication.AUDIT_USER_ID);\n if (!userId && !opts.allowAnonymous) {\n throw getError({\n message: `[getCurrentUserId] No AUDIT_USER_ID found in request context | columnName: ${opts.columnField} | allowAnonymous: ${opts.allowAnonymous} | userId: ${userId}`,\n });\n }\n\n return (userId as T) ?? null;\n }\n}\n"]}
1
+ {"version":3,"file":"audit-user.js","sourceRoot":"","sources":["../../../../../../src/relational/core/models/enrichers/audit-user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/E;;;;;;;;;;GAUG;AACH,MAAM,OAAO,iBAAiB;IAC5B,MAAM,CAAC,kBAAkB,CAAI,IAAsD;QACjF,MAAM,OAAO,GAAG,sBAAsB,CAAC,OAAO,EAAE,CAAC;QAEjD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;gBACzB,MAAM,QAAQ,CAAC;oBACb,OAAO,EAAE,6EAA6E,IAAI,CAAC,WAAW,sBAAsB,IAAI,CAAC,cAAc,EAAE;iBAClJ,CAAC,CAAC;YACL,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAEzD,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACpC,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,8EAA8E,IAAI,CAAC,WAAW,sBAAsB,IAAI,CAAC,cAAc,cAAc,MAAM,EAAE;aACvK,CAAC,CAAC;QACL,CAAC;QAED,OAAQ,MAAY,IAAI,IAAI,CAAC;IAC/B,CAAC;CACF","sourcesContent":["import { getError } from '@venizia/ignis-helpers/core';\nimport { Authentication, RequestContextRegistry } from '@venizia/ignis-kernel';\n\n/**\n * Who to stamp on `created_by` / `modified_by`. Engine-neutral on purpose: the column BUILDERS\n * differ per dialect, this decision does not, and it was byte-identical in the postgres and sqlite\n * enrichers - so every review of this security-adjacent path had to happen twice.\n *\n * CAUTION: fire-and-forget promises may run outside async context, losing AUDIT_USER_ID.\n *\n * The context comes from the registry, never from `hono/context-storage` directly: that module\n * constructs an `AsyncLocalStorage` in its own body, which is a `TypeError` at import in a browser.\n * A host with no resolver installed reports \"no request context\" - the first branch below.\n */\nexport class AuditUserResolver {\n static resolveAuditUserId<T>(opts: { allowAnonymous: boolean; columnField: string }): T | null {\n const context = RequestContextRegistry.resolve();\n\n if (!context) {\n if (!opts.allowAnonymous) {\n throw getError({\n message: `[getCurrentUserId] Invalid request context to identify user | columnName: ${opts.columnField} | allowAnonymous: ${opts.allowAnonymous}`,\n });\n }\n\n return null;\n }\n\n const userId = context.get(Authentication.AUDIT_USER_ID);\n\n if (!userId && !opts.allowAnonymous) {\n throw getError({\n message: `[getCurrentUserId] No AUDIT_USER_ID found in request context | columnName: ${opts.columnField} | allowAnonymous: ${opts.allowAnonymous} | userId: ${userId}`,\n });\n }\n\n return (userId as T) ?? null;\n }\n}\n"]}
@@ -20,6 +20,20 @@ export declare class ModelFactory {
20
20
  * The table comes first, as a plain drizzle table (`pgTable`, `pgSchema(...).table`,
21
21
  * `sqliteTable`): relations point at TABLES, so two entities that relate to each other never
22
22
  * import each other, and the compiler keeps both row types.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * import { ModelFactory, one } from '@venizia/ignis-connectors/relational';
27
+ * import { integer, pgTable } from 'drizzle-orm/pg-core';
28
+ *
29
+ * const users = pgTable('User', { id: integer('id').primaryKey() });
30
+ * const posts = pgTable('Post', { id: integer('id').primaryKey(), authorId: integer('author_id') });
31
+ *
32
+ * export class Post extends ModelFactory.defineEntity({
33
+ * table: posts,
34
+ * relations: () => ({ author: one(users, { fields: [posts.authorId], references: [users.id] }) }),
35
+ * }) {}
36
+ * ```
23
37
  */
24
38
  static defineEntity<Schema extends TTableSchemaWithId, Relations extends TRelationDefinitions = {}>(opts: {
25
39
  table: Schema;