@warlock.js/cascade 5.31.0 → 5.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/cjs/index.cjs +104 -85
  3. package/cjs/index.cjs.map +1 -1
  4. package/esm/context/database-data-source-context.d.mts +2 -3
  5. package/esm/context/database-data-source-context.d.mts.map +1 -1
  6. package/esm/context/database-transaction-context.d.mts +2 -3
  7. package/esm/context/database-transaction-context.d.mts.map +1 -1
  8. package/esm/contracts/database-driver.contract.d.mts +56 -36
  9. package/esm/contracts/database-driver.contract.d.mts.map +1 -1
  10. package/esm/contracts/database-id-generator.contract.d.mts +7 -5
  11. package/esm/contracts/database-id-generator.contract.d.mts.map +1 -1
  12. package/esm/contracts/database-remover.contract.d.mts +3 -5
  13. package/esm/contracts/database-remover.contract.d.mts.map +1 -1
  14. package/esm/contracts/database-restorer.contract.d.mts +6 -6
  15. package/esm/contracts/database-restorer.contract.d.mts.map +1 -1
  16. package/esm/contracts/database-writer.contract.d.mts +4 -6
  17. package/esm/contracts/database-writer.contract.d.mts.map +1 -1
  18. package/esm/contracts/driver-blueprint.contract.d.mts +2 -3
  19. package/esm/contracts/driver-blueprint.contract.d.mts.map +1 -1
  20. package/esm/contracts/index.d.mts +2 -1
  21. package/esm/contracts/migration-driver.contract.d.mts +101 -53
  22. package/esm/contracts/migration-driver.contract.d.mts.map +1 -1
  23. package/esm/contracts/query-builder.contract.d.mts +51 -33
  24. package/esm/contracts/query-builder.contract.d.mts.map +1 -1
  25. package/esm/contracts/sync-adapter.contract.d.mts +25 -14
  26. package/esm/contracts/sync-adapter.contract.d.mts.map +1 -1
  27. package/esm/data-source/data-source-registry.d.mts +4 -5
  28. package/esm/data-source/data-source-registry.d.mts.map +1 -1
  29. package/esm/data-source/data-source.d.mts +8 -5
  30. package/esm/data-source/data-source.d.mts.map +1 -1
  31. package/esm/database-dirty-tracker.d.mts +2 -2
  32. package/esm/database-dirty-tracker.d.mts.map +1 -1
  33. package/esm/database-dirty-tracker.mjs +3 -2
  34. package/esm/database-dirty-tracker.mjs.map +1 -1
  35. package/esm/drivers/mongodb/mongodb-driver.d.mts +3 -4
  36. package/esm/drivers/mongodb/mongodb-driver.d.mts.map +1 -1
  37. package/esm/drivers/mongodb/mongodb-id-generator.d.mts +2 -3
  38. package/esm/drivers/mongodb/mongodb-id-generator.d.mts.map +1 -1
  39. package/esm/drivers/mongodb/mongodb-migration-driver.d.mts +1 -3
  40. package/esm/drivers/mongodb/mongodb-migration-driver.d.mts.map +1 -1
  41. package/esm/drivers/mongodb/mongodb-query-builder.d.mts +2 -3
  42. package/esm/drivers/mongodb/mongodb-query-builder.d.mts.map +1 -1
  43. package/esm/drivers/mongodb/mongodb-query-builder.mjs +8 -5
  44. package/esm/drivers/mongodb/mongodb-query-builder.mjs.map +1 -1
  45. package/esm/drivers/mongodb/mongodb-query-operations.d.mts +1 -3
  46. package/esm/drivers/mongodb/mongodb-query-operations.d.mts.map +1 -1
  47. package/esm/drivers/mongodb/mongodb-query-parser.d.mts +7 -6
  48. package/esm/drivers/mongodb/mongodb-query-parser.d.mts.map +1 -1
  49. package/esm/drivers/mongodb/mongodb-query-parser.mjs +2 -6
  50. package/esm/drivers/mongodb/mongodb-query-parser.mjs.map +1 -1
  51. package/esm/drivers/mongodb/mongodb-sync-adapter.d.mts +1 -3
  52. package/esm/drivers/mongodb/mongodb-sync-adapter.d.mts.map +1 -1
  53. package/esm/drivers/mongodb/types.d.mts +11 -9
  54. package/esm/drivers/mongodb/types.d.mts.map +1 -1
  55. package/esm/drivers/postgres/index.d.mts +2 -1
  56. package/esm/drivers/postgres/index.mjs +1 -1
  57. package/esm/drivers/postgres/naming.mjs +1 -1
  58. package/esm/drivers/postgres/postgres-blueprint.d.mts +1 -3
  59. package/esm/drivers/postgres/postgres-blueprint.d.mts.map +1 -1
  60. package/esm/drivers/postgres/postgres-dialect.d.mts +4 -6
  61. package/esm/drivers/postgres/postgres-dialect.d.mts.map +1 -1
  62. package/esm/drivers/postgres/postgres-driver.d.mts +4 -5
  63. package/esm/drivers/postgres/postgres-driver.d.mts.map +1 -1
  64. package/esm/drivers/postgres/postgres-migration-driver.d.mts +1 -3
  65. package/esm/drivers/postgres/postgres-migration-driver.d.mts.map +1 -1
  66. package/esm/drivers/postgres/postgres-migration-driver.mjs +13 -10
  67. package/esm/drivers/postgres/postgres-migration-driver.mjs.map +1 -1
  68. package/esm/drivers/postgres/postgres-query-builder.d.mts +4 -4
  69. package/esm/drivers/postgres/postgres-query-builder.d.mts.map +1 -1
  70. package/esm/drivers/postgres/postgres-query-builder.mjs +14 -10
  71. package/esm/drivers/postgres/postgres-query-builder.mjs.map +1 -1
  72. package/esm/drivers/postgres/postgres-query-parser.d.mts +16 -11
  73. package/esm/drivers/postgres/postgres-query-parser.d.mts.map +1 -1
  74. package/esm/drivers/postgres/postgres-query-parser.mjs +1 -1
  75. package/esm/drivers/postgres/postgres-query-parser.mjs.map +1 -1
  76. package/esm/drivers/postgres/postgres-sql-serializer.mjs +13 -10
  77. package/esm/drivers/postgres/postgres-sql-serializer.mjs.map +1 -1
  78. package/esm/drivers/postgres/postgres-ttl-purge.mjs +1 -1
  79. package/esm/drivers/postgres/postgres-type-converters.mjs +2 -2
  80. package/esm/drivers/postgres/postgres-type-converters.mjs.map +1 -1
  81. package/esm/drivers/postgres/postgres-update-validator.mjs +1 -1
  82. package/esm/drivers/postgres/postgres-update-validator.mjs.map +1 -1
  83. package/esm/drivers/postgres/types.d.mts +87 -45
  84. package/esm/drivers/postgres/types.d.mts.map +1 -1
  85. package/esm/drivers/sql/sql-dialect.contract.d.mts +1 -3
  86. package/esm/drivers/sql/sql-dialect.contract.d.mts.map +1 -1
  87. package/esm/drivers/sql/sql-types.d.mts +113 -59
  88. package/esm/drivers/sql/sql-types.d.mts.map +1 -1
  89. package/esm/errors/missing-data-source.error.d.mts +1 -2
  90. package/esm/errors/missing-data-source.error.d.mts.map +1 -1
  91. package/esm/errors/transaction-rollback.error.d.mts +1 -2
  92. package/esm/errors/transaction-rollback.error.d.mts.map +1 -1
  93. package/esm/errors/undefined-where-value.error.d.mts +1 -2
  94. package/esm/errors/undefined-where-value.error.d.mts.map +1 -1
  95. package/esm/errors/unsafe-filter.error.d.mts +1 -2
  96. package/esm/errors/unsafe-filter.error.d.mts.map +1 -1
  97. package/esm/errors/unsafe-raw-expression.error.d.mts +1 -2
  98. package/esm/errors/unsafe-raw-expression.error.d.mts.map +1 -1
  99. package/esm/errors/unsupported-lean-operation.error.d.mts +1 -2
  100. package/esm/errors/unsupported-lean-operation.error.d.mts.map +1 -1
  101. package/esm/errors/unsupported-lock-for-update.error.d.mts +1 -2
  102. package/esm/errors/unsupported-lock-for-update.error.d.mts.map +1 -1
  103. package/esm/errors/unsupported-query-operation.error.d.mts +1 -2
  104. package/esm/errors/unsupported-query-operation.error.d.mts.map +1 -1
  105. package/esm/errors/unsupported-update-operation.error.d.mts +1 -2
  106. package/esm/errors/unsupported-update-operation.error.d.mts.map +1 -1
  107. package/esm/events/model-events.d.mts +8 -6
  108. package/esm/events/model-events.d.mts.map +1 -1
  109. package/esm/expressions/aggregate-expressions.d.mts +7 -7
  110. package/esm/expressions/aggregate-expressions.d.mts.map +1 -1
  111. package/esm/expressions/column-expressions.d.mts +11 -11
  112. package/esm/expressions/column-expressions.d.mts.map +1 -1
  113. package/esm/index.d.mts +7 -2
  114. package/esm/index.mjs +1 -1
  115. package/esm/migration/column-builder.d.mts +2 -3
  116. package/esm/migration/column-builder.d.mts.map +1 -1
  117. package/esm/migration/column-helpers.d.mts +49 -50
  118. package/esm/migration/column-helpers.d.mts.map +1 -1
  119. package/esm/migration/column-helpers.mjs +1 -1
  120. package/esm/migration/foreign-key-builder.d.mts +2 -3
  121. package/esm/migration/foreign-key-builder.d.mts.map +1 -1
  122. package/esm/migration/index.d.mts +3 -2
  123. package/esm/migration/index.mjs +2 -2
  124. package/esm/migration/migration-runner.d.mts +7 -6
  125. package/esm/migration/migration-runner.d.mts.map +1 -1
  126. package/esm/migration/migration-runner.mjs +15 -11
  127. package/esm/migration/migration-runner.mjs.map +1 -1
  128. package/esm/migration/migration.d.mts +50 -32
  129. package/esm/migration/migration.d.mts.map +1 -1
  130. package/esm/migration/migration.mjs +1 -3
  131. package/esm/migration/migration.mjs.map +1 -1
  132. package/esm/migration/sql-serializer.d.mts +1 -3
  133. package/esm/migration/sql-serializer.d.mts.map +1 -1
  134. package/esm/migration/types.d.mts +7 -7
  135. package/esm/migration/types.d.mts.map +1 -1
  136. package/esm/model/methods/accessor-methods.mjs +1 -1
  137. package/esm/model/methods/accessor-methods.mjs.map +1 -1
  138. package/esm/model/methods/meta-methods.mjs +4 -2
  139. package/esm/model/methods/meta-methods.mjs.map +1 -1
  140. package/esm/model/methods/query-methods.mjs +1 -1
  141. package/esm/model/methods/write-methods.d.mts +3 -2
  142. package/esm/model/methods/write-methods.d.mts.map +1 -1
  143. package/esm/model/methods/write-methods.mjs +5 -2
  144. package/esm/model/methods/write-methods.mjs.map +1 -1
  145. package/esm/model/model.d.mts +9 -9
  146. package/esm/model/model.d.mts.map +1 -1
  147. package/esm/model/model.types.d.mts +7 -7
  148. package/esm/model/model.types.d.mts.map +1 -1
  149. package/esm/model/register-model.d.mts +13 -15
  150. package/esm/model/register-model.d.mts.map +1 -1
  151. package/esm/model/relation-decorators.d.mts +6 -8
  152. package/esm/model/relation-decorators.d.mts.map +1 -1
  153. package/esm/operations/database.d.mts +13 -8
  154. package/esm/operations/database.d.mts.map +1 -1
  155. package/esm/operations/index.d.mts +2 -1
  156. package/esm/operations/index.mjs +1 -1
  157. package/esm/operations/migrations.d.mts +18 -14
  158. package/esm/operations/migrations.d.mts.map +1 -1
  159. package/esm/query-builder/query-builder.d.mts +2 -4
  160. package/esm/query-builder/query-builder.d.mts.map +1 -1
  161. package/esm/query-builder/query-builder.mjs +12 -11
  162. package/esm/query-builder/query-builder.mjs.map +1 -1
  163. package/esm/relations/index.d.mts +2 -1
  164. package/esm/relations/index.mjs +1 -1
  165. package/esm/relations/key-conventions.mjs +2 -1
  166. package/esm/relations/key-conventions.mjs.map +1 -1
  167. package/esm/relations/pivot-operations.d.mts +3 -5
  168. package/esm/relations/pivot-operations.d.mts.map +1 -1
  169. package/esm/relations/relation-hydrator.d.mts +3 -5
  170. package/esm/relations/relation-hydrator.d.mts.map +1 -1
  171. package/esm/relations/relation-loader.d.mts +2 -4
  172. package/esm/relations/relation-loader.d.mts.map +1 -1
  173. package/esm/relations/relation-loader.mjs +4 -5
  174. package/esm/relations/relation-loader.mjs.map +1 -1
  175. package/esm/relations/types.d.mts +14 -15
  176. package/esm/relations/types.d.mts.map +1 -1
  177. package/esm/remover/database-remover.d.mts +1 -3
  178. package/esm/remover/database-remover.d.mts.map +1 -1
  179. package/esm/restorer/database-restorer.d.mts +1 -3
  180. package/esm/restorer/database-restorer.d.mts.map +1 -1
  181. package/esm/restorer/database-restorer.mjs +2 -1
  182. package/esm/restorer/database-restorer.mjs.map +1 -1
  183. package/esm/sql-database-dirty-tracker.d.mts +1 -3
  184. package/esm/sql-database-dirty-tracker.d.mts.map +1 -1
  185. package/esm/sync/model-events.mjs +1 -1
  186. package/esm/sync/model-sync-operation.d.mts +2 -4
  187. package/esm/sync/model-sync-operation.d.mts.map +1 -1
  188. package/esm/sync/model-sync.d.mts +3 -4
  189. package/esm/sync/model-sync.d.mts.map +1 -1
  190. package/esm/sync/sync-context.d.mts +2 -4
  191. package/esm/sync/sync-context.d.mts.map +1 -1
  192. package/esm/sync/sync-fanout.mjs +1 -1
  193. package/esm/sync/sync-manager.d.mts +2 -4
  194. package/esm/sync/sync-manager.d.mts.map +1 -1
  195. package/esm/sync/types.d.mts +121 -64
  196. package/esm/sync/types.d.mts.map +1 -1
  197. package/esm/transactions/after-commit.d.mts +2 -2
  198. package/esm/transactions/after-commit.d.mts.map +1 -1
  199. package/esm/types.d.mts +7 -8
  200. package/esm/types.d.mts.map +1 -1
  201. package/esm/utils/connect-to-database.d.mts +7 -8
  202. package/esm/utils/connect-to-database.d.mts.map +1 -1
  203. package/esm/utils/database-writer.utils.d.mts +3 -4
  204. package/esm/utils/database-writer.utils.d.mts.map +1 -1
  205. package/esm/utils/define-model.d.mts +3 -5
  206. package/esm/utils/define-model.d.mts.map +1 -1
  207. package/esm/utils/escape-regex.d.mts +3 -4
  208. package/esm/utils/escape-regex.d.mts.map +1 -1
  209. package/esm/utils/once-connected.d.mts +2 -4
  210. package/esm/utils/once-connected.d.mts.map +1 -1
  211. package/esm/utils/sanitize-filter.d.mts +3 -4
  212. package/esm/utils/sanitize-filter.d.mts.map +1 -1
  213. package/esm/validation/database-seal-plugins.d.mts +2 -1
  214. package/esm/validation/database-writer-validation-error.d.mts +1 -3
  215. package/esm/validation/database-writer-validation-error.d.mts.map +1 -1
  216. package/esm/validation/index.d.mts +3 -1
  217. package/esm/validation/index.mjs +1 -1
  218. package/esm/validation/plugins/database-rules-plugin.d.mts +2 -3
  219. package/esm/validation/plugins/database-rules-plugin.d.mts.map +1 -1
  220. package/esm/validation/plugins/embed-validator-plugin.d.mts +4 -3
  221. package/esm/validation/plugins/embed-validator-plugin.d.mts.map +1 -1
  222. package/esm/validation/types.d.mts +14 -10
  223. package/esm/validation/types.d.mts.map +1 -1
  224. package/esm/validation/validators/embed-validator.d.mts +2 -3
  225. package/esm/validation/validators/embed-validator.d.mts.map +1 -1
  226. package/esm/writer/database-writer.d.mts +1 -3
  227. package/esm/writer/database-writer.d.mts.map +1 -1
  228. package/esm/writer/database-writer.mjs +1 -1
  229. package/esm/writer/database-writer.mjs.map +1 -1
  230. package/package.json +5 -5
