@mikro-orm/core 7.0.0-dev.62 → 7.0.0-dev.64

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.
Files changed (60) hide show
  1. package/MikroORM.js +0 -7
  2. package/entity/defineEntity.d.ts +2 -8
  3. package/enums.d.ts +2 -0
  4. package/index.d.ts +1 -2
  5. package/index.js +0 -1
  6. package/metadata/EntitySchema.d.ts +1 -9
  7. package/metadata/MetadataDiscovery.js +1 -4
  8. package/metadata/MetadataProvider.d.ts +2 -2
  9. package/metadata/MetadataProvider.js +15 -0
  10. package/metadata/index.d.ts +1 -1
  11. package/metadata/index.js +1 -1
  12. package/metadata/types.d.ts +480 -0
  13. package/metadata/types.js +1 -0
  14. package/package.json +2 -3
  15. package/typings.d.ts +2 -10
  16. package/utils/Configuration.d.ts +5 -11
  17. package/utils/Configuration.js +3 -5
  18. package/utils/ConfigurationLoader.js +6 -3
  19. package/utils/Utils.d.ts +0 -4
  20. package/utils/Utils.js +0 -8
  21. package/decorators/Check.d.ts +0 -3
  22. package/decorators/Check.js +0 -13
  23. package/decorators/CreateRequestContext.d.ts +0 -3
  24. package/decorators/CreateRequestContext.js +0 -32
  25. package/decorators/Embeddable.d.ts +0 -10
  26. package/decorators/Embeddable.js +0 -11
  27. package/decorators/Embedded.d.ts +0 -12
  28. package/decorators/Embedded.js +0 -18
  29. package/decorators/Entity.d.ts +0 -35
  30. package/decorators/Entity.js +0 -12
  31. package/decorators/Enum.d.ts +0 -9
  32. package/decorators/Enum.js +0 -16
  33. package/decorators/Filter.d.ts +0 -2
  34. package/decorators/Filter.js +0 -8
  35. package/decorators/Formula.d.ts +0 -4
  36. package/decorators/Formula.js +0 -15
  37. package/decorators/Indexed.d.ts +0 -19
  38. package/decorators/Indexed.js +0 -20
  39. package/decorators/ManyToMany.d.ts +0 -42
  40. package/decorators/ManyToMany.js +0 -14
  41. package/decorators/ManyToOne.d.ts +0 -34
  42. package/decorators/ManyToOne.js +0 -14
  43. package/decorators/OneToMany.d.ts +0 -28
  44. package/decorators/OneToMany.js +0 -17
  45. package/decorators/OneToOne.d.ts +0 -28
  46. package/decorators/OneToOne.js +0 -7
  47. package/decorators/PrimaryKey.d.ts +0 -8
  48. package/decorators/PrimaryKey.js +0 -20
  49. package/decorators/Property.d.ts +0 -294
  50. package/decorators/Property.js +0 -32
  51. package/decorators/Transactional.d.ts +0 -15
  52. package/decorators/Transactional.js +0 -31
  53. package/decorators/hooks.d.ts +0 -16
  54. package/decorators/hooks.js +0 -47
  55. package/decorators/index.d.ts +0 -17
  56. package/decorators/index.js +0 -17
  57. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  58. package/metadata/ReflectMetadataProvider.js +0 -44
  59. package/utils/resolveContextProvider.d.ts +0 -10
  60. package/utils/resolveContextProvider.js +0 -28
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-dev.62",
4
+ "version": "7.0.0-dev.64",
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",
@@ -52,8 +52,7 @@
52
52
  "access": "public"
53
53
  },
54
54
  "dependencies": {
55
- "mikro-orm": "7.0.0-dev.62",
56
- "reflect-metadata": "0.2.2"
55
+ "mikro-orm": "7.0.0-dev.64"
57
56
  },
58
57
  "peerDependencies": {
59
58
  "dataloader": "2.2.3"
package/typings.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Transaction } from './connections/Connection.js';
2
- import { type Cascade, type DeferMode, type EventType, type LoadStrategy, type PopulatePath, type QueryOrderMap, ReferenceKind } from './enums.js';
2
+ import { type Cascade, type DeferMode, type EventType, type LoadStrategy, type PopulatePath, type QueryOrderMap, ReferenceKind, type EmbeddedPrefixMode } from './enums.js';
3
3
  import { type AssignOptions } from './entity/EntityAssigner.js';
4
4
  import { type EntityIdentifier } from './entity/EntityIdentifier.js';
5
5
  import { type EntityLoaderOptions } from './entity/EntityLoader.js';
@@ -7,7 +7,6 @@ import { type Collection } from './entity/Collection.js';
7
7
  import { type EntityFactory } from './entity/EntityFactory.js';
