mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 06:14:59 +00:00
code: package,get,dbal (1 files)
This commit is contained in:
@@ -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<Result<Package>> {
|
||||
if (!id) {
|
||||
return { success: false, error: { code: 'VALIDATION_ERROR', message: 'ID required' } };
|
||||
export const getPackage = async (store: InMemoryStore, id: string): Promise<Result<Package>> => {
|
||||
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<Result<Package>> {
|
||||
if (!packageId) {
|
||||
return { success: false, error: { code: 'VALIDATION_ERROR', message: 'Package ID required' } };
|
||||
export const getPackageByPackageId = async (store: InMemoryStore, packageKey: string): Promise<Result<Package>> => {
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user