@@ -322,7 +322,7 @@ var PostgresQueryBuilder = class PostgresQueryBuilder extends QueryBuilder {
322
322
  if (timing === "before") beforeOps.push(...temp.operations);
323
323
  else afterOps.push(...temp.operations);
324
324
  }
325
- const HAS_OP_TYPES = new Set([
325
+ const HAS_OP_TYPES = /* @__PURE__ */ new Set([
326
326
  "has",
327
327
  "whereHas",
328
328
  "orWhereHas",
@@ -475,8 +475,10 @@ var PostgresQueryBuilder = class PostgresQueryBuilder extends QueryBuilder {
475
475
  if (!def) throw new Error(`Relation "${segName}" not found on model ${currentModel?.name ?? "unknown"}`);
476
476
  let selectColumns = segColumns ?? def.select;
477
477
  let constraintOps;
478
- if (i === segments.length - 1 && constraint !== void 0) if (typeof constraint === "string") selectColumns = constraint.split(",").filter(Boolean);
479
- else constraintOps = this._resolveConstraintOps(constraint);
478
+ if (i === segments.length - 1 && constraint !== void 0) {
479
+ if (typeof constraint === "string") selectColumns = constraint.split(",").filter(Boolean);
480
+ else constraintOps = this._resolveConstraintOps(constraint);
481
+ }
480
482
  const alias = currentPath.replace(/\./g, "_");
481
483
  this.joinRelations.set(currentPath, {
482
484
  alias,
@@ -984,7 +986,7 @@ var PostgresQueryBuilder = class PostgresQueryBuilder extends QueryBuilder {
984
986
  */
985
987
  applyHasRelations() {
986
988
  if (this.hasRelationsApplied) return;
987
- const HAS_OP_TYPES = new Set([
989
+ const HAS_OP_TYPES = /* @__PURE__ */ new Set([
988
990
  "has",
989
991
  "whereHas",
990
992
  "orWhereHas",
@@ -1308,12 +1310,14 @@ var PostgresQueryBuilder = class PostgresQueryBuilder extends QueryBuilder {
1308
1310
  const RelatedModel = resolveModelClass(config.model);
1309
1311
  if (!RelatedModel) continue;
1310
1312
  const childKeys = Array.from(this.joinRelations.keys()).filter((p) => p.startsWith(`${path}.`)).map((p) => p.split(".")[path.split(".").length]).filter((segment) => segment !== void 0);
1311
- if (config.type === "hasMany") attachLoadedRelation(model, key, (Array.isArray(data) ? data : []).map((row) => {
1312
- const rowData = { ...row };
1313
- for (const childKey of childKeys) delete rowData[childKey];
1314
- return RelatedModel.hydrate(rowData);
1315
- }));
1316
- else {
1313
+ if (config.type === "hasMany") {
1314
+ const instances = (Array.isArray(data) ? data : []).map((row) => {
1315
+ const rowData = { ...row };
1316
+ for (const childKey of childKeys) delete rowData[childKey];
1317
+ return RelatedModel.hydrate(rowData);
1318
+ });
1319
+ attachLoadedRelation(model, key, instances);
1320
+ } else {
1317
1321
  const modelData = { ...data };
1318
1322
  for (const childKey of childKeys) delete modelData[childKey];
1319
1323
  const relatedInstance = RelatedModel.hydrate(modelData);