UNPKG

@lunora/cli

Version:

The Lunora CLI: init, dev, deploy, codegen, migrate, seed, doctor, insights, logs, registry, and the rest of the project commands

2 lines (1 loc) 3.34 kB
import{LunoraError as i}from"@lunora/errors";const l=/[\r\n]/u,d=/^[A-Za-z_]\w*$/u,g=/^[A-Za-z0-9][\w-]*$/u,b=/^[\w.-]+(?:\/[\w.-]+)*$/u,L=(a,o)=>{if(typeof a!="object"||a===null)throw new i("INTERNAL",`registry.json for "${o}" is not an object`);const t=a,{name:s}=t;if(typeof s!="string"||s.length===0)throw new i("INTERNAL",`registry.json for "${o}" is missing a string "name"`);if(!g.test(s))throw new i("INTERNAL",`registry.json for "${o}": name "${s}" must match ${g.source} (letters, digits, "-", "_"; no path separators, "..", or code)`);const y=t.files;if(!Array.isArray(y))throw new TypeError(`registry.json for "${o}" is missing a "files" array`);const w=y.map((e,r)=>{if(typeof e!="object"||e===null)throw new i("INTERNAL",`registry.json "${o}": files[${String(r)}] is not an object`);const n=e,{from:f}=n,{to:p}=n,{merge:m}=n;if(typeof f!="string"||typeof p!="string")throw new TypeError(`registry.json "${o}": files[${String(r)}] needs string "from" and "to"`);if(m!=="create-or-skip"&&m!=="schema-extension")throw new i("INTERNAL",`registry.json "${o}": files[${String(r)}].merge must be "create-or-skip" or "schema-extension"`);for(const[R,c]of[["from",f],["to",p]])if(c.includes("..")||c.startsWith("/"))throw new i("INTERNAL",`registry.json "${o}": files[${String(r)}].${R} "${c}" must be a relative path without ".."`);return{from:f,merge:m,to:p}}),u=e=>typeof e=="object"&&e!==null?e:void 0,h=u(t.deps),$=u(t.devDependencies),A=Array.isArray(t.requires)?t.requires.filter(e=>typeof e=="string"):void 0,v=Array.isArray(t.bindings)?t.bindings.filter(e=>{if(typeof e!="object"||e===null)return!1;const r=e;return Array.isArray(r.path)&&r.path.every(n=>typeof n=="string")}):void 0,j=Array.isArray(t.entrypointReexports)?t.entrypointReexports.filter(e=>typeof e=="object"&&e!==null&&typeof e.module=="string").map(e=>{if(e.module.includes("..")||e.module.startsWith("/")||!b.test(e.module))throw new i("INTERNAL",`registry.json "${o}": entrypointReexports[].module "${e.module}" must be a safe relative module path without path traversal or unsafe characters`);const r={module:e.module};if(typeof e.comment=="string"){if(l.test(e.comment))throw new i("INTERNAL",`registry.json "${o}": entrypointReexports[].comment must not contain a newline`);r.comment=e.comment}return r}):void 0,N=Array.isArray(t.envVars)?t.envVars.filter(e=>typeof e=="object"&&e!==null&&typeof e.name=="string").map(e=>{const r=typeof e.value=="string";if(!d.test(e.name))throw new i("INTERNAL",`registry.json "${o}": envVars["${e.name}"].name must match ${d.source} (letters, digits, underscore; no "=" or newline)`);if(r&&l.test(e.value))throw new i("INTERNAL",`registry.json "${o}": envVars["${e.name}"].value must not contain a newline`);if(typeof e.description=="string"&&l.test(e.description))throw new i("INTERNAL",`registry.json "${o}": envVars["${e.name}"].description must not contain a newline`);return{...typeof e.description=="string"?{description:e.description}:{},name:e.name,secret:typeof e.secret=="boolean"?e.secret:!r,...r?{value:e.value}:{}}}):void 0;return{bindings:v,deps:h,description:typeof t.description=="string"?t.description:void 0,devDependencies:$,docs:typeof t.docs=="string"?t.docs:void 0,entrypointReexports:j,envVars:N,files:w,name:s,requires:A,title:typeof t.title=="string"?t.title:void 0}};export{L as default};