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

Fix missing implicit types #211

Merged
merged 3 commits into from
Oct 6, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { MethodKind } from "@bufbuild/protobuf";
import {
createQueryService,
createUnaryHooks,
UnaryFunctionsWithHooks,
} from "@connectrpc/connect-query";

export const typeName = "connectrpc.eliza.v1.BigIntService";
Expand Down Expand Up @@ -48,7 +49,7 @@ const $queryService = createQueryService({ service: BigIntService });
/**
* @generated from rpc connectrpc.eliza.v1.BigIntService.Count
*/
export const count = {
export const count: UnaryFunctionsWithHooks<CountRequest, CountResponse> = {
...$queryService.count,
...createUnaryHooks($queryService.count),
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { MethodKind } from "@bufbuild/protobuf";
import {
createQueryService,
createUnaryHooks,
UnaryFunctionsWithHooks,
} from "@connectrpc/connect-query";

export const typeName = "connectrpc.eliza.v1.ElizaService";
Expand Down Expand Up @@ -102,7 +103,7 @@ const $queryService = createQueryService({ service: ElizaService });
*
* @generated from rpc connectrpc.eliza.v1.ElizaService.Say
*/
export const say = {
export const say: UnaryFunctionsWithHooks<SayRequest, SayResponse> = {
...$queryService.say,
...createUnaryHooks($queryService.say),
};
Expand All @@ -112,7 +113,7 @@ export const say = {
*
* @generated from rpc connectrpc.eliza.v1.ElizaService.SayAgain
*/
export const sayAgain = {
export const sayAgain: UnaryFunctionsWithHooks<SayRequest, SayResponse> = {
...$queryService.sayAgain,
...createUnaryHooks($queryService.sayAgain),
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { MethodKind } from "@bufbuild/protobuf";
import {
createQueryService,
createUnaryHooks,
UnaryFunctionsWithHooks,
} from "@connectrpc/connect-query";

export const typeName = "connectrpc.eliza.v1.Haberdasher";
Expand Down Expand Up @@ -48,7 +49,7 @@ const $queryService = createQueryService({ service: Haberdasher });
/**
* @generated from rpc connectrpc.eliza.v1.Haberdasher.Work
*/
export const work = {
export const work: UnaryFunctionsWithHooks<Nothing, Nothing> = {
...$queryService.work,
...createUnaryHooks($queryService.work),
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { MethodKind } from "@bufbuild/protobuf";
import {
createQueryService,
createUnaryHooks,
UnaryFunctionsWithHooks,
} from "@connectrpc/connect-query";

export const typeName = "connectrpc.eliza.v1.PaginatedService";
Expand Down Expand Up @@ -48,7 +49,7 @@ const $queryService = createQueryService({ service: PaginatedService });
/**
* @generated from rpc connectrpc.eliza.v1.PaginatedService.List
*/
export const list = {
export const list: UnaryFunctionsWithHooks<ListRequest, ListResponse> = {
...$queryService.list,
...createUnaryHooks($queryService.list),
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { MethodKind } from "@bufbuild/protobuf";
import {
createQueryService,
createUnaryHooks,
UnaryFunctionsWithHooks,
} from "@connectrpc/connect-query";

export const typeName = "connectrpc.eliza.v1.SecondService";
Expand Down Expand Up @@ -86,7 +87,7 @@ const $queryService = createQueryService({ service: SecondService });
*
* @generated from rpc connectrpc.eliza.v1.SecondService.Say
*/
export const say = {
export const say: UnaryFunctionsWithHooks<SayRequest, SayResponse> = {
...$queryService.say,
...createUnaryHooks($queryService.say),
};
3 changes: 2 additions & 1 deletion examples/react/basic/src/gen/eliza-Slouch_connectquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { MethodKind } from "@bufbuild/protobuf";
import {
createQueryService,
createUnaryHooks,
UnaryFunctionsWithHooks,
} from "@connectrpc/connect-query";

export const typeName = "connectrpc.eliza.v1.Slouch";
Expand Down Expand Up @@ -48,7 +49,7 @@ const $queryService = createQueryService({ service: Slouch });
/**
* @generated from rpc connectrpc.eliza.v1.Slouch.Work
*/
export const work = {
export const work: UnaryFunctionsWithHooks<Nothing, Nothing> = {
...$queryService.work,
...createUnaryHooks($queryService.work),
};
3 changes: 2 additions & 1 deletion examples/react/basic/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"strict": true,
"target": "ESNext",
"useDefineForClassFields": true,
"types": ["jest", "node"]
"types": ["jest", "node"],
"declaration": true // necessary to check if generated code can be published
},
"include": ["src", "./*.config.ts", "__mocks__"],
"references": [{ "path": "./tsconfig.node.json" }]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { MethodKind } from "@bufbuild/protobuf";
import {
createQueryService,
createUnaryHooks,
UnaryFunctionsWithHooks,
} from "@connectrpc/connect-query";

export const typeName = "connectrpc.eliza.v1.ElizaService";
Expand Down Expand Up @@ -92,7 +93,7 @@ const $queryService = createQueryService({ service: ElizaService });
*
* @generated from rpc connectrpc.eliza.v1.ElizaService.Say
*/
export const say = {
export const say: UnaryFunctionsWithHooks<SayRequest, SayResponse> = {
...$queryService.say,
...createUnaryHooks($queryService.say),
};
14 changes: 10 additions & 4 deletions packages/protoc-gen-connect-query/src/generateTs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const { safeIdentifier } = codegenInfo;
*/
const generateServiceFile =
(schema: Schema, protoFile: DescFile, extension: 'js' | 'ts') =>
(service: DescService) => {
(service: DescService) => {
const isTs = extension === "ts";
const f = schema.generateFile(
`${protoFile.name}-${localName(service)}_connectquery.${extension}`,
);
Expand Down Expand Up @@ -63,7 +64,7 @@ const generateServiceFile =
f.print(" },");
}
f.print(" }");
f.print("}", extension === "ts" ? " as const" : "", ";");
f.print("}", isTs ? " as const" : "", ";");
f.print();

f.print(`const $queryService = `,
Expand All @@ -74,13 +75,18 @@ const generateServiceFile =
);
f.print();


service.methods
.filter((method) => method.methodKind === MethodKind.Unary)
.forEach((method, index, filteredMethods) => {
f.print(makeJsDoc(method));
const methodTsType = [
": ",
f.import('UnaryFunctionsWithHooks', '@connectrpc/connect-query'),
`<${method.input.name}, ${method.output.name}>`
]

f.print(
`export const ${safeIdentifier(localName(method))} = { `,
`export const ${safeIdentifier(localName(method))}`, ...(isTs ? methodTsType : []), ` = { `,
` ...$queryService.${localName(method)},`,
` ...`, f.import('createUnaryHooks', '@connectrpc/connect-query'),`($queryService.${localName(method)})`,
`};`
Expand Down