hysteria-orm 10.7.5 → 10.7.6
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/lib/cli.js.map +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +393 -66
- package/lib/index.d.ts +393 -66
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -3196,11 +3196,13 @@ type DateColumnOptions = {
|
|
|
3196
3196
|
timezone?: Timezone;
|
|
3197
3197
|
/**
|
|
3198
3198
|
* @description Whether to automatically update the timestamp on record updates, uses timezone and format from the dateColumn options
|
|
3199
|
+
* @warning This is a code wise implementation it does not generate a trigger in the database, works with bulk updates too
|
|
3199
3200
|
* @default false
|
|
3200
3201
|
*/
|
|
3201
3202
|
autoUpdate?: boolean;
|
|
3202
3203
|
/**
|
|
3203
3204
|
* @description Whether to automatically set the timestamp on record creation, uses timezone and format from the dateColumn options
|
|
3205
|
+
* @warning This is a code wise implementation it does not generate a trigger in the database, works with bulk creations too
|
|
3204
3206
|
* @default false
|
|
3205
3207
|
*/
|
|
3206
3208
|
autoCreate?: boolean;
|
|
@@ -6526,11 +6528,13 @@ declare abstract class Model<T extends Model<T> = any> extends Entity {
|
|
|
6526
6528
|
private static dispatchModelManager;
|
|
6527
6529
|
}
|
|
6528
6530
|
|
|
6531
|
+
declare const __selfBrand: unique symbol;
|
|
6532
|
+
|
|
6529
6533
|
/**
|
|
6530
6534
|
* Phantom-typed descriptor for a model column.
|
|
6531
6535
|
* `T` carries the TypeScript type the column resolves to at the instance level.
|
|
6532
6536
|
*/
|
|
6533
|
-
interface ColumnDef<T =
|
|
6537
|
+
interface ColumnDef<T = unknown> {
|
|
6534
6538
|
readonly _phantom: T;
|
|
6535
6539
|
readonly _apply: (target: Object, propertyKey: string) => void;
|
|
6536
6540
|
}
|
|
@@ -6542,114 +6546,437 @@ interface RelationDef<T = any> {
|
|
|
6542
6546
|
readonly _phantom: T;
|
|
6543
6547
|
readonly _apply: (target: Object, propertyKey: string) => void;
|
|
6544
6548
|
}
|
|
6545
|
-
type
|
|
6546
|
-
type
|
|
6549
|
+
type ColOptions = Omit<ColumnOptions, "primaryKey" | "serialize" | "prepare">;
|
|
6550
|
+
type ColPrimaryOptions = Omit<ColumnOptions, "primaryKey" | "serialize" | "prepare">;
|
|
6551
|
+
type ColStringOptions = Omit<ColumnOptions, "type" | "serialize" | "prepare"> & {
|
|
6547
6552
|
length?: number;
|
|
6548
6553
|
};
|
|
6549
|
-
type ColTextOptions = Omit<ColumnOptions, "type">;
|
|
6550
|
-
type ColIntegerOptions = Omit<ColumnOptions, "serialize">;
|
|
6551
|
-
type ColBigIntegerOptions = Omit<ColumnOptions, "serialize">;
|
|
6552
|
-
type ColFloatOptions = Omit<ColumnOptions, "serialize">;
|
|
6553
|
-
type ColDecimalOptions = Omit<ColumnOptions, "serialize"> & {
|
|
6554
|
+
type ColTextOptions = Omit<ColumnOptions, "type" | "serialize" | "prepare">;
|
|
6555
|
+
type ColIntegerOptions = Omit<ColumnOptions, "serialize" | "prepare">;
|
|
6556
|
+
type ColBigIntegerOptions = Omit<ColumnOptions, "serialize" | "prepare">;
|
|
6557
|
+
type ColFloatOptions = Omit<ColumnOptions, "serialize" | "prepare">;
|
|
6558
|
+
type ColDecimalOptions = Omit<ColumnOptions, "serialize" | "prepare"> & {
|
|
6554
6559
|
precision?: number;
|
|
6555
6560
|
scale?: number;
|
|
6556
6561
|
};
|
|
6557
|
-
type ColIncrementOptions = Omit<ColumnOptions, "serialize" | "primaryKey" | "nullable">;
|
|
6558
|
-
type ColBigIncrementOptions = Omit<ColumnOptions, "serialize" | "primaryKey" | "nullable">;
|
|
6562
|
+
type ColIncrementOptions = Omit<ColumnOptions, "serialize" | "prepare" | "primaryKey" | "nullable">;
|
|
6563
|
+
type ColBigIncrementOptions = Omit<ColumnOptions, "serialize" | "prepare" | "primaryKey" | "nullable">;
|
|
6559
6564
|
type ColBooleanOptions = Omit<ColumnOptions, "prepare" | "serialize">;
|
|
6560
|
-
type ColDateOptions = Omit<DateColumnOptions, "format">;
|
|
6561
|
-
type ColDatetimeOptions = DatetimeColumnOptions
|
|
6562
|
-
type ColTimestampOptions = DatetimeColumnOptions
|
|
6563
|
-
type ColTimeOptions = Omit<DateColumnOptions, "format">;
|
|
6565
|
+
type ColDateOptions = Omit<DateColumnOptions, "format" | "serialize" | "prepare">;
|
|
6566
|
+
type ColDatetimeOptions = Omit<DatetimeColumnOptions, "serialize" | "prepare">;
|
|
6567
|
+
type ColTimestampOptions = Omit<DatetimeColumnOptions, "serialize" | "prepare">;
|
|
6568
|
+
type ColTimeOptions = Omit<DateColumnOptions, "format" | "serialize" | "prepare">;
|
|
6564
6569
|
type ColJsonOptions = Omit<ColumnOptions, "prepare" | "serialize">;
|
|
6565
|
-
type ColUuidOptions = Omit<ColumnOptions, "prepare">;
|
|
6566
|
-
type ColUlidOptions = Omit<ColumnOptions, "prepare">;
|
|
6567
|
-
type ColBinaryOptions = Omit<ColumnOptions, "type">;
|
|
6570
|
+
type ColUuidOptions = Omit<ColumnOptions, "prepare" | "serialize">;
|
|
6571
|
+
type ColUlidOptions = Omit<ColumnOptions, "prepare" | "serialize">;
|
|
6572
|
+
type ColBinaryOptions = Omit<ColumnOptions, "type" | "serialize" | "prepare">;
|
|
6573
|
+
type ColEnumOptions = Omit<ColumnOptions, "type" | "serialize" | "prepare">;
|
|
6568
6574
|
type ColSymmetricOptions = Omit<SymmetricEncryptionOptions, "prepare" | "serialize">;
|
|
6569
6575
|
type ColAsymmetricOptions = Omit<AsymmetricEncryptionOptions, "prepare" | "serialize">;
|
|
6570
6576
|
type RelationConstraintOptions = {
|
|
6577
|
+
/**
|
|
6578
|
+
* Useful for auto generated migrations to specify the on delete action, it does not affect the code wise implementation
|
|
6579
|
+
*/
|
|
6571
6580
|
onDelete?: OnUpdateOrDelete;
|
|
6581
|
+
/**
|
|
6582
|
+
* Useful for auto generated migrations to specify the on update action, it does not affect the code wise implementation
|
|
6583
|
+
*/
|
|
6572
6584
|
onUpdate?: OnUpdateOrDelete;
|
|
6585
|
+
/**
|
|
6586
|
+
* Useful for auto generated migrations to specify the constraint name, it does not affect the code wise implementation
|
|
6587
|
+
*/
|
|
6573
6588
|
constraintName?: string;
|
|
6574
6589
|
};
|
|
6590
|
+
type RelationNullableOption = {
|
|
6591
|
+
nullable?: boolean;
|
|
6592
|
+
};
|
|
6593
|
+
/**
|
|
6594
|
+
* Resolves to `Base` when `Opts` has `{ nullable: false }`, otherwise
|
|
6595
|
+
* `Base | null | undefined`. This powers nullable-aware type inference
|
|
6596
|
+
* for `col.*()` methods.
|
|
6597
|
+
*/
|
|
6598
|
+
type NullableColumn<Base, Opts> = Opts extends {
|
|
6599
|
+
nullable: false;
|
|
6600
|
+
} ? Base : Base | null | undefined;
|
|
6601
|
+
type TypedSerialize<T> = {
|
|
6602
|
+
serialize?: (value: any) => T;
|
|
6603
|
+
};
|
|
6604
|
+
type TypedPrepare<T> = {
|
|
6605
|
+
prepare?: (value: T) => any;
|
|
6606
|
+
};
|
|
6575
6607
|
interface ColNamespace {
|
|
6576
|
-
|
|
6577
|
-
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
|
|
6594
|
-
|
|
6595
|
-
|
|
6608
|
+
/**
|
|
6609
|
+
* Generic column — you control the TypeScript type via `col<T>()`.
|
|
6610
|
+
* Use for columns whose type doesn't match any built-in helper.
|
|
6611
|
+
*
|
|
6612
|
+
* Supports typed `serialize` and `prepare` callbacks.
|
|
6613
|
+
*
|
|
6614
|
+
* ```ts
|
|
6615
|
+
* col<string>({ nullable: false })
|
|
6616
|
+
* col<MyCustomType>({ serialize: (raw) => parse(raw), prepare: (v) => stringify(v) })
|
|
6617
|
+
* ```
|
|
6618
|
+
*/
|
|
6619
|
+
<T = unknown>(options?: ColOptions & TypedSerialize<T> & TypedPrepare<T>): ColumnDef<T>;
|
|
6620
|
+
/**
|
|
6621
|
+
* Generic primary key column. Defaults to `string | number`.
|
|
6622
|
+
* Override the generic when you know the exact type.
|
|
6623
|
+
*
|
|
6624
|
+
* ```ts
|
|
6625
|
+
* col.primary<number>({ nullable: false })
|
|
6626
|
+
* ```
|
|
6627
|
+
*/
|
|
6628
|
+
primary<T = string | number>(options?: ColPrimaryOptions & TypedSerialize<T> & TypedPrepare<T>): ColumnDef<T>;
|
|
6629
|
+
/**
|
|
6630
|
+
* VARCHAR column. Accepts an optional `length` option.
|
|
6631
|
+
* Type: `string` (nullable-aware).
|
|
6632
|
+
*
|
|
6633
|
+
* ```ts
|
|
6634
|
+
* col.string({ length: 255, nullable: false }) // string
|
|
6635
|
+
* col.string() // string | null | undefined
|
|
6636
|
+
* ```
|
|
6637
|
+
*/
|
|
6638
|
+
string<O extends ColStringOptions = ColStringOptions>(options?: O & TypedSerialize<NullableColumn<string, O>> & TypedPrepare<NullableColumn<string, O>>): ColumnDef<NullableColumn<string, O>>;
|
|
6639
|
+
/**
|
|
6640
|
+
* LONGTEXT column for large text content.
|
|
6641
|
+
* Type: `string` (nullable-aware).
|
|
6642
|
+
*/
|
|
6643
|
+
text<O extends ColTextOptions = ColTextOptions>(options?: O & TypedSerialize<NullableColumn<string, O>> & TypedPrepare<NullableColumn<string, O>>): ColumnDef<NullableColumn<string, O>>;
|
|
6644
|
+
/**
|
|
6645
|
+
* Integer column.
|
|
6646
|
+
* Type: `number` (nullable-aware). Only `prepare` is exposed (no `serialize`).
|
|
6647
|
+
*/
|
|
6648
|
+
integer<O extends ColIntegerOptions = ColIntegerOptions>(options?: O & TypedPrepare<NullableColumn<number, O>>): ColumnDef<NullableColumn<number, O>>;
|
|
6649
|
+
/**
|
|
6650
|
+
* Big integer column for values exceeding 32-bit range.
|
|
6651
|
+
* Type: `number | bigint` (nullable-aware). Only `prepare` is exposed.
|
|
6652
|
+
*/
|
|
6653
|
+
bigInteger<O extends ColBigIntegerOptions = ColBigIntegerOptions>(options?: O & TypedPrepare<NullableColumn<number | bigint, O>>): ColumnDef<NullableColumn<number | bigint, O>>;
|
|
6654
|
+
/**
|
|
6655
|
+
* Floating-point column.
|
|
6656
|
+
* Type: `number` (nullable-aware). Only `prepare` is exposed.
|
|
6657
|
+
*/
|
|
6658
|
+
float<O extends ColFloatOptions = ColFloatOptions>(options?: O & TypedPrepare<NullableColumn<number, O>>): ColumnDef<NullableColumn<number, O>>;
|
|
6659
|
+
/**
|
|
6660
|
+
* Decimal column with optional `precision` and `scale`.
|
|
6661
|
+
* Type: `number` (nullable-aware). Only `prepare` is exposed.
|
|
6662
|
+
*
|
|
6663
|
+
* ```ts
|
|
6664
|
+
* col.decimal({ precision: 10, scale: 2, nullable: false }) // number
|
|
6665
|
+
* ```
|
|
6666
|
+
*/
|
|
6667
|
+
decimal<O extends ColDecimalOptions = ColDecimalOptions>(options?: O & TypedPrepare<NullableColumn<number, O>>): ColumnDef<NullableColumn<number, O>>;
|
|
6668
|
+
/**
|
|
6669
|
+
* Auto-incrementing integer primary key. Always non-nullable.
|
|
6670
|
+
* Type: `number`. Only `prepare` is exposed.
|
|
6671
|
+
*/
|
|
6672
|
+
increment(options?: ColIncrementOptions & TypedPrepare<number>): ColumnDef<number>;
|
|
6673
|
+
/**
|
|
6674
|
+
* Auto-incrementing bigint primary key. Always non-nullable.
|
|
6675
|
+
* Type: `number`. Only `prepare` is exposed.
|
|
6676
|
+
*/
|
|
6677
|
+
bigIncrement(options?: ColBigIncrementOptions & TypedPrepare<number>): ColumnDef<number>;
|
|
6678
|
+
/**
|
|
6679
|
+
* Boolean column.
|
|
6680
|
+
* Type: `boolean` (nullable-aware). No `serialize` or `prepare` exposed.
|
|
6681
|
+
*/
|
|
6682
|
+
boolean<O extends ColBooleanOptions = ColBooleanOptions>(options?: O): ColumnDef<NullableColumn<boolean, O>>;
|
|
6683
|
+
/**
|
|
6684
|
+
* DATE column (YYYY-MM-DD). Defaults to `Date` because database drivers
|
|
6685
|
+
* return `Date` objects.
|
|
6686
|
+
*
|
|
6687
|
+
* To type as `string`, use `col.date<string>()` and provide a `serialize`
|
|
6688
|
+
* function that converts the driver `Date` into a string:
|
|
6689
|
+
*
|
|
6690
|
+
* ```ts
|
|
6691
|
+
* col.date<string>({ serialize: (raw) => raw.toISOString().split("T")[0] })
|
|
6692
|
+
* ```
|
|
6693
|
+
*/
|
|
6694
|
+
date<T extends Date | string = Date>(options: ColDateOptions & {
|
|
6695
|
+
nullable: false;
|
|
6696
|
+
} & TypedSerialize<T> & TypedPrepare<T>): ColumnDef<T>;
|
|
6697
|
+
date<T extends Date | string = Date>(options?: ColDateOptions & TypedSerialize<T | null | undefined> & TypedPrepare<T | null | undefined>): ColumnDef<T | null | undefined>;
|
|
6698
|
+
/**
|
|
6699
|
+
* DATETIME column. Defaults to `Date` because database drivers return
|
|
6700
|
+
* `Date` objects.
|
|
6701
|
+
*
|
|
6702
|
+
* To type as `string`, use `col.datetime<string>()` and provide a
|
|
6703
|
+
* `serialize` function that converts the driver `Date` into a string:
|
|
6704
|
+
*
|
|
6705
|
+
* ```ts
|
|
6706
|
+
* col.datetime<string>({ serialize: (raw) => new Date(raw).toISOString() })
|
|
6707
|
+
* ```
|
|
6708
|
+
*/
|
|
6709
|
+
datetime<T extends Date | string = Date>(options: ColDatetimeOptions & {
|
|
6710
|
+
nullable: false;
|
|
6711
|
+
} & TypedSerialize<T> & TypedPrepare<T>): ColumnDef<T>;
|
|
6712
|
+
datetime<T extends Date | string = Date>(options?: ColDatetimeOptions & TypedSerialize<T | null | undefined> & TypedPrepare<T | null | undefined>): ColumnDef<T | null | undefined>;
|
|
6713
|
+
/**
|
|
6714
|
+
* TIMESTAMP column. Defaults to `Date` because database drivers return
|
|
6715
|
+
* `Date` objects.
|
|
6716
|
+
*
|
|
6717
|
+
* To type as `string`, use `col.timestamp<string>()` and provide a
|
|
6718
|
+
* `serialize` function that converts the driver `Date` into a string:
|
|
6719
|
+
*
|
|
6720
|
+
* ```ts
|
|
6721
|
+
* col.timestamp<string>({ serialize: (raw) => new Date(raw).toISOString() })
|
|
6722
|
+
* ```
|
|
6723
|
+
*/
|
|
6724
|
+
timestamp<T extends Date | string = Date>(options: ColTimestampOptions & {
|
|
6725
|
+
nullable: false;
|
|
6726
|
+
} & TypedSerialize<T> & TypedPrepare<T>): ColumnDef<T>;
|
|
6727
|
+
timestamp<T extends Date | string = Date>(options?: ColTimestampOptions & TypedSerialize<T | null | undefined> & TypedPrepare<T | null | undefined>): ColumnDef<T | null | undefined>;
|
|
6728
|
+
/**
|
|
6729
|
+
* TIME column. Defaults to `Date` because database drivers return
|
|
6730
|
+
* `Date` objects.
|
|
6731
|
+
*
|
|
6732
|
+
* To type as `string`, use `col.time<string>()` and provide a
|
|
6733
|
+
* `serialize` function that converts the driver `Date` into a string:
|
|
6734
|
+
*
|
|
6735
|
+
* ```ts
|
|
6736
|
+
* col.time<string>({ serialize: (raw) => new Date(raw).toTimeString() })
|
|
6737
|
+
* ```
|
|
6738
|
+
*/
|
|
6739
|
+
time<T extends Date | string = Date>(options: ColTimeOptions & {
|
|
6740
|
+
nullable: false;
|
|
6741
|
+
} & TypedSerialize<T> & TypedPrepare<T>): ColumnDef<T>;
|
|
6742
|
+
time<T extends Date | string = Date>(options?: ColTimeOptions & TypedSerialize<T | null | undefined> & TypedPrepare<T | null | undefined>): ColumnDef<T | null | undefined>;
|
|
6743
|
+
/**
|
|
6744
|
+
* JSON/JSONB column. Defaults to `unknown`.
|
|
6745
|
+
* Pass a concrete type for structured JSON data: `col.json<MyType>()`.
|
|
6746
|
+
*
|
|
6747
|
+
* No `serialize` or `prepare` exposed — serialization is handled internally.
|
|
6748
|
+
*
|
|
6749
|
+
* ```ts
|
|
6750
|
+
* col.json<{ theme: string }>({ nullable: false }) // { theme: string }
|
|
6751
|
+
* col.json() // unknown | null | undefined
|
|
6752
|
+
* ```
|
|
6753
|
+
*/
|
|
6754
|
+
json<T = unknown>(options: ColJsonOptions & {
|
|
6755
|
+
nullable: false;
|
|
6756
|
+
}): ColumnDef<T>;
|
|
6757
|
+
json<T = unknown>(options?: ColJsonOptions): ColumnDef<T | null | undefined>;
|
|
6758
|
+
/**
|
|
6759
|
+
* UUID column. Auto-generates a UUID if no value is provided on insert.
|
|
6760
|
+
* Type: `string` (nullable-aware). Only `serialize` is exposed.
|
|
6761
|
+
*/
|
|
6762
|
+
uuid<O extends ColUuidOptions = ColUuidOptions>(options?: O & TypedSerialize<NullableColumn<string, O>>): ColumnDef<NullableColumn<string, O>>;
|
|
6763
|
+
/**
|
|
6764
|
+
* ULID column. Auto-generates a ULID if no value is provided on insert.
|
|
6765
|
+
* Type: `string` (nullable-aware). Only `serialize` is exposed.
|
|
6766
|
+
*/
|
|
6767
|
+
ulid<O extends ColUlidOptions = ColUlidOptions>(options?: O & TypedSerialize<NullableColumn<string, O>>): ColumnDef<NullableColumn<string, O>>;
|
|
6768
|
+
/**
|
|
6769
|
+
* Binary/blob column.
|
|
6770
|
+
* Type: `Buffer | Uint8Array | string` (nullable-aware).
|
|
6771
|
+
* Supports typed `serialize` and `prepare`.
|
|
6772
|
+
*/
|
|
6773
|
+
binary<T extends Buffer | Uint8Array | string = Buffer | Uint8Array | string, O extends ColBinaryOptions = ColBinaryOptions>(options?: O & TypedSerialize<NullableColumn<T, O>> & TypedPrepare<NullableColumn<T, O>>): ColumnDef<NullableColumn<T, O>>;
|
|
6774
|
+
/**
|
|
6775
|
+
* Enum column constrained to the given values array.
|
|
6776
|
+
* Type: `values[number]` (nullable-aware).
|
|
6777
|
+
*
|
|
6778
|
+
* ```ts
|
|
6779
|
+
* col.enum(["active", "inactive"] as const) // "active" | "inactive" | null | undefined
|
|
6780
|
+
* col.enum(["active", "inactive"] as const, { nullable: false }) // "active" | "inactive"
|
|
6781
|
+
* ```
|
|
6782
|
+
*/
|
|
6783
|
+
enum<const V extends readonly string[], O extends ColEnumOptions = ColEnumOptions>(values: V, options?: O & TypedSerialize<NullableColumn<V[number], O>> & TypedPrepare<NullableColumn<V[number], O>>): ColumnDef<NullableColumn<V[number], O>>;
|
|
6784
|
+
/** Encryption column helpers. */
|
|
6596
6785
|
encryption: {
|
|
6597
|
-
|
|
6598
|
-
|
|
6786
|
+
/**
|
|
6787
|
+
* Symmetric encryption column (AES). Requires `key` in options.
|
|
6788
|
+
* Type: `string` (nullable-aware). No `serialize` or `prepare` exposed.
|
|
6789
|
+
*/
|
|
6790
|
+
symmetric<O extends ColSymmetricOptions = ColSymmetricOptions>(options: O): ColumnDef<NullableColumn<string, O>>;
|
|
6791
|
+
/**
|
|
6792
|
+
* Asymmetric encryption column (RSA). Requires `publicKey` and
|
|
6793
|
+
* `privateKey` in options.
|
|
6794
|
+
* Type: `string` (nullable-aware). No `serialize` or `prepare` exposed.
|
|
6795
|
+
*/
|
|
6796
|
+
asymmetric<O extends ColAsymmetricOptions = ColAsymmetricOptions>(options: O): ColumnDef<NullableColumn<string, O>>;
|
|
6599
6797
|
};
|
|
6600
6798
|
}
|
|
6601
6799
|
type AnyModelClass = abstract new (...args: any[]) => Model;
|
|
6800
|
+
type SelfModelInstance = Model & {
|
|
6801
|
+
readonly [__selfBrand]: true;
|
|
6802
|
+
};
|
|
6803
|
+
type SelfToken = abstract new (...args: any[]) => SelfModelInstance;
|
|
6804
|
+
/**
|
|
6805
|
+
* Model callback type for relation definitions.
|
|
6806
|
+
* Accepts either `() => OtherModel` or `(self) => self` for self-referencing
|
|
6807
|
+
* relations (tree structures, parent/child, etc.).
|
|
6808
|
+
*/
|
|
6809
|
+
type RelModelCallback<M extends AnyModelClass> = (self: SelfToken) => M;
|
|
6810
|
+
/**
|
|
6811
|
+
* Provides autocomplete for column keys of the related model while still accepting any string
|
|
6812
|
+
*/
|
|
6813
|
+
type ForeignKeyOf<M extends AnyModelClass> = ModelKey<InstanceType<M> & Model> | (string & {});
|
|
6814
|
+
/**
|
|
6815
|
+
* Extracts the Model instance type from a through-model callback.
|
|
6816
|
+
*/
|
|
6817
|
+
type InferThroughModelInstance<TM> = TM extends () => infer T ? T extends AnyModelClass ? InstanceType<T> & Model : Model : Model;
|
|
6602
6818
|
interface RelNamespace {
|
|
6603
|
-
|
|
6604
|
-
|
|
6605
|
-
|
|
6606
|
-
|
|
6819
|
+
/**
|
|
6820
|
+
* One-to-one relation where the foreign key lives on the **related** model.
|
|
6821
|
+
* The `foreignKey` parameter autocompletes with column keys of `M`.
|
|
6822
|
+
*
|
|
6823
|
+
* Pass `{ nullable: false }` to type the relation as non-nullable.
|
|
6824
|
+
*
|
|
6825
|
+
* ```ts
|
|
6826
|
+
* rel.hasOne(() => Profile, "userId", { nullable: false }) // Profile
|
|
6827
|
+
* rel.hasOne(() => Profile, "userId") // Profile | null | undefined
|
|
6828
|
+
* ```
|
|
6829
|
+
*
|
|
6830
|
+
* @param model Callback returning the related model class (or `(self) => self` for self-referencing).
|
|
6831
|
+
* @param foreignKey Column on the related model that references the current model's primary key.
|
|
6832
|
+
* @param options `{ nullable: false }` to mark the relation as always present.
|
|
6833
|
+
*/
|
|
6834
|
+
hasOne<M extends AnyModelClass>(model: RelModelCallback<M>, foreignKey: ForeignKeyOf<M> | undefined, options: {
|
|
6835
|
+
nullable: false;
|
|
6836
|
+
}): RelationDef<InstanceType<M>>;
|
|
6837
|
+
hasOne<M extends AnyModelClass>(model: RelModelCallback<M>, foreignKey?: ForeignKeyOf<M>, options?: RelationNullableOption): RelationDef<InstanceType<M> | null | undefined>;
|
|
6838
|
+
/**
|
|
6839
|
+
* One-to-many relation where the foreign key lives on the **related** model.
|
|
6840
|
+
* The `foreignKey` parameter autocompletes with column keys of `M`.
|
|
6841
|
+
*
|
|
6842
|
+
* Pass `{ nullable: false }` to type the relation as non-nullable (always
|
|
6843
|
+
* returns an array, never `null | undefined`).
|
|
6844
|
+
*
|
|
6845
|
+
* ```ts
|
|
6846
|
+
* rel.hasMany(() => Post, "authorId", { nullable: false }) // Post[]
|
|
6847
|
+
* rel.hasMany(() => Post, "authorId") // Post[] | null | undefined
|
|
6848
|
+
* ```
|
|
6849
|
+
*
|
|
6850
|
+
* @param model Callback returning the related model class (or `(self) => self` for self-referencing).
|
|
6851
|
+
* @param foreignKey Column on the related model that references the current model's primary key.
|
|
6852
|
+
* @param options `{ nullable: false }` to mark the relation as always present.
|
|
6853
|
+
*/
|
|
6854
|
+
hasMany<M extends AnyModelClass>(model: RelModelCallback<M>, foreignKey: ForeignKeyOf<M> | undefined, options: {
|
|
6855
|
+
nullable: false;
|
|
6856
|
+
}): RelationDef<InstanceType<M>[]>;
|
|
6857
|
+
hasMany<M extends AnyModelClass>(model: RelModelCallback<M>, foreignKey?: ForeignKeyOf<M>, options?: RelationNullableOption): RelationDef<InstanceType<M>[] | null | undefined>;
|
|
6858
|
+
/**
|
|
6859
|
+
* Inverse one-to-one / many-to-one relation where the foreign key lives
|
|
6860
|
+
* on the **current** model.
|
|
6861
|
+
*
|
|
6862
|
+
* The `foreignKey` parameter autocompletes with column keys of the related
|
|
6863
|
+
* model `M` as a naming hint; any string is still accepted since the
|
|
6864
|
+
* actual column is on the current model.
|
|
6865
|
+
*
|
|
6866
|
+
* Pass `{ nullable: false }` (inside the constraint options) to type the
|
|
6867
|
+
* relation as non-nullable.
|
|
6868
|
+
*
|
|
6869
|
+
* ```ts
|
|
6870
|
+
* rel.belongsTo(() => User, "userId", { nullable: false }) // User
|
|
6871
|
+
* rel.belongsTo(() => User, "userId") // User | null | undefined
|
|
6872
|
+
* rel.belongsTo((self) => self, "parentId") // self-referencing
|
|
6873
|
+
* ```
|
|
6874
|
+
*
|
|
6875
|
+
* @param model Callback returning the related model class (or `(self) => self` for self-referencing).
|
|
6876
|
+
* @param foreignKey Column on the **current** model that references the related model's primary key.
|
|
6877
|
+
* @param options Constraint options (`onDelete`, `onUpdate`, `constraintName`) and `{ nullable: false }`.
|
|
6878
|
+
*/
|
|
6879
|
+
belongsTo<M extends AnyModelClass>(model: RelModelCallback<M>, foreignKey: ForeignKeyOf<M> | undefined, options: RelationConstraintOptions & {
|
|
6880
|
+
nullable: false;
|
|
6881
|
+
}): RelationDef<InstanceType<M>>;
|
|
6882
|
+
belongsTo<M extends AnyModelClass>(model: RelModelCallback<M>, foreignKey?: ForeignKeyOf<M>, options?: RelationConstraintOptions & RelationNullableOption): RelationDef<InstanceType<M> | null | undefined>;
|
|
6883
|
+
/**
|
|
6884
|
+
* Many-to-many relation through a pivot (join) table.
|
|
6885
|
+
*
|
|
6886
|
+
* - `throughModel`: either a string (pivot table name) or a callback
|
|
6887
|
+
* returning a Model class (`() => PivotModel`).
|
|
6888
|
+
* - When a Model callback is provided:
|
|
6889
|
+
* - `leftForeignKey` autocompletes with the **through model**'s column
|
|
6890
|
+
* keys (the FK on the pivot table referencing the current model).
|
|
6891
|
+
* - `rightForeignKey` autocompletes with the **related model** `M`'s
|
|
6892
|
+
* column keys (the FK on the pivot table referencing the related model).
|
|
6893
|
+
* - When a plain string is provided, both keys accept any string.
|
|
6894
|
+
*
|
|
6895
|
+
* Pass `{ nullable: false }` to type the relation as non-nullable.
|
|
6896
|
+
*
|
|
6897
|
+
* ```ts
|
|
6898
|
+
* // Through model as callback — typed FK autocomplete
|
|
6899
|
+
* rel.manyToMany(() => Tag, () => PostTag, {
|
|
6900
|
+
* leftForeignKey: "postId", // autocompletes with PostTag keys
|
|
6901
|
+
* rightForeignKey: "tagId", // autocompletes with Tag keys
|
|
6902
|
+
* })
|
|
6903
|
+
*
|
|
6904
|
+
* // Through model as string — plain string FKs
|
|
6905
|
+
* rel.manyToMany(() => Tag, "post_tags", {
|
|
6906
|
+
* leftForeignKey: "post_id",
|
|
6907
|
+
* rightForeignKey: "tag_id",
|
|
6908
|
+
* })
|
|
6909
|
+
* ```
|
|
6910
|
+
*
|
|
6911
|
+
* @param model Callback returning the related model class.
|
|
6912
|
+
* @param throughModel Pivot model callback or table name string.
|
|
6913
|
+
* @param throughModelKeys Foreign key mapping on the pivot table.
|
|
6914
|
+
* @param options Constraint options and `{ nullable: false }`.
|
|
6915
|
+
*/
|
|
6916
|
+
manyToMany<M extends AnyModelClass, T extends AnyModelConstructor = AnyModelConstructor, TM extends ThroughModel<T> = ThroughModel<T>>(model: RelModelCallback<M>, throughModel: TM, throughModelKeys: TM extends string ? ManyToManyStringOptions : {
|
|
6917
|
+
leftForeignKey?: ModelKey<InferThroughModelInstance<TM>> | (string & {});
|
|
6918
|
+
rightForeignKey?: ForeignKeyOf<M>;
|
|
6919
|
+
}, options: RelationConstraintOptions & {
|
|
6920
|
+
nullable: false;
|
|
6921
|
+
}): RelationDef<InstanceType<M>[]>;
|
|
6922
|
+
manyToMany<M extends AnyModelClass, T extends AnyModelConstructor = AnyModelConstructor, TM extends ThroughModel<T> = ThroughModel<T>>(model: RelModelCallback<M>, throughModel: TM, throughModelKeys?: TM extends string ? ManyToManyStringOptions : {
|
|
6923
|
+
leftForeignKey?: ModelKey<InferThroughModelInstance<TM>> | (string & {});
|
|
6924
|
+
rightForeignKey?: ForeignKeyOf<M>;
|
|
6925
|
+
}, options?: RelationConstraintOptions & RelationNullableOption): RelationDef<InstanceType<M>[] | null | undefined>;
|
|
6607
6926
|
}
|
|
6608
|
-
type IndexDefinition = string[] | {
|
|
6609
|
-
columns:
|
|
6927
|
+
type IndexDefinition<K extends string = string> = K[] | {
|
|
6928
|
+
columns: K[];
|
|
6610
6929
|
name?: string;
|
|
6611
6930
|
};
|
|
6612
|
-
type UniqueDefinition = string[] | {
|
|
6613
|
-
columns:
|
|
6931
|
+
type UniqueDefinition<K extends string = string> = K[] | {
|
|
6932
|
+
columns: K[];
|
|
6614
6933
|
name?: string;
|
|
6615
6934
|
};
|
|
6616
6935
|
type CheckDefinition = string | {
|
|
6617
6936
|
expression: string;
|
|
6618
6937
|
name?: string;
|
|
6619
6938
|
};
|
|
6620
|
-
type HooksDefinition = {
|
|
6939
|
+
type HooksDefinition<T = any> = {
|
|
6621
6940
|
beforeFetch?: (queryBuilder: ModelQueryBuilder<any>) => Promise<void> | void;
|
|
6622
|
-
afterFetch?: (data:
|
|
6623
|
-
beforeInsert?: (data:
|
|
6624
|
-
beforeInsertMany?: (data:
|
|
6941
|
+
afterFetch?: (data: T[]) => Promise<T[]> | T[];
|
|
6942
|
+
beforeInsert?: (data: Partial<T>) => Promise<void> | void;
|
|
6943
|
+
beforeInsertMany?: (data: Partial<T>[]) => Promise<void> | void;
|
|
6625
6944
|
beforeUpdate?: (queryBuilder: ModelQueryBuilder<any>) => Promise<void> | void;
|
|
6626
6945
|
beforeDelete?: (queryBuilder: ModelQueryBuilder<any>) => Promise<void> | void;
|
|
6627
6946
|
};
|
|
6628
|
-
type DefineModelOptions = {
|
|
6947
|
+
type DefineModelOptions<K extends string = string> = {
|
|
6629
6948
|
modelCaseConvention?: CaseConvention;
|
|
6630
6949
|
databaseCaseConvention?: CaseConvention;
|
|
6631
|
-
softDeleteColumn?:
|
|
6950
|
+
softDeleteColumn?: K;
|
|
6632
6951
|
softDeleteValue?: boolean | string;
|
|
6633
6952
|
};
|
|
6634
|
-
type ModelDefinition<C extends Record<string, ColumnDef> = Record<string, ColumnDef>, R extends Record<string, RelationDef> = Record<string, RelationDef>> = {
|
|
6635
|
-
columns: C;
|
|
6636
|
-
relations?: R;
|
|
6637
|
-
indexes?: IndexDefinition[];
|
|
6638
|
-
uniques?: UniqueDefinition[];
|
|
6639
|
-
checks?: CheckDefinition[];
|
|
6640
|
-
hooks?: HooksDefinition;
|
|
6641
|
-
options?: DefineModelOptions;
|
|
6642
|
-
};
|
|
6643
6953
|
type InferColumns<C extends Record<string, ColumnDef>> = {
|
|
6644
6954
|
[K in keyof C]: C[K] extends ColumnDef<infer T> ? T : never;
|
|
6645
6955
|
};
|
|
6646
|
-
|
|
6647
|
-
|
|
6956
|
+
/**
|
|
6957
|
+
* Detects self-referencing relations (branded with `SelfModelInstance`) and
|
|
6958
|
+
* replaces them with the actual column types of the defining model.
|
|
6959
|
+
* Non-self relations pass through unchanged.
|
|
6960
|
+
*/
|
|
6961
|
+
type ResolveSelfRef<T, SelfType> = [T] extends [
|
|
6962
|
+
SelfModelInstance[] | null | undefined
|
|
6963
|
+
] ? SelfType[] | Extract<T, null | undefined> : [T] extends [SelfModelInstance | null | undefined] ? SelfType | Extract<T, null | undefined> : T;
|
|
6964
|
+
type InferRelations<C extends Record<string, ColumnDef>, R extends Record<string, RelationDef>> = {
|
|
6965
|
+
[K in keyof R]: R[K] extends RelationDef<infer T> ? ResolveSelfRef<T, InferColumns<C> & Model> : never;
|
|
6648
6966
|
};
|
|
6649
6967
|
/**
|
|
6650
6968
|
* Infers the instance type of a model defined with `defineModel`.
|
|
6651
6969
|
*/
|
|
6652
|
-
type InferModel<C extends Record<string, ColumnDef>, R extends Record<string, RelationDef>> = InferColumns<C> & InferRelations<R>;
|
|
6970
|
+
type InferModel<C extends Record<string, ColumnDef>, R extends Record<string, RelationDef>> = InferColumns<C> & InferRelations<C, R>;
|
|
6971
|
+
type ModelDefinition<C extends Record<string, ColumnDef> = Record<string, ColumnDef>, R extends Record<string, RelationDef> = Record<string, RelationDef>> = {
|
|
6972
|
+
columns: C;
|
|
6973
|
+
relations?: R;
|
|
6974
|
+
indexes?: IndexDefinition<keyof C & string>[];
|
|
6975
|
+
uniques?: UniqueDefinition<keyof C & string>[];
|
|
6976
|
+
checks?: CheckDefinition[];
|
|
6977
|
+
hooks?: HooksDefinition<InferColumns<C>>;
|
|
6978
|
+
options?: DefineModelOptions<keyof C & string>;
|
|
6979
|
+
};
|
|
6653
6980
|
/**
|
|
6654
6981
|
* Public statics of `typeof Model` without the abstract constructor flag.
|
|
6655
6982
|
*/
|
|
@@ -8171,4 +8498,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
|
|
|
8171
8498
|
$id?: string;
|
|
8172
8499
|
}>;
|
|
8173
8500
|
|
|
8174
|
-
export { type AbstractConstructor, type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnyConstructor, type AnyModelConstructor, type AsymmetricEncryptionOptions, type BaseModelMethodOptions, type BaseModelRelationType, BaseSeeder, type BigIntFields, type BuildSelectType, type BuildSingleSelectType, type CacheAdapter, type CacheKeys, type CheckType, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnDef, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type ComposeBuildSelect, type ComposeSelect, type ConnectionPolicies, type Constructor, type CustomLogger, type DataSourceInput, type DataSourceType, type DateColumnOptions, type DatetimeColumnOptions, type DefinedModel, type ExcludeMethods, type ExtractColumnName, type ExtractSourceColumn, type FetchHooks, type FindReturnType, type GetColumnType, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type IncrementFields, type IndexType, type LazyRelationType, type LoggerConfig, type ManyOptions, type ManyToManyOptions, type ManyToManyStringOptions, Migration, type MigrationConfig, type MigrationConfigBase, type MixinColumns, MixinFactory, Model, type ModelDataProperties, type ModelInstanceType, type ModelKey, ModelQueryBuilder, type ModelQueryResult, type ModelRelation, type ModelSelectTuple, type ModelSelectableInput, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput$1 as MongoDataSourceInput, type MssqlConnectionInstance, type MssqlDataSourceInput, type MssqlPoolInstance, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullableOracleDBDataSourceInput, type NotNullableOracleMssqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type OracleDBDataSourceInput, type OracleDBPoolInstance, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, RawNode, type RawQueryOptions, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationDef, type RelationQueryBuilderType, type ReplicationType, type ReturningColumns, type ReturningKey, Schema, SchemaBuilder, type SeederConfig, type SelectBrand, type SelectableColumn, type SelectedModel, type SlaveAlgorithm, type SlaveContext, type SqlCloneOptions, SqlDataSource, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDriverSpecificOptions, type SqlPoolType, type Sqlite3ConnectionOptions, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, type TimestampFields, Transaction, type TransactionExecutionOptions, type TypedPropertyDecorator, type UlidFields, UlidMixin, type UniqueType, type UseCacheReturnType, type UseConnectionInput, type UuidFields, UuidMixin, WriteOperation, type WriteReturnType, belongsTo, bigIntMixin, check, col, column, createMixin, createModelFactory, defineMigrator, defineModel, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getChecks, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, incrementMixin, index, HysteriaLogger as logger, manyToMany, property, RedisDataSource as redis, rel, timestampMixin, ulidMixin, unique, uuidMixin, view, withPerformance };
|
|
8501
|
+
export { type AbstractConstructor, type AdminJsActionOptions, type AdminJsAssets, type AdminJsBranding, type AdminJsInstance, type AdminJsLocale, type AdminJsOptions, type AdminJsPage, type AdminJsPropertyOptions, type AdminJsResourceOptions, type AdminJsSettings, type AnyConstructor, type AnyModelConstructor, type AsymmetricEncryptionOptions, type BaseModelMethodOptions, type BaseModelRelationType, BaseSeeder, type BigIntFields, type BuildSelectType, type BuildSingleSelectType, type CacheAdapter, type CacheKeys, type CheckType, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnDef, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type ComposeBuildSelect, type ComposeSelect, type ConnectionPolicies, type Constructor, type CustomLogger, type DataSourceInput, type DataSourceType, type DateColumnOptions, type DatetimeColumnOptions, type DefinedModel, type ExcludeMethods, type ExtractColumnName, type ExtractSourceColumn, type FetchHooks, type FindReturnType, type GetColumnType, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type IncrementFields, type IndexType, type LazyRelationType, type LoggerConfig, type ManyOptions, type ManyToManyOptions, type ManyToManyStringOptions, Migration, type MigrationConfig, type MigrationConfigBase, type MixinColumns, MixinFactory, Model, type ModelDataProperties, type ModelInstanceType, type ModelKey, ModelQueryBuilder, type ModelQueryResult, type ModelRelation, type ModelSelectTuple, type ModelSelectableInput, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput$1 as MongoDataSourceInput, type MssqlConnectionInstance, type MssqlDataSourceInput, type MssqlPoolInstance, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullableOracleDBDataSourceInput, type NotNullableOracleMssqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NullableColumn, type NumberModelKey, type OneOptions, type OracleDBDataSourceInput, type OracleDBPoolInstance, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, RawNode, type RawQueryOptions, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelModelCallback, type RelatedInstance, type RelationDef, type RelationNullableOption, type RelationQueryBuilderType, type ReplicationType, type ReturningColumns, type ReturningKey, Schema, SchemaBuilder, type SeederConfig, type SelectBrand, type SelectableColumn, type SelectedModel, type SlaveAlgorithm, type SlaveContext, type SqlCloneOptions, SqlDataSource, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDriverSpecificOptions, type SqlPoolType, type Sqlite3ConnectionOptions, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, type TimestampFields, Transaction, type TransactionExecutionOptions, type TypedPrepare, type TypedPropertyDecorator, type TypedSerialize, type UlidFields, UlidMixin, type UniqueType, type UseCacheReturnType, type UseConnectionInput, type UuidFields, UuidMixin, WriteOperation, type WriteReturnType, belongsTo, bigIntMixin, check, col, column, createMixin, createModelFactory, defineMigrator, defineModel, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getChecks, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, incrementMixin, index, HysteriaLogger as logger, manyToMany, property, RedisDataSource as redis, rel, timestampMixin, ulidMixin, unique, uuidMixin, view, withPerformance };
|