metal-orm 1.0.32 → 1.0.34

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.
@@ -30,37 +30,37 @@ export type ColumnToTs<T extends ColumnDef> =
30
30
  T['type'] extends 'BLOB' | 'blob' | 'BINARY' | 'binary' | 'VARBINARY' | 'varbinary' | 'BYTEA' | 'bytea' ? Buffer :
31
31
  T['type'] extends 'DATE' | 'date' | 'DATETIME' | 'datetime' | 'TIMESTAMP' | 'timestamp' | 'TIMESTAMPTZ' | 'timestamptz' ? string :
32
32
  string;
33
-
34
- /**
35
- * Infers a row shape from a table definition
36
- */
37
- export type InferRow<TTable extends TableDef> = {
38
- [K in keyof TTable['columns']]: ColumnToTs<TTable['columns'][K]>;
39
- };
40
-
33
+
34
+ /**
35
+ * Infers a row shape from a table definition
36
+ */
37
+ export type InferRow<TTable extends TableDef> = {
38
+ [K in keyof TTable['columns']]: ColumnToTs<TTable['columns'][K]>;
39
+ };
40
+
41
41
  type RelationResult<T extends RelationDef> =
42
42
  T extends HasManyRelation<infer TTarget> ? InferRow<TTarget>[] :
43
43
  T extends HasOneRelation<infer TTarget> ? InferRow<TTarget> | null :
44
44
  T extends BelongsToRelation<infer TTarget> ? InferRow<TTarget> | null :
45
45
  T extends BelongsToManyRelation<infer TTarget> ? (InferRow<TTarget> & { _pivot?: any })[] :
46
46
  never;
47
-
48
- /**
49
- * Maps relation names to the expected row results
50
- */
51
- export type RelationMap<TTable extends TableDef> = {
52
- [K in keyof TTable['relations']]: RelationResult<TTable['relations'][K]>;
53
- };
54
-
55
- export interface HasManyCollection<TChild> {
56
- load(): Promise<TChild[]>;
57
- getItems(): TChild[];
58
- add(data: Partial<TChild>): TChild;
59
- attach(entity: TChild): void;
60
- remove(entity: TChild): void;
61
- clear(): void;
62
- }
63
-
47
+
48
+ /**
49
+ * Maps relation names to the expected row results
50
+ */
51
+ export type RelationMap<TTable extends TableDef> = {
52
+ [K in keyof TTable['relations']]: RelationResult<TTable['relations'][K]>;
53
+ };
54
+
55
+ export interface HasManyCollection<TChild> {
56
+ load(): Promise<TChild[]>;
57
+ getItems(): TChild[];
58
+ add(data: Partial<TChild>): TChild;
59
+ attach(entity: TChild): void;
60
+ remove(entity: TChild): void;
61
+ clear(): void;
62
+ }
63
+
64
64
  export interface BelongsToReference<TParent> {
65
65
  load(): Promise<TParent | null>;
66
66
  get(): TParent | null;
@@ -72,28 +72,28 @@ export interface HasOneReference<TChild> {
72
72
  get(): TChild | null;
73
73
  set(data: Partial<TChild> | TChild | null): TChild | null;
74
74
  }
75
-
76
- export interface ManyToManyCollection<TTarget> {
77
- load(): Promise<TTarget[]>;
78
- getItems(): TTarget[];
79
- attach(target: TTarget | number | string): void;
80
- detach(target: TTarget | number | string): void;
81
- syncByIds(ids: (number | string)[]): Promise<void>;
82
- }
83
-
84
- export type Entity<
75
+
76
+ export interface ManyToManyCollection<TTarget> {
77
+ load(): Promise<TTarget[]>;
78
+ getItems(): TTarget[];
79
+ attach(target: TTarget | number | string): void;
80
+ detach(target: TTarget | number | string): void;
81
+ syncByIds(ids: (number | string)[]): Promise<void>;
82
+ }
83
+
84
+ export type EntityInstance<
85
85
  TTable extends TableDef,
86
86
  TRow = InferRow<TTable>
87
87
  > = TRow & {
88
88
  [K in keyof RelationMap<TTable>]:
89
89
  TTable['relations'][K] extends HasManyRelation<infer TTarget>
90
- ? HasManyCollection<Entity<TTarget>>
90
+ ? HasManyCollection<EntityInstance<TTarget>>
91
91
  : TTable['relations'][K] extends HasOneRelation<infer TTarget>
92
- ? HasOneReference<Entity<TTarget>>
92
+ ? HasOneReference<EntityInstance<TTarget>>
93
93
  : TTable['relations'][K] extends BelongsToManyRelation<infer TTarget>
94
- ? ManyToManyCollection<Entity<TTarget>>
94
+ ? ManyToManyCollection<EntityInstance<TTarget>>
95
95
  : TTable['relations'][K] extends BelongsToRelation<infer TTarget>
96
- ? BelongsToReference<Entity<TTarget>>
96
+ ? BelongsToReference<EntityInstance<TTarget>>
97
97
  : never;
98
98
  } & {
99
99
  $load<K extends keyof RelationMap<TTable>>(relation: K): Promise<RelationMap<TTable>[K]>;