@tim-smart/openapi-gen 0.3.20 → 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 +79 -57
- 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,32 +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 = [];
|
|
35569
35593
|
const singleSuccessCode = operation.successSchemas.size === 1;
|
|
35570
35594
|
operation.successSchemas.forEach((schema, status2) => {
|
|
35571
35595
|
const statusCode = singleSuccessCode && status2.startsWith("2") ? "2xx" : status2;
|
|
35572
|
-
decodes.push(
|
|
35573
|
-
`"${statusCode}": r => HttpClientResponse.schemaBodyJson(${schema})(r)`
|
|
35574
|
-
);
|
|
35596
|
+
decodes.push(`"${statusCode}": decodeSuccess(${schema})`);
|
|
35575
35597
|
});
|
|
35576
35598
|
operation.errorSchemas.forEach((schema, status2) => {
|
|
35577
|
-
decodes.push(`"${status2}":
|
|
35599
|
+
decodes.push(`"${status2}": decodeError(${schema})`);
|
|
35578
35600
|
});
|
|
35579
|
-
decodes.push(`orElse:
|
|
35580
|
-
|
|
35601
|
+
decodes.push(`orElse: unexpectedStatus`);
|
|
35602
|
+
const execute2 = `withResponse(HttpClientResponse.matchStatus({
|
|
35581
35603
|
${decodes.join(",\n ")}
|
|
35582
|
-
}))
|
|
35604
|
+
}))`;
|
|
35605
|
+
pipeline.push(effectfulRequest ? `Effect.flatMap(${execute2})` : execute2);
|
|
35583
35606
|
return `"${operation.id}": (${params}) => HttpClientRequest.make("${operation.method.toUpperCase()}")(${operation.pathTemplate}).pipe(
|
|
35584
35607
|
${pipeline.join(",\n ")}
|
|
35585
35608
|
)`;
|
|
@@ -35672,12 +35695,23 @@ export const ${name2}Error = <Tag extends string, E>(
|
|
|
35672
35695
|
}),
|
|
35673
35696
|
),
|
|
35674
35697
|
)
|
|
35675
|
-
const
|
|
35676
|
-
|
|
35677
|
-
)
|
|
35678
|
-
|
|
35679
|
-
|
|
35680
|
-
|
|
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))
|
|
35681
35715
|
const decodeSuccess = <A>(response: HttpClientResponse.HttpClientResponse) =>
|
|
35682
35716
|
response.json as Effect.Effect<A, HttpClientError.ResponseError>
|
|
35683
35717
|
const decodeVoid = (_response: HttpClientResponse.HttpClientResponse) =>
|
|
@@ -35696,27 +35730,21 @@ export const ${name2}Error = <Tag extends string, E>(
|
|
|
35696
35730
|
)
|
|
35697
35731
|
const onRequest = (
|
|
35698
35732
|
successCodes: ReadonlyArray<string>,
|
|
35699
|
-
errorCodes
|
|
35733
|
+
errorCodes?: Record<string, string>,
|
|
35700
35734
|
) => {
|
|
35701
35735
|
const cases: any = { orElse: unexpectedStatus }
|
|
35702
35736
|
for (const code of successCodes) {
|
|
35703
35737
|
cases[code] = decodeSuccess
|
|
35704
35738
|
}
|
|
35705
|
-
|
|
35706
|
-
|
|
35739
|
+
if (errorCodes) {
|
|
35740
|
+
for (const [code, tag] of Object.entries(errorCodes)) {
|
|
35741
|
+
cases[code] = decodeError(tag)
|
|
35742
|
+
}
|
|
35707
35743
|
}
|
|
35708
35744
|
if (successCodes.length === 0) {
|
|
35709
35745
|
cases["2xx"] = decodeVoid
|
|
35710
35746
|
}
|
|
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
|
-
)
|
|
35747
|
+
return withResponse(HttpClientResponse.matchStatus(cases) as any)
|
|
35720
35748
|
}
|
|
35721
35749
|
return {
|
|
35722
35750
|
httpClient,
|
|
@@ -35731,6 +35759,7 @@ export const ${name2}Error = <Tag extends string, E>(
|
|
|
35731
35759
|
}
|
|
35732
35760
|
const params = `${args2.join(", ")}`;
|
|
35733
35761
|
const pipeline = [];
|
|
35762
|
+
let effectfulRequest = false;
|
|
35734
35763
|
if (operation.params) {
|
|
35735
35764
|
const varName = operation.payload ? "options.params?." : "options?.";
|
|
35736
35765
|
if (operation.urlParams.length > 0) {
|
|
@@ -35748,24 +35777,17 @@ export const ${name2}Error = <Tag extends string, E>(
|
|
|
35748
35777
|
}
|
|
35749
35778
|
const payloadVarName = operation.params ? "options.payload" : "options";
|
|
35750
35779
|
if (operation.payload === "FormData") {
|
|
35751
|
-
pipeline.push(
|
|
35752
|
-
`HttpClientRequest.bodyFormData(${payloadVarName})`,
|
|
35753
|
-
"Effect.succeed"
|
|
35754
|
-
);
|
|
35780
|
+
pipeline.push(`HttpClientRequest.bodyFormData(${payloadVarName})`);
|
|
35755
35781
|
} else if (operation.payload) {
|
|
35756
|
-
|
|
35757
|
-
|
|
35758
|
-
);
|
|
35759
|
-
} else {
|
|
35760
|
-
pipeline.push("Effect.succeed");
|
|
35782
|
+
effectfulRequest = true;
|
|
35783
|
+
pipeline.push(`jsonBody(${payloadVarName})`);
|
|
35761
35784
|
}
|
|
35762
35785
|
const successCodesRaw = Array.from(operation.successSchemas.keys());
|
|
35763
35786
|
const successCodes = successCodesRaw.map((_) => JSON.stringify(_)).join(", ");
|
|
35764
35787
|
const singleSuccessCode = successCodesRaw.length === 1 && successCodesRaw[0].startsWith("2");
|
|
35765
|
-
const errorCodes = Object.fromEntries(operation.errorSchemas.entries());
|
|
35766
|
-
|
|
35767
|
-
|
|
35768
|
-
);
|
|
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);
|
|
35769
35791
|
return `"${operation.id}": (${params}) => HttpClientRequest.make("${operation.method.toUpperCase()}")(${operation.pathTemplate}).pipe(
|
|
35770
35792
|
${pipeline.join(",\n ")}
|
|
35771
35793
|
)`;
|