@tim-smart/openapi-gen 0.3.19 → 0.3.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/main.js +81 -59
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -35510,20 +35510,49 @@ var layerTransformerSchema2 = sync6(OpenApiTransformer, () => {
|
|
|
35510
35510
|
readonly transformClient?: ((client: HttpClient.HttpClient) => Effect.Effect<HttpClient.HttpClient>) | undefined
|
|
35511
35511
|
} = {}
|
|
35512
35512
|
): ${name2} => {
|
|
35513
|
-
const unexpectedStatus = (
|
|
35513
|
+
const unexpectedStatus = (response: HttpClientResponse.HttpClientResponse) =>
|
|
35514
35514
|
Effect.flatMap(
|
|
35515
35515
|
Effect.orElseSucceed(response.text, () => "Unexpected status code"),
|
|
35516
35516
|
(description) =>
|
|
35517
|
-
Effect.fail(
|
|
35518
|
-
|
|
35519
|
-
|
|
35520
|
-
|
|
35521
|
-
|
|
35522
|
-
|
|
35517
|
+
Effect.fail(
|
|
35518
|
+
new HttpClientError.ResponseError({
|
|
35519
|
+
request: response.request,
|
|
35520
|
+
response,
|
|
35521
|
+
reason: "StatusCode",
|
|
35522
|
+
description,
|
|
35523
|
+
}),
|
|
35524
|
+
),
|
|
35523
35525
|
)
|
|
35524
|
-
const
|
|
35525
|
-
|
|
35526
|
-
|
|
35526
|
+
const withResponse: <A, E, R>(
|
|
35527
|
+
f: (
|
|
35528
|
+
response: HttpClientResponse.HttpClientResponse,
|
|
35529
|
+
) => Effect.Effect<A, E, R>,
|
|
35530
|
+
) => (
|
|
35531
|
+
request: HttpClientRequest.HttpClientRequest,
|
|
35532
|
+
) => Effect.Effect<A, E | HttpClientError.HttpClientError, R> =
|
|
35533
|
+
options.transformClient
|
|
35534
|
+
? (f) => (request) =>
|
|
35535
|
+
Effect.flatMap(
|
|
35536
|
+
Effect.flatMap(options.transformClient!(httpClient), (client) =>
|
|
35537
|
+
client.execute(request),
|
|
35538
|
+
),
|
|
35539
|
+
f,
|
|
35540
|
+
)
|
|
35541
|
+
: (f) => (request) => Effect.flatMap(httpClient.execute(request), f)
|
|
35542
|
+
const jsonBody =
|
|
35543
|
+
(body: unknown) => (request: HttpClientRequest.HttpClientRequest) =>
|
|
35544
|
+
Effect.orDie(HttpClientRequest.bodyJson(request, body))
|
|
35545
|
+
const decodeSuccess =
|
|
35546
|
+
<A, I, R>(schema: S.Schema<A, I, R>) =>
|
|
35547
|
+
(response: HttpClientResponse.HttpClientResponse) =>
|
|
35548
|
+
HttpClientResponse.schemaBodyJson(schema)(response)
|
|
35549
|
+
const decodeError =
|
|
35550
|
+
<A, I, R>(schema: S.Schema<A, I, R>) =>
|
|
35551
|
+
(response: HttpClientResponse.HttpClientResponse) =>
|
|
35552
|
+
Effect.flatMap(
|
|
35553
|
+
HttpClientResponse.schemaBodyJson(schema)(response),
|
|
35554
|
+
Effect.fail,
|
|
35555
|
+
)
|
|
35527
35556
|
return {
|
|
35528
35557
|
httpClient,
|
|
35529
35558
|
${operations.map(operationToImpl).join(",\n ")}
|
|
@@ -35537,6 +35566,7 @@ var layerTransformerSchema2 = sync6(OpenApiTransformer, () => {
|
|
|
35537
35566
|
}
|
|
35538
35567
|
const params = `${args2.join(", ")}`;
|
|
35539
35568
|
const pipeline = [];
|
|
35569
|
+
let effectfulRequest = false;
|
|
35540
35570
|
if (operation.params) {
|
|
35541
35571
|
const varName = operation.payload ? "options.params?." : "options?.";
|
|
35542
35572
|
if (operation.urlParams.length > 0) {
|
|
@@ -35554,30 +35584,25 @@ var layerTransformerSchema2 = sync6(OpenApiTransformer, () => {
|
|
|
35554
35584
|
}
|
|
35555
35585
|
const payloadVarName = operation.params ? "options.payload" : "options";
|
|
35556
35586
|
if (operation.payload === "FormData") {
|
|
35557
|
-
pipeline.push(
|
|
35558
|
-
`HttpClientRequest.bodyFormData(${payloadVarName})`,
|
|
35559
|
-
"Effect.succeed"
|
|
35560
|
-
);
|
|
35587
|
+
pipeline.push(`HttpClientRequest.bodyFormData(${payloadVarName})`);
|
|
35561
35588
|
} else if (operation.payload) {
|
|
35562
|
-
|
|
35563
|
-
|
|
35564
|
-
);
|
|
35565
|
-
} else {
|
|
35566
|
-
pipeline.push("Effect.succeed");
|
|
35589
|
+
effectfulRequest = true;
|
|
35590
|
+
pipeline.push(`jsonBody(${payloadVarName})`);
|
|
35567
35591
|
}
|
|
35568
35592
|
const decodes = [];
|
|
35593
|
+
const singleSuccessCode = operation.successSchemas.size === 1;
|
|
35569
35594
|
operation.successSchemas.forEach((schema, status2) => {
|
|
35570
|
-
|
|
35571
|
-
|
|
35572
|
-
);
|
|
35595
|
+
const statusCode = singleSuccessCode && status2.startsWith("2") ? "2xx" : status2;
|
|
35596
|
+
decodes.push(`"${statusCode}": decodeSuccess(${schema})`);
|
|
35573
35597
|
});
|
|
35574
35598
|
operation.errorSchemas.forEach((schema, status2) => {
|
|
35575
|
-
decodes.push(`"${status2}":
|
|
35599
|
+
decodes.push(`"${status2}": decodeError(${schema})`);
|
|
35576
35600
|
});
|
|
35577
|
-
decodes.push(`orElse:
|
|
35578
|
-
|
|
35601
|
+
decodes.push(`orElse: unexpectedStatus`);
|
|
35602
|
+
const execute2 = `withResponse(HttpClientResponse.matchStatus({
|
|
35579
35603
|
${decodes.join(",\n ")}
|
|
35580
|
-
}))
|
|
35604
|
+
}))`;
|
|
35605
|
+
pipeline.push(effectfulRequest ? `Effect.flatMap(${execute2})` : execute2);
|
|
35581
35606
|
return `"${operation.id}": (${params}) => HttpClientRequest.make("${operation.method.toUpperCase()}")(${operation.pathTemplate}).pipe(
|
|
35582
35607
|
${pipeline.join(",\n ")}
|
|
35583
35608
|
)`;
|
|
@@ -35588,7 +35613,6 @@ var layerTransformerSchema2 = sync6(OpenApiTransformer, () => {
|
|
|
35588
35613
|
'import * as HttpClientError from "@effect/platform/HttpClientError"',
|
|
35589
35614
|
'import * as HttpClientRequest from "@effect/platform/HttpClientRequest"',
|
|
35590
35615
|
'import * as HttpClientResponse from "@effect/platform/HttpClientResponse"',
|
|
35591
|
-
'import * as UrlParams from "@effect/platform/UrlParams"',
|
|
35592
35616
|
'import * as Effect from "effect/Effect"',
|
|
35593
35617
|
'import type { ParseError } from "effect/ParseResult"',
|
|
35594
35618
|
'import * as S from "effect/Schema"'
|
|
@@ -35671,12 +35695,23 @@ export const ${name2}Error = <Tag extends string, E>(
|
|
|
35671
35695
|
}),
|
|
35672
35696
|
),
|
|
35673
35697
|
)
|
|
35674
|
-
const
|
|
35675
|
-
|
|
35676
|
-
)
|
|
35677
|
-
|
|
35678
|
-
|
|
35679
|
-
|
|
35698
|
+
const withResponse: <A, E>(
|
|
35699
|
+
f: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, E>,
|
|
35700
|
+
) => (
|
|
35701
|
+
request: HttpClientRequest.HttpClientRequest,
|
|
35702
|
+
) => Effect.Effect<any, any> = options.transformClient
|
|
35703
|
+
? (f) => (request) =>
|
|
35704
|
+
Effect.flatMap(
|
|
35705
|
+
Effect.flatMap(options.transformClient!(httpClient), (client) =>
|
|
35706
|
+
client.execute(request),
|
|
35707
|
+
),
|
|
35708
|
+
f,
|
|
35709
|
+
)
|
|
35710
|
+
: (f) => (request) => Effect.flatMap(httpClient.execute(request), f)
|
|
35711
|
+
const jsonBody =
|
|
35712
|
+
(body: unknown) =>
|
|
35713
|
+
(request: HttpClientRequest.HttpClientRequest) =>
|
|
35714
|
+
Effect.orDie(HttpClientRequest.bodyJson(request, body))
|
|
35680
35715
|
const decodeSuccess = <A>(response: HttpClientResponse.HttpClientResponse) =>
|
|
35681
35716
|
response.json as Effect.Effect<A, HttpClientError.ResponseError>
|
|
35682
35717
|
const decodeVoid = (_response: HttpClientResponse.HttpClientResponse) =>
|
|
@@ -35695,27 +35730,21 @@ export const ${name2}Error = <Tag extends string, E>(
|
|
|
35695
35730
|
)
|
|
35696
35731
|
const onRequest = (
|
|
35697
35732
|
successCodes: ReadonlyArray<string>,
|
|
35698
|
-
errorCodes
|
|
35733
|
+
errorCodes?: Record<string, string>,
|
|
35699
35734
|
) => {
|
|
35700
35735
|
const cases: any = { orElse: unexpectedStatus }
|
|
35701
35736
|
for (const code of successCodes) {
|
|
35702
35737
|
cases[code] = decodeSuccess
|
|
35703
35738
|
}
|
|
35704
|
-
|
|
35705
|
-
|
|
35739
|
+
if (errorCodes) {
|
|
35740
|
+
for (const [code, tag] of Object.entries(errorCodes)) {
|
|
35741
|
+
cases[code] = decodeError(tag)
|
|
35742
|
+
}
|
|
35706
35743
|
}
|
|
35707
35744
|
if (successCodes.length === 0) {
|
|
35708
35745
|
cases["2xx"] = decodeVoid
|
|
35709
35746
|
}
|
|
35710
|
-
return (
|
|
35711
|
-
request: HttpClientRequest.HttpClientRequest,
|
|
35712
|
-
): Effect.Effect<any, any> =>
|
|
35713
|
-
Effect.flatMap(applyClientTransform(httpClient), (httpClient) =>
|
|
35714
|
-
Effect.flatMap(
|
|
35715
|
-
httpClient.execute(request),
|
|
35716
|
-
HttpClientResponse.matchStatus(cases) as any,
|
|
35717
|
-
),
|
|
35718
|
-
)
|
|
35747
|
+
return withResponse(HttpClientResponse.matchStatus(cases) as any)
|
|
35719
35748
|
}
|
|
35720
35749
|
return {
|
|
35721
35750
|
httpClient,
|
|
@@ -35730,6 +35759,7 @@ export const ${name2}Error = <Tag extends string, E>(
|
|
|
35730
35759
|
}
|
|
35731
35760
|
const params = `${args2.join(", ")}`;
|
|
35732
35761
|
const pipeline = [];
|
|
35762
|
+
let effectfulRequest = false;
|
|
35733
35763
|
if (operation.params) {
|
|
35734
35764
|
const varName = operation.payload ? "options.params?." : "options?.";
|
|
35735
35765
|
if (operation.urlParams.length > 0) {
|
|
@@ -35747,24 +35777,17 @@ export const ${name2}Error = <Tag extends string, E>(
|
|
|
35747
35777
|
}
|
|
35748
35778
|
const payloadVarName = operation.params ? "options.payload" : "options";
|
|
35749
35779
|
if (operation.payload === "FormData") {
|
|
35750
|
-
pipeline.push(
|
|
35751
|
-
`HttpClientRequest.bodyFormData(${payloadVarName})`,
|
|
35752
|
-
"Effect.succeed"
|
|
35753
|
-
);
|
|
35780
|
+
pipeline.push(`HttpClientRequest.bodyFormData(${payloadVarName})`);
|
|
35754
35781
|
} else if (operation.payload) {
|
|
35755
|
-
|
|
35756
|
-
|
|
35757
|
-
);
|
|
35758
|
-
} else {
|
|
35759
|
-
pipeline.push("Effect.succeed");
|
|
35782
|
+
effectfulRequest = true;
|
|
35783
|
+
pipeline.push(`jsonBody(${payloadVarName})`);
|
|
35760
35784
|
}
|
|
35761
35785
|
const successCodesRaw = Array.from(operation.successSchemas.keys());
|
|
35762
35786
|
const successCodes = successCodesRaw.map((_) => JSON.stringify(_)).join(", ");
|
|
35763
35787
|
const singleSuccessCode = successCodesRaw.length === 1 && successCodesRaw[0].startsWith("2");
|
|
35764
|
-
const errorCodes = Object.fromEntries(operation.errorSchemas.entries());
|
|
35765
|
-
|
|
35766
|
-
|
|
35767
|
-
);
|
|
35788
|
+
const errorCodes = operation.errorSchemas.size > 0 && Object.fromEntries(operation.errorSchemas.entries());
|
|
35789
|
+
const execute2 = `onRequest([${singleSuccessCode ? `"2xx"` : successCodes}]${errorCodes ? `, ${JSON.stringify(errorCodes)}` : ""})`;
|
|
35790
|
+
pipeline.push(effectfulRequest ? `Effect.flatMap(${execute2})` : execute2);
|
|
35768
35791
|
return `"${operation.id}": (${params}) => HttpClientRequest.make("${operation.method.toUpperCase()}")(${operation.pathTemplate}).pipe(
|
|
35769
35792
|
${pipeline.join(",\n ")}
|
|
35770
35793
|
)`;
|
|
@@ -35775,7 +35798,6 @@ export const ${name2}Error = <Tag extends string, E>(
|
|
|
35775
35798
|
'import * as HttpClientError from "@effect/platform/HttpClientError"',
|
|
35776
35799
|
'import * as HttpClientRequest from "@effect/platform/HttpClientRequest"',
|
|
35777
35800
|
'import * as HttpClientResponse from "@effect/platform/HttpClientResponse"',
|
|
35778
|
-
'import * as UrlParams from "@effect/platform/UrlParams"',
|
|
35779
35801
|
'import * as Data from "effect/Data"',
|
|
35780
35802
|
'import * as Effect from "effect/Effect"'
|
|
35781
35803
|
].join("\n"),
|