@rebasepro/client 0.29.1 → 0.29.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.
- package/dist/auth.d.ts +1 -1
- package/dist/client-contract.types.d.ts +57 -0
- package/dist/collection.d.ts +9 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +42 -30
- package/dist/index.es.js.map +1 -1
- package/dist/{offline-Cy6woFyt.js → offline-B6J1YUWF.js} +69 -9
- package/dist/offline-B6J1YUWF.js.map +1 -0
- package/dist/offline-connectivity.d.ts +8 -2
- package/dist/{offline-store-C2Sy3Kwl.js → offline-store-B7F5mimt.js} +51 -6
- package/dist/offline-store-B7F5mimt.js.map +1 -0
- package/dist/offline.d.ts +9 -0
- package/dist/transport.d.ts +15 -1
- package/dist/websocket.d.ts +34 -1
- package/package.json +4 -4
- package/dist/offline-Cy6woFyt.js.map +0 -1
- package/dist/offline-store-C2Sy3Kwl.js.map +0 -1
package/dist/auth.d.ts
CHANGED
|
@@ -275,7 +275,7 @@ export declare function createAuth(transport: Transport, options?: CreateAuthOpt
|
|
|
275
275
|
*
|
|
276
276
|
* This is where an MFA-enrolled account's real session is minted, at
|
|
277
277
|
* `aal2` — so this client adopts the returned tokens and announces
|
|
278
|
-
* `SIGNED_IN`, exactly
|
|
278
|
+
* `SIGNED_IN`, exactly like any other sign-in. Pass the same
|
|
279
279
|
* `mfaToken` the challenge was opened with when finishing a sign-in.
|
|
280
280
|
*/
|
|
281
281
|
verifyChallenge(challengeId: string, code: string, options?: MfaPendingOptions): Promise<{
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-time assertion that what `createRebaseClient()` returns is a
|
|
3
|
+
* `RebaseClient` — the type `<Rebase client={…}>` takes.
|
|
4
|
+
*
|
|
5
|
+
* A plain module under `src`, imported by nothing, for the reason
|
|
6
|
+
* `query-contract.types.ts` gives: `pnpm typecheck` reads `src`, and a type
|
|
7
|
+
* assertion in a jest test is checked by nothing.
|
|
8
|
+
*
|
|
9
|
+
* ## What went wrong that this exists to prevent
|
|
10
|
+
*
|
|
11
|
+
* 0.29.2 added `batch` to `RebaseSdkData`, and the typed data layer kept
|
|
12
|
+
* picking `collection` alone. A `createRebaseClient<Database>()` stopped being
|
|
13
|
+
* a `RebaseClient<Database>`, and every app passing one to `<Rebase>` — the
|
|
14
|
+
* Cloud console among them — stopped compiling. Nothing in this repo passes a
|
|
15
|
+
* typed client anywhere that wants a `RebaseClient`, so nothing here noticed.
|
|
16
|
+
*/
|
|
17
|
+
import type { RebaseClient } from "@rebasepro/types";
|
|
18
|
+
/**
|
|
19
|
+
* Shaped the way the generator writes one: an `interface` (no implicit index
|
|
20
|
+
* signature, so the typed branch of `TypedDataLayer` is taken) whose entries
|
|
21
|
+
* carry `Row`, `Insert`, `Update` and `Slug`.
|
|
22
|
+
*/
|
|
23
|
+
interface ContractDatabase {
|
|
24
|
+
orders: {
|
|
25
|
+
Row: {
|
|
26
|
+
id: string;
|
|
27
|
+
total: number;
|
|
28
|
+
};
|
|
29
|
+
Insert: {
|
|
30
|
+
total: number;
|
|
31
|
+
};
|
|
32
|
+
Update: {
|
|
33
|
+
total?: number;
|
|
34
|
+
};
|
|
35
|
+
Slug: "orders";
|
|
36
|
+
};
|
|
37
|
+
orderItems: {
|
|
38
|
+
Row: {
|
|
39
|
+
id: string;
|
|
40
|
+
order_id: string;
|
|
41
|
+
sku: string;
|
|
42
|
+
};
|
|
43
|
+
Insert: {
|
|
44
|
+
order_id: string;
|
|
45
|
+
sku: string;
|
|
46
|
+
};
|
|
47
|
+
Update: {
|
|
48
|
+
sku?: string;
|
|
49
|
+
};
|
|
50
|
+
Slug: "order_items";
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export declare const typedIsARebaseClient: RebaseClient<ContractDatabase>;
|
|
54
|
+
export declare const untypedIsARebaseClient: RebaseClient;
|
|
55
|
+
/** `data.batch` takes the accessor names, as `client.batch` does. */
|
|
56
|
+
export declare const typedDataBatch: () => Promise<import("@rebasepro/types").BatchResult<Record<string, unknown>>>;
|
|
57
|
+
export {};
|
package/dist/collection.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { FindParams, Transport } from "./transport.js";
|
|
2
|
-
import { RebaseWebSocketClient } from "./websocket.js";
|
|
2
|
+
import type { RebaseWebSocketClient } from "./websocket.js";
|
|
3
3
|
import { FindResult, SDKCollectionClient, type ByIdReadOptions, type IncludeSpec, type RestoreOptions, type TrashClient, RebaseClientError } from "@rebasepro/types";
|
|
4
4
|
import { etagOf } from "@rebasepro/common";
|
|
5
|
+
/**
|
|
6
|
+
* The part of a {@link Transport} a collection client uses: its requests, and
|
|
7
|
+
* the address they go to (to tell when a query is too long for a URL).
|
|
8
|
+
*/
|
|
9
|
+
export type CollectionTransport = Pick<Transport, "request" | "baseUrl" | "apiPath">;
|
|
10
|
+
/** The part of the realtime client a collection client listens through. */
|
|
11
|
+
export type CollectionRealtime = Pick<RebaseWebSocketClient, "listenCollection" | "listenOne">;
|
|
5
12
|
/**
|
|
6
13
|
* A bulk call given something other than an array. A `RebaseClientError` with
|
|
7
14
|
* the code the server uses for the same mistake in a request body, so one
|
|
@@ -103,4 +110,4 @@ export interface CollectionClient<M extends Record<string, unknown> = Record<str
|
|
|
103
110
|
* nothing else, so `realtime` never travels as a query parameter.
|
|
104
111
|
*/
|
|
105
112
|
export declare function byIdRead<Inc>(options: ObserveByIdOptions<Inc> | undefined): ByIdReadOptions<Inc> | undefined;
|
|
106
|
-
export declare function createCollectionClient<M extends Record<string, unknown> = Record<string, unknown>>(transport:
|
|
113
|
+
export declare function createCollectionClient<M extends Record<string, unknown> = Record<string, unknown>>(transport: CollectionTransport, slug: string, ws?: CollectionRealtime): CollectionClient<M>;
|
package/dist/index.d.ts
CHANGED
|
@@ -113,7 +113,7 @@ type TypedDataLayer<DB> = {
|
|
|
113
113
|
collection<S extends string>(slug: S): CollectionClient<RowOf<DBEntry<DB, S>>, InsertOf<DBEntry<DB, S>>, UpdateOf<DBEntry<DB, S>>, IncludeOf<DBEntry<DB, S>, DB>>;
|
|
114
114
|
} & {
|
|
115
115
|
[K in keyof DB]: CollectionClient<RowOf<DB[K]>, InsertOf<DB[K]>, UpdateOf<DB[K]>, IncludeOf<DB[K], DB>>;
|
|
116
|
-
} & (string extends keyof DB ? RebaseSdkData : Pick<RebaseSdkData, "collection">);
|
|
116
|
+
} & (string extends keyof DB ? RebaseSdkData : Pick<RebaseSdkData, "collection"> & Pick<RebaseSdkData<DB>, "batch">);
|
|
117
117
|
/**
|
|
118
118
|
* The return type of `createRebaseClient<DB>()`.
|
|
119
119
|
*
|
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as invalidBulkBody, d as RebaseApiError, h as parseRebaseJson, i as isOfflineError, l as SDKQueryBuilder, m as defaultCodeForStatus, n as MemoryOfflineStore, o as createCollectionClient, p as createTransport, s as etagOf, u as RebaseClientError } from "./offline-store-
|
|
1
|
+
import { c as invalidBulkBody, d as RebaseApiError, h as parseRebaseJson, i as isOfflineError, l as SDKQueryBuilder, m as defaultCodeForStatus, n as MemoryOfflineStore, o as createCollectionClient, p as createTransport, s as etagOf, u as RebaseClientError } from "./offline-store-B7F5mimt.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";
|
|
@@ -1392,7 +1392,7 @@ function createAuth(transport, options) {
|
|
|
1392
1392
|
*
|
|
1393
1393
|
* This is where an MFA-enrolled account's real session is minted, at
|
|
1394
1394
|
* `aal2` — so this client adopts the returned tokens and announces
|
|
1395
|
-
* `SIGNED_IN`, exactly
|
|
1395
|
+
* `SIGNED_IN`, exactly like any other sign-in. Pass the same
|
|
1396
1396
|
* `mfaToken` the challenge was opened with when finishing a sign-in.
|
|
1397
1397
|
*/
|
|
1398
1398
|
async verifyChallenge(challengeId, code, options) {
|
|
@@ -3185,7 +3185,7 @@ var RebaseWebSocketClient = class {
|
|
|
3185
3185
|
this.ws.onmessage = (event) => {
|
|
3186
3186
|
this.lastFrameAt = Date.now();
|
|
3187
3187
|
try {
|
|
3188
|
-
const message = parseRebaseJson(event.data);
|
|
3188
|
+
const message = parseRebaseJson(String(event.data));
|
|
3189
3189
|
this.handleWebSocketMessage(message);
|
|
3190
3190
|
} catch (error) {
|
|
3191
3191
|
console.error("Error parsing WebSocket message:", error);
|
|
@@ -5006,7 +5006,7 @@ var LazyOfflineManager = class {
|
|
|
5006
5006
|
keepsLastUser;
|
|
5007
5007
|
constructor(config, createInner) {
|
|
5008
5008
|
this.keepsLastUser = config.keepLastUser === true;
|
|
5009
|
-
import("./offline-
|
|
5009
|
+
import("./offline-B6J1YUWF.js").then(({ OfflineManager: Engine }) => {
|
|
5010
5010
|
const engine = new Engine(config, createInner);
|
|
5011
5011
|
this.engine = engine;
|
|
5012
5012
|
const queued = this.queued;
|
|
@@ -5118,6 +5118,8 @@ var LazyOfflineManager = class {
|
|
|
5118
5118
|
upsert: async (data, options) => (await client()).upsert(data, options),
|
|
5119
5119
|
updateMany: async (updates, options) => (await client()).updateMany(updates, options),
|
|
5120
5120
|
deleteMany: async (ids, options) => (await client()).deleteMany(ids, options),
|
|
5121
|
+
updateWhere: async (query, data, options) => (await client()).updateWhere(query, data, options),
|
|
5122
|
+
deleteWhere: async (query, options) => (await client()).deleteWhere(query, options),
|
|
5121
5123
|
update: async (id, data, options) => (await client()).update(id, data, options),
|
|
5122
5124
|
delete: async (id, options) => (await client()).delete(id, options),
|
|
5123
5125
|
count: async (params) => (await client()).count(params),
|
|
@@ -5361,7 +5363,39 @@ function createRebaseClient(options) {
|
|
|
5361
5363
|
}
|
|
5362
5364
|
return collectionClients.get(slug);
|
|
5363
5365
|
}
|
|
5364
|
-
|
|
5366
|
+
/**
|
|
5367
|
+
* `client.batch()`, and `client.data.batch()` — the same function, so the
|
|
5368
|
+
* HTTP client's data layer is the `RebaseSdkData` that `<Rebase>` and the
|
|
5369
|
+
* in-process `context.data` take.
|
|
5370
|
+
*/
|
|
5371
|
+
const batch = async (operations, batchOptions) => {
|
|
5372
|
+
if (!Array.isArray(operations)) throw invalidBulkBody("batch expects an array of operations.");
|
|
5373
|
+
if (operations.length === 0) return {
|
|
5374
|
+
data: [],
|
|
5375
|
+
meta: { operations: 0 }
|
|
5376
|
+
};
|
|
5377
|
+
const headers = {};
|
|
5378
|
+
if (batchOptions?.idempotencyKey) headers["Idempotency-Key"] = batchOptions.idempotencyKey;
|
|
5379
|
+
if (batchOptions?.returning === false) headers.Prefer = "return=minimal";
|
|
5380
|
+
const dictionary = options.collections;
|
|
5381
|
+
const wire = dictionary ? operations.map((operation) => {
|
|
5382
|
+
if (!operation || typeof operation !== "object") return operation;
|
|
5383
|
+
const name = operation.collection;
|
|
5384
|
+
return typeof name === "string" && Object.hasOwn(dictionary, name) ? {
|
|
5385
|
+
...operation,
|
|
5386
|
+
collection: dictionary[name]
|
|
5387
|
+
} : operation;
|
|
5388
|
+
}) : operations;
|
|
5389
|
+
return transport.request("/data/_batch", {
|
|
5390
|
+
method: "POST",
|
|
5391
|
+
body: JSON.stringify({ operations: wire }),
|
|
5392
|
+
...Object.keys(headers).length > 0 ? { headers } : {}
|
|
5393
|
+
});
|
|
5394
|
+
};
|
|
5395
|
+
const dataTarget = {
|
|
5396
|
+
collection,
|
|
5397
|
+
batch
|
|
5398
|
+
};
|
|
5365
5399
|
/**
|
|
5366
5400
|
* Names the proxy never serves as a collection: the ones promise and
|
|
5367
5401
|
* serialisation machinery probe for (`then`, `toJSON`, React's
|
|
@@ -5376,6 +5410,7 @@ function createRebaseClient(options) {
|
|
|
5376
5410
|
const dataProxy = new Proxy(dataTarget, {
|
|
5377
5411
|
get(_target, prop) {
|
|
5378
5412
|
if (prop === "collection") return collection;
|
|
5413
|
+
if (prop === "batch") return batch;
|
|
5379
5414
|
if (typeof prop === "symbol") return void 0;
|
|
5380
5415
|
if (isProbedName(prop)) return void 0;
|
|
5381
5416
|
if (options.collections && Object.hasOwn(options.collections, prop)) return collection(options.collections[prop]);
|
|
@@ -5402,7 +5437,7 @@ function createRebaseClient(options) {
|
|
|
5402
5437
|
return collection(slug);
|
|
5403
5438
|
},
|
|
5404
5439
|
has(_target, prop) {
|
|
5405
|
-
if (prop === "collection") return true;
|
|
5440
|
+
if (prop === "collection" || prop === "batch") return true;
|
|
5406
5441
|
if (typeof prop === "symbol") return false;
|
|
5407
5442
|
if (isProbedName(prop)) return false;
|
|
5408
5443
|
if (options.collections) return Object.hasOwn(options.collections, prop);
|
|
@@ -5500,30 +5535,7 @@ function createRebaseClient(options) {
|
|
|
5500
5535
|
body: payload !== void 0 ? JSON.stringify(payload) : void 0
|
|
5501
5536
|
});
|
|
5502
5537
|
},
|
|
5503
|
-
batch
|
|
5504
|
-
if (!Array.isArray(operations)) throw invalidBulkBody("batch expects an array of operations.");
|
|
5505
|
-
if (operations.length === 0) return {
|
|
5506
|
-
data: [],
|
|
5507
|
-
meta: { operations: 0 }
|
|
5508
|
-
};
|
|
5509
|
-
const headers = {};
|
|
5510
|
-
if (batchOptions?.idempotencyKey) headers["Idempotency-Key"] = batchOptions.idempotencyKey;
|
|
5511
|
-
if (batchOptions?.returning === false) headers.Prefer = "return=minimal";
|
|
5512
|
-
const dictionary = options.collections;
|
|
5513
|
-
const wire = dictionary ? operations.map((operation) => {
|
|
5514
|
-
if (!operation || typeof operation !== "object") return operation;
|
|
5515
|
-
const name = operation.collection;
|
|
5516
|
-
return typeof name === "string" && Object.hasOwn(dictionary, name) ? {
|
|
5517
|
-
...operation,
|
|
5518
|
-
collection: dictionary[name]
|
|
5519
|
-
} : operation;
|
|
5520
|
-
}) : operations;
|
|
5521
|
-
return transport.request("/data/_batch", {
|
|
5522
|
-
method: "POST",
|
|
5523
|
-
body: JSON.stringify({ operations: wire }),
|
|
5524
|
-
...Object.keys(headers).length > 0 ? { headers } : {}
|
|
5525
|
-
});
|
|
5526
|
-
},
|
|
5538
|
+
batch,
|
|
5527
5539
|
data: dataProxy,
|
|
5528
5540
|
...offlineManager ? { offline: offlineManager.api } : {}
|
|
5529
5541
|
};
|