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

Function normalizeTransport

packages/httpapi-codegen/src/index.ts:609–647  ·  view source on GitHub ↗
(
  schema: Schema.Top | undefined,
  source: InputField["source"] | "success" | "error",
  endpoint: HttpApiEndpoint.AnyWithProps,
  operation: string,
)

Source from the content-addressed store, hash-verified

607}
608
609function normalizeTransport(
610 schema: Schema.Top | undefined,
611 source: InputField["source"] | "success" | "error",
612 endpoint: HttpApiEndpoint.AnyWithProps,
613 operation: string,
614) {
615 if (schema === undefined) return undefined
616 if (isStreamSchema(schema)) return { schema, effectPortable: true } as const
617 if (!metadataPortable(schema.ast, new Set())) {
618 throw new GenerationError({ reason: `Unportable schema: ${operation}.${source}` })
619 }
620 const decoded = Schema.toType(schema)
621 if (!isPathInput(endpoint.path)) {
622 throw new GenerationError({ reason: `Invalid endpoint path: ${operation}` })
623 }
624 const rebuilt = HttpApiEndpoint.make(endpoint.method)(endpoint.name, endpoint.path, {
625 ...(source === "params" ? { params: decoded } : undefined),
626 ...(source === "query" ? { query: decoded } : undefined),
627 ...(source === "headers" ? { headers: decoded } : undefined),
628 ...(source === "payload" ? { payload: decoded } : undefined),
629 ...(source === "success" ? { success: decoded } : { success: Schema.String }),
630 ...(source === "error" ? { error: decoded } : undefined),
631 })
632 const normalized =
633 source === "params"
634 ? rebuilt.params
635 : source === "query"
636 ? rebuilt.query
637 : source === "headers"
638 ? rebuilt.headers
639 : source === "payload"
640 ? Array.from(rebuilt.payload.values())[0]?.schemas[0]
641 : source === "success"
642 ? Array.from(rebuilt.success)[0]
643 : Array.from(rebuilt.error)[0]
644 if (normalized === undefined) throw new GenerationError({ reason: `Unportable schema: ${operation}.${source}` })
645 if (!sameEncoding(schema.ast, normalized.ast)) return { schema, effectPortable: false } as const
646 return { schema: decoded, effectPortable: true } as const
647}
648
649function isPathInput(path: string): path is HttpRouter.PathInput {
650 return path === "*" || path.startsWith("/")

Callers 1

onEndpointFunction · 0.85

Calls 7

isStreamSchemaFunction · 0.85
metadataPortableFunction · 0.85
isPathInputFunction · 0.85
sameEncodingFunction · 0.85
makeMethod · 0.45
fromMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected