Skip to content

Commit f452e61

Browse files
ldanilekConvex, Inc.
authored andcommitted
only require db.table in child component (#28617)
GitOrigin-RevId: cec2e901f06d2836565c440947c1bd9feecc175c
1 parent 4dd39d6 commit f452e61

File tree

3 files changed

+46
-57
lines changed

3 files changed

+46
-57
lines changed

npm-packages/component-tests/projects/basic/convex/_generated/server.d.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
import {
1313
ActionBuilder,
1414
HttpActionBuilder,
15-
MutationBuilderWithTable,
16-
QueryBuilderWithTable,
15+
MutationBuilder,
16+
QueryBuilder,
1717
GenericActionCtx,
18-
GenericMutationCtxWithTable,
19-
GenericQueryCtxWithTable,
20-
GenericDatabaseReaderWithTable,
21-
GenericDatabaseWriterWithTable,
18+
GenericMutationCtx,
19+
GenericQueryCtx,
20+
GenericDatabaseReader,
21+
GenericDatabaseWriter,
2222
FunctionReference,
2323
} from "convex/server";
2424
import type { DataModel } from "./dataModel.js";
@@ -36,7 +36,7 @@ type GenericCtx =
3636
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
3737
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
3838
*/
39-
export declare const query: QueryBuilderWithTable<DataModel, "public">;
39+
export declare const query: QueryBuilder<DataModel, "public">;
4040

4141
/**
4242
* Define a query that is only accessible from other Convex functions (but not from the client).
@@ -46,10 +46,7 @@ export declare const query: QueryBuilderWithTable<DataModel, "public">;
4646
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
4747
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
4848
*/
49-
export declare const internalQuery: QueryBuilderWithTable<
50-
DataModel,
51-
"internal"
52-
>;
49+
export declare const internalQuery: QueryBuilder<DataModel, "internal">;
5350

5451
/**
5552
* Define a mutation in this Convex app's public API.
@@ -59,7 +56,7 @@ export declare const internalQuery: QueryBuilderWithTable<
5956
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
6057
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
6158
*/
62-
export declare const mutation: MutationBuilderWithTable<DataModel, "public">;
59+
export declare const mutation: MutationBuilder<DataModel, "public">;
6360

6461
/**
6562
* Define a mutation that is only accessible from other Convex functions (but not from the client).
@@ -69,10 +66,7 @@ export declare const mutation: MutationBuilderWithTable<DataModel, "public">;
6966
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
7067
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
7168
*/
72-
export declare const internalMutation: MutationBuilderWithTable<
73-
DataModel,
74-
"internal"
75-
>;
69+
export declare const internalMutation: MutationBuilder<DataModel, "internal">;
7670

7771
/**
7872
* Define an action in this Convex app's public API.
@@ -116,15 +110,15 @@ export declare const httpAction: HttpActionBuilder;
116110
* This differs from the {@link MutationCtx} because all of the services are
117111
* read-only.
118112
*/
119-
export type QueryCtx = GenericQueryCtxWithTable<DataModel>;
113+
export type QueryCtx = GenericQueryCtx<DataModel>;
120114

121115
/**
122116
* A set of services for use within Convex mutation functions.
123117
*
124118
* The mutation context is passed as the first argument to any Convex mutation
125119
* function run on the server.
126120
*/
127-
export type MutationCtx = GenericMutationCtxWithTable<DataModel>;
121+
export type MutationCtx = GenericMutationCtx<DataModel>;
128122

129123
/**
130124
* A set of services for use within Convex action functions.
@@ -141,7 +135,7 @@ export type ActionCtx = GenericActionCtx<DataModel>;
141135
* document by its {@link Id}, or {@link DatabaseReader.query}, which starts
142136
* building a query.
143137
*/
144-
export type DatabaseReader = GenericDatabaseReaderWithTable<DataModel>;
138+
export type DatabaseReader = GenericDatabaseReader<DataModel>;
145139

146140
/**
147141
* An interface to read from and write to the database within Convex mutation
@@ -152,7 +146,7 @@ export type DatabaseReader = GenericDatabaseReaderWithTable<DataModel>;
152146
* your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
153147
* for the guarantees Convex provides your functions.
154148
*/
155-
export type DatabaseWriter = GenericDatabaseWriterWithTable<DataModel>;
149+
export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
156150

157151
export declare const app: {
158152
errors: {

npm-packages/component-tests/projects/with-schema/convex/_generated/server.d.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
import {
1313
ActionBuilder,
1414
HttpActionBuilder,
15-
MutationBuilderWithTable,
16-
QueryBuilderWithTable,
15+
MutationBuilder,
16+
QueryBuilder,
1717
GenericActionCtx,
18-
GenericMutationCtxWithTable,
19-
GenericQueryCtxWithTable,
20-
GenericDatabaseReaderWithTable,
21-
GenericDatabaseWriterWithTable,
18+
GenericMutationCtx,
19+
GenericQueryCtx,
20+
GenericDatabaseReader,
21+
GenericDatabaseWriter,
2222
FunctionReference,
2323
} from "convex/server";
2424
import type { DataModel } from "./dataModel.js";
@@ -36,7 +36,7 @@ type GenericCtx =
3636
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
3737
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
3838
*/
39-
export declare const query: QueryBuilderWithTable<DataModel, "public">;
39+
export declare const query: QueryBuilder<DataModel, "public">;
4040

4141
/**
4242
* Define a query that is only accessible from other Convex functions (but not from the client).
@@ -46,10 +46,7 @@ export declare const query: QueryBuilderWithTable<DataModel, "public">;
4646
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
4747
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
4848
*/
49-
export declare const internalQuery: QueryBuilderWithTable<
50-
DataModel,
51-
"internal"
52-
>;
49+
export declare const internalQuery: QueryBuilder<DataModel, "internal">;
5350

5451
/**
5552
* Define a mutation in this Convex app's public API.
@@ -59,7 +56,7 @@ export declare const internalQuery: QueryBuilderWithTable<
5956
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
6057
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
6158
*/
62-
export declare const mutation: MutationBuilderWithTable<DataModel, "public">;
59+
export declare const mutation: MutationBuilder<DataModel, "public">;
6360

6461
/**
6562
* Define a mutation that is only accessible from other Convex functions (but not from the client).
@@ -69,10 +66,7 @@ export declare const mutation: MutationBuilderWithTable<DataModel, "public">;
6966
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
7067
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
7168
*/
72-
export declare const internalMutation: MutationBuilderWithTable<
73-
DataModel,
74-
"internal"
75-
>;
69+
export declare const internalMutation: MutationBuilder<DataModel, "internal">;
7670

7771
/**
7872
* Define an action in this Convex app's public API.
@@ -116,15 +110,15 @@ export declare const httpAction: HttpActionBuilder;
116110
* This differs from the {@link MutationCtx} because all of the services are
117111
* read-only.
118112
*/
119-
export type QueryCtx = GenericQueryCtxWithTable<DataModel>;
113+
export type QueryCtx = GenericQueryCtx<DataModel>;
120114

121115
/**
122116
* A set of services for use within Convex mutation functions.
123117
*
124118
* The mutation context is passed as the first argument to any Convex mutation
125119
* function run on the server.
126120
*/
127-
export type MutationCtx = GenericMutationCtxWithTable<DataModel>;
121+
export type MutationCtx = GenericMutationCtx<DataModel>;
128122

129123
/**
130124
* A set of services for use within Convex action functions.
@@ -141,7 +135,7 @@ export type ActionCtx = GenericActionCtx<DataModel>;
141135
* document by its {@link Id}, or {@link DatabaseReader.query}, which starts
142136
* building a query.
143137
*/
144-
export type DatabaseReader = GenericDatabaseReaderWithTable<DataModel>;
138+
export type DatabaseReader = GenericDatabaseReader<DataModel>;
145139

146140
/**
147141
* An interface to read from and write to the database within Convex mutation
@@ -152,7 +146,7 @@ export type DatabaseReader = GenericDatabaseReaderWithTable<DataModel>;
152146
* your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
153147
* for the guarantees Convex provides your functions.
154148
*/
155-
export type DatabaseWriter = GenericDatabaseWriterWithTable<DataModel>;
149+
export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
156150

157151
export declare const app: {
158152
component: {

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,22 @@ export function componentServerJS(isRoot: boolean): string {
119119
return result;
120120
}
121121

122-
function componentServerDTSPrelude(): string {
122+
function componentServerDTSPrelude(isRoot: boolean): string {
123+
const withTable = isRoot ? "" : "WithTable";
123124
return `
124125
${header(
125126
"Generated utilities for implementing server-side Convex query and mutation functions.",
126127
)}
127128
import {
128129
ActionBuilder,
129130
HttpActionBuilder,
130-
MutationBuilderWithTable,
131-
QueryBuilderWithTable,
131+
MutationBuilder${withTable},
132+
QueryBuilder${withTable},
132133
GenericActionCtx,
133-
GenericMutationCtxWithTable,
134-
GenericQueryCtxWithTable,
135-
GenericDatabaseReaderWithTable,
136-
GenericDatabaseWriterWithTable,
134+
GenericMutationCtx${withTable},
135+
GenericQueryCtx${withTable},
136+
GenericDatabaseReader${withTable},
137+
GenericDatabaseWriter${withTable},
137138
FunctionReference,
138139
} from "convex/server";
139140
import type { DataModel } from "./dataModel.js";
@@ -148,7 +149,7 @@ function componentServerDTSPrelude(): string {
148149
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
149150
* @returns The wrapped query. Include this as an \`export\` to name it and make it accessible.
150151
*/
151-
export declare const query: QueryBuilderWithTable<DataModel, "public">;
152+
export declare const query: QueryBuilder${withTable}<DataModel, "public">;
152153
153154
/**
154155
* Define a query that is only accessible from other Convex functions (but not from the client).
@@ -158,7 +159,7 @@ function componentServerDTSPrelude(): string {
158159
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
159160
* @returns The wrapped query. Include this as an \`export\` to name it and make it accessible.
160161
*/
161-
export declare const internalQuery: QueryBuilderWithTable<DataModel, "internal">;
162+
export declare const internalQuery: QueryBuilder${withTable}<DataModel, "internal">;
162163
163164
/**
164165
* Define a mutation in this Convex app's public API.
@@ -168,7 +169,7 @@ function componentServerDTSPrelude(): string {
168169
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
169170
* @returns The wrapped mutation. Include this as an \`export\` to name it and make it accessible.
170171
*/
171-
export declare const mutation: MutationBuilderWithTable<DataModel, "public">;
172+
export declare const mutation: MutationBuilder${withTable}<DataModel, "public">;
172173
173174
/**
174175
* Define a mutation that is only accessible from other Convex functions (but not from the client).
@@ -178,7 +179,7 @@ function componentServerDTSPrelude(): string {
178179
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
179180
* @returns The wrapped mutation. Include this as an \`export\` to name it and make it accessible.
180181
*/
181-
export declare const internalMutation: MutationBuilderWithTable<DataModel, "internal">;
182+
export declare const internalMutation: MutationBuilder${withTable}<DataModel, "internal">;
182183
183184
/**
184185
* Define an action in this Convex app's public API.
@@ -222,15 +223,15 @@ function componentServerDTSPrelude(): string {
222223
* This differs from the {@link MutationCtx} because all of the services are
223224
* read-only.
224225
*/
225-
export type QueryCtx = GenericQueryCtxWithTable<DataModel>;
226+
export type QueryCtx = GenericQueryCtx${withTable}<DataModel>;
226227
227228
/**
228229
* A set of services for use within Convex mutation functions.
229230
*
230231
* The mutation context is passed as the first argument to any Convex mutation
231232
* function run on the server.
232233
*/
233-
export type MutationCtx = GenericMutationCtxWithTable<DataModel>;
234+
export type MutationCtx = GenericMutationCtx${withTable}<DataModel>;
234235
235236
/**
236237
* A set of services for use within Convex action functions.
@@ -247,7 +248,7 @@ function componentServerDTSPrelude(): string {
247248
* document by its {@link Id}, or {@link DatabaseReader.query}, which starts
248249
* building a query.
249250
*/
250-
export type DatabaseReader = GenericDatabaseReaderWithTable<DataModel>;
251+
export type DatabaseReader = GenericDatabaseReader${withTable}<DataModel>;
251252
252253
/**
253254
* An interface to read from and write to the database within Convex mutation
@@ -258,12 +259,12 @@ function componentServerDTSPrelude(): string {
258259
* your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
259260
* for the guarantees Convex provides your functions.
260261
*/
261-
export type DatabaseWriter = GenericDatabaseWriterWithTable<DataModel>;
262+
export type DatabaseWriter = GenericDatabaseWriter${withTable}<DataModel>;
262263
`;
263264
}
264265

265266
export function componentServerStubDTS(isRoot: boolean): string {
266-
let result = componentServerDTSPrelude();
267+
let result = componentServerDTSPrelude(isRoot);
267268
if (isRoot) {
268269
result += `
269270
export declare const app: AnyApp;
@@ -283,7 +284,7 @@ export async function componentServerDTS(
283284
rootComponent: ComponentDirectory,
284285
componentDirectory: ComponentDirectory,
285286
): Promise<string> {
286-
const result = [componentServerDTSPrelude()];
287+
const result = [componentServerDTSPrelude(componentDirectory.isRoot)];
287288

288289
const identifier = componentDirectory.isRoot ? "app" : "component";
289290
result.push(`export declare const ${identifier}: {`);

0 commit comments

Comments
 (0)