@mikro-orm/decorators 7.0.4 → 7.0.5-dev.1
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 +1 -1
- package/es/Check.d.ts +1 -3
- package/es/Check.js +6 -6
- package/es/CreateRequestContext.d.ts +2 -13
- package/es/CreateRequestContext.js +22 -24
- package/es/Embeddable.d.ts +1 -3
- package/es/Embeddable.js +9 -9
- package/es/Embedded.d.ts +1 -4
- package/es/Embedded.js +10 -10
- package/es/Entity.d.ts +1 -3
- package/es/Entity.js +9 -9
- package/es/Enum.d.ts +1 -3
- package/es/Enum.js +10 -10
- package/es/Filter.js +4 -4
- package/es/Formula.d.ts +1 -4
- package/es/Formula.js +9 -9
- package/es/Indexed.d.ts +2 -6
- package/es/Indexed.js +11 -11
- package/es/ManyToMany.d.ts +1 -5
- package/es/ManyToMany.js +8 -8
- package/es/ManyToOne.d.ts +1 -4
- package/es/ManyToOne.js +7 -7
- package/es/OneToMany.d.ts +2 -8
- package/es/OneToMany.js +8 -8
- package/es/OneToOne.d.ts +1 -5
- package/es/OneToOne.js +9 -9
- package/es/PrimaryKey.d.ts +2 -6
- package/es/PrimaryKey.js +12 -12
- package/es/Property.d.ts +1 -11
- package/es/Property.js +41 -37
- package/es/Transactional.d.ts +3 -8
- package/es/Transactional.js +15 -18
- package/es/hooks.d.ts +8 -32
- package/es/hooks.js +16 -16
- package/legacy/Check.d.ts +1 -3
- package/legacy/Check.js +9 -9
- package/legacy/CreateRequestContext.d.ts +1 -4
- package/legacy/CreateRequestContext.js +24 -26
- package/legacy/Embeddable.js +8 -8
- package/legacy/Embedded.d.ts +1 -4
- package/legacy/Embedded.js +11 -11
- package/legacy/Entity.js +8 -8
- package/legacy/Enum.d.ts +1 -3
- package/legacy/Enum.js +10 -10
- package/legacy/Filter.js +4 -4
- package/legacy/Formula.d.ts +1 -4
- package/legacy/Formula.js +9 -9
- package/legacy/Indexed.d.ts +2 -6
- package/legacy/Indexed.js +12 -12
- package/legacy/ManyToMany.d.ts +2 -8
- package/legacy/ManyToMany.js +8 -8
- package/legacy/ManyToOne.d.ts +2 -7
- package/legacy/ManyToOne.js +8 -8
- package/legacy/OneToMany.d.ts +2 -8
- package/legacy/OneToMany.js +8 -8
- package/legacy/OneToOne.d.ts +2 -8
- package/legacy/OneToOne.js +10 -10
- package/legacy/PrimaryKey.d.ts +2 -6
- package/legacy/PrimaryKey.js +13 -13
- package/legacy/Property.d.ts +1 -3
- package/legacy/Property.js +25 -25
- package/legacy/ReflectMetadataProvider.d.ts +2 -2
- package/legacy/ReflectMetadataProvider.js +44 -48
- package/legacy/Transactional.d.ts +2 -2
- package/legacy/Transactional.js +17 -20
- package/legacy/hooks.js +15 -15
- package/package.json +2 -2
- package/utils.d.ts +10 -40
- package/utils.js +86 -89
package/es/Property.js
CHANGED
|
@@ -2,41 +2,45 @@ import { ReferenceKind, Utils } from '@mikro-orm/core';
|
|
|
2
2
|
import { prepareMetadataContext } from '../utils.js';
|
|
3
3
|
/** Defines a scalar property on an entity (TC39 decorator). */
|
|
4
4
|
export function Property(options = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
5
|
+
return function (value, context) {
|
|
6
|
+
const meta = prepareMetadataContext(context, ReferenceKind.SCALAR);
|
|
7
|
+
const { check, ...opts } = options;
|
|
8
|
+
const prop = { kind: ReferenceKind.SCALAR, ...opts };
|
|
9
|
+
const name = options.name ?? context.name;
|
|
10
|
+
meta.checks ??= [];
|
|
11
|
+
if (context.name !== name) {
|
|
12
|
+
Utils.renameKey(options, 'name', 'fieldName');
|
|
13
|
+
}
|
|
14
|
+
if (context.kind === 'field') {
|
|
15
|
+
prop.name = context.name;
|
|
16
|
+
prop.getter = false;
|
|
17
|
+
prop.setter = false;
|
|
18
|
+
}
|
|
19
|
+
else if (context.kind === 'getter') {
|
|
20
|
+
prop.name = context.name;
|
|
21
|
+
prop.getter = true;
|
|
22
|
+
prop.setter = false;
|
|
23
|
+
}
|
|
24
|
+
else if (context.kind === 'setter') {
|
|
25
|
+
prop.name = context.name;
|
|
26
|
+
prop.getter = false;
|
|
27
|
+
prop.setter = true;
|
|
28
|
+
}
|
|
29
|
+
else if (context.kind === 'accessor') {
|
|
30
|
+
prop.name = context.name;
|
|
31
|
+
prop.getter = true;
|
|
32
|
+
prop.setter = true;
|
|
33
|
+
}
|
|
34
|
+
else if (context.kind === 'method') {
|
|
35
|
+
prop.getter = true;
|
|
36
|
+
prop.persist = false;
|
|
37
|
+
prop.type = 'method';
|
|
38
|
+
prop.getterName = context.name;
|
|
39
|
+
prop.name = name;
|
|
40
|
+
}
|
|
41
|
+
if (check) {
|
|
42
|
+
meta.checks.push({ property: prop.name, expression: check });
|
|
43
|
+
}
|
|
44
|
+
meta.properties[prop.name] = prop;
|
|
45
|
+
};
|
|
42
46
|
}
|
package/es/Transactional.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type TransactionOptions } from '@mikro-orm/core';
|
|
2
2
|
import { type ContextProvider } from '../utils.js';
|
|
3
3
|
type TransactionalOptions<T> = TransactionOptions & {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
context?: ContextProvider<T>;
|
|
5
|
+
contextName?: string;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* This decorator wraps the method with `em.transactional()`, so you can provide `TransactionOptions` just like with `em.transactional()`.
|
|
@@ -11,10 +11,5 @@ type TransactionalOptions<T> = TransactionOptions & {
|
|
|
11
11
|
* It works on async functions and can be nested with `em.transactional()`.
|
|
12
12
|
* Unlike `em.transactional()`, this decorator uses `REQUIRED` propagation by default, which means it will join existing transactions.
|
|
13
13
|
*/
|
|
14
|
-
export declare function Transactional<
|
|
15
|
-
Owner extends object,
|
|
16
|
-
Value extends (this: Owner, ...args: any) => any = (this: Owner, ...args: any) => any,
|
|
17
|
-
>(
|
|
18
|
-
options?: TransactionalOptions<Owner>,
|
|
19
|
-
): (value: Value, context: ClassMethodDecoratorContext<Owner, Value>) => (this: Owner, ...args: any) => Promise<any>;
|
|
14
|
+
export declare function Transactional<Owner extends object, Value extends (this: Owner, ...args: any) => any = (this: Owner, ...args: any) => any>(options?: TransactionalOptions<Owner>): (value: Value, context: ClassMethodDecoratorContext<Owner, Value>) => (this: Owner, ...args: any) => Promise<any>;
|
|
20
15
|
export {};
|
package/es/Transactional.js
CHANGED
|
@@ -8,23 +8,20 @@ import { resolveContextProvider } from '../utils.js';
|
|
|
8
8
|
* Unlike `em.transactional()`, this decorator uses `REQUIRED` propagation by default, which means it will join existing transactions.
|
|
9
9
|
*/
|
|
10
10
|
export function Transactional(options = {}) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
return em.transactional(() => value.apply(this, args), txOptions);
|
|
11
|
+
return function (value, context) {
|
|
12
|
+
if (value.constructor.name !== 'AsyncFunction') {
|
|
13
|
+
throw new Error('@Transactional() should be use with async functions');
|
|
14
|
+
}
|
|
15
|
+
return async function (...args) {
|
|
16
|
+
const { context, contextName, ...txOptions } = options;
|
|
17
|
+
txOptions.propagation ??= TransactionPropagation.REQUIRED;
|
|
18
|
+
const em = (await resolveContextProvider(this, context)) ||
|
|
19
|
+
TransactionContext.getEntityManager(contextName) ||
|
|
20
|
+
RequestContext.getEntityManager(contextName);
|
|
21
|
+
if (!em) {
|
|
22
|
+
throw new Error(`@Transactional() decorator can only be applied to methods of classes with \`orm: MikroORM\` property, \`em: EntityManager\` property, or with a callback parameter like \`@Transactional(() => orm)\` that returns one of those types. The parameter will contain a reference to current \`this\`. Returning an EntityRepository from it is also supported.`);
|
|
23
|
+
}
|
|
24
|
+
return em.transactional(() => value.apply(this, args), txOptions);
|
|
25
|
+
};
|
|
28
26
|
};
|
|
29
|
-
};
|
|
30
27
|
}
|
package/es/hooks.d.ts
CHANGED
|
@@ -1,33 +1,15 @@
|
|
|
1
1
|
/** Called before a new entity is persisted to the database (TC39 decorator). */
|
|
2
|
-
export declare function BeforeCreate(): (
|
|
3
|
-
value: (...args: any[]) => unknown,
|
|
4
|
-
context: ClassMethodDecoratorContext,
|
|
5
|
-
) => void;
|
|
2
|
+
export declare function BeforeCreate(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
6
3
|
/** Called after a new entity has been persisted to the database (TC39 decorator). */
|
|
7
|
-
export declare function AfterCreate(): (
|
|
8
|
-
value: (...args: any[]) => unknown,
|
|
9
|
-
context: ClassMethodDecoratorContext,
|
|
10
|
-
) => void;
|
|
4
|
+
export declare function AfterCreate(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
11
5
|
/** Called before an existing entity is updated in the database (TC39 decorator). */
|
|
12
|
-
export declare function BeforeUpdate(): (
|
|
13
|
-
value: (...args: any[]) => unknown,
|
|
14
|
-
context: ClassMethodDecoratorContext,
|
|
15
|
-
) => void;
|
|
6
|
+
export declare function BeforeUpdate(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
16
7
|
/** Called after an existing entity has been updated in the database (TC39 decorator). */
|
|
17
|
-
export declare function AfterUpdate(): (
|
|
18
|
-
value: (...args: any[]) => unknown,
|
|
19
|
-
context: ClassMethodDecoratorContext,
|
|
20
|
-
) => void;
|
|
8
|
+
export declare function AfterUpdate(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
21
9
|
/** Called before an entity is upserted (TC39 decorator). */
|
|
22
|
-
export declare function BeforeUpsert(): (
|
|
23
|
-
value: (...args: any[]) => unknown,
|
|
24
|
-
context: ClassMethodDecoratorContext,
|
|
25
|
-
) => void;
|
|
10
|
+
export declare function BeforeUpsert(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
26
11
|
/** Called after an entity has been upserted (TC39 decorator). */
|
|
27
|
-
export declare function AfterUpsert(): (
|
|
28
|
-
value: (...args: any[]) => unknown,
|
|
29
|
-
context: ClassMethodDecoratorContext,
|
|
30
|
-
) => void;
|
|
12
|
+
export declare function AfterUpsert(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
31
13
|
/** Called when an entity is instantiated by the EntityManager (TC39 decorator). */
|
|
32
14
|
export declare function OnInit(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
33
15
|
/** Called after an entity is loaded from the database (TC39 decorator). */
|
|
@@ -35,14 +17,8 @@ export declare function OnLoad(): (value: (...args: any[]) => unknown, context:
|
|
|
35
17
|
/**
|
|
36
18
|
* Called before deleting entity, but only when providing initialized entity to EM#remove()
|
|
37
19
|
*/
|
|
38
|
-
export declare function BeforeDelete(): (
|
|
39
|
-
value: (...args: any[]) => unknown,
|
|
40
|
-
context: ClassMethodDecoratorContext,
|
|
41
|
-
) => void;
|
|
20
|
+
export declare function BeforeDelete(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
42
21
|
/**
|
|
43
22
|
* Called after deleting entity, but only when providing initialized entity to EM#remove()
|
|
44
23
|
*/
|
|
45
|
-
export declare function AfterDelete(): (
|
|
46
|
-
value: (...args: any[]) => unknown,
|
|
47
|
-
context: ClassMethodDecoratorContext,
|
|
48
|
-
) => void;
|
|
24
|
+
export declare function AfterDelete(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
package/es/hooks.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
1
|
import { EventType } from '@mikro-orm/core';
|
|
2
2
|
function hook(type) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
9
|
}
|
|
10
10
|
/** Called before a new entity is persisted to the database (TC39 decorator). */
|
|
11
11
|
export function BeforeCreate() {
|
|
12
|
-
|
|
12
|
+
return hook(EventType.beforeCreate);
|
|
13
13
|
}
|
|
14
14
|
/** Called after a new entity has been persisted to the database (TC39 decorator). */
|
|
15
15
|
export function AfterCreate() {
|
|
16
|
-
|
|
16
|
+
return hook(EventType.afterCreate);
|
|
17
17
|
}
|
|
18
18
|
/** Called before an existing entity is updated in the database (TC39 decorator). */
|
|
19
19
|
export function BeforeUpdate() {
|
|
20
|
-
|
|
20
|
+
return hook(EventType.beforeUpdate);
|
|
21
21
|
}
|
|
22
22
|
/** Called after an existing entity has been updated in the database (TC39 decorator). */
|
|
23
23
|
export function AfterUpdate() {
|
|
24
|
-
|
|
24
|
+
return hook(EventType.afterUpdate);
|
|
25
25
|
}
|
|
26
26
|
/** Called before an entity is upserted (TC39 decorator). */
|
|
27
27
|
export function BeforeUpsert() {
|
|
28
|
-
|
|
28
|
+
return hook(EventType.beforeUpsert);
|
|
29
29
|
}
|
|
30
30
|
/** Called after an entity has been upserted (TC39 decorator). */
|
|
31
31
|
export function AfterUpsert() {
|
|
32
|
-
|
|
32
|
+
return hook(EventType.afterUpsert);
|
|
33
33
|
}
|
|
34
34
|
/** Called when an entity is instantiated by the EntityManager (TC39 decorator). */
|
|
35
35
|
export function OnInit() {
|
|
36
|
-
|
|
36
|
+
return hook(EventType.onInit);
|
|
37
37
|
}
|
|
38
38
|
/** Called after an entity is loaded from the database (TC39 decorator). */
|
|
39
39
|
export function OnLoad() {
|
|
40
|
-
|
|
40
|
+
return hook(EventType.onLoad);
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Called before deleting entity, but only when providing initialized entity to EM#remove()
|
|
44
44
|
*/
|
|
45
45
|
export function BeforeDelete() {
|
|
46
|
-
|
|
46
|
+
return hook(EventType.beforeDelete);
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Called after deleting entity, but only when providing initialized entity to EM#remove()
|
|
50
50
|
*/
|
|
51
51
|
export function AfterDelete() {
|
|
52
|
-
|
|
52
|
+
return hook(EventType.afterDelete);
|
|
53
53
|
}
|
package/legacy/Check.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
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;
|
|
3
|
+
export declare function Check<T>(options: CheckConstraint<T>): (target: T, propertyName?: T extends EntityClass<unknown> ? undefined : keyof T) => any;
|
package/legacy/Check.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
2
2
|
/** Defines a database check constraint on a property or entity class (legacy TypeScript decorator). */
|
|
3
3
|
export function Check(options) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
};
|
|
13
13
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
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;
|
|
3
|
+
export declare function CreateRequestContext<T extends object>(context?: ContextProvider<T>, respectExistingContext?: boolean): MethodDecorator;
|
|
7
4
|
/** Like `@CreateRequestContext`, but reuses an existing RequestContext if one is available (legacy TypeScript decorator). */
|
|
8
5
|
export declare function EnsureRequestContext<T extends object>(context?: ContextProvider<T>): MethodDecorator;
|
|
@@ -2,34 +2,32 @@ import { RequestContext, TransactionContext } from '@mikro-orm/core';
|
|
|
2
2
|
import { resolveContextProvider } from '../utils.js';
|
|
3
3
|
/** Wraps an async method in a new RequestContext, forking the EntityManager (legacy TypeScript decorator). */
|
|
4
4
|
export function CreateRequestContext(context, respectExistingContext = false) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
28
|
};
|
|
29
|
-
return descriptor;
|
|
30
|
-
};
|
|
31
29
|
}
|
|
32
30
|
/** Like `@CreateRequestContext`, but reuses an existing RequestContext if one is available (legacy TypeScript decorator). */
|
|
33
31
|
export function EnsureRequestContext(context) {
|
|
34
|
-
|
|
32
|
+
return CreateRequestContext(context, true);
|
|
35
33
|
}
|
package/legacy/Embeddable.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
2
2
|
/** Marks a class as an embeddable type (legacy TypeScript decorator). */
|
|
3
3
|
export function Embeddable(options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
};
|
|
12
12
|
}
|
package/legacy/Embedded.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
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;
|
|
3
|
+
export declare function Embedded<Owner extends object, Target>(type?: EmbeddedOptions<Owner, Target> | (() => EntityName<Target> | EntityName[]), options?: EmbeddedOptions<Owner, Target>): (target: AnyEntity, propertyName: string) => void;
|
package/legacy/Embedded.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { ReferenceKind, Utils } from '@mikro-orm/core';
|
|
1
|
+
import { ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
2
2
|
import { validateSingleDecorator, getMetadataFromDecorator } from '../utils.js';
|
|
3
3
|
/** Defines an embedded property on an entity (legacy TypeScript decorator). */
|
|
4
4
|
export function Embedded(type = {}, options = {}) {
|
|
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
16
|
}
|
package/legacy/Entity.js
CHANGED
|
@@ -2,12 +2,12 @@ import { Utils } from '@mikro-orm/core';
|
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
3
|
/** Marks a class as a MikroORM entity (legacy TypeScript decorator). */
|
|
4
4
|
export function Entity(options = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
};
|
|
13
13
|
}
|
package/legacy/Enum.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
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;
|
|
3
|
+
export declare function Enum<T extends object>(options?: EnumOptions<AnyEntity> | (() => Dictionary)): (target: T, propertyName: string) => void;
|
package/legacy/Enum.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { ReferenceKind } from '@mikro-orm/core';
|
|
1
|
+
import { ReferenceKind, } from '@mikro-orm/core';
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
3
|
/** Defines an enum property on an entity (legacy TypeScript decorator). */
|
|
4
4
|
export function Enum(options = {}) {
|
|
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
15
|
}
|
package/legacy/Filter.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
2
2
|
/** Registers a named filter on an entity class (legacy TypeScript decorator). */
|
|
3
3
|
export function Filter(options) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
return function (target) {
|
|
5
|
+
const meta = getMetadataFromDecorator(target);
|
|
6
|
+
meta.filters[options.name] = options;
|
|
7
|
+
};
|
|
8
8
|
}
|
package/legacy/Formula.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
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;
|
|
3
|
+
export declare function Formula<T extends object>(formula: string | FormulaCallback<T>, options?: PropertyOptions<T>): (target: T, propertyName: string) => void;
|
package/legacy/Formula.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ReferenceKind } from '@mikro-orm/core';
|
|
1
|
+
import { ReferenceKind, } from '@mikro-orm/core';
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
3
|
/** Defines a computed SQL formula property on an entity (legacy TypeScript decorator). */
|
|
4
4
|
export function Formula(formula, options = {}) {
|
|
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
14
|
}
|
package/legacy/Indexed.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { type EntityClass, type IndexOptions, type UniqueOptions } from '@mikro-orm/core';
|
|
2
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;
|
|
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) => any;
|
|
6
4
|
/** 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;
|
|
5
|
+
export declare function Unique<T extends object, H extends string>(options?: UniqueOptions<T, H>): (target: T, propertyName?: T extends EntityClass<unknown> ? undefined : keyof T) => any;
|
package/legacy/Indexed.js
CHANGED
|
@@ -1,21 +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
14
|
/** Defines a database index on a property or entity class (legacy TypeScript decorator). */
|
|
15
15
|
export function Index(options = {}) {
|
|
16
|
-
|
|
16
|
+
return createDecorator(options, false);
|
|
17
17
|
}
|
|
18
18
|
/** Defines a unique constraint on a property or entity class (legacy TypeScript decorator). */
|
|
19
19
|
export function Unique(options = {}) {
|
|
20
|
-
|
|
20
|
+
return createDecorator(options, true);
|
|
21
21
|
}
|
package/legacy/ManyToMany.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
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
|
+
export declare function ManyToMany<Target extends object, Owner extends object>(entity: () => EntityName<Target>, mappedBy?: (string & keyof Target) | ((e: Target) => any), options?: Partial<ManyToManyOptions<Owner, Target>>): (target: Owner, propertyName: keyof Owner) => void;
|
|
8
4
|
export declare function ManyToMany<Target extends object, Owner extends object>(entity: string, options?: any): never;
|
|
9
|
-
export declare function ManyToMany<Target extends object, Owner extends object>(
|
|
10
|
-
options?: ManyToManyOptions<Owner, Target>,
|
|
11
|
-
): (target: Owner, propertyName: keyof Owner) => void;
|
|
5
|
+
export declare function ManyToMany<Target extends object, Owner extends object>(options?: ManyToManyOptions<Owner, Target>): (target: Owner, propertyName: keyof Owner) => void;
|
package/legacy/ManyToMany.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ReferenceKind } from '@mikro-orm/core';
|
|
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
|
}
|