@uecsio/nestjs-crud-module 1.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/LICENSE +21 -0
- package/README.md +332 -0
- package/dist/crud.controller.d.ts +6 -0
- package/dist/crud.controller.js +50 -0
- package/dist/crud.controller.js.map +1 -0
- package/dist/crud.module.d.ts +7 -0
- package/dist/crud.module.js +51 -0
- package/dist/crud.module.js.map +1 -0
- package/dist/crud.service.d.ts +4 -0
- package/dist/crud.service.js +33 -0
- package/dist/crud.service.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/crud-module-options.interface.d.ts +22 -0
- package/dist/interfaces/crud-module-options.interface.js +3 -0
- package/dist/interfaces/crud-module-options.interface.js.map +1 -0
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/interfaces/index.js +3 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/crud-route-name.type.d.ts +1 -0
- package/dist/types/crud-route-name.type.js +3 -0
- package/dist/types/crud-route-name.type.js.map +1 -0
- package/dist/types/crud-service.type.d.ts +4 -0
- package/dist/types/crud-service.type.js +3 -0
- package/dist/types/crud-service.type.js.map +1 -0
- package/dist/types/dto.type.d.ts +1 -0
- package/dist/types/dto.type.js +3 -0
- package/dist/types/dto.type.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
# NestJS CRUD Module
|
|
2
|
+
|
|
3
|
+
[](https://github.com/your-org/nestjs-crud-module/actions/workflows/ci.yml)
|
|
4
|
+
[](https://codecov.io/gh/your-org/nestjs-crud-module)
|
|
5
|
+
[](https://badge.fury.io/js/@your-org%2Fnestjs-crud-module)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
A dynamic CRUD module for NestJS with TypeORM, based on [@dataui/crud](https://github.com/gid-oss/dataui-nestjs-crud). This package simplifies the creation of RESTful CRUD endpoints by providing a configurable module that accepts TypeORM entities, DTOs, guards, and filters.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- 🚀 Quick setup with minimal boilerplate
|
|
13
|
+
- 🔧 Configurable DTOs for create, update, and replace operations
|
|
14
|
+
- 🛡️ Support for guards, filters, and interceptors
|
|
15
|
+
- 📦 TypeORM integration out of the box
|
|
16
|
+
- 🎯 Based on the powerful @dataui/crud framework
|
|
17
|
+
- 🔄 Register single or multiple CRUD resources
|
|
18
|
+
- ✨ Full TypeScript support
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @your-org/nestjs-crud-module @dataui/crud @dataui/crud-typeorm @nestjs/typeorm typeorm class-validator class-transformer
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### 1. Define Your Entity
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
|
|
32
|
+
|
|
33
|
+
@Entity()
|
|
34
|
+
export class User {
|
|
35
|
+
@PrimaryGeneratedColumn()
|
|
36
|
+
id: number;
|
|
37
|
+
|
|
38
|
+
@Column()
|
|
39
|
+
name: string;
|
|
40
|
+
|
|
41
|
+
@Column()
|
|
42
|
+
email: string;
|
|
43
|
+
|
|
44
|
+
@Column()
|
|
45
|
+
age: number;
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 2. Define Your DTOs
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { IsString, IsEmail, IsNumber, IsOptional } from 'class-validator';
|
|
53
|
+
|
|
54
|
+
export class CreateUserDto {
|
|
55
|
+
@IsString()
|
|
56
|
+
name: string;
|
|
57
|
+
|
|
58
|
+
@IsEmail()
|
|
59
|
+
email: string;
|
|
60
|
+
|
|
61
|
+
@IsNumber()
|
|
62
|
+
age: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export class UpdateUserDto {
|
|
66
|
+
@IsString()
|
|
67
|
+
@IsOptional()
|
|
68
|
+
name?: string;
|
|
69
|
+
|
|
70
|
+
@IsEmail()
|
|
71
|
+
@IsOptional()
|
|
72
|
+
email?: string;
|
|
73
|
+
|
|
74
|
+
@IsNumber()
|
|
75
|
+
@IsOptional()
|
|
76
|
+
age?: number;
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 3. Register the CRUD Module
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { Module } from '@nestjs/common';
|
|
84
|
+
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
85
|
+
import { CrudModule } from '@your-org/nestjs-crud-module';
|
|
86
|
+
import { User } from './user.entity';
|
|
87
|
+
import { CreateUserDto, UpdateUserDto } from './user.dto';
|
|
88
|
+
|
|
89
|
+
@Module({
|
|
90
|
+
imports: [
|
|
91
|
+
TypeOrmModule.forRoot({
|
|
92
|
+
// Your TypeORM configuration
|
|
93
|
+
}),
|
|
94
|
+
CrudModule.register({
|
|
95
|
+
entity: User,
|
|
96
|
+
path: 'users',
|
|
97
|
+
createDto: CreateUserDto,
|
|
98
|
+
updateDto: UpdateUserDto,
|
|
99
|
+
}),
|
|
100
|
+
],
|
|
101
|
+
})
|
|
102
|
+
export class AppModule {}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
That's it! You now have a fully functional CRUD API with the following endpoints:
|
|
106
|
+
|
|
107
|
+
- `GET /users` - Get all users (with filtering, sorting, pagination)
|
|
108
|
+
- `GET /users/:id` - Get a specific user
|
|
109
|
+
- `POST /users` - Create a new user
|
|
110
|
+
- `POST /users/bulk` - Create multiple users
|
|
111
|
+
- `PATCH /users/:id` - Update a user
|
|
112
|
+
- `PUT /users/:id` - Replace a user
|
|
113
|
+
- `DELETE /users/:id` - Delete a user
|
|
114
|
+
|
|
115
|
+
## Advanced Usage
|
|
116
|
+
|
|
117
|
+
### With Guards and Filters
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { JwtAuthGuard } from './guards/jwt-auth.guard';
|
|
121
|
+
import { HttpExceptionFilter } from './filters/http-exception.filter';
|
|
122
|
+
|
|
123
|
+
CrudModule.register({
|
|
124
|
+
entity: User,
|
|
125
|
+
path: 'users',
|
|
126
|
+
createDto: CreateUserDto,
|
|
127
|
+
updateDto: UpdateUserDto,
|
|
128
|
+
guards: [JwtAuthGuard],
|
|
129
|
+
filters: [HttpExceptionFilter],
|
|
130
|
+
})
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### With Custom CRUD Options
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
CrudModule.register({
|
|
137
|
+
entity: User,
|
|
138
|
+
path: 'users',
|
|
139
|
+
createDto: CreateUserDto,
|
|
140
|
+
updateDto: UpdateUserDto,
|
|
141
|
+
crudOptions: {
|
|
142
|
+
query: {
|
|
143
|
+
limit: 10,
|
|
144
|
+
maxLimit: 100,
|
|
145
|
+
alwaysPaginate: true,
|
|
146
|
+
sort: [{ field: 'id', order: 'DESC' }],
|
|
147
|
+
join: {
|
|
148
|
+
profile: { eager: true },
|
|
149
|
+
'profile.avatar': {},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
params: {
|
|
153
|
+
id: {
|
|
154
|
+
field: 'id',
|
|
155
|
+
type: 'uuid',
|
|
156
|
+
primary: true,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
})
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Limiting Routes
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
// Only enable specific routes
|
|
167
|
+
CrudModule.register({
|
|
168
|
+
entity: User,
|
|
169
|
+
path: 'users',
|
|
170
|
+
createDto: CreateUserDto,
|
|
171
|
+
updateDto: UpdateUserDto,
|
|
172
|
+
routes: {
|
|
173
|
+
only: ['getManyBase', 'getOneBase', 'createOneBase'],
|
|
174
|
+
},
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
// Or exclude specific routes
|
|
178
|
+
CrudModule.register({
|
|
179
|
+
entity: User,
|
|
180
|
+
path: 'users',
|
|
181
|
+
createDto: CreateUserDto,
|
|
182
|
+
updateDto: UpdateUserDto,
|
|
183
|
+
routes: {
|
|
184
|
+
exclude: ['deleteOneBase'],
|
|
185
|
+
},
|
|
186
|
+
})
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Registering Multiple CRUD Resources
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import { Product } from './product.entity';
|
|
193
|
+
import { Category } from './category.entity';
|
|
194
|
+
|
|
195
|
+
@Module({
|
|
196
|
+
imports: [
|
|
197
|
+
CrudModule.registerMany([
|
|
198
|
+
{
|
|
199
|
+
entity: User,
|
|
200
|
+
path: 'users',
|
|
201
|
+
createDto: CreateUserDto,
|
|
202
|
+
updateDto: UpdateUserDto,
|
|
203
|
+
guards: [JwtAuthGuard],
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
entity: Product,
|
|
207
|
+
path: 'products',
|
|
208
|
+
createDto: CreateProductDto,
|
|
209
|
+
updateDto: UpdateProductDto,
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
entity: Category,
|
|
213
|
+
path: 'categories',
|
|
214
|
+
createDto: CreateCategoryDto,
|
|
215
|
+
updateDto: UpdateCategoryDto,
|
|
216
|
+
},
|
|
217
|
+
]),
|
|
218
|
+
],
|
|
219
|
+
})
|
|
220
|
+
export class AppModule {}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Custom Service
|
|
224
|
+
|
|
225
|
+
If you need custom business logic, you can extend the base service:
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
import { Injectable } from '@nestjs/common';
|
|
229
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
230
|
+
import { Repository } from 'typeorm';
|
|
231
|
+
import { TypeOrmCrudService } from '@dataui/crud-typeorm';
|
|
232
|
+
import { User } from './user.entity';
|
|
233
|
+
|
|
234
|
+
@Injectable()
|
|
235
|
+
export class CustomUserService extends TypeOrmCrudService<User> {
|
|
236
|
+
constructor(@InjectRepository(User) repo: Repository<User>) {
|
|
237
|
+
super(repo);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Add your custom methods
|
|
241
|
+
async findByEmail(email: string): Promise<User> {
|
|
242
|
+
return this.repo.findOne({ where: { email } });
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Then use it in the module
|
|
247
|
+
CrudModule.register({
|
|
248
|
+
entity: User,
|
|
249
|
+
path: 'users',
|
|
250
|
+
service: CustomUserService,
|
|
251
|
+
createDto: CreateUserDto,
|
|
252
|
+
updateDto: UpdateUserDto,
|
|
253
|
+
})
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Query Parameters
|
|
257
|
+
|
|
258
|
+
Thanks to @dataui/crud, you can use powerful query parameters:
|
|
259
|
+
|
|
260
|
+
### Filtering
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
GET /users?filter=age||$gt||18
|
|
264
|
+
GET /users?filter=name||$cont||John
|
|
265
|
+
GET /users?filter=email||$notnull
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Sorting
|
|
269
|
+
|
|
270
|
+
```
|
|
271
|
+
GET /users?sort=name,ASC
|
|
272
|
+
GET /users?sort=age,DESC&sort=name,ASC
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Pagination
|
|
276
|
+
|
|
277
|
+
```
|
|
278
|
+
GET /users?page=1&limit=10
|
|
279
|
+
GET /users?offset=20&limit=10
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Relations
|
|
283
|
+
|
|
284
|
+
```
|
|
285
|
+
GET /users?join=profile
|
|
286
|
+
GET /users?join=profile||email,avatar
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Field Selection
|
|
290
|
+
|
|
291
|
+
```
|
|
292
|
+
GET /users?fields=id,name,email
|
|
293
|
+
GET /users?fields=id,name&join=profile||email
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## API Reference
|
|
297
|
+
|
|
298
|
+
### CrudModuleOptions
|
|
299
|
+
|
|
300
|
+
| Property | Type | Required | Description |
|
|
301
|
+
|----------|------|----------|-------------|
|
|
302
|
+
| `entity` | `Type<Entity>` | Yes | TypeORM entity class |
|
|
303
|
+
| `path` | `string` | Yes | Controller route path |
|
|
304
|
+
| `createDto` | `Type<any>` | No | DTO for create operations |
|
|
305
|
+
| `updateDto` | `Type<any>` | No | DTO for update operations |
|
|
306
|
+
| `replaceDto` | `Type<any>` | No | DTO for replace operations |
|
|
307
|
+
| `guards` | `Type<any>[]` | No | Guards to apply to the controller |
|
|
308
|
+
| `filters` | `Type<any>[]` | No | Exception filters to apply |
|
|
309
|
+
| `interceptors` | `Type<any>[]` | No | Interceptors to apply |
|
|
310
|
+
| `service` | `Type<any>` | No | Custom service (must extend TypeOrmCrudService) |
|
|
311
|
+
| `routes` | `object` | No | Enable/disable specific routes |
|
|
312
|
+
| `crudOptions` | `CrudOptions` | No | Additional @dataui/crud options |
|
|
313
|
+
|
|
314
|
+
## Testing
|
|
315
|
+
|
|
316
|
+
The package includes comprehensive tests with >97% coverage:
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
npm test # Run all tests
|
|
320
|
+
npm run test:watch # Run tests in watch mode
|
|
321
|
+
npm run test:coverage # Run tests with coverage report
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
See [test/README.md](test/README.md) for detailed testing documentation.
|
|
325
|
+
|
|
326
|
+
## License
|
|
327
|
+
|
|
328
|
+
MIT
|
|
329
|
+
|
|
330
|
+
## Credits
|
|
331
|
+
|
|
332
|
+
Built on top of [@dataui/crud](https://github.com/gid-oss/dataui-nestjs-crud) by the GID team.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
import { CrudController } from '@dataui/crud';
|
|
3
|
+
import { TypeOrmCrudService } from '@dataui/crud-typeorm';
|
|
4
|
+
import { ObjectLiteral } from 'typeorm';
|
|
5
|
+
import { CrudModuleOptions } from './interfaces/crud-module-options.interface';
|
|
6
|
+
export declare function createCrudController<Entity extends ObjectLiteral>(options: CrudModuleOptions<Entity>, ServiceClass: Type<TypeOrmCrudService<Entity>>): Type<CrudController<Entity>>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createCrudController = createCrudController;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const crud_1 = require("@dataui/crud");
|
|
15
|
+
const crud_typeorm_1 = require("@dataui/crud-typeorm");
|
|
16
|
+
function createCrudController(options, ServiceClass) {
|
|
17
|
+
const crudOptions = {
|
|
18
|
+
model: {
|
|
19
|
+
type: options.entity,
|
|
20
|
+
},
|
|
21
|
+
dto: {
|
|
22
|
+
create: options.createDto,
|
|
23
|
+
update: options.updateDto,
|
|
24
|
+
replace: options.replaceDto,
|
|
25
|
+
},
|
|
26
|
+
routes: options.routes,
|
|
27
|
+
...options.crudOptions,
|
|
28
|
+
};
|
|
29
|
+
let CrudControllerHost = class CrudControllerHost {
|
|
30
|
+
constructor(service) {
|
|
31
|
+
this.service = service;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
CrudControllerHost = __decorate([
|
|
35
|
+
(0, crud_1.Crud)(crudOptions),
|
|
36
|
+
(0, common_1.Controller)(options.path),
|
|
37
|
+
__metadata("design:paramtypes", [crud_typeorm_1.TypeOrmCrudService])
|
|
38
|
+
], CrudControllerHost);
|
|
39
|
+
if (options.guards && options.guards.length > 0) {
|
|
40
|
+
(0, common_1.UseGuards)(...options.guards)(CrudControllerHost);
|
|
41
|
+
}
|
|
42
|
+
if (options.filters && options.filters.length > 0) {
|
|
43
|
+
(0, common_1.UseFilters)(...options.filters)(CrudControllerHost);
|
|
44
|
+
}
|
|
45
|
+
if (options.interceptors && options.interceptors.length > 0) {
|
|
46
|
+
(0, common_1.UseInterceptors)(...options.interceptors)(CrudControllerHost);
|
|
47
|
+
}
|
|
48
|
+
return CrudControllerHost;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=crud.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud.controller.js","sourceRoot":"","sources":["../src/crud.controller.ts"],"names":[],"mappings":";;;;;;;;;;;AASA,oDAyCC;AAlDD,2CAA0F;AAC1F,uCAAiE;AACjE,uDAA0D;AAO1D,SAAgB,oBAAoB,CAClC,OAAkC,EAClC,YAA8C;IAG9C,MAAM,WAAW,GAAgB;QAC/B,KAAK,EAAE;YACL,IAAI,EAAE,OAAO,CAAC,MAAM;SACrB;QACD,GAAG,EAAE;YACH,MAAM,EAAE,OAAO,CAAC,SAAS;YACzB,MAAM,EAAE,OAAO,CAAC,SAAS;YACzB,OAAO,EAAE,OAAO,CAAC,UAAU;SAC5B;QACD,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,GAAG,OAAO,CAAC,WAAW;KACvB,CAAC;IAGF,IAEM,kBAAkB,GAFxB,MAEM,kBAAkB;QACtB,YAAmB,OAAmC;YAAnC,YAAO,GAAP,OAAO,CAA4B;QAAG,CAAC;KAC3D,CAAA;IAFK,kBAAkB;QAFvB,IAAA,WAAI,EAAC,WAAW,CAAC;QACjB,IAAA,mBAAU,EAAC,OAAO,CAAC,IAAI,CAAC;yCAEK,iCAAkB;OAD1C,kBAAkB,CAEvB;IAGD,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChD,IAAA,kBAAS,EAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,kBAAkB,CAAC,CAAC;IACnD,CAAC;IAGD,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClD,IAAA,mBAAU,EAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,kBAAkB,CAAC,CAAC;IACrD,CAAC;IAGD,IAAI,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5D,IAAA,wBAAe,EAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,kBAAkB,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,kBAAkB,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { ObjectLiteral } from 'typeorm';
|
|
3
|
+
import { CrudModuleOptions } from './interfaces/crud-module-options.interface';
|
|
4
|
+
export declare class CrudModule {
|
|
5
|
+
static register<Entity extends ObjectLiteral>(options: CrudModuleOptions<Entity>): DynamicModule;
|
|
6
|
+
static registerMany<Entity extends ObjectLiteral>(optionsArray: Array<CrudModuleOptions<Entity>>): DynamicModule;
|
|
7
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var CrudModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.CrudModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
13
|
+
const crud_service_1 = require("./crud.service");
|
|
14
|
+
const crud_controller_1 = require("./crud.controller");
|
|
15
|
+
let CrudModule = CrudModule_1 = class CrudModule {
|
|
16
|
+
static register(options) {
|
|
17
|
+
const ServiceClass = options.service || (0, crud_service_1.createCrudService)(options.entity);
|
|
18
|
+
const ControllerClass = (0, crud_controller_1.createCrudController)(options, ServiceClass);
|
|
19
|
+
return {
|
|
20
|
+
module: CrudModule_1,
|
|
21
|
+
imports: [typeorm_1.TypeOrmModule.forFeature([options.entity])],
|
|
22
|
+
controllers: [ControllerClass],
|
|
23
|
+
providers: [ServiceClass],
|
|
24
|
+
exports: [ServiceClass],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
static registerMany(optionsArray) {
|
|
28
|
+
const controllers = [];
|
|
29
|
+
const providers = [];
|
|
30
|
+
const entities = [];
|
|
31
|
+
for (const options of optionsArray) {
|
|
32
|
+
const ServiceClass = options.service || (0, crud_service_1.createCrudService)(options.entity);
|
|
33
|
+
const ControllerClass = (0, crud_controller_1.createCrudController)(options, ServiceClass);
|
|
34
|
+
controllers.push(ControllerClass);
|
|
35
|
+
providers.push(ServiceClass);
|
|
36
|
+
entities.push(options.entity);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
module: CrudModule_1,
|
|
40
|
+
imports: [typeorm_1.TypeOrmModule.forFeature(entities)],
|
|
41
|
+
controllers,
|
|
42
|
+
providers,
|
|
43
|
+
exports: providers,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.CrudModule = CrudModule;
|
|
48
|
+
exports.CrudModule = CrudModule = CrudModule_1 = __decorate([
|
|
49
|
+
(0, common_1.Module)({})
|
|
50
|
+
], CrudModule);
|
|
51
|
+
//# sourceMappingURL=crud.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud.module.js","sourceRoot":"","sources":["../src/crud.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA6D;AAC7D,6CAAgD;AAKhD,iDAAmD;AACnD,uDAAyD;AAGlD,IAAM,UAAU,kBAAhB,MAAM,UAAU;IAMrB,MAAM,CAAC,QAAQ,CAA+B,OAAkC;QAE9E,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,IAAI,IAAA,gCAAiB,EAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAG1E,MAAM,eAAe,GAAG,IAAA,sCAAoB,EAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAEpE,OAAO;YACL,MAAM,EAAE,YAAU;YAClB,OAAO,EAAE,CAAC,uBAAa,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;YACrD,WAAW,EAAE,CAAC,eAAe,CAAC;YAC9B,SAAS,EAAE,CAAC,YAAY,CAAC;YACzB,OAAO,EAAE,CAAC,YAAY,CAAC;SACxB,CAAC;IACJ,CAAC;IAOD,MAAM,CAAC,YAAY,CACjB,YAA8C;QAE9C,MAAM,WAAW,GAAwC,EAAE,CAAC;QAC5D,MAAM,SAAS,GAA4C,EAAE,CAAC;QAC9D,MAAM,QAAQ,GAAwB,EAAE,CAAC;QAEzC,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;YAEnC,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,IAAI,IAAA,gCAAiB,EAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAG1E,MAAM,eAAe,GAAG,IAAA,sCAAoB,EAAC,OAAO,EAAE,YAAY,CAAC,CAAC;YAEpE,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YAClC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAC7B,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QAED,OAAO;YACL,MAAM,EAAE,YAAU;YAClB,OAAO,EAAE,CAAC,uBAAa,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YAC7C,WAAW;YACX,SAAS;YACT,OAAO,EAAE,SAAS;SACnB,CAAC;IACJ,CAAC;CACF,CAAA;AAtDY,gCAAU;qBAAV,UAAU;IADtB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,UAAU,CAsDtB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createCrudService = createCrudService;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
18
|
+
const typeorm_2 = require("typeorm");
|
|
19
|
+
const crud_typeorm_1 = require("@dataui/crud-typeorm");
|
|
20
|
+
function createCrudService(entity) {
|
|
21
|
+
let CrudService = class CrudService extends crud_typeorm_1.TypeOrmCrudService {
|
|
22
|
+
constructor(repo) {
|
|
23
|
+
super(repo);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
CrudService = __decorate([
|
|
27
|
+
(0, common_1.Injectable)(),
|
|
28
|
+
__param(0, (0, typeorm_1.InjectRepository)(entity)),
|
|
29
|
+
__metadata("design:paramtypes", [typeorm_2.Repository])
|
|
30
|
+
], CrudService);
|
|
31
|
+
return CrudService;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=crud.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud.service.js","sourceRoot":"","sources":["../src/crud.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AASA,8CAWC;AApBD,2CAAkD;AAClD,6CAAmD;AACnD,qCAAoD;AACpD,uDAA0D;AAM1D,SAAgB,iBAAiB,CAC/B,MAAoB;IAEpB,IACM,WAAW,GADjB,MACM,WAAY,SAAQ,iCAA0B;QAClD,YAAsC,IAAwB;YAC5D,KAAK,CAAC,IAAI,CAAC,CAAC;QACd,CAAC;KACF,CAAA;IAJK,WAAW;QADhB,IAAA,mBAAU,GAAE;QAEE,WAAA,IAAA,0BAAgB,EAAC,MAAM,CAAC,CAAA;yCAAO,oBAAU;OADlD,WAAW,CAIhB;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { CrudModule } from './crud.module';
|
|
2
|
+
export * from './interfaces';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export { createCrudService } from './crud.service';
|
|
5
|
+
export { createCrudController } from './crud.controller';
|
|
6
|
+
export { Crud, CrudController, CrudRequest, CrudRequestInterceptor, CrudAuth, Override, ParsedRequest, ParsedBody, CreateManyDto, } from '@dataui/crud';
|
|
7
|
+
export { TypeOrmCrudService } from '@dataui/crud-typeorm';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.TypeOrmCrudService = exports.ParsedBody = exports.ParsedRequest = exports.Override = exports.CrudAuth = exports.CrudRequestInterceptor = exports.Crud = exports.createCrudController = exports.createCrudService = exports.CrudModule = void 0;
|
|
18
|
+
var crud_module_1 = require("./crud.module");
|
|
19
|
+
Object.defineProperty(exports, "CrudModule", { enumerable: true, get: function () { return crud_module_1.CrudModule; } });
|
|
20
|
+
__exportStar(require("./interfaces"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
22
|
+
var crud_service_1 = require("./crud.service");
|
|
23
|
+
Object.defineProperty(exports, "createCrudService", { enumerable: true, get: function () { return crud_service_1.createCrudService; } });
|
|
24
|
+
var crud_controller_1 = require("./crud.controller");
|
|
25
|
+
Object.defineProperty(exports, "createCrudController", { enumerable: true, get: function () { return crud_controller_1.createCrudController; } });
|
|
26
|
+
var crud_1 = require("@dataui/crud");
|
|
27
|
+
Object.defineProperty(exports, "Crud", { enumerable: true, get: function () { return crud_1.Crud; } });
|
|
28
|
+
Object.defineProperty(exports, "CrudRequestInterceptor", { enumerable: true, get: function () { return crud_1.CrudRequestInterceptor; } });
|
|
29
|
+
Object.defineProperty(exports, "CrudAuth", { enumerable: true, get: function () { return crud_1.CrudAuth; } });
|
|
30
|
+
Object.defineProperty(exports, "Override", { enumerable: true, get: function () { return crud_1.Override; } });
|
|
31
|
+
Object.defineProperty(exports, "ParsedRequest", { enumerable: true, get: function () { return crud_1.ParsedRequest; } });
|
|
32
|
+
Object.defineProperty(exports, "ParsedBody", { enumerable: true, get: function () { return crud_1.ParsedBody; } });
|
|
33
|
+
var crud_typeorm_1 = require("@dataui/crud-typeorm");
|
|
34
|
+
Object.defineProperty(exports, "TypeOrmCrudService", { enumerable: true, get: function () { return crud_typeorm_1.TypeOrmCrudService; } });
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AAGnB,+CAA6B;AAG7B,0CAAwB;AAGxB,+CAAmD;AAA1C,iHAAA,iBAAiB,OAAA;AAC1B,qDAAyD;AAAhD,uHAAA,oBAAoB,OAAA;AAG7B,qCAUsB;AATpB,4FAAA,IAAI,OAAA;AAGJ,8GAAA,sBAAsB,OAAA;AACtB,gGAAA,QAAQ,OAAA;AACR,gGAAA,QAAQ,OAAA;AACR,qGAAA,aAAa,OAAA;AACb,kGAAA,UAAU,OAAA;AAIZ,qDAA0D;AAAjD,kHAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Type, CanActivate, ExceptionFilter, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { CrudOptions } from '@dataui/crud';
|
|
3
|
+
import { TypeOrmCrudService } from '@dataui/crud-typeorm';
|
|
4
|
+
import { ObjectLiteral } from 'typeorm';
|
|
5
|
+
import { DtoType } from '../types/dto.type';
|
|
6
|
+
import { CrudRouteName } from '../types/crud-route-name.type';
|
|
7
|
+
export interface CrudModuleOptions<Entity extends ObjectLiteral = ObjectLiteral> {
|
|
8
|
+
entity: Type<Entity>;
|
|
9
|
+
createDto?: DtoType;
|
|
10
|
+
updateDto?: DtoType;
|
|
11
|
+
replaceDto?: DtoType;
|
|
12
|
+
guards?: Array<Type<CanActivate>>;
|
|
13
|
+
filters?: Array<Type<ExceptionFilter>>;
|
|
14
|
+
interceptors?: Array<Type<NestInterceptor>>;
|
|
15
|
+
path: string;
|
|
16
|
+
crudOptions?: CrudOptions;
|
|
17
|
+
service?: Type<TypeOrmCrudService<Entity>>;
|
|
18
|
+
routes?: {
|
|
19
|
+
only?: Array<CrudRouteName>;
|
|
20
|
+
exclude?: Array<CrudRouteName>;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud-module-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/crud-module-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CrudModuleOptions } from './crud-module-options.interface';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":""}
|