@kravc/dos 1.12.6 → 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 -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
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MutationMap, Request } from './Request';
|
|
2
|
+
/** Returns mutation parameters of a request. */
|
|
3
|
+
declare const getMutationParameters: (request: Request) => {
|
|
4
|
+
bodyJson: string | null;
|
|
5
|
+
mutation: MutationMap | null;
|
|
6
|
+
};
|
|
7
|
+
export default getMutationParameters;
|
|
8
|
+
//# sourceMappingURL=getMutationParameters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMutationParameters.d.ts","sourceRoot":"","sources":["../../src/Context/getMutationParameters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEtD,gDAAgD;AAChD,QAAA,MAAM,qBAAqB,GAAI,SAAS,OAAO;cAKjC,MAAM,GAAG,IAAI;cACb,WAAW,GAAG,IAAI;CAsB/B,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const lodash_1 = require("lodash");
|
|
4
|
+
/** Returns mutation parameters of a request. */
|
|
5
|
+
const getMutationParameters = (request) => {
|
|
6
|
+
const result = {
|
|
7
|
+
bodyJson: null,
|
|
8
|
+
mutation: null,
|
|
9
|
+
};
|
|
10
|
+
const { body } = request;
|
|
11
|
+
if (!body) {
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
const isJSON = (0, lodash_1.isString)(body);
|
|
15
|
+
if (isJSON) {
|
|
16
|
+
result.bodyJson = body;
|
|
17
|
+
result.mutation = JSON.parse(body);
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
result.bodyJson = JSON.stringify(body);
|
|
21
|
+
result.mutation = body;
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
exports.default = getMutationParameters;
|
|
25
|
+
//# sourceMappingURL=getMutationParameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMutationParameters.js","sourceRoot":"","sources":["../../src/Context/getMutationParameters.ts"],"names":[],"mappings":";;AAAA,mCAAkC;AAGlC,gDAAgD;AAChD,MAAM,qBAAqB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACjD,MAAM,MAAM,GAAG;QACb,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,IAAI;KAIf,CAAC;IAEF,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IAEzB,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,MAAM,GAAG,IAAA,iBAAQ,EAAC,IAAI,CAAC,CAAC;IAE9B,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEnC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACvC,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;IAEvB,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,kBAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { OpenAPIV2 } from 'openapi-types';
|
|
2
|
+
import type { Request } from './Request';
|
|
3
|
+
/** Returns operation ID for a request. */
|
|
4
|
+
declare const getOperationId: (spec: OpenAPIV2.Document, request: Request) => string;
|
|
5
|
+
export default getOperationId;
|
|
6
|
+
//# sourceMappingURL=getOperationId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOperationId.d.ts","sourceRoot":"","sources":["../../src/Context/getOperationId.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,OAAO,EAAiB,MAAM,WAAW,CAAC;AAIxD,0CAA0C;AAC1C,QAAA,MAAM,cAAc,GAAI,MAAM,SAAS,CAAC,QAAQ,EAAE,SAAS,OAAO,KAAG,MAWpE,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const getHttpPath_1 = __importDefault(require("./getHttpPath"));
|
|
8
|
+
const getHttpMethod_1 = __importDefault(require("./getHttpMethod"));
|
|
9
|
+
const UNDEFINED_VALUE = 'undefined';
|
|
10
|
+
/** Returns operation ID for a request. */
|
|
11
|
+
const getOperationId = (spec, request) => {
|
|
12
|
+
const { operationId } = request;
|
|
13
|
+
if (operationId) {
|
|
14
|
+
return operationId;
|
|
15
|
+
}
|
|
16
|
+
const httpPath = (0, getHttpPath_1.default)(spec, request);
|
|
17
|
+
const httpMethod = (0, getHttpMethod_1.default)(spec, request);
|
|
18
|
+
return (0, lodash_1.get)(spec.paths, `${httpPath}.${httpMethod}.operationId`, UNDEFINED_VALUE);
|
|
19
|
+
};
|
|
20
|
+
exports.default = getOperationId;
|
|
21
|
+
//# sourceMappingURL=getOperationId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOperationId.js","sourceRoot":"","sources":["../../src/Context/getOperationId.ts"],"names":[],"mappings":";;;;;AAAA,mCAA6B;AAC7B,gEAAwC;AACxC,oEAA4C;AAI5C,MAAM,eAAe,GAAG,WAAW,CAAC;AAEpC,0CAA0C;AAC1C,MAAM,cAAc,GAAG,CAAC,IAAwB,EAAE,OAAgB,EAAU,EAAE;IAC5E,MAAM,EAAE,WAAW,EAAE,GAAG,OAAwB,CAAC;IAEjD,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,QAAQ,GAAG,IAAA,qBAAW,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5C,MAAM,UAAU,GAAG,IAAA,uBAAa,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEhD,OAAO,IAAA,YAAG,EAAC,IAAI,CAAC,KAAK,EAAE,GAAG,QAAQ,IAAI,UAAU,cAAc,EAAE,eAAe,CAAW,CAAC;AAC7F,CAAC,CAAC;AAEF,kBAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getQueryParameters.d.ts","sourceRoot":"","sources":["../../src/Context/getQueryParameters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAInD,6CAA6C;AAC7C,QAAA,MAAM,kBAAkB,GAAI,SAAS,OAAO,KAAG,QAoC9C,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const lodash_1 = require("lodash");
|
|
4
|
+
const BASE_URL = 'http://localhost:3000';
|
|
5
|
+
/** Returns query parameters of a request. */
|
|
6
|
+
const getQueryParameters = (request) => {
|
|
7
|
+
let parameters = {};
|
|
8
|
+
const url = (0, lodash_1.get)(request, 'url');
|
|
9
|
+
if (url) {
|
|
10
|
+
const { searchParams } = new URL(url, BASE_URL);
|
|
11
|
+
parameters = Object.fromEntries(searchParams);
|
|
12
|
+
}
|
|
13
|
+
const queryStringParameters = (0, lodash_1.get)(request, 'queryStringParameters');
|
|
14
|
+
if (queryStringParameters) {
|
|
15
|
+
const keys = Object.keys(queryStringParameters);
|
|
16
|
+
for (const key of keys) {
|
|
17
|
+
const value = queryStringParameters[key];
|
|
18
|
+
queryStringParameters[key] = decodeURIComponent(value);
|
|
19
|
+
}
|
|
20
|
+
parameters = queryStringParameters;
|
|
21
|
+
}
|
|
22
|
+
const queryKeys = Object.keys(parameters);
|
|
23
|
+
for (const queryKey of queryKeys) {
|
|
24
|
+
const value = parameters[queryKey];
|
|
25
|
+
const isArrayOfStrings = `${value}`.startsWith('["');
|
|
26
|
+
if (isArrayOfStrings) {
|
|
27
|
+
parameters[queryKey] = JSON.parse(`${value}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return parameters;
|
|
31
|
+
};
|
|
32
|
+
exports.default = getQueryParameters;
|
|
33
|
+
//# sourceMappingURL=getQueryParameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getQueryParameters.js","sourceRoot":"","sources":["../../src/Context/getQueryParameters.ts"],"names":[],"mappings":";;AAAA,mCAA6B;AAG7B,MAAM,QAAQ,GAAG,uBAAuB,CAAC;AAEzC,6CAA6C;AAC7C,MAAM,kBAAkB,GAAG,CAAC,OAAgB,EAAY,EAAE;IACxD,IAAI,UAAU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":["../../src/Context/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAC;AAChC,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAEtD,eAAe,OAAO,CAAC;AAEvB,OAAO,EACL,OAAO,EACP,kBAAkB,GACnB,CAAC;AAEF,mBAAmB,WAAW,CAAC;AAC/B,mBAAmB,WAAW,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.withSafeAttributes = exports.Context = void 0;
|
|
7
|
+
const Context_1 = __importDefault(require("./Context"));
|
|
8
|
+
exports.Context = Context_1.default;
|
|
9
|
+
const withSafeAttributes_1 = __importDefault(require("./withSafeAttributes"));
|
|
10
|
+
exports.withSafeAttributes = withSafeAttributes_1.default;
|
|
11
|
+
exports.default = Context_1.default;
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Context/index.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAM9B,kBANK,iBAAO,CAML;AALT,8EAAsD;AAMpD,6BANK,4BAAkB,CAML;AAJpB,kBAAe,iBAAO,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns instance of an object with safe attributes.
|
|
3
|
+
*
|
|
4
|
+
* ## Intent
|
|
5
|
+
*
|
|
6
|
+
* Wraps an object instance in a Proxy that enforces safe attribute access. This function ensures that:
|
|
7
|
+
* - Properties and methods must exist on the instance before they can be accessed
|
|
8
|
+
* - Clear, descriptive errors are thrown when accessing undefined properties/methods
|
|
9
|
+
* - The object cannot be accidentally treated as a Promise (by returning `undefined` for `then`)
|
|
10
|
+
*
|
|
11
|
+
* This is particularly useful for component classes where you want to catch typos and undefined
|
|
12
|
+
* property access early with helpful error messages that include the class name.
|
|
13
|
+
*
|
|
14
|
+
* ## Use Cases
|
|
15
|
+
*
|
|
16
|
+
* 1. **Component Safety**: Wrap component instances to ensure all property/method accesses are valid
|
|
17
|
+
* 2. **Early Error Detection**: Catch typos and undefined accesses at runtime with clear error messages
|
|
18
|
+
* 3. **Promise Prevention**: Prevent objects from being accidentally treated as Promises in async contexts
|
|
19
|
+
* 4. **Type Safety**: Provide runtime validation complementing TypeScript's compile-time checks
|
|
20
|
+
*/
|
|
21
|
+
declare function withSafeAttributes<T>(targetInstance: T, className: string): T;
|
|
22
|
+
export default withSafeAttributes;
|
|
23
|
+
//# sourceMappingURL=withSafeAttributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withSafeAttributes.d.ts","sourceRoot":"","sources":["../../src/Context/withSafeAttributes.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iBAAS,kBAAkB,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC,CActE;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require("@kravc/schema");
|
|
4
|
+
/**
|
|
5
|
+
* Returns instance of an object with safe attributes.
|
|
6
|
+
*
|
|
7
|
+
* ## Intent
|
|
8
|
+
*
|
|
9
|
+
* Wraps an object instance in a Proxy that enforces safe attribute access. This function ensures that:
|
|
10
|
+
* - Properties and methods must exist on the instance before they can be accessed
|
|
11
|
+
* - Clear, descriptive errors are thrown when accessing undefined properties/methods
|
|
12
|
+
* - The object cannot be accidentally treated as a Promise (by returning `undefined` for `then`)
|
|
13
|
+
*
|
|
14
|
+
* This is particularly useful for component classes where you want to catch typos and undefined
|
|
15
|
+
* property access early with helpful error messages that include the class name.
|
|
16
|
+
*
|
|
17
|
+
* ## Use Cases
|
|
18
|
+
*
|
|
19
|
+
* 1. **Component Safety**: Wrap component instances to ensure all property/method accesses are valid
|
|
20
|
+
* 2. **Early Error Detection**: Catch typos and undefined accesses at runtime with clear error messages
|
|
21
|
+
* 3. **Promise Prevention**: Prevent objects from being accidentally treated as Promises in async contexts
|
|
22
|
+
* 4. **Type Safety**: Provide runtime validation complementing TypeScript's compile-time checks
|
|
23
|
+
*/
|
|
24
|
+
function withSafeAttributes(targetInstance, className) {
|
|
25
|
+
return new Proxy(targetInstance, {
|
|
26
|
+
/** Ensures attribute is defined as property or method of the instance. */
|
|
27
|
+
get(target, prop) {
|
|
28
|
+
const shouldSkip = ['then'].includes(prop);
|
|
29
|
+
if (shouldSkip) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const errorTemplate = `"$PATH" property or method is undefined for ${className} instance`;
|
|
33
|
+
return (0, schema_1.got)(target, prop, errorTemplate);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
;
|
|
38
|
+
exports.default = withSafeAttributes;
|
|
39
|
+
//# sourceMappingURL=withSafeAttributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withSafeAttributes.js","sourceRoot":"","sources":["../../src/Context/withSafeAttributes.ts"],"names":[],"mappings":";;AAAA,0CAAoC;AAEpC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,kBAAkB,CAAI,cAAiB,EAAE,SAAiB;IACjE,OAAO,IAAI,KAAK,CAAC,cAAwB,EAAE;QACzC,0EAA0E;QAC1E,GAAG,CAAC,MAA+B,EAAE,IAAY;YAC/C,MAAM,UAAU,GAAG,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAE3C,IAAI,UAAU,EAAE,CAAC;gBACf,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,MAAM,aAAa,GAAG,+CAA+C,SAAS,WAAW,CAAC;YAC1F,OAAO,IAAA,YAAG,EAAC,MAAM,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;QAC1C,CAAC;KACF,CAAM,CAAC;AACV,CAAC;AAAA,CAAC;AAEF,kBAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import Component from '../Component';
|
|
2
|
+
import { Schema, type PropertiesSchemaSource } from '@kravc/schema';
|
|
3
|
+
import Context, { type QueryMap, type MutationMap } from '../Context';
|
|
4
|
+
export type IndexOptions = {
|
|
5
|
+
sort?: 'asc' | 'desc';
|
|
6
|
+
limit?: number;
|
|
7
|
+
index?: string;
|
|
8
|
+
exclusiveStartKey?: string;
|
|
9
|
+
};
|
|
10
|
+
export type IndexAllOptions = {
|
|
11
|
+
sort?: 'asc' | 'desc';
|
|
12
|
+
index?: string;
|
|
13
|
+
};
|
|
14
|
+
export type DefaultAttributes = {
|
|
15
|
+
id: string;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
createdBy: string;
|
|
18
|
+
createdByUserName?: string;
|
|
19
|
+
updatedAt?: string;
|
|
20
|
+
updatedBy?: string;
|
|
21
|
+
updatedByUserName?: string;
|
|
22
|
+
};
|
|
23
|
+
type Constructor<T, D extends Document<T> = Document<T>> = {
|
|
24
|
+
new (context: Context, attributes: T): D;
|
|
25
|
+
_index(query: QueryMap, options: IndexOptions): Promise<{
|
|
26
|
+
count: number;
|
|
27
|
+
items: T[];
|
|
28
|
+
lastEvaluatedKey?: string;
|
|
29
|
+
}>;
|
|
30
|
+
_indexAll(query: QueryMap, options: IndexAllOptions): Promise<{
|
|
31
|
+
count: number;
|
|
32
|
+
items: T[];
|
|
33
|
+
}>;
|
|
34
|
+
_read(query: QueryMap, options: unknown): Promise<T>;
|
|
35
|
+
_create(attributes: T): Promise<void>;
|
|
36
|
+
_update<T>(query: QueryMap, mutation: MutationMap): Promise<T>;
|
|
37
|
+
_delete(query: QueryMap): Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
/** Abstract document class. */
|
|
40
|
+
declare class Document<Attributes> extends Component<Attributes> {
|
|
41
|
+
private static _bodySchema;
|
|
42
|
+
private _previousAttributes;
|
|
43
|
+
/** Returns partition key of a document. */
|
|
44
|
+
static get partitionKey(): string;
|
|
45
|
+
/** Returns prefix for new IDs. */
|
|
46
|
+
static get idPrefix(): string;
|
|
47
|
+
/** Returns attribute name to sort index action results by. */
|
|
48
|
+
static get indexSortBy(): string;
|
|
49
|
+
/** Defines default sort direction for index action results. */
|
|
50
|
+
static get indexDefaultSort(): 'asc' | 'desc';
|
|
51
|
+
/** Defines default limit for index action. */
|
|
52
|
+
static get indexDefaultLimit(): number;
|
|
53
|
+
/** Generates ID for new document unless it's defined in parameters. */
|
|
54
|
+
static createId(attributes: Record<string, unknown>): string;
|
|
55
|
+
/** Returns default attributes schema source. */
|
|
56
|
+
static get defaultAttributesSchemaSource(): PropertiesSchemaSource;
|
|
57
|
+
/** Extends document schema with default attributes. */
|
|
58
|
+
static set schema(schema: Schema);
|
|
59
|
+
/** Returns schema to validate document attributes. */
|
|
60
|
+
static get schema(): Schema;
|
|
61
|
+
/** Returns body schema of a document. */
|
|
62
|
+
static get bodySchema(): Schema;
|
|
63
|
+
/** Returns schema for document create and update mutations. */
|
|
64
|
+
static get mutationSchema(): Schema;
|
|
65
|
+
/** Returns partition to save document based on context and parameters. */
|
|
66
|
+
static getPartition(_context: Context, _parameters: Record<string, unknown>): string | undefined;
|
|
67
|
+
/** Extends parameters with partition of a document. */
|
|
68
|
+
static _extendWithPartition(context: Context, parameters: Record<string, unknown>): void;
|
|
69
|
+
/** Extends mutation with created stamps. */
|
|
70
|
+
static _extendWithCreatedStamps(context: Context, mutation: MutationMap): void;
|
|
71
|
+
/** Extends mutation with updated stamps. */
|
|
72
|
+
static _extendWithUpdatedStamps(context: Context, mutation: MutationMap): void;
|
|
73
|
+
/** Returns documents in batches. */
|
|
74
|
+
static index<T, D extends Document<T> = Document<T>>(this: Constructor<T, D>, context: Context, query?: QueryMap, options?: IndexOptions): Promise<{
|
|
75
|
+
count: number;
|
|
76
|
+
objects: D[];
|
|
77
|
+
lastEvaluatedKey?: string;
|
|
78
|
+
}>;
|
|
79
|
+
/** Returns all documents. */
|
|
80
|
+
static indexAll<T, D extends Document<T> = Document<T>>(this: Constructor<T, D>, context: Context, query?: QueryMap, options?: IndexAllOptions): Promise<{
|
|
81
|
+
count: number;
|
|
82
|
+
objects: D[];
|
|
83
|
+
}>;
|
|
84
|
+
/** Returns a document by ID attribute. */
|
|
85
|
+
static read<T, D extends Document<T> = Document<T>>(this: Constructor<T, D>, context: Context, query: QueryMap, options?: unknown): Promise<D>;
|
|
86
|
+
/** Creates a document. */
|
|
87
|
+
static create<T, D extends Document<T> = Document<T>>(this: Constructor<T, D>, context: Context, query: QueryMap | MutationMap, mutation?: MutationMap): Promise<D>;
|
|
88
|
+
/** Before create hook. */
|
|
89
|
+
static beforeCreate(_context: Context, _query: QueryMap, _mutation: MutationMap): Promise<void>;
|
|
90
|
+
/** After create hook. */
|
|
91
|
+
static afterCreate(_context: Context, _query: QueryMap, _mutation: MutationMap, _createdDocument: unknown): Promise<void>;
|
|
92
|
+
/** Updates a document. */
|
|
93
|
+
static update<T, D extends Document<T> = Document<T>>(this: Constructor<T, D>, context: Context, query: QueryMap, mutation: MutationMap): Promise<D>;
|
|
94
|
+
/** Before update hook. */
|
|
95
|
+
static beforeUpdate(_context: Context, _query: QueryMap, _mutation: MutationMap): Promise<void>;
|
|
96
|
+
/** After update hook. */
|
|
97
|
+
static afterUpdate(_context: Context, _query: QueryMap, _mutation: MutationMap, _updatedDocument: unknown): Promise<void>;
|
|
98
|
+
/** Deletes a document. */
|
|
99
|
+
static delete<T, D extends Document<T> = Document<T>>(this: Constructor<T, D>, context: Context, query: QueryMap): Promise<D>;
|
|
100
|
+
/** Before delete hook. */
|
|
101
|
+
static beforeDelete(_context: Context, _query: QueryMap): Promise<void>;
|
|
102
|
+
/** After delete hook. */
|
|
103
|
+
static afterDelete(_context: Context, _query: QueryMap, _deletedDocument: unknown): Promise<void>;
|
|
104
|
+
/** Returns document ID. */
|
|
105
|
+
get id(): string;
|
|
106
|
+
/** Returns previous attributes after update action. */
|
|
107
|
+
get previousAttributes(): NonNullable<Attributes> | null;
|
|
108
|
+
/** Flags if document attribute has been changed via update action. */
|
|
109
|
+
hasAttributeChanged(path: string): boolean;
|
|
110
|
+
/** Updates document attributes. */
|
|
111
|
+
update(mutation: MutationMap): Promise<void>;
|
|
112
|
+
}
|
|
113
|
+
export default Document;
|
|
114
|
+
//# sourceMappingURL=Document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Document.d.ts","sourceRoot":"","sources":["../../src/Document/Document.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,KAAK,sBAAsB,EAAO,MAAM,eAAe,CAAC;AACzE,OAAO,OAAO,EAAE,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAOtE,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC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,CAAC;IAIvG,2BAA2B;IAC3B,IAAI,EAAE,IAAI,MAAM,CAGf;IAED,uDAAuD;IACvD,IAAI,kBAAkB,mCAErB;IAED,sEAAsE;IACtE,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAa1C,mCAAmC;IAC7B,MAAM,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAYnD;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ulid_1 = require("ulid");
|
|
7
|
+
const Component_1 = __importDefault(require("../Component"));
|
|
8
|
+
const schema_1 = require("@kravc/schema");
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
const DEFAULT_INDEX_SORT = 'desc';
|
|
11
|
+
const DEFAULT_INDEX_LIMIT = 300;
|
|
12
|
+
const DEFAULT_PARTITION_KEY = 'partition';
|
|
13
|
+
/** Abstract document class. */
|
|
14
|
+
class Document extends Component_1.default {
|
|
15
|
+
static _bodySchema;
|
|
16
|
+
_previousAttributes;
|
|
17
|
+
/** Returns partition key of a document. */
|
|
18
|
+
static get partitionKey() {
|
|
19
|
+
return DEFAULT_PARTITION_KEY;
|
|
20
|
+
}
|
|
21
|
+
/** Returns prefix for new IDs. */
|
|
22
|
+
static get idPrefix() {
|
|
23
|
+
return this.name;
|
|
24
|
+
}
|
|
25
|
+
/** Returns attribute name to sort index action results by. */
|
|
26
|
+
static get indexSortBy() {
|
|
27
|
+
return this.idKey;
|
|
28
|
+
}
|
|
29
|
+
/** Defines default sort direction for index action results. */
|
|
30
|
+
static get indexDefaultSort() {
|
|
31
|
+
return DEFAULT_INDEX_SORT;
|
|
32
|
+
}
|
|
33
|
+
/** Defines default limit for index action. */
|
|
34
|
+
static get indexDefaultLimit() {
|
|
35
|
+
return DEFAULT_INDEX_LIMIT;
|
|
36
|
+
}
|
|
37
|
+
/** Generates ID for new document unless it's defined in parameters. */
|
|
38
|
+
static createId(attributes) {
|
|
39
|
+
const id = (0, lodash_1.get)(attributes, this.idKey);
|
|
40
|
+
const hasId = !!id;
|
|
41
|
+
if (hasId) {
|
|
42
|
+
return id;
|
|
43
|
+
}
|
|
44
|
+
return `${this.idPrefix}_` + (0, ulid_1.ulid)();
|
|
45
|
+
}
|
|
46
|
+
/** Returns default attributes schema source. */
|
|
47
|
+
static get defaultAttributesSchemaSource() {
|
|
48
|
+
const documentTitle = this.getTitle(false);
|
|
49
|
+
return {
|
|
50
|
+
id: {
|
|
51
|
+
description: (0, lodash_1.capitalize)(documentTitle) + ' ID',
|
|
52
|
+
required: true
|
|
53
|
+
},
|
|
54
|
+
createdAt: {
|
|
55
|
+
description: `Date and time when ${documentTitle} was created`,
|
|
56
|
+
format: 'date-time',
|
|
57
|
+
required: true
|
|
58
|
+
},
|
|
59
|
+
createdBy: {
|
|
60
|
+
description: `ID of a user who created ${documentTitle}`,
|
|
61
|
+
required: true
|
|
62
|
+
},
|
|
63
|
+
createdByUserName: {
|
|
64
|
+
description: `Name of a user who created ${documentTitle}`
|
|
65
|
+
},
|
|
66
|
+
updatedAt: {
|
|
67
|
+
description: `Date and time when ${documentTitle} was updated`,
|
|
68
|
+
format: 'date-time'
|
|
69
|
+
},
|
|
70
|
+
updatedBy: {
|
|
71
|
+
description: `ID of a user who updated ${documentTitle}`
|
|
72
|
+
},
|
|
73
|
+
updatedByUserName: {
|
|
74
|
+
description: `Name of a user who updated ${documentTitle}`
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** Extends document schema with default attributes. */
|
|
79
|
+
static set schema(schema) {
|
|
80
|
+
this._schema = schema.extend(this.defaultAttributesSchemaSource, this.id);
|
|
81
|
+
this._bodySchema = schema.clone(`${this.id}Body`);
|
|
82
|
+
}
|
|
83
|
+
/** Returns schema to validate document attributes. */
|
|
84
|
+
static get schema() {
|
|
85
|
+
if (!this._schema) {
|
|
86
|
+
throw new Error(`Schema is not set for "${this.id}"`);
|
|
87
|
+
}
|
|
88
|
+
return this._schema;
|
|
89
|
+
}
|
|
90
|
+
/** Returns body schema of a document. */
|
|
91
|
+
static get bodySchema() {
|
|
92
|
+
return this._bodySchema;
|
|
93
|
+
}
|
|
94
|
+
/** Returns schema for document create and update mutations. */
|
|
95
|
+
static get mutationSchema() {
|
|
96
|
+
return this.bodySchema;
|
|
97
|
+
}
|
|
98
|
+
/** Returns partition to save document based on context and parameters. */
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
100
|
+
static getPartition(_context, _parameters) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
/** Extends parameters with partition of a document. */
|
|
104
|
+
static _extendWithPartition(context, parameters) {
|
|
105
|
+
const hasPartition = !!(0, lodash_1.get)(parameters, this.partitionKey);
|
|
106
|
+
if (hasPartition) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const partition = this.getPartition(context, parameters);
|
|
110
|
+
if (!partition) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
(0, lodash_1.set)(parameters, this.partitionKey, partition);
|
|
114
|
+
}
|
|
115
|
+
/** Extends mutation with created stamps. */
|
|
116
|
+
static _extendWithCreatedStamps(context, mutation) {
|
|
117
|
+
const timestamp = new Date().toJSON();
|
|
118
|
+
mutation.createdAt = timestamp;
|
|
119
|
+
mutation.createdBy = context.identityId;
|
|
120
|
+
mutation.createdByUserName = context.identityName;
|
|
121
|
+
}
|
|
122
|
+
/** Extends mutation with updated stamps. */
|
|
123
|
+
static _extendWithUpdatedStamps(context, mutation) {
|
|
124
|
+
const timestamp = new Date().toJSON();
|
|
125
|
+
mutation.updatedAt = timestamp;
|
|
126
|
+
mutation.updatedBy = context.identityId;
|
|
127
|
+
mutation.updatedByUserName = context.identityName;
|
|
128
|
+
}
|
|
129
|
+
/** Returns documents in batches. */
|
|
130
|
+
static async index(context, query = {}, options = {}) {
|
|
131
|
+
const _this = this;
|
|
132
|
+
_this._extendWithPartition(context, query);
|
|
133
|
+
if (!options.limit) {
|
|
134
|
+
options.limit = _this.indexDefaultLimit;
|
|
135
|
+
}
|
|
136
|
+
if (!options.sort) {
|
|
137
|
+
options.sort = _this.indexDefaultSort;
|
|
138
|
+
}
|
|
139
|
+
const { items, count, lastEvaluatedKey, ...otherPagination } = await this._index(query, options);
|
|
140
|
+
const objects = items.map(attributes => new this(context, attributes));
|
|
141
|
+
return { objects, count, lastEvaluatedKey, ...otherPagination };
|
|
142
|
+
}
|
|
143
|
+
/** Returns all documents. */
|
|
144
|
+
static async indexAll(context, query = {}, options = {}) {
|
|
145
|
+
const _this = this;
|
|
146
|
+
_this._extendWithPartition(context, query);
|
|
147
|
+
if (!options.sort) {
|
|
148
|
+
options.sort = _this.indexDefaultSort;
|
|
149
|
+
}
|
|
150
|
+
const { items, count } = await this._indexAll(query, options);
|
|
151
|
+
const objects = items.map(attributes => new this(context, attributes));
|
|
152
|
+
return { objects, count };
|
|
153
|
+
}
|
|
154
|
+
/** Returns a document by ID attribute. */
|
|
155
|
+
static async read(context, query, options) {
|
|
156
|
+
const _this = this;
|
|
157
|
+
_this._extendWithPartition(context, query);
|
|
158
|
+
const attributes = await this._read(query, options);
|
|
159
|
+
const object = new this(context, attributes);
|
|
160
|
+
return object;
|
|
161
|
+
}
|
|
162
|
+
/** Creates a document. */
|
|
163
|
+
static async create(context, query, mutation) {
|
|
164
|
+
const _this = this;
|
|
165
|
+
// NOTE: This allows implementing the create-unless-exists flow, which first
|
|
166
|
+
// checks existence of the document via before hooks. If it does
|
|
167
|
+
// exist, they add it to the context. Then the operation's action
|
|
168
|
+
// method would do nothing and just return the document from the context.
|
|
169
|
+
const createdDocument = context.get('createdDocument');
|
|
170
|
+
const shouldNotCreate = createdDocument?.componentId === this.name;
|
|
171
|
+
if (shouldNotCreate) {
|
|
172
|
+
return createdDocument;
|
|
173
|
+
}
|
|
174
|
+
if (!mutation) {
|
|
175
|
+
mutation = query;
|
|
176
|
+
query = {};
|
|
177
|
+
}
|
|
178
|
+
const { validator } = context;
|
|
179
|
+
const attributes = validator.normalize(mutation, _this.id);
|
|
180
|
+
const idValue = _this.createId(attributes);
|
|
181
|
+
(0, lodash_1.set)(attributes, _this.idKey, idValue);
|
|
182
|
+
_this._extendWithCreatedStamps(context, attributes);
|
|
183
|
+
_this._extendWithPartition(context, attributes);
|
|
184
|
+
await _this.beforeCreate(context, query, attributes);
|
|
185
|
+
await this._create(attributes);
|
|
186
|
+
const object = new this(context, attributes);
|
|
187
|
+
await _this.afterCreate(context, query, mutation, object);
|
|
188
|
+
return object;
|
|
189
|
+
}
|
|
190
|
+
/** Before create hook. */
|
|
191
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
192
|
+
static async beforeCreate(_context, _query, _mutation) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
/** After create hook. */
|
|
196
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
197
|
+
static async afterCreate(_context, _query, _mutation, _createdDocument) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
/** Updates a document. */
|
|
201
|
+
static async update(context, query, mutation) {
|
|
202
|
+
const _this = this;
|
|
203
|
+
mutation = (0, lodash_1.omit)(mutation, Object.keys(_this.defaultAttributesSchemaSource));
|
|
204
|
+
_this._extendWithUpdatedStamps(context, mutation);
|
|
205
|
+
_this._extendWithPartition(context, query);
|
|
206
|
+
await _this.beforeUpdate(context, query, mutation);
|
|
207
|
+
/* NOTE: In some workflows operation before action helper may be doing
|
|
208
|
+
some verifications with the document to be updated. Here we
|
|
209
|
+
allow to cache it in the context. */
|
|
210
|
+
const idValue = (0, schema_1.got)(query, _this.idKey, 'Query parameter "$PATH" is required');
|
|
211
|
+
const previousDocument = context.get(idValue);
|
|
212
|
+
let previousAttributes = previousDocument?.attributes;
|
|
213
|
+
/* NOTE: Ensure that document to be updated exists and save it in the
|
|
214
|
+
context so can be referenced in the after action helper. */
|
|
215
|
+
if (!previousAttributes) {
|
|
216
|
+
previousAttributes = await this._read(query, {});
|
|
217
|
+
}
|
|
218
|
+
const updatedAttributes = await this._update(query, mutation);
|
|
219
|
+
const object = new this(context, updatedAttributes);
|
|
220
|
+
object._previousAttributes = previousAttributes;
|
|
221
|
+
await _this.afterUpdate(context, query, mutation, object);
|
|
222
|
+
return object;
|
|
223
|
+
}
|
|
224
|
+
/** Before update hook. */
|
|
225
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
226
|
+
static async beforeUpdate(_context, _query, _mutation) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
/** After update hook. */
|
|
230
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
231
|
+
static async afterUpdate(_context, _query, _mutation, _updatedDocument) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
/** Deletes a document. */
|
|
235
|
+
static async delete(context, query) {
|
|
236
|
+
const _this = this;
|
|
237
|
+
_this._extendWithPartition(context, query);
|
|
238
|
+
await _this.beforeDelete(context, query);
|
|
239
|
+
const attributes = await this._read(query, {});
|
|
240
|
+
const object = new this(context, attributes);
|
|
241
|
+
await this._delete(query);
|
|
242
|
+
await _this.afterDelete(context, query, object);
|
|
243
|
+
return object;
|
|
244
|
+
}
|
|
245
|
+
/** Before delete hook. */
|
|
246
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
247
|
+
static async beforeDelete(_context, _query) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
/** After delete hook. */
|
|
251
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
252
|
+
static async afterDelete(_context, _query, _deletedDocument) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
/** Returns document ID. */
|
|
256
|
+
get id() {
|
|
257
|
+
const klass = this.constructor;
|
|
258
|
+
return (0, schema_1.got)(this.attributes, klass.idKey);
|
|
259
|
+
}
|
|
260
|
+
/** Returns previous attributes after update action. */
|
|
261
|
+
get previousAttributes() {
|
|
262
|
+
return this._previousAttributes || null;
|
|
263
|
+
}
|
|
264
|
+
/** Flags if document attribute has been changed via update action. */
|
|
265
|
+
hasAttributeChanged(path) {
|
|
266
|
+
if (!this.previousAttributes) {
|
|
267
|
+
throw Error(`${this.componentId} ${this.id} has not been updated`);
|
|
268
|
+
}
|
|
269
|
+
const currentValue = (0, lodash_1.get)(this.attributes, path);
|
|
270
|
+
const previousValue = (0, lodash_1.get)(this.previousAttributes, path);
|
|
271
|
+
const hasChanged = previousValue !== currentValue;
|
|
272
|
+
return hasChanged;
|
|
273
|
+
}
|
|
274
|
+
/** Updates document attributes. */
|
|
275
|
+
async update(mutation) {
|
|
276
|
+
const klass = this.constructor;
|
|
277
|
+
this.context.set(this.id, this);
|
|
278
|
+
const query = (0, lodash_1.pick)(this.attributes, [klass.idKey, klass.partitionKey]);
|
|
279
|
+
const object = await klass.update(this.context, query, mutation);
|
|
280
|
+
this._previousAttributes = (0, lodash_1.cloneDeep)(this.attributes);
|
|
281
|
+
(0, lodash_1.set)(this, '_attributes', object.attributes);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
exports.default = Document;
|
|
285
|
+
//# sourceMappingURL=Document.js.map
|