Skip to content

Commit d0be520

Browse files
ldanilekConvex, Inc.
authored and
Convex, Inc.
committed
fix npx convex run --watch --component-path and make schemas reactive (#29494)
fix the CLI so it passes through component path when you do `npx convex run --watch`. and on schema failures we can rebuild when the data changes in the component whose schema failed. also there was a bug: when the websocket starts up after creating a query, which happens occasionally in the dashboard and happens every time when the CLI calls `subscribe`, we weren't passing the component path the second time. GitOrigin-RevId: ee29a46f68ca5726051686636faf1ddb434036c0
1 parent b7d6c25 commit d0be520

File tree

9 files changed

+43
-7
lines changed

9 files changed

+43
-7
lines changed

npm-packages/convex/src/browser/sync/local_state.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type LocalQuery = {
2424
args: Record<string, Value>;
2525
numSubscribers: number;
2626
journal?: QueryJournal;
27+
componentPath?: string;
2728
};
2829

2930
export class LocalSyncState {
@@ -95,6 +96,7 @@ export class LocalSyncState {
9596
args,
9697
numSubscribers: 1,
9798
journal,
99+
componentPath,
98100
};
99101
this.querySet.set(queryToken, query);
100102
this.queryIdToToken.set(queryId, queryToken);
@@ -279,6 +281,7 @@ export class LocalSyncState {
279281
udfPath: localQuery.canonicalizedUdfPath,
280282
args: [convexToJson(localQuery.args)],
281283
journal: localQuery.journal,
284+
componentPath: localQuery.componentPath,
282285
};
283286
modifications.push(add);
284287

npm-packages/convex/src/bundler/context.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export type ErrorType =
1616
// The `convex dev` command will wait for either file OR table data change
1717
// to retry (if a table name is specified as the value in this Object).
1818
| {
19-
"invalid filesystem or db data": string | null;
19+
"invalid filesystem or db data": {
20+
tableName: string;
21+
componentPath?: string;
22+
} | null;
2023
}
2124
// The error was caused by either the local state (ie schema.ts content)
2225
// or the state of the deployment environment variables.

npm-packages/convex/src/cli/convexExport.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ async function waitForStableExportState(
145145
adminKey,
146146
"_system/cli/exports:getLatest",
147147
{},
148+
undefined,
148149
donePromise,
149150
{
150151
onChange: (value: any) => {

npm-packages/convex/src/cli/convexImport.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ export async function waitForStableImportState(
363363
adminKey,
364364
"_system/cli/queryImport",
365365
{ importId },
366+
undefined,
366367
donePromise,
367368
{
368369
onChange: (value: any) => {

npm-packages/convex/src/cli/dev.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,12 @@ export async function watchAndPush(
306306
return;
307307
}
308308
const fileSystemWatch = getFileSystemWatch(ctx, watch, cmdOptions);
309-
const tableWatch = getTableWatch(ctx, options, tableNameTriggeringRetry);
309+
const tableWatch = getTableWatch(
310+
ctx,
311+
options,
312+
tableNameTriggeringRetry?.tableName ?? null,
313+
tableNameTriggeringRetry?.componentPath,
314+
);
310315
const envVarWatch = getDeplymentEnvVarWatch(
311316
ctx,
312317
options,
@@ -330,9 +335,14 @@ function getTableWatch(
330335
adminKey: string;
331336
},
332337
tableName: string | null,
338+
componentPath: string | undefined,
333339
) {
334-
return getFunctionWatch(ctx, credentials, "_system/cli/queryTable", () =>
335-
tableName !== null ? { tableName } : null,
340+
return getFunctionWatch(
341+
ctx,
342+
credentials,
343+
"_system/cli/queryTable",
344+
() => (tableName !== null ? { tableName } : null),
345+
componentPath,
336346
);
337347
}
338348

@@ -349,6 +359,7 @@ function getDeplymentEnvVarWatch(
349359
credentials,
350360
"_system/cli/queryEnvironmentVariables",
351361
() => (shouldRetryOnDeploymentEnvVarChange ? {} : null),
362+
undefined,
352363
);
353364
}
354365

@@ -360,6 +371,7 @@ function getFunctionWatch(
360371
},
361372
functionName: string,
362373
getArgs: () => Record<string, Value> | null,
374+
componentPath: string | undefined,
363375
) {
364376
const [stopPromise, stop] = waitUntilCalled();
365377
return {
@@ -375,6 +387,7 @@ function getFunctionWatch(
375387
credentials.adminKey,
376388
functionName,
377389
args,
390+
componentPath,
378391
stopPromise,
379392
{
380393
onChange: () => {

npm-packages/convex/src/cli/lib/deploy2.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,12 @@ export async function waitForSchema(
154154
return await ctx.crash({
155155
exitCode: 1,
156156
errorType: {
157-
"invalid filesystem or db data": currentStatus.tableName ?? null,
157+
"invalid filesystem or db data": currentStatus.tableName
158+
? {
159+
tableName: currentStatus.tableName,
160+
componentPath: currentStatus.componentPath,
161+
}
162+
: null,
158163
},
159164
printedMessage: null, // TODO - move logging into here
160165
});

npm-packages/convex/src/cli/lib/indexes.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ async function waitForReadySchema(
133133
return await ctx.crash({
134134
exitCode: 1,
135135
errorType: {
136-
"invalid filesystem or db data": data.schemaState.tableName ?? null,
136+
"invalid filesystem or db data": data.schemaState.tableName
137+
? {
138+
tableName: data.schemaState.tableName,
139+
}
140+
: null,
137141
},
138142
printedMessage: null, // TODO - move logging into here
139143
});

npm-packages/convex/src/cli/lib/run.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ export async function subscribeAndLog(
125125
adminKey: string,
126126
functionName: string,
127127
args: Record<string, Value>,
128+
componentPath: string | undefined,
128129
) {
129130
return subscribe(
130131
ctx,
131132
deploymentUrl,
132133
adminKey,
133134
functionName,
134135
args,
136+
componentPath,
135137
waitForever(),
136138
{
137139
onStart() {
@@ -156,6 +158,7 @@ export async function subscribe(
156158
adminKey: string,
157159
functionName: string,
158160
args: Record<string, Value>,
161+
componentPath: string | undefined,
159162
until: Promise<unknown>,
160163
callbacks?: {
161164
onStart?: () => void;
@@ -177,7 +180,9 @@ export async function subscribe(
177180
},
178181
);
179182
client.setAdminAuth(adminKey);
180-
const { unsubscribe } = client.subscribe(functionName, args);
183+
const { unsubscribe } = client.subscribe(functionName, args, {
184+
componentPath,
185+
});
181186

182187
callbacks?.onStart?.();
183188

npm-packages/convex/src/cli/run.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export const run = new Command("run")
103103
adminKey,
104104
functionName,
105105
args,
106+
options.componentPath,
106107
);
107108
}
108109
return await runFunctionAndLog(

0 commit comments

Comments
 (0)