fix(codegen): stabilize generated contract names (#44000)
This commit is contained in:
@@ -120,8 +120,8 @@ describe("HttpApiCodegen.generate", () => {
|
||||
const source = output.files[0]?.content
|
||||
|
||||
expect(source).toContain('import type { Session } from "@example/schema/session"')
|
||||
expect(source).toContain('export type Endpoint0_0Input = { readonly "id": string }')
|
||||
expect(source).toContain("export type Endpoint0_0Output = Session.Info")
|
||||
expect(source).toContain('export type SessionGetInput = { readonly "id": string }')
|
||||
expect(source).toContain("export type SessionGetOutput = Session.Info")
|
||||
expect(source).not.toContain("HttpApiClient")
|
||||
expect(source).not.toContain("@example/api")
|
||||
})
|
||||
@@ -141,7 +141,53 @@ describe("HttpApiCodegen.generate", () => {
|
||||
const source = output.files[0]?.content
|
||||
|
||||
expect(source).toContain('import type { OpenCodeEvent } from "@example/protocol/event"')
|
||||
expect(source).toContain("export type Endpoint0_0Output = OpenCodeEvent")
|
||||
expect(source).toContain("export type SessionEventsOutput = OpenCodeEvent")
|
||||
})
|
||||
|
||||
test("rejects authoritative Effect types colliding with generated aliases", () => {
|
||||
expect(() =>
|
||||
emitEffectShape(compileContract(api(HttpApiEndpoint.get("get", "/session", { success: Schema.String }))), {
|
||||
outputTypes: {
|
||||
"session.get": {
|
||||
name: "SessionGetOutput",
|
||||
import: 'import type { SessionGetOutput } from "@example/schema/session"',
|
||||
},
|
||||
},
|
||||
}),
|
||||
).toThrow("Generated Effect type collides with imported type: SessionGetOutput")
|
||||
})
|
||||
|
||||
test("rejects qualified Effect imports colliding with generated interfaces", () => {
|
||||
const Info = Schema.Struct({ id: Schema.String }).annotate({ identifier: "Session.Info" })
|
||||
|
||||
expect(() =>
|
||||
emitEffectShape(compileContract(api(HttpApiEndpoint.get("get", "/session", { success: Info }))), {
|
||||
typeReferences: [
|
||||
{
|
||||
schema: Info,
|
||||
name: "SessionApi.Info",
|
||||
import: 'import type { SessionApi } from "@example/schema/session"',
|
||||
},
|
||||
],
|
||||
}),
|
||||
).toThrow("Generated Effect type collides with imported type: SessionApi")
|
||||
})
|
||||
|
||||
test("rejects imported endpoints colliding with generated adapter values", () => {
|
||||
const contract = compileContract(api(HttpApiEndpoint.get("session.get", "/session", { success: Schema.String })))
|
||||
|
||||
expect(() =>
|
||||
emitEffectImported(contract, {
|
||||
module: "@example/api",
|
||||
endpoints: { "session.session.get": "EndpointSessionGet" },
|
||||
}),
|
||||
).toThrow("Generated Effect adapter collides with imported endpoint: EndpointSessionGet")
|
||||
expect(() =>
|
||||
emitEffectImported(contract, {
|
||||
module: "@example/api",
|
||||
api: "EndpointSessionGet",
|
||||
}),
|
||||
).toThrow("Generated Effect adapter collides with imported endpoint: EndpointSessionGet")
|
||||
})
|
||||
|
||||
test("exposes an imported Effect client through its generated shape", () => {
|
||||
@@ -151,8 +197,8 @@ describe("HttpApiCodegen.generate", () => {
|
||||
)
|
||||
const source = output.files.find((file) => file.path === "client.ts")?.content
|
||||
|
||||
expect(source).toContain('import type { Endpoint0_0Output } from "../api"')
|
||||
expect(source).toContain("preserveEffect<Endpoint0_0Output>()")
|
||||
expect(source).toContain('import type { SessionGetOutput } from "../api"')
|
||||
expect(source).toContain("preserveEffect<SessionGetOutput>()")
|
||||
})
|
||||
|
||||
test("projects imported endpoint constants into a generated API", () => {
|
||||
@@ -271,12 +317,12 @@ describe("HttpApiCodegen.generate", () => {
|
||||
|
||||
const effect = emitEffect(contract)
|
||||
expect(effect.files.find((file) => file.path === "session.ts")?.content).toContain(
|
||||
'"instructions": { "list": Endpoint0(raw), "put": Endpoint1(raw), "remove": Endpoint2(raw) }',
|
||||
'"instructions": { "list": EndpointInstructionsList(raw), "put": EndpointInstructionsPut(raw), "remove": EndpointInstructionsRemove(raw) }',
|
||||
)
|
||||
|
||||
const imported = emitEffectImported(contract, { module: "@example/api", api: "Api" })
|
||||
expect(imported.files.find((file) => file.path === "client.ts")?.content).toContain(
|
||||
'"instructions": { "list": Endpoint0_0(raw), "put": Endpoint0_1(raw), "remove": Endpoint0_2(raw) }',
|
||||
'"instructions": { "list": EndpointSessionInstructionsList(raw), "put": EndpointSessionInstructionsPut(raw), "remove": EndpointSessionInstructionsRemove(raw) }',
|
||||
)
|
||||
|
||||
const shape = emitEffectShape(contract)
|
||||
@@ -396,9 +442,14 @@ describe("HttpApiCodegen.generate", () => {
|
||||
})
|
||||
|
||||
test("rejects normalized group, operation-key, and group prototype collisions", () => {
|
||||
const normalized = HttpApi.make("test")
|
||||
const sanitized = HttpApi.make("test")
|
||||
.add(HttpApiGroup.make("foo-bar").add(HttpApiEndpoint.get("get", "/first", { success: Schema.String })))
|
||||
.add(HttpApiGroup.make("foo.bar").add(HttpApiEndpoint.get("get", "/second", { success: Schema.String })))
|
||||
expect(() => compileContract(sanitized)).toThrow("Client module name collision: foo-bar")
|
||||
|
||||
const normalized = HttpApi.make("test")
|
||||
.add(HttpApiGroup.make("foo_bar").add(HttpApiEndpoint.get("get", "/first", { success: Schema.String })))
|
||||
.add(HttpApiGroup.make("foo.bar").add(HttpApiEndpoint.get("get", "/second", { success: Schema.String })))
|
||||
expect(() => compileContract(normalized)).toThrow("Client group type collision: FooBar")
|
||||
|
||||
const endpointType = HttpApi.make("test")
|
||||
@@ -499,7 +550,9 @@ describe("HttpApiCodegen.generate", () => {
|
||||
|
||||
expect(contract.groups[0]?.endpoints[0]?.operation.name).toBe("get")
|
||||
expect(promise).toContain('"get": (input: SessionGetInput, requestOptions?: RequestOptions)')
|
||||
expect(effect).toContain('const adaptGroup0 = (raw: RawClient["session"]) => ({ "get": Endpoint0_0(raw) })')
|
||||
expect(effect).toContain(
|
||||
'const adaptGroupSession = (raw: RawClient["session"]) => ({ "get": EndpointSessionGet(raw) })',
|
||||
)
|
||||
expect(effect).toContain('raw["session.get"]')
|
||||
})
|
||||
|
||||
@@ -1478,7 +1531,7 @@ describe("HttpApiCodegen.generate", () => {
|
||||
|
||||
expect(output.operations[0]).toBeDefined()
|
||||
expect(output.files.find((file) => file.path === "session.ts")?.content).toContain(
|
||||
'extends Schema.TaggedError<Endpoint0Error0Class>("Unauthorized")',
|
||||
'extends Schema.TaggedError<EndpointGetError0Class>("Unauthorized")',
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1494,7 +1547,7 @@ describe("HttpApiCodegen.generate", () => {
|
||||
)
|
||||
|
||||
expect(output.files.find((file) => file.path === "session.ts")?.content).toContain(
|
||||
'Endpoint0Error0Class.annotate({ "httpApiStatus": 404 })',
|
||||
'EndpointGetError0Class.annotate({ "httpApiStatus": 404 })',
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1504,35 +1557,35 @@ describe("HttpApiCodegen.generate", () => {
|
||||
expect(output.files.find((file) => file.path === "session.ts")?.content).toContain('HttpApiEndpoint.make("TRACE")')
|
||||
})
|
||||
|
||||
test("uses safe unique module paths without changing public group identifiers", () => {
|
||||
test("uses safe identity-derived module paths without changing public group identifiers", () => {
|
||||
const output = compile(
|
||||
HttpApi.make("test")
|
||||
.add(HttpApiGroup.make("../session").add(HttpApiEndpoint.get("get", "/session", { success: Schema.String })))
|
||||
.add(HttpApiGroup.make("GROUP-0").add(HttpApiEndpoint.get("list", "/session", { success: Schema.String }))),
|
||||
)
|
||||
|
||||
expect(output.files.slice(0, 2).map((file) => file.path)).toEqual(["group-0.ts", "GROUP-0-1.ts"])
|
||||
expect(output.files.slice(0, 2).map((file) => file.path)).toEqual(["session.ts", "GROUP-0.ts"])
|
||||
expect(output.files[0]?.content).toContain('HttpApiGroup.make("../session"')
|
||||
})
|
||||
|
||||
test("reserves support module names case-insensitively", () => {
|
||||
test("prefixes group modules that collide with support or Windows-reserved names", () => {
|
||||
const output = compile(
|
||||
HttpApi.make("test")
|
||||
.add(HttpApiGroup.make("client").add(HttpApiEndpoint.get("get", "/client", { success: Schema.String })))
|
||||
.add(HttpApiGroup.make("INDEX").add(HttpApiEndpoint.get("get", "/index", { success: Schema.String }))),
|
||||
.add(HttpApiGroup.make("INDEX").add(HttpApiEndpoint.get("get", "/index", { success: Schema.String })))
|
||||
.add(HttpApiGroup.make("CON").add(HttpApiEndpoint.get("get", "/con", { success: Schema.String }))),
|
||||
)
|
||||
|
||||
expect(output.files.slice(0, 2).map((file) => file.path)).toEqual(["client-0.ts", "INDEX-1.ts"])
|
||||
expect(output.files.slice(0, 2).map((file) => file.path)).toEqual(["group-INDEX.ts", "group-CON.ts"])
|
||||
})
|
||||
|
||||
test("keeps searching when a reserved-name fallback is also occupied", () => {
|
||||
const output = compile(
|
||||
HttpApi.make("test")
|
||||
.add(HttpApiGroup.make("client-1").add(HttpApiEndpoint.get("first", "/first", { success: Schema.String })))
|
||||
.add(HttpApiGroup.make("client").add(HttpApiEndpoint.get("second", "/second", { success: Schema.String }))),
|
||||
)
|
||||
|
||||
expect(output.files.slice(0, 2).map((file) => file.path)).toEqual(["client-1.ts", "client-1-1.ts"])
|
||||
test("rejects module names colliding after normalization", () => {
|
||||
expect(() =>
|
||||
compile(
|
||||
HttpApi.make("test")
|
||||
.add(HttpApiGroup.make("my.group").add(HttpApiEndpoint.get("first", "/first", { success: Schema.String })))
|
||||
.add(HttpApiGroup.make("my/group").add(HttpApiEndpoint.get("second", "/second", { success: Schema.String }))),
|
||||
),
|
||||
).toThrow("Client module name collision: my-group")
|
||||
})
|
||||
|
||||
test("rejects collisions in the flattened client namespace", () => {
|
||||
@@ -1558,7 +1611,7 @@ describe("HttpApiCodegen.generate", () => {
|
||||
),
|
||||
)
|
||||
|
||||
expect(output.files[0]?.content).toContain("type RawGroup = HttpApiClient.Client<typeof Group0")
|
||||
expect(output.files[0]?.content).toContain("type RawGroup = HttpApiClient.Client<typeof GroupHealth")
|
||||
})
|
||||
|
||||
it.effect("reports compiler failures in the generate Effect", () =>
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
// Generated by @opencode-ai/httpapi-codegen. Do not edit.
|
||||
import { Effect } from "effect"
|
||||
import { HttpApi, HttpApiClient } from "effect/unstable/httpapi"
|
||||
import { adaptGroup0, Group0 } from "./session"
|
||||
import { adaptGroup1, Group1 } from "./event"
|
||||
import { adaptGroup2, Group2 } from "./system"
|
||||
import { adaptGroupSession, GroupSession } from "./session"
|
||||
import { adaptGroupEvent, GroupEvent } from "./event"
|
||||
import { adaptGroupSystem, GroupSystem } from "./system"
|
||||
|
||||
const Api = HttpApi.make("generated").add(Group0).add(Group1).add(Group2)
|
||||
const Api = HttpApi.make("generated").add(GroupSession).add(GroupEvent).add(GroupSystem)
|
||||
const adaptClient = (raw: HttpApiClient.ForApi<typeof Api>) => ({
|
||||
session: adaptGroup0(raw["session"]),
|
||||
event: adaptGroup1(raw["event"]),
|
||||
...adaptGroup2({ status: raw["status"] }),
|
||||
session: adaptGroupSession(raw["session"]),
|
||||
event: adaptGroupEvent(raw["event"]),
|
||||
...adaptGroupSystem({ status: raw["status"] }),
|
||||
})
|
||||
|
||||
export const make = (options?: { readonly baseUrl?: URL | string }) =>
|
||||
|
||||
@@ -5,35 +5,35 @@ import { HttpClientError } from "effect/unstable/http"
|
||||
import { HttpApiClient, HttpApiEndpoint, HttpApiGroup, HttpApiSchema } from "effect/unstable/httpapi"
|
||||
import { ClientError } from "./client-error.js"
|
||||
|
||||
const Endpoint0SuccessData = Schema.Struct({ type: Schema.String })
|
||||
const EndpointSubscribeSuccessData = Schema.Struct({ type: Schema.String })
|
||||
|
||||
const Endpoint0SuccessError = Schema.Never
|
||||
const EndpointSubscribeSuccessError = Schema.Never
|
||||
|
||||
export const Group1 = HttpApiGroup.make("event", { topLevel: false }).add(
|
||||
export const GroupEvent = HttpApiGroup.make("event", { topLevel: false }).add(
|
||||
HttpApiEndpoint.make("GET")("subscribe", "/event", {
|
||||
success: HttpApiSchema.StreamSse({
|
||||
data: Endpoint0SuccessData,
|
||||
error: Endpoint0SuccessError,
|
||||
data: EndpointSubscribeSuccessData,
|
||||
error: EndpointSubscribeSuccessError,
|
||||
contentType: "text/event-stream",
|
||||
}).pipe(HttpApiSchema.status(202)),
|
||||
}),
|
||||
)
|
||||
|
||||
type RawGroup = HttpApiClient.Client.Group<typeof Group1, never, never>
|
||||
type RawGroup = HttpApiClient.Client.Group<typeof GroupEvent, never, never>
|
||||
|
||||
const Endpoint0DeclaredError = Schema.Union([Endpoint0SuccessError])
|
||||
const mapEndpoint0Error = (error: unknown) =>
|
||||
const EndpointSubscribeDeclaredError = Schema.Union([EndpointSubscribeSuccessError])
|
||||
const mapEndpointSubscribeError = (error: unknown) =>
|
||||
HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error)
|
||||
? new ClientError({ cause: error })
|
||||
: Schema.is(Endpoint0DeclaredError)(error)
|
||||
: Schema.is(EndpointSubscribeDeclaredError)(error)
|
||||
? error
|
||||
: new ClientError({ cause: error })
|
||||
const Endpoint0 = (raw: RawGroup) => () =>
|
||||
const EndpointSubscribe = (raw: RawGroup) => () =>
|
||||
Stream.unwrap(
|
||||
raw["subscribe"]({}).pipe(
|
||||
Effect.mapError(mapEndpoint0Error),
|
||||
Effect.map((stream) => stream.pipe(Stream.mapError(mapEndpoint0Error))),
|
||||
Effect.mapError(mapEndpointSubscribeError),
|
||||
Effect.map((stream) => stream.pipe(Stream.mapError(mapEndpointSubscribeError))),
|
||||
),
|
||||
)
|
||||
|
||||
export const adaptGroup1 = (raw: RawGroup) => ({ subscribe: Endpoint0(raw) })
|
||||
export const adaptGroupEvent = (raw: RawGroup) => ({ subscribe: EndpointSubscribe(raw) })
|
||||
|
||||
@@ -5,137 +5,141 @@ import { HttpClientError } from "effect/unstable/http"
|
||||
import { HttpApiClient, HttpApiEndpoint, HttpApiGroup } from "effect/unstable/httpapi"
|
||||
import { ClientError } from "./client-error.js"
|
||||
|
||||
const Endpoint0Success = Schema.String
|
||||
const EndpointHealthSuccess = Schema.String
|
||||
|
||||
const Endpoint1Query = Schema.Struct({ archived: Schema.optionalKey(Schema.Union([Schema.Boolean, Schema.Undefined])) })
|
||||
const EndpointListQuery = Schema.Struct({
|
||||
archived: Schema.optionalKey(Schema.Union([Schema.Boolean, Schema.Undefined])),
|
||||
})
|
||||
|
||||
const Endpoint1Success = Schema.Array(Schema.String)
|
||||
const EndpointListSuccess = Schema.Array(Schema.String)
|
||||
|
||||
const Endpoint2Params = Schema.Struct({ sessionID: Schema.String })
|
||||
const EndpointGetParams = Schema.Struct({ sessionID: Schema.String })
|
||||
|
||||
const Endpoint2Success = Schema.Struct({ data: Schema.String })
|
||||
const EndpointGetSuccess = Schema.Struct({ data: Schema.String })
|
||||
|
||||
class Endpoint2Error0Class extends Schema.TaggedError<Endpoint2Error0Class>("Missing")("Missing", {
|
||||
class EndpointGetError0Class extends Schema.TaggedError<EndpointGetError0Class>("Missing")("Missing", {
|
||||
message: Schema.String,
|
||||
}) {}
|
||||
const Endpoint2Error0 = Endpoint2Error0Class.annotate({ httpApiStatus: 404 })
|
||||
const EndpointGetError0 = EndpointGetError0Class.annotate({ httpApiStatus: 404 })
|
||||
|
||||
const Endpoint3Params = Schema.Struct({ sessionID: Schema.String })
|
||||
const EndpointInterruptParams = Schema.Struct({ sessionID: Schema.String })
|
||||
|
||||
const Endpoint3Success = Schema.Void.annotate({ httpApiStatus: 204 })
|
||||
const EndpointInterruptSuccess = Schema.Void.annotate({ httpApiStatus: 204 })
|
||||
|
||||
const Endpoint4Params = Schema.Struct({ sessionID: Schema.String })
|
||||
const EndpointConfigureParams = Schema.Struct({ sessionID: Schema.String })
|
||||
|
||||
const Endpoint4Query = Schema.Struct({ dryRun: Schema.optionalKey(Schema.Union([Schema.Boolean, Schema.Undefined])) })
|
||||
const EndpointConfigureQuery = Schema.Struct({
|
||||
dryRun: Schema.optionalKey(Schema.Union([Schema.Boolean, Schema.Undefined])),
|
||||
})
|
||||
|
||||
const Endpoint4Headers = Schema.Struct({ traceID: Schema.String })
|
||||
const EndpointConfigureHeaders = Schema.Struct({ traceID: Schema.String })
|
||||
|
||||
const Endpoint4Payload0 = Schema.Union([
|
||||
const EndpointConfigurePayload0 = Schema.Union([
|
||||
Schema.Struct({ type: Schema.Literal("local"), command: Schema.Array(Schema.String) }),
|
||||
Schema.Struct({ type: Schema.Literal("remote"), url: Schema.String }),
|
||||
])
|
||||
|
||||
const Endpoint4Success = Schema.String
|
||||
const EndpointConfigureSuccess = Schema.String
|
||||
|
||||
export const Group0 = HttpApiGroup.make("session", { topLevel: false })
|
||||
.add(HttpApiEndpoint.make("GET")("health", "/session/health", { success: Endpoint0Success }))
|
||||
.add(HttpApiEndpoint.make("GET")("list", "/session", { query: Endpoint1Query, success: Endpoint1Success }))
|
||||
export const GroupSession = HttpApiGroup.make("session", { topLevel: false })
|
||||
.add(HttpApiEndpoint.make("GET")("health", "/session/health", { success: EndpointHealthSuccess }))
|
||||
.add(HttpApiEndpoint.make("GET")("list", "/session", { query: EndpointListQuery, success: EndpointListSuccess }))
|
||||
.add(
|
||||
HttpApiEndpoint.make("GET")("get", "/session/:sessionID", {
|
||||
params: Endpoint2Params,
|
||||
success: Endpoint2Success,
|
||||
error: Endpoint2Error0,
|
||||
params: EndpointGetParams,
|
||||
success: EndpointGetSuccess,
|
||||
error: EndpointGetError0,
|
||||
}),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.make("POST")("interrupt", "/session/:sessionID/interrupt", {
|
||||
params: Endpoint3Params,
|
||||
success: Endpoint3Success,
|
||||
params: EndpointInterruptParams,
|
||||
success: EndpointInterruptSuccess,
|
||||
}),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.make("POST")("configure", "/session/:sessionID/configure", {
|
||||
params: Endpoint4Params,
|
||||
query: Endpoint4Query,
|
||||
headers: Endpoint4Headers,
|
||||
payload: Endpoint4Payload0,
|
||||
success: Endpoint4Success,
|
||||
params: EndpointConfigureParams,
|
||||
query: EndpointConfigureQuery,
|
||||
headers: EndpointConfigureHeaders,
|
||||
payload: EndpointConfigurePayload0,
|
||||
success: EndpointConfigureSuccess,
|
||||
}),
|
||||
)
|
||||
|
||||
type RawGroup = HttpApiClient.Client.Group<typeof Group0, never, never>
|
||||
type RawGroup = HttpApiClient.Client.Group<typeof GroupSession, never, never>
|
||||
|
||||
const Endpoint0DeclaredError = Schema.Never
|
||||
const mapEndpoint0Error = (error: unknown) =>
|
||||
const EndpointHealthDeclaredError = Schema.Never
|
||||
const mapEndpointHealthError = (error: unknown) =>
|
||||
HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error)
|
||||
? new ClientError({ cause: error })
|
||||
: Schema.is(Endpoint0DeclaredError)(error)
|
||||
: Schema.is(EndpointHealthDeclaredError)(error)
|
||||
? error
|
||||
: new ClientError({ cause: error })
|
||||
const Endpoint0 = (raw: RawGroup) => () => raw["health"]({}).pipe(Effect.mapError(mapEndpoint0Error))
|
||||
const EndpointHealth = (raw: RawGroup) => () => raw["health"]({}).pipe(Effect.mapError(mapEndpointHealthError))
|
||||
|
||||
type Endpoint1Input = { readonly archived?: (typeof Endpoint1Query.Type)["archived"] }
|
||||
const Endpoint1DeclaredError = Schema.Never
|
||||
const mapEndpoint1Error = (error: unknown) =>
|
||||
type EndpointListInput = { readonly archived?: (typeof EndpointListQuery.Type)["archived"] }
|
||||
const EndpointListDeclaredError = Schema.Never
|
||||
const mapEndpointListError = (error: unknown) =>
|
||||
HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error)
|
||||
? new ClientError({ cause: error })
|
||||
: Schema.is(Endpoint1DeclaredError)(error)
|
||||
: Schema.is(EndpointListDeclaredError)(error)
|
||||
? error
|
||||
: new ClientError({ cause: error })
|
||||
const Endpoint1 = (raw: RawGroup) => (input?: Endpoint1Input) =>
|
||||
raw["list"]({ query: { archived: input?.["archived"] } }).pipe(Effect.mapError(mapEndpoint1Error))
|
||||
const EndpointList = (raw: RawGroup) => (input?: EndpointListInput) =>
|
||||
raw["list"]({ query: { archived: input?.["archived"] } }).pipe(Effect.mapError(mapEndpointListError))
|
||||
|
||||
type Endpoint2Input = { readonly sessionID: (typeof Endpoint2Params.Type)["sessionID"] }
|
||||
const Endpoint2DeclaredError = Schema.Union([Endpoint2Error0])
|
||||
const mapEndpoint2Error = (error: unknown) =>
|
||||
type EndpointGetInput = { readonly sessionID: (typeof EndpointGetParams.Type)["sessionID"] }
|
||||
const EndpointGetDeclaredError = Schema.Union([EndpointGetError0])
|
||||
const mapEndpointGetError = (error: unknown) =>
|
||||
HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error)
|
||||
? new ClientError({ cause: error })
|
||||
: Schema.is(Endpoint2DeclaredError)(error)
|
||||
: Schema.is(EndpointGetDeclaredError)(error)
|
||||
? error
|
||||
: new ClientError({ cause: error })
|
||||
const Endpoint2 = (raw: RawGroup) => (input: Endpoint2Input) =>
|
||||
const EndpointGet = (raw: RawGroup) => (input: EndpointGetInput) =>
|
||||
raw["get"]({ params: { sessionID: input["sessionID"] } }).pipe(
|
||||
Effect.mapError(mapEndpoint2Error),
|
||||
Effect.mapError(mapEndpointGetError),
|
||||
Effect.map((value) => value.data),
|
||||
)
|
||||
|
||||
type Endpoint3Input = { readonly sessionID: (typeof Endpoint3Params.Type)["sessionID"] }
|
||||
const Endpoint3DeclaredError = Schema.Never
|
||||
const mapEndpoint3Error = (error: unknown) =>
|
||||
type EndpointInterruptInput = { readonly sessionID: (typeof EndpointInterruptParams.Type)["sessionID"] }
|
||||
const EndpointInterruptDeclaredError = Schema.Never
|
||||
const mapEndpointInterruptError = (error: unknown) =>
|
||||
HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error)
|
||||
? new ClientError({ cause: error })
|
||||
: Schema.is(Endpoint3DeclaredError)(error)
|
||||
: Schema.is(EndpointInterruptDeclaredError)(error)
|
||||
? error
|
||||
: new ClientError({ cause: error })
|
||||
const Endpoint3 = (raw: RawGroup) => (input: Endpoint3Input) =>
|
||||
raw["interrupt"]({ params: { sessionID: input["sessionID"] } }).pipe(Effect.mapError(mapEndpoint3Error))
|
||||
const EndpointInterrupt = (raw: RawGroup) => (input: EndpointInterruptInput) =>
|
||||
raw["interrupt"]({ params: { sessionID: input["sessionID"] } }).pipe(Effect.mapError(mapEndpointInterruptError))
|
||||
|
||||
type Endpoint4Request = Parameters<RawGroup["configure"]>[0]
|
||||
type Endpoint4Input = {
|
||||
readonly sessionID: (typeof Endpoint4Params.Type)["sessionID"]
|
||||
readonly dryRun?: (typeof Endpoint4Query.Type)["dryRun"]
|
||||
readonly traceID: (typeof Endpoint4Headers.Type)["traceID"]
|
||||
readonly payload: typeof Endpoint4Payload0.Type
|
||||
type EndpointConfigureRequest = Parameters<RawGroup["configure"]>[0]
|
||||
type EndpointConfigureInput = {
|
||||
readonly sessionID: (typeof EndpointConfigureParams.Type)["sessionID"]
|
||||
readonly dryRun?: (typeof EndpointConfigureQuery.Type)["dryRun"]
|
||||
readonly traceID: (typeof EndpointConfigureHeaders.Type)["traceID"]
|
||||
readonly payload: typeof EndpointConfigurePayload0.Type
|
||||
}
|
||||
const Endpoint4DeclaredError = Schema.Never
|
||||
const mapEndpoint4Error = (error: unknown) =>
|
||||
const EndpointConfigureDeclaredError = Schema.Never
|
||||
const mapEndpointConfigureError = (error: unknown) =>
|
||||
HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error)
|
||||
? new ClientError({ cause: error })
|
||||
: Schema.is(Endpoint4DeclaredError)(error)
|
||||
: Schema.is(EndpointConfigureDeclaredError)(error)
|
||||
? error
|
||||
: new ClientError({ cause: error })
|
||||
const Endpoint4 = (raw: RawGroup) => (input: Endpoint4Input) =>
|
||||
const EndpointConfigure = (raw: RawGroup) => (input: EndpointConfigureInput) =>
|
||||
raw["configure"]({
|
||||
params: { sessionID: input["sessionID"] },
|
||||
query: { dryRun: input["dryRun"] },
|
||||
headers: { traceID: input["traceID"] },
|
||||
payload: input["payload"],
|
||||
} as Endpoint4Request).pipe(Effect.mapError(mapEndpoint4Error))
|
||||
} as EndpointConfigureRequest).pipe(Effect.mapError(mapEndpointConfigureError))
|
||||
|
||||
export const adaptGroup0 = (raw: RawGroup) => ({
|
||||
health: Endpoint0(raw),
|
||||
list: Endpoint1(raw),
|
||||
get: Endpoint2(raw),
|
||||
interrupt: Endpoint3(raw),
|
||||
configure: Endpoint4(raw),
|
||||
export const adaptGroupSession = (raw: RawGroup) => ({
|
||||
health: EndpointHealth(raw),
|
||||
list: EndpointList(raw),
|
||||
get: EndpointGet(raw),
|
||||
interrupt: EndpointInterrupt(raw),
|
||||
configure: EndpointConfigure(raw),
|
||||
})
|
||||
|
||||
@@ -5,21 +5,21 @@ import { HttpClientError } from "effect/unstable/http"
|
||||
import { HttpApiClient, HttpApiEndpoint, HttpApiGroup } from "effect/unstable/httpapi"
|
||||
import { ClientError } from "./client-error.js"
|
||||
|
||||
const Endpoint0Success = Schema.String
|
||||
const EndpointStatusSuccess = Schema.String
|
||||
|
||||
export const Group2 = HttpApiGroup.make("system", { topLevel: true }).add(
|
||||
HttpApiEndpoint.make("GET")("status", "/status", { success: Endpoint0Success }),
|
||||
export const GroupSystem = HttpApiGroup.make("system", { topLevel: true }).add(
|
||||
HttpApiEndpoint.make("GET")("status", "/status", { success: EndpointStatusSuccess }),
|
||||
)
|
||||
|
||||
type RawGroup = HttpApiClient.Client<typeof Group2>
|
||||
type RawGroup = HttpApiClient.Client<typeof GroupSystem>
|
||||
|
||||
const Endpoint0DeclaredError = Schema.Never
|
||||
const mapEndpoint0Error = (error: unknown) =>
|
||||
const EndpointStatusDeclaredError = Schema.Never
|
||||
const mapEndpointStatusError = (error: unknown) =>
|
||||
HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error)
|
||||
? new ClientError({ cause: error })
|
||||
: Schema.is(Endpoint0DeclaredError)(error)
|
||||
: Schema.is(EndpointStatusDeclaredError)(error)
|
||||
? error
|
||||
: new ClientError({ cause: error })
|
||||
const Endpoint0 = (raw: RawGroup) => () => raw["status"]({}).pipe(Effect.mapError(mapEndpoint0Error))
|
||||
const EndpointStatus = (raw: RawGroup) => () => raw["status"]({}).pipe(Effect.mapError(mapEndpointStatusError))
|
||||
|
||||
export const adaptGroup2 = (raw: RawGroup) => ({ status: Endpoint0(raw) })
|
||||
export const adaptGroupSystem = (raw: RawGroup) => ({ status: EndpointStatus(raw) })
|
||||
|
||||
Reference in New Issue
Block a user