diff --git a/package-lock.json b/package-lock.json index 19e6c477d..a153e4701 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7618,25 +7618,27 @@ } }, "node_modules/@validup/adapter-routup": { - "version": "0.1.8", - "resolved": "https://registry.npmjs.org/@validup/adapter-routup/-/adapter-routup-0.1.8.tgz", - "integrity": "sha512-qLcqxm4YuwFWysfJThxMgEhOyz/9K3W+ZCuuCaoAsE3J5RJbJEFiMoI1aMJPp/56H2RA14Q2Md8ukksbAo5EWQ==", + "version": "0.1.9", + "resolved": "https://registry.npmjs.org/@validup/adapter-routup/-/adapter-routup-0.1.9.tgz", + "integrity": "sha512-VMiiqQoLeXgosdlKEwzoeVXHP5Dr4cNNChkCnBzPibtWsJPwQXPJpdVqzVssXSjiYOu8zmoqhAUbSu53KAD6+A==", + "license": "MIT", "engines": { "node": ">=18.0.0" }, "peerDependencies": { "@routup/basic": "^1.4.1", "routup": "^4.0.1", - "validup": "^0.1.7" + "validup": "^0.1.8" } }, "node_modules/@validup/adapter-validator": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/@validup/adapter-validator/-/adapter-validator-0.1.7.tgz", - "integrity": "sha512-ioLFf112KRpBBKk9FKLWVEBWr5BsVPVBQ2MnY4AvYJRqZAU+wVtFkSP9Q9BeCTAxLjeSdVlAdS1VggJvuUslmg==", + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@validup/adapter-validator/-/adapter-validator-0.2.0.tgz", + "integrity": "sha512-q+FOnpIJ949a7Nyn9o0hp1R7whilszdvWPY3ESz6TabGlYxQQ1+ZcMf7cF547YMxhsCkg7g7kRA8qD/Vd1dBEg==", + "license": "MIT", "dependencies": { "smob": "^1.5.0", - "validup": "^0.1.7" + "validup": "^0.1.8" }, "engines": { "node": ">=18.0.0" @@ -26226,12 +26228,12 @@ } }, "node_modules/validup": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/validup/-/validup-0.1.7.tgz", - "integrity": "sha512-s4HqxKHBZMe2YukL+NrnDnDqND/ajUxXCdjwYpT8lkI8eNtnGde/7ABiW06r04LpBQlMJmrkhvjrXKdIOj7NoA==", + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/validup/-/validup-0.1.8.tgz", + "integrity": "sha512-nKqXeNxvwLbUdpt8bRPDkTnYk8Wm9Hu1jSso5ZCBZbOxSauVk4Y8Vx6XyanhAE2sgjLhyrGe3S9lzi/3Bz1T4w==", "license": "MIT", "dependencies": { - "pathtrace": "^1.0.0", + "pathtrace": "^1.1.0", "smob": "^1.5.0" }, "engines": { @@ -28262,8 +28264,8 @@ "@routup/rate-limit": "^2.4.0", "@routup/swagger": "^2.4.1", "@socket.io/redis-emitter": "^5.1.0", - "@validup/adapter-routup": "^0.1.8", - "@validup/adapter-validator": "^0.1.7", + "@validup/adapter-routup": "^0.1.9", + "@validup/adapter-validator": "^0.2.0", "amqp-extension": "^4.0.0-beta.3", "busboy": "^1.6.0", "cors": "^2.8.5", @@ -28283,7 +28285,7 @@ "singa": "^1.0.0", "typeorm": "^0.3.20", "typeorm-extension": "^3.6.3", - "validup": "^0.1.7", + "validup": "^0.1.8", "yargs": "^17.7.1", "zod": "^3.23.7" }, @@ -28343,7 +28345,7 @@ "cors": "^2.8.5", "hapic": "^2.5.1", "locter": "^2.1.4", - "validup": "^0.1.7" + "validup": "^0.1.8" }, "devDependencies": { "@types/cors": "^2.8.17", @@ -28445,8 +28447,8 @@ "@privateaim/storage-kit": "^0.8.4", "@routup/basic": "^1.4.1", "@routup/decorators": "^3.4.1", - "@validup/adapter-routup": "^0.1.8", - "@validup/adapter-validator": "^0.1.7", + "@validup/adapter-routup": "^0.1.9", + "@validup/adapter-validator": "^0.2.0", "busboy": "^1.6.0", "cors": "^2.8.5", "dotenv": "^16.4.4", @@ -28461,7 +28463,7 @@ "tar-stream": "^3.1.6", "typeorm": "^0.3.20", "typeorm-extension": "^3.6.3", - "validup": "^0.1.7" + "validup": "^0.1.8" }, "devDependencies": { "@types/busboy": "^1.5.3", diff --git a/packages/server-core/package.json b/packages/server-core/package.json index 385d6c2b9..644b6a66d 100644 --- a/packages/server-core/package.json +++ b/packages/server-core/package.json @@ -30,8 +30,8 @@ "@routup/rate-limit": "^2.4.0", "@routup/swagger": "^2.4.1", "@socket.io/redis-emitter": "^5.1.0", - "@validup/adapter-routup": "^0.1.8", - "@validup/adapter-validator": "^0.1.7", + "@validup/adapter-routup": "^0.1.9", + "@validup/adapter-validator": "^0.2.0", "amqp-extension": "^4.0.0-beta.3", "busboy": "^1.6.0", "cors": "^2.8.5", @@ -51,7 +51,7 @@ "singa": "^1.0.0", "typeorm": "^0.3.20", "typeorm-extension": "^3.6.3", - "validup": "^0.1.7", + "validup": "^0.1.8", "yargs": "^17.7.1", "zod": "^3.23.7" }, diff --git a/packages/server-core/src/http/controllers/analysis-bucket-file/utils/validator.ts b/packages/server-core/src/http/controllers/analysis-bucket-file/utils/validator.ts index bcedc9d3c..b04462e5a 100644 --- a/packages/server-core/src/http/controllers/analysis-bucket-file/utils/validator.ts +++ b/packages/server-core/src/http/controllers/analysis-bucket-file/utils/validator.ts @@ -7,7 +7,7 @@ import { Container } from 'validup'; import type { AnalysisBucketFile } from '@privateaim/core-kit'; -import { createValidator } from '@validup/adapter-validator'; +import { createValidationChain, createValidator } from '@validup/adapter-validator'; import { HTTPHandlerOperation } from '@privateaim/server-http-kit'; export class AnalysisBucketFileValidator extends Container { @@ -17,44 +17,56 @@ export class AnalysisBucketFileValidator extends Container { this.mount( 'bucket_id', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .notEmpty() - .isUUID()), + createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .notEmpty() + .isUUID(); + }), ); + const nameValidator = createValidator(() => { + const chain = createValidationChain(); + + return chain + .exists() + .isString(); + }); this.mount( 'name', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .isString()), + nameValidator, ); this.mount( 'name', { group: HTTPHandlerOperation.UPDATE, optional: true }, - createValidator((chain) => chain - .exists() - .isString() - .optional({ values: 'null' })), + nameValidator, ); this.mount( 'external_id', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .isUUID()), + createValidator(() => { + const chain = createValidationChain(); + + return chain + .exists() + .isUUID(); + }), ); this.mount( 'root', - createValidator((chain) => chain - .optional() - .toBoolean() - .isBoolean() - .default(false)), + createValidator(() => { + const chain = createValidationChain(); + return chain + .optional() + .toBoolean() + .isBoolean() + .default(false); + }), ); } } diff --git a/packages/server-core/src/http/controllers/analysis-bucket/utils/validator.ts b/packages/server-core/src/http/controllers/analysis-bucket/utils/validator.ts index 8de088649..b112bf639 100644 --- a/packages/server-core/src/http/controllers/analysis-bucket/utils/validator.ts +++ b/packages/server-core/src/http/controllers/analysis-bucket/utils/validator.ts @@ -8,7 +8,7 @@ import type { AnalysisBucket } from '@privateaim/core-kit'; import { AnalysisBucketType } from '@privateaim/core-kit'; import { Container } from 'validup'; -import { createValidator } from '@validup/adapter-validator'; +import { createValidationChain, createValidator } from '@validup/adapter-validator'; import { HTTPHandlerOperation } from '@privateaim/server-http-kit'; export class AnalysisBucketValidator extends Container { @@ -18,18 +18,26 @@ export class AnalysisBucketValidator extends Container { this.mount( 'analysis_id', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .notEmpty() - .isUUID()), + createValidator(() => { + const chain = createValidationChain(); + + return chain + .exists() + .notEmpty() + .isUUID(); + }), ); this.mount( 'type', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .notEmpty() - .isIn(Object.values(AnalysisBucketType))), + createValidator(() => { + const chain = createValidationChain(); + + return chain + .notEmpty() + .isIn(Object.values(AnalysisBucketType)); + }), ); } } diff --git a/packages/server-core/src/http/controllers/analysis-node/handlers/update.ts b/packages/server-core/src/http/controllers/analysis-node/handlers/update.ts index 9eb89bb2b..d8875cf6d 100644 --- a/packages/server-core/src/http/controllers/analysis-node/handlers/update.ts +++ b/packages/server-core/src/http/controllers/analysis-node/handlers/update.ts @@ -85,7 +85,7 @@ export async function updateAnalysisNodeRouteHandler(req: Request, res: Response } if (!isAuthorityOfNode || !canUpdate) { - if (data.run_status) { + if (isPropertySet(data, 'run_status')) { throw new BadRequestError( 'You are either no authority of the node or you don\'t have the required permissions.', ); diff --git a/packages/server-core/src/http/controllers/analysis-node/utils/validation.ts b/packages/server-core/src/http/controllers/analysis-node/utils/validation.ts index 29f896077..34a1360de 100644 --- a/packages/server-core/src/http/controllers/analysis-node/utils/validation.ts +++ b/packages/server-core/src/http/controllers/analysis-node/utils/validation.ts @@ -7,7 +7,7 @@ import { AnalysisNodeApprovalStatus, AnalysisNodeRunStatus } from '@privateaim/core-kit'; import { Container } from 'validup'; -import { createValidator } from '@validup/adapter-validator'; +import { createValidationChain, createValidator } from '@validup/adapter-validator'; import { HTTPHandlerOperation } from '@privateaim/server-http-kit'; import type { AnalysisNodeEntity } from '../../../../domains'; @@ -18,52 +18,70 @@ export class AnalysisNodeValidator extends Container { this.mount( 'node_id', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .notEmpty() - .isUUID()), + createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .notEmpty() + .isUUID(); + }), ); this.mount( 'analysis_id', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .notEmpty() - .isUUID()), + createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .notEmpty() + .isUUID(); + }), ); this.mount( 'run_status', { optional: true }, - createValidator((chain) => chain - .isIn(Object.values(AnalysisNodeRunStatus)) - .optional({ values: 'null' })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isIn(Object.values(AnalysisNodeRunStatus)) + .optional({ values: 'null' }); + }), ); this.mount( 'index', { optional: true }, - createValidator((chain) => chain - .exists() - .isInt() - .optional({ values: 'null' })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .isInt() + .optional({ values: 'null' }); + }), ); this.mount( 'approval_status', { optional: true }, - createValidator((chain) => chain - .optional({ nullable: true }) - .isIn(Object.values(AnalysisNodeApprovalStatus))), + createValidator(() => { + const chain = createValidationChain(); + return chain + .optional({ nullable: true }) + .isIn(Object.values(AnalysisNodeApprovalStatus)); + }), ); this.mount( 'comment', { optional: true }, - createValidator((chain) => chain - .optional({ nullable: true }) - .isString()), + createValidator(() => { + const chain = createValidationChain(); + return chain + .optional({ nullable: true }) + .isString(); + }), ); } } diff --git a/packages/server-core/src/http/controllers/analysis-permission/utils/validation.ts b/packages/server-core/src/http/controllers/analysis-permission/utils/validation.ts index 7a6352545..9d80d1a9b 100644 --- a/packages/server-core/src/http/controllers/analysis-permission/utils/validation.ts +++ b/packages/server-core/src/http/controllers/analysis-permission/utils/validation.ts @@ -6,7 +6,7 @@ */ import { Container } from 'validup'; -import { createValidator } from '@validup/adapter-validator'; +import { createValidationChain, createValidator } from '@validup/adapter-validator'; import { HTTPHandlerOperation } from '@privateaim/server-http-kit'; import type { AnalysisPermissionEntity } from '../../../../domains'; @@ -17,27 +17,38 @@ export class AnalysisPermissionValidator extends Container chain - .exists() - .notEmpty() - .isUUID()), + createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .notEmpty() + .isUUID(); + }), ); this.mount( 'analysis_id', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .notEmpty() - .isUUID()), + createValidator(() => { + const chain = createValidationChain(); + + return chain + .exists() + .notEmpty() + .isUUID(); + }), ); this.mount( 'policy_id', { optional: true }, - createValidator((chain) => chain - .isUUID() - .optional({ values: 'null' })), + createValidator(() => { + const chain = createValidationChain(); + + return chain + .isUUID() + .optional({ values: 'null' }); + }), ); } } diff --git a/packages/server-core/src/http/controllers/analysis/utils/validator-command.ts b/packages/server-core/src/http/controllers/analysis/utils/validator-command.ts index 1795ef871..460e1b21f 100644 --- a/packages/server-core/src/http/controllers/analysis/utils/validator-command.ts +++ b/packages/server-core/src/http/controllers/analysis/utils/validator-command.ts @@ -6,7 +6,7 @@ */ import { AnalysisAPICommand } from '@privateaim/core-kit'; -import { createValidator } from '@validup/adapter-validator'; +import { createValidationChain, createValidator } from '@validup/adapter-validator'; import { Container } from 'validup'; export class AnalysisCommandValidator extends Container<{ command: AnalysisAPICommand }> { @@ -15,9 +15,12 @@ export class AnalysisCommandValidator extends Container<{ command: AnalysisAPICo this.mount( 'command', - createValidator((chain) => chain - .exists() - .custom((command) => Object.values(AnalysisAPICommand).includes(command))), + createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .custom((command) => Object.values(AnalysisAPICommand).includes(command)); + }), ); } } diff --git a/packages/server-core/src/http/controllers/analysis/utils/validator.ts b/packages/server-core/src/http/controllers/analysis/utils/validator.ts index 9cdd8478e..12d0dc6a0 100644 --- a/packages/server-core/src/http/controllers/analysis/utils/validator.ts +++ b/packages/server-core/src/http/controllers/analysis/utils/validator.ts @@ -6,7 +6,7 @@ */ import { Container } from 'validup'; -import { createValidator } from '@validup/adapter-validator'; +import { createValidationChain, createValidator } from '@validup/adapter-validator'; import type { Analysis } from '@privateaim/core-kit'; import { HTTPHandlerOperation } from '@privateaim/server-http-kit'; @@ -17,44 +17,59 @@ export class AnalysisValidator extends Container { this.mount( 'project_id', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .notEmpty() - .isUUID()), + createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .notEmpty() + .isUUID(); + }), ); this.mount( 'name', { optional: true }, - createValidator((chain) => chain - .isString() - .isLength({ min: 3, max: 128 }) - .optional({ values: 'null' })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isString() + .isLength({ min: 3, max: 128 }) + .optional({ values: 'null' }); + }), ); this.mount( 'description', { optional: true }, - createValidator((chain) => chain - .isString() - .isLength({ min: 5, max: 4096 }) - .optional({ values: 'null' })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isString() + .isLength({ min: 5, max: 4096 }) + .optional({ values: 'null' }); + }), ); this.mount( 'master_image_id', { optional: true }, - createValidator((chain) => chain - .isUUID() - .optional({ values: 'null' })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isUUID() + .optional({ values: 'null' }); + }), ); this.mount( 'registry_id', { optional: true }, - createValidator((chain) => chain - .isUUID() - .optional({ values: 'null' })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isUUID() + .optional({ values: 'null' }); + }), ); } } diff --git a/packages/server-core/src/http/controllers/node/utils/validation.ts b/packages/server-core/src/http/controllers/node/utils/validation.ts index a430e438c..e5bda2022 100644 --- a/packages/server-core/src/http/controllers/node/utils/validation.ts +++ b/packages/server-core/src/http/controllers/node/utils/validation.ts @@ -7,7 +7,7 @@ import { NodeType } from '@privateaim/core-kit'; import { Container } from 'validup'; -import { createValidator } from '@validup/adapter-validator'; +import { createValidationChain, createValidator } from '@validup/adapter-validator'; import { HTTPHandlerOperation } from '@privateaim/server-http-kit'; import type { NodeEntity } from '../../../../domains'; @@ -18,78 +18,106 @@ export class NodeValidator extends Container { this.mount( 'name', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .isLength({ min: 3, max: 128 }) - .exists() - .notEmpty()), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isLength({ min: 3, max: 128 }) + .exists() + .notEmpty(); + }), ); this.mount( 'name', { group: HTTPHandlerOperation.UPDATE, optional: true }, - createValidator((chain) => chain - .isLength({ min: 3, max: 128 }) - .optional({ values: 'null' })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isLength({ min: 3, max: 128 }) + .optional({ values: 'null' }); + }), ); this.mount( 'type', { optional: true }, - createValidator((chain) => chain - .isIn(Object.values(NodeType)) - .optional({ values: 'null' })), + createValidator(() => { + const chain = createValidationChain(); + + return chain + .isIn(Object.values(NodeType)) + .optional({ values: 'null' }); + }), ); this.mount( 'hidden', { optional: true }, - createValidator((chain) => chain - .isBoolean() - .optional({ values: 'null' })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isBoolean() + .optional({ values: 'null' }); + }), ); this.mount( 'public_key', { optional: true }, - createValidator((chain) => chain - .isLength({ min: 5, max: 4096 }) - .exists() - .optional({ values: 'null' })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isLength({ min: 5, max: 4096 }) + .exists() + .optional({ values: 'null' }); + }), ); this.mount( 'external_name', { optional: true }, - createValidator((chain) => chain - .isLength({ min: 1, max: 64 }) - .exists() - .matches(/^[a-z0-9-_]*$/) - .optional({ nullable: true })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isLength({ min: 1, max: 64 }) + .exists() + .matches(/^[a-z0-9-_]*$/) + .optional({ nullable: true }); + }), ); this.mount( 'registry_id', { optional: true }, - createValidator((chain) => chain - .isUUID() - .optional({ nullable: true })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isUUID() + .optional({ nullable: true }); + }), ); this.mount( 'robot_id', { optional: true }, - createValidator((chain) => chain - .isUUID() - .optional({ nullable: true })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isUUID() + .optional({ nullable: true }); + }), ); this.mount( 'realm_id', { group: HTTPHandlerOperation.CREATE, optional: true }, - createValidator((chain) => chain - .exists() - .isUUID() - .optional({ nullable: true })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .isUUID() + .optional({ nullable: true }); + }), ); } } diff --git a/packages/server-core/src/http/controllers/project-node/utils/validation.ts b/packages/server-core/src/http/controllers/project-node/utils/validation.ts index 29fa57143..2b302892b 100644 --- a/packages/server-core/src/http/controllers/project-node/utils/validation.ts +++ b/packages/server-core/src/http/controllers/project-node/utils/validation.ts @@ -7,7 +7,7 @@ import { ProjectNodeApprovalStatus } from '@privateaim/core-kit'; import { Container } from 'validup'; -import { createValidator } from '@validup/adapter-validator'; +import { createValidationChain, createValidator } from '@validup/adapter-validator'; import { HTTPHandlerOperation } from '@privateaim/server-http-kit'; import type { ProjectNodeEntity } from '../../../../domains'; @@ -18,36 +18,48 @@ export class ProjectNodeValidator extends Container { this.mount( 'project_id', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .notEmpty() - .isUUID()), + createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .notEmpty() + .isUUID(); + }), ); this.mount( 'node_id', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .notEmpty() - .isUUID()), + createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .notEmpty() + .isUUID(); + }), ); this.mount( 'approval_status', { group: HTTPHandlerOperation.UPDATE }, - createValidator((chain) => chain - .optional({ values: 'null' }) - .isIn(Object.values(ProjectNodeApprovalStatus))), + createValidator(() => { + const chain = createValidationChain(); + return chain + .optional({ values: 'null' }) + .isIn(Object.values(ProjectNodeApprovalStatus)); + }), ); this.mount( 'comment', { group: HTTPHandlerOperation.UPDATE, optional: true }, - createValidator((chain) => chain - .optional({ nullable: true }) - .isString() - .isLength({ min: 3, max: 4096 })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .optional({ nullable: true }) + .isString() + .isLength({ min: 3, max: 4096 }); + }), ); } } diff --git a/packages/server-core/src/http/controllers/project/utils/validator.ts b/packages/server-core/src/http/controllers/project/utils/validator.ts index e27327c51..918f0515f 100644 --- a/packages/server-core/src/http/controllers/project/utils/validator.ts +++ b/packages/server-core/src/http/controllers/project/utils/validator.ts @@ -6,7 +6,7 @@ */ import { Container } from 'validup'; -import { createValidator } from '@validup/adapter-validator'; +import { createValidationChain, createValidator } from '@validup/adapter-validator'; import { HTTPHandlerOperation } from '@privateaim/server-http-kit'; import type { ProjectEntity } from '../../../../domains'; @@ -14,37 +14,45 @@ export class ProjectValidator extends Container { protected initialize() { super.initialize(); + const nameValidator = createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .isLength({ min: 5, max: 100 }); + }); this.mount( 'name', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .isLength({ min: 5, max: 100 })), + nameValidator, ); this.mount( 'name', { group: HTTPHandlerOperation.UPDATE, optional: true }, - createValidator((chain) => chain - .exists() - .isLength({ min: 5, max: 100 })), + nameValidator, ); this.mount( 'description', { optional: true }, - createValidator((chain) => chain - .isString() - .isLength({ min: 5, max: 4096 }) - .optional({ values: 'null' })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isString() + .isLength({ min: 5, max: 4096 }) + .optional({ values: 'null' }); + }), ); this.mount( 'master_image_id', { optional: true }, - createValidator((chain) => chain - .isUUID() - .optional({ nullable: true })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isUUID() + .optional({ nullable: true }); + }), ); } } diff --git a/packages/server-core/src/http/controllers/registry-project/utils/validator.ts b/packages/server-core/src/http/controllers/registry-project/utils/validator.ts index 1bcc1b5be..41a020831 100644 --- a/packages/server-core/src/http/controllers/registry-project/utils/validator.ts +++ b/packages/server-core/src/http/controllers/registry-project/utils/validator.ts @@ -7,7 +7,7 @@ import { RegistryProjectType } from '@privateaim/core-kit'; import { Container } from 'validup'; -import { createValidator } from '@validup/adapter-validator'; +import { createValidationChain, createValidator } from '@validup/adapter-validator'; import { HTTPHandlerOperation } from '@privateaim/server-http-kit'; import type { RegistryProjectEntity } from '../../../../domains'; @@ -18,54 +18,61 @@ export class RegistryProjectValidator extends Container { this.mount( 'registry_id', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .notEmpty() - .isUUID()), + createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .notEmpty() + .isUUID(); + }), ); + const nameValidator = createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .isLength({ min: 5, max: 128 }); + }); this.mount( 'name', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .isLength({ min: 5, max: 128 })), + nameValidator, ); this.mount( 'name', { group: HTTPHandlerOperation.UPDATE, optional: true }, - createValidator((chain) => chain - .exists() - .isLength({ min: 5, max: 128 }) - .optional({ values: 'null' })), + nameValidator, ); + const externalNameValidator = createValidator(() => { + const chain = createValidationChain(); + return chain + .isLength({ min: 1, max: 255 }) + .exists() + .matches(/^[a-z0-9-_]*$/); + }); this.mount( 'external_name', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .isLength({ min: 1, max: 255 }) - .exists() - .matches(/^[a-z0-9-_]*$/)), + externalNameValidator, ); this.mount( 'external_name', { group: HTTPHandlerOperation.UPDATE, optional: true }, - createValidator((chain) => chain - .isLength({ min: 1, max: 255 }) - .exists() - .matches(/^[a-z0-9-_]*$/) - .optional({ values: 'null' })), + externalNameValidator, ); this.mount( 'type', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .isIn(Object.values(RegistryProjectType))), + createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .isIn(Object.values(RegistryProjectType)); + }), ); } } diff --git a/packages/server-core/src/http/controllers/registry/utils/validator.ts b/packages/server-core/src/http/controllers/registry/utils/validator.ts index 269f0e13a..bc48e81c6 100644 --- a/packages/server-core/src/http/controllers/registry/utils/validator.ts +++ b/packages/server-core/src/http/controllers/registry/utils/validator.ts @@ -6,7 +6,7 @@ */ import { Container } from 'validup'; -import { createValidator } from '@validup/adapter-validator'; +import { createValidationChain, createValidator } from '@validup/adapter-validator'; import { HTTPHandlerOperation } from '@privateaim/server-http-kit'; import type { RegistryEntity } from '../../../../domains'; @@ -14,58 +14,66 @@ export class RegistryValidator extends Container { protected initialize() { super.initialize(); + const nameValidator = createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .isLength({ min: 3, max: 128 }); + }); + this.mount( 'name', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .isLength({ min: 3, max: 128 })), + nameValidator, ); this.mount( 'name', { group: HTTPHandlerOperation.UPDATE, optional: true }, - createValidator((chain) => chain - .exists() - .isLength({ min: 3, max: 128 }) - .optional({ values: 'null' })), + nameValidator, ); + const hostValidator = createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .isString() + .isLength({ min: 3, max: 512 }); + }); this.mount( 'host', { group: HTTPHandlerOperation.CREATE }, - createValidator((chain) => chain - .exists() - .isString() - .isLength({ min: 3, max: 512 })), + hostValidator, ); this.mount( 'host', { group: HTTPHandlerOperation.CREATE, optional: true }, - createValidator((chain) => chain - .exists() - .isString() - .isLength({ min: 3, max: 512 }) - .optional({ values: 'null' })), + hostValidator, ); this.mount( 'account_name', { optional: true }, - createValidator((chain) => chain - .exists() - .isLength({ min: 3, max: 256 }) - .optional({ nullable: true })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .isLength({ min: 3, max: 256 }) + .optional({ nullable: true }); + }), ); this.mount( 'account_secret', { optional: true }, - createValidator((chain) => chain - .exists() - .isLength({ min: 3, max: 256 }) - .optional({ nullable: true })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .exists() + .isLength({ min: 3, max: 256 }) + .optional({ nullable: true }); + }), ); } } diff --git a/packages/server-core/src/http/controllers/service/utils/validation.ts b/packages/server-core/src/http/controllers/service/utils/validation.ts index 42c1da739..3d882b0ae 100644 --- a/packages/server-core/src/http/controllers/service/utils/validation.ts +++ b/packages/server-core/src/http/controllers/service/utils/validation.ts @@ -6,7 +6,7 @@ */ import { RegistryAPICommand } from '@privateaim/core-kit'; -import { createValidator } from '@validup/adapter-validator'; +import { createValidationChain, createValidator } from '@validup/adapter-validator'; import { Container } from 'validup'; type ValidationResult = { @@ -21,23 +21,32 @@ export class ServiceRegistryValidator extends Container { this.mount( 'id', - createValidator((chain) => chain - .isUUID()), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isUUID(); + }), ); this.mount( 'command', - createValidator((chain) => chain - .isString() - .custom((value) => Object.values(RegistryAPICommand).includes(value))), + createValidator(() => { + const chain = createValidationChain(); + return chain + .isString() + .custom((value) => Object.values(RegistryAPICommand).includes(value)); + }), ); this.mount( 'secret', { optional: true }, - createValidator((chain) => chain - .matches(/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).{8,}$/) - .optional({ nullable: true })), + createValidator(() => { + const chain = createValidationChain(); + return chain + .matches(/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).{8,}$/) + .optional({ nullable: true }); + }), ); } } diff --git a/packages/server-http-kit/package.json b/packages/server-http-kit/package.json index 023d44ec8..13e40655b 100644 --- a/packages/server-http-kit/package.json +++ b/packages/server-http-kit/package.json @@ -27,7 +27,7 @@ "cors": "^2.8.5", "hapic": "^2.5.1", "locter": "^2.1.4", - "validup": "^0.1.7" + "validup": "^0.1.8" }, "devDependencies": { "@types/cors": "^2.8.17", diff --git a/packages/server-storage/package.json b/packages/server-storage/package.json index 2cc4c7b94..2b50f721a 100644 --- a/packages/server-storage/package.json +++ b/packages/server-storage/package.json @@ -20,8 +20,8 @@ "@privateaim/storage-kit": "^0.8.4", "@routup/basic": "^1.4.1", "@routup/decorators": "^3.4.1", - "@validup/adapter-routup": "^0.1.8", - "@validup/adapter-validator": "^0.1.7", + "@validup/adapter-routup": "^0.1.9", + "@validup/adapter-validator": "^0.2.0", "busboy": "^1.6.0", "cors": "^2.8.5", "dotenv": "^16.4.4", @@ -36,7 +36,7 @@ "tar-stream": "^3.1.6", "typeorm": "^0.3.20", "typeorm-extension": "^3.6.3", - "validup": "^0.1.7" + "validup": "^0.1.8" }, "devDependencies": { "@types/busboy": "^1.5.3", diff --git a/packages/server-storage/src/http/controllers/bucket/utils/validation.ts b/packages/server-storage/src/http/controllers/bucket/utils/validation.ts index 84e1b46bd..d0e26f3cb 100644 --- a/packages/server-storage/src/http/controllers/bucket/utils/validation.ts +++ b/packages/server-storage/src/http/controllers/bucket/utils/validation.ts @@ -6,7 +6,7 @@ */ import { HTTPHandlerOperation } from '@privateaim/server-http-kit'; -import { createValidator } from '@validup/adapter-validator'; +import { createValidationChain, createValidator } from '@validup/adapter-validator'; import { Container } from 'validup'; import type { BucketEntity } from '../../../../domains'; @@ -18,7 +18,10 @@ export class BucketValidator extends Container { 'name', { group: HTTPHandlerOperation.CREATE }, createValidator( - (chain) => chain.isLength({ min: 3, max: 256 }), + () => { + const chain = createValidationChain(); + return chain.isLength({ min: 3, max: 256 }); + }, ), ); @@ -26,9 +29,12 @@ export class BucketValidator extends Container { 'region', { group: HTTPHandlerOperation.CREATE, optional: true }, createValidator( - (chain) => chain - .isLength({ min: 3, max: 256 }) - .optional({ values: 'null' }), + () => { + const chain = createValidationChain(); + return chain + .isLength({ min: 3, max: 256 }) + .optional({ values: 'null' }); + }, ), ); }