@mikro-orm/core 7.0.2-dev.9 → 7.0.3-dev.0
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 +4 -0
- package/EntityManager.js +4 -0
- package/MikroORM.d.ts +2 -0
- package/MikroORM.js +2 -0
- package/README.md +128 -294
- package/cache/CacheAdapter.d.ts +2 -0
- package/cache/GeneratedCacheAdapter.d.ts +1 -0
- package/cache/GeneratedCacheAdapter.js +1 -0
- package/cache/MemoryCacheAdapter.d.ts +1 -0
- package/cache/MemoryCacheAdapter.js +1 -0
- package/cache/NullCacheAdapter.d.ts +1 -0
- package/cache/NullCacheAdapter.js +1 -0
- package/connections/Connection.d.ts +13 -0
- package/connections/Connection.js +9 -0
- package/drivers/DatabaseDriver.d.ts +12 -0
- package/drivers/DatabaseDriver.js +12 -0
- package/drivers/IDatabaseDriver.d.ts +44 -0
- package/drivers/IDatabaseDriver.js +1 -0
- package/entity/BaseEntity.d.ts +11 -0
- package/entity/BaseEntity.js +11 -0
- package/entity/Collection.d.ts +26 -0
- package/entity/Collection.js +15 -0
- package/entity/EntityAssigner.d.ts +3 -0
- package/entity/EntityAssigner.js +2 -0
- package/entity/EntityFactory.d.ts +16 -0
- package/entity/EntityFactory.js +19 -0
- package/entity/EntityLoader.d.ts +19 -0
- package/entity/EntityLoader.js +2 -0
- package/entity/EntityRepository.d.ts +2 -0
- package/entity/EntityRepository.js +2 -0
- package/entity/Reference.d.ts +20 -0
- package/entity/Reference.js +16 -0
- package/entity/WrappedEntity.d.ts +20 -0
- package/entity/WrappedEntity.js +21 -1
- package/entity/defineEntity.d.ts +12 -2
- package/entity/defineEntity.js +1 -0
- package/enums.d.ts +132 -0
- package/enums.js +132 -0
- package/errors.d.ts +6 -0
- package/errors.js +6 -0
- package/events/EventManager.d.ts +5 -0
- package/events/EventManager.js +5 -0
- package/events/EventSubscriber.d.ts +4 -0
- package/events/TransactionEventBroadcaster.d.ts +2 -0
- package/events/TransactionEventBroadcaster.js +2 -0
- package/hydration/Hydrator.d.ts +2 -0
- package/hydration/Hydrator.js +2 -0
- package/hydration/ObjectHydrator.d.ts +1 -0
- package/hydration/ObjectHydrator.js +1 -0
- package/logging/DefaultLogger.d.ts +3 -0
- package/logging/DefaultLogger.js +3 -0
- package/logging/Logger.d.ts +5 -0
- package/metadata/EntitySchema.d.ts +22 -0
- package/metadata/EntitySchema.js +22 -2
- package/metadata/MetadataDiscovery.d.ts +4 -0
- package/metadata/MetadataDiscovery.js +18 -11
- package/metadata/MetadataProvider.d.ts +8 -0
- package/metadata/MetadataProvider.js +9 -1
- package/metadata/MetadataStorage.d.ts +14 -0
- package/metadata/MetadataStorage.js +14 -1
- package/naming-strategy/AbstractNamingStrategy.d.ts +1 -0
- package/naming-strategy/AbstractNamingStrategy.js +1 -0
- package/naming-strategy/MongoNamingStrategy.d.ts +1 -0
- package/naming-strategy/MongoNamingStrategy.js +1 -0
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -0
- package/naming-strategy/UnderscoreNamingStrategy.js +1 -0
- package/package.json +1 -1
- package/platforms/ExceptionConverter.d.ts +1 -0
- package/platforms/ExceptionConverter.js +1 -0
- package/platforms/Platform.d.ts +65 -0
- package/platforms/Platform.js +65 -0
- package/serialization/EntitySerializer.d.ts +2 -0
- package/serialization/EntitySerializer.js +2 -0
- package/serialization/EntityTransformer.d.ts +2 -0
- package/serialization/EntityTransformer.js +2 -0
- package/serialization/SerializationContext.d.ts +5 -0
- package/serialization/SerializationContext.js +5 -0
- package/types/ArrayType.d.ts +1 -0
- package/types/ArrayType.js +1 -0
- package/types/BlobType.d.ts +1 -0
- package/types/BlobType.js +1 -0
- package/types/BooleanType.d.ts +1 -0
- package/types/BooleanType.js +1 -0
- package/types/CharacterType.d.ts +1 -0
- package/types/CharacterType.js +1 -0
- package/types/DateTimeType.d.ts +1 -0
- package/types/DateTimeType.js +1 -0
- package/types/DateType.d.ts +1 -0
- package/types/DateType.js +1 -0
- package/types/EnumArrayType.d.ts +1 -0
- package/types/EnumArrayType.js +1 -0
- package/types/EnumType.d.ts +1 -0
- package/types/EnumType.js +1 -0
- package/types/FloatType.d.ts +1 -0
- package/types/FloatType.js +1 -0
- package/types/IntegerType.d.ts +1 -0
- package/types/IntegerType.js +1 -0
- package/types/IntervalType.d.ts +1 -0
- package/types/IntervalType.js +1 -0
- package/types/JsonType.d.ts +1 -0
- package/types/JsonType.js +1 -0
- package/types/MediumIntType.d.ts +1 -0
- package/types/MediumIntType.js +1 -0
- package/types/SmallIntType.d.ts +1 -0
- package/types/SmallIntType.js +1 -0
- package/types/StringType.d.ts +1 -0
- package/types/StringType.js +1 -0
- package/types/TextType.d.ts +1 -0
- package/types/TextType.js +1 -0
- package/types/TimeType.d.ts +1 -0
- package/types/TimeType.js +1 -0
- package/types/TinyIntType.d.ts +1 -0
- package/types/TinyIntType.js +1 -0
- package/types/Type.d.ts +11 -0
- package/types/Type.js +11 -0
- package/types/Uint8ArrayType.d.ts +1 -0
- package/types/Uint8ArrayType.js +1 -0
- package/types/UnknownType.d.ts +1 -0
- package/types/UnknownType.js +1 -0
- package/types/UuidType.d.ts +1 -0
- package/types/UuidType.js +1 -0
- package/types/index.d.ts +2 -0
- package/types/index.js +13 -1
- package/typings.d.ts +177 -0
- package/typings.js +11 -0
- package/unit-of-work/ChangeSet.d.ts +4 -0
- package/unit-of-work/ChangeSet.js +4 -0
- package/unit-of-work/ChangeSetComputer.d.ts +2 -0
- package/unit-of-work/ChangeSetComputer.js +15 -2
- package/unit-of-work/ChangeSetPersister.d.ts +4 -0
- package/unit-of-work/ChangeSetPersister.js +4 -0
- package/unit-of-work/IdentityMap.d.ts +7 -0
- package/unit-of-work/IdentityMap.js +7 -0
- package/unit-of-work/UnitOfWork.d.ts +15 -0
- package/unit-of-work/UnitOfWork.js +15 -0
- package/utils/Configuration.d.ts +8 -0
- package/utils/Configuration.js +8 -0
- package/utils/EntityComparator.d.ts +2 -0
- package/utils/EntityComparator.js +2 -0
- package/utils/NullHighlighter.d.ts +1 -0
- package/utils/NullHighlighter.js +1 -0
- package/utils/RawQueryFragment.d.ts +10 -0
- package/utils/RawQueryFragment.js +9 -0
- package/utils/RequestContext.d.ts +1 -0
- package/utils/TransactionContext.d.ts +1 -0
- package/utils/TransactionContext.js +1 -0
- package/utils/Utils.d.ts +6 -0
- package/utils/Utils.js +7 -1
package/entity/WrappedEntity.js
CHANGED
|
@@ -6,6 +6,7 @@ import { ValidationError } from '../errors.js';
|
|
|
6
6
|
import { helper } from './wrap.js';
|
|
7
7
|
import { EntitySerializer } from '../serialization/EntitySerializer.js';
|
|
8
8
|
import { expandDotPaths } from './utils.js';
|
|
9
|
+
/** @internal Wrapper attached to every managed entity, holding ORM state such as initialization flags, identity map references, and change tracking snapshots. */
|
|
9
10
|
export class WrappedEntity {
|
|
10
11
|
constructor(entity, hydrator, pkGetter, pkSerializer, pkGetterConverted) {
|
|
11
12
|
this.entity = entity;
|
|
@@ -19,15 +20,19 @@ export class WrappedEntity {
|
|
|
19
20
|
this.__data = {};
|
|
20
21
|
this.__processing = false;
|
|
21
22
|
}
|
|
23
|
+
/** Returns whether the entity has been fully loaded from the database. */
|
|
22
24
|
isInitialized() {
|
|
23
25
|
return this.__initialized;
|
|
24
26
|
}
|
|
27
|
+
/** Returns whether the entity is managed by an EntityManager (tracked in the identity map). */
|
|
25
28
|
isManaged() {
|
|
26
29
|
return !!this.__managed;
|
|
27
30
|
}
|
|
31
|
+
/** Marks the entity as populated or not for serialization purposes. */
|
|
28
32
|
populated(populated = true) {
|
|
29
33
|
this.__populated = populated;
|
|
30
34
|
}
|
|
35
|
+
/** Sets the serialization context with populate hints, field selections, and exclusions. */
|
|
31
36
|
setSerializationContext(options) {
|
|
32
37
|
const exclude = options.exclude ?? [];
|
|
33
38
|
const context = this.__serializationContext;
|
|
@@ -44,29 +49,36 @@ export class WrappedEntity {
|
|
|
44
49
|
context.fields = new Set(['*']);
|
|
45
50
|
}
|
|
46
51
|
}
|
|
52
|
+
/** Returns a Reference wrapper for this entity, creating one if it does not already exist. */
|
|
47
53
|
toReference() {
|
|
48
54
|
this.__reference ??= new Reference(this.entity);
|
|
49
55
|
return this.__reference;
|
|
50
56
|
}
|
|
57
|
+
/** Converts the entity to a plain object representation, optionally excluding specified fields. */
|
|
51
58
|
toObject(ignoreFields) {
|
|
52
59
|
return EntityTransformer.toObject(this.entity, ignoreFields);
|
|
53
60
|
}
|
|
61
|
+
/** Serializes the entity with control over which relations and fields to include or exclude. */
|
|
54
62
|
serialize(options) {
|
|
55
63
|
return EntitySerializer.serialize(this.entity, options);
|
|
56
64
|
}
|
|
65
|
+
/** Converts the entity to a plain object, including all properties regardless of serialization rules. */
|
|
57
66
|
toPOJO() {
|
|
58
67
|
return EntityTransformer.toObject(this.entity, [], true);
|
|
59
68
|
}
|
|
69
|
+
/** Serializes the entity using its `toJSON` method (supports `JSON.stringify`). */
|
|
60
70
|
toJSON(...args) {
|
|
61
71
|
// toJSON methods is added to the prototype during discovery to support automatic serialization via JSON.stringify()
|
|
62
72
|
return this.entity.toJSON(...args);
|
|
63
73
|
}
|
|
74
|
+
/** Assigns the given data to this entity, updating its properties and relations. */
|
|
64
75
|
assign(data, options) {
|
|
65
76
|
if ('assign' in this.entity) {
|
|
66
77
|
return this.entity.assign(data, options);
|
|
67
78
|
}
|
|
68
79
|
return EntityAssigner.assign(this.entity, data, options);
|
|
69
80
|
}
|
|
81
|
+
/** Initializes (refreshes) the entity by reloading it from the database. Returns null if not found. */
|
|
70
82
|
async init(options) {
|
|
71
83
|
if (!this.__em) {
|
|
72
84
|
throw ValidationError.entityNotManaged(this.entity);
|
|
@@ -77,6 +89,7 @@ export class WrappedEntity {
|
|
|
77
89
|
schema: this.__schema,
|
|
78
90
|
});
|
|
79
91
|
}
|
|
92
|
+
/** Loads the specified relations on this entity. */
|
|
80
93
|
async populate(populate, options = {}) {
|
|
81
94
|
if (!this.__em) {
|
|
82
95
|
throw ValidationError.entityNotManaged(this.entity);
|
|
@@ -85,10 +98,12 @@ export class WrappedEntity {
|
|
|
85
98
|
await this.__em.populate(this.entity, populate, options);
|
|
86
99
|
return this.entity;
|
|
87
100
|
}
|
|
101
|
+
/** Returns whether this entity has a primary key value set. */
|
|
88
102
|
hasPrimaryKey() {
|
|
89
103
|
const pk = this.getPrimaryKey();
|
|
90
104
|
return pk != null;
|
|
91
105
|
}
|
|
106
|
+
/** Returns the primary key value, optionally converting custom types to their database representation. */
|
|
92
107
|
getPrimaryKey(convertCustomTypes = false) {
|
|
93
108
|
const prop = this.__meta.getPrimaryProps()[0];
|
|
94
109
|
if (!prop) {
|
|
@@ -105,7 +120,8 @@ export class WrappedEntity {
|
|
|
105
120
|
}
|
|
106
121
|
return this.__pk ?? this.pkGetter(this.entity);
|
|
107
122
|
}
|
|
108
|
-
|
|
123
|
+
/** Returns all primary key values as an array. Used internally for composite key handling. */
|
|
124
|
+
// TODO: currently used only in `Driver.syncCollection` — candidate for removal
|
|
109
125
|
getPrimaryKeys(convertCustomTypes = false) {
|
|
110
126
|
const pk = this.getPrimaryKey(convertCustomTypes);
|
|
111
127
|
if (pk == null) {
|
|
@@ -126,16 +142,20 @@ export class WrappedEntity {
|
|
|
126
142
|
}
|
|
127
143
|
return [pk];
|
|
128
144
|
}
|
|
145
|
+
/** Returns the database schema this entity belongs to. */
|
|
129
146
|
getSchema() {
|
|
130
147
|
return this.__schema;
|
|
131
148
|
}
|
|
149
|
+
/** Sets the database schema for this entity. */
|
|
132
150
|
setSchema(schema) {
|
|
133
151
|
this.__schema = schema;
|
|
134
152
|
}
|
|
153
|
+
/** Sets the primary key value on the entity. */
|
|
135
154
|
setPrimaryKey(id) {
|
|
136
155
|
this.entity[this.__meta.primaryKeys[0]] = id;
|
|
137
156
|
this.__pk = id;
|
|
138
157
|
}
|
|
158
|
+
/** Returns the primary key serialized as a string suitable for identity map lookups. */
|
|
139
159
|
getSerializedPrimaryKey() {
|
|
140
160
|
return this.pkSerializer(this.entity);
|
|
141
161
|
}
|
package/entity/defineEntity.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { IType, Type } from '../types/Type.js';
|
|
|
10
10
|
import { types } from '../types/index.js';
|
|
11
11
|
import type { Collection } from './Collection.js';
|
|
12
12
|
import type { FilterOptions } from '../drivers/IDatabaseDriver.js';
|
|
13
|
+
/** Union of all option keys supported across all property definition types (scalar, enum, embedded, relations). */
|
|
13
14
|
export type UniversalPropertyKeys = keyof PropertyOptions<any> | keyof EnumOptions<any> | keyof EmbeddedOptions<any, any> | keyof ReferenceOptions<any, any> | keyof ManyToOneOptions<any, any> | keyof OneToManyOptions<any, any> | keyof OneToOneOptions<any, any> | keyof ManyToManyOptions<any, any>;
|
|
14
15
|
type BuilderExtraKeys = '~options' | '~type' | '$type';
|
|
15
16
|
type ExcludeKeys = 'entity' | 'items';
|
|
@@ -494,6 +495,7 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
494
495
|
orphanRemoval(orphanRemoval?: boolean): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
495
496
|
accessor(accessor?: string | boolean): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
496
497
|
}
|
|
498
|
+
/** Empty options object used as the initial state for property builders. */
|
|
497
499
|
export interface EmptyOptions extends Partial<Record<UniversalPropertyKeys, unknown>> {
|
|
498
500
|
}
|
|
499
501
|
/** @internal */
|
|
@@ -510,6 +512,7 @@ type EntityTarget = {
|
|
|
510
512
|
} | EntityClass;
|
|
511
513
|
declare const propertyBuilders: PropertyBuilders;
|
|
512
514
|
type PropertyBuildersOverrideKeys = 'bigint' | 'array' | 'decimal' | 'json' | 'datetime' | 'time' | 'enum';
|
|
515
|
+
/** Map of factory functions for creating type-safe property builders (scalars, enums, embeddables, and relations). */
|
|
513
516
|
export type PropertyBuilders = {
|
|
514
517
|
[K in Exclude<keyof typeof types, PropertyBuildersOverrideKeys>]: () => UniversalPropertyOptionsBuilder<InferPropertyValueType<(typeof types)[K]>, EmptyOptions, IncludeKeysForProperty>;
|
|
515
518
|
} & {
|
|
@@ -540,6 +543,7 @@ export type PropertyBuilders = {
|
|
|
540
543
|
};
|
|
541
544
|
/** Own keys + base entity keys (when TBase is not `never`). Guards against `keyof never = string | number | symbol`. */
|
|
542
545
|
type AllKeys<TProperties, TBase> = keyof TProperties | (IsNever<TBase> extends true ? never : keyof TBase);
|
|
546
|
+
/** Metadata descriptor for `defineEntity()`, combining entity options with property definitions. */
|
|
543
547
|
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> extends Omit<Partial<EntityMetadata<InferEntityFromProperties<TProperties, TPK, TBase, TRepository>>>, 'properties' | 'extends' | 'primaryKeys' | 'hooks' | 'discriminatorColumn' | 'versionProperty' | 'concurrencyCheckKeys' | 'serializedPrimaryKey' | 'indexes' | 'uniques' | 'repository' | 'orderBy'> {
|
|
544
548
|
name: TName;
|
|
545
549
|
tableName?: TTableName;
|
|
@@ -576,7 +580,9 @@ export interface EntityMetadataWithProperties<TName extends string, TTableName e
|
|
|
576
580
|
deferMode?: DeferMode | `${DeferMode}`;
|
|
577
581
|
}[];
|
|
578
582
|
}
|
|
583
|
+
/** Defines an entity schema using property builders, with full type inference from the property definitions. */
|
|
579
584
|
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>(meta: EntityMetadataWithProperties<TName, TTableName, TProperties, TPK, TBase, TRepository, TForceObject>): EntitySchemaWithMeta<TName, TTableName, InferEntityFromProperties<TProperties, TPK, TBase, TRepository, TForceObject>, TBase, TProperties>;
|
|
585
|
+
/** Defines an entity schema for an existing class, combining the class with property builders. */
|
|
580
586
|
export declare function defineEntity<const TEntity = any, const TProperties extends Record<string, any> = Record<string, any>, const TClassName extends string = string, const TTableName extends string = string, const TBase = never, const TClass extends EntityCtor = EntityCtor<TEntity>>(meta: Omit<Partial<EntityMetadata<TEntity>>, 'properties' | 'extends' | 'className' | 'tableName' | 'hooks'> & {
|
|
581
587
|
class: TClass;
|
|
582
588
|
className?: TClassName;
|
|
@@ -588,8 +594,10 @@ export declare function defineEntity<const TEntity = any, const TProperties exte
|
|
|
588
594
|
export declare namespace defineEntity {
|
|
589
595
|
var properties: PropertyBuilders;
|
|
590
596
|
}
|
|
597
|
+
/** Shorthand alias for `defineEntity.properties` - the property builders for use in `defineEntity()`. */
|
|
591
598
|
export { propertyBuilders as p };
|
|
592
599
|
type EntityHookValue<T, K extends keyof EventSubscriber<T>> = (keyof T | NonNullable<EventSubscriber<T>[K]>)[];
|
|
600
|
+
/** Lifecycle hook definitions for entities created via `defineEntity()`. */
|
|
593
601
|
export interface DefineEntityHooks<T = any> {
|
|
594
602
|
onInit?: EntityHookValue<T, 'onInit'>;
|
|
595
603
|
onLoad?: EntityHookValue<T, 'onLoad'>;
|
|
@@ -608,6 +616,7 @@ type InferTypeByString<T extends string> = T extends keyof typeof types ? InferJ
|
|
|
608
616
|
type InferJSType<T> = T extends typeof Type<infer TValue, any> ? NonNullable<TValue> : never;
|
|
609
617
|
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;
|
|
610
618
|
type BaseEntityMethodKeys = 'toObject' | 'toPOJO' | 'serialize' | 'assign' | 'populate' | 'init' | 'toReference';
|
|
619
|
+
/** Infers the entity type from a `defineEntity()` properties map, resolving builders, base classes, and primary keys. */
|
|
611
620
|
export type InferEntityFromProperties<Properties extends Record<string, any>, PK extends (keyof Properties)[] | undefined = undefined, Base = never, Repository = never, ForceObject extends boolean = false> = (IsNever<Base> extends true ? {} : Base extends {
|
|
612
621
|
toObject(...args: any[]): any;
|
|
613
622
|
} ? Pick<IWrappedEntity<{
|
|
@@ -632,6 +641,7 @@ type ExtractBasePrimaryKey<Base> = Base extends {
|
|
|
632
641
|
[PrimaryKeyProp]?: infer BasePK;
|
|
633
642
|
} ? BasePK : never;
|
|
634
643
|
type CombinePrimaryKeys<ChildPK, BasePK> = [ChildPK] extends [never] ? BasePK : [BasePK] extends [never] ? IsUnion<ChildPK> extends true ? ChildPK[] : ChildPK : ChildPK | BasePK;
|
|
644
|
+
/** Extracts the primary key property names from a properties map by finding builders with `primary: true`. */
|
|
635
645
|
export type InferPrimaryKey<Properties extends Record<string, any>> = {
|
|
636
646
|
[K in keyof Properties]: MaybeReturnType<Properties[K]> extends {
|
|
637
647
|
'~options': {
|
|
@@ -688,9 +698,9 @@ type MaybeOpt<Value, Options> = Options extends {
|
|
|
688
698
|
version: true;
|
|
689
699
|
} | {
|
|
690
700
|
formula: string | ((...args: any[]) => any);
|
|
691
|
-
} ? Opt<Value> : Value;
|
|
701
|
+
} ? Opt<NonNullable<Value>> | Extract<Value, null | undefined> : Value;
|
|
692
702
|
type MaybeHidden<Value, Options> = Options extends {
|
|
693
703
|
hidden: true;
|
|
694
|
-
} ? Hidden<Value> : Value;
|
|
704
|
+
} ? Hidden<NonNullable<Value>> | Extract<Value, null | undefined> : Value;
|
|
695
705
|
type ValueOf<T extends Dictionary> = T[keyof T];
|
|
696
706
|
type IsUnion<T, U = T> = T extends U ? ([U] extends [T] ? false : true) : false;
|
package/entity/defineEntity.js
CHANGED
|
@@ -534,4 +534,5 @@ export function defineEntity(meta) {
|
|
|
534
534
|
return new EntitySchema({ properties, ...options });
|
|
535
535
|
}
|
|
536
536
|
defineEntity.properties = propertyBuilders;
|
|
537
|
+
/** Shorthand alias for `defineEntity.properties` - the property builders for use in `defineEntity()`. */
|
|
537
538
|
export { propertyBuilders as p };
|
package/enums.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { EntityKey, ExpandProperty } from './typings.js';
|
|
2
2
|
import type { Transaction } from './connections/Connection.js';
|
|
3
3
|
import type { LogContext } from './logging/Logger.js';
|
|
4
|
+
/** Controls when the `EntityManager` flushes pending changes to the database. */
|
|
4
5
|
export declare enum FlushMode {
|
|
5
6
|
/** The `EntityManager` delays the flush until the current Transaction is committed. */
|
|
6
7
|
COMMIT = "commit",
|
|
@@ -9,63 +10,114 @@ export declare enum FlushMode {
|
|
|
9
10
|
/** Flushes the `EntityManager` before every query. */
|
|
10
11
|
ALWAYS = "always"
|
|
11
12
|
}
|
|
13
|
+
/** Controls how populate hints are resolved when using `FindOptions.populateWhere`. */
|
|
12
14
|
export declare enum PopulateHint {
|
|
15
|
+
/** Infer population hints from the `where` condition. */
|
|
13
16
|
INFER = "infer",
|
|
17
|
+
/** Apply population hints to all relations. */
|
|
14
18
|
ALL = "all"
|
|
15
19
|
}
|
|
20
|
+
/** Special tokens used as populate path values in `FindOptions.populate`. */
|
|
16
21
|
export declare enum PopulatePath {
|
|
22
|
+
/** Infer which relations to populate based on fields accessed in the `where` or `orderBy` clause. */
|
|
17
23
|
INFER = "$infer",
|
|
24
|
+
/** Populate all relations. */
|
|
18
25
|
ALL = "*"
|
|
19
26
|
}
|
|
27
|
+
/** Logical grouping operators for combining query conditions. */
|
|
20
28
|
export declare enum GroupOperator {
|
|
29
|
+
/** Logical AND — all conditions must match. */
|
|
21
30
|
$and = "and",
|
|
31
|
+
/** Logical OR — at least one condition must match. */
|
|
22
32
|
$or = "or"
|
|
23
33
|
}
|
|
34
|
+
/** Comparison and filtering operators used in query conditions. */
|
|
24
35
|
export declare enum QueryOperator {
|
|
36
|
+
/** Equal. */
|
|
25
37
|
$eq = "=",
|
|
38
|
+
/** Included in the given list. */
|
|
26
39
|
$in = "in",
|
|
40
|
+
/** Not included in the given list. */
|
|
27
41
|
$nin = "not in",
|
|
42
|
+
/** Greater than. */
|
|
28
43
|
$gt = ">",
|
|
44
|
+
/** Greater than or equal to. */
|
|
29
45
|
$gte = ">=",
|
|
46
|
+
/** Less than. */
|
|
30
47
|
$lt = "<",
|
|
48
|
+
/** Less than or equal to. */
|
|
31
49
|
$lte = "<=",
|
|
50
|
+
/** Not equal. */
|
|
32
51
|
$ne = "!=",
|
|
52
|
+
/** Negation wrapper. */
|
|
33
53
|
$not = "not",
|
|
54
|
+
/** SQL LIKE pattern matching. */
|
|
34
55
|
$like = "like",
|
|
56
|
+
/** Regular expression matching. */
|
|
35
57
|
$re = "regexp",
|
|
58
|
+
/** Full-text search. */
|
|
36
59
|
$fulltext = "fulltext",
|
|
60
|
+
/** Checks that the value is not null (i.e., exists). */
|
|
37
61
|
$exists = "not null",
|
|
62
|
+
/** Case-insensitive LIKE (PostgreSQL only). */
|
|
38
63
|
$ilike = "ilike",// postgres only
|
|
64
|
+
/** Array overlap operator (PostgreSQL only). */
|
|
39
65
|
$overlap = "&&",// postgres only
|
|
66
|
+
/** Array/JSON contains operator (PostgreSQL only). */
|
|
40
67
|
$contains = "@>",// postgres only
|
|
68
|
+
/** Array/JSON contained-by operator (PostgreSQL only). */
|
|
41
69
|
$contained = "<@",// postgres only
|
|
70
|
+
/** No element in the collection matches (SQL only). */
|
|
42
71
|
$none = "none",// collection operators, sql only
|
|
72
|
+
/** At least one element in the collection matches (SQL only). */
|
|
43
73
|
$some = "some",// collection operators, sql only
|
|
74
|
+
/** Every element in the collection matches (SQL only). */
|
|
44
75
|
$every = "every",// collection operators, sql only
|
|
76
|
+
/** Matches collections by their size (SQL only). */
|
|
45
77
|
$size = "size",// collection operators, sql only
|
|
78
|
+
/** JSON object has the given key (PostgreSQL only). */
|
|
46
79
|
$hasKey = "?",// postgres only, json
|
|
80
|
+
/** JSON object has all of the given keys (PostgreSQL only). */
|
|
47
81
|
$hasKeys = "?&",// postgres only, json
|
|
82
|
+
/** JSON object has at least one of the given keys (PostgreSQL only). */
|
|
48
83
|
$hasSomeKeys = "?|",// postgres only, json
|
|
84
|
+
/** Matches an element inside a JSON array (SQL only). */
|
|
49
85
|
$elemMatch = "elemMatch"
|
|
50
86
|
}
|
|
51
87
|
export declare const ARRAY_OPERATORS: string[];
|
|
52
88
|
export declare const JSON_KEY_OPERATORS: string[];
|
|
89
|
+
/** Sort direction for query results. Both upper- and lower-case variants are accepted. */
|
|
53
90
|
export declare enum QueryOrder {
|
|
91
|
+
/** Ascending order. */
|
|
54
92
|
ASC = "ASC",
|
|
93
|
+
/** Ascending order with nulls sorted last. */
|
|
55
94
|
ASC_NULLS_LAST = "ASC NULLS LAST",
|
|
95
|
+
/** Ascending order with nulls sorted first. */
|
|
56
96
|
ASC_NULLS_FIRST = "ASC NULLS FIRST",
|
|
97
|
+
/** Descending order. */
|
|
57
98
|
DESC = "DESC",
|
|
99
|
+
/** Descending order with nulls sorted last. */
|
|
58
100
|
DESC_NULLS_LAST = "DESC NULLS LAST",
|
|
101
|
+
/** Descending order with nulls sorted first. */
|
|
59
102
|
DESC_NULLS_FIRST = "DESC NULLS FIRST",
|
|
103
|
+
/** Ascending order (lower-case variant). */
|
|
60
104
|
asc = "asc",
|
|
105
|
+
/** Ascending order with nulls sorted last (lower-case variant). */
|
|
61
106
|
asc_nulls_last = "asc nulls last",
|
|
107
|
+
/** Ascending order with nulls sorted first (lower-case variant). */
|
|
62
108
|
asc_nulls_first = "asc nulls first",
|
|
109
|
+
/** Descending order (lower-case variant). */
|
|
63
110
|
desc = "desc",
|
|
111
|
+
/** Descending order with nulls sorted last (lower-case variant). */
|
|
64
112
|
desc_nulls_last = "desc nulls last",
|
|
113
|
+
/** Descending order with nulls sorted first (lower-case variant). */
|
|
65
114
|
desc_nulls_first = "desc nulls first"
|
|
66
115
|
}
|
|
116
|
+
/** Numeric sort direction, compatible with MongoDB-style ordering. */
|
|
67
117
|
export declare enum QueryOrderNumeric {
|
|
118
|
+
/** Ascending order. */
|
|
68
119
|
ASC = 1,
|
|
120
|
+
/** Descending order. */
|
|
69
121
|
DESC = -1
|
|
70
122
|
}
|
|
71
123
|
export type QueryOrderKeysFlat = QueryOrder | QueryOrderNumeric | `${QueryOrder}`;
|
|
@@ -76,97 +128,174 @@ export type QueryOrderMap<T> = {
|
|
|
76
128
|
export interface FlatQueryOrderMap {
|
|
77
129
|
[x: string]: QueryOrderKeysFlat;
|
|
78
130
|
}
|
|
131
|
+
/** Flags that modify query builder behavior. */
|
|
79
132
|
export declare enum QueryFlag {
|
|
133
|
+
/** Add a DISTINCT clause to the SELECT statement. */
|
|
80
134
|
DISTINCT = "DISTINCT",
|
|
135
|
+
/** Enable result pagination via a sub-query for the primary keys. */
|
|
81
136
|
PAGINATE = "PAGINATE",
|
|
137
|
+
/** Disable the automatic pagination sub-query. */
|
|
82
138
|
DISABLE_PAGINATE = "DISABLE_PAGINATE",
|
|
139
|
+
/** Wrap UPDATE statements in a sub-query. */
|
|
83
140
|
UPDATE_SUB_QUERY = "UPDATE_SUB_QUERY",
|
|
141
|
+
/** Wrap DELETE statements in a sub-query. */
|
|
84
142
|
DELETE_SUB_QUERY = "DELETE_SUB_QUERY",
|
|
143
|
+
/** Convert values through custom type mappings when reading results. */
|
|
85
144
|
CONVERT_CUSTOM_TYPES = "CONVERT_CUSTOM_TYPES",
|
|
145
|
+
/** Include lazy formula properties in the SELECT clause. */
|
|
86
146
|
INCLUDE_LAZY_FORMULAS = "INCLUDE_LAZY_FORMULAS",
|
|
147
|
+
/** Automatically join the owning side of one-to-one relations. */
|
|
87
148
|
AUTO_JOIN_ONE_TO_ONE_OWNER = "AUTO_JOIN_ONE_TO_ONE_OWNER",
|
|
149
|
+
/** Infer the populate hint from the query fields. */
|
|
88
150
|
INFER_POPULATE = "INFER_POPULATE",
|
|
151
|
+
/** Prevent nested conditions from being promoted to INNER JOINs. */
|
|
89
152
|
DISABLE_NESTED_INNER_JOIN = "DISABLE_NESTED_INNER_JOIN",
|
|
153
|
+
/** Enable IDENTITY_INSERT for explicit PK values (MSSQL only). */
|
|
90
154
|
IDENTITY_INSERT = "IDENTITY_INSERT",// mssql only
|
|
155
|
+
/** Use an OUTPUT...INTO temp table for returning rows (MSSQL only). */
|
|
91
156
|
OUTPUT_TABLE = "OUTPUT_TABLE"
|
|
92
157
|
}
|
|
93
158
|
export declare const SCALAR_TYPES: Set<string>;
|
|
159
|
+
/** Describes the kind of relationship a property represents. */
|
|
94
160
|
export declare enum ReferenceKind {
|
|
161
|
+
/** A plain scalar property (not a relation). */
|
|
95
162
|
SCALAR = "scalar",
|
|
163
|
+
/** A one-to-one relation. */
|
|
96
164
|
ONE_TO_ONE = "1:1",
|
|
165
|
+
/** A one-to-many relation (inverse side of a many-to-one). */
|
|
97
166
|
ONE_TO_MANY = "1:m",
|
|
167
|
+
/** A many-to-one relation (owning side). */
|
|
98
168
|
MANY_TO_ONE = "m:1",
|
|
169
|
+
/** A many-to-many relation. */
|
|
99
170
|
MANY_TO_MANY = "m:n",
|
|
171
|
+
/** An embedded entity (inline object stored within the parent). */
|
|
100
172
|
EMBEDDED = "embedded"
|
|
101
173
|
}
|
|
174
|
+
/** Cascade operations that propagate from a parent entity to its relations. */
|
|
102
175
|
export declare enum Cascade {
|
|
176
|
+
/** Cascade persist — new related entities are automatically persisted. */
|
|
103
177
|
PERSIST = "persist",
|
|
178
|
+
/** Cascade merge — detached related entities are merged into the identity map. */
|
|
104
179
|
MERGE = "merge",
|
|
180
|
+
/** Cascade remove — removing the parent also removes related entities. */
|
|
105
181
|
REMOVE = "remove",
|
|
182
|
+
/** Enable all cascade operations (persist, merge, remove). */
|
|
106
183
|
ALL = "all",
|
|
107
184
|
/** @internal */
|
|
108
185
|
SCHEDULE_ORPHAN_REMOVAL = "schedule_orphan_removal",
|
|
109
186
|
/** @internal */
|
|
110
187
|
CANCEL_ORPHAN_REMOVAL = "cancel_orphan_removal"
|
|
111
188
|
}
|
|
189
|
+
/** Strategy used to load related entities when populating. */
|
|
112
190
|
export declare enum LoadStrategy {
|
|
191
|
+
/** Load relations with a separate SELECT ... WHERE pk IN (...) query. */
|
|
113
192
|
SELECT_IN = "select-in",
|
|
193
|
+
/** Load relations via SQL JOINs in a single query. */
|
|
114
194
|
JOINED = "joined",
|
|
195
|
+
/** Use joined strategy for to-one relations and select-in for to-many. */
|
|
115
196
|
BALANCED = "balanced"
|
|
116
197
|
}
|
|
198
|
+
/** Controls which relation types use the dataloader for batched loading. */
|
|
117
199
|
export declare enum DataloaderType {
|
|
200
|
+
/** Dataloader is disabled. */
|
|
118
201
|
NONE = 0,
|
|
202
|
+
/** Use the dataloader for Reference (to-one) relations only. */
|
|
119
203
|
REFERENCE = 1,
|
|
204
|
+
/** Use the dataloader for Collection (to-many) relations only. */
|
|
120
205
|
COLLECTION = 2,
|
|
206
|
+
/** Use the dataloader for both Reference and Collection relations. */
|
|
121
207
|
ALL = 3
|
|
122
208
|
}
|
|
209
|
+
/** Locking strategy for concurrency control. */
|
|
123
210
|
export declare enum LockMode {
|
|
211
|
+
/** No locking. */
|
|
124
212
|
NONE = 0,
|
|
213
|
+
/** Optimistic locking via a version column. */
|
|
125
214
|
OPTIMISTIC = 1,
|
|
215
|
+
/** Pessimistic shared lock (FOR SHARE). */
|
|
126
216
|
PESSIMISTIC_READ = 2,
|
|
217
|
+
/** Pessimistic exclusive lock (FOR UPDATE). */
|
|
127
218
|
PESSIMISTIC_WRITE = 3,
|
|
219
|
+
/** Pessimistic exclusive lock that skips already-locked rows (FOR UPDATE SKIP LOCKED). */
|
|
128
220
|
PESSIMISTIC_PARTIAL_WRITE = 4,
|
|
221
|
+
/** Pessimistic exclusive lock that fails immediately if the row is locked (FOR UPDATE NOWAIT). */
|
|
129
222
|
PESSIMISTIC_WRITE_OR_FAIL = 5,
|
|
223
|
+
/** Pessimistic shared lock that skips already-locked rows (FOR SHARE SKIP LOCKED). */
|
|
130
224
|
PESSIMISTIC_PARTIAL_READ = 6,
|
|
225
|
+
/** Pessimistic shared lock that fails immediately if the row is locked (FOR SHARE NOWAIT). */
|
|
131
226
|
PESSIMISTIC_READ_OR_FAIL = 7
|
|
132
227
|
}
|
|
228
|
+
/** Transaction isolation levels as defined by the SQL standard (plus vendor extensions). */
|
|
133
229
|
export declare enum IsolationLevel {
|
|
230
|
+
/** Allows dirty reads, non-repeatable reads, and phantom reads. */
|
|
134
231
|
READ_UNCOMMITTED = "read uncommitted",
|
|
232
|
+
/** Prevents dirty reads; non-repeatable and phantom reads are still possible. */
|
|
135
233
|
READ_COMMITTED = "read committed",
|
|
234
|
+
/** Snapshot isolation — each transaction sees a consistent snapshot of the database (MSSQL). */
|
|
136
235
|
SNAPSHOT = "snapshot",
|
|
236
|
+
/** Prevents dirty and non-repeatable reads; phantom reads are still possible. */
|
|
137
237
|
REPEATABLE_READ = "repeatable read",
|
|
238
|
+
/** Full isolation — transactions are executed as if they were run sequentially. */
|
|
138
239
|
SERIALIZABLE = "serializable"
|
|
139
240
|
}
|
|
241
|
+
/** Lifecycle and transaction events emitted by the ORM. */
|
|
140
242
|
export declare enum EventType {
|
|
243
|
+
/** Fired when an entity instance is created (via constructor or `em.create`). */
|
|
141
244
|
onInit = "onInit",
|
|
245
|
+
/** Fired after an entity is loaded from the database. */
|
|
142
246
|
onLoad = "onLoad",
|
|
247
|
+
/** Fired before a new entity is inserted into the database. */
|
|
143
248
|
beforeCreate = "beforeCreate",
|
|
249
|
+
/** Fired after a new entity has been inserted into the database. */
|
|
144
250
|
afterCreate = "afterCreate",
|
|
251
|
+
/** Fired before an existing entity is updated in the database. */
|
|
145
252
|
beforeUpdate = "beforeUpdate",
|
|
253
|
+
/** Fired after an existing entity has been updated in the database. */
|
|
146
254
|
afterUpdate = "afterUpdate",
|
|
255
|
+
/** Fired before an upsert operation. */
|
|
147
256
|
beforeUpsert = "beforeUpsert",
|
|
257
|
+
/** Fired after an upsert operation. */
|
|
148
258
|
afterUpsert = "afterUpsert",
|
|
259
|
+
/** Fired before an entity is deleted from the database. */
|
|
149
260
|
beforeDelete = "beforeDelete",
|
|
261
|
+
/** Fired after an entity has been deleted from the database. */
|
|
150
262
|
afterDelete = "afterDelete",
|
|
263
|
+
/** Fired at the very beginning of `em.flush()`, before change detection. */
|
|
151
264
|
beforeFlush = "beforeFlush",
|
|
265
|
+
/** Fired during `em.flush()` after change detection but before database writes. */
|
|
152
266
|
onFlush = "onFlush",
|
|
267
|
+
/** Fired after `em.flush()` has completed all database writes. */
|
|
153
268
|
afterFlush = "afterFlush",
|
|
269
|
+
/** Fired before a new database transaction is started. */
|
|
154
270
|
beforeTransactionStart = "beforeTransactionStart",
|
|
271
|
+
/** Fired after a new database transaction has been started. */
|
|
155
272
|
afterTransactionStart = "afterTransactionStart",
|
|
273
|
+
/** Fired before a database transaction is committed. */
|
|
156
274
|
beforeTransactionCommit = "beforeTransactionCommit",
|
|
275
|
+
/** Fired after a database transaction has been committed. */
|
|
157
276
|
afterTransactionCommit = "afterTransactionCommit",
|
|
277
|
+
/** Fired before a database transaction is rolled back. */
|
|
158
278
|
beforeTransactionRollback = "beforeTransactionRollback",
|
|
279
|
+
/** Fired after a database transaction has been rolled back. */
|
|
159
280
|
afterTransactionRollback = "afterTransactionRollback"
|
|
160
281
|
}
|
|
161
282
|
export declare const EventTypeMap: Record<EventType, number>;
|
|
162
283
|
export type TransactionEventType = EventType.beforeTransactionStart | EventType.afterTransactionStart | EventType.beforeTransactionCommit | EventType.afterTransactionCommit | EventType.beforeTransactionRollback | EventType.afterTransactionRollback;
|
|
284
|
+
/** Controls how a transactional operation interacts with an existing transaction. */
|
|
163
285
|
export declare enum TransactionPropagation {
|
|
286
|
+
/** Join the current transaction or create a new one if none exists. */
|
|
164
287
|
REQUIRED = "required",
|
|
288
|
+
/** Always create a new transaction, suspending the current one if it exists. */
|
|
165
289
|
REQUIRES_NEW = "requires_new",
|
|
290
|
+
/** Create a nested savepoint within the current transaction, or a new transaction if none exists. */
|
|
166
291
|
NESTED = "nested",
|
|
292
|
+
/** Execute non-transactionally, suspending the current transaction if one exists. */
|
|
167
293
|
NOT_SUPPORTED = "not_supported",
|
|
294
|
+
/** Join the current transaction if one exists, otherwise execute non-transactionally. */
|
|
168
295
|
SUPPORTS = "supports",
|
|
296
|
+
/** Join the current transaction; throw if no transaction is active. */
|
|
169
297
|
MANDATORY = "mandatory",
|
|
298
|
+
/** Execute non-transactionally; throw if a transaction is active. */
|
|
170
299
|
NEVER = "never"
|
|
171
300
|
}
|
|
172
301
|
export interface TransactionOptions {
|
|
@@ -181,8 +310,11 @@ export interface TransactionOptions {
|
|
|
181
310
|
}
|
|
182
311
|
export declare abstract class PlainObject {
|
|
183
312
|
}
|
|
313
|
+
/** Constraint deferral mode for database constraints (e.g., foreign keys, unique). */
|
|
184
314
|
export declare enum DeferMode {
|
|
315
|
+
/** The constraint is checked immediately by default, but can be deferred within a transaction. */
|
|
185
316
|
INITIALLY_IMMEDIATE = "immediate",
|
|
317
|
+
/** The constraint is deferred until the transaction is committed. */
|
|
186
318
|
INITIALLY_DEFERRED = "deferred"
|
|
187
319
|
}
|
|
188
320
|
/** With `absolute` the prefix is set at the root of the entity (regardless of the nesting level) */
|