Skip to content

Commit

Permalink
feat(typescript): export serializers under the namespace (#4649)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Sep 15, 2024
1 parent 69595ab commit 072c0a2
Show file tree
Hide file tree
Showing 79 changed files with 121 additions and 14 deletions.
10 changes: 1 addition & 9 deletions docker/seed/Dockerfile.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
FROM node:lts-slim as base

FROM base AS builder

RUN mkdir /yarn-cache-template
RUN yarn config set cache-folder /yarn-cache-template
FROM node:lts-slim

RUN yarn add \
# jest
Expand Down Expand Up @@ -45,9 +40,6 @@ RUN yarn add \
# fetch mock jest
fetch-mock-jest@1.5.1

FROM base AS runner

COPY --from=builder /yarn-cache-template /yarn-cache-template
# Installs tsc
RUN npm install -g typescript

Expand Down
19 changes: 19 additions & 0 deletions generators/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ 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.40.3] - 2024-09-12

- Fix: If the serde layer is enabled, then all the serializers are exported under the
namespace `serializers`.

```ts
import { serializers } from "@plantstore/sdk";

export function main(): void {
// serialize to json

const json = serializers.Plant.toJson({
name: "fern",
});

const parsed = serializers.Plant.parseOrThrow(`{ "name": "fern" }`);
}
```

## [0.40.2] - 2024-09-12

- Fix: The generated SDK now handles reading IR JSONs that are larger than 500MB. In order to
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.40.2
0.40.3
29 changes: 25 additions & 4 deletions generators/typescript/sdk/generator/src/SdkGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,13 @@ export class SdkGenerator {
this.generateTypeSchemas();
this.generateEndpointTypeSchemas();
this.generateInlinedRequestBodySchemas();
this.context.logger.debug("Generated serde layer.");
const serializationDirectory = this.rootDirectory.getDirectory(RelativeFilePath.of("src/serialization"));
if (serializationDirectory != null && serializationDirectory?.getSourceFiles().length > 0) {
this.exportsManager.addExportsForDirectories([
{ nameOnDisk: "serialization", exportDeclaration: { namespaceExport: "serializers" } }
]);
this.context.logger.debug("Generated serde layer.");
}
}

if (this.generateOAuthClients) {
Expand Down Expand Up @@ -556,16 +562,21 @@ export class SdkGenerator {
}
}

private generateTypeSchemas() {
private generateTypeSchemas(): { generated: boolean } {
let generated = false;
for (const typeDeclaration of Object.values(this.intermediateRepresentation.types)) {
this.withSourceFile({
filepath: this.typeSchemaDeclarationReferencer.getExportedFilepath(typeDeclaration.name),
run: ({ sourceFile, importsManager }) => {
if (!generated) {
generated = true;
}
const context = this.generateSdkContext({ sourceFile, importsManager });
context.typeSchema.getGeneratedTypeSchema(typeDeclaration.name).writeToFile(context);
}
});
}
return { generated };
}

private generateErrorDeclarations() {
Expand Down Expand Up @@ -611,7 +622,8 @@ export class SdkGenerator {
});
}

private generateEndpointTypeSchemas() {
private generateEndpointTypeSchemas(): { generated: boolean } {
let generated = false;
this.forEachService((service, packageId) => {
for (const endpoint of service.endpoints) {
this.withSourceFile({
Expand All @@ -624,10 +636,14 @@ export class SdkGenerator {
context.sdkEndpointTypeSchemas
.getGeneratedEndpointTypeSchemas(packageId, endpoint.name)
.writeToFile(context);
if (!generated) {
generated = true;
}
}
});
}
});
return { generated };
}

private generateRequestWrappers() {
Expand All @@ -652,7 +668,8 @@ export class SdkGenerator {
});
}

private generateInlinedRequestBodySchemas() {
private generateInlinedRequestBodySchemas(): { generated: boolean } {
let generated = false;
this.forEachService((service, packageId) => {
for (const endpoint of service.endpoints) {
if (endpoint.requestBody?.type === "inlinedRequestBody") {
Expand All @@ -666,11 +683,15 @@ export class SdkGenerator {
context.sdkInlinedRequestBodySchema
.getGeneratedInlinedRequestBodySchema(packageId, endpoint.name)
.writeToFile(context);
if (!generated) {
generated = true;
}
}
});
}
}
});
return { generated };
}

private generateServiceDeclarations() {
Expand Down
1 change: 1 addition & 0 deletions seed/ts-sdk/alias-extends/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/alias/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/any-auth/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/api-wide-base-path/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/audiences/no-custom-config/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/audiences/with-partner-audience/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/auth-environment-variables/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/basic-auth-environment-variables/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/basic-auth/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/bearer-token-environment-variable/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/circular-references-advanced/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/circular-references/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/cross-package-type-names/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/custom-auth/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/enum/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/error-property/union-utils/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/examples/retain-original-casing/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/exhaustive/allow-extra-fields/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/exhaustive/bigint/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/exhaustive/bundle/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/exhaustive/custom-package-json/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/exhaustive/dev-dependencies/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/exhaustive/jsr/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/exhaustive/no-custom-config/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/exhaustive/retain-original-casing/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/extends/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/extra-properties/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/file-upload/no-custom-config/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/file-upload/wrap-file-properties/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/folders/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/grpc-proto-exhaustive/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/grpc-proto/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/idempotency-headers/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/imdb/no-custom-config/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/imdb/noScripts/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/imdb/omit-undefined/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/literal/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/mixed-case/no-custom-config/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/mixed-case/retain-original-casing/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/mixed-file-directory/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/multi-line-docs/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/multi-url-environment-no-default/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/multi-url-environment/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/no-environment/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/oauth-client-credentials-default/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/oauth-client-credentials/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/object/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/objects-with-imports/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions seed/ts-sdk/optional/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 072c0a2

Please sign in to comment.