@klerick/json-api-nestjs 10.0.0-beta.9 → 10.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 +157 -0
- package/README.md +299 -23
- package/package.json +4 -8
- package/src/index.d.ts +1 -1
- package/src/index.js +2 -1
- package/src/index.js.map +1 -1
- package/src/lib/constants/di.d.ts +1 -0
- package/src/lib/constants/di.js +2 -1
- package/src/lib/constants/di.js.map +1 -1
- package/src/lib/json-api.module.js +3 -2
- package/src/lib/json-api.module.js.map +1 -1
- package/src/lib/modules/atomic-operation/atomic-operation.module.d.ts +1 -2
- package/src/lib/modules/atomic-operation/atomic-operation.module.js +6 -5
- package/src/lib/modules/atomic-operation/atomic-operation.module.js.map +1 -1
- package/src/lib/modules/atomic-operation/controllers/operation.controller.js +4 -4
- package/src/lib/modules/atomic-operation/controllers/operation.controller.js.map +1 -1
- package/src/lib/modules/atomic-operation/factory/map-controller-entity.d.ts +1 -2
- package/src/lib/modules/atomic-operation/factory/map-controller-entity.js +8 -7
- package/src/lib/modules/atomic-operation/factory/map-controller-entity.js.map +1 -1
- package/src/lib/modules/atomic-operation/pipes/input-operation.pipe.js.map +1 -1
- package/src/lib/modules/atomic-operation/service/execute.service.d.ts +13 -3
- package/src/lib/modules/atomic-operation/service/execute.service.js +80 -33
- package/src/lib/modules/atomic-operation/service/execute.service.js.map +1 -1
- package/src/lib/modules/atomic-operation/service/explorer.service.js +10 -6
- package/src/lib/modules/atomic-operation/service/explorer.service.js.map +1 -1
- package/src/lib/modules/atomic-operation/service/swagger.service.js +6 -6
- package/src/lib/modules/atomic-operation/service/swagger.service.js.map +1 -1
- package/src/lib/modules/atomic-operation/utils/zod/zod-helper.d.ts +14 -7
- package/src/lib/modules/atomic-operation/utils/zod/zod-helper.js +12 -9
- package/src/lib/modules/atomic-operation/utils/zod/zod-helper.js.map +1 -1
- package/src/lib/modules/mixin/config/bindings.js +20 -0
- package/src/lib/modules/mixin/config/bindings.js.map +1 -1
- package/src/lib/modules/mixin/controllers/json-base.controller.d.ts +5 -5
- package/src/lib/modules/mixin/controllers/json-base.controller.js +5 -5
- package/src/lib/modules/mixin/controllers/json-base.controller.js.map +1 -1
- package/src/lib/modules/mixin/decorators/index.d.ts +1 -0
- package/src/lib/modules/mixin/decorators/index.js +1 -0
- package/src/lib/modules/mixin/decorators/index.js.map +1 -1
- package/src/lib/modules/mixin/decorators/json-api-response-from/json-api-response-from.decorator.d.ts +19 -0
- package/src/lib/modules/mixin/decorators/json-api-response-from/json-api-response-from.decorator.js +35 -0
- package/src/lib/modules/mixin/decorators/json-api-response-from/json-api-response-from.decorator.js.map +1 -0
- package/src/lib/modules/mixin/factory/zod-validate.factory.d.ts +2 -1
- package/src/lib/modules/mixin/factory/zod-validate.factory.js +5 -1
- package/src/lib/modules/mixin/factory/zod-validate.factory.js.map +1 -1
- package/src/lib/modules/mixin/helpers/bind-controller.js +4 -1
- package/src/lib/modules/mixin/helpers/bind-controller.js.map +1 -1
- package/src/lib/modules/mixin/mixin.module.js +1 -0
- package/src/lib/modules/mixin/mixin.module.js.map +1 -1
- package/src/lib/modules/mixin/pipe/index.d.ts +1 -0
- package/src/lib/modules/mixin/pipe/index.js +5 -0
- package/src/lib/modules/mixin/pipe/index.js.map +1 -1
- package/src/lib/modules/mixin/pipe/meta-extractor/index.d.ts +1 -0
- package/src/lib/modules/mixin/pipe/meta-extractor/index.js +5 -0
- package/src/lib/modules/mixin/pipe/meta-extractor/index.js.map +1 -0
- package/src/lib/modules/mixin/pipe/meta-extractor/meta-extractor.pipe.d.ts +6 -0
- package/src/lib/modules/mixin/pipe/meta-extractor/meta-extractor.pipe.js +27 -0
- package/src/lib/modules/mixin/pipe/meta-extractor/meta-extractor.pipe.js.map +1 -0
- package/src/lib/modules/mixin/service/json-api-transformer.service.d.ts +2 -2
- package/src/lib/modules/mixin/service/json-api-transformer.service.js.map +1 -1
- package/src/lib/modules/mixin/swagger/error-response-model.d.ts +11 -0
- package/src/lib/modules/mixin/swagger/error-response-model.js +63 -0
- package/src/lib/modules/mixin/swagger/error-response-model.js.map +1 -0
- package/src/lib/modules/mixin/swagger/method/delete-one.js +3 -3
- package/src/lib/modules/mixin/swagger/method/delete-one.js.map +1 -1
- package/src/lib/modules/mixin/swagger/method/delete-relationship.js +6 -6
- package/src/lib/modules/mixin/swagger/method/delete-relationship.js.map +1 -1
- package/src/lib/modules/mixin/swagger/method/get-all.js +9 -39
- package/src/lib/modules/mixin/swagger/method/get-all.js.map +1 -1
- package/src/lib/modules/mixin/swagger/method/get-one.js +5 -5
- package/src/lib/modules/mixin/swagger/method/get-one.js.map +1 -1
- package/src/lib/modules/mixin/swagger/method/get-relationship.js +5 -4
- package/src/lib/modules/mixin/swagger/method/get-relationship.js.map +1 -1
- package/src/lib/modules/mixin/swagger/method/patch-one.js +5 -5
- package/src/lib/modules/mixin/swagger/method/patch-one.js.map +1 -1
- package/src/lib/modules/mixin/swagger/method/patch-relationship.js +7 -7
- package/src/lib/modules/mixin/swagger/method/patch-relationship.js.map +1 -1
- package/src/lib/modules/mixin/swagger/method/post-one.js +5 -5
- package/src/lib/modules/mixin/swagger/method/post-one.js.map +1 -1
- package/src/lib/modules/mixin/swagger/method/post-relationship.js +7 -7
- package/src/lib/modules/mixin/swagger/method/post-relationship.js.map +1 -1
- package/src/lib/modules/mixin/swagger/open-api-types.d.ts +18 -0
- package/src/lib/modules/mixin/swagger/open-api-types.js +3 -0
- package/src/lib/modules/mixin/swagger/open-api-types.js.map +1 -0
- package/src/lib/modules/mixin/swagger/swagger-bind.service.d.ts +1 -0
- package/src/lib/modules/mixin/swagger/swagger-bind.service.js +52 -13
- package/src/lib/modules/mixin/swagger/swagger-bind.service.js.map +1 -1
- package/src/lib/modules/mixin/swagger/utils.d.ts +17 -142
- package/src/lib/modules/mixin/swagger/utils.js +178 -124
- package/src/lib/modules/mixin/swagger/utils.js.map +1 -1
- package/src/lib/modules/mixin/zod/index.d.ts +1 -1
- package/src/lib/modules/mixin/zod/index.js +4 -0
- package/src/lib/modules/mixin/zod/index.js.map +1 -1
- package/src/lib/modules/mixin/zod/map-transform-to-json-shema.d.ts +2 -0
- package/src/lib/modules/mixin/zod/map-transform-to-json-shema.js +10 -0
- package/src/lib/modules/mixin/zod/map-transform-to-json-shema.js.map +1 -1
- package/src/lib/modules/mixin/zod/zod-input-patch-relationship-schema/index.d.ts +8 -0
- package/src/lib/modules/mixin/zod/zod-input-patch-relationship-schema/index.js +8 -3
- package/src/lib/modules/mixin/zod/zod-input-patch-relationship-schema/index.js.map +1 -1
- package/src/lib/modules/mixin/zod/zod-input-patch-schema/index.d.ts +3 -1
- package/src/lib/modules/mixin/zod/zod-input-patch-schema/index.js +1 -0
- package/src/lib/modules/mixin/zod/zod-input-patch-schema/index.js.map +1 -1
- package/src/lib/modules/mixin/zod/zod-input-post-relationship-schema/index.d.ts +1 -0
- package/src/lib/modules/mixin/zod/zod-input-post-relationship-schema/index.js +1 -0
- package/src/lib/modules/mixin/zod/zod-input-post-relationship-schema/index.js.map +1 -1
- package/src/lib/modules/mixin/zod/zod-input-post-schema/index.d.ts +4 -2
- package/src/lib/modules/mixin/zod/zod-input-post-schema/index.js +2 -1
- package/src/lib/modules/mixin/zod/zod-input-post-schema/index.js.map +1 -1
- package/src/lib/modules/mixin/zod/zod-input-query-schema/fields.d.ts +8 -5
- package/src/lib/modules/mixin/zod/zod-input-query-schema/fields.js +16 -12
- package/src/lib/modules/mixin/zod/zod-input-query-schema/fields.js.map +1 -1
- package/src/lib/modules/mixin/zod/zod-input-query-schema/filter.d.ts +76 -6
- package/src/lib/modules/mixin/zod/zod-input-query-schema/filter.js +32 -10
- package/src/lib/modules/mixin/zod/zod-input-query-schema/filter.js.map +1 -1
- package/src/lib/modules/mixin/zod/zod-input-query-schema/index.d.ts +40 -15
- package/src/lib/modules/mixin/zod/zod-input-query-schema/index.js +3 -1
- package/src/lib/modules/mixin/zod/zod-input-query-schema/index.js.map +1 -1
- package/src/lib/modules/mixin/zod/zod-query-schema/fields.d.ts +1 -1
- package/src/lib/modules/mixin/zod/zod-query-schema/fields.js +5 -4
- package/src/lib/modules/mixin/zod/zod-query-schema/fields.js.map +1 -1
- package/src/lib/modules/mixin/zod/zod-query-schema/filter.d.ts +4 -2
- package/src/lib/modules/mixin/zod/zod-query-schema/filter.js +19 -8
- package/src/lib/modules/mixin/zod/zod-query-schema/filter.js.map +1 -1
- package/src/lib/modules/mixin/zod/zod-query-schema/include.d.ts +9 -2
- package/src/lib/modules/mixin/zod/zod-query-schema/include.js +2 -1
- package/src/lib/modules/mixin/zod/zod-query-schema/include.js.map +1 -1
- package/src/lib/modules/mixin/zod/zod-query-schema/sort.d.ts +2 -2
- package/src/lib/modules/mixin/zod/zod-query-schema/sort.js +5 -4
- package/src/lib/modules/mixin/zod/zod-query-schema/sort.js.map +1 -1
- package/src/lib/modules/mixin/zod/zod-share/attributes.d.ts +12 -6
- package/src/lib/modules/mixin/zod/zod-share/attributes.js +12 -7
- package/src/lib/modules/mixin/zod/zod-share/attributes.js.map +1 -1
- package/src/lib/modules/mixin/zod/zod-share/id.d.ts +12 -0
- package/src/lib/modules/mixin/zod/zod-share/id.js +17 -0
- package/src/lib/modules/mixin/zod/zod-share/id.js.map +1 -1
- package/src/lib/modules/mixin/zod/zod-share/index.d.ts +1 -0
- package/src/lib/modules/mixin/zod/zod-share/index.js +1 -0
- package/src/lib/modules/mixin/zod/zod-share/index.js.map +1 -1
- package/src/lib/modules/mixin/zod/zod-share/meta.d.ts +11 -0
- package/src/lib/modules/mixin/zod/zod-share/meta.js +15 -0
- package/src/lib/modules/mixin/zod/zod-share/meta.js.map +1 -0
- package/src/lib/modules/mixin/zod/zod-share/page.d.ts +2 -2
- package/src/lib/modules/mixin/zod/zod-utils.d.ts +2 -0
- package/src/lib/modules/mixin/zod/zod-utils.js +20 -0
- package/src/lib/modules/mixin/zod/zod-utils.js.map +1 -1
- package/src/lib/types/entity-param.type.d.ts +7 -7
- package/src/lib/types/module-options.types.d.ts +1 -0
- package/src/lib/utils/module-helper.js +1 -0
- package/src/lib/utils/module-helper.js.map +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.postRelationship = postRelationship;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
4
|
const swagger_1 = require("@nestjs/swagger");
|
|
6
5
|
const utils_1 = require("../utils");
|
|
7
|
-
const
|
|
6
|
+
const zod_1 = require("../../zod");
|
|
8
7
|
const types_1 = require("../../../../types");
|
|
8
|
+
const error_response_model_1 = require("../error-response-model");
|
|
9
9
|
function postRelationship(controller, descriptor, entity, mapEntity, methodName) {
|
|
10
10
|
const entityName = entity.name;
|
|
11
11
|
const { relations, primaryColumnType } = mapEntity.getParamMap(entity);
|
|
@@ -24,7 +24,7 @@ function postRelationship(controller, descriptor, entity, mapEntity, methodName)
|
|
|
24
24
|
})(controller, methodName, descriptor);
|
|
25
25
|
(0, swagger_1.ApiBody)({
|
|
26
26
|
description: `Json api schema for update "${entityName}" item`,
|
|
27
|
-
schema:
|
|
27
|
+
schema: (0, utils_1.zodToOpenApiSchema)(zod_1.zodPatchRelationship),
|
|
28
28
|
required: true,
|
|
29
29
|
})(controller, methodName, descriptor);
|
|
30
30
|
(0, swagger_1.ApiOperation)({
|
|
@@ -33,23 +33,23 @@ function postRelationship(controller, descriptor, entity, mapEntity, methodName)
|
|
|
33
33
|
})(controller, methodName, descriptor);
|
|
34
34
|
(0, swagger_1.ApiResponse)({
|
|
35
35
|
status: 200,
|
|
36
|
-
schema: utils_1.
|
|
36
|
+
schema: utils_1.schemaTypeForRelationRef,
|
|
37
37
|
description: `Item/s of relation for "${entityName}" has been created`,
|
|
38
38
|
})(controller, methodName, descriptor);
|
|
39
39
|
(0, swagger_1.ApiResponse)({
|
|
40
40
|
status: 400,
|
|
41
41
|
description: 'Wrong url parameters',
|
|
42
|
-
schema:
|
|
42
|
+
schema: { $ref: (0, swagger_1.getSchemaPath)(error_response_model_1.JsonApiErrorResponseModel) },
|
|
43
43
|
})(controller, methodName, descriptor);
|
|
44
44
|
(0, swagger_1.ApiResponse)({
|
|
45
45
|
status: 422,
|
|
46
46
|
description: 'Incorrect type for relation',
|
|
47
|
-
schema:
|
|
47
|
+
schema: { $ref: (0, swagger_1.getSchemaPath)(error_response_model_1.JsonApiErrorResponseModel) },
|
|
48
48
|
})(controller, methodName, descriptor);
|
|
49
49
|
(0, swagger_1.ApiResponse)({
|
|
50
50
|
status: 404,
|
|
51
51
|
description: 'Resource not found ',
|
|
52
|
-
schema:
|
|
52
|
+
schema: { $ref: (0, swagger_1.getSchemaPath)(error_response_model_1.JsonApiErrorResponseModel) },
|
|
53
53
|
})(controller, methodName, descriptor);
|
|
54
54
|
}
|
|
55
55
|
//# sourceMappingURL=post-relationship.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-relationship.js","sourceRoot":"","sources":["../../../../../../../../../../libs/json-api/json-api-nestjs/src/lib/modules/mixin/swagger/method/post-relationship.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"post-relationship.js","sourceRoot":"","sources":["../../../../../../../../../../libs/json-api/json-api-nestjs/src/lib/modules/mixin/swagger/method/post-relationship.ts"],"names":[],"mappings":";;AAgBA,4CA4DC;AA3ED,6CAMyB;AAGzB,oCAAwE;AACxE,mCAAiD;AACjD,6CAA8C;AAE9C,kEAAoE;AAEpE,SAAgB,gBAAgB,CAC9B,UAAqB,EACrB,UAA8B,EAC9B,MAAsB,EACtB,SAA0C,EAC1C,UAAkB;IAElB,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC;IAE/B,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,GAAG,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAEvE,IAAA,kBAAQ,EAAC;QACP,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;QACd,IAAI,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AAM,EAAE,GAAG;QACX,WAAW,EAAE,6BAA6B;QAC1C,MAAM,EAAE,EAAE,IAAI,EAAE,IAAA,uBAAa,EAAC,gDAAyB,CAAC,EAAE;KAC3D,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAEvC,IAAA,qBAAW,EAAC;QACV,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,qBAAqB;QAClC,MAAM,EAAE,EAAE,IAAI,EAAE,IAAA,uBAAa,EAAC,gDAAyB,CAAC,EAAE;KAC3D,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { OpenAPIObject } from '@nestjs/swagger';
|
|
2
|
+
/**
|
|
3
|
+
* @nestjs/swagger exposes only `.`, `./plugin` and `./package.json` through its
|
|
4
|
+
* exports map, and its root barrel re-exports just `ApiTagOptions` and
|
|
5
|
+
* `OpenAPIObject` out of the OpenAPI spec interfaces. The schema types are
|
|
6
|
+
* therefore derived from `OpenAPIObject` rather than reached for through a deep
|
|
7
|
+
* import, which stops resolving the moment the package tightens its exports.
|
|
8
|
+
*
|
|
9
|
+
* `components.schemas` is typed as `Record<string, SchemaObject |
|
|
10
|
+
* ReferenceObject>`, and a reference is the only member carrying `$ref`, so the
|
|
11
|
+
* union splits cleanly.
|
|
12
|
+
*/
|
|
13
|
+
type SchemaOrReference = NonNullable<NonNullable<OpenAPIObject['components']>['schemas']>[string];
|
|
14
|
+
export type ReferenceObject = Extract<SchemaOrReference, {
|
|
15
|
+
$ref: string;
|
|
16
|
+
}>;
|
|
17
|
+
export type SchemaObject = Exclude<SchemaOrReference, ReferenceObject>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-api-types.js","sourceRoot":"","sources":["../../../../../../../../../libs/json-api/json-api-nestjs/src/lib/modules/mixin/swagger/open-api-types.ts"],"names":[],"mappings":""}
|
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SwaggerBindService = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
|
-
const constants_1 = require("@nestjs/swagger/dist/constants");
|
|
7
6
|
const swagger_1 = require("@nestjs/swagger");
|
|
7
|
+
const swagger_2 = require("@nestjs/swagger");
|
|
8
8
|
const core_1 = require("@nestjs/core");
|
|
9
9
|
const json_api_nestjs_shared_1 = require("@klerick/json-api-nestjs-shared");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const constants_1 = require("@nestjs/common/constants");
|
|
11
|
+
const constants_2 = require("../../../constants");
|
|
12
12
|
const helpers_1 = require("../helpers");
|
|
13
13
|
const controllers_1 = require("../controllers");
|
|
14
14
|
const filter_operand_model_1 = require("./filter-operand-model");
|
|
@@ -16,6 +16,8 @@ const utils_1 = require("./utils");
|
|
|
16
16
|
const bindings_1 = require("../config/bindings");
|
|
17
17
|
const method_1 = require("./method");
|
|
18
18
|
const service_1 = require("../service");
|
|
19
|
+
const error_response_model_1 = require("./error-response-model");
|
|
20
|
+
const decorators_1 = require("../decorators");
|
|
19
21
|
let SwaggerBindService = class SwaggerBindService {
|
|
20
22
|
entity;
|
|
21
23
|
discoveryService;
|
|
@@ -25,25 +27,27 @@ let SwaggerBindService = class SwaggerBindService {
|
|
|
25
27
|
this.initSwagger();
|
|
26
28
|
}
|
|
27
29
|
initSwagger() {
|
|
28
|
-
const controllerName = (0, helpers_1.nameIt)((0, helpers_1.getProviderName)(this.entity,
|
|
30
|
+
const controllerName = (0, helpers_1.nameIt)((0, helpers_1.getProviderName)(this.entity, constants_2.JSON_API_CONTROLLER_POSTFIX), controllers_1.JsonBaseController).name;
|
|
29
31
|
const controllerInst = this.discoveryService
|
|
30
32
|
.getControllers()
|
|
31
33
|
.find((i) => i.name === controllerName ||
|
|
32
34
|
this.entity ===
|
|
33
|
-
Reflect.getMetadata(
|
|
35
|
+
Reflect.getMetadata(constants_2.JSON_API_DECORATOR_ENTITY, i.instance.constructor));
|
|
34
36
|
if (!controllerInst)
|
|
35
37
|
throw new Error(`Controller for ${this.entity.name} is empty`);
|
|
36
38
|
const mapProps = this.mapEntity.getParamMap(this.entity);
|
|
37
39
|
if (!mapProps)
|
|
38
40
|
throw new Error(`ZodEntityProps for ${this.entity.name} is empty`);
|
|
39
41
|
const controller = controllerInst.instance.constructor;
|
|
40
|
-
const apiTag = Reflect.getMetadata(
|
|
42
|
+
const apiTag = Reflect.getMetadata(swagger_1.DECORATORS.API_TAGS, controller);
|
|
41
43
|
if (!apiTag) {
|
|
42
|
-
(0,
|
|
44
|
+
(0, swagger_2.ApiTags)(this.config['overrideRoute'] || this.entity.name)(controller);
|
|
43
45
|
}
|
|
44
|
-
(0,
|
|
45
|
-
(0,
|
|
46
|
-
(0,
|
|
46
|
+
(0, swagger_2.ApiExtraModels)(filter_operand_model_1.FilterOperand)(controller);
|
|
47
|
+
(0, swagger_2.ApiExtraModels)(error_response_model_1.JsonApiErrorResponseModel)(controller);
|
|
48
|
+
(0, swagger_2.ApiExtraModels)((0, utils_1.createApiModels)(this.entity, mapProps))(controller);
|
|
49
|
+
(0, utils_1.ensureZodSchemasRegistered)();
|
|
50
|
+
(0, swagger_2.ApiExtraModels)(utils_1.ZodSchemaRef)(controller);
|
|
47
51
|
const { allowMethod = json_api_nestjs_shared_1.ObjectTyped.keys(bindings_1.Bindings) } = this.config;
|
|
48
52
|
for (const method of json_api_nestjs_shared_1.ObjectTyped.keys(bindings_1.Bindings)) {
|
|
49
53
|
if (!allowMethod.includes(method))
|
|
@@ -54,13 +58,48 @@ let SwaggerBindService = class SwaggerBindService {
|
|
|
54
58
|
if (!descriptor)
|
|
55
59
|
throw new Error(`Descriptor for entity controller ${this.entity.name} is empty`);
|
|
56
60
|
method_1.swaggerMethod[method](controller.prototype, descriptor, this.entity, this.mapEntity, method);
|
|
57
|
-
Reflect.defineMetadata(
|
|
61
|
+
Reflect.defineMetadata(constants_1.PARAMTYPES_METADATA, [Object], controller.prototype, method);
|
|
62
|
+
}
|
|
63
|
+
// Process JsonApiResponseFrom decorators on custom methods
|
|
64
|
+
this.processJsonApiResponseFrom(controller);
|
|
65
|
+
}
|
|
66
|
+
processJsonApiResponseFrom(controller) {
|
|
67
|
+
const responseMeta = Reflect.getMetadata(decorators_1.JSON_API_RESPONSE_FROM, controller);
|
|
68
|
+
if (!responseMeta)
|
|
69
|
+
return;
|
|
70
|
+
const prototype = controller.prototype;
|
|
71
|
+
for (const [targetMethod, sourceMapping] of Object.entries(responseMeta)) {
|
|
72
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(prototype, targetMethod);
|
|
73
|
+
if (!descriptor)
|
|
74
|
+
continue;
|
|
75
|
+
const targetResponses = Reflect.getMetadata(swagger_1.DECORATORS.API_RESPONSE, descriptor.value);
|
|
76
|
+
if (!targetResponses)
|
|
77
|
+
continue;
|
|
78
|
+
for (const [sourceMethod, mappings] of Object.entries(sourceMapping)) {
|
|
79
|
+
const sourceDescriptor = Reflect.getOwnPropertyDescriptor(prototype, sourceMethod);
|
|
80
|
+
if (!sourceDescriptor)
|
|
81
|
+
continue;
|
|
82
|
+
const sourceResponses = Reflect.getMetadata(swagger_1.DECORATORS.API_RESPONSE, sourceDescriptor.value);
|
|
83
|
+
if (!sourceResponses || !mappings)
|
|
84
|
+
continue;
|
|
85
|
+
for (const { fromStatus, toStatus } of [...mappings]) {
|
|
86
|
+
const sourceResponse = sourceResponses[fromStatus];
|
|
87
|
+
if (!sourceResponse?.schema)
|
|
88
|
+
continue;
|
|
89
|
+
const existingTarget = targetResponses[toStatus] || {};
|
|
90
|
+
(0, swagger_2.ApiResponse)({
|
|
91
|
+
status: toStatus,
|
|
92
|
+
...existingTarget,
|
|
93
|
+
schema: sourceResponse.schema,
|
|
94
|
+
})(prototype, targetMethod, descriptor);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
58
97
|
}
|
|
59
98
|
}
|
|
60
99
|
};
|
|
61
100
|
exports.SwaggerBindService = SwaggerBindService;
|
|
62
101
|
tslib_1.__decorate([
|
|
63
|
-
(0, common_1.Inject)(
|
|
102
|
+
(0, common_1.Inject)(constants_2.CURRENT_ENTITY),
|
|
64
103
|
tslib_1.__metadata("design:type", Object)
|
|
65
104
|
], SwaggerBindService.prototype, "entity", void 0);
|
|
66
105
|
tslib_1.__decorate([
|
|
@@ -68,7 +107,7 @@ tslib_1.__decorate([
|
|
|
68
107
|
tslib_1.__metadata("design:type", core_1.DiscoveryService)
|
|
69
108
|
], SwaggerBindService.prototype, "discoveryService", void 0);
|
|
70
109
|
tslib_1.__decorate([
|
|
71
|
-
(0, common_1.Inject)(
|
|
110
|
+
(0, common_1.Inject)(constants_2.CONTROLLER_OPTIONS_TOKEN),
|
|
72
111
|
tslib_1.__metadata("design:type", Object)
|
|
73
112
|
], SwaggerBindService.prototype, "config", void 0);
|
|
74
113
|
tslib_1.__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swagger-bind.service.js","sourceRoot":"","sources":["../../../../../../../../../libs/json-api/json-api-nestjs/src/lib/modules/mixin/swagger/swagger-bind.service.ts"],"names":[],"mappings":";;;;AAAA,2CAAkE;AAClE,
|
|
1
|
+
{"version":3,"file":"swagger-bind.service.js","sourceRoot":"","sources":["../../../../../../../../../libs/json-api/json-api-nestjs/src/lib/modules/mixin/swagger/swagger-bind.service.ts"],"names":[],"mappings":";;;;AAAA,2CAAkE;AAClE,6CAA6C;AAC7C,6CAAuE;AACvE,uCAAgD;AAChD,4EAA2E;AAC3E,wDAA+D;AAE/D,kDAK4B;AAC5B,wCAAqD;AACrD,gDAAoD;AAEpD,iEAAuD;AACvD,mCAAoF;AACpF,iDAA8C;AAE9C,qCAAyC;AACzC,wCAAmD;AACnD,iEAAmE;AACnE,8CAGuB;AAGhB,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAGG,MAAM,CAAkB;IAC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B,CAAC,CAAC,SAAS,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;gBAC1C,CAAC;YACH,CAAC;QAEH,CAAC;IACH,CAAC;CACF,CAAA;AArIY,gDAAkB;AAGG;IAA/B,IAAA,eAAM,EAAC,0BAAc,CAAC;;kDAAiC;AACtB;IAAjC,IAAA,eAAM,EAAC,uBAAgB,CAAC;sCAA4B,uBAAgB;4DAAC;AAC5B;IAAzC,IAAA,eAAM,EAAC,oCAAwB,CAAC;;kDAAmC;AAE7B;IAAtC,IAAA,eAAM,EAAC,+BAAqB,CAAC;sCAAqB,+BAAqB;qDAGtE;6BAVS,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;GACA,kBAAkB,CAqI9B"}
|
|
@@ -1,49 +1,10 @@
|
|
|
1
|
-
import { SchemaObject } from '
|
|
2
|
-
import {
|
|
1
|
+
import type { SchemaObject, ReferenceObject } from './open-api-types';
|
|
2
|
+
import { EntityClass, AttrKeys } from '@klerick/json-api-nestjs-shared';
|
|
3
3
|
import { EntityParam } from '../../../types';
|
|
4
|
-
import { EntityParamMap } from '../types';
|
|
5
4
|
import { EntityParamMapService } from '../service';
|
|
6
|
-
import { toJSONSchema } from 'zod';
|
|
5
|
+
import { toJSONSchema, ZodType } from 'zod';
|
|
7
6
|
export declare function assertIsKeysOfObject<E extends object>(object: EntityClass<E>, element: any): asserts element is readonly [keyof E];
|
|
8
|
-
export declare function assertIsKeyOfObject<E extends object>(object: EntityClass<E>, element: unknown): asserts element is
|
|
9
|
-
export declare const errorSchema: {
|
|
10
|
-
type: string;
|
|
11
|
-
properties: {
|
|
12
|
-
statusCode: {
|
|
13
|
-
type: string;
|
|
14
|
-
};
|
|
15
|
-
error: {
|
|
16
|
-
type: string;
|
|
17
|
-
};
|
|
18
|
-
message: {
|
|
19
|
-
type: string;
|
|
20
|
-
items: {
|
|
21
|
-
type: string;
|
|
22
|
-
properties: {
|
|
23
|
-
code: {
|
|
24
|
-
type: string;
|
|
25
|
-
};
|
|
26
|
-
message: {
|
|
27
|
-
type: string;
|
|
28
|
-
};
|
|
29
|
-
path: {
|
|
30
|
-
type: string;
|
|
31
|
-
items: {
|
|
32
|
-
type: string;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
keys: {
|
|
36
|
-
type: string;
|
|
37
|
-
items: {
|
|
38
|
-
type: string;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
required: string[];
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
};
|
|
7
|
+
export declare function assertIsKeyOfObject<E extends object>(object: EntityClass<E>, element: unknown): asserts element is AttrKeys<E>;
|
|
47
8
|
export declare function jsonSchemaResponse<E extends object, IdKey extends string = 'id'>(entity: EntityClass<E>, mapEntity: EntityParamMapService<E, IdKey>, array?: boolean): {
|
|
48
9
|
type: string;
|
|
49
10
|
properties: {
|
|
@@ -51,110 +12,15 @@ export declare function jsonSchemaResponse<E extends object, IdKey extends strin
|
|
|
51
12
|
type: string;
|
|
52
13
|
};
|
|
53
14
|
data: {
|
|
54
|
-
|
|
55
|
-
properties: {
|
|
56
|
-
type: {
|
|
57
|
-
type: string;
|
|
58
|
-
const: string;
|
|
59
|
-
};
|
|
60
|
-
id: {
|
|
61
|
-
type: string;
|
|
62
|
-
};
|
|
63
|
-
attributes: {
|
|
64
|
-
type: string;
|
|
65
|
-
properties: Record<string, SchemaObject>;
|
|
66
|
-
};
|
|
67
|
-
relationships: {
|
|
68
|
-
type: string;
|
|
69
|
-
properties: Record<string, SchemaObject>;
|
|
70
|
-
};
|
|
71
|
-
links: {
|
|
72
|
-
type: string;
|
|
73
|
-
properties: {
|
|
74
|
-
self: {
|
|
75
|
-
type: string;
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
required: string[];
|
|
79
|
-
};
|
|
80
|
-
};
|
|
15
|
+
$ref: string;
|
|
81
16
|
} | {
|
|
82
17
|
type: string;
|
|
83
18
|
items: {
|
|
84
|
-
|
|
85
|
-
properties: {
|
|
86
|
-
type: {
|
|
87
|
-
type: string;
|
|
88
|
-
const: string;
|
|
89
|
-
};
|
|
90
|
-
id: {
|
|
91
|
-
type: string;
|
|
92
|
-
};
|
|
93
|
-
attributes: {
|
|
94
|
-
type: string;
|
|
95
|
-
properties: Record<string, SchemaObject>;
|
|
96
|
-
};
|
|
97
|
-
relationships: {
|
|
98
|
-
type: string;
|
|
99
|
-
properties: Record<string, SchemaObject>;
|
|
100
|
-
};
|
|
101
|
-
links: {
|
|
102
|
-
type: string;
|
|
103
|
-
properties: {
|
|
104
|
-
self: {
|
|
105
|
-
type: string;
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
required: string[];
|
|
109
|
-
};
|
|
110
|
-
};
|
|
19
|
+
$ref: string;
|
|
111
20
|
};
|
|
112
21
|
};
|
|
113
22
|
includes: {
|
|
114
|
-
|
|
115
|
-
items: {
|
|
116
|
-
type: string;
|
|
117
|
-
properties: {
|
|
118
|
-
type: {
|
|
119
|
-
type: string;
|
|
120
|
-
};
|
|
121
|
-
id: {
|
|
122
|
-
type: string;
|
|
123
|
-
};
|
|
124
|
-
attributes: {
|
|
125
|
-
type: string;
|
|
126
|
-
};
|
|
127
|
-
relationships: {
|
|
128
|
-
type: string;
|
|
129
|
-
properties: {
|
|
130
|
-
relationName: {
|
|
131
|
-
properties: {
|
|
132
|
-
links: {
|
|
133
|
-
type: string;
|
|
134
|
-
properties: {
|
|
135
|
-
self: {
|
|
136
|
-
type: string;
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
required: string[];
|
|
140
|
-
};
|
|
141
|
-
};
|
|
142
|
-
required: string[];
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
};
|
|
146
|
-
links: {
|
|
147
|
-
type: string;
|
|
148
|
-
properties: {
|
|
149
|
-
self: {
|
|
150
|
-
type: string;
|
|
151
|
-
};
|
|
152
|
-
};
|
|
153
|
-
required: string[];
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
required: string[];
|
|
157
|
-
};
|
|
23
|
+
$ref: string;
|
|
158
24
|
};
|
|
159
25
|
};
|
|
160
26
|
required: string[];
|
|
@@ -194,5 +60,14 @@ export declare const schemaTypeForRelation: {
|
|
|
194
60
|
};
|
|
195
61
|
};
|
|
196
62
|
};
|
|
197
|
-
export declare function getEntityMapProps<E extends object>(mapEntity: EntityParamMap<EntityClass<AnyEntity>>, entity: EntityClass<E>): EntityParam<EntityClass<object>>;
|
|
198
63
|
export declare const zodToJSONSchemaParams: Parameters<typeof toJSONSchema>[1];
|
|
64
|
+
export declare class ZodSchemaRef {
|
|
65
|
+
JsonApiLinks: unknown;
|
|
66
|
+
JsonApiIncludes: unknown;
|
|
67
|
+
RelationshipResponse: unknown;
|
|
68
|
+
}
|
|
69
|
+
export declare const schemaTypeForRelationRef: {
|
|
70
|
+
$ref: string;
|
|
71
|
+
};
|
|
72
|
+
export declare function ensureZodSchemasRegistered(): void;
|
|
73
|
+
export declare function zodToOpenApiSchema<T extends ZodType>(schema: T, params?: Parameters<typeof toJSONSchema>[1]): SchemaObject | ReferenceObject;
|