@mikro-orm/decorators 7.0.0-dev.64
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/LICENSE +21 -0
- package/README.md +390 -0
- package/es/Check.d.ts +2 -0
- package/es/Check.js +8 -0
- package/es/CreateRequestContext.d.ts +3 -0
- package/es/CreateRequestContext.js +29 -0
- package/es/Embeddable.d.ts +2 -0
- package/es/Embeddable.js +11 -0
- package/es/Embedded.d.ts +2 -0
- package/es/Embedded.js +15 -0
- package/es/Entity.d.ts +2 -0
- package/es/Entity.js +11 -0
- package/es/Enum.d.ts +2 -0
- package/es/Enum.js +14 -0
- package/es/Filter.d.ts +2 -0
- package/es/Filter.js +7 -0
- package/es/Formula.d.ts +2 -0
- package/es/Formula.js +13 -0
- package/es/Indexed.d.ts +3 -0
- package/es/Indexed.js +17 -0
- package/es/ManyToMany.d.ts +2 -0
- package/es/ManyToMany.js +12 -0
- package/es/ManyToOne.d.ts +2 -0
- package/es/ManyToOne.js +11 -0
- package/es/OneToMany.d.ts +3 -0
- package/es/OneToMany.js +12 -0
- package/es/OneToOne.d.ts +2 -0
- package/es/OneToOne.js +13 -0
- package/es/PrimaryKey.d.ts +3 -0
- package/es/PrimaryKey.js +17 -0
- package/es/Property.d.ts +2 -0
- package/es/Property.js +31 -0
- package/es/Transactional.d.ts +15 -0
- package/es/Transactional.js +27 -0
- package/es/hooks.d.ts +16 -0
- package/es/hooks.js +45 -0
- package/es/index.d.ts +17 -0
- package/es/index.js +17 -0
- package/legacy/Check.d.ts +2 -0
- package/legacy/Check.js +12 -0
- package/legacy/CreateRequestContext.d.ts +3 -0
- package/legacy/CreateRequestContext.js +31 -0
- package/legacy/Embeddable.d.ts +2 -0
- package/legacy/Embeddable.js +11 -0
- package/legacy/Embedded.d.ts +2 -0
- package/legacy/Embedded.js +14 -0
- package/legacy/Entity.d.ts +2 -0
- package/legacy/Entity.js +11 -0
- package/legacy/Enum.d.ts +2 -0
- package/legacy/Enum.js +13 -0
- package/legacy/Filter.d.ts +2 -0
- package/legacy/Filter.js +7 -0
- package/legacy/Formula.d.ts +2 -0
- package/legacy/Formula.js +12 -0
- package/legacy/Indexed.d.ts +3 -0
- package/legacy/Indexed.js +19 -0
- package/legacy/ManyToMany.d.ts +2 -0
- package/legacy/ManyToMany.js +10 -0
- package/legacy/ManyToOne.d.ts +2 -0
- package/legacy/ManyToOne.js +10 -0
- package/legacy/OneToMany.d.ts +3 -0
- package/legacy/OneToMany.js +10 -0
- package/legacy/OneToOne.d.ts +2 -0
- package/legacy/OneToOne.js +12 -0
- package/legacy/PrimaryKey.d.ts +3 -0
- package/legacy/PrimaryKey.js +16 -0
- package/legacy/Property.d.ts +2 -0
- package/legacy/Property.js +28 -0
- package/legacy/ReflectMetadataProvider.d.ts +6 -0
- package/legacy/ReflectMetadataProvider.js +39 -0
- package/legacy/Transactional.d.ts +15 -0
- package/legacy/Transactional.js +29 -0
- package/legacy/hooks.d.ts +16 -0
- package/legacy/hooks.js +44 -0
- package/legacy/index.d.ts +18 -0
- package/legacy/index.js +18 -0
- package/package.json +66 -0
- package/resolveContextProvider.d.ts +14 -0
- package/resolveContextProvider.js +26 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function BeforeCreate(): (target: any, method: string) => void;
|
|
2
|
+
export declare function AfterCreate(): (target: any, method: string) => void;
|
|
3
|
+
export declare function BeforeUpdate(): (target: any, method: string) => void;
|
|
4
|
+
export declare function AfterUpdate(): (target: any, method: string) => void;
|
|
5
|
+
export declare function BeforeUpsert(): (target: any, method: string) => void;
|
|
6
|
+
export declare function AfterUpsert(): (target: any, method: string) => void;
|
|
7
|
+
export declare function OnInit(): (target: any, method: string) => void;
|
|
8
|
+
export declare function OnLoad(): (target: any, method: string) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Called before deleting entity, but only when providing initialized entity to EM#remove()
|
|
11
|
+
*/
|
|
12
|
+
export declare function BeforeDelete(): (target: any, method: string) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Called after deleting entity, but only when providing initialized entity to EM#remove()
|
|
15
|
+
*/
|
|
16
|
+
export declare function AfterDelete(): (target: any, method: string) => void;
|
package/legacy/hooks.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { MetadataStorage, EventType } from '@mikro-orm/core';
|
|
2
|
+
function hook(type) {
|
|
3
|
+
return function (target, method) {
|
|
4
|
+
const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
|
|
5
|
+
meta.hooks[type] ??= [];
|
|
6
|
+
meta.hooks[type].push(method);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function BeforeCreate() {
|
|
10
|
+
return hook(EventType.beforeCreate);
|
|
11
|
+
}
|
|
12
|
+
export function AfterCreate() {
|
|
13
|
+
return hook(EventType.afterCreate);
|
|
14
|
+
}
|
|
15
|
+
export function BeforeUpdate() {
|
|
16
|
+
return hook(EventType.beforeUpdate);
|
|
17
|
+
}
|
|
18
|
+
export function AfterUpdate() {
|
|
19
|
+
return hook(EventType.afterUpdate);
|
|
20
|
+
}
|
|
21
|
+
export function BeforeUpsert() {
|
|
22
|
+
return hook(EventType.beforeUpsert);
|
|
23
|
+
}
|
|
24
|
+
export function AfterUpsert() {
|
|
25
|
+
return hook(EventType.afterUpsert);
|
|
26
|
+
}
|
|
27
|
+
export function OnInit() {
|
|
28
|
+
return hook(EventType.onInit);
|
|
29
|
+
}
|
|
30
|
+
export function OnLoad() {
|
|
31
|
+
return hook(EventType.onLoad);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Called before deleting entity, but only when providing initialized entity to EM#remove()
|
|
35
|
+
*/
|
|
36
|
+
export function BeforeDelete() {
|
|
37
|
+
return hook(EventType.beforeDelete);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Called after deleting entity, but only when providing initialized entity to EM#remove()
|
|
41
|
+
*/
|
|
42
|
+
export function AfterDelete() {
|
|
43
|
+
return hook(EventType.afterDelete);
|
|
44
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './PrimaryKey.js';
|
|
2
|
+
export * from './Entity.js';
|
|
3
|
+
export * from './OneToOne.js';
|
|
4
|
+
export * from './ManyToOne.js';
|
|
5
|
+
export * from './ManyToMany.js';
|
|
6
|
+
export * from './OneToMany.js';
|
|
7
|
+
export * from './Property.js';
|
|
8
|
+
export * from './Check.js';
|
|
9
|
+
export * from './Enum.js';
|
|
10
|
+
export * from './Formula.js';
|
|
11
|
+
export * from './Indexed.js';
|
|
12
|
+
export * from './Embeddable.js';
|
|
13
|
+
export * from './Embedded.js';
|
|
14
|
+
export * from './Filter.js';
|
|
15
|
+
export * from './CreateRequestContext.js';
|
|
16
|
+
export * from './hooks.js';
|
|
17
|
+
export * from './Transactional.js';
|
|
18
|
+
export * from './ReflectMetadataProvider.js';
|
package/legacy/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './PrimaryKey.js';
|
|
2
|
+
export * from './Entity.js';
|
|
3
|
+
export * from './OneToOne.js';
|
|
4
|
+
export * from './ManyToOne.js';
|
|
5
|
+
export * from './ManyToMany.js';
|
|
6
|
+
export * from './OneToMany.js';
|
|
7
|
+
export * from './Property.js';
|
|
8
|
+
export * from './Check.js';
|
|
9
|
+
export * from './Enum.js';
|
|
10
|
+
export * from './Formula.js';
|
|
11
|
+
export * from './Indexed.js';
|
|
12
|
+
export * from './Embeddable.js';
|
|
13
|
+
export * from './Embedded.js';
|
|
14
|
+
export * from './Filter.js';
|
|
15
|
+
export * from './CreateRequestContext.js';
|
|
16
|
+
export * from './hooks.js';
|
|
17
|
+
export * from './Transactional.js';
|
|
18
|
+
export * from './ReflectMetadataProvider.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mikro-orm/decorators",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "7.0.0-dev.64",
|
|
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
|
+
"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
|
+
"keywords": [
|
|
17
|
+
"orm",
|
|
18
|
+
"mongo",
|
|
19
|
+
"mongodb",
|
|
20
|
+
"mysql",
|
|
21
|
+
"mariadb",
|
|
22
|
+
"postgresql",
|
|
23
|
+
"sqlite",
|
|
24
|
+
"sqlite3",
|
|
25
|
+
"ts",
|
|
26
|
+
"typescript",
|
|
27
|
+
"js",
|
|
28
|
+
"javascript",
|
|
29
|
+
"entity",
|
|
30
|
+
"ddd",
|
|
31
|
+
"mikro-orm",
|
|
32
|
+
"unit-of-work",
|
|
33
|
+
"data-mapper",
|
|
34
|
+
"identity-map"
|
|
35
|
+
],
|
|
36
|
+
"author": "Martin Adámek",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/mikro-orm/mikro-orm/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://mikro-orm.io",
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">= 22.17.0"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "yarn clean && yarn compile && yarn copy",
|
|
47
|
+
"clean": "yarn run -T rimraf ./dist",
|
|
48
|
+
"compile": "yarn run -T tsc -p tsconfig.build.json",
|
|
49
|
+
"copy": "node ../../scripts/copy.mjs"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@mikro-orm/core": "^6.6.1"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"@mikro-orm/core": "7.0.0-dev.64",
|
|
59
|
+
"reflect-metadata": "^0.1.0 || ^0.2.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"reflect-metadata": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type MaybePromise, EntityManager, EntityRepository, MikroORM } from '@mikro-orm/core';
|
|
2
|
+
/**
|
|
3
|
+
* The type of context that the user intends to inject.
|
|
4
|
+
*/
|
|
5
|
+
export type ContextProvider<T> = MaybePromise<MikroORM> | ((type: T) => MaybePromise<MikroORM | EntityManager | EntityRepository<any> | {
|
|
6
|
+
getEntityManager(): EntityManager;
|
|
7
|
+
}>);
|
|
8
|
+
/**
|
|
9
|
+
* Find `EntityManager` in provided context, or else in instance's `orm` or `em` properties.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveContextProvider<T>(caller: T & {
|
|
12
|
+
orm?: MaybePromise<MikroORM>;
|
|
13
|
+
em?: MaybePromise<EntityManager>;
|
|
14
|
+
}, provider?: ContextProvider<T>): Promise<EntityManager | undefined>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EntityManager, EntityRepository, MikroORM } from '@mikro-orm/core';
|
|
2
|
+
function getEntityManager(caller, context) {
|
|
3
|
+
if (context instanceof EntityManager) {
|
|
4
|
+
return context;
|
|
5
|
+
}
|
|
6
|
+
if (context instanceof EntityRepository) {
|
|
7
|
+
return context.getEntityManager();
|
|
8
|
+
}
|
|
9
|
+
if (context instanceof MikroORM) {
|
|
10
|
+
return context.em;
|
|
11
|
+
}
|
|
12
|
+
if (caller.em instanceof EntityManager) {
|
|
13
|
+
return caller.em;
|
|
14
|
+
}
|
|
15
|
+
if (caller.orm instanceof MikroORM) {
|
|
16
|
+
return caller.orm.em;
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Find `EntityManager` in provided context, or else in instance's `orm` or `em` properties.
|
|
22
|
+
*/
|
|
23
|
+
export async function resolveContextProvider(caller, provider) {
|
|
24
|
+
const context = typeof provider === 'function' ? await provider(caller) : await provider;
|
|
25
|
+
return getEntityManager({ orm: await caller.orm, em: await caller.em }, context);
|
|
26
|
+
}
|