litedbmodel 2.2.6 → 2.2.8
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/README.md +146 -86
- package/dist/Column.d.ts +30 -6
- package/dist/Column.d.ts.map +1 -1
- package/dist/Column.js +30 -10
- package/dist/Column.js.map +1 -1
- package/dist/DBModel.d.ts +28 -16
- package/dist/DBModel.d.ts.map +1 -1
- package/dist/DBModel.js +60 -46
- package/dist/DBModel.js.map +1 -1
- package/dist/LazyRelation.d.ts +2 -2
- package/dist/LazyRelation.js +2 -2
- package/dist/TypeCast.d.ts +2 -2
- package/dist/TypeCast.d.ts.map +1 -1
- package/dist/TypeCast.js +7 -9
- package/dist/TypeCast.js.map +1 -1
- package/dist/decorators.d.ts +128 -60
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +393 -251
- package/dist/decorators.js.map +1 -1
- package/dist/drivers/MysqlHelper.d.ts +3 -3
- package/dist/drivers/MysqlHelper.d.ts.map +1 -1
- package/dist/drivers/MysqlHelper.js +3 -17
- package/dist/drivers/MysqlHelper.js.map +1 -1
- package/dist/drivers/MysqlSqlBuilder.d.ts.map +1 -1
- package/dist/drivers/MysqlSqlBuilder.js +2 -13
- package/dist/drivers/MysqlSqlBuilder.js.map +1 -1
- package/dist/drivers/PostgresHelper.d.ts +3 -2
- package/dist/drivers/PostgresHelper.d.ts.map +1 -1
- package/dist/drivers/PostgresHelper.js +3 -16
- package/dist/drivers/PostgresHelper.js.map +1 -1
- package/dist/drivers/PostgresSqlBuilder.d.ts.map +1 -1
- package/dist/drivers/PostgresSqlBuilder.js +2 -14
- package/dist/drivers/PostgresSqlBuilder.js.map +1 -1
- package/dist/drivers/SqliteHelper.d.ts +4 -2
- package/dist/drivers/SqliteHelper.d.ts.map +1 -1
- package/dist/drivers/SqliteHelper.js +4 -2
- package/dist/drivers/SqliteHelper.js.map +1 -1
- package/dist/drivers/SqliteSqlBuilder.d.ts.map +1 -1
- package/dist/drivers/SqliteSqlBuilder.js +2 -13
- package/dist/drivers/SqliteSqlBuilder.js.map +1 -1
- package/dist/index.cjs +861 -816
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/scp/coltype.d.ts +14 -5
- package/dist/scp/coltype.d.ts.map +1 -1
- package/dist/scp/coltype.js +35 -36
- package/dist/scp/coltype.js.map +1 -1
- package/dist/scp/decorator-adapter.d.ts +12 -15
- package/dist/scp/decorator-adapter.d.ts.map +1 -1
- package/dist/scp/decorator-adapter.js +13 -15
- package/dist/scp/decorator-adapter.js.map +1 -1
- package/dist/scp/index.cjs +237 -233
- package/dist/scp/index.mjs +237 -233
- package/dist/scp/makesql/json-array.d.ts +6 -0
- package/dist/scp/makesql/json-array.d.ts.map +1 -1
- package/dist/scp/makesql/json-array.js +17 -2
- package/dist/scp/makesql/json-array.js.map +1 -1
- package/dist/scp/makesql/tx.d.ts.map +1 -1
- package/dist/scp/makesql/tx.js +1 -3
- package/dist/scp/makesql/tx.js.map +1 -1
- package/dist/scp/relation.d.ts.map +1 -1
- package/dist/scp/relation.js +8 -10
- package/dist/scp/relation.js.map +1 -1
- package/docs/BENCHMARK.md +3 -3
- package/docs/COMPARISON.md +7 -7
- package/docs/api/README.md +18 -18
- package/docs/api/classes/Conditions.md +10 -10
- package/docs/api/classes/DBHandler.md +1 -1
- package/docs/api/classes/DBModel.md +84 -84
- package/docs/api/classes/LimitExceededError.md +1 -1
- package/docs/api/classes/Middleware.md +1 -1
- package/docs/api/classes/SqlRaw.md +1 -1
- package/docs/api/classes/SqlRef.md +1 -1
- package/docs/api/classes/Values.md +6 -6
- package/docs/api/classes/WriteInReadOnlyContextError.md +1 -1
- package/docs/api/classes/WriteOutsideTransactionError.md +1 -1
- package/docs/api/functions/belongsTo.md +10 -4
- package/docs/api/functions/closeAllPools.md +1 -1
- package/docs/api/functions/condsToRecord.md +4 -3
- package/docs/api/functions/createMiddleware.md +1 -1
- package/docs/api/functions/createPostgresDriver.md +1 -1
- package/docs/api/functions/createSqliteDriver.md +1 -1
- package/docs/api/functions/dbCast.md +1 -1
- package/docs/api/functions/dbCastIn.md +1 -1
- package/docs/api/functions/dbDynamic.md +1 -1
- package/docs/api/functions/dbFalse.md +1 -1
- package/docs/api/functions/dbImmediate.md +1 -1
- package/docs/api/functions/dbIn.md +1 -1
- package/docs/api/functions/dbNotNull.md +1 -1
- package/docs/api/functions/dbNow.md +1 -1
- package/docs/api/functions/dbNull.md +1 -1
- package/docs/api/functions/dbRaw.md +1 -1
- package/docs/api/functions/dbTrue.md +1 -1
- package/docs/api/functions/dbUuid.md +1 -1
- package/docs/api/functions/dbUuidIn.md +1 -1
- package/docs/api/functions/formatLocalDate.md +2 -2
- package/docs/api/functions/formatUTCDate.md +2 -2
- package/docs/api/functions/getDBConfig.md +1 -1
- package/docs/api/functions/getDBHandler.md +1 -1
- package/docs/api/functions/getTransactionConnection.md +2 -2
- package/docs/api/functions/getTransactionContext.md +2 -2
- package/docs/api/functions/hasMany.md +11 -5
- package/docs/api/functions/hasOne.md +10 -4
- package/docs/api/functions/initDBHandler.md +1 -1
- package/docs/api/functions/isAnySqlFragment.md +1 -1
- package/docs/api/functions/isConnectionError.md +1 -1
- package/docs/api/functions/isSqlCondition.md +1 -1
- package/docs/api/functions/isSqlFragment.md +1 -1
- package/docs/api/functions/isSqlRaw.md +1 -1
- package/docs/api/functions/isSqlRef.md +1 -1
- package/docs/api/functions/isSqlTypedFragment.md +1 -1
- package/docs/api/functions/model.md +8 -155
- package/docs/api/functions/parentRef.md +1 -1
- package/docs/api/functions/sql.md +1 -1
- package/docs/api/globals.md +99 -58
- package/docs/api/interfaces/Column.md +32 -31
- package/docs/api/interfaces/ColumnDecorator.md +81 -0
- package/docs/api/interfaces/ColumnOptions.md +6 -10
- package/docs/api/interfaces/CreatedMiddlewareClass.md +1 -1
- package/docs/api/interfaces/DBConfig.md +1 -1
- package/docs/api/interfaces/DBConfigOptions.md +1 -1
- package/docs/api/interfaces/DeleteOptions.md +1 -1
- package/docs/api/interfaces/InsertOptions.md +1 -1
- package/docs/api/interfaces/LimitConfig.md +1 -1
- package/docs/api/interfaces/MiddlewareConfig.md +1 -1
- package/docs/api/interfaces/ModelClassDecorator.md +64 -0
- package/docs/api/interfaces/ModelOptions.md +1 -1
- package/docs/api/interfaces/PkeyResult.md +1 -1
- package/docs/api/interfaces/RelationDecorator.md +72 -0
- package/docs/api/interfaces/SelectOptions.md +1 -1
- package/docs/api/interfaces/SqlCondition.md +1 -1
- package/docs/api/interfaces/SqlFragment.md +1 -1
- package/docs/api/interfaces/SqlTypedFragment.md +1 -1
- package/docs/api/interfaces/TransactionOptions.md +1 -1
- package/docs/api/interfaces/UpdateManyOptions.md +1 -1
- package/docs/api/interfaces/UpdateOptions.md +1 -1
- package/docs/api-guide.md +17 -17
- package/docs/architecture.md +14 -10
- package/docs/sql-tagged-template.md +5 -5
- package/eslint-plugin/rules/require-declare-for-relations.js +59 -4
- package/package.json +8 -7
package/dist/decorators.d.ts
CHANGED
|
@@ -38,14 +38,12 @@ export interface ColumnMeta {
|
|
|
38
38
|
/** SQL type for automatic casting in conditions (e.g., 'uuid') */
|
|
39
39
|
sqlCast?: string;
|
|
40
40
|
/**
|
|
41
|
-
* The
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* (
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* its family already maps to the SQL type. `REAL`/`DECIMAL` (a `Number` that is not INT) stays pinned
|
|
48
|
-
* via the adapter's `columnTypes` escape hatch. @internal
|
|
41
|
+
* The SQL-type token a CAST-FREE family declares (`@column.text()` → `TEXT`), so it types the SCP
|
|
42
|
+
* typed-read de-box exactly as a cast-carrying family does: `materializeCell` never mis-reads a
|
|
43
|
+
* string as an int32. A family that already carries a `sqlCast` (`@column.boolean()` / `.bigint()` /
|
|
44
|
+
* `.uuid()` / …) does not set this — its family already maps to the SQL type — and `@column.number()`
|
|
45
|
+
* sets neither, because a JS `number` backs an INTEGER as readily as a REAL/DECIMAL; the DBModel read
|
|
46
|
+
* path pins those to passthrough via the adapter's `columnTypes`. @internal
|
|
49
47
|
*/
|
|
50
48
|
baseSqlType?: string;
|
|
51
49
|
}
|
|
@@ -121,7 +119,21 @@ export interface RelationMeta {
|
|
|
121
119
|
keysFactory: KeysFactory;
|
|
122
120
|
options?: RelationDecoratorOptions;
|
|
123
121
|
}
|
|
124
|
-
/**
|
|
122
|
+
/** The TC39 metadata bag, keyed by our own symbols. @internal */
|
|
123
|
+
type MetadataBag = Record<PropertyKey, unknown>;
|
|
124
|
+
/**
|
|
125
|
+
* The subset of a TC39 `ClassFieldDecoratorContext` / `ClassDecoratorContext` this module reads.
|
|
126
|
+
* `metadata` is optional in the type only to keep the runtime guard honest — a missing bag THROWS
|
|
127
|
+
* ({@link classMetadataBag}) rather than registering a column nowhere.
|
|
128
|
+
* @internal
|
|
129
|
+
*/
|
|
130
|
+
export interface StandardDecoratorContext {
|
|
131
|
+
readonly kind: string;
|
|
132
|
+
readonly name?: string | symbol;
|
|
133
|
+
readonly metadata?: MetadataBag;
|
|
134
|
+
addInitializer?(initializer: (this: unknown) => void): void;
|
|
135
|
+
}
|
|
136
|
+
/** Options that can be passed to any `@column.*` decorator */
|
|
125
137
|
export interface ColumnOptions {
|
|
126
138
|
/** Custom column name (defaults to property name) */
|
|
127
139
|
columnName?: string;
|
|
@@ -134,6 +146,33 @@ export interface ColumnOptions {
|
|
|
134
146
|
*/
|
|
135
147
|
autoIncrement?: boolean;
|
|
136
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* What a `@column.*` decorator may be applied to, under EITHER protocol.
|
|
151
|
+
*
|
|
152
|
+
* Both overloads are typed: `Value` is the decorated field's declared TS type, so a family whose read
|
|
153
|
+
* contract yields a `string` (`@column.datetime()`, `@column.bigint()`, …) will not compile onto a
|
|
154
|
+
* field declared `Date` / `bigint`. That is the compile-time half of the fix for the "declared type ≠
|
|
155
|
+
* value `find()` returns" defect (issue #286), and it holds under BOTH protocols — the legacy
|
|
156
|
+
* property decorator receives the prototype, whose property types a mapped type can constrain.
|
|
157
|
+
*
|
|
158
|
+
* @category Decorators
|
|
159
|
+
*/
|
|
160
|
+
export interface ColumnDecorator<Value> {
|
|
161
|
+
/**
|
|
162
|
+
* Legacy (`experimentalDecorators`) property decorator. The prototype it receives IS typed, so the
|
|
163
|
+
* decorated property's declared type is constrained here too — `@column.datetime() x?: Date` does
|
|
164
|
+
* not compile under either protocol. (It was believed legacy carried no type information; it does,
|
|
165
|
+
* and the majority of models are compiled that way.)
|
|
166
|
+
*/
|
|
167
|
+
<This extends Partial<Record<Key, Value>>, Key extends string | symbol>(target: This, propertyKey: Key): void;
|
|
168
|
+
/** TC39 standard class-field decorator. */
|
|
169
|
+
<This>(value: undefined, context: ClassFieldDecoratorContext<This, Value>): void;
|
|
170
|
+
}
|
|
171
|
+
/** What a relation decorator may be applied to, under either protocol. @category Decorators */
|
|
172
|
+
export interface RelationDecorator<Value> {
|
|
173
|
+
<This extends Partial<Record<Key, Value>>, Key extends string | symbol>(target: This, propertyKey: Key): void;
|
|
174
|
+
<This>(value: undefined, context: ClassFieldDecoratorContext<This, Value>): void;
|
|
175
|
+
}
|
|
137
176
|
/**
|
|
138
177
|
* Serialize function type that optionally accepts driver type cast helper.
|
|
139
178
|
* @internal
|
|
@@ -142,53 +181,69 @@ export type SerializeFunction = (val: unknown, typeCast?: DriverTypeCast) => unk
|
|
|
142
181
|
/**
|
|
143
182
|
* Column decorator for defining model properties.
|
|
144
183
|
*
|
|
145
|
-
* **
|
|
146
|
-
*
|
|
147
|
-
*
|
|
184
|
+
* **A column declares its own type with a family** — the family decides both the TypeScript type the
|
|
185
|
+
* model declares and the value `find()` gives back, on every toolchain and under either decorator
|
|
186
|
+
* protocol. Nothing is inferred from the TypeScript type annotation.
|
|
148
187
|
*
|
|
149
|
-
* Auto-inferred types:
|
|
150
188
|
* ```typescript
|
|
151
|
-
* @column() id?: number;
|
|
152
|
-
* @column() name?: string;
|
|
153
|
-
* @column()
|
|
154
|
-
* @column()
|
|
155
|
-
* @column()
|
|
156
|
-
* @column(
|
|
189
|
+
* @column.number({ primaryKey: true, autoIncrement: true }) id?: number;
|
|
190
|
+
* @column.text() name?: string; // TEXT / VARCHAR / CHAR / ENUM — no cast needed
|
|
191
|
+
* @column.text('custom_name') prop?: string; // custom column name
|
|
192
|
+
* @column.decimal() price?: string; // NUMERIC / DECIMAL — exact decimal string
|
|
193
|
+
* @column.boolean() is_active?: boolean;
|
|
194
|
+
* @column.datetime() created_at?: string; // TZ-attached string, NOT a JS Date
|
|
195
|
+
* @column.date() birth_date?: string; // 'YYYY-MM-DD'
|
|
196
|
+
* @column.bigint() large_id?: bigint; // bc `int` — a JS bigint
|
|
197
|
+
* @column.uuid() ext_id?: string;
|
|
198
|
+
* @column.stringArray() tags?: string[];
|
|
199
|
+
* @column.intArray() scores?: number[];
|
|
200
|
+
* @column.json<MyType>() data?: MyType;
|
|
201
|
+
* @column.date() birth_date?: string; // 'YYYY-MM-DD' — not a datetime
|
|
202
|
+
* @column.passthrough() payload?: unknown; // BYTEA / BLOB — no cast exists
|
|
203
|
+
* @column.custom((v) => String(v).toUpperCase()) status?: string;
|
|
157
204
|
* ```
|
|
158
205
|
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* @column.json<MyType>() data?: MyType; // Generic type unknown
|
|
164
|
-
* @column.date() birth_date?: string; // date vs datetime distinction
|
|
165
|
-
* ```
|
|
166
|
-
*
|
|
167
|
-
* Note: The explicit variants (`@column.boolean()`, `@column.datetime()`, etc.)
|
|
168
|
-
* still work and can be used when you want to be explicit about the conversion.
|
|
206
|
+
* Every family takes what the removed bare `@column()` took: a column name, or {@link ColumnOptions}.
|
|
207
|
+
* The bare form inferred the type from `emitDecoratorMetadata`, which esbuild (tsx / vite / vitest)
|
|
208
|
+
* never emits and TC39 standard decorators do not have, so it silently produced untyped reads; it now
|
|
209
|
+
* reports the migration instead (see {@link requireColumnFamily}).
|
|
169
210
|
*
|
|
170
211
|
* @category Decorators
|
|
171
212
|
*/
|
|
172
|
-
export declare const column: ((
|
|
213
|
+
export declare const column: ((_columnNameOrOptions?: string | ColumnOptions) => never) & {
|
|
214
|
+
/**
|
|
215
|
+
* Text type (TEXT / VARCHAR / CHAR / ENUM / citext) — the driver value is already a string, so no
|
|
216
|
+
* cast is applied. The family still DECLARES the column so the typed read types it as `TEXT`.
|
|
217
|
+
* @example @column.text() name?: string;
|
|
218
|
+
* @example @column.text('user_name') name?: string;
|
|
219
|
+
*/
|
|
220
|
+
text: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
|
|
221
|
+
/**
|
|
222
|
+
* Exact decimal type (NUMERIC / DECIMAL) — read back as its exact decimal STRING (a JS number
|
|
223
|
+
* rounds past 2^53). The family states the column is `numeric`, so a write binds the string as a
|
|
224
|
+
* numeric — a batch write (`createMany` / `updateMany`) included.
|
|
225
|
+
* @example @column.decimal() price?: string;
|
|
226
|
+
*/
|
|
227
|
+
decimal: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
|
|
173
228
|
/**
|
|
174
229
|
* Boolean type conversion
|
|
175
230
|
* Converts 't'/'f', 'true'/'false', 1/0 to boolean
|
|
176
231
|
* Preserves null for nullable columns, undefined stays undefined
|
|
177
232
|
* @example @column.boolean() is_active?: boolean;
|
|
178
233
|
*/
|
|
179
|
-
boolean: (
|
|
234
|
+
boolean: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<boolean | null | undefined>;
|
|
180
235
|
/**
|
|
181
236
|
* Number type conversion (from string)
|
|
182
237
|
* Preserves null for nullable columns, undefined stays undefined
|
|
183
238
|
* @example @column.number() amount?: number;
|
|
184
239
|
*/
|
|
185
|
-
number: (
|
|
240
|
+
number: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<number | null | undefined>;
|
|
186
241
|
/**
|
|
187
242
|
* BigInt type conversion
|
|
188
243
|
* Preserves null for nullable columns, undefined stays undefined
|
|
189
|
-
* @example @column.bigint() large_id?: bigint;
|
|
244
|
+
* @example @column.bigint() large_id?: bigint; // bc `int` — a JS bigint, checked i64
|
|
190
245
|
*/
|
|
191
|
-
bigint: (
|
|
246
|
+
bigint: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<bigint | null | undefined>;
|
|
192
247
|
/**
|
|
193
248
|
* DateTime type conversion (timestamp, timestamptz)
|
|
194
249
|
* Preserves null for nullable columns, undefined stays undefined
|
|
@@ -197,9 +252,9 @@ export declare const column: ((columnNameOrOptions?: string | ColumnOptions) =>
|
|
|
197
252
|
* - PostgreSQL: Serializes to ISO 8601 UTC string with 'Z' suffix for explicit timezone
|
|
198
253
|
* - MySQL/SQLite: Passes Date object to driver (driver-dependent timezone handling)
|
|
199
254
|
*
|
|
200
|
-
* @example @column.datetime() created_at?: Date
|
|
255
|
+
* @example @column.datetime() created_at?: string; // TZ-attached string, NOT a JS Date
|
|
201
256
|
*/
|
|
202
|
-
datetime: (
|
|
257
|
+
datetime: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
|
|
203
258
|
/**
|
|
204
259
|
* Date type conversion — returns YYYY-MM-DD string.
|
|
205
260
|
* Preserves null for nullable columns, undefined stays undefined.
|
|
@@ -207,46 +262,46 @@ export declare const column: ((columnNameOrOptions?: string | ColumnOptions) =>
|
|
|
207
262
|
* DB values (Date object or string) are normalized to 'YYYY-MM-DD' string.
|
|
208
263
|
* On write, string values are passed through; Date objects are formatted as 'YYYY-MM-DD'.
|
|
209
264
|
*
|
|
210
|
-
* @example @column.date() birth_date?: string;
|
|
265
|
+
* @example @column.date() birth_date?: string; // 'YYYY-MM-DD'
|
|
211
266
|
*/
|
|
212
|
-
date: (
|
|
267
|
+
date: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
|
|
213
268
|
/**
|
|
214
269
|
* String array type conversion (text[])
|
|
215
270
|
* Preserves null for nullable columns, undefined stays undefined
|
|
216
271
|
* @example @column.stringArray() tags?: string[];
|
|
217
272
|
*/
|
|
218
|
-
stringArray: (
|
|
273
|
+
stringArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string[] | null | undefined>;
|
|
219
274
|
/**
|
|
220
275
|
* Integer array type conversion (integer[])
|
|
221
276
|
* Preserves null for nullable columns, undefined stays undefined
|
|
222
277
|
* @example @column.intArray() scores?: number[];
|
|
223
278
|
*/
|
|
224
|
-
intArray: (
|
|
279
|
+
intArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<number[] | null | undefined>;
|
|
225
280
|
/**
|
|
226
281
|
* Numeric array type conversion (numeric[], allows null elements)
|
|
227
282
|
* Preserves null for nullable columns, undefined stays undefined
|
|
228
283
|
* @example @column.numericArray() values?: (number | null)[];
|
|
229
284
|
*/
|
|
230
|
-
numericArray: (
|
|
285
|
+
numericArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<(number | null)[] | null | undefined>;
|
|
231
286
|
/**
|
|
232
287
|
* Boolean array type conversion (boolean[])
|
|
233
288
|
* Preserves null for nullable columns, undefined stays undefined
|
|
234
289
|
* @example @column.booleanArray() flags?: (boolean | null)[];
|
|
235
290
|
*/
|
|
236
|
-
booleanArray: (
|
|
291
|
+
booleanArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<(boolean | null)[] | null | undefined>;
|
|
237
292
|
/**
|
|
238
293
|
* DateTime array type conversion (timestamp[])
|
|
239
294
|
* Preserves null for nullable columns, undefined stays undefined
|
|
240
|
-
* @example @column.datetimeArray() event_dates?: (
|
|
295
|
+
* @example @column.datetimeArray() event_dates?: (string | null)[];
|
|
241
296
|
*/
|
|
242
|
-
datetimeArray: (
|
|
297
|
+
datetimeArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<(string | null)[] | null | undefined>;
|
|
243
298
|
/**
|
|
244
299
|
* JSON/JSONB type conversion
|
|
245
300
|
* Preserves null for nullable columns, undefined stays undefined
|
|
246
301
|
* @example @column.json() metadata?: Record<string, unknown>;
|
|
247
302
|
* @example @column.json<UserSettings>() settings?: UserSettings;
|
|
248
303
|
*/
|
|
249
|
-
json: <T = Record<string, unknown>>(
|
|
304
|
+
json: <T = Record<string, unknown>>(columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<T | null | undefined>;
|
|
250
305
|
/**
|
|
251
306
|
* UUID type with automatic casting for PostgreSQL.
|
|
252
307
|
* Automatically adds ::uuid cast to conditions and INSERT/UPDATE values.
|
|
@@ -266,13 +321,21 @@ export declare const column: ((columnNameOrOptions?: string | ColumnOptions) =>
|
|
|
266
321
|
* // → WHERE id IN (?::uuid, ?::uuid)
|
|
267
322
|
* ```
|
|
268
323
|
*/
|
|
269
|
-
uuid: (columnNameOrOptions?: string | ColumnOptions) =>
|
|
324
|
+
uuid: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
|
|
325
|
+
/**
|
|
326
|
+
* The driver's value, UNCAST — for a column whose type the library has no cast for (`BYTEA` /
|
|
327
|
+
* `BLOB` arrives as a driver Buffer, a vendor type as whatever the driver decodes). It states
|
|
328
|
+
* "this column is passed through", which is a DECLARATION; the removed bare `@column()` was the
|
|
329
|
+
* absence of one, and produced this same passthrough by accident for every unresolvable type.
|
|
330
|
+
* @example @column.passthrough() payload?: unknown;
|
|
331
|
+
*/
|
|
332
|
+
passthrough: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<unknown>;
|
|
270
333
|
/**
|
|
271
334
|
* Custom type conversion with user-provided function
|
|
272
335
|
* @example @column.custom((v) => String(v).toUpperCase()) status?: string;
|
|
273
336
|
* @example @column.custom((v) => v, (v) => JSON.stringify(v)) data?: MyType; // with serializer
|
|
274
337
|
*/
|
|
275
|
-
custom: <T>(castFn: (value: unknown) => T, serializeFn?: SerializeFn,
|
|
338
|
+
custom: <T>(castFn: (value: unknown) => T, serializeFn?: SerializeFn, columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<T | null | undefined>;
|
|
276
339
|
};
|
|
277
340
|
/**
|
|
278
341
|
* HasMany relation decorator (1:N).
|
|
@@ -283,7 +346,7 @@ export declare const column: ((columnNameOrOptions?: string | ColumnOptions) =>
|
|
|
283
346
|
*
|
|
284
347
|
* @example
|
|
285
348
|
* ```typescript
|
|
286
|
-
* // Single key relation
|
|
349
|
+
* // Single key relation (legacy decorators: `declare`; standard decorators: `posts!: …`)
|
|
287
350
|
* @hasMany(() => [User.id, Post.author_id])
|
|
288
351
|
* declare posts: Promise<Post[]>;
|
|
289
352
|
*
|
|
@@ -304,7 +367,7 @@ export declare const column: ((columnNameOrOptions?: string | ColumnOptions) =>
|
|
|
304
367
|
*
|
|
305
368
|
* @category Decorators
|
|
306
369
|
*/
|
|
307
|
-
export declare function hasMany(keys: KeysFactory, options?: RelationDecoratorOptions):
|
|
370
|
+
export declare function hasMany<Value = unknown>(keys: KeysFactory, options?: RelationDecoratorOptions): RelationDecorator<Value>;
|
|
308
371
|
/**
|
|
309
372
|
* BelongsTo relation decorator (N:1).
|
|
310
373
|
* Defines a many-to-one relationship where this model belongs to a parent record.
|
|
@@ -328,7 +391,7 @@ export declare function hasMany(keys: KeysFactory, options?: RelationDecoratorOp
|
|
|
328
391
|
*
|
|
329
392
|
* @category Decorators
|
|
330
393
|
*/
|
|
331
|
-
export declare function belongsTo(keys: KeysFactory, options?: RelationDecoratorOptions):
|
|
394
|
+
export declare function belongsTo<Value = unknown>(keys: KeysFactory, options?: RelationDecoratorOptions): RelationDecorator<Value>;
|
|
332
395
|
/**
|
|
333
396
|
* HasOne relation decorator (1:1).
|
|
334
397
|
* Defines a one-to-one relationship where this model has one related record.
|
|
@@ -352,7 +415,7 @@ export declare function belongsTo(keys: KeysFactory, options?: RelationDecorator
|
|
|
352
415
|
*
|
|
353
416
|
* @category Decorators
|
|
354
417
|
*/
|
|
355
|
-
export declare function hasOne(keys: KeysFactory, options?: RelationDecoratorOptions):
|
|
418
|
+
export declare function hasOne<Value = unknown>(keys: KeysFactory, options?: RelationDecoratorOptions): RelationDecorator<Value>;
|
|
356
419
|
/**
|
|
357
420
|
* Get relation metadata from a model class
|
|
358
421
|
* @internal
|
|
@@ -375,10 +438,10 @@ export declare function getRelationMeta(modelClass: object): RelationMeta[];
|
|
|
375
438
|
* ```typescript
|
|
376
439
|
* @model('users')
|
|
377
440
|
* class User extends DBModel {
|
|
378
|
-
* @column() id?: number;
|
|
379
|
-
* @column() name?: string;
|
|
441
|
+
* @column.number() id?: number;
|
|
442
|
+
* @column.text() name?: string;
|
|
380
443
|
* @column.boolean() is_active?: boolean;
|
|
381
|
-
* @column.datetime() created_at?:
|
|
444
|
+
* @column.datetime() created_at?: string;
|
|
382
445
|
*
|
|
383
446
|
* @hasMany(() => [User.id, Post.author_id])
|
|
384
447
|
* declare posts: Promise<Post[]>;
|
|
@@ -397,15 +460,20 @@ export declare function getRelationMeta(modelClass: object): RelationMeta[];
|
|
|
397
460
|
*
|
|
398
461
|
* @category Decorators
|
|
399
462
|
*/
|
|
463
|
+
/** A class decorator that works under both protocols. @category Decorators */
|
|
464
|
+
export interface ModelClassDecorator {
|
|
465
|
+
<T extends {
|
|
466
|
+
new (...args: unknown[]): object;
|
|
467
|
+
}>(constructor: T): T;
|
|
468
|
+
<T extends {
|
|
469
|
+
new (...args: unknown[]): object;
|
|
470
|
+
}>(value: T, context: ClassDecoratorContext): T;
|
|
471
|
+
}
|
|
400
472
|
export declare function model<T extends {
|
|
401
473
|
new (...args: unknown[]): object;
|
|
402
474
|
}>(constructor: T): T;
|
|
403
|
-
export declare function model(tableName: string):
|
|
404
|
-
|
|
405
|
-
}>(constructor: T) => T;
|
|
406
|
-
export declare function model(tableName: string, options: ModelOptions): <T extends {
|
|
407
|
-
new (...args: unknown[]): object;
|
|
408
|
-
}>(constructor: T) => T;
|
|
475
|
+
export declare function model(tableName: string): ModelClassDecorator;
|
|
476
|
+
export declare function model(tableName: string, options: ModelOptions): ModelClassDecorator;
|
|
409
477
|
/**
|
|
410
478
|
* Get column metadata from a model class
|
|
411
479
|
* Useful for building tools and plugins
|
package/dist/decorators.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,SAAS,EAA+B,KAAK,KAAK,
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,SAAS,EAA+B,KAAK,KAAK,EAAE,MAAM,UAAU,CAAC;AAChG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAWtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA+B5C,mCAAmC;AACnC,KAAK,UAAU,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;AAE9C,mEAAmE;AACnE,KAAK,WAAW,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC;AAE1E;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;;;;;OASG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAMD;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG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