ts-prorm-orm 2.0.0 → 2.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 (83) hide show
  1. package/CHANGELOG.md +132 -0
  2. package/dist/compliance/data-classifier.d.ts +6 -0
  3. package/dist/compliance/data-classifier.js +6 -0
  4. package/dist/compliance/data-lineage.d.ts +4 -0
  5. package/dist/compliance/data-lineage.js +4 -0
  6. package/dist/compliance/data-masker.d.ts +4 -0
  7. package/dist/compliance/data-masker.js +4 -0
  8. package/dist/compliance/index.d.ts +2 -0
  9. package/dist/compliance/index.js +2 -0
  10. package/dist/compliance/pseudonymization.d.ts +4 -0
  11. package/dist/compliance/pseudonymization.js +4 -0
  12. package/dist/compliance/query-firewall.d.ts +9 -9
  13. package/dist/compliance/query-firewall.js +9 -9
  14. package/dist/compliance/rate-limiter.d.ts +4 -0
  15. package/dist/compliance/rate-limiter.js +4 -0
  16. package/dist/compliance/row-level-security.d.ts +2 -0
  17. package/dist/compliance/row-level-security.js +2 -0
  18. package/dist/compliance/security-decorator.d.ts +8 -0
  19. package/dist/compliance/security-decorator.js +8 -0
  20. package/dist/compliance/session-isolation.d.ts +4 -0
  21. package/dist/compliance/session-isolation.js +4 -0
  22. package/dist/compliance/worm-storage.d.ts +4 -0
  23. package/dist/compliance/worm-storage.js +4 -0
  24. package/dist/decorators/audit.d.ts +3 -1
  25. package/dist/decorators/audit.js +3 -1
  26. package/dist/decorators/check.d.ts +15 -15
  27. package/dist/decorators/check.js +15 -15
  28. package/dist/decorators/collate.d.ts +16 -0
  29. package/dist/decorators/collate.js +16 -0
  30. package/dist/decorators/comment.d.ts +3 -1
  31. package/dist/decorators/comment.js +3 -1
  32. package/dist/decorators/database-settings.d.ts +6 -0
  33. package/dist/decorators/database-settings.js +6 -0
  34. package/dist/decorators/default.d.ts +2 -0
  35. package/dist/decorators/default.js +2 -0
  36. package/dist/decorators/encryption.d.ts +7 -1
  37. package/dist/decorators/encryption.js +7 -1
  38. package/dist/decorators/engine.d.ts +4 -0
  39. package/dist/decorators/engine.js +4 -0
  40. package/dist/decorators/fk-constraints.d.ts +32 -32
  41. package/dist/decorators/fk-constraints.js +32 -32
  42. package/dist/decorators/foreign-table.d.ts +1 -1
  43. package/dist/decorators/generated.d.ts +8 -0
  44. package/dist/decorators/generated.js +8 -0
  45. package/dist/decorators/hstore.d.ts +6 -0
  46. package/dist/decorators/hstore.js +6 -0
  47. package/dist/decorators/json-column.d.ts +2 -0
  48. package/dist/decorators/json-column.js +2 -0
  49. package/dist/decorators/jsonb.d.ts +6 -0
  50. package/dist/decorators/jsonb.js +6 -0
  51. package/dist/decorators/permissions.d.ts +12 -0
  52. package/dist/decorators/permissions.js +12 -0
  53. package/dist/decorators/procedure.d.ts +4 -2
  54. package/dist/decorators/procedure.js +4 -2
  55. package/dist/decorators/query-options.d.ts +24 -0
  56. package/dist/decorators/query-options.js +24 -0
  57. package/dist/decorators/range.d.ts +8 -0
  58. package/dist/decorators/range.js +8 -0
  59. package/dist/decorators/set-column.d.ts +2 -0
  60. package/dist/decorators/set-column.js +2 -0
  61. package/dist/decorators/spatial.d.ts +2 -0
  62. package/dist/decorators/spatial.js +2 -0
  63. package/dist/decorators/storage.d.ts +24 -0
  64. package/dist/decorators/storage.js +24 -0
  65. package/dist/decorators/timezone.d.ts +7 -7
  66. package/dist/decorators/timezone.js +7 -7
  67. package/dist/decorators/trigger.d.ts +3 -1
  68. package/dist/decorators/trigger.js +3 -1
  69. package/dist/decorators/uuid.d.ts +6 -0
  70. package/dist/decorators/uuid.js +6 -0
  71. package/dist/decorators/view.d.ts +7 -1
  72. package/dist/decorators/view.js +7 -1
  73. package/dist/dialects/dialect.d.ts +112 -0
  74. package/dist/external-fields/decorator.d.ts +2 -0
  75. package/dist/external-fields/decorator.js +2 -0
  76. package/dist/models/associations.d.ts +38 -0
  77. package/dist/models/associations.js +16 -0
  78. package/dist/models/decorators.d.ts +16 -16
  79. package/dist/models/decorators.js +21 -19
  80. package/dist/schema-objects.d.ts +42 -0
  81. package/dist/schema-objects.js +28 -0
  82. package/dist/types/index.d.ts +334 -0
  83. package/package.json +8 -4
