@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,406 @@
|
|
|
1
|
+
import { unset } from 'lodash';
|
|
2
|
+
import { wait, MemoryDocument } from '../../';
|
|
3
|
+
import { createContext, profileSchema } from '../../Context/__tests__/__helpers';
|
|
4
|
+
import { User, Profile, type ProfileAttributes } from './__helpers';
|
|
5
|
+
import { DocumentExistsError, DocumentNotFoundError } from '../../Operation';
|
|
6
|
+
|
|
7
|
+
describe('MemoryDocument', () => {
|
|
8
|
+
const context = createContext({ schemas: [ Profile.schema, User.schema ] });
|
|
9
|
+
|
|
10
|
+
const attributes = {
|
|
11
|
+
name: 'John Doe'
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
await User.reset();
|
|
16
|
+
await Profile.reset();
|
|
17
|
+
|
|
18
|
+
context.runtimeReset();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('MemoryDocument.partitionKey', () => {
|
|
22
|
+
it('returns default partition key', () => {
|
|
23
|
+
expect(Profile.partitionKey).toEqual('partition');
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('MemoryDocument.idPrefix', () => {
|
|
28
|
+
it('returns default id prefix', () => {
|
|
29
|
+
expect(Profile.idPrefix).toEqual('Profile');
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('MemoryDocument.createId(attributes)', () => {
|
|
34
|
+
it('returns ID for a new document', () => {
|
|
35
|
+
expect(Profile.createId({})).toBeDefined();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('returns existing ID when predefined', () => {
|
|
39
|
+
const id = Profile.createId({ id: 'TEST_ID' });
|
|
40
|
+
expect(id).toEqual('TEST_ID');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('MemoryDocument.defaultAttributesSchemaSource', () => {
|
|
45
|
+
it('returns default attributes schema source', () => {
|
|
46
|
+
expect(Profile.defaultAttributesSchemaSource).toBeDefined();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('MemoryDocument.bodySchema', () => {
|
|
51
|
+
it('returns document body schema', () => {
|
|
52
|
+
expect(Profile.bodySchema.source).toEqual(profileSchema.source);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('MemoryDocument.create(context, query, mutation)', () => {
|
|
57
|
+
it('creates a document from mutation', async () => {
|
|
58
|
+
const profile = await Profile.create(context, {}, attributes);
|
|
59
|
+
|
|
60
|
+
expect(profile.id).toBeDefined();
|
|
61
|
+
expect(profile.name).toEqual('John Doe');
|
|
62
|
+
expect(profile.attributes.createdAt).toBeDefined();
|
|
63
|
+
expect(profile.attributes.createdBy).toEqual('SYSTEM');
|
|
64
|
+
expect(profile.attributes.createdByUserName).toBeNull();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('creates a document from query', async () => {
|
|
68
|
+
const profile = await Profile.create(context, attributes);
|
|
69
|
+
|
|
70
|
+
expect(profile.id).toBeDefined();
|
|
71
|
+
expect(profile.name).toEqual('John Doe');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('creates a document with context identity', async () => {
|
|
75
|
+
const identity = { sub: 'TEST_USER_ID', name: 'John Doe' };
|
|
76
|
+
const context = createContext({ identity });
|
|
77
|
+
|
|
78
|
+
const profile = await Profile.create(context, attributes);
|
|
79
|
+
|
|
80
|
+
expect(profile.id).toBeDefined();
|
|
81
|
+
expect(profile.name).toEqual('John Doe');
|
|
82
|
+
expect(profile.attributes.createdAt).toBeDefined();
|
|
83
|
+
expect(profile.attributes.createdBy).toEqual('TEST_USER_ID');
|
|
84
|
+
expect(profile.attributes.createdByUserName).toEqual('John Doe');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('returns created document from the context', async () => {
|
|
88
|
+
const createdProfile = await Profile.create(context, attributes);
|
|
89
|
+
context.set('createdDocument', createdProfile);
|
|
90
|
+
|
|
91
|
+
const profile = await Profile.create(context, attributes);
|
|
92
|
+
|
|
93
|
+
expect(profile.id).toEqual(createdProfile.id);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('skips context created document if of other type', async () => {
|
|
97
|
+
const createdProfile = await Profile.create(context, attributes);
|
|
98
|
+
context.set('createdDocument', createdProfile);
|
|
99
|
+
|
|
100
|
+
const user = await User.create(context, attributes);
|
|
101
|
+
|
|
102
|
+
expect(user.id).not.toEqual(createdProfile.id);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('throws DocumentExistsError if document with specified ID already exists', async () => {
|
|
106
|
+
const createdProfile = await Profile.create(context, attributes);
|
|
107
|
+
|
|
108
|
+
const { id } = createdProfile;
|
|
109
|
+
const mutation = { id };
|
|
110
|
+
|
|
111
|
+
await expect(Profile.create(context, mutation))
|
|
112
|
+
.rejects
|
|
113
|
+
.toThrow(DocumentExistsError);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe('MemoryDocument.read(context, query, options)', () => {
|
|
118
|
+
it('returns document by ID', async () => {
|
|
119
|
+
const createdProfile = await Profile.create(context, attributes);
|
|
120
|
+
const { id } = createdProfile;
|
|
121
|
+
|
|
122
|
+
const profile = await Profile.read(context, { id });
|
|
123
|
+
|
|
124
|
+
expect(profile.id).toEqual(createdProfile.id);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('throws DocumentNotFoundError if document not found by ID', async () => {
|
|
128
|
+
await expect(Profile.read(context, { id: 'BAD_ID' }))
|
|
129
|
+
.rejects
|
|
130
|
+
.toThrow(DocumentNotFoundError);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('MemoryDocument.update(context, query, mutation)', () => {
|
|
135
|
+
it('updates a document', async () => {
|
|
136
|
+
const createdProfile = await Profile.create(context, attributes);
|
|
137
|
+
const { id } = createdProfile;
|
|
138
|
+
|
|
139
|
+
const mutation = { name: 'Jane Doe' };
|
|
140
|
+
const profile = await Profile.update(context, { id }, mutation);
|
|
141
|
+
|
|
142
|
+
expect(profile.name).toEqual('Jane Doe');
|
|
143
|
+
expect(profile.attributes.updatedAt).toBeDefined();
|
|
144
|
+
expect(profile.attributes.updatedBy).toEqual('SYSTEM');
|
|
145
|
+
expect(profile.attributes.updatedByUserName).toBeNull();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('updates a document with context identity', async () => {
|
|
149
|
+
const identity = { sub: 'TEST_USER_ID', name: 'John Doe' };
|
|
150
|
+
const context = createContext({ identity });
|
|
151
|
+
|
|
152
|
+
const createdProfile = await Profile.create(context, attributes);
|
|
153
|
+
const { id } = createdProfile;
|
|
154
|
+
|
|
155
|
+
const mutation = { name: 'Jane Doe' };
|
|
156
|
+
const profile = await Profile.update(context, { id }, mutation);
|
|
157
|
+
|
|
158
|
+
expect(profile.name).toEqual('Jane Doe');
|
|
159
|
+
expect(profile.attributes.updatedAt).toBeDefined();
|
|
160
|
+
expect(profile.attributes.updatedBy).toEqual('TEST_USER_ID');
|
|
161
|
+
expect(profile.attributes.updatedByUserName).toEqual('John Doe');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('throws DocumentNotFoundError if document not found by ID', async () => {
|
|
165
|
+
const mutation = { name: 'Jane Doe' };
|
|
166
|
+
await expect(Profile.update(context, { id: 'BAD_ID' }, mutation))
|
|
167
|
+
.rejects
|
|
168
|
+
.toThrow(DocumentNotFoundError);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe('MemoryDocument.delete(context, query)', () => {
|
|
173
|
+
it('deletes a document', async () => {
|
|
174
|
+
const createdProfile = await Profile.create(context, attributes);
|
|
175
|
+
const { id } = createdProfile;
|
|
176
|
+
|
|
177
|
+
const deletedProfile = await Profile.delete(context, { id });
|
|
178
|
+
|
|
179
|
+
expect(deletedProfile.id).toEqual(id);
|
|
180
|
+
await expect(Profile.read(context, { id }))
|
|
181
|
+
.rejects
|
|
182
|
+
.toThrow(DocumentNotFoundError);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('throws DocumentNotFoundError if document not found by ID', async () => {
|
|
186
|
+
await expect(Profile.delete(context, { id: 'BAD_ID' }))
|
|
187
|
+
.rejects
|
|
188
|
+
.toThrow(DocumentNotFoundError);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe('MemoryDocument.indexAll(context, query, options)', () => {
|
|
193
|
+
it('returns all documents in default sort order', async () => {
|
|
194
|
+
await Profile.create(context, { name: 'John Doe' });
|
|
195
|
+
await wait(10);
|
|
196
|
+
await Profile.create(context, { name: 'Josh Doe' });
|
|
197
|
+
await wait(10);
|
|
198
|
+
await Profile.create(context, { name: 'Jenn Doe' });
|
|
199
|
+
await wait(10);
|
|
200
|
+
await Profile.create(context, { name: 'James Doe' });
|
|
201
|
+
|
|
202
|
+
const { count, objects } = await Profile.indexAll(context);
|
|
203
|
+
|
|
204
|
+
expect(count).toEqual(4);
|
|
205
|
+
|
|
206
|
+
const [ profile ] = objects;
|
|
207
|
+
expect(profile.name).toEqual('James Doe');
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('returns all documents in ascending sort order', async () => {
|
|
211
|
+
await Profile.create(context, { name: 'John Doe' });
|
|
212
|
+
await wait(10);
|
|
213
|
+
await Profile.create(context, { name: 'Josh Doe' });
|
|
214
|
+
await wait(10);
|
|
215
|
+
await Profile.create(context, { name: 'Jenn Doe' });
|
|
216
|
+
await wait(10);
|
|
217
|
+
await Profile.create(context, { name: 'James Doe' });
|
|
218
|
+
|
|
219
|
+
const sort = 'asc';
|
|
220
|
+
const { count, objects } = await Profile.indexAll(context, {}, { sort });
|
|
221
|
+
|
|
222
|
+
expect(count).toEqual(4);
|
|
223
|
+
|
|
224
|
+
const [ profile ] = objects;
|
|
225
|
+
expect(profile.name).toEqual('John Doe');
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
describe('MemoryDocument.index(context, query, options)', () => {
|
|
230
|
+
it('returns documents in batches', async () => {
|
|
231
|
+
await Profile.create(context, { name: 'John Doe' });
|
|
232
|
+
await wait(10);
|
|
233
|
+
await Profile.create(context, { name: 'Josh Doe' });
|
|
234
|
+
await wait(10);
|
|
235
|
+
await Profile.create(context, { name: 'Jenn Doe' });
|
|
236
|
+
await wait(10);
|
|
237
|
+
await Profile.create(context, { name: 'James Doe' });
|
|
238
|
+
|
|
239
|
+
const limit = 2;
|
|
240
|
+
|
|
241
|
+
const {
|
|
242
|
+
count: count1,
|
|
243
|
+
objects: objects1,
|
|
244
|
+
lastEvaluatedKey: exclusiveStartKey
|
|
245
|
+
} = await Profile.index(context, {}, { limit });
|
|
246
|
+
|
|
247
|
+
expect(count1).toEqual(2);
|
|
248
|
+
expect(objects1.length).toEqual(2);
|
|
249
|
+
expect(exclusiveStartKey).toEqual(objects1[1].id);
|
|
250
|
+
|
|
251
|
+
const {
|
|
252
|
+
count: count2,
|
|
253
|
+
objects: objects2,
|
|
254
|
+
lastEvaluatedKey: lastEvaluatedKey1
|
|
255
|
+
} = await Profile.index(context, {}, { limit, exclusiveStartKey });
|
|
256
|
+
|
|
257
|
+
expect(count2).toEqual(2);
|
|
258
|
+
expect(objects2.length).toEqual(2);
|
|
259
|
+
expect(lastEvaluatedKey1).toBeUndefined();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('supports descending sort option', async () => {
|
|
263
|
+
await Profile.create(context, { name: 'John Doe' });
|
|
264
|
+
await wait(10);
|
|
265
|
+
await Profile.create(context, { name: 'Josh Doe' });
|
|
266
|
+
await wait(10);
|
|
267
|
+
await Profile.create(context, { name: 'Jenn Doe' });
|
|
268
|
+
await wait(10);
|
|
269
|
+
await Profile.create(context, { name: 'James Doe' });
|
|
270
|
+
|
|
271
|
+
const sort = 'desc';
|
|
272
|
+
const limit = 1;
|
|
273
|
+
|
|
274
|
+
const { count, objects, lastEvaluatedKey } = await Profile.index(context, {}, { sort, limit });
|
|
275
|
+
|
|
276
|
+
expect(count).toEqual(1);
|
|
277
|
+
expect(objects.length).toEqual(1);
|
|
278
|
+
expect(objects[0].id).toEqual(lastEvaluatedKey);
|
|
279
|
+
expect(objects[0].name).toEqual('James Doe');
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('supports default options', async () => {
|
|
283
|
+
await Profile.create(context, { name: 'John Doe' });
|
|
284
|
+
await wait(10);
|
|
285
|
+
await Profile.create(context, { name: 'Josh Doe' });
|
|
286
|
+
await wait(10);
|
|
287
|
+
await Profile.create(context, { name: 'Jenn Doe' });
|
|
288
|
+
await wait(10);
|
|
289
|
+
await Profile.create(context, { name: 'James Doe' });
|
|
290
|
+
|
|
291
|
+
const { count, objects, lastEvaluatedKey } = await Profile.index(context);
|
|
292
|
+
|
|
293
|
+
expect(count).toEqual(4);
|
|
294
|
+
expect(objects.length).toEqual(4);
|
|
295
|
+
expect(lastEvaluatedKey).toBeUndefined();
|
|
296
|
+
expect(objects[0].name).toEqual('James Doe');
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
describe('MemoryDocument.getPartition(context, parameters)', () => {
|
|
301
|
+
it('returns default partition', () => {
|
|
302
|
+
expect(Profile.getPartition(context, {})).toBeUndefined();
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it('supports custom method', async () => {
|
|
306
|
+
await User.create(context, { name: 'John Doe' });
|
|
307
|
+
|
|
308
|
+
const { count: count0 } = await User.index(context, { partition: 'A' });
|
|
309
|
+
const { count: count1 } = await User.index(context, { partition: 'J' });
|
|
310
|
+
|
|
311
|
+
expect(count0).toEqual(0);
|
|
312
|
+
expect(count1).toEqual(1);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
describe('MemoryDocument.schema', () => {
|
|
317
|
+
it('returns document schema', () => {
|
|
318
|
+
const schema = profileSchema.extend(Profile.defaultAttributesSchemaSource, 'Profile');
|
|
319
|
+
|
|
320
|
+
expect(Profile.schema).toEqual(schema);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('validates the document', async () => {
|
|
324
|
+
const profile = await Profile.create(context, { name: 'John Doe' });
|
|
325
|
+
|
|
326
|
+
expect(() => profile.validate())
|
|
327
|
+
.not.toThrow();
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it('throws ValidationError for invalid document attributes', async () => {
|
|
331
|
+
const profile = await Profile.create(context, { name: 'John Doe' });
|
|
332
|
+
unset(profile, '_attributes.name');
|
|
333
|
+
|
|
334
|
+
expect(() => profile.validate())
|
|
335
|
+
.toThrow('"Profile" validation failed');
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it('throws exception if document schema is not defined', () => {
|
|
339
|
+
/** No schema document example. */
|
|
340
|
+
class NoSchemaProfile extends MemoryDocument<ProfileAttributes> {
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
expect(() => NoSchemaProfile.schema)
|
|
344
|
+
.toThrow('Schema is not set for "NoSchemaProfile"');
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
describe('.hasAttributeChanged(path)', () => {
|
|
349
|
+
it('returns true if attribute has been updated', async () => {
|
|
350
|
+
const profile = await Profile.create(context, attributes);
|
|
351
|
+
const { id } = profile;
|
|
352
|
+
|
|
353
|
+
const updatedProfile = await Profile.update(context, { id }, { name: 'Josh Doe' });
|
|
354
|
+
|
|
355
|
+
const hasIdChanged = updatedProfile.hasAttributeChanged('id');
|
|
356
|
+
const hasNameChanged = updatedProfile.hasAttributeChanged('name');
|
|
357
|
+
|
|
358
|
+
expect(hasIdChanged).toBeFalsy();
|
|
359
|
+
expect(hasNameChanged).toBeTruthy();
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('uses document from the context runtime instead of a read', async () => {
|
|
363
|
+
const profile = await Profile.create(context, attributes);
|
|
364
|
+
|
|
365
|
+
const { id } = profile;
|
|
366
|
+
context.set(id, profile);
|
|
367
|
+
|
|
368
|
+
const updatedProfile = await Profile.update(context, { id }, { name: 'Josh Doe' });
|
|
369
|
+
|
|
370
|
+
const hasIdChanged = updatedProfile.hasAttributeChanged('id');
|
|
371
|
+
const hasNameChanged = updatedProfile.hasAttributeChanged('name');
|
|
372
|
+
|
|
373
|
+
expect(hasIdChanged).toBeFalsy();
|
|
374
|
+
expect(hasNameChanged).toBeTruthy();
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('throws exception if document has not been updated', async () => {
|
|
378
|
+
const profile = await Profile.create(context, attributes);
|
|
379
|
+
|
|
380
|
+
expect(() => profile.hasAttributeChanged('name'))
|
|
381
|
+
.toThrow(`Profile ${profile.id} has not been updated`);
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
describe('.update(mutation)', () => {
|
|
386
|
+
it('updates document and document instance attributes', async () => {
|
|
387
|
+
const profile = await Profile.create(context, attributes);
|
|
388
|
+
|
|
389
|
+
await profile.update({ name: 'Josh Doe' });
|
|
390
|
+
const hasNameChanged = profile.hasAttributeChanged('name');
|
|
391
|
+
|
|
392
|
+
expect(hasNameChanged).toBeTruthy();
|
|
393
|
+
expect(profile.name).toEqual('Josh Doe');
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it('supports document with partition defined', async () => {
|
|
397
|
+
const user = await User.create(context, attributes);
|
|
398
|
+
|
|
399
|
+
await user.update({ name: 'Josh Doe' });
|
|
400
|
+
const hasNameChanged = user.hasAttributeChanged('name');
|
|
401
|
+
|
|
402
|
+
expect(hasNameChanged).toBeTruthy();
|
|
403
|
+
expect(user.attributes.name).toEqual('Josh Doe');
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { got } from '@kravc/schema';
|
|
2
|
+
import { profileSchema } from '../../Context/__tests__/__helpers';
|
|
3
|
+
import Context, { type MutationMap } from '../../Context';
|
|
4
|
+
import { MemoryDocument, type DefaultAttributes } from '../../';
|
|
5
|
+
|
|
6
|
+
interface ProfileAttributes extends DefaultAttributes {
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/** Example of a default document. */
|
|
11
|
+
class Profile extends MemoryDocument<ProfileAttributes> {
|
|
12
|
+
/** Returns a profile name. */
|
|
13
|
+
get name() {
|
|
14
|
+
return this.attributes.name;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Profile.schema = profileSchema;
|
|
19
|
+
|
|
20
|
+
/** Example of a document with custom getPartition method. */
|
|
21
|
+
class User extends MemoryDocument<ProfileAttributes> {
|
|
22
|
+
/** Returns custom partition based off parameters. */
|
|
23
|
+
static getPartition(_context: Context, parameters: MutationMap) {
|
|
24
|
+
const name = got(parameters, 'name') as string;
|
|
25
|
+
const partition = name[0].toUpperCase();
|
|
26
|
+
|
|
27
|
+
return partition;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
User.schema = profileSchema;
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
User,
|
|
35
|
+
Profile,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type {
|
|
39
|
+
ProfileAttributes,
|
|
40
|
+
};
|