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

Function onEndpoint

packages/effect/src/http-api/HttpApiClient.ts:482–640  ·  view source on GitHub ↗
(onEndpointOptions)

Source from the content-addressed store, hash-verified

480 options.onGroup?.(onGroupOptions)
481 },
482 onEndpoint(onEndpointOptions) {
483 const { group, endpoint, mergedAnnotations } = onEndpointOptions
484 const parseOptions = HttpApi.getSlotParseOptions(mergedAnnotations)
485 const makeUrl = compilePath(endpoint.path, endpoint.params)
486 const upgrade = getUpgradeSuccessSchema(endpoint)
487 const decodeEndpointResponse = makeEndpointDecoder(onEndpointOptions)
488
489 const encodeParams = UndefinedOr.map(
490 endpoint.params,
491 (schema) => Schema.encodeUnknownEffect(schema, parseOptions.params)
492 )
493
494 const payloadSchemas: Array<Schema.Top> = []
495 let streamPayload: StreamPayloadSchema | undefined
496 for (const schema of HttpApiEndpoint.getPayloadSchemas(endpoint)) {
497 if (HttpApiSchema.isStreamUint8Array(schema) || HttpApiSchema.isStreamNdjson(schema)) {
498 streamPayload = schema
499 } else {
500 payloadSchemas.push(schema)
501 }
502 }
503 const streamPayloadEncoder = UndefinedOr.map(streamPayload, (schema) => ({
504 contentType: schema.contentType,
505 encode: makeStreamPayloadEncoder(schema, parseOptions.payload)
506 }))
507 const encodePayload = Arr.isArrayNonEmpty(payloadSchemas) ?
508 Schema.encodeUnknownEffect(
509 HttpMethod.hasBody(endpoint.method)
510 ? getEncodePayloadSchema(payloadSchemas, endpoint.method)
511 : Schema.Union(payloadSchemas),
512 parseOptions.payload
513 ) :
514 undefined
515
516 const encodeHeaders = UndefinedOr.map(
517 endpoint.headers,
518 (schema) => Schema.encodeUnknownEffect(schema, parseOptions.headers)
519 )
520 const encodeQuery = UndefinedOr.map(
521 endpoint.query,
522 (schema) => Schema.encodeUnknownEffect(schema, parseOptions.query)
523 )
524
525 const middlewareKeys = Array.from(onEndpointOptions.middleware, (tag) => `${tag.key}/Client`)
526 const redactedNames = HttpApi.getEndpointRedactedNames(api, group, endpoint)
527 const redactedParams = HttpApi.getEndpointRedactedParams(api, group, endpoint)
528 // Names declared on the API or group may belong to other endpoints.
529 const redactsPath = redactedParams.all ||
530 redactedParams.names.some((name) => endpoint.path.includes(`:${name}`))
531
532 const declaredPath: ClientPath = { template: endpoint.path, path: endpoint.path }
533
534 const endpointFn = Effect.fnUntraced(function*(
535 request: {
536 readonly params: Record<string, string> | undefined
537 readonly query: unknown
538 readonly payload: unknown
539 readonly headers: Record<string, string> | undefined

Callers

nothing calls this directly

Calls 15

withoutTemplateFunction · 0.90
makeStreamPayloadEncoderFunction · 0.85
getEncodePayloadSchemaFunction · 0.85
fullPathFunction · 0.85
encodePayloadFunction · 0.85
encodeHeadersFunction · 0.85
encodeQueryFunction · 0.85
executeMiddlewareFunction · 0.85
withRedactedNamesFunction · 0.85
fromMethod · 0.80
someMethod · 0.80
contextMethod · 0.80

Tested by

no test coverage detected