postgrelize 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (319) hide show
  1. package/CHANGELOG.md +289 -0
  2. package/LICENSE +21 -0
  3. package/README.md +131 -2
  4. package/dist/associations/alias-minifier.d.ts +43 -0
  5. package/dist/associations/association-accessors.d.ts +21 -0
  6. package/dist/associations/association-key-types.d.ts +44 -0
  7. package/dist/associations/association-keys.d.ts +98 -0
  8. package/dist/associations/association-lookup.d.ts +26 -0
  9. package/dist/associations/association-shape.d.ts +25 -0
  10. package/dist/associations/association.d.ts +95 -0
  11. package/dist/associations/belongs-to-many.d.ts +86 -0
  12. package/dist/associations/belongs-to.d.ts +45 -0
  13. package/dist/associations/has-many.d.ts +79 -0
  14. package/dist/associations/has-one.d.ts +44 -0
  15. package/dist/associations/include-assembler.d.ts +21 -0
  16. package/dist/associations/include-columns.d.ts +24 -0
  17. package/dist/associations/include-joins.d.ts +17 -0
  18. package/dist/associations/include-loader.d.ts +48 -0
  19. package/dist/associations/include-order.d.ts +22 -0
  20. package/dist/associations/include-query-builder.d.ts +54 -0
  21. package/dist/associations/include-resolver.d.ts +29 -0
  22. package/dist/associations/include-rows.d.ts +47 -0
  23. package/dist/associations/include-sub-query.d.ts +35 -0
  24. package/dist/associations/include.d.ts +112 -0
  25. package/dist/associations/junction-keys.d.ts +23 -0
  26. package/dist/associations/nested-creator.d.ts +44 -0
  27. package/dist/associations/nested-saver.d.ts +30 -0
  28. package/dist/associations/owner-keys.d.ts +34 -0
  29. package/dist/associations/separate-include-loader.d.ts +24 -0
  30. package/dist/associations/types.d.ts +139 -0
  31. package/dist/connection/after-connect-hook.d.ts +24 -0
  32. package/dist/connection/connect-hooks.d.ts +26 -0
  33. package/dist/connection/connection-config.d.ts +33 -0
  34. package/dist/connection/connection-manager.d.ts +65 -0
  35. package/dist/connection/connection-types.d.ts +21 -0
  36. package/dist/connection/copy-from-stdin.d.ts +52 -0
  37. package/dist/connection/copy-runner.d.ts +30 -0
  38. package/dist/connection/copy-to-stdout.d.ts +49 -0
  39. package/dist/connection/copy.d.ts +22 -0
  40. package/dist/connection/notifications.d.ts +28 -0
  41. package/dist/connection/options.d.ts +165 -0
  42. package/dist/connection/query-logger.d.ts +41 -0
  43. package/dist/connection/replica-router.d.ts +20 -0
  44. package/dist/connection/statement-cache.d.ts +36 -0
  45. package/dist/connection/statement-timeout.d.ts +22 -0
  46. package/dist/data-types/abstract-data-type.d.ts +58 -0
  47. package/dist/data-types/array-literal-parser.d.ts +17 -0
  48. package/dist/data-types/array-type.d.ts +18 -0
  49. package/dist/data-types/bit-type.d.ts +14 -0
  50. package/dist/data-types/blob-type.d.ts +12 -0
  51. package/dist/data-types/char-type.d.ts +12 -0
  52. package/dist/data-types/composite-fields.d.ts +26 -0
  53. package/dist/data-types/composite-type.d.ts +32 -0
  54. package/dist/data-types/data-types.d.ts +176 -0
  55. package/dist/data-types/date-type.d.ts +14 -0
  56. package/dist/data-types/decimal-type.d.ts +13 -0
  57. package/dist/data-types/default-value-generator.d.ts +15 -0
  58. package/dist/data-types/enum-type.d.ts +19 -0
  59. package/dist/data-types/ewkb-reader.d.ts +18 -0
  60. package/dist/data-types/ewkb-writer.d.ts +17 -0
  61. package/dist/data-types/float-type.d.ts +12 -0
  62. package/dist/data-types/geometric-text.d.ts +65 -0
  63. package/dist/data-types/geometric-type.d.ts +46 -0
  64. package/dist/data-types/hstore-type.d.ts +16 -0
  65. package/dist/data-types/integer-type.d.ts +24 -0
  66. package/dist/data-types/json-type.d.ts +16 -0
  67. package/dist/data-types/multirange-type.d.ts +19 -0
  68. package/dist/data-types/range-type.d.ts +28 -0
  69. package/dist/data-types/record-text.d.ts +29 -0
  70. package/dist/data-types/scalar-type.d.ts +13 -0
  71. package/dist/data-types/spatial-type.d.ts +20 -0
  72. package/dist/data-types/string-type.d.ts +12 -0
  73. package/dist/data-types/text-type.d.ts +12 -0
  74. package/dist/data-types/timestamp-type.d.ts +15 -0
  75. package/dist/data-types/virtual-type.d.ts +15 -0
  76. package/dist/data-types/wall-clock.d.ts +14 -0
  77. package/dist/ddl/column-ddl.d.ts +73 -0
  78. package/dist/ddl/constraint-ddl.d.ts +30 -0
  79. package/dist/ddl/ddl-generator.d.ts +181 -0
  80. package/dist/ddl/ddl-guards.d.ts +60 -0
  81. package/dist/ddl/ddl-types.d.ts +204 -0
  82. package/dist/ddl/enum-ddl.d.ts +42 -0
  83. package/dist/ddl/extension-ddl.d.ts +57 -0
  84. package/dist/ddl/function-ddl.d.ts +98 -0
  85. package/dist/ddl/index-ddl.d.ts +29 -0
  86. package/dist/ddl/index-element-ddl.d.ts +19 -0
  87. package/dist/ddl/partition-ddl.d.ts +88 -0
  88. package/dist/ddl/partition-types.d.ts +94 -0
  89. package/dist/ddl/policy-ddl.d.ts +137 -0
  90. package/dist/ddl/routine-guards.d.ts +63 -0
  91. package/dist/ddl/sequence-ddl.d.ts +103 -0
  92. package/dist/ddl/sql-literal.d.ts +61 -0
  93. package/dist/ddl/table-ddl.d.ts +35 -0
  94. package/dist/ddl/trigger-ddl.d.ts +81 -0
  95. package/dist/ddl/view-ddl.d.ts +122 -0
  96. package/dist/decorators/association-applier.d.ts +18 -0
  97. package/dist/decorators/association-decorators.d.ts +72 -0
  98. package/dist/decorators/column-decorators.d.ts +147 -0
  99. package/dist/decorators/decorator-factory.d.ts +45 -0
  100. package/dist/decorators/decorator-signature.d.ts +26 -0
  101. package/dist/decorators/decorator-types.d.ts +24 -0
  102. package/dist/decorators/foreign-key-decorator.d.ts +21 -0
  103. package/dist/decorators/hook-decorators.d.ts +393 -0
  104. package/dist/decorators/init-arguments.d.ts +29 -0
  105. package/dist/decorators/model-decorators.d.ts +18 -0
  106. package/dist/decorators/model-metadata.d.ts +70 -0
  107. package/dist/decorators/table-decorators.d.ts +43 -0
  108. package/dist/decorators/timestamp-decorators.d.ts +38 -0
  109. package/dist/errors/base-error.d.ts +40 -0
  110. package/dist/errors/connection-errors.d.ts +152 -0
  111. package/dist/errors/database-errors.d.ts +186 -0
  112. package/dist/errors/errors.d.ts +5 -0
  113. package/dist/errors/map-pg-error.d.ts +27 -0
  114. package/dist/errors/misc-errors.d.ts +232 -0
  115. package/dist/errors/validation-errors.d.ts +141 -0
  116. package/dist/exports-associations.d.ts +6 -0
  117. package/dist/exports-core.d.ts +95 -0
  118. package/dist/exports-decorators.d.ts +8 -0
  119. package/dist/exports-errors.d.ts +2 -0
  120. package/dist/exports-model.d.ts +21 -0
  121. package/dist/exports-schema.d.ts +19 -0
  122. package/dist/expressions/call-expressions.d.ts +54 -0
  123. package/dist/expressions/condition-expressions.d.ts +51 -0
  124. package/dist/expressions/expression.d.ts +52 -0
  125. package/dist/expressions/jsonpath-helpers.d.ts +37 -0
  126. package/dist/expressions/logic.d.ts +25 -0
  127. package/dist/expressions/methods.d.ts +188 -0
  128. package/dist/expressions/op.d.ts +182 -0
  129. package/dist/expressions/query-expressions.d.ts +110 -0
  130. package/dist/expressions/row-expressions.d.ts +35 -0
  131. package/dist/expressions/search-helpers.d.ts +138 -0
  132. package/dist/expressions/trigram-helpers.d.ts +40 -0
  133. package/dist/hooks/hooks.d.ts +125 -0
  134. package/dist/index.cjs +21864 -0
  135. package/dist/index.cjs.map +1 -0
  136. package/dist/index.d.ts +6 -0
  137. package/dist/index.js +21688 -0
  138. package/dist/index.js.map +1 -0
  139. package/dist/model/attribute-columns.d.ts +85 -0
  140. package/dist/model/attribute-normalizer.d.ts +42 -0
  141. package/dist/model/attribute-options.d.ts +121 -0
  142. package/dist/model/bulk-insert-builder.d.ts +24 -0
  143. package/dist/model/bulk-options.d.ts +173 -0
  144. package/dist/model/copy-options.d.ts +51 -0
  145. package/dist/model/cte-builder.d.ts +134 -0
  146. package/dist/model/definition-normalizer.d.ts +26 -0
  147. package/dist/model/delete-query-builder.d.ts +42 -0
  148. package/dist/model/find-options.d.ts +144 -0
  149. package/dist/model/find-query-builder.d.ts +38 -0
  150. package/dist/model/inflector.d.ts +28 -0
  151. package/dist/model/insert-query-builder.d.ts +41 -0
  152. package/dist/model/instance-destroyer.d.ts +44 -0
  153. package/dist/model/instance-lifecycle-services.d.ts +61 -0
  154. package/dist/model/instance-lifecycle.d.ts +128 -0
  155. package/dist/model/instance-saver.d.ts +25 -0
  156. package/dist/model/instance-state.d.ts +48 -0
  157. package/dist/model/instance-validation.d.ts +35 -0
  158. package/dist/model/instance-values.d.ts +88 -0
  159. package/dist/model/instance-writer.d.ts +59 -0
  160. package/dist/model/join-source-builder.d.ts +25 -0
  161. package/dist/model/lateral-keys-builder.d.ts +25 -0
  162. package/dist/model/merge-action-builder.d.ts +31 -0
  163. package/dist/model/merge-options.d.ts +72 -0
  164. package/dist/model/merge-query-builder.d.ts +29 -0
  165. package/dist/model/merge-source-builder.d.ts +22 -0
  166. package/dist/model/mixins/model-aggregates.d.ts +69 -0
  167. package/dist/model/mixins/model-associations.d.ts +113 -0
  168. package/dist/model/mixins/model-constructor.d.ts +7 -0
  169. package/dist/model/mixins/model-finders.d.ts +140 -0
  170. package/dist/model/mixins/model-hooks.d.ts +142 -0
  171. package/dist/model/mixins/model-postgres.d.ts +198 -0
  172. package/dist/model/mixins/model-schema-binding.d.ts +36 -0
  173. package/dist/model/mixins/model-schema.d.ts +100 -0
  174. package/dist/model/mixins/model-scopes.d.ts +57 -0
  175. package/dist/model/mixins/model-writers.d.ts +175 -0
  176. package/dist/model/mixins/named-hooks.d.ts +28 -0
  177. package/dist/model/model-accessors.d.ts +22 -0
  178. package/dist/model/model-base.d.ts +83 -0
  179. package/dist/model/model-definition.d.ts +130 -0
  180. package/dist/model/model-instance-persistence.d.ts +132 -0
  181. package/dist/model/model-instance-values.d.ts +197 -0
  182. package/dist/model/model-operations.d.ts +22 -0
  183. package/dist/model/model-registry.d.ts +152 -0
  184. package/dist/model/model-services.d.ts +46 -0
  185. package/dist/model/model-state.d.ts +68 -0
  186. package/dist/model/model-values.d.ts +86 -0
  187. package/dist/model/model.d.ts +629 -0
  188. package/dist/model/on-conflict-builder.d.ts +111 -0
  189. package/dist/model/operations/bulk-create-operation.d.ts +40 -0
  190. package/dist/model/operations/copy-from-source.d.ts +51 -0
  191. package/dist/model/operations/copy-operation.d.ts +54 -0
  192. package/dist/model/operations/count-operation.d.ts +52 -0
  193. package/dist/model/operations/create-operation.d.ts +31 -0
  194. package/dist/model/operations/destroy-operation.d.ts +65 -0
  195. package/dist/model/operations/find-cursor.d.ts +23 -0
  196. package/dist/model/operations/find-lookups.d.ts +99 -0
  197. package/dist/model/operations/find-operation.d.ts +47 -0
  198. package/dist/model/operations/increment-operation.d.ts +40 -0
  199. package/dist/model/operations/insert-operation.d.ts +71 -0
  200. package/dist/model/operations/merge-operation.d.ts +56 -0
  201. package/dist/model/operations/model-operation.d.ts +33 -0
  202. package/dist/model/operations/update-operation.d.ts +45 -0
  203. package/dist/model/operations/upsert-operation.d.ts +39 -0
  204. package/dist/model/options.d.ts +103 -0
  205. package/dist/model/returning-old.d.ts +52 -0
  206. package/dist/model/row-mapper.d.ts +78 -0
  207. package/dist/model/row-plan.d.ts +31 -0
  208. package/dist/model/runtime.d.ts +56 -0
  209. package/dist/model/scope-registry.d.ts +81 -0
  210. package/dist/model/select-aggregates.d.ts +37 -0
  211. package/dist/model/select-lock.d.ts +13 -0
  212. package/dist/model/select-options.d.ts +92 -0
  213. package/dist/model/select-query-builder.d.ts +73 -0
  214. package/dist/model/select-targets.d.ts +77 -0
  215. package/dist/model/source-option-builder.d.ts +23 -0
  216. package/dist/model/source-options.d.ts +108 -0
  217. package/dist/model/statement-builder.d.ts +77 -0
  218. package/dist/model/statement-services.d.ts +2 -0
  219. package/dist/model/sync-hooks.d.ts +18 -0
  220. package/dist/model/table-sample-builder.d.ts +13 -0
  221. package/dist/model/types.d.ts +85 -0
  222. package/dist/model/unnest-insert-builder.d.ts +24 -0
  223. package/dist/model/update-query-builder.d.ts +39 -0
  224. package/dist/model/v6-conflict-builder.d.ts +37 -0
  225. package/dist/model/value-cloner.d.ts +17 -0
  226. package/dist/model/values-writer.d.ts +12 -0
  227. package/dist/model/where-options.d.ts +164 -0
  228. package/dist/model/write-options.d.ts +160 -0
  229. package/dist/model/written-rows.d.ts +56 -0
  230. package/dist/package-version.d.ts +8 -0
  231. package/dist/query/query-result-shaper.d.ts +93 -0
  232. package/dist/query/raw-query.d.ts +27 -0
  233. package/dist/query-interface/alter-planner.d.ts +40 -0
  234. package/dist/query-interface/bulk-data.d.ts +44 -0
  235. package/dist/query-interface/column-commands.d.ts +52 -0
  236. package/dist/query-interface/column-describer.d.ts +17 -0
  237. package/dist/query-interface/enum-commands.d.ts +36 -0
  238. package/dist/query-interface/index-commands.d.ts +57 -0
  239. package/dist/query-interface/model-tables.d.ts +58 -0
  240. package/dist/query-interface/object-commands.d.ts +71 -0
  241. package/dist/query-interface/partition-commands.d.ts +43 -0
  242. package/dist/query-interface/policy-commands.d.ts +54 -0
  243. package/dist/query-interface/query-interface-catalog.d.ts +180 -0
  244. package/dist/query-interface/query-interface-objects.d.ts +108 -0
  245. package/dist/query-interface/query-interface-partitions.d.ts +66 -0
  246. package/dist/query-interface/query-interface-policies.d.ts +86 -0
  247. package/dist/query-interface/query-interface-routines.d.ts +120 -0
  248. package/dist/query-interface/query-interface-tables.d.ts +179 -0
  249. package/dist/query-interface/query-interface-types.d.ts +62 -0
  250. package/dist/query-interface/query-interface-views.d.ts +84 -0
  251. package/dist/query-interface/query-interface.d.ts +256 -0
  252. package/dist/query-interface/routine-commands.d.ts +71 -0
  253. package/dist/query-interface/schema-synchronizer.d.ts +110 -0
  254. package/dist/query-interface/statement-runner.d.ts +40 -0
  255. package/dist/query-interface/sync-planner.d.ts +26 -0
  256. package/dist/query-interface/table-commands.d.ts +63 -0
  257. package/dist/query-interface/table-introspector.d.ts +58 -0
  258. package/dist/query-interface/view-commands.d.ts +47 -0
  259. package/dist/sequelize/instance-hook-adders.d.ts +72 -0
  260. package/dist/sequelize/sequelize-base.d.ts +196 -0
  261. package/dist/sequelize/sequelize-constructor.d.ts +7 -0
  262. package/dist/sequelize/sequelize-helpers.d.ts +133 -0
  263. package/dist/sequelize/sequelize-hooks.d.ts +99 -0
  264. package/dist/sequelize/sequelize-internals.d.ts +87 -0
  265. package/dist/sequelize/sequelize-notifications.d.ts +66 -0
  266. package/dist/sequelize/sequelize-schema.d.ts +125 -0
  267. package/dist/sequelize/sequelize-transactions.d.ts +96 -0
  268. package/dist/sequelize.d.ts +1175 -0
  269. package/dist/sql/ast-clauses.d.ts +137 -0
  270. package/dist/sql/ast-expressions.d.ts +88 -0
  271. package/dist/sql/ast-statements.d.ts +80 -0
  272. package/dist/sql/ast.d.ts +21 -0
  273. package/dist/sql/compile.d.ts +21 -0
  274. package/dist/sql/dml-compiler.d.ts +54 -0
  275. package/dist/sql/expression-compiler.d.ts +56 -0
  276. package/dist/sql/from-compiler.d.ts +39 -0
  277. package/dist/sql/identifier-quoter.d.ts +15 -0
  278. package/dist/sql/merge-compiler.d.ts +20 -0
  279. package/dist/sql/order.d.ts +15 -0
  280. package/dist/sql/query-compiler.d.ts +45 -0
  281. package/dist/sql/sql-chunks.d.ts +50 -0
  282. package/dist/sql/with-compiler.d.ts +19 -0
  283. package/dist/transaction/advisory-locks.d.ts +28 -0
  284. package/dist/transaction/cls-namespace.d.ts +44 -0
  285. package/dist/transaction/transaction-constants.d.ts +35 -0
  286. package/dist/transaction/transaction-runner.d.ts +78 -0
  287. package/dist/transaction/transaction-starter.d.ts +25 -0
  288. package/dist/transaction/transaction-statements.d.ts +29 -0
  289. package/dist/transaction/transaction.d.ts +201 -0
  290. package/dist/validation/attribute-validators.d.ts +23 -0
  291. package/dist/validation/builtin-attribute-validator.d.ts +19 -0
  292. package/dist/validation/builtin-validators.d.ts +16 -0
  293. package/dist/validation/core-validator.d.ts +16 -0
  294. package/dist/validation/custom-validators.d.ts +13 -0
  295. package/dist/validation/instance-validator.d.ts +25 -0
  296. package/dist/validation/schema-items.d.ts +22 -0
  297. package/dist/validation/standard-schema-validator.d.ts +30 -0
  298. package/dist/validation/standard-schema.d.ts +39 -0
  299. package/dist/validation/types.d.ts +36 -0
  300. package/dist/validation/validation-target.d.ts +13 -0
  301. package/dist/where/comparison-compiler.d.ts +27 -0
  302. package/dist/where/condition-compiler.d.ts +18 -0
  303. package/dist/where/operand-resolver.d.ts +10 -0
  304. package/dist/where/operator-allowlist.d.ts +14 -0
  305. package/dist/where/where-support.d.ts +52 -0
  306. package/dist/where/where.d.ts +46 -0
  307. package/dist/where/window-compiler.d.ts +14 -0
  308. package/llm/USAGE.md +423 -0
  309. package/package.json +103 -4
  310. package/skills/postgrelize/SKILL.md +57 -0
  311. package/skills/postgrelize/reference/associations.md +108 -0
  312. package/skills/postgrelize/reference/errors.md +37 -0
  313. package/skills/postgrelize/reference/migrating-from-sequelize.md +15 -0
  314. package/skills/postgrelize/reference/postgresql-features.md +157 -0
  315. package/skills/postgrelize/reference/querying.md +111 -0
  316. package/skills/postgrelize/reference/schema.md +135 -0
  317. package/skills/postgrelize/reference/security.md +34 -0
  318. package/skills/postgrelize/reference/transactions-and-sessions.md +122 -0
  319. package/skills/postgrelize/reference/writing.md +198 -0