8
8
  import { type EntityRepository } from './entity/EntityRepository.js';
9
9
  import { Reference, type ScalarReference } from './entity/Reference.js';
10
- import type { MikroORM } from './MikroORM.js';
11
10
  import type { SerializationContext } from './serialization/SerializationContext.js';
12
11
  import type { SerializeOptions } from './serialization/EntitySerializer.js';
13
12
  import type { MetadataStorage } from './metadata/MetadataStorage.js';
@@ -17,7 +16,6 @@ import type { Platform } from './platforms/Platform.js';
17
16
  import type { Configuration } from './utils/Configuration.js';
18
17
  import type { RawQueryFragment } from './utils/RawQueryFragment.js';
19
18
  import type { EntityManager } from './EntityManager.js';
20
- import type { EmbeddedPrefixMode } from './decorators/Embedded.js';
21
19
  import type { EventSubscriber } from './events/EventSubscriber.js';
22
20
  import type { FilterOptions, FindOneOptions, FindOptions, LoadHint } from './drivers/IDatabaseDriver.js';
23
21
  export type Constructor<T = unknown> = new (...args: any[]) => T;
@@ -150,7 +148,6 @@ export type FilterValue<T> = OperatorMap<FilterItemValue<T>> | FilterItemValue<T
150
148
  export type FilterObject<T> = {
151
149
  -readonly [K in EntityKey<T>]?: ExpandQuery<ExpandProperty<T[K]>> | FilterValue<ExpandProperty<T[K]>> | null;
152
150
  };
153
- export type ExpandObject<T> = T extends object ? T extends Scalar ? never : FilterObject<T> : never;
154
151
  export type ExpandQuery<T> = T extends object ? T extends Scalar ? never : FilterQuery<T> : FilterValue<T>;