@@ -1,11 +1,12 @@
1
1
  /**
2
- * @Trigger class decorator — declare a database trigger on a model class.
2
+ * `@Trigger` class decorator — declare a database trigger on a model class.
3
3
  *
4
4
  * Stores trigger metadata using plain class properties (no reflect-metadata
5
5
  * dependency) consistent with the rest of this decorator suite.
6
6
  *
7
7
  * Example:
8
8
  *
9
+ * ```ts
9
10
  * @Trigger({
10
11
  * name: 'trg_users_audit',
11
12
  * timing: 'AFTER',
@@ -20,6 +21,7 @@
20
21
  *
21
22
  * // Generate DDL:
22
23
  * const sql = buildCreateTriggerSQL('users', triggers[0], 'mysql');
24
+ * ```
23
25
  */
24
26
  export interface TriggerOptions {
25
27
  /** The trigger name in the database. */
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  /**
3
- * @Trigger class decorator — declare a database trigger on a model class.
3
+ * `@Trigger` class decorator — declare a database trigger on a model class.
4
4
  *
5
5
  * Stores trigger metadata using plain class properties (no reflect-metadata
6
6
  * dependency) consistent with the rest of this decorator suite.
7
7
  *
8
8
  * Example:
9
9
  *
10
+ * ```ts
10
11
  * @Trigger({
11
12
  * name: 'trg_users_audit',
12
13
  * timing: 'AFTER',
@@ -21,6 +22,7 @@
21
22
  *
22
23
  * // Generate DDL:
23
24
  * const sql = buildCreateTriggerSQL('users', triggers[0], 'mysql');
25
+ * ```
24
26
  */
25
27
  Object.defineProperty(exports, "__esModule", { value: true });
26
28
  exports.Trigger = Trigger;
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * Usage:
8
8
  *
9
+ * ```ts
9
10
  * // Auto-generate UUID using gen_random_uuid() (PostgreSQL 13+)
10
11
  * @UUID()
11
12
  * id: string;
@@ -17,6 +18,7 @@
17
18
  * // With custom default
18
19
  * @UUID({ defaultValue: 'gen_random_uuid' })
19
20
  * id: string;
21
+ * ```
20
22
  */
21
23
  /**
22
24
  * Options for UUID column type
@@ -49,14 +51,18 @@ export interface UUIDMetadata {
49
51
  * @example
50
52
  * // Auto-generate UUID
51
53
  * class User extends Model {
54
+ * ```ts
52
55
  * @UUID()
53
56
  * id: string;
57
+ * ```
54
58
  * }
55
59
  *
56
60
  * // With specific default
57
61
  * class User extends Model {
62
+ * ```ts
58
63
  * @UUID({ defaultValue: 'uuid_generate_v4' })
59
64
  * id: string;
65
+ * ```
60
66
  * }
61
67
  */
62
68
  export declare function UUID(options?: UUIDDecoratorOptions): PropertyDecorator;
@@ -7,6 +7,7 @@
7
7
  *
8
8
  * Usage:
9
9
  *
10
+ * ```ts
10
11
  * // Auto-generate UUID using gen_random_uuid() (PostgreSQL 13+)
11
12
  * @UUID()
12
13
  * id: string;
@@ -18,6 +19,7 @@
18
19
  * // With custom default
19
20
  * @UUID({ defaultValue: 'gen_random_uuid' })
20
21
  * id: string;
22
+ * ```
21
23
  */
22
24
  Object.defineProperty(exports, "__esModule", { value: true });
23
25
  exports.UUID = UUID;
@@ -37,14 +39,18 @@ const uuidMetadataMap = new Map();
37
39
  * @example
38
40
  * // Auto-generate UUID
39
41
  * class User extends Model {
42
+ * ```ts
40
43
  * @UUID()
41
44
  * id: string;
45
+ * ```
42
46
  * }
43
47
  *
44
48
  * // With specific default
45
49
  * class User extends Model {
50
+ * ```ts
46
51
  * @UUID({ defaultValue: 'uuid_generate_v4' })
47
52
  * id: string;
53
+ * ```
48
54
  * }
49
55
  */
50
56
  function UUID(options) {
@@ -1,10 +1,11 @@
1
1
  /**
2
- * @View class decorator — annotate a Model class so it maps to a database view
2
+ * `@View` class decorator — annotate a Model class so it maps to a database view
3
3
  * instead of a base table. The ORM stores the view definition and can generate
4
4
  * the CREATE VIEW DDL for you.
5
5
  *
6
6
  * Example:
7
7
  *
8
+ * ```ts
8
9
  * @View({
9
10
  * name: 'active_users_view',
10
11
  * query: `
@@ -30,6 +31,7 @@
30
31
  *
31
32
  * // Query it just like a normal model:
32
33
  * const users = await ActiveUser.findAll({ where: { name: 'Alice' } });
34
+ * ```
33
35
  */
34
36
  import type { Prorm } from '../prorm';
35
37
  export interface ViewOptions {
@@ -83,8 +85,10 @@ export declare function getViewOptions(target: Function): ViewOptions | undefine
83
85
  * - Sets the `tableName` option to the view name so findAll() etc. work correctly.
84
86
  * - Registers view metadata so the ORM can generate CREATE VIEW DDL.
85
87
  *
88
+ * ```ts
86
89
  * @View({ name: 'active_users_view', query: 'SELECT ...' })
87
90
  * class ActiveUser extends Model { ... }
91
+ * ```
88
92
  */
89
93
  export declare function View(options: ViewOptions): (target: Function) => void;
90
94
  export declare const ViewRegistry: {
@@ -166,6 +170,7 @@ export declare function getMaterializedViewOptions(target: Function): Materializ
166
170
  * - Registers materialized view metadata so the ORM can generate CREATE MATERIALIZED VIEW DDL.
167
171
  * - Adds a `refresh()` static method for refreshing the view data.
168
172
  *
173
+ * ```ts
169
174
  * @MaterializedView({
170
175
  * name: 'user_stats_view',
171
176
  * query: `
@@ -194,6 +199,7 @@ export declare function getMaterializedViewOptions(target: Function): Materializ
194
199
  * await UserStats.refresh();
195
200
  * // Or concurrently (requires unique index):
196
201
  * await UserStats.refresh({ concurrently: true });
202
+ * ```
197
203
  */
198
204
  export declare function MaterializedView(options: MaterializedViewDecoratorOptions): (target: Function) => void;
199
205
  export declare const MaterializedViewRegistry: {
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  /**
3
- * @View class decorator — annotate a Model class so it maps to a database view
3
+ * `@View` class decorator — annotate a Model class so it maps to a database view
4
4
  * instead of a base table. The ORM stores the view definition and can generate
5
5
  * the CREATE VIEW DDL for you.
6
6
  *
7
7
  * Example:
8
8
  *
9
+ * ```ts
9
10
  * @View({
10
11
  * name: 'active_users_view',
11
12
  * query: `
@@ -31,6 +32,7 @@
31
32
  *
32
33
  * // Query it just like a normal model:
33
34
  * const users = await ActiveUser.findAll({ where: { name: 'Alice' } });
35
+ * ```
34
36
  */
35
37
  Object.defineProperty(exports, "__esModule", { value: true });
36
38
  exports.MaterializedViewRegistry = exports.ViewRegistry = void 0;
@@ -54,8 +56,10 @@ function getViewOptions(target) {
54
56
  * - Sets the `tableName` option to the view name so findAll() etc. work correctly.
55
57
  * - Registers view metadata so the ORM can generate CREATE VIEW DDL.
56
58
  *
59
+ * ```ts
57
60
  * @View({ name: 'active_users_view', query: 'SELECT ...' })
58
61
  * class ActiveUser extends Model { ... }
62
+ * ```
59
63
  */
60
64
  function View(options) {
61
65
  return function (target) {
@@ -143,6 +147,7 @@ function getMaterializedViewOptions(target) {
143
147
  * - Registers materialized view metadata so the ORM can generate CREATE MATERIALIZED VIEW DDL.
144
148
  * - Adds a `refresh()` static method for refreshing the view data.
145
149
  *
150
+ * ```ts
146
151
  * @MaterializedView({
147
152
  * name: 'user_stats_view',
148
153
  * query: `
@@ -171,6 +176,7 @@ function getMaterializedViewOptions(target) {
171
176
  * await UserStats.refresh();
172
177
  * // Or concurrently (requires unique index):
173
178
  * await UserStats.refresh({ concurrently: true });
179
+ * ```
174
180
  */
175
181
  function MaterializedView(options) {
176
182
  return function (target) {
@@ -4,6 +4,16 @@
4
4
  */
5
5
  import { Transaction, TransactionOptions, QueryResult, QueryOptions, DataType, WhereOptions, Order, IncludeOptions, PartitionBound, CreatePartitionOptions, AttachPartitionOptions, DetachPartitionOptions, RefreshOptions, MaterializedViewOptions, DropMaterializedViewOptions, StoredProcedureOptions, DropStoredProcedureOptions, ExecuteStoredProcedureOptions, TriggerOptions, DropTriggerOptions, SequenceOptions, DropSequenceOptions, PolicyOptions, DropPolicyOptions, StreamOptions } from '../types';
6
6
  import type { Readable } from 'stream';
7
+ /**
8
+ * The contract every SQL engine implements.
9
+ *
10
+ * A dialect owns everything engine-specific: identifier quoting, value escaping,
11
+ * how DDL is written, which clauses are legal, and how pagination and locking
12
+ * are spelled. Model code builds the same `FindOptions` regardless, and
13
+ * the dialect is the single place that turns it into SQL for one engine —
14
+ * which is why `LIMIT ... OFFSET` on PostgreSQL becomes `OFFSET ... FETCH
15
+ * NEXT` on MSSQL without the caller changing.
16
+ */
7
17
  export interface Dialect {
8
18
  /**
9
19
  * The name of the dialect
@@ -582,6 +592,10 @@ export interface Dialect {
582
592
  executeStoredProcedure(options: ExecuteStoredProcedureOptions): Promise<QueryResult>;
583
593
  hasStoredProcedure(procedureName: string, schema?: string): Promise<boolean>;
584
594
  }
595
+ /**
596
+ * One column in a `CREATE TABLE` or `ALTER TABLE`: its type, nullability,
597
+ * default, and key or reference membership.
598
+ */
585
599
  export interface ColumnDefinition {
586
600
  type: DataType;
587
601
  allowNull?: boolean;
@@ -616,6 +630,10 @@ export interface ColumnDefinition {
616
630
  */
617
631
  invisible?: boolean;
618
632
  }
633
+ /**
634
+ * Table-level options for `CREATE TABLE` — the engine, charset, comment,
635
+ * partitioning and any indexes or constraints declared inline.
636
+ */
619
637
  export interface TableOptions {
620
638
  ifNotExists?: boolean;
621
639
  engine?: string;
@@ -667,6 +685,9 @@ export interface TableOptions {
667
685
  validToColumn?: string;
668
686
  };
669
687
  }
688
+ /**
689
+ * An index declared alongside the table rather than in a separate statement.
690
+ */
670
691
  export interface TableIndex {
671
692
  name?: string;
672
693
  unique?: boolean;
@@ -680,6 +701,10 @@ export interface TableIndex {
680
701
  /** Include columns for covering index (PostgreSQL 11+, MySQL 8.0.17+) */
681
702
  include?: string[];
682
703
  }
704
+ /**
705
+ * A constraint declared alongside the table: primary key, unique, check,
706
+ * foreign key or exclusion.
707
+ */
683
708
  export interface TableConstraint {
684
709
  name?: string;
685
710
  type: 'PRIMARY KEY' | 'UNIQUE' | 'FOREIGN KEY' | 'CHECK';
@@ -692,10 +717,18 @@ export interface TableConstraint {
692
717
  };
693
718
  check?: string;
694
719
  }
720
+ /**
721
+ * Options for `DROP TABLE`, including `ifExists` and whether to cascade to
722
+ * dependent objects.
723
+ */
695
724
  export interface DropTableOptions {
696
725
  ifExists?: boolean;
697
726
  cascade?: boolean;
698
727
  }
728
+ /**
729
+ * What the engine reports back about an existing table — the shape returned
730
+ * by `describeTable`, used by schema diffing.
731
+ */
699
732
  export interface TableDescription {
700
733
  [columnName: string]: {
701
734
  type: string;
@@ -705,6 +738,11 @@ export interface TableDescription {
705
738
  autoIncrement: boolean;
706
739
  };
707
740
  }
741
+ /**
742
+ * Options for `CREATE INDEX`: uniqueness, method, included columns, and the
743
+ * `where` predicate that makes it partial. Not every engine supports partial
744
+ * indexes; the dialect rejects the option rather than silently dropping it.
745
+ */
708
746
  export interface IndexOptions {
709
747
  /** Explicit index name (used by the `(tableName, fields, options)` addIndex shorthand) */
710
748
  name?: string;
@@ -744,6 +782,9 @@ export interface IndexOptions {
744
782
  */
745
783
  invisible?: boolean;
746
784
  }
785
+ /**
786
+ * An existing index as reported by the engine.
787
+ */
747
788
  export interface IndexDefinition {
748
789
  name: string;
749
790
  unique?: boolean;
@@ -755,10 +796,17 @@ export interface IndexDefinition {
755
796
  /** See {@link IndexOptions.invisible}. */
756
797
  invisible?: boolean;
757
798
  }
799
+ /**
800
+ * Options for `DROP INDEX`, including `ifExists` and concurrency where the
801
+ * engine offers it.
802
+ */
758
803
  export interface DropIndexOptions {
759
804
  ifExists?: boolean;
760
805
  cascade?: boolean;
761
806
  }
807
+ /**
808
+ * An existing constraint as reported by the engine.
809
+ */
762
810
  export interface ConstraintDefinition {
763
811
  name: string;
764
812
  type: 'PRIMARY KEY' | 'UNIQUE' | 'FOREIGN KEY' | 'CHECK';
@@ -772,6 +820,9 @@ export interface ConstraintDefinition {
772
820
  check?: string;
773
821
  deferrable?: 'INITIALLY DEFERRED' | 'INITIALLY IMMEDIATE';
774
822
  }
823
+ /**
824
+ * Options for dropping a named constraint.
825
+ */
775
826
  export interface DropConstraintOptions {
776
827
  ifExists?: boolean;
777
828
  cascade?: boolean;
@@ -796,6 +847,10 @@ export interface DropViewOptions {
796
847
  /** If true, also drops dependent views (PostgreSQL) */
797
848
  cascade?: boolean;
798
849
  }
850
+ /**
851
+ * Options for dropping a schema, including whether to cascade to the objects
852
+ * inside it.
853
+ */
799
854
  export interface DropSchemaOptions {
800
855
  ifExists?: boolean;
801
856
  cascade?: boolean;
@@ -889,6 +944,10 @@ export interface DropDomainOptions {
889
944
  /** Schema the domain lives in */
890
945
  schema?: string;
891
946
  }
947
+ /**
948
+ * Options for `CREATE VIEW` — the defining query, whether it is materialised,
949
+ * and whether to replace an existing view.
950
+ */
892
951
  export interface ViewOptions {
893
952
  /** Replace the view if it already exists (CREATE OR REPLACE) */
894
953
  replace?: boolean;
@@ -897,12 +956,19 @@ export interface ViewOptions {
897
956
  /** View comment */
898
957
  comment?: string;
899
958
  }
959
+ /**
960
+ * A foreign server: the wrapper that reaches it and the connection options it
961
+ * needs. See the foreign-data-wrappers guide.
962
+ */
900
963
  export interface FdwForeignServerOptions {
901
964
  fdw: string;
902
965
  options?: Record<string, string>;
903
966
  version?: string;
904
967
  ifNotExists?: boolean;
905
968
  }
969
+ /**
970
+ * Changes to an existing foreign server's version or options.
971
+ */
906
972
  export interface FdwAlterForeignServerOptions {
907
973
  options?: Record<string, string>;
908
974
  addOptions?: Record<string, string>;
@@ -910,16 +976,26 @@ export interface FdwAlterForeignServerOptions {
910
976
  dropOptions?: string[];
911
977
  version?: string;
912
978
  }
979
+ /**
980
+ * Maps a local role to credentials on a foreign server.
981
+ */
913
982
  export interface FdwUserMappingOptions {
914
983
  serverName: string;
915
984
  user: string;
916
985
  options?: Record<string, string>;
917
986
  ifNotExists?: boolean;
918
987
  }
988
+ /**
989
+ * One column of a foreign table, including the remote name when it differs.
990
+ */
919
991
  export interface FdwForeignTableColumnDef {
920
992
  type: string;
921
993
  options?: string;
922
994
  }
995
+ /**
996
+ * A foreign table: which server it lives on, its columns, and the remote
997
+ * object it maps to.
998
+ */
923
999
  export interface FdwForeignTableOptions {
924
1000
  serverName: string;
925
1001
  schema?: string;
@@ -927,21 +1003,36 @@ export interface FdwForeignTableOptions {
927
1003
  options?: Record<string, string>;
928
1004
  ifNotExists?: boolean;
929
1005
  }
1006
+ /**
1007
+ * Options for importing a remote schema wholesale, with optional limits on
1008
+ * which tables come across.
1009
+ */
930
1010
  export interface FdwImportForeignSchemaOptions {
931
1011
  localSchema?: string;
932
1012
  limitTo?: string[];
933
1013
  except?: string[];
934
1014
  options?: Record<string, string>;
935
1015
  }
1016
+ /**
1017
+ * Options for dropping a view, including the materialised variant.
1018
+ */
936
1019
  export interface DropViewOptions {
937
1020
  ifExists?: boolean;
938
1021
  cascade?: boolean;
939
1022
  }
1023
+ /**
1024
+ * Shared options for the statement builders: the transaction to run inside
1025
+ * and any per-statement logging override.
1026
+ */
940
1027
  export interface BuildOptions {
941
1028
  replacements?: Record<string, any>;
942
1029
  model?: any;
943
1030
  include?: IncludeOptions[];
944
1031
  }
1032
+ /**
1033
+ * Options for building an `INSERT`, including returning clauses and conflict
1034
+ * handling where the engine supports them.
1035
+ */
945
1036
  export interface InsertOptions {
946
1037
  /** Schema to use for the table */
947
1038
  schema?: string;
@@ -951,6 +1042,10 @@ export interface InsertOptions {
951
1042
  /** Fields to update on conflict (MySQL: ON DUPLICATE KEY UPDATE, PostgreSQL/SQLite: ON CONFLICT DO UPDATE, MariaDB: ON DUPLICATE KEY UPDATE) */
952
1043
  updateOnDuplicate?: string[];
953
1044
  }
1045
+ /**
1046
+ * Options for an insert-or-update, including which columns decide whether a
1047
+ * row already exists and which are written on conflict.
1048
+ */
954
1049
  export interface UpsertQueryOptions {
955
1050
  /** Fields to use for conflict resolution (ON CONFLICT for PostgreSQL/SQLite, ON DUPLICATE KEY for MySQL/MariaDB) */
956
1051
  conflictFields?: string[];
@@ -963,15 +1058,28 @@ export interface UpsertQueryOptions {
963
1058
  /** Model raw attributes for type casting */
964
1059
  model?: any;
965
1060
  }
1061
+ /**
1062
+ * Options for building an `UPDATE`: the `where` that selects rows, and any
1063
+ * limit or ordering the engine permits on it.
1064
+ */
966
1065
  export interface UpdateOptions {
967
1066
  limit?: number;
968
1067
  returning?: boolean | string[];
969
1068
  }
1069
+ /**
1070
+ * Options for building a `DELETE`, including the `where` and any limit the
1071
+ * engine permits.
1072
+ */
970
1073
  export interface DeleteOptions {
971
1074
  limit?: number;
972
1075
  returning?: boolean | string[];
973
1076
  truncate?: boolean;
974
1077
  }
1078
+ /**
1079
+ * Everything a `SELECT` can carry once associations have been resolved:
1080
+ * columns, joins, filtering, grouping, ordering, pagination and locking. This
1081
+ * is the dialect-facing form of `FindOptions`.
1082
+ */
975
1083
  export interface SelectOptions {
976
1084
  tableName: string;
977
1085
  /** Schema to use for the table */
@@ -1051,6 +1159,10 @@ export interface CTEOption {
1051
1159
  /** Optional explicit column list: `name (col1, col2, ...) AS (...)`. */
1052
1160
  columns?: string[];
1053
1161
  }
1162
+ /**
1163
+ * Construction options for a dialect instance — the connection settings and
1164
+ * behaviour flags it needs to build and run statements.
1165
+ */
1054
1166
  export interface DialectOptions {
1055
1167
  host?: string;
1056
1168
  port?: number;
@@ -9,6 +9,7 @@
9
9
  *
10
10
  * prorm.registerStore('assets', s3Store, { defaultBucket: 'avatars' });
11
11
  *
12
+ * ```ts
12
13
  * @Table()
13
14
  * class User extends Model {
14
15
  * @Column(DataTypes.STRING) declare name: string;
@@ -21,6 +22,7 @@
21
22
  * await user.loadAvatar(); // GET, populates user.avatar
22
23
  * user.avatar = newBytes;
23
24
  * await user.save(); // PUT, then persists the key column
25
+ * ```
24
26
  *
25
27
  * The key column (`avatarKey` by default) is registered automatically, so it
26
28
  * does not need its own `@Column`.
@@ -10,6 +10,7 @@
10
10
  *
11
11
  * prorm.registerStore('assets', s3Store, { defaultBucket: 'avatars' });
12
12
  *
13
+ * ```ts
13
14
  * @Table()
14
15
  * class User extends Model {
15
16
  * @Column(DataTypes.STRING) declare name: string;
@@ -22,6 +23,7 @@
22
23
  * await user.loadAvatar(); // GET, populates user.avatar
23
24
  * user.avatar = newBytes;
24
25
  * await user.save(); // PUT, then persists the key column
26
+ * ```
25
27
  *
26
28
  * The key column (`avatarKey` by default) is registered automatically, so it
27
29
  * does not need its own `@Column`.
@@ -18,6 +18,10 @@ declare abstract class BaseAssociation {
18
18
  */
19
19
  getAssociationConfig(): AssociationConfig;
20
20
  }
21
+ /**
22
+ * The resolved shape of a declared association: the two models, the foreign
23
+ * key, the alias, and any join table.
24
+ */
21
25
  export interface AssociationConfig {
22
26
  model: ModelStatic<any>;
23
27
  as: string;
@@ -28,6 +32,9 @@ export interface AssociationConfig {
28
32
  onDelete?: string;
29
33
  onUpdate?: string;
30
34
  }
35
+ /**
36
+ * An eager-load nested inside another, for traversing more than one hop.
37
+ */
31
38
  export interface NestedIncludeOptions extends IncludeOptions {
32
39
  /**
33
40
  * Nested includes - support for multi-level eager loading
@@ -59,6 +66,10 @@ export declare class HasOneAssociation extends BaseAssociation {
59
66
  */
60
67
  getConstraintSql(tableName: string): string;
61
68
  }
69
+ /**
70
+ * A one-to-many relationship. The foreign key lives on the **target**, so the
71
+ * child rows are what get written when the association changes.
72
+ */
62
73
  export declare class HasManyAssociation extends BaseAssociation {
63
74
  constructor(source: ModelStatic<any>, target: ModelStatic<any>, options?: AssociationOptions);
64
75
  inferForeignKey(): string;
@@ -68,6 +79,10 @@ export declare class HasManyAssociation extends BaseAssociation {
68
79
  */
69
80
  getConstraintSql(tableName: string): string;
70
81
  }
82
+ /**
83
+ * A many-to-one relationship. The foreign key lives on the **source**, so the
84
+ * row you called it on is what gets written.
85
+ */
71
86
  export declare class BelongsToAssociation extends BaseAssociation {
72
87
  constructor(source: ModelStatic<any>, target: ModelStatic<any>, options?: AssociationOptions);
73
88
  inferForeignKey(): string;
@@ -81,6 +96,10 @@ export declare class BelongsToAssociation extends BaseAssociation {
81
96
  */
82
97
  getForeignKeyOptions(): AssociationForeignKeyOptions | undefined;
83
98
  }
99
+ /**
100
+ * A many-to-many relationship through a join table. Neither side holds a
101
+ * foreign key; the join table holds both.
102
+ */
84
103
  export declare class BelongsToManyAssociation extends BaseAssociation {
85
104
  private through;
86
105
  private throughModel;
@@ -93,18 +112,37 @@ export declare class BelongsToManyAssociation extends BaseAssociation {
93
112
  setThroughModel(model: ModelStatic<any>): void;
94
113
  getThroughModel(): ModelStatic<any> | null;
95
114
  }
115
+ /**
116
+ * The instance methods a `hasOne` adds — get, set and create the related row.
117
+ */
96
118
  export interface HasOneMixin {
97
119
  (target: ModelStatic<any>, options?: AssociationOptions): HasOneAssociation;
98
120
  }
121
+ /**
122
+ * The instance methods a `hasMany` adds — get, set, add, remove, count and
123
+ * create related rows.
124
+ */
99
125
  export interface HasManyMixin {
100
126
  (target: ModelStatic<any>, options?: AssociationOptions): HasManyAssociation;
101
127
  }
128
+ /**
129
+ * The instance methods a `belongsTo` adds — get, set, unset and create the
130
+ * parent row.
131
+ */
102
132
  export interface BelongsToMixin {
103
133
  (target: ModelStatic<any>, options?: AssociationOptions): BelongsToAssociation;
104
134
  }
135
+ /**
136
+ * The instance methods a `belongsToMany` adds, including the join-table
137
+ * operations for adding and removing links.
138
+ */
105
139
  export interface BelongsToManyMixin {
106
140
  (target: ModelStatic<any>, options?: AssociationOptions): BelongsToManyAssociation;
107
141
  }
142
+ /**
143
+ * Attaches the association helper methods to a model, named after the alias
144
+ * so `User.hasMany(Post)` yields `getPosts`, `addPost` and the rest.
145
+ */
108
146
  export declare function createAssociationMixins(source: ModelStatic<any>, sourceModelName: string, instancePrototype?: any): {
109
147
  hasOne: HasOneMixin;
110
148
  hasMany: HasManyMixin;
@@ -130,6 +130,10 @@ class HasOneAssociation extends BaseAssociation {
130
130
  }
131
131
  exports.HasOneAssociation = HasOneAssociation;
132
132
  // HasMany Association - one-to-many where source has many targets
133
+ /**
134
+ * A one-to-many relationship. The foreign key lives on the **target**, so the
135
+ * child rows are what get written when the association changes.
136
+ */
133
137
  class HasManyAssociation extends BaseAssociation {
134
138
  constructor(source, target, options = {}) {
135
139
  super(source, target, options);
@@ -163,6 +167,10 @@ class HasManyAssociation extends BaseAssociation {
163
167
  }
164
168
  exports.HasManyAssociation = HasManyAssociation;
165
169
  // BelongsTo Association - one-to-one where source belongs to target
170
+ /**
171
+ * A many-to-one relationship. The foreign key lives on the **source**, so the
172
+ * row you called it on is what gets written.
173
+ */
166
174
  class BelongsToAssociation extends BaseAssociation {
167
175
  constructor(source, target, options = {}) {
168
176
  super(source, target, options);
@@ -203,6 +211,10 @@ class BelongsToAssociation extends BaseAssociation {
203
211
  }
204
212
  exports.BelongsToAssociation = BelongsToAssociation;
205
213
  // BelongsToMany Association - many-to-many through a junction table
214
+ /**
215
+ * A many-to-many relationship through a join table. Neither side holds a
216
+ * foreign key; the join table holds both.
217
+ */
206
218
  class BelongsToManyAssociation extends BaseAssociation {
207
219
  constructor(source, target, options = {}) {
208
220
  super(source, target, options);
@@ -278,6 +290,10 @@ class BelongsToManyAssociation extends BaseAssociation {
278
290
  }
279
291
  exports.BelongsToManyAssociation = BelongsToManyAssociation;
280
292
  // Factory function to create association mixin methods
293
+ /**
294
+ * Attaches the association helper methods to a model, named after the alias
295
+ * so `User.hasMany(Post)` yields `getPosts`, `addPost` and the rest.
296
+ */
281
297
  function createAssociationMixins(source, sourceModelName, instancePrototype) {
282
298
  // Use provided instance prototype, or fall back to source.prototype, or source itself
283
299
  const prototypeTarget = instancePrototype || source.prototype || source;