@mikro-orm/decorators 7.0.4-dev.9 → 7.0.4
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 +3 -1
- package/es/Check.js +6 -6
- package/es/CreateRequestContext.d.ts +13 -2
- package/es/CreateRequestContext.js +24 -22
- package/es/Embeddable.d.ts +3 -1
- package/es/Embeddable.js +9 -9
- package/es/Embedded.d.ts +4 -1
- package/es/Embedded.js +10 -10
- package/es/Entity.d.ts +3 -1
- package/es/Entity.js +9 -9
- package/es/Enum.d.ts +3 -1
- package/es/Enum.js +10 -10
- package/es/Filter.js +4 -4
- package/es/Formula.d.ts +4 -1
- package/es/Formula.js +9 -9
- package/es/Indexed.d.ts +6 -2
- package/es/Indexed.js +11 -11
- package/es/ManyToMany.d.ts +5 -1
- package/es/ManyToMany.js +8 -8
- package/es/ManyToOne.d.ts +4 -1
- package/es/ManyToOne.js +7 -7
- package/es/OneToMany.d.ts +8 -2
- package/es/OneToMany.js +8 -8
- package/es/OneToOne.d.ts +5 -1
- package/es/OneToOne.js +9 -9
- package/es/PrimaryKey.d.ts +6 -2
- package/es/PrimaryKey.js +12 -12
- package/es/Property.d.ts +11 -1
- package/es/Property.js +37 -41
- package/es/Transactional.d.ts +8 -3
- package/es/Transactional.js +18 -15
- package/es/hooks.d.ts +32 -8
- package/es/hooks.js +16 -16
- package/legacy/Check.d.ts +3 -1
- package/legacy/Check.js +9 -9
- package/legacy/CreateRequestContext.d.ts +4 -1
- package/legacy/CreateRequestContext.js +26 -24
- package/legacy/Embeddable.js +8 -8
- package/legacy/Embedded.d.ts +4 -1
- package/legacy/Embedded.js +11 -11
- package/legacy/Entity.js +8 -8
- package/legacy/Enum.d.ts +3 -1
- package/legacy/Enum.js +10 -10
- package/legacy/Filter.js +4 -4
- package/legacy/Formula.d.ts +4 -1
- package/legacy/Formula.js +9 -9
- package/legacy/Indexed.d.ts +6 -2
- package/legacy/Indexed.js +12 -12
- package/legacy/ManyToMany.d.ts +8 -2
- package/legacy/ManyToMany.js +8 -8
- package/legacy/ManyToOne.d.ts +7 -2
- package/legacy/ManyToOne.js +8 -8
- package/legacy/OneToMany.d.ts +8 -2
- package/legacy/OneToMany.js +8 -8
- package/legacy/OneToOne.d.ts +8 -2
- package/legacy/OneToOne.js +10 -10
- package/legacy/PrimaryKey.d.ts +6 -2
- package/legacy/PrimaryKey.js +13 -13
- package/legacy/Property.d.ts +3 -1
- package/legacy/Property.js +25 -25
- package/legacy/ReflectMetadataProvider.d.ts +2 -2
- package/legacy/ReflectMetadataProvider.js +48 -44
- package/legacy/Transactional.d.ts +2 -2
- package/legacy/Transactional.js +20 -17
- package/legacy/hooks.js +15 -15
- package/package.json +3 -3
- package/utils.d.ts +40 -10
- package/utils.js +89 -85
package/README.md
CHANGED
|
@@ -133,7 +133,7 @@ const author = await em.findOneOrFail(Author, 1, {
|
|
|
133
133
|
populate: ['books'],
|
|
134
134
|
});
|
|
135
135
|
author.name = 'Jon Snow II';
|
|
136
|
-
author.books.getItems().forEach(book => book.title += ' (2nd ed.)');
|
|
136
|
+
author.books.getItems().forEach(book => (book.title += ' (2nd ed.)'));
|
|
137
137
|
author.books.add(orm.em.create(Book, { title: 'New Book', author }));
|
|
138
138
|
|
|
139
139
|
// Flush computes change sets and executes them in a single transaction
|
package/es/Check.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { type CheckConstraint } from '@mikro-orm/core';
|
|
2
2
|
/** Defines a database check constraint on a property (TC39 decorator). */
|
|
3
|
-
export declare function Check<T>(
|
|
3
|
+
export declare function Check<T>(
|
|
4
|
+
options: CheckConstraint<T>,
|
|
5
|
+
): (value: unknown, context: ClassFieldDecoratorContext<T>) => void;
|
package/es/Check.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** Defines a database check constraint on a property (TC39 decorator). */
|
|
2
2
|
export function Check(options) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
return function (value, context) {
|
|
4
|
+
const meta = context.metadata;
|
|
5
|
+
meta.checks ??= [];
|
|
6
|
+
options.property ??= context.name;
|
|
7
|
+
meta.checks.push(options);
|
|
8
|
+
};
|
|
9
9
|
}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { type ContextProvider } from '../utils.js';
|
|
2
2
|
/** Wraps an async method in a new RequestContext, forking the EntityManager (TC39 decorator). */
|
|
3
|
-
export declare function CreateRequestContext<T extends object>(
|
|
3
|
+
export declare function CreateRequestContext<T extends object>(
|
|
4
|
+
contextProvider?: ContextProvider<T>,
|
|
5
|
+
respectExistingContext?: boolean,
|
|
6
|
+
): (
|
|
7
|
+
value: (this: T, ...args: any) => any,
|
|
8
|
+
context: ClassMethodDecoratorContext<T>,
|
|
9
|
+
) => (this: T, ...args: any[]) => Promise<any>;
|
|
4
10
|
/** Like `@CreateRequestContext`, but reuses an existing RequestContext if one is available (TC39 decorator). */
|
|
5
|
-
export declare function EnsureRequestContext<T extends object>(
|
|
11
|
+
export declare function EnsureRequestContext<T extends object>(
|
|
12
|
+
context?: ContextProvider<T>,
|
|
13
|
+
): (
|
|
14
|
+
value: (this: T, ...args: any) => any,
|
|
15
|
+
context: ClassMethodDecoratorContext<T>,
|
|
16
|
+
) => (this: T, ...args: any[]) => Promise<any>;
|
|
@@ -2,30 +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 (TC39 decorator). */
|
|
4
4
|
export function CreateRequestContext(contextProvider, respectExistingContext = false) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
5
|
+
return function (value, context) {
|
|
6
|
+
const name = respectExistingContext ? 'EnsureRequestContext' : 'CreateRequestContext';
|
|
7
|
+
if (value.constructor.name !== 'AsyncFunction') {
|
|
8
|
+
throw new Error(`@${name}() should be use with async functions`);
|
|
9
|
+
}
|
|
10
|
+
return async function (...args) {
|
|
11
|
+
const em = await resolveContextProvider(this, contextProvider);
|
|
12
|
+
if (!em) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
`@${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
|
+
}
|
|
17
|
+
// reuse existing context if available for given respect `contextName`
|
|
18
|
+
if (respectExistingContext && RequestContext.getEntityManager(em.name)) {
|
|
19
|
+
return value.apply(this, args);
|
|
20
|
+
}
|
|
21
|
+
// Otherwise, the outer tx context would be preferred.
|
|
22
|
+
const txContext = TransactionContext.currentTransactionContext();
|
|
23
|
+
const provider = txContext ? TransactionContext : RequestContext;
|
|
24
|
+
return txContext
|
|
25
|
+
? provider.create(em.fork({ useContext: true }), () => value.apply(this, args))
|
|
26
|
+
: provider.create(em, () => value.apply(this, args));
|
|
26
27
|
};
|
|
28
|
+
};
|
|
27
29
|
}
|
|
28
30
|
/** Like `@CreateRequestContext`, but reuses an existing RequestContext if one is available (TC39 decorator). */
|
|
29
31
|
export function EnsureRequestContext(context) {
|
|
30
|
-
|
|
32
|
+
return CreateRequestContext(context, true);
|
|
31
33
|
}
|
package/es/Embeddable.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { type Constructor, type EmbeddableOptions, type EntityClass } from '@mikro-orm/core';
|
|
2
2
|
/** Marks a class as an embeddable type (TC39 decorator). */
|
|
3
|
-
export declare function Embeddable<Owner extends EntityClass<unknown> & Constructor>(
|
|
3
|
+
export declare function Embeddable<Owner extends EntityClass<unknown> & Constructor>(
|
|
4
|
+
options?: EmbeddableOptions<Owner>,
|
|
5
|
+
): (target: Owner, context: ClassDecoratorContext<Owner>) => Owner;
|
package/es/Embeddable.js
CHANGED
|
@@ -2,13 +2,13 @@ import { Utils } from '@mikro-orm/core';
|
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
3
|
/** Marks a class as an embeddable type (TC39 decorator). */
|
|
4
4
|
export function Embeddable(options = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
return function (target, context) {
|
|
6
|
+
const meta = getMetadataFromDecorator(target);
|
|
7
|
+
const metadata = { ...context.metadata };
|
|
8
|
+
Utils.mergeConfig(meta, metadata, options);
|
|
9
|
+
meta.class = target;
|
|
10
|
+
meta.name = meta.class.name;
|
|
11
|
+
meta.embeddable = true;
|
|
12
|
+
return target;
|
|
13
|
+
};
|
|
14
14
|
}
|
package/es/Embedded.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { type EntityName, type EmbeddedOptions } from '@mikro-orm/core';
|
|
2
2
|
/** Defines an embedded property on an entity (TC39 decorator). */
|
|
3
|
-
export declare function Embedded<Owner extends object, Target>(
|
|
3
|
+
export declare function Embedded<Owner extends object, Target>(
|
|
4
|
+
type?: EmbeddedOptions<Owner, Target> | (() => EntityName<Target> | EntityName[]),
|
|
5
|
+
options?: EmbeddedOptions<Owner, Target>,
|
|
6
|
+
): (value: unknown, context: ClassFieldDecoratorContext<Owner>) => void;
|
package/es/Embedded.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { ReferenceKind, Utils
|
|
1
|
+
import { ReferenceKind, Utils } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext } from '../utils.js';
|
|
3
3
|
/** Defines an embedded property on an entity (TC39 decorator). */
|
|
4
4
|
export function Embedded(type = {}, options = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
5
|
+
return function (value, context) {
|
|
6
|
+
const meta = prepareMetadataContext(context, ReferenceKind.EMBEDDED);
|
|
7
|
+
options = type instanceof Function ? { entity: type, ...options } : { ...type, ...options };
|
|
8
|
+
Utils.defaultValue(options, 'prefix', true);
|
|
9
|
+
meta.properties[context.name] = {
|
|
10
|
+
name: context.name,
|
|
11
|
+
kind: ReferenceKind.EMBEDDED,
|
|
12
|
+
...options,
|
|
14
13
|
};
|
|
14
|
+
};
|
|
15
15
|
}
|
package/es/Entity.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { type Constructor, type EntityOptions, type EntityClass } from '@mikro-orm/core';
|
|
2
2
|
/** Marks a class as a MikroORM entity (TC39 decorator). */
|
|
3
|
-
export declare function Entity<Owner extends EntityClass<unknown> & Constructor>(
|
|
3
|
+
export declare function Entity<Owner extends EntityClass<unknown> & Constructor>(
|
|
4
|
+
options?: EntityOptions<Owner>,
|
|
5
|
+
): (target: Owner, context: ClassDecoratorContext<Owner>) => void;
|
package/es/Entity.js
CHANGED
|
@@ -2,13 +2,13 @@ import { Utils } from '@mikro-orm/core';
|
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
3
|
/** Marks a class as a MikroORM entity (TC39 decorator). */
|
|
4
4
|
export function Entity(options = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
return function (target, context) {
|
|
6
|
+
const meta = getMetadataFromDecorator(target);
|
|
7
|
+
const metadata = { ...context.metadata };
|
|
8
|
+
Utils.mergeConfig(meta, metadata, options);
|
|
9
|
+
meta.class = target;
|
|
10
|
+
if (!options.abstract || meta.discriminatorColumn) {
|
|
11
|
+
meta.name = context.name;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
14
|
}
|
package/es/Enum.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { type EnumOptions, type AnyEntity, type Dictionary } from '@mikro-orm/core';
|
|
2
2
|
/** Defines an enum property on an entity (TC39 decorator). */
|
|
3
|
-
export declare function Enum<Owner extends object>(
|
|
3
|
+
export declare function Enum<Owner extends object>(
|
|
4
|
+
options?: EnumOptions<AnyEntity> | (() => Dictionary),
|
|
5
|
+
): (target: unknown, context: ClassFieldDecoratorContext<Owner>) => void;
|
package/es/Enum.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext } from '../utils.js';
|
|
3
3
|
/** Defines an enum property on an entity (TC39 decorator). */
|
|
4
4
|
export function Enum(options = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
5
|
+
return function (target, context) {
|
|
6
|
+
const meta = prepareMetadataContext(context);
|
|
7
|
+
options = options instanceof Function ? { items: options } : options;
|
|
8
|
+
meta.properties[context.name] = {
|
|
9
|
+
name: context.name,
|
|
10
|
+
kind: ReferenceKind.SCALAR,
|
|
11
|
+
enum: true,
|
|
12
|
+
...options,
|
|
14
13
|
};
|
|
14
|
+
};
|
|
15
15
|
}
|
package/es/Filter.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
2
2
|
/** Registers a named filter on an entity class (TC39 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/es/Formula.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { type FormulaCallback, type PropertyOptions } from '@mikro-orm/core';
|
|
2
2
|
/** Defines a computed SQL formula property on an entity (TC39 decorator). */
|
|
3
|
-
export declare function Formula<Owner extends object>(
|
|
3
|
+
export declare function Formula<Owner extends object>(
|
|
4
|
+
formula: string | FormulaCallback<Owner>,
|
|
5
|
+
options?: PropertyOptions<Owner>,
|
|
6
|
+
): (value: unknown, context: ClassFieldDecoratorContext<Owner>) => void;
|
package/es/Formula.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext } from '../utils.js';
|
|
3
3
|
/** Defines a computed SQL formula property on an entity (TC39 decorator). */
|
|
4
4
|
export function Formula(formula, options = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
5
|
+
return function (value, context) {
|
|
6
|
+
const meta = prepareMetadataContext(context);
|
|
7
|
+
meta.properties[context.name] = {
|
|
8
|
+
name: context.name,
|
|
9
|
+
kind: ReferenceKind.SCALAR,
|
|
10
|
+
formula,
|
|
11
|
+
...options,
|
|
13
12
|
};
|
|
13
|
+
};
|
|
14
14
|
}
|
package/es/Indexed.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type IndexOptions, type UniqueOptions, type Constructor } from '@mikro-orm/core';
|
|
2
2
|
/** Defines a database index on a property or entity class (TC39 decorator). */
|
|
3
|
-
export declare function Index<T extends object, H extends string>(
|
|
3
|
+
export declare function Index<T extends object, H extends string>(
|
|
4
|
+
options?: IndexOptions<T, H>,
|
|
5
|
+
): (value: unknown, context: ClassDecoratorContext<T & Constructor> | ClassFieldDecoratorContext<T>) => any;
|
|
4
6
|
/** Defines a unique constraint on a property or entity class (TC39 decorator). */
|
|
5
|
-
export declare function Unique<T extends object, H extends string>(
|
|
7
|
+
export declare function Unique<T extends object, H extends string>(
|
|
8
|
+
options?: UniqueOptions<T, H>,
|
|
9
|
+
): (value: unknown, context: ClassDecoratorContext<T & Constructor> | ClassFieldDecoratorContext<T>) => any;
|
package/es/Indexed.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
function createDecorator(options, unique) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
return function (value, context) {
|
|
3
|
+
const meta = context.metadata;
|
|
4
|
+
if (context.kind === 'field') {
|
|
5
|
+
options.properties ??= context.name;
|
|
6
|
+
}
|
|
7
|
+
const key = unique ? 'uniques' : 'indexes';
|
|
8
|
+
meta[key] ??= [];
|
|
9
|
+
meta[key].push(options);
|
|
10
|
+
};
|
|
11
11
|
}
|
|
12
12
|
/** Defines a database index on a property or entity class (TC39 decorator). */
|
|
13
13
|
export function Index(options = {}) {
|
|
14
|
-
|
|
14
|
+
return createDecorator(options, false);
|
|
15
15
|
}
|
|
16
16
|
/** Defines a unique constraint on a property or entity class (TC39 decorator). */
|
|
17
17
|
export function Unique(options = {}) {
|
|
18
|
-
|
|
18
|
+
return createDecorator(options, true);
|
|
19
19
|
}
|
package/es/ManyToMany.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { type EntityName, type ManyToManyOptions, type Collection } from '@mikro-orm/core';
|
|
2
2
|
/** Defines a many-to-many relationship (TC39 decorator). */
|
|
3
|
-
export declare function ManyToMany<Target extends object, Owner extends object>(
|
|
3
|
+
export declare function ManyToMany<Target extends object, Owner extends object>(
|
|
4
|
+
entity?: ManyToManyOptions<Owner, Target> | string | (() => EntityName<Target>),
|
|
5
|
+
mappedBy?: (string & keyof Target) | ((e: Target) => any),
|
|
6
|
+
options?: Partial<ManyToManyOptions<Owner, Target>>,
|
|
7
|
+
): (_: unknown, context: ClassFieldDecoratorContext<Owner, Collection<Target> | undefined>) => void;
|
package/es/ManyToMany.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ReferenceKind, Utils
|
|
1
|
+
import { ReferenceKind, Utils } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext, processDecoratorParameters } from '../utils.js';
|
|
3
3
|
/** Defines a many-to-many relationship (TC39 decorator). */
|
|
4
4
|
export function ManyToMany(entity, mappedBy, options = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
return function (_, context) {
|
|
6
|
+
const meta = prepareMetadataContext(context, ReferenceKind.MANY_TO_MANY);
|
|
7
|
+
options = processDecoratorParameters({ entity, mappedBy, options });
|
|
8
|
+
const property = { name: context.name, kind: ReferenceKind.MANY_TO_MANY };
|
|
9
|
+
meta.properties[context.name] ??= {};
|
|
10
|
+
Utils.mergeConfig(meta.properties[context.name], property, options);
|
|
11
|
+
};
|
|
12
12
|
}
|
package/es/ManyToOne.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { type ManyToOneOptions, type EntityName, type Ref } from '@mikro-orm/core';
|
|
2
2
|
/** Defines a many-to-one relationship (TC39 decorator). */
|
|
3
|
-
export declare function ManyToOne<Target extends object, Owner extends object>(
|
|
3
|
+
export declare function ManyToOne<Target extends object, Owner extends object>(
|
|
4
|
+
entity?: ManyToOneOptions<Owner, Target> | ((e?: Owner) => EntityName<Target> | EntityName[]),
|
|
5
|
+
options?: Partial<ManyToOneOptions<Owner, Target>>,
|
|
6
|
+
): (_: unknown, context: ClassFieldDecoratorContext<Owner, Target | undefined | null | Ref<Target>>) => void;
|
package/es/ManyToOne.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ReferenceKind, Utils
|
|
1
|
+
import { ReferenceKind, Utils } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext, processDecoratorParameters } from '../utils.js';
|
|
3
3
|
/** Defines a many-to-one relationship (TC39 decorator). */
|
|
4
4
|
export function ManyToOne(entity = {}, options = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
return function (_, context) {
|
|
6
|
+
const meta = prepareMetadataContext(context, ReferenceKind.MANY_TO_ONE);
|
|
7
|
+
options = processDecoratorParameters({ entity, options });
|
|
8
|
+
const property = { name: context.name, kind: ReferenceKind.MANY_TO_ONE };
|
|
9
|
+
meta.properties[context.name] = Utils.mergeConfig(meta.properties[context.name] ?? {}, property, options);
|
|
10
|
+
};
|
|
11
11
|
}
|
package/es/OneToMany.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { type Collection, type EntityName, type OneToManyOptions } from '@mikro-orm/core';
|
|
2
2
|
/** Defines a one-to-many relationship (TC39 decorator). */
|
|
3
|
-
export declare function OneToMany<Target extends object, Owner extends object>(
|
|
4
|
-
|
|
3
|
+
export declare function OneToMany<Target extends object, Owner extends object>(
|
|
4
|
+
entity: string | ((e?: Owner) => EntityName<Target>),
|
|
5
|
+
mappedBy: (string & keyof Target) | ((e: Target) => any),
|
|
6
|
+
options?: Partial<OneToManyOptions<Owner, Target>>,
|
|
7
|
+
): (value: unknown, context: ClassFieldDecoratorContext<Owner, Collection<Target> | undefined>) => void;
|
|
8
|
+
export declare function OneToMany<Target extends object, Owner extends object>(
|
|
9
|
+
options: OneToManyOptions<Owner, Target>,
|
|
10
|
+
): (value: unknown, context: ClassFieldDecoratorContext<Owner, Collection<Target> | undefined>) => void;
|
package/es/OneToMany.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ReferenceKind, Utils
|
|
1
|
+
import { ReferenceKind, Utils } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext, processDecoratorParameters } from '../utils.js';
|
|
3
3
|
export function OneToMany(entity, mappedBy, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
return function (value, context) {
|
|
5
|
+
const meta = prepareMetadataContext(context, ReferenceKind.ONE_TO_MANY);
|
|
6
|
+
options = processDecoratorParameters({ entity, mappedBy, options });
|
|
7
|
+
const property = { name: context.name, kind: ReferenceKind.ONE_TO_MANY };
|
|
8
|
+
meta.properties[context.name] ??= {};
|
|
9
|
+
Utils.mergeConfig(meta.properties[context.name], property, options);
|
|
10
|
+
};
|
|
11
11
|
}
|
package/es/OneToOne.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { type EntityName, type OneToOneOptions, type Ref } from '@mikro-orm/core';
|
|
2
2
|
/** Defines a one-to-one relationship (TC39 decorator). */
|
|
3
|
-
export declare function OneToOne<Target extends object, Owner extends object>(
|
|
3
|
+
export declare function OneToOne<Target extends object, Owner extends object>(
|
|
4
|
+
entity?: OneToOneOptions<Owner, Target> | string | ((e: Owner) => EntityName<Target> | EntityName[]),
|
|
5
|
+
mappedByOrOptions?: (string & keyof Target) | ((e: Target) => any) | Partial<OneToOneOptions<Owner, Target>>,
|
|
6
|
+
options?: Partial<OneToOneOptions<Owner, Target>>,
|
|
7
|
+
): (_: unknown, context: ClassFieldDecoratorContext<Owner, Target | Ref<Target> | null | undefined>) => void;
|
package/es/OneToOne.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext, processDecoratorParameters } from '../utils.js';
|
|
3
3
|
/** Defines a one-to-one relationship (TC39 decorator). */
|
|
4
4
|
export function OneToOne(entity, mappedByOrOptions, options = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
const mappedBy = typeof mappedByOrOptions === 'object' ? mappedByOrOptions.mappedBy : mappedByOrOptions;
|
|
6
|
+
options = typeof mappedByOrOptions === 'object' ? { ...mappedByOrOptions, ...options } : options;
|
|
7
|
+
return function (_, context) {
|
|
8
|
+
const meta = prepareMetadataContext(context, ReferenceKind.ONE_TO_ONE);
|
|
9
|
+
options = processDecoratorParameters({ entity, mappedBy, options });
|
|
10
|
+
const property = { name: context.name, kind: ReferenceKind.ONE_TO_ONE };
|
|
11
|
+
meta.properties[context.name] = Object.assign(meta.properties[context.name] ?? {}, property, options);
|
|
12
|
+
};
|
|
13
13
|
}
|
package/es/PrimaryKey.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type PrimaryKeyOptions, type SerializedPrimaryKeyOptions } from '@mikro-orm/core';
|
|
2
2
|
/** Marks a property as the primary key of an entity (TC39 decorator). */
|
|
3
|
-
export declare function PrimaryKey<T extends object>(
|
|
3
|
+
export declare function PrimaryKey<T extends object>(
|
|
4
|
+
options?: PrimaryKeyOptions<T>,
|
|
5
|
+
): (value: unknown, context: ClassFieldDecoratorContext<T>) => void;
|
|
4
6
|
/** Marks a property as the serialized form of the primary key, e.g. for MongoDB ObjectId (TC39 decorator). */
|
|
5
|
-
export declare function SerializedPrimaryKey<T extends object>(
|
|
7
|
+
export declare function SerializedPrimaryKey<T extends object>(
|
|
8
|
+
options?: SerializedPrimaryKeyOptions<T>,
|
|
9
|
+
): (value: unknown, context: ClassFieldDecoratorContext<T>) => void;
|
package/es/PrimaryKey.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext } from '../utils.js';
|
|
3
3
|
function createDecorator(options, serialized) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
4
|
+
return function (value, context) {
|
|
5
|
+
const meta = prepareMetadataContext(context, ReferenceKind.SCALAR);
|
|
6
|
+
const key = serialized ? 'serializedPrimaryKey' : 'primary';
|
|
7
|
+
options[key] = true;
|
|
8
|
+
meta.properties[context.name] = {
|
|
9
|
+
name: context.name,
|
|
10
|
+
kind: ReferenceKind.SCALAR,
|
|
11
|
+
...options,
|
|
13
12
|
};
|
|
13
|
+
};
|
|
14
14
|
}
|
|
15
15
|
/** Marks a property as the primary key of an entity (TC39 decorator). */
|
|
16
16
|
export function PrimaryKey(options = {}) {
|
|
17
|
-
|
|
17
|
+
return createDecorator(options, false);
|
|
18
18
|
}
|
|
19
19
|
/** Marks a property as the serialized form of the primary key, e.g. for MongoDB ObjectId (TC39 decorator). */
|
|
20
20
|
export function SerializedPrimaryKey(options = {}) {
|
|
21
|
-
|
|
21
|
+
return createDecorator(options, true);
|
|
22
22
|
}
|
package/es/Property.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
import { type PropertyOptions } from '@mikro-orm/core';
|
|
2
2
|
/** Defines a scalar property on an entity (TC39 decorator). */
|
|
3
|
-
export declare function Property<T extends object>(
|
|
3
|
+
export declare function Property<T extends object>(
|
|
4
|
+
options?: PropertyOptions<T>,
|
|
5
|
+
): (
|
|
6
|
+
value: unknown,
|
|
7
|
+
context:
|
|
8
|
+
| ClassFieldDecoratorContext<T>
|
|
9
|
+
| ClassGetterDecoratorContext<T>
|
|
10
|
+
| ClassSetterDecoratorContext<T>
|
|
11
|
+
| ClassAccessorDecoratorContext<T>
|
|
12
|
+
| ClassMethodDecoratorContext<T>,
|
|
13
|
+
) => void;
|