@mikro-orm/decorators 7.0.0-rc.2 → 7.0.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/README.md +5 -4
- package/es/CreateRequestContext.d.ts +1 -1
- package/es/Indexed.d.ts +2 -2
- package/es/PrimaryKey.d.ts +2 -2
- 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/Indexed.d.ts +2 -2
- 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 +6 -3
package/README.md
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
<a href="https://mikro-orm.io"><img src="https://raw.githubusercontent.com/mikro-orm/mikro-orm/master/docs/static/img/logo-readme.svg?sanitize=true" alt="MikroORM" /></a>
|
|
3
3
|
</h1>
|
|
4
4
|
|
|
5
|
-
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL
|
|
5
|
+
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL, SQLite (including libSQL), MSSQL and Oracle databases.
|
|
6
6
|
|
|
7
7
|
> Heavily inspired by [Doctrine](https://www.doctrine-project.org/) and [Hibernate](https://hibernate.org/).
|
|
8
8
|
|
|
9
|
-
[](https://
|
|
10
|
-
[](https://
|
|
9
|
+
[](https://npmx.dev/package/@mikro-orm/core)
|
|
10
|
+
[](https://npmx.dev/package/@mikro-orm/core)
|
|
11
11
|
[](https://discord.gg/w8bjxFHS7X)
|
|
12
|
-
[](https://
|
|
12
|
+
[](https://npmx.dev/package/@mikro-orm/core)
|
|
13
13
|
[](https://coveralls.io/r/mikro-orm/mikro-orm?branch=master)
|
|
14
14
|
[](https://github.com/mikro-orm/mikro-orm/actions?workflow=tests)
|
|
15
15
|
|
|
@@ -181,6 +181,7 @@ yarn add @mikro-orm/core @mikro-orm/mysql # for mysql/mariadb
|
|
|
181
181
|
yarn add @mikro-orm/core @mikro-orm/mariadb # for mysql/mariadb
|
|
182
182
|
yarn add @mikro-orm/core @mikro-orm/postgresql # for postgresql
|
|
183
183
|
yarn add @mikro-orm/core @mikro-orm/mssql # for mssql
|
|
184
|
+
yarn add @mikro-orm/core @mikro-orm/oracledb # for oracle
|
|
184
185
|
yarn add @mikro-orm/core @mikro-orm/sqlite # for sqlite
|
|
185
186
|
yarn add @mikro-orm/core @mikro-orm/libsql # for libsql
|
|
186
187
|
```
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type ContextProvider } from '../utils.js';
|
|
2
2
|
export declare function CreateRequestContext<T extends object>(contextProvider?: ContextProvider<T>, respectExistingContext?: boolean): (value: (this: T, ...args: any) => any, context: ClassMethodDecoratorContext<T>) => (this: T, ...args: any[]) => Promise<any>;
|
|
3
|
-
export declare function EnsureRequestContext<T extends object>(context?: ContextProvider<T>): (value: (this: T, ...args: any) => any, context: ClassMethodDecoratorContext<T
|
|
3
|
+
export declare function EnsureRequestContext<T extends object>(context?: ContextProvider<T>): (value: (this: T, ...args: any) => any, context: ClassMethodDecoratorContext<T>) => (this: T, ...args: any[]) => Promise<any>;
|
package/es/Indexed.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type IndexOptions, type UniqueOptions, type Constructor } from '@mikro-orm/core';
|
|
2
|
-
export declare function Index<T extends object, H extends string>(options?: IndexOptions<T, H>): (value: unknown, context: ClassDecoratorContext<T & Constructor> | ClassFieldDecoratorContext<T
|
|
3
|
-
export declare function Unique<T extends object, H extends string>(options?: UniqueOptions<T, H>): (value: unknown, context: ClassDecoratorContext<T & Constructor> | ClassFieldDecoratorContext<T
|
|
2
|
+
export declare function Index<T extends object, H extends string>(options?: IndexOptions<T, H>): (value: unknown, context: ClassDecoratorContext<T & Constructor> | ClassFieldDecoratorContext<T>) => any;
|
|
3
|
+
export declare function Unique<T extends object, H extends string>(options?: UniqueOptions<T, H>): (value: unknown, context: ClassDecoratorContext<T & Constructor> | ClassFieldDecoratorContext<T>) => any;
|
package/es/PrimaryKey.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type PrimaryKeyOptions, type SerializedPrimaryKeyOptions } from '@mikro-orm/core';
|
|
2
|
-
export declare function PrimaryKey<T extends object>(options?: PrimaryKeyOptions<T>): (value: unknown, context: ClassFieldDecoratorContext<T
|
|
3
|
-
export declare function SerializedPrimaryKey<T extends object>(options?: SerializedPrimaryKeyOptions<T>): (value: unknown, context: ClassFieldDecoratorContext<T
|
|
2
|
+
export declare function PrimaryKey<T extends object>(options?: PrimaryKeyOptions<T>): (value: unknown, context: ClassFieldDecoratorContext<T>) => void;
|
|
3
|
+
export declare function SerializedPrimaryKey<T extends object>(options?: SerializedPrimaryKeyOptions<T>): (value: unknown, context: ClassFieldDecoratorContext<T>) => void;
|
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/Indexed.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type EntityClass, type IndexOptions, type UniqueOptions } from '@mikro-orm/core';
|
|
2
|
-
export declare function Index<T extends object, H extends string>(options?: IndexOptions<T, H>): (target: T, propertyName?:
|
|
3
|
-
export declare function Unique<T extends object, H extends string>(options?: UniqueOptions<T, H>): (target: T, propertyName?:
|
|
2
|
+
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;
|
|
3
|
+
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/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.2",
|
|
3
|
+
"version": "7.0.0",
|
|
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": "^
|
|
52
|
+
"@mikro-orm/core": "^7.0.0"
|
|
56
53
|
},
|
|
57
54
|
"peerDependencies": {
|
|
58
|
-
"@mikro-orm/core": "
|
|
55
|
+
"@mikro-orm/core": "^6.0.0",
|
|
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
|
@@ -86,7 +86,7 @@ export function lookupPathFromDecorator(name, stack) {
|
|
|
86
86
|
// __decorate(), replacing it with the constructor name. To support these cases we look for
|
|
87
87
|
// Reflect.decorate() as well. Also when babel is used, we need to check
|
|
88
88
|
// the `_applyDecoratedDescriptor` method instead.
|
|
89
|
-
let line = stack.findIndex(line =>
|
|
89
|
+
let line = stack.findIndex(line => /__decorate|Reflect\.decorate|_applyDecoratedDescriptor/.exec(line));
|
|
90
90
|
// bun does not have those lines at all, only the DecorateProperty/DecorateConstructor,
|
|
91
91
|
// but those are also present in node, so we need to check this only if they weren't found.
|
|
92
92
|
if (line === -1) {
|
|
@@ -105,7 +105,7 @@ export function lookupPathFromDecorator(name, stack) {
|
|
|
105
105
|
line++;
|
|
106
106
|
}
|
|
107
107
|
try {
|
|
108
|
-
const re =
|
|
108
|
+
const re = /\(.+\)/i.exec(stack[line]) ? /\((.*):\d+:\d+\)/ : /at\s*(.*):\d+:\d+$/;
|
|
109
109
|
return stack[line].match(re)[1];
|
|
110
110
|
}
|
|
111
111
|
catch {
|
|
@@ -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
|
}
|