litedbmodel 2.2.6 → 2.2.7
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 +145 -86
- package/dist/Column.d.ts +17 -4
- package/dist/Column.d.ts.map +1 -1
- package/dist/Column.js.map +1 -1
- package/dist/DBModel.d.ts +13 -14
- package/dist/DBModel.d.ts.map +1 -1
- package/dist/DBModel.js +20 -21
- package/dist/DBModel.js.map +1 -1
- package/dist/LazyRelation.d.ts +2 -2
- package/dist/LazyRelation.js +2 -2
- package/dist/decorators.d.ts +120 -60
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +379 -248
- package/dist/decorators.js.map +1 -1
- package/dist/index.cjs +283 -217
- 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 +11 -15
- package/dist/scp/decorator-adapter.d.ts.map +1 -1
- package/dist/scp/decorator-adapter.js +11 -15
- package/dist/scp/decorator-adapter.js.map +1 -1
- package/dist/scp/index.cjs +186 -193
- package/dist/scp/index.mjs +186 -193
- 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 +1 -1
- package/docs/api/classes/DBHandler.md +1 -1
- package/docs/api/classes/DBModel.md +82 -82
- 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 +1 -1
- 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 +2 -2
- 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 +1 -1
- package/docs/api/functions/formatUTCDate.md +1 -1
- package/docs/api/functions/getDBConfig.md +1 -1
- package/docs/api/functions/getDBHandler.md +1 -1
- package/docs/api/functions/getTransactionConnection.md +1 -1
- package/docs/api/functions/getTransactionContext.md +1 -1
- 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 +96 -58
- package/docs/api/interfaces/Column.md +1 -1
- 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 +3 -3
- 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,61 @@ export type SerializeFunction = (val: unknown, typeCast?: DriverTypeCast) => unk
|
|
|
142
181
|
/**
|
|
143
182
|
* Column decorator for defining model properties.
|
|
144
183
|
*
|
|
145
|
-
* **
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* Auto-inferred types:
|
|
150
|
-
* ```typescript
|
|
151
|
-
* @column() id?: number; // Auto: Number conversion
|
|
152
|
-
* @column() name?: string; // No conversion needed
|
|
153
|
-
* @column() is_active?: boolean; // Auto: Boolean conversion
|
|
154
|
-
* @column() created_at?: Date; // Auto: DateTime conversion
|
|
155
|
-
* @column() large_id?: bigint; // Auto: BigInt conversion
|
|
156
|
-
* @column('custom_name') prop?: string; // Custom column name
|
|
157
|
-
* ```
|
|
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.
|
|
158
187
|
*
|
|
159
|
-
* Explicit type conversion required (cannot be auto-inferred):
|
|
160
188
|
* ```typescript
|
|
161
|
-
* @column.
|
|
162
|
-
* @column.
|
|
163
|
-
* @column.
|
|
164
|
-
* @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.boolean() is_active?: boolean;
|
|
193
|
+
* @column.datetime() created_at?: string; // TZ-attached string, NOT a JS Date
|
|
194
|
+
* @column.date() birth_date?: string; // 'YYYY-MM-DD'
|
|
195
|
+
* @column.bigint() large_id?: bigint; // bc `int` — a JS bigint
|
|
196
|
+
* @column.uuid() ext_id?: string;
|
|
197
|
+
* @column.stringArray() tags?: string[];
|
|
198
|
+
* @column.intArray() scores?: number[];
|
|
199
|
+
* @column.json<MyType>() data?: MyType;
|
|
200
|
+
* @column.date() birth_date?: string; // 'YYYY-MM-DD' — not a datetime
|
|
201
|
+
* @column.passthrough() payload?: unknown; // BYTEA / BLOB — no cast exists
|
|
202
|
+
* @column.custom((v) => String(v).toUpperCase()) status?: string;
|
|
165
203
|
* ```
|
|
166
204
|
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
205
|
+
* Every family takes what the removed bare `@column()` took: a column name, or {@link ColumnOptions}.
|
|
206
|
+
* The bare form inferred the type from `emitDecoratorMetadata`, which esbuild (tsx / vite / vitest)
|
|
207
|
+
* never emits and TC39 standard decorators do not have, so it silently produced untyped reads; it now
|
|
208
|
+
* reports the migration instead (see {@link requireColumnFamily}).
|
|
169
209
|
*
|
|
170
210
|
* @category Decorators
|
|
171
211
|
*/
|
|
172
|
-
export declare const column: ((
|
|
212
|
+
export declare const column: ((_columnNameOrOptions?: string | ColumnOptions) => never) & {
|
|
213
|
+
/**
|
|
214
|
+
* Text type (TEXT / VARCHAR / CHAR / ENUM / citext) — the driver value is already a string, so no
|
|
215
|
+
* cast is applied. The family still DECLARES the column so the typed read types it as `TEXT`.
|
|
216
|
+
* @example @column.text() name?: string;
|
|
217
|
+
* @example @column.text('user_name') name?: string;
|
|
218
|
+
*/
|
|
219
|
+
text: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
|
|
173
220
|
/**
|
|
174
221
|
* Boolean type conversion
|
|
175
222
|
* Converts 't'/'f', 'true'/'false', 1/0 to boolean
|
|
176
223
|
* Preserves null for nullable columns, undefined stays undefined
|
|
177
224
|
* @example @column.boolean() is_active?: boolean;
|
|
178
225
|
*/
|
|
179
|
-
boolean: (
|
|
226
|
+
boolean: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<boolean | null | undefined>;
|
|
180
227
|
/**
|
|
181
228
|
* Number type conversion (from string)
|
|
182
229
|
* Preserves null for nullable columns, undefined stays undefined
|
|
183
230
|
* @example @column.number() amount?: number;
|
|
184
231
|
*/
|
|
185
|
-
number: (
|
|
232
|
+
number: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<number | null | undefined>;
|
|
186
233
|
/**
|
|
187
234
|
* BigInt type conversion
|
|
188
235
|
* Preserves null for nullable columns, undefined stays undefined
|
|
189
|
-
* @example @column.bigint() large_id?: bigint;
|
|
236
|
+
* @example @column.bigint() large_id?: bigint; // bc `int` — a JS bigint, checked i64
|
|
190
237
|
*/
|
|
191
|
-
bigint: (
|
|
238
|
+
bigint: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<bigint | null | undefined>;
|
|
192
239
|
/**
|
|
193
240
|
* DateTime type conversion (timestamp, timestamptz)
|
|
194
241
|
* Preserves null for nullable columns, undefined stays undefined
|
|
@@ -197,9 +244,9 @@ export declare const column: ((columnNameOrOptions?: string | ColumnOptions) =>
|
|
|
197
244
|
* - PostgreSQL: Serializes to ISO 8601 UTC string with 'Z' suffix for explicit timezone
|
|
198
245
|
* - MySQL/SQLite: Passes Date object to driver (driver-dependent timezone handling)
|
|
199
246
|
*
|
|
200
|
-
* @example @column.datetime() created_at?: Date
|
|
247
|
+
* @example @column.datetime() created_at?: string; // TZ-attached string, NOT a JS Date
|
|
201
248
|
*/
|
|
202
|
-
datetime: (
|
|
249
|
+
datetime: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
|
|
203
250
|
/**
|
|
204
251
|
* Date type conversion — returns YYYY-MM-DD string.
|
|
205
252
|
* Preserves null for nullable columns, undefined stays undefined.
|
|
@@ -207,46 +254,46 @@ export declare const column: ((columnNameOrOptions?: string | ColumnOptions) =>
|
|
|
207
254
|
* DB values (Date object or string) are normalized to 'YYYY-MM-DD' string.
|
|
208
255
|
* On write, string values are passed through; Date objects are formatted as 'YYYY-MM-DD'.
|
|
209
256
|
*
|
|
210
|
-
* @example @column.date() birth_date?: string;
|
|
257
|
+
* @example @column.date() birth_date?: string; // 'YYYY-MM-DD'
|
|
211
258
|
*/
|
|
212
|
-
date: (
|
|
259
|
+
date: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
|
|
213
260
|
/**
|
|
214
261
|
* String array type conversion (text[])
|
|
215
262
|
* Preserves null for nullable columns, undefined stays undefined
|
|
216
263
|
* @example @column.stringArray() tags?: string[];
|
|
217
264
|
*/
|
|
218
|
-
stringArray: (
|
|
265
|
+
stringArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string[] | null | undefined>;
|
|
219
266
|
/**
|
|
220
267
|
* Integer array type conversion (integer[])
|
|
221
268
|
* Preserves null for nullable columns, undefined stays undefined
|
|
222
269
|
* @example @column.intArray() scores?: number[];
|
|
223
270
|
*/
|
|
224
|
-
intArray: (
|
|
271
|
+
intArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<number[] | null | undefined>;
|
|
225
272
|
/**
|
|
226
273
|
* Numeric array type conversion (numeric[], allows null elements)
|
|
227
274
|
* Preserves null for nullable columns, undefined stays undefined
|
|
228
275
|
* @example @column.numericArray() values?: (number | null)[];
|
|
229
276
|
*/
|
|
230
|
-
numericArray: (
|
|
277
|
+
numericArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<(number | null)[] | null | undefined>;
|
|
231
278
|
/**
|
|
232
279
|
* Boolean array type conversion (boolean[])
|
|
233
280
|
* Preserves null for nullable columns, undefined stays undefined
|
|
234
281
|
* @example @column.booleanArray() flags?: (boolean | null)[];
|
|
235
282
|
*/
|
|
236
|
-
booleanArray: (
|
|
283
|
+
booleanArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<(boolean | null)[] | null | undefined>;
|
|
237
284
|
/**
|
|
238
285
|
* DateTime array type conversion (timestamp[])
|
|
239
286
|
* Preserves null for nullable columns, undefined stays undefined
|
|
240
|
-
* @example @column.datetimeArray() event_dates?: (
|
|
287
|
+
* @example @column.datetimeArray() event_dates?: (string | null)[];
|
|
241
288
|
*/
|
|
242
|
-
datetimeArray: (
|
|
289
|
+
datetimeArray: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<(string | null)[] | null | undefined>;
|
|
243
290
|
/**
|
|
244
291
|
* JSON/JSONB type conversion
|
|
245
292
|
* Preserves null for nullable columns, undefined stays undefined
|
|
246
293
|
* @example @column.json() metadata?: Record<string, unknown>;
|
|
247
294
|
* @example @column.json<UserSettings>() settings?: UserSettings;
|
|
248
295
|
*/
|
|
249
|
-
json: <T = Record<string, unknown>>(
|
|
296
|
+
json: <T = Record<string, unknown>>(columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<T | null | undefined>;
|
|
250
297
|
/**
|
|
251
298
|
* UUID type with automatic casting for PostgreSQL.
|
|
252
299
|
* Automatically adds ::uuid cast to conditions and INSERT/UPDATE values.
|
|
@@ -266,13 +313,21 @@ export declare const column: ((columnNameOrOptions?: string | ColumnOptions) =>
|
|
|
266
313
|
* // → WHERE id IN (?::uuid, ?::uuid)
|
|
267
314
|
* ```
|
|
268
315
|
*/
|
|
269
|
-
uuid: (columnNameOrOptions?: string | ColumnOptions) =>
|
|
316
|
+
uuid: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<string | null | undefined>;
|
|
317
|
+
/**
|
|
318
|
+
* The driver's value, UNCAST — for a column whose type the library has no cast for (`BYTEA` /
|
|
319
|
+
* `BLOB` arrives as a driver Buffer, a vendor type as whatever the driver decodes). It states
|
|
320
|
+
* "this column is passed through", which is a DECLARATION; the removed bare `@column()` was the
|
|
321
|
+
* absence of one, and produced this same passthrough by accident for every unresolvable type.
|
|
322
|
+
* @example @column.passthrough() payload?: unknown;
|
|
323
|
+
*/
|
|
324
|
+
passthrough: (columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<unknown>;
|
|
270
325
|
/**
|
|
271
326
|
* Custom type conversion with user-provided function
|
|
272
327
|
* @example @column.custom((v) => String(v).toUpperCase()) status?: string;
|
|
273
328
|
* @example @column.custom((v) => v, (v) => JSON.stringify(v)) data?: MyType; // with serializer
|
|
274
329
|
*/
|
|
275
|
-
custom: <T>(castFn: (value: unknown) => T, serializeFn?: SerializeFn,
|
|
330
|
+
custom: <T>(castFn: (value: unknown) => T, serializeFn?: SerializeFn, columnNameOrOptions?: string | ColumnOptions) => ColumnDecorator<T | null | undefined>;
|
|
276
331
|
};
|
|
277
332
|
/**
|
|
278
333
|
* HasMany relation decorator (1:N).
|
|
@@ -283,7 +338,7 @@ export declare const column: ((columnNameOrOptions?: string | ColumnOptions) =>
|
|
|
283
338
|
*
|
|
284
339
|
* @example
|
|
285
340
|
* ```typescript
|
|
286
|
-
* // Single key relation
|
|
341
|
+
* // Single key relation (legacy decorators: `declare`; standard decorators: `posts!: …`)
|
|
287
342
|
* @hasMany(() => [User.id, Post.author_id])
|
|
288
343
|
* declare posts: Promise<Post[]>;
|
|
289
344
|
*
|
|
@@ -304,7 +359,7 @@ export declare const column: ((columnNameOrOptions?: string | ColumnOptions) =>
|
|
|
304
359
|
*
|
|
305
360
|
* @category Decorators
|
|
306
361
|
*/
|
|
307
|
-
export declare function hasMany(keys: KeysFactory, options?: RelationDecoratorOptions):
|
|
362
|
+
export declare function hasMany<Value = unknown>(keys: KeysFactory, options?: RelationDecoratorOptions): RelationDecorator<Value>;
|
|
308
363
|
/**
|
|
309
364
|
* BelongsTo relation decorator (N:1).
|
|
310
365
|
* Defines a many-to-one relationship where this model belongs to a parent record.
|
|
@@ -328,7 +383,7 @@ export declare function hasMany(keys: KeysFactory, options?: RelationDecoratorOp
|
|
|
328
383
|
*
|
|
329
384
|
* @category Decorators
|
|
330
385
|
*/
|
|
331
|
-
export declare function belongsTo(keys: KeysFactory, options?: RelationDecoratorOptions):
|
|
386
|
+
export declare function belongsTo<Value = unknown>(keys: KeysFactory, options?: RelationDecoratorOptions): RelationDecorator<Value>;
|
|
332
387
|
/**
|
|
333
388
|
* HasOne relation decorator (1:1).
|
|
334
389
|
* Defines a one-to-one relationship where this model has one related record.
|
|
@@ -352,7 +407,7 @@ export declare function belongsTo(keys: KeysFactory, options?: RelationDecorator
|
|
|
352
407
|
*
|
|
353
408
|
* @category Decorators
|
|
354
409
|
*/
|
|
355
|
-
export declare function hasOne(keys: KeysFactory, options?: RelationDecoratorOptions):
|
|
410
|
+
export declare function hasOne<Value = unknown>(keys: KeysFactory, options?: RelationDecoratorOptions): RelationDecorator<Value>;
|
|
356
411
|
/**
|
|
357
412
|
* Get relation metadata from a model class
|
|
358
413
|
* @internal
|
|
@@ -375,10 +430,10 @@ export declare function getRelationMeta(modelClass: object): RelationMeta[];
|
|
|
375
430
|
* ```typescript
|
|
376
431
|
* @model('users')
|
|
377
432
|
* class User extends DBModel {
|
|
378
|
-
* @column() id?: number;
|
|
379
|
-
* @column() name?: string;
|
|
433
|
+
* @column.number() id?: number;
|
|
434
|
+
* @column.text() name?: string;
|
|
380
435
|
* @column.boolean() is_active?: boolean;
|
|
381
|
-
* @column.datetime() created_at?:
|
|
436
|
+
* @column.datetime() created_at?: string;
|
|
382
437
|
*
|
|
383
438
|
* @hasMany(() => [User.id, Post.author_id])
|
|
384
439
|
* declare posts: Promise<Post[]>;
|
|
@@ -397,15 +452,20 @@ export declare function getRelationMeta(modelClass: object): RelationMeta[];
|
|
|
397
452
|
*
|
|
398
453
|
* @category Decorators
|
|
399
454
|
*/
|
|
455
|
+
/** A class decorator that works under both protocols. @category Decorators */
|
|
456
|
+
export interface ModelClassDecorator {
|
|
457
|
+
<T extends {
|
|
458
|
+
new (...args: unknown[]): object;
|
|
459
|
+
}>(constructor: T): T;
|
|
460
|
+
<T extends {
|
|
461
|
+
new (...args: unknown[]): object;
|
|
462
|
+
}>(value: T, context: ClassDecoratorContext): T;
|
|
463
|
+
}
|
|
400
464
|
export declare function model<T extends {
|
|
401
465
|
new (...args: unknown[]): object;
|
|
402
466
|
}>(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;
|
|
467
|
+
export declare function model(tableName: string): ModelClassDecorator;
|
|
468
|
+
export declare function model(tableName: string, options: ModelOptions): ModelClassDecorator;
|
|
409
469
|
/**
|
|
410
470
|
* Get column metadata from a model class
|
|
411
471
|
* 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,EAAiB,MAAM,UAAU,CAAC;AAC/G,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAWtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
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,EAAiB,MAAM,UAAU,CAAC;AAC/G,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;;;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