155
152
  export type EntityProps<T> = {
156
153
  -readonly [K in EntityKey<T>]?: T[K];
@@ -583,6 +580,7 @@ export interface GenerateOptions {
583
580
  bidirectionalRelations?: boolean;
584
581
  identifiedReferences?: boolean;
585
582
  entityDefinition?: 'decorators' | 'defineEntity' | 'entitySchema';
583
+ decorators?: 'es' | 'legacy';
586
584
  inferEntityType?: boolean;
587
585
  enumMode?: 'ts-enum' | 'union-type' | 'dictionary';
588
586
  esmImport?: boolean;
@@ -847,12 +845,6 @@ export interface Seeder<T extends Dictionary = Dictionary> {
847
845
  }
848
846
  export type ConnectionType = 'read' | 'write';
849
847
  export type MetadataProcessor = (metadata: EntityMetadata[], platform: Platform) => MaybePromise<void>;
850
- /**
851
- * The type of context that the user intends to inject.
852
- */
853
- export type ContextProvider<T> = MaybePromise<MikroORM> | ((type: T) => MaybePromise<MikroORM | EntityManager | EntityRepository<any> | {
854
- getEntityManager(): EntityManager;
855
- }>);
856
848
  export type MaybeReturnType<T> = T extends (...args: any[]) => infer R ? R : T;
857
849
  export interface EntitySchemaWithMeta<TName extends string = string, TTableName extends string = string, TEntity = any, TBase = never, TProperties extends Record<string, any> = Record<string, any>> extends EntitySchema<TEntity, TBase> {
858
850
  readonly name: TName;
@@ -9,15 +9,13 @@ import { type Logger, type LoggerNamespace, type LoggerOptions } from '../loggin
9
9
  import type { EntityManager } from '../EntityManager.js';
10
10
  import type { Platform } from '../platforms/Platform.js';
11
11
  import type { EntitySchema } from '../metadata/EntitySchema.js';
12
- import type { MetadataProvider } from '../metadata/MetadataProvider.js';
12
+ import { MetadataProvider } from '../metadata/MetadataProvider.js';
13
13
  import type { MetadataStorage } from '../metadata/MetadataStorage.js';
14
- import { ReflectMetadataProvider } from '../metadata/ReflectMetadataProvider.js';
15
- import type { EmbeddedPrefixMode } from '../decorators/Embedded.js';
16
14
  import type { EventSubscriber } from '../events/EventSubscriber.js';
17
15
  import type { AssignOptions } from '../entity/EntityAssigner.js';
18
16
  import type { EntityManagerType, IDatabaseDriver } from '../drivers/IDatabaseDriver.js';
19
17
  import { NotFoundError } from '../errors.js';
20
- import { DataloaderType, FlushMode, LoadStrategy, PopulateHint } from '../enums.js';
18
+ import { DataloaderType, FlushMode, LoadStrategy, PopulateHint, type EmbeddedPrefixMode } from '../enums.js';
21
19
  import { MemoryCacheAdapter } from '../cache/MemoryCacheAdapter.js';
22
20
  import { EntityComparator } from './EntityComparator.js';
23
21
  import type { Type } from '../types/Type.js';
@@ -31,13 +29,10 @@ declare const DEFAULTS: {
31
29
  readonly filters: {};
32
30
  readonly discovery: {
33
31
  readonly warnWhenNoEntities: true;
34
- readonly requireEntitiesArray: false;
35
32
  readonly checkDuplicateTableNames: true;
36
33
  readonly checkDuplicateFieldNames: true;
37
34
  readonly checkDuplicateEntities: true;
38
35
  readonly checkNonPersistentCompositeProps: true;
39
- readonly alwaysAnalyseProperties: true;
40
- readonly disableDynamicFileAccess: false;
41
36
  readonly inferDefaultValues: true;
42
37
  };
43
38
  readonly strict: false;
@@ -118,6 +113,7 @@ declare const DEFAULTS: {
118
113
  readonly identifiedReferences: true;
119
114
  readonly scalarPropertiesForRelations: "never";
120
115
  readonly entityDefinition: "defineEntity";
116
+ readonly decorators: "legacy";
121
117
  readonly enumMode: "dictionary";
122
118
  readonly fileName: (className: string) => string;
123
119
  readonly onlyPurePivotTables: false;
@@ -137,7 +133,7 @@ declare const DEFAULTS: {
137
133
  readonly expiration: 1000;
138
134
  readonly options: {};
139
135
  };
140
- readonly metadataProvider: typeof ReflectMetadataProvider;
136
+ readonly metadataProvider: typeof MetadataProvider;
141
137
  readonly highlighter: NullHighlighter;
142
138
  readonly seeder: {
143
139
  readonly path: "./seeders";
@@ -284,18 +280,16 @@ export interface PoolConfig {
284
280
  }
285
281
  export interface MetadataDiscoveryOptions {
286
282
  warnWhenNoEntities?: boolean;
287
- requireEntitiesArray?: boolean;
288
283
  checkDuplicateTableNames?: boolean;
289
284
  checkDuplicateFieldNames?: boolean;
290
285
  checkDuplicateEntities?: boolean;
291
286
  checkNonPersistentCompositeProps?: boolean;
292
- alwaysAnalyseProperties?: boolean;
293
- disableDynamicFileAccess?: boolean;
294
287
  inferDefaultValues?: boolean;
295
288
  getMappedType?: (type: string, platform: Platform) => Type<unknown> | undefined;
296
289
  onMetadata?: (meta: EntityMetadata, platform: Platform) => MaybePromise<void>;
297
290
  afterDiscovered?: (storage: MetadataStorage, platform: Platform) => MaybePromise<void>;
298
291
  tsConfigPath?: string;
292
+ /** @internal */
299
293
  skipSyncDiscovery?: boolean;
300
294
  }
301
295
  export interface Options<Driver extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager<Driver> & Driver[typeof EntityManagerType] = EntityManager<Driver> & Driver[typeof EntityManagerType], Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends ConnectionOptions {
@@ -5,7 +5,7 @@ import { NullHighlighter } from '../utils/NullHighlighter.js';
5
5
  import { DefaultLogger } from '../logging/DefaultLogger.js';
6
6
  import { colors } from '../logging/colors.js';
7
7
  import { Utils } from '../utils/Utils.js';
8
- import { ReflectMetadataProvider } from '../metadata/ReflectMetadataProvider.js';
8
+ import { MetadataProvider } from '../metadata/MetadataProvider.js';
9
9
  import { NotFoundError } from '../errors.js';
10
10
  import { RequestContext } from './RequestContext.js';
11
11
  import { DataloaderType, FlushMode, LoadStrategy, PopulateHint } from '../enums.js';
@@ -20,13 +20,10 @@ const DEFAULTS = {
20
20
  filters: {},
21
21
  discovery: {
22
22
  warnWhenNoEntities: true,
23
- requireEntitiesArray: false,
24
23
  checkDuplicateTableNames: true,
25
24
  checkDuplicateFieldNames: true,
26
25
  checkDuplicateEntities: true,
27
26
  checkNonPersistentCompositeProps: true,
28
- alwaysAnalyseProperties: true,
29
- disableDynamicFileAccess: false,
30
27
  inferDefaultValues: true,
31
28
  },
32
29
  strict: false,
@@ -108,6 +105,7 @@ const DEFAULTS = {
108
105
  identifiedReferences: true,
109
106
  scalarPropertiesForRelations: 'never',
110
107
  entityDefinition: 'defineEntity',
108
+ decorators: 'legacy',
111
109
  enumMode: 'dictionary',
112
110
  fileName: (className) => className,
113
111
  onlyPurePivotTables: false,
@@ -125,7 +123,7 @@ const DEFAULTS = {
125
123
  expiration: 1000, // 1s
126
124
  options: {},
127
125
  },
128
- metadataProvider: ReflectMetadataProvider,
126
+ metadataProvider: MetadataProvider,
129
127
  highlighter: new NullHighlighter(),
130
128
  seeder: {
131
129
  path: './seeders',
@@ -245,9 +245,12 @@ export class ConfigurationLoader {
245
245
  read(ret, 'MIKRO_ORM_COLORS', 'colors', bool);
246
246
  ret.discovery = {};
247
247
  read(ret.discovery, 'MIKRO_ORM_DISCOVERY_WARN_WHEN_NO_ENTITIES', 'warnWhenNoEntities', bool);
248
- read(ret.discovery, 'MIKRO_ORM_DISCOVERY_REQUIRE_ENTITIES_ARRAY', 'requireEntitiesArray', bool);
249
- read(ret.discovery, 'MIKRO_ORM_DISCOVERY_ALWAYS_ANALYSE_PROPERTIES', 'alwaysAnalyseProperties', bool);
250
- read(ret.discovery, 'MIKRO_ORM_DISCOVERY_DISABLE_DYNAMIC_FILE_ACCESS', 'disableDynamicFileAccess', bool);
248
+ read(ret.discovery, 'MIKRO_ORM_DISCOVERY_CHECK_DUPLICATE_TABLE_NAMES', 'checkDuplicateTableNames', bool);
249
+ read(ret.discovery, 'MIKRO_ORM_DISCOVERY_CHECK_DUPLICATE_FIELD_NAMES', 'checkDuplicateFieldNames', bool);
250
+ read(ret.discovery, 'MIKRO_ORM_DISCOVERY_CHECK_DUPLICATE_ENTITIES', 'checkDuplicateEntities', bool);
251
+ read(ret.discovery, 'MIKRO_ORM_DISCOVERY_CHECK_NON_PERSISTENT_COMPOSITE_PROPS', 'checkNonPersistentCompositeProps', bool);
252
+ read(ret.discovery, 'MIKRO_ORM_DISCOVERY_INFER_DEFAULT_VALUES', 'inferDefaultValues', bool);
253
+ read(ret.discovery, 'MIKRO_ORM_DISCOVERY_TS_CONFIG_PATH', 'tsConfigPath');
251
254
  cleanup(ret, 'discovery');
252
255
  ret.migrations = {};
253
256
  read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_TABLE_NAME', 'tableName');
package/utils/Utils.d.ts CHANGED
@@ -227,10 +227,6 @@ export declare class Utils {
227
227
  static getORMVersion(): string;
228
228
  static createFunction(context: Map<string, any>, code: string): any;
229
229
  static callCompiledFunction<T extends unknown[], R>(fn: (...args: T) => R, ...args: T): R;
230
- /**
231
- * @see https://github.com/mikro-orm/mikro-orm/issues/840
232
- */
233
- static propertyDecoratorReturnValue(): any;
234
230
  static unwrapProperty<T>(entity: T, meta: EntityMetadata<T>, prop: EntityProperty<T>, payload?: boolean): [unknown, number[]][];
235
231
  static setPayloadProperty<T>(entity: EntityDictionary<T>, meta: EntityMetadata<T>, prop: EntityProperty<T>, value: unknown, idx: number[]): void;
236
232
  static tryRequire<T extends Dictionary = any>({ module, from, allowError, warning }: {
package/utils/Utils.js CHANGED
@@ -975,14 +975,6 @@ export class Utils {
975
975
  throw e;
976
976
  }
977
977
  }
978
- /**
979
- * @see https://github.com/mikro-orm/mikro-orm/issues/840
980
- */
981
- static propertyDecoratorReturnValue() {
982
- if (process.env.BABEL_DECORATORS_COMPAT) {
983
- return {};
984
- }
985
- }
986
978
  static unwrapProperty(entity, meta, prop, payload = false) {
987
979
  let p = prop;
988
980
  const path = [];
@@ -1,3 +0,0 @@
1
- import type { CheckConstraint, EntityClass } from '../typings.js';
2
- export declare function Check<T>(options: CheckOptions<T>): (target: T, propertyName?: T extends EntityClass<unknown> ? undefined : keyof T) => any;
3
- export type CheckOptions<T = any> = CheckConstraint<T>;
@@ -1,13 +0,0 @@
1
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
- import { Utils } from '../utils/Utils.js';
3
- export function Check(options) {
4
- return function (target, propertyName) {
5
- const meta = MetadataStorage.getMetadataFromDecorator((propertyName ? target.constructor : target));
6
- options.property ??= propertyName;
7
- meta.checks.push(options);
8
- if (!propertyName) {
9
- return target;
10
- }
11
- return Utils.propertyDecoratorReturnValue();
12
- };
13
- }
@@ -1,3 +0,0 @@
1
- import type { ContextProvider } from '../typings.js';
2
- export declare function CreateRequestContext<T extends object>(context?: ContextProvider<T>, respectExistingContext?: boolean): MethodDecorator;
3
- export declare function EnsureRequestContext<T extends object>(context?: ContextProvider<T>): MethodDecorator;
@@ -1,32 +0,0 @@
1
- import { RequestContext } from '../utils/RequestContext.js';
2
- import { resolveContextProvider } from '../utils/resolveContextProvider.js';
3
- import { TransactionContext } from '../utils/TransactionContext.js';
4
- export function CreateRequestContext(context, respectExistingContext = false) {
5
- return function (target, propertyKey, descriptor) {
6
- const originalMethod = descriptor.value;
7
- const name = respectExistingContext ? 'EnsureRequestContext' : 'CreateRequestContext';
8
- if (originalMethod.constructor.name !== 'AsyncFunction') {
9
- throw new Error(`@${name}() should be use with async functions`);
10
- }
11
- descriptor.value = async function (...args) {
12
- const em = await resolveContextProvider(this, context);
13
- if (!em) {
14
- throw new Error(`@${name}() decorator can only be applied to methods of classes with \`orm: MikroORM\` property, \`em: EntityManager\` property, or with a callback parameter like \`@${name}(() => orm)\` that returns one of those types. The parameter will contain a reference to current \`this\`. Returning an EntityRepository from it is also supported.`);
15
- }
16
- // reuse existing context if available for given respect `contextName`
17
- if (respectExistingContext && RequestContext.getEntityManager(em.name)) {
18
- return originalMethod.apply(this, args);
19
- }
20
- // Otherwise, the outer tx context would be preferred.
21
- const txContext = TransactionContext.currentTransactionContext();
22
- const provider = txContext ? TransactionContext : RequestContext;
23
- return txContext
24
- ? provider.create(em.fork({ useContext: true }), () => originalMethod.apply(this, args))
25
- : provider.create(em, () => originalMethod.apply(this, args));
26
- };
27
- return descriptor;
28
- };
29
- }
30
- export function EnsureRequestContext(context) {
31
- return CreateRequestContext(context, true);
32
- }
@@ -1,10 +0,0 @@
1
- import type { AnyString, Dictionary, EntityClass } from '../typings.js';
2
- export declare function Embeddable<T>(options?: EmbeddableOptions<T>): (target: T) => T;
3
- export interface EmbeddableOptions<T> {
4
- /** Specify constructor parameters to be used in `em.create` or when `forceConstructor` is enabled. Those should be names of declared entity properties in the same order as your constructor uses them. The ORM tries to infer those automatically, use this option in case the inference fails. */
5
- constructorParams?: (T extends EntityClass<infer P> ? keyof P : string)[];
6
- discriminatorColumn?: (T extends EntityClass<infer P> ? keyof P : string) | AnyString;
7
- discriminatorMap?: Dictionary<string>;
8
- discriminatorValue?: number | string;
9
- abstract?: boolean;
10
- }
@@ -1,11 +0,0 @@
1
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
- export function Embeddable(options = {}) {
3
- return function (target) {
4
- const meta = MetadataStorage.getMetadataFromDecorator(target);
5
- meta.class = target;
6
- meta.name = meta.class.name;
7
- meta.embeddable = true;
8
- Object.assign(meta, options);
9
- return target;
10
- };
11
- }
@@ -1,12 +0,0 @@
1
- import type { AnyEntity, EntityName } from '../typings.js';
2
- import type { PropertyOptions } from './Property.js';
3
- export declare function Embedded<Owner extends object, Target>(type?: EmbeddedOptions<Owner, Target> | (() => EntityName<Target> | EntityName<Target>[]), options?: EmbeddedOptions<Owner, Target>): (target: AnyEntity, propertyName: string) => any;
4
- /** With `absolute` the prefix is set at the root of the entity (regardless of the nesting level) */
5
- export type EmbeddedPrefixMode = 'absolute' | 'relative';
6
- export interface EmbeddedOptions<Owner, Target> extends PropertyOptions<Owner> {
7
- entity?: string | (() => EntityName<Target> | EntityName<Target>[]);
8
- prefix?: string | boolean;
9
- prefixMode?: EmbeddedPrefixMode;
10
- object?: boolean;
11
- array?: boolean;
12
- }
@@ -1,18 +0,0 @@
1
- import { MetadataValidator } from '../metadata/MetadataValidator.js';
2
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
3
- import { Utils } from '../utils/Utils.js';
4
- import { ReferenceKind } from '../enums.js';
5
- export function Embedded(type = {}, options = {}) {
6
- return function (target, propertyName) {
7
- const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
8
- MetadataValidator.validateSingleDecorator(meta, propertyName, ReferenceKind.EMBEDDED);
9
- options = type instanceof Function ? { entity: type, ...options } : { ...type, ...options };
10
- Utils.defaultValue(options, 'prefix', true);
11
- meta.properties[propertyName] = {
12
- name: propertyName,
13
- kind: ReferenceKind.EMBEDDED,
14
- ...options,
15
- };
16
- return Utils.propertyDecoratorReturnValue();
17
- };
18
- }
@@ -1,35 +0,0 @@
1
- import type { AnyString, Constructor, Dictionary, EntityClass, ObjectQuery } from '../typings.js';
2
- import type { FindOptions } from '../drivers/IDatabaseDriver.js';
3
- export declare function Entity<T extends EntityClass<unknown>>(options?: EntityOptions<T>): (target: T) => void;
4
- export type EntityOptions<T, E = T extends EntityClass<infer P> ? P : T> = {
5
- /** Override default collection/table name. Alias for `collection`. */
6
- tableName?: string;
7
- /** Sets the schema name. */
8
- schema?: string;
9
- /** Override default collection/table name. Alias for `tableName`. */
10
- collection?: string;
11
- /** For {@doclink inheritance-mapping#single-table-inheritance | Single Table Inheritance}. */
12
- discriminatorColumn?: (T extends EntityClass<infer P> ? keyof P : string) | AnyString;
13
- /** For {@doclink inheritance-mapping#single-table-inheritance | Single Table Inheritance}. */
14
- discriminatorMap?: Dictionary<string>;
15
- /** For {@doclink inheritance-mapping#single-table-inheritance | Single Table Inheritance}. */
16
- discriminatorValue?: number | string;
17
- /** Enforce use of constructor when creating managed entity instances. */
18
- forceConstructor?: boolean;
19
- /** Specify constructor parameters to be used in `em.create` or when `forceConstructor` is enabled. Those should be names of declared entity properties in the same order as your constructor uses them. The ORM tries to infer those automatically, use this option in case the inference fails. */
20
- constructorParams?: (T extends EntityClass<infer P> ? keyof P : string)[];
21
- /** Specify comment to table. (SQL only) */
22
- comment?: string;
23
- /** Marks entity as abstract, such entities are inlined during discovery. */
24
- abstract?: boolean;
25
- /** Disables change tracking - such entities are ignored during flush. */
26
- readonly?: boolean;
27
- /** Marks entity as {@doclink virtual-entities | virtual}. This is set automatically when you use `expression` option. */
28
- virtual?: boolean;
29
- /** Used to make ORM aware of externally defined triggers. This is needed for MS SQL Server multi inserts, ignored in other dialects. */
30
- hasTriggers?: boolean;
31
- /** SQL query that maps to a {@doclink virtual-entities | virtual entity}. */
32
- expression?: string | ((em: any, where: ObjectQuery<E>, options: FindOptions<E, any, any, any>, stream?: boolean) => object);
33
- /** Set {@doclink repositories#custom-repository | custom repository class}. */
34
- repository?: () => Constructor;
35
- };
@@ -1,12 +0,0 @@
1
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
- import { Utils } from '../utils/Utils.js';
3
- export function Entity(options = {}) {
4
- return function (target) {
5
- const meta = MetadataStorage.getMetadataFromDecorator(target);
6
- Utils.mergeConfig(meta, options);
7
- meta.class = target;
8
- if (!options.abstract || meta.discriminatorColumn) {
9
- meta.name = target.name;
10
- }
11
- };
12
- }
@@ -1,9 +0,0 @@
1
- import type { PropertyOptions } from './Property.js';
2
- import type { AnyEntity, Dictionary } from '../typings.js';
3
- export declare function Enum<T extends object>(options?: EnumOptions<AnyEntity> | (() => Dictionary)): (target: T, propertyName: string) => any;
4
- export interface EnumOptions<T> extends PropertyOptions<T> {
5
- items?: (number | string)[] | (() => Dictionary);
6
- array?: boolean;
7
- /** for postgres, by default it uses text column with check constraint */
8
- nativeEnumName?: string;
9
- }
@@ -1,16 +0,0 @@
1
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
- import { ReferenceKind } from '../enums.js';
3
- import { Utils } from '../utils/Utils.js';
4
- export function Enum(options = {}) {
5
- return function (target, propertyName) {
6
- const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
7
- options = options instanceof Function ? { items: options } : options;
8
- meta.properties[propertyName] = {
9
- name: propertyName,
10
- kind: ReferenceKind.SCALAR,
11
- enum: true,
12
- ...options,
13
- };
14
- return Utils.propertyDecoratorReturnValue();
15
- };
16
- }
@@ -1,2 +0,0 @@
1
- import type { Dictionary, FilterDef } from '../typings.js';
2
- export declare function Filter<T>(options: FilterDef): <U>(target: U & Dictionary) => U & Dictionary;
@@ -1,8 +0,0 @@
1
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
- export function Filter(options) {
3
- return function (target) {
4
- const meta = MetadataStorage.getMetadataFromDecorator(target);
5
- meta.filters[options.name] = options;
6
- return target;
7
- };
8
- }
@@ -1,4 +0,0 @@
1
- import type { PropertyOptions } from './Property.js';
2
- export declare function Formula<T extends object>(formula: string | ((alias: string) => string), options?: FormulaOptions<T>): (target: T, propertyName: string) => any;
3
- export interface FormulaOptions<T> extends PropertyOptions<T> {
4
- }
@@ -1,15 +0,0 @@
1
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
- import { ReferenceKind } from '../enums.js';
3
- import { Utils } from '../utils/Utils.js';
4
- export function Formula(formula, options = {}) {
5
- return function (target, propertyName) {
6
- const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
7
- meta.properties[propertyName] = {
8
- name: propertyName,
9
- kind: ReferenceKind.SCALAR,
10
- formula,
11
- ...options,
12
- };
13
- return Utils.propertyDecoratorReturnValue();
14
- };
15
- }
@@ -1,19 +0,0 @@
1
- import type { EntityClass, Dictionary, AutoPath, IndexCallback } from '../typings.js';
2
- import type { DeferMode } from '../enums.js';
3
- export declare function Index<T extends object, H extends string>(options?: IndexOptions<T, H>): (target: T, propertyName?: (T extends EntityClass<unknown> ? undefined : keyof T) | undefined) => any;
4
- export declare function Unique<T extends object, H extends string>(options?: UniqueOptions<T, H>): (target: T, propertyName?: (T extends EntityClass<unknown> ? undefined : keyof T) | undefined) => any;
5
- type MaybeArray<T> = T | T[];
6
- type Properties<T, H extends string> = MaybeArray<AutoPath<T, H>>;
7
- interface BaseOptions<T, H extends string> {
8
- name?: string;
9
- properties?: (T extends EntityClass<infer P> ? Properties<P, H> : Properties<T, H>);
10
- options?: Dictionary;
11
- expression?: string | (T extends EntityClass<infer P> ? IndexCallback<P> : IndexCallback<T>);
12
- }
13
- export interface UniqueOptions<T, H extends string = string> extends BaseOptions<T, H> {
14
- deferMode?: DeferMode | `${DeferMode}`;
15
- }
16
- export interface IndexOptions<T, H extends string = string> extends BaseOptions<T, H> {
17
- type?: string;
18
- }
19
- export {};
@@ -1,20 +0,0 @@
1
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
- import { Utils } from '../utils/Utils.js';
3
- function createDecorator(options, unique) {
4
- return function (target, propertyName) {
5
- const meta = MetadataStorage.getMetadataFromDecorator(propertyName ? target.constructor : target);
6
- options.properties ??= propertyName;
7
- const key = unique ? 'uniques' : 'indexes';
8
- meta[key].push(options);
9
- if (!propertyName) {
10
- return target;
11
- }
12
- return Utils.propertyDecoratorReturnValue();
13
- };
14
- }
15
- export function Index(options = {}) {
16
- return createDecorator(options, false);
17
- }
18
- export function Unique(options = {}) {
19
- return createDecorator(options, true);
20
- }
@@ -1,42 +0,0 @@
1
- import type { ReferenceOptions } from './Property.js';
2
- import type { EntityName, FilterQuery, AnyString } from '../typings.js';
3
- import { type QueryOrderMap } from '../enums.js';
4
- export declare function ManyToMany<Target extends object, Owner extends object>(entity?: ManyToManyOptions<Owner, Target> | string | (() => EntityName<Target>), mappedBy?: (string & keyof Target) | ((e: Target) => any), options?: Partial<ManyToManyOptions<Owner, Target>>): (target: Owner, propertyName: keyof Owner) => any;
5
- export interface ManyToManyOptions<Owner, Target> extends ReferenceOptions<Owner, Target> {
6
- /** 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. */
7
- owner?: boolean;
8
- /** Point to the inverse side property name. */
9
- inversedBy?: (string & keyof Target) | ((e: Target) => any);
10
- /** Point to the owning side property name. */
11
- mappedBy?: (string & keyof Target) | ((e: Target) => any);
12
- /** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
13
- where?: FilterQuery<Target>;
14
- /** Set default ordering. */
15
- orderBy?: QueryOrderMap<Target> | QueryOrderMap<Target>[];
16
- /** Force stable insertion order of items in the collection (see {@doclink collections | Collections}). */
17
- fixedOrder?: boolean;
18
- /** Override default order column name (`id`) for fixed ordering. */
19
- fixedOrderColumn?: string;
20
- /** Override default name for pivot table (see {@doclink naming-strategy | Naming Strategy}). */
21
- pivotTable?: string;
22
- /** Set pivot entity for this relation (see {@doclink collections#custom-pivot-table-entity | Custom pivot table entity}). */
23
- pivotEntity?: string | (() => EntityName<any>);
24
- /** 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. */
25
- joinColumn?: string;
26
- /** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
27
- joinColumns?: string[];
28
- /** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
29
- inverseJoinColumn?: string;
30
- /** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
31
- inverseJoinColumns?: string[];
32
- /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
33
- referenceColumnName?: string;
34
- /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
35
- referencedColumnNames?: string[];
36
- /** What to do when the target entity gets deleted. */
37
- deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
38
- /** What to do when the reference to the target entity gets updated. */
39
- updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
40
- /** Enable/disable foreign key constraint creation on this relation */
41
- createForeignKeyConstraint?: boolean;
42
- }
@@ -1,14 +0,0 @@
1
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
- import { MetadataValidator } from '../metadata/MetadataValidator.js';
3
- import { Utils } from '../utils/Utils.js';
4
- import { ReferenceKind } from '../enums.js';
5
- export function ManyToMany(entity, mappedBy, options = {}) {
6
- return function (target, propertyName) {
7
- options = Utils.processDecoratorParameters({ entity, mappedBy, options });
8
- const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
9
- MetadataValidator.validateSingleDecorator(meta, propertyName, ReferenceKind.MANY_TO_MANY);
10
- const property = { name: propertyName, kind: ReferenceKind.MANY_TO_MANY };
11
- meta.properties[propertyName] = Object.assign(meta.properties[propertyName] ?? {}, property, options);
12
- return Utils.propertyDecoratorReturnValue();
13
- };
14
- }
@@ -1,34 +0,0 @@
1
- import type { ReferenceOptions } from './Property.js';
2
- import { type DeferMode } from '../enums.js';
3
- import type { AnyString, EntityName } from '../typings.js';
4
- export declare function ManyToOne<Target extends object, Owner extends object>(entity?: ManyToOneOptions<Owner, Target> | string | ((e?: any) => EntityName<Target>), options?: Partial<ManyToOneOptions<Owner, Target>>): (target: Owner, propertyName: keyof Owner) => any;
5
- export interface ManyToOneOptions<Owner, Target> extends ReferenceOptions<Owner, Target> {
6
- /** Point to the inverse side property name. */
7
- inversedBy?: (string & keyof Target) | ((e: Target) => any);
8
- /** Wrap the entity in {@apilink Reference} wrapper. */
9
- ref?: boolean;
10
- /** Use this relation as a primary key. */
11
- primary?: boolean;
12
- /** Map this relation to the primary key value instead of an entity. */
13
- mapToPk?: boolean;
14
- /** 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. */
15
- joinColumn?: string;
16
- /** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
17
- joinColumns?: string[];
18
- /** When a part of a composite column is shared in other properties, use this option to specify what columns are considered as owned by this property. This is useful when your composite property is nullable, but parts of it are not. */
19
- ownColumns?: string[];
20
- /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
21
- referenceColumnName?: string;
22
- /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
23
- referencedColumnNames?: string[];
24
- /** What to do when the target entity gets deleted. */
25
- deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
26
- /** What to do when the reference to the target entity gets updated. */
27
- updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
28
- /** 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. */
29
- deferMode?: DeferMode | `${DeferMode}`;
30
- /** Enable/disable foreign key constraint creation on this relation */
31
- createForeignKeyConstraint?: boolean;
32
- /** Set a custom foreign key constraint name, overriding NamingStrategy.indexName(). */
33
- foreignKeyName?: string;
34
- }
@@ -1,14 +0,0 @@
1
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
- import { MetadataValidator } from '../metadata/MetadataValidator.js';
3
- import { Utils } from '../utils/Utils.js';
4
- import { ReferenceKind } from '../enums.js';
5
- export function ManyToOne(entity = {}, options = {}) {
6
- return function (target, propertyName) {
7
- options = Utils.processDecoratorParameters({ entity, options });
8
- const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
9
- MetadataValidator.validateSingleDecorator(meta, propertyName, ReferenceKind.MANY_TO_ONE);
10
- const property = { name: propertyName, kind: ReferenceKind.MANY_TO_ONE };
11
- meta.properties[propertyName] = Object.assign(meta.properties[propertyName] ?? {}, property, options);
12
- return Utils.propertyDecoratorReturnValue();
13
- };
14
- }