@tim-smart/openapi-gen 0.3.23 → 0.3.24

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.
Files changed (2) hide show
  1. package/main.js +65 -74
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -35484,9 +35484,11 @@ var OpenApiTransformer = class extends Tag2("OpenApiTransformer")() {
35484
35484
  var layerTransformerSchema2 = sync6(OpenApiTransformer, () => {
35485
35485
  const operationsToInterface = (name2, operations) => `export interface ${name2} {
35486
35486
  readonly httpClient: HttpClient.HttpClient
35487
- ${operations.map(operationToMethod).join("\n ")}
35488
- }`;
35489
- const operationToMethod = (operation) => {
35487
+ ${operations.map((op) => operationToMethod(name2, op)).join("\n ")}
35488
+ }
35489
+
35490
+ ${clientErrorSource(name2)}`;
35491
+ const operationToMethod = (name2, operation) => {
35490
35492
  const args2 = [];
35491
35493
  if (operation.pathIds.length > 0) {
35492
35494
  args2.push(...operation.pathIds.map((id2) => `${id2}: string`));
@@ -35520,7 +35522,7 @@ var layerTransformerSchema2 = sync6(OpenApiTransformer, () => {
35520
35522
  if (operation.errorSchemas.size > 0) {
35521
35523
  errors.push(
35522
35524
  ...Array.from(operation.errorSchemas.values()).map(
35523
- (schema) => `typeof ${schema}.Type`
35525
+ (schema) => `${name2}Error<"${schema}", typeof ${schema}.Type>`
35524
35526
  )
35525
35527
  );
35526
35528
  }
@@ -35532,45 +35534,17 @@ var layerTransformerSchema2 = sync6(OpenApiTransformer, () => {
35532
35534
  readonly transformClient?: ((client: HttpClient.HttpClient) => Effect.Effect<HttpClient.HttpClient>) | undefined
35533
35535
  } = {}
35534
35536
  ): ${name2} => {
35535
- const unexpectedStatus = (response: HttpClientResponse.HttpClientResponse) =>
35536
- Effect.flatMap(
35537
- Effect.orElseSucceed(response.json, () => "Unexpected status code"),
35538
- (description) =>
35539
- Effect.fail(
35540
- new HttpClientError.ResponseError({
35541
- request: response.request,
35542
- response,
35543
- reason: "StatusCode",
35544
- description: typeof description === "string" ? description : JSON.stringify(description),
35545
- }),
35546
- ),
35547
- )
35548
- const withResponse: <A, E, R>(
35549
- f: (
35550
- response: HttpClientResponse.HttpClientResponse,
35551
- ) => Effect.Effect<A, E, R>,
35552
- ) => (
35553
- request: HttpClientRequest.HttpClientRequest,
35554
- ) => Effect.Effect<A, E | HttpClientError.HttpClientError, R> =
35555
- options.transformClient
35556
- ? (f) => (request) =>
35557
- Effect.flatMap(
35558
- Effect.flatMap(options.transformClient!(httpClient), (client) =>
35559
- client.execute(request),
35560
- ),
35561
- f,
35562
- )
35563
- : (f) => (request) => Effect.flatMap(httpClient.execute(request), f)
35537
+ ${commonSource}
35564
35538
  const decodeSuccess =
35565
35539
  <A, I, R>(schema: S.Schema<A, I, R>) =>
35566
35540
  (response: HttpClientResponse.HttpClientResponse) =>
35567
35541
  HttpClientResponse.schemaBodyJson(schema)(response)
35568
35542
  const decodeError =
35569
- <A, I, R>(schema: S.Schema<A, I, R>) =>
35543
+ <const Tag extends string, A, I, R>(tag: Tag, schema: S.Schema<A, I, R>) =>
35570
35544
  (response: HttpClientResponse.HttpClientResponse) =>
35571
35545
  Effect.flatMap(
35572
35546
  HttpClientResponse.schemaBodyJson(schema)(response),
35573
- Effect.fail,
35547
+ (cause) => Effect.fail(${name2}Error(tag, cause, response)),
35574
35548
  )
35575
35549
  return {
35576
35550
  httpClient,
@@ -35615,7 +35589,7 @@ var layerTransformerSchema2 = sync6(OpenApiTransformer, () => {
35615
35589
  decodes.push(`"${statusCode}": decodeSuccess(${schema})`);
35616
35590
  });
35617
35591
  operation.errorSchemas.forEach((schema, status2) => {
35618
- decodes.push(`"${status2}": decodeError(${schema})`);
35592
+ decodes.push(`"${status2}": decodeError("${schema}", ${schema})`);
35619
35593
  });
35620
35594
  decodes.push(`orElse: unexpectedStatus`);
35621
35595
  pipeline.push(`withResponse(HttpClientResponse.matchStatus({
@@ -35631,6 +35605,7 @@ var layerTransformerSchema2 = sync6(OpenApiTransformer, () => {
35631
35605
  'import * as HttpClientError from "@effect/platform/HttpClientError"',
35632
35606
  'import * as HttpClientRequest from "@effect/platform/HttpClientRequest"',
35633
35607
  'import * as HttpClientResponse from "@effect/platform/HttpClientResponse"',
35608
+ 'import * as Data from "effect/Data"',
35634
35609
  'import * as Effect from "effect/Effect"',
35635
35610
  'import type { ParseError } from "effect/ParseResult"',
35636
35611
  'import * as S from "effect/Schema"'
@@ -35645,17 +35620,7 @@ var layerTransformerTs2 = sync6(OpenApiTransformer, () => {
35645
35620
  ${operations.map((s) => operationToMethod(name2, s)).join("\n ")}
35646
35621
  }
35647
35622
 
35648
- export interface ${name2}Error<Tag extends string, E> {
35649
- readonly _tag: Tag
35650
- readonly cause: E
35651
- }
35652
-
35653
- class ${name2}ErrorImpl extends Data.Error<{ _tag: string; cause: any }> {}
35654
-
35655
- export const ${name2}Error = <Tag extends string, E>(
35656
- tag: Tag,
35657
- cause: E,
35658
- ): ${name2}Error<Tag, E> => new ${name2}ErrorImpl({ _tag: tag, cause }) as any`;
35623
+ ${clientErrorSource(name2)}`;
35659
35624
  const operationToMethod = (name2, operation) => {
35660
35625
  const args2 = [];
35661
35626
  if (operation.pathIds.length > 0) {
@@ -35700,32 +35665,7 @@ export const ${name2}Error = <Tag extends string, E>(
35700
35665
  readonly transformClient?: ((client: HttpClient.HttpClient) => Effect.Effect<HttpClient.HttpClient>) | undefined
35701
35666
  } = {}
35702
35667
  ): ${name2} => {
35703
- const unexpectedStatus = (response: HttpClientResponse.HttpClientResponse) =>
35704
- Effect.flatMap(
35705
- Effect.orElseSucceed(response.json, () => "Unexpected status code"),
35706
- (description) =>
35707
- Effect.fail(
35708
- new HttpClientError.ResponseError({
35709
- request: response.request,
35710
- response,
35711
- reason: "StatusCode",
35712
- description: typeof description === "string" ? description : JSON.stringify(description),
35713
- }),
35714
- ),
35715
- )
35716
- const withResponse: <A, E>(
35717
- f: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, E>,
35718
- ) => (
35719
- request: HttpClientRequest.HttpClientRequest,
35720
- ) => Effect.Effect<any, any> = options.transformClient
35721
- ? (f) => (request) =>
35722
- Effect.flatMap(
35723
- Effect.flatMap(options.transformClient!(httpClient), (client) =>
35724
- client.execute(request),
35725
- ),
35726
- f,
35727
- )
35728
- : (f) => (request) => Effect.flatMap(httpClient.execute(request), f)
35668
+ ${commonSource}
35729
35669
  const decodeSuccess = <A>(response: HttpClientResponse.HttpClientResponse) =>
35730
35670
  response.json as Effect.Effect<A, HttpClientError.ResponseError>
35731
35671
  const decodeVoid = (_response: HttpClientResponse.HttpClientResponse) =>
@@ -35740,7 +35680,7 @@ export const ${name2}Error = <Tag extends string, E>(
35740
35680
  > =>
35741
35681
  Effect.flatMap(
35742
35682
  response.json as Effect.Effect<E, HttpClientError.ResponseError>,
35743
- (cause) => Effect.fail(${name2}Error(tag, cause)),
35683
+ (cause) => Effect.fail(${name2}Error(tag, cause, response)),
35744
35684
  )
35745
35685
  const onRequest = (
35746
35686
  successCodes: ReadonlyArray<string>,
@@ -35829,6 +35769,57 @@ var processPath = (path2) => {
35829
35769
  });
35830
35770
  return { path: "`" + path2 + "`", ids: ids3 };
35831
35771
  };
35772
+ var commonSource = `const unexpectedStatus = (response: HttpClientResponse.HttpClientResponse) =>
35773
+ Effect.flatMap(
35774
+ Effect.orElseSucceed(response.json, () => "Unexpected status code"),
35775
+ (description) =>
35776
+ Effect.fail(
35777
+ new HttpClientError.ResponseError({
35778
+ request: response.request,
35779
+ response,
35780
+ reason: "StatusCode",
35781
+ description: typeof description === "string" ? description : JSON.stringify(description),
35782
+ }),
35783
+ ),
35784
+ )
35785
+ const withResponse: <A, E>(
35786
+ f: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, E>,
35787
+ ) => (
35788
+ request: HttpClientRequest.HttpClientRequest,
35789
+ ) => Effect.Effect<any, any> = options.transformClient
35790
+ ? (f) => (request) =>
35791
+ Effect.flatMap(
35792
+ Effect.flatMap(options.transformClient!(httpClient), (client) =>
35793
+ client.execute(request),
35794
+ ),
35795
+ f,
35796
+ )
35797
+ : (f) => (request) => Effect.flatMap(httpClient.execute(request), f)`;
35798
+ var clientErrorSource = (name2) => `export interface ${name2}Error<Tag extends string, E> {
35799
+ readonly _tag: Tag
35800
+ readonly request: HttpClientRequest.HttpClientRequest
35801
+ readonly response: HttpClientResponse.HttpClientResponse
35802
+ readonly cause: E
35803
+ }
35804
+
35805
+ class ${name2}ErrorImpl extends Data.Error<{
35806
+ _tag: string
35807
+ cause: any
35808
+ request: HttpClientRequest.HttpClientRequest
35809
+ response: HttpClientResponse.HttpClientResponse
35810
+ }> {}
35811
+
35812
+ export const ${name2}Error = <Tag extends string, E>(
35813
+ tag: Tag,
35814
+ cause: E,
35815
+ response: HttpClientResponse.HttpClientResponse,
35816
+ ): ${name2}Error<Tag, E> =>
35817
+ new ${name2}ErrorImpl({
35818
+ _tag: tag,
35819
+ cause,
35820
+ response,
35821
+ request: response.request,
35822
+ }) as any`;
35832
35823
 
35833
35824
  // src/main.ts
35834
35825
  var spec = fileParse2("spec").pipe(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tim-smart/openapi-gen",
3
- "version": "0.3.23",
3
+ "version": "0.3.24",
4
4
  "description": "Generate Effect http clients from OpenAPI specs",
5
5
  "bin": "main.js",
6
6
  "repository": {