@mikro-orm/decorators 7.1.13-dev.1 → 7.1.13-dev.12
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/Check.js +3 -2
- package/es/Indexed.js +2 -2
- package/es/Property.js +2 -3
- package/es/Trigger.js +2 -2
- package/es/hooks.js +3 -3
- package/package.json +2 -2
- package/utils.d.ts +7 -0
- package/utils.js +12 -0
package/es/Check.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { ensureOwnMetadataArray } from '../utils.js';
|
|
1
2
|
/** Defines a database check constraint on a property or entity class (TC39 decorator). */
|
|
2
3
|
export function Check(options) {
|
|
3
4
|
return function (value, context) {
|
|
4
5
|
const meta = context.metadata;
|
|
5
|
-
|
|
6
|
+
const checks = ensureOwnMetadataArray(meta, 'checks');
|
|
6
7
|
if (context.kind === 'field') {
|
|
7
8
|
options.property ??= context.name;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
+
checks.push(options);
|
|
10
11
|
};
|
|
11
12
|
}
|
package/es/Indexed.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ensureOwnMetadataArray } from '../utils.js';
|
|
1
2
|
function createDecorator(options, unique) {
|
|
2
3
|
return function (value, context) {
|
|
3
4
|
const meta = context.metadata;
|
|
@@ -5,8 +6,7 @@ function createDecorator(options, unique) {
|
|
|
5
6
|
options.properties ??= context.name;
|
|
6
7
|
}
|
|
7
8
|
const key = unique ? 'uniques' : 'indexes';
|
|
8
|
-
meta
|
|
9
|
-
meta[key].push(options);
|
|
9
|
+
ensureOwnMetadataArray(meta, key).push(options);
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
/** Defines a database index on a property or entity class (TC39 decorator). */
|
package/es/Property.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReferenceKind, Utils } from '@mikro-orm/core';
|
|
2
|
-
import { prepareMetadataContext } from '../utils.js';
|
|
2
|
+
import { ensureOwnMetadataArray, prepareMetadataContext } from '../utils.js';
|
|
3
3
|
/** Defines a scalar property on an entity (TC39 decorator). */
|
|
4
4
|
export function Property(options = {}) {
|
|
5
5
|
return function (value, context) {
|
|
@@ -7,7 +7,6 @@ export function Property(options = {}) {
|
|
|
7
7
|
const { check, ...opts } = options;
|
|
8
8
|
const prop = { kind: ReferenceKind.SCALAR, ...opts };
|
|
9
9
|
const name = options.name ?? context.name;
|
|
10
|
-
meta.checks ??= [];
|
|
11
10
|
if (context.name !== name) {
|
|
12
11
|
Utils.renameKey(options, 'name', 'fieldName');
|
|
13
12
|
}
|
|
@@ -39,7 +38,7 @@ export function Property(options = {}) {
|
|
|
39
38
|
prop.name = name;
|
|
40
39
|
}
|
|
41
40
|
if (check) {
|
|
42
|
-
meta
|
|
41
|
+
ensureOwnMetadataArray(meta, 'checks').push({ property: prop.name, expression: check });
|
|
43
42
|
}
|
|
44
43
|
meta.properties[prop.name] = prop;
|
|
45
44
|
};
|
package/es/Trigger.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { ensureOwnMetadataArray } from '../utils.js';
|
|
1
2
|
/** Defines a database trigger on an entity class (TC39 decorator). */
|
|
2
3
|
export function Trigger(options) {
|
|
3
4
|
return function (value, context) {
|
|
4
5
|
const meta = context.metadata;
|
|
5
|
-
meta.
|
|
6
|
-
meta.triggers.push(options);
|
|
6
|
+
ensureOwnMetadataArray(meta, 'triggers').push(options);
|
|
7
7
|
};
|
|
8
8
|
}
|
package/es/hooks.js
CHANGED
|
@@ -2,9 +2,9 @@ import { EventType } from '@mikro-orm/core';
|
|
|
2
2
|
function hook(type) {
|
|
3
3
|
return function (value, context) {
|
|
4
4
|
const meta = context.metadata;
|
|
5
|
-
meta.hooks
|
|
6
|
-
|
|
7
|
-
meta.hooks[type].
|
|
5
|
+
meta.hooks = Object.hasOwn(meta, 'hooks') ? meta.hooks : { ...meta.hooks };
|
|
6
|
+
// the array itself may still be inherited from a base class metadata, so never push into it in place
|
|
7
|
+
meta.hooks[type] = [...(meta.hooks[type] ?? []), value];
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
/** Called before a new entity is persisted to the database (TC39 decorator). */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/decorators",
|
|
3
|
-
"version": "7.1.13-dev.
|
|
3
|
+
"version": "7.1.13-dev.12",
|
|
4
4
|
"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.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@mikro-orm/core": "^7.1.12"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@mikro-orm/core": "7.1.13-dev.
|
|
55
|
+
"@mikro-orm/core": "7.1.13-dev.12",
|
|
56
56
|
"reflect-metadata": "^0.1.0 || ^0.2.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
package/utils.d.ts
CHANGED
|
@@ -34,6 +34,13 @@ export declare function validateSingleDecorator(meta: EntityMetadata, propertyNa
|
|
|
34
34
|
* exist for some base entity.
|
|
35
35
|
*/
|
|
36
36
|
export declare function prepareMetadataContext<T>(context: ClassFieldDecoratorContext<T> | ClassGetterDecoratorContext<T> | ClassSetterDecoratorContext<T> | ClassAccessorDecoratorContext<T> | ClassMethodDecoratorContext<T>, kind?: ReferenceKind): EntityMetadata<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Ensures the metadata object has its own array under the given key, copying any items inherited from a base class.
|
|
39
|
+
* The decorator metadata object respects inheritance (a subclass metadata object has the parent metadata object as
|
|
40
|
+
* its prototype), and the `@Entity()` decorator transfers only own properties of the metadata object, so pushing to
|
|
41
|
+
* an inherited array would both leak the item to the base class metadata and lose it for the subclass.
|
|
42
|
+
*/
|
|
43
|
+
export declare function ensureOwnMetadataArray<T, K extends 'checks' | 'indexes' | 'uniques' | 'triggers'>(meta: Partial<EntityMetadata<T>>, key: K): NonNullable<Partial<EntityMetadata<T>>[K]>;
|
|
37
44
|
/**
|
|
38
45
|
* Uses some dark magic to get source path to caller where decorator is used.
|
|
39
46
|
* Analyzes stack trace of error created inside the function call.
|
package/utils.js
CHANGED
|
@@ -75,6 +75,18 @@ export function prepareMetadataContext(context, kind) {
|
|
|
75
75
|
}
|
|
76
76
|
return meta;
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Ensures the metadata object has its own array under the given key, copying any items inherited from a base class.
|
|
80
|
+
* The decorator metadata object respects inheritance (a subclass metadata object has the parent metadata object as
|
|
81
|
+
* its prototype), and the `@Entity()` decorator transfers only own properties of the metadata object, so pushing to
|
|
82
|
+
* an inherited array would both leak the item to the base class metadata and lose it for the subclass.
|
|
83
|
+
*/
|
|
84
|
+
export function ensureOwnMetadataArray(meta, key) {
|
|
85
|
+
if (!Object.hasOwn(meta, key)) {
|
|
86
|
+
meta[key] = [...(meta[key] ?? [])];
|
|
87
|
+
}
|
|
88
|
+
return meta[key];
|
|
89
|
+
}
|
|
78
90
|
/**
|
|
79
91
|
* Uses some dark magic to get source path to caller where decorator is used.
|
|
80
92
|
* Analyzes stack trace of error created inside the function call.
|