Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typescript): support bytes responses #5402

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fern/pages/changelogs/ts-express/2024-12-12.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.18.0
**`(internal):`** Upgraces to v53 of the IR.

2 changes: 1 addition & 1 deletion generators/typescript/codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-api/base-generator": "workspace:*",
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@types/jest": "^29.5.12",
"@types/node": "18.7.18",
"depcheck": "^1.4.6",
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/express/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"devDependencies": {
"@fern-fern/generator-exec-sdk": "^0.0.898",
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/abstract-generator-cli": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/abstract-schema-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ export class GeneratedExpressEndpointTypeSchemasImpl implements GeneratedExpress
if (this.endpoint.response.body?.type === "text") {
throw new Error("Text response is not supported");
}
if (this.endpoint.response.body.type === "bytes") {
throw new Error("Bytes response is not supported");
}

if (!this.includeSerdeLayer) {
return referenceToParsedResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/abstract-error-class-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/abstract-schema-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/abstract-schema-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"@fern-typescript/resolvers": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"@fern-typescript/resolvers": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,9 @@ export class GeneratedExpressServiceImpl implements GeneratedExpressService {
fileDownload: () => {
throw new Error("File download is not supported");
},
bytes: () => {
throw new Error("Bytes is not supported");
},
text: () => {
throw new Error("Text response is not supported");
},
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/express/generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@fern-api/core-utils": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/logger": "workspace:*",
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"@fern-typescript/express-endpoint-type-schemas-generator": "workspace:*",
Expand Down
6 changes: 6 additions & 0 deletions generators/typescript/express/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
- changelogEntry:
- summary: Upgraces to v53 of the IR.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Upgraces" typo

type: internal
irVersion: 53
version: 0.18.0

- changelogEntry:
- summary: Re-release the `0.17.5` version.
type: feat
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/model/type-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"@fern-typescript/union-generator": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-api/core-utils": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/resolvers": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"ts-morph": "^15.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/abstract-schema-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/model/union-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"ts-morph": "^15.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/abstract-schema-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
9 changes: 9 additions & 0 deletions generators/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.44.0] - 2024-12-12

- Feature: The SDK now has first class support for `bytes` responses and returns them as
a `Promise<ArrayBuffer>`. This is particularly useful for usecases like text to speech
where you would like to play the audio in the browser.

Additional this feature ugprade the dependency of the generator to Intermediate Representation v54.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ugprade" typo

Please upgrade the Fern CLI to `0.46.1` or above to use this generator.

## [0.43.0] - 2024-12-11

- Feature: Generate inline types for inline schemas by setting `enableInlineTypes` to `true` in the generator config.
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.43.0
0.44.0
2 changes: 1 addition & 1 deletion generators/typescript/sdk/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"devDependencies": {
"@fern-api/fs-utils": "workspace:*",
"@fern-api/base-generator": "workspace:*",
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/abstract-generator-cli": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"@fern-typescript/resolvers": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass {
| HttpResponseBody.FileDownload
| HttpResponseBody.Text
| HttpResponseBody.Streaming
| HttpResponseBody.Bytes
| undefined;
}) => {
if (neverThrowErrors) {
Expand Down Expand Up @@ -237,7 +238,12 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass {
const getDefaultEndpointImplementation = ({
response
}: {
response: HttpResponseBody.Json | HttpResponseBody.FileDownload | HttpResponseBody.Text | undefined;
response:
| HttpResponseBody.Json
| HttpResponseBody.FileDownload
| HttpResponseBody.Text
| HttpResponseBody.Bytes
| undefined;
}) => {
return new GeneratedDefaultEndpointImplementation({
endpoint,
Expand Down Expand Up @@ -307,6 +313,11 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass {
retainOriginalCasing: this.retainOriginalCasing,
omitUndefined: this.omitUndefined
}),
bytes: (bytesResponse) => {
return getDefaultEndpointImplementation({
response: HttpResponseBody.bytes(bytesResponse)
});
},
text: (textResponse) => {
return getDefaultEndpointImplementation({
response: HttpResponseBody.text(textResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,17 @@ export class GeneratedDefaultEndpointImplementation implements GeneratedEndpoint
withCredentials: this.includeCredentialsOnCrossOriginRequests
};

let cast: ts.TypeNode | undefined = undefined;

if (this.endpoint.response?.body?.type === "text") {
fetcherArgs.responseType = "text";
}

if (this.endpoint.response?.body?.type === "bytes") {
fetcherArgs.responseType = "arrayBuffer";
cast = ts.factory.createTypeReferenceNode("ArrayBuffer");
}

return [
ts.factory.createVariableStatement(
undefined,
Expand All @@ -440,7 +447,7 @@ export class GeneratedDefaultEndpointImplementation implements GeneratedEndpoint
undefined,
context.coreUtilities.fetcher.fetcher._invoke(fetcherArgs, {
referenceToFetcher: this.generatedSdkClientClass.getReferenceToFetcher(context),
cast: undefined
cast
})
)
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export declare namespace GeneratedNonThrowingEndpointResponse {
| HttpResponseBody.FileDownload
| HttpResponseBody.Streaming
| HttpResponseBody.Text
| HttpResponseBody.Bytes
| undefined;
errorDiscriminationStrategy: ErrorDiscriminationStrategy;
errorResolver: ErrorResolver;
Expand All @@ -37,6 +38,7 @@ export class GeneratedNonThrowingEndpointResponse implements GeneratedEndpointRe
| HttpResponseBody.FileDownload
| HttpResponseBody.Streaming
| HttpResponseBody.Text
| HttpResponseBody.Bytes
| undefined;
private errorDiscriminationStrategy: ErrorDiscriminationStrategy;
private errorResolver: ErrorResolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export declare namespace GeneratedThrowingEndpointResponse {
| HttpResponseBody.FileDownload
| HttpResponseBody.Streaming
| HttpResponseBody.Text
| HttpResponseBody.Bytes
| undefined;
errorDiscriminationStrategy: ErrorDiscriminationStrategy;
errorResolver: ErrorResolver;
Expand All @@ -53,6 +54,7 @@ export class GeneratedThrowingEndpointResponse implements GeneratedEndpointRespo
| HttpResponseBody.FileDownload
| HttpResponseBody.Streaming
| HttpResponseBody.Text
| HttpResponseBody.Bytes
| undefined;
private errorDiscriminationStrategy: ErrorDiscriminationStrategy;
private errorResolver: ErrorResolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function getSuccessReturnType(
| HttpResponseBody.FileDownload
| HttpResponseBody.Streaming
| HttpResponseBody.Text
| HttpResponseBody.Bytes
| undefined,
context: SdkContext,
opts: {
Expand All @@ -27,6 +28,8 @@ export function getSuccessReturnType(
includeContentHeadersOnResponse: opts.includeContentHeadersOnResponse
});
}
case "bytes":
return ts.factory.createTypeReferenceNode("ArrayBuffer");
case "json":
return context.type.getReferenceToType(response.value.responseBodyType).typeNode;
case "text":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"@fern-typescript/resolvers": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"ts-morph": "^15.1.0"
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/sdk/generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@fern-api/logger": "workspace:*",
"@fern-fern/generator-cli-sdk": "0.0.17",
"@fern-fern/generator-exec-sdk": "^0.0.898",
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-fern/snippet-sdk": "^0.0.5526",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"ts-morph": "^15.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/abstract-schema-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ export class GeneratedSdkEndpointTypeSchemasImpl implements GeneratedSdkEndpoint
}

if (this.endpoint.response.body.type === "text") {
return ts.factory.createAsExpression(
referenceToRawResponse,
context.type.getReferenceToType(TypeReference.primitive({ v1: PrimitiveTypeV1.String, v2: undefined }))
.typeNode
);
return referenceToRawResponse;
}

if (this.endpoint.response.body.type === "bytes") {
return referenceToRawResponse;
}

if (this.endpoint.response.body.value.responseBodyType.type === "unknown") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.23.0",
"@fern-fern/ir-sdk": "54.0.0",
"@fern-typescript/abstract-error-class-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Loading
Loading