@mikro-orm/core 7.2.0-dev.2 → 7.2.0-dev.21
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/EntityManager.d.ts +42 -8
- package/EntityManager.js +256 -70
- package/MikroORM.d.ts +4 -0
- package/MikroORM.js +9 -0
- package/cache/CacheAdapter.d.ts +6 -4
- package/cache/FileCacheAdapter.d.ts +1 -1
- package/cache/FileCacheAdapter.js +7 -2
- package/connections/Connection.d.ts +10 -1
- package/connections/Connection.js +9 -0
- package/drivers/DatabaseDriver.d.ts +17 -1
- package/drivers/DatabaseDriver.js +203 -41
- package/drivers/IDatabaseDriver.d.ts +1 -0
- package/entity/Collection.js +4 -2
- package/entity/EntityFactory.js +6 -0
- package/entity/EntityLoader.d.ts +7 -1
- package/entity/EntityLoader.js +46 -11
- package/entity/EntityRepository.d.ts +4 -5
- package/entity/EntityRepository.js +7 -2
- package/entity/defineEntity.d.ts +48 -14
- package/entity/defineEntity.js +32 -1
- package/enums.d.ts +5 -1
- package/enums.js +2 -0
- package/errors.d.ts +36 -0
- package/errors.js +90 -0
- package/events/EventManager.js +6 -3
- package/exceptions.d.ts +5 -0
- package/exceptions.js +5 -0
- package/hydration/ObjectHydrator.d.ts +2 -0
- package/hydration/ObjectHydrator.js +15 -8
- package/index.d.ts +1 -1
- package/metadata/EntitySchema.js +5 -2
- package/metadata/MetadataDiscovery.d.ts +3 -0
- package/metadata/MetadataDiscovery.js +161 -28
- package/metadata/MetadataProvider.js +1 -1
- package/metadata/MetadataStorage.d.ts +4 -3
- package/metadata/MetadataStorage.js +32 -2
- package/metadata/Routine.js +4 -1
- package/metadata/types.d.ts +19 -3
- package/naming-strategy/AbstractNamingStrategy.js +2 -1
- package/naming-strategy/NamingStrategy.d.ts +2 -1
- package/package.json +1 -1
- package/platforms/Platform.d.ts +24 -3
- package/platforms/Platform.js +63 -1
- package/types/BigIntType.d.ts +1 -0
- package/types/BigIntType.js +23 -0
- package/types/DateTimeType.d.ts +1 -0
- package/types/DateTimeType.js +8 -0
- package/types/StringType.d.ts +14 -3
- package/types/StringType.js +34 -4
- package/types/TextType.d.ts +2 -4
- package/types/TextType.js +2 -8
- package/types/Type.d.ts +11 -0
- package/types/Type.js +4 -4
- package/types/index.d.ts +2 -2
- package/typings.d.ts +58 -2
- package/typings.js +24 -1
- package/unit-of-work/ChangeSet.js +10 -7
- package/unit-of-work/ChangeSetPersister.js +32 -20
- package/unit-of-work/UnitOfWork.js +11 -4
- package/utils/AbstractMigrator.d.ts +1 -1
- package/utils/AbstractMigrator.js +3 -2
- package/utils/Configuration.d.ts +15 -1
- package/utils/Configuration.js +13 -2
- package/utils/Cursor.d.ts +2 -0
- package/utils/Cursor.js +44 -39
- package/utils/DataloaderUtils.js +2 -1
- package/utils/EntityComparator.d.ts +2 -0
- package/utils/EntityComparator.js +11 -4
- package/utils/QueryHelper.d.ts +17 -0
- package/utils/QueryHelper.js +100 -4
- package/utils/RawQueryFragment.d.ts +6 -0
- package/utils/RawQueryFragment.js +15 -6
- package/utils/RequestContext.d.ts +2 -2
- package/utils/RequestContext.js +11 -2
- package/utils/TransactionManager.d.ts +6 -0
- package/utils/TransactionManager.js +36 -3
- package/utils/Utils.d.ts +14 -2
- package/utils/Utils.js +36 -6
- package/utils/clone.js +6 -0
- package/utils/env-vars.js +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/rls-utils.d.ts +35 -0
- package/utils/rls-utils.js +97 -0
- package/utils/upsert-utils.d.ts +9 -1
- package/utils/upsert-utils.js +26 -3
package/entity/EntityLoader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { QueryHelper } from '../utils/QueryHelper.js';
|
|
2
|
-
import { Utils } from '../utils/Utils.js';
|
|
2
|
+
import { DANGEROUS_PROPERTY_NAMES, Utils } from '../utils/Utils.js';
|
|
3
3
|
import { ValidationError } from '../errors.js';
|
|
4
4
|
import { LoadStrategy, PopulatePath, ReferenceKind, } from '../enums.js';
|
|
5
5
|
import { Reference } from './Reference.js';
|
|
@@ -124,10 +124,10 @@ export class EntityLoader {
|
|
|
124
124
|
mergeNestedPopulate(populate) {
|
|
125
125
|
const tmp = populate.reduce((ret, item) => {
|
|
126
126
|
/* v8 ignore next */
|
|
127
|
-
if (item.field === PopulatePath.ALL) {
|
|
127
|
+
if (item.field === PopulatePath.ALL || DANGEROUS_PROPERTY_NAMES.includes(item.field)) {
|
|
128
128
|
return ret;
|
|
129
129
|
}
|
|
130
|
-
if (!ret
|
|
130
|
+
if (!Object.hasOwn(ret, item.field)) {
|
|
131
131
|
ret[item.field] = item;
|
|
132
132
|
return ret;
|
|
133
133
|
}
|
|
@@ -229,9 +229,10 @@ export class EntityLoader {
|
|
|
229
229
|
}
|
|
230
230
|
toPopulate.push(entity);
|
|
231
231
|
}
|
|
232
|
-
else if (refValue == null && !helper(entity).__loadedProperties.has(prop.name)) {
|
|
232
|
+
else if (refValue == null && !prop.object && !helper(entity).__loadedProperties.has(prop.name)) {
|
|
233
233
|
// FK columns weren't loaded (partial loading) — need to re-fetch them.
|
|
234
234
|
// If the property IS in __loadedProperties, the FK was loaded and is genuinely null.
|
|
235
|
+
// Object-embedded virtual props are skipped — they are populated via the embeddable instance.
|
|
235
236
|
needsFkLoad.push(entity);
|
|
236
237
|
}
|
|
237
238
|
}
|
|
@@ -333,7 +334,7 @@ export class EntityLoader {
|
|
|
333
334
|
// When targetKey is set, use it for FK lookup instead of the PK
|
|
334
335
|
let fk = prop.targetKey ?? Utils.getPrimaryKeyHash(meta.primaryKeys);
|
|
335
336
|
let schema = options.schema;
|
|
336
|
-
const partial = !Utils.isEmpty(prop.where) || !Utils.isEmpty(options.where);
|
|
337
|
+
const partial = !Utils.isEmpty(prop.where) || !Utils.isEmpty(options.where) || !Utils.isEmpty(options.populateFilter);
|
|
337
338
|
let polymorphicOwnerProp;
|
|
338
339
|
const ownerProp = prop.kind === ReferenceKind.ONE_TO_MANY || (prop.kind === ReferenceKind.MANY_TO_MANY && !prop.owner)
|
|
339
340
|
? meta.properties[prop.mappedBy]
|
|
@@ -393,12 +394,20 @@ export class EntityLoader {
|
|
|
393
394
|
if (!Utils.isEmpty(prop.where) || Raw.hasObjectFragments(prop.where)) {
|
|
394
395
|
where = { $and: [where, prop.where] };
|
|
395
396
|
}
|
|
397
|
+
const childFilter = options.populateFilter ? await this.extractChildPopulateFilter(options, prop) : undefined;
|
|
398
|
+
// conditions on the populated entity itself have no sink in the child query (the joined strategy puts
|
|
399
|
+
// them on the join), only the nested relation ones can be forwarded as its own `populateFilter`
|
|
400
|
+
const [ownFilter, nestedFilter] = this.splitPopulateFilter(childFilter, meta);
|
|
401
|
+
if (ownFilter) {
|
|
402
|
+
where = { $and: [where, ownFilter] };
|
|
403
|
+
}
|
|
396
404
|
const orderBy = QueryHelper.mergeOrderBy(options.orderBy, prop.orderBy);
|
|
397
405
|
const findOptions = {
|
|
398
406
|
filters,
|
|
399
407
|
convertCustomTypes,
|
|
400
408
|
lockMode,
|
|
401
409
|
populateWhere,
|
|
410
|
+
populateFilter: nestedFilter,
|
|
402
411
|
logging,
|
|
403
412
|
orderBy,
|
|
404
413
|
populate: populate.children ?? populate.all ?? [],
|
|
@@ -445,7 +454,10 @@ export class EntityLoader {
|
|
|
445
454
|
}
|
|
446
455
|
}
|
|
447
456
|
}
|
|
448
|
-
|
|
457
|
+
// a missing target row means an orphaned reference, unless the query was narrowed by a populate condition
|
|
458
|
+
if ([ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(prop.kind) &&
|
|
459
|
+
items.length !== children.length &&
|
|
460
|
+
Utils.isEmpty(options.where)) {
|
|
449
461
|
const nullVal = this.#em.config.get('forceUndefined') ? undefined : null;
|
|
450
462
|
const itemsMap = new Set();
|
|
451
463
|
const childrenMap = new Set();
|
|
@@ -571,6 +583,9 @@ export class EntityLoader {
|
|
|
571
583
|
filters,
|
|
572
584
|
ignoreLazyScalarProperties,
|
|
573
585
|
populateWhere,
|
|
586
|
+
populateFilter: options.populateFilter
|
|
587
|
+
? (await this.extractChildPopulateFilter(options, prop))
|
|
588
|
+
: undefined,
|
|
574
589
|
connectionType,
|
|
575
590
|
logging,
|
|
576
591
|
schema,
|
|
@@ -607,7 +622,7 @@ export class EntityLoader {
|
|
|
607
622
|
const fields = this.buildFields(options.fields, prop);
|
|
608
623
|
// oxfmt-ignore
|
|
609
624
|
const exclude = Array.isArray(options.exclude) ? Utils.extractChildElements(options.exclude, prop.name) : options.exclude;
|
|
610
|
-
const populateFilter = options.populateFilter
|
|
625
|
+
const populateFilter = options.populateFilter ? await this.extractChildPopulateFilter(options, prop) : undefined;
|
|
611
626
|
const options2 = { ...options, fields, exclude, populateFilter };
|
|
612
627
|
['limit', 'offset', 'first', 'last', 'before', 'after', 'overfetch'].forEach(prop => delete options2[prop]);
|
|
613
628
|
options2.populate = populate?.children ?? [];
|
|
@@ -620,7 +635,7 @@ export class EntityLoader {
|
|
|
620
635
|
if (!Utils.isEmpty(prop.where)) {
|
|
621
636
|
where = { $and: [where, prop.where] };
|
|
622
637
|
}
|
|
623
|
-
const map = await this.#driver.loadFromPivotTable(prop, ids, where, orderBy,
|
|
638
|
+
const map = await this.#em.withSessionContext(this.#em.getTransactionContext(), ctx => this.#driver.loadFromPivotTable(prop, ids, where, orderBy, ctx, options2, pivotJoin));
|
|
624
639
|
const children = [];
|
|
625
640
|
const isUnionTargetMN = QueryHelper.isUnionTargetPolymorphic(prop);
|
|
626
641
|
for (let i = 0; i < filtered.length; i++) {
|
|
@@ -652,7 +667,8 @@ export class EntityLoader {
|
|
|
652
667
|
}
|
|
653
668
|
async extractChildCondition(options, prop, filters = false) {
|
|
654
669
|
const where = options.where;
|
|
655
|
-
|
|
670
|
+
// shallow copy, the operator normalization below must not mutate the caller's condition
|
|
671
|
+
const subCond = Utils.isPlainObject(where[prop.name]) ? { ...where[prop.name] } : {};
|
|
656
672
|
const meta2 = prop.targetMeta;
|
|
657
673
|
const pk = Utils.getPrimaryKeyHash(meta2.primaryKeys);
|
|
658
674
|
['$and', '$or'].forEach(op => {
|
|
@@ -667,15 +683,16 @@ export class EntityLoader {
|
|
|
667
683
|
}
|
|
668
684
|
return cond;
|
|
669
685
|
});
|
|
670
|
-
|
|
686
|
+
// partial extraction from `$or` is unsound — the parent may have matched via a dropped branch
|
|
687
|
+
if (child.length > 0 && (op === '$and' || child.length === where[op].length)) {
|
|
671
688
|
subCond[op] = child;
|
|
672
689
|
}
|
|
673
690
|
}
|
|
674
691
|
});
|
|
675
692
|
const operators = Object.keys(subCond).filter(key => Utils.isOperator(key, false));
|
|
676
693
|
if (operators.length > 0) {
|
|
694
|
+
subCond[pk] = Utils.isPlainObject(subCond[pk]) ? { ...subCond[pk] } : (subCond[pk] ?? {});
|
|
677
695
|
operators.forEach(op => {
|
|
678
|
-
subCond[pk] ??= {};
|
|
679
696
|
subCond[pk][op] = subCond[op];
|
|
680
697
|
delete subCond[op];
|
|
681
698
|
});
|
|
@@ -685,6 +702,24 @@ export class EntityLoader {
|
|
|
685
702
|
}
|
|
686
703
|
return subCond;
|
|
687
704
|
}
|
|
705
|
+
/** Extracts the part of `options.populateFilter` that applies to the given relation. */
|
|
706
|
+
async extractChildPopulateFilter(options, prop) {
|
|
707
|
+
const filter = await this.extractChildCondition({ ...options, where: options.populateFilter }, prop);
|
|
708
|
+
return Utils.isEmpty(filter) ? undefined : filter;
|
|
709
|
+
}
|
|
710
|
+
/** Splits an extracted populate filter into the conditions on the populated entity and those on its own relations. */
|
|
711
|
+
splitPopulateFilter(filter, meta) {
|
|
712
|
+
if (!filter) {
|
|
713
|
+
return [undefined, undefined];
|
|
714
|
+
}
|
|
715
|
+
const own = {};
|
|
716
|
+
const nested = {};
|
|
717
|
+
for (const key of Object.keys(filter)) {
|
|
718
|
+
const target = meta.relations.some(rel => rel.name === key) ? nested : own;
|
|
719
|
+
target[key] = filter[key];
|
|
720
|
+
}
|
|
721
|
+
return [Utils.isEmpty(own) ? undefined : own, Utils.isEmpty(nested) ? undefined : nested];
|
|
722
|
+
}
|
|
688
723
|
buildFields(fields = [], prop, ref) {
|
|
689
724
|
if (ref) {
|
|
690
725
|
fields = prop.targetMeta.primaryKeys.map(targetPkName => `${prop.name}.${targetPkName}`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PopulatePath } from '../enums.js';
|
|
2
|
-
import type { CreateOptions, EntityManager, MergeOptions } from '../EntityManager.js';
|
|
2
|
+
import type { CreateOptions, EntityManager, MapOptions, MergeOptions } from '../EntityManager.js';
|
|
3
3
|
import type { AssignOptions } from './EntityAssigner.js';
|
|
4
4
|
import type { Dictionary, EntityData, EntityDictionary, EntityKey, EntityName, FilterQuery, Loaded, Primary, AutoPath, RequiredEntityData, Ref, EntityType, EntityDTO, MergeSelected, FromEntityType, IsSubset, MergeLoaded, ArrayElement, IndexFilterQuery, WithUsingOptions } from '../typings.js';
|
|
5
5
|
import type { CountByOptions, CountOptions, DeleteOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetReferenceOptions, NativeInsertUpdateOptions, StreamOptions, UpdateOptions, UpsertManyOptions, UpsertOptions } from '../drivers/IDatabaseDriver.js';
|
|
@@ -115,11 +115,10 @@ export declare class EntityRepository<Entity extends object> {
|
|
|
115
115
|
*/
|
|
116
116
|
nativeDelete(where: FilterQuery<Entity>, options?: DeleteOptions<Entity>): Promise<number>;
|
|
117
117
|
/**
|
|
118
|
-
* Maps raw database result to an entity and merges it to this EntityManager.
|
|
118
|
+
* Maps raw database result to an entity and merges it to this EntityManager by default.
|
|
119
|
+
* Use `disableIdentityMap` to return an isolated entity without affecting the current context.
|
|
119
120
|
*/
|
|
120
|
-
map(result: EntityDictionary<Entity>, options?:
|
|
121
|
-
schema?: string;
|
|
122
|
-
}): Entity;
|
|
121
|
+
map(result: EntityDictionary<Entity>, options?: Omit<MapOptions, 'mapped'>): Entity;
|
|
123
122
|
/**
|
|
124
123
|
* Gets a reference to the entity identified by the given type and alternate key property without actually loading it.
|
|
125
124
|
* The key option specifies which property to use for identity map lookup instead of the primary key.
|
|
@@ -131,7 +131,8 @@ export class EntityRepository {
|
|
|
131
131
|
return this.getEntityManager().nativeDelete(this.entityName, where, options);
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
134
|
-
* Maps raw database result to an entity and merges it to this EntityManager.
|
|
134
|
+
* Maps raw database result to an entity and merges it to this EntityManager by default.
|
|
135
|
+
* Use `disableIdentityMap` to return an isolated entity without affecting the current context.
|
|
135
136
|
*/
|
|
136
137
|
map(result, options) {
|
|
137
138
|
return this.getEntityManager().map(this.entityName, result, options);
|
|
@@ -223,7 +224,11 @@ export class EntityRepository {
|
|
|
223
224
|
}
|
|
224
225
|
const entityName = entities[0].constructor.name;
|
|
225
226
|
const repoType = Utils.className(this.entityName);
|
|
226
|
-
|
|
227
|
+
// compare class identity where possible, as minifiers can mangle two classes to the same name
|
|
228
|
+
const entityMeta = entities[0].__meta;
|
|
229
|
+
const repoMeta = this.getEntityManager().getMetadata?.().find(this.entityName);
|
|
230
|
+
const mismatch = entityMeta && repoMeta ? entityMeta.class !== repoMeta.class : entityName && repoType !== entityName;
|
|
231
|
+
if (mismatch) {
|
|
227
232
|
throw ValidationError.fromWrongRepositoryType(entityName, repoType, method);
|
|
228
233
|
}
|
|
229
234
|
}
|
package/entity/defineEntity.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EntityManager } from '../EntityManager.js';
|
|
2
2
|
import type { ColumnType, PropertyOptions, ReferenceOptions, EnumOptions, EmbeddedOptions, ManyToOneOptions, OneToManyOptions, OneToOneOptions, ManyToManyOptions, IndexColumnOptions } from '../metadata/types.js';
|
|
3
|
-
import type { AnyString, GeneratedColumnCallback, Constructor, CheckCallback, FilterQuery, EntityName, Dictionary, EntityMetadata, PrimaryKeyProp, EntityRepositoryType, Hidden, Opt, Primary, EntityClass, EntitySchemaWithMeta, InferEntity, MaybeReturnType, Ref, LazyRef, IndexCallback, TriggerCallback, FormulaCallback, EntityCtor, IsNever, IWrappedEntity, DefineConfig, Config, MaybePromise, IndexHints, ExtractDefineEntityProperties } from '../typings.js';
|
|
3
|
+
import type { AnyString, GeneratedColumnCallback, Constructor, CheckCallback, FilterQuery, EntityName, Dictionary, EntityMetadata, PrimaryKeyProp, EntityRepositoryType, Hidden, Opt, Primary, EntityClass, EntitySchemaWithMeta, InferEntity, MaybeReturnType, Ref, LazyRef, IndexCallback, TriggerCallback, FormulaCallback, EntityCtor, IsNever, IWrappedEntity, DefineConfig, Config, MaybePromise, IndexHints, OptionalProps, ExtractDefineEntityProperties } from '../typings.js';
|
|
4
4
|
import type { Raw } from '../utils/RawQueryFragment.js';
|
|
5
5
|
import type { ScalarReference } from './Reference.js';
|
|
6
6
|
import type { SerializeOptions } from '../serialization/EntitySerializer.js';
|
|
@@ -22,7 +22,7 @@ type HasKind<Options, K extends string> = Options extends {
|
|
|
22
22
|
kind: infer X extends string;
|
|
23
23
|
} ? X extends K ? true : false : false;
|
|
24
24
|
/** Lightweight chain result type for property builders - reduces type instantiation cost by avoiding full class resolution. */
|
|
25
|
-
export interface PropertyChain<Value, Options> {
|
|
25
|
+
export interface PropertyChain<in out Value, in out Options> {
|
|
26
26
|
'~type'?: {
|
|
27
27
|
value: Value;
|
|
28
28
|
};
|
|
@@ -112,7 +112,7 @@ export interface PropertyChain<Value, Options> {
|
|
|
112
112
|
getter(getter?: boolean): PropertyChain<Value, Options>;
|
|
113
113
|
getterName(getterName: string): PropertyChain<Value, Options>;
|
|
114
114
|
serializedPrimaryKey(serializedPrimaryKey?: boolean): PropertyChain<Value, Options>;
|
|
115
|
-
serializer(serializer: (value: Value, options?: SerializeOptions<any>) => any): PropertyChain<Value, Options>;
|
|
115
|
+
serializer(serializer: (value: SerializerValue<Value, Options>, options?: SerializeOptions<any>) => any): PropertyChain<Value, Options>;
|
|
116
116
|
serializedName(serializedName: string): PropertyChain<Value, Options>;
|
|
117
117
|
groups(...groups: string[]): PropertyChain<Value, Options>;
|
|
118
118
|
customOrder(...customOrder: string[] | number[] | boolean[]): PropertyChain<Value, Options>;
|
|
@@ -148,6 +148,8 @@ export interface PropertyChain<Value, Options> {
|
|
|
148
148
|
orphanRemoval(orphanRemoval?: boolean): HasKind<Options, '1:m' | '1:1'> extends true ? PropertyChain<Value, Options> : never;
|
|
149
149
|
discriminator(discriminator: string): HasKind<Options, 'm:1' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
150
150
|
discriminatorMap(discriminatorMap: Dictionary<string>): HasKind<Options, 'm:1' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
151
|
+
/** Resolve this read-only to-one relation via a subquery on another entity (see {@doclink relationships#to-one-relations-through-another-entity | To-one relations through another entity}). */
|
|
152
|
+
through(through: () => EntityName): HasKind<Options, 'm:1' | '1:1'> extends true ? PropertyChain<Value, Options> : never;
|
|
151
153
|
pivotTable(pivotTable: string): HasKind<Options, 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
152
154
|
pivotEntity(pivotEntity: () => EntityName): HasKind<Options, 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
153
155
|
fixedOrder(fixedOrder?: boolean): HasKind<Options, 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
@@ -180,7 +182,7 @@ export interface PropertyChain<Value, Options> {
|
|
|
180
182
|
foreignKeyName(foreignKeyName: string): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
181
183
|
}
|
|
182
184
|
/** @internal */
|
|
183
|
-
export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys extends BuilderKeys> implements Record<Exclude<UniversalPropertyKeys, ExcludeKeys>, any> {
|
|
185
|
+
export declare class UniversalPropertyOptionsBuilder<in out Value, in out Options, in out IncludeKeys extends BuilderKeys> implements Record<Exclude<UniversalPropertyKeys, ExcludeKeys>, any> {
|
|
184
186
|
'~options': Options;
|
|
185
187
|
'~type'?: {
|
|
186
188
|
value: Value;
|
|
@@ -528,6 +530,8 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
528
530
|
fixedOrderColumn(fixedOrderColumn: string): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
529
531
|
/** Override default name for pivot table (see {@doclink naming-strategy | Naming Strategy}). */
|
|
530
532
|
pivotTable(pivotTable: string): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
533
|
+
/** Resolve this read-only to-one relation via a subquery on another entity (see {@doclink relationships#to-one-relations-through-another-entity | To-one relations through another entity}). */
|
|
534
|
+
through(through: () => EntityName): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
531
535
|
/** Set pivot entity for this relation (see {@doclink collections#custom-pivot-table-entity | Custom pivot table entity}). */
|
|
532
536
|
pivotEntity(pivotEntity: () => EntityName): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
533
537
|
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
|
|
@@ -570,6 +574,13 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
570
574
|
export interface EmptyOptions extends Partial<Record<UniversalPropertyKeys, unknown>> {
|
|
571
575
|
}
|
|
572
576
|
/** @internal */
|
|
577
|
+
export declare class StringPropertyOptionsBuilder<Value, Options> extends UniversalPropertyOptionsBuilder<Value, Options, IncludeKeysForProperty> {
|
|
578
|
+
trim(): StringPropertyOptionsBuilder<Value, Options>;
|
|
579
|
+
lowercase(): StringPropertyOptionsBuilder<Value, Options>;
|
|
580
|
+
uppercase(): StringPropertyOptionsBuilder<Value, Options>;
|
|
581
|
+
private withOptions;
|
|
582
|
+
}
|
|
583
|
+
/** @internal */
|
|
573
584
|
export declare class OneToManyOptionsBuilderOnlyMappedBy<Value extends object> extends UniversalPropertyOptionsBuilder<Value, EmptyOptions & {
|
|
574
585
|
kind: '1:m';
|
|
575
586
|
}, IncludeKeysForOneToManyOptions> {
|
|
@@ -582,7 +593,7 @@ type EntityTarget = {
|
|
|
582
593
|
'~entity': any;
|
|
583
594
|
} | EntityClass;
|
|
584
595
|
declare const propertyBuilders: PropertyBuilders;
|
|
585
|
-
type PropertyBuildersOverrideKeys = 'bigint' | 'array' | 'decimal' | 'json' | 'datetime' | 'time' | 'enum';
|
|
596
|
+
type PropertyBuildersOverrideKeys = 'bigint' | 'array' | 'decimal' | 'json' | 'string' | 'text' | 'datetime' | 'time' | 'enum';
|
|
586
597
|
/** Map of factory functions for creating type-safe property builders (scalars, enums, embeddables, and relations). */
|
|
587
598
|
export type PropertyBuilders = {
|
|
588
599
|
[K in Exclude<keyof typeof types, PropertyBuildersOverrideKeys>]: () => UniversalPropertyOptionsBuilder<InferPropertyValueType<(typeof types)[K]>, EmptyOptions, IncludeKeysForProperty>;
|
|
@@ -591,6 +602,8 @@ export type PropertyBuilders = {
|
|
|
591
602
|
array: <T = string>(toJsValue?: (i: string) => T, toDbValue?: (i: T) => string) => UniversalPropertyOptionsBuilder<InferPropertyValueType<typeof types.array<T>>, EmptyOptions, IncludeKeysForProperty>;
|
|
592
603
|
decimal: <Mode extends 'number' | 'string' = 'string'>(mode?: Mode) => UniversalPropertyOptionsBuilder<InferPropertyValueType<typeof types.decimal<Mode>>, EmptyOptions, IncludeKeysForProperty>;
|
|
593
604
|
json: <T>() => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>;
|
|
605
|
+
string: () => StringPropertyOptionsBuilder<InferPropertyValueType<typeof types.string>, EmptyOptions>;
|
|
606
|
+
text: () => StringPropertyOptionsBuilder<InferPropertyValueType<typeof types.text>, EmptyOptions>;
|
|
594
607
|
formula: <T>(formula: string | FormulaCallback<any>) => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>;
|
|
595
608
|
datetime: (length?: number) => UniversalPropertyOptionsBuilder<InferPropertyValueType<typeof types.datetime>, EmptyOptions, IncludeKeysForProperty>;
|
|
596
609
|
time: (length?: number) => UniversalPropertyOptionsBuilder<InferPropertyValueType<typeof types.time>, EmptyOptions, IncludeKeysForProperty>;
|
|
@@ -618,7 +631,7 @@ type PartialWhere<TProperties, TBase> = string | FilterQuery<{
|
|
|
618
631
|
[K in AllKeys<TProperties, TBase> & string]?: unknown;
|
|
619
632
|
}>;
|
|
620
633
|
/** Metadata descriptor for `defineEntity()`, combining entity options with property definitions. */
|
|
621
|
-
export interface EntityMetadataWithProperties<TName extends string, TTableName extends string, TProperties extends Record<string, any>, TPK extends (keyof TProperties)[] | undefined = undefined, TBase = never, TRepository = never, TForceObject extends boolean = false, TDiscriminatorColumn extends string | undefined = undefined, TDiscriminatorValue extends string | number | undefined = undefined, TBaseDiscriminatorColumn extends string | undefined = undefined> extends Omit<Partial<EntityMetadata<InferEntityFromProperties<TProperties, TPK, TBase, TRepository>>>, 'properties' | 'extends' | 'primaryKeys' | 'hooks' | 'discriminator' | 'discriminatorColumn' | 'discriminatorValue' | 'versionProperty' | 'concurrencyCheckKeys' | 'serializedPrimaryKey' | 'indexes' | 'uniques' | 'triggers' | 'repository' | 'filters' | 'orderBy'> {
|
|
634
|
+
export interface EntityMetadataWithProperties<TName extends string, TTableName extends string, TProperties extends Record<string, any>, TPK extends (keyof TProperties)[] | undefined = undefined, TBase = never, TRepository = never, TForceObject extends boolean = false, TDiscriminatorColumn extends string | undefined = undefined, TDiscriminatorValue extends string | number | undefined = undefined, TBaseDiscriminatorColumn extends string | undefined = undefined, TEmbeddable extends boolean = false> extends Omit<Partial<EntityMetadata<InferEntityFromProperties<TProperties, TPK, TBase, TRepository>>>, 'properties' | 'extends' | 'primaryKeys' | 'hooks' | 'discriminator' | 'discriminatorColumn' | 'discriminatorValue' | 'versionProperty' | 'concurrencyCheckKeys' | 'serializedPrimaryKey' | 'indexes' | 'uniques' | 'triggers' | 'repository' | 'filters' | 'orderBy'> {
|
|
622
635
|
name: TName;
|
|
623
636
|
tableName?: TTableName;
|
|
624
637
|
extends?: {
|
|
@@ -638,8 +651,12 @@ export interface EntityMetadataWithProperties<TName extends string, TTableName e
|
|
|
638
651
|
entity?: EntityName<any> | EntityName<any>[];
|
|
639
652
|
args?: boolean;
|
|
640
653
|
strict?: boolean;
|
|
654
|
+
rls?: boolean | {
|
|
655
|
+
setting?: string;
|
|
656
|
+
};
|
|
641
657
|
}>;
|
|
642
658
|
forceObject?: TForceObject;
|
|
659
|
+
embeddable?: TEmbeddable;
|
|
643
660
|
inheritance?: 'tpt';
|
|
644
661
|
orderBy?: {
|
|
645
662
|
[K in Extract<AllKeys<TProperties, TBase>, string>]?: QueryOrderKeysFlat;
|
|
@@ -690,7 +707,7 @@ export interface EntityMetadataWithProperties<TName extends string, TTableName e
|
|
|
690
707
|
}[];
|
|
691
708
|
}
|
|
692
709
|
/** Defines an entity schema using property builders, with full type inference from the property definitions. */
|
|
693
|
-
export declare function defineEntity<const TName extends string, const TTableName extends string, const TProperties extends Record<string, any>, const TPK extends (keyof TProperties)[] | undefined = undefined, const TBase = never, const TRepository = never, const TForceObject extends boolean = false, const TDiscriminatorColumn extends string | undefined = undefined, const TDiscriminatorValue extends string | number | undefined = undefined, const TBaseDiscriminatorColumn extends string | undefined = undefined>(meta: EntityMetadataWithProperties<TName, TTableName, TProperties, TPK, TBase, TRepository, TForceObject, TDiscriminatorColumn, TDiscriminatorValue, TBaseDiscriminatorColumn>): EntitySchemaWithMeta<TName, TTableName, InferEntityFromProperties<TProperties, TPK, TBase, TRepository, TForceObject, TBaseDiscriminatorColumn, TDiscriminatorValue>, TBase, TProperties, EntityCtor<InferEntityFromProperties<TProperties, TPK, TBase, TRepository, TForceObject, TBaseDiscriminatorColumn, TDiscriminatorValue>>, TDiscriminatorColumn>;
|
|
710
|
+
export declare function defineEntity<const TName extends string, const TTableName extends string, const TProperties extends Record<string, any>, const TPK extends (keyof TProperties)[] | undefined = undefined, const TBase = never, const TRepository = never, const TForceObject extends boolean = false, const TDiscriminatorColumn extends string | undefined = undefined, const TDiscriminatorValue extends string | number | undefined = undefined, const TBaseDiscriminatorColumn extends string | undefined = undefined, const TEmbeddable extends boolean = false>(meta: EntityMetadataWithProperties<TName, TTableName, TProperties, TPK, TBase, TRepository, TForceObject, TDiscriminatorColumn, TDiscriminatorValue, TBaseDiscriminatorColumn, TEmbeddable>): EntitySchemaWithMeta<TName, TTableName, InferEntityFromProperties<TProperties, TPK, TBase, TRepository, TForceObject, TBaseDiscriminatorColumn, TDiscriminatorValue, TEmbeddable>, TBase, TProperties, EntityCtor<InferEntityFromProperties<TProperties, TPK, TBase, TRepository, TForceObject, TBaseDiscriminatorColumn, TDiscriminatorValue, TEmbeddable>>, TDiscriminatorColumn>;
|
|
694
711
|
export declare namespace defineEntity {
|
|
695
712
|
export { propertyBuilders as properties };
|
|
696
713
|
}
|
|
@@ -725,22 +742,24 @@ type InferTypeByString<T extends string> = T extends keyof typeof types ? InferJ
|
|
|
725
742
|
type InferJSType<T> = T extends typeof Type<infer TValue, any> ? NonNullable<TValue> : never;
|
|
726
743
|
type InferColumnType<T extends string> = T extends 'int' | 'int4' | 'integer' | 'bigint' | 'int8' | 'int2' | 'tinyint' | 'smallint' | 'mediumint' ? number : T extends 'double' | 'double precision' | 'real' | 'float8' | 'decimal' | 'numeric' | 'float' | 'float4' ? number : T extends 'datetime' | 'time' | 'time with time zone' | 'timestamp' | 'timestamp with time zone' | 'timetz' | 'timestamptz' | 'date' | 'interval' ? Date : T extends 'ObjectId' | 'objectId' | 'character varying' | 'varchar' | 'char' | 'character' | 'uuid' | 'text' | 'tinytext' | 'mediumtext' | 'longtext' | 'enum' ? string : T extends 'boolean' | 'bool' | 'bit' ? boolean : T extends 'blob' | 'tinyblob' | 'mediumblob' | 'longblob' | 'bytea' ? Buffer : T extends 'point' | 'line' | 'lseg' | 'box' | 'circle' | 'path' | 'polygon' | 'geometry' ? number[] : T extends 'tsvector' | 'tsquery' ? string[] : T extends 'json' | 'jsonb' ? any : any;
|
|
727
744
|
type BaseEntityMethodKeys = 'toObject' | 'toPOJO' | 'serialize' | 'assign' | 'populate' | 'init' | 'toReference';
|
|
745
|
+
interface BaseEntityMethods<in out Entity extends object> extends Pick<IWrappedEntity<Entity>, BaseEntityMethodKeys> {
|
|
746
|
+
}
|
|
728
747
|
/** Infers the entity type from a `defineEntity()` properties map, resolving builders, base classes, and primary keys. */
|
|
729
|
-
export type InferEntityFromProperties<Properties extends Record<string, any>, PK extends (keyof Properties)[] | undefined = undefined, Base = never, Repository = never, ForceObject extends boolean = false, BaseDiscriminatorColumn extends string | undefined = undefined, DiscriminatorValue extends string | number | undefined = undefined> = (IsNever<Base> extends true ? {} : Base extends {
|
|
748
|
+
export type InferEntityFromProperties<Properties extends Record<string, any>, PK extends (keyof Properties)[] | undefined = undefined, Base = never, Repository = never, ForceObject extends boolean = false, BaseDiscriminatorColumn extends string | undefined = undefined, DiscriminatorValue extends string | number | undefined = undefined, Embeddable extends boolean = false> = (IsNever<Base> extends true ? {} : Base extends {
|
|
730
749
|
toObject(...args: any[]): any;
|
|
731
|
-
} ?
|
|
750
|
+
} ? BaseEntityMethods<{
|
|
732
751
|
-readonly [K in keyof Properties]: InferBuilderValue<MaybeReturnType<Properties[K]>>;
|
|
733
752
|
} & {
|
|
734
753
|
[PrimaryKeyProp]?: InferCombinedPrimaryKey<Properties, PK, Base>;
|
|
735
754
|
} & (IsNever<Repository> extends true ? {} : {
|
|
736
755
|
[EntityRepositoryType]?: Repository extends Constructor<infer R> ? R : Repository;
|
|
737
|
-
}) & NarrowDiscriminator<Omit<Base, typeof PrimaryKeyProp>, BaseDiscriminatorColumn, DiscriminatorValue
|
|
756
|
+
}) & NarrowDiscriminator<Omit<Base, typeof PrimaryKeyProp>, BaseDiscriminatorColumn, DiscriminatorValue, Embeddable>> : {}) & {
|
|
738
757
|
-readonly [K in keyof Properties]: InferBuilderValue<MaybeReturnType<Properties[K]>>;
|
|
739
758
|
} & {
|
|
740
759
|
[PrimaryKeyProp]?: InferCombinedPrimaryKey<Properties, PK, Base>;
|
|
741
760
|
} & (IsNever<Repository> extends true ? {} : {
|
|
742
761
|
[EntityRepositoryType]?: Repository extends Constructor<infer R> ? R : Repository;
|
|
743
|
-
}) & (IsNever<Base> extends true ? {} : NarrowDiscriminator<Omit<Base, typeof PrimaryKeyProp>, BaseDiscriminatorColumn, DiscriminatorValue>) & (ForceObject extends true ? {
|
|
762
|
+
}) & (IsNever<Base> extends true ? {} : NarrowDiscriminator<Omit<Base, typeof PrimaryKeyProp>, BaseDiscriminatorColumn, DiscriminatorValue, Embeddable>) & (ForceObject extends true ? {
|
|
744
763
|
[Config]?: DefineConfig<{
|
|
745
764
|
forceObject: true;
|
|
746
765
|
}>;
|
|
@@ -748,13 +767,26 @@ export type InferEntityFromProperties<Properties extends Record<string, any>, PK
|
|
|
748
767
|
[IndexHints]?: [Omit<ExtractBaseProperties<Base>, keyof Properties> & Properties];
|
|
749
768
|
};
|
|
750
769
|
type ExtractBaseProperties<Base> = [ExtractDefineEntityProperties<Base>] extends [infer P extends Record<string, any>] ? [P] extends [never] ? {} : P : {};
|
|
751
|
-
type
|
|
770
|
+
type ExtractOptionalProps<Base> = Base extends {
|
|
771
|
+
[OptionalProps]?: infer K;
|
|
772
|
+
} ? (K extends string ? K : never) : never;
|
|
773
|
+
type NarrowDiscriminator<Base, DiscColumn extends string | undefined, DiscValue, Embeddable extends boolean = false> = DiscColumn extends string ? DiscColumn extends keyof Base ? DiscValue extends string | number ? Embeddable extends true ? Omit<Base, DiscColumn> & {
|
|
774
|
+
[K in DiscColumn]: DiscValue;
|
|
775
|
+
} : Omit<Base, DiscColumn | typeof OptionalProps> & {
|
|
752
776
|
[K in DiscColumn]: DiscValue;
|
|
777
|
+
} & {
|
|
778
|
+
[OptionalProps]?: DiscColumn | ExtractOptionalProps<Base>;
|
|
753
779
|
} : Base : Base : Base;
|
|
754
780
|
type InferCombinedPrimaryKey<Properties extends Record<string, any>, PK, Base> = PK extends undefined ? CombinePrimaryKeys<InferPrimaryKey<Properties>, ExtractBasePrimaryKey<Base>> : PK;
|
|
755
|
-
type ExtractBasePrimaryKey<Base> = Base extends {
|
|
781
|
+
type ExtractBasePrimaryKey<Base> = typeof PrimaryKeyProp extends keyof Base ? Base extends {
|
|
756
782
|
[PrimaryKeyProp]?: infer BasePK;
|
|
757
|
-
} ? BasePK : never
|
|
783
|
+
} ? BasePK : never : [keyof Base] extends [never] ? never : Base extends {
|
|
784
|
+
_id?: any;
|
|
785
|
+
} ? '_id' : Base extends {
|
|
786
|
+
id?: any;
|
|
787
|
+
} ? 'id' : Base extends {
|
|
788
|
+
uuid?: any;
|
|
789
|
+
} ? 'uuid' : never;
|
|
758
790
|
type CombinePrimaryKeys<ChildPK, BasePK> = [ChildPK] extends [never] ? BasePK : [BasePK] extends [never] ? IsUnion<ChildPK> extends true ? ChildPK[] : ChildPK : ChildPK | BasePK;
|
|
759
791
|
/** Extracts the primary key property names from a properties map by finding builders with `primary: true`. */
|
|
760
792
|
export type InferPrimaryKey<Properties extends Record<string, any>> = {
|
|
@@ -781,6 +813,8 @@ type InferBuilderValue<Builder> = Builder extends {
|
|
|
781
813
|
type MaybeArray<Value, Options> = Options extends {
|
|
782
814
|
array: true;
|
|
783
815
|
} ? Value[] : Value;
|
|
816
|
+
/** The runtime value passed to a custom serializer — the property value as stored on the entity (e.g. `Collection`/`Ref` for relations). Skips `MaybeMapToPk`, as its `Primary<Value>` branch is too costly for the type checker. */
|
|
817
|
+
type SerializerValue<Value, Options> = MaybeNullable<MaybeRelationRef<MaybeArray<Value, Options>, Options>, Options>;
|
|
784
818
|
type MaybeMapToPk<Value, Options> = Options extends {
|
|
785
819
|
mapToPk: true;
|
|
786
820
|
} ? Primary<Value> : Value;
|
package/entity/defineEntity.js
CHANGED
|
@@ -403,6 +403,10 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
403
403
|
pivotTable(pivotTable) {
|
|
404
404
|
return this.assignOptions({ pivotTable });
|
|
405
405
|
}
|
|
406
|
+
/** Resolve this read-only to-one relation via a subquery on another entity (see {@doclink relationships#to-one-relations-through-another-entity | To-one relations through another entity}). */
|
|
407
|
+
through(through) {
|
|
408
|
+
return this.assignOptions({ through });
|
|
409
|
+
}
|
|
406
410
|
/** Set pivot entity for this relation (see {@doclink collections#custom-pivot-table-entity | Custom pivot table entity}). */
|
|
407
411
|
pivotEntity(pivotEntity) {
|
|
408
412
|
return this.assignOptions({ pivotEntity });
|
|
@@ -472,10 +476,31 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
472
476
|
}
|
|
473
477
|
}
|
|
474
478
|
/** @internal */
|
|
479
|
+
export class StringPropertyOptionsBuilder extends UniversalPropertyOptionsBuilder {
|
|
480
|
+
trim() {
|
|
481
|
+
return this.withOptions({ trim: true });
|
|
482
|
+
}
|
|
483
|
+
lowercase() {
|
|
484
|
+
return this.withOptions({ case: 'lower' });
|
|
485
|
+
}
|
|
486
|
+
uppercase() {
|
|
487
|
+
return this.withOptions({ case: 'upper' });
|
|
488
|
+
}
|
|
489
|
+
withOptions(options) {
|
|
490
|
+
const type = this['~options'].type;
|
|
491
|
+
const TypeClass = typeof type === 'function' ? type : type.constructor;
|
|
492
|
+
const currentOptions = typeof type === 'function' ? {} : type.options;
|
|
493
|
+
return new StringPropertyOptionsBuilder({
|
|
494
|
+
...this['~options'],
|
|
495
|
+
type: new TypeClass({ ...currentOptions, ...options }),
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
/** @internal */
|
|
475
500
|
export class OneToManyOptionsBuilderOnlyMappedBy extends UniversalPropertyOptionsBuilder {
|
|
476
501
|
/** Point to the owning side property name. */
|
|
477
502
|
mappedBy(mappedBy) {
|
|
478
|
-
return
|
|
503
|
+
return this.assignOptions({ mappedBy });
|
|
479
504
|
}
|
|
480
505
|
}
|
|
481
506
|
function createPropertyBuilders(options) {
|
|
@@ -487,6 +512,12 @@ const propertyBuilders = {
|
|
|
487
512
|
array: (toJsValue = i => i, toDbValue = i => i) => new UniversalPropertyOptionsBuilder({ type: new types.array(toJsValue, toDbValue) }),
|
|
488
513
|
decimal: (mode) => new UniversalPropertyOptionsBuilder({ type: new types.decimal(mode) }),
|
|
489
514
|
json: () => new UniversalPropertyOptionsBuilder({ type: types.json }),
|
|
515
|
+
string: () => new StringPropertyOptionsBuilder({
|
|
516
|
+
type: types.string,
|
|
517
|
+
}),
|
|
518
|
+
text: () => new StringPropertyOptionsBuilder({
|
|
519
|
+
type: types.text,
|
|
520
|
+
}),
|
|
490
521
|
formula: (formula) => new UniversalPropertyOptionsBuilder({ formula }),
|
|
491
522
|
datetime: (length) => new UniversalPropertyOptionsBuilder({ type: types.datetime, length }),
|
|
492
523
|
time: (length) => new UniversalPropertyOptionsBuilder({ type: types.time, length }),
|
package/enums.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EntityKey, ExpandProperty } from './typings.js';
|
|
1
|
+
import type { EntityKey, ExpandProperty, SessionContext } from './typings.js';
|
|
2
2
|
import type { InflightQueryAbortStrategy, Transaction } from './connections/Connection.js';
|
|
3
3
|
import type { LogContext } from './logging/Logger.js';
|
|
4
4
|
/** Controls when the `EntityManager` flushes pending changes to the database. */
|
|
@@ -39,6 +39,8 @@ export declare enum QueryOperator {
|
|
|
39
39
|
$in = "in",
|
|
40
40
|
/** Not included in the given list. */
|
|
41
41
|
$nin = "not in",
|
|
42
|
+
/** Contains all of the given values, supported on collection properties and on mongo arrays. */
|
|
43
|
+
$all = "all",
|
|
42
44
|
/** Greater than. */
|
|
43
45
|
$gt = ">",
|
|
44
46
|
/** Greater than or equal to. */
|
|
@@ -307,6 +309,8 @@ export interface TransactionOptions {
|
|
|
307
309
|
flushMode?: FlushMode | `${FlushMode}`;
|
|
308
310
|
ignoreNestedTransactions?: boolean;
|
|
309
311
|
loggerContext?: LogContext;
|
|
312
|
+
/** @internal database session context applied on `begin()` (set via `em.setSessionContext()`). */
|
|
313
|
+
sessionContext?: SessionContext;
|
|
310
314
|
/**
|
|
311
315
|
* `AbortSignal` cancelling every query within the transaction (including the implicit flush).
|
|
312
316
|
* Cancelling mid-transaction triggers a rollback once the in-flight query settles.
|
package/enums.js
CHANGED
|
@@ -41,6 +41,8 @@ export var QueryOperator;
|
|
|
41
41
|
QueryOperator["$in"] = "in";
|
|
42
42
|
/** Not included in the given list. */
|
|
43
43
|
QueryOperator["$nin"] = "not in";
|
|
44
|
+
/** Contains all of the given values, supported on collection properties and on mongo arrays. */
|
|
45
|
+
QueryOperator["$all"] = "all";
|
|
44
46
|
/** Greater than. */
|
|
45
47
|
QueryOperator["$gt"] = ">";
|
|
46
48
|
/** Greater than or equal to. */
|
package/errors.d.ts
CHANGED
|
@@ -25,6 +25,13 @@ export declare class ValidationError<T extends AnyEntity = AnyEntity> extends Er
|
|
|
25
25
|
static invalidCompositeIdentifier(meta: EntityMetadata): ValidationError;
|
|
26
26
|
static cannotCommit(): ValidationError;
|
|
27
27
|
static cannotUseGlobalContext(): ValidationError;
|
|
28
|
+
static sessionContextNotSupported(): ValidationError;
|
|
29
|
+
static sessionContextRequiresImplicitTransactions(): ValidationError;
|
|
30
|
+
static sessionContextWithDisabledTransactions(): ValidationError;
|
|
31
|
+
static sessionContextInsideTransaction(action?: 'set' | 'clear'): ValidationError;
|
|
32
|
+
static cannotStageNonScalarSessionVariable(filterName: string, argName: string): ValidationError;
|
|
33
|
+
static sessionContextStreamRequiresTransaction(): ValidationError;
|
|
34
|
+
static connectionSessionContextNotSupported(): ValidationError;
|
|
28
35
|
static cannotUseOperatorsInsideEmbeddables(entityName: EntityName, propName: string, payload: unknown): ValidationError;
|
|
29
36
|
static cannotUseGroupOperatorsInsideScalars(entityName: EntityName, propName: string, payload: unknown): ValidationError;
|
|
30
37
|
static invalidEmbeddableQuery(entityName: EntityName, propName: string, embeddableType: string): ValidationError;
|
|
@@ -34,6 +41,7 @@ export declare class ValidationError<T extends AnyEntity = AnyEntity> extends Er
|
|
|
34
41
|
export declare class CursorError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
|
|
35
42
|
static entityNotPopulated(entity: AnyEntity, prop: string): ValidationError;
|
|
36
43
|
static missingValue(entityName: string, prop: string): ValidationError;
|
|
44
|
+
static invalidCursor(entityName: string, cause: Error): CursorError;
|
|
37
45
|
}
|
|
38
46
|
/** Error thrown when an optimistic lock conflict is detected during entity persistence. */
|
|
39
47
|
export declare class OptimisticLockError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
|
|
@@ -60,11 +68,15 @@ export declare class MetadataError<T extends AnyEntity = AnyEntity> extends Vali
|
|
|
60
68
|
static duplicateFieldName(entityName: EntityName, names: [string, string][]): MetadataError;
|
|
61
69
|
static multipleDecorators(entityName: string, propertyName: string): MetadataError;
|
|
62
70
|
static missingMetadata(entity: string): MetadataError;
|
|
71
|
+
static ambiguousEntityName(className: string): MetadataError;
|
|
63
72
|
static invalidPrimaryKey(meta: EntityMetadata, prop: EntityProperty, requiredName: string): MetadataError;
|
|
64
73
|
static invalidManyToManyWithPivotEntity(meta1: EntityMetadata, prop1: EntityProperty, meta2: EntityMetadata, prop2: EntityProperty): MetadataError;
|
|
65
74
|
static targetIsAbstract(meta: EntityMetadata, prop: EntityProperty): MetadataError;
|
|
66
75
|
static nonPersistentCompositeProp(meta: EntityMetadata, prop: EntityProperty): MetadataError;
|
|
67
76
|
static propertyTargetsEntityType(meta: EntityMetadata, prop: EntityProperty, target: EntityMetadata): MetadataError;
|
|
77
|
+
static throughRelationMissingProperty(meta: EntityMetadata, prop: EntityProperty, through: EntityMetadata, side: 'owner' | 'target'): MetadataError;
|
|
78
|
+
static throughRelationCompositeTarget(meta: EntityMetadata, prop: EntityProperty): MetadataError;
|
|
79
|
+
static throughRelationInvalidKind(meta: EntityMetadata, prop: EntityProperty): MetadataError;
|
|
68
80
|
static fromMissingOption(meta: EntityMetadata, prop: EntityProperty, option: string): MetadataError;
|
|
69
81
|
static targetKeyOnManyToMany(meta: EntityMetadata, prop: EntityProperty): MetadataError;
|
|
70
82
|
static targetKeyNotUnique(meta: EntityMetadata, prop: EntityProperty, target?: EntityMetadata): MetadataError;
|
|
@@ -76,6 +88,30 @@ export declare class MetadataError<T extends AnyEntity = AnyEntity> extends Vali
|
|
|
76
88
|
static tptNotSupportedByDriver(meta: EntityMetadata): MetadataError;
|
|
77
89
|
/** Thrown when database triggers are defined on an entity using a driver that does not support them. */
|
|
78
90
|
static triggersNotSupportedByDriver(meta: EntityMetadata): MetadataError;
|
|
91
|
+
/** Thrown when row level security is declared on an entity using a driver that does not support it. */
|
|
92
|
+
static rowLevelSecurityNotSupportedByDriver(meta: EntityMetadata): MetadataError;
|
|
93
|
+
/** Thrown when row level security is declared on a non-root entity of an STI hierarchy. */
|
|
94
|
+
static rowLevelSecurityOnNonRootStiEntity(meta: EntityMetadata): MetadataError;
|
|
95
|
+
/** Thrown when two policies on the same entity are given the same explicit name. */
|
|
96
|
+
static duplicatePolicyName(meta: EntityMetadata, name: string): MetadataError;
|
|
97
|
+
/** Thrown when a filter flagged with `rls` is declared on a driver that does not support row level security. */
|
|
98
|
+
static rlsFilterNotSupportedByDriver(meta: EntityMetadata, filterName: string): MetadataError;
|
|
99
|
+
/** Thrown when a filter flagged with `rls` is declared on a non-root entity of an STI hierarchy. */
|
|
100
|
+
static rlsFilterOnNonRootStiEntity(meta: EntityMetadata, filterName: string): MetadataError;
|
|
101
|
+
/** Thrown when a global (config or EM registered) filter is flagged with `rls`; RLS filters must be entity scoped. */
|
|
102
|
+
static rlsFilterMustBeEntityScoped(filterName: string): MetadataError;
|
|
103
|
+
/** Thrown when an entity-scoped `rls` filter is registered at runtime via `em.addFilter()` instead of in metadata. */
|
|
104
|
+
static rlsFilterCannotBeRegisteredAtRuntime(filterName: string): MetadataError;
|
|
105
|
+
/** Thrown when a filter's custom `setting` is used with more than one argument. */
|
|
106
|
+
static rlsFilterMultiArgSetting(filterName: string, args: string[]): MetadataError;
|
|
107
|
+
/** Thrown when an `rls` filter's condition depends on runtime state and cannot be compiled to a static policy. */
|
|
108
|
+
static rlsFilterDependsOnRuntimeState(filterName: string): MetadataError;
|
|
109
|
+
/** Thrown when an `rls` filter compares against a column whose type has no automatic session-variable cast. */
|
|
110
|
+
static rlsFilterUncastableType(filterName: string, columnType: string): MetadataError;
|
|
111
|
+
/** Thrown when an `rls` filter references an argument outside of a direct comparison, which cannot be compiled. */
|
|
112
|
+
static rlsFilterUnsupportedCond(filterName: string): MetadataError;
|
|
113
|
+
/** Thrown when an `rls` filter compares against a column the schema generator does not manage. */
|
|
114
|
+
static rlsFilterUnmanagedColumn(filterName: string, column: string): MetadataError;
|
|
79
115
|
private static fromMessage;
|
|
80
116
|
}
|
|
81
117
|
/** Error thrown when an entity lookup fails to find the expected result. */
|