@mikro-orm/decorators 7.0.2-dev.9 → 7.0.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/README.md +128 -294
- package/es/Check.d.ts +4 -1
- package/es/Check.js +7 -6
- package/es/CreateRequestContext.d.ts +15 -2
- package/es/CreateRequestContext.js +26 -22
- package/es/Embeddable.d.ts +4 -1
- package/es/Embeddable.js +10 -9
- package/es/Embedded.d.ts +5 -1
- package/es/Embedded.js +11 -10
- package/es/Entity.d.ts +4 -1
- package/es/Entity.js +10 -9
- package/es/Enum.d.ts +4 -1
- package/es/Enum.js +11 -10
- package/es/Filter.d.ts +1 -0
- package/es/Filter.js +5 -4
- package/es/Formula.d.ts +5 -1
- package/es/Formula.js +10 -9
- package/es/Indexed.d.ts +8 -2
- package/es/Indexed.js +13 -11
- package/es/ManyToMany.d.ts +6 -1
- package/es/ManyToMany.js +9 -8
- package/es/ManyToOne.d.ts +5 -1
- package/es/ManyToOne.js +8 -7
- package/es/OneToMany.d.ts +9 -2
- package/es/OneToMany.js +8 -8
- package/es/OneToOne.d.ts +6 -1
- package/es/OneToOne.js +10 -9
- package/es/PrimaryKey.d.ts +8 -2
- package/es/PrimaryKey.js +14 -12
- package/es/Property.d.ts +12 -1
- package/es/Property.js +38 -41
- package/es/Transactional.d.ts +8 -3
- package/es/Transactional.js +18 -15
- package/es/hooks.d.ts +40 -8
- package/es/hooks.js +25 -17
- package/legacy/Check.d.ts +4 -1
- package/legacy/Check.js +10 -9
- package/legacy/CreateRequestContext.d.ts +6 -1
- package/legacy/CreateRequestContext.js +28 -24
- package/legacy/Embeddable.d.ts +1 -0
- package/legacy/Embeddable.js +9 -8
- package/legacy/Embedded.d.ts +5 -1
- package/legacy/Embedded.js +12 -11
- package/legacy/Entity.d.ts +1 -0
- package/legacy/Entity.js +9 -8
- package/legacy/Enum.d.ts +4 -1
- package/legacy/Enum.js +11 -10
- package/legacy/Filter.d.ts +1 -0
- package/legacy/Filter.js +5 -4
- package/legacy/Formula.d.ts +5 -1
- package/legacy/Formula.js +10 -9
- package/legacy/Indexed.d.ts +8 -2
- package/legacy/Indexed.js +14 -12
- package/legacy/ManyToMany.d.ts +9 -2
- package/legacy/ManyToMany.js +8 -8
- package/legacy/ManyToOne.d.ts +8 -2
- package/legacy/ManyToOne.js +8 -8
- package/legacy/OneToMany.d.ts +9 -2
- package/legacy/OneToMany.js +8 -8
- package/legacy/OneToOne.d.ts +9 -2
- package/legacy/OneToOne.js +10 -10
- package/legacy/PrimaryKey.d.ts +8 -2
- package/legacy/PrimaryKey.js +15 -13
- package/legacy/Property.d.ts +4 -1
- package/legacy/Property.js +26 -25
- package/legacy/ReflectMetadataProvider.d.ts +3 -2
- package/legacy/ReflectMetadataProvider.js +49 -44
- package/legacy/Transactional.d.ts +2 -2
- package/legacy/Transactional.js +20 -17
- package/legacy/hooks.d.ts +8 -0
- package/legacy/hooks.js +23 -15
- package/package.json +3 -3
- package/utils.d.ts +41 -10
- package/utils.js +91 -85
package/es/hooks.js
CHANGED
|
@@ -1,45 +1,53 @@
|
|
|
1
1
|
import { EventType } from '@mikro-orm/core';
|
|
2
2
|
function hook(type) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
3
|
+
return function (value, context) {
|
|
4
|
+
const meta = context.metadata;
|
|
5
|
+
meta.hooks ??= {};
|
|
6
|
+
meta.hooks[type] ??= [];
|
|
7
|
+
meta.hooks[type].push(value);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/** Called before a new entity is persisted to the database (TC39 decorator). */
|
|
10
11
|
export function BeforeCreate() {
|
|
11
|
-
|
|
12
|
+
return hook(EventType.beforeCreate);
|
|
12
13
|
}
|
|
14
|
+
/** Called after a new entity has been persisted to the database (TC39 decorator). */
|
|
13
15
|
export function AfterCreate() {
|
|
14
|
-
|
|
16
|
+
return hook(EventType.afterCreate);
|
|
15
17
|
}
|
|
18
|
+
/** Called before an existing entity is updated in the database (TC39 decorator). */
|
|
16
19
|
export function BeforeUpdate() {
|
|
17
|
-
|
|
20
|
+
return hook(EventType.beforeUpdate);
|
|
18
21
|
}
|
|
22
|
+
/** Called after an existing entity has been updated in the database (TC39 decorator). */
|
|
19
23
|
export function AfterUpdate() {
|
|
20
|
-
|
|
24
|
+
return hook(EventType.afterUpdate);
|
|
21
25
|
}
|
|
26
|
+
/** Called before an entity is upserted (TC39 decorator). */
|
|
22
27
|
export function BeforeUpsert() {
|
|
23
|
-
|
|
28
|
+
return hook(EventType.beforeUpsert);
|
|
24
29
|
}
|
|
30
|
+
/** Called after an entity has been upserted (TC39 decorator). */
|
|
25
31
|
export function AfterUpsert() {
|
|
26
|
-
|
|
32
|
+
return hook(EventType.afterUpsert);
|
|
27
33
|
}
|
|
34
|
+
/** Called when an entity is instantiated by the EntityManager (TC39 decorator). */
|
|
28
35
|
export function OnInit() {
|
|
29
|
-
|
|
36
|
+
return hook(EventType.onInit);
|
|
30
37
|
}
|
|
38
|
+
/** Called after an entity is loaded from the database (TC39 decorator). */
|
|
31
39
|
export function OnLoad() {
|
|
32
|
-
|
|
40
|
+
return hook(EventType.onLoad);
|
|
33
41
|
}
|
|
34
42
|
/**
|
|
35
43
|
* Called before deleting entity, but only when providing initialized entity to EM#remove()
|
|
36
44
|
*/
|
|
37
45
|
export function BeforeDelete() {
|
|
38
|
-
|
|
46
|
+
return hook(EventType.beforeDelete);
|
|
39
47
|
}
|
|
40
48
|
/**
|
|
41
49
|
* Called after deleting entity, but only when providing initialized entity to EM#remove()
|
|
42
50
|
*/
|
|
43
51
|
export function AfterDelete() {
|
|
44
|
-
|
|
52
|
+
return hook(EventType.afterDelete);
|
|
45
53
|
}
|
package/legacy/Check.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { type CheckConstraint, type EntityClass } from '@mikro-orm/core';
|
|
2
|
-
|
|
2
|
+
/** Defines a database check constraint on a property or entity class (legacy TypeScript decorator). */
|
|
3
|
+
export declare function Check<T>(
|
|
4
|
+
options: CheckConstraint<T>,
|
|
5
|
+
): (target: T, propertyName?: T extends EntityClass<unknown> ? undefined : keyof T) => any;
|
package/legacy/Check.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
2
|
+
/** Defines a database check constraint on a property or entity class (legacy TypeScript decorator). */
|
|
2
3
|
export function Check(options) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
return function (target, propertyName) {
|
|
5
|
+
const meta = getMetadataFromDecorator(propertyName ? target.constructor : target);
|
|
6
|
+
options.property ??= propertyName;
|
|
7
|
+
meta.checks.push(options);
|
|
8
|
+
if (!propertyName) {
|
|
9
|
+
return target;
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
};
|
|
12
13
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { type ContextProvider } from '../utils.js';
|
|
2
|
-
|
|
2
|
+
/** Wraps an async method in a new RequestContext, forking the EntityManager (legacy TypeScript decorator). */
|
|
3
|
+
export declare function CreateRequestContext<T extends object>(
|
|
4
|
+
context?: ContextProvider<T>,
|
|
5
|
+
respectExistingContext?: boolean,
|
|
6
|
+
): MethodDecorator;
|
|
7
|
+
/** Like `@CreateRequestContext`, but reuses an existing RequestContext if one is available (legacy TypeScript decorator). */
|
|
3
8
|
export declare function EnsureRequestContext<T extends object>(context?: ContextProvider<T>): MethodDecorator;
|
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
import { RequestContext, TransactionContext } from '@mikro-orm/core';
|
|
2
2
|
import { resolveContextProvider } from '../utils.js';
|
|
3
|
+
/** Wraps an async method in a new RequestContext, forking the EntityManager (legacy TypeScript decorator). */
|
|
3
4
|
export function CreateRequestContext(context, respectExistingContext = false) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
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(
|
|
15
|
+
`@${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.`,
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
// reuse existing context if available for given respect `contextName`
|
|
19
|
+
if (respectExistingContext && RequestContext.getEntityManager(em.name)) {
|
|
20
|
+
return originalMethod.apply(this, args);
|
|
21
|
+
}
|
|
22
|
+
// Otherwise, the outer tx context would be preferred.
|
|
23
|
+
const txContext = TransactionContext.currentTransactionContext();
|
|
24
|
+
const provider = txContext ? TransactionContext : RequestContext;
|
|
25
|
+
return txContext
|
|
26
|
+
? provider.create(em.fork({ useContext: true }), () => originalMethod.apply(this, args))
|
|
27
|
+
: provider.create(em, () => originalMethod.apply(this, args));
|
|
27
28
|
};
|
|
29
|
+
return descriptor;
|
|
30
|
+
};
|
|
28
31
|
}
|
|
32
|
+
/** Like `@CreateRequestContext`, but reuses an existing RequestContext if one is available (legacy TypeScript decorator). */
|
|
29
33
|
export function EnsureRequestContext(context) {
|
|
30
|
-
|
|
34
|
+
return CreateRequestContext(context, true);
|
|
31
35
|
}
|
package/legacy/Embeddable.d.ts
CHANGED
package/legacy/Embeddable.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
2
|
+
/** Marks a class as an embeddable type (legacy TypeScript decorator). */
|
|
2
3
|
export function Embeddable(options = {}) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
return function (target) {
|
|
5
|
+
const meta = getMetadataFromDecorator(target);
|
|
6
|
+
meta.class = target;
|
|
7
|
+
meta.name = meta.class.name;
|
|
8
|
+
meta.embeddable = true;
|
|
9
|
+
Object.assign(meta, options);
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
11
12
|
}
|
package/legacy/Embedded.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { type AnyEntity, type EntityName, type EmbeddedOptions } from '@mikro-orm/core';
|
|
2
|
-
|
|
2
|
+
/** Defines an embedded property on an entity (legacy TypeScript decorator). */
|
|
3
|
+
export declare function Embedded<Owner extends object, Target>(
|
|
4
|
+
type?: EmbeddedOptions<Owner, Target> | (() => EntityName<Target> | EntityName[]),
|
|
5
|
+
options?: EmbeddedOptions<Owner, Target>,
|
|
6
|
+
): (target: AnyEntity, propertyName: string) => void;
|
package/legacy/Embedded.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { ReferenceKind, Utils
|
|
1
|
+
import { ReferenceKind, Utils } from '@mikro-orm/core';
|
|
2
2
|
import { validateSingleDecorator, getMetadataFromDecorator } from '../utils.js';
|
|
3
|
+
/** Defines an embedded property on an entity (legacy TypeScript decorator). */
|
|
3
4
|
export function Embedded(type = {}, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
5
|
+
return function (target, propertyName) {
|
|
6
|
+
const meta = getMetadataFromDecorator(target.constructor);
|
|
7
|
+
validateSingleDecorator(meta, propertyName, ReferenceKind.EMBEDDED);
|
|
8
|
+
options = type instanceof Function ? { entity: type, ...options } : { ...type, ...options };
|
|
9
|
+
Utils.defaultValue(options, 'prefix', true);
|
|
10
|
+
meta.properties[propertyName] = {
|
|
11
|
+
name: propertyName,
|
|
12
|
+
kind: ReferenceKind.EMBEDDED,
|
|
13
|
+
...options,
|
|
14
14
|
};
|
|
15
|
+
};
|
|
15
16
|
}
|
package/legacy/Entity.d.ts
CHANGED
package/legacy/Entity.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Utils } from '@mikro-orm/core';
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
|
+
/** Marks a class as a MikroORM entity (legacy TypeScript decorator). */
|
|
3
4
|
export function Entity(options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
return function (target) {
|
|
6
|
+
const meta = getMetadataFromDecorator(target);
|
|
7
|
+
Utils.mergeConfig(meta, options);
|
|
8
|
+
meta.class = target;
|
|
9
|
+
if (!options.abstract || meta.discriminatorColumn) {
|
|
10
|
+
meta.name = target.name;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
12
13
|
}
|
package/legacy/Enum.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { type EnumOptions, type AnyEntity, type Dictionary } from '@mikro-orm/core';
|
|
2
|
-
|
|
2
|
+
/** Defines an enum property on an entity (legacy TypeScript decorator). */
|
|
3
|
+
export declare function Enum<T extends object>(
|
|
4
|
+
options?: EnumOptions<AnyEntity> | (() => Dictionary),
|
|
5
|
+
): (target: T, propertyName: string) => void;
|
package/legacy/Enum.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
|
+
/** Defines an enum property on an entity (legacy TypeScript decorator). */
|
|
3
4
|
export function Enum(options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
5
|
+
return function (target, propertyName) {
|
|
6
|
+
const meta = 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
13
|
};
|
|
14
|
+
};
|
|
14
15
|
}
|
package/legacy/Filter.d.ts
CHANGED
package/legacy/Filter.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
2
|
+
/** Registers a named filter on an entity class (legacy TypeScript decorator). */
|
|
2
3
|
export function Filter(options) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
return function (target) {
|
|
5
|
+
const meta = getMetadataFromDecorator(target);
|
|
6
|
+
meta.filters[options.name] = options;
|
|
7
|
+
};
|
|
7
8
|
}
|
package/legacy/Formula.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { type FormulaCallback, type PropertyOptions } from '@mikro-orm/core';
|
|
2
|
-
|
|
2
|
+
/** Defines a computed SQL formula property on an entity (legacy TypeScript decorator). */
|
|
3
|
+
export declare function Formula<T extends object>(
|
|
4
|
+
formula: string | FormulaCallback<T>,
|
|
5
|
+
options?: PropertyOptions<T>,
|
|
6
|
+
): (target: T, propertyName: string) => void;
|
package/legacy/Formula.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
|
+
/** Defines a computed SQL formula property on an entity (legacy TypeScript decorator). */
|
|
3
4
|
export function Formula(formula, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
5
|
+
return function (target, propertyName) {
|
|
6
|
+
const meta = getMetadataFromDecorator(target.constructor);
|
|
7
|
+
meta.properties[propertyName] = {
|
|
8
|
+
name: propertyName,
|
|
9
|
+
kind: ReferenceKind.SCALAR,
|
|
10
|
+
formula,
|
|
11
|
+
...options,
|
|
12
12
|
};
|
|
13
|
+
};
|
|
13
14
|
}
|
package/legacy/Indexed.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { type EntityClass, type IndexOptions, type UniqueOptions } from '@mikro-orm/core';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
2
|
+
/** Defines a database index on a property or entity class (legacy TypeScript decorator). */
|
|
3
|
+
export declare function Index<T extends object, H extends string>(
|
|
4
|
+
options?: IndexOptions<T, H>,
|
|
5
|
+
): (target: T, propertyName?: T extends EntityClass<unknown> ? undefined : keyof T) => any;
|
|
6
|
+
/** Defines a unique constraint on a property or entity class (legacy TypeScript decorator). */
|
|
7
|
+
export declare function Unique<T extends object, H extends string>(
|
|
8
|
+
options?: UniqueOptions<T, H>,
|
|
9
|
+
): (target: T, propertyName?: T extends EntityClass<unknown> ? undefined : keyof T) => any;
|
package/legacy/Indexed.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
2
2
|
function createDecorator(options, unique) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
return function (target, propertyName) {
|
|
4
|
+
const meta = getMetadataFromDecorator(propertyName ? target.constructor : target);
|
|
5
|
+
options.properties ??= propertyName;
|
|
6
|
+
const key = unique ? 'uniques' : 'indexes';
|
|
7
|
+
meta[key].push(options);
|
|
8
|
+
if (!propertyName) {
|
|
9
|
+
return target;
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
};
|
|
13
13
|
}
|
|
14
|
+
/** Defines a database index on a property or entity class (legacy TypeScript decorator). */
|
|
14
15
|
export function Index(options = {}) {
|
|
15
|
-
|
|
16
|
+
return createDecorator(options, false);
|
|
16
17
|
}
|
|
18
|
+
/** Defines a unique constraint on a property or entity class (legacy TypeScript decorator). */
|
|
17
19
|
export function Unique(options = {}) {
|
|
18
|
-
|
|
20
|
+
return createDecorator(options, true);
|
|
19
21
|
}
|
package/legacy/ManyToMany.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { type EntityName, type ManyToManyOptions } from '@mikro-orm/core';
|
|
2
|
-
|
|
2
|
+
/** Defines a many-to-many relationship (legacy TypeScript decorator). */
|
|
3
|
+
export declare function ManyToMany<Target extends object, Owner extends object>(
|
|
4
|
+
entity: () => EntityName<Target>,
|
|
5
|
+
mappedBy?: (string & keyof Target) | ((e: Target) => any),
|
|
6
|
+
options?: Partial<ManyToManyOptions<Owner, Target>>,
|
|
7
|
+
): (target: Owner, propertyName: keyof Owner) => void;
|
|
3
8
|
export declare function ManyToMany<Target extends object, Owner extends object>(entity: string, options?: any): never;
|
|
4
|
-
export declare function ManyToMany<Target extends object, Owner extends object>(
|
|
9
|
+
export declare function ManyToMany<Target extends object, Owner extends object>(
|
|
10
|
+
options?: ManyToManyOptions<Owner, Target>,
|
|
11
|
+
): (target: Owner, propertyName: keyof Owner) => void;
|
package/legacy/ManyToMany.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { processDecoratorParameters, validateSingleDecorator, getMetadataFromDecorator } from '../utils.js';
|
|
3
3
|
export function ManyToMany(entity, mappedBy, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
return function (target, propertyName) {
|
|
5
|
+
options = processDecoratorParameters({ entity, mappedBy, options });
|
|
6
|
+
const meta = getMetadataFromDecorator(target.constructor);
|
|
7
|
+
validateSingleDecorator(meta, propertyName, ReferenceKind.MANY_TO_MANY);
|
|
8
|
+
const property = { name: propertyName, kind: ReferenceKind.MANY_TO_MANY };
|
|
9
|
+
meta.properties[propertyName] = Object.assign(meta.properties[propertyName] ?? {}, property, options);
|
|
10
|
+
};
|
|
11
11
|
}
|
package/legacy/ManyToOne.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { type ManyToOneOptions, type EntityName } from '@mikro-orm/core';
|
|
2
|
-
|
|
2
|
+
/** Defines a many-to-one relationship (legacy TypeScript decorator). */
|
|
3
|
+
export declare function ManyToOne<Target extends object, Owner extends object>(
|
|
4
|
+
entity: (e?: any) => EntityName<Target> | EntityName[],
|
|
5
|
+
options?: Partial<ManyToOneOptions<Owner, Target>>,
|
|
6
|
+
): (target: Owner, propertyName: string) => void;
|
|
3
7
|
export declare function ManyToOne<Target extends object, Owner extends object>(entity: string, options?: any): never;
|
|
4
|
-
export declare function ManyToOne<Target extends object, Owner extends object>(
|
|
8
|
+
export declare function ManyToOne<Target extends object, Owner extends object>(
|
|
9
|
+
options?: ManyToOneOptions<Owner, Target>,
|
|
10
|
+
): (target: Owner, propertyName: string) => void;
|
package/legacy/ManyToOne.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { processDecoratorParameters, validateSingleDecorator, getMetadataFromDecorator } from '../utils.js';
|
|
3
3
|
export function ManyToOne(entity = {}, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
return function (target, propertyName) {
|
|
5
|
+
options = processDecoratorParameters({ entity, options });
|
|
6
|
+
const meta = getMetadataFromDecorator(target.constructor);
|
|
7
|
+
validateSingleDecorator(meta, propertyName, ReferenceKind.MANY_TO_ONE);
|
|
8
|
+
const property = { name: propertyName, kind: ReferenceKind.MANY_TO_ONE };
|
|
9
|
+
meta.properties[propertyName] = Object.assign(meta.properties[propertyName] ?? {}, property, options);
|
|
10
|
+
};
|
|
11
11
|
}
|
package/legacy/OneToMany.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { type EntityName, type OneToManyOptions } from '@mikro-orm/core';
|
|
2
|
-
|
|
3
|
-
export declare function OneToMany<Target extends object, Owner extends object>(
|
|
2
|
+
/** Defines a one-to-many relationship (legacy TypeScript decorator). */
|
|
3
|
+
export declare function OneToMany<Target extends object, Owner extends object>(
|
|
4
|
+
entity: (e?: any) => EntityName<Target>,
|
|
5
|
+
mappedBy: (string & keyof Target) | ((e: Target) => any),
|
|
6
|
+
options?: Partial<OneToManyOptions<Owner, Target>>,
|
|
7
|
+
): (target: Owner, propertyName: string) => void;
|
|
8
|
+
export declare function OneToMany<Target extends object, Owner extends object>(
|
|
9
|
+
options: OneToManyOptions<Owner, Target>,
|
|
10
|
+
): (target: Owner, propertyName: string) => void;
|
package/legacy/OneToMany.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { processDecoratorParameters, validateSingleDecorator, getMetadataFromDecorator } from '../utils.js';
|
|
3
3
|
export function OneToMany(entity, mappedBy, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
return function (target, propertyName) {
|
|
5
|
+
options = processDecoratorParameters({ entity, mappedBy, options });
|
|
6
|
+
const meta = getMetadataFromDecorator(target.constructor);
|
|
7
|
+
validateSingleDecorator(meta, propertyName, ReferenceKind.ONE_TO_MANY);
|
|
8
|
+
const property = { name: propertyName, kind: ReferenceKind.ONE_TO_MANY };
|
|
9
|
+
meta.properties[propertyName] = Object.assign(meta.properties[propertyName] ?? {}, property, options);
|
|
10
|
+
};
|
|
11
11
|
}
|
package/legacy/OneToOne.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { type EntityName, type OneToOneOptions } from '@mikro-orm/core';
|
|
2
|
-
|
|
3
|
-
export declare function OneToOne<Target, Owner>(
|
|
2
|
+
/** Defines a one-to-one relationship (legacy TypeScript decorator). */
|
|
3
|
+
export declare function OneToOne<Target, Owner>(
|
|
4
|
+
entity: (e: Owner) => EntityName<Target> | EntityName[],
|
|
5
|
+
mappedByOrOptions?: (string & keyof Target) | ((e: Target) => any) | Partial<OneToOneOptions<Owner, Target>>,
|
|
6
|
+
options?: Partial<OneToOneOptions<Owner, Target>>,
|
|
7
|
+
): (target: Owner, propertyName: string) => void;
|
|
8
|
+
export declare function OneToOne<Target, Owner>(
|
|
9
|
+
entity?: OneToOneOptions<Owner, Target>,
|
|
10
|
+
): (target: Owner, propertyName: string) => void;
|
package/legacy/OneToOne.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { processDecoratorParameters, validateSingleDecorator, getMetadataFromDecorator } from '../utils.js';
|
|
3
3
|
export function OneToOne(entity, mappedByOrOptions, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
const mappedBy = typeof mappedByOrOptions === 'object' ? mappedByOrOptions.mappedBy : mappedByOrOptions;
|
|
5
|
+
options = typeof mappedByOrOptions === 'object' ? { ...mappedByOrOptions, ...options } : options;
|
|
6
|
+
return function (target, propertyName) {
|
|
7
|
+
options = processDecoratorParameters({ entity, mappedBy, options });
|
|
8
|
+
const meta = getMetadataFromDecorator(target.constructor);
|
|
9
|
+
validateSingleDecorator(meta, propertyName, ReferenceKind.ONE_TO_ONE);
|
|
10
|
+
const property = { name: propertyName, kind: ReferenceKind.ONE_TO_ONE };
|
|
11
|
+
meta.properties[propertyName] = Object.assign(meta.properties[propertyName] ?? {}, property, options);
|
|
12
|
+
};
|
|
13
13
|
}
|
package/legacy/PrimaryKey.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { type PrimaryKeyOptions, type SerializedPrimaryKeyOptions } from '@mikro-orm/core';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
2
|
+
/** Marks a property as the primary key of an entity (legacy TypeScript decorator). */
|
|
3
|
+
export declare function PrimaryKey<T extends object>(
|
|
4
|
+
options?: PrimaryKeyOptions<T>,
|
|
5
|
+
): (target: T, propertyName: string) => void;
|
|
6
|
+
/** Marks a property as the serialized form of the primary key, e.g. for MongoDB ObjectId (legacy TypeScript decorator). */
|
|
7
|
+
export declare function SerializedPrimaryKey<T extends object>(
|
|
8
|
+
options?: SerializedPrimaryKeyOptions<T>,
|
|
9
|
+
): (target: T, propertyName: string) => void;
|
package/legacy/PrimaryKey.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { validateSingleDecorator, getMetadataFromDecorator } from '../utils.js';
|
|
3
3
|
function createDecorator(options, serialized) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
4
|
+
return function (target, propertyName) {
|
|
5
|
+
const meta = getMetadataFromDecorator(target.constructor);
|
|
6
|
+
validateSingleDecorator(meta, propertyName, ReferenceKind.SCALAR);
|
|
7
|
+
const k = serialized ? 'serializedPrimaryKey' : 'primary';
|
|
8
|
+
options[k] = true;
|
|
9
|
+
meta.properties[propertyName] = {
|
|
10
|
+
name: propertyName,
|
|
11
|
+
kind: ReferenceKind.SCALAR,
|
|
12
|
+
...options,
|
|
14
13
|
};
|
|
14
|
+
};
|
|
15
15
|
}
|
|
16
|
+
/** Marks a property as the primary key of an entity (legacy TypeScript decorator). */
|
|
16
17
|
export function PrimaryKey(options = {}) {
|
|
17
|
-
|
|
18
|
+
return createDecorator(options, false);
|
|
18
19
|
}
|
|
20
|
+
/** Marks a property as the serialized form of the primary key, e.g. for MongoDB ObjectId (legacy TypeScript decorator). */
|
|
19
21
|
export function SerializedPrimaryKey(options = {}) {
|
|
20
|
-
|
|
22
|
+
return createDecorator(options, true);
|
|
21
23
|
}
|
package/legacy/Property.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { type PropertyOptions } from '@mikro-orm/core';
|
|
2
|
-
|
|
2
|
+
/** Defines a scalar property on an entity (legacy TypeScript decorator). */
|
|
3
|
+
export declare function Property<T extends object>(
|
|
4
|
+
options?: PropertyOptions<T>,
|
|
5
|
+
): (target: T, propertyName: string) => void;
|