MCPcopy Index your code
hub / github.com/anomalyco/opencode / promisePath

Function promisePath

packages/httpapi-codegen/src/index.ts:586–599  ·  view source on GitHub ↗
(path: string, input: ReadonlyArray<InputField>)

Source from the content-addressed store, hash-verified

584}
585
586function promisePath(path: string, input: ReadonlyArray<InputField>) {
587 if (path.includes("*")) throw new GenerationError({ reason: `Unsupported Promise path wildcard: ${path}` })
588 const fields = new Set(input.filter((field) => field.source === "params").map((field) => field.name))
589 const segments = path.split(/(:[A-Za-z_][A-Za-z0-9_]*)/g).filter(Boolean)
590 const template = segments
591 .map((segment) => {
592 if (!segment.startsWith(":")) return segment.replaceAll("`", "\\`")
593 const name = segment.slice(1)
594 if (!fields.has(name)) throw new GenerationError({ reason: `Missing path parameter: ${name}` })
595 return `\${encodeURIComponent(input.${name})}`
596 })
597 .join("")
598 return `\`${template}\``
599}
600
601function uniqueModule(base: string, index: number, modules: ReadonlySet<string>) {
602 if (!modules.has(base.toLowerCase())) return base

Callers 1

renderPromiseClientFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected