@mikro-orm/decorators 7.0.0-dev.98 → 7.0.0-rc.0
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/es/Embeddable.js +3 -2
- package/es/Embedded.d.ts +1 -1
- package/es/Embedded.js +2 -4
- package/es/Entity.d.ts +1 -1
- package/es/Entity.js +3 -2
- package/es/Enum.js +2 -2
- package/es/Formula.d.ts +2 -2
- package/es/Formula.js +2 -2
- package/es/ManyToMany.js +2 -4
- package/es/ManyToOne.d.ts +1 -1
- package/es/ManyToOne.js +2 -4
- package/es/OneToMany.js +2 -4
- package/es/OneToOne.d.ts +1 -1
- package/es/OneToOne.js +2 -4
- package/es/PrimaryKey.js +2 -4
- package/es/Property.js +2 -4
- package/legacy/Embedded.d.ts +1 -1
- package/legacy/Formula.d.ts +2 -2
- package/legacy/ManyToMany.d.ts +3 -1
- package/legacy/ManyToOne.d.ts +3 -1
- package/legacy/OneToMany.d.ts +1 -1
- package/legacy/OneToOne.d.ts +2 -1
- package/legacy/ReflectMetadataProvider.js +5 -2
- package/package.json +4 -4
- package/utils.d.ts +9 -3
- package/utils.js +22 -7
package/es/Embeddable.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Utils
|
|
1
|
+
import { Utils } from '@mikro-orm/core';
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
3
|
export function Embeddable(options = {}) {
|
|
4
4
|
return function (target, context) {
|
|
5
5
|
const meta = getMetadataFromDecorator(target);
|
|
6
|
-
|
|
6
|
+
const metadata = { ...context.metadata };
|
|
7
|
+
Utils.mergeConfig(meta, metadata, options);
|
|
7
8
|
meta.class = target;
|
|
8
9
|
meta.name = meta.class.name;
|
|
9
10
|
meta.embeddable = true;
|
package/es/Embedded.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type EntityName, type EmbeddedOptions } from '@mikro-orm/core';
|
|
2
|
-
export declare function Embedded<Owner extends object, Target>(type?: EmbeddedOptions<Owner, Target> | (() => EntityName<Target> | EntityName
|
|
2
|
+
export declare function Embedded<Owner extends object, Target>(type?: EmbeddedOptions<Owner, Target> | (() => EntityName<Target> | EntityName[]), options?: EmbeddedOptions<Owner, Target>): (value: unknown, context: ClassFieldDecoratorContext<Owner>) => void;
|
package/es/Embedded.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
2
|
-
import {
|
|
2
|
+
import { prepareMetadataContext } from '../utils.js';
|
|
3
3
|
export function Embedded(type = {}, options = {}) {
|
|
4
4
|
return function (value, context) {
|
|
5
|
-
const meta = context.
|
|
6
|
-
meta.properties ??= {};
|
|
7
|
-
validateSingleDecorator(meta, context.name, ReferenceKind.EMBEDDED);
|
|
5
|
+
const meta = prepareMetadataContext(context, ReferenceKind.EMBEDDED);
|
|
8
6
|
options = type instanceof Function ? { entity: type, ...options } : { ...type, ...options };
|
|
9
7
|
Utils.defaultValue(options, 'prefix', true);
|
|
10
8
|
meta.properties[context.name] = {
|
package/es/Entity.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Constructor, type EntityOptions, type EntityClass } from '@mikro-orm/core';
|
|
2
2
|
export declare function Entity<Owner extends EntityClass<unknown> & Constructor>(options?: EntityOptions<Owner>): (target: Owner, context: ClassDecoratorContext<Owner>) => void;
|
package/es/Entity.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Utils
|
|
1
|
+
import { Utils } from '@mikro-orm/core';
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
3
|
export function Entity(options = {}) {
|
|
4
4
|
return function (target, context) {
|
|
5
5
|
const meta = getMetadataFromDecorator(target);
|
|
6
|
-
|
|
6
|
+
const metadata = { ...context.metadata };
|
|
7
|
+
Utils.mergeConfig(meta, metadata, options);
|
|
7
8
|
meta.class = target;
|
|
8
9
|
if (!options.abstract || meta.discriminatorColumn) {
|
|
9
10
|
meta.name = context.name;
|
package/es/Enum.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReferenceKind, } from '@mikro-orm/core';
|
|
2
|
+
import { prepareMetadataContext } from '../utils.js';
|
|
2
3
|
export function Enum(options = {}) {
|
|
3
4
|
return function (target, context) {
|
|
4
|
-
const meta = context
|
|
5
|
-
meta.properties ??= {};
|
|
5
|
+
const meta = prepareMetadataContext(context);
|
|
6
6
|
options = options instanceof Function ? { items: options } : options;
|
|
7
7
|
meta.properties[context.name] = {
|
|
8
8
|
name: context.name,
|
package/es/Formula.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type PropertyOptions } from '@mikro-orm/core';
|
|
2
|
-
export declare function Formula<Owner extends object>(formula: string |
|
|
1
|
+
import { type FormulaCallback, type PropertyOptions } from '@mikro-orm/core';
|
|
2
|
+
export declare function Formula<Owner extends object>(formula: string | FormulaCallback<Owner>, options?: PropertyOptions<Owner>): (value: unknown, context: ClassFieldDecoratorContext<Owner>) => void;
|
package/es/Formula.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReferenceKind, } from '@mikro-orm/core';
|
|
2
|
+
import { prepareMetadataContext } from '../utils.js';
|
|
2
3
|
export function Formula(formula, options = {}) {
|
|
3
4
|
return function (value, context) {
|
|
4
|
-
const meta = context
|
|
5
|
-
meta.properties ??= {};
|
|
5
|
+
const meta = prepareMetadataContext(context);
|
|
6
6
|
meta.properties[context.name] = {
|
|
7
7
|
name: context.name,
|
|
8
8
|
kind: ReferenceKind.SCALAR,
|
package/es/ManyToMany.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
2
|
-
import {
|
|
2
|
+
import { prepareMetadataContext, processDecoratorParameters } from '../utils.js';
|
|
3
3
|
export function ManyToMany(entity, mappedBy, options = {}) {
|
|
4
4
|
return function (_, context) {
|
|
5
|
-
const meta = context.
|
|
6
|
-
meta.properties ??= {};
|
|
7
|
-
validateSingleDecorator(meta, context.name, ReferenceKind.MANY_TO_MANY);
|
|
5
|
+
const meta = prepareMetadataContext(context, ReferenceKind.MANY_TO_MANY);
|
|
8
6
|
options = processDecoratorParameters({ entity, mappedBy, options });
|
|
9
7
|
const property = { name: context.name, kind: ReferenceKind.MANY_TO_MANY };
|
|
10
8
|
meta.properties[context.name] ??= {};
|
package/es/ManyToOne.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type ManyToOneOptions, type EntityName, type Ref } from '@mikro-orm/core';
|
|
2
|
-
export declare function ManyToOne<Target extends object, Owner extends object>(entity?: ManyToOneOptions<Owner, Target> |
|
|
2
|
+
export declare function ManyToOne<Target extends object, Owner extends object>(entity?: ManyToOneOptions<Owner, Target> | ((e?: Owner) => EntityName<Target> | EntityName[]), options?: Partial<ManyToOneOptions<Owner, Target>>): (_: unknown, context: ClassFieldDecoratorContext<Owner, Target | undefined | null | Ref<Target>>) => void;
|
package/es/ManyToOne.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
2
|
-
import {
|
|
2
|
+
import { prepareMetadataContext, processDecoratorParameters } from '../utils.js';
|
|
3
3
|
export function ManyToOne(entity = {}, options = {}) {
|
|
4
4
|
return function (_, context) {
|
|
5
|
-
const meta = context.
|
|
6
|
-
meta.properties ??= {};
|
|
7
|
-
validateSingleDecorator(meta, context.name, ReferenceKind.MANY_TO_ONE);
|
|
5
|
+
const meta = prepareMetadataContext(context, ReferenceKind.MANY_TO_ONE);
|
|
8
6
|
options = processDecoratorParameters({ entity, options });
|
|
9
7
|
const property = { name: context.name, kind: ReferenceKind.MANY_TO_ONE };
|
|
10
8
|
meta.properties[context.name] = Utils.mergeConfig(meta.properties[context.name] ?? {}, property, options);
|
package/es/OneToMany.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
2
|
-
import {
|
|
2
|
+
import { prepareMetadataContext, processDecoratorParameters } from '../utils.js';
|
|
3
3
|
export function OneToMany(entity, mappedBy, options = {}) {
|
|
4
4
|
return function (value, context) {
|
|
5
|
-
const meta = context.
|
|
6
|
-
meta.properties ??= {};
|
|
7
|
-
validateSingleDecorator(meta, context.name, ReferenceKind.ONE_TO_MANY);
|
|
5
|
+
const meta = prepareMetadataContext(context, ReferenceKind.ONE_TO_MANY);
|
|
8
6
|
options = processDecoratorParameters({ entity, mappedBy, options });
|
|
9
7
|
const property = { name: context.name, kind: ReferenceKind.ONE_TO_MANY };
|
|
10
8
|
meta.properties[context.name] ??= {};
|
package/es/OneToOne.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type EntityName, type OneToOneOptions, type Ref } from '@mikro-orm/core';
|
|
2
|
-
export declare function OneToOne<Target extends object, Owner extends object>(entity?: OneToOneOptions<Owner, Target> | string | ((e: Owner) => EntityName<Target>), mappedByOrOptions?: (string & keyof Target) | ((e: Target) => any) | Partial<OneToOneOptions<Owner, Target>>, options?: Partial<OneToOneOptions<Owner, Target>>): (_: unknown, context: ClassFieldDecoratorContext<Owner, Target | Ref<Target> | null | undefined>) => void;
|
|
2
|
+
export declare function OneToOne<Target extends object, Owner extends object>(entity?: OneToOneOptions<Owner, Target> | string | ((e: Owner) => EntityName<Target> | EntityName[]), mappedByOrOptions?: (string & keyof Target) | ((e: Target) => any) | Partial<OneToOneOptions<Owner, Target>>, options?: Partial<OneToOneOptions<Owner, Target>>): (_: unknown, context: ClassFieldDecoratorContext<Owner, Target | Ref<Target> | null | undefined>) => void;
|
package/es/OneToOne.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { ReferenceKind, } from '@mikro-orm/core';
|
|
2
|
-
import {
|
|
2
|
+
import { prepareMetadataContext, processDecoratorParameters } from '../utils.js';
|
|
3
3
|
export function OneToOne(entity, mappedByOrOptions, options = {}) {
|
|
4
4
|
const mappedBy = typeof mappedByOrOptions === 'object' ? mappedByOrOptions.mappedBy : mappedByOrOptions;
|
|
5
5
|
options = typeof mappedByOrOptions === 'object' ? { ...mappedByOrOptions, ...options } : options;
|
|
6
6
|
return function (_, context) {
|
|
7
|
-
const meta = context.
|
|
8
|
-
meta.properties ??= {};
|
|
9
|
-
validateSingleDecorator(meta, context.name, ReferenceKind.ONE_TO_ONE);
|
|
7
|
+
const meta = prepareMetadataContext(context, ReferenceKind.ONE_TO_ONE);
|
|
10
8
|
options = processDecoratorParameters({ entity, mappedBy, options });
|
|
11
9
|
const property = { name: context.name, kind: ReferenceKind.ONE_TO_ONE };
|
|
12
10
|
meta.properties[context.name] = Object.assign(meta.properties[context.name] ?? {}, property, options);
|
package/es/PrimaryKey.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { ReferenceKind, } from '@mikro-orm/core';
|
|
2
|
-
import {
|
|
2
|
+
import { prepareMetadataContext } from '../utils.js';
|
|
3
3
|
function createDecorator(options, serialized) {
|
|
4
4
|
return function (value, context) {
|
|
5
|
-
const meta = context.
|
|
6
|
-
meta.properties ??= {};
|
|
7
|
-
validateSingleDecorator(meta, context.name, ReferenceKind.SCALAR);
|
|
5
|
+
const meta = prepareMetadataContext(context, ReferenceKind.SCALAR);
|
|
8
6
|
const key = serialized ? 'serializedPrimaryKey' : 'primary';
|
|
9
7
|
options[key] = true;
|
|
10
8
|
meta.properties[context.name] = { name: context.name, kind: ReferenceKind.SCALAR, ...options };
|
package/es/Property.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
2
|
-
import {
|
|
2
|
+
import { prepareMetadataContext } from '../utils.js';
|
|
3
3
|
export function Property(options = {}) {
|
|
4
4
|
return function (value, context) {
|
|
5
|
-
const meta = context.
|
|
6
|
-
meta.properties ??= {};
|
|
7
|
-
validateSingleDecorator(meta, context.name, ReferenceKind.SCALAR);
|
|
5
|
+
const meta = prepareMetadataContext(context, ReferenceKind.SCALAR);
|
|
8
6
|
const { check, ...opts } = options;
|
|
9
7
|
const prop = { kind: ReferenceKind.SCALAR, ...opts };
|
|
10
8
|
const name = options.name ?? context.name;
|
package/legacy/Embedded.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type AnyEntity, type EntityName, type EmbeddedOptions } from '@mikro-orm/core';
|
|
2
|
-
export declare function Embedded<Owner extends object, Target>(type?: EmbeddedOptions<Owner, Target> | (() => EntityName<Target> | EntityName
|
|
2
|
+
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/Formula.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type PropertyOptions } from '@mikro-orm/core';
|
|
2
|
-
export declare function Formula<T extends object>(formula: string |
|
|
1
|
+
import { type FormulaCallback, type PropertyOptions } from '@mikro-orm/core';
|
|
2
|
+
export declare function Formula<T extends object>(formula: string | FormulaCallback<T>, options?: PropertyOptions<T>): (target: T, propertyName: string) => void;
|
package/legacy/ManyToMany.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { type EntityName, type ManyToManyOptions } from '@mikro-orm/core';
|
|
2
|
-
export declare function ManyToMany<Target extends object, Owner extends object>(entity
|
|
2
|
+
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;
|
|
3
|
+
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>(options?: ManyToManyOptions<Owner, Target>): (target: Owner, propertyName: keyof Owner) => void;
|
package/legacy/ManyToOne.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { type ManyToOneOptions, type EntityName } from '@mikro-orm/core';
|
|
2
|
-
export declare function ManyToOne<Target extends object, Owner extends object>(entity
|
|
2
|
+
export declare function ManyToOne<Target extends object, Owner extends object>(entity: (e?: any) => EntityName<Target> | EntityName[], options?: Partial<ManyToOneOptions<Owner, Target>>): (target: Owner, propertyName: string) => void;
|
|
3
|
+
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>(options?: ManyToOneOptions<Owner, Target>): (target: Owner, propertyName: string) => void;
|
package/legacy/OneToMany.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type EntityName, type OneToManyOptions } from '@mikro-orm/core';
|
|
2
|
-
export declare function OneToMany<Target extends object, Owner extends object>(entity:
|
|
2
|
+
export declare function OneToMany<Target extends object, Owner extends object>(entity: (e?: any) => EntityName<Target>, mappedBy: (string & keyof Target) | ((e: Target) => any), options?: Partial<OneToManyOptions<Owner, Target>>): (target: Owner, propertyName: string) => void;
|
|
3
3
|
export declare function OneToMany<Target extends object, Owner extends object>(options: OneToManyOptions<Owner, Target>): (target: Owner, propertyName: string) => void;
|
package/legacy/OneToOne.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type EntityName, type OneToOneOptions } from '@mikro-orm/core';
|
|
2
|
-
export declare function OneToOne<Target, Owner>(entity
|
|
2
|
+
export declare function OneToOne<Target, Owner>(entity: ((e: Owner) => EntityName<Target> | EntityName[]), mappedByOrOptions?: (string & keyof Target) | ((e: Target) => any) | Partial<OneToOneOptions<Owner, Target>>, options?: Partial<OneToOneOptions<Owner, Target>>): (target: Owner, propertyName: string) => void;
|
|
3
|
+
export declare function OneToOne<Target, Owner>(entity?: OneToOneOptions<Owner, Target>): (target: Owner, propertyName: string) => void;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import { MetadataProvider, ReferenceKind, Utils } from '@mikro-orm/core';
|
|
2
|
+
import { EntitySchema, MetadataProvider, ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
3
3
|
export class ReflectMetadataProvider extends MetadataProvider {
|
|
4
4
|
loadEntityMetadata(meta) {
|
|
5
5
|
// load types and column names
|
|
6
6
|
for (const prop of meta.props) {
|
|
7
|
+
/* v8 ignore next */
|
|
7
8
|
if (typeof prop.entity === 'string') {
|
|
8
|
-
prop.
|
|
9
|
+
throw new Error(`Relation target needs to be an entity class or EntitySchema instance, '${prop.entity}' given instead for ${meta.className}.${prop.name}.`);
|
|
9
10
|
}
|
|
10
11
|
else if (prop.entity) {
|
|
11
12
|
const tmp = prop.entity();
|
|
12
13
|
prop.type = Array.isArray(tmp) ? tmp.map(t => Utils.className(t)).sort().join(' | ') : Utils.className(tmp);
|
|
14
|
+
prop.target = tmp instanceof EntitySchema ? tmp.meta.class : tmp;
|
|
13
15
|
}
|
|
14
16
|
else {
|
|
15
17
|
this.initPropertyType(meta, prop);
|
|
@@ -35,5 +37,6 @@ export class ReflectMetadataProvider extends MetadataProvider {
|
|
|
35
37
|
}
|
|
36
38
|
prop.type ??= typeName;
|
|
37
39
|
prop.runtimeType ??= typeName;
|
|
40
|
+
prop.target = type;
|
|
38
41
|
}
|
|
39
42
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/decorators",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-
|
|
4
|
+
"version": "7.0.0-rc.0",
|
|
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",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"node": ">= 22.17.0"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
|
-
"build": "yarn
|
|
46
|
+
"build": "yarn compile && yarn copy",
|
|
47
47
|
"clean": "yarn run -T rimraf ./dist",
|
|
48
48
|
"compile": "yarn run -T tsc -p tsconfig.build.json",
|
|
49
49
|
"copy": "node ../../scripts/copy.mjs"
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@mikro-orm/core": "^6.6.
|
|
55
|
+
"@mikro-orm/core": "^6.6.4"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@mikro-orm/core": "7.0.0-
|
|
58
|
+
"@mikro-orm/core": "7.0.0-rc.0",
|
|
59
59
|
"reflect-metadata": "^0.1.0 || ^0.2.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependenciesMeta": {
|
package/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Dictionary, EntityManager, type EntityMetadata, EntityRepository, type MaybePromise, MetadataStorage, MikroORM, type ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
/**
|
|
3
3
|
* The type of context that the user intends to inject.
|
|
4
4
|
*/
|
|
@@ -25,9 +25,15 @@ export declare function processDecoratorParameters<T>(params: Dictionary): T;
|
|
|
25
25
|
/**
|
|
26
26
|
* Validate there is only one property decorator. This disallows using `@Property()` together with e.g. `@ManyToOne()`
|
|
27
27
|
* on the same property. One should use only `@ManyToOne()` in such case.
|
|
28
|
-
* We allow the existence of the property in metadata if the reference
|
|
28
|
+
* We allow the existence of the property in metadata if the reference kind is the same, this should allow things like HMR to work.
|
|
29
29
|
*/
|
|
30
|
-
export declare function validateSingleDecorator(meta: EntityMetadata, propertyName: string,
|
|
30
|
+
export declare function validateSingleDecorator(meta: EntityMetadata, propertyName: string, kind: ReferenceKind): void;
|
|
31
|
+
/**
|
|
32
|
+
* Prepares and returns a metadata context for an entity, ensuring default structure and validating proper usage of a single decorator.
|
|
33
|
+
* We need to use the `Object.hasOwn` here, since the metadata object respects inheritance, and the `properties` object might already
|
|
34
|
+
* exist for some base entity.
|
|
35
|
+
*/
|
|
36
|
+
export declare function prepareMetadataContext<T>(context: ClassFieldDecoratorContext<T> | ClassGetterDecoratorContext<T> | ClassMethodDecoratorContext<T>, kind?: ReferenceKind): EntityMetadata<T>;
|
|
31
37
|
/**
|
|
32
38
|
* Uses some dark magic to get source path to caller where decorator is used.
|
|
33
39
|
* Analyzes stack trace of error created inside the function call.
|
package/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EntityManager, EntityRepository, MetadataError, MetadataStorage, MikroORM, Utils, } from '@mikro-orm/core';
|
|
2
2
|
function getEntityManager(caller, context) {
|
|
3
3
|
if (context instanceof EntityManager) {
|
|
4
4
|
return context;
|
|
@@ -53,13 +53,28 @@ export function processDecoratorParameters(params) {
|
|
|
53
53
|
/**
|
|
54
54
|
* Validate there is only one property decorator. This disallows using `@Property()` together with e.g. `@ManyToOne()`
|
|
55
55
|
* on the same property. One should use only `@ManyToOne()` in such case.
|
|
56
|
-
* We allow the existence of the property in metadata if the reference
|
|
56
|
+
* We allow the existence of the property in metadata if the reference kind is the same, this should allow things like HMR to work.
|
|
57
57
|
*/
|
|
58
|
-
export function validateSingleDecorator(meta, propertyName,
|
|
59
|
-
if (meta.properties[propertyName] && meta.properties[propertyName].kind !==
|
|
58
|
+
export function validateSingleDecorator(meta, propertyName, kind) {
|
|
59
|
+
if (meta.properties[propertyName] && meta.properties[propertyName].kind !== kind) {
|
|
60
60
|
throw MetadataError.multipleDecorators(meta.className, propertyName);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Prepares and returns a metadata context for an entity, ensuring default structure and validating proper usage of a single decorator.
|
|
65
|
+
* We need to use the `Object.hasOwn` here, since the metadata object respects inheritance, and the `properties` object might already
|
|
66
|
+
* exist for some base entity.
|
|
67
|
+
*/
|
|
68
|
+
export function prepareMetadataContext(context, kind) {
|
|
69
|
+
const meta = context.metadata;
|
|
70
|
+
if (!Object.hasOwn(meta, 'properties')) {
|
|
71
|
+
meta.properties = { ...meta.properties };
|
|
72
|
+
}
|
|
73
|
+
if (kind) {
|
|
74
|
+
validateSingleDecorator(meta, context.name, kind);
|
|
75
|
+
}
|
|
76
|
+
return meta;
|
|
77
|
+
}
|
|
63
78
|
/**
|
|
64
79
|
* Uses some dark magic to get source path to caller where decorator is used.
|
|
65
80
|
* Analyzes stack trace of error created inside the function call.
|
|
@@ -77,7 +92,7 @@ export function lookupPathFromDecorator(name, stack) {
|
|
|
77
92
|
if (line === -1) {
|
|
78
93
|
// here we handle bun which stack is different from nodejs so we search for reflect-metadata
|
|
79
94
|
// Different bun versions might have different stack traces. The "last index" works for both 1.2.6 and 1.2.7.
|
|
80
|
-
const reflectLine = stack.findLastIndex(line =>
|
|
95
|
+
const reflectLine = stack.findLastIndex(line => line.replace(/\\/g, '/').includes('node_modules/reflect-metadata/Reflect.js'));
|
|
81
96
|
if (reflectLine === -1 || reflectLine + 2 >= stack.length || !stack[reflectLine + 1].includes('bun:wrap')) {
|
|
82
97
|
return name;
|
|
83
98
|
}
|
|
@@ -86,12 +101,12 @@ export function lookupPathFromDecorator(name, stack) {
|
|
|
86
101
|
if (stack[line].includes('Reflect.decorate')) {
|
|
87
102
|
line++;
|
|
88
103
|
}
|
|
89
|
-
if (
|
|
104
|
+
if (stack[line].replace(/\\/g, '/').includes('node_modules/tslib/tslib')) {
|
|
90
105
|
line++;
|
|
91
106
|
}
|
|
92
107
|
try {
|
|
93
108
|
const re = stack[line].match(/\(.+\)/i) ? /\((.*):\d+:\d+\)/ : /at\s*(.*):\d+:\d+$/;
|
|
94
|
-
return
|
|
109
|
+
return stack[line].match(re)[1];
|
|
95
110
|
}
|
|
96
111
|
catch {
|
|
97
112
|
return name;
|