MCPcopy Index your code
hub / github.com/Effect-TS/effect / make

Function make

packages/platform/src/HttpApiEndpoint.ts:860–912  ·  view source on GitHub ↗
(method: Method)

Source from the content-addressed store, hash-verified

858 * @category constructors
859 */
860export const make = <Method extends HttpMethod>(method: Method): {
861 <const Name extends string>(name: Name): HttpApiEndpoint.Constructor<Name, Method>
862 <const Name extends string>(name: Name, path: PathSegment): HttpApiEndpoint<Name, Method>
863} =>
864 ((name: string, ...args: [PathSegment]) => {
865 if (args.length === 1) {
866 return makeProto({
867 name,
868 path: args[0],
869 method,
870 pathSchema: Option.none(),
871 urlParamsSchema: Option.none(),
872 payloadSchema: Option.none(),
873 headersSchema: Option.none(),
874 successSchema: HttpApiSchema.NoContent as any,
875 errorSchema: Schema.Never as any,
876 annotations: Context.empty(),
877 middlewares: new Set()
878 })
879 }
880 return (
881 segments: TemplateStringsArray,
882 ...schemas: ReadonlyArray<Schema.Schema.Any | Schema.PropertySignature.Any>
883 ) => {
884 let path = segments[0].replace(":", "::") as PathSegment
885 let pathSchema = Option.none<Schema.Schema.Any>()
886 if (schemas.length > 0) {
887 const obj: Record<string, Schema.Schema.Any | Schema.PropertySignature.Any> = {}
888 for (let i = 0; i < schemas.length; i++) {
889 const schema = schemas[i]
890 const key = HttpApiSchema.getParam(schema.ast) ?? String(i)
891 const optional = schema.ast._tag === "PropertySignatureTransformation" && schema.ast.from.isOptional ||
892 schema.ast._tag === "PropertySignatureDeclaration" && schema.ast.isOptional
893 obj[key] = schema
894 path += `:${key}${optional ? "?" : ""}${segments[i + 1].replace(":", "::")}`
895 }
896 pathSchema = Option.some(Schema.Struct(obj))
897 }
898 return makeProto({
899 name,
900 path,
901 method,
902 pathSchema,
903 urlParamsSchema: Option.none(),
904 payloadSchema: Option.none(),
905 headersSchema: Option.none(),
906 successSchema: HttpApiSchema.NoContent as any,
907 errorSchema: Schema.Never as any,
908 annotations: Context.empty(),
909 middlewares: new Set()
910 })
911 }
912 }) as any
913
914/**
915 * @since 1.0.0

Callers 1

HttpApiEndpoint.tsFile · 0.70

Calls 2

StringInterface · 0.85
makeProtoFunction · 0.70

Tested by

no test coverage detected