@rebasepro/client 0.0.1-canary.bbcb8b4 → 0.0.1-canary.c53f5db
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/dist/collection.d.ts +2 -1
- package/dist/collection.test.d.ts +1 -0
- package/dist/index.es.js +16 -10
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +16 -10
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
- package/src/collection.test.ts +159 -0
- package/src/collection.ts +8 -0
- package/src/websocket.ts +10 -10
package/dist/collection.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Transport } from "./transport";
|
|
1
|
+
import { Transport, FindParams } from "./transport";
|
|
2
2
|
import { RebaseWebSocketClient } from "./websocket";
|
|
3
3
|
import { CollectionAccessor } from "@rebasepro/types";
|
|
4
4
|
import { FilterOperator, QueryBuilder } from "./query_builder";
|
|
@@ -15,5 +15,6 @@ export interface CollectionClient<M extends Record<string, unknown> = Record<str
|
|
|
15
15
|
offset(count: number): QueryBuilder<M>;
|
|
16
16
|
search(searchString: string): QueryBuilder<M>;
|
|
17
17
|
include(...relations: string[]): QueryBuilder<M>;
|
|
18
|
+
count(params?: FindParams): Promise<number>;
|
|
18
19
|
}
|
|
19
20
|
export declare function createCollectionClient<M extends Record<string, unknown> = Record<string, unknown>>(transport: Transport, slug: string, ws?: RebaseWebSocketClient): CollectionClient<M>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.es.js
CHANGED
|
@@ -1077,6 +1077,12 @@ function createCollectionClient(transport, slug, ws) {
|
|
|
1077
1077
|
method: "DELETE"
|
|
1078
1078
|
});
|
|
1079
1079
|
},
|
|
1080
|
+
async count(params) {
|
|
1081
|
+
const countParams = { ...params, limit: void 0, offset: void 0 };
|
|
1082
|
+
const qs = buildQueryString(countParams);
|
|
1083
|
+
const raw = await transport.request(basePath + "/count" + qs, { method: "GET" });
|
|
1084
|
+
return raw.count ?? 0;
|
|
1085
|
+
},
|
|
1080
1086
|
// Fluent builder instantiation
|
|
1081
1087
|
where(column, operator, value) {
|
|
1082
1088
|
return new QueryBuilder(client).where(column, operator, value);
|
|
@@ -1249,7 +1255,7 @@ class RebaseWebSocketClient {
|
|
|
1249
1255
|
setAuthTokenGetter(getAuthToken) {
|
|
1250
1256
|
this.getAuthToken = getAuthToken;
|
|
1251
1257
|
if (this.isConnected && !this.isAuthenticated && !this.authPromise) {
|
|
1252
|
-
console.
|
|
1258
|
+
console.debug("WebSocket auto-authenticating after token getter set");
|
|
1253
1259
|
this.getAuthToken().then((token) => {
|
|
1254
1260
|
if (!this.ws) return;
|
|
1255
1261
|
if (token) {
|
|
@@ -1285,7 +1291,7 @@ class RebaseWebSocketClient {
|
|
|
1285
1291
|
try {
|
|
1286
1292
|
this.ws = new this.WebSocketConstructor(this.websocketUrl);
|
|
1287
1293
|
this.ws.onopen = async () => {
|
|
1288
|
-
console.
|
|
1294
|
+
console.debug("Connected to PostgreSQL backend");
|
|
1289
1295
|
const wasReconnect = this.reconnectAttempts > 0;
|
|
1290
1296
|
this.isConnected = true;
|
|
1291
1297
|
this.reconnectAttempts = 0;
|
|
@@ -1294,7 +1300,7 @@ class RebaseWebSocketClient {
|
|
|
1294
1300
|
const token = await this.getAuthToken();
|
|
1295
1301
|
if (token) {
|
|
1296
1302
|
await this.authenticate(token);
|
|
1297
|
-
console.
|
|
1303
|
+
console.debug("WebSocket auto-authenticated");
|
|
1298
1304
|
}
|
|
1299
1305
|
} catch (error) {
|
|
1300
1306
|
console.warn("WebSocket auto-auth failed, requests may fail:", error);
|
|
@@ -1315,7 +1321,7 @@ class RebaseWebSocketClient {
|
|
|
1315
1321
|
}
|
|
1316
1322
|
};
|
|
1317
1323
|
this.ws.onclose = () => {
|
|
1318
|
-
console.
|
|
1324
|
+
console.debug("Disconnected from PostgreSQL backend");
|
|
1319
1325
|
this.isConnected = false;
|
|
1320
1326
|
this.isAuthenticated = false;
|
|
1321
1327
|
this.authPromise = null;
|
|
@@ -1357,7 +1363,7 @@ class RebaseWebSocketClient {
|
|
|
1357
1363
|
}
|
|
1358
1364
|
this.reconnectAttempts++;
|
|
1359
1365
|
const delay = Math.min(1e3 * Math.pow(2, this.reconnectAttempts), 3e4);
|
|
1360
|
-
console.
|
|
1366
|
+
console.debug(`Attempting to reconnect in ${delay}ms (attempt ${this.reconnectAttempts})`);
|
|
1361
1367
|
if (this.reconnectTimeout) {
|
|
1362
1368
|
clearTimeout(this.reconnectTimeout);
|
|
1363
1369
|
}
|
|
@@ -1527,7 +1533,7 @@ class RebaseWebSocketClient {
|
|
|
1527
1533
|
this.authPromise = this.authenticate(token);
|
|
1528
1534
|
await this.authPromise;
|
|
1529
1535
|
this.authPromise = null;
|
|
1530
|
-
console.
|
|
1536
|
+
console.debug("WebSocket authenticated on demand");
|
|
1531
1537
|
return;
|
|
1532
1538
|
} catch (error) {
|
|
1533
1539
|
this.authPromise = null;
|
|
@@ -1546,7 +1552,7 @@ class RebaseWebSocketClient {
|
|
|
1546
1552
|
}
|
|
1547
1553
|
if (attempt < retryCount - 1) {
|
|
1548
1554
|
const delay = Math.min(1e3 * (attempt + 1), 3e3);
|
|
1549
|
-
console.
|
|
1555
|
+
console.debug(`WebSocket auth attempt ${attempt + 1} failed, retrying in ${delay}ms...`);
|
|
1550
1556
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1551
1557
|
}
|
|
1552
1558
|
}
|
|
@@ -1563,7 +1569,7 @@ class RebaseWebSocketClient {
|
|
|
1563
1569
|
try {
|
|
1564
1570
|
const token = await this.getAuthToken();
|
|
1565
1571
|
await this.authenticate(token);
|
|
1566
|
-
console.
|
|
1572
|
+
console.debug("WebSocket reauthenticated successfully");
|
|
1567
1573
|
} catch (error) {
|
|
1568
1574
|
console.error("WebSocket reauthentication failed:", error);
|
|
1569
1575
|
throw error;
|
|
@@ -1821,7 +1827,7 @@ class RebaseWebSocketClient {
|
|
|
1821
1827
|
};
|
|
1822
1828
|
}
|
|
1823
1829
|
}
|
|
1824
|
-
console.
|
|
1830
|
+
console.debug(`[RebaseWS] Row ${incomingEntity.id} refetch mismatch:
|
|
1825
1831
|
`, JSON.stringify(mismatches, null, 2));
|
|
1826
1832
|
}
|
|
1827
1833
|
}
|
|
@@ -1981,7 +1987,7 @@ class RebaseWebSocketClient {
|
|
|
1981
1987
|
* we need to re-register everything to resume receiving updates.
|
|
1982
1988
|
*/
|
|
1983
1989
|
resubscribeAll() {
|
|
1984
|
-
console.
|
|
1990
|
+
console.debug(`[WS] Re-subscribing: ${this.collectionSubscriptions.size} collection(s), ${this.entitySubscriptions.size} entity(ies)`);
|
|
1985
1991
|
for (const [key, sub] of this.collectionSubscriptions.entries()) {
|
|
1986
1992
|
const oldBackendId = sub.backendSubscriptionId;
|
|
1987
1993
|
const newBackendId = `collection_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|