diff --git a/dbal/ts/src/core/entities/package/get-package.ts b/dbal/ts/src/core/entities/package/get-package.ts index 9d3a7011d..03d98b01e 100644 --- a/dbal/ts/src/core/entities/package/get-package.ts +++ b/dbal/ts/src/core/entities/package/get-package.ts @@ -2,37 +2,39 @@ * @file get-package.ts * @description Get package operations */ -import type { Package, Result } from '../types'; -import type { InMemoryStore } from '../store/in-memory-store'; +import type { Package, Result } from '../../types' +import type { InMemoryStore } from '../../store/in-memory-store' +import { validateId } from '../../validation/validate-id' /** * Get a package by ID */ -export async function getPackage(store: InMemoryStore, id: string): Promise> { - if (!id) { - return { success: false, error: { code: 'VALIDATION_ERROR', message: 'ID required' } }; +export const getPackage = async (store: InMemoryStore, id: string): Promise> => { + const idErrors = validateId(id) + if (idErrors.length > 0) { + return { success: false, error: { code: 'VALIDATION_ERROR', message: idErrors[0] } } } - const pkg = store.packages.get(id); + const pkg = store.packages.get(id) if (!pkg) { - return { success: false, error: { code: 'NOT_FOUND', message: `Package not found: ${id}` } }; + return { success: false, error: { code: 'NOT_FOUND', message: `Package not found: ${id}` } } } - return { success: true, data: pkg }; + return { success: true, data: pkg } } /** - * Get a package by package_id (snake_case identifier) + * Get a package by name+version key (name@version) */ -export async function getPackageByPackageId(store: InMemoryStore, packageId: string): Promise> { - if (!packageId) { - return { success: false, error: { code: 'VALIDATION_ERROR', message: 'Package ID required' } }; +export const getPackageByPackageId = async (store: InMemoryStore, packageKey: string): Promise> => { + if (!packageKey) { + return { success: false, error: { code: 'VALIDATION_ERROR', message: 'Package key is required' } } } - const id = store.packageIds.get(packageId); + const id = store.packageKeys.get(packageKey) if (!id) { - return { success: false, error: { code: 'NOT_FOUND', message: `Package not found: ${packageId}` } }; + return { success: false, error: { code: 'NOT_FOUND', message: `Package not found: ${packageKey}` } } } - return getPackage(store, id); + return getPackage(store, id) }