@mikro-orm/sql 7.0.0-dev.299 → 7.0.0-dev.301
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/AbstractSqlConnection.js +2 -1
- package/AbstractSqlDriver.js +135 -39
- package/AbstractSqlPlatform.js +2 -3
- package/PivotCollectionPersister.js +2 -2
- package/SqlEntityManager.d.ts +1 -1
- package/SqlEntityManager.js +5 -5
- package/dialects/mssql/MsSqlNativeQueryBuilder.js +3 -4
- package/dialects/mysql/BaseMySqlPlatform.js +1 -2
- package/dialects/mysql/MySqlSchemaHelper.js +21 -10
- package/dialects/postgresql/BasePostgreSqlPlatform.js +38 -30
- package/dialects/postgresql/PostgreSqlSchemaHelper.js +55 -45
- package/dialects/sqlite/BaseSqliteConnection.js +2 -2
- package/dialects/sqlite/NodeSqliteDialect.js +3 -1
- package/dialects/sqlite/SqlitePlatform.js +4 -1
- package/dialects/sqlite/SqliteSchemaHelper.js +11 -9
- package/package.json +29 -29
- package/plugin/transformer.js +17 -16
- package/query/CriteriaNode.js +28 -10
- package/query/CriteriaNodeFactory.js +5 -1
- package/query/NativeQueryBuilder.js +1 -1
- package/query/ObjectCriteriaNode.js +67 -43
- package/query/QueryBuilder.d.ts +25 -12
- package/query/QueryBuilder.js +105 -49
- package/query/QueryBuilderHelper.js +41 -14
- package/query/ScalarCriteriaNode.js +13 -6
- package/query/raw.js +1 -1
- package/schema/DatabaseSchema.js +21 -15
- package/schema/DatabaseTable.js +81 -51
- package/schema/SchemaComparator.js +54 -30
- package/schema/SchemaHelper.js +28 -8
- package/schema/SqlSchemaGenerator.js +13 -7
- package/tsconfig.build.tsbuildinfo +1 -1
- package/typings.d.ts +1 -1
|
@@ -7,7 +7,8 @@ const COLLECTION_OPERATORS = ['$some', '$none', '$every', '$size'];
|
|
|
7
7
|
*/
|
|
8
8
|
export class ObjectCriteriaNode extends CriteriaNode {
|
|
9
9
|
process(qb, options) {
|
|
10
|
-
const matchPopulateJoins = options?.matchPopulateJoins ||
|
|
10
|
+
const matchPopulateJoins = options?.matchPopulateJoins ||
|
|
11
|
+
(this.prop && [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(this.prop.kind));
|
|
11
12
|
const nestedAlias = qb.getAliasForJoinPath(this.getPath(options), { ...options, matchPopulateJoins });
|
|
12
13
|
const ownerAlias = options?.alias || qb.alias;
|
|
13
14
|
const keys = Utils.getObjectQueryKeys(this.payload);
|
|
@@ -20,13 +21,15 @@ export class ObjectCriteriaNode extends CriteriaNode {
|
|
|
20
21
|
if (![ReferenceKind.MANY_TO_MANY, ReferenceKind.ONE_TO_MANY].includes(this.prop.kind)) {
|
|
21
22
|
// ignore collection operators when used on a non-relational property - this can happen when they get into
|
|
22
23
|
// populateWhere via `infer` on m:n properties with select-in strategy
|
|
23
|
-
if (this.parent?.parent) {
|
|
24
|
+
if (this.parent?.parent) {
|
|
25
|
+
// we validate only usage on top level
|
|
24
26
|
return {};
|
|
25
27
|
}
|
|
26
28
|
throw new Error(`Collection operators can be used only inside a collection property context, but it was used for ${this.getPath()}.`);
|
|
27
29
|
}
|
|
28
30
|
const $and = [];
|
|
29
|
-
const knownKey = [ReferenceKind.SCALAR, ReferenceKind.MANY_TO_ONE, ReferenceKind.EMBEDDED].includes(this.prop.kind) ||
|
|
31
|
+
const knownKey = [ReferenceKind.SCALAR, ReferenceKind.MANY_TO_ONE, ReferenceKind.EMBEDDED].includes(this.prop.kind) ||
|
|
32
|
+
(this.prop.kind === ReferenceKind.ONE_TO_ONE && this.prop.owner);
|
|
30
33
|
const parentMeta = this.metadata.find(this.parent.entityName);
|
|
31
34
|
const primaryKeys = parentMeta.primaryKeys.map(pk => {
|
|
32
35
|
return [QueryType.SELECT, QueryType.COUNT].includes(qb.type) ? `${knownKey ? alias : ownerAlias}.${pk}` : pk;
|
|
@@ -48,7 +51,9 @@ export class ObjectCriteriaNode extends CriteriaNode {
|
|
|
48
51
|
const pks = this.prop.referencedColumnNames;
|
|
49
52
|
const countExpr = raw(`count(${pks.map(() => '??').join(', ')})`, pks.map(pk => `${joinAlias}.${pk}`));
|
|
50
53
|
sub.groupBy(parentMeta.primaryKeys);
|
|
51
|
-
sub.having({
|
|
54
|
+
sub.having({
|
|
55
|
+
$and: Object.keys(sizeCondition).map(op => ({ [countExpr]: { [op]: sizeCondition[op] } })),
|
|
56
|
+
});
|
|
52
57
|
}
|
|
53
58
|
else if (key === '$every') {
|
|
54
59
|
sub.where({ $not: { [this.key]: payload } });
|
|
@@ -111,7 +116,11 @@ export class ObjectCriteriaNode extends CriteriaNode {
|
|
|
111
116
|
// use '??' placeholder to properly quote the identifier
|
|
112
117
|
o[raw('??', [field])] = payload;
|
|
113
118
|
}
|
|
114
|
-
else if (primaryKey ||
|
|
119
|
+
else if (primaryKey ||
|
|
120
|
+
virtual ||
|
|
121
|
+
operator ||
|
|
122
|
+
field.includes('.') ||
|
|
123
|
+
![QueryType.SELECT, QueryType.COUNT].includes(qb.type)) {
|
|
115
124
|
this.inlineCondition(field.replaceAll(ALIAS_REPLACEMENT, alias), o, payload);
|
|
116
125
|
}
|
|
117
126
|
else {
|
|
@@ -121,9 +130,10 @@ export class ObjectCriteriaNode extends CriteriaNode {
|
|
|
121
130
|
}, {});
|
|
122
131
|
}
|
|
123
132
|
isStrict() {
|
|
124
|
-
return this.strict ||
|
|
125
|
-
|
|
126
|
-
|
|
133
|
+
return (this.strict ||
|
|
134
|
+
Utils.getObjectQueryKeys(this.payload).some(key => {
|
|
135
|
+
return this.payload[key].isStrict();
|
|
136
|
+
}));
|
|
127
137
|
}
|
|
128
138
|
unwrap() {
|
|
129
139
|
return Utils.getObjectQueryKeys(this.payload).reduce((o, field) => {
|
|
@@ -148,14 +158,18 @@ export class ObjectCriteriaNode extends CriteriaNode {
|
|
|
148
158
|
}
|
|
149
159
|
shouldInline(payload) {
|
|
150
160
|
const rawField = RawQueryFragment.isKnownFragmentSymbol(this.key);
|
|
151
|
-
const scalar = Utils.isPrimaryKey(payload) ||
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
161
|
+
const scalar = Utils.isPrimaryKey(payload) ||
|
|
162
|
+
payload instanceof RegExp ||
|
|
163
|
+
payload instanceof Date ||
|
|
164
|
+
rawField;
|
|
165
|
+
const operator = Utils.isObject(payload) &&
|
|
166
|
+
Utils.getObjectQueryKeys(payload).every(k => {
|
|
167
|
+
if (k === '$not' && Utils.isPlainObject(payload[k])) {
|
|
168
|
+
// $not wrapping non-operator conditions (entity props) should be inlined
|
|
169
|
+
return Utils.getObjectQueryKeys(payload[k]).every(ik => Utils.isOperator(ik, false));
|
|
170
|
+
}
|
|
171
|
+
return Utils.isOperator(k, false);
|
|
172
|
+
});
|
|
159
173
|
return !!this.prop && this.prop.kind !== ReferenceKind.SCALAR && !scalar && !operator;
|
|
160
174
|
}
|
|
161
175
|
getChildKey(k, prop, childAlias, alias) {
|
|
@@ -167,7 +181,9 @@ export class ObjectCriteriaNode extends CriteriaNode {
|
|
|
167
181
|
inlineArrayChildPayload(obj, payload, k, prop, childAlias, alias) {
|
|
168
182
|
const key = this.getChildKey(k, prop, childAlias);
|
|
169
183
|
const value = payload.map((child) => Utils.getObjectQueryKeys(child).reduce((inner, childKey) => {
|
|
170
|
-
const key =
|
|
184
|
+
const key = RawQueryFragment.isKnownFragmentSymbol(childKey) || this.isPrefixed(childKey) || Utils.isOperator(childKey)
|
|
185
|
+
? childKey
|
|
186
|
+
: this.aliased(childKey, childAlias);
|
|
171
187
|
inner[key] = child[childKey];
|
|
172
188
|
return inner;
|
|
173
189
|
}, {}));
|
|
@@ -179,7 +195,9 @@ export class ObjectCriteriaNode extends CriteriaNode {
|
|
|
179
195
|
if (RawQueryFragment.isKnownFragmentSymbol(k)) {
|
|
180
196
|
o[k] = payload[k];
|
|
181
197
|
}
|
|
182
|
-
else if (k === '$not' &&
|
|
198
|
+
else if (k === '$not' &&
|
|
199
|
+
Utils.isPlainObject(payload[k]) &&
|
|
200
|
+
Utils.getObjectQueryKeys(payload[k]).some(ik => !Utils.isOperator(ik, false))) {
|
|
183
201
|
// $not wraps entity conditions (from auto-join), inline at current level
|
|
184
202
|
this.inlineCondition(k, o, payload[k]);
|
|
185
203
|
}
|
|
@@ -228,34 +246,42 @@ export class ObjectCriteriaNode extends CriteriaNode {
|
|
|
228
246
|
}
|
|
229
247
|
const meta = this.metadata.find(this.entityName);
|
|
230
248
|
const embeddable = this.prop.kind === ReferenceKind.EMBEDDED;
|
|
231
|
-
const knownKey = [ReferenceKind.SCALAR, ReferenceKind.MANY_TO_ONE, ReferenceKind.EMBEDDED].includes(this.prop.kind) ||
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
249
|
+
const knownKey = [ReferenceKind.SCALAR, ReferenceKind.MANY_TO_ONE, ReferenceKind.EMBEDDED].includes(this.prop.kind) ||
|
|
250
|
+
(this.prop.kind === ReferenceKind.ONE_TO_ONE && this.prop.owner);
|
|
251
|
+
const operatorKeys = knownKey &&
|
|
252
|
+
keys.every(key => {
|
|
253
|
+
if (key === '$not') {
|
|
254
|
+
// $not wraps conditions like $and/$or, check if it wraps entity property conditions (needs auto-join)
|
|
255
|
+
// vs simple operator conditions on the FK (doesn't need auto-join)
|
|
256
|
+
const childPayload = this.payload[key].payload;
|
|
257
|
+
if (Utils.isPlainObject(childPayload)) {
|
|
258
|
+
return Utils.getObjectQueryKeys(childPayload).every(k => Utils.isOperator(k, false));
|
|
259
|
+
}
|
|
239
260
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
261
|
+
return Utils.isOperator(key, false);
|
|
262
|
+
});
|
|
263
|
+
const primaryKeys = knownKey &&
|
|
264
|
+
keys.every(key => {
|
|
265
|
+
if (typeof key !== 'string' || !meta.primaryKeys.includes(key)) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
if (!Utils.isPlainObject(this.payload[key].payload) ||
|
|
269
|
+
![ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(meta.properties[key].kind)) {
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
return Utils.getObjectQueryKeys(this.payload[key].payload).every(k => typeof k === 'string' && meta.properties[key].targetMeta.primaryKeys.includes(k));
|
|
273
|
+
});
|
|
252
274
|
return !primaryKeys && !nestedAlias && !operatorKeys && !embeddable;
|
|
253
275
|
}
|
|
254
276
|
autoJoin(qb, alias, options) {
|
|
255
277
|
const nestedAlias = qb.getNextAlias(this.prop?.pivotEntity ?? this.entityName);
|
|
256
278
|
const rawField = RawQueryFragment.isKnownFragmentSymbol(this.key);
|
|
257
|
-
const scalar = Utils.isPrimaryKey(this.payload) ||
|
|
258
|
-
|
|
279
|
+
const scalar = Utils.isPrimaryKey(this.payload) ||
|
|
280
|
+
this.payload instanceof RegExp ||
|
|
281
|
+
this.payload instanceof Date ||
|
|
282
|
+
rawField;
|
|
283
|
+
const operator = Utils.isPlainObject(this.payload) &&
|
|
284
|
+
Utils.getObjectQueryKeys(this.payload).every(k => Utils.isOperator(k, false));
|
|
259
285
|
const field = `${alias}.${this.prop.name}`;
|
|
260
286
|
const method = qb.hasFlag(QueryFlag.INFER_POPULATE) ? 'joinAndSelect' : 'join';
|
|
261
287
|
const path = this.getPath();
|
|
@@ -265,9 +291,7 @@ export class ObjectCriteriaNode extends CriteriaNode {
|
|
|
265
291
|
else {
|
|
266
292
|
const prev = qb._fields?.slice();
|
|
267
293
|
const toOneProperty = [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(this.prop.kind);
|
|
268
|
-
const joinType = toOneProperty && !this.prop.nullable
|
|
269
|
-
? JoinType.innerJoin
|
|
270
|
-
: JoinType.leftJoin;
|
|
294
|
+
const joinType = toOneProperty && !this.prop.nullable ? JoinType.innerJoin : JoinType.leftJoin;
|
|
271
295
|
qb[method](field, nestedAlias, undefined, joinType, path);
|
|
272
296
|
if (!qb.hasFlag(QueryFlag.INFER_POPULATE)) {
|
|
273
297
|
qb._fields = prev;
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -84,7 +84,7 @@ type RawOrderKeys<RawAliases extends string> = {
|
|
|
84
84
|
export type ContextOrderByMap<Entity, RootAlias extends string = never, Context = never, RawAliases extends string = never> = QueryOrderMap<Entity> | ((IsNever<RootAlias> extends true ? {} : RootAliasOrderKeys<RootAlias, Entity>) & ([Context] extends [never] ? {} : ContextOrderKeys<Context>) & (IsNever<RawAliases> extends true ? {} : string extends RawAliases ? {} : RawOrderKeys<RawAliases>));
|
|
85
85
|
type AliasedPath<Alias extends string, Type, P extends string> = P extends `${Alias}.*` ? P : P extends `${Alias}.${infer Rest}` ? `${Alias}.${AutoPath<Type & object, Rest, `${PopulatePath.ALL}`>}` : never;
|
|
86
86
|
type ContextAliasedPath<Context, P extends string> = Context[keyof Context] extends infer Join ? Join extends any ? Join extends [string, infer Alias, infer Type, any] ? AliasedPath<Alias & string, Type, P> : never : never : never;
|
|
87
|
-
type NestedAutoPath<Entity, RootAlias extends string, Context, P extends string> = P extends `${string}:ref` ? never : P extends `${infer Path} as ${string}` ?
|
|
87
|
+
type NestedAutoPath<Entity, RootAlias extends string, Context, P extends string> = P extends `${string}:ref` ? never : P extends `${infer Path} as ${string}` ? AliasedPath<RootAlias, Entity, Path> | ContextAliasedPath<Context, Path> | AutoPath<Entity, Path, `${PopulatePath.ALL}`> extends never ? never : P : AliasedPath<RootAlias, Entity, P> | ContextAliasedPath<Context, P> | AutoPath<Entity, P, `${PopulatePath.ALL}`>;
|
|
88
88
|
type AliasedObjectQuery<Entity extends object, Alias extends string> = {
|
|
89
89
|
[K in EntityKey<Entity> as `${Alias}.${K}`]?: ObjectQuery<Entity>[K];
|
|
90
90
|
};
|
|
@@ -96,7 +96,7 @@ type JoinCondition<JoinedEntity extends object, Alias extends string> = (ObjectQ
|
|
|
96
96
|
type RawJoinCondition = {
|
|
97
97
|
[key: string]: FilterValue<Scalar> | RawQueryFragment;
|
|
98
98
|
};
|
|
99
|
-
type ExtractRawAliasFromField<F> = F extends RawQueryFragment<infer A> ?
|
|
99
|
+
type ExtractRawAliasFromField<F> = F extends RawQueryFragment<infer A> ? A extends string ? A : never : F extends `${string} as ${infer A}` ? A : never;
|
|
100
100
|
type ExtractRawAliasesFromTuple<T extends readonly unknown[]> = T extends readonly [infer Head, ...infer Tail] ? ExtractRawAliasFromField<Head> | ExtractRawAliasesFromTuple<Tail> : never;
|
|
101
101
|
type ExtractRawAliases<Fields> = Fields extends readonly unknown[] ? ExtractRawAliasesFromTuple<Fields> : ExtractRawAliasFromField<Fields>;
|
|
102
102
|
type FlatOperatorMap = {
|
|
@@ -420,11 +420,26 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
420
420
|
* .where({ 'a.name': 'John' });
|
|
421
421
|
* ```
|
|
422
422
|
*/
|
|
423
|
-
joinAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly [
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
423
|
+
joinAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly [
|
|
424
|
+
JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>,
|
|
425
|
+
...JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>[]
|
|
426
|
+
] | undefined = undefined>(field: Field | [Field, RawQueryFragment | QueryBuilder<any>], alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, type?: JoinType, path?: string, fields?: JoinFields, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, ModifyContext<Entity, Context, Field, Alias, true>, RawAliases, ModifyFields<Fields, RootAlias, Context, Field, Alias, JoinFields>, CTEs>;
|
|
427
|
+
leftJoinAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly [
|
|
428
|
+
JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>,
|
|
429
|
+
...JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>[]
|
|
430
|
+
] | undefined = undefined>(field: Field | [Field, RawQueryFragment | QueryBuilder<any>], alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, fields?: JoinFields, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, ModifyContext<Entity, Context, Field, Alias, true>, RawAliases, ModifyFields<Fields, RootAlias, Context, Field, Alias, JoinFields>, CTEs>;
|
|
431
|
+
leftJoinLateralAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly [
|
|
432
|
+
JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>,
|
|
433
|
+
...JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>[]
|
|
434
|
+
] | undefined = undefined>(field: [Field, RawQueryFragment | QueryBuilder<any>], alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, fields?: JoinFields, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, ModifyContext<Entity, Context, Field, Alias, true>, RawAliases, ModifyFields<Fields, RootAlias, Context, Field, Alias, JoinFields>, CTEs>;
|
|
435
|
+
innerJoinAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly [
|
|
436
|
+
JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>,
|
|
437
|
+
...JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>[]
|
|
438
|
+
] | undefined = undefined>(field: Field | [Field, RawQueryFragment | QueryBuilder<any>], alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, fields?: JoinFields, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, ModifyContext<Entity, Context, Field, Alias, true>, RawAliases, ModifyFields<Fields, RootAlias, Context, Field, Alias, JoinFields>, CTEs>;
|
|
439
|
+
innerJoinLateralAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly [
|
|
440
|
+
JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>,
|
|
441
|
+
...JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>[]
|
|
442
|
+
] | undefined = undefined>(field: [Field, RawQueryFragment | QueryBuilder<any>], alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, fields?: JoinFields, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, ModifyContext<Entity, Context, Field, Alias, true>, RawAliases, ModifyFields<Fields, RootAlias, Context, Field, Alias, JoinFields>, CTEs>;
|
|
428
443
|
protected getFieldsForJoinedLoad(prop: EntityProperty<Entity>, alias: string, explicitFields?: readonly string[]): InternalField<Entity>[];
|
|
429
444
|
/**
|
|
430
445
|
* Apply filters to the QB where condition.
|
|
@@ -540,7 +555,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
540
555
|
* ```
|
|
541
556
|
*/
|
|
542
557
|
orderBy<const T extends Record<string, QueryOrderKeysFlat>>(orderBy: T & {
|
|
543
|
-
[K in keyof T]: K extends NestedAutoPath<Entity, RootAlias, Context, K & string> ? T[K] :
|
|
558
|
+
[K in keyof T]: K extends NestedAutoPath<Entity, RootAlias, Context, K & string> ? T[K] : K extends RawAliases ? T[K] : never;
|
|
544
559
|
}): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
545
560
|
/**
|
|
546
561
|
* Adds additional ORDER BY clause without replacing existing order.
|
|
@@ -550,7 +565,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
550
565
|
* Adds additional ORDER BY clause without replacing existing order.
|
|
551
566
|
*/
|
|
552
567
|
andOrderBy<const T extends Record<string, QueryOrderKeysFlat>>(orderBy: T & {
|
|
553
|
-
[K in keyof T]: K extends NestedAutoPath<Entity, RootAlias, Context, K & string> ? T[K] :
|
|
568
|
+
[K in keyof T]: K extends NestedAutoPath<Entity, RootAlias, Context, K & string> ? T[K] : K extends RawAliases ? T[K] : never;
|
|
554
569
|
}): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
555
570
|
private processOrderBy;
|
|
556
571
|
/** Collect custom aliases from select fields (stored as 'resolved as alias' strings by select()). */
|
|
@@ -955,9 +970,7 @@ type PopulatedDTO<T, K extends keyof T> = NonNullable<T[K]> extends Collection<i
|
|
|
955
970
|
type SubFields<F extends string, Rel extends string> = F extends `${Rel}.${infer Sub}` ? Sub : never;
|
|
956
971
|
type RootFields<F extends string, H extends string> = F extends `${string}.${string}` ? F extends `${H}.${string}` ? never : F : F;
|
|
957
972
|
type JoinDTO<T, K extends keyof T, F extends string> = NonNullable<T[K]> extends Collection<infer U> ? SubFields<F, K & string> extends never ? EntityDTOProp<T, Collection<U>> : DirectDTO<U, (SubFields<F, K & string> | PrimaryProperty<U>) & keyof U>[] : SubFields<F, K & string> extends never ? EntityDTOProp<T, T[K]> : DirectDTO<NonNullable<T[K]>, (SubFields<F, K & string> | PrimaryProperty<NonNullable<T[K]>>) & keyof NonNullable<T[K]>> | Extract<T[K], null | undefined>;
|
|
958
|
-
type ExecuteDTO<T, H extends string, F extends string> = [
|
|
959
|
-
H
|
|
960
|
-
] extends [never] ? [F] extends ['*'] ? EntityDTOFlat<T> : DirectDTO<T, F & keyof T> : [F] extends ['*'] ? true extends (H extends `${string}.${string}` ? true : false) ? SerializeDTO<T, H> : Omit<EntityDTOFlat<T>, H & keyof EntityDTOFlat<T>> & {
|
|
973
|
+
type ExecuteDTO<T, H extends string, F extends string> = [H] extends [never] ? [F] extends ['*'] ? EntityDTOFlat<T> : DirectDTO<T, F & keyof T> : [F] extends ['*'] ? true extends (H extends `${string}.${string}` ? true : false) ? SerializeDTO<T, H> : Omit<EntityDTOFlat<T>, H & keyof EntityDTOFlat<T>> & {
|
|
961
974
|
[K in H & keyof T as K & keyof EntityDTOFlat<T>]: PopulatedDTO<T, K> | Extract<T[K], null | undefined>;
|
|
962
975
|
} : true extends (H extends `${string}.${string}` ? true : false) ? EntityDTOFlat<Loaded<T, H, F>> : DirectDTO<T, (RootFields<F, H> | PrimaryProperty<T>) & keyof T> & {
|
|
963
976
|
[K in H & keyof T]: JoinDTO<T, K, F>;
|