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

Function expand

packages/httpapi-codegen/src/index.ts:570–580  ·  view source on GitHub ↗
(type: string, seen = new Set<string>())

Source from the content-addressed store, hash-verified

568 document.references.nonRecursives.map((reference) => [reference.$ref, reference.code.Type]),
569 )
570 const expand = (type: string, seen = new Set<string>()): string => {
571 for (const [reference, value] of references) {
572 const pattern = `(?<![A-Za-z0-9_$.'"])${reference.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?![A-Za-z0-9_$.'"])`
573 if (!new RegExp(pattern).test(type)) continue
574 if (seen.has(reference)) {
575 throw new GenerationError({ reason: `Recursive Promise types are not implemented: ${reference}` })
576 }
577 type = type.replace(new RegExp(pattern, "g"), `(${expand(value, new Set([...seen, reference]))})`)
578 }
579 return type
580 }
581 return expand(document.codes[0].Type)
582 .replaceAll(/ & Brand\.Brand<"[^"]+">/g, "")
583 .replaceAll("Schema.Json", "JsonValue")

Callers 1

structuralTypeFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected