@medusajs/types 1.12.0-preview-20240703030457 → 1.12.0-preview-20240703090453
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/dml/index.d.ts +27 -6
- package/dist/dml/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/dml/index.d.ts
CHANGED
@@ -94,19 +94,40 @@ export interface EntityConstructor<Props> extends Function {
|
|
94
94
|
* From a IDmlEntity, infer the foreign keys name and type for
|
95
95
|
* "belongsTo" relation meaning "hasOne" and "ManyToOne"
|
96
96
|
*/
|
97
|
-
export type InferForeignKeys<
|
97
|
+
export type InferForeignKeys<Schema extends DMLSchema> = {
|
98
98
|
[K in keyof Schema as Schema[K] extends {
|
99
99
|
type: infer Type;
|
100
100
|
} ? Type extends RelationshipTypes ? `${K & string}_id` : K : K]: Schema[K] extends {
|
101
101
|
type: infer Type;
|
102
102
|
} ? Type extends RelationshipTypes ? string : Schema[K] : Schema[K];
|
103
|
-
}
|
103
|
+
};
|
104
|
+
/**
|
105
|
+
* Infer fields for a belongsTo relationship
|
106
|
+
*/
|
107
|
+
export type InferBelongsToFields<Relation> = Relation extends () => IDmlEntity<infer R> ? InferSchemaFields<R> : Relation extends () => IDmlEntity<infer R> | null ? InferSchemaFields<R> | null : never;
|
108
|
+
/**
|
109
|
+
* Infer fields for a hasOne relationship
|
110
|
+
*/
|
111
|
+
export type InferHasOneFields<Relation> = InferBelongsToFields<Relation>;
|
112
|
+
/**
|
113
|
+
* Infer fields for hasMany relationship
|
114
|
+
*/
|
115
|
+
export type InferHasManyFields<Relation> = Relation extends () => IDmlEntity<infer R> ? InferSchemaFields<R>[] : never;
|
116
|
+
/**
|
117
|
+
* Infer fields for manyToMany relationship
|
118
|
+
*/
|
119
|
+
export type InferManyToManyFields<Relation> = InferHasManyFields<Relation>;
|
120
|
+
/**
|
121
|
+
* Inferring the types of the schema fields from the DML
|
122
|
+
* entity
|
123
|
+
*/
|
124
|
+
export type InferSchemaFields<Schema extends DMLSchema> = {
|
125
|
+
[K in keyof Schema]: Schema[K] extends RelationshipType<any> ? Schema[K]["type"] extends "belongsTo" ? InferBelongsToFields<Schema[K]["$dataType"]> : Schema[K]["type"] extends "hasOne" ? InferHasOneFields<Schema[K]["$dataType"]> : Schema[K]["type"] extends "hasMany" ? InferHasManyFields<Schema[K]["$dataType"]> : Schema[K]["type"] extends "manyToMany" ? InferManyToManyFields<Schema[K]["$dataType"]> : never : Schema[K]["$dataType"];
|
126
|
+
};
|
104
127
|
/**
|
105
128
|
* Helper to infer the schema type of a DmlEntity
|
106
129
|
*/
|
107
|
-
export type Infer<T> = T extends IDmlEntity<infer Schema> ? EntityConstructor<
|
108
|
-
[K in keyof Schema]: Schema[K]["$dataType"] extends () => infer R ? Infer<R> : Schema[K]["$dataType"] extends (() => infer R) | null ? Infer<R> | null : Schema[K]["$dataType"];
|
109
|
-
} & InferForeignKeys<T>> : never;
|
130
|
+
export type Infer<T> = T extends IDmlEntity<infer Schema> ? EntityConstructor<InferSchemaFields<Schema>> : never;
|
110
131
|
/**
|
111
132
|
* Extracts names of relationships from a schema
|
112
133
|
*/
|
@@ -141,7 +162,7 @@ export type InferIndexableProperties<T> = keyof (T extends IDmlEntity<infer Sche
|
|
141
162
|
[K in keyof Schema as Schema[K] extends {
|
142
163
|
type: infer Type;
|
143
164
|
} ? Type extends RelationshipTypes ? never : K : K]: string;
|
144
|
-
} & InferForeignKeys<
|
165
|
+
} & InferForeignKeys<Schema> : never);
|
145
166
|
export type EntityIndex<TSchema extends DMLSchema = DMLSchema, TWhere = string> = {
|
146
167
|
/**
|
147
168
|
* The name of the index. If not provided,
|
package/dist/dml/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dml/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,WAAW,eAA4B,CAAA;AAEpD;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAC5B,MAAM,EACN,YAAY,CAAC,GAAG,CA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