@rebasepro/client 0.19.1 → 0.19.2-canary.g08eed46
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 +16 -0
- package/dist/index.d.ts +37 -2
- package/dist/index.es.js +378 -49
- package/dist/index.es.js.map +1 -1
- package/dist/offline-query.d.ts +0 -30
- package/dist/sdk_query_builder.d.ts +81 -8
- package/dist/transport.d.ts +37 -2
- package/dist/websocket.d.ts +2 -2
- package/package.json +4 -4
package/dist/collection.d.ts
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { FindParams, Transport } from "./transport.js";
|
|
2
2
|
import { RebaseWebSocketClient } from "./websocket.js";
|
|
3
3
|
import { FindResult, SDKCollectionClient } from "@rebasepro/types";
|
|
4
|
+
/**
|
|
5
|
+
* The version of a row, when it came straight from a read that reported one.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const post = await client.data.posts.get(1);
|
|
9
|
+
* await client.data.posts.update(1, { title: "New" }, { ifMatch: etagOf(post) });
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* `undefined` for a row from `find()` (a list response carries one ETag at
|
|
13
|
+
* most, and it would not be this row's), from the offline cache, or from a
|
|
14
|
+
* server that does not send them. Passing `undefined` as `ifMatch` sends no
|
|
15
|
+
* precondition, so the call above degrades to an ordinary update rather than
|
|
16
|
+
* failing — which is the right default, and the reason to read this at the call
|
|
17
|
+
* site where the choice is visible.
|
|
18
|
+
*/
|
|
19
|
+
export declare function etagOf(row: unknown): string | undefined;
|
|
4
20
|
/**
|
|
5
21
|
* A live query result: a normal {@link FindResult} plus what an interface
|
|
6
22
|
* needs to decide whether to show a "saving…" or "offline" affordance over it.
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { createFunctionsClient } from "./functions.js";
|
|
|
9
9
|
import { RebaseWebSocketClient } from "./websocket.js";
|
|
10
10
|
import { RebaseRealtimeChannel, type ChannelOptions } from "./realtime-channel.js";
|
|
11
11
|
import { type OfflineApi, type OfflineConfig } from "./offline.js";
|
|
12
|
-
import { InsertOf, RebaseClient, RebaseSdkData, RowOf, StorageSource, StorageSourceDefinition, StorageSourceRegistry, UpdateOf } from "@rebasepro/types";
|
|
12
|
+
import { type BatchOperation, type BatchResult, InsertOf, RebaseClient, RebaseSdkData, RowOf, StorageSource, StorageSourceDefinition, StorageSourceRegistry, UpdateOf, type WriteOptions } from "@rebasepro/types";
|
|
13
13
|
export { RebaseApiError } from "./transport.js";
|
|
14
14
|
export { RebaseClientError } from "./errors.js";
|
|
15
15
|
export type { RebaseErrorCode } from "@rebasepro/types";
|
|
@@ -19,7 +19,7 @@ export type { FindResult, SDKCollectionClient, SDKQueryBuilderInterface, Paginat
|
|
|
19
19
|
export type { IterateParams, FindAllParams, PageWalkOptions, CursorSpec } from "@rebasepro/types";
|
|
20
20
|
export { RebasePaginationError } from "@rebasepro/common";
|
|
21
21
|
export type { PaginationErrorCode } from "@rebasepro/common";
|
|
22
|
-
export { QueryBuilder, or, and, cond } from "@rebasepro/common";
|
|
22
|
+
export { QueryBuilder, or, and, not, cond } from "@rebasepro/common";
|
|
23
23
|
export { createCookieStorage, createMemoryStorage } from "./auth.js";
|
|
24
24
|
export type { AuthConfig, AuthStorage, CookieStorageOptions, CreateAuthOptions } from "./auth.js";
|
|
25
25
|
export type { User, RebaseSession, AuthTokens, AuthChangeEvent, DeviceSession } from "@rebasepro/types";
|
|
@@ -36,6 +36,8 @@ export type { PresenceState, PresenceDiff, BroadcastEvent, ChannelTransport, Cha
|
|
|
36
36
|
export type { OfflineApi, OfflineConfig, OfflineStatus } from "./offline.js";
|
|
37
37
|
export { isOfflineError } from "./offline.js";
|
|
38
38
|
export type { LiveResult, ObserveOptions, RowSnapshotMeta } from "./collection.js";
|
|
39
|
+
export { etagOf } from "./collection.js";
|
|
40
|
+
export type { BatchOperation, BatchRef, BatchResult, FieldOperation, UpdateValues, UpsertOptions } from "@rebasepro/types";
|
|
39
41
|
export type { OfflineStore, OfflineCacheEntry, OfflineCacheRecord, PendingMutation, MutationRollback } from "./offline-store.js";
|
|
40
42
|
export { MemoryOfflineStore } from "./offline-store.js";
|
|
41
43
|
export interface CreateRebaseClientOptions extends RebaseClientConfig {
|
|
@@ -146,6 +148,39 @@ export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<Rebase
|
|
|
146
148
|
*/
|
|
147
149
|
call: <T = unknown>(endpoint: string, payload?: unknown) => Promise<T>;
|
|
148
150
|
collection: <M extends Record<string, unknown> = Record<string, unknown>>(slug: string) => CollectionClient<M>;
|
|
151
|
+
/**
|
|
152
|
+
* Write across collections in one transaction.
|
|
153
|
+
*
|
|
154
|
+
* `createMany` and friends are one collection at a time, which is the wrong
|
|
155
|
+
* shape for the writes that most need to be atomic: an order and its line
|
|
156
|
+
* items, a user and their membership row, a document and its audit entry.
|
|
157
|
+
* Sent as separate calls those can half-succeed, and the recovery — read
|
|
158
|
+
* back, work out which half landed, undo it — is code nobody writes.
|
|
159
|
+
*
|
|
160
|
+
* Operations run in order, each through the pipeline its single-row
|
|
161
|
+
* equivalent uses: the same validation, callbacks and row-level security,
|
|
162
|
+
* as the same user. All of them land or none do.
|
|
163
|
+
*
|
|
164
|
+
* Name an operation with `ref` and a later one can stand
|
|
165
|
+
* `{ $ref: "<name>.<field>" }` wherever a value goes — which is the only
|
|
166
|
+
* way to express "insert the parent, then point the children at it" in a
|
|
167
|
+
* single request, since the parent's id does not exist until the server
|
|
168
|
+
* assigns it. Only backward references resolve.
|
|
169
|
+
*
|
|
170
|
+
* `data` is aligned to `operations`: the written row for a create, upsert
|
|
171
|
+
* or update, and `null` for a delete.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* await client.batch([
|
|
176
|
+
* { op: "create", collection: "orders", values: { total: 40 }, ref: "order" },
|
|
177
|
+
* { op: "create", collection: "order_items",
|
|
178
|
+
* values: { order_id: { $ref: "order.id" }, sku: "A-1" } },
|
|
179
|
+
* { op: "update", collection: "stock", id: "A-1", values: { count: { $inc: -1 } } }
|
|
180
|
+
* ]);
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
batch: (operations: BatchOperation<DB>[], options?: WriteOptions) => Promise<BatchResult>;
|
|
149
184
|
data: TypedDataLayer<DB>;
|
|
150
185
|
/** Present only when the client was created with `offline` enabled. */
|
|
151
186
|
offline?: OfflineApi;
|