From 8fca8dbc7ebbf12c2bfde3b04823b1276d3f4764 Mon Sep 17 00:00:00 2001 From: JohnDoe6345789 Date: Thu, 25 Dec 2025 19:37:04 +0000 Subject: [PATCH] code: validate,update,package (1 files) --- .../validation/validate-package-update.ts | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 dbal/ts/src/core/validation/validate-package-update.ts diff --git a/dbal/ts/src/core/validation/validate-package-update.ts b/dbal/ts/src/core/validation/validate-package-update.ts new file mode 100644 index 000000000..f49c14170 --- /dev/null +++ b/dbal/ts/src/core/validation/validate-package-update.ts @@ -0,0 +1,51 @@ +import type { Package } from '../types' +import { isPlainObject } from './is-plain-object' +import { isValidDate } from './is-valid-date' +import { isValidSemver } from './is-valid-semver' +import { isValidUuid } from './is-valid-uuid' + +export function validatePackageUpdate(data: Partial): string[] { + const errors: string[] = [] + + if (data.name !== undefined) { + if (typeof data.name !== 'string' || data.name.length === 0 || data.name.length > 255) { + errors.push('name must be 1-255 characters') + } + } + + if (data.version !== undefined) { + if (typeof data.version !== 'string' || !isValidSemver(data.version)) { + errors.push('version must be semantic (x.y.z)') + } + } + + if (data.author !== undefined) { + if (typeof data.author !== 'string' || data.author.length === 0 || data.author.length > 255) { + errors.push('author must be 1-255 characters') + } + } + + if (data.manifest !== undefined && !isPlainObject(data.manifest)) { + errors.push('manifest must be an object') + } + + if (data.isInstalled !== undefined && typeof data.isInstalled !== 'boolean') { + errors.push('isInstalled must be a boolean') + } + + if (data.installedAt !== undefined && !isValidDate(data.installedAt)) { + errors.push('installedAt must be a valid date') + } + + if (data.installedBy !== undefined) { + if (typeof data.installedBy !== 'string' || !isValidUuid(data.installedBy)) { + errors.push('installedBy must be a valid UUID') + } + } + + if (data.description !== undefined && typeof data.description !== 'string') { + errors.push('description must be a string') + } + + return errors +}