@kravc/dos 1.12.5 → 2.0.0-alpha.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/README.md +31 -994
- package/dist/Component/Component.d.ts +43 -0
- package/dist/Component/Component.d.ts.map +1 -0
- package/dist/Component/Component.js +99 -0
- package/dist/Component/Component.js.map +1 -0
- package/dist/Component/index.d.ts +4 -0
- package/dist/Component/index.d.ts.map +1 -0
- package/dist/Component/index.js +10 -0
- package/dist/Component/index.js.map +1 -0
- package/dist/Context/Context.d.ts +86 -0
- package/dist/Context/Context.d.ts.map +1 -0
- package/dist/Context/Context.js +148 -0
- package/dist/Context/Context.js.map +1 -0
- package/dist/Context/Request.d.ts +35 -0
- package/dist/Context/Request.d.ts.map +1 -0
- package/dist/Context/Request.js +3 -0
- package/dist/Context/Request.js.map +1 -0
- package/dist/Context/__tests__/__helpers.d.ts +14 -0
- package/dist/Context/__tests__/__helpers.d.ts.map +1 -0
- package/dist/Context/__tests__/__helpers.js +69 -0
- package/dist/Context/__tests__/__helpers.js.map +1 -0
- package/dist/Context/getHttpMethod.d.ts +6 -0
- package/dist/Context/getHttpMethod.d.ts.map +1 -0
- package/dist/Context/getHttpMethod.js +16 -0
- package/dist/Context/getHttpMethod.js.map +1 -0
- package/dist/Context/getHttpPath.d.ts +6 -0
- package/dist/Context/getHttpPath.d.ts.map +1 -0
- package/dist/Context/getHttpPath.js +25 -0
- package/dist/Context/getHttpPath.js.map +1 -0
- package/dist/Context/getMutationParameters.d.ts +8 -0
- package/dist/Context/getMutationParameters.d.ts.map +1 -0
- package/dist/Context/getMutationParameters.js +25 -0
- package/dist/Context/getMutationParameters.js.map +1 -0
- package/dist/Context/getOperationId.d.ts +6 -0
- package/dist/Context/getOperationId.d.ts.map +1 -0
- package/dist/Context/getOperationId.js +21 -0
- package/dist/Context/getOperationId.js.map +1 -0
- package/dist/Context/getQueryParameters.d.ts +5 -0
- package/dist/Context/getQueryParameters.d.ts.map +1 -0
- package/dist/Context/getQueryParameters.js +33 -0
- package/dist/Context/getQueryParameters.js.map +1 -0
- package/dist/Context/index.d.ts +7 -0
- package/dist/Context/index.d.ts.map +1 -0
- package/dist/Context/index.js +12 -0
- package/dist/Context/index.js.map +1 -0
- package/dist/Context/withSafeAttributes.d.ts +23 -0
- package/dist/Context/withSafeAttributes.d.ts.map +1 -0
- package/dist/Context/withSafeAttributes.js +39 -0
- package/dist/Context/withSafeAttributes.js.map +1 -0
- package/dist/Document/Document.d.ts +114 -0
- package/dist/Document/Document.d.ts.map +1 -0
- package/dist/Document/Document.js +285 -0
- package/dist/Document/Document.js.map +1 -0
- package/dist/Document/MemoryDocument.d.ts +34 -0
- package/dist/Document/MemoryDocument.d.ts.map +1 -0
- package/dist/Document/MemoryDocument.js +103 -0
- package/dist/Document/MemoryDocument.js.map +1 -0
- package/dist/Document/__tests__/__helpers.d.ts +18 -0
- package/dist/Document/__tests__/__helpers.d.ts.map +1 -0
- package/dist/Document/__tests__/__helpers.js +28 -0
- package/dist/Document/__tests__/__helpers.js.map +1 -0
- package/dist/Document/index.d.ts +5 -0
- package/dist/Document/index.d.ts.map +1 -0
- package/dist/Document/index.js +11 -0
- package/dist/Document/index.js.map +1 -0
- package/dist/Operation/Operation.d.ts +95 -0
- package/dist/Operation/Operation.d.ts.map +1 -0
- package/dist/Operation/Operation.js +301 -0
- package/dist/Operation/Operation.js.map +1 -0
- package/dist/Operation/errors/AccessDeniedError.d.ts +22 -0
- package/dist/Operation/errors/AccessDeniedError.d.ts.map +1 -0
- package/dist/Operation/errors/AccessDeniedError.js +29 -0
- package/dist/Operation/errors/AccessDeniedError.js.map +1 -0
- package/dist/Operation/errors/CommonError.d.ts +30 -0
- package/dist/Operation/errors/CommonError.d.ts.map +1 -0
- package/dist/Operation/errors/CommonError.js +39 -0
- package/dist/Operation/errors/CommonError.js.map +1 -0
- package/dist/Operation/errors/DocumentExistsError.d.ts +27 -0
- package/dist/Operation/errors/DocumentExistsError.d.ts.map +1 -0
- package/dist/Operation/errors/DocumentExistsError.js +35 -0
- package/dist/Operation/errors/DocumentExistsError.js.map +1 -0
- package/dist/Operation/errors/DocumentNotFoundError.d.ts +28 -0
- package/dist/Operation/errors/DocumentNotFoundError.d.ts.map +1 -0
- package/dist/Operation/errors/DocumentNotFoundError.js +36 -0
- package/dist/Operation/errors/DocumentNotFoundError.js.map +1 -0
- package/dist/Operation/errors/InvalidParametersError.d.ts +27 -0
- package/dist/Operation/errors/InvalidParametersError.d.ts.map +1 -0
- package/dist/Operation/errors/InvalidParametersError.js +34 -0
- package/dist/Operation/errors/InvalidParametersError.js.map +1 -0
- package/dist/Operation/errors/UnauthorizedError.d.ts +25 -0
- package/dist/Operation/errors/UnauthorizedError.d.ts.map +1 -0
- package/dist/Operation/errors/UnauthorizedError.js +32 -0
- package/dist/Operation/errors/UnauthorizedError.js.map +1 -0
- package/dist/Operation/errors/UnprocessibleConditionError.d.ts +29 -0
- package/dist/Operation/errors/UnprocessibleConditionError.d.ts.map +1 -0
- package/dist/Operation/errors/UnprocessibleConditionError.js +36 -0
- package/dist/Operation/errors/UnprocessibleConditionError.js.map +1 -0
- package/dist/Operation/errors/index.d.ts +9 -0
- package/dist/Operation/errors/index.d.ts.map +1 -0
- package/dist/Operation/errors/index.js +21 -0
- package/dist/Operation/errors/index.js.map +1 -0
- package/dist/Operation/helpers/index.d.ts +4 -0
- package/dist/Operation/helpers/index.d.ts.map +1 -0
- package/dist/Operation/helpers/index.js +9 -0
- package/dist/Operation/helpers/index.js.map +1 -0
- package/dist/Operation/helpers/withActivity.d.ts +16 -0
- package/dist/Operation/helpers/withActivity.d.ts.map +1 -0
- package/dist/Operation/helpers/withActivity.js +23 -0
- package/dist/Operation/helpers/withActivity.js.map +1 -0
- package/dist/Operation/index.d.ts +14 -0
- package/dist/Operation/index.d.ts.map +1 -0
- package/dist/Operation/index.js +40 -0
- package/dist/Operation/index.js.map +1 -0
- package/dist/Operation/operations/Create.d.ts +5 -0
- package/dist/Operation/operations/Create.d.ts.map +1 -0
- package/dist/Operation/operations/Create.js +44 -0
- package/dist/Operation/operations/Create.js.map +1 -0
- package/dist/Operation/operations/Delete.d.ts +5 -0
- package/dist/Operation/operations/Delete.d.ts.map +1 -0
- package/dist/Operation/operations/Delete.js +58 -0
- package/dist/Operation/operations/Delete.js.map +1 -0
- package/dist/Operation/operations/Index.d.ts +11 -0
- package/dist/Operation/operations/Index.d.ts.map +1 -0
- package/dist/Operation/operations/Index.js +128 -0
- package/dist/Operation/operations/Index.js.map +1 -0
- package/dist/Operation/operations/List.d.ts +5 -0
- package/dist/Operation/operations/List.d.ts.map +1 -0
- package/dist/Operation/operations/List.js +48 -0
- package/dist/Operation/operations/List.js.map +1 -0
- package/dist/Operation/operations/Read.d.ts +5 -0
- package/dist/Operation/operations/Read.d.ts.map +1 -0
- package/dist/Operation/operations/Read.js +50 -0
- package/dist/Operation/operations/Read.js.map +1 -0
- package/dist/Operation/operations/Update.d.ts +5 -0
- package/dist/Operation/operations/Update.d.ts.map +1 -0
- package/dist/Operation/operations/Update.js +54 -0
- package/dist/Operation/operations/Update.js.map +1 -0
- package/dist/Operation/security/JwtAuthorization.d.ts +67 -0
- package/dist/Operation/security/JwtAuthorization.d.ts.map +1 -0
- package/dist/Operation/security/JwtAuthorization.js +148 -0
- package/dist/Operation/security/JwtAuthorization.js.map +1 -0
- package/dist/Operation/security/LambdaAuthorization.d.ts +30 -0
- package/dist/Operation/security/LambdaAuthorization.d.ts.map +1 -0
- package/dist/Operation/security/LambdaAuthorization.js +77 -0
- package/dist/Operation/security/LambdaAuthorization.js.map +1 -0
- package/dist/Operation/security/index.d.ts +8 -0
- package/dist/Operation/security/index.d.ts.map +1 -0
- package/dist/Operation/security/index.js +17 -0
- package/dist/Operation/security/index.js.map +1 -0
- package/dist/Operation/security/systemAuthorization.d.ts +5 -0
- package/dist/Operation/security/systemAuthorization.d.ts.map +1 -0
- package/dist/Operation/security/systemAuthorization.js +24 -0
- package/dist/Operation/security/systemAuthorization.js.map +1 -0
- package/dist/Operation/security/userAuthorization.d.ts +11 -0
- package/dist/Operation/security/userAuthorization.d.ts.map +1 -0
- package/dist/Operation/security/userAuthorization.js +36 -0
- package/dist/Operation/security/userAuthorization.js.map +1 -0
- package/dist/Operation/security/verifyToken.d.ts +6 -0
- package/dist/Operation/security/verifyToken.d.ts.map +1 -0
- package/dist/Operation/security/verifyToken.js +15 -0
- package/dist/Operation/security/verifyToken.js.map +1 -0
- package/dist/Service/Service.d.ts +62 -0
- package/dist/Service/Service.d.ts.map +1 -0
- package/dist/Service/Service.js +213 -0
- package/dist/Service/Service.js.map +1 -0
- package/dist/Service/authorize.d.ts +26 -0
- package/dist/Service/authorize.d.ts.map +1 -0
- package/dist/Service/authorize.js +40 -0
- package/dist/Service/authorize.js.map +1 -0
- package/dist/Service/errors/InvalidInputError.d.ts +29 -0
- package/dist/Service/errors/InvalidInputError.d.ts.map +1 -0
- package/dist/Service/errors/InvalidInputError.js +36 -0
- package/dist/Service/errors/InvalidInputError.js.map +1 -0
- package/dist/Service/errors/InvalidOutputError.d.ts +29 -0
- package/dist/Service/errors/InvalidOutputError.d.ts.map +1 -0
- package/dist/Service/errors/InvalidOutputError.js +36 -0
- package/dist/Service/errors/InvalidOutputError.js.map +1 -0
- package/dist/Service/errors/OperationError.d.ts +30 -0
- package/dist/Service/errors/OperationError.d.ts.map +1 -0
- package/dist/Service/errors/OperationError.js +61 -0
- package/dist/Service/errors/OperationError.js.map +1 -0
- package/dist/Service/errors/OperationNotFoundError.d.ts +38 -0
- package/dist/Service/errors/OperationNotFoundError.d.ts.map +1 -0
- package/dist/Service/errors/OperationNotFoundError.js +45 -0
- package/dist/Service/errors/OperationNotFoundError.js.map +1 -0
- package/dist/Service/errors/index.d.ts +8 -0
- package/dist/Service/errors/index.d.ts.map +1 -0
- package/dist/Service/errors/index.js +15 -0
- package/dist/Service/errors/index.js.map +1 -0
- package/dist/Service/errors/logOperationError.d.ts +35 -0
- package/dist/Service/errors/logOperationError.d.ts.map +1 -0
- package/dist/Service/errors/logOperationError.js +47 -0
- package/dist/Service/errors/logOperationError.js.map +1 -0
- package/dist/Service/errors/maskSecrets.d.ts +13 -0
- package/dist/Service/errors/maskSecrets.d.ts.map +1 -0
- package/dist/Service/errors/maskSecrets.js +57 -0
- package/dist/Service/errors/maskSecrets.js.map +1 -0
- package/dist/Service/index.d.ts +5 -0
- package/dist/Service/index.d.ts.map +1 -0
- package/dist/Service/index.js +25 -0
- package/dist/Service/index.js.map +1 -0
- package/dist/Service/logRequest.d.ts +5 -0
- package/dist/Service/logRequest.d.ts.map +1 -0
- package/dist/Service/logRequest.js +26 -0
- package/dist/Service/logRequest.js.map +1 -0
- package/dist/Service/spec/createSpec.d.ts +7 -0
- package/dist/Service/spec/createSpec.d.ts.map +1 -0
- package/dist/Service/spec/createSpec.js +56 -0
- package/dist/Service/spec/createSpec.js.map +1 -0
- package/dist/Service/spec/getErrorResponseDescription.d.ts +8 -0
- package/dist/Service/spec/getErrorResponseDescription.d.ts.map +1 -0
- package/dist/Service/spec/getErrorResponseDescription.js +15 -0
- package/dist/Service/spec/getErrorResponseDescription.js.map +1 -0
- package/dist/Service/spec/getHttpMethod.d.ts +4 -0
- package/dist/Service/spec/getHttpMethod.d.ts.map +1 -0
- package/dist/Service/spec/getHttpMethod.js +21 -0
- package/dist/Service/spec/getHttpMethod.js.map +1 -0
- package/dist/Service/spec/getOperation.d.ts +6 -0
- package/dist/Service/spec/getOperation.d.ts.map +1 -0
- package/dist/Service/spec/getOperation.js +71 -0
- package/dist/Service/spec/getOperation.js.map +1 -0
- package/dist/Service/spec/getOperationParameters.d.ts +6 -0
- package/dist/Service/spec/getOperationParameters.d.ts.map +1 -0
- package/dist/Service/spec/getOperationParameters.js +32 -0
- package/dist/Service/spec/getOperationParameters.js.map +1 -0
- package/dist/Service/spec/getServiceDefinitions.d.ts +6 -0
- package/dist/Service/spec/getServiceDefinitions.d.ts.map +1 -0
- package/dist/Service/spec/getServiceDefinitions.js +18 -0
- package/dist/Service/spec/getServiceDefinitions.js.map +1 -0
- package/dist/Service/spec/getServiceInfo.d.ts +7 -0
- package/dist/Service/spec/getServiceInfo.d.ts.map +1 -0
- package/dist/Service/spec/getServiceInfo.js +15 -0
- package/dist/Service/spec/getServiceInfo.js.map +1 -0
- package/dist/Service/spec/getServiceSecurityDefinitions.d.ts +6 -0
- package/dist/Service/spec/getServiceSecurityDefinitions.d.ts.map +1 -0
- package/dist/Service/spec/getServiceSecurityDefinitions.js +21 -0
- package/dist/Service/spec/getServiceSecurityDefinitions.js.map +1 -0
- package/dist/Service/spec/getServiceTags.d.ts +7 -0
- package/dist/Service/spec/getServiceTags.d.ts.map +1 -0
- package/dist/Service/spec/getServiceTags.js +19 -0
- package/dist/Service/spec/getServiceTags.js.map +1 -0
- package/dist/Service/spec/getSuccessStatusCode.d.ts +4 -0
- package/dist/Service/spec/getSuccessStatusCode.d.ts.map +1 -0
- package/dist/Service/spec/getSuccessStatusCode.js +14 -0
- package/dist/Service/spec/getSuccessStatusCode.js.map +1 -0
- package/dist/Service/spec/index.d.ts +3 -0
- package/dist/Service/spec/index.d.ts.map +1 -0
- package/dist/Service/spec/index.js +9 -0
- package/dist/Service/spec/index.js.map +1 -0
- package/dist/Service/spec/validateSpec.d.ts +5 -0
- package/dist/Service/spec/validateSpec.d.ts.map +1 -0
- package/dist/Service/spec/validateSpec.js +21 -0
- package/dist/Service/spec/validateSpec.js.map +1 -0
- package/dist/Service/test/createAccessToken.d.ts +9 -0
- package/dist/Service/test/createAccessToken.d.ts.map +1 -0
- package/dist/Service/test/createAccessToken.js +16 -0
- package/dist/Service/test/createAccessToken.js.map +1 -0
- package/dist/Service/test/ensureItem.d.ts +5 -0
- package/dist/Service/test/ensureItem.d.ts.map +1 -0
- package/dist/Service/test/ensureItem.js +13 -0
- package/dist/Service/test/ensureItem.js.map +1 -0
- package/dist/Service/test/ensureNoItem.d.ts +5 -0
- package/dist/Service/test/ensureNoItem.d.ts.map +1 -0
- package/dist/Service/test/ensureNoItem.js +13 -0
- package/dist/Service/test/ensureNoItem.js.map +1 -0
- package/dist/Service/test/execute.d.ts +44 -0
- package/dist/Service/test/execute.d.ts.map +1 -0
- package/dist/Service/test/execute.js +65 -0
- package/dist/Service/test/execute.js.map +1 -0
- package/dist/Service/test/findItem.d.ts +7 -0
- package/dist/Service/test/findItem.d.ts.map +1 -0
- package/dist/Service/test/findItem.js +16 -0
- package/dist/Service/test/findItem.js.map +1 -0
- package/dist/Service/test/firstItemGet.d.ts +5 -0
- package/dist/Service/test/firstItemGet.d.ts.map +1 -0
- package/dist/Service/test/firstItemGet.js +15 -0
- package/dist/Service/test/firstItemGet.js.map +1 -0
- package/dist/Service/test/index.d.ts +10 -0
- package/dist/Service/test/index.d.ts.map +1 -0
- package/dist/Service/test/index.js +36 -0
- package/dist/Service/test/index.js.map +1 -0
- package/dist/Service/test/keys.d.ts +5 -0
- package/dist/Service/test/keys.d.ts.map +1 -0
- package/dist/Service/test/keys.js +74 -0
- package/dist/Service/test/keys.js.map +1 -0
- package/dist/Service/test/wait.d.ts +4 -0
- package/dist/Service/test/wait.d.ts.map +1 -0
- package/dist/Service/test/wait.js +6 -0
- package/dist/Service/test/wait.js.map +1 -0
- package/dist/Service/useComposerMiddleware.d.ts +11 -0
- package/dist/Service/useComposerMiddleware.d.ts.map +1 -0
- package/dist/Service/useComposerMiddleware.js +41 -0
- package/dist/Service/useComposerMiddleware.js.map +1 -0
- package/dist/Service/useOasMiddleware.d.ts +16 -0
- package/dist/Service/useOasMiddleware.d.ts.map +1 -0
- package/dist/Service/useOasMiddleware.js +53 -0
- package/dist/Service/useOasMiddleware.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/eslint.config.mjs +32 -52
- package/example/documents/Profile/Profile.ts +8 -0
- package/example/documents/Profile/Profile.yaml +6 -0
- package/example/documents/Profile/ProfileAttributes.d.ts +5 -0
- package/example/documents/Profile/index.ts +3 -0
- package/example/documents/index.ts +5 -0
- package/example/index.ts +38 -0
- package/example/lib/createActivity.ts +28 -0
- package/example/lib/index.ts +24 -0
- package/example/operations/Profile/CreateProfile.ts +9 -0
- package/example/operations/Profile/DeleteProfile.ts +9 -0
- package/example/operations/Profile/IndexProfiles.ts +9 -0
- package/example/operations/Profile/ReadProfile.ts +9 -0
- package/example/operations/Profile/ReadProfileSystem.ts +9 -0
- package/example/operations/Profile/UpdateProfile.ts +9 -0
- package/example/operations/Service/Health.ts +11 -0
- package/example/operations/index.ts +22 -0
- package/example/security/index.ts +25 -0
- package/jest.config.mjs +7 -0
- package/package.json +34 -24
- package/src/Component/Component.ts +120 -0
- package/src/Component/__tests__/Component.test.ts +161 -0
- package/src/Component/index.ts +7 -0
- package/src/Context/Context.ts +217 -0
- package/src/Context/Request.ts +41 -0
- package/src/Context/__tests__/Context.test.ts +271 -0
- package/src/Context/__tests__/__helpers.ts +86 -0
- package/src/Context/getHttpMethod.ts +21 -0
- package/src/Context/getHttpPath.ts +34 -0
- package/src/Context/getMutationParameters.ts +35 -0
- package/src/Context/getOperationId.ts +23 -0
- package/src/Context/getQueryParameters.ts +45 -0
- package/src/Context/index.ts +12 -0
- package/src/Context/withSafeAttributes.ts +39 -0
- package/src/Document/Document.ts +448 -0
- package/src/Document/MemoryDocument.ts +152 -0
- package/src/Document/__tests__/MemoryDocument.test.ts +406 -0
- package/src/Document/__tests__/__helpers.ts +40 -0
- package/src/Document/index.ts +11 -0
- package/src/Operation/Operation.ts +401 -0
- package/src/Operation/__tests__/Operation.test.ts +142 -0
- package/src/Operation/errors/AccessDeniedError.ts +25 -0
- package/src/Operation/errors/CommonError.ts +41 -0
- package/src/Operation/errors/DocumentExistsError.ts +33 -0
- package/src/Operation/errors/DocumentNotFoundError.ts +34 -0
- package/src/Operation/errors/InvalidParametersError.ts +30 -0
- package/src/Operation/errors/UnauthorizedError.ts +28 -0
- package/src/Operation/errors/UnprocessibleConditionError.ts +32 -0
- package/src/Operation/errors/__tests__/InvalidParametersError.test.ts +20 -0
- package/src/Operation/errors/__tests__/UnprocessibleConditionError.test.ts +20 -0
- package/src/Operation/errors/index.ts +17 -0
- package/src/Operation/helpers/index.ts +9 -0
- package/src/Operation/helpers/withActivity.ts +43 -0
- package/src/Operation/index.ts +29 -0
- package/src/Operation/operations/Create.ts +49 -0
- package/src/Operation/operations/Delete.ts +65 -0
- package/src/Operation/operations/Index.ts +164 -0
- package/src/Operation/operations/List.ts +62 -0
- package/src/Operation/operations/Read.ts +55 -0
- package/src/Operation/operations/Update.ts +60 -0
- package/src/Operation/operations/__tests__/Create.test.ts +153 -0
- package/src/Operation/operations/__tests__/Delete.test.ts +163 -0
- package/src/Operation/operations/__tests__/Index.test.ts +209 -0
- package/src/Operation/operations/__tests__/List.test.ts +146 -0
- package/src/Operation/operations/__tests__/Read.test.ts +152 -0
- package/src/Operation/operations/__tests__/Update.test.ts +158 -0
- package/src/Operation/security/JwtAuthorization.ts +247 -0
- package/src/Operation/security/LambdaAuthorization.ts +103 -0
- package/src/Operation/security/__tests__/JwtAuthorization.test.ts +230 -0
- package/src/Operation/security/__tests__/LambdaAuthorization.test.ts +63 -0
- package/src/Operation/security/__tests__/userAuthorization.test.ts +42 -0
- package/src/Operation/security/index.ts +15 -0
- package/src/Operation/security/systemAuthorization.ts +23 -0
- package/src/Operation/security/userAuthorization.ts +47 -0
- package/src/Operation/security/verifyToken.ts +22 -0
- package/src/Service/Service.ts +317 -0
- package/src/Service/__tests__/Service.test.ts +229 -0
- package/src/Service/authorize.ts +80 -0
- package/src/Service/errors/InvalidInputError.ts +40 -0
- package/src/Service/errors/InvalidOutputError.ts +40 -0
- package/src/Service/errors/OperationError.ts +74 -0
- package/src/{errors → Service/errors}/OperationError.yaml +7 -10
- package/src/Service/errors/OperationErrorAttributes.d.ts +12 -0
- package/src/Service/errors/OperationNotFoundError.ts +45 -0
- package/src/Service/errors/__tests__/OperationError.test.ts +17 -0
- package/src/Service/errors/__tests__/maskSecrets.test.ts +92 -0
- package/src/Service/errors/index.ts +18 -0
- package/src/Service/errors/logOperationError.ts +72 -0
- package/src/Service/errors/maskSecrets.ts +65 -0
- package/src/Service/index.ts +9 -0
- package/src/Service/logRequest.ts +50 -0
- package/src/Service/spec/__tests__/validateSpec.test.ts +10 -0
- package/src/Service/spec/createSpec.ts +68 -0
- package/src/Service/spec/getErrorResponseDescription.ts +20 -0
- package/src/Service/spec/getHttpMethod.ts +20 -0
- package/src/Service/spec/getOperation.ts +99 -0
- package/src/Service/spec/getOperationParameters.ts +43 -0
- package/src/Service/spec/getServiceDefinitions.ts +23 -0
- package/src/Service/spec/getServiceInfo.ts +18 -0
- package/src/Service/spec/getServiceSecurityDefinitions.ts +26 -0
- package/src/Service/spec/getServiceTags.ts +23 -0
- package/src/Service/spec/getSuccessStatusCode.ts +15 -0
- package/src/Service/spec/index.ts +5 -0
- package/src/Service/spec/validateSpec.ts +22 -0
- package/src/Service/test/__tests__/createAccessToken.test.ts +104 -0
- package/src/Service/test/__tests__/ensureItem.test.ts +41 -0
- package/src/Service/test/__tests__/ensureNoItem.test.ts +49 -0
- package/src/Service/test/__tests__/execute.test.ts +125 -0
- package/src/Service/test/__tests__/findItem.test.ts +45 -0
- package/src/Service/test/__tests__/firstItemGet.test.ts +50 -0
- package/src/Service/test/__tests__/wait.test.ts +66 -0
- package/src/Service/test/createAccessToken.ts +28 -0
- package/src/Service/test/ensureItem.ts +9 -0
- package/src/Service/test/ensureNoItem.ts +9 -0
- package/src/Service/test/execute.ts +112 -0
- package/src/Service/test/findItem.ts +22 -0
- package/src/Service/test/firstItemGet.ts +18 -0
- package/src/Service/test/index.ts +19 -0
- package/src/Service/test/keys.ts +75 -0
- package/src/Service/test/wait.ts +5 -0
- package/src/Service/useComposerMiddleware.ts +56 -0
- package/src/Service/useOasMiddleware.ts +69 -0
- package/src/index.ts +12 -0
- package/tsconfig.json +26 -0
- package/examples/CreateProfile.js +0 -40
- package/examples/DeleteProfile.js +0 -6
- package/examples/Health.js +0 -8
- package/examples/IndexProfiles.js +0 -6
- package/examples/Profile.js +0 -8
- package/examples/Profile.yaml +0 -4
- package/examples/ReadProfile.js +0 -18
- package/examples/UpdateProfile.js +0 -25
- package/examples/index.js +0 -29
- package/src/Component.js +0 -59
- package/src/Component.spec.js +0 -65
- package/src/Document.js +0 -310
- package/src/Document.spec.js +0 -331
- package/src/Operation.js +0 -258
- package/src/Operation.spec.js +0 -474
- package/src/Service.js +0 -207
- package/src/Service.spec.js +0 -388
- package/src/errors/AccessDeniedError.js +0 -11
- package/src/errors/CommonError.js +0 -19
- package/src/errors/DocumentExistsError.js +0 -15
- package/src/errors/DocumentNotFoundError.js +0 -15
- package/src/errors/InvalidInputError.js +0 -19
- package/src/errors/InvalidOutputError.js +0 -20
- package/src/errors/InvalidParametersError.js +0 -11
- package/src/errors/OperationError.js +0 -44
- package/src/errors/OperationNotFoundError.js +0 -16
- package/src/errors/UnauthorizedError.js +0 -11
- package/src/errors/UnprocessibleConditionError.js +0 -11
- package/src/errors/index.js +0 -11
- package/src/helpers/asSafeClass.js +0 -22
- package/src/helpers/authorize.js +0 -44
- package/src/helpers/createContext.js +0 -96
- package/src/helpers/createSchemasMap.js +0 -37
- package/src/helpers/createSpec.js +0 -196
- package/src/helpers/defaultId.js +0 -30
- package/src/helpers/defaultSummary.js +0 -15
- package/src/helpers/defaultTags.js +0 -16
- package/src/helpers/getComponentTitle.js +0 -22
- package/src/helpers/getDefaultSchemaAttributes.js +0 -32
- package/src/helpers/getHttpMethod.js +0 -19
- package/src/helpers/getIdPrefix.js +0 -7
- package/src/helpers/getOrFail.js +0 -24
- package/src/helpers/getOrFail.spec.js +0 -17
- package/src/helpers/getSuccessStatusCode.js +0 -15
- package/src/helpers/handler.js +0 -21
- package/src/helpers/loadSync.js +0 -14
- package/src/helpers/logError.js +0 -33
- package/src/helpers/logRequest.js +0 -36
- package/src/helpers/maskSecrets.js +0 -42
- package/src/helpers/specMiddleware.js +0 -81
- package/src/index.d.ts +0 -350
- package/src/index.js +0 -35
- package/src/operations/Create.js +0 -39
- package/src/operations/Delete.js +0 -54
- package/src/operations/Index.js +0 -107
- package/src/operations/Read.js +0 -46
- package/src/operations/Update.js +0 -50
- package/src/security/JwtAuthorization.js +0 -125
- package/src/security/SystemAuthorization.js +0 -73
- package/src/security/index.js +0 -9
- package/src/security/verifyToken.js +0 -17
- package/src/test/createAccessToken.js +0 -23
- package/src/test/execute.js +0 -84
- package/src/test/index.js +0 -11
- package/src/test/keys.js +0 -39
- package/src/test/wait.js +0 -5
- /package/{specs → .composer}/Documents.yaml +0 -0
- /package/{specs → .composer}/Enums.yaml +0 -0
- /package/{specs → .composer}/Operations.yaml +0 -0
- /package/{specs → .composer}/Parameters.yaml +0 -0
- /package/{specs → .composer}/Scenarios.yaml +0 -0
- /package/{specs → .composer}/Schemas.yaml +0 -0
package/src/Document.spec.js
DELETED
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const loadSync = require('./helpers/loadSync')
|
|
4
|
-
const { expect } = require('chai')
|
|
5
|
-
const { Document } = require('src')
|
|
6
|
-
const { Validator } = require('@kravc/schema')
|
|
7
|
-
|
|
8
|
-
const expectError = async (fn) => {
|
|
9
|
-
try {
|
|
10
|
-
await fn()
|
|
11
|
-
|
|
12
|
-
} catch (error) {
|
|
13
|
-
return error
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
throw new Error('Expected error has not been thrown')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
class Profile extends Document {}
|
|
21
|
-
Profile.schema = loadSync('examples/Profile.yaml')
|
|
22
|
-
|
|
23
|
-
describe('Document', () => {
|
|
24
|
-
const validator = new Validator([ Profile.schema ])
|
|
25
|
-
const identity = { sub: 'USER_ID' }
|
|
26
|
-
const getContext = () => ({ validator, identity })
|
|
27
|
-
|
|
28
|
-
let id
|
|
29
|
-
|
|
30
|
-
describe('Document.create(context, query, mutation)', () => {
|
|
31
|
-
it('creates document', async () => {
|
|
32
|
-
const context = getContext()
|
|
33
|
-
const profile = await Profile.create(context, { name: 'Oleksandr' })
|
|
34
|
-
|
|
35
|
-
expect(profile.id).to.exist
|
|
36
|
-
expect(profile.attributes.name).to.eql('Oleksandr')
|
|
37
|
-
expect(profile.attributes.createdAt).to.exist
|
|
38
|
-
expect(profile.attributes.createdBy).to.exist
|
|
39
|
-
|
|
40
|
-
id = profile.id
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it('creates document via mutation', async () => {
|
|
44
|
-
const context = getContext()
|
|
45
|
-
const profile = await Profile.create(context, {}, { name: 'Olga' })
|
|
46
|
-
|
|
47
|
-
expect(profile.id).to.exist
|
|
48
|
-
expect(profile.attributes.name).to.eql('Olga')
|
|
49
|
-
expect(profile.attributes.createdAt).to.exist
|
|
50
|
-
expect(profile.attributes.createdBy).to.exist
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
it('creates document with custom ID', async () => {
|
|
54
|
-
const context = getContext()
|
|
55
|
-
const profile = await Profile.create(context, {}, { id: 'CUSTOM_ID', name: 'Olga' })
|
|
56
|
-
|
|
57
|
-
expect(profile.id).to.eql('CUSTOM_ID')
|
|
58
|
-
expect(profile.attributes.name).to.eql('Olga')
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('creates document without identity in context as SYSTEM', async () => {
|
|
62
|
-
const context = { validator }
|
|
63
|
-
const profile = await Profile.create(context, { name: 'Oleg' })
|
|
64
|
-
|
|
65
|
-
expect(profile.id).to.exist
|
|
66
|
-
expect(profile.attributes.name).to.eql('Oleg')
|
|
67
|
-
expect(profile.attributes.createdAt).to.exist
|
|
68
|
-
expect(profile.attributes.createdBy).to.eql('SYSTEM')
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('returns exiting document from the context', async () => {
|
|
72
|
-
const context = getContext()
|
|
73
|
-
const profile = await Profile.create(context, { name: 'Volodymyr' })
|
|
74
|
-
const existingProfile = await Profile.create({ ...context, document: profile }, { name: 'Volodymyr' })
|
|
75
|
-
|
|
76
|
-
expect(profile.id).to.eql(existingProfile.id)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('throws "DocumentExistsError" if document already exists', async () => {
|
|
80
|
-
const context = getContext()
|
|
81
|
-
const { id } = await Profile.create(context, {}, { name: 'Artem' })
|
|
82
|
-
const error = await expectError(() => Profile.create(context, {}, { id, name: 'Liam' }))
|
|
83
|
-
|
|
84
|
-
expect(error.code).to.eql('DocumentExistsError')
|
|
85
|
-
expect(error.message).to.include('Profile already exists {')
|
|
86
|
-
})
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
describe('Document.read(context, query)', () => {
|
|
90
|
-
it('returns document', async () => {
|
|
91
|
-
const context = getContext()
|
|
92
|
-
const profile = await Profile.read(context, { id })
|
|
93
|
-
|
|
94
|
-
expect(profile).to.exist
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it('throws "DocumentNotFoundError" if document not found', async () => {
|
|
98
|
-
const error = await expectError(() => Profile.read(
|
|
99
|
-
{ validator }, {}))
|
|
100
|
-
|
|
101
|
-
expect(error.code).to.eql('DocumentNotFoundError')
|
|
102
|
-
expect(error.message).to.include('Profile not found {')
|
|
103
|
-
})
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
describe('Document.update(context, query, mutation)', () => {
|
|
107
|
-
it('updates document', async () => {
|
|
108
|
-
const context = getContext()
|
|
109
|
-
await Profile.update(context, { id }, { name: 'Margarita' })
|
|
110
|
-
|
|
111
|
-
const profile = await Profile.read(context, { id })
|
|
112
|
-
|
|
113
|
-
expect(profile.attributes.name).to.eql('Margarita')
|
|
114
|
-
expect(profile.attributes.updatedAt).to.exist
|
|
115
|
-
expect(profile.attributes.updatedBy).to.exist
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
it('updates document without identity in context as SYSTEM', async () => {
|
|
119
|
-
const context = { validator }
|
|
120
|
-
const { id } = await Profile.create(context, { name: 'Gustav' })
|
|
121
|
-
|
|
122
|
-
const profile = await Profile.update(context, { id }, { name: 'Jack' })
|
|
123
|
-
|
|
124
|
-
expect(profile.attributes.updatedAt).to.exist
|
|
125
|
-
expect(profile.attributes.updatedBy).to.eql('SYSTEM')
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
it('throws "DocumentNotFoundError" if document not found', async () => {
|
|
129
|
-
const error = await expectError(() => Profile.update(
|
|
130
|
-
{ validator }, {}, { name: 'Liam' }))
|
|
131
|
-
|
|
132
|
-
expect(error.code).to.eql('DocumentNotFoundError')
|
|
133
|
-
expect(error.message).to.include('Profile not found {')
|
|
134
|
-
})
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
describe('Document.delete(context, query)', () => {
|
|
138
|
-
it('deletes document', async () => {
|
|
139
|
-
const context = getContext()
|
|
140
|
-
await Profile.delete(context, { id })
|
|
141
|
-
|
|
142
|
-
try {
|
|
143
|
-
await Profile.read(context, { id })
|
|
144
|
-
|
|
145
|
-
} catch (error) {
|
|
146
|
-
expect(error.code).to.eql('DocumentNotFoundError')
|
|
147
|
-
|
|
148
|
-
return
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
throw new Error('Document has not been deleted')
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
it('throws "DocumentNotFoundError" if document not found', async () => {
|
|
155
|
-
const error = await expectError(() => Profile.delete(
|
|
156
|
-
{ validator }, {}))
|
|
157
|
-
|
|
158
|
-
expect(error.code).to.eql('DocumentNotFoundError')
|
|
159
|
-
expect(error.message).to.include('Profile not found {')
|
|
160
|
-
})
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
describe('Document.index(context, query)', () => {
|
|
164
|
-
it('returns documents', async () => {
|
|
165
|
-
const context = getContext()
|
|
166
|
-
await Profile.reset()
|
|
167
|
-
|
|
168
|
-
let result
|
|
169
|
-
|
|
170
|
-
result = await Profile.index(context)
|
|
171
|
-
|
|
172
|
-
expect(result.objects.length).to.eql(0)
|
|
173
|
-
expect(result.count).to.eql(0)
|
|
174
|
-
|
|
175
|
-
await Profile.create(context, { name: 'Oleksandr' })
|
|
176
|
-
await Profile.create(context, { name: 'Dasha' })
|
|
177
|
-
await Profile.create(context, { name: 'Veronica' })
|
|
178
|
-
|
|
179
|
-
result = await Profile.index(context)
|
|
180
|
-
|
|
181
|
-
expect(result.objects.length).to.eql(3)
|
|
182
|
-
expect(result.count).to.eql(3)
|
|
183
|
-
|
|
184
|
-
result = await Profile.indexAll(context, { name: 'Dasha' })
|
|
185
|
-
expect(result.count).to.eql(1)
|
|
186
|
-
|
|
187
|
-
result = await Profile.indexAll(context)
|
|
188
|
-
expect(result.count).to.eql(3)
|
|
189
|
-
})
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
describe('Document.bodySchema', () => {
|
|
193
|
-
it('returns document body schema', async () => {
|
|
194
|
-
expect(Profile.bodySchema).to.exist
|
|
195
|
-
})
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
describe('.delete()', () => {
|
|
199
|
-
it('deletes document', async () => {
|
|
200
|
-
const context = getContext()
|
|
201
|
-
const profile = await Profile.create(context, { name: 'Oleksandr' })
|
|
202
|
-
|
|
203
|
-
const { id } = profile
|
|
204
|
-
|
|
205
|
-
await profile.delete()
|
|
206
|
-
|
|
207
|
-
try {
|
|
208
|
-
await Profile.read(context, { id })
|
|
209
|
-
|
|
210
|
-
} catch (error) {
|
|
211
|
-
expect(error.code).to.eql('DocumentNotFoundError')
|
|
212
|
-
|
|
213
|
-
return
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
throw new Error('Document has not been deleted')
|
|
217
|
-
})
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
describe('.update(mutation, shouldMutate = false)', () => {
|
|
221
|
-
it('updates document', async () => {
|
|
222
|
-
const context = getContext()
|
|
223
|
-
const profile = await Profile.create(context, { name: 'Oleksandr' })
|
|
224
|
-
|
|
225
|
-
const updatedProfile = await profile.update({ name: 'Anton' })
|
|
226
|
-
|
|
227
|
-
expect(profile.attributes.name).to.eql('Oleksandr')
|
|
228
|
-
expect(updatedProfile.attributes.name).to.eql('Anton')
|
|
229
|
-
})
|
|
230
|
-
|
|
231
|
-
it('updates and mutates document', async () => {
|
|
232
|
-
const context = getContext()
|
|
233
|
-
const profile = await Profile.create(context, { name: 'Oleksandr' })
|
|
234
|
-
|
|
235
|
-
await profile.update({ name: 'Anton' }, true)
|
|
236
|
-
|
|
237
|
-
expect(profile.attributes.name).to.eql('Anton')
|
|
238
|
-
})
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
describe('before*, after* callbacks', () => {
|
|
242
|
-
it('executes callbacks for create, update and delete mutations', async () => {
|
|
243
|
-
const callbacks = {}
|
|
244
|
-
|
|
245
|
-
class CustomProfile extends Profile {
|
|
246
|
-
static getPartition() {
|
|
247
|
-
return 'CustomProfile'
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
static beforeCreate(context, mutation) {
|
|
251
|
-
callbacks.beforeCreate = mutation
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
static beforeUpdate(context, query, mutation) {
|
|
255
|
-
callbacks.beforeUpdate = mutation
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
static beforeDelete(context, query) {
|
|
259
|
-
callbacks.beforeDelete = query
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
static afterCreate(context, profile) {
|
|
263
|
-
callbacks.afterCreate = profile
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
static afterUpdate(context, query, mutation, profile) {
|
|
267
|
-
callbacks.afterUpdate = profile
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
static afterDelete(context, query) {
|
|
271
|
-
callbacks.afterDelete = query
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
CustomProfile.schema = Profile.schema.clone('CustomProfile')
|
|
276
|
-
|
|
277
|
-
const validator = new Validator([ CustomProfile.schema ])
|
|
278
|
-
|
|
279
|
-
const { id } = await CustomProfile.create({ validator }, { name: 'Irina' })
|
|
280
|
-
|
|
281
|
-
const context = getContext()
|
|
282
|
-
await CustomProfile.update(context, { id, mutation: { name: 'Maria' } })
|
|
283
|
-
await CustomProfile.delete(context, { id })
|
|
284
|
-
|
|
285
|
-
expect(callbacks.beforeCreate).to.exist
|
|
286
|
-
expect(callbacks.afterCreate).to.exist
|
|
287
|
-
expect(callbacks.beforeUpdate).to.exist
|
|
288
|
-
expect(callbacks.afterUpdate).to.exist
|
|
289
|
-
expect(callbacks.beforeDelete).to.exist
|
|
290
|
-
expect(callbacks.afterDelete).to.exist
|
|
291
|
-
})
|
|
292
|
-
})
|
|
293
|
-
|
|
294
|
-
describe('.hasAttributeChanged(attributePath)', () => {
|
|
295
|
-
it('throws "Error" if context has no original document', async () => {
|
|
296
|
-
const context = getContext()
|
|
297
|
-
const profile = await Profile.create(context, { name: 'Sonya' })
|
|
298
|
-
|
|
299
|
-
try {
|
|
300
|
-
profile.hasAttributeChanged('name')
|
|
301
|
-
|
|
302
|
-
} catch (error) {
|
|
303
|
-
expect(error.message).to.eql('Original document is undefined')
|
|
304
|
-
|
|
305
|
-
return
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
throw new Error('Error has not been thrown')
|
|
309
|
-
})
|
|
310
|
-
|
|
311
|
-
it('returns true if attribute value has changed', async () => {
|
|
312
|
-
const context = getContext()
|
|
313
|
-
const profile = await Profile.create(context, { name: 'Sonya' })
|
|
314
|
-
|
|
315
|
-
await profile.update({ name: 'Sasha', age: 7 }, true)
|
|
316
|
-
|
|
317
|
-
expect(profile.hasAttributeChanged('name')).to.be.true
|
|
318
|
-
expect(profile.hasAttributeChanged('age')).to.be.true
|
|
319
|
-
})
|
|
320
|
-
|
|
321
|
-
it('returns false if attribute value has not changed', async () => {
|
|
322
|
-
const context = getContext()
|
|
323
|
-
const profile = await Profile.create(context, { name: 'Sonya' })
|
|
324
|
-
|
|
325
|
-
await profile.update({ name: 'Sonya', age: 5 }, true)
|
|
326
|
-
const hasNameChanged = profile.hasAttributeChanged('name')
|
|
327
|
-
|
|
328
|
-
expect(hasNameChanged).to.be.false
|
|
329
|
-
})
|
|
330
|
-
})
|
|
331
|
-
})
|
package/src/Operation.js
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { Schema } = require('@kravc/schema')
|
|
4
|
-
const { isEmpty, cloneDeep } = require('lodash')
|
|
5
|
-
|
|
6
|
-
const defaultId = require('./helpers/defaultId')
|
|
7
|
-
const defaultTags = require('./helpers/defaultTags')
|
|
8
|
-
const asSafeClass = require('./helpers/asSafeClass')
|
|
9
|
-
const defaultSummary = require('./helpers/defaultSummary')
|
|
10
|
-
|
|
11
|
-
class Operation {
|
|
12
|
-
static get types() {
|
|
13
|
-
return {
|
|
14
|
-
READ: 'read',
|
|
15
|
-
CREATE: 'create',
|
|
16
|
-
UPDATE: 'update',
|
|
17
|
-
DELETE: 'delete'
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static get type() {
|
|
22
|
-
return Operation.types.READ
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static get id() {
|
|
26
|
-
return defaultId(this)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static get tags() {
|
|
30
|
-
return defaultTags(this.Component)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static get summary() {
|
|
34
|
-
return defaultSummary(this.Component, this.componentAction)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
static get description() {
|
|
38
|
-
return ''
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static get security() {
|
|
42
|
-
return []
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static get errors() {
|
|
46
|
-
let errors = {}
|
|
47
|
-
|
|
48
|
-
for (const orRequirement of this.security) {
|
|
49
|
-
const andRequirements = Object.values(orRequirement)
|
|
50
|
-
|
|
51
|
-
for (const andRequirement of andRequirements) {
|
|
52
|
-
errors = { ...andRequirement.klass.errors, ...errors }
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (this.inputSchema) {
|
|
57
|
-
errors.InvalidInputError = {
|
|
58
|
-
statusCode: 400,
|
|
59
|
-
description: 'Invalid operation input, make sure operation parameters' +
|
|
60
|
-
' do match specification'
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
errors.InvalidParametersError = {
|
|
64
|
-
statusCode: 400,
|
|
65
|
-
description: 'Invalid operation parameters, input syntax is correct,' +
|
|
66
|
-
' but input values are not processible'
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (this.outputSchema) {
|
|
71
|
-
errors.InvalidOutputError = {
|
|
72
|
-
statusCode: 500,
|
|
73
|
-
description: 'Invalid output returned by the operation, this issue' +
|
|
74
|
-
' to be addressed by service developer'
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
errors.UnprocessibleConditionError = {
|
|
79
|
-
statusCode: 422,
|
|
80
|
-
description: 'Operation failed to process the request cause of expected' +
|
|
81
|
-
' exit condition'
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return errors
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
static get query() {
|
|
88
|
-
return {}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
static get mutation() {
|
|
92
|
-
const { type, Component } = this
|
|
93
|
-
|
|
94
|
-
if (Component) {
|
|
95
|
-
const { bodySchema, schema } = Component
|
|
96
|
-
const mutationSchema = bodySchema || schema
|
|
97
|
-
|
|
98
|
-
if (type === Operation.types.UPDATE) {
|
|
99
|
-
return mutationSchema.pure()
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (type === Operation.types.CREATE) {
|
|
103
|
-
return mutationSchema.clone()
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return null
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
static get mutationSchema() {
|
|
111
|
-
const { id, mutation: schemaOrSource } = this
|
|
112
|
-
|
|
113
|
-
if (!schemaOrSource) { return null }
|
|
114
|
-
|
|
115
|
-
return new Schema(schemaOrSource, `${id}InputMutation`)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
static get inputSchema() {
|
|
119
|
-
const { id } = this
|
|
120
|
-
let source = { ...this.query }
|
|
121
|
-
|
|
122
|
-
if (this.mutationSchema) {
|
|
123
|
-
source = {
|
|
124
|
-
...source,
|
|
125
|
-
mutation: {
|
|
126
|
-
$ref: `${id}InputMutation`,
|
|
127
|
-
required: true
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (isEmpty(source)) { return null }
|
|
133
|
-
|
|
134
|
-
return new Schema(source, `${id}Input`)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
static get output() {
|
|
138
|
-
if (!this.Component) { return null }
|
|
139
|
-
|
|
140
|
-
return {
|
|
141
|
-
data: {
|
|
142
|
-
$ref: this.Component.schema.id,
|
|
143
|
-
required: true
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
static get outputSchema() {
|
|
149
|
-
const { id, output: schemaOrSource } = this
|
|
150
|
-
|
|
151
|
-
if (!schemaOrSource) { return null }
|
|
152
|
-
|
|
153
|
-
return new Schema(schemaOrSource, `${id}Output`)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
static get Component() {
|
|
157
|
-
return null
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
static get componentAction() {
|
|
161
|
-
return this.type
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
static get componentActionMethod() {
|
|
165
|
-
const { Component, componentAction } = this
|
|
166
|
-
|
|
167
|
-
if (!Component) {
|
|
168
|
-
throw new Error(`Operation "${this.id}" expects component to be defined`)
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const componentActionMethod = Component[componentAction]
|
|
172
|
-
|
|
173
|
-
if (!componentActionMethod) {
|
|
174
|
-
throw new Error(`Operation "${this.id}" expects component action` +
|
|
175
|
-
` method "${Component.name}.${componentAction}(context, ...)" to be` +
|
|
176
|
-
' defined')
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return componentActionMethod.bind(Component)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
constructor(context) {
|
|
183
|
-
this._context = context
|
|
184
|
-
|
|
185
|
-
this._headers = {}
|
|
186
|
-
this._multiValueHeaders = {}
|
|
187
|
-
|
|
188
|
-
return asSafeClass(this)
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
setHeader(name, value, isMultiValue = false) {
|
|
192
|
-
if (isMultiValue) {
|
|
193
|
-
this._multiValueHeaders[name.toLowerCase()] = value
|
|
194
|
-
|
|
195
|
-
return
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
this._headers[name.toLowerCase()] = value
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
get context() {
|
|
202
|
-
return this._context
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
before() {
|
|
206
|
-
return
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
async action(parameters) {
|
|
210
|
-
const { Component } = this.constructor
|
|
211
|
-
|
|
212
|
-
if (!Component) {
|
|
213
|
-
return {}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const { componentActionMethod } = this.constructor
|
|
217
|
-
|
|
218
|
-
const { mutation, ...query } = parameters
|
|
219
|
-
|
|
220
|
-
const data = await (mutation
|
|
221
|
-
? componentActionMethod(this.context, query, mutation)
|
|
222
|
-
: componentActionMethod(this.context, query)
|
|
223
|
-
)
|
|
224
|
-
|
|
225
|
-
return { data }
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
after() {
|
|
229
|
-
return
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
async exec(_parameters) {
|
|
233
|
-
let parameters = cloneDeep(_parameters)
|
|
234
|
-
let result
|
|
235
|
-
|
|
236
|
-
const beforeResult = await this.before(parameters)
|
|
237
|
-
|
|
238
|
-
parameters = beforeResult
|
|
239
|
-
? beforeResult
|
|
240
|
-
: parameters
|
|
241
|
-
|
|
242
|
-
result = await this.action(parameters)
|
|
243
|
-
|
|
244
|
-
const afterResult = await this.after(parameters, result.data || result)
|
|
245
|
-
|
|
246
|
-
result = afterResult
|
|
247
|
-
? ( result.data ? { ...result, data: afterResult } : afterResult )
|
|
248
|
-
: result
|
|
249
|
-
|
|
250
|
-
return {
|
|
251
|
-
result,
|
|
252
|
-
headers: this._headers,
|
|
253
|
-
multiValueHeaders: this._multiValueHeaders
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
module.exports = Operation
|