@rebasepro/client 0.30.0 → 0.31.0-canary.g59cd6fd
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/README.md +10 -10
- package/dist/auth.d.ts +56 -0
- package/dist/client-contract.types.d.ts +25 -0
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +34 -29
- package/dist/index.es.js +227 -75
- package/dist/index.es.js.map +1 -1
- package/dist/{offline-B6J1YUWF.js → offline-D_wKJcO3.js} +102 -93
- package/dist/offline-D_wKJcO3.js.map +1 -0
- package/dist/offline-codec.d.ts +7 -1
- package/dist/offline-lazy.d.ts +5 -5
- package/dist/{offline-store-B7F5mimt.js → offline-store-DtmBwmKE.js} +52 -146
- package/dist/offline-store-DtmBwmKE.js.map +1 -0
- package/dist/offline-store.d.ts +11 -2
- package/dist/offline.d.ts +23 -23
- package/dist/query-contract.types.d.ts +4 -4
- package/dist/schema.d.ts +29 -0
- package/dist/sdk_query_builder.d.ts +7 -7
- package/dist/{collection.d.ts → table.d.ts} +13 -13
- package/dist/transport.d.ts +3 -4
- package/dist/websocket.d.ts +6 -12
- package/package.json +7 -5
- package/dist/offline-B6J1YUWF.js.map +0 -1
- package/dist/offline-store-B7F5mimt.js.map +0 -1
- package/dist/reviver.d.ts +0 -19
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as invalidBulkBody, d as RebaseApiError,
|
|
1
|
+
import { c as invalidBulkBody, d as RebaseApiError, i as isOfflineError, l as SDKQueryBuilder, m as defaultCodeForStatus, n as MemoryOfflineStore, o as createTableClient, p as createTransport, s as etagOf, u as RebaseClientError } from "./offline-store-DtmBwmKE.js";
|
|
2
2
|
import { AUTH_FLOW_HEADER, DEFAULT_STORAGE_SOURCE_KEY, PUBLIC_STORAGE_PREFIX, RebaseApiError as RebaseApiError$1, RebaseClientError as RebaseClientError$1, STORAGE_REFERENCE_SCHEME, isPublicStoragePath, isStorageReference, isUnsupported, parseStorageReference, resolveStorageReferences, simulationHeaders, storageObjectPath, storageReference, storageReferencesForDownloadUrls, storageTargetOfDownloadUrl, storageTargetsInText } from "@rebasepro/types";
|
|
3
3
|
import { COMPOSITE_ID_SEPARATOR, DOWNLOAD_URL_CONCURRENCY, RESUMABLE_UPLOAD_THRESHOLD, RebasePaginationError, and, buildCompositeId, cond, createBatchLoader, createConcurrencyLimit, createDownloadUrlCache, not, or, warnDeprecated, withETag } from "@rebasepro/common";
|
|
4
4
|
import { toSnakeCase, unref } from "@rebasepro/utils";
|
|
@@ -1257,6 +1257,95 @@ function createAuth(transport, options) {
|
|
|
1257
1257
|
};
|
|
1258
1258
|
}
|
|
1259
1259
|
/**
|
|
1260
|
+
* Start a device sign-in: the way something without a browser of its own —
|
|
1261
|
+
* a terminal — signs in through one (RFC 8628's device authorization
|
|
1262
|
+
* grant). Show the person `verificationUriComplete` and `userCode`, then
|
|
1263
|
+
* call {@link pollDeviceLogin} every `interval` seconds until it is
|
|
1264
|
+
* decided. Refused unless the backend has `auth.deviceLogin` on; its
|
|
1265
|
+
* `/auth/config` says `deviceLogin: true` when it does.
|
|
1266
|
+
*
|
|
1267
|
+
* @param options.clientName What the approval page calls this device.
|
|
1268
|
+
*/
|
|
1269
|
+
async function startDeviceLogin(options) {
|
|
1270
|
+
const res = await getFetch()(authUrl("/device"), {
|
|
1271
|
+
method: "POST",
|
|
1272
|
+
headers: { "Content-Type": "application/json" },
|
|
1273
|
+
body: JSON.stringify({ clientName: options?.clientName })
|
|
1274
|
+
});
|
|
1275
|
+
const body = await res.json().catch(() => ({}));
|
|
1276
|
+
if (!res.ok) throwApiError(res.status, body, res.statusText);
|
|
1277
|
+
return body;
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Ask once whether a device sign-in has been decided. When it has been
|
|
1281
|
+
* approved, this client is signed in — the session is stored like any other
|
|
1282
|
+
* sign-in's is — and the answer carries it. Any other answer is what to do
|
|
1283
|
+
* next: wait `interval` seconds and ask again (`pending`, `slow_down`),
|
|
1284
|
+
* or stop (`denied`, `expired`).
|
|
1285
|
+
*
|
|
1286
|
+
* Rejects for anything else: a network failure, a rate limit, a device
|
|
1287
|
+
* code that has already been used.
|
|
1288
|
+
*/
|
|
1289
|
+
async function pollDeviceLogin(deviceCode) {
|
|
1290
|
+
const res = await getFetch()(authUrl("/device/token"), {
|
|
1291
|
+
method: "POST",
|
|
1292
|
+
headers: { "Content-Type": "application/json" },
|
|
1293
|
+
body: JSON.stringify({ deviceCode })
|
|
1294
|
+
});
|
|
1295
|
+
const body = await res.json().catch(() => ({}));
|
|
1296
|
+
if (!res.ok) {
|
|
1297
|
+
const error = apiError(res.status, body, res.statusText);
|
|
1298
|
+
const details = error.details;
|
|
1299
|
+
const interval = typeof details === "object" && details !== null && "interval" in details && typeof details.interval === "number" ? details.interval : void 0;
|
|
1300
|
+
if (error.code === "authorization_pending") return {
|
|
1301
|
+
status: "pending",
|
|
1302
|
+
interval: interval ?? 5
|
|
1303
|
+
};
|
|
1304
|
+
if (error.code === "slow_down") return {
|
|
1305
|
+
status: "slow_down",
|
|
1306
|
+
interval: interval ?? 10
|
|
1307
|
+
};
|
|
1308
|
+
if (error.code === "access_denied") return { status: "denied" };
|
|
1309
|
+
if (error.code === "expired_token") return { status: "expired" };
|
|
1310
|
+
throw error;
|
|
1311
|
+
}
|
|
1312
|
+
const session = handleAuthResponse(body, "SIGNED_IN");
|
|
1313
|
+
return {
|
|
1314
|
+
status: "approved",
|
|
1315
|
+
user: session.user,
|
|
1316
|
+
accessToken: session.accessToken,
|
|
1317
|
+
refreshToken: session.refreshToken
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
/**
|
|
1321
|
+
* What a device sign-in is, for the page that approves it: the code, what
|
|
1322
|
+
* the device calls itself and where it asked from. Needs this client to
|
|
1323
|
+
* be signed in. Rejects with `DEVICE_LOGIN_NOT_FOUND` (404) for a code no
|
|
1324
|
+
* sign-in has.
|
|
1325
|
+
*/
|
|
1326
|
+
async function describeDeviceLogin(userCode) {
|
|
1327
|
+
return transport.request(`${authPath}/device/${encodeURIComponent(userCode)}`, { method: "GET" });
|
|
1328
|
+
}
|
|
1329
|
+
/**
|
|
1330
|
+
* Approve a device sign-in as the signed-in account: the device's next
|
|
1331
|
+
* poll gets a session for it. Rejects with `DEVICE_LOGIN_EXPIRED` (410),
|
|
1332
|
+
* `DEVICE_LOGIN_DECIDED` (409), or `AAL2_REQUIRED` (403) when the account
|
|
1333
|
+
* has two-factor authentication on and this session did not use it.
|
|
1334
|
+
*/
|
|
1335
|
+
async function approveDeviceLogin(userCode) {
|
|
1336
|
+
await transport.request(`${authPath}/device/approve`, {
|
|
1337
|
+
method: "POST",
|
|
1338
|
+
body: JSON.stringify({ userCode })
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
/** Deny a device sign-in: its next poll is told so, and it gets nothing. */
|
|
1342
|
+
async function denyDeviceLogin(userCode) {
|
|
1343
|
+
await transport.request(`${authPath}/device/deny`, {
|
|
1344
|
+
method: "POST",
|
|
1345
|
+
body: JSON.stringify({ userCode })
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1260
1349
|
* Sign in without credentials, as a throwaway account.
|
|
1261
1350
|
*
|
|
1262
1351
|
* The account is real — it has an id, roles and a session, so row-level
|
|
@@ -1582,6 +1671,11 @@ function createAuth(transport, options) {
|
|
|
1582
1671
|
verifyMagicLink,
|
|
1583
1672
|
sendEmailOtp,
|
|
1584
1673
|
verifyEmailOtp,
|
|
1674
|
+
startDeviceLogin,
|
|
1675
|
+
pollDeviceLogin,
|
|
1676
|
+
describeDeviceLogin,
|
|
1677
|
+
approveDeviceLogin,
|
|
1678
|
+
denyDeviceLogin,
|
|
1585
1679
|
getSessions,
|
|
1586
1680
|
revokeSession,
|
|
1587
1681
|
revokeAllSessions,
|
|
@@ -1910,6 +2004,76 @@ function saveFrom(url, fileName) {
|
|
|
1910
2004
|
a.remove();
|
|
1911
2005
|
}
|
|
1912
2006
|
//#endregion
|
|
2007
|
+
//#region src/schema.ts
|
|
2008
|
+
/**
|
|
2009
|
+
* The code `client.schema.tables()` rejects with when the backend serves no
|
|
2010
|
+
* tables: auth is not configured there (the route answers `404` with this
|
|
2011
|
+
* code), or the server predates the route (a bare `404`).
|
|
2012
|
+
*
|
|
2013
|
+
* @group Schema
|
|
2014
|
+
*/
|
|
2015
|
+
var SCHEMA_UNAVAILABLE = "SCHEMA_UNAVAILABLE";
|
|
2016
|
+
/**
|
|
2017
|
+
* Whether an error from `client.schema.tables()` says the backend serves no
|
|
2018
|
+
* tables at all — as opposed to refusing this caller or failing.
|
|
2019
|
+
*
|
|
2020
|
+
* @group Schema
|
|
2021
|
+
*/
|
|
2022
|
+
function isSchemaUnavailable(error) {
|
|
2023
|
+
return error instanceof RebaseApiError$1 && error.code === "SCHEMA_UNAVAILABLE";
|
|
2024
|
+
}
|
|
2025
|
+
/** The path of the route, under the API base path. */
|
|
2026
|
+
var TABLES_PATH = "/schema/tables";
|
|
2027
|
+
function isTableDescriptor(value) {
|
|
2028
|
+
return typeof value === "object" && value !== null && "slug" in value && typeof value.slug === "string" && "columns" in value && Array.isArray(value.columns);
|
|
2029
|
+
}
|
|
2030
|
+
/**
|
|
2031
|
+
* `client.schema`: the backend's tables as `GET /api/schema/tables` serves
|
|
2032
|
+
* them to the signed-in caller.
|
|
2033
|
+
*
|
|
2034
|
+
* The answer is redacted per caller and the server tags it with an `ETag`;
|
|
2035
|
+
* the last answer is kept with its tag and the next request sends the tag in
|
|
2036
|
+
* `If-None-Match`, so an unchanged schema costs a `304` and no body. A `304`
|
|
2037
|
+
* says the answer for *this* caller still has the tag that was sent, so the
|
|
2038
|
+
* kept tables are exactly what the server would have sent — whoever is signed
|
|
2039
|
+
* in now.
|
|
2040
|
+
*/
|
|
2041
|
+
function createSchema(transport) {
|
|
2042
|
+
let last;
|
|
2043
|
+
async function tables(options) {
|
|
2044
|
+
const cached = last;
|
|
2045
|
+
const meta = {};
|
|
2046
|
+
let body;
|
|
2047
|
+
try {
|
|
2048
|
+
body = await transport.request(TABLES_PATH, {
|
|
2049
|
+
method: "GET",
|
|
2050
|
+
...cached ? { headers: { "If-None-Match": cached.etag } } : {},
|
|
2051
|
+
...options?.signal ? { signal: options.signal } : {}
|
|
2052
|
+
}, meta);
|
|
2053
|
+
} catch (error) {
|
|
2054
|
+
if (!(error instanceof RebaseApiError$1)) throw error;
|
|
2055
|
+
if (error.status === 304 && cached) return cached.tables;
|
|
2056
|
+
if (error.status === 404 && error.code !== "SCHEMA_UNAVAILABLE") throw new RebaseApiError$1(`This backend does not serve its tables (GET ${transport.apiPath}${TABLES_PATH} answered 404): it predates the route. Upgrade @rebasepro/server, or pass the collections to <RebaseCMS collections> yourself.`, {
|
|
2057
|
+
status: 404,
|
|
2058
|
+
code: SCHEMA_UNAVAILABLE,
|
|
2059
|
+
...error.requestId ? { requestId: error.requestId } : {},
|
|
2060
|
+
cause: error
|
|
2061
|
+
});
|
|
2062
|
+
throw error;
|
|
2063
|
+
}
|
|
2064
|
+
if (!Array.isArray(body) || !body.every(isTableDescriptor)) throw new RebaseApiError$1(`GET ${transport.apiPath}${TABLES_PATH} answered something other than a list of tables. Check that the client's baseUrl points at the Rebase backend.`, {
|
|
2065
|
+
status: meta.status,
|
|
2066
|
+
code: "INVALID_RESPONSE"
|
|
2067
|
+
});
|
|
2068
|
+
last = meta.etag ? {
|
|
2069
|
+
etag: meta.etag,
|
|
2070
|
+
tables: body
|
|
2071
|
+
} : void 0;
|
|
2072
|
+
return body;
|
|
2073
|
+
}
|
|
2074
|
+
return { tables };
|
|
2075
|
+
}
|
|
2076
|
+
//#endregion
|
|
1913
2077
|
//#region src/api-keys.ts
|
|
1914
2078
|
/**
|
|
1915
2079
|
* Creates a client for the project's service keys, via the admin routes.
|
|
@@ -2683,6 +2847,13 @@ function channelErrorCode(message) {
|
|
|
2683
2847
|
const raw = message.payload?.error;
|
|
2684
2848
|
if (raw && typeof raw === "object" && "code" in raw && typeof raw.code === "string") return raw.code;
|
|
2685
2849
|
}
|
|
2850
|
+
/**
|
|
2851
|
+
* The name of the collection config an admin panel handed beside a data
|
|
2852
|
+
* call's path, if it handed one: what a subscription key carries of it.
|
|
2853
|
+
*/
|
|
2854
|
+
function viewCollectionName(value) {
|
|
2855
|
+
return typeof value === "object" && value !== null && "name" in value && typeof value.name === "string" ? value.name : void 0;
|
|
2856
|
+
}
|
|
2686
2857
|
var RebaseWebSocketClient = class {
|
|
2687
2858
|
websocketUrl;
|
|
2688
2859
|
affinity;
|
|
@@ -3186,7 +3357,7 @@ var RebaseWebSocketClient = class {
|
|
|
3186
3357
|
this.ws.onmessage = (event) => {
|
|
3187
3358
|
this.lastFrameAt = Date.now();
|
|
3188
3359
|
try {
|
|
3189
|
-
const message =
|
|
3360
|
+
const message = JSON.parse(String(event.data));
|
|
3190
3361
|
this.handleWebSocketMessage(message);
|
|
3191
3362
|
} catch (error) {
|
|
3192
3363
|
console.error("Error parsing WebSocket message:", error);
|
|
@@ -3503,7 +3674,7 @@ var RebaseWebSocketClient = class {
|
|
|
3503
3674
|
try {
|
|
3504
3675
|
callback.onUpdate(rows, collectionSub.latestMeta);
|
|
3505
3676
|
} catch (error) {
|
|
3506
|
-
console.error("Error in
|
|
3677
|
+
console.error("Error in table subscription callback:", error);
|
|
3507
3678
|
if (callback.onError) callback.onError(error instanceof Error ? error : new Error(String(error)));
|
|
3508
3679
|
}
|
|
3509
3680
|
});
|
|
@@ -3851,15 +4022,14 @@ var RebaseWebSocketClient = class {
|
|
|
3851
4022
|
async fetchCurrentDatabase() {
|
|
3852
4023
|
return (await this.sendMessage({ type: "FETCH_CURRENT_DATABASE" })).database;
|
|
3853
4024
|
}
|
|
3854
|
-
async checkUniqueField(path, name, value, id
|
|
4025
|
+
async checkUniqueField(path, name, value, id) {
|
|
3855
4026
|
return (await this.sendMessage({
|
|
3856
4027
|
type: "CHECK_UNIQUE_FIELD",
|
|
3857
4028
|
payload: {
|
|
3858
4029
|
path,
|
|
3859
4030
|
name,
|
|
3860
4031
|
value,
|
|
3861
|
-
id
|
|
3862
|
-
collection
|
|
4032
|
+
id
|
|
3863
4033
|
}
|
|
3864
4034
|
})).isUnique;
|
|
3865
4035
|
}
|
|
@@ -3926,17 +4096,11 @@ var RebaseWebSocketClient = class {
|
|
|
3926
4096
|
/**
|
|
3927
4097
|
* Recursively compare two values a refetch can carry for structural
|
|
3928
4098
|
* equality: primitives, null, undefined, Date, RegExp, arrays and objects.
|
|
3929
|
-
*
|
|
3930
|
-
*
|
|
3931
|
-
*
|
|
3932
|
-
* done by normalising each side into a copy first — two deep copies of
|
|
3933
|
-
* every cached row on every frame, most of which then compared equal. It is
|
|
3934
|
-
* done in place now, and an unchanged row costs no copy.
|
|
3935
|
-
*
|
|
3936
|
-
* `relationAware` is off for a relation's own fields: the copies never
|
|
3937
|
-
* looked inside those either.
|
|
4099
|
+
* In place — an unchanged row costs no copy. A row is wire values only, so
|
|
4100
|
+
* a relation is its key, or the related row an `include` named, compared
|
|
4101
|
+
* like any other value.
|
|
3938
4102
|
*/
|
|
3939
|
-
deepEqual(a, b
|
|
4103
|
+
deepEqual(a, b) {
|
|
3940
4104
|
if (a === b) return true;
|
|
3941
4105
|
if (a === null || b === null || a === void 0 || b === void 0) return false;
|
|
3942
4106
|
if (typeof a !== typeof b) return false;
|
|
@@ -3950,31 +4114,17 @@ var RebaseWebSocketClient = class {
|
|
|
3950
4114
|
if (aIsArray !== bIsArray) return false;
|
|
3951
4115
|
if (aIsArray && bIsArray) {
|
|
3952
4116
|
if (a.length !== b.length) return false;
|
|
3953
|
-
for (let i = 0; i < a.length; i++) if (!this.deepEqual(a[i], b[i]
|
|
4117
|
+
for (let i = 0; i < a.length; i++) if (!this.deepEqual(a[i], b[i])) return false;
|
|
3954
4118
|
return true;
|
|
3955
4119
|
}
|
|
3956
4120
|
const aObj = a;
|
|
3957
4121
|
const bObj = b;
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
if (relationAware) {
|
|
3961
|
-
const aIsRelation = aObj.__type === "relation";
|
|
3962
|
-
if (aIsRelation !== (bObj.__type === "relation")) return false;
|
|
3963
|
-
if (aIsRelation) {
|
|
3964
|
-
skip = "data";
|
|
3965
|
-
nested = false;
|
|
3966
|
-
}
|
|
3967
|
-
}
|
|
3968
|
-
let aCount = 0;
|
|
3969
|
-
for (const key of Object.keys(aObj)) {
|
|
3970
|
-
if (key === skip) continue;
|
|
3971
|
-
aCount++;
|
|
4122
|
+
const aKeys = Object.keys(aObj);
|
|
4123
|
+
for (const key of aKeys) {
|
|
3972
4124
|
if (!Object.prototype.hasOwnProperty.call(bObj, key)) return false;
|
|
3973
|
-
if (!this.deepEqual(aObj[key], bObj[key]
|
|
4125
|
+
if (!this.deepEqual(aObj[key], bObj[key])) return false;
|
|
3974
4126
|
}
|
|
3975
|
-
|
|
3976
|
-
for (const key of Object.keys(bObj)) if (key !== skip) bCount++;
|
|
3977
|
-
return aCount === bCount;
|
|
4127
|
+
return aKeys.length === Object.keys(bObj).length;
|
|
3978
4128
|
}
|
|
3979
4129
|
/**
|
|
3980
4130
|
* The address of a row, for matching it against another copy of itself.
|
|
@@ -4040,7 +4190,7 @@ var RebaseWebSocketClient = class {
|
|
|
4040
4190
|
if (existingSubscription.latestData !== void 0 && existingSubscription.isInitialDataReceived) try {
|
|
4041
4191
|
onUpdate(existingSubscription.latestData, existingSubscription.latestMeta);
|
|
4042
4192
|
} catch (error) {
|
|
4043
|
-
console.error("Error in
|
|
4193
|
+
console.error("Error in table subscription callback:", error);
|
|
4044
4194
|
if (onError) onError(error instanceof Error ? error : new Error(String(error)));
|
|
4045
4195
|
}
|
|
4046
4196
|
else if (!existingSubscription.subscribeInFlight) this.sendCollectionSubscribe(subscriptionKey);
|
|
@@ -4224,7 +4374,7 @@ var RebaseWebSocketClient = class {
|
|
|
4224
4374
|
if (callback.onError) try {
|
|
4225
4375
|
callback.onError(error);
|
|
4226
4376
|
} catch (callbackError) {
|
|
4227
|
-
console.error("Error in
|
|
4377
|
+
console.error("Error in table subscription error callback:", callbackError);
|
|
4228
4378
|
}
|
|
4229
4379
|
});
|
|
4230
4380
|
}
|
|
@@ -4318,7 +4468,7 @@ var RebaseWebSocketClient = class {
|
|
|
4318
4468
|
* we need to re-register everything to resume receiving updates.
|
|
4319
4469
|
*/
|
|
4320
4470
|
resubscribeAll() {
|
|
4321
|
-
this.connectionDebug(`[WS] Re-subscribing: ${this.collectionSubscriptions.size}
|
|
4471
|
+
this.connectionDebug(`[WS] Re-subscribing: ${this.collectionSubscriptions.size} table subscription(s), ${this.singleSubscriptions.size} row(ies)`);
|
|
4322
4472
|
for (const [key, sub] of this.collectionSubscriptions.entries()) {
|
|
4323
4473
|
if (sub.subscribeInFlight) continue;
|
|
4324
4474
|
const oldBackendId = sub.backendSubscriptionId;
|
|
@@ -4339,10 +4489,10 @@ var RebaseWebSocketClient = class {
|
|
|
4339
4489
|
}
|
|
4340
4490
|
}
|
|
4341
4491
|
createCollectionSubscriptionKey(props) {
|
|
4342
|
-
const
|
|
4492
|
+
const viewCollection = Reflect.get(props, "collection");
|
|
4343
4493
|
const key = {
|
|
4344
|
-
...
|
|
4345
|
-
collection:
|
|
4494
|
+
...props,
|
|
4495
|
+
collection: viewCollectionName(viewCollection)
|
|
4346
4496
|
};
|
|
4347
4497
|
return JSON.stringify(key, (_, value) => {
|
|
4348
4498
|
if (value && typeof value === "object" && !Array.isArray(value)) return Object.keys(value).sort().reduce((sorted, k) => {
|
|
@@ -4987,7 +5137,7 @@ function rejoinsAfter(code, message) {
|
|
|
4987
5137
|
*
|
|
4988
5138
|
* - Calls made before the engine has arrived are queued and run, in the order
|
|
4989
5139
|
* they were made, the moment it does — the scope changes the factory makes
|
|
4990
|
-
* from auth events, and every
|
|
5140
|
+
* from auth events, and every table a client wrapped meanwhile.
|
|
4991
5141
|
* - What answers with a promise waits for the engine and then asks it.
|
|
4992
5142
|
* - What answers synchronously answers what the engine would have before
|
|
4993
5143
|
* anything ran: `status()` is the initial status, a subscription is
|
|
@@ -5007,7 +5157,7 @@ var LazyOfflineManager = class {
|
|
|
5007
5157
|
keepsLastUser;
|
|
5008
5158
|
constructor(config, createInner) {
|
|
5009
5159
|
this.keepsLastUser = config.keepLastUser === true;
|
|
5010
|
-
import("./offline-
|
|
5160
|
+
import("./offline-D_wKJcO3.js").then(({ OfflineManager: Engine }) => {
|
|
5011
5161
|
const engine = new Engine(config, createInner);
|
|
5012
5162
|
this.engine = engine;
|
|
5013
5163
|
const queued = this.queued;
|
|
@@ -5200,6 +5350,7 @@ function createRebaseClient(options) {
|
|
|
5200
5350
|
const admin = createAdmin(transport, options.admin);
|
|
5201
5351
|
const cron = createCron(transport, options.cron);
|
|
5202
5352
|
const backups = createBackups(transport);
|
|
5353
|
+
const schema = createSchema(transport);
|
|
5203
5354
|
const apiKeys = createApiKeys(transport, options.apiKeys);
|
|
5204
5355
|
const personalKeys = createPersonalKeys(transport, options.personalKeys);
|
|
5205
5356
|
const storage = createStorage(transport);
|
|
@@ -5272,10 +5423,10 @@ function createRebaseClient(options) {
|
|
|
5272
5423
|
});
|
|
5273
5424
|
}
|
|
5274
5425
|
/**
|
|
5275
|
-
* Suggest the closest known
|
|
5426
|
+
* Suggest the closest known table key for a mistyped accessor.
|
|
5276
5427
|
* Uses edit-distance-1 and prefix matching — no external dependency.
|
|
5277
5428
|
*/
|
|
5278
|
-
function
|
|
5429
|
+
function suggestTable(prop, knownKeys) {
|
|
5279
5430
|
const prefixMatch = knownKeys.find((k) => k.startsWith(prop) || prop.startsWith(k));
|
|
5280
5431
|
if (prefixMatch) return prefixMatch;
|
|
5281
5432
|
for (const key of knownKeys) {
|
|
@@ -5308,7 +5459,7 @@ function createRebaseClient(options) {
|
|
|
5308
5459
|
if (diffs <= 1) return key;
|
|
5309
5460
|
}
|
|
5310
5461
|
}
|
|
5311
|
-
const offlineManager = options.offline ? new LazyOfflineManager(typeof options.offline === "object" ? options.offline : {}, (slug) =>
|
|
5462
|
+
const offlineManager = options.offline ? new LazyOfflineManager(typeof options.offline === "object" ? options.offline : {}, (slug) => createTableClient(transport, slug)) : void 0;
|
|
5312
5463
|
if (offlineManager) {
|
|
5313
5464
|
offlineManager.holdScope();
|
|
5314
5465
|
auth.onAuthStateChange((event, session) => {
|
|
@@ -5355,14 +5506,14 @@ function createRebaseClient(options) {
|
|
|
5355
5506
|
ws.disconnect();
|
|
5356
5507
|
ws.ensureConnected();
|
|
5357
5508
|
}
|
|
5358
|
-
const
|
|
5509
|
+
const tableClients = /* @__PURE__ */ new Map();
|
|
5359
5510
|
let untypedWarned = false;
|
|
5360
|
-
function
|
|
5361
|
-
if (!
|
|
5362
|
-
const inner =
|
|
5363
|
-
|
|
5511
|
+
function table(slug) {
|
|
5512
|
+
if (!tableClients.has(slug)) {
|
|
5513
|
+
const inner = createTableClient(transport, slug, ws);
|
|
5514
|
+
tableClients.set(slug, offlineManager ? offlineManager.wrap(slug, inner) : inner);
|
|
5364
5515
|
}
|
|
5365
|
-
return
|
|
5516
|
+
return tableClients.get(slug);
|
|
5366
5517
|
}
|
|
5367
5518
|
/**
|
|
5368
5519
|
* `client.batch()`, and `client.data.batch()` — the same function, so the
|
|
@@ -5378,13 +5529,13 @@ function createRebaseClient(options) {
|
|
|
5378
5529
|
const headers = {};
|
|
5379
5530
|
if (batchOptions?.idempotencyKey) headers["Idempotency-Key"] = batchOptions.idempotencyKey;
|
|
5380
5531
|
if (batchOptions?.returning === false) headers.Prefer = "return=minimal";
|
|
5381
|
-
const dictionary = options.
|
|
5532
|
+
const dictionary = options.tables;
|
|
5382
5533
|
const wire = dictionary ? operations.map((operation) => {
|
|
5383
5534
|
if (!operation || typeof operation !== "object") return operation;
|
|
5384
|
-
const name = operation.
|
|
5535
|
+
const name = operation.table;
|
|
5385
5536
|
return typeof name === "string" && Object.hasOwn(dictionary, name) ? {
|
|
5386
5537
|
...operation,
|
|
5387
|
-
|
|
5538
|
+
table: dictionary[name]
|
|
5388
5539
|
} : operation;
|
|
5389
5540
|
}) : operations;
|
|
5390
5541
|
return transport.request("/data/_batch", {
|
|
@@ -5394,36 +5545,36 @@ function createRebaseClient(options) {
|
|
|
5394
5545
|
});
|
|
5395
5546
|
};
|
|
5396
5547
|
const dataTarget = {
|
|
5397
|
-
|
|
5548
|
+
table,
|
|
5398
5549
|
batch
|
|
5399
5550
|
};
|
|
5400
5551
|
/**
|
|
5401
|
-
* Names the proxy never serves as a
|
|
5552
|
+
* Names the proxy never serves as a table: the ones promise and
|
|
5402
5553
|
* serialisation machinery probe for (`then`, `toJSON`, React's
|
|
5403
5554
|
* `$$typeof`), and everything a plain object inherits — so
|
|
5404
|
-
* `client.data.toString` is `Object.prototype.toString`, not a
|
|
5555
|
+
* `client.data.toString` is `Object.prototype.toString`, not a table
|
|
5405
5556
|
* client, and `String(client.data)` is `"[object Object]"` rather than a
|
|
5406
|
-
* throw. `prop in
|
|
5407
|
-
* `toString` and `constructor` became "
|
|
5557
|
+
* throw. `prop in tables` used to walk the prototype too, which is how
|
|
5558
|
+
* `toString` and `constructor` became "tables" under a dictionary.
|
|
5408
5559
|
*/
|
|
5409
5560
|
const isProbedName = (prop) => prop === "then" || prop === "toJSON" || prop === "$$typeof";
|
|
5410
5561
|
const isReservedName = (prop) => isProbedName(prop) || prop in Object.prototype;
|
|
5411
5562
|
const dataProxy = new Proxy(dataTarget, {
|
|
5412
5563
|
get(_target, prop) {
|
|
5413
|
-
if (prop === "
|
|
5564
|
+
if (prop === "table") return table;
|
|
5414
5565
|
if (prop === "batch") return batch;
|
|
5415
5566
|
if (typeof prop === "symbol") return void 0;
|
|
5416
5567
|
if (isProbedName(prop)) return void 0;
|
|
5417
|
-
if (options.
|
|
5568
|
+
if (options.tables && Object.hasOwn(options.tables, prop)) return table(options.tables[prop]);
|
|
5418
5569
|
if (prop in Object.prototype) return Reflect.get(_target, prop);
|
|
5419
|
-
if (options.
|
|
5420
|
-
const knownKeys = Object.keys(options.
|
|
5421
|
-
const suggestion =
|
|
5422
|
-
let msg = `Unknown
|
|
5570
|
+
if (options.tables) {
|
|
5571
|
+
const knownKeys = Object.keys(options.tables);
|
|
5572
|
+
const suggestion = suggestTable(prop, knownKeys);
|
|
5573
|
+
let msg = `Unknown table accessor "${prop}". Known tables: ${knownKeys.join(", ")}.`;
|
|
5423
5574
|
if (suggestion) msg += ` Did you mean "${suggestion}"?`;
|
|
5424
|
-
msg += ` Use data.
|
|
5575
|
+
msg += ` Use data.table("<slug>") for dynamic slugs.`;
|
|
5425
5576
|
throw new RebaseClientError(msg, {
|
|
5426
|
-
code: "
|
|
5577
|
+
code: "UNKNOWN_TABLE",
|
|
5427
5578
|
details: {
|
|
5428
5579
|
accessor: prop,
|
|
5429
5580
|
known: knownKeys
|
|
@@ -5433,15 +5584,15 @@ function createRebaseClient(options) {
|
|
|
5433
5584
|
const slug = toSnakeCase(prop);
|
|
5434
5585
|
if (!untypedWarned) {
|
|
5435
5586
|
untypedWarned = true;
|
|
5436
|
-
console.warn(`[Rebase] Untyped data access detected: client.data.${prop} was sent to /data/${slug}, its name in snake_case, because this client has no \`
|
|
5587
|
+
console.warn(`[Rebase] Untyped data access detected: client.data.${prop} was sent to /data/${slug}, its name in snake_case, because this client has no \`tables\` dictionary. A table whose slug is not that (a kebab-case slug, a renamed accessor) answers 404. With generated types, pass \`tables: tablesDictionary\` (from generated/sdk/database.types) to createRebaseClient(); a typed client needs it. Otherwise use client.data.table("<slug>").`);
|
|
5437
5588
|
}
|
|
5438
|
-
return
|
|
5589
|
+
return table(slug);
|
|
5439
5590
|
},
|
|
5440
5591
|
has(_target, prop) {
|
|
5441
|
-
if (prop === "
|
|
5592
|
+
if (prop === "table" || prop === "batch") return true;
|
|
5442
5593
|
if (typeof prop === "symbol") return false;
|
|
5443
5594
|
if (isProbedName(prop)) return false;
|
|
5444
|
-
if (options.
|
|
5595
|
+
if (options.tables) return Object.hasOwn(options.tables, prop);
|
|
5445
5596
|
return !isReservedName(prop);
|
|
5446
5597
|
}
|
|
5447
5598
|
});
|
|
@@ -5450,6 +5601,7 @@ function createRebaseClient(options) {
|
|
|
5450
5601
|
admin,
|
|
5451
5602
|
cron,
|
|
5452
5603
|
backups,
|
|
5604
|
+
schema,
|
|
5453
5605
|
apiKeys,
|
|
5454
5606
|
personalKeys,
|
|
5455
5607
|
functions,
|
|
@@ -5509,7 +5661,7 @@ function createRebaseClient(options) {
|
|
|
5509
5661
|
baseUrl: options.baseUrl,
|
|
5510
5662
|
apiPath: options.apiPath,
|
|
5511
5663
|
fetch: options.fetch,
|
|
5512
|
-
|
|
5664
|
+
tables: options.tables,
|
|
5513
5665
|
schemaVersion: options.schemaVersion,
|
|
5514
5666
|
headers: {
|
|
5515
5667
|
...options.headers ?? {},
|
|
@@ -5528,7 +5680,7 @@ function createRebaseClient(options) {
|
|
|
5528
5680
|
},
|
|
5529
5681
|
baseUrl: transport.baseUrl,
|
|
5530
5682
|
apiPath: transport.apiPath,
|
|
5531
|
-
|
|
5683
|
+
table,
|
|
5532
5684
|
call: async (endpoint, payload) => {
|
|
5533
5685
|
const prefix = endpoint.startsWith("/") ? "" : "/";
|
|
5534
5686
|
return transport.request(`${prefix}${endpoint}`, {
|
|
@@ -5542,6 +5694,6 @@ function createRebaseClient(options) {
|
|
|
5542
5694
|
};
|
|
5543
5695
|
}
|
|
5544
5696
|
//#endregion
|
|
5545
|
-
export { APPLE_JS_SDK_URL, MemoryOfflineStore, RebaseApiError, RebaseClientError, RebasePaginationError, RebaseRealtimeChannel, RebaseWebSocketClient, STORAGE_REFERENCE_SCHEME, and, cond, createCookieStorage, createMemoryStorage, createRebaseClient, etagOf, isOfflineError, isStorageReference, not, or, parseStorageReference, preloadAppleSignIn, requestAppleAuthorization, resolveStorageReferences, storageReference, storageReferencesForDownloadUrls, storageTargetOfDownloadUrl, storageTargetsInText };
|
|
5697
|
+
export { APPLE_JS_SDK_URL, MemoryOfflineStore, RebaseApiError, RebaseClientError, RebasePaginationError, RebaseRealtimeChannel, RebaseWebSocketClient, SCHEMA_UNAVAILABLE, STORAGE_REFERENCE_SCHEME, and, cond, createCookieStorage, createMemoryStorage, createRebaseClient, etagOf, isOfflineError, isSchemaUnavailable, isStorageReference, not, or, parseStorageReference, preloadAppleSignIn, requestAppleAuthorization, resolveStorageReferences, storageReference, storageReferencesForDownloadUrls, storageTargetOfDownloadUrl, storageTargetsInText };
|
|
5546
5698
|
|
|
5547
5699
|
//# sourceMappingURL=index.es.js.map
|