Skip to content

Commit c8d78a4

Browse files
thomasballingerConvex, Inc.
authored andcommitted
Generate a Mounts type in component codegen (#29609)
Generate a Mounts type in component codegen GitOrigin-RevId: 1009bd46515be96a8dfedc09e02c49c779923e3f
1 parent ef9790b commit c8d78a4

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

npm-packages/component-tests/component/_generated/api.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import type {
2828
declare const fullApi: ApiFromModules<{
2929
messages: typeof messages;
3030
}>;
31-
declare const fullApiWithMounts: typeof fullApi & {
31+
export type Mounts = {
3232
messages: {
3333
dateNow: FunctionReference<"query", "public", {}, any>;
3434
hello: FunctionReference<"action", "public", {}, any>;
@@ -43,6 +43,10 @@ declare const fullApiWithMounts: typeof fullApi & {
4343
tryToPaginate: FunctionReference<"query", "public", {}, any>;
4444
};
4545
};
46+
// For now fullApiWithMounts is only fullApi which provides
47+
// jump-to-definition in component client code.
48+
// Use Mounts for the same type without the inference.
49+
declare const fullApiWithMounts: typeof fullApi;
4650

4751
export declare const api: FilterApi<
4852
typeof fullApiWithMounts,

npm-packages/component-tests/envVars/_generated/api.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import type {
2828
declare const fullApi: ApiFromModules<{
2929
messages: typeof messages;
3030
}>;
31-
declare const fullApiWithMounts: typeof fullApi & {
31+
export type Mounts = {
3232
messages: {
3333
envVarAction: FunctionReference<"action", "public", any, any>;
3434
envVarQuery: FunctionReference<"query", "public", any, any>;
@@ -37,6 +37,10 @@ declare const fullApiWithMounts: typeof fullApi & {
3737
systemEnvVarQuery: FunctionReference<"query", "public", any, any>;
3838
};
3939
};
40+
// For now fullApiWithMounts is only fullApi which provides
41+
// jump-to-definition in component client code.
42+
// Use Mounts for the same type without the inference.
43+
declare const fullApiWithMounts: typeof fullApi;
4044

4145
export declare const api: FilterApi<
4246
typeof fullApiWithMounts,

npm-packages/component-tests/errors/_generated/api.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ import type {
2828
declare const fullApi: ApiFromModules<{
2929
throwSystemError: typeof throwSystemError;
3030
}>;
31-
declare const fullApiWithMounts: typeof fullApi & {
31+
export type Mounts = {
3232
throwSystemError: {
3333
fromAction: FunctionReference<"action", "public", any, any>;
3434
fromQuery: FunctionReference<"query", "public", any, any>;
3535
};
3636
};
37+
// For now fullApiWithMounts is only fullApi which provides
38+
// jump-to-definition in component client code.
39+
// Use Mounts for the same type without the inference.
40+
declare const fullApiWithMounts: typeof fullApi;
3741

3842
export declare const api: FilterApi<
3943
typeof fullApiWithMounts,

npm-packages/convex/src/cli/codegen_templates/component_api.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,17 @@ async function* codegenApiWithMounts(
123123
definitionPath: ComponentDefinitionPath,
124124
): AsyncGenerator<string> {
125125
const mountTree = await buildMountTree(ctx, startPush, definitionPath, []);
126-
if (!mountTree) {
126+
if (mountTree) {
127+
yield "export type Mounts = ";
128+
yield* codegenMountTree(mountTree);
129+
yield `;`;
130+
yield `// For now fullApiWithMounts is only fullApi which provides`;
131+
yield `// jump-to-definition in component client code.`;
132+
yield `// Use Mounts for the same type without the inference.`;
133+
yield "declare const fullApiWithMounts: typeof fullApi;";
134+
} else {
127135
yield "declare const fullApiWithMounts: typeof fullApi;";
128-
return;
129136
}
130-
yield "declare const fullApiWithMounts: typeof fullApi &";
131-
yield* codegenMountTree(mountTree);
132-
yield `;`;
133137
}
134138

135139
function* codegenMountTree(tree: MountTree): Generator<string> {

0 commit comments

Comments
 (0)