MCPcopy Create free account
hub / github.com/Effect-TS/effect / compilePath

Function compilePath

packages/effect/src/unstable/httpapi/HttpApiClient.ts:709–727  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

707const paramsRegExp = /(\/?):(\w+)(\?)?/g
708
709const compilePath = (path: string) => {
710 if (!paramsRegExp.test(path)) {
711 return (_: any) => path
712 }
713 paramsRegExp.lastIndex = 0
714 return (params: Record<string, string | undefined>) => {
715 paramsRegExp.lastIndex = 0
716 return path.replace(paramsRegExp, (_, slash: string, key: string, optional: string | undefined) => {
717 const value = params[key]
718 if (value === undefined) {
719 if (optional !== undefined) {
720 return ""
721 }
722 throw new Error(`Missing path parameter: ${key}`)
723 }
724 return `${slash}${encodeURIComponent(value)}`
725 })
726 }
727}
728
729function schemasToResponse(schemas: readonly [Schema.Constraint, ...Array<Schema.Constraint>]) {
730 const hasWithHeaders = schemas.some((schema) =>

Callers 1

onEndpointFunction · 0.85

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected