UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

1 lines 2.52 kB
{"version":3,"file":"catalog.cjs","names":["bosContract","cliCommandMeta"],"sources":["../../src/cli/catalog.ts"],"sourcesContent":["import { bosContract } from \"../contract\";\nimport { type CliCommandMeta, cliCommandMeta } from \"../contract.meta\";\n\nexport type CommandDescriptor = {\n key: keyof typeof bosContract;\n commandPath: string[];\n summary: string;\n meta: CliCommandMeta;\n procedure: (typeof bosContract)[keyof typeof bosContract];\n};\n\nfunction splitCamelCase(value: string): string[] {\n return value\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .split(/\\s+/)\n .map((part) => part.trim())\n .filter(Boolean)\n .map((part) => part.toLowerCase());\n}\n\nexport const commandCatalog: CommandDescriptor[] = (\n Object.entries(bosContract) as Array<\n [keyof typeof bosContract, (typeof bosContract)[keyof typeof bosContract]]\n >\n).map(([key, procedure]) => {\n const meta = cliCommandMeta[key as keyof typeof cliCommandMeta] ?? {\n summary: splitCamelCase(String(key)).join(\" \"),\n };\n return {\n key,\n commandPath: meta.commandPath ?? splitCamelCase(String(key)),\n summary: meta.summary,\n meta,\n procedure,\n };\n});\n\nconst sortedCommandCatalog = [...commandCatalog].sort(\n (a, b) => b.commandPath.length - a.commandPath.length,\n);\n\nexport function findCommandDescriptor(\n args: string[],\n): { descriptor: CommandDescriptor; consumed: number } | null {\n for (const descriptor of sortedCommandCatalog) {\n const parts = args.slice(0, descriptor.commandPath.length).map((part) => part.toLowerCase());\n if (parts.join(\" \") === descriptor.commandPath.join(\" \")) {\n return { descriptor, consumed: descriptor.commandPath.length };\n }\n }\n return null;\n}\n"],"mappings":";;;;AAWA,SAAS,eAAe,OAAyB;CAC/C,OAAO,MACJ,QAAQ,sBAAsB,OAAO,CAAC,CACtC,MAAM,KAAK,CAAC,CACZ,KAAK,SAAS,KAAK,KAAK,CAAC,CAAC,CAC1B,OAAO,OAAO,CAAC,CACf,KAAK,SAAS,KAAK,YAAY,CAAC;AACrC;AAEA,MAAa,iBACX,OAAO,QAAQA,4BAAW,CAAC,CAG3B,KAAK,CAAC,KAAK,eAAe;CAC1B,MAAM,OAAOC,qCAAe,QAAuC,EACjE,SAAS,eAAe,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAC/C;CACA,OAAO;EACL;EACA,aAAa,KAAK,eAAe,eAAe,OAAO,GAAG,CAAC;EAC3D,SAAS,KAAK;EACd;EACA;CACF;AACF,CAAC;AAED,MAAM,uBAAuB,CAAC,GAAG,cAAc,CAAC,CAAC,MAC9C,GAAG,MAAM,EAAE,YAAY,SAAS,EAAE,YAAY,MACjD;AAEA,SAAgB,sBACd,MAC4D;CAC5D,KAAK,MAAM,cAAc,sBAEvB,IADc,KAAK,MAAM,GAAG,WAAW,YAAY,MAAM,CAAC,CAAC,KAAK,SAAS,KAAK,YAAY,CAClF,CAAC,CAAC,KAAK,GAAG,MAAM,WAAW,YAAY,KAAK,GAAG,GACrD,OAAO;EAAE;EAAY,UAAU,WAAW,YAAY;CAAO;CAGjE,OAAO;AACT"}