@mikro-orm/decorators 7.0.0-rc.1 → 7.0.0-rc.3
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/PrimaryKey.js +5 -1
- package/es/Property.js +1 -1
- package/es/Transactional.js +3 -3
- package/legacy/Formula.js +1 -1
- package/legacy/OneToMany.js +1 -1
- package/legacy/OneToOne.d.ts +1 -1
- package/legacy/PrimaryKey.js +5 -1
- package/legacy/Property.js +1 -1
- package/legacy/ReflectMetadataProvider.js +9 -2
- package/legacy/Transactional.js +3 -3
- package/package.json +32 -32
- package/utils.js +4 -1
package/es/PrimaryKey.js
CHANGED
|
@@ -5,7 +5,11 @@ function createDecorator(options, serialized) {
|
|
|
5
5
|
const meta = prepareMetadataContext(context, ReferenceKind.SCALAR);
|
|
6
6
|
const key = serialized ? 'serializedPrimaryKey' : 'primary';
|
|
7
7
|
options[key] = true;
|
|
8
|
-
meta.properties[context.name] = {
|
|
8
|
+
meta.properties[context.name] = {
|
|
9
|
+
name: context.name,
|
|
10
|
+
kind: ReferenceKind.SCALAR,
|
|
11
|
+
...options,
|
|
12
|
+
};
|
|
9
13
|
};
|
|
10
14
|
}
|
|
11
15
|
export function PrimaryKey(options = {}) {
|
package/es/Property.js
CHANGED
package/es/Transactional.js
CHANGED
|
@@ -15,9 +15,9 @@ export function Transactional(options = {}) {
|
|
|
15
15
|
return async function (...args) {
|
|
16
16
|
const { context, contextName, ...txOptions } = options;
|
|
17
17
|
txOptions.propagation ??= TransactionPropagation.REQUIRED;
|
|
18
|
-
const em = (await resolveContextProvider(this, context))
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const em = (await resolveContextProvider(this, context)) ||
|
|
19
|
+
TransactionContext.getEntityManager(contextName) ||
|
|
20
|
+
RequestContext.getEntityManager(contextName);
|
|
21
21
|
if (!em) {
|
|
22
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
23
|
}
|
package/legacy/Formula.js
CHANGED
package/legacy/OneToMany.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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 OneToMany(entity, mappedBy, options = {}) {
|
|
4
4
|
return function (target, propertyName) {
|
package/legacy/OneToOne.d.ts
CHANGED
|
@@ -1,3 +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
3
|
export declare function OneToOne<Target, Owner>(entity?: OneToOneOptions<Owner, Target>): (target: Owner, propertyName: string) => void;
|
package/legacy/PrimaryKey.js
CHANGED
|
@@ -6,7 +6,11 @@ function createDecorator(options, serialized) {
|
|
|
6
6
|
validateSingleDecorator(meta, propertyName, ReferenceKind.SCALAR);
|
|
7
7
|
const k = serialized ? 'serializedPrimaryKey' : 'primary';
|
|
8
8
|
options[k] = true;
|
|
9
|
-
meta.properties[propertyName] = {
|
|
9
|
+
meta.properties[propertyName] = {
|
|
10
|
+
name: propertyName,
|
|
11
|
+
kind: ReferenceKind.SCALAR,
|
|
12
|
+
...options,
|
|
13
|
+
};
|
|
10
14
|
};
|
|
11
15
|
}
|
|
12
16
|
export function PrimaryKey(options = {}) {
|
package/legacy/Property.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Utils, ReferenceKind
|
|
1
|
+
import { Utils, ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { validateSingleDecorator, getMetadataFromDecorator } from '../utils.js';
|
|
3
3
|
export function Property(options = {}) {
|
|
4
4
|
return function (target, propertyName) {
|
|
@@ -10,7 +10,12 @@ export class ReflectMetadataProvider extends MetadataProvider {
|
|
|
10
10
|
}
|
|
11
11
|
else if (prop.entity) {
|
|
12
12
|
const tmp = prop.entity();
|
|
13
|
-
prop.type = Array.isArray(tmp)
|
|
13
|
+
prop.type = Array.isArray(tmp)
|
|
14
|
+
? tmp
|
|
15
|
+
.map(t => Utils.className(t))
|
|
16
|
+
.sort()
|
|
17
|
+
.join(' | ')
|
|
18
|
+
: Utils.className(tmp);
|
|
14
19
|
prop.target = tmp instanceof EntitySchema ? tmp.meta.class : tmp;
|
|
15
20
|
}
|
|
16
21
|
else {
|
|
@@ -20,7 +25,9 @@ export class ReflectMetadataProvider extends MetadataProvider {
|
|
|
20
25
|
}
|
|
21
26
|
initPropertyType(meta, prop) {
|
|
22
27
|
const type = Reflect.getMetadata('design:type', meta.prototype, prop.name);
|
|
23
|
-
if (!prop.type &&
|
|
28
|
+
if (!prop.type &&
|
|
29
|
+
(!type || (type === Object && prop.kind !== ReferenceKind.SCALAR)) &&
|
|
30
|
+
!(prop.enum && (prop.items?.length ?? 0) > 0)) {
|
|
24
31
|
throw new Error(`Please provide either 'type' or 'entity' attribute in ${meta.className}.${prop.name}. Make sure you have 'emitDecoratorMetadata' enabled in your tsconfig.json.`);
|
|
25
32
|
}
|
|
26
33
|
// Force mapping to UnknownType which is a string when we see just `Object`, as that often means failed inference.
|
package/legacy/Transactional.js
CHANGED
|
@@ -16,9 +16,9 @@ export function Transactional(options = {}) {
|
|
|
16
16
|
descriptor.value = async function (...args) {
|
|
17
17
|
const { context, contextName, ...txOptions } = options;
|
|
18
18
|
txOptions.propagation ??= TransactionPropagation.REQUIRED;
|
|
19
|
-
const em = (await resolveContextProvider(this, context))
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const em = (await resolveContextProvider(this, context)) ||
|
|
20
|
+
TransactionContext.getEntityManager(contextName) ||
|
|
21
|
+
RequestContext.getEntityManager(contextName);
|
|
22
22
|
if (!em) {
|
|
23
23
|
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.`);
|
|
24
24
|
}
|
package/package.json
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/decorators",
|
|
3
|
-
"
|
|
4
|
-
"version": "7.0.0-rc.1",
|
|
3
|
+
"version": "7.0.0-rc.3",
|
|
5
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.",
|
|
6
|
-
"exports": {
|
|
7
|
-
"./package.json": "./package.json",
|
|
8
|
-
"./es": "./es/index.js",
|
|
9
|
-
"./legacy": "./legacy/index.js"
|
|
10
|
-
},
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+ssh://git@github.com/mikro-orm/mikro-orm.git"
|
|
14
|
-
},
|
|
15
|
-
"funding": "https://github.com/sponsors/b4nan",
|
|
16
5
|
"keywords": [
|
|
17
|
-
"
|
|
6
|
+
"data-mapper",
|
|
7
|
+
"ddd",
|
|
8
|
+
"entity",
|
|
9
|
+
"identity-map",
|
|
10
|
+
"javascript",
|
|
11
|
+
"js",
|
|
12
|
+
"mariadb",
|
|
13
|
+
"mikro-orm",
|
|
18
14
|
"mongo",
|
|
19
15
|
"mongodb",
|
|
20
16
|
"mysql",
|
|
21
|
-
"
|
|
17
|
+
"orm",
|
|
22
18
|
"postgresql",
|
|
23
19
|
"sqlite",
|
|
24
20
|
"sqlite3",
|
|
25
21
|
"ts",
|
|
26
22
|
"typescript",
|
|
27
|
-
"
|
|
28
|
-
"javascript",
|
|
29
|
-
"entity",
|
|
30
|
-
"ddd",
|
|
31
|
-
"mikro-orm",
|
|
32
|
-
"unit-of-work",
|
|
33
|
-
"data-mapper",
|
|
34
|
-
"identity-map"
|
|
23
|
+
"unit-of-work"
|
|
35
24
|
],
|
|
36
|
-
"
|
|
37
|
-
"license": "MIT",
|
|
25
|
+
"homepage": "https://mikro-orm.io",
|
|
38
26
|
"bugs": {
|
|
39
27
|
"url": "https://github.com/mikro-orm/mikro-orm/issues"
|
|
40
28
|
},
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"author": "Martin Adámek",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+ssh://git@github.com/mikro-orm/mikro-orm.git"
|
|
34
|
+
},
|
|
35
|
+
"funding": "https://github.com/sponsors/b4nan",
|
|
36
|
+
"type": "module",
|
|
37
|
+
"exports": {
|
|
38
|
+
"./package.json": "./package.json",
|
|
39
|
+
"./es": "./es/index.js",
|
|
40
|
+
"./legacy": "./legacy/index.js"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "yarn compile && yarn copy",
|
|
@@ -48,19 +48,19 @@
|
|
|
48
48
|
"compile": "yarn run -T tsc -p tsconfig.build.json",
|
|
49
49
|
"copy": "node ../../scripts/copy.mjs"
|
|
50
50
|
},
|
|
51
|
-
"publishConfig": {
|
|
52
|
-
"access": "public"
|
|
53
|
-
},
|
|
54
51
|
"devDependencies": {
|
|
55
|
-
"@mikro-orm/core": "^6.6.
|
|
52
|
+
"@mikro-orm/core": "^6.6.8"
|
|
56
53
|
},
|
|
57
54
|
"peerDependencies": {
|
|
58
|
-
"@mikro-orm/core": "7.0.0-rc.
|
|
55
|
+
"@mikro-orm/core": "7.0.0-rc.3",
|
|
59
56
|
"reflect-metadata": "^0.1.0 || ^0.2.0"
|
|
60
57
|
},
|
|
61
58
|
"peerDependenciesMeta": {
|
|
62
59
|
"reflect-metadata": {
|
|
63
60
|
"optional": true
|
|
64
61
|
}
|
|
62
|
+
},
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">= 22.17.0"
|
|
65
65
|
}
|
|
66
66
|
}
|
package/utils.js
CHANGED
|
@@ -114,7 +114,10 @@ export function lookupPathFromDecorator(name, stack) {
|
|
|
114
114
|
}
|
|
115
115
|
export function getMetadataFromDecorator(target) {
|
|
116
116
|
if (!Object.hasOwn(target, MetadataStorage.PATH_SYMBOL)) {
|
|
117
|
-
Object.defineProperty(target, MetadataStorage.PATH_SYMBOL, {
|
|
117
|
+
Object.defineProperty(target, MetadataStorage.PATH_SYMBOL, {
|
|
118
|
+
value: lookupPathFromDecorator(target.name),
|
|
119
|
+
writable: true,
|
|
120
|
+
});
|
|
118
121
|
}
|
|
119
122
|
return MetadataStorage.getMetadata(target.name, target[MetadataStorage.PATH_SYMBOL]);
|
|
120
123
|
}
|