@zerotal/orm 1.9.0 → 1.10.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.
package/api-surface.md CHANGED
@@ -806,14 +806,14 @@ interface CastField = {
806
806
  }
807
807
 
808
808
  interface ColumnOptions = {
809
- cast?: 'boolean' | 'date' | 'datetime' | 'array' | 'integer' | 'json' | 'float' | 'enum' | 'immutable_datetime' | 'encrypted' | 'encrypted:json' | `decimal:${number}` | { get?: (dbValue: unknown) => unknown; set?: (jsValue: unknown) => unknown;} | CastContract<unknown>
809
+ cast?: 'boolean' | 'date' | 'datetime' | 'array' | 'integer' | 'json' | 'float' | 'enum' | 'immutable_datetime' | 'encrypted' | 'encrypted:json' | `decimal:${number}` | { get?: (dbValue: unknown) => unknown; set?: (jsValue: unknown) => unknown;} | CastContract<unknown> | undefined
810
810
  default?: unknown
811
- enumValues?: Record<string, string | number>
812
- index?: boolean
813
- nullable?: boolean
814
- primary?: boolean
815
- type?: 'string' | 'number' | 'boolean' | 'text' | 'datetime' | 'json'
816
- unique?: boolean
811
+ enumValues?: Record<string, string | number> | undefined
812
+ index?: boolean | undefined
813
+ nullable?: boolean | undefined
814
+ primary?: boolean | undefined
815
+ type?: 'string' | 'number' | 'boolean' | 'text' | 'datetime' | 'json' | undefined
816
+ unique?: boolean | undefined
817
817
  }
818
818
 
