@kravc/dos 1.12.6 → 2.0.0-alpha.1
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/{src → dist/Service}/errors/OperationError.yaml +7 -10
- 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 +35 -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 +9 -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/Service/errors/OperationError.yaml +29 -0
- 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 -352
- 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/Operation.spec.js
DELETED
|
@@ -1,474 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const loadSync = require('./helpers/loadSync')
|
|
4
|
-
const { expect } = require('chai')
|
|
5
|
-
const { Validator } = require('@kravc/schema')
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
Read,
|
|
9
|
-
Index,
|
|
10
|
-
Create,
|
|
11
|
-
Update,
|
|
12
|
-
Delete,
|
|
13
|
-
Document,
|
|
14
|
-
Component,
|
|
15
|
-
Operation
|
|
16
|
-
} = require('src')
|
|
17
|
-
|
|
18
|
-
class Profile extends Document {}
|
|
19
|
-
Profile.schema = loadSync('examples/Profile.yaml')
|
|
20
|
-
|
|
21
|
-
const validator = new Validator([ Profile.schema ])
|
|
22
|
-
const identity = { sub: 'USER_ID' }
|
|
23
|
-
const DEFAULT_CONTEXT = { validator, identity }
|
|
24
|
-
|
|
25
|
-
describe('Operation', () => {
|
|
26
|
-
describe('Helpers', () => {
|
|
27
|
-
describe('Create(Component, componentAction = \'create\')', () => {
|
|
28
|
-
it('returns "Create" operation class', () => {
|
|
29
|
-
const CreateProfile = Create(Profile)
|
|
30
|
-
|
|
31
|
-
expect(CreateProfile.id).eql('CreateProfile')
|
|
32
|
-
expect(CreateProfile.Component).eql(Profile)
|
|
33
|
-
expect(CreateProfile.componentAction).eql('create')
|
|
34
|
-
|
|
35
|
-
expect(CreateProfile.tags).to.include('Profiles')
|
|
36
|
-
expect(CreateProfile.summary).eql('Create profile')
|
|
37
|
-
expect(CreateProfile.description).to.be.empty
|
|
38
|
-
|
|
39
|
-
expect(CreateProfile.inputSchema.id).eql('CreateProfileInput')
|
|
40
|
-
expect(CreateProfile.inputSchema.source).to.deep.eql({
|
|
41
|
-
mutation: {
|
|
42
|
-
$ref: 'CreateProfileInputMutation',
|
|
43
|
-
required: true
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
expect(CreateProfile.mutationSchema.id).to.eql('CreateProfileInputMutation')
|
|
48
|
-
expect(CreateProfile.mutationSchema.source).to.deep.eql({
|
|
49
|
-
id: {
|
|
50
|
-
required: true,
|
|
51
|
-
type: 'string'
|
|
52
|
-
},
|
|
53
|
-
name: {
|
|
54
|
-
type: 'string'
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
expect(CreateProfile.outputSchema.id).to.eql('CreateProfileOutput')
|
|
59
|
-
expect(CreateProfile.outputSchema.source).to.deep.eql({
|
|
60
|
-
data: {
|
|
61
|
-
$ref: 'Profile',
|
|
62
|
-
required: true
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
expect(CreateProfile.errors.DocumentExistsError.statusCode).eql(422)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('throws error if "Component" argument is undefined', () => {
|
|
70
|
-
expect(() => Create()).to.throw('Argument "Component" is undefined')
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
describe('Read(Component, componentAction = \'read\')', () => {
|
|
75
|
-
it('returns "Read" operation class', () => {
|
|
76
|
-
const ReadProfile = Read(Profile)
|
|
77
|
-
|
|
78
|
-
expect(ReadProfile.id).eql('ReadProfile')
|
|
79
|
-
expect(ReadProfile.Component).eql(Profile)
|
|
80
|
-
expect(ReadProfile.componentAction).eql('read')
|
|
81
|
-
|
|
82
|
-
expect(ReadProfile.tags).to.include('Profiles')
|
|
83
|
-
expect(ReadProfile.summary).eql('Read profile')
|
|
84
|
-
expect(ReadProfile.description).to.be.empty
|
|
85
|
-
|
|
86
|
-
expect(ReadProfile.inputSchema.id).eql('ReadProfileInput')
|
|
87
|
-
expect(ReadProfile.inputSchema.source).to.deep.eql({
|
|
88
|
-
id: {
|
|
89
|
-
description: 'Profile ID',
|
|
90
|
-
required: true,
|
|
91
|
-
type: 'string'
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
expect(ReadProfile.outputSchema.id).to.eql('ReadProfileOutput')
|
|
96
|
-
expect(ReadProfile.outputSchema.source).to.deep.eql({
|
|
97
|
-
data: {
|
|
98
|
-
$ref: 'Profile',
|
|
99
|
-
required: true
|
|
100
|
-
}
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
expect(ReadProfile.mutationSchema).to.eql(null)
|
|
104
|
-
|
|
105
|
-
expect(ReadProfile.errors.DocumentNotFoundError.statusCode).eql(404)
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
it('throws error if "Component" argument is undefined', () => {
|
|
109
|
-
expect(() => Read()).to.throw('Argument "Component" is undefined')
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
describe('.exec(_parameters)', () => {
|
|
113
|
-
it('triggers "componentActionMethod" without mutation parameter', async () => {
|
|
114
|
-
Profile.reset()
|
|
115
|
-
|
|
116
|
-
const CreateProfile = Create(Profile)
|
|
117
|
-
const ReadProfiles = Read(Profile)
|
|
118
|
-
|
|
119
|
-
const { result: { data: { id } } } = await (
|
|
120
|
-
new CreateProfile(DEFAULT_CONTEXT)).exec({ mutation: { name: 'Taras' } }
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
const operation = new ReadProfiles(DEFAULT_CONTEXT)
|
|
124
|
-
const { result } = await operation.exec({ id })
|
|
125
|
-
|
|
126
|
-
expect(result.data).to.exist
|
|
127
|
-
})
|
|
128
|
-
})
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
describe('Update(Component, componentAction = \'update\')', () => {
|
|
132
|
-
it('returns "Update" operation class', () => {
|
|
133
|
-
const UpdateProfile = Update(Profile)
|
|
134
|
-
|
|
135
|
-
expect(UpdateProfile.id).eql('UpdateProfile')
|
|
136
|
-
expect(UpdateProfile.Component).eql(Profile)
|
|
137
|
-
expect(UpdateProfile.componentAction).eql('update')
|
|
138
|
-
|
|
139
|
-
expect(UpdateProfile.tags).to.include('Profiles')
|
|
140
|
-
expect(UpdateProfile.summary).eql('Update profile')
|
|
141
|
-
expect(UpdateProfile.description).to.be.empty
|
|
142
|
-
|
|
143
|
-
expect(UpdateProfile.inputSchema.id).eql('UpdateProfileInput')
|
|
144
|
-
expect(UpdateProfile.inputSchema.source).to.deep.eql({
|
|
145
|
-
id: {
|
|
146
|
-
description: 'Profile ID',
|
|
147
|
-
required: true,
|
|
148
|
-
type: 'string'
|
|
149
|
-
},
|
|
150
|
-
mutation: {
|
|
151
|
-
$ref: 'UpdateProfileInputMutation',
|
|
152
|
-
required: true
|
|
153
|
-
}
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
expect(UpdateProfile.mutationSchema.id).to.eql('UpdateProfileInputMutation')
|
|
157
|
-
expect(UpdateProfile.mutationSchema.source).to.deep.eql({
|
|
158
|
-
id: {
|
|
159
|
-
type: 'string'
|
|
160
|
-
},
|
|
161
|
-
name: {
|
|
162
|
-
type: 'string'
|
|
163
|
-
}
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
expect(UpdateProfile.outputSchema.id).to.eql('UpdateProfileOutput')
|
|
167
|
-
expect(UpdateProfile.outputSchema.source).to.deep.eql({
|
|
168
|
-
data: {
|
|
169
|
-
$ref: 'Profile',
|
|
170
|
-
required: true
|
|
171
|
-
}
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
expect(UpdateProfile.errors.DocumentNotFoundError.statusCode).eql(404)
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
it('throws error if "Component" argument is undefined', () => {
|
|
178
|
-
expect(() => Update()).to.throw('Argument "Component" is undefined')
|
|
179
|
-
})
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
describe('Delete(Component, componentAction = \'delete\')', () => {
|
|
183
|
-
it('returns "Delete" operation class', () => {
|
|
184
|
-
const DeleteProfile = Delete(Profile)
|
|
185
|
-
|
|
186
|
-
expect(DeleteProfile.id).eql('DeleteProfile')
|
|
187
|
-
expect(DeleteProfile.Component).eql(Profile)
|
|
188
|
-
expect(DeleteProfile.componentAction).eql('delete')
|
|
189
|
-
|
|
190
|
-
expect(DeleteProfile.tags).to.include('Profiles')
|
|
191
|
-
expect(DeleteProfile.summary).eql('Delete profile')
|
|
192
|
-
expect(DeleteProfile.description).to.be.empty
|
|
193
|
-
|
|
194
|
-
expect(DeleteProfile.query.id).to.exist
|
|
195
|
-
expect(DeleteProfile.outputSchema).eql(null)
|
|
196
|
-
expect(DeleteProfile.mutationSchema).eql(null)
|
|
197
|
-
|
|
198
|
-
expect(DeleteProfile.errors.DocumentNotFoundError.statusCode).eql(404)
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
it('throws error if "Component" argument is undefined', () => {
|
|
202
|
-
expect(() => Delete()).to.throw('Argument "Component" is undefined')
|
|
203
|
-
})
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
describe('Index(Component, componentAction = \'index\')', () => {
|
|
207
|
-
it('returns "Index" operation class', () => {
|
|
208
|
-
const IndexProfiles = Index(Profile)
|
|
209
|
-
|
|
210
|
-
expect(IndexProfiles.id).eql('IndexProfiles')
|
|
211
|
-
expect(IndexProfiles.Component).eql(Profile)
|
|
212
|
-
expect(IndexProfiles.componentAction).eql('index')
|
|
213
|
-
|
|
214
|
-
expect(IndexProfiles.tags).to.include('Profiles')
|
|
215
|
-
expect(IndexProfiles.summary).eql('Index profiles')
|
|
216
|
-
expect(IndexProfiles.description).to.be.empty
|
|
217
|
-
|
|
218
|
-
expect(IndexProfiles.inputSchema.id).to.eql('IndexProfilesInput')
|
|
219
|
-
expect(IndexProfiles.inputSchema.source).to.deep.eql({
|
|
220
|
-
limit: {
|
|
221
|
-
description: 'Limit number of profiles to be returned',
|
|
222
|
-
type: 'integer',
|
|
223
|
-
default: 20
|
|
224
|
-
},
|
|
225
|
-
sort: {
|
|
226
|
-
description: 'Sort direction',
|
|
227
|
-
enum: [ 'asc', 'desc' ],
|
|
228
|
-
default: 'desc',
|
|
229
|
-
type: 'string'
|
|
230
|
-
},
|
|
231
|
-
exclusiveStartKey: {
|
|
232
|
-
description: 'Return profiles starting from specific key',
|
|
233
|
-
type: 'string'
|
|
234
|
-
}
|
|
235
|
-
})
|
|
236
|
-
|
|
237
|
-
expect(IndexProfiles.outputSchema.id).to.eql('IndexProfilesOutput')
|
|
238
|
-
expect(IndexProfiles.outputSchema.source).to.deep.eql({
|
|
239
|
-
data: {
|
|
240
|
-
items: {
|
|
241
|
-
$ref: 'Profile'
|
|
242
|
-
},
|
|
243
|
-
required: true,
|
|
244
|
-
type: 'array'
|
|
245
|
-
},
|
|
246
|
-
pageInfo: {
|
|
247
|
-
required: true,
|
|
248
|
-
properties: {
|
|
249
|
-
exclusiveStartKey: {
|
|
250
|
-
description: 'Exclusive start key specified in the request',
|
|
251
|
-
type: 'string'
|
|
252
|
-
},
|
|
253
|
-
lastEvaluatedKey: {
|
|
254
|
-
description: 'Last evaluated key to get next portion of results',
|
|
255
|
-
type: 'string'
|
|
256
|
-
},
|
|
257
|
-
limit: {
|
|
258
|
-
description: 'Limit value specified in the request',
|
|
259
|
-
type: 'integer'
|
|
260
|
-
},
|
|
261
|
-
count: {
|
|
262
|
-
description: 'Number of results',
|
|
263
|
-
type: 'integer'
|
|
264
|
-
},
|
|
265
|
-
sort: {
|
|
266
|
-
description: 'Sort direction',
|
|
267
|
-
enum: [ 'asc', 'desc' ],
|
|
268
|
-
type: 'string'
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
type: 'object'
|
|
272
|
-
}
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
expect(IndexProfiles.mutationSchema).to.eql(null)
|
|
276
|
-
})
|
|
277
|
-
|
|
278
|
-
it('throws error if "Component" argument is undefined', () => {
|
|
279
|
-
expect(() => Index()).to.throw('Argument "Component" is undefined')
|
|
280
|
-
})
|
|
281
|
-
|
|
282
|
-
describe('.exec(_parameters)', () => {
|
|
283
|
-
it('returns operation execution result', async () => {
|
|
284
|
-
Profile.reset()
|
|
285
|
-
|
|
286
|
-
const CreateProfile = Create(Profile)
|
|
287
|
-
const IndexProfiles = Index(Profile)
|
|
288
|
-
|
|
289
|
-
await (new CreateProfile(DEFAULT_CONTEXT)).exec({ mutation: { name: 'Margarita' } })
|
|
290
|
-
await (new CreateProfile(DEFAULT_CONTEXT)).exec({ mutation: { name: 'Veronica' } })
|
|
291
|
-
await (new CreateProfile(DEFAULT_CONTEXT)).exec({ mutation: { name: 'Dasha' } })
|
|
292
|
-
|
|
293
|
-
const operation = new IndexProfiles(DEFAULT_CONTEXT)
|
|
294
|
-
const { result } = await operation.exec({ sort: 'asc', limit: 20 })
|
|
295
|
-
|
|
296
|
-
expect(result.data).to.have.lengthOf(3)
|
|
297
|
-
expect(result.pageInfo.sort).to.eql('asc')
|
|
298
|
-
expect(result.pageInfo.count).to.eql(3)
|
|
299
|
-
expect(result.pageInfo.limit).to.eql(20)
|
|
300
|
-
})
|
|
301
|
-
})
|
|
302
|
-
})
|
|
303
|
-
})
|
|
304
|
-
|
|
305
|
-
describe('Operation.id', () => {
|
|
306
|
-
it('throws error if operation ID is undefined', () => {
|
|
307
|
-
const InvalidOperation = () => class extends Operation {}
|
|
308
|
-
expect(() => InvalidOperation().id).to.throw('Operation ID is undefined')
|
|
309
|
-
})
|
|
310
|
-
})
|
|
311
|
-
|
|
312
|
-
describe('Operation.tags', () => {
|
|
313
|
-
it('returns empty list by default', () => {
|
|
314
|
-
expect(Operation.tags).to.be.empty
|
|
315
|
-
})
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
describe('Operation.summary', () => {
|
|
319
|
-
it('returns empty string by default', () => {
|
|
320
|
-
expect(Operation.summary).to.be.empty
|
|
321
|
-
})
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
describe('Operation.security', () => {
|
|
325
|
-
it('returns no requirements by default', () => {
|
|
326
|
-
const CreateProfile = Create(Profile)
|
|
327
|
-
expect(CreateProfile.security).to.be.empty
|
|
328
|
-
})
|
|
329
|
-
})
|
|
330
|
-
|
|
331
|
-
describe('Operation.inputSchema', () => {
|
|
332
|
-
it('returns null for operations without query and mutation', () => {
|
|
333
|
-
const Test = class extends Operation {}
|
|
334
|
-
expect(Test.inputSchema).to.be.null
|
|
335
|
-
})
|
|
336
|
-
})
|
|
337
|
-
|
|
338
|
-
describe('Operation.errors', () => {
|
|
339
|
-
it('does not include "InvalidInputError" for operation without input schema', () => {
|
|
340
|
-
const Test = class extends Operation {}
|
|
341
|
-
expect(Test.errors.InvalidInputError).to.not.exist
|
|
342
|
-
})
|
|
343
|
-
})
|
|
344
|
-
|
|
345
|
-
describe('Operation.mutation', () => {
|
|
346
|
-
it('uses "schema" for components without "bodySchema"', () => {
|
|
347
|
-
class RemoteProfile extends Component {}
|
|
348
|
-
RemoteProfile.schema = loadSync('examples/Profile.yaml')
|
|
349
|
-
|
|
350
|
-
const CreateRemoteProfile = Create(RemoteProfile)
|
|
351
|
-
expect(CreateRemoteProfile.mutation).to.exist
|
|
352
|
-
})
|
|
353
|
-
})
|
|
354
|
-
|
|
355
|
-
describe('Operation.output', () => {
|
|
356
|
-
it('returns null for operations without component', () => {
|
|
357
|
-
const Test = class extends Operation {}
|
|
358
|
-
expect(Test.output).to.be.null
|
|
359
|
-
})
|
|
360
|
-
})
|
|
361
|
-
|
|
362
|
-
describe('Operation.componentActionMethod', () => {
|
|
363
|
-
it('throws error if component is undefined', () => {
|
|
364
|
-
class TestOperation extends Operation {}
|
|
365
|
-
expect(() => TestOperation.componentActionMethod)
|
|
366
|
-
.to.throw('Operation "TestOperation" expects')
|
|
367
|
-
})
|
|
368
|
-
|
|
369
|
-
it('throws error if component action is undefined', () => {
|
|
370
|
-
class TestOperation extends Operation {
|
|
371
|
-
static get Component() {
|
|
372
|
-
return Profile
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
static get componentAction() {
|
|
376
|
-
return 'destroy'
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
expect(() => TestOperation.componentActionMethod)
|
|
380
|
-
.to.throw('Operation "TestOperation" expects component action method' +
|
|
381
|
-
' "Profile.destroy(context, ...)" to be defined')
|
|
382
|
-
})
|
|
383
|
-
})
|
|
384
|
-
|
|
385
|
-
describe('.setHeader(name, value)', () => {
|
|
386
|
-
it('adds header to the operation response', async () => {
|
|
387
|
-
const CreateProfile = class extends Create(Profile) {
|
|
388
|
-
after() {
|
|
389
|
-
this.setHeader('x-response-time', 100)
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
const { headers, result: { data: profile } } = await (
|
|
394
|
-
new CreateProfile(DEFAULT_CONTEXT)
|
|
395
|
-
).exec({ mutation: { name: 'Oleksandr' } })
|
|
396
|
-
|
|
397
|
-
expect(headers).to.include({ 'x-response-time': 100 })
|
|
398
|
-
expect(profile.attributes.name).to.eql('Oleksandr')
|
|
399
|
-
})
|
|
400
|
-
})
|
|
401
|
-
|
|
402
|
-
describe('.before(parameters)', () => {
|
|
403
|
-
it('allows to modify parameters before action', async () => {
|
|
404
|
-
const CreateProfile = class extends Create(Profile) {
|
|
405
|
-
before(parameters) {
|
|
406
|
-
parameters.mutation.lastName = 'Kravets'
|
|
407
|
-
return parameters
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
const { result: { data: profile } } = await (
|
|
412
|
-
new CreateProfile(DEFAULT_CONTEXT)
|
|
413
|
-
).exec({ mutation: { name: 'Oleksandr' } })
|
|
414
|
-
|
|
415
|
-
expect(profile.attributes.lastName).to.eql('Kravets')
|
|
416
|
-
})
|
|
417
|
-
|
|
418
|
-
it('supports passthrough execution, when parameters are not changed', async () => {
|
|
419
|
-
const CreateProfile = class extends Create(Profile) {
|
|
420
|
-
before() {
|
|
421
|
-
this.setHeader('set-cookie', [ 'a=1', 'b=2' ], true)
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
const { multiValueHeaders, result: { data: profile } } = await (
|
|
426
|
-
new CreateProfile(DEFAULT_CONTEXT)
|
|
427
|
-
).exec({ mutation: { name: 'Oleksandr' } })
|
|
428
|
-
|
|
429
|
-
expect(multiValueHeaders['set-cookie']).to.exist
|
|
430
|
-
expect(multiValueHeaders['set-cookie']).to.have.lengthOf(2)
|
|
431
|
-
expect(profile.attributes.name).to.eql('Oleksandr')
|
|
432
|
-
})
|
|
433
|
-
})
|
|
434
|
-
|
|
435
|
-
describe('.after(parameters, result)', () => {
|
|
436
|
-
it('allows to modify after action response', async () => {
|
|
437
|
-
const CreateProfile = class extends Create(Profile) {
|
|
438
|
-
after(parameters, profile) {
|
|
439
|
-
profile.attributes.lastName = 'Kravets'
|
|
440
|
-
return profile
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
const { result: { data: profile } } = await (
|
|
445
|
-
new CreateProfile(DEFAULT_CONTEXT)
|
|
446
|
-
).exec({ mutation: { name: 'Oleksandr' } })
|
|
447
|
-
|
|
448
|
-
expect(profile.attributes.lastName).to.eql('Kravets')
|
|
449
|
-
})
|
|
450
|
-
|
|
451
|
-
it('supports non-data attribute in result', async () => {
|
|
452
|
-
const Health = class extends Operation {
|
|
453
|
-
action() {
|
|
454
|
-
return { status: 'OK' }
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
after(parameters, result) {
|
|
458
|
-
return { ...result, service: 'Test' }
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
const { result } = await (new Health(DEFAULT_CONTEXT)).exec()
|
|
463
|
-
expect(result).to.deep.eql({ status: 'OK', service: 'Test' })
|
|
464
|
-
})
|
|
465
|
-
})
|
|
466
|
-
|
|
467
|
-
describe('.action()', () => {
|
|
468
|
-
it('supports dummy mode without defined "Component"', async () => {
|
|
469
|
-
const { result } = await new Operation().exec()
|
|
470
|
-
|
|
471
|
-
expect(result).to.be.empty
|
|
472
|
-
})
|
|
473
|
-
})
|
|
474
|
-
})
|
package/src/Service.js
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const handler = require('./helpers/handler')
|
|
4
|
-
const authorize = require('./helpers/authorize')
|
|
5
|
-
const createSpec = require('./helpers/createSpec')
|
|
6
|
-
const { Validator } = require('@kravc/schema')
|
|
7
|
-
const OperationError = require('./errors/OperationError')
|
|
8
|
-
const createSchemasMap = require('./helpers/createSchemasMap')
|
|
9
|
-
const InvalidInputError = require('./errors/InvalidInputError')
|
|
10
|
-
const InvalidOutputError = require('./errors/InvalidOutputError')
|
|
11
|
-
const OperationNotFoundError = require('./errors/OperationNotFoundError')
|
|
12
|
-
const { get, uniq, compact } = require('lodash')
|
|
13
|
-
|
|
14
|
-
const ROOT_PATH = process.cwd()
|
|
15
|
-
const DEFAULT_URL = 'http://localhost:3000/'
|
|
16
|
-
const DEFAULT_SERVICE_PATH = `${ROOT_PATH}/src`
|
|
17
|
-
const DEFAULT_SKIP_OPERATIONS = []
|
|
18
|
-
|
|
19
|
-
class Service {
|
|
20
|
-
constructor(modules, options = {}) {
|
|
21
|
-
let {
|
|
22
|
-
url = DEFAULT_URL,
|
|
23
|
-
path = DEFAULT_SERVICE_PATH,
|
|
24
|
-
skipOperations = DEFAULT_SKIP_OPERATIONS,
|
|
25
|
-
} = options
|
|
26
|
-
|
|
27
|
-
if (!url.endsWith('/')) { url = url + '/' }
|
|
28
|
-
|
|
29
|
-
const schemasMap = createSchemasMap(path, modules)
|
|
30
|
-
|
|
31
|
-
let components = modules.filter(Component => !Component.types)
|
|
32
|
-
|
|
33
|
-
let operations = modules
|
|
34
|
-
.filter(Component => !!Component.types)
|
|
35
|
-
.filter(({ id }) => !skipOperations.includes(id))
|
|
36
|
-
|
|
37
|
-
const operationComponents = compact(operations.map(({ Component }) => Component))
|
|
38
|
-
components = uniq([ ...components, ...operationComponents ])
|
|
39
|
-
|
|
40
|
-
for (const component of components) {
|
|
41
|
-
if (!component.schema) {
|
|
42
|
-
const schema = schemasMap[component.id]
|
|
43
|
-
|
|
44
|
-
if (!schema) {
|
|
45
|
-
throw new Error(`Schema for component "${component.id}" not found`)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
component.schema = schema
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
schemasMap[component.id] = component.schema
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const operationsMap = {}
|
|
55
|
-
|
|
56
|
-
for (const operationClass of operations) {
|
|
57
|
-
const { mutationSchema, inputSchema, outputSchema } = operationClass
|
|
58
|
-
|
|
59
|
-
if (mutationSchema) {
|
|
60
|
-
schemasMap[mutationSchema.id] = mutationSchema
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (inputSchema) {
|
|
64
|
-
schemasMap[inputSchema.id] = inputSchema
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (outputSchema) {
|
|
68
|
-
schemasMap[outputSchema.id] = outputSchema
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
operationsMap[operationClass.id] = operationClass
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
schemasMap[OperationError.id] = OperationError.schema
|
|
75
|
-
|
|
76
|
-
const spec = createSpec(operations, schemasMap, url)
|
|
77
|
-
const schemas = Object.values(schemasMap)
|
|
78
|
-
const validator = new Validator(schemas)
|
|
79
|
-
|
|
80
|
-
this._url = url
|
|
81
|
-
this._spec = spec
|
|
82
|
-
this._validator = validator
|
|
83
|
-
this._schemasMap = schemasMap
|
|
84
|
-
this._operationsMap = operationsMap
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
get baseUrl() {
|
|
88
|
-
return this._url
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
get validator() {
|
|
92
|
-
return this._validator
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
get spec() {
|
|
96
|
-
return this._spec
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
get basePath() {
|
|
100
|
-
return this._spec.basePath
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
getOperationId(httpMethod, httpPath) {
|
|
104
|
-
return get(this._spec.paths, `${httpPath}.${httpMethod}.operationId`, 'NONE')
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
handler(request, extraContext) {
|
|
108
|
-
return handler(this)(request, extraContext)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async process(context) {
|
|
112
|
-
const { operationId } = context
|
|
113
|
-
const Operation = this._operationsMap[operationId]
|
|
114
|
-
|
|
115
|
-
let response = {}
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
const { httpMethod, httpPath } = context
|
|
119
|
-
if (!Operation) { throw new OperationNotFoundError({ operationId, httpMethod, httpPath }) }
|
|
120
|
-
|
|
121
|
-
context.identity = await authorize(Operation, context)
|
|
122
|
-
const isUpdate = Operation.type === Operation.types.UPDATE
|
|
123
|
-
const parameters = this._getParameters(Operation.inputSchema, context, isUpdate)
|
|
124
|
-
|
|
125
|
-
const operation = new Operation(context)
|
|
126
|
-
response = await operation.exec(parameters)
|
|
127
|
-
|
|
128
|
-
response.output = this._getOutput(Operation.outputSchema, response.result)
|
|
129
|
-
response.statusCode = this._getStatusCode(Operation)
|
|
130
|
-
|
|
131
|
-
} catch (error) {
|
|
132
|
-
let errorStatusCode
|
|
133
|
-
|
|
134
|
-
const { code } = error
|
|
135
|
-
|
|
136
|
-
if (Operation) {
|
|
137
|
-
errorStatusCode = get(Operation.errors, `${code}.statusCode`, 500)
|
|
138
|
-
|
|
139
|
-
} else {
|
|
140
|
-
errorStatusCode = get(error, 'statusCode', 500)
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
response.output = new OperationError(context, errorStatusCode, error).validate()
|
|
145
|
-
response.statusCode = errorStatusCode
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const { output, statusCode, headers, multiValueHeaders } = response
|
|
149
|
-
|
|
150
|
-
if (!output) {
|
|
151
|
-
return { statusCode, headers, multiValueHeaders }
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const body = JSON.stringify(output, null, 2)
|
|
155
|
-
|
|
156
|
-
return { statusCode, headers, multiValueHeaders, body }
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
_getParameters(inputSchema, context, shouldNullifyEmptyValues) {
|
|
160
|
-
if (!inputSchema) { return {} }
|
|
161
|
-
|
|
162
|
-
const { query, mutation } = context
|
|
163
|
-
const input = { ...query, mutation }
|
|
164
|
-
|
|
165
|
-
let result
|
|
166
|
-
|
|
167
|
-
try {
|
|
168
|
-
result = this._validator.validate(input, inputSchema.id, shouldNullifyEmptyValues)
|
|
169
|
-
|
|
170
|
-
} catch (validationError) {
|
|
171
|
-
throw new InvalidInputError(validationError, context)
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return result
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
_getOutput(outputSchema, object) {
|
|
179
|
-
if (!outputSchema) { return null }
|
|
180
|
-
|
|
181
|
-
let output
|
|
182
|
-
|
|
183
|
-
try {
|
|
184
|
-
output = this._validator.validate(object, outputSchema.id, false, true)
|
|
185
|
-
|
|
186
|
-
} catch (validationError) {
|
|
187
|
-
throw new InvalidOutputError(object, validationError)
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return output
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
_getStatusCode(Operation) {
|
|
195
|
-
if (!Operation.outputSchema) {
|
|
196
|
-
return 204
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (Operation.type === Operation.types.CREATE) {
|
|
200
|
-
return 201
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return 200
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
module.exports = Service
|