@mikro-orm/decorators 7.0.2-dev.9 → 7.0.3-dev.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 +128 -294
- package/es/Check.d.ts +1 -0
- package/es/Check.js +1 -0
- package/es/CreateRequestContext.d.ts +2 -0
- package/es/CreateRequestContext.js +2 -0
- package/es/Embeddable.d.ts +1 -0
- package/es/Embeddable.js +1 -0
- package/es/Embedded.d.ts +1 -0
- package/es/Embedded.js +1 -0
- package/es/Entity.d.ts +1 -0
- package/es/Entity.js +1 -0
- package/es/Enum.d.ts +1 -0
- package/es/Enum.js +1 -0
- package/es/Filter.d.ts +1 -0
- package/es/Filter.js +1 -0
- package/es/Formula.d.ts +1 -0
- package/es/Formula.js +1 -0
- package/es/Indexed.d.ts +2 -0
- package/es/Indexed.js +2 -0
- package/es/ManyToMany.d.ts +1 -0
- package/es/ManyToMany.js +1 -0
- package/es/ManyToOne.d.ts +1 -0
- package/es/ManyToOne.js +1 -0
- package/es/OneToMany.d.ts +1 -0
- package/es/OneToOne.d.ts +1 -0
- package/es/OneToOne.js +1 -0
- package/es/PrimaryKey.d.ts +2 -0
- package/es/PrimaryKey.js +2 -0
- package/es/Property.d.ts +1 -0
- package/es/Property.js +1 -0
- package/es/hooks.d.ts +8 -0
- package/es/hooks.js +8 -0
- package/legacy/Check.d.ts +1 -0
- package/legacy/Check.js +1 -0
- package/legacy/CreateRequestContext.d.ts +2 -0
- package/legacy/CreateRequestContext.js +2 -0
- package/legacy/Embeddable.d.ts +1 -0
- package/legacy/Embeddable.js +1 -0
- package/legacy/Embedded.d.ts +1 -0
- package/legacy/Embedded.js +1 -0
- package/legacy/Entity.d.ts +1 -0
- package/legacy/Entity.js +1 -0
- package/legacy/Enum.d.ts +1 -0
- package/legacy/Enum.js +1 -0
- package/legacy/Filter.d.ts +1 -0
- package/legacy/Filter.js +1 -0
- package/legacy/Formula.d.ts +1 -0
- package/legacy/Formula.js +1 -0
- package/legacy/Indexed.d.ts +2 -0
- package/legacy/Indexed.js +2 -0
- package/legacy/ManyToMany.d.ts +1 -0
- package/legacy/ManyToOne.d.ts +1 -0
- package/legacy/OneToMany.d.ts +1 -0
- package/legacy/OneToOne.d.ts +1 -0
- package/legacy/PrimaryKey.d.ts +2 -0
- package/legacy/PrimaryKey.js +2 -0
- package/legacy/Property.d.ts +1 -0
- package/legacy/Property.js +1 -0
- package/legacy/ReflectMetadataProvider.d.ts +1 -0
- package/legacy/ReflectMetadataProvider.js +2 -1
- package/legacy/hooks.d.ts +8 -0
- package/legacy/hooks.js +8 -0
- package/package.json +3 -3
- package/utils.d.ts +1 -0
- package/utils.js +1 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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, SQLite (including libSQL), MSSQL and Oracle databases.
|
|
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
|
|
|
@@ -13,143 +13,173 @@ TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-or
|
|
|
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
|
|
|
16
|
-
##
|
|
16
|
+
## Quick Start
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Install a driver package for your database:
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
```sh
|
|
21
|
+
npm install @mikro-orm/postgresql # PostgreSQL
|
|
22
|
+
npm install @mikro-orm/mysql # MySQL
|
|
23
|
+
npm install @mikro-orm/mariadb # MariaDB
|
|
24
|
+
npm install @mikro-orm/sqlite # SQLite
|
|
25
|
+
npm install @mikro-orm/libsql # libSQL / Turso
|
|
26
|
+
npm install @mikro-orm/mongodb # MongoDB
|
|
27
|
+
npm install @mikro-orm/mssql # MS SQL Server
|
|
28
|
+
npm install @mikro-orm/oracledb # Oracle
|
|
29
|
+
```
|
|
22
30
|
|
|
23
|
-
>
|
|
24
|
-
> loaded object in a map. Looks up objects using the map when referring to them.
|
|
25
|
-
> [(Martin Fowler)](https://www.martinfowler.com/eaaCatalog/identityMap.html)
|
|
31
|
+
> If you use additional packages like `@mikro-orm/cli`, `@mikro-orm/migrations`, or `@mikro-orm/entity-generator`, install `@mikro-orm/core` explicitly as well. See the [quick start guide](https://mikro-orm.io/docs/quick-start) for details.
|
|
26
32
|
|
|
27
|
-
|
|
33
|
+
### Define Entities
|
|
28
34
|
|
|
29
|
-
|
|
35
|
+
The recommended way to define entities is using [`defineEntity`](https://mikro-orm.io/docs/define-entity) with `setClass`:
|
|
30
36
|
|
|
31
|
-
|
|
37
|
+
```typescript
|
|
38
|
+
import { defineEntity, p, MikroORM } from '@mikro-orm/postgresql';
|
|
39
|
+
|
|
40
|
+
const AuthorSchema = defineEntity({
|
|
41
|
+
name: 'Author',
|
|
42
|
+
properties: {
|
|
43
|
+
id: p.integer().primary(),
|
|
44
|
+
name: p.string(),
|
|
45
|
+
email: p.string(),
|
|
46
|
+
born: p.datetime().nullable(),
|
|
47
|
+
books: () => p.oneToMany(Book).mappedBy('author'),
|
|
48
|
+
},
|
|
49
|
+
});
|
|
32
50
|
|
|
33
|
-
|
|
51
|
+
export class Author extends AuthorSchema.class {}
|
|
52
|
+
AuthorSchema.setClass(Author);
|
|
34
53
|
|
|
35
|
-
|
|
54
|
+
const BookSchema = defineEntity({
|
|
55
|
+
name: 'Book',
|
|
56
|
+
properties: {
|
|
57
|
+
id: p.integer().primary(),
|
|
58
|
+
title: p.string(),
|
|
59
|
+
author: () => p.manyToOne(Author).inversedBy('books'),
|
|
60
|
+
},
|
|
61
|
+
});
|
|
36
62
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
user.email = 'foo@bar.com';
|
|
40
|
-
const car = new Car();
|
|
41
|
-
user.cars.add(car);
|
|
42
|
-
|
|
43
|
-
// thanks to bi-directional cascading we only need to persist user entity
|
|
44
|
-
// flushing will create a transaction, insert new car and update user with new email
|
|
45
|
-
// as user entity is managed, calling flush() is enough
|
|
46
|
-
await em.flush();
|
|
63
|
+
export class Book extends BookSchema.class {}
|
|
64
|
+
BookSchema.setClass(Book);
|
|
47
65
|
```
|
|
48
66
|
|
|
49
|
-
|
|
67
|
+
You can also define entities using [decorators](https://mikro-orm.io/docs/defining-entities) or [`EntitySchema`](https://mikro-orm.io/docs/entity-schema). See the [defining entities guide](https://mikro-orm.io/docs/defining-entities) for all options.
|
|
50
68
|
|
|
51
|
-
|
|
69
|
+
### Initialize and Use
|
|
52
70
|
|
|
53
71
|
```typescript
|
|
54
|
-
@
|
|
55
|
-
export class User {
|
|
72
|
+
import { MikroORM, RequestContext } from '@mikro-orm/postgresql';
|
|
56
73
|
|
|
57
|
-
|
|
58
|
-
|
|
74
|
+
const orm = await MikroORM.init({
|
|
75
|
+
entities: [Author, Book],
|
|
76
|
+
dbName: 'my-db',
|
|
77
|
+
});
|
|
59
78
|
|
|
60
|
-
|
|
61
|
-
|
|
79
|
+
// Create new entities
|
|
80
|
+
const author = orm.em.create(Author, {
|
|
81
|
+
name: 'Jon Snow',
|
|
82
|
+
email: 'snow@wall.st',
|
|
83
|
+
});
|
|
84
|
+
const book = orm.em.create(Book, {
|
|
85
|
+
title: 'My Life on The Wall',
|
|
86
|
+
author,
|
|
87
|
+
});
|
|
62
88
|
|
|
63
|
-
|
|
64
|
-
|
|
89
|
+
// Flush persists all tracked changes in a single transaction
|
|
90
|
+
await orm.em.flush();
|
|
91
|
+
```
|
|
65
92
|
|
|
66
|
-
|
|
67
|
-
cars = new Collection<Car>(this);
|
|
93
|
+
### Querying
|
|
68
94
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
95
|
+
```typescript
|
|
96
|
+
// Find with relations
|
|
97
|
+
const authors = await orm.em.findAll(Author, {
|
|
98
|
+
populate: ['books'],
|
|
99
|
+
orderBy: { name: 'asc' },
|
|
100
|
+
});
|
|
72
101
|
|
|
73
|
-
|
|
102
|
+
// Type-safe QueryBuilder
|
|
103
|
+
const qb = orm.em.createQueryBuilder(Author);
|
|
104
|
+
const result = await qb
|
|
105
|
+
.select('*')
|
|
106
|
+
.where({ books: { title: { $like: '%Wall%' } } })
|
|
107
|
+
.getResult();
|
|
74
108
|
```
|
|
75
109
|
|
|
76
|
-
|
|
110
|
+
### Request Context
|
|
111
|
+
|
|
112
|
+
In web applications, use `RequestContext` to isolate the identity map per request:
|
|
77
113
|
|
|
78
114
|
```typescript
|
|
79
|
-
const
|
|
80
|
-
|
|
115
|
+
const app = express();
|
|
116
|
+
|
|
117
|
+
app.use((req, res, next) => {
|
|
118
|
+
RequestContext.create(orm.em, next);
|
|
119
|
+
});
|
|
81
120
|
```
|
|
82
121
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
122
|
+
More info about `RequestContext` is described [here](https://mikro-orm.io/docs/identity-map/#request-context).
|
|
123
|
+
|
|
124
|
+
## Unit of Work
|
|
125
|
+
|
|
126
|
+
> Unit of Work maintains a list of objects (_entities_) affected by a business transaction
|
|
127
|
+
> and coordinates the writing out of changes. [(Martin Fowler)](https://www.martinfowler.com/eaaCatalog/unitOfWork.html)
|
|
128
|
+
|
|
129
|
+
When you call `em.flush()`, all computed changes are queried inside a database transaction. This means you can control transaction boundaries simply by making changes to your entities and calling `flush()` when ready.
|
|
87
130
|
|
|
88
131
|
```typescript
|
|
89
|
-
const
|
|
90
|
-
populate: ['
|
|
132
|
+
const author = await em.findOneOrFail(Author, 1, {
|
|
133
|
+
populate: ['books'],
|
|
91
134
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const car = new Car('VW');
|
|
96
|
-
user.cars.add(car);
|
|
135
|
+
author.name = 'Jon Snow II';
|
|
136
|
+
author.books.getItems().forEach(book => book.title += ' (2nd ed.)');
|
|
137
|
+
author.books.add(orm.em.create(Book, { title: 'New Book', author }));
|
|
97
138
|
|
|
98
|
-
//
|
|
139
|
+
// Flush computes change sets and executes them in a single transaction
|
|
99
140
|
await em.flush();
|
|
100
141
|
```
|
|
101
142
|
|
|
102
|
-
|
|
143
|
+
The above flush will execute:
|
|
103
144
|
|
|
104
145
|
```sql
|
|
105
146
|
begin;
|
|
106
|
-
update "
|
|
107
|
-
update "
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
when ("id" =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
where "id" in (1, 2, 3)
|
|
115
|
-
insert into "car" ("brand", "owner") values ('VW', 1);
|
|
147
|
+
update "author" set "name" = 'Jon Snow II' where "id" = 1;
|
|
148
|
+
update "book"
|
|
149
|
+
set "title" = case
|
|
150
|
+
when ("id" = 1) then 'My Life on The Wall (2nd ed.)'
|
|
151
|
+
when ("id" = 2) then 'Another Book (2nd ed.)'
|
|
152
|
+
else "title" end
|
|
153
|
+
where "id" in (1, 2);
|
|
154
|
+
insert into "book" ("title", "author_id") values ('New Book', 1);
|
|
116
155
|
commit;
|
|
117
156
|
```
|
|
118
157
|
|
|
119
|
-
|
|
158
|
+
## Core Features
|
|
120
159
|
|
|
121
|
-
|
|
160
|
+
- [Clean and Simple Entity Definition](https://mikro-orm.io/docs/defining-entities) — decorators, `EntitySchema`, or `defineEntity`
|
|
161
|
+
- [Identity Map](https://mikro-orm.io/docs/identity-map) and [Unit of Work](https://mikro-orm.io/docs/unit-of-work) — automatic change tracking
|
|
162
|
+
- [Entity References](https://mikro-orm.io/docs/entity-references) and [Collections](https://mikro-orm.io/docs/collections)
|
|
163
|
+
- [QueryBuilder](https://mikro-orm.io/docs/query-builder) and [Kysely Integration](https://mikro-orm.io/docs/kysely)
|
|
164
|
+
- [Transactions](https://mikro-orm.io/docs/transactions) and [Cascading](https://mikro-orm.io/docs/cascading)
|
|
165
|
+
- [Populating Relations](https://mikro-orm.io/docs/populating-relations) and [Loading Strategies](https://mikro-orm.io/docs/loading-strategies)
|
|
166
|
+
- [Filters](https://mikro-orm.io/docs/filters) and [Lifecycle Hooks](https://mikro-orm.io/docs/events#hooks)
|
|
167
|
+
- [Schema Generator](https://mikro-orm.io/docs/schema-generator) and [Migrations](https://mikro-orm.io/docs/migrations)
|
|
168
|
+
- [Entity Generator](https://mikro-orm.io/docs/entity-generator) and [Seeding](https://mikro-orm.io/docs/seeding)
|
|
169
|
+
- [Embeddables](https://mikro-orm.io/docs/embeddables), [Custom Types](https://mikro-orm.io/docs/custom-types), and [Serialization](https://mikro-orm.io/docs/serializing)
|
|
170
|
+
- [Composite and Foreign Keys as Primary Key](https://mikro-orm.io/docs/composite-keys)
|
|
171
|
+
- [Entity Constructors](https://mikro-orm.io/docs/entity-constructors) and [Property Validation](https://mikro-orm.io/docs/property-validation)
|
|
172
|
+
- [Modelling Relationships](https://mikro-orm.io/docs/relationships) and [Vanilla JS Support](https://mikro-orm.io/docs/usage-with-js)
|
|
122
173
|
|
|
123
|
-
##
|
|
174
|
+
## Documentation
|
|
124
175
|
|
|
125
176
|
MikroORM documentation, included in this repo in the root directory, is built with [Docusaurus](https://docusaurus.io) and publicly hosted on GitHub Pages at https://mikro-orm.io.
|
|
126
177
|
|
|
127
|
-
There is also auto-generated [CHANGELOG.md](CHANGELOG.md) file based on commit messages (via `semantic-release`).
|
|
128
|
-
|
|
129
|
-
## ✨ Core Features
|
|
130
|
-
|
|
131
|
-
- [Clean and Simple Entity Definition](https://mikro-orm.io/docs/defining-entities)
|
|
132
|
-
- [Identity Map](https://mikro-orm.io/docs/identity-map)
|
|
133
|
-
- [Entity References](https://mikro-orm.io/docs/entity-references)
|
|
134
|
-
- [Using Entity Constructors](https://mikro-orm.io/docs/entity-constructors)
|
|
135
|
-
- [Modelling Relationships](https://mikro-orm.io/docs/relationships)
|
|
136
|
-
- [Collections](https://mikro-orm.io/docs/collections)
|
|
137
|
-
- [Unit of Work](https://mikro-orm.io/docs/unit-of-work)
|
|
138
|
-
- [Transactions](https://mikro-orm.io/docs/transactions)
|
|
139
|
-
- [Cascading persist and remove](https://mikro-orm.io/docs/cascading)
|
|
140
|
-
- [Composite and Foreign Keys as Primary Key](https://mikro-orm.io/docs/composite-keys)
|
|
141
|
-
- [Filters](https://mikro-orm.io/docs/filters)
|
|
142
|
-
- [Using `QueryBuilder`](https://mikro-orm.io/docs/query-builder)
|
|
143
|
-
- [Populating relations](https://mikro-orm.io/docs/populating-relations)
|
|
144
|
-
- [Property Validation](https://mikro-orm.io/docs/property-validation)
|
|
145
|
-
- [Lifecycle Hooks](https://mikro-orm.io/docs/events#hooks)
|
|
146
|
-
- [Vanilla JS Support](https://mikro-orm.io/docs/usage-with-js)
|
|
147
|
-
- [Schema Generator](https://mikro-orm.io/docs/schema-generator)
|
|
148
|
-
- [Entity Generator](https://mikro-orm.io/docs/entity-generator)
|
|
178
|
+
There is also auto-generated [CHANGELOG.md](CHANGELOG.md) file based on commit messages (via `semantic-release`).
|
|
149
179
|
|
|
150
|
-
##
|
|
180
|
+
## Example Integrations
|
|
151
181
|
|
|
152
|
-
You can find example integrations for some popular frameworks in the [`mikro-orm-examples` repository](https://github.com/mikro-orm/mikro-orm-examples):
|
|
182
|
+
You can find example integrations for some popular frameworks in the [`mikro-orm-examples` repository](https://github.com/mikro-orm/mikro-orm-examples):
|
|
153
183
|
|
|
154
184
|
### TypeScript Examples
|
|
155
185
|
|
|
@@ -165,213 +195,17 @@ You can find example integrations for some popular frameworks in the [`mikro-orm
|
|
|
165
195
|
- [Elysia.js + libSQL + Bun](https://github.com/mikro-orm/elysia-bun-example-app)
|
|
166
196
|
- [Electron.js + PostgreSQL](https://github.com/adnanlah/electron-mikro-orm-example-app)
|
|
167
197
|
|
|
168
|
-
### JavaScript Examples
|
|
198
|
+
### JavaScript Examples
|
|
169
199
|
|
|
170
200
|
- [Express + SQLite](https://github.com/mikro-orm/express-js-example-app)
|
|
171
201
|
|
|
172
|
-
##
|
|
173
|
-
|
|
174
|
-
First install the module via `yarn` or `npm` and do not forget to install the database driver as well:
|
|
175
|
-
|
|
176
|
-
> Since v4, you should install the driver package, but not the db connector itself, e.g. install `@mikro-orm/sqlite`, but not `sqlite3` as that is already included in the driver package.
|
|
177
|
-
|
|
178
|
-
```sh
|
|
179
|
-
yarn add @mikro-orm/core @mikro-orm/mongodb # for mongo
|
|
180
|
-
yarn add @mikro-orm/core @mikro-orm/mysql # for mysql/mariadb
|
|
181
|
-
yarn add @mikro-orm/core @mikro-orm/mariadb # for mysql/mariadb
|
|
182
|
-
yarn add @mikro-orm/core @mikro-orm/postgresql # for postgresql
|
|
183
|
-
yarn add @mikro-orm/core @mikro-orm/mssql # for mssql
|
|
184
|
-
yarn add @mikro-orm/core @mikro-orm/oracledb # for oracle
|
|
185
|
-
yarn add @mikro-orm/core @mikro-orm/sqlite # for sqlite
|
|
186
|
-
yarn add @mikro-orm/core @mikro-orm/libsql # for libsql
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
or
|
|
190
|
-
|
|
191
|
-
```sh
|
|
192
|
-
npm i -s @mikro-orm/core @mikro-orm/mongodb # for mongo
|
|
193
|
-
npm i -s @mikro-orm/core @mikro-orm/mysql # for mysql/mariadb
|
|
194
|
-
npm i -s @mikro-orm/core @mikro-orm/mariadb # for mysql/mariadb
|
|
195
|
-
npm i -s @mikro-orm/core @mikro-orm/postgresql # for postgresql
|
|
196
|
-
npm i -s @mikro-orm/core @mikro-orm/mssql # for mssql
|
|
197
|
-
npm i -s @mikro-orm/core @mikro-orm/sqlite # for sqlite
|
|
198
|
-
npm i -s @mikro-orm/core @mikro-orm/libsql # for libsql
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
Next, if you want to use decorators for your entity definition, you will need to enable support for [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) as well as `esModuleInterop` in `tsconfig.json` via:
|
|
202
|
-
|
|
203
|
-
```json
|
|
204
|
-
"experimentalDecorators": true,
|
|
205
|
-
"emitDecoratorMetadata": true,
|
|
206
|
-
"esModuleInterop": true,
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
Alternatively, you can use [`EntitySchema`](https://mikro-orm.io/docs/entity-schema).
|
|
210
|
-
|
|
211
|
-
Then call `MikroORM.init` as part of bootstrapping your app:
|
|
212
|
-
|
|
213
|
-
> To access driver specific methods like `em.createQueryBuilder()` we need to specify the driver type when calling `MikroORM.init()`. Alternatively we can cast the `orm.em` to `EntityManager` exported from the driver package:
|
|
214
|
-
>
|
|
215
|
-
> ```ts
|
|
216
|
-
> import { EntityManager } from '@mikro-orm/postgresql';
|
|
217
|
-
> const em = orm.em as EntityManager;
|
|
218
|
-
> const qb = em.createQueryBuilder(...);
|
|
219
|
-
> ```
|
|
220
|
-
|
|
221
|
-
```typescript
|
|
222
|
-
import type { PostgreSqlDriver } from '@mikro-orm/postgresql'; // or any other SQL driver package
|
|
223
|
-
|
|
224
|
-
const orm = await MikroORM.init<PostgreSqlDriver>({
|
|
225
|
-
entities: ['./dist/entities'], // path to your JS entities (dist), relative to `baseDir`
|
|
226
|
-
dbName: 'my-db-name',
|
|
227
|
-
type: 'postgresql',
|
|
228
|
-
});
|
|
229
|
-
console.log(orm.em); // access EntityManager via `em` property
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
There are more ways to configure your entities, take a look at [installation page](https://mikro-orm.io/docs/installation/).
|
|
233
|
-
|
|
234
|
-
> Read more about all the possible configuration options in [Advanced Configuration](https://mikro-orm.io/docs/configuration) section.
|
|
235
|
-
|
|
236
|
-
Then you will need to fork entity manager for each request so their [identity maps](https://mikro-orm.io/docs/identity-map/) will not collide. To do so, use the `RequestContext` helper:
|
|
237
|
-
|
|
238
|
-
```typescript
|
|
239
|
-
const app = express();
|
|
240
|
-
|
|
241
|
-
app.use((req, res, next) => {
|
|
242
|
-
RequestContext.create(orm.em, next);
|
|
243
|
-
});
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
> You should register this middleware as the last one just before request handlers and before any of your custom middleware that is using the ORM. There might be issues when you register it before request processing middleware like `queryParser` or `bodyParser`, so definitely register the context after them.
|
|
247
|
-
|
|
248
|
-
More info about `RequestContext` is described [here](https://mikro-orm.io/docs/identity-map/#request-context).
|
|
249
|
-
|
|
250
|
-
Now you can start defining your entities (in one of the `entities` folders). This is how simple entity can look like in mongo driver:
|
|
251
|
-
|
|
252
|
-
**`./entities/MongoBook.ts`**
|
|
253
|
-
|
|
254
|
-
```typescript
|
|
255
|
-
@Entity()
|
|
256
|
-
export class MongoBook {
|
|
257
|
-
|
|
258
|
-
@PrimaryKey()
|
|
259
|
-
_id: ObjectID;
|
|
260
|
-
|
|
261
|
-
@SerializedPrimaryKey()
|
|
262
|
-
id: string;
|
|
263
|
-
|
|
264
|
-
@Property()
|
|
265
|
-
title: string;
|
|
266
|
-
|
|
267
|
-
@ManyToOne(() => Author)
|
|
268
|
-
author: Author;
|
|
269
|
-
|
|
270
|
-
@ManyToMany(() => BookTag)
|
|
271
|
-
tags = new Collection<BookTag>(this);
|
|
272
|
-
|
|
273
|
-
constructor(title: string, author: Author) {
|
|
274
|
-
this.title = title;
|
|
275
|
-
this.author = author;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
For SQL drivers, you can use `id: number` PK:
|
|
282
|
-
|
|
283
|
-
**`./entities/SqlBook.ts`**
|
|
284
|
-
|
|
285
|
-
```typescript
|
|
286
|
-
@Entity()
|
|
287
|
-
export class SqlBook {
|
|
288
|
-
|
|
289
|
-
@PrimaryKey()
|
|
290
|
-
id: number;
|
|
291
|
-
|
|
292
|
-
}
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
Or if you want to use UUID primary keys:
|
|
296
|
-
|
|
297
|
-
**`./entities/UuidBook.ts`**
|
|
298
|
-
|
|
299
|
-
```typescript
|
|
300
|
-
import { randomUUID } from 'node:crypto';
|
|
301
|
-
|
|
302
|
-
@Entity()
|
|
303
|
-
export class UuidBook {
|
|
304
|
-
|
|
305
|
-
@PrimaryKey()
|
|
306
|
-
uuid = randomUUID();
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
More information can be found in [defining entities section](https://mikro-orm.io/docs/defining-entities/) in docs.
|
|
312
|
-
|
|
313
|
-
When you have your entities defined, you can start using ORM either via `EntityManager` or via `EntityRepository`s.
|
|
314
|
-
|
|
315
|
-
To save entity state to database, you need to persist it. Persist takes care or deciding whether to use `insert` or `update` and computes appropriate change-set. Entity references that are not persisted yet (does not have identifier) will be cascade persisted automatically.
|
|
316
|
-
|
|
317
|
-
```typescript
|
|
318
|
-
// use constructors in your entities for required parameters
|
|
319
|
-
const author = new Author('Jon Snow', 'snow@wall.st');
|
|
320
|
-
author.born = new Date();
|
|
321
|
-
|
|
322
|
-
const publisher = new Publisher('7K publisher');
|
|
323
|
-
|
|
324
|
-
const book1 = new Book('My Life on The Wall, part 1', author);
|
|
325
|
-
book1.publisher = publisher;
|
|
326
|
-
const book2 = new Book('My Life on The Wall, part 2', author);
|
|
327
|
-
book2.publisher = publisher;
|
|
328
|
-
const book3 = new Book('My Life on The Wall, part 3', author);
|
|
329
|
-
book3.publisher = publisher;
|
|
330
|
-
|
|
331
|
-
// just persist books, author and publisher will be automatically cascade persisted
|
|
332
|
-
await em.persistAndFlush([book1, book2, book3]);
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
To fetch entities from database you can use `find()` and `findOne()` of `EntityManager`:
|
|
336
|
-
|
|
337
|
-
```typescript
|
|
338
|
-
const authors = em.find(Author, {}, { populate: ['books'] });
|
|
339
|
-
|
|
340
|
-
for (const author of authors) {
|
|
341
|
-
console.log(author); // instance of Author entity
|
|
342
|
-
console.log(author.name); // Jon Snow
|
|
343
|
-
|
|
344
|
-
for (const book of author.books) { // iterating books collection
|
|
345
|
-
console.log(book); // instance of Book entity
|
|
346
|
-
console.log(book.title); // My Life on The Wall, part 1/2/3
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
More convenient way of fetching entities from database is by using `EntityRepository`, that carries the entity name, so you do not have to pass it to every `find` and `findOne` calls:
|
|
352
|
-
|
|
353
|
-
```typescript
|
|
354
|
-
const booksRepository = em.getRepository(Book);
|
|
355
|
-
|
|
356
|
-
const books = await booksRepository.find({ author: '...' }, {
|
|
357
|
-
populate: ['author'],
|
|
358
|
-
limit: 1,
|
|
359
|
-
offset: 2,
|
|
360
|
-
orderBy: { title: QueryOrder.DESC },
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
console.log(books); // Loaded<Book, 'author'>[]
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
Take a look at docs about [working with `EntityManager`](https://mikro-orm.io/docs/entity-manager/) or [using `EntityRepository` instead](https://mikro-orm.io/docs/repositories/).
|
|
367
|
-
|
|
368
|
-
## 🤝 Contributing
|
|
202
|
+
## Contributing
|
|
369
203
|
|
|
370
204
|
Contributions, issues and feature requests are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the process for submitting pull requests to us.
|
|
371
205
|
|
|
372
206
|
## Authors
|
|
373
207
|
|
|
374
|
-
|
|
208
|
+
**Martin Adámek**
|
|
375
209
|
|
|
376
210
|
- Twitter: [@B4nan](https://twitter.com/B4nan)
|
|
377
211
|
- Github: [@b4nan](https://github.com/b4nan)
|
|
@@ -380,12 +214,12 @@ See also the list of contributors who [participated](https://github.com/mikro-or
|
|
|
380
214
|
|
|
381
215
|
## Show Your Support
|
|
382
216
|
|
|
383
|
-
Please
|
|
217
|
+
Please star this repository if this project helped you!
|
|
384
218
|
|
|
385
219
|
> If you'd like to support my open-source work, consider sponsoring me directly at [github.com/sponsors/b4nan](https://github.com/sponsors/b4nan).
|
|
386
220
|
|
|
387
|
-
##
|
|
221
|
+
## License
|
|
388
222
|
|
|
389
|
-
Copyright © 2018 [Martin Adámek](https://github.com/b4nan).
|
|
223
|
+
Copyright © 2018-present [Martin Adámek](https://github.com/b4nan).
|
|
390
224
|
|
|
391
225
|
This project is licensed under the MIT License - see the [LICENSE file](LICENSE) for details.
|
package/es/Check.d.ts
CHANGED
package/es/Check.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { type ContextProvider } from '../utils.js';
|
|
2
|
+
/** Wraps an async method in a new RequestContext, forking the EntityManager (TC39 decorator). */
|
|
2
3
|
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>;
|
|
4
|
+
/** Like `@CreateRequestContext`, but reuses an existing RequestContext if one is available (TC39 decorator). */
|
|
3
5
|
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>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RequestContext, TransactionContext } from '@mikro-orm/core';
|
|
2
2
|
import { resolveContextProvider } from '../utils.js';
|
|
3
|
+
/** Wraps an async method in a new RequestContext, forking the EntityManager (TC39 decorator). */
|
|
3
4
|
export function CreateRequestContext(contextProvider, respectExistingContext = false) {
|
|
4
5
|
return function (value, context) {
|
|
5
6
|
const name = respectExistingContext ? 'EnsureRequestContext' : 'CreateRequestContext';
|
|
@@ -24,6 +25,7 @@ export function CreateRequestContext(contextProvider, respectExistingContext = f
|
|
|
24
25
|
};
|
|
25
26
|
};
|
|
26
27
|
}
|
|
28
|
+
/** Like `@CreateRequestContext`, but reuses an existing RequestContext if one is available (TC39 decorator). */
|
|
27
29
|
export function EnsureRequestContext(context) {
|
|
28
30
|
return CreateRequestContext(context, true);
|
|
29
31
|
}
|
package/es/Embeddable.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type Constructor, type EmbeddableOptions, type EntityClass } from '@mikro-orm/core';
|
|
2
|
+
/** Marks a class as an embeddable type (TC39 decorator). */
|
|
2
3
|
export declare function Embeddable<Owner extends EntityClass<unknown> & Constructor>(options?: EmbeddableOptions<Owner>): (target: Owner, context: ClassDecoratorContext<Owner>) => Owner;
|
package/es/Embeddable.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Utils } from '@mikro-orm/core';
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
|
+
/** Marks a class as an embeddable type (TC39 decorator). */
|
|
3
4
|
export function Embeddable(options = {}) {
|
|
4
5
|
return function (target, context) {
|
|
5
6
|
const meta = getMetadataFromDecorator(target);
|
package/es/Embedded.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type EntityName, type EmbeddedOptions } from '@mikro-orm/core';
|
|
2
|
+
/** Defines an embedded property on an entity (TC39 decorator). */
|
|
2
3
|
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,5 +1,6 @@
|
|
|
1
1
|
import { ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext } from '../utils.js';
|
|
3
|
+
/** Defines an embedded property on an entity (TC39 decorator). */
|
|
3
4
|
export function Embedded(type = {}, options = {}) {
|
|
4
5
|
return function (value, context) {
|
|
5
6
|
const meta = prepareMetadataContext(context, ReferenceKind.EMBEDDED);
|
package/es/Entity.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type Constructor, type EntityOptions, type EntityClass } from '@mikro-orm/core';
|
|
2
|
+
/** Marks a class as a MikroORM entity (TC39 decorator). */
|
|
2
3
|
export declare function Entity<Owner extends EntityClass<unknown> & Constructor>(options?: EntityOptions<Owner>): (target: Owner, context: ClassDecoratorContext<Owner>) => void;
|
package/es/Entity.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Utils } from '@mikro-orm/core';
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
|
+
/** Marks a class as a MikroORM entity (TC39 decorator). */
|
|
3
4
|
export function Entity(options = {}) {
|
|
4
5
|
return function (target, context) {
|
|
5
6
|
const meta = getMetadataFromDecorator(target);
|
package/es/Enum.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type EnumOptions, type AnyEntity, type Dictionary } from '@mikro-orm/core';
|
|
2
|
+
/** Defines an enum property on an entity (TC39 decorator). */
|
|
2
3
|
export declare function Enum<Owner extends object>(options?: EnumOptions<AnyEntity> | (() => Dictionary)): (target: unknown, context: ClassFieldDecoratorContext<Owner>) => void;
|
package/es/Enum.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReferenceKind, } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext } from '../utils.js';
|
|
3
|
+
/** Defines an enum property on an entity (TC39 decorator). */
|
|
3
4
|
export function Enum(options = {}) {
|
|
4
5
|
return function (target, context) {
|
|
5
6
|
const meta = prepareMetadataContext(context);
|
package/es/Filter.d.ts
CHANGED
package/es/Filter.js
CHANGED
package/es/Formula.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type FormulaCallback, type PropertyOptions } from '@mikro-orm/core';
|
|
2
|
+
/** Defines a computed SQL formula property on an entity (TC39 decorator). */
|
|
2
3
|
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,5 +1,6 @@
|
|
|
1
1
|
import { ReferenceKind, } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext } from '../utils.js';
|
|
3
|
+
/** Defines a computed SQL formula property on an entity (TC39 decorator). */
|
|
3
4
|
export function Formula(formula, options = {}) {
|
|
4
5
|
return function (value, context) {
|
|
5
6
|
const meta = prepareMetadataContext(context);
|
package/es/Indexed.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { type IndexOptions, type UniqueOptions, type Constructor } from '@mikro-orm/core';
|
|
2
|
+
/** Defines a database index on a property or entity class (TC39 decorator). */
|
|
2
3
|
export declare function Index<T extends object, H extends string>(options?: IndexOptions<T, H>): (value: unknown, context: ClassDecoratorContext<T & Constructor> | ClassFieldDecoratorContext<T>) => any;
|
|
4
|
+
/** Defines a unique constraint on a property or entity class (TC39 decorator). */
|
|
3
5
|
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/Indexed.js
CHANGED
|
@@ -9,9 +9,11 @@ function createDecorator(options, unique) {
|
|
|
9
9
|
meta[key].push(options);
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
+
/** Defines a database index on a property or entity class (TC39 decorator). */
|
|
12
13
|
export function Index(options = {}) {
|
|
13
14
|
return createDecorator(options, false);
|
|
14
15
|
}
|
|
16
|
+
/** Defines a unique constraint on a property or entity class (TC39 decorator). */
|
|
15
17
|
export function Unique(options = {}) {
|
|
16
18
|
return createDecorator(options, true);
|
|
17
19
|
}
|
package/es/ManyToMany.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type EntityName, type ManyToManyOptions, type Collection } from '@mikro-orm/core';
|
|
2
|
+
/** Defines a many-to-many relationship (TC39 decorator). */
|
|
2
3
|
export declare function ManyToMany<Target extends object, Owner extends object>(entity?: ManyToManyOptions<Owner, Target> | string | (() => EntityName<Target>), mappedBy?: (string & keyof Target) | ((e: Target) => any), options?: Partial<ManyToManyOptions<Owner, Target>>): (_: unknown, context: ClassFieldDecoratorContext<Owner, Collection<Target> | undefined>) => void;
|
package/es/ManyToMany.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext, processDecoratorParameters } from '../utils.js';
|
|
3
|
+
/** Defines a many-to-many relationship (TC39 decorator). */
|
|
3
4
|
export function ManyToMany(entity, mappedBy, options = {}) {
|
|
4
5
|
return function (_, context) {
|
|
5
6
|
const meta = prepareMetadataContext(context, ReferenceKind.MANY_TO_MANY);
|
package/es/ManyToOne.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type ManyToOneOptions, type EntityName, type Ref } from '@mikro-orm/core';
|
|
2
|
+
/** Defines a many-to-one relationship (TC39 decorator). */
|
|
2
3
|
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,5 +1,6 @@
|
|
|
1
1
|
import { ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext, processDecoratorParameters } from '../utils.js';
|
|
3
|
+
/** Defines a many-to-one relationship (TC39 decorator). */
|
|
3
4
|
export function ManyToOne(entity = {}, options = {}) {
|
|
4
5
|
return function (_, context) {
|
|
5
6
|
const meta = prepareMetadataContext(context, ReferenceKind.MANY_TO_ONE);
|
package/es/OneToMany.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type Collection, type EntityName, type OneToManyOptions } from '@mikro-orm/core';
|
|
2
|
+
/** Defines a one-to-many relationship (TC39 decorator). */
|
|
2
3
|
export declare function OneToMany<Target extends object, Owner extends object>(entity: string | ((e?: Owner) => EntityName<Target>), mappedBy: (string & keyof Target) | ((e: Target) => any), options?: Partial<OneToManyOptions<Owner, Target>>): (value: unknown, context: ClassFieldDecoratorContext<Owner, Collection<Target> | undefined>) => void;
|
|
3
4
|
export declare function OneToMany<Target extends object, Owner extends object>(options: OneToManyOptions<Owner, Target>): (value: unknown, context: ClassFieldDecoratorContext<Owner, Collection<Target> | undefined>) => void;
|
package/es/OneToOne.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type EntityName, type OneToOneOptions, type Ref } from '@mikro-orm/core';
|
|
2
|
+
/** Defines a one-to-one relationship (TC39 decorator). */
|
|
2
3
|
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,5 +1,6 @@
|
|
|
1
1
|
import { ReferenceKind, } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext, processDecoratorParameters } from '../utils.js';
|
|
3
|
+
/** Defines a one-to-one relationship (TC39 decorator). */
|
|
3
4
|
export function OneToOne(entity, mappedByOrOptions, options = {}) {
|
|
4
5
|
const mappedBy = typeof mappedByOrOptions === 'object' ? mappedByOrOptions.mappedBy : mappedByOrOptions;
|
|
5
6
|
options = typeof mappedByOrOptions === 'object' ? { ...mappedByOrOptions, ...options } : options;
|
package/es/PrimaryKey.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { type PrimaryKeyOptions, type SerializedPrimaryKeyOptions } from '@mikro-orm/core';
|
|
2
|
+
/** Marks a property as the primary key of an entity (TC39 decorator). */
|
|
2
3
|
export declare function PrimaryKey<T extends object>(options?: PrimaryKeyOptions<T>): (value: unknown, context: ClassFieldDecoratorContext<T>) => void;
|
|
4
|
+
/** Marks a property as the serialized form of the primary key, e.g. for MongoDB ObjectId (TC39 decorator). */
|
|
3
5
|
export declare function SerializedPrimaryKey<T extends object>(options?: SerializedPrimaryKeyOptions<T>): (value: unknown, context: ClassFieldDecoratorContext<T>) => void;
|
package/es/PrimaryKey.js
CHANGED
|
@@ -12,9 +12,11 @@ function createDecorator(options, serialized) {
|
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
+
/** Marks a property as the primary key of an entity (TC39 decorator). */
|
|
15
16
|
export function PrimaryKey(options = {}) {
|
|
16
17
|
return createDecorator(options, false);
|
|
17
18
|
}
|
|
19
|
+
/** Marks a property as the serialized form of the primary key, e.g. for MongoDB ObjectId (TC39 decorator). */
|
|
18
20
|
export function SerializedPrimaryKey(options = {}) {
|
|
19
21
|
return createDecorator(options, true);
|
|
20
22
|
}
|
package/es/Property.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type PropertyOptions } from '@mikro-orm/core';
|
|
2
|
+
/** Defines a scalar property on an entity (TC39 decorator). */
|
|
2
3
|
export declare function Property<T extends object>(options?: PropertyOptions<T>): (value: unknown, context: ClassFieldDecoratorContext<T> | ClassGetterDecoratorContext<T> | ClassSetterDecoratorContext<T> | ClassAccessorDecoratorContext<T> | ClassMethodDecoratorContext<T>) => void;
|
package/es/Property.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReferenceKind, Utils } from '@mikro-orm/core';
|
|
2
2
|
import { prepareMetadataContext } from '../utils.js';
|
|
3
|
+
/** Defines a scalar property on an entity (TC39 decorator). */
|
|
3
4
|
export function Property(options = {}) {
|
|
4
5
|
return function (value, context) {
|
|
5
6
|
const meta = prepareMetadataContext(context, ReferenceKind.SCALAR);
|
package/es/hooks.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
/** Called before a new entity is persisted to the database (TC39 decorator). */
|
|
1
2
|
export declare function BeforeCreate(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
3
|
+
/** Called after a new entity has been persisted to the database (TC39 decorator). */
|
|
2
4
|
export declare function AfterCreate(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
5
|
+
/** Called before an existing entity is updated in the database (TC39 decorator). */
|
|
3
6
|
export declare function BeforeUpdate(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
7
|
+
/** Called after an existing entity has been updated in the database (TC39 decorator). */
|
|
4
8
|
export declare function AfterUpdate(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
9
|
+
/** Called before an entity is upserted (TC39 decorator). */
|
|
5
10
|
export declare function BeforeUpsert(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
11
|
+
/** Called after an entity has been upserted (TC39 decorator). */
|
|
6
12
|
export declare function AfterUpsert(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
13
|
+
/** Called when an entity is instantiated by the EntityManager (TC39 decorator). */
|
|
7
14
|
export declare function OnInit(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
15
|
+
/** Called after an entity is loaded from the database (TC39 decorator). */
|
|
8
16
|
export declare function OnLoad(): (value: (...args: any[]) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
9
17
|
/**
|
|
10
18
|
* Called before deleting entity, but only when providing initialized entity to EM#remove()
|
package/es/hooks.js
CHANGED
|
@@ -7,27 +7,35 @@ function hook(type) {
|
|
|
7
7
|
meta.hooks[type].push(value);
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
|
+
/** Called before a new entity is persisted to the database (TC39 decorator). */
|
|
10
11
|
export function BeforeCreate() {
|
|
11
12
|
return hook(EventType.beforeCreate);
|
|
12
13
|
}
|
|
14
|
+
/** Called after a new entity has been persisted to the database (TC39 decorator). */
|
|
13
15
|
export function AfterCreate() {
|
|
14
16
|
return hook(EventType.afterCreate);
|
|
15
17
|
}
|
|
18
|
+
/** Called before an existing entity is updated in the database (TC39 decorator). */
|
|
16
19
|
export function BeforeUpdate() {
|
|
17
20
|
return hook(EventType.beforeUpdate);
|
|
18
21
|
}
|
|
22
|
+
/** Called after an existing entity has been updated in the database (TC39 decorator). */
|
|
19
23
|
export function AfterUpdate() {
|
|
20
24
|
return hook(EventType.afterUpdate);
|
|
21
25
|
}
|
|
26
|
+
/** Called before an entity is upserted (TC39 decorator). */
|
|
22
27
|
export function BeforeUpsert() {
|
|
23
28
|
return hook(EventType.beforeUpsert);
|
|
24
29
|
}
|
|
30
|
+
/** Called after an entity has been upserted (TC39 decorator). */
|
|
25
31
|
export function AfterUpsert() {
|
|
26
32
|
return hook(EventType.afterUpsert);
|
|
27
33
|
}
|
|
34
|
+
/** Called when an entity is instantiated by the EntityManager (TC39 decorator). */
|
|
28
35
|
export function OnInit() {
|
|
29
36
|
return hook(EventType.onInit);
|
|
30
37
|
}
|
|
38
|
+
/** Called after an entity is loaded from the database (TC39 decorator). */
|
|
31
39
|
export function OnLoad() {
|
|
32
40
|
return hook(EventType.onLoad);
|
|
33
41
|
}
|
package/legacy/Check.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type CheckConstraint, type EntityClass } from '@mikro-orm/core';
|
|
2
|
+
/** Defines a database check constraint on a property or entity class (legacy TypeScript decorator). */
|
|
2
3
|
export declare function Check<T>(options: CheckConstraint<T>): (target: T, propertyName?: T extends EntityClass<unknown> ? undefined : keyof T) => any;
|
package/legacy/Check.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
2
|
+
/** Defines a database check constraint on a property or entity class (legacy TypeScript decorator). */
|
|
2
3
|
export function Check(options) {
|
|
3
4
|
return function (target, propertyName) {
|
|
4
5
|
const meta = getMetadataFromDecorator((propertyName ? target.constructor : target));
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { type ContextProvider } from '../utils.js';
|
|
2
|
+
/** Wraps an async method in a new RequestContext, forking the EntityManager (legacy TypeScript decorator). */
|
|
2
3
|
export declare function CreateRequestContext<T extends object>(context?: ContextProvider<T>, respectExistingContext?: boolean): MethodDecorator;
|
|
4
|
+
/** Like `@CreateRequestContext`, but reuses an existing RequestContext if one is available (legacy TypeScript decorator). */
|
|
3
5
|
export declare function EnsureRequestContext<T extends object>(context?: ContextProvider<T>): MethodDecorator;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RequestContext, TransactionContext } from '@mikro-orm/core';
|
|
2
2
|
import { resolveContextProvider } from '../utils.js';
|
|
3
|
+
/** Wraps an async method in a new RequestContext, forking the EntityManager (legacy TypeScript decorator). */
|
|
3
4
|
export function CreateRequestContext(context, respectExistingContext = false) {
|
|
4
5
|
return function (target, propertyKey, descriptor) {
|
|
5
6
|
const originalMethod = descriptor.value;
|
|
@@ -26,6 +27,7 @@ export function CreateRequestContext(context, respectExistingContext = false) {
|
|
|
26
27
|
return descriptor;
|
|
27
28
|
};
|
|
28
29
|
}
|
|
30
|
+
/** Like `@CreateRequestContext`, but reuses an existing RequestContext if one is available (legacy TypeScript decorator). */
|
|
29
31
|
export function EnsureRequestContext(context) {
|
|
30
32
|
return CreateRequestContext(context, true);
|
|
31
33
|
}
|
package/legacy/Embeddable.d.ts
CHANGED
package/legacy/Embeddable.js
CHANGED
package/legacy/Embedded.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type AnyEntity, type EntityName, type EmbeddedOptions } from '@mikro-orm/core';
|
|
2
|
+
/** Defines an embedded property on an entity (legacy TypeScript decorator). */
|
|
2
3
|
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/Embedded.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
2
2
|
import { validateSingleDecorator, getMetadataFromDecorator } from '../utils.js';
|
|
3
|
+
/** Defines an embedded property on an entity (legacy TypeScript decorator). */
|
|
3
4
|
export function Embedded(type = {}, options = {}) {
|
|
4
5
|
return function (target, propertyName) {
|
|
5
6
|
const meta = getMetadataFromDecorator(target.constructor);
|
package/legacy/Entity.d.ts
CHANGED
package/legacy/Entity.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Utils } from '@mikro-orm/core';
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
|
+
/** Marks a class as a MikroORM entity (legacy TypeScript decorator). */
|
|
3
4
|
export function Entity(options = {}) {
|
|
4
5
|
return function (target) {
|
|
5
6
|
const meta = getMetadataFromDecorator(target);
|
package/legacy/Enum.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type EnumOptions, type AnyEntity, type Dictionary } from '@mikro-orm/core';
|
|
2
|
+
/** Defines an enum property on an entity (legacy TypeScript decorator). */
|
|
2
3
|
export declare function Enum<T extends object>(options?: EnumOptions<AnyEntity> | (() => Dictionary)): (target: T, propertyName: string) => void;
|
package/legacy/Enum.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReferenceKind, } from '@mikro-orm/core';
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
|
+
/** Defines an enum property on an entity (legacy TypeScript decorator). */
|
|
3
4
|
export function Enum(options = {}) {
|
|
4
5
|
return function (target, propertyName) {
|
|
5
6
|
const meta = getMetadataFromDecorator(target.constructor);
|
package/legacy/Filter.d.ts
CHANGED
package/legacy/Filter.js
CHANGED
package/legacy/Formula.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type FormulaCallback, type PropertyOptions } from '@mikro-orm/core';
|
|
2
|
+
/** Defines a computed SQL formula property on an entity (legacy TypeScript decorator). */
|
|
2
3
|
export declare function Formula<T extends object>(formula: string | FormulaCallback<T>, options?: PropertyOptions<T>): (target: T, propertyName: string) => void;
|
package/legacy/Formula.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReferenceKind, } from '@mikro-orm/core';
|
|
2
2
|
import { getMetadataFromDecorator } from '../utils.js';
|
|
3
|
+
/** Defines a computed SQL formula property on an entity (legacy TypeScript decorator). */
|
|
3
4
|
export function Formula(formula, options = {}) {
|
|
4
5
|
return function (target, propertyName) {
|
|
5
6
|
const meta = getMetadataFromDecorator(target.constructor);
|
package/legacy/Indexed.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { type EntityClass, type IndexOptions, type UniqueOptions } from '@mikro-orm/core';
|
|
2
|
+
/** Defines a database index on a property or entity class (legacy TypeScript decorator). */
|
|
2
3
|
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;
|
|
4
|
+
/** Defines a unique constraint on a property or entity class (legacy TypeScript decorator). */
|
|
3
5
|
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/Indexed.js
CHANGED
|
@@ -11,9 +11,11 @@ function createDecorator(options, unique) {
|
|
|
11
11
|
return undefined;
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
+
/** Defines a database index on a property or entity class (legacy TypeScript decorator). */
|
|
14
15
|
export function Index(options = {}) {
|
|
15
16
|
return createDecorator(options, false);
|
|
16
17
|
}
|
|
18
|
+
/** Defines a unique constraint on a property or entity class (legacy TypeScript decorator). */
|
|
17
19
|
export function Unique(options = {}) {
|
|
18
20
|
return createDecorator(options, true);
|
|
19
21
|
}
|
package/legacy/ManyToMany.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type EntityName, type ManyToManyOptions } from '@mikro-orm/core';
|
|
2
|
+
/** Defines a many-to-many relationship (legacy TypeScript decorator). */
|
|
2
3
|
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
4
|
export declare function ManyToMany<Target extends object, Owner extends object>(entity: string, options?: any): never;
|
|
4
5
|
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,4 +1,5 @@
|
|
|
1
1
|
import { type ManyToOneOptions, type EntityName } from '@mikro-orm/core';
|
|
2
|
+
/** Defines a many-to-one relationship (legacy TypeScript decorator). */
|
|
2
3
|
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
4
|
export declare function ManyToOne<Target extends object, Owner extends object>(entity: string, options?: any): never;
|
|
4
5
|
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,4 @@
|
|
|
1
1
|
import { type EntityName, type OneToManyOptions } from '@mikro-orm/core';
|
|
2
|
+
/** Defines a one-to-many relationship (legacy TypeScript decorator). */
|
|
2
3
|
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
4
|
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,3 +1,4 @@
|
|
|
1
1
|
import { type EntityName, type OneToOneOptions } from '@mikro-orm/core';
|
|
2
|
+
/** Defines a one-to-one relationship (legacy TypeScript decorator). */
|
|
2
3
|
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
4
|
export declare function OneToOne<Target, Owner>(entity?: OneToOneOptions<Owner, Target>): (target: Owner, propertyName: string) => void;
|
package/legacy/PrimaryKey.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { type PrimaryKeyOptions, type SerializedPrimaryKeyOptions } from '@mikro-orm/core';
|
|
2
|
+
/** Marks a property as the primary key of an entity (legacy TypeScript decorator). */
|
|
2
3
|
export declare function PrimaryKey<T extends object>(options?: PrimaryKeyOptions<T>): (target: T, propertyName: string) => void;
|
|
4
|
+
/** Marks a property as the serialized form of the primary key, e.g. for MongoDB ObjectId (legacy TypeScript decorator). */
|
|
3
5
|
export declare function SerializedPrimaryKey<T extends object>(options?: SerializedPrimaryKeyOptions<T>): (target: T, propertyName: string) => void;
|
package/legacy/PrimaryKey.js
CHANGED
|
@@ -13,9 +13,11 @@ function createDecorator(options, serialized) {
|
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
+
/** Marks a property as the primary key of an entity (legacy TypeScript decorator). */
|
|
16
17
|
export function PrimaryKey(options = {}) {
|
|
17
18
|
return createDecorator(options, false);
|
|
18
19
|
}
|
|
20
|
+
/** Marks a property as the serialized form of the primary key, e.g. for MongoDB ObjectId (legacy TypeScript decorator). */
|
|
19
21
|
export function SerializedPrimaryKey(options = {}) {
|
|
20
22
|
return createDecorator(options, true);
|
|
21
23
|
}
|
package/legacy/Property.d.ts
CHANGED
package/legacy/Property.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Utils, ReferenceKind } from '@mikro-orm/core';
|
|
2
2
|
import { validateSingleDecorator, getMetadataFromDecorator } from '../utils.js';
|
|
3
|
+
/** Defines a scalar property on an entity (legacy TypeScript decorator). */
|
|
3
4
|
export function Property(options = {}) {
|
|
4
5
|
return function (target, propertyName) {
|
|
5
6
|
const meta = getMetadataFromDecorator(target.constructor);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { type EntityMetadata, type EntityProperty, MetadataProvider } from '@mikro-orm/core';
|
|
3
|
+
/** Metadata provider that uses `reflect-metadata` to infer property types from TypeScript's emitted design:type metadata. */
|
|
3
4
|
export declare class ReflectMetadataProvider extends MetadataProvider {
|
|
4
5
|
loadEntityMetadata(meta: EntityMetadata): void;
|
|
5
6
|
protected initPropertyType(meta: EntityMetadata, prop: EntityProperty): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { EntitySchema, MetadataProvider, ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
3
|
+
/** Metadata provider that uses `reflect-metadata` to infer property types from TypeScript's emitted design:type metadata. */
|
|
3
4
|
export class ReflectMetadataProvider extends MetadataProvider {
|
|
4
5
|
loadEntityMetadata(meta) {
|
|
5
6
|
// load types and column names
|
|
@@ -16,7 +17,7 @@ export class ReflectMetadataProvider extends MetadataProvider {
|
|
|
16
17
|
.sort()
|
|
17
18
|
.join(' | ')
|
|
18
19
|
: Utils.className(tmp);
|
|
19
|
-
prop.target = tmp
|
|
20
|
+
prop.target = EntitySchema.is(tmp) ? tmp.meta.class : tmp;
|
|
20
21
|
}
|
|
21
22
|
else {
|
|
22
23
|
this.initPropertyType(meta, prop);
|
package/legacy/hooks.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
/** Called before a new entity is persisted to the database (legacy TypeScript decorator). */
|
|
1
2
|
export declare function BeforeCreate(): (target: any, method: string) => void;
|
|
3
|
+
/** Called after a new entity has been persisted to the database (legacy TypeScript decorator). */
|
|
2
4
|
export declare function AfterCreate(): (target: any, method: string) => void;
|
|
5
|
+
/** Called before an existing entity is updated in the database (legacy TypeScript decorator). */
|
|
3
6
|
export declare function BeforeUpdate(): (target: any, method: string) => void;
|
|
7
|
+
/** Called after an existing entity has been updated in the database (legacy TypeScript decorator). */
|
|
4
8
|
export declare function AfterUpdate(): (target: any, method: string) => void;
|
|
9
|
+
/** Called before an entity is upserted (legacy TypeScript decorator). */
|
|
5
10
|
export declare function BeforeUpsert(): (target: any, method: string) => void;
|
|
11
|
+
/** Called after an entity has been upserted (legacy TypeScript decorator). */
|
|
6
12
|
export declare function AfterUpsert(): (target: any, method: string) => void;
|
|
13
|
+
/** Called when an entity is instantiated by the EntityManager (legacy TypeScript decorator). */
|
|
7
14
|
export declare function OnInit(): (target: any, method: string) => void;
|
|
15
|
+
/** Called after an entity is loaded from the database (legacy TypeScript decorator). */
|
|
8
16
|
export declare function OnLoad(): (target: any, method: string) => void;
|
|
9
17
|
/**
|
|
10
18
|
* Called before deleting entity, but only when providing initialized entity to EM#remove()
|
package/legacy/hooks.js
CHANGED
|
@@ -7,27 +7,35 @@ function hook(type) {
|
|
|
7
7
|
meta.hooks[type].push(method);
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
|
+
/** Called before a new entity is persisted to the database (legacy TypeScript decorator). */
|
|
10
11
|
export function BeforeCreate() {
|
|
11
12
|
return hook(EventType.beforeCreate);
|
|
12
13
|
}
|
|
14
|
+
/** Called after a new entity has been persisted to the database (legacy TypeScript decorator). */
|
|
13
15
|
export function AfterCreate() {
|
|
14
16
|
return hook(EventType.afterCreate);
|
|
15
17
|
}
|
|
18
|
+
/** Called before an existing entity is updated in the database (legacy TypeScript decorator). */
|
|
16
19
|
export function BeforeUpdate() {
|
|
17
20
|
return hook(EventType.beforeUpdate);
|
|
18
21
|
}
|
|
22
|
+
/** Called after an existing entity has been updated in the database (legacy TypeScript decorator). */
|
|
19
23
|
export function AfterUpdate() {
|
|
20
24
|
return hook(EventType.afterUpdate);
|
|
21
25
|
}
|
|
26
|
+
/** Called before an entity is upserted (legacy TypeScript decorator). */
|
|
22
27
|
export function BeforeUpsert() {
|
|
23
28
|
return hook(EventType.beforeUpsert);
|
|
24
29
|
}
|
|
30
|
+
/** Called after an entity has been upserted (legacy TypeScript decorator). */
|
|
25
31
|
export function AfterUpsert() {
|
|
26
32
|
return hook(EventType.afterUpsert);
|
|
27
33
|
}
|
|
34
|
+
/** Called when an entity is instantiated by the EntityManager (legacy TypeScript decorator). */
|
|
28
35
|
export function OnInit() {
|
|
29
36
|
return hook(EventType.onInit);
|
|
30
37
|
}
|
|
38
|
+
/** Called after an entity is loaded from the database (legacy TypeScript decorator). */
|
|
31
39
|
export function OnLoad() {
|
|
32
40
|
return hook(EventType.onLoad);
|
|
33
41
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/decorators",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.3-dev.0",
|
|
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",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"copy": "node ../../scripts/copy.mjs"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@mikro-orm/core": "^7.0.
|
|
52
|
+
"@mikro-orm/core": "^7.0.2"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@mikro-orm/core": "7.0.
|
|
55
|
+
"@mikro-orm/core": "7.0.3-dev.0",
|
|
56
56
|
"reflect-metadata": "^0.1.0 || ^0.2.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
package/utils.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export declare function prepareMetadataContext<T>(context: ClassFieldDecoratorCo
|
|
|
39
39
|
* Analyzes stack trace of error created inside the function call.
|
|
40
40
|
*/
|
|
41
41
|
export declare function lookupPathFromDecorator(name: string, stack?: string[]): string;
|
|
42
|
+
/** Retrieves or creates the metadata object for a decorated entity class. */
|
|
42
43
|
export declare function getMetadataFromDecorator<T = any>(target: T & Dictionary & {
|
|
43
44
|
[MetadataStorage.PATH_SYMBOL]?: string;
|
|
44
45
|
}): EntityMetadata<T>;
|
package/utils.js
CHANGED
|
@@ -114,6 +114,7 @@ export function lookupPathFromDecorator(name, stack) {
|
|
|
114
114
|
return name;
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
+
/** Retrieves or creates the metadata object for a decorated entity class. */
|
|
117
118
|
export function getMetadataFromDecorator(target) {
|
|
118
119
|
if (!Object.hasOwn(target, MetadataStorage.PATH_SYMBOL)) {
|
|
119
120
|
Object.defineProperty(target, MetadataStorage.PATH_SYMBOL, {
|