mongodb-dynamic-api 1.1.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/CHANGELOG.md +30 -0
- package/LICENSE +21 -0
- package/README.md +190 -0
- package/index.d.ts +1 -0
- package/index.js +17 -0
- package/package.json +119 -0
- package/src/builders/index.d.ts +1 -0
- package/src/builders/index.js +17 -0
- package/src/builders/route-decorators.builder.d.ts +18 -0
- package/src/builders/route-decorators.builder.js +76 -0
- package/src/decorators/index.d.ts +1 -0
- package/src/decorators/index.js +17 -0
- package/src/decorators/schema-options.decorator.d.ts +4 -0
- package/src/decorators/schema-options.decorator.js +11 -0
- package/src/dtos/entity.param.d.ts +4 -0
- package/src/dtos/entity.param.js +26 -0
- package/src/dtos/entity.query.d.ts +2 -0
- package/src/dtos/entity.query.js +6 -0
- package/src/dtos/index.d.ts +2 -0
- package/src/dtos/index.js +18 -0
- package/src/dynamic-api.module.d.ts +8 -0
- package/src/dynamic-api.module.js +101 -0
- package/src/helpers/config.helper.d.ts +61 -0
- package/src/helpers/config.helper.js +95 -0
- package/src/helpers/index.d.ts +2 -0
- package/src/helpers/index.js +18 -0
- package/src/helpers/route-decorators.helper.d.ts +4 -0
- package/src/helpers/route-decorators.helper.js +8 -0
- package/src/index.d.ts +10 -0
- package/src/index.js +26 -0
- package/src/interfaces/dynamic-api-options.interface.d.ts +15 -0
- package/src/interfaces/dynamic-api-options.interface.js +2 -0
- package/src/interfaces/dynamic-api-schema-options.interface.d.ts +43 -0
- package/src/interfaces/dynamic-api-schema-options.interface.js +2 -0
- package/src/interfaces/entity-mappers.interface.d.ts +8 -0
- package/src/interfaces/entity-mappers.interface.js +2 -0
- package/src/interfaces/index.d.ts +6 -0
- package/src/interfaces/index.js +22 -0
- package/src/interfaces/maybe-promise.type.d.ts +2 -0
- package/src/interfaces/maybe-promise.type.js +2 -0
- package/src/interfaces/route-config.interface.d.ts +17 -0
- package/src/interfaces/route-config.interface.js +2 -0
- package/src/interfaces/service-provider.interface.d.ts +6 -0
- package/src/interfaces/service-provider.interface.js +2 -0
- package/src/mixins/entity-body.mixin.d.ts +16 -0
- package/src/mixins/entity-body.mixin.js +24 -0
- package/src/mixins/entity-presenter.mixin.d.ts +15 -0
- package/src/mixins/entity-presenter.mixin.js +10 -0
- package/src/mixins/index.d.ts +2 -0
- package/src/mixins/index.js +18 -0
- package/src/models/base-entity.model.d.ts +32 -0
- package/src/models/base-entity.model.js +40 -0
- package/src/models/index.d.ts +2 -0
- package/src/models/index.js +18 -0
- package/src/models/soft-deletable-entity.model.d.ts +5 -0
- package/src/models/soft-deletable-entity.model.js +29 -0
- package/src/modules/create-many/base-create-many.service.d.ts +33 -0
- package/src/modules/create-many/base-create-many.service.js +22 -0
- package/src/modules/create-many/create-many-controller.interface.d.ts +9 -0
- package/src/modules/create-many/create-many-controller.interface.js +2 -0
- package/src/modules/create-many/create-many-controller.mixin.d.ts +6 -0
- package/src/modules/create-many/create-many-controller.mixin.js +81 -0
- package/src/modules/create-many/create-many-service.interface.d.ts +5 -0
- package/src/modules/create-many/create-many-service.interface.js +2 -0
- package/src/modules/create-many/create-many.helper.d.ts +7 -0
- package/src/modules/create-many/create-many.helper.js +68 -0
- package/src/modules/create-many/create-many.module.d.ts +6 -0
- package/src/modules/create-many/create-many.module.js +28 -0
- package/src/modules/create-many/index.d.ts +6 -0
- package/src/modules/create-many/index.js +22 -0
- package/src/modules/create-one/base-create-one.service.d.ts +33 -0
- package/src/modules/create-one/base-create-one.service.js +22 -0
- package/src/modules/create-one/create-one-controller.interface.d.ts +7 -0
- package/src/modules/create-one/create-one-controller.interface.js +2 -0
- package/src/modules/create-one/create-one-controller.mixin.d.ts +6 -0
- package/src/modules/create-one/create-one-controller.mixin.js +62 -0
- package/src/modules/create-one/create-one-service.interface.d.ts +5 -0
- package/src/modules/create-one/create-one-service.interface.js +2 -0
- package/src/modules/create-one/create-one.helper.d.ts +7 -0
- package/src/modules/create-one/create-one.helper.js +68 -0
- package/src/modules/create-one/create-one.module.d.ts +6 -0
- package/src/modules/create-one/create-one.module.js +28 -0
- package/src/modules/create-one/index.d.ts +6 -0
- package/src/modules/create-one/index.js +22 -0
- package/src/modules/delete-one/base-delete-one.service.d.ts +34 -0
- package/src/modules/delete-one/base-delete-one.service.js +29 -0
- package/src/modules/delete-one/delete-one-controller.interface.d.ts +7 -0
- package/src/modules/delete-one/delete-one-controller.interface.js +2 -0
- package/src/modules/delete-one/delete-one-controller.mixin.d.ts +6 -0
- package/src/modules/delete-one/delete-one-controller.mixin.js +63 -0
- package/src/modules/delete-one/delete-one-service.interface.d.ts +8 -0
- package/src/modules/delete-one/delete-one-service.interface.js +2 -0
- package/src/modules/delete-one/delete-one.helper.d.ts +7 -0
- package/src/modules/delete-one/delete-one.helper.js +68 -0
- package/src/modules/delete-one/delete-one.module.d.ts +6 -0
- package/src/modules/delete-one/delete-one.module.js +28 -0
- package/src/modules/delete-one/delete-one.presenter.d.ts +3 -0
- package/src/modules/delete-one/delete-one.presenter.js +20 -0
- package/src/modules/delete-one/index.d.ts +7 -0
- package/src/modules/delete-one/index.js +23 -0
- package/src/modules/duplicate-one/base-duplicate-one.service.d.ts +33 -0
- package/src/modules/duplicate-one/base-duplicate-one.service.js +41 -0
- package/src/modules/duplicate-one/duplicate-one-controller.interface.d.ts +7 -0
- package/src/modules/duplicate-one/duplicate-one-controller.interface.js +2 -0
- package/src/modules/duplicate-one/duplicate-one-controller.mixin.d.ts +6 -0
- package/src/modules/duplicate-one/duplicate-one-controller.mixin.js +72 -0
- package/src/modules/duplicate-one/duplicate-one-service.interface.d.ts +5 -0
- package/src/modules/duplicate-one/duplicate-one-service.interface.js +2 -0
- package/src/modules/duplicate-one/duplicate-one.helper.d.ts +7 -0
- package/src/modules/duplicate-one/duplicate-one.helper.js +68 -0
- package/src/modules/duplicate-one/duplicate-one.module.d.ts +6 -0
- package/src/modules/duplicate-one/duplicate-one.module.js +28 -0
- package/src/modules/duplicate-one/index.d.ts +6 -0
- package/src/modules/duplicate-one/index.js +22 -0
- package/src/modules/get-many/base-get-many.service.d.ts +33 -0
- package/src/modules/get-many/base-get-many.service.js +21 -0
- package/src/modules/get-many/get-many-controller.interface.d.ts +7 -0
- package/src/modules/get-many/get-many-controller.interface.js +2 -0
- package/src/modules/get-many/get-many-controller.mixin.d.ts +6 -0
- package/src/modules/get-many/get-many-controller.mixin.js +63 -0
- package/src/modules/get-many/get-many-service.interface.d.ts +5 -0
- package/src/modules/get-many/get-many-service.interface.js +2 -0
- package/src/modules/get-many/get-many.helper.d.ts +7 -0
- package/src/modules/get-many/get-many.helper.js +68 -0
- package/src/modules/get-many/get-many.module.d.ts +6 -0
- package/src/modules/get-many/get-many.module.js +28 -0
- package/src/modules/get-many/index.d.ts +6 -0
- package/src/modules/get-many/index.js +22 -0
- package/src/modules/get-one/base-get-one.service.d.ts +33 -0
- package/src/modules/get-one/base-get-one.service.js +24 -0
- package/src/modules/get-one/get-one-controller.interface.d.ts +7 -0
- package/src/modules/get-one/get-one-controller.interface.js +2 -0
- package/src/modules/get-one/get-one-controller.mixin.d.ts +6 -0
- package/src/modules/get-one/get-one-controller.mixin.js +71 -0
- package/src/modules/get-one/get-one-service.interface.d.ts +5 -0
- package/src/modules/get-one/get-one-service.interface.js +2 -0
- package/src/modules/get-one/get-one.helper.d.ts +7 -0
- package/src/modules/get-one/get-one.helper.js +68 -0
- package/src/modules/get-one/get-one.module.d.ts +6 -0
- package/src/modules/get-one/get-one.module.js +28 -0
- package/src/modules/get-one/index.d.ts +6 -0
- package/src/modules/get-one/index.js +22 -0
- package/src/modules/index.d.ts +8 -0
- package/src/modules/index.js +24 -0
- package/src/modules/replace-one/base-replace-one.service.d.ts +33 -0
- package/src/modules/replace-one/base-replace-one.service.js +33 -0
- package/src/modules/replace-one/index.d.ts +6 -0
- package/src/modules/replace-one/index.js +22 -0
- package/src/modules/replace-one/replace-one-controller.interface.d.ts +7 -0
- package/src/modules/replace-one/replace-one-controller.interface.js +2 -0
- package/src/modules/replace-one/replace-one-controller.mixin.d.ts +6 -0
- package/src/modules/replace-one/replace-one-controller.mixin.js +72 -0
- package/src/modules/replace-one/replace-one-service.interface.d.ts +5 -0
- package/src/modules/replace-one/replace-one-service.interface.js +2 -0
- package/src/modules/replace-one/replace-one.helper.d.ts +7 -0
- package/src/modules/replace-one/replace-one.helper.js +68 -0
- package/src/modules/replace-one/replace-one.module.d.ts +6 -0
- package/src/modules/replace-one/replace-one.module.js +28 -0
- package/src/modules/update-one/base-update-one.service.d.ts +33 -0
- package/src/modules/update-one/base-update-one.service.js +30 -0
- package/src/modules/update-one/index.d.ts +6 -0
- package/src/modules/update-one/index.js +22 -0
- package/src/modules/update-one/update-one-controller.interface.d.ts +7 -0
- package/src/modules/update-one/update-one-controller.interface.js +2 -0
- package/src/modules/update-one/update-one-controller.mixin.d.ts +6 -0
- package/src/modules/update-one/update-one-controller.mixin.js +72 -0
- package/src/modules/update-one/update-one-service.interface.d.ts +5 -0
- package/src/modules/update-one/update-one-service.interface.js +2 -0
- package/src/modules/update-one/update-one.helper.d.ts +7 -0
- package/src/modules/update-one/update-one.helper.js +68 -0
- package/src/modules/update-one/update-one.module.d.ts +6 -0
- package/src/modules/update-one/update-one.module.js +28 -0
- package/src/services/base.service.d.ts +36 -0
- package/src/services/base.service.js +33 -0
- package/src/services/index.d.ts +1 -0
- package/src/services/index.js +17 -0
- package/src/version.json +3 -0
- package/tsconfig.tsbuildinfo +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Changelog
|
|
2
|
+
|
|
3
|
+
## 1.1.0 (2024-03-03)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
* activate schema timestamps ([ee2e8e4](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/ee2e8e4442bd692b2fe1566687b98f421bc9f9f6))
|
|
7
|
+
* rename mixin dtos ([7a0fc65](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/7a0fc6540a4d93000c735744786469204a734ce4))
|
|
8
|
+
* rework validation options ([3cb0b56](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/3cb0b56a81e7016f1dc03c0f46ec1714ad57eff2))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### api
|
|
12
|
+
|
|
13
|
+
* **api:** add the possibility to enable the api uri versioning ([0f52917](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/0f529174ea583078bb136d2db484ef64b6aa6e49))
|
|
14
|
+
* **api:** correct CreateMany response type and body ([804b7d5](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/804b7d55fe2b8b515436b41fa338be75c5e030e2))
|
|
15
|
+
* **api:** make routes optional, add all routes automatically if not configured ([f17e2eb](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/f17e2ebdbbde8f05a5c80c404ffc1febf460bc20))
|
|
16
|
+
* **api:** set duplicate one body optional ([f24b2b9](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/f24b2b964e251fbb92acfc14222386fec3239dcb))
|
|
17
|
+
* **api:** add create-many module ([9ae72d5](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/9ae72d5dd7bda27423f96dd642d41eff31e75370))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### swagger
|
|
21
|
+
|
|
22
|
+
* **swagger:** add enable method ([5f3f865](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/5f3f8656dc186e833d5c4792efacf9f0a2005afd))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## 1.0.0 (2024-02-27)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* add mongodb dynamic api files ([33dfc14](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/33dfc143d34e31c802a5d1adb5e8d99ad5aadc6f))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Mickaël Nodanche
|
|
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,190 @@
|
|
|
1
|
+
<div style="text-align: center; width: 100%;">
|
|
2
|
+
<div style="display: inline-block">
|
|
3
|
+
|
|
4
|
+
[](https://www.npmjs.com/package/mongodb-dynamic-api)
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
</div>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<div style="text-align: center; width: 100%;">
|
|
11
|
+
<div style="display: inline-block">
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
[](https://app.circleci.com/pipelines/github/MikeDev75015/mongodb-dynamic-api)
|
|
15
|
+

|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div style="text-align: center; width: 100%;">
|
|
20
|
+
<div style="display: inline-block">
|
|
21
|
+
|
|
22
|
+

|
|
23
|
+

|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
<div style="text-align: center; width: 100%;">
|
|
28
|
+
<div style="display: inline-block">
|
|
29
|
+
|
|
30
|
+
[](https://sonarcloud.io/dashboard?id=MikeDev75015_mongodb-dynamic-api)
|
|
31
|
+
[](https://sonarcloud.io/dashboard?id=MikeDev75015_mongodb-dynamic-api)
|
|
32
|
+
[](https://sonarcloud.io/dashboard?id=MikeDev75015_mongodb-dynamic-api)
|
|
33
|
+
[](https://sonarcloud.io/dashboard?id=MikeDev75015_mongodb-dynamic-api)
|
|
34
|
+
[](https://sonarcloud.io/dashboard?id=MikeDev75015_mongodb-dynamic-api)
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<div style="text-align: center; width: 100%;">
|
|
39
|
+
<div style="display: inline-block">
|
|
40
|
+
|
|
41
|
+

|
|
42
|
+

|
|
43
|
+

|
|
44
|
+

|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
<div style="text-align: center; width: 100%;">
|
|
51
|
+
|
|
52
|
+
# mongodb-dynamic-api
|
|
53
|
+
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
<p style="text-align: justify; width: 100%;font-size: 15px;">
|
|
58
|
+
|
|
59
|
+
**mongodb-dynamic-api** is an auto generated CRUD API for MongoDB using NestJS 10.
|
|
60
|
+
|
|
61
|
+
</p>
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## npm package <img src="https://pbs.twimg.com/media/EDoWJbUXYAArclg.png" width="24" height="24" />
|
|
66
|
+
```text
|
|
67
|
+
npm install --save mongodb-dynamic-api
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
### HOW TO ENJOY IT
|
|
73
|
+
|
|
74
|
+
- Start a new [nest](https://docs.nestjs.com/) project with **typescript** (use the `--strict` option)
|
|
75
|
+
```text
|
|
76
|
+
nest new --strict your-project-name
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
- Go to your project root and install the [mongodb-dynamic-api](https://www.npmjs.com/package/mongodb-dynamic-api) package
|
|
80
|
+
```text
|
|
81
|
+
npm i -S mongodb-dynamic-api
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- Add DynamicApiModule to your app.module.ts and pass the MongoDB connection string to the `forRoot` method
|
|
85
|
+
```typescript
|
|
86
|
+
@Module({
|
|
87
|
+
imports: [
|
|
88
|
+
// ...
|
|
89
|
+
DynamicApiModule.forRoot(
|
|
90
|
+
// <- pass the MongoDB connection string here
|
|
91
|
+
),
|
|
92
|
+
// ...
|
|
93
|
+
],
|
|
94
|
+
controllers: [AppController],
|
|
95
|
+
providers: [AppService],
|
|
96
|
+
})
|
|
97
|
+
export class AppModule {}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
- Ok, now let's add our first content. This content will be a simple `User` with a `name` and an `email` field.
|
|
101
|
+
```typescript
|
|
102
|
+
// user.ts
|
|
103
|
+
@Schema({ collection: 'users' })
|
|
104
|
+
export class User extends BaseEntity { // <- you must extend BaseEntity
|
|
105
|
+
@Prop({ type: String })
|
|
106
|
+
name: string;
|
|
107
|
+
|
|
108
|
+
@Prop({ type: String })
|
|
109
|
+
email: string;
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
```typescript
|
|
113
|
+
// users.module.ts
|
|
114
|
+
@Module({
|
|
115
|
+
imports: [
|
|
116
|
+
DynamicApiModule.forFeature({ // <- use the forFeature method to add the User content
|
|
117
|
+
entity: User,
|
|
118
|
+
controllerOptions: {
|
|
119
|
+
path: 'users',
|
|
120
|
+
},
|
|
121
|
+
}),
|
|
122
|
+
],
|
|
123
|
+
})
|
|
124
|
+
export class UsersModule {}
|
|
125
|
+
```
|
|
126
|
+
```typescript
|
|
127
|
+
// app.module.ts
|
|
128
|
+
@Module({
|
|
129
|
+
imports: [
|
|
130
|
+
// ...
|
|
131
|
+
DynamicApiModule.forRoot('...'),
|
|
132
|
+
UsersModule, // <- add the module to the imports after the DynamicApiModule
|
|
133
|
+
],
|
|
134
|
+
controllers: [AppController],
|
|
135
|
+
providers: [AppService],
|
|
136
|
+
})
|
|
137
|
+
export class AppModule {}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**That's all !** *You now have a fully functional CRUD API for the `User` content at the `/users` path.*
|
|
141
|
+
|
|
142
|
+
___
|
|
143
|
+
### [Swagger]() (optional but recommended)
|
|
144
|
+
```typescript
|
|
145
|
+
async function bootstrap() {
|
|
146
|
+
const app = await NestFactory.create(AppModule);
|
|
147
|
+
// ...
|
|
148
|
+
enableDynamicAPISwagger(app); // <- add this line in your main.ts file
|
|
149
|
+
|
|
150
|
+
await app.listen(3000);
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
The `enableDynamicAPISwagger` function will automatically build the swagger documentation.
|
|
154
|
+
This method can be called with optional parameters to specify more documentation options.
|
|
155
|
+
|
|
156
|
+
Do not forget to add the `@ApiProperty` decorator to your entity properties to have a better swagger documentation.
|
|
157
|
+
```typescript
|
|
158
|
+
// user.ts
|
|
159
|
+
@Schema({ collection: 'users' })
|
|
160
|
+
export class User extends BaseEntity {
|
|
161
|
+
@ApiProperty() // <- add this line
|
|
162
|
+
@Prop({ type: String })
|
|
163
|
+
name: string;
|
|
164
|
+
|
|
165
|
+
@ApiProperty() // <- add this line
|
|
166
|
+
@Prop({ type: String })
|
|
167
|
+
email: string;
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
go to the swagger API path (default to `/openapi`) and you will see the auto generated API
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+

|
|
175
|
+
|
|
176
|
+
[more screenshots](https://github.com/MikeDev75015/mongodb-dynamic-api/blob/develop/README/swagger.md)
|
|
177
|
+
|
|
178
|
+
___
|
|
179
|
+
### Versioning (optional)
|
|
180
|
+
```typescript
|
|
181
|
+
async function bootstrap() {
|
|
182
|
+
const app = await NestFactory.create(AppModule);
|
|
183
|
+
// ...
|
|
184
|
+
enableDynamicAPIVersioning(app); // <- add this line in your main.ts file
|
|
185
|
+
|
|
186
|
+
await app.listen(3000);
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
The `enableDynamicAPIVersioning` function will automatically add versioning to the API. By default it will use the URI versioning type.
|
|
190
|
+
This method can be called with a second optional parameter to specify more options.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src';
|
package/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
__exportStar(require("./src"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mongodb-dynamic-api",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Auto generated CRUD API for MongoDB using NestJS",
|
|
5
|
+
"readmeFilename": "README.md",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"prepare": "npm run build",
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
12
|
+
"lint": "tslint -p tsconfig.json -c tslint.json",
|
|
13
|
+
"test": "jest --runInBand",
|
|
14
|
+
"test-cov": "jest --runInBand --coverage",
|
|
15
|
+
"test:ci:junit": "jest --ci --runInBand --coverage --testResultsProcessor=jest-junit",
|
|
16
|
+
"test:ci:sonar": "jest --ci --runInBand --coverage --testResultsProcessor=jest-sonar-reporter",
|
|
17
|
+
"pre-release-tag": "git tag -f prerelease && git push -f origin prerelease",
|
|
18
|
+
"release-tag": "git tag -f release && git push -f origin release",
|
|
19
|
+
"auto-prerelease": "release-it --ci --preRelease=beta --no-git.requireUpstream --no-git.tag",
|
|
20
|
+
"auto-release": "release-it --ci --no-git.requireUpstream --no-git.tag",
|
|
21
|
+
"publish-prerelease": "npm publish ./dist --tag prerelease",
|
|
22
|
+
"publish-release": "npm publish ./dist --tag latest"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/MikeDev75015/mongodb-dynamic-api.git"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"nestjs",
|
|
30
|
+
"mongodb",
|
|
31
|
+
"dynamic-api",
|
|
32
|
+
"crud"
|
|
33
|
+
],
|
|
34
|
+
"author": "Mickaël NODANCHE <mikeonline75@gmail.com> (https://cv-mikeonline.web.app)",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/MikeDev75015/mongodb-dynamic-api/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://mikedev75015.github.io",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@nestjs/common": "^10.3.2",
|
|
42
|
+
"@nestjs/core": "^10.3.2",
|
|
43
|
+
"@nestjs/mongoose": "^10.0.4",
|
|
44
|
+
"@nestjs/platform-express": "^10.3.2",
|
|
45
|
+
"@nestjs/swagger": "^7.3.0",
|
|
46
|
+
"@types/lodash": "^4.14.202",
|
|
47
|
+
"builder-pattern": "^2.2.0",
|
|
48
|
+
"class-transformer": "^0.5.1",
|
|
49
|
+
"class-validator": "^0.14.1",
|
|
50
|
+
"lodash": "^4.17.21",
|
|
51
|
+
"mongoose": "^8.1.1",
|
|
52
|
+
"reflect-metadata": "^0.2.1",
|
|
53
|
+
"rxjs": "^7.8.1"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@golevelup/ts-jest": "^0.4.0",
|
|
57
|
+
"@nestjs/cli": "^10.3.1",
|
|
58
|
+
"@nestjs/schematics": "^10.1.0",
|
|
59
|
+
"@nestjs/testing": "^10.3.2",
|
|
60
|
+
"@release-it/bumper": "^6.0.1",
|
|
61
|
+
"@release-it/conventional-changelog": "^8.0.1",
|
|
62
|
+
"@swc/cli": "^0.3.9",
|
|
63
|
+
"@swc/core": "^1.4.0",
|
|
64
|
+
"@types/express": "^4.17.21",
|
|
65
|
+
"@types/jest": "^29.5.12",
|
|
66
|
+
"@types/node": "^20.11.16",
|
|
67
|
+
"@types/supertest": "^6.0.2",
|
|
68
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
69
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
70
|
+
"eslint": "^8.56.0",
|
|
71
|
+
"eslint-config-prettier": "^9.1.0",
|
|
72
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
73
|
+
"jest": "^29.7.0",
|
|
74
|
+
"jest-junit": "^16.0.0",
|
|
75
|
+
"jest-sonar-reporter": "^2.0.0",
|
|
76
|
+
"prettier": "^3.2.5",
|
|
77
|
+
"release-it": "^17.1.1",
|
|
78
|
+
"source-map-support": "^0.5.21",
|
|
79
|
+
"supertest": "^6.3.4",
|
|
80
|
+
"ts-jest": "^29.1.2",
|
|
81
|
+
"ts-loader": "^9.5.1",
|
|
82
|
+
"ts-node": "^10.9.2",
|
|
83
|
+
"tsconfig-paths": "^4.2.0",
|
|
84
|
+
"typescript": "^5.3.3"
|
|
85
|
+
},
|
|
86
|
+
"jest": {
|
|
87
|
+
"moduleFileExtensions": [
|
|
88
|
+
"js",
|
|
89
|
+
"json",
|
|
90
|
+
"ts"
|
|
91
|
+
],
|
|
92
|
+
"rootDir": "libs",
|
|
93
|
+
"testRegex": ".*\\.spec\\.ts$",
|
|
94
|
+
"transform": {
|
|
95
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
96
|
+
},
|
|
97
|
+
"collectCoverageFrom": [
|
|
98
|
+
"./**/*.ts"
|
|
99
|
+
],
|
|
100
|
+
"coverageDirectory": "../coverage",
|
|
101
|
+
"testEnvironment": "node",
|
|
102
|
+
"roots": [
|
|
103
|
+
"<rootDir>/"
|
|
104
|
+
],
|
|
105
|
+
"coveragePathIgnorePatterns": [
|
|
106
|
+
"index.ts",
|
|
107
|
+
".*\\.mock\\.ts"
|
|
108
|
+
],
|
|
109
|
+
"reporters": [
|
|
110
|
+
"default"
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
"jestSonar": {
|
|
114
|
+
"reportPath": "reports/sonar"
|
|
115
|
+
},
|
|
116
|
+
"publishConfig": {
|
|
117
|
+
"access": "public"
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './route-decorators.builder';
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
__exportStar(require("./route-decorators.builder"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
import { RouteType } from '../interfaces';
|
|
3
|
+
import { BaseEntity } from '../models';
|
|
4
|
+
declare class RouteDecoratorsBuilder<Entity extends BaseEntity> {
|
|
5
|
+
private readonly routeType;
|
|
6
|
+
private readonly entity;
|
|
7
|
+
private readonly description?;
|
|
8
|
+
private readonly param?;
|
|
9
|
+
private readonly query?;
|
|
10
|
+
private readonly body?;
|
|
11
|
+
private readonly presenter?;
|
|
12
|
+
private readonly responseRouteTypeIsArray;
|
|
13
|
+
constructor(routeType: RouteType, entity: Type<Entity>, description?: string, param?: Type, query?: Type, body?: Type, presenter?: Type);
|
|
14
|
+
build(): MethodDecorator[];
|
|
15
|
+
private getRouteDecorators;
|
|
16
|
+
private getApiDecorators;
|
|
17
|
+
}
|
|
18
|
+
export { RouteDecoratorsBuilder };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouteDecoratorsBuilder = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
class RouteDecoratorsBuilder {
|
|
8
|
+
constructor(routeType, entity, description, param, query, body, presenter) {
|
|
9
|
+
this.routeType = routeType;
|
|
10
|
+
this.entity = entity;
|
|
11
|
+
this.description = description;
|
|
12
|
+
this.param = param;
|
|
13
|
+
this.query = query;
|
|
14
|
+
this.body = body;
|
|
15
|
+
this.presenter = presenter;
|
|
16
|
+
this.responseRouteTypeIsArray = [
|
|
17
|
+
'GetMany',
|
|
18
|
+
'CreateMany',
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
build() {
|
|
22
|
+
const [paramKey] = this.param ? (0, lodash_1.keys)(new this.param()) : [];
|
|
23
|
+
return [
|
|
24
|
+
...this.getRouteDecorators(paramKey),
|
|
25
|
+
...this.getApiDecorators(paramKey),
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
getRouteDecorators(paramKey) {
|
|
29
|
+
switch (this.routeType) {
|
|
30
|
+
case 'GetMany':
|
|
31
|
+
return [(0, common_1.Get)()];
|
|
32
|
+
case 'GetOne':
|
|
33
|
+
return [(0, common_1.Get)(`:${paramKey}`)];
|
|
34
|
+
case 'CreateMany':
|
|
35
|
+
return [(0, common_1.Post)('many')];
|
|
36
|
+
case 'CreateOne':
|
|
37
|
+
return [(0, common_1.Post)()];
|
|
38
|
+
case 'UpdateOne':
|
|
39
|
+
return [(0, common_1.Patch)(`:${paramKey}`)];
|
|
40
|
+
case 'ReplaceOne':
|
|
41
|
+
return [(0, common_1.Put)(`:${paramKey}`)];
|
|
42
|
+
case 'DuplicateOne':
|
|
43
|
+
return [(0, common_1.Post)(`:${paramKey}`)];
|
|
44
|
+
case 'DeleteOne':
|
|
45
|
+
return [(0, common_1.Delete)(`:${paramKey}`)];
|
|
46
|
+
default:
|
|
47
|
+
throw new Error(`Unexpected route type! Cannot build route decorators. Received: ${this.routeType}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
getApiDecorators(paramKey) {
|
|
51
|
+
return [
|
|
52
|
+
(0, swagger_1.ApiOperation)({
|
|
53
|
+
operationId: `${(0, lodash_1.lowerFirst)(this.routeType)}${this.entity.name}`,
|
|
54
|
+
summary: this.description ??
|
|
55
|
+
`${(0, lodash_1.upperFirst)((0, lodash_1.lowerCase)(this.routeType))} ${(0, lodash_1.lowerCase)(this.entity.name)}`,
|
|
56
|
+
}),
|
|
57
|
+
(0, swagger_1.ApiResponse)({
|
|
58
|
+
type: this.presenter ?? this.entity,
|
|
59
|
+
isArray: this.responseRouteTypeIsArray.includes(this.routeType),
|
|
60
|
+
}),
|
|
61
|
+
...(this.body ? [(0, swagger_1.ApiBody)({
|
|
62
|
+
type: this.body,
|
|
63
|
+
...(this.routeType === 'DuplicateOne' ? { required: false } : {})
|
|
64
|
+
})] : []),
|
|
65
|
+
...(this.param && paramKey
|
|
66
|
+
? [
|
|
67
|
+
(0, swagger_1.ApiParam)({
|
|
68
|
+
type: typeof new this.param()[paramKey],
|
|
69
|
+
name: paramKey,
|
|
70
|
+
}),
|
|
71
|
+
]
|
|
72
|
+
: []),
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.RouteDecoratorsBuilder = RouteDecoratorsBuilder;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './schema-options.decorator';
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
__exportStar(require("./schema-options.decorator"), exports);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { DynamicAPISchemaOptionsInterface } from '../interfaces';
|
|
2
|
+
declare const DYNAMIC_API_SCHEMA_OPTIONS_METADATA = "dynamic-api-module:schema-options";
|
|
3
|
+
declare function DynamicAPISchemaOptions(options: DynamicAPISchemaOptionsInterface): ClassDecorator;
|
|
4
|
+
export { DYNAMIC_API_SCHEMA_OPTIONS_METADATA, DynamicAPISchemaOptions };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamicAPISchemaOptions = exports.DYNAMIC_API_SCHEMA_OPTIONS_METADATA = void 0;
|
|
4
|
+
const DYNAMIC_API_SCHEMA_OPTIONS_METADATA = 'dynamic-api-module:schema-options';
|
|
5
|
+
exports.DYNAMIC_API_SCHEMA_OPTIONS_METADATA = DYNAMIC_API_SCHEMA_OPTIONS_METADATA;
|
|
6
|
+
function DynamicAPISchemaOptions(options) {
|
|
7
|
+
return (target) => {
|
|
8
|
+
Reflect.defineMetadata(DYNAMIC_API_SCHEMA_OPTIONS_METADATA, options, target);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
exports.DynamicAPISchemaOptions = DynamicAPISchemaOptions;
|
|
@@ -0,0 +1,26 @@
|
|
|
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.EntityParam = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
const class_validator_1 = require("class-validator");
|
|
15
|
+
class EntityParam {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.id = '';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.EntityParam = EntityParam;
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, swagger_1.ApiProperty)(),
|
|
23
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
24
|
+
(0, class_validator_1.IsString)(),
|
|
25
|
+
__metadata("design:type", Object)
|
|
26
|
+
], EntityParam.prototype, "id", void 0);
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
__exportStar(require("./entity.param"), exports);
|
|
18
|
+
__exportStar(require("./entity.query"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { DynamicApiOptions } from './interfaces';
|
|
3
|
+
import { BaseEntity } from './models';
|
|
4
|
+
export declare class DynamicApiModule {
|
|
5
|
+
static readonly connectionName = "dynamic-api-connection";
|
|
6
|
+
static forRoot(uri: string): DynamicModule;
|
|
7
|
+
static forFeature<Entity extends BaseEntity>({ entity, controllerOptions: { path, apiTag, version: controllerVersion, validationPipeOptions: controllerValidationPipeOptions, }, routes, }: DynamicApiOptions<Entity>): DynamicModule;
|
|
8
|
+
}
|