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.
Files changed (75) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/browser.bundle.js +1 -1
  3. package/dist/browser.bundle.js.map +2 -2
  4. package/dist/cjs/browser/index.js.map +2 -2
  5. package/dist/cjs/browser/sync/client.js.map +1 -1
  6. package/dist/cjs/browser/sync/paginated_query_client.js.map +2 -2
  7. package/dist/cjs/cli/codegen_templates/common.js +6 -0
  8. package/dist/cjs/cli/codegen_templates/common.js.map +2 -2
  9. package/dist/cjs/cli/codegen_templates/component_api.js +2 -2
  10. package/dist/cjs/cli/codegen_templates/component_api.js.map +2 -2
  11. package/dist/cjs/cli/lib/codegen.js +2 -1
  12. package/dist/cjs/cli/lib/codegen.js.map +2 -2
  13. package/dist/cjs/index.js +1 -1
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/react/client.js.map +2 -2
  16. package/dist/cjs/server/meta.js.map +1 -1
  17. package/dist/cjs-types/browser/index.d.ts.map +1 -1
  18. package/dist/cjs-types/browser/sync/paginated_query_client.d.ts +1 -38
  19. package/dist/cjs-types/browser/sync/paginated_query_client.d.ts.map +1 -1
  20. package/dist/cjs-types/cli/codegen_templates/common.d.ts +12 -0
  21. package/dist/cjs-types/cli/codegen_templates/common.d.ts.map +1 -1
  22. package/dist/cjs-types/cli/codegen_templates/common.test.d.ts +2 -0
  23. package/dist/cjs-types/cli/codegen_templates/common.test.d.ts.map +1 -0
  24. package/dist/cjs-types/cli/codegen_templates/component_api.d.ts.map +1 -1
  25. package/dist/cjs-types/cli/lib/codegen.d.ts.map +1 -1
  26. package/dist/cjs-types/index.d.ts +1 -1
  27. package/dist/cjs-types/index.d.ts.map +1 -1
  28. package/dist/cjs-types/react/client.d.ts.map +1 -1
  29. package/dist/cjs-types/server/meta.d.ts +10 -2
  30. package/dist/cjs-types/server/meta.d.ts.map +1 -1
  31. package/dist/cli.bundle.cjs +9 -4
  32. package/dist/cli.bundle.cjs.map +2 -2
  33. package/dist/esm/browser/index.js.map +2 -2
  34. package/dist/esm/browser/sync/client.js.map +1 -1
  35. package/dist/esm/browser/sync/paginated_query_client.js.map +2 -2
  36. package/dist/esm/cli/codegen_templates/common.js +5 -0
  37. package/dist/esm/cli/codegen_templates/common.js.map +2 -2
  38. package/dist/esm/cli/codegen_templates/component_api.js +8 -3
  39. package/dist/esm/cli/codegen_templates/component_api.js.map +2 -2
  40. package/dist/esm/cli/lib/codegen.js +2 -1
  41. package/dist/esm/cli/lib/codegen.js.map +2 -2
  42. package/dist/esm/index.js +1 -1
  43. package/dist/esm/index.js.map +1 -1
  44. package/dist/esm/react/client.js.map +2 -2
  45. package/dist/esm-types/browser/index.d.ts.map +1 -1
  46. package/dist/esm-types/browser/sync/paginated_query_client.d.ts +1 -38
  47. package/dist/esm-types/browser/sync/paginated_query_client.d.ts.map +1 -1
  48. package/dist/esm-types/cli/codegen_templates/common.d.ts +12 -0
  49. package/dist/esm-types/cli/codegen_templates/common.d.ts.map +1 -1
  50. package/dist/esm-types/cli/codegen_templates/common.test.d.ts +2 -0
  51. package/dist/esm-types/cli/codegen_templates/common.test.d.ts.map +1 -0
  52. package/dist/esm-types/cli/codegen_templates/component_api.d.ts.map +1 -1
  53. package/dist/esm-types/cli/lib/codegen.d.ts.map +1 -1
  54. package/dist/esm-types/index.d.ts +1 -1
  55. package/dist/esm-types/index.d.ts.map +1 -1
  56. package/dist/esm-types/react/client.d.ts.map +1 -1
  57. package/dist/esm-types/server/meta.d.ts +10 -2
  58. package/dist/esm-types/server/meta.d.ts.map +1 -1
  59. package/dist/react.bundle.js +1 -1
  60. package/dist/react.bundle.js.map +2 -2
  61. package/package.json +1 -1
  62. package/src/browser/index.ts +2 -0
  63. package/src/browser/sync/client.test.ts +8 -1
  64. package/src/browser/sync/client.ts +63 -0
  65. package/src/browser/sync/paginated_query_client.ts +3 -2
  66. package/src/cli/codegen_templates/common.test.ts +52 -0
  67. package/src/cli/codegen_templates/common.ts +17 -0
  68. package/src/cli/codegen_templates/component_api.ts +8 -3
  69. package/src/cli/lib/codegen.ts +2 -1
  70. package/src/index.ts +1 -1
  71. package/src/react/ConvexAuthState.test.tsx +24 -8
  72. package/src/react/auth_websocket.test.tsx +39 -29
  73. package/src/react/client.ts +3 -2
  74. package/src/react/client_provided_base_client.test.tsx +154 -36
  75. 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
- // A minimal subclass of `BaseConvexClient` used to prove that a
11
- // caller-provided `BaseConvexClient` (of any subclass) can be plugged into a
12
- // `ConvexReactClient` via the `client` option.
13
- class MinimalBaseConvexClient extends BaseConvexClient {}
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
- new MinimalBaseConvexClient(address, () => {}, {
17
- webSocketConstructor: ws as unknown as typeof WebSocket,
18
- });
18
+ const testBaseConvexClient = () =>
19
+ new MinimalBaseConvexClient(address, () => {}, {
20
+ webSocketConstructor: ws as unknown as typeof WebSocket,
21
+ });
19
22
 
20
- describe("ConvexReactClient with a provided BaseConvexClient", () => {
21
- test("uses the provided client as its `sync` client", () => {
22
- const baseClient = testBaseConvexClient();
23
- const client = new ConvexReactClient(address, { baseClient });
24
- expect(client.sync).toBe(baseClient);
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
- test("applies setAdminAuth called before the client is lazily instantiated", () => {
28
- const baseClient = testBaseConvexClient();
29
- const setAdminAuthSpy = vi.spyOn(baseClient, "setAdminAuth");
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
- // Accessing `sync` lazily instantiates the client, applying admin auth.
35
- expect(client.sync).toBe(baseClient);
36
- expect(setAdminAuthSpy).toHaveBeenCalledWith("admin-token", undefined);
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
- test("queries and mutations work through the provided client", async () => {
40
- const baseClient = testBaseConvexClient();
41
- const client = new ConvexReactClient(address, { baseClient });
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
- void client.mutation(
44
- anyApi.myMutation.default,
45
- {},
46
- {
47
- optimisticUpdate: (localStore) => {
48
- localStore.setQuery(anyApi.myQuery.default, {}, "queryResult");
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
- const queryResult = client.query(anyApi.myQuery.default, {});
54
- expect(await queryResult).toStrictEqual("queryResult");
170
+ const queryResult = client.query(anyApi.myQuery.default, {});
171
+ expect(await queryResult).toStrictEqual("queryResult");
172
+ });
55
173
  });
56
174
  });
@@ -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 `"d1024"`.
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
  };