@@ -0,0 +1,71 @@
1
+ import { Subquery } from '../../expressions/methods.ts';
2
+ import { OnConflictNode } from '../../sql/ast.ts';
3
+ import { SqlCompiler } from '../../sql/compile.ts';
4
+ import { AttributeColumns } from '../attribute-columns.ts';
5
+ import { InsertQueryBuilder } from '../insert-query-builder.ts';
6
+ import { ModelRegistry } from '../model-registry.ts';
7
+ import { ModelValues } from '../model-values.ts';
8
+ import { OnConflictBuilder } from '../on-conflict-builder.ts';
9
+ import { AnyModel, InsertFromOptions, InsertOptions, ModelStatic, Values } from '../options.ts';
10
+ import { ReturningOld } from '../returning-old.ts';
11
+ import { QueryOptionsBase } from '../runtime.ts';
12
+ import { WrittenRows } from '../written-rows.ts';
13
+ import { ModelOperation, OperationServices } from './model-operation.ts';
14
+ /** Collaborators of {@link InsertOperation}. */
15
+ export type InsertOperationServices = OperationServices & Readonly<{
16
+ /** Model state. */
17
+ registry: ModelRegistry;
18
+ /** Value rules. */
19
+ values: ModelValues;
20
+ /** RETURNING lists. */
21
+ columns: AttributeColumns;
22
+ /** INSERT builder. */
23
+ inserts: InsertQueryBuilder;
24
+ /** ON CONFLICT builder. */
25
+ conflicts: OnConflictBuilder;
26
+ /** `returningOld` support. */
27
+ returningOld: ReturningOld;
28
+ /** Instances of returned rows. */
29
+ written: WrittenRows;
30
+ /** SQL compiler. */
31
+ compiler: SqlCompiler;
32
+ }>;
33
+ /**
34
+ * `INSERT ... ON CONFLICT ... RETURNING` writes that return the written rows with `wasInserted`:
35
+ * `Model.insert`, `Model.insertFrom` and the `onConflict` paths of `create` / `bulkCreate`.
36
+ */
37
+ export declare class InsertOperation extends ModelOperation<InsertOperationServices> {
38
+ #private;
39
+ /**
40
+ * `Model.insert`: inserts rows with `INSERT ... ON CONFLICT` and returns the written rows.
41
+ *
42
+ * @param model - Model class.
43
+ * @param values - One row or several rows.
44
+ * @param options - Insert options.
45
+ * @returns Instances of the rows written by the statement.
46
+ */
47
+ insert<M extends AnyModel>(model: ModelStatic<M>, values: Values | readonly Values[], options: InsertOptions): Promise<M[]>;
48
+ /**
49
+ * `Model.insertFrom`: `INSERT INTO ... SELECT` from a subquery.
50
+ *
51
+ * @param model - Model class.
52
+ * @param source - Subquery whose columns match `options.columns`.
53
+ * @param options - Target columns, `onConflict` and query options.
54
+ * @returns Written rows.
55
+ */
56
+ insertFrom<M extends AnyModel>(model: ModelStatic<M>, source: Subquery, options: InsertFromOptions): Promise<M[]>;
57
+ /**
58
+ * Inserts attribute-keyed rows with an optional ON CONFLICT clause and returns the written rows
59
+ * with `wasInserted`.
60
+ *
61
+ * @param model - Model class.
62
+ * @param rows - Values by attribute name.
63
+ * @param onConflict - ON CONFLICT clause.
64
+ * @param options - Query options, `overriding`, `returningOld`.
65
+ * @returns Instances of the written rows.
66
+ */
67
+ withConflict<M extends AnyModel>(model: ModelStatic<M>, rows: readonly Values[], onConflict: OnConflictNode | undefined, options: QueryOptionsBase & Readonly<{
68
+ overriding?: 'system' | 'user';
69
+ returningOld?: boolean;
70
+ }>): Promise<M[]>;
71
+ }
@@ -0,0 +1,56 @@
1
+ import { SqlCompiler } from '../../sql/compile.ts';
2
+ import { MergeQueryBuilder, MergeOptions } from '../merge-query-builder.ts';
3
+ import { ModelRegistry } from '../model-registry.ts';
4
+ import { AnyModel, ModelStatic } from '../options.ts';
5
+ import { ReturningOld } from '../returning-old.ts';
6
+ import { QueryOptionsBase } from '../runtime.ts';
7
+ import { WrittenRows } from '../written-rows.ts';
8
+ /** Action reported by `merge_action()`. */
9
+ export type MergeActionName = 'INSERT' | 'UPDATE' | 'DELETE';
10
+ /** Result of `Model.merge`. */
11
+ export type MergeResult<M> = Readonly<{
12
+ /** Number of affected rows. */
13
+ rowCount: number;
14
+ /** Written rows (with `returning: true`). */
15
+ rows: readonly Readonly<{
16
+ /** Action taken. */ action: MergeActionName;
17
+ /** Row after the action. */ instance: M;
18
+ }>[];
19
+ }>;
20
+ /** Options of `Model.merge` with query and RETURNING options. */
21
+ export type MergeCallOptions = MergeOptions<unknown> & QueryOptionsBase & Readonly<{
22
+ /** Return written rows (PostgreSQL 17+). */
23
+ returning?: boolean;
24
+ /** With `returning`: expose pre-statement values as `instance.oldValues` (PostgreSQL 18+). */
25
+ returningOld?: boolean;
26
+ }>;
27
+ /** Collaborators of {@link MergeOperation}. */
28
+ export type MergeOperationServices = Readonly<{
29
+ /** Model state. */
30
+ registry: ModelRegistry;
31
+ /** MERGE builder. */
32
+ merges: MergeQueryBuilder;
33
+ /** `returningOld` support. */
34
+ returningOld: ReturningOld;
35
+ /** Instances of returned rows. */
36
+ written: WrittenRows;
37
+ /** SQL compiler. */
38
+ compiler: SqlCompiler;
39
+ }>;
40
+ /** `Model.merge`: `MERGE INTO ... USING ...` with server version checks (PostgreSQL 15 / 17 / 18). */
41
+ export declare class MergeOperation {
42
+ #private;
43
+ /**
44
+ * @param services - Collaborators.
45
+ */
46
+ constructor(services: MergeOperationServices);
47
+ /**
48
+ * `Model.merge`.
49
+ *
50
+ * @param model - Model class.
51
+ * @param options - Source, join condition, WHEN clauses, `returning`, `returningOld`.
52
+ * @returns Affected row count and, with `returning`, `{ action, instance }` per row.
53
+ * @throws Error when the server is too old for the requested features.
54
+ */
55
+ merge<M extends AnyModel>(model: ModelStatic<M>, options: MergeCallOptions): Promise<MergeResult<M>>;
56
+ }
@@ -0,0 +1,33 @@
1
+ import { HookType } from '../../hooks/hooks.ts';
2
+ import { InstanceLifecycle } from '../instance-lifecycle.ts';
3
+ import { MutableOptions } from '../options.ts';
4
+ /** Services every operation has: the hook runner. */
5
+ export type OperationServices = Readonly<{
6
+ /** Hooks. */
7
+ lifecycle: InstanceLifecycle;
8
+ }>;
9
+ type OperationMethod = (model: any, options: MutableOptions, ...rest: any[]) => Promise<unknown>;
10
+ /**
11
+ * Base of `Model` operations: holds the injected services and provides the hook decorators.
12
+ *
13
+ * @typeParam S - Services of the operation.
14
+ * @internal
15
+ */
16
+ export declare abstract class ModelOperation<S extends OperationServices> {
17
+ /** Injected collaborators. */
18
+ protected readonly services: S;
19
+ /**
20
+ * @param services - Collaborators.
21
+ */
22
+ constructor(services: S);
23
+ /**
24
+ * Method decorator: runs `before` / `after` hooks with the options around a
25
+ * `(model, options, ...rest)` method when `options.hooks === true`.
26
+ *
27
+ * @param before - Hook run before the method.
28
+ * @param after - Hook run after the method resolved.
29
+ * @returns The decorator.
30
+ */
31
+ static bulkHooks(before: HookType, after: HookType): <T extends OperationMethod>(method: T, context: ClassMethodDecoratorContext<ModelOperation<OperationServices>>) => T;
32
+ }
33
+ export {};
@@ -0,0 +1,45 @@
1
+ import { SqlCompiler } from '../../sql/compile.ts';
2
+ import { AttributeColumns } from '../attribute-columns.ts';
3
+ import { JoinSourceBuilder } from '../join-source-builder.ts';
4
+ import { ModelRegistry } from '../model-registry.ts';
5
+ import { ModelValues } from '../model-values.ts';
6
+ import { AnyModel, ModelStatic, UpdateOptions, Values } from '../options.ts';
7
+ import { ReturningOld } from '../returning-old.ts';
8
+ import { UpdateQueryBuilder } from '../update-query-builder.ts';
9
+ import { WrittenRows } from '../written-rows.ts';
10
+ import { ModelOperation, OperationServices } from './model-operation.ts';
11
+ /** Collaborators of {@link UpdateOperation}. */
12
+ export type UpdateOperationServices = OperationServices & Readonly<{
13
+ /** Model state and scopes. */
14
+ registry: ModelRegistry;
15
+ /** Value rules. */
16
+ values: ModelValues;
17
+ /** SET items, paranoid filter. */
18
+ columns: AttributeColumns;
19
+ /** UPDATE builder. */
20
+ updates: UpdateQueryBuilder;
21
+ /** `from` relations. */
22
+ joins: JoinSourceBuilder;
23
+ /** `returningOld` support. */
24
+ returningOld: ReturningOld;
25
+ /** Instances of returned rows. */
26
+ written: WrittenRows;
27
+ /** SQL compiler. */
28
+ compiler: SqlCompiler;
29
+ }>;
30
+ type UpdateResult<M> = [affectedCount: number, affectedRows?: M[]];
31
+ /** `Model.update`: bulk UPDATE with validation, bulk / individual hooks, `from` and `returning`. */
32
+ export declare class UpdateOperation extends ModelOperation<UpdateOperationServices> {
33
+ #private;
34
+ /**
35
+ * `Model.update`.
36
+ *
37
+ * @param model - Model class.
38
+ * @param values - New attribute values.
39
+ * @param options - Update options.
40
+ * @returns `[affectedCount]`, or `[affectedCount, rows]` with `returning: true`.
41
+ * @throws Error for `individualHooks` with `from`, or `returningOld` without `returning`.
42
+ */
43
+ update<M extends AnyModel>(model: ModelStatic<M>, values: Values, options: UpdateOptions): Promise<UpdateResult<M>>;
44
+ }
45
+ export {};
@@ -0,0 +1,39 @@
1
+ import { SqlCompiler } from '../../sql/compile.ts';
2
+ import { AttributeColumns } from '../attribute-columns.ts';
3
+ import { InsertQueryBuilder } from '../insert-query-builder.ts';
4
+ import { ModelRegistry } from '../model-registry.ts';
5
+ import { ModelValues } from '../model-values.ts';
6
+ import { OnConflictBuilder } from '../on-conflict-builder.ts';
7
+ import { AnyModel, ModelStatic, UpsertOptions, Values } from '../options.ts';
8
+ import { WrittenRows } from '../written-rows.ts';
9
+ import { ModelOperation, OperationServices } from './model-operation.ts';
10
+ /** Collaborators of {@link UpsertOperation}. */
11
+ export type UpsertOperationServices = OperationServices & Readonly<{
12
+ /** Model state. */
13
+ registry: ModelRegistry;
14
+ /** Value rules. */
15
+ values: ModelValues;
16
+ /** RETURNING lists. */
17
+ columns: AttributeColumns;
18
+ /** INSERT builder. */
19
+ inserts: InsertQueryBuilder;
20
+ /** ON CONFLICT builder. */
21
+ conflicts: OnConflictBuilder;
22
+ /** Marker columns of returned rows. */
23
+ written: WrittenRows;
24
+ /** SQL compiler. */
25
+ compiler: SqlCompiler;
26
+ }>;
27
+ /** `Model.upsert`: `INSERT ... ON CONFLICT DO UPDATE` with Sequelize v6 target rules or `onConflict`. */
28
+ export declare class UpsertOperation extends ModelOperation<UpsertOperationServices> {
29
+ #private;
30
+ /**
31
+ * `Model.upsert`.
32
+ *
33
+ * @param model - Model class.
34
+ * @param values - Attribute values.
35
+ * @param options - Upsert options.
36
+ * @returns `[instance, null]` like Sequelize v6, or `[instance, created]` with `onConflict`.
37
+ */
38
+ upsert<M extends AnyModel>(model: ModelStatic<M>, values: Values, options: UpsertOptions): Promise<[M, boolean | null]>;
39
+ }
@@ -0,0 +1,103 @@
1
+ import { IncludeOption } from '../associations/include.ts';
2
+ import { HooksOption } from '../hooks/hooks.ts';
3
+ import { StandardSchemaV1 } from '../validation/standard-schema.ts';
4
+ import { ModelValidatorFunction } from '../validation/types.ts';
5
+ import { DefinitionOptions } from './model-definition.ts';
6
+ import { ScopeDefinition, ScopeOptions, WhereMergeStrategy } from './scope-registry.ts';
7
+ import { Model } from './model.ts';
8
+ import { RuntimeOwner } from './runtime.ts';
9
+ import { MakeNullishOptional } from './types.ts';
10
+ export type { AggregateOptions, CountOptions, FindAndCountResult, FindOptions, FindOrCreateOptions, } from './find-options.ts';
11
+ export type { AttributeAmounts, CreateOptions, IncrementOptions, InsertFromOptions, InsertOptions, SaveOptions, UpsertOptions, } from './write-options.ts';
12
+ export type { BulkCreateOptions, BulkHookOptions, DestroyOptions, InstanceDestroyOptions, RestoreOptions, UpdateOptions, } from './bulk-options.ts';
13
+ export type { CopyFromOptions, CopyToFormatOptions, CopyToOptions } from './copy-options.ts';
14
+ /** Plain attribute values of a model. */
15
+ export type Values = Record<string, unknown>;
16
+ /** @internal Options object of an operation, passed to hooks (which may change it). */
17
+ export type MutableOptions = Record<string, unknown>;
18
+ /** Any model instance type. */
19
+ export type AnyModel = Model<any, any>;
20
+ /** Attribute types of model instance type `M`. */
21
+ export type Attributes<M extends AnyModel> = M['_attributes'];
22
+ /** Creation attribute types of model instance type `M`. */
23
+ export type CreationAttributes<M extends AnyModel> = MakeNullishOptional<M['_creationAttributes']>;
24
+ /** A model class whose instances are `M` (Sequelize v6 `ModelStatic`). */
25
+ export type ModelStatic<M extends AnyModel> = Omit<typeof Model, 'prototype'> & {
26
+ new (values?: Values, options?: BuildOptions): M;
27
+ /** Instance prototype. */
28
+ prototype: M;
29
+ };
30
+ /** Schema-qualified table name returned by `getTableName`. */
31
+ export type QualifiedTableName = Readonly<{
32
+ /** Table name. */
33
+ tableName: string;
34
+ /** Table name (v6 alias of `tableName`). */
35
+ table: string;
36
+ /** Model name. */
37
+ name: string;
38
+ /** Schema name. */
39
+ schema: string;
40
+ /** Separator between schema and table. */
41
+ delimiter: string;
42
+ /** Quoted `"schema"."table"` reference. */
43
+ toString: () => string;
44
+ }>;
45
+ /**
46
+ * Options of `Model.init`: table-level options plus hooks, scopes and validation.
47
+ *
48
+ * Extends {@link DefinitionOptions}.
49
+ *
50
+ * @see {@link Model.init}
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * User.init(
55
+ * { name: DataTypes.STRING, email: DataTypes.STRING },
56
+ * {
57
+ * sequelize,
58
+ * modelName: 'User',
59
+ * paranoid: true,
60
+ * defaultScope: { where: { active: true } },
61
+ * scopes: { admins: { where: { role: 'admin' } } },
62
+ * },
63
+ * );
64
+ * ```
65
+ */
66
+ export type InitOptions = DefinitionOptions & Readonly<{
67
+ /** Owning `Sequelize` instance. */
68
+ sequelize: RuntimeOwner;
69
+ /** Lifecycle hooks, by hook name. */
70
+ hooks?: HooksOption;
71
+ /** Scope applied to every query unless `unscoped()` / `scope()` is used. */
72
+ defaultScope?: ScopeOptions;
73
+ /** Named scopes: options or functions returning options. */
74
+ scopes?: Readonly<Record<string, ScopeDefinition>>;
75
+ /** How `where` of merged scopes combine: `'overwrite'` replaces same keys, `'and'` joins them with `Op.and`.
76
+ * @defaultValue 'overwrite' */
77
+ whereMergeStrategy?: WhereMergeStrategy;
78
+ /** Model-level validators; throw to fail. */
79
+ validate?: Readonly<Record<string, ModelValidatorFunction>>;
80
+ /** Standard Schema (zod, valibot, arktype) validating all attribute values. Extension; `schema` keeps its v6 meaning (PostgreSQL schema). */
81
+ validationSchema?: StandardSchemaV1;
82
+ }>;
83
+ /**
84
+ * Options of `Model.build` (and the model constructor).
85
+ *
86
+ * @see {@link Model.build}
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * const opts: BuildOptions = { isNewRecord: false, raw: true };
91
+ * const user = User.build({ id: 1, name: 'Ann' }, opts);
92
+ * ```
93
+ */
94
+ export type BuildOptions = Readonly<{
95
+ /** Whether the instance represents a row that does not exist yet; `save()` inserts when true, updates when false.
96
+ * @defaultValue true */
97
+ isNewRecord?: boolean;
98
+ /** Set values without setters and without change tracking.
99
+ * @defaultValue false */
100
+ raw?: boolean;
101
+ /** Build associated instances from nested values (Sequelize v6 nested creation). */
102
+ include?: IncludeOption;
103
+ }>;
@@ -0,0 +1,52 @@
1
+ import { ExprNode } from '../sql/ast.ts';
2
+ import { AttributeColumns } from './attribute-columns.ts';
3
+ import { ModelDefinition } from './model-definition.ts';
4
+ import { RowMapper } from './row-mapper.ts';
5
+ import { ModelRuntime } from './runtime.ts';
6
+ /**
7
+ * `returningOld` option (PostgreSQL 18+ `RETURNING WITH (OLD AS ...)`): checks the server
8
+ * version, adds the pre-statement row to a write's RETURNING list and reads it back.
9
+ */
10
+ export declare class ReturningOld {
11
+ #private;
12
+ /** Alias of the pre-statement row in `RETURNING WITH (OLD AS ...)`. */
13
+ static readonly ALIAS = "__pgz_old";
14
+ /** Prefix of returned columns carrying pre-statement values. */
15
+ static readonly PREFIX: string;
16
+ /**
17
+ * @param columns - Stored columns of a model.
18
+ * @param rows - Parses returned values.
19
+ */
20
+ constructor(columns: AttributeColumns, rows: RowMapper);
21
+ /**
22
+ * Whether the write should return pre-statement values.
23
+ *
24
+ * @param runtime - Runtime of the model (server version).
25
+ * @param options - Write options.
26
+ * @returns True with `returningOld: true`.
27
+ * @throws Error on PostgreSQL older than 18.
28
+ */
29
+ enabled(runtime: Pick<ModelRuntime, 'serverVersion'>, options: Readonly<{
30
+ returningOld?: boolean;
31
+ }>): Promise<boolean>;
32
+ /**
33
+ * Adds the pre-statement row (all stored columns) to the RETURNING list of a write.
34
+ *
35
+ * @param definition - Model definition.
36
+ * @param node - INSERT / UPDATE / MERGE node.
37
+ * @returns Node with `returningOld`.
38
+ */
39
+ node<N extends Readonly<{
40
+ returning?: readonly ExprNode[];
41
+ }>>(definition: ModelDefinition, node: N): N & Readonly<{
42
+ returningOld: string;
43
+ }>;
44
+ /**
45
+ * Pre-statement values of a returned row.
46
+ *
47
+ * @param definition - Model definition.
48
+ * @param row - Returned row.
49
+ * @returns Attribute values, or `null` when the row did not exist before (inserted).
50
+ */
51
+ previous(definition: ModelDefinition, row: Readonly<Record<string, unknown>>): Readonly<Record<string, unknown>> | null;
52
+ }
@@ -0,0 +1,78 @@
1
+ import { QueryResultRow } from 'pg';
2
+ import { AttributeDefinition, ModelDefinition } from './model-definition.ts';
3
+ import { ModelRegistry } from './model-registry.ts';
4
+ import { AnyModel, ModelStatic, Values } from './options.ts';
5
+ /**
6
+ * Converts driver rows into attribute values and model instances: column names to attribute
7
+ * names, data type parsers, nested `raw` rows and aggregate results.
8
+ */
9
+ export declare class RowMapper {
10
+ #private;
11
+ /**
12
+ * @param registry - Model definitions.
13
+ */
14
+ constructor(registry: ModelRegistry);
15
+ /**
16
+ * Converts a driver row into attribute values: maps column names to attribute names (when the
17
+ * query did not alias them) and applies data type parsers. Unknown columns are kept as is.
18
+ *
19
+ * @param definition - Model definition.
20
+ * @param row - Driver row.
21
+ * @returns Attribute values.
22
+ */
23
+ parse(definition: ModelDefinition, row: QueryResultRow): Readonly<Record<string, unknown>>;
24
+ /**
25
+ * Like {@link RowMapper.parse}, for a row nobody else reads afterwards (raw results): parsers
26
+ * are applied in place and the row itself is returned, which saves one object per row. A column
27
+ * that maps to another attribute name switches to {@link RowMapper.parse} for the remaining
28
+ * columns, so the key order matches `parse`.
29
+ *
30
+ * @param definition - Model definition.
31
+ * @param row - Driver row; modified.
32
+ * @returns Attribute values.
33
+ */
34
+ parseOwned(definition: ModelDefinition, row: QueryResultRow): Readonly<Record<string, unknown>>;
35
+ /**
36
+ * {@link RowMapper.parseOwned} for every row of one result. All rows of a query have the same
37
+ * columns, so the column plan is resolved once from the first row and each row only runs the
38
+ * parsers: a result without parsers is returned untouched.
39
+ *
40
+ * @param definition - Model definition.
41
+ * @param rows - Driver rows of one query; modified.
42
+ * @returns Attribute values per row (the same array).
43
+ */
44
+ parseAllOwned(definition: ModelDefinition, rows: readonly QueryResultRow[]): readonly Readonly<Record<string, unknown>>[];
45
+ /**
46
+ * Parses a driver row into attribute values of `model`.
47
+ *
48
+ * @param model - Model class.
49
+ * @param row - Driver row.
50
+ * @returns Attribute values.
51
+ */
52
+ parseModel(model: object, row: Readonly<Record<string, unknown>>): Readonly<Record<string, unknown>>;
53
+ /**
54
+ * Builds a persisted instance from a driver row.
55
+ *
56
+ * @param model - Model class.
57
+ * @param row - Driver row.
58
+ * @returns Instance with `isNewRecord: false`.
59
+ */
60
+ instance<M extends AnyModel>(model: ModelStatic<M>, row: Readonly<Record<string, unknown>>): M;
61
+ /**
62
+ * Nests `a.b` keys of a raw row into objects (`nest: true`).
63
+ *
64
+ * @param row - Raw row.
65
+ * @returns Nested values.
66
+ */
67
+ nest(row: Values): Values;
68
+ /**
69
+ * Parses an aggregate result: numbers for counts and numeric attributes, the attribute parser
70
+ * otherwise.
71
+ *
72
+ * @param attribute - Aggregated attribute.
73
+ * @param aggregateFunction - Aggregate function name.
74
+ * @param value - Returned value.
75
+ * @returns Parsed value.
76
+ */
77
+ aggregate(attribute: Pick<AttributeDefinition, 'type'> | undefined, aggregateFunction: string, value: unknown): unknown;
78
+ }
@@ -0,0 +1,31 @@
1
+ import { ModelDefinition } from './model-definition.ts';
2
+ /** How one driver column is stored: the attribute it maps to and its data type parser. */
3
+ export type ColumnPlan = Readonly<{
4
+ name: string;
5
+ parse: ((value: unknown) => unknown) | undefined;
6
+ }>;
7
+ /**
8
+ * Per-definition cache of column plans. A driver row is converted once per row and column, so the
9
+ * attribute lookup (`attributes`, `fieldToAttribute`, type parser) is resolved once per column name
10
+ * instead. Definitions are replaced, never mutated, so the cache is keyed by definition identity.
11
+ */
12
+ export declare class RowPlans {
13
+ #private;
14
+ /**
15
+ * Plans of a definition, filled lazily by {@link RowPlans.plan}.
16
+ *
17
+ * @param definition - Model definition.
18
+ * @returns Column plans by driver column name.
19
+ */
20
+ columns(definition: ModelDefinition): Map<string, ColumnPlan>;
21
+ /**
22
+ * Resolves and remembers the plan of a column. Columns that match no attribute are kept as they
23
+ * are, without a parser.
24
+ *
25
+ * @param definition - Model definition.
26
+ * @param columns - The definition's plans.
27
+ * @param key - Driver column name.
28
+ * @returns The plan.
29
+ */
30
+ plan(definition: ModelDefinition, columns: Map<string, ColumnPlan>, key: string): ColumnPlan;
31
+ }
@@ -0,0 +1,56 @@
1
+ import { QueryResult } from '../connection/connection-manager.ts';
2
+ import { LoggingFunction, ModelDefaults } from '../connection/options.ts';
3
+ import { CompiledQuery } from '../sql/compile.ts';
4
+ import { HookRegistry } from '../hooks/hooks.ts';
5
+ import { QueryInterface } from '../query-interface/query-interface.ts';
6
+ import { Transaction, TransactionOptions } from '../transaction/transaction.ts';
7
+ /** Options common to every query issued by a model. */
8
+ export type QueryOptionsBase = Readonly<{
9
+ /** Transaction to run in; `null` forces running outside the CLS transaction. */
10
+ transaction?: Transaction | null;
11
+ /** SQL logger for this query, or `false`. */
12
+ logging?: LoggingFunction | false;
13
+ /** Pass query duration to the logger. */
14
+ benchmark?: boolean;
15
+ /**
16
+ * `statement_timeout` for this query only, in milliseconds (non-negative integer; `0` disables it).
17
+ * PostgreSQL cancels the statement with a `DatabaseError` (code `57014`) when it runs longer.
18
+ * Outside a transaction the query runs in its own short transaction; inside one the previous
19
+ * timeout is restored afterwards. PostgreSQL extension.
20
+ */
21
+ statementTimeout?: number;
22
+ /** Force the writer even for SELECTs when read replicas are configured. */
23
+ useMaster?: boolean;
24
+ }>;
25
+ /** Services a `Sequelize` instance provides to its models. */
26
+ export type ModelRuntime = Readonly<{
27
+ execute: (query: CompiledQuery, options: QueryOptionsBase, kind?: 'read' | 'write') => Promise<QueryResult>;
28
+ transaction: <T>(run: (transaction: Transaction) => Promise<T>, parent?: Transaction | null) => Promise<T>;
29
+ register: (name: string, model: object) => void;
30
+ /** Defines a model through the owning Sequelize instance (used for implicit through models). */
31
+ defineModel: (name: string, attributes: Readonly<Record<string, unknown>>, options: Readonly<Record<string, unknown>>) => object;
32
+ /** Schema API of the owning Sequelize instance. */
33
+ queryInterface: () => QueryInterface;
34
+ /** Streams encoded lines into `COPY ... FROM STDIN`. */
35
+ copyFrom: (text: string, lines: AsyncIterable<string>, options: QueryOptionsBase) => Promise<number>;
36
+ /** Streams `COPY ... TO STDOUT` output. */
37
+ copyTo: (text: string, options: QueryOptionsBase, kind?: 'read' | 'write') => AsyncGenerator<Buffer, void, undefined>;
38
+ /** Starts an unmanaged transaction. */
39
+ beginTransaction: (options?: TransactionOptions) => Promise<Transaction>;
40
+ /** `server_version_num` of the database (cached). */
41
+ serverVersion: () => Promise<number>;
42
+ /** Registered models by name. */
43
+ models: () => Readonly<Record<string, object>>;
44
+ hooks: () => HookRegistry;
45
+ defaults: ModelDefaults;
46
+ inAsAnyThreshold: number | undefined;
47
+ /** `minifyAliases` option: shorten include aliases. */
48
+ minifyAliases?: boolean | undefined;
49
+ }>;
50
+ /** @internal */
51
+ export declare const runtimeKey: unique symbol;
52
+ /** Owner of the internal model services: the `Sequelize` instance. */
53
+ export interface RuntimeOwner {
54
+ /** Internal services used by models. */
55
+ readonly [runtimeKey]: ModelRuntime;
56
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Find options stored in a scope (`where`, `attributes`, `order`, `limit`, ...).
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * const scope: ScopeOptions = { where: { active: true }, order: [['createdAt', 'DESC']], limit: 100 };
7
+ * User.init({ name: DataTypes.STRING }, { sequelize, defaultScope: scope });
8
+ * ```
9
+ */
10
+ export type ScopeOptions = Readonly<Record<string, unknown>>;
11
+ /** Scope definition: options, or a function of arguments returning options. */
12
+ export type ScopeDefinition = ScopeOptions | ((...args: never[]) => ScopeOptions);
13
+ /** Scope selector for `Model.scope()`: a name, `{ method: [name, ...args] }`, or inline options. */
14
+ export type ScopeSelector = string | ScopeMethodSelector | ScopeOptions | null;
15
+ /** `{ method: [name, ...args] }` — calls a function scope with arguments. */
16
+ export type ScopeMethodSelector = Readonly<{
17
+ /** Scope function name, or `[name, ...args]`. */
18
+ method: string | readonly [string, ...unknown[]];
19
+ }>;
20
+ /** `whereMergeStrategy` model option: overwrite same keys (v6 default) or combine with `Op.and`. */
21
+ export type WhereMergeStrategy = 'overwrite' | 'and';
22
+ /**
23
+ * Scopes of a model (default scope, named scopes, `whereMergeStrategy`) and the Sequelize v6
24
+ * option merging rules used to apply them. Immutable: {@link ScopeRegistry.with} returns a new registry.
25
+ */
26
+ export declare class ScopeRegistry {
27
+ #private;
28
+ /** Default scope (`{}` when none). */
29
+ readonly defaultScope: ScopeOptions;
30
+ /** Named scopes. */
31
+ readonly scopes: ReadonlyMap<string, ScopeDefinition>;
32
+ /** How `where` / `having` of merged options combine. */
33
+ readonly whereMergeStrategy: WhereMergeStrategy;
34
+ /**
35
+ * @param defaultScope - Default scope of the model.
36
+ * @param scopes - Named scopes.
37
+ * @param whereMergeStrategy - `'overwrite'` (default) or `'and'`.
38
+ */
39
+ constructor(defaultScope: ScopeOptions | undefined, scopes: Readonly<Record<string, ScopeDefinition>> | ReadonlyMap<string, ScopeDefinition> | undefined, whereMergeStrategy: WhereMergeStrategy | undefined);
40
+ /**
41
+ * Merges find options like Sequelize v6 `_assignOptions`: `where` / `having` keys of `right`
42
+ * overwrite `left` (or are AND-ed with `whereMergeStrategy: 'and'`), arrays are unioned, other
43
+ * keys of `right` win.
44
+ *
45
+ * @param left - Base options.
46
+ * @param right - Options applied on top.
47
+ * @returns Merged options.
48
+ */
49
+ merge(left: ScopeOptions, right: ScopeOptions): ScopeOptions;
50
+ /**
51
+ * Resolves and merges the selected scopes in order (later scopes win).
52
+ *
53
+ * @param selectors - Scope names, `{ method: [name, ...args] }`, inline options or `null`.
54
+ * @returns Merged scope options.
55
+ * @throws Error for unknown scopes.
56
+ */
57
+ resolve(selectors: readonly ScopeSelector[]): ScopeOptions;
58
+ /**
59
+ * Applies a resolved scope to query options; the query options win (Sequelize v6 `_injectScope`).
60
+ *
61
+ * @param scope - Resolved scope.
62
+ * @param options - Query options.
63
+ * @returns Merged options.
64
+ */
65
+ inject<T extends ScopeOptions>(scope: ScopeOptions, options: T): T;
66
+ /**
67
+ * Whether a scope with this name exists (`'defaultScope'`: whether it is not empty).
68
+ *
69
+ * @param name - Scope name.
70
+ * @returns True when defined.
71
+ */
72
+ has(name: string): boolean;
73
+ /**
74
+ * Registry with a scope added or replaced (`'defaultScope'` replaces the default scope).
75
+ *
76
+ * @param name - Scope name.
77
+ * @param scope - Options or a function returning options.
78
+ * @returns New registry.
79
+ */
80
+ with(name: string, scope: ScopeDefinition): ScopeRegistry;
81
+ }