819
819
  interface Compose = {
@@ -836,10 +836,10 @@ interface CursorPaginateResult = {
836
836
 
837
837
  interface DatabaseConfigShape = {
838
838
  driver: 'sqlite' | 'postgres' | 'mysql'
839
- pool?: { max?: number; idleTimeout?: number;}
840
- replicas?: string[]
839
+ pool?: { max?: number; idleTimeout?: number;} | undefined
840
+ replicas?: string[] | undefined
841
841
  sqlite: { path: string;}
842
- synchronize?: boolean | { enabled: boolean; disruptive?: boolean;}
842
+ synchronize?: boolean | { enabled: boolean; disruptive?: boolean;} | undefined
843
843
  url: string
844
844
  }
845
845
 
@@ -850,9 +850,9 @@ interface HasMany = {
850
850
 
851
851
  interface HasManyThroughOptions = {
852
852
  firstKey: string
853
- localKey?: string
853
+ localKey?: string | undefined
854
854
  secondKey: string
855
- throughLocalKey?: string
855
+ throughLocalKey?: string | undefined
856
856
  }
857
857
 
858
858
  interface HasOne = {
@@ -861,10 +861,10 @@ interface HasOne = {
861
861
  }
862
862
 
863
863
  interface KeysetOptions = {
864
- column?: string
865
- cursor?: string | null
866
- direction?: 'asc' | 'desc'
867
- limit?: number
864
+ column?: string | undefined
865
+ cursor?: string | null | undefined
866
+ direction?: 'asc' | 'desc' | undefined
867
+ limit?: number | undefined
868
868
  }
869
869
 
870
870
  interface KeysetPaginateResult = {
@@ -890,13 +890,13 @@ interface ManyToMany = {
890
890
  }
891
891
 
892
892
  interface ManyToManyOptions = {
893
- localKey?: string
893
+ localKey?: string | undefined
894
894
  pivotForeignKey: string
895
895
  pivotRelatedKey: string
896
896
  pivotTable: string
897
- relatedKey?: string
898
- withPivot?: string[]
899
- withTimestamps?: boolean
897
+ relatedKey?: string | undefined
898
+ withPivot?: string[] | undefined
899
+ withTimestamps?: boolean | undefined
900
900
  }
901
901
 
902
902
  interface MigrationEntry = {
@@ -931,9 +931,9 @@ interface ModelObserver = {
931
931
  interface MorphedByManyOptions = {
932
932
  morphName: string
933
933
  parentPivotKey: string
934
- pivotTable?: string
935
- withPivot?: string[]
936
- withTimestamps?: boolean
934
+ pivotTable?: string | undefined
935
+ withPivot?: string[] | undefined
936
+ withTimestamps?: boolean | undefined
937
937
  }
938
938
 
939
939
  interface MorphMany = {
@@ -942,7 +942,7 @@ interface MorphMany = {
942
942
  }
943
943
 
944
944
  interface MorphManyOptions = {
945
- localKey?: string
945
+ localKey?: string | undefined
946
946
  morphName: string
947
947
  }
948
948
 
@@ -952,7 +952,7 @@ interface MorphOne = {
952
952
  }
953
953
 
954
954
  interface MorphOneOptions = {
955
- localKey?: string
955
+ localKey?: string | undefined
956
956
  morphName: string
957
957
  }
958
958
 
@@ -963,21 +963,21 @@ interface MorphTo = {
963
963
 
964
964
  interface MorphToManyOptions = {
965
965
  morphName: string
966
- pivotTable?: string
966
+ pivotTable?: string | undefined
967
967
  relatedPivotKey: string
968
- withPivot?: string[]
969
- withTimestamps?: boolean
968
+ withPivot?: string[] | undefined
969
+ withTimestamps?: boolean | undefined
970
970
  }
971
971
 
972
972
  interface MorphToOptions = {
973
- morphForeignKey?: string
973
+ morphForeignKey?: string | undefined
974
974
  morphMap: Record<string, () => unknown>
975
- morphTypeColumn?: string
975
+ morphTypeColumn?: string | undefined
976
976
  }
977
977
 
978
978
  interface NPlusOneOptions = {
979
- mode?: 'warn' | 'throw'
980
- threshold?: number
979
+ mode?: 'warn' | 'throw' | undefined
980
+ threshold?: number | undefined
981
981
  }
982
982
 
983
983
  interface PaginateMeta = {
@@ -1067,8 +1067,8 @@ interface TableDecoratorBuilder = {
1067
1067
  }
1068
1068
 
1069
1069
  interface TableOptions = {
1070
- primaryKey?: string
1071
- timestamps?: boolean
1070
+ primaryKey?: string | undefined
1071
+ timestamps?: boolean | undefined
1072
1072
  }
1073
1073
 
1074
1074
  interface TransitionContext = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerotal/orm",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "license": "MIT",
5
5
  "maturity": "stable",
6
6
  "private": false,
@@ -31,8 +31,8 @@
31
31
  "typecheck": "tsc --noEmit"
32
32
  },
33
33
  "dependencies": {
34
- "@zerotal/core": "1.9.0",
35
- "@zerotal/validator": "1.9.0"
34
+ "@zerotal/core": "1.10.0",
35
+ "@zerotal/validator": "1.10.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "typescript": "^5.8.0"
@@ -45,15 +45,15 @@ export interface BackupOptions {
45
45
  * it". An empty `bookings` table in a snapshot of a live system is not a small
46
46
  * discrepancy, it is the whole failure — and it is invisible in a byte count.
47
47
  */
48
- requireRows?: string[];
48
+ requireRows?: string[] | undefined;
49
49
  /**
50
50
  * Perform the restore, not just a read of the snapshot: copy it to a scratch
51
51
  * path, open the copy, and check it there. Exercises the operation an incident
52
52
  * actually needs, rather than the one that is convenient to test.
53
53
  */
54
- rehearse?: boolean;
54
+ rehearse?: boolean | undefined;
55
55
  /** Clock, so the snapshot name is deterministic under test. */
56
- now?: Date;
56
+ now?: Date | undefined;
57
57
  }
58
58
 
59
59
  /** What a completed backup wrote and proved. */
package/src/config.ts CHANGED
@@ -28,17 +28,19 @@ export interface DatabaseConfigShape {
28
28
  * env('REPLICA_2_URL'),
29
29
  * ].filter((url) => url !== undefined)
30
30
  */
31
- replicas?: string[];
31
+ replicas?: string[] | undefined;
32
32
  /**
33
33
  * Connection pool options (PostgreSQL and MySQL only).
34
34
  * Bun.sql manages the pool automatically - these tune its behaviour.
35
35
  */
36
- pool?: {
37
- /** Maximum number of connections in the pool. Default: 10 */
38
- max?: number;
39
- /** Seconds an idle connection is kept before being closed. Default: 30 */
40
- idleTimeout?: number;
41
- };
36
+ pool?:
37
+ | {
38
+ /** Maximum number of connections in the pool. Default: 10 */
39
+ max?: number;
40
+ /** Seconds an idle connection is kept before being closed. Default: 30 */
41
+ idleTimeout?: number;
42
+ }
43
+ | undefined;
42
44
  /** SQLite-specific options */
43
45
  sqlite: {
44
46
  /** Path to the SQLite file. Use ':memory:' for in-memory database. */
@@ -58,7 +60,7 @@ export interface DatabaseConfigShape {
58
60
  * synchronize: { enabled: true, disruptive: false } // explicit, additive
59
61
  * synchronize: { enabled: true, disruptive: true } // also drops removed columns
60
62
  */
61
- synchronize?: boolean | { enabled: boolean; disruptive?: boolean };
63
+ synchronize?: boolean | { enabled: boolean; disruptive?: boolean } | undefined;
62
64
  }
63
65
 
64
66
  const defaults: DatabaseConfigShape = {
@@ -104,12 +104,12 @@ let _forced = false; // true when explicitly configured via preventNPlusOne()
104
104
 
105
105
  export interface NPlusOneOptions {
106
106
  /** How many identical query shapes in one request triggers a violation. Default: 5. */
107
- threshold?: number;
107
+ threshold?: number | undefined;
108
108
  /**
109
109
  * 'warn' → console.warn (default — non-breaking, still visible)
110
110
  * 'throw' → throws NPlusOneError (good for CI / strict mode)
111
111
  */
112
- mode?: "warn" | "throw";
112
+ mode?: "warn" | "throw" | undefined;
113
113
  }
114
114
 
115
115
  /**
package/src/db/types.ts CHANGED
@@ -159,7 +159,7 @@ function _pageUrl(baseUrl: string, page: number, extra: Record<string, string> =
159
159
  /** Options accepted by the pagination helper factories. */
160
160
  export interface PaginationHelperOptions {
161
161
  /** Base path used by no-argument URL helpers and `meta.path`. Default: `''`. */
162
- path?: string;
162
+ path?: string | undefined;
163
163
  }
164
164
 
165
165
  /** Attach URL helper methods + metadata to a plain paginate result object. */
@@ -276,13 +276,13 @@ export interface KeysetOptions {
276
276
  * Opaque cursor string from the previous page's `nextCursor`.
277
277
  * `null` or omitted = first page.
278
278
  */
279
- cursor?: string | null;
279
+ cursor?: string | null | undefined;
280
280
  /** Column used for keyset ordering. Must be a safe SQL identifier. Default: `'id'`. */
281
- column?: string;
281
+ column?: string | undefined;
282
282
  /** Sort direction. Default: `'asc'`. */
283
- direction?: "asc" | "desc";
283
+ direction?: "asc" | "desc" | undefined;
284
284
  /** Items per page. Default: `15`. */
285
- limit?: number;
285
+ limit?: number | undefined;
286
286
  }
287
287
 
288
288
  /** Result of {@link QueryBuilder.keysetPaginate} — opaque-cursor keyset pagination. */
@@ -5,9 +5,9 @@ export interface BelongsToOptions {
5
5
  /** FK column on this (child) model pointing to the related row (e.g. `user_id`). */
6
6
  foreignKey: string;
7
7
  /** Key on the related model the FK references. Defaults to `'id'`. */
8
- localKey?: string;
8
+ localKey?: string | undefined;
9
9
  /** Return a default (unsaved) related model instead of null when absent. */
10
- withDefault?: boolean | Record<string, unknown> | ((model: unknown) => void);
10
+ withDefault?: boolean | Record<string, unknown> | ((model: unknown) => void) | undefined;
11
11
  }
12
12
 
13
13
  /**
@@ -82,11 +82,11 @@ export interface ColumnOptions {
82
82
  *
83
83
  * @default "string"
84
84
  */
85
- type?: "string" | "text" | "number" | "boolean" | "datetime" | "json";
85
+ type?: "string" | "text" | "number" | "boolean" | "datetime" | "json" | undefined;
86
86
  /** Mark this column as the table's primary key. */
87
- primary?: boolean;
87
+ primary?: boolean | undefined;
88
88
  /** Allow SQL `NULL` for this column. */
89
- nullable?: boolean;
89
+ nullable?: boolean | undefined;
90
90
  /** Default value applied when none is provided. */
91
91
  default?: unknown;
92
92
  /**
@@ -96,9 +96,9 @@ export interface ColumnOptions {
96
96
  * usually a correctness property (a webhook idempotency key, an invoice number),
97
97
  * and `migrate:generate` can only emit constraints it can see declared.
98
98
  */
99
- unique?: boolean;
99
+ unique?: boolean | undefined;
100
100
  /** Add a plain (non-unique) index on this column. */
101
- index?: boolean;
101
+ index?: boolean | undefined;
102
102
  /**
103
103
  * Shorthand cast types automatically serialize/deserialize the column value.
104
104
  * Can also be a custom object with `get`/`set` functions for full control.
@@ -134,9 +134,10 @@ export interface ColumnOptions {
134
134
  get?: (dbValue: unknown) => unknown;
135
135
  set?: (jsValue: unknown) => unknown;
136
136
  }
137
- | CastContract<unknown>;
137
+ | CastContract<unknown>
138
+ | undefined;
138
139
  /** Enum object (e.g. the imported TS enum) used alongside cast: 'enum'. */
139
- enumValues?: Record<string, string | number>;
140
+ enumValues?: Record<string, string | number> | undefined;
140
141
  }
141
142
 
142
143
  /**
@@ -5,7 +5,7 @@ export interface HasManyOptions {
5
5
  /** FK column on the related table pointing back to the parent (e.g. `user_id`). */
6
6
  foreignKey: string;
7
7
  /** Parent local key the FK references. Defaults to `'id'`. */
8
- localKey?: string;
8
+ localKey?: string | undefined;
9
9
  }
10
10
 
11
11
  /**
@@ -6,9 +6,9 @@ export interface HasManyThroughOptions {
6
6
  /** FK on the related table referencing the through model (e.g. 'user_id' on posts). */
7
7
  secondKey: string;
8
8
  /** Parent local key the firstKey references. Default 'id'. */
9
- localKey?: string;
9
+ localKey?: string | undefined;
10
10
  /** Through local key the secondKey references. Default 'id'. */
11
- throughLocalKey?: string;
11
+ throughLocalKey?: string | undefined;
12
12
  }
13
13
 
14
14
  /**
@@ -5,7 +5,7 @@ export interface HasOneOptions {
5
5
  /** FK column on the related table pointing back to the parent (e.g. `user_id`). */
6
6
  foreignKey: string;
7
7
  /** Parent local key the FK references. Defaults to `'id'`. */
8
- localKey?: string;
8
+ localKey?: string | undefined;
9
9
  }
10
10
 
11
11
  /**
@@ -9,13 +9,13 @@ export interface ManyToManyOptions {
9
9
  /** Pivot column referencing the related model (e.g. `role_id`). */
10
10
  pivotRelatedKey: string;
11
11
  /** Parent local key the pivot FK references. Defaults to `'id'`. */
12
- localKey?: string;
12
+ localKey?: string | undefined;
13
13
  /** Related local key the pivot relatedKey references. Defaults to `'id'`. */
14
- relatedKey?: string;
14
+ relatedKey?: string | undefined;
15
15
  /** Extra pivot columns to hydrate onto each related model's `pivot` bag. */
16
- withPivot?: string[];
16
+ withPivot?: string[] | undefined;
17
17
  /** Maintain created_at / updated_at on the pivot table during attach/sync. */
18
- withTimestamps?: boolean;
18
+ withTimestamps?: boolean | undefined;
19
19
  }
20
20
 
21
21
  /**
@@ -7,7 +7,7 @@ export interface MorphManyOptions {
7
7
  */
8
8
  morphName: string;
9
9
  /** Override the local key. Defaults to 'id'. */
10
- localKey?: string;
10
+ localKey?: string | undefined;
11
11
  }
12
12
 
13
13
  /**
@@ -7,7 +7,7 @@ export interface MorphOneOptions {
7
7
  */
8
8
  morphName: string;
9
9
  /** Override the local key. Defaults to 'id'. */
10
- localKey?: string;
10
+ localKey?: string | undefined;
11
11
  }
12
12
 
13
13
  /**
@@ -7,12 +7,12 @@ export interface MorphToOptions {
7
7
  * Override the _type column name. Defaults to `<propertyName>_type`.
8
8
  * e.g. property `commentable` → `commentable_type`.
9
9
  */
10
- morphTypeColumn?: string;
10
+ morphTypeColumn?: string | undefined;
11
11
  /**
12
12
  * Override the _id column name. Defaults to `<propertyName>_id`.
13
13
  * e.g. property `commentable` → `commentable_id`.
14
14
  */
15
- morphForeignKey?: string;
15
+ morphForeignKey?: string | undefined;
16
16
  }
17
17
 
18
18
  function _toSnake(s: string): string {
@@ -6,11 +6,11 @@ export interface MorphToManyOptions {
6
6
  /** FK on the pivot table referencing the related model (e.g. 'tag_id'). */
7
7
  relatedPivotKey: string;
8
8
  /** Pivot table name. Defaults to `{morphName}s`. */
9
- pivotTable?: string;
9
+ pivotTable?: string | undefined;
10
10
  /** Extra pivot columns to hydrate. */
11
- withPivot?: string[];
11
+ withPivot?: string[] | undefined;
12
12
  /** Maintain pivot timestamps. */
13
- withTimestamps?: boolean;
13
+ withTimestamps?: boolean | undefined;
14
14
  }
15
15
 
16
16
  /**
@@ -6,9 +6,9 @@ export interface MorphedByManyOptions {
6
6
  /** FK on the pivot referencing the parent model (e.g. 'tag_id'). */
7
7
  parentPivotKey: string;
8
8
  /** Pivot table name. Defaults to `{morphName}s`. */
9
- pivotTable?: string;
10
- withPivot?: string[];
11
- withTimestamps?: boolean;
9
+ pivotTable?: string | undefined;
10
+ withPivot?: string[] | undefined;
11
+ withTimestamps?: boolean | undefined;
12
12
  }
13
13
 
14
14
  /**
@@ -11,9 +11,9 @@ import type { ClassRef } from "../../support/classRef.ts";
11
11
  */
12
12
  export interface TableOptions {
13
13
  /** Enable / disable automatic timestamp columns. @default true */
14
- timestamps?: boolean;
14
+ timestamps?: boolean | undefined;
15
15
  /** Override the primary key column name. @default "id" */
16
- primaryKey?: string;
16
+ primaryKey?: string | undefined;
17
17
  }
18
18
 
19
19
  /**
@@ -52,7 +52,7 @@ export interface SynchronizeOptions {
52
52
  * declared by any model. Off by default - additive changes are always safe,
53
53
  * drops can lose data.
54
54
  */
55
- disruptive?: boolean;
55
+ disruptive?: boolean | undefined;
56
56
  }
57
57
 
58
58
  /**