uql-orm 0.24.2 → 0.24.3
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.
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import type { EntityGetter, FieldOptions, FieldType, RelationManyToManyOptions, RelationManyToOneOptions, RelationOneToManyOptions, RelationOneToOneOptions, TsTypeOf } from '../../type/index.js';
|
|
1
|
+
import type { EntityGetter, FieldOptions, FieldType, IdValue, RelationManyToManyOptions, RelationManyToOneOptions, RelationOneToManyOptions, RelationOneToOneOptions, TsTypeOf } from '../../type/index.js';
|
|
2
2
|
/** A member decorator that also constrains the property it may be applied to. */
|
|
3
3
|
type MemberDecorator<V> = (value: undefined, context: ClassFieldDecoratorContext<unknown, V>) => void;
|
|
4
|
+
/**
|
|
5
|
+
* The property type a set of field options describes, in the same order schema generation resolves the
|
|
6
|
+
* column: a declared `type` wins, and otherwise the column - and so the property - is the referenced
|
|
7
|
+
* primary key's own type. Which is what makes `@Field({ references: () => User })` on a `number`, where
|
|
8
|
+
* `User.id` is a `uuid`, a compile error rather than a column that disagrees with its property.
|
|
9
|
+
*/
|
|
10
|
+
type DeclaredValue<O> = O extends {
|
|
11
|
+
readonly type: infer T extends FieldType;
|
|
12
|
+
} ? TsTypeOf<T> : O extends {
|
|
13
|
+
readonly references: EntityGetter<infer E>;
|
|
14
|
+
} ? IdValue<E> : never;
|
|
4
15
|
/**
|
|
5
16
|
* Declares a persisted field.
|
|
6
17
|
*
|
|
@@ -8,27 +19,22 @@ type MemberDecorator<V> = (value: undefined, context: ClassFieldDecoratorContext
|
|
|
8
19
|
* which is what makes the now-mandatory `type` worth stating.
|
|
9
20
|
*
|
|
10
21
|
* @example `@Field({ type: String }) name?: string;`
|
|
11
|
-
* @example `@Field({ references: () =>
|
|
12
|
-
*/
|
|
13
|
-
export declare function Field<T extends FieldType>(opts: FieldOptions & {
|
|
14
|
-
readonly type: T;
|
|
15
|
-
}): MemberDecorator<TsTypeOf<T> | undefined>;
|
|
16
|
-
/**
|
|
17
|
-
* A foreign key may omit `type`: schema generation resolves it from the referenced primary key, so the
|
|
18
|
-
* column picks up that key's `columnType`, length and chained references rather than a guess.
|
|
22
|
+
* @example `@Field({ references: () => User }) userId?: string;` (where `User.id` is a `uuid`)
|
|
19
23
|
*/
|
|
20
|
-
export declare function Field
|
|
21
|
-
|
|
22
|
-
}
|
|
24
|
+
export declare function Field<O extends FieldOptions<DeclaredValue<O>> & ({
|
|
25
|
+
type: FieldType;
|
|
26
|
+
} | {
|
|
27
|
+
references: EntityGetter;
|
|
28
|
+
})>(opts: O): MemberDecorator<DeclaredValue<O> | undefined>;
|
|
23
29
|
/**
|
|
24
30
|
* Declares the primary key, checked the same way as `@Field`.
|
|
25
31
|
*
|
|
26
32
|
* @example `@Id({ type: Number }) id?: number;`
|
|
27
33
|
* @example `@Id({ type: 'uuid', onInsert: uuidv7 }) id?: string;`
|
|
28
34
|
*/
|
|
29
|
-
export declare function Id<
|
|
30
|
-
|
|
31
|
-
}): MemberDecorator<
|
|
35
|
+
export declare function Id<O extends FieldOptions<DeclaredValue<O>> & {
|
|
36
|
+
type: FieldType;
|
|
37
|
+
}>(opts: O): MemberDecorator<DeclaredValue<O> | undefined>;
|
|
32
38
|
/**
|
|
33
39
|
* `E` comes from the mandatory `entity` getter, so the context can insist the property really holds that
|
|
34
40
|
* entity: `@ManyToOne({ entity: () => Other })` on a `Company` field stops compiling, and a to-many
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { memberRegistrations } from './bag.js';
|
|
2
|
+
/**
|
|
3
|
+
* Declares a persisted field.
|
|
4
|
+
*
|
|
5
|
+
* `@Field({ type: String })` on a `number` property is a compile error rather than a silent TEXT column,
|
|
6
|
+
* which is what makes the now-mandatory `type` worth stating.
|
|
7
|
+
*
|
|
8
|
+
* @example `@Field({ type: String }) name?: string;`
|
|
9
|
+
* @example `@Field({ references: () => User }) userId?: string;` (where `User.id` is a `uuid`)
|
|
10
|
+
*/
|
|
2
11
|
export function Field(opts) {
|
|
3
12
|
return (_value, context) => {
|
|
4
13
|
memberRegistrations(context.metadata).fields[String(context.name)] = opts;
|
package/dist/type/entity.d.ts
CHANGED
|
@@ -206,9 +206,11 @@ export type FieldType = StringConstructor | NumberConstructor | BooleanConstruct
|
|
|
206
206
|
*/
|
|
207
207
|
export type TypeFor<V, T = NonNullable<V>> = IsJson<T> extends true ? JsonColumnType : IsJson<NonNullable<Unpacked<T>>> extends true ? JsonColumnType : T extends readonly number[] ? VectorColumnType : T extends string ? StringConstructor | StringColumnType : T extends number ? NumberConstructor | NumericColumnType : T extends bigint ? BigIntConstructor | NumericColumnType : T extends boolean ? BooleanConstructor | BooleanColumnType : T extends Date ? DateConstructor | DateColumnType : T extends Uint8Array ? BlobColumnType : FieldType;
|
|
208
208
|
/**
|
|
209
|
-
* Configurable options for a field
|
|
209
|
+
* Configurable options for a field, carrying `V`, the value the column holds: what a generator returns
|
|
210
|
+
* and what a default is has to be that value, checked the same way the declared `type` is. `Scalar` by
|
|
211
|
+
* by default, for the places that handle a field without knowing which one it is.
|
|
210
212
|
*/
|
|
211
|
-
export type FieldOptions = {
|
|
213
|
+
export type FieldOptions<V = TsTypeOf<FieldType>> = {
|
|
212
214
|
readonly name?: string;
|
|
213
215
|
readonly isId?: true;
|
|
214
216
|
readonly type?: FieldType;
|
|
@@ -238,8 +240,8 @@ export type FieldOptions = {
|
|
|
238
240
|
readonly virtual?: QueryRaw;
|
|
239
241
|
readonly updatable?: boolean;
|
|
240
242
|
readonly eager?: boolean;
|
|
241
|
-
readonly onInsert?: OnFieldCallback
|
|
242
|
-
readonly onUpdate?: OnFieldCallback
|
|
243
|
+
readonly onInsert?: OnFieldCallback<V>;
|
|
244
|
+
readonly onUpdate?: OnFieldCallback<V>;
|
|
243
245
|
/**
|
|
244
246
|
* Marks this field as the soft-delete field. Its presence makes the entity "soft deletable":
|
|
245
247
|
* a `delete` becomes an `UPDATE` that stamps this field instead of removing the row, and reads
|
|
@@ -251,7 +253,7 @@ export type FieldOptions = {
|
|
|
251
253
|
* @example `@Field({ softDelete: true }) deletedAt?: Date;`
|
|
252
254
|
* @example `@Field({ softDelete: () => Date.now() }) deletedAt?: number;`
|
|
253
255
|
*/
|
|
254
|
-
readonly softDelete?: OnFieldCallback
|
|
256
|
+
readonly softDelete?: true | OnFieldCallback<V>;
|
|
255
257
|
/**
|
|
256
258
|
* SQL column type for migrations. If not specified, inferred from TypeScript type.
|
|
257
259
|
*/
|
|
@@ -279,7 +281,7 @@ export type FieldOptions = {
|
|
|
279
281
|
/**
|
|
280
282
|
* Default value for the column
|
|
281
283
|
*/
|
|
282
|
-
readonly defaultValue?:
|
|
284
|
+
readonly defaultValue?: V | Record<string, unknown>;
|
|
283
285
|
/**
|
|
284
286
|
* Whether the column is auto-incrementing (for integer IDs).
|
|
285
287
|
*/
|
|
@@ -293,7 +295,7 @@ export type FieldOptions = {
|
|
|
293
295
|
*/
|
|
294
296
|
readonly comment?: string;
|
|
295
297
|
};
|
|
296
|
-
export type OnFieldCallback =
|
|
298
|
+
export type OnFieldCallback<V = TsTypeOf<FieldType>> = V | QueryRaw | (() => V | QueryRaw);
|
|
297
299
|
/**
|
|
298
300
|
* The TypeScript types a field may be declared as, given the `type` it registers: the inverse of
|
|
299
301
|
* {@link TypeFor}.
|
|
@@ -316,9 +318,9 @@ export type TsTypeOf<T> = T extends StringConstructor ? string : T extends Numbe
|
|
|
316
318
|
* `@Field({ references: () => Company })` would silently downgrade a `uuid` key to TEXT on every
|
|
317
319
|
* column pointing at it.
|
|
318
320
|
*/
|
|
319
|
-
export type FieldOptionsFor<V> = (FieldOptions & {
|
|
321
|
+
export type FieldOptionsFor<V> = (FieldOptions<NonNullable<V>> & {
|
|
320
322
|
readonly type: TypeFor<V>;
|
|
321
|
-
}) | (FieldOptions & {
|
|
323
|
+
}) | (FieldOptions<NonNullable<V>> & {
|
|
322
324
|
readonly references: EntityGetter;
|
|
323
325
|
readonly type?: TypeFor<V>;
|
|
324
326
|
});
|
|
@@ -14,12 +14,20 @@ export declare function filterFieldKeys<E>(meta: EntityMeta<E>, payload: E, call
|
|
|
14
14
|
* chunk-size estimate inspects the raw payload).
|
|
15
15
|
*/
|
|
16
16
|
export declare function getInsertFieldKeys<E>(meta: EntityMeta<E>, payloads: E[]): FieldKey<E>[];
|
|
17
|
-
export declare function getFieldCallbackValue(val: OnFieldCallback): QueryRaw |
|
|
17
|
+
export declare function getFieldCallbackValue(val: OnFieldCallback): string | number | bigint | boolean | Date | QueryRaw | readonly {
|
|
18
|
+
readonly __json?: never;
|
|
19
|
+
}[] | readonly number[] | Uint8Array<ArrayBufferLike> | {
|
|
20
|
+
readonly __json?: never;
|
|
21
|
+
};
|
|
18
22
|
/**
|
|
19
23
|
* Resolves the value stamped on the soft-delete field when deleting a row.
|
|
20
24
|
* `true` stamps the current timestamp (`new Date()`); any other marker is an {@link OnFieldCallback}.
|
|
21
25
|
*/
|
|
22
|
-
export declare function getSoftDeleteValue(field: FieldOptions): QueryRaw |
|
|
26
|
+
export declare function getSoftDeleteValue(field: FieldOptions): string | number | bigint | boolean | Date | QueryRaw | readonly {
|
|
27
|
+
readonly __json?: never;
|
|
28
|
+
}[] | readonly number[] | Uint8Array<ArrayBufferLike> | {
|
|
29
|
+
readonly __json?: never;
|
|
30
|
+
};
|
|
23
31
|
export declare function fillOnFields<E>(meta: EntityMeta<E>, payload: E | E[], callbackKey: CallbackKey): E[];
|
|
24
32
|
/**
|
|
25
33
|
* The relation keys present in `payload` whose cascade configuration allows `action`. Only
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"homepage": "https://uql-orm.dev",
|
|
4
4
|
"description": "Extremely fast, type-safe TypeScript ORM - one API for every database",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.24.
|
|
6
|
+
"version": "0.24.3",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=24"
|
|
@@ -198,5 +198,5 @@
|
|
|
198
198
|
"publishConfig": {
|
|
199
199
|
"access": "public"
|
|
200
200
|
},
|
|
201
|
-
"gitHead": "
|
|
201
|
+
"gitHead": "4301613bcab77a626513197f1e815f972aa21bba"
|
|
202
202
|
}
|