convex 1.42.2-alpha.0 → 1.42.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/browser.bundle.js +1 -1
- package/dist/browser.bundle.js.map +2 -2
- package/dist/cjs/browser/index.js.map +2 -2
- package/dist/cjs/browser/sync/client.js.map +1 -1
- package/dist/cjs/browser/sync/paginated_query_client.js.map +2 -2
- package/dist/cjs/cli/codegen_templates/common.js +6 -0
- package/dist/cjs/cli/codegen_templates/common.js.map +2 -2
- package/dist/cjs/cli/codegen_templates/component_api.js +2 -2
- package/dist/cjs/cli/codegen_templates/component_api.js.map +2 -2
- package/dist/cjs/cli/lib/codegen.js +2 -1
- package/dist/cjs/cli/lib/codegen.js.map +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react/client.js.map +2 -2
- package/dist/cjs/server/meta.js.map +1 -1
- package/dist/cjs-types/browser/index.d.ts.map +1 -1
- package/dist/cjs-types/browser/sync/paginated_query_client.d.ts +1 -38
- package/dist/cjs-types/browser/sync/paginated_query_client.d.ts.map +1 -1
- package/dist/cjs-types/cli/codegen_templates/common.d.ts +12 -0
- package/dist/cjs-types/cli/codegen_templates/common.d.ts.map +1 -1
- package/dist/cjs-types/cli/codegen_templates/common.test.d.ts +2 -0
- package/dist/cjs-types/cli/codegen_templates/common.test.d.ts.map +1 -0
- package/dist/cjs-types/cli/codegen_templates/component_api.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/codegen.d.ts.map +1 -1
- package/dist/cjs-types/index.d.ts +1 -1
- package/dist/cjs-types/index.d.ts.map +1 -1
- package/dist/cjs-types/react/client.d.ts.map +1 -1
- package/dist/cjs-types/server/meta.d.ts +10 -2
- package/dist/cjs-types/server/meta.d.ts.map +1 -1
- package/dist/cli.bundle.cjs +9 -4
- package/dist/cli.bundle.cjs.map +2 -2
- package/dist/esm/browser/index.js.map +2 -2
- package/dist/esm/browser/sync/client.js.map +1 -1
- package/dist/esm/browser/sync/paginated_query_client.js.map +2 -2
- package/dist/esm/cli/codegen_templates/common.js +5 -0
- package/dist/esm/cli/codegen_templates/common.js.map +2 -2
- package/dist/esm/cli/codegen_templates/component_api.js +8 -3
- package/dist/esm/cli/codegen_templates/component_api.js.map +2 -2
- package/dist/esm/cli/lib/codegen.js +2 -1
- package/dist/esm/cli/lib/codegen.js.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/react/client.js.map +2 -2
- package/dist/esm-types/browser/index.d.ts.map +1 -1
- package/dist/esm-types/browser/sync/paginated_query_client.d.ts +1 -38
- package/dist/esm-types/browser/sync/paginated_query_client.d.ts.map +1 -1
- package/dist/esm-types/cli/codegen_templates/common.d.ts +12 -0
- package/dist/esm-types/cli/codegen_templates/common.d.ts.map +1 -1
- package/dist/esm-types/cli/codegen_templates/common.test.d.ts +2 -0
- package/dist/esm-types/cli/codegen_templates/common.test.d.ts.map +1 -0
- package/dist/esm-types/cli/codegen_templates/component_api.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/codegen.d.ts.map +1 -1
- package/dist/esm-types/index.d.ts +1 -1
- package/dist/esm-types/index.d.ts.map +1 -1
- package/dist/esm-types/react/client.d.ts.map +1 -1
- package/dist/esm-types/server/meta.d.ts +10 -2
- package/dist/esm-types/server/meta.d.ts.map +1 -1
- package/dist/react.bundle.js +1 -1
- package/dist/react.bundle.js.map +2 -2
- package/package.json +1 -1
- package/src/browser/index.ts +2 -0
- package/src/browser/sync/client.test.ts +8 -1
- package/src/browser/sync/client.ts +63 -0
- package/src/browser/sync/paginated_query_client.ts +3 -2
- package/src/cli/codegen_templates/common.test.ts +52 -0
- package/src/cli/codegen_templates/common.ts +17 -0
- package/src/cli/codegen_templates/component_api.ts +8 -3
- package/src/cli/lib/codegen.ts +2 -1
- package/src/index.ts +1 -1
- package/src/react/ConvexAuthState.test.tsx +24 -8
- package/src/react/auth_websocket.test.tsx +39 -29
- package/src/react/client.ts +3 -2
- package/src/react/client_provided_base_client.test.tsx +154 -36
- package/src/server/meta.ts +2 -4
|
@@ -4,53 +4,171 @@ import ws from "ws";
|
|
|
4
4
|
import { ConvexReactClient } from "./client.js";
|
|
5
5
|
import { anyApi } from "../server/api.js";
|
|
6
6
|
import { BaseConvexClient } from "../browser/index.js";
|
|
7
|
+
import { BaseConvexClientInterface } from "../browser/sync/client.js";
|
|
7
8
|
|
|
8
9
|
const address = "https://127.0.0.1:3001";
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
|
|
11
|
+
describe("Creating a ConvexReactClient with a custom base client", () => {
|
|
12
|
+
describe("with a `BaseConvexClient` subclass", () => {
|
|
13
|
+
// A minimal subclass of `BaseConvexClient` used to prove that a
|
|
14
|
+
// caller-provided `BaseConvexClient` (of any subclass) can be plugged into
|
|
15
|
+
// a `ConvexReactClient` via the `client` option.
|
|
16
|
+
class MinimalBaseConvexClient extends BaseConvexClient {}
|
|
14
17
|
|
|
15
|
-
const testBaseConvexClient = () =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
const testBaseConvexClient = () =>
|
|
19
|
+
new MinimalBaseConvexClient(address, () => {}, {
|
|
20
|
+
webSocketConstructor: ws as unknown as typeof WebSocket,
|
|
21
|
+
});
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
test("uses the provided client as its `sync` client", () => {
|
|
24
|
+
const baseClient = testBaseConvexClient();
|
|
25
|
+
const client = new ConvexReactClient(address, { baseClient });
|
|
26
|
+
expect(client.sync).toBe(baseClient);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("applies setAdminAuth called before the client is lazily instantiated", () => {
|
|
30
|
+
const baseClient = testBaseConvexClient();
|
|
31
|
+
const setAdminAuthSpy = vi.spyOn(baseClient, "setAdminAuth");
|
|
32
|
+
const client = new ConvexReactClient(address, { baseClient });
|
|
33
|
+
client.setAdminAuth("admin-token");
|
|
34
|
+
expect(setAdminAuthSpy).not.toHaveBeenCalled();
|
|
35
|
+
|
|
36
|
+
// Accessing `sync` lazily instantiates the client, applying admin auth.
|
|
37
|
+
expect(client.sync).toBe(baseClient);
|
|
38
|
+
expect(setAdminAuthSpy).toHaveBeenCalledWith("admin-token", undefined);
|
|
39
|
+
});
|
|
26
40
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const client = new ConvexReactClient(address, { baseClient });
|
|
31
|
-
client.setAdminAuth("admin-token");
|
|
32
|
-
expect(setAdminAuthSpy).not.toHaveBeenCalled();
|
|
41
|
+
test("queries and mutations work through the provided client", async () => {
|
|
42
|
+
const baseClient = testBaseConvexClient();
|
|
43
|
+
const client = new ConvexReactClient(address, { baseClient });
|
|
33
44
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
45
|
+
void client.mutation(
|
|
46
|
+
anyApi.myMutation.default,
|
|
47
|
+
{},
|
|
48
|
+
{
|
|
49
|
+
optimisticUpdate: (localStore) => {
|
|
50
|
+
localStore.setQuery(anyApi.myQuery.default, {}, "queryResult");
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const queryResult = client.query(anyApi.myQuery.default, {});
|
|
56
|
+
expect(await queryResult).toStrictEqual("queryResult");
|
|
57
|
+
});
|
|
37
58
|
});
|
|
38
59
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
60
|
+
describe("with a from-scratch BaseConvexClientInterface implementation", () => {
|
|
61
|
+
// A from-scratch (non-subclass) implementation of `BaseConvexClientInterface`.
|
|
62
|
+
// Unlike `MinimalBaseConvexClient` above, this does not extend
|
|
63
|
+
// `BaseConvexClient`, so TypeScript forces every public member to be
|
|
64
|
+
// declared here explicitly — if `BaseConvexClientInterface` ever gains a member,
|
|
65
|
+
// this class fails to compile until a matching forwarding method is added.
|
|
66
|
+
class ComposedBaseConvexClient implements BaseConvexClientInterface {
|
|
67
|
+
private inner: BaseConvexClient;
|
|
68
|
+
|
|
69
|
+
constructor(...args: ConstructorParameters<typeof BaseConvexClient>) {
|
|
70
|
+
this.inner = new BaseConvexClient(...args);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
addOnTransitionHandler(
|
|
74
|
+
...args: Parameters<BaseConvexClient["addOnTransitionHandler"]>
|
|
75
|
+
) {
|
|
76
|
+
return this.inner.addOnTransitionHandler(...args);
|
|
77
|
+
}
|
|
78
|
+
setAuth(...args: Parameters<BaseConvexClient["setAuth"]>) {
|
|
79
|
+
return this.inner.setAuth(...args);
|
|
80
|
+
}
|
|
81
|
+
setAdminAuth(...args: Parameters<BaseConvexClient["setAdminAuth"]>) {
|
|
82
|
+
return this.inner.setAdminAuth(...args);
|
|
83
|
+
}
|
|
84
|
+
clearAuth() {
|
|
85
|
+
return this.inner.clearAuth();
|
|
86
|
+
}
|
|
87
|
+
subscribe(...args: Parameters<BaseConvexClient["subscribe"]>) {
|
|
88
|
+
return this.inner.subscribe(...args);
|
|
89
|
+
}
|
|
90
|
+
localQueryResult(
|
|
91
|
+
...args: Parameters<BaseConvexClient["localQueryResult"]>
|
|
92
|
+
) {
|
|
93
|
+
return this.inner.localQueryResult(...args);
|
|
94
|
+
}
|
|
95
|
+
localQueryResultByToken(
|
|
96
|
+
...args: Parameters<BaseConvexClient["localQueryResultByToken"]>
|
|
97
|
+
) {
|
|
98
|
+
return this.inner.localQueryResultByToken(...args);
|
|
99
|
+
}
|
|
100
|
+
hasLocalQueryResultByToken(
|
|
101
|
+
...args: Parameters<BaseConvexClient["hasLocalQueryResultByToken"]>
|
|
102
|
+
) {
|
|
103
|
+
return this.inner.hasLocalQueryResultByToken(...args);
|
|
104
|
+
}
|
|
105
|
+
localQueryLogs(...args: Parameters<BaseConvexClient["localQueryLogs"]>) {
|
|
106
|
+
return this.inner.localQueryLogs(...args);
|
|
107
|
+
}
|
|
108
|
+
queryJournal(...args: Parameters<BaseConvexClient["queryJournal"]>) {
|
|
109
|
+
return this.inner.queryJournal(...args);
|
|
110
|
+
}
|
|
111
|
+
connectionState() {
|
|
112
|
+
return this.inner.connectionState();
|
|
113
|
+
}
|
|
114
|
+
subscribeToConnectionState(
|
|
115
|
+
...args: Parameters<BaseConvexClient["subscribeToConnectionState"]>
|
|
116
|
+
) {
|
|
117
|
+
return this.inner.subscribeToConnectionState(...args);
|
|
118
|
+
}
|
|
119
|
+
mutation(...args: Parameters<BaseConvexClient["mutation"]>) {
|
|
120
|
+
return this.inner.mutation(...args);
|
|
121
|
+
}
|
|
122
|
+
action(...args: Parameters<BaseConvexClient["action"]>) {
|
|
123
|
+
return this.inner.action(...args);
|
|
124
|
+
}
|
|
125
|
+
close() {
|
|
126
|
+
return this.inner.close();
|
|
127
|
+
}
|
|
128
|
+
get url() {
|
|
129
|
+
return this.inner.url;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const testBaseConvexClient = () =>
|
|
134
|
+
new ComposedBaseConvexClient(address, () => {}, {
|
|
135
|
+
webSocketConstructor: ws as unknown as typeof WebSocket,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("uses the provided client as its `sync` client", () => {
|
|
139
|
+
const baseClient = testBaseConvexClient();
|
|
140
|
+
const client = new ConvexReactClient(address, { baseClient });
|
|
141
|
+
expect(client.sync).toBe(baseClient);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("applies setAdminAuth called before the client is lazily instantiated", () => {
|
|
145
|
+
const baseClient = testBaseConvexClient();
|
|
146
|
+
const setAdminAuthSpy = vi.spyOn(baseClient, "setAdminAuth");
|
|
147
|
+
const client = new ConvexReactClient(address, { baseClient });
|
|
148
|
+
client.setAdminAuth("admin-token");
|
|
149
|
+
expect(setAdminAuthSpy).not.toHaveBeenCalled();
|
|
150
|
+
|
|
151
|
+
// Accessing `sync` lazily instantiates the client, applying admin auth.
|
|
152
|
+
expect(client.sync).toBe(baseClient);
|
|
153
|
+
expect(setAdminAuthSpy).toHaveBeenCalledWith("admin-token", undefined);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("queries and mutations work through the provided client", async () => {
|
|
157
|
+
const baseClient = testBaseConvexClient();
|
|
158
|
+
const client = new ConvexReactClient(address, { baseClient });
|
|
42
159
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
160
|
+
void client.mutation(
|
|
161
|
+
anyApi.myMutation.default,
|
|
162
|
+
{},
|
|
163
|
+
{
|
|
164
|
+
optimisticUpdate: (localStore) => {
|
|
165
|
+
localStore.setQuery(anyApi.myQuery.default, {}, "queryResult");
|
|
166
|
+
},
|
|
49
167
|
},
|
|
50
|
-
|
|
51
|
-
);
|
|
168
|
+
);
|
|
52
169
|
|
|
53
|
-
|
|
54
|
-
|
|
170
|
+
const queryResult = client.query(anyApi.myQuery.default, {});
|
|
171
|
+
expect(await queryResult).toStrictEqual("queryResult");
|
|
172
|
+
});
|
|
55
173
|
});
|
|
56
174
|
});
|
package/src/server/meta.ts
CHANGED
|
@@ -84,9 +84,9 @@ export type DeploymentMetadata = {
|
|
|
84
84
|
*/
|
|
85
85
|
region: string | null;
|
|
86
86
|
/**
|
|
87
|
-
* The deployment class, e.g. `"s16"`, `"s256"`, or `"
|
|
87
|
+
* The deployment class, e.g. `"s16"`, `"s256"`, `"d1024"`, or `"d2048"`.
|
|
88
88
|
*/
|
|
89
|
-
class: "s16" | "s256" | "d1024";
|
|
89
|
+
class: "s16" | "s256" | "d1024" | "d2048";
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
/**
|
|
@@ -120,8 +120,6 @@ export type RequestMetadata = {
|
|
|
120
120
|
*
|
|
121
121
|
* This is the same token that `ctx.auth.getUserIdentity()` derives its
|
|
122
122
|
* attributes from.
|
|
123
|
-
*
|
|
124
|
-
* @internal
|
|
125
123
|
*/
|
|
126
124
|
authToken: string | null;
|
|
127
125
|
};
|