@rebasepro/client 0.0.1-canary.eae7889 → 0.1.0
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/auth.d.ts +6 -1
- package/dist/collection.d.ts +2 -1
- package/dist/collection.test.d.ts +1 -0
- package/dist/functions.d.ts +49 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.es.js +46 -23
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +46 -23
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -4
- package/src/auth.ts +20 -8
- package/src/collection.test.ts +159 -0
- package/src/collection.ts +8 -0
- package/src/functions.ts +80 -0
- package/src/index.ts +6 -0
- package/src/websocket.ts +17 -13
package/dist/index.umd.js
CHANGED
|
@@ -383,21 +383,18 @@
|
|
|
383
383
|
refreshToken: session.refreshToken
|
|
384
384
|
};
|
|
385
385
|
}
|
|
386
|
-
async function signInWithGoogle(
|
|
386
|
+
async function signInWithGoogle(tokenOrPayload) {
|
|
387
387
|
const fetchFn = getFetch();
|
|
388
|
+
const body = typeof tokenOrPayload === "string" ? { idToken: tokenOrPayload } : tokenOrPayload;
|
|
388
389
|
const res = await fetchFn(authUrl("/google"), {
|
|
389
390
|
method: "POST",
|
|
390
391
|
headers: { "Content-Type": "application/json" },
|
|
391
|
-
body: JSON.stringify(
|
|
392
|
+
body: JSON.stringify(body)
|
|
392
393
|
});
|
|
393
|
-
const
|
|
394
|
-
if (!res.ok) throwApiError(res.status,
|
|
395
|
-
const session = handleAuthResponse(
|
|
396
|
-
return {
|
|
397
|
-
user: session.user,
|
|
398
|
-
accessToken: session.accessToken,
|
|
399
|
-
refreshToken: session.refreshToken
|
|
400
|
-
};
|
|
394
|
+
const responseBody = await res.json().catch(() => ({}));
|
|
395
|
+
if (!res.ok) throwApiError(res.status, responseBody, res.statusText);
|
|
396
|
+
const session = handleAuthResponse(responseBody, "SIGNED_IN");
|
|
397
|
+
return { user: session.user, accessToken: session.accessToken, refreshToken: session.refreshToken };
|
|
401
398
|
}
|
|
402
399
|
async function signInWithLinkedin(code, redirectUri) {
|
|
403
400
|
const fetchFn = getFetch();
|
|
@@ -1079,6 +1076,12 @@
|
|
|
1079
1076
|
method: "DELETE"
|
|
1080
1077
|
});
|
|
1081
1078
|
},
|
|
1079
|
+
async count(params) {
|
|
1080
|
+
const countParams = { ...params, limit: void 0, offset: void 0 };
|
|
1081
|
+
const qs = buildQueryString(countParams);
|
|
1082
|
+
const raw = await transport.request(basePath + "/count" + qs, { method: "GET" });
|
|
1083
|
+
return raw.count ?? 0;
|
|
1084
|
+
},
|
|
1082
1085
|
// Fluent builder instantiation
|
|
1083
1086
|
where(column, operator, value) {
|
|
1084
1087
|
return new QueryBuilder(client).where(column, operator, value);
|
|
@@ -1145,6 +1148,23 @@
|
|
|
1145
1148
|
}
|
|
1146
1149
|
return client;
|
|
1147
1150
|
}
|
|
1151
|
+
function createFunctionsClient(transport) {
|
|
1152
|
+
return {
|
|
1153
|
+
async invoke(name, payload, options) {
|
|
1154
|
+
const method = options?.method ?? "POST";
|
|
1155
|
+
const subPath = options?.path ? `/${options.path.replace(/^\//, "")}` : "";
|
|
1156
|
+
const routePath = `/functions/${encodeURIComponent(name)}${subPath}`;
|
|
1157
|
+
const init = { method };
|
|
1158
|
+
if (payload !== void 0 && method !== "GET") {
|
|
1159
|
+
init.body = JSON.stringify(payload);
|
|
1160
|
+
}
|
|
1161
|
+
if (options?.headers) {
|
|
1162
|
+
init.headers = options.headers;
|
|
1163
|
+
}
|
|
1164
|
+
return transport.request(routePath, init);
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1148
1168
|
function rehydrateEntity(entity) {
|
|
1149
1169
|
return entity;
|
|
1150
1170
|
}
|
|
@@ -1251,16 +1271,16 @@
|
|
|
1251
1271
|
setAuthTokenGetter(getAuthToken) {
|
|
1252
1272
|
this.getAuthToken = getAuthToken;
|
|
1253
1273
|
if (this.isConnected && !this.isAuthenticated && !this.authPromise) {
|
|
1254
|
-
console.
|
|
1274
|
+
console.debug("WebSocket auto-authenticating after token getter set");
|
|
1255
1275
|
this.getAuthToken().then((token) => {
|
|
1256
1276
|
if (!this.ws) return;
|
|
1257
1277
|
if (token) {
|
|
1258
1278
|
this.authenticate(token).catch((e) => {
|
|
1259
|
-
if (this.ws) console.
|
|
1279
|
+
if (this.ws) console.debug("WebSocket auto-auth skipped:", e?.message || e);
|
|
1260
1280
|
});
|
|
1261
1281
|
}
|
|
1262
1282
|
}).catch((e) => {
|
|
1263
|
-
if (this.ws) console.
|
|
1283
|
+
if (this.ws) console.debug("WebSocket auto-auth skipped:", e?.message || e);
|
|
1264
1284
|
});
|
|
1265
1285
|
}
|
|
1266
1286
|
}
|
|
@@ -1287,7 +1307,7 @@
|
|
|
1287
1307
|
try {
|
|
1288
1308
|
this.ws = new this.WebSocketConstructor(this.websocketUrl);
|
|
1289
1309
|
this.ws.onopen = async () => {
|
|
1290
|
-
console.
|
|
1310
|
+
console.debug("Connected to PostgreSQL backend");
|
|
1291
1311
|
const wasReconnect = this.reconnectAttempts > 0;
|
|
1292
1312
|
this.isConnected = true;
|
|
1293
1313
|
this.reconnectAttempts = 0;
|
|
@@ -1296,10 +1316,10 @@
|
|
|
1296
1316
|
const token = await this.getAuthToken();
|
|
1297
1317
|
if (token) {
|
|
1298
1318
|
await this.authenticate(token);
|
|
1299
|
-
console.
|
|
1319
|
+
console.debug("WebSocket auto-authenticated");
|
|
1300
1320
|
}
|
|
1301
1321
|
} catch (error) {
|
|
1302
|
-
console.
|
|
1322
|
+
console.debug("WebSocket connected without auth:", error?.message || error);
|
|
1303
1323
|
}
|
|
1304
1324
|
}
|
|
1305
1325
|
this.emit(wasReconnect ? "reconnect" : "connect");
|
|
@@ -1317,7 +1337,7 @@
|
|
|
1317
1337
|
}
|
|
1318
1338
|
};
|
|
1319
1339
|
this.ws.onclose = () => {
|
|
1320
|
-
console.
|
|
1340
|
+
console.debug("Disconnected from PostgreSQL backend");
|
|
1321
1341
|
this.isConnected = false;
|
|
1322
1342
|
this.isAuthenticated = false;
|
|
1323
1343
|
this.authPromise = null;
|
|
@@ -1359,7 +1379,7 @@
|
|
|
1359
1379
|
}
|
|
1360
1380
|
this.reconnectAttempts++;
|
|
1361
1381
|
const delay = Math.min(1e3 * Math.pow(2, this.reconnectAttempts), 3e4);
|
|
1362
|
-
console.
|
|
1382
|
+
console.debug(`Attempting to reconnect in ${delay}ms (attempt ${this.reconnectAttempts})`);
|
|
1363
1383
|
if (this.reconnectTimeout) {
|
|
1364
1384
|
clearTimeout(this.reconnectTimeout);
|
|
1365
1385
|
}
|
|
@@ -1529,7 +1549,7 @@
|
|
|
1529
1549
|
this.authPromise = this.authenticate(token);
|
|
1530
1550
|
await this.authPromise;
|
|
1531
1551
|
this.authPromise = null;
|
|
1532
|
-
console.
|
|
1552
|
+
console.debug("WebSocket authenticated on demand");
|
|
1533
1553
|
return;
|
|
1534
1554
|
} catch (error) {
|
|
1535
1555
|
this.authPromise = null;
|
|
@@ -1548,7 +1568,7 @@
|
|
|
1548
1568
|
}
|
|
1549
1569
|
if (attempt < retryCount - 1) {
|
|
1550
1570
|
const delay = Math.min(1e3 * (attempt + 1), 3e3);
|
|
1551
|
-
console.
|
|
1571
|
+
console.debug(`WebSocket auth attempt ${attempt + 1} failed, retrying in ${delay}ms...`);
|
|
1552
1572
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1553
1573
|
}
|
|
1554
1574
|
}
|
|
@@ -1565,7 +1585,7 @@
|
|
|
1565
1585
|
try {
|
|
1566
1586
|
const token = await this.getAuthToken();
|
|
1567
1587
|
await this.authenticate(token);
|
|
1568
|
-
console.
|
|
1588
|
+
console.debug("WebSocket reauthenticated successfully");
|
|
1569
1589
|
} catch (error) {
|
|
1570
1590
|
console.error("WebSocket reauthentication failed:", error);
|
|
1571
1591
|
throw error;
|
|
@@ -1823,7 +1843,7 @@
|
|
|
1823
1843
|
};
|
|
1824
1844
|
}
|
|
1825
1845
|
}
|
|
1826
|
-
console.
|
|
1846
|
+
console.debug(`[RebaseWS] Row ${incomingEntity.id} refetch mismatch:
|
|
1827
1847
|
`, JSON.stringify(mismatches, null, 2));
|
|
1828
1848
|
}
|
|
1829
1849
|
}
|
|
@@ -1983,7 +2003,7 @@
|
|
|
1983
2003
|
* we need to re-register everything to resume receiving updates.
|
|
1984
2004
|
*/
|
|
1985
2005
|
resubscribeAll() {
|
|
1986
|
-
console.
|
|
2006
|
+
console.debug(`[WS] Re-subscribing: ${this.collectionSubscriptions.size} collection(s), ${this.entitySubscriptions.size} entity(ies)`);
|
|
1987
2007
|
for (const [key, sub] of this.collectionSubscriptions.entries()) {
|
|
1988
2008
|
const oldBackendId = sub.backendSubscriptionId;
|
|
1989
2009
|
const newBackendId = `collection_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
@@ -2184,6 +2204,7 @@
|
|
|
2184
2204
|
const admin = createAdmin(transport, options.admin);
|
|
2185
2205
|
const cron = createCron(transport, options.cron);
|
|
2186
2206
|
const storage = createStorage(transport);
|
|
2207
|
+
const functions = createFunctionsClient(transport);
|
|
2187
2208
|
const resolvedWsUrl = options.websocketUrl ?? deriveWebSocketUrl(options.baseUrl);
|
|
2188
2209
|
let ws;
|
|
2189
2210
|
if (resolvedWsUrl) {
|
|
@@ -2240,6 +2261,7 @@
|
|
|
2240
2261
|
auth,
|
|
2241
2262
|
admin,
|
|
2242
2263
|
cron,
|
|
2264
|
+
functions,
|
|
2243
2265
|
storage,
|
|
2244
2266
|
ws,
|
|
2245
2267
|
setToken: transport.setToken,
|
|
@@ -2269,6 +2291,7 @@
|
|
|
2269
2291
|
exports2.createAuth = createAuth;
|
|
2270
2292
|
exports2.createCollectionClient = createCollectionClient;
|
|
2271
2293
|
exports2.createCron = createCron;
|
|
2294
|
+
exports2.createFunctionsClient = createFunctionsClient;
|
|
2272
2295
|
exports2.createMemoryStorage = createMemoryStorage;
|
|
2273
2296
|
exports2.createRebaseClient = createRebaseClient;
|
|
2274
2297
|
exports2.createStorage = createStorage;
|