UNPKG

@next-boilerplate/cli-helpers

Version:
36 lines (33 loc) 1.26 kB
import { z } from 'zod'; const storeConfigFileName = "config.json"; const storeNameRegex = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/; const storeVersionRegex = /^[~^]?[\da-z.-]+$/; const matchItem = /^((?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*)@([~^]?[\da-z.-]+)\/(.*)$/; const storeSchema = z.object({ name: z.string().regex(storeNameRegex).max(100), version: z.string().regex(storeVersionRegex).max(100) }); const storeConfigSchema = z.object({ name: z.string().regex(storeNameRegex).max(100), version: z.string().regex(storeVersionRegex).max(100) }); const fullStoreSchema = storeConfigSchema.extend({ uid: z.string(), fullPath: z.string() }); const getStoreUID = (store) => `${store.name}@${store.version}`; const getItemUID = (item) => `${item.store.name}@${item.store.version}/${item.name}`; const extractItemUID = (itemUID) => { const match = itemUID.match(matchItem); if (!match) { throw new Error(`Invalid item UID: ${itemUID}`); } return { store: { name: match[1], version: match[2] }, name: match[3] }; }; export { extractItemUID, fullStoreSchema, getItemUID, getStoreUID, matchItem, storeConfigFileName, storeConfigSchema, storeNameRegex, storeSchema, storeVersionRegex };