@rebasepro/client 0.30.1 → 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/client-contract.types.d.ts +25 -0
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +33 -28
- package/dist/index.es.js +133 -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";
|
|
@@ -2004,6 +2004,76 @@ function saveFrom(url, fileName) {
|
|
|
2004
2004
|
a.remove();
|
|
2005
2005
|
}
|
|
2006
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
|
|
2007
2077
|
//#region src/api-keys.ts
|
|
2008
2078
|
/**
|
|
2009
2079
|
* Creates a client for the project's service keys, via the admin routes.
|
|
@@ -2777,6 +2847,13 @@ function channelErrorCode(message) {
|
|
|
2777
2847
|
const raw = message.payload?.error;
|
|
2778
2848
|
if (raw && typeof raw === "object" && "code" in raw && typeof raw.code === "string") return raw.code;
|
|
2779
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
|
+
}
|
|
2780
2857
|
var RebaseWebSocketClient = class {
|
|
2781
2858
|
websocketUrl;
|
|
2782
2859
|
affinity;
|
|
@@ -3280,7 +3357,7 @@ var RebaseWebSocketClient = class {
|
|
|
3280
3357
|
this.ws.onmessage = (event) => {
|
|
3281
3358
|
this.lastFrameAt = Date.now();
|
|
3282
3359
|
try {
|
|
3283
|
-
const message =
|
|
3360
|
+
const message = JSON.parse(String(event.data));
|
|
3284
3361
|
this.handleWebSocketMessage(message);
|
|
3285
3362
|
} catch (error) {
|
|
3286
3363
|
console.error("Error parsing WebSocket message:", error);
|
|
@@ -3597,7 +3674,7 @@ var RebaseWebSocketClient = class {
|
|
|
3597
3674
|
try {
|
|
3598
3675
|
callback.onUpdate(rows, collectionSub.latestMeta);
|
|
3599
3676
|
} catch (error) {
|
|
3600
|
-
console.error("Error in
|
|
3677
|
+
console.error("Error in table subscription callback:", error);
|
|
3601
3678
|
if (callback.onError) callback.onError(error instanceof Error ? error : new Error(String(error)));
|
|
3602
3679
|
}
|
|
3603
3680
|
});
|
|
@@ -3945,15 +4022,14 @@ var RebaseWebSocketClient = class {
|
|
|
3945
4022
|
async fetchCurrentDatabase() {
|
|
3946
4023
|
return (await this.sendMessage({ type: "FETCH_CURRENT_DATABASE" })).database;
|
|
3947
4024
|
}
|
|
3948
|
-
async checkUniqueField(path, name, value, id
|
|
4025
|
+
async checkUniqueField(path, name, value, id) {
|
|
3949
4026
|
return (await this.sendMessage({
|
|
3950
4027
|
type: "CHECK_UNIQUE_FIELD",
|
|
3951
4028
|
payload: {
|
|
3952
4029
|
path,
|
|
3953
4030
|
name,
|
|
3954
4031
|
value,
|
|
3955
|
-
id
|
|
3956
|
-
collection
|
|
4032
|
+
id
|
|
3957
4033
|
}
|
|
3958
4034
|
})).isUnique;
|
|
3959
4035
|
}
|
|
@@ -4020,17 +4096,11 @@ var RebaseWebSocketClient = class {
|
|
|
4020
4096
|
/**
|
|
4021
4097
|
* Recursively compare two values a refetch can carry for structural
|
|
4022
4098
|
* equality: primitives, null, undefined, Date, RegExp, arrays and objects.
|
|
4023
|
-
*
|
|
4024
|
-
*
|
|
4025
|
-
*
|
|
4026
|
-
* done by normalising each side into a copy first — two deep copies of
|
|
4027
|
-
* every cached row on every frame, most of which then compared equal. It is
|
|
4028
|
-
* done in place now, and an unchanged row costs no copy.
|
|
4029
|
-
*
|
|
4030
|
-
* `relationAware` is off for a relation's own fields: the copies never
|
|
4031
|
-
* 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.
|
|
4032
4102
|
*/
|
|
4033
|
-
deepEqual(a, b
|
|
4103
|
+
deepEqual(a, b) {
|
|
4034
4104
|
if (a === b) return true;
|
|
4035
4105
|
if (a === null || b === null || a === void 0 || b === void 0) return false;
|
|
4036
4106
|
if (typeof a !== typeof b) return false;
|
|
@@ -4044,31 +4114,17 @@ var RebaseWebSocketClient = class {
|
|
|
4044
4114
|
if (aIsArray !== bIsArray) return false;
|
|
4045
4115
|
if (aIsArray && bIsArray) {
|
|
4046
4116
|
if (a.length !== b.length) return false;
|
|
4047
|
-
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;
|
|
4048
4118
|
return true;
|
|
4049
4119
|
}
|
|
4050
4120
|
const aObj = a;
|
|
4051
4121
|
const bObj = b;
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
if (relationAware) {
|
|
4055
|
-
const aIsRelation = aObj.__type === "relation";
|
|
4056
|
-
if (aIsRelation !== (bObj.__type === "relation")) return false;
|
|
4057
|
-
if (aIsRelation) {
|
|
4058
|
-
skip = "data";
|
|
4059
|
-
nested = false;
|
|
4060
|
-
}
|
|
4061
|
-
}
|
|
4062
|
-
let aCount = 0;
|
|
4063
|
-
for (const key of Object.keys(aObj)) {
|
|
4064
|
-
if (key === skip) continue;
|
|
4065
|
-
aCount++;
|
|
4122
|
+
const aKeys = Object.keys(aObj);
|
|
4123
|
+
for (const key of aKeys) {
|
|
4066
4124
|
if (!Object.prototype.hasOwnProperty.call(bObj, key)) return false;
|
|
4067
|
-
if (!this.deepEqual(aObj[key], bObj[key]
|
|
4125
|
+
if (!this.deepEqual(aObj[key], bObj[key])) return false;
|
|
4068
4126
|
}
|
|
4069
|
-
|
|
4070
|
-
for (const key of Object.keys(bObj)) if (key !== skip) bCount++;
|
|
4071
|
-
return aCount === bCount;
|
|
4127
|
+
return aKeys.length === Object.keys(bObj).length;
|
|
4072
4128
|
}
|
|
4073
4129
|
/**
|
|
4074
4130
|
* The address of a row, for matching it against another copy of itself.
|
|
@@ -4134,7 +4190,7 @@ var RebaseWebSocketClient = class {
|
|
|
4134
4190
|
if (existingSubscription.latestData !== void 0 && existingSubscription.isInitialDataReceived) try {
|
|
4135
4191
|
onUpdate(existingSubscription.latestData, existingSubscription.latestMeta);
|
|
4136
4192
|
} catch (error) {
|
|
4137
|
-
console.error("Error in
|
|
4193
|
+
console.error("Error in table subscription callback:", error);
|
|
4138
4194
|
if (onError) onError(error instanceof Error ? error : new Error(String(error)));
|
|
4139
4195
|
}
|
|
4140
4196
|
else if (!existingSubscription.subscribeInFlight) this.sendCollectionSubscribe(subscriptionKey);
|
|
@@ -4318,7 +4374,7 @@ var RebaseWebSocketClient = class {
|
|
|
4318
4374
|
if (callback.onError) try {
|
|
4319
4375
|
callback.onError(error);
|
|
4320
4376
|
} catch (callbackError) {
|
|
4321
|
-
console.error("Error in
|
|
4377
|
+
console.error("Error in table subscription error callback:", callbackError);
|
|
4322
4378
|
}
|
|
4323
4379
|
});
|
|
4324
4380
|
}
|
|
@@ -4412,7 +4468,7 @@ var RebaseWebSocketClient = class {
|
|
|
4412
4468
|
* we need to re-register everything to resume receiving updates.
|
|
4413
4469
|
*/
|
|
4414
4470
|
resubscribeAll() {
|
|
4415
|
-
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)`);
|
|
4416
4472
|
for (const [key, sub] of this.collectionSubscriptions.entries()) {
|
|
4417
4473
|
if (sub.subscribeInFlight) continue;
|
|
4418
4474
|
const oldBackendId = sub.backendSubscriptionId;
|
|
@@ -4433,10 +4489,10 @@ var RebaseWebSocketClient = class {
|
|
|
4433
4489
|
}
|
|
4434
4490
|
}
|
|
4435
4491
|
createCollectionSubscriptionKey(props) {
|
|
4436
|
-
const
|
|
4492
|
+
const viewCollection = Reflect.get(props, "collection");
|
|
4437
4493
|
const key = {
|
|
4438
|
-
...
|
|
4439
|
-
collection:
|
|
4494
|
+
...props,
|
|
4495
|
+
collection: viewCollectionName(viewCollection)
|
|
4440
4496
|
};
|
|
4441
4497
|
return JSON.stringify(key, (_, value) => {
|
|
4442
4498
|
if (value && typeof value === "object" && !Array.isArray(value)) return Object.keys(value).sort().reduce((sorted, k) => {
|
|
@@ -5081,7 +5137,7 @@ function rejoinsAfter(code, message) {
|
|
|
5081
5137
|
*
|
|
5082
5138
|
* - Calls made before the engine has arrived are queued and run, in the order
|
|
5083
5139
|
* they were made, the moment it does — the scope changes the factory makes
|
|
5084
|
-
* from auth events, and every
|
|
5140
|
+
* from auth events, and every table a client wrapped meanwhile.
|
|
5085
5141
|
* - What answers with a promise waits for the engine and then asks it.
|
|
5086
5142
|
* - What answers synchronously answers what the engine would have before
|
|
5087
5143
|
* anything ran: `status()` is the initial status, a subscription is
|
|
@@ -5101,7 +5157,7 @@ var LazyOfflineManager = class {
|
|
|
5101
5157
|
keepsLastUser;
|
|
5102
5158
|
constructor(config, createInner) {
|
|
5103
5159
|
this.keepsLastUser = config.keepLastUser === true;
|
|
5104
|
-
import("./offline-
|
|
5160
|
+
import("./offline-D_wKJcO3.js").then(({ OfflineManager: Engine }) => {
|
|
5105
5161
|
const engine = new Engine(config, createInner);
|
|
5106
5162
|
this.engine = engine;
|
|
5107
5163
|
const queued = this.queued;
|
|
@@ -5294,6 +5350,7 @@ function createRebaseClient(options) {
|
|
|
5294
5350
|
const admin = createAdmin(transport, options.admin);
|
|
5295
5351
|
const cron = createCron(transport, options.cron);
|
|
5296
5352
|
const backups = createBackups(transport);
|
|
5353
|
+
const schema = createSchema(transport);
|
|
5297
5354
|
const apiKeys = createApiKeys(transport, options.apiKeys);
|
|
5298
5355
|
const personalKeys = createPersonalKeys(transport, options.personalKeys);
|
|
5299
5356
|
const storage = createStorage(transport);
|
|
@@ -5366,10 +5423,10 @@ function createRebaseClient(options) {
|
|
|
5366
5423
|
});
|
|
5367
5424
|
}
|
|
5368
5425
|
/**
|
|
5369
|
-
* Suggest the closest known
|
|
5426
|
+
* Suggest the closest known table key for a mistyped accessor.
|
|
5370
5427
|
* Uses edit-distance-1 and prefix matching — no external dependency.
|
|
5371
5428
|
*/
|
|
5372
|
-
function
|
|
5429
|
+
function suggestTable(prop, knownKeys) {
|
|
5373
5430
|
const prefixMatch = knownKeys.find((k) => k.startsWith(prop) || prop.startsWith(k));
|
|
5374
5431
|
if (prefixMatch) return prefixMatch;
|
|
5375
5432
|
for (const key of knownKeys) {
|
|
@@ -5402,7 +5459,7 @@ function createRebaseClient(options) {
|
|
|
5402
5459
|
if (diffs <= 1) return key;
|
|
5403
5460
|
}
|
|
5404
5461
|
}
|
|
5405
|
-
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;
|
|
5406
5463
|
if (offlineManager) {
|
|
5407
5464
|
offlineManager.holdScope();
|
|
5408
5465
|
auth.onAuthStateChange((event, session) => {
|
|
@@ -5449,14 +5506,14 @@ function createRebaseClient(options) {
|
|
|
5449
5506
|
ws.disconnect();
|
|
5450
5507
|
ws.ensureConnected();
|
|
5451
5508
|
}
|
|
5452
|
-
const
|
|
5509
|
+
const tableClients = /* @__PURE__ */ new Map();
|
|
5453
5510
|
let untypedWarned = false;
|
|
5454
|
-
function
|
|
5455
|
-
if (!
|
|
5456
|
-
const inner =
|
|
5457
|
-
|
|
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);
|
|
5458
5515
|
}
|
|
5459
|
-
return
|
|
5516
|
+
return tableClients.get(slug);
|
|
5460
5517
|
}
|
|
5461
5518
|
/**
|
|
5462
5519
|
* `client.batch()`, and `client.data.batch()` — the same function, so the
|
|
@@ -5472,13 +5529,13 @@ function createRebaseClient(options) {
|
|
|
5472
5529
|
const headers = {};
|
|
5473
5530
|
if (batchOptions?.idempotencyKey) headers["Idempotency-Key"] = batchOptions.idempotencyKey;
|
|
5474
5531
|
if (batchOptions?.returning === false) headers.Prefer = "return=minimal";
|
|
5475
|
-
const dictionary = options.
|
|
5532
|
+
const dictionary = options.tables;
|
|
5476
5533
|
const wire = dictionary ? operations.map((operation) => {
|
|
5477
5534
|
if (!operation || typeof operation !== "object") return operation;
|
|
5478
|
-
const name = operation.
|
|
5535
|
+
const name = operation.table;
|
|
5479
5536
|
return typeof name === "string" && Object.hasOwn(dictionary, name) ? {
|
|
5480
5537
|
...operation,
|
|
5481
|
-
|
|
5538
|
+
table: dictionary[name]
|
|
5482
5539
|
} : operation;
|
|
5483
5540
|
}) : operations;
|
|
5484
5541
|
return transport.request("/data/_batch", {
|
|
@@ -5488,36 +5545,36 @@ function createRebaseClient(options) {
|
|
|
5488
5545
|
});
|
|
5489
5546
|
};
|
|
5490
5547
|
const dataTarget = {
|
|
5491
|
-
|
|
5548
|
+
table,
|
|
5492
5549
|
batch
|
|
5493
5550
|
};
|
|
5494
5551
|
/**
|
|
5495
|
-
* Names the proxy never serves as a
|
|
5552
|
+
* Names the proxy never serves as a table: the ones promise and
|
|
5496
5553
|
* serialisation machinery probe for (`then`, `toJSON`, React's
|
|
5497
5554
|
* `$$typeof`), and everything a plain object inherits — so
|
|
5498
|
-
* `client.data.toString` is `Object.prototype.toString`, not a
|
|
5555
|
+
* `client.data.toString` is `Object.prototype.toString`, not a table
|
|
5499
5556
|
* client, and `String(client.data)` is `"[object Object]"` rather than a
|
|
5500
|
-
* throw. `prop in
|
|
5501
|
-
* `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.
|
|
5502
5559
|
*/
|
|
5503
5560
|
const isProbedName = (prop) => prop === "then" || prop === "toJSON" || prop === "$$typeof";
|
|
5504
5561
|
const isReservedName = (prop) => isProbedName(prop) || prop in Object.prototype;
|
|
5505
5562
|
const dataProxy = new Proxy(dataTarget, {
|
|
5506
5563
|
get(_target, prop) {
|
|
5507
|
-
if (prop === "
|
|
5564
|
+
if (prop === "table") return table;
|
|
5508
5565
|
if (prop === "batch") return batch;
|
|
5509
5566
|
if (typeof prop === "symbol") return void 0;
|
|
5510
5567
|
if (isProbedName(prop)) return void 0;
|
|
5511
|
-
if (options.
|
|
5568
|
+
if (options.tables && Object.hasOwn(options.tables, prop)) return table(options.tables[prop]);
|
|
5512
5569
|
if (prop in Object.prototype) return Reflect.get(_target, prop);
|
|
5513
|
-
if (options.
|
|
5514
|
-
const knownKeys = Object.keys(options.
|
|
5515
|
-
const suggestion =
|
|
5516
|
-
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(", ")}.`;
|
|
5517
5574
|
if (suggestion) msg += ` Did you mean "${suggestion}"?`;
|
|
5518
|
-
msg += ` Use data.
|
|
5575
|
+
msg += ` Use data.table("<slug>") for dynamic slugs.`;
|
|
5519
5576
|
throw new RebaseClientError(msg, {
|
|
5520
|
-
code: "
|
|
5577
|
+
code: "UNKNOWN_TABLE",
|
|
5521
5578
|
details: {
|
|
5522
5579
|
accessor: prop,
|
|
5523
5580
|
known: knownKeys
|
|
@@ -5527,15 +5584,15 @@ function createRebaseClient(options) {
|
|
|
5527
5584
|
const slug = toSnakeCase(prop);
|
|
5528
5585
|
if (!untypedWarned) {
|
|
5529
5586
|
untypedWarned = true;
|
|
5530
|
-
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>").`);
|
|
5531
5588
|
}
|
|
5532
|
-
return
|
|
5589
|
+
return table(slug);
|
|
5533
5590
|
},
|
|
5534
5591
|
has(_target, prop) {
|
|
5535
|
-
if (prop === "
|
|
5592
|
+
if (prop === "table" || prop === "batch") return true;
|
|
5536
5593
|
if (typeof prop === "symbol") return false;
|
|
5537
5594
|
if (isProbedName(prop)) return false;
|
|
5538
|
-
if (options.
|
|
5595
|
+
if (options.tables) return Object.hasOwn(options.tables, prop);
|
|
5539
5596
|
return !isReservedName(prop);
|
|
5540
5597
|
}
|
|
5541
5598
|
});
|
|
@@ -5544,6 +5601,7 @@ function createRebaseClient(options) {
|
|
|
5544
5601
|
admin,
|
|
5545
5602
|
cron,
|
|
5546
5603
|
backups,
|
|
5604
|
+
schema,
|
|
5547
5605
|
apiKeys,
|
|
5548
5606
|
personalKeys,
|
|
5549
5607
|
functions,
|
|
@@ -5603,7 +5661,7 @@ function createRebaseClient(options) {
|
|
|
5603
5661
|
baseUrl: options.baseUrl,
|
|
5604
5662
|
apiPath: options.apiPath,
|
|
5605
5663
|
fetch: options.fetch,
|
|
5606
|
-
|
|
5664
|
+
tables: options.tables,
|
|
5607
5665
|
schemaVersion: options.schemaVersion,
|
|
5608
5666
|
headers: {
|
|
5609
5667
|
...options.headers ?? {},
|
|
@@ -5622,7 +5680,7 @@ function createRebaseClient(options) {
|
|
|
5622
5680
|
},
|
|
5623
5681
|
baseUrl: transport.baseUrl,
|
|
5624
5682
|
apiPath: transport.apiPath,
|
|
5625
|
-
|
|
5683
|
+
table,
|
|
5626
5684
|
call: async (endpoint, payload) => {
|
|
5627
5685
|
const prefix = endpoint.startsWith("/") ? "" : "/";
|
|
5628
5686
|
return transport.request(`${prefix}${endpoint}`, {
|
|
@@ -5636,6 +5694,6 @@ function createRebaseClient(options) {
|
|
|
5636
5694
|
};
|
|
5637
5695
|
}
|
|
5638
5696
|
//#endregion
|
|
5639
|
-
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 };
|
|
5640
5698
|
|
|
5641
5699
|
//# sourceMappingURL=index.es.js.map
|