mongodb-dynamic-api 1.4.3 → 2.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/CHANGELOG.md +17 -0
- package/README.md +7 -2
- package/package.json +1 -1
- package/src/builders/route-decorators/auth-decorators.builder.d.ts +2 -2
- package/src/builders/route-decorators/route-decorators.builder.d.ts +2 -2
- package/src/dynamic-api.module.js +5 -6
- package/src/helpers/controller-ability-predicates.helper.d.ts +2 -2
- package/src/helpers/controller-ability-predicates.helper.js +1 -6
- package/src/helpers/route-decorators.helper.d.ts +2 -2
- package/src/helpers/schema.helper.js +7 -2
- package/src/interfaces/dynamic-api-casl-ability.interface.d.ts +4 -12
- package/src/interfaces/dynamic-api-casl-ability.interface.js +0 -9
- package/src/interfaces/dynamic-api-controller-options.interface.d.ts +12 -0
- package/src/interfaces/dynamic-api-decorator-builder.interface.d.ts +5 -0
- package/src/interfaces/dynamic-api-options.interface.d.ts +4 -4
- package/src/interfaces/dynamic-api-schema-options.interface.d.ts +7 -1
- package/src/interfaces/dynamic-api-schema-options.interface.js +14 -0
- package/src/interfaces/index.d.ts +2 -3
- package/src/interfaces/index.js +2 -3
- package/src/mixins/entity-presenter.mixin.d.ts +1 -1
- package/src/mixins/entity-presenter.mixin.js +12 -2
- package/src/models/base-entity.model.d.ts +1 -1
- package/src/modules/auth/auth.helper.d.ts +4 -4
- package/src/modules/auth/auth.helper.js +3 -3
- package/src/modules/auth/auth.module.d.ts +2 -2
- package/src/modules/auth/auth.module.js +3 -3
- package/src/modules/auth/interfaces/auth-options.interface.d.ts +12 -9
- package/src/modules/auth/mixins/auth-controller.mixin.d.ts +2 -3
- package/src/modules/auth/mixins/auth-controller.mixin.js +21 -4
- package/src/modules/auth/mixins/auth-register-policies-guard.mixin.d.ts +2 -2
- package/src/routes/create-many/create-many-controller.mixin.d.ts +2 -2
- package/src/routes/create-many/create-many.helper.d.ts +2 -2
- package/src/routes/create-many/create-many.module.d.ts +2 -2
- package/src/routes/create-one/create-one-controller.mixin.d.ts +2 -2
- package/src/routes/create-one/create-one.helper.d.ts +2 -2
- package/src/routes/create-one/create-one.module.d.ts +2 -2
- package/src/routes/delete-many/delete-many-controller.mixin.d.ts +2 -2
- package/src/routes/delete-many/delete-many.helper.d.ts +2 -2
- package/src/routes/delete-many/delete-many.module.d.ts +2 -2
- package/src/routes/delete-one/delete-one-controller.mixin.d.ts +2 -2
- package/src/routes/delete-one/delete-one.helper.d.ts +2 -2
- package/src/routes/delete-one/delete-one.module.d.ts +2 -2
- package/src/routes/duplicate-many/duplicate-many-controller.mixin.d.ts +2 -2
- package/src/routes/duplicate-many/duplicate-many.helper.d.ts +2 -2
- package/src/routes/duplicate-many/duplicate-many.module.d.ts +2 -2
- package/src/routes/duplicate-one/duplicate-one-controller.mixin.d.ts +2 -2
- package/src/routes/duplicate-one/duplicate-one.helper.d.ts +2 -2
- package/src/routes/duplicate-one/duplicate-one.module.d.ts +2 -2
- package/src/routes/get-many/base-get-many.service.js +1 -1
- package/src/routes/get-many/get-many-controller.mixin.d.ts +2 -2
- package/src/routes/get-many/get-many-controller.mixin.js +1 -1
- package/src/routes/get-many/get-many.helper.d.ts +2 -2
- package/src/routes/get-many/get-many.module.d.ts +2 -2
- package/src/routes/get-one/get-one-controller.mixin.d.ts +2 -2
- package/src/routes/get-one/get-one.helper.d.ts +2 -2
- package/src/routes/get-one/get-one.module.d.ts +2 -2
- package/src/routes/replace-one/replace-one-controller.mixin.d.ts +2 -2
- package/src/routes/replace-one/replace-one.helper.d.ts +2 -2
- package/src/routes/replace-one/replace-one.module.d.ts +2 -2
- package/src/routes/update-many/update-many-controller.mixin.d.ts +2 -2
- package/src/routes/update-many/update-many.helper.d.ts +2 -2
- package/src/routes/update-many/update-many.module.d.ts +2 -2
- package/src/routes/update-one/update-one-controller.mixin.d.ts +2 -2
- package/src/routes/update-one/update-one.helper.d.ts +2 -2
- package/src/routes/update-one/update-one.module.d.ts +2 -2
- package/src/version.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/src/interfaces/controller-options.interface.d.ts +0 -12
- package/src/interfaces/decorator-builder.interface.d.ts +0 -5
- package/src/interfaces/maybe-promise.type.d.ts +0 -2
- package/src/interfaces/maybe-promise.type.js +0 -2
- /package/src/interfaces/{controller-options.interface.js → dynamic-api-controller-options.interface.js} +0 -0
- /package/src/interfaces/{decorator-builder.interface.js → dynamic-api-decorator-builder.interface.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
|
|
3
|
+
## [2.0.0](https://github.com/MikeDev75015/mongodb-dynamic-api/compare/v1.4.3...v2.0.0) (2024-03-18)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### ⚠ BREAKING CHANGES
|
|
7
|
+
|
|
8
|
+
* **schema-options:** bind event type to route type to improve understanding
|
|
9
|
+
* **authentication:** rework options
|
|
10
|
+
|
|
11
|
+
### schema-options
|
|
12
|
+
|
|
13
|
+
* **schema-options:** bind event type to route type to improve understanding ([8a6a391](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/8a6a391c19a68697998ed6508d88ed63c1fbde7d))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### authentication
|
|
17
|
+
|
|
18
|
+
* **authentication:** rework options ([e833898](https://github.com/MikeDev75015/mongodb-dynamic-api/commit/e833898903279e1e1e220b065724e013b1729029))
|
|
19
|
+
|
|
3
20
|
## [1.4.3](https://github.com/MikeDev75015/mongodb-dynamic-api/compare/v1.4.2...v1.4.3) (2024-03-15)
|
|
4
21
|
|
|
5
22
|
## [1.4.2](https://github.com/MikeDev75015/mongodb-dynamic-api/compare/v1.4.1...v1.4.2) (2024-03-15)
|
package/README.md
CHANGED
|
@@ -113,8 +113,13 @@ export class AppModule {}
|
|
|
113
113
|
- Ok, now let's add our first content with just 2 files. It will be a simple `User` with a `name` and an `email` field.
|
|
114
114
|
- We use the `@Schema` and `@Prop` decorators from the <a href="https://docs.nestjs.com/techniques/mongodb#model-injection" target="_blank">@nestjs/mongoose</a> package to define our MongoDB model.
|
|
115
115
|
|
|
116
|
-
- You must extend the `BaseEntity` class from the `mongodb-dynamic-api` package **for all your collection models**.
|
|
117
|
-
|
|
116
|
+
- You must extend the `BaseEntity` | `SoftDeletableEntity` class from the `mongodb-dynamic-api` package **for all your collection models**.
|
|
117
|
+
**See more details [here](https://github.com/MikeDev75015/mongodb-dynamic-api/blob/develop/README/entities.md)**.
|
|
118
|
+
|
|
119
|
+
- You can also add the `@DynamicAPISchemaOptions` decorator to pass schema options.
|
|
120
|
+
**See more details [here](https://github.com/MikeDev75015/mongodb-dynamic-api/blob/develop/README/schema-options.md)**.
|
|
121
|
+
|
|
122
|
+
Just create a new file `user.ts` and add the following code.
|
|
118
123
|
|
|
119
124
|
```typescript
|
|
120
125
|
// src/users/user.ts
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare class AuthDecoratorsBuilder implements
|
|
1
|
+
import { DynamicApiDecoratorBuilder } from '../../interfaces';
|
|
2
|
+
declare class AuthDecoratorsBuilder implements DynamicApiDecoratorBuilder<any> {
|
|
3
3
|
private readonly protectRegister;
|
|
4
4
|
constructor(protectRegister: boolean | undefined);
|
|
5
5
|
build(): (ClassDecorator & MethodDecorator)[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Type } from '@nestjs/common';
|
|
2
|
-
import {
|
|
2
|
+
import { DynamicApiDecoratorBuilder, RouteType } from '../../interfaces';
|
|
3
3
|
import { BaseEntity } from '../../models';
|
|
4
|
-
declare class RouteDecoratorsBuilder<Entity extends BaseEntity> implements
|
|
4
|
+
declare class RouteDecoratorsBuilder<Entity extends BaseEntity> implements DynamicApiDecoratorBuilder<Entity> {
|
|
5
5
|
private readonly routeType;
|
|
6
6
|
private readonly entity;
|
|
7
7
|
private readonly version;
|
|
@@ -53,17 +53,16 @@ let DynamicApiModule = DynamicApiModule_1 = class DynamicApiModule {
|
|
|
53
53
|
entity: useAuth.user.entity,
|
|
54
54
|
loginField: useAuth.user.loginField ?? 'email',
|
|
55
55
|
passwordField: useAuth.user.passwordField ?? 'password',
|
|
56
|
-
|
|
57
|
-
toRegister: [],
|
|
58
|
-
toRequest: [],
|
|
59
|
-
},
|
|
56
|
+
requestAdditionalFields: useAuth.user.requestAdditionalFields ?? [],
|
|
60
57
|
},
|
|
61
58
|
jwt: {
|
|
62
59
|
secret: useAuth.jwt?.secret ?? 'dynamic-api-jwt-secret',
|
|
63
60
|
expiresIn: useAuth.jwt?.expiresIn ?? '1d',
|
|
64
61
|
},
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
register: useAuth.register ?? {
|
|
63
|
+
protected: false,
|
|
64
|
+
additionalFields: [],
|
|
65
|
+
},
|
|
67
66
|
}),
|
|
68
67
|
] : []),
|
|
69
68
|
],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DynamicApiControllerAbilityPredicate, DynamicApiRouteCaslAbilityPredicate, RouteType } from '../interfaces';
|
|
2
2
|
import { BaseEntity } from '../models';
|
|
3
|
-
declare function getPredicateFromControllerAbilityPredicates<Entity extends BaseEntity>(controllerAbilityPredicates:
|
|
3
|
+
declare function getPredicateFromControllerAbilityPredicates<Entity extends BaseEntity>(controllerAbilityPredicates: DynamicApiControllerAbilityPredicate<Entity>[], route: RouteType): DynamicApiRouteCaslAbilityPredicate<Entity>;
|
|
4
4
|
export { getPredicateFromControllerAbilityPredicates };
|
|
@@ -8,15 +8,10 @@ function getPredicateFromControllerAbilityPredicates(controllerAbilityPredicates
|
|
|
8
8
|
}
|
|
9
9
|
for (const controllerAbilityPredicate of controllerAbilityPredicates) {
|
|
10
10
|
const { targets, predicate } = controllerAbilityPredicate;
|
|
11
|
-
if (
|
|
11
|
+
if (targets.includes(route)) {
|
|
12
12
|
routePredicate = predicate;
|
|
13
13
|
break;
|
|
14
14
|
}
|
|
15
|
-
targets.forEach((routes) => {
|
|
16
|
-
if (routes.includes(route) && !routePredicate) {
|
|
17
|
-
routePredicate = predicate;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
15
|
}
|
|
21
16
|
return routePredicate;
|
|
22
17
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DynamicApiDecoratorBuilder } from '../interfaces';
|
|
2
2
|
import { BaseEntity } from '../models';
|
|
3
|
-
declare function RouteDecoratorsHelper<Entity extends BaseEntity>(routeDecorators:
|
|
3
|
+
declare function RouteDecoratorsHelper<Entity extends BaseEntity>(routeDecorators: DynamicApiDecoratorBuilder<Entity>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
4
4
|
export { RouteDecoratorsHelper };
|
|
@@ -3,18 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.buildSchemaFromEntity = void 0;
|
|
4
4
|
const mongoose_1 = require("@nestjs/mongoose");
|
|
5
5
|
const decorators_1 = require("../decorators");
|
|
6
|
+
const interfaces_1 = require("../interfaces");
|
|
6
7
|
function buildSchemaFromEntity(entity) {
|
|
7
8
|
const { indexes, hooks } = Reflect.getOwnMetadata(decorators_1.DYNAMIC_API_SCHEMA_OPTIONS_METADATA, entity) ?? {};
|
|
8
9
|
const schema = mongoose_1.SchemaFactory.createForClass(entity);
|
|
9
|
-
schema.
|
|
10
|
+
if (Object.getOwnPropertyNames(schema.paths).includes('createdAt')) {
|
|
11
|
+
schema.set('timestamps', true);
|
|
12
|
+
}
|
|
10
13
|
if (indexes) {
|
|
11
14
|
indexes.forEach(({ fields, options }) => {
|
|
12
15
|
schema.index(fields, options);
|
|
13
16
|
});
|
|
14
17
|
}
|
|
15
18
|
if (hooks?.length) {
|
|
19
|
+
const isSoftDeletable = Object.getOwnPropertyNames(schema.paths).includes('deletedAt');
|
|
16
20
|
hooks.forEach(({ type, method, callback, options }) => {
|
|
17
|
-
|
|
21
|
+
const { query, softDeletableQuery } = interfaces_1.queryByRouteTypeMap.get(type);
|
|
22
|
+
schema[method](isSoftDeletable && softDeletableQuery ? softDeletableQuery : query, { document: true, query: true, ...options }, callback);
|
|
18
23
|
});
|
|
19
24
|
}
|
|
20
25
|
return schema;
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
import { BaseEntity } from '../models';
|
|
2
2
|
import { RouteType } from './dynamic-api-route-type.type';
|
|
3
|
-
declare enum CaslAction {
|
|
4
|
-
Manage = "manage",
|
|
5
|
-
Create = "create",
|
|
6
|
-
Read = "read",
|
|
7
|
-
Update = "update",
|
|
8
|
-
Delete = "delete"
|
|
9
|
-
}
|
|
10
|
-
type DynamicApiCaslActionRoutesMap = Map<CaslAction, RouteType[]>;
|
|
11
3
|
type DynamicApiRouteCaslAbilityPredicate<Entity extends BaseEntity, T = any> = (entity: Entity, user?: T) => boolean;
|
|
12
|
-
type
|
|
13
|
-
type
|
|
14
|
-
targets: RouteType[]
|
|
4
|
+
type DynamicApiRegisterAbilityPredicate<T = any> = (user?: T) => boolean;
|
|
5
|
+
type DynamicApiControllerAbilityPredicate<Entity extends BaseEntity> = {
|
|
6
|
+
targets: RouteType[];
|
|
15
7
|
predicate: DynamicApiRouteCaslAbilityPredicate<Entity>;
|
|
16
8
|
};
|
|
17
|
-
export {
|
|
9
|
+
export { DynamicApiRouteCaslAbilityPredicate, DynamicApiRegisterAbilityPredicate, DynamicApiControllerAbilityPredicate, };
|
|
@@ -1,11 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CaslAction = void 0;
|
|
4
|
-
var CaslAction;
|
|
5
|
-
(function (CaslAction) {
|
|
6
|
-
CaslAction["Manage"] = "manage";
|
|
7
|
-
CaslAction["Create"] = "create";
|
|
8
|
-
CaslAction["Read"] = "read";
|
|
9
|
-
CaslAction["Update"] = "update";
|
|
10
|
-
CaslAction["Delete"] = "delete";
|
|
11
|
-
})(CaslAction || (exports.CaslAction = CaslAction = {}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ValidationPipeOptions } from '@nestjs/common';
|
|
2
|
+
import { BaseEntity } from '../models';
|
|
3
|
+
import { DynamicApiControllerAbilityPredicate } from './dynamic-api-casl-ability.interface';
|
|
4
|
+
interface DynamicApiControllerOptions<Entity extends BaseEntity> {
|
|
5
|
+
path: string;
|
|
6
|
+
apiTag?: string;
|
|
7
|
+
version?: string;
|
|
8
|
+
isPublic?: boolean;
|
|
9
|
+
validationPipeOptions?: ValidationPipeOptions;
|
|
10
|
+
abilityPredicates?: DynamicApiControllerAbilityPredicate<Entity>[];
|
|
11
|
+
}
|
|
12
|
+
export { DynamicApiControllerOptions };
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Type } from '@nestjs/common';
|
|
2
2
|
import { BaseEntity } from '../models';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { DynamicApiAuthOptions } from '../modules';
|
|
4
|
+
import { DynamicApiControllerOptions } from './dynamic-api-controller-options.interface';
|
|
5
5
|
import { DynamicApiCacheOptions } from './dynamic-api-cache-options.interface';
|
|
6
6
|
import { DynamicAPIRouteConfig } from './dynamic-api-route-config.interface';
|
|
7
7
|
declare const DYNAMIC_API_GLOBAL_STATE: unique symbol;
|
|
8
8
|
interface DynamicApiForRootOptions {
|
|
9
9
|
useGlobalCache?: boolean;
|
|
10
10
|
cacheOptions?: DynamicApiCacheOptions;
|
|
11
|
-
useAuth?:
|
|
11
|
+
useAuth?: DynamicApiAuthOptions;
|
|
12
12
|
}
|
|
13
13
|
interface DynamicApiForFeatureOptions<Entity extends BaseEntity> {
|
|
14
14
|
entity: Type<Entity>;
|
|
15
|
-
controllerOptions:
|
|
15
|
+
controllerOptions: DynamicApiControllerOptions<Entity>;
|
|
16
16
|
routes?: DynamicAPIRouteConfig<Entity>[];
|
|
17
17
|
}
|
|
18
18
|
export { DynamicApiForFeatureOptions, DynamicApiForRootOptions, DYNAMIC_API_GLOBAL_STATE };
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
/// <reference types="mongoose/types/virtuals" />
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
25
|
import { IndexDefinition, IndexOptions } from 'mongoose';
|
|
26
|
-
|
|
26
|
+
import { RouteType } from './dynamic-api-route-type.type';
|
|
27
|
+
type HookEvent = RouteType;
|
|
28
|
+
type MongoDBQuery = 'deleteMany' | 'deleteOne' | 'find' | 'findOne' | 'findOneAndReplace' | 'findOneAndUpdate' | 'save' | 'updateMany' | 'updateOne';
|
|
27
29
|
type SchemaHook = {
|
|
28
30
|
type: HookEvent;
|
|
29
31
|
method: 'pre' | 'post';
|
|
@@ -33,6 +35,10 @@ type SchemaHook = {
|
|
|
33
35
|
query?: boolean;
|
|
34
36
|
};
|
|
35
37
|
};
|
|
38
|
+
export declare const queryByRouteTypeMap: Map<HookEvent, {
|
|
39
|
+
query: MongoDBQuery;
|
|
40
|
+
softDeletableQuery?: MongoDBQuery;
|
|
41
|
+
}>;
|
|
36
42
|
interface DynamicAPISchemaOptionsInterface {
|
|
37
43
|
indexes?: {
|
|
38
44
|
fields: IndexDefinition;
|
|
@@ -1,2 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queryByRouteTypeMap = void 0;
|
|
4
|
+
exports.queryByRouteTypeMap = new Map([
|
|
5
|
+
['CreateMany', { query: 'save' }],
|
|
6
|
+
['CreateOne', { query: 'save' }],
|
|
7
|
+
['DeleteMany', { query: 'deleteMany', softDeletableQuery: 'updateMany' }],
|
|
8
|
+
['DeleteOne', { query: 'deleteOne', softDeletableQuery: 'updateOne' }],
|
|
9
|
+
['DuplicateMany', { query: 'save' }],
|
|
10
|
+
['DuplicateOne', { query: 'save' }],
|
|
11
|
+
['GetMany', { query: 'find' }],
|
|
12
|
+
['GetOne', { query: 'findOne' }],
|
|
13
|
+
['ReplaceOne', { query: 'findOneAndReplace' }],
|
|
14
|
+
['UpdateMany', { query: 'updateMany' }],
|
|
15
|
+
['UpdateOne', { query: 'findOneAndUpdate' }],
|
|
16
|
+
]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './controller-options.interface';
|
|
2
|
-
export * from './decorator-builder.interface';
|
|
1
|
+
export * from './dynamic-api-controller-options.interface';
|
|
2
|
+
export * from './dynamic-api-decorator-builder.interface';
|
|
3
3
|
export * from './dynamic-api-cache-options.interface';
|
|
4
4
|
export * from './dynamic-api-casl-ability.interface';
|
|
5
5
|
export * from './dynamic-api-entity-mappers.interface';
|
|
@@ -13,4 +13,3 @@ export * from './dynamic-api-route-type.type';
|
|
|
13
13
|
export * from './dynamic-api-schema-options.interface';
|
|
14
14
|
export * from './dynamic-api-service-provider.interface';
|
|
15
15
|
export * from './dynamic-api-swagger-options.type';
|
|
16
|
-
export * from './maybe-promise.type';
|
package/src/interfaces/index.js
CHANGED
|
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./controller-options.interface"), exports);
|
|
18
|
-
__exportStar(require("./decorator-builder.interface"), exports);
|
|
17
|
+
__exportStar(require("./dynamic-api-controller-options.interface"), exports);
|
|
18
|
+
__exportStar(require("./dynamic-api-decorator-builder.interface"), exports);
|
|
19
19
|
__exportStar(require("./dynamic-api-cache-options.interface"), exports);
|
|
20
20
|
__exportStar(require("./dynamic-api-casl-ability.interface"), exports);
|
|
21
21
|
__exportStar(require("./dynamic-api-entity-mappers.interface"), exports);
|
|
@@ -29,4 +29,3 @@ __exportStar(require("./dynamic-api-route-type.type"), exports);
|
|
|
29
29
|
__exportStar(require("./dynamic-api-schema-options.interface"), exports);
|
|
30
30
|
__exportStar(require("./dynamic-api-service-provider.interface"), exports);
|
|
31
31
|
__exportStar(require("./dynamic-api-swagger-options.type"), exports);
|
|
32
|
-
__exportStar(require("./maybe-promise.type"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Type } from '@nestjs/common';
|
|
2
2
|
import { BaseEntity } from '../models';
|
|
3
|
-
declare function EntityPresenterMixin<Entity extends BaseEntity>(entity: Type<Entity>,
|
|
3
|
+
declare function EntityPresenterMixin<Entity extends BaseEntity>(entity: Type<Entity>, additionalKeysToExclude?: (keyof Entity)[]): {
|
|
4
4
|
new (...args: any[]): {};
|
|
5
5
|
apply(this: Function, thisArg: any, argArray?: any): any;
|
|
6
6
|
call(this: Function, thisArg: any, ...argArray: any[]): any;
|
|
@@ -2,8 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EntityPresenterMixin = void 0;
|
|
4
4
|
const swagger_1 = require("@nestjs/swagger");
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const baseEntityKeysToExclude = () => [
|
|
6
|
+
'deletedAt',
|
|
7
|
+
'isDeleted',
|
|
8
|
+
'_id',
|
|
9
|
+
'__v',
|
|
10
|
+
];
|
|
11
|
+
function EntityPresenterMixin(entity, additionalKeysToExclude) {
|
|
12
|
+
const keysToExclude = [
|
|
13
|
+
...baseEntityKeysToExclude(),
|
|
14
|
+
...(additionalKeysToExclude ?? []),
|
|
15
|
+
];
|
|
16
|
+
class EntityPresenter extends (0, swagger_1.OmitType)(entity, keysToExclude) {
|
|
7
17
|
}
|
|
8
18
|
return EntityPresenter;
|
|
9
19
|
}
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
/// <reference types="mongoose/types/virtuals" />
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
25
|
import { ObjectId } from 'mongoose';
|
|
26
|
-
export declare class BaseEntity {
|
|
26
|
+
export declare abstract class BaseEntity {
|
|
27
27
|
_id: ObjectId;
|
|
28
28
|
__v: number;
|
|
29
29
|
id: string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Type } from '@nestjs/common';
|
|
2
|
-
import {
|
|
2
|
+
import { DynamicAPIServiceProvider } from '../../interfaces';
|
|
3
3
|
import { BaseEntity } from '../../models';
|
|
4
|
-
import {
|
|
4
|
+
import { AuthControllerConstructor, DynamicApiRegisterOptions } from './interfaces';
|
|
5
5
|
declare const authServiceProviderName = "DynamicApiAuthService";
|
|
6
6
|
declare const localStrategyProviderName = "DynamicApiLocalStrategy";
|
|
7
7
|
declare function createLocalStrategyProvider<Entity extends BaseEntity>(loginField: keyof Entity, passwordField: keyof Entity): DynamicAPIServiceProvider;
|
|
8
|
-
declare function createAuthServiceProvider<Entity extends BaseEntity>(userEntity: Type<Entity>, loginField: keyof Entity, passwordField: keyof Entity, additionalFields:
|
|
9
|
-
declare function createAuthController<Entity extends BaseEntity>(userEntity: Type<Entity>, loginField: keyof Entity, passwordField: keyof Entity,
|
|
8
|
+
declare function createAuthServiceProvider<Entity extends BaseEntity>(userEntity: Type<Entity>, loginField: keyof Entity, passwordField: keyof Entity, additionalFields: (keyof Entity)[] | undefined): DynamicAPIServiceProvider;
|
|
9
|
+
declare function createAuthController<Entity extends BaseEntity>(userEntity: Type<Entity>, loginField: keyof Entity, passwordField: keyof Entity, additionalRequestFields: (keyof Entity)[] | undefined, registerOptions: DynamicApiRegisterOptions<Entity> | undefined): AuthControllerConstructor<Entity>;
|
|
10
10
|
export { authServiceProviderName, createAuthController, createAuthServiceProvider, createLocalStrategyProvider, localStrategyProviderName, };
|
|
@@ -63,7 +63,7 @@ function createAuthServiceProvider(userEntity, loginField, passwordField, additi
|
|
|
63
63
|
this.model = model;
|
|
64
64
|
this.jwtService = jwtService;
|
|
65
65
|
this.bcryptService = bcryptService;
|
|
66
|
-
this.additionalRequestFields = additionalFields
|
|
66
|
+
this.additionalRequestFields = additionalFields ?? [];
|
|
67
67
|
this.loginField = loginField;
|
|
68
68
|
this.passwordField = passwordField;
|
|
69
69
|
}
|
|
@@ -80,8 +80,8 @@ function createAuthServiceProvider(userEntity, loginField, passwordField, additi
|
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
exports.createAuthServiceProvider = createAuthServiceProvider;
|
|
83
|
-
function createAuthController(userEntity, loginField, passwordField,
|
|
84
|
-
let AuthController = class AuthController extends (0, mixins_1.AuthControllerMixin)(userEntity, loginField, passwordField,
|
|
83
|
+
function createAuthController(userEntity, loginField, passwordField, additionalRequestFields, registerOptions) {
|
|
84
|
+
let AuthController = class AuthController extends (0, mixins_1.AuthControllerMixin)(userEntity, loginField, passwordField, additionalRequestFields, registerOptions ?? {}) {
|
|
85
85
|
constructor(service) {
|
|
86
86
|
super(service);
|
|
87
87
|
this.service = service;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BaseEntity } from '../../models';
|
|
2
2
|
import { BcryptService } from '../../services';
|
|
3
|
-
import {
|
|
3
|
+
import { DynamicApiAuthOptions } from './interfaces';
|
|
4
4
|
import { JwtStrategy } from './strategies';
|
|
5
5
|
export declare class AuthModule {
|
|
6
|
-
static forRoot<Entity extends BaseEntity>({ user: { entity: userEntity, loginField, passwordField,
|
|
6
|
+
static forRoot<Entity extends BaseEntity>({ user: { entity: userEntity, loginField, passwordField, requestAdditionalFields, }, jwt: { secret, expiresIn }, register, }: DynamicApiAuthOptions<Entity>, extraImports?: any[]): {
|
|
7
7
|
module: typeof AuthModule;
|
|
8
8
|
imports: any[];
|
|
9
9
|
providers: (typeof BcryptService | import("../../interfaces/dynamic-api-service-provider.interface").DynamicAPIServiceProvider | typeof JwtStrategy)[];
|
|
@@ -18,9 +18,9 @@ const services_1 = require("../../services");
|
|
|
18
18
|
const auth_helper_1 = require("./auth.helper");
|
|
19
19
|
const strategies_1 = require("./strategies");
|
|
20
20
|
let AuthModule = AuthModule_1 = class AuthModule {
|
|
21
|
-
static forRoot({ user: { entity: userEntity, loginField, passwordField,
|
|
22
|
-
const AuthController = (0, auth_helper_1.createAuthController)(userEntity, loginField, passwordField,
|
|
23
|
-
const AuthServiceProvider = (0, auth_helper_1.createAuthServiceProvider)(userEntity, loginField, passwordField,
|
|
21
|
+
static forRoot({ user: { entity: userEntity, loginField, passwordField, requestAdditionalFields, }, jwt: { secret, expiresIn }, register, }, extraImports = []) {
|
|
22
|
+
const AuthController = (0, auth_helper_1.createAuthController)(userEntity, loginField, passwordField, requestAdditionalFields, register);
|
|
23
|
+
const AuthServiceProvider = (0, auth_helper_1.createAuthServiceProvider)(userEntity, loginField, passwordField, requestAdditionalFields);
|
|
24
24
|
const LocalStrategyProvider = (0, auth_helper_1.createLocalStrategyProvider)(loginField, passwordField);
|
|
25
25
|
return {
|
|
26
26
|
module: AuthModule_1,
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import { Type } from '@nestjs/common';
|
|
2
|
-
import {
|
|
2
|
+
import { DynamicApiRegisterAbilityPredicate } from '../../../interfaces';
|
|
3
3
|
import { BaseEntity } from '../../../models';
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
type DynamicApiRegisterOptions<Entity extends BaseEntity = any> = {
|
|
5
|
+
protected?: boolean;
|
|
6
|
+
abilityPredicate?: DynamicApiRegisterAbilityPredicate;
|
|
7
|
+
additionalFields?: (keyof Entity | {
|
|
8
|
+
name: keyof Entity;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
})[];
|
|
7
11
|
};
|
|
8
|
-
type
|
|
12
|
+
type DynamicApiAuthOptions<Entity extends BaseEntity = any> = {
|
|
9
13
|
user: {
|
|
10
14
|
entity: Type<Entity>;
|
|
11
15
|
loginField?: keyof Entity;
|
|
12
16
|
passwordField?: keyof Entity;
|
|
13
|
-
|
|
17
|
+
requestAdditionalFields?: (keyof Entity)[];
|
|
14
18
|
};
|
|
19
|
+
register?: DynamicApiRegisterOptions;
|
|
15
20
|
jwt?: {
|
|
16
21
|
secret: string;
|
|
17
22
|
expiresIn?: string | number;
|
|
18
23
|
};
|
|
19
|
-
protectRegister?: boolean;
|
|
20
|
-
registerAbilityPredicate?: DynamicApiAuthRegisterCaslAbilityPredicate;
|
|
21
24
|
};
|
|
22
|
-
export type {
|
|
25
|
+
export type { DynamicApiAuthOptions, DynamicApiRegisterOptions };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Type } from '@nestjs/common';
|
|
2
|
-
import { DynamicApiAuthRegisterCaslAbilityPredicate } from '../../../interfaces';
|
|
3
2
|
import { BaseEntity } from '../../../models';
|
|
4
|
-
import { AuthControllerConstructor } from '../interfaces';
|
|
5
|
-
declare function AuthControllerMixin<Entity extends BaseEntity>(userEntity: Type<Entity>, loginField: keyof Entity, passwordField: keyof Entity,
|
|
3
|
+
import { AuthControllerConstructor, DynamicApiRegisterOptions } from '../interfaces';
|
|
4
|
+
declare function AuthControllerMixin<Entity extends BaseEntity>(userEntity: Type<Entity>, loginField: keyof Entity, passwordField: keyof Entity, additionalRequestFields?: (keyof Entity)[], { additionalFields: additionalRegisterFields, protected: registerProtected, abilityPredicate: registerAbilityPredicate, }?: DynamicApiRegisterOptions<Entity>): AuthControllerConstructor<Entity>;
|
|
6
5
|
export { AuthControllerMixin };
|
|
@@ -21,7 +21,7 @@ const decorators_1 = require("../../../decorators");
|
|
|
21
21
|
const helpers_1 = require("../../../helpers");
|
|
22
22
|
const guards_1 = require("../guards");
|
|
23
23
|
const auth_register_policies_guard_mixin_1 = require("./auth-register-policies-guard.mixin");
|
|
24
|
-
function AuthControllerMixin(userEntity, loginField, passwordField,
|
|
24
|
+
function AuthControllerMixin(userEntity, loginField, passwordField, additionalRequestFields = [], { additionalFields: additionalRegisterFields, protected: registerProtected, abilityPredicate: registerAbilityPredicate, } = {}) {
|
|
25
25
|
var _a;
|
|
26
26
|
class AuthBodyPasswordFieldDto {
|
|
27
27
|
}
|
|
@@ -34,7 +34,24 @@ function AuthControllerMixin(userEntity, loginField, passwordField, additionalRe
|
|
|
34
34
|
], AuthBodyPasswordFieldDto.prototype, _a, void 0);
|
|
35
35
|
class AuthLoginDto extends (0, swagger_1.IntersectionType)((0, swagger_1.PickType)(userEntity, [loginField]), AuthBodyPasswordFieldDto) {
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
const additionalMandatoryFields = [];
|
|
38
|
+
const additionalOptionalFields = [];
|
|
39
|
+
additionalRegisterFields.forEach((field) => {
|
|
40
|
+
if (typeof field === 'string') {
|
|
41
|
+
additionalOptionalFields.push(field);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const { required, name } = field;
|
|
45
|
+
if (required) {
|
|
46
|
+
additionalMandatoryFields.push(name);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
additionalOptionalFields.push(name);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
class AuthRegisterDto extends (0, swagger_1.IntersectionType)((0, swagger_1.PickType)(userEntity, [loginField, ...additionalMandatoryFields]), additionalOptionalFields?.length
|
|
53
|
+
? (0, swagger_1.IntersectionType)(AuthBodyPasswordFieldDto, (0, swagger_1.PartialType)((0, swagger_1.PickType)(userEntity, additionalOptionalFields)))
|
|
54
|
+
: AuthBodyPasswordFieldDto) {
|
|
38
55
|
}
|
|
39
56
|
class AuthPresenter {
|
|
40
57
|
}
|
|
@@ -44,8 +61,8 @@ function AuthControllerMixin(userEntity, loginField, passwordField, additionalRe
|
|
|
44
61
|
], AuthPresenter.prototype, "accessToken", void 0);
|
|
45
62
|
class AuthUserPresenter extends (0, swagger_1.PickType)(userEntity, ['id', loginField, ...additionalRequestFields]) {
|
|
46
63
|
}
|
|
47
|
-
const authDecorators = new builders_1.AuthDecoratorsBuilder(
|
|
48
|
-
class AuthRegisterPoliciesGuard extends (0, auth_register_policies_guard_mixin_1.AuthRegisterPoliciesGuardMixin)(userEntity,
|
|
64
|
+
const authDecorators = new builders_1.AuthDecoratorsBuilder(registerProtected);
|
|
65
|
+
class AuthRegisterPoliciesGuard extends (0, auth_register_policies_guard_mixin_1.AuthRegisterPoliciesGuardMixin)(userEntity, registerAbilityPredicate) {
|
|
49
66
|
}
|
|
50
67
|
class BaseAuthController {
|
|
51
68
|
constructor(service) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Type } from '@nestjs/common';
|
|
2
|
-
import {
|
|
2
|
+
import { DynamicApiRegisterAbilityPredicate, PoliciesGuardConstructor, RouteType } from '../../../interfaces';
|
|
3
3
|
import { BaseEntity } from '../../../models';
|
|
4
4
|
declare const registerRouteType: RouteType;
|
|
5
|
-
declare function AuthRegisterPoliciesGuardMixin<Entity extends BaseEntity>(entity: Type<Entity>, abilityPredicate:
|
|
5
|
+
declare function AuthRegisterPoliciesGuardMixin<Entity extends BaseEntity>(entity: Type<Entity>, abilityPredicate: DynamicApiRegisterAbilityPredicate | undefined): PoliciesGuardConstructor<Entity>;
|
|
6
6
|
export { AuthRegisterPoliciesGuardMixin, registerRouteType };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Type } from '@nestjs/common';
|
|
2
|
-
import {
|
|
2
|
+
import { DynamicApiControllerOptions, DynamicAPIRouteConfig } from '../../interfaces';
|
|
3
3
|
import { BaseEntity } from '../../models';
|
|
4
4
|
import { CreateManyControllerConstructor } from './create-many-controller.interface';
|
|
5
|
-
declare function CreateManyControllerMixin<Entity extends BaseEntity>(entity: Type<Entity>, { path, apiTag, isPublic: isPublicController, abilityPredicates: controllerAbilityPredicates, }:
|
|
5
|
+
declare function CreateManyControllerMixin<Entity extends BaseEntity>(entity: Type<Entity>, { path, apiTag, isPublic: isPublicController, abilityPredicates: controllerAbilityPredicates, }: DynamicApiControllerOptions<Entity>, { type: routeType, description, dTOs, isPublic: isPublicRoute, abilityPredicate: routeAbilityPredicate, }: DynamicAPIRouteConfig<Entity>, version?: string): CreateManyControllerConstructor<Entity>;
|
|
6
6
|
export { CreateManyControllerMixin };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Type, ValidationPipeOptions } from '@nestjs/common';
|
|
2
|
-
import {
|
|
2
|
+
import { DynamicApiControllerOptions, DynamicAPIRouteConfig, DynamicAPIServiceProvider } from '../../interfaces';
|
|
3
3
|
import { BaseEntity } from '../../models';
|
|
4
4
|
import { CreateManyControllerConstructor } from './create-many-controller.interface';
|
|
5
5
|
declare function createCreateManyServiceProvider<Entity extends BaseEntity>(entity: Type<Entity>, version: string | undefined): DynamicAPIServiceProvider;
|
|
6
|
-
declare function createCreateManyController<Entity extends BaseEntity>(entity: Type<Entity>, controllerOptions:
|
|
6
|
+
declare function createCreateManyController<Entity extends BaseEntity>(entity: Type<Entity>, controllerOptions: DynamicApiControllerOptions<Entity>, routeConfig: DynamicAPIRouteConfig<Entity>, version?: string, validationPipeOptions?: ValidationPipeOptions): CreateManyControllerConstructor<Entity>;
|
|
7
7
|
export { createCreateManyController, createCreateManyServiceProvider };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DynamicModule, Type, ValidationPipeOptions } from '@nestjs/common';
|
|
2
|
-
import {
|
|
2
|
+
import { DynamicApiControllerOptions, DynamicAPIRouteConfig } from '../../interfaces';
|
|
3
3
|
import { BaseEntity } from '../../models';
|
|
4
4
|
export declare class CreateManyModule {
|
|
5
|
-
static forFeature<Entity extends BaseEntity>(databaseModule: DynamicModule, entity: Type<Entity>, controllerOptions:
|
|
5
|
+
static forFeature<Entity extends BaseEntity>(databaseModule: DynamicModule, entity: Type<Entity>, controllerOptions: DynamicApiControllerOptions<Entity>, routeConfig: DynamicAPIRouteConfig<Entity>, version?: string, validationPipeOptions?: ValidationPipeOptions): Promise<DynamicModule>;
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Type } from '@nestjs/common';
|
|
2
|
-
import {
|
|
2
|
+
import { DynamicApiControllerOptions, DynamicAPIRouteConfig } from '../../interfaces';
|
|
3
3
|
import { BaseEntity } from '../../models';
|
|
4
4
|
import { CreateOneControllerConstructor } from './create-one-controller.interface';
|
|
5
|
-
declare function CreateOneControllerMixin<Entity extends BaseEntity>(entity: Type<Entity>, { path, apiTag, isPublic: isPublicController, abilityPredicates: controllerAbilityPredicates, }:
|
|
5
|
+
declare function CreateOneControllerMixin<Entity extends BaseEntity>(entity: Type<Entity>, { path, apiTag, isPublic: isPublicController, abilityPredicates: controllerAbilityPredicates, }: DynamicApiControllerOptions<Entity>, { type: routeType, description, dTOs, isPublic: isPublicRoute, abilityPredicate: routeAbilityPredicate, }: DynamicAPIRouteConfig<Entity>, version?: string): CreateOneControllerConstructor<Entity>;
|
|
6
6
|
export { CreateOneControllerMixin };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Type, ValidationPipeOptions } from '@nestjs/common';
|
|
2
|
-
import {
|
|
2
|
+
import { DynamicApiControllerOptions, DynamicAPIRouteConfig, DynamicAPIServiceProvider } from '../../interfaces';
|
|
3
3
|
import { BaseEntity } from '../../models';
|
|
4
4
|
import { CreateOneControllerConstructor } from './create-one-controller.interface';
|
|
5
5
|
declare function createCreateOneServiceProvider<Entity extends BaseEntity>(entity: Type<Entity>, version: string | undefined): DynamicAPIServiceProvider;
|
|
6
|
-
declare function createCreateOneController<Entity extends BaseEntity>(entity: Type<Entity>, controllerOptions:
|
|
6
|
+
declare function createCreateOneController<Entity extends BaseEntity>(entity: Type<Entity>, controllerOptions: DynamicApiControllerOptions<Entity>, routeConfig: DynamicAPIRouteConfig<Entity>, version?: string, validationPipeOptions?: ValidationPipeOptions): CreateOneControllerConstructor<Entity>;
|
|
7
7
|
export { createCreateOneController, createCreateOneServiceProvider };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DynamicModule, Provider, Type, ValidationPipeOptions } from '@nestjs/common';
|
|
2
|
-
import {
|
|
2
|
+
import { DynamicApiControllerOptions, DynamicAPIRouteConfig } from '../../interfaces';
|
|
3
3
|
import { BaseEntity } from '../../models';
|
|
4
4
|
export declare class CreateOneModule {
|
|
5
|
-
static forFeature<Entity extends BaseEntity>(databaseModule: DynamicModule, entity: Type<Entity>, controllerOptions:
|
|
5
|
+
static forFeature<Entity extends BaseEntity>(databaseModule: DynamicModule, entity: Type<Entity>, controllerOptions: DynamicApiControllerOptions<Entity>, routeConfig: DynamicAPIRouteConfig<Entity>, version?: string, validationPipeOptions?: ValidationPipeOptions, extraProviders?: Provider[]): DynamicModule;
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Type } from '@nestjs/common';
|
|
2
|
-
import {
|
|
2
|
+
import { DynamicApiControllerOptions, DynamicAPIRouteConfig } from '../../interfaces';
|
|
3
3
|
import { BaseEntity } from '../../models';
|
|
4
4
|
import { DeleteManyControllerConstructor } from './delete-many-controller.interface';
|
|
5
|
-
declare function DeleteManyControllerMixin<Entity extends BaseEntity>(entity: Type<Entity>, { path, apiTag, isPublic: isPublicController, abilityPredicates: controllerAbilityPredicates, }:
|
|
5
|
+
declare function DeleteManyControllerMixin<Entity extends BaseEntity>(entity: Type<Entity>, { path, apiTag, isPublic: isPublicController, abilityPredicates: controllerAbilityPredicates, }: DynamicApiControllerOptions<Entity>, { type: routeType, description, dTOs, isPublic: isPublicRoute, abilityPredicate: routeAbilityPredicate, }: DynamicAPIRouteConfig<Entity>, version?: string): DeleteManyControllerConstructor<Entity>;
|
|
6
6
|
export { DeleteManyControllerMixin };
|