nestjs-query-mikro-orm 0.1.3 โ 0.1.5
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 +138 -103
- package/dist/index.cjs +425 -138
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -11
- package/dist/index.d.ts +47 -11
- package/dist/index.mjs +425 -138
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,56 +1,59 @@
|
|
|
1
1
|
# nestjs-query-mikro-orm
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A NestJS Query adapter for MikroORM.
|
|
4
|
+
|
|
5
|
+
This package provides a QueryService implementation for MikroORM entities, designed to work with the NestJS Query ecosystem while staying database-agnostic.
|
|
6
|
+
|
|
7
|
+
## What You Get โจ
|
|
8
|
+
|
|
9
|
+
- ๐ Full QueryService CRUD support for MikroORM repositories
|
|
10
|
+
- ๐ Filtering, sorting, paging, and count support
|
|
11
|
+
- ๐ Relation operations:
|
|
12
|
+
- queryRelations
|
|
13
|
+
- findRelation
|
|
14
|
+
- countRelations
|
|
15
|
+
- aggregateRelations
|
|
16
|
+
- add/set/remove relation helpers
|
|
17
|
+
- ๐ Aggregate queries with groupBy support
|
|
18
|
+
- ๐งน Soft delete support
|
|
19
|
+
- โ๏ธ Configurable relation loading behavior:
|
|
20
|
+
- native-first relation loading
|
|
21
|
+
- MikroORM relation strategy control (`select-in`, `joined`, `balanced`)
|
|
22
|
+
- optional dataloader forwarding for native relation loads
|
|
23
|
+
- ๐ง TypeScript-first API
|
|
24
|
+
- ๐ฆ ESM and CJS package output
|
|
25
|
+
|
|
26
|
+
## Installation ๐ฅ
|
|
4
27
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- ๐ Full NestJS Query support with MikroORM
|
|
10
|
-
- ๐ฆ Type-safe query building
|
|
11
|
-
- ๐ Advanced filtering and sorting
|
|
12
|
-
- ๐ Relation query support
|
|
13
|
-
- ๐ Aggregation queries
|
|
14
|
-
- ๐ฏ Soft delete support
|
|
15
|
-
- โจ Built with TypeScript
|
|
16
|
-
- ๐ฆ Dual-format support (ESM & CommonJS)
|
|
17
|
-
|
|
18
|
-
## Compatibility
|
|
19
|
-
|
|
20
|
-
This package supports both **ES Modules (ESM)** and **CommonJS (CJS)** for maximum compatibility across different Node.js environments and bundlers.
|
|
21
|
-
|
|
22
|
-
- **ESM**: `import { MikroOrmQueryService } from 'nestjs-query-mikro-orm'`
|
|
23
|
-
- **CommonJS**: `const { MikroOrmQueryService } = require('nestjs-query-mikro-orm')`
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add nestjs-query-mikro-orm
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
# peer dependencies (minimum typical setup)
|
|
32
|
+
pnpm add @mikro-orm/core @mikro-orm/decorators @mikro-orm/nestjs
|
|
33
|
+
pnpm add @nestjs/common @nestjs/core @ptc-org/nestjs-query-core
|
|
34
|
+
pnpm add class-transformer reflect-metadata rxjs
|
|
35
|
+
```
|
|
26
36
|
|
|
27
|
-
|
|
37
|
+
If you plan to enable dataloader-based native relation loading, also install:
|
|
28
38
|
|
|
29
39
|
```bash
|
|
30
|
-
pnpm add
|
|
31
|
-
|
|
32
|
-
# Install peer dependencies if you haven't already
|
|
33
|
-
pnpm add @mikro-orm/core @nestjs/common @nestjs/core @ptc-org/nestjs-query-core reflect-metadata rxjs
|
|
40
|
+
pnpm add dataloader
|
|
34
41
|
```
|
|
35
42
|
|
|
36
|
-
##
|
|
43
|
+
## Compatibility โ
|
|
37
44
|
|
|
38
|
-
|
|
45
|
+
- Node.js: >= 18
|
|
46
|
+
- NestJS: 10 or 11
|
|
47
|
+
- MikroORM: 7
|
|
48
|
+
- @ptc-org/nestjs-query-core: 9.4+
|
|
39
49
|
|
|
40
|
-
|
|
41
|
-
import { NestQueryMikroOrmModule } from 'nestjs-query-mikro-orm';
|
|
42
|
-
import { Module } from '@nestjs/common';
|
|
43
|
-
import { UserEntity } from './user.entity';
|
|
50
|
+
The package supports both ESM and CommonJS consumers.
|
|
44
51
|
|
|
45
|
-
|
|
46
|
-
imports: [NestQueryMikroOrmModule.forFeature([UserEntity])],
|
|
47
|
-
})
|
|
48
|
-
export class UserModule {}
|
|
49
|
-
```
|
|
52
|
+
## Quick Start ๐
|
|
50
53
|
|
|
51
|
-
###
|
|
54
|
+
### 1. Define an entity
|
|
52
55
|
|
|
53
|
-
```
|
|
56
|
+
```ts
|
|
54
57
|
import { Entity, PrimaryKey, Property } from '@mikro-orm/core';
|
|
55
58
|
|
|
56
59
|
@Entity()
|
|
@@ -63,112 +66,144 @@ export class UserEntity {
|
|
|
63
66
|
|
|
64
67
|
@Property()
|
|
65
68
|
email!: string;
|
|
66
|
-
|
|
67
|
-
@Property()
|
|
68
|
-
createdAt: Date = new Date();
|
|
69
69
|
}
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
###
|
|
72
|
+
### 2. Register the feature module
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { Module } from '@nestjs/common';
|
|
76
|
+
import { NestjsQueryMikroOrmModule } from 'nestjs-query-mikro-orm';
|
|
77
|
+
import { UserEntity } from './user.entity';
|
|
78
|
+
|
|
79
|
+
@Module({
|
|
80
|
+
imports: [NestjsQueryMikroOrmModule.forFeature([UserEntity])],
|
|
81
|
+
})
|
|
82
|
+
export class UserModule {}
|
|
83
|
+
```
|
|
73
84
|
|
|
74
|
-
|
|
85
|
+
### 3. Use the service
|
|
86
|
+
|
|
87
|
+
```ts
|
|
75
88
|
import { Injectable } from '@nestjs/common';
|
|
89
|
+
import { InjectRepository } from '@mikro-orm/nestjs';
|
|
90
|
+
import { EntityRepository } from '@mikro-orm/core';
|
|
76
91
|
import { MikroOrmQueryService } from 'nestjs-query-mikro-orm';
|
|
77
92
|
import { UserEntity } from './user.entity';
|
|
78
93
|
|
|
79
94
|
@Injectable()
|
|
80
95
|
export class UserService extends MikroOrmQueryService<UserEntity> {
|
|
81
|
-
|
|
96
|
+
constructor(@InjectRepository(UserEntity) readonly repo: EntityRepository<UserEntity>) {
|
|
97
|
+
super(repo);
|
|
98
|
+
}
|
|
82
99
|
}
|
|
83
100
|
```
|
|
84
101
|
|
|
85
|
-
##
|
|
102
|
+
## Feature Module Options โ๏ธ
|
|
86
103
|
|
|
87
|
-
|
|
104
|
+
You can pass options to forFeature to configure generated QueryService providers.
|
|
88
105
|
|
|
89
|
-
|
|
90
|
-
- pnpm >= 9
|
|
106
|
+
`forFeature` supports both signatures:
|
|
91
107
|
|
|
92
|
-
|
|
108
|
+
- `forFeature([Entity], 'contextName')`
|
|
109
|
+
- `forFeature([Entity], { contextName, queryServiceOpts })`
|
|
93
110
|
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
pnpm install
|
|
111
|
+
```ts
|
|
112
|
+
import { NestjsQueryMikroOrmModule } from 'nestjs-query-mikro-orm';
|
|
97
113
|
|
|
98
|
-
|
|
99
|
-
|
|
114
|
+
NestjsQueryMikroOrmModule.forFeature([UserEntity], {
|
|
115
|
+
contextName: 'default',
|
|
116
|
+
queryServiceOpts: {
|
|
117
|
+
useSoftDelete: true,
|
|
118
|
+
relationLoading: {
|
|
119
|
+
strategy: 'select-in',
|
|
120
|
+
useDataloader: true,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
});
|
|
100
124
|
```
|
|
101
125
|
|
|
102
|
-
###
|
|
126
|
+
### relationLoading options
|
|
103
127
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
128
|
+
- strategy:
|
|
129
|
+
- `select-in`: force MikroORM select-in loading strategy for native relation population
|
|
130
|
+
- `joined`: force MikroORM joined loading strategy for native relation population
|
|
131
|
+
- `balanced`: force MikroORM balanced loading strategy for native relation population
|
|
132
|
+
- omitted: use MikroORM default strategy
|
|
133
|
+
- useDataloader:
|
|
134
|
+
- when `true`, native relation load paths forward `dataloader: true` to MikroORM relation loading
|
|
107
135
|
|
|
108
|
-
|
|
109
|
-
pnpm dev
|
|
136
|
+
## Soft Delete ๐งน
|
|
110
137
|
|
|
111
|
-
|
|
112
|
-
pnpm test
|
|
138
|
+
Enable soft delete behavior by passing useSoftDelete in service options.
|
|
113
139
|
|
|
114
|
-
|
|
115
|
-
|
|
140
|
+
```ts
|
|
141
|
+
super(repo, { useSoftDelete: true });
|
|
142
|
+
```
|
|
116
143
|
|
|
117
|
-
|
|
118
|
-
pnpm test:coverage
|
|
144
|
+
When enabled, read operations automatically include deletedAt = null filtering, and restoreOne/restoreMany become available.
|
|
119
145
|
|
|
120
|
-
|
|
121
|
-
pnpm lint
|
|
146
|
+
## Relation Loading Notes ๐
|
|
122
147
|
|
|
123
|
-
|
|
124
|
-
|
|
148
|
+
- Relation reads are native-first and use MikroORM population/identity-map semantics.
|
|
149
|
+
- If native extraction cannot resolve a relation shape (common with not-managed/custom hydrator flows), the adapter safely falls back to condition-based relation querying.
|
|
150
|
+
- `useDataloader` is applied to native relation loading paths, including batched relation resolution.
|
|
151
|
+
- For best dataloader results, enable MikroORM dataloaders in ORM config and execute relation loads in a batched execution frame.
|
|
125
152
|
|
|
126
|
-
|
|
127
|
-
pnpm format
|
|
153
|
+
## Integration with NestJS Query GraphQL ๐งฉ
|
|
128
154
|
|
|
129
|
-
|
|
130
|
-
pnpm format:check
|
|
155
|
+
This library focuses on QueryService behavior. You can plug it into your NestJS Query GraphQL setup as your backing service implementation.
|
|
131
156
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
157
|
+
Use relation decorators/resolvers from your GraphQL layer as usual; relation methods from this adapter are compatible with request-scoped loader patterns used by NestJS Query GraphQL.
|
|
158
|
+
|
|
159
|
+
## Public API ๐
|
|
160
|
+
|
|
161
|
+
Main exports include:
|
|
135
162
|
|
|
136
|
-
|
|
163
|
+
- NestjsQueryMikroOrmModule
|
|
164
|
+
- MikroOrmQueryService
|
|
165
|
+
- RelationQueryService
|
|
166
|
+
- Query builder helpers from the query export
|
|
137
167
|
|
|
138
|
-
|
|
168
|
+
## Development ๐ ๏ธ
|
|
139
169
|
|
|
140
|
-
|
|
141
|
-
- **pre-push**: Runs lint, typecheck, and tests before pushing
|
|
142
|
-
- **commit-msg**: Validates commit messages using commitlint
|
|
170
|
+
### Prerequisites ๐
|
|
143
171
|
|
|
144
|
-
|
|
172
|
+
- Node.js >= 18
|
|
173
|
+
- pnpm >= 9
|
|
145
174
|
|
|
146
|
-
|
|
175
|
+
### Setup ๐งช
|
|
147
176
|
|
|
148
177
|
```bash
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
docs: update documentation
|
|
152
|
-
style: format code
|
|
153
|
-
refactor: refactor code
|
|
154
|
-
test: add tests
|
|
155
|
-
chore: update dependencies
|
|
178
|
+
pnpm install
|
|
179
|
+
pnpm prepare
|
|
156
180
|
```
|
|
157
181
|
|
|
158
|
-
|
|
182
|
+
### Scripts ๐
|
|
159
183
|
|
|
160
|
-
|
|
184
|
+
```bash
|
|
185
|
+
pnpm build
|
|
186
|
+
pnpm dev
|
|
187
|
+
pnpm test
|
|
188
|
+
pnpm test:watch
|
|
189
|
+
pnpm test:coverage
|
|
190
|
+
pnpm lint
|
|
191
|
+
pnpm lint:fix
|
|
192
|
+
pnpm format
|
|
193
|
+
pnpm format:check
|
|
194
|
+
pnpm typecheck
|
|
195
|
+
```
|
|
161
196
|
|
|
162
|
-
##
|
|
197
|
+
## Contributing ๐ค
|
|
163
198
|
|
|
164
|
-
|
|
199
|
+
Contributions are welcome.
|
|
165
200
|
|
|
166
|
-
|
|
201
|
+
1. Fork the repository
|
|
202
|
+
2. Create your branch
|
|
203
|
+
3. Commit your changes
|
|
204
|
+
4. Push your branch
|
|
205
|
+
5. Open a pull request
|
|
167
206
|
|
|
168
|
-
|
|
207
|
+
## License ๐
|
|
169
208
|
|
|
170
|
-
|
|
171
|
-
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
172
|
-
3. Commit your changes (`git commit -m 'feat: add amazing feature'`)
|
|
173
|
-
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
174
|
-
5. Open a Pull Request
|
|
209
|
+
MIT
|