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: include service and definition types with implementations #552

Merged
merged 1 commit into from
May 1, 2022
Merged
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
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
## [next](https://github.com/stephenh/ts-proto/compare/v1.110.4...main) (????-??-??)

### Features

* When outputing service and service definition implementations, include types. Eg, before:

```ts
export const TestDefinition = {
name: 'Test',
fullName: 'simple.Test',
methods: {
},
} as const;
```

Now:

```ts
export type TestDefinition = typeof TestDefinition;
export const TestDefinition = {
name: 'Test',
fullName: 'simple.Test',
methods: {
},
} as const;
```

## [1.110.4](https://github.com/stephenh/ts-proto/compare/v1.110.3...v1.110.4) (2022-04-08)


Expand Down
1 change: 1 addition & 0 deletions integration/generic-metadata/hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export class HeroServiceClientImpl implements HeroService {
}
}

export type HeroServiceDefinition = typeof HeroServiceDefinition;
export const HeroServiceDefinition = {
name: 'HeroService',
fullName: 'hero.HeroService',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const TestMessage = {
};

/** @deprecated */
export type TestDefinition = typeof TestDefinition;
export const TestDefinition = {
name: 'Test',
fullName: 'simple.Test',
Expand Down
1 change: 1 addition & 0 deletions integration/generic-service-definitions/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const TestMessage = {
};

/** @deprecated */
export type TestDefinition = typeof TestDefinition;
export const TestDefinition = {
name: 'Test',
fullName: 'simple.Test',
Expand Down
1 change: 1 addition & 0 deletions integration/grpc-js/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const TestMessage = {
*
* @deprecated
*/
export type TestService = typeof TestService;
export const TestService = {
/**
* Unary
Expand Down
1 change: 1 addition & 0 deletions integration/use-date-true/use-date-true.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export class ClockClientImpl implements Clock {
}
}

export type ClockDefinition = typeof ClockDefinition;
export const ClockDefinition = {
name: 'Clock',
fullName: 'Clock',
Expand Down
8 changes: 7 additions & 1 deletion src/generate-generic-service-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ export function generateGenericServiceDefinition(

maybeAddComment(sourceInfo, chunks, serviceDesc.options?.deprecated);

// Service definition type
const name = def(`${serviceDesc.name}Definition`);
chunks.push(code`
export type ${name} = typeof ${name};
`);

// Service definition
chunks.push(code`
export const ${def(`${serviceDesc.name}Definition`)} = {
export const ${name} = {
`);

serviceDesc.options?.uninterpretedOption;
Expand Down
8 changes: 7 additions & 1 deletion src/generate-grpc-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ function generateServiceDefinition(

maybeAddComment(sourceInfo, chunks, serviceDesc.options?.deprecated);

// Service definition type
const name = def(`${serviceDesc.name}Service`);
chunks.push(code`
export type ${name} = typeof ${name};
`);

// Service definition
chunks.push(code`
export const ${def(`${serviceDesc.name}Service`)} = {
export const ${name} = {
`);

for (const [index, methodDesc] of serviceDesc.method.entries()) {
Expand Down