-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
38 lines (35 loc) · 1.41 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type DynaRecord from "../DynaRecord";
import { type EntityAttributes } from "../operations/types";
import type { NullableForeignKey, ForeignKey, Optional } from "../types";
/**
* Returns attributes on the provided model which are EntityAttributes of type ForeignKey
*/
export type ForeignEntityAttribute<T extends DynaRecord> = {
[K in keyof T]: T[K] extends ForeignKey
? K
: T[K] extends NullableForeignKey
? Optional<K>
: never;
}[keyof EntityAttributes<T>];
/**
* Represents the properties of an attribute that are configurable via the {@link Attribute} decorator.
*/
export interface AttributeOptions {
/**
* An optional alias for the attribute as represented in the database table.
*
* This alias is used as the column name in the database table corresponding to
* the entity. If omitted, the ORM defaults to using the attribute's key as defined
* within the entity model. Specifying an alias allows for mapping between the
* entity's attribute names in the code and their respective column names in
* the database, providing flexibility in naming conventions and supporting
* scenarios where column names in the database differ from attribute names in the code.
*/
alias?: string;
}
/**
* Do not allow ForeignKey or NullableForeignKey types when using the Attribute decorator
*/
export type NotForeignKey<T> = T extends ForeignKey | NullableForeignKey
? never
: T;