Skip to content

Commit

Permalink
remove dead isRegistered check on UDFs (#31729)
Browse files Browse the repository at this point in the history
this code is effectively

```ts
const func = ((arg) => handler(arg));
if (func.isRegistered) { // condition is always false
  throw new Error()
}
func.isRegistered = true; // field is never read
```

GitOrigin-RevId: 7549a97d05be8d7eb84b858ab7f26699b1c49483
  • Loading branch information
ldanilek authored and Convex, Inc. committed Nov 22, 2024
1 parent 6f07478 commit 922daec
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 39 deletions.
35 changes: 0 additions & 35 deletions npm-packages/convex/src/server/impl/registration_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,7 @@ export const mutationGeneric: MutationBuilder<any, "public"> = ((
const func = ((ctx: any, args: any) =>
handler(ctx, args)) as RegisteredMutation<"public", any, any>;

// Helpful runtime check that functions are only be registered once
if (func.isRegistered) {
throw new Error("Function registered twice " + func);
}
assertNotBrowser();
func.isRegistered = true;
func.isMutation = true;
func.isPublic = true;
func.invokeMutation = (argsStr) => invokeMutation(func, argsStr);
Expand Down Expand Up @@ -221,12 +216,7 @@ export const internalMutationGeneric: MutationBuilder<any, "internal"> = ((
const func = ((ctx: any, args: any) =>
handler(ctx, args)) as RegisteredMutation<"internal", any, any>;

// Helpful runtime check that functions are only be registered once
if (func.isRegistered) {
throw new Error("Function registered twice " + func);
}
assertNotBrowser();
func.isRegistered = true;
func.isMutation = true;
func.isInternal = true;
func.invokeMutation = (argsStr) => invokeMutation(func, argsStr);
Expand Down Expand Up @@ -281,12 +271,7 @@ export const queryGeneric: QueryBuilder<any, "public"> = ((
any
>;

// Helpful runtime check that functions are only be registered once
if (func.isRegistered) {
throw new Error("Function registered twice " + func);
}
assertNotBrowser();
func.isRegistered = true;
func.isQuery = true;
func.isPublic = true;
func.invokeQuery = (argsStr) => invokeQuery(func, argsStr);
Expand Down Expand Up @@ -323,12 +308,7 @@ export const internalQueryGeneric: QueryBuilder<any, "internal"> = ((
any
>;

// Helpful runtime check that functions are only be registered once
if (func.isRegistered) {
throw new Error("Function registered twice " + func);
}
assertNotBrowser();
func.isRegistered = true;
func.isQuery = true;
func.isInternal = true;
func.invokeQuery = (argsStr) => invokeQuery(func as any, argsStr);
Expand Down Expand Up @@ -376,12 +356,7 @@ export const actionGeneric: ActionBuilder<any, "public"> = ((
const func = ((ctx: any, args: any) =>
handler(ctx, args)) as RegisteredAction<"public", any, any>;

// Helpful runtime check that functions are only be registered once
if (func.isRegistered) {
throw new Error("Function registered twice " + func);
}
assertNotBrowser();
func.isRegistered = true;
func.isAction = true;
func.isPublic = true;
func.invokeAction = (requestId, argsStr) =>
Expand Down Expand Up @@ -414,12 +389,7 @@ export const internalActionGeneric: ActionBuilder<any, "internal"> = ((
const func = ((ctx: any, args: any) =>
handler(ctx, args)) as RegisteredAction<"internal", any, any>;

// Helpful runtime check that functions are only be registered once
if (func.isRegistered) {
throw new Error("Function registered twice " + func);
}
assertNotBrowser();
func.isRegistered = true;
func.isAction = true;
func.isInternal = true;
func.invokeAction = (requestId, argsStr) =>
Expand Down Expand Up @@ -465,12 +435,7 @@ export const httpActionGeneric = (
const handler = func as unknown as PublicHttpAction;
const q = ((ctx: any, request: any) =>
handler(ctx, request)) as PublicHttpAction;
// Helpful runtime check that functions are only be registered once
if (q.isRegistered) {
throw new Error("Function registered twice " + func);
}
assertNotBrowser();
q.isRegistered = true;
q.isHttp = true;
q.invokeHttpAction = (request) => invokeHttpAction(func as any, request);
q._handler = func;
Expand Down
4 changes: 0 additions & 4 deletions npm-packages/convex/src/server/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ export type RegisteredMutation<

isConvexFunction: true;
isMutation: true;
isRegistered?: true;

/** @internal */
invokeMutation(argsStr: string): Promise<string>;
Expand Down Expand Up @@ -385,7 +384,6 @@ export type RegisteredQuery<

isConvexFunction: true;
isQuery: true;
isRegistered?: true;

/** @internal */
invokeQuery(argsStr: string): Promise<string>;
Expand Down Expand Up @@ -417,7 +415,6 @@ export type RegisteredAction<

isConvexFunction: true;
isAction: true;
isRegistered?: true;

/** @internal */
invokeAction(requestId: string, argsStr: string): Promise<string>;
Expand All @@ -443,7 +440,6 @@ export type RegisteredAction<
export type PublicHttpAction = {
(ctx: GenericActionCtx<any>, request: Request): Promise<Response>;
isHttp: true;
isRegistered?: true;

/** @internal */
invokeHttpAction(request: Request): Promise<Response>;
Expand Down

0 comments on commit 922daec

Please sign in to comment.