@mikro-orm/core 7.0.0-rc.1 → 7.0.0-rc.2
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 +1 -1
- package/EntityManager.js +1 -1
- package/drivers/IDatabaseDriver.d.ts +6 -1
- package/entity/BaseEntity.d.ts +3 -3
- package/entity/EntityFactory.js +5 -2
- package/entity/EntityHelper.js +2 -2
- package/entity/EntityLoader.d.ts +6 -6
- package/entity/EntityRepository.d.ts +1 -1
- package/entity/WrappedEntity.d.ts +3 -3
- package/entity/defineEntity.d.ts +179 -47
- package/entity/defineEntity.js +20 -24
- package/index.d.ts +2 -2
- package/index.js +1 -1
- package/metadata/EntitySchema.d.ts +1 -1
- package/metadata/MetadataDiscovery.js +1 -1
- package/package.json +5 -2
- package/platforms/Platform.d.ts +3 -1
- package/platforms/Platform.js +1 -1
- package/serialization/EntitySerializer.d.ts +3 -3
- package/serialization/EntityTransformer.js +6 -4
- package/typings.d.ts +54 -14
- package/typings.js +2 -0
- package/unit-of-work/ChangeSetPersister.js +2 -2
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +305 -0
- package/utils/Configuration.d.ts +3 -1
- package/utils/Utils.js +1 -1
- package/utils/fs-utils.d.ts +1 -0
- package/utils/fs-utils.js +4 -0
- package/utils/index.d.ts +0 -2
- package/utils/index.js +0 -2
package/entity/defineEntity.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { types } from '../types/index.js';
|
|
2
2
|
import { EntitySchema } from '../metadata/EntitySchema.js';
|
|
3
|
+
// Parameter-level sync assertion lives in tests/defineEntity.test.ts to avoid
|
|
4
|
+
// instantiating the full builder class in production builds (~680 instantiations).
|
|
3
5
|
/** @internal */
|
|
4
6
|
export class UniversalPropertyOptionsBuilder {
|
|
5
7
|
'~options';
|
|
@@ -82,9 +84,6 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
82
84
|
scale(scale) {
|
|
83
85
|
return this.assignOptions({ scale });
|
|
84
86
|
}
|
|
85
|
-
/**
|
|
86
|
-
* Explicitly specify the auto increment of the primary key.
|
|
87
|
-
*/
|
|
88
87
|
autoincrement(autoincrement = true) {
|
|
89
88
|
return this.assignOptions({ autoincrement });
|
|
90
89
|
}
|
|
@@ -143,8 +142,8 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
143
142
|
/**
|
|
144
143
|
* Set column as nullable for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
|
|
145
144
|
*/
|
|
146
|
-
nullable(
|
|
147
|
-
return this.assignOptions({ nullable });
|
|
145
|
+
nullable() {
|
|
146
|
+
return this.assignOptions({ nullable: true });
|
|
148
147
|
}
|
|
149
148
|
/**
|
|
150
149
|
* Set column as unsigned for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
@@ -152,9 +151,6 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
152
151
|
unsigned(unsigned = true) {
|
|
153
152
|
return this.assignOptions({ unsigned });
|
|
154
153
|
}
|
|
155
|
-
/**
|
|
156
|
-
* Set false to define {@link https://mikro-orm.io/docs/serializing#shadow-properties Shadow Property}.
|
|
157
|
-
*/
|
|
158
154
|
persist(persist = true) {
|
|
159
155
|
return this.assignOptions({ persist });
|
|
160
156
|
}
|
|
@@ -167,20 +163,20 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
167
163
|
/**
|
|
168
164
|
* Enable `ScalarReference` wrapper for lazy values. Use this in combination with `lazy: true` to have a type-safe accessor object in place of the value.
|
|
169
165
|
*/
|
|
170
|
-
ref(
|
|
171
|
-
return this.assignOptions({ ref });
|
|
166
|
+
ref() {
|
|
167
|
+
return this.assignOptions({ ref: true });
|
|
172
168
|
}
|
|
173
169
|
/**
|
|
174
170
|
* Set to true to omit the property when {@link https://mikro-orm.io/docs/serializing Serializing}.
|
|
175
171
|
*/
|
|
176
|
-
hidden(
|
|
177
|
-
return this.assignOptions({ hidden });
|
|
172
|
+
hidden() {
|
|
173
|
+
return this.assignOptions({ hidden: true });
|
|
178
174
|
}
|
|
179
175
|
/**
|
|
180
176
|
* Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via version field. (SQL only)
|
|
181
177
|
*/
|
|
182
|
-
version(
|
|
183
|
-
return this.assignOptions({ version });
|
|
178
|
+
version() {
|
|
179
|
+
return this.assignOptions({ version: true });
|
|
184
180
|
}
|
|
185
181
|
/**
|
|
186
182
|
* Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via concurrency fields.
|
|
@@ -213,16 +209,16 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
213
209
|
*
|
|
214
210
|
* @see https://mikro-orm.io/docs/defining-entities#lazy-scalar-properties
|
|
215
211
|
*/
|
|
216
|
-
lazy(
|
|
217
|
-
return this.assignOptions({ lazy
|
|
212
|
+
lazy() {
|
|
213
|
+
return this.assignOptions({ lazy: true });
|
|
218
214
|
}
|
|
219
215
|
/**
|
|
220
216
|
* Set true to define entity's unique primary key identifier.
|
|
221
217
|
*
|
|
222
218
|
* @see https://mikro-orm.io/docs/decorators#primarykey
|
|
223
219
|
*/
|
|
224
|
-
primary(
|
|
225
|
-
return this.assignOptions({ primary });
|
|
220
|
+
primary() {
|
|
221
|
+
return this.assignOptions({ primary: true });
|
|
226
222
|
}
|
|
227
223
|
/**
|
|
228
224
|
* Set true to define the properties as setter. (virtual)
|
|
@@ -321,8 +317,8 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
321
317
|
ignoreSchemaChanges(...ignoreSchemaChanges) {
|
|
322
318
|
return this.assignOptions({ ignoreSchemaChanges });
|
|
323
319
|
}
|
|
324
|
-
array(
|
|
325
|
-
return this.assignOptions({ array });
|
|
320
|
+
array() {
|
|
321
|
+
return this.assignOptions({ array: true });
|
|
326
322
|
}
|
|
327
323
|
/** for postgres, by default it uses text column with check constraint */
|
|
328
324
|
nativeEnumName(nativeEnumName) {
|
|
@@ -350,8 +346,8 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
350
346
|
return this.assignOptions({ strategy });
|
|
351
347
|
}
|
|
352
348
|
/** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
|
|
353
|
-
owner(
|
|
354
|
-
return this.assignOptions({ owner });
|
|
349
|
+
owner() {
|
|
350
|
+
return this.assignOptions({ owner: true });
|
|
355
351
|
}
|
|
356
352
|
/** For polymorphic relations. Specifies the property name that stores the entity type discriminator. Defaults to the property name. */
|
|
357
353
|
discriminator(discriminator) {
|
|
@@ -430,8 +426,8 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
430
426
|
return this.assignOptions({ updateRule });
|
|
431
427
|
}
|
|
432
428
|
/** Map this relation to the primary key value instead of an entity. */
|
|
433
|
-
mapToPk(
|
|
434
|
-
return this.assignOptions({ mapToPk });
|
|
429
|
+
mapToPk() {
|
|
430
|
+
return this.assignOptions({ mapToPk: true });
|
|
435
431
|
}
|
|
436
432
|
/** Set the constraint type. Immediate constraints are checked for each statement, while deferred ones are only checked at the end of the transaction. Only for postgres unique constraints. */
|
|
437
433
|
deferMode(deferMode) {
|
package/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module core
|
|
4
4
|
*/
|
|
5
|
-
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config } from './typings.js';
|
|
6
|
-
export type { CompiledFunctions, Constructor, ConnectionType, Dictionary, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity,
|
|
5
|
+
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName } from './typings.js';
|
|
6
|
+
export type { CompiledFunctions, Constructor, ConnectionType, Dictionary, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, InferEntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, EntityDTOFlat, EntityDTOProp, SerializeDTO, MigrationDiff, GenerateOptions, FilterObject, IMigrationRunner, IEntityGenerator, ISeedManager, SeederObject, IMigratorStorage, RequiredEntityData, CheckCallback, IndexCallback, FormulaCallback, FormulaTable, SchemaTable, SchemaColumns, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, MigrationInfo, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, EntityDataValue, FilterKey, EntityType, FromEntityType, Selected, IsSubset, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, FilterValue, MergeLoaded, MergeSelected, TypeConfig, AnyString, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, ImportsResolver, RequiredNullable, DefineConfig, Opt, Hidden, EntitySchemaWithMeta, InferEntity, CheckConstraint, GeneratedColumnCallback, FilterDef, EntityCtor, Subquery, PopulateHintOptions, Prefixes, } from './typings.js';
|
|
7
7
|
export * from './enums.js';
|
|
8
8
|
export * from './errors.js';
|
|
9
9
|
export * from './exceptions.js';
|
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module core
|
|
4
4
|
*/
|
|
5
|
-
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config } from './typings.js';
|
|
5
|
+
export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName } from './typings.js';
|
|
6
6
|
export * from './enums.js';
|
|
7
7
|
export * from './errors.js';
|
|
8
8
|
export * from './exceptions.js';
|
|
@@ -108,6 +108,6 @@ export declare class EntitySchema<Entity = any, Base = never, Class extends Enti
|
|
|
108
108
|
* });
|
|
109
109
|
* ```
|
|
110
110
|
*/
|
|
111
|
-
addHook<Event extends EventType | `${EventType}
|
|
111
|
+
addHook<Event extends EventType | `${EventType}`, T extends Entity = Entity>(event: Event, handler: NonNullable<EventSubscriber<T>[Event]>): this;
|
|
112
112
|
}
|
|
113
113
|
export {};
|
|
@@ -1474,7 +1474,7 @@ export class MetadataDiscovery {
|
|
|
1474
1474
|
}
|
|
1475
1475
|
/* v8 ignore next */
|
|
1476
1476
|
if (prop.default != null) {
|
|
1477
|
-
return '' + this.platform.
|
|
1477
|
+
return '' + this.platform.convertVersionValue(prop.default, prop);
|
|
1478
1478
|
}
|
|
1479
1479
|
this.initCustomType(meta, prop, true);
|
|
1480
1480
|
const type = prop.customType?.runtimeType ?? prop.runtimeType ?? prop.type;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-rc.
|
|
4
|
+
"version": "7.0.0-rc.2",
|
|
5
5
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./package.json": "./package.json",
|
|
@@ -13,7 +13,10 @@
|
|
|
13
13
|
"./fs-utils": {
|
|
14
14
|
"node": "./utils/fs-utils.js",
|
|
15
15
|
"browser": "./not-supported.js"
|
|
16
|
-
}
|
|
16
|
+
},
|
|
17
|
+
"./migrations": "./utils/AbstractMigrator.js",
|
|
18
|
+
"./schema": "./utils/AbstractSchemaGenerator.js",
|
|
19
|
+
"./dataloader": "./utils/DataloaderUtils.js"
|
|
17
20
|
},
|
|
18
21
|
"repository": {
|
|
19
22
|
"type": "git",
|
package/platforms/Platform.d.ts
CHANGED
|
@@ -66,7 +66,9 @@ export declare abstract class Platform {
|
|
|
66
66
|
$flags?: string;
|
|
67
67
|
};
|
|
68
68
|
isAllowedTopLevelOperator(operator: string): boolean;
|
|
69
|
-
|
|
69
|
+
convertVersionValue(value: Date | number, prop: EntityProperty): Date | string | number | {
|
|
70
|
+
$in: (string | number)[];
|
|
71
|
+
};
|
|
70
72
|
getDefaultVersionLength(): number;
|
|
71
73
|
allowsComparingTuples(): boolean;
|
|
72
74
|
isBigIntProperty(prop: EntityProperty): boolean;
|
package/platforms/Platform.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ArrayElement, AutoPath, CleanTypeConfig,
|
|
1
|
+
import type { ArrayElement, AutoPath, CleanTypeConfig, SerializeDTO, FromEntityType, TypeConfig, UnboxArray } from '../typings.js';
|
|
2
2
|
import { type PopulatePath } from '../enums.js';
|
|
3
3
|
export declare class EntitySerializer {
|
|
4
|
-
static serialize<T extends object, P extends string = never, E extends string = never>(entity: T, options?: SerializeOptions<T, P, E>):
|
|
4
|
+
static serialize<T extends object, P extends string = never, E extends string = never>(entity: T, options?: SerializeOptions<T, P, E>): SerializeDTO<T, P, E>;
|
|
5
5
|
private static propertyName;
|
|
6
6
|
private static processProperty;
|
|
7
7
|
private static processCustomType;
|
|
@@ -39,4 +39,4 @@ export interface SerializeOptions<T, P extends string = never, E extends string
|
|
|
39
39
|
* const dto2 = wrap(user).serialize({ exclude: ['id', 'email'], forceObject: true });
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
export declare function serialize<Entity extends object, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Populate extends string = never, Exclude extends string = never, Config extends TypeConfig = never>(entity: Entity, options?: Config & SerializeOptions<UnboxArray<Entity>, Populate, Exclude>): Naked extends object[] ?
|
|
42
|
+
export declare function serialize<Entity extends object, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Populate extends string = never, Exclude extends string = never, Config extends TypeConfig = never>(entity: Entity, options?: Config & SerializeOptions<UnboxArray<Entity>, Populate, Exclude>): Naked extends object[] ? SerializeDTO<ArrayElement<Naked>, Populate, Exclude, CleanTypeConfig<Config>>[] : SerializeDTO<Naked, Populate, Exclude, CleanTypeConfig<Config>>;
|
|
@@ -58,10 +58,12 @@ export class EntityTransformer {
|
|
|
58
58
|
continue;
|
|
59
59
|
}
|
|
60
60
|
const populated = root.isMarkedAsPopulated(meta.class, prop);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
if (!raw) {
|
|
62
|
+
const partiallyLoaded = root.isPartiallyLoaded(meta.class, prop);
|
|
63
|
+
const isPrimary = includePrimaryKeys && meta.properties[prop].primary;
|
|
64
|
+
if (!partiallyLoaded && !populated && !isPrimary) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
65
67
|
}
|
|
66
68
|
const cycle = root.visit(meta.class, prop);
|
|
67
69
|
if (cycle && visited) {
|
package/typings.d.ts
CHANGED
|
@@ -110,6 +110,10 @@ export declare const OptionalProps: unique symbol;
|
|
|
110
110
|
export declare const EagerProps: unique symbol;
|
|
111
111
|
export declare const HiddenProps: unique symbol;
|
|
112
112
|
export declare const Config: unique symbol;
|
|
113
|
+
export declare const EntityName: unique symbol;
|
|
114
|
+
export type InferEntityName<T> = T extends {
|
|
115
|
+
[EntityName]?: infer Name;
|
|
116
|
+
} ? Name extends string ? Name : never : never;
|
|
113
117
|
export type Opt<T = unknown> = T & Opt.Brand;
|
|
114
118
|
export declare namespace Opt {
|
|
115
119
|
const __optional: unique symbol;
|
|
@@ -243,7 +247,7 @@ export interface IWrappedEntity<Entity extends object> {
|
|
|
243
247
|
isInitialized(): boolean;
|
|
244
248
|
isManaged(): boolean;
|
|
245
249
|
populated(populated?: boolean): void;
|
|
246
|
-
populate<Hint extends string = never>(populate: readonly AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
|
|
250
|
+
populate<Hint extends string = never, Fields extends string = never>(populate: readonly AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity, Fields>): Promise<Loaded<Entity, Hint>>;
|
|
247
251
|
init<Hint extends string = never, Fields extends string = '*', Exclude extends string = never>(options?: FindOneOptions<Entity, Hint, Fields, Exclude>): Promise<Loaded<Entity, Hint, Fields, Exclude> | null>;
|
|
248
252
|
toReference(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
|
|
249
253
|
toObject(): EntityDTO<Entity>;
|
|
@@ -251,7 +255,7 @@ export interface IWrappedEntity<Entity extends object> {
|
|
|
251
255
|
toObject<Ignored extends EntityKey<Entity>>(ignoreFields: Ignored[]): Omit<EntityDTO<Entity>, Ignored>;
|
|
252
256
|
toJSON(...args: any[]): EntityDTO<Entity>;
|
|
253
257
|
toPOJO(): EntityDTO<Entity>;
|
|
254
|
-
serialize<Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Naked, Hint, Exclude>):
|
|
258
|
+
serialize<Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Naked, Hint, Exclude>): SerializeDTO<Naked, Hint, Exclude>;
|
|
255
259
|
setSerializationContext<Hint extends string = never, Fields extends string = '*', Exclude extends string = never>(options: LoadHint<Entity, Hint, Fields, Exclude>): void;
|
|
256
260
|
assign<Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Convert extends boolean = false, Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> = EntityData<Naked, Convert> | Partial<EntityDTO<Naked>>>(data: Data & IsSubset<EntityData<Naked, Convert>, Data>, options?: AssignOptions<Convert>): MergeSelected<Entity, Naked, keyof Data & string>;
|
|
257
261
|
getSchema(): string | undefined;
|
|
@@ -385,9 +389,10 @@ type PreferExplicitConfig<E, I> = IsNever<E, I, E>;
|
|
|
385
389
|
type PrimaryOrObject<T, U, C extends TypeConfig> = PreferExplicitConfig<C, ExtractConfig<T>>['forceObject'] extends true ? {
|
|
386
390
|
[K in PrimaryProperty<U> & keyof U]: U[K];
|
|
387
391
|
} : Primary<U>;
|
|
388
|
-
|
|
392
|
+
type DTOWrapper<T, C extends TypeConfig, Flat extends boolean> = Flat extends true ? EntityDTOFlat<T, C> : EntityDTO<T, C>;
|
|
393
|
+
export type EntityDTOProp<E, T, C extends TypeConfig = never, Flat extends boolean = false> = T extends Scalar ? T : T extends ScalarReference<infer U> ? U : T extends {
|
|
389
394
|
__serialized?: infer U;
|
|
390
|
-
} ? (IsUnknown<U> extends false ? U : T) : T extends LoadedReferenceShape<infer U> ?
|
|
395
|
+
} ? (IsUnknown<U> extends false ? U : T) : T extends LoadedReferenceShape<infer U> ? DTOWrapper<U, C, Flat> : T extends ReferenceShape<infer U> ? PrimaryOrObject<E, U, C> : T extends LoadedCollectionShape<infer U> ? DTOWrapper<U & object, C, Flat>[] : T extends CollectionShape<infer U> ? PrimaryOrObject<E, U & object, C>[] : T extends readonly (infer U)[] ? U extends Scalar ? T : EntityDTOProp<E, U, C, Flat>[] : T extends Relation<T> ? DTOWrapper<T, C, Flat> : T;
|
|
391
396
|
type UnwrapLoadedEntity<T> = T extends {
|
|
392
397
|
[__loadedType]?: infer U;
|
|
393
398
|
} ? NonNullable<U> : T;
|
|
@@ -400,6 +405,27 @@ export type EntityDTO<T, C extends TypeConfig = never> = {
|
|
|
400
405
|
} & {
|
|
401
406
|
[K in keyof T as DTOOptionalKeys<T, K>]?: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
|
|
402
407
|
};
|
|
408
|
+
/**
|
|
409
|
+
* @internal
|
|
410
|
+
* 1-pass variant of EntityDTO — ~2x cheaper to resolve but all keys are required
|
|
411
|
+
* (optional keys use `| undefined` in value type instead of `?` modifier).
|
|
412
|
+
* Use only for internal type computations (output types), never as a user-facing
|
|
413
|
+
* function parameter type where generic assignability checks are needed.
|
|
414
|
+
*/
|
|
415
|
+
export type EntityDTOFlat<T, C extends TypeConfig = never> = {
|
|
416
|
+
[K in keyof T as ExcludeHidden<T, K> & CleanKeys<T, K>]: EntityDTOProp<T, T[K], C, true> | AddOptional<T[K]>;
|
|
417
|
+
};
|
|
418
|
+
/**
|
|
419
|
+
* @internal
|
|
420
|
+
* Single-pass fused type that combines Loaded + EntityDTO into one mapped type.
|
|
421
|
+
* ~40x faster than `EntityDTO<Loaded<T, H>>` for populated entities.
|
|
422
|
+
*/
|
|
423
|
+
type SerializeTopHints<H extends string> = H extends `${infer Top}.${string}` ? Top : H;
|
|
424
|
+
type SerializeSubHints<K extends string, H extends string> = H extends `${K}.${infer Rest}` ? Rest : never;
|
|
425
|
+
type SerializePropValue<T, K extends keyof T, H extends string, C extends TypeConfig = never> = (K & string) extends SerializeTopHints<H> ? NonNullable<T[K]> extends CollectionShape<infer U> ? SerializeDTO<U & object, SerializeSubHints<K & string, H>, never, C>[] : SerializeDTO<ExpandProperty<T[K]>, SerializeSubHints<K & string, H>, never, C> | Extract<T[K], null | undefined> : EntityDTOProp<T, T[K], C>;
|
|
426
|
+
export type SerializeDTO<T, H extends string = never, E extends string = never, C extends TypeConfig = never> = string extends H ? EntityDTOFlat<T, C> : {
|
|
427
|
+
[K in keyof T as ExcludeHidden<T, K> & CleanKeys<T, K> & (IsNever<E> extends true ? K : Exclude<K, E>)]: SerializePropValue<T, K, H, C> | Extract<T[K], null | undefined>;
|
|
428
|
+
};
|
|
403
429
|
type TargetKeys<T> = T extends EntityClass<infer P> ? keyof P : keyof T;
|
|
404
430
|
type PropertyName<T> = IsUnknown<T> extends false ? TargetKeys<T> : string;
|
|
405
431
|
export type FormulaTable = {
|
|
@@ -792,7 +818,7 @@ export interface GenerateOptions {
|
|
|
792
818
|
export interface IEntityGenerator {
|
|
793
819
|
generate(options?: GenerateOptions): Promise<string[]>;
|
|
794
820
|
}
|
|
795
|
-
export type
|
|
821
|
+
export type MigrationInfo = {
|
|
796
822
|
name: string;
|
|
797
823
|
path?: string;
|
|
798
824
|
};
|
|
@@ -812,6 +838,14 @@ export type MigrationRow = {
|
|
|
812
838
|
name: string;
|
|
813
839
|
executed_at: Date;
|
|
814
840
|
};
|
|
841
|
+
/**
|
|
842
|
+
* @internal
|
|
843
|
+
*/
|
|
844
|
+
export interface IMigrationRunner {
|
|
845
|
+
run(migration: Migration, method: 'up' | 'down'): Promise<void>;
|
|
846
|
+
setMasterMigration(trx: Transaction): void;
|
|
847
|
+
unsetMasterMigration(): void;
|
|
848
|
+
}
|
|
815
849
|
/**
|
|
816
850
|
* @internal
|
|
817
851
|
*/
|
|
@@ -852,23 +886,23 @@ export interface IMigrator {
|
|
|
852
886
|
/**
|
|
853
887
|
* Returns list of pending (not yet executed) migrations found in the migration directory.
|
|
854
888
|
*/
|
|
855
|
-
getPending(): Promise<
|
|
889
|
+
getPending(): Promise<MigrationInfo[]>;
|
|
856
890
|
/**
|
|
857
891
|
* Executes specified migrations. Without parameter it will migrate up to the latest version.
|
|
858
892
|
*/
|
|
859
|
-
up(options?: string | string[] | MigrateOptions): Promise<
|
|
893
|
+
up(options?: string | string[] | MigrateOptions): Promise<MigrationInfo[]>;
|
|
860
894
|
/**
|
|
861
895
|
* Executes down migrations to the given point. Without parameter it will migrate one version down.
|
|
862
896
|
*/
|
|
863
|
-
down(options?: string | string[] | MigrateOptions): Promise<
|
|
897
|
+
down(options?: string | string[] | Omit<MigrateOptions, 'from'>): Promise<MigrationInfo[]>;
|
|
864
898
|
/**
|
|
865
899
|
* Registers event handler.
|
|
866
900
|
*/
|
|
867
|
-
on(event: MigratorEvent, listener: (event:
|
|
901
|
+
on(event: MigratorEvent, listener: (event: MigrationInfo) => MaybePromise<void>): IMigrator;
|
|
868
902
|
/**
|
|
869
903
|
* Removes event handler.
|
|
870
904
|
*/
|
|
871
|
-
off(event: MigratorEvent, listener: (event:
|
|
905
|
+
off(event: MigratorEvent, listener: (event: MigrationInfo) => MaybePromise<void>): IMigrator;
|
|
872
906
|
/**
|
|
873
907
|
* @internal
|
|
874
908
|
*/
|
|
@@ -896,6 +930,10 @@ export interface IMigrationGenerator {
|
|
|
896
930
|
export interface Migration {
|
|
897
931
|
up(): Promise<void> | void;
|
|
898
932
|
down(): Promise<void> | void;
|
|
933
|
+
isTransactional(): boolean;
|
|
934
|
+
reset(): void;
|
|
935
|
+
setTransactionContext(ctx: Transaction): void;
|
|
936
|
+
getQueries?(): any[];
|
|
899
937
|
}
|
|
900
938
|
export interface MigrationObject {
|
|
901
939
|
name: string;
|
|
@@ -951,7 +989,7 @@ type IsTrue<T> = IsNever<T> extends true ? false : T extends boolean ? T extends
|
|
|
951
989
|
type StringLiteral<T> = T extends string ? string extends T ? never : T : never;
|
|
952
990
|
type Prefix<T, K> = K extends `${infer S}.${string}` ? S : (K extends '*' ? keyof T : K);
|
|
953
991
|
type IsPrefixedExclude<T, K extends keyof T, E extends string> = K extends E ? never : K;
|
|
954
|
-
export type IsPrefixed<T, K extends keyof T, L extends string, E extends string = never> = IsNever<E> extends false ? IsPrefixedExclude<T, K, E> : K extends symbol ? never : IsTrue<L> extends true ? (T[K] & {} extends LoadableShape ? K : never) : IsNever<StringLiteral<L>> extends true ? never :
|
|
992
|
+
export type IsPrefixed<T, K extends keyof T, L extends string, E extends string = never> = IsNever<E> extends false ? IsPrefixedExclude<T, K, E> : K extends symbol ? never : IsTrue<L> extends true ? (T[K] & {} extends LoadableShape ? K : never) : IsNever<StringLiteral<L>> extends true ? never : '*' extends L ? K : K extends Prefix<T, L> ? K : K extends PrimaryProperty<T> ? K : never;
|
|
955
993
|
type Suffix<Key, Hint extends string, All = true | '*'> = Hint extends `${infer Pref}.${infer Suf}` ? (Pref extends Key ? Suf : never) : Hint extends All ? Hint : never;
|
|
956
994
|
export type IsSubset<T, U> = keyof U extends keyof T ? {} : string extends keyof U ? {} : {
|
|
957
995
|
[K in keyof U as K extends keyof T ? never : CleanKeys<U, K>]: never;
|
|
@@ -981,9 +1019,7 @@ type LoadedProp<T, L extends string = never, F extends string = '*', E extends s
|
|
|
981
1019
|
export type AddEager<T> = ExtractEagerProps<T> & string;
|
|
982
1020
|
export type ExpandHint<T, L extends string> = L | AddEager<T>;
|
|
983
1021
|
export type Selected<T, L extends string = never, F extends string = '*'> = {
|
|
984
|
-
[K in keyof T as IsPrefixed<T, K, L | F | AddEager<T>>]: LoadedProp<NonNullable<T[K]>, Suffix<K, L, true>, Suffix<K, F, true>> | AddOptional<T[K]>;
|
|
985
|
-
} & {
|
|
986
|
-
[K in keyof T as FunctionKeys<T, K>]: T[K];
|
|
1022
|
+
[K in keyof T as IsPrefixed<T, K, L | F | AddEager<T>> | FunctionKeys<T, K>]: T[K] extends Function ? T[K] : NonNullable<T[K]> extends Scalar ? T[K] : LoadedProp<NonNullable<T[K]>, Suffix<K, L, true>, Suffix<K, F, true>> | AddOptional<T[K]>;
|
|
987
1023
|
} & {
|
|
988
1024
|
[__selectedType]?: T;
|
|
989
1025
|
};
|
|
@@ -1056,6 +1092,10 @@ export interface ISeedManager {
|
|
|
1056
1092
|
export interface Seeder<T extends Dictionary = Dictionary> {
|
|
1057
1093
|
run(em: EntityManager, context?: T): void | Promise<void>;
|
|
1058
1094
|
}
|
|
1095
|
+
export interface SeederObject {
|
|
1096
|
+
name: string;
|
|
1097
|
+
class: Constructor<Seeder>;
|
|
1098
|
+
}
|
|
1059
1099
|
export type ConnectionType = 'read' | 'write';
|
|
1060
1100
|
export type MetadataProcessor = (metadata: EntityMetadata[], platform: Platform) => MaybePromise<void>;
|
|
1061
1101
|
export type MaybeReturnType<T> = T extends (...args: any[]) => infer R ? R : T;
|
package/typings.js
CHANGED
|
@@ -11,6 +11,8 @@ export const OptionalProps = Symbol('OptionalProps');
|
|
|
11
11
|
export const EagerProps = Symbol('EagerProps');
|
|
12
12
|
export const HiddenProps = Symbol('HiddenProps');
|
|
13
13
|
export const Config = Symbol('Config');
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
15
|
+
export const EntityName = Symbol('EntityName');
|
|
14
16
|
export class EntityMetadata {
|
|
15
17
|
static counter = 0;
|
|
16
18
|
_id = 1000 * EntityMetadata.counter++; // keep the id >= 1000 to allow computing cache keys by simple addition
|
|
@@ -272,7 +272,7 @@ export class ChangeSetPersister {
|
|
|
272
272
|
return this.driver.nativeUpdate(changeSet.meta.class, cond, changeSet.payload, options);
|
|
273
273
|
}
|
|
274
274
|
if (meta.versionProperty) {
|
|
275
|
-
cond[meta.versionProperty] = this.platform.
|
|
275
|
+
cond[meta.versionProperty] = this.platform.convertVersionValue(changeSet.entity[meta.versionProperty], meta.properties[meta.versionProperty]);
|
|
276
276
|
}
|
|
277
277
|
this.checkConcurrencyKeys(meta, changeSet, cond);
|
|
278
278
|
return this.driver.nativeUpdate(changeSet.meta.class, cond, changeSet.payload, options);
|
|
@@ -287,7 +287,7 @@ export class ChangeSetPersister {
|
|
|
287
287
|
const cond = Utils.getPrimaryKeyCond(cs.originalEntity, meta.primaryKeys.concat(...meta.concurrencyCheckKeys));
|
|
288
288
|
if (meta.versionProperty) {
|
|
289
289
|
// @ts-ignore
|
|
290
|
-
cond[meta.versionProperty] = this.platform.
|
|
290
|
+
cond[meta.versionProperty] = this.platform.convertVersionValue(cs.entity[meta.versionProperty], meta.properties[meta.versionProperty]);
|
|
291
291
|
}
|
|
292
292
|
return cond;
|
|
293
293
|
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { Constructor, IMigrationGenerator, IMigrationRunner, IMigrator, IMigratorStorage, MaybePromise, Migration, MigrationInfo, MigrationRow, MigratorEvent } from '../typings.js';
|
|
2
|
+
import type { Transaction } from '../connections/Connection.js';
|
|
3
|
+
import type { Configuration, MigrationsOptions } from './Configuration.js';
|
|
4
|
+
import type { EntityManagerType, IDatabaseDriver } from '../drivers/IDatabaseDriver.js';
|
|
5
|
+
interface RunnableMigration {
|
|
6
|
+
name: string;
|
|
7
|
+
path?: string;
|
|
8
|
+
up: () => MaybePromise<void>;
|
|
9
|
+
down: () => MaybePromise<void>;
|
|
10
|
+
}
|
|
11
|
+
type MigrateOptions = {
|
|
12
|
+
from?: string | number;
|
|
13
|
+
to?: string | number;
|
|
14
|
+
migrations?: string[];
|
|
15
|
+
transaction?: Transaction;
|
|
16
|
+
};
|
|
17
|
+
export declare abstract class AbstractMigrator<D extends IDatabaseDriver> implements IMigrator {
|
|
18
|
+
protected readonly em: D[typeof EntityManagerType];
|
|
19
|
+
protected runner: IMigrationRunner;
|
|
20
|
+
protected storage: IMigratorStorage;
|
|
21
|
+
protected generator: IMigrationGenerator;
|
|
22
|
+
protected readonly driver: D;
|
|
23
|
+
protected readonly config: Configuration;
|
|
24
|
+
protected readonly options: MigrationsOptions;
|
|
25
|
+
protected absolutePath: string;
|
|
26
|
+
protected initialized: boolean;
|
|
27
|
+
private readonly listeners;
|
|
28
|
+
constructor(em: D[typeof EntityManagerType]);
|
|
29
|
+
protected abstract createRunner(): IMigrationRunner;
|
|
30
|
+
protected abstract createStorage(): IMigratorStorage;
|
|
31
|
+
protected abstract getDefaultGenerator(): IMigrationGenerator;
|
|
32
|
+
abstract create(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<{
|
|
33
|
+
fileName: string;
|
|
34
|
+
code: string;
|
|
35
|
+
diff: {
|
|
36
|
+
up: string[];
|
|
37
|
+
down: string[];
|
|
38
|
+
};
|
|
39
|
+
}>;
|
|
40
|
+
abstract checkSchema(): Promise<boolean>;
|
|
41
|
+
abstract createInitial(path?: string, name?: string, blank?: boolean): Promise<{
|
|
42
|
+
fileName: string;
|
|
43
|
+
code: string;
|
|
44
|
+
diff: {
|
|
45
|
+
up: string[];
|
|
46
|
+
down: string[];
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* @inheritDoc
|
|
51
|
+
*/
|
|
52
|
+
on(eventName: MigratorEvent, listener: (event: MigrationInfo) => MaybePromise<void>): this;
|
|
53
|
+
/**
|
|
54
|
+
* @inheritDoc
|
|
55
|
+
*/
|
|
56
|
+
off(eventName: MigratorEvent, listener: (event: MigrationInfo) => MaybePromise<void>): this;
|
|
57
|
+
/**
|
|
58
|
+
* @inheritDoc
|
|
59
|
+
*/
|
|
60
|
+
getExecuted(): Promise<MigrationRow[]>;
|
|
61
|
+
/**
|
|
62
|
+
* @inheritDoc
|
|
63
|
+
*/
|
|
64
|
+
getPending(): Promise<MigrationInfo[]>;
|
|
65
|
+
/**
|
|
66
|
+
* @inheritDoc
|
|
67
|
+
*/
|
|
68
|
+
up(options?: string | string[] | MigrateOptions): Promise<MigrationInfo[]>;
|
|
69
|
+
/**
|
|
70
|
+
* @inheritDoc
|
|
71
|
+
*/
|
|
72
|
+
down(options?: string | string[] | Omit<MigrateOptions, 'from'>): Promise<MigrationInfo[]>;
|
|
73
|
+
abstract getStorage(): IMigratorStorage;
|
|
74
|
+
protected init(): Promise<void>;
|
|
75
|
+
protected initServices(): void;
|
|
76
|
+
protected resolve(params: {
|
|
77
|
+
name: string;
|
|
78
|
+
path: string;
|
|
79
|
+
}): RunnableMigration;
|
|
80
|
+
protected initialize(MigrationClass: Constructor<Migration>, name: string): RunnableMigration;
|
|
81
|
+
/**
|
|
82
|
+
* Checks if `src` folder exists, it so, tries to adjust the migrations and seeders paths automatically to use it.
|
|
83
|
+
* If there is a `dist` or `build` folder, it will be used for the JS variant (`path` option), while the `src` folder will be
|
|
84
|
+
* used for the TS variant (`pathTs` option).
|
|
85
|
+
*
|
|
86
|
+
* If the default folder exists (e.g. `/migrations`), the config will respect that, so this auto-detection should not
|
|
87
|
+
* break existing projects, only help with the new ones.
|
|
88
|
+
*/
|
|
89
|
+
private detectSourceFolder;
|
|
90
|
+
private registerDefaultListeners;
|
|
91
|
+
private emit;
|
|
92
|
+
private discoverMigrations;
|
|
93
|
+
private executeMigrations;
|
|
94
|
+
private filterUp;
|
|
95
|
+
private filterDown;
|
|
96
|
+
private getMigrationFilename;
|
|
97
|
+
private prefix;
|
|
98
|
+
private runMigrations;
|
|
99
|
+
private runInTransaction;
|
|
100
|
+
}
|
|
101
|
+
export {};
|