@prisma-next/mongo-orm 0.11.0-dev.67 → 0.11.0-dev.69
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/dist/index.d.mts +55 -54
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +15 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- package/src/collection.ts +34 -25
- package/src/field-accessor.ts +52 -31
- package/src/mongo-raw.ts +4 -3
- package/src/types.ts +33 -32
package/src/field-accessor.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ContractField,
|
|
3
|
+
ContractValueObject,
|
|
4
|
+
ContractValueObjectsMap,
|
|
5
|
+
} from '@prisma-next/contract/types';
|
|
2
6
|
import type {
|
|
3
7
|
ExtractMongoCodecTypes,
|
|
4
8
|
ExtractMongoFieldOutputTypes,
|
|
5
9
|
InferModelRow,
|
|
6
10
|
MongoContract,
|
|
7
11
|
MongoContractWithTypeMaps,
|
|
12
|
+
MongoModelsMap,
|
|
8
13
|
MongoTypeMaps,
|
|
9
14
|
} from '@prisma-next/mongo-contract';
|
|
10
15
|
import type { MongoValue } from '@prisma-next/mongo-value';
|
|
@@ -32,46 +37,51 @@ export interface FieldOperation {
|
|
|
32
37
|
|
|
33
38
|
type ScalarFieldKeys<
|
|
34
39
|
TContract extends MongoContract,
|
|
35
|
-
ModelName extends string & keyof TContract
|
|
40
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
36
41
|
> = {
|
|
37
|
-
[K in keyof TContract[
|
|
38
|
-
string]: TContract[
|
|
42
|
+
[K in keyof MongoModelsMap<TContract>[ModelName]['fields'] &
|
|
43
|
+
string]: MongoModelsMap<TContract>[ModelName]['fields'][K] extends {
|
|
39
44
|
readonly type: { readonly kind: 'scalar' };
|
|
40
45
|
}
|
|
41
46
|
? K
|
|
42
47
|
: never;
|
|
43
|
-
}[keyof TContract[
|
|
48
|
+
}[keyof MongoModelsMap<TContract>[ModelName]['fields'] & string];
|
|
44
49
|
|
|
45
50
|
type ValueObjectFieldKeys<
|
|
46
51
|
TContract extends MongoContract,
|
|
47
|
-
ModelName extends string & keyof TContract
|
|
52
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
48
53
|
> = {
|
|
49
|
-
[K in keyof TContract[
|
|
50
|
-
string]: TContract[
|
|
54
|
+
[K in keyof MongoModelsMap<TContract>[ModelName]['fields'] &
|
|
55
|
+
string]: MongoModelsMap<TContract>[ModelName]['fields'][K] extends {
|
|
51
56
|
readonly type: { readonly kind: 'valueObject'; readonly name: string };
|
|
52
57
|
}
|
|
53
58
|
? K
|
|
54
59
|
: never;
|
|
55
|
-
}[keyof TContract[
|
|
60
|
+
}[keyof MongoModelsMap<TContract>[ModelName]['fields'] & string];
|
|
56
61
|
|
|
57
62
|
type ResolvedModelRow<
|
|
58
63
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
59
|
-
ModelName extends string & keyof TContract
|
|
64
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
60
65
|
TCodecTypes extends Record<string, { output: unknown }> = ExtractMongoCodecTypes<TContract>,
|
|
61
66
|
> = string extends keyof ExtractMongoFieldOutputTypes<TContract>
|
|
62
|
-
? InferModelRow<TContract, ModelName, TContract[
|
|
67
|
+
? InferModelRow<TContract, ModelName, MongoModelsMap<TContract>[ModelName]['fields'], TCodecTypes>
|
|
63
68
|
: ModelName extends keyof ExtractMongoFieldOutputTypes<TContract>
|
|
64
69
|
? {
|
|
65
70
|
-readonly [K in keyof ExtractMongoFieldOutputTypes<TContract>[ModelName]]: ExtractMongoFieldOutputTypes<TContract>[ModelName][K];
|
|
66
71
|
}
|
|
67
|
-
: InferModelRow<
|
|
72
|
+
: InferModelRow<
|
|
73
|
+
TContract,
|
|
74
|
+
ModelName,
|
|
75
|
+
MongoModelsMap<TContract>[ModelName]['fields'],
|
|
76
|
+
TCodecTypes
|
|
77
|
+
>;
|
|
68
78
|
|
|
69
79
|
type ResolveFieldType<
|
|
70
80
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
71
|
-
ModelName extends string & keyof TContract
|
|
72
|
-
K extends keyof TContract[
|
|
81
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
82
|
+
K extends keyof MongoModelsMap<TContract>[ModelName]['fields'] & string,
|
|
73
83
|
TCodecTypes extends Record<string, { output: unknown }> = ExtractMongoCodecTypes<TContract>,
|
|
74
|
-
> = TContract[
|
|
84
|
+
> = MongoModelsMap<TContract>[ModelName]['fields'][K] extends {
|
|
75
85
|
readonly type: {
|
|
76
86
|
readonly kind: 'scalar';
|
|
77
87
|
readonly codecId: infer CId extends string & keyof TCodecTypes;
|
|
@@ -80,7 +90,7 @@ type ResolveFieldType<
|
|
|
80
90
|
readonly nullable: true;
|
|
81
91
|
}
|
|
82
92
|
? readonly TCodecTypes[CId]['output'][] | null
|
|
83
|
-
: TContract[
|
|
93
|
+
: MongoModelsMap<TContract>[ModelName]['fields'][K] extends {
|
|
84
94
|
readonly type: {
|
|
85
95
|
readonly kind: 'scalar';
|
|
86
96
|
readonly codecId: infer CId extends string & keyof TCodecTypes;
|
|
@@ -88,7 +98,7 @@ type ResolveFieldType<
|
|
|
88
98
|
readonly many: true;
|
|
89
99
|
}
|
|
90
100
|
? readonly TCodecTypes[CId]['output'][]
|
|
91
|
-
: TContract[
|
|
101
|
+
: MongoModelsMap<TContract>[ModelName]['fields'][K] extends {
|
|
92
102
|
readonly type: {
|
|
93
103
|
readonly kind: 'scalar';
|
|
94
104
|
readonly codecId: infer CId extends string & keyof TCodecTypes;
|
|
@@ -96,7 +106,7 @@ type ResolveFieldType<
|
|
|
96
106
|
readonly nullable: true;
|
|
97
107
|
}
|
|
98
108
|
? TCodecTypes[CId]['output'] | null
|
|
99
|
-
: TContract[
|
|
109
|
+
: MongoModelsMap<TContract>[ModelName]['fields'][K] extends {
|
|
100
110
|
readonly type: {
|
|
101
111
|
readonly kind: 'scalar';
|
|
102
112
|
readonly codecId: infer CId extends string & keyof TCodecTypes;
|
|
@@ -121,13 +131,24 @@ export type FieldExpression<T = unknown> = {
|
|
|
121
131
|
pop(end: 1 | -1): FieldOperation;
|
|
122
132
|
} & (T extends number ? NumericOps : unknown);
|
|
123
133
|
|
|
124
|
-
type HasValueObjects =
|
|
134
|
+
type HasValueObjects = MongoContract;
|
|
125
135
|
|
|
126
|
-
type
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
136
|
+
type MergedContractValueObjects<TContract extends HasValueObjects> =
|
|
137
|
+
ContractValueObjectsMap<TContract> &
|
|
138
|
+
(TContract extends { readonly valueObjects?: infer VOs }
|
|
139
|
+
? VOs extends Record<string, ContractValueObject>
|
|
140
|
+
? VOs
|
|
141
|
+
: Record<string, never>
|
|
142
|
+
: Record<string, never>);
|
|
143
|
+
|
|
144
|
+
type VOFields<
|
|
145
|
+
TContract extends HasValueObjects,
|
|
146
|
+
VOName extends string,
|
|
147
|
+
> = VOName extends keyof MergedContractValueObjects<TContract>
|
|
148
|
+
? MergedContractValueObjects<TContract>[VOName] extends {
|
|
149
|
+
readonly fields: infer F extends Record<string, ContractField>;
|
|
150
|
+
}
|
|
151
|
+
? F
|
|
131
152
|
: never
|
|
132
153
|
: never;
|
|
133
154
|
|
|
@@ -161,12 +182,12 @@ type VODotPaths<
|
|
|
161
182
|
|
|
162
183
|
export type DotPath<
|
|
163
184
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
164
|
-
ModelName extends string & keyof TContract
|
|
185
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
165
186
|
> = {
|
|
166
187
|
[K in ValueObjectFieldKeys<
|
|
167
188
|
TContract,
|
|
168
189
|
ModelName
|
|
169
|
-
>]: TContract[
|
|
190
|
+
>]: MongoModelsMap<TContract>[ModelName]['fields'][K] extends {
|
|
170
191
|
readonly type: { readonly kind: 'valueObject'; readonly name: infer N extends string };
|
|
171
192
|
}
|
|
172
193
|
? VODotPaths<TContract, VOFields<TContract, N>, `${K}.`>
|
|
@@ -199,12 +220,12 @@ type ResolveDotPathInFields<
|
|
|
199
220
|
|
|
200
221
|
export type ResolveDotPathType<
|
|
201
222
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
202
|
-
ModelName extends string & keyof TContract
|
|
223
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
203
224
|
Path extends string,
|
|
204
225
|
TCodecTypes extends Record<string, { output: unknown }> = ExtractMongoCodecTypes<TContract>,
|
|
205
226
|
> = Path extends `${infer Head}.${infer Rest}`
|
|
206
|
-
? Head extends keyof TContract[
|
|
207
|
-
? TContract[
|
|
227
|
+
? Head extends keyof MongoModelsMap<TContract>[ModelName]['fields'] & string
|
|
228
|
+
? MongoModelsMap<TContract>[ModelName]['fields'][Head] extends {
|
|
208
229
|
readonly type: { readonly kind: 'valueObject'; readonly name: infer N extends string };
|
|
209
230
|
}
|
|
210
231
|
? ResolveDotPathInFields<TContract, VOFields<TContract, N>, Rest, TCodecTypes>
|
|
@@ -214,7 +235,7 @@ export type ResolveDotPathType<
|
|
|
214
235
|
|
|
215
236
|
export type FieldAccessor<
|
|
216
237
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
217
|
-
ModelName extends string & keyof TContract
|
|
238
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
218
239
|
TCodecTypes extends Record<string, { output: unknown }> = ExtractMongoCodecTypes<TContract>,
|
|
219
240
|
> = {
|
|
220
241
|
readonly [K in ScalarFieldKeys<TContract, ModelName>]: FieldExpression<
|
|
@@ -271,7 +292,7 @@ function createFieldExpression(fieldPath: string): RuntimeFieldExpression {
|
|
|
271
292
|
|
|
272
293
|
export function createFieldAccessor<
|
|
273
294
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
274
|
-
ModelName extends string & keyof TContract
|
|
295
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
275
296
|
TCodecTypes extends Record<string, { output: unknown }> = ExtractMongoCodecTypes<TContract>,
|
|
276
297
|
>(): FieldAccessor<TContract, ModelName, TCodecTypes> {
|
|
277
298
|
return new Proxy((() => {}) as unknown as FieldAccessor<TContract, ModelName, TCodecTypes>, {
|
package/src/mongo-raw.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { contractModels, type PlanMeta } from '@prisma-next/contract/types';
|
|
2
2
|
import type { MongoContract, MongoModelDefinition } from '@prisma-next/mongo-contract';
|
|
3
3
|
import { createRawMongoCollection, type RawMongoCollection } from './raw-collection';
|
|
4
4
|
|
|
@@ -14,10 +14,11 @@ export function mongoRaw<TContract extends MongoContract>(options: {
|
|
|
14
14
|
return {
|
|
15
15
|
collection<K extends keyof TContract['roots'] & string>(rootName: K): RawMongoCollection {
|
|
16
16
|
const modelName = contract.roots[rootName]?.model;
|
|
17
|
-
|
|
17
|
+
const models = contractModels(contract);
|
|
18
|
+
if (!modelName || !Object.hasOwn(models, modelName)) {
|
|
18
19
|
throw new Error(`Unknown model "${modelName ?? ''}" for root "${rootName}"`);
|
|
19
20
|
}
|
|
20
|
-
const model =
|
|
21
|
+
const model = models[modelName] as MongoModelDefinition;
|
|
21
22
|
const collectionName = model.storage.collection ?? modelName;
|
|
22
23
|
|
|
23
24
|
const meta: PlanMeta = {
|
package/src/types.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
InferModelRow,
|
|
7
7
|
MongoContract,
|
|
8
8
|
MongoContractWithTypeMaps,
|
|
9
|
+
MongoModelsMap,
|
|
9
10
|
MongoTypeMaps,
|
|
10
11
|
} from '@prisma-next/mongo-contract';
|
|
11
12
|
|
|
@@ -13,12 +14,12 @@ type Simplify<T> = T extends unknown ? { [K in keyof T]: T[K] } : never;
|
|
|
13
14
|
|
|
14
15
|
type ModelRelations<
|
|
15
16
|
TContract extends MongoContract,
|
|
16
|
-
ModelName extends string & keyof TContract
|
|
17
|
-
> = NonNullable<TContract[
|
|
17
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
18
|
+
> = NonNullable<MongoModelsMap<TContract>[ModelName]['relations']>;
|
|
18
19
|
|
|
19
20
|
export type ReferenceRelationKeys<
|
|
20
21
|
TContract extends MongoContract,
|
|
21
|
-
ModelName extends string & keyof TContract
|
|
22
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
22
23
|
> = {
|
|
23
24
|
[K in keyof ModelRelations<TContract, ModelName>]: ModelRelations<
|
|
24
25
|
TContract,
|
|
@@ -30,7 +31,7 @@ export type ReferenceRelationKeys<
|
|
|
30
31
|
|
|
31
32
|
export type EmbedRelationKeys<
|
|
32
33
|
TContract extends MongoContract,
|
|
33
|
-
ModelName extends string & keyof TContract
|
|
34
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
34
35
|
> = {
|
|
35
36
|
[K in keyof ModelRelations<TContract, ModelName>]: ModelRelations<
|
|
36
37
|
TContract,
|
|
@@ -42,7 +43,7 @@ export type EmbedRelationKeys<
|
|
|
42
43
|
|
|
43
44
|
type ResolvedOutputRow<
|
|
44
45
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
45
|
-
ModelName extends string & keyof TContract
|
|
46
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
46
47
|
> = string extends keyof ExtractMongoFieldOutputTypes<TContract>
|
|
47
48
|
? InferModelRow<TContract, ModelName>
|
|
48
49
|
: ModelName extends keyof ExtractMongoFieldOutputTypes<TContract>
|
|
@@ -53,7 +54,7 @@ type ResolvedOutputRow<
|
|
|
53
54
|
|
|
54
55
|
type ResolvedInputRow<
|
|
55
56
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
56
|
-
ModelName extends string & keyof TContract
|
|
57
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
57
58
|
> = string extends keyof ExtractMongoFieldInputTypes<TContract>
|
|
58
59
|
? InferModelRow<TContract, ModelName>
|
|
59
60
|
: ModelName extends keyof ExtractMongoFieldInputTypes<TContract>
|
|
@@ -63,21 +64,21 @@ type ResolvedInputRow<
|
|
|
63
64
|
: InferModelRow<TContract, ModelName>;
|
|
64
65
|
|
|
65
66
|
type RelationTargetModel<TContract extends MongoContract, R> = R extends {
|
|
66
|
-
readonly to: { readonly model: infer M extends string & keyof TContract
|
|
67
|
+
readonly to: { readonly model: infer M extends string & keyof MongoModelsMap<TContract> };
|
|
67
68
|
}
|
|
68
69
|
? M
|
|
69
70
|
: never;
|
|
70
71
|
|
|
71
72
|
type EmbedRelationRowType<
|
|
72
73
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
73
|
-
ModelName extends string & keyof TContract
|
|
74
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
74
75
|
RelKey extends keyof ModelRelations<TContract, ModelName>,
|
|
75
76
|
> = ModelRelations<TContract, ModelName>[RelKey] extends infer R
|
|
76
77
|
? R extends { readonly cardinality: infer C }
|
|
77
78
|
? ModelRelations<TContract, ModelName>[RelKey] extends ContractReferenceRelation
|
|
78
79
|
? never
|
|
79
80
|
: RelationTargetModel<TContract, R> extends infer To extends string &
|
|
80
|
-
keyof TContract
|
|
81
|
+
keyof MongoModelsMap<TContract>
|
|
81
82
|
? C extends '1:N'
|
|
82
83
|
? ResolvedOutputRow<TContract, To>[]
|
|
83
84
|
: ResolvedOutputRow<TContract, To>
|
|
@@ -87,7 +88,7 @@ type EmbedRelationRowType<
|
|
|
87
88
|
|
|
88
89
|
export type InferFullRow<
|
|
89
90
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
90
|
-
ModelName extends string & keyof TContract
|
|
91
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
91
92
|
> =
|
|
92
93
|
EmbedRelationKeys<TContract, ModelName> extends never
|
|
93
94
|
? ResolvedOutputRow<TContract, ModelName>
|
|
@@ -102,14 +103,14 @@ export type InferFullRow<
|
|
|
102
103
|
|
|
103
104
|
type VariantRow<
|
|
104
105
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
105
|
-
ModelName extends string & keyof TContract
|
|
106
|
-
> = TContract[
|
|
106
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
107
|
+
> = MongoModelsMap<TContract>[ModelName] extends {
|
|
107
108
|
readonly discriminator: { readonly field: infer DiscField extends string };
|
|
108
109
|
readonly variants: infer V;
|
|
109
110
|
}
|
|
110
111
|
? V extends Record<string, { readonly value: string }>
|
|
111
112
|
? {
|
|
112
|
-
[VK in keyof V]: VK extends string & keyof TContract
|
|
113
|
+
[VK in keyof V]: VK extends string & keyof MongoModelsMap<TContract>
|
|
113
114
|
? Simplify<
|
|
114
115
|
Omit<InferFullRow<TContract, ModelName>, DiscField> &
|
|
115
116
|
InferFullRow<TContract, VK> &
|
|
@@ -122,13 +123,13 @@ type VariantRow<
|
|
|
122
123
|
|
|
123
124
|
export type InferRootRow<
|
|
124
125
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
125
|
-
ModelName extends string & keyof TContract
|
|
126
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
126
127
|
> = VariantRow<TContract, ModelName>;
|
|
127
128
|
|
|
128
129
|
export type VariantNames<
|
|
129
130
|
TContract extends MongoContract,
|
|
130
|
-
ModelName extends string & keyof TContract
|
|
131
|
-
> = TContract[
|
|
131
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
132
|
+
> = MongoModelsMap<TContract>[ModelName] extends {
|
|
132
133
|
readonly variants: infer V extends Record<string, unknown>;
|
|
133
134
|
}
|
|
134
135
|
? keyof V & string
|
|
@@ -136,14 +137,14 @@ export type VariantNames<
|
|
|
136
137
|
|
|
137
138
|
export type VariantModelRow<
|
|
138
139
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
139
|
-
ModelName extends string & keyof TContract
|
|
140
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
140
141
|
VariantName extends string,
|
|
141
|
-
> = TContract[
|
|
142
|
+
> = MongoModelsMap<TContract>[ModelName] extends {
|
|
142
143
|
readonly discriminator: { readonly field: infer DiscField extends string };
|
|
143
144
|
readonly variants: infer V;
|
|
144
145
|
}
|
|
145
146
|
? V extends Record<string, { readonly value: string }>
|
|
146
|
-
? VariantName extends keyof V & string & keyof TContract
|
|
147
|
+
? VariantName extends keyof V & string & keyof MongoModelsMap<TContract>
|
|
147
148
|
? Simplify<
|
|
148
149
|
Omit<InferFullRow<TContract, ModelName>, DiscField> &
|
|
149
150
|
InferFullRow<TContract, VariantName> &
|
|
@@ -155,13 +156,13 @@ export type VariantModelRow<
|
|
|
155
156
|
|
|
156
157
|
type IncludeRelationRowType<
|
|
157
158
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
158
|
-
ModelName extends string & keyof TContract
|
|
159
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
159
160
|
RelKey extends keyof ModelRelations<TContract, ModelName>,
|
|
160
161
|
> = ModelRelations<TContract, ModelName>[RelKey] extends ContractReferenceRelation
|
|
161
162
|
? ModelRelations<TContract, ModelName>[RelKey] extends infer R
|
|
162
163
|
? R extends { readonly cardinality: infer C }
|
|
163
164
|
? RelationTargetModel<TContract, R> extends infer To extends string &
|
|
164
|
-
keyof TContract
|
|
165
|
+
keyof MongoModelsMap<TContract>
|
|
165
166
|
? C extends 'N:1' | '1:1'
|
|
166
167
|
? InferFullRow<TContract, To> | null
|
|
167
168
|
: InferFullRow<TContract, To>[]
|
|
@@ -172,7 +173,7 @@ type IncludeRelationRowType<
|
|
|
172
173
|
|
|
173
174
|
export type IncludeResultFields<
|
|
174
175
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
175
|
-
ModelName extends string & keyof TContract
|
|
176
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
176
177
|
TInclude extends MongoIncludeSpec<TContract, ModelName>,
|
|
177
178
|
> = {
|
|
178
179
|
-readonly [K in keyof TInclude & string as TInclude[K] extends true
|
|
@@ -184,10 +185,10 @@ export type IncludeResultFields<
|
|
|
184
185
|
|
|
185
186
|
export type MongoWhereFilter<
|
|
186
187
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
187
|
-
ModelName extends string & keyof TContract
|
|
188
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
188
189
|
TCodecTypes extends Record<string, { output: unknown }> = ExtractMongoCodecTypes<TContract>,
|
|
189
190
|
> = {
|
|
190
|
-
readonly [K in keyof TContract[
|
|
191
|
+
readonly [K in keyof MongoModelsMap<TContract>[ModelName]['fields']]?: MongoModelsMap<TContract>[ModelName]['fields'][K] extends {
|
|
191
192
|
readonly type: {
|
|
192
193
|
readonly kind: 'scalar';
|
|
193
194
|
readonly codecId: infer CId extends string & keyof TCodecTypes;
|
|
@@ -199,7 +200,7 @@ export type MongoWhereFilter<
|
|
|
199
200
|
|
|
200
201
|
export type MongoIncludeSpec<
|
|
201
202
|
TContract extends MongoContract,
|
|
202
|
-
ModelName extends string & keyof TContract
|
|
203
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
203
204
|
> = {
|
|
204
205
|
readonly [K in ReferenceRelationKeys<TContract, ModelName>]?: true;
|
|
205
206
|
};
|
|
@@ -208,18 +209,18 @@ export type NoIncludes = Pick<Record<string, boolean>, never>;
|
|
|
208
209
|
|
|
209
210
|
export type IncludedRow<
|
|
210
211
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
211
|
-
ModelName extends string & keyof TContract
|
|
212
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
212
213
|
TIncludes extends MongoIncludeSpec<TContract, ModelName> = NoIncludes,
|
|
213
214
|
> = InferRootRow<TContract, ModelName> & IncludeResultFields<TContract, ModelName, TIncludes>;
|
|
214
215
|
|
|
215
216
|
export type DefaultModelRow<
|
|
216
217
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
217
|
-
ModelName extends string & keyof TContract
|
|
218
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
218
219
|
> = ResolvedOutputRow<TContract, ModelName>;
|
|
219
220
|
|
|
220
221
|
export type CreateInput<
|
|
221
222
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
222
|
-
ModelName extends string & keyof TContract
|
|
223
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
223
224
|
> = Omit<ResolvedInputRow<TContract, ModelName>, '_id'> &
|
|
224
225
|
Partial<
|
|
225
226
|
Pick<
|
|
@@ -230,8 +231,8 @@ export type CreateInput<
|
|
|
230
231
|
|
|
231
232
|
type DiscriminatorField<
|
|
232
233
|
TContract extends MongoContract,
|
|
233
|
-
ModelName extends string & keyof TContract
|
|
234
|
-
> = TContract[
|
|
234
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
235
|
+
> = MongoModelsMap<TContract>[ModelName] extends {
|
|
235
236
|
readonly discriminator: { readonly field: infer F extends string };
|
|
236
237
|
}
|
|
237
238
|
? F
|
|
@@ -243,7 +244,7 @@ type DiscriminatorField<
|
|
|
243
244
|
// input-side VariantModelRow.
|
|
244
245
|
export type VariantCreateInput<
|
|
245
246
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
246
|
-
ModelName extends string & keyof TContract
|
|
247
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
247
248
|
VariantName extends string,
|
|
248
249
|
> = Omit<
|
|
249
250
|
VariantModelRow<TContract, ModelName, VariantName>,
|
|
@@ -258,7 +259,7 @@ export type VariantCreateInput<
|
|
|
258
259
|
|
|
259
260
|
export type ResolvedCreateInput<
|
|
260
261
|
TContract extends MongoContractWithTypeMaps<MongoContract, MongoTypeMaps>,
|
|
261
|
-
ModelName extends string & keyof TContract
|
|
262
|
+
ModelName extends string & keyof MongoModelsMap<TContract>,
|
|
262
263
|
TVariant extends string,
|
|
263
264
|
> = [TVariant] extends [never]
|
|
264
265
|
? CreateInput<TContract, ModelName>
|