Skip to content

Commit a59c0c3

Browse files
thomasballingerConvex, Inc.
authored and
Convex, Inc.
committed
Make component types resistant to multiple convex packages (#29972)
Modify component types to allow multiple copies of the convex library to typecheck against each other. GitOrigin-RevId: 0577742902edefeebd634aa03a5355e4a90b5dc1
1 parent 64fe5c0 commit a59c0c3

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

npm-packages/convex/.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ build.cjs
2828
tmpPackage*
2929
tmpDist*
3030
api-extractor-configs/temp/
31-
*.log
31+
*.log

npm-packages/convex/src/server/components/index.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
ComponentDefinitionAnalysis,
1313
ComponentDefinitionType,
1414
} from "./definition.js";
15-
import { toReferencePath } from "./paths.js";
15+
import { setReferencePath, toReferencePath } from "./paths.js";
1616

1717
/**
1818
* A serializable reference to a Convex function.
@@ -158,15 +158,10 @@ class InstalledComponent<Definition extends ComponentDefinition<any>> {
158158
*/
159159
_name: string;
160160

161-
/**
162-
* @internal
163-
*/
164-
[toReferencePath]: string;
165-
166161
constructor(definition: Definition, name: string) {
167162
this._definition = definition;
168163
this._name = name;
169-
this[toReferencePath] = `_reference/childComponent/${name}`;
164+
setReferencePath(this, `_reference/childComponent/${name}`);
170165
}
171166

172167
get exports(): ComponentDefinitionExports<Definition> {

npm-packages/convex/src/server/components/paths.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
export const toReferencePath = Symbol.for("toReferencePath");
22

3+
// Multiple instances of the same Symbol.for() are equal at runtime but not
4+
// at type-time, so `[toReferencePath]` properties aren't used in types.
5+
// Use this function to set the property invisibly.
6+
export function setReferencePath<T>(obj: T, value: string) {
7+
(obj as any)[toReferencePath] = value;
8+
}
9+
310
export function extractReferencePath(reference: any): string | null {
411
return reference[toReferencePath] ?? null;
512
}

npm-packages/convex/src/server/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export type RouteSpec = RouteSpecWithPath | RouteSpecWithPathPrefix;
142142
export class HttpRouter {
143143
exactRoutes: Map<string, Map<RoutableMethod, PublicHttpAction>> = new Map();
144144
prefixRoutes: Map<RoutableMethod, Map<string, PublicHttpAction>> = new Map();
145-
isRouter = true;
145+
isRouter: true = true;
146146

147147
/**
148148
* Specify an HttpAction to be used to respond to requests

0 commit comments

Comments
 (0)