@tim-smart/openapi-gen 0.3.20 → 0.3.22
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 +66 -55
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -35510,20 +35510,46 @@ 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 decodeSuccess =
|
|
35543
|
+
<A, I, R>(schema: S.Schema<A, I, R>) =>
|
|
35544
|
+
(response: HttpClientResponse.HttpClientResponse) =>
|
|
35545
|
+
HttpClientResponse.schemaBodyJson(schema)(response)
|
|
35546
|
+
const decodeError =
|
|
35547
|
+
<A, I, R>(schema: S.Schema<A, I, R>) =>
|
|
35548
|
+
(response: HttpClientResponse.HttpClientResponse) =>
|
|
35549
|
+
Effect.flatMap(
|
|
35550
|
+
HttpClientResponse.schemaBodyJson(schema)(response),
|
|
35551
|
+
Effect.fail,
|
|
35552
|
+
)
|
|
35527
35553
|
return {
|
|
35528
35554
|
httpClient,
|
|
35529
35555
|
${operations.map(operationToImpl).join(",\n ")}
|
|
@@ -35554,32 +35580,23 @@ var layerTransformerSchema2 = sync6(OpenApiTransformer, () => {
|
|
|
35554
35580
|
}
|
|
35555
35581
|
const payloadVarName = operation.params ? "options.payload" : "options";
|
|
35556
35582
|
if (operation.payload === "FormData") {
|
|
35557
|
-
pipeline.push(
|
|
35558
|
-
`HttpClientRequest.bodyFormData(${payloadVarName})`,
|
|
35559
|
-
"Effect.succeed"
|
|
35560
|
-
);
|
|
35583
|
+
pipeline.push(`HttpClientRequest.bodyFormData(${payloadVarName})`);
|
|
35561
35584
|
} else if (operation.payload) {
|
|
35562
|
-
pipeline.push(
|
|
35563
|
-
`(req) => Effect.orDie(HttpClientRequest.bodyJson(req, ${payloadVarName}))`
|
|
35564
|
-
);
|
|
35565
|
-
} else {
|
|
35566
|
-
pipeline.push("Effect.succeed");
|
|
35585
|
+
pipeline.push(`HttpClientRequest.bodyUnsafeJson(${payloadVarName})`);
|
|
35567
35586
|
}
|
|
35568
35587
|
const decodes = [];
|
|
35569
35588
|
const singleSuccessCode = operation.successSchemas.size === 1;
|
|
35570
35589
|
operation.successSchemas.forEach((schema, status2) => {
|
|
35571
35590
|
const statusCode = singleSuccessCode && status2.startsWith("2") ? "2xx" : status2;
|
|
35572
|
-
decodes.push(
|
|
35573
|
-
`"${statusCode}": r => HttpClientResponse.schemaBodyJson(${schema})(r)`
|
|
35574
|
-
);
|
|
35591
|
+
decodes.push(`"${statusCode}": decodeSuccess(${schema})`);
|
|
35575
35592
|
});
|
|
35576
35593
|
operation.errorSchemas.forEach((schema, status2) => {
|
|
35577
|
-
decodes.push(`"${status2}":
|
|
35594
|
+
decodes.push(`"${status2}": decodeError(${schema})`);
|
|
35578
35595
|
});
|
|
35579
|
-
decodes.push(`orElse:
|
|
35580
|
-
pipeline.push(`
|
|
35596
|
+
decodes.push(`orElse: unexpectedStatus`);
|
|
35597
|
+
pipeline.push(`withResponse(HttpClientResponse.matchStatus({
|
|
35581
35598
|
${decodes.join(",\n ")}
|
|
35582
|
-
}))
|
|
35599
|
+
}))`);
|
|
35583
35600
|
return `"${operation.id}": (${params}) => HttpClientRequest.make("${operation.method.toUpperCase()}")(${operation.pathTemplate}).pipe(
|
|
35584
35601
|
${pipeline.join(",\n ")}
|
|
35585
35602
|
)`;
|
|
@@ -35672,12 +35689,19 @@ export const ${name2}Error = <Tag extends string, E>(
|
|
|
35672
35689
|
}),
|
|
35673
35690
|
),
|
|
35674
35691
|
)
|
|
35675
|
-
const
|
|
35676
|
-
|
|
35677
|
-
)
|
|
35678
|
-
|
|
35679
|
-
|
|
35680
|
-
|
|
35692
|
+
const withResponse: <A, E>(
|
|
35693
|
+
f: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, E>,
|
|
35694
|
+
) => (
|
|
35695
|
+
request: HttpClientRequest.HttpClientRequest,
|
|
35696
|
+
) => Effect.Effect<any, any> = options.transformClient
|
|
35697
|
+
? (f) => (request) =>
|
|
35698
|
+
Effect.flatMap(
|
|
35699
|
+
Effect.flatMap(options.transformClient!(httpClient), (client) =>
|
|
35700
|
+
client.execute(request),
|
|
35701
|
+
),
|
|
35702
|
+
f,
|
|
35703
|
+
)
|
|
35704
|
+
: (f) => (request) => Effect.flatMap(httpClient.execute(request), f)
|
|
35681
35705
|
const decodeSuccess = <A>(response: HttpClientResponse.HttpClientResponse) =>
|
|
35682
35706
|
response.json as Effect.Effect<A, HttpClientError.ResponseError>
|
|
35683
35707
|
const decodeVoid = (_response: HttpClientResponse.HttpClientResponse) =>
|
|
@@ -35696,27 +35720,21 @@ export const ${name2}Error = <Tag extends string, E>(
|
|
|
35696
35720
|
)
|
|
35697
35721
|
const onRequest = (
|
|
35698
35722
|
successCodes: ReadonlyArray<string>,
|
|
35699
|
-
errorCodes
|
|
35723
|
+
errorCodes?: Record<string, string>,
|
|
35700
35724
|
) => {
|
|
35701
35725
|
const cases: any = { orElse: unexpectedStatus }
|
|
35702
35726
|
for (const code of successCodes) {
|
|
35703
35727
|
cases[code] = decodeSuccess
|
|
35704
35728
|
}
|
|
35705
|
-
|
|
35706
|
-
|
|
35729
|
+
if (errorCodes) {
|
|
35730
|
+
for (const [code, tag] of Object.entries(errorCodes)) {
|
|
35731
|
+
cases[code] = decodeError(tag)
|
|
35732
|
+
}
|
|
35707
35733
|
}
|
|
35708
35734
|
if (successCodes.length === 0) {
|
|
35709
35735
|
cases["2xx"] = decodeVoid
|
|
35710
35736
|
}
|
|
35711
|
-
return (
|
|
35712
|
-
request: HttpClientRequest.HttpClientRequest,
|
|
35713
|
-
): Effect.Effect<any, any> =>
|
|
35714
|
-
Effect.flatMap(applyClientTransform(httpClient), (httpClient) =>
|
|
35715
|
-
Effect.flatMap(
|
|
35716
|
-
httpClient.execute(request),
|
|
35717
|
-
HttpClientResponse.matchStatus(cases) as any,
|
|
35718
|
-
),
|
|
35719
|
-
)
|
|
35737
|
+
return withResponse(HttpClientResponse.matchStatus(cases) as any)
|
|
35720
35738
|
}
|
|
35721
35739
|
return {
|
|
35722
35740
|
httpClient,
|
|
@@ -35748,23 +35766,16 @@ export const ${name2}Error = <Tag extends string, E>(
|
|
|
35748
35766
|
}
|
|
35749
35767
|
const payloadVarName = operation.params ? "options.payload" : "options";
|
|
35750
35768
|
if (operation.payload === "FormData") {
|
|
35751
|
-
pipeline.push(
|
|
35752
|
-
`HttpClientRequest.bodyFormData(${payloadVarName})`,
|
|
35753
|
-
"Effect.succeed"
|
|
35754
|
-
);
|
|
35769
|
+
pipeline.push(`HttpClientRequest.bodyFormData(${payloadVarName})`);
|
|
35755
35770
|
} else if (operation.payload) {
|
|
35756
|
-
pipeline.push(
|
|
35757
|
-
`(req) => Effect.orDie(HttpClientRequest.bodyJson(req, ${payloadVarName}))`
|
|
35758
|
-
);
|
|
35759
|
-
} else {
|
|
35760
|
-
pipeline.push("Effect.succeed");
|
|
35771
|
+
pipeline.push(`HttpClientRequest.bodyUnsafeJson(${payloadVarName})`);
|
|
35761
35772
|
}
|
|
35762
35773
|
const successCodesRaw = Array.from(operation.successSchemas.keys());
|
|
35763
35774
|
const successCodes = successCodesRaw.map((_) => JSON.stringify(_)).join(", ");
|
|
35764
35775
|
const singleSuccessCode = successCodesRaw.length === 1 && successCodesRaw[0].startsWith("2");
|
|
35765
|
-
const errorCodes = Object.fromEntries(operation.errorSchemas.entries());
|
|
35776
|
+
const errorCodes = operation.errorSchemas.size > 0 && Object.fromEntries(operation.errorSchemas.entries());
|
|
35766
35777
|
pipeline.push(
|
|
35767
|
-
`
|
|
35778
|
+
`onRequest([${singleSuccessCode ? `"2xx"` : successCodes}]${errorCodes ? `, ${JSON.stringify(errorCodes)}` : ""})`
|
|
35768
35779
|
);
|
|
35769
35780
|
return `"${operation.id}": (${params}) => HttpClientRequest.make("${operation.method.toUpperCase()}")(${operation.pathTemplate}).pipe(
|
|
35770
35781
|
${pipeline.join(",\n ")}
|