@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/README.md
CHANGED
|
@@ -16,15 +16,15 @@ of it resolves too: Node has supported `require(esm)` since 22.12.
|
|
|
16
16
|
|
|
17
17
|
`@rebasepro/client` is the primary SDK for interacting with a Rebase backend from any JavaScript/TypeScript environment (browser, Node.js, edge). It creates a single client instance that provides:
|
|
18
18
|
|
|
19
|
-
- **
|
|
19
|
+
- **Table CRUD** with a fluent query builder (`.where()`, `.orderBy()`, `.limit()`, etc.)
|
|
20
20
|
- **Authentication** — email/password, Google, 10+ OAuth providers, session management, password reset
|
|
21
21
|
- **Admin** — user CRUD for admins
|
|
22
22
|
- **Storage** — file upload, download, delete, list
|
|
23
|
-
- **Realtime** — WebSocket subscriptions for
|
|
23
|
+
- **Realtime** — WebSocket subscriptions for table and row changes
|
|
24
24
|
- **Offline / local-first sync** (opt-in) — a local row database, writes that apply instantly offline and replay when the connection returns, and live queries
|
|
25
25
|
- **Cron** — list, trigger, and manage cron jobs
|
|
26
26
|
- **Custom functions** — invoke server-side Hono route functions
|
|
27
|
-
- **Type-safe data proxy** — `client.data.products` auto-maps to the `products`
|
|
27
|
+
- **Type-safe data proxy** — `client.data.products` auto-maps to the `products` table
|
|
28
28
|
|
|
29
29
|
## Key Exports
|
|
30
30
|
|
|
@@ -34,7 +34,7 @@ of it resolves too: Node has supported `require(esm)` since 22.12.
|
|
|
34
34
|
|---|---|
|
|
35
35
|
| `createRebaseClient<DB>(options)` | Create a client instance. Generic `DB` parameter enables type-safe `client.data.*` access. |
|
|
36
36
|
| `CreateRebaseClientResult<DB>` | The client type it returns (`RebaseClient<DB>` from `@rebasepro/types`, narrowed) — includes `auth`, `admin`, `cron`, `functions`, `storage`, `ws`, `data`, `call`, and token management methods. |
|
|
37
|
-
| `CreateRebaseClientOptions` | Extends `RebaseClientConfig` with the `auth`, `admin`, `cron`, `apiKeys` and `personalKeys` sub-configs, plus `storageSources`, `
|
|
37
|
+
| `CreateRebaseClientOptions` | Extends `RebaseClientConfig` with the `auth`, `admin`, `cron`, `apiKeys` and `personalKeys` sub-configs, plus `storageSources`, `tables`, `offline` and `debug`. |
|
|
38
38
|
|
|
39
39
|
### Config
|
|
40
40
|
|
|
@@ -47,7 +47,7 @@ of it resolves too: Node has supported `require(esm)` since 22.12.
|
|
|
47
47
|
| `onUnauthorized` | `() => Promise<boolean>` | auto-refresh | Handler for a refused token, over HTTP (401) and on the realtime socket |
|
|
48
48
|
| `websocketUrl` | `string` | derived from `baseUrl` | WebSocket URL for realtime |
|
|
49
49
|
| `realtime` | `boolean` | `true` | Open the WebSocket — `false` lets a one-shot script exit |
|
|
50
|
-
| `
|
|
50
|
+
| `tables` | `Record<string, string>` | — | Maps accessor names to table slugs: the generated `tablesDictionary`. With it, an unknown accessor throws `UNKNOWN_TABLE` |
|
|
51
51
|
| `offline` | `boolean \| OfflineConfig` | `false` | Local-first sync — see [the docs](https://rebase.pro/docs/sdk/offline) |
|
|
52
52
|
| `debug` | `boolean` | `false` | Log the realtime connection's progress with `console.debug`. One browser can turn it on with `localStorage.setItem("rebase_debug", "1")` — see [Connection logging](https://rebase.pro/docs/sdk#connection-logging) |
|
|
53
53
|
|
|
@@ -66,9 +66,9 @@ Installing a getter or calling `setToken()` rebuilds an open socket so it authen
|
|
|
66
66
|
client.setAuthTokenGetter(() => clerk.session?.getToken() ?? Promise.resolve(null));
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
###
|
|
69
|
+
### Table Client
|
|
70
70
|
|
|
71
|
-
`client.data.
|
|
71
|
+
`client.data.table("slug")` or `client.data.myTable` returns a `TableClient<M>`:
|
|
72
72
|
|
|
73
73
|
| Method | Description |
|
|
74
74
|
|---|---|
|
|
@@ -81,7 +81,7 @@ client.setAuthTokenGetter(() => clerk.session?.getToken() ?? Promise.resolve(nul
|
|
|
81
81
|
| `where(col, op, val)` | Start a fluent query — returns a query builder |
|
|
82
82
|
| `orderBy(col, dir?)` | Order results — returns a query builder |
|
|
83
83
|
| `limit(n)` / `offset(n)` | Pagination — returns a query builder |
|
|
84
|
-
| `search(str)` | Text search: a case-insensitive substring match by default, ranked full-text where the
|
|
84
|
+
| `search(str)` | Text search: a case-insensitive substring match by default, ranked full-text where the table opts in — returns a query builder |
|
|
85
85
|
| `include(...rels)` | Include related rows — returns a query builder |
|
|
86
86
|
| `listen(params, onUpdate, onError?)` | Realtime subscription (requires WebSocket) |
|
|
87
87
|
| `listenById(id, onUpdate, onError?)` | Realtime single-row subscription |
|
|
@@ -189,7 +189,7 @@ const unsubscribe = client.data.products.listen(
|
|
|
189
189
|
|
|
190
190
|
## Related Packages
|
|
191
191
|
|
|
192
|
-
- [`@rebasepro/common`](../common) — `
|
|
193
|
-
- [`@rebasepro/types`](../types) — `
|
|
192
|
+
- [`@rebasepro/common`](../common) — `buildSdkData`, query helpers (`or`, `and`, `cond`), shared utilities
|
|
193
|
+
- [`@rebasepro/types`](../types) — `FindResult`, `SDKTableClient`, etc.
|
|
194
194
|
- [`@rebasepro/utils`](../utils) — `toSnakeCase` and other helpers
|
|
195
195
|
- [`@rebasepro/app`](../app) — React hook adapter that wraps `client.auth` for CMS integration
|
|
@@ -54,4 +54,29 @@ export declare const typedIsARebaseClient: RebaseClient<ContractDatabase>;
|
|
|
54
54
|
export declare const untypedIsARebaseClient: RebaseClient;
|
|
55
55
|
/** `data.batch` takes the accessor names, as `client.batch` does. */
|
|
56
56
|
export declare const typedDataBatch: () => Promise<import("@rebasepro/types").BatchResult<Record<string, unknown>>>;
|
|
57
|
+
/**
|
|
58
|
+
* `data.table(slug)` is the by-slug accessor, typed from the generated
|
|
59
|
+
* `Database` exactly as the accessor property is: `table("order_items")` is
|
|
60
|
+
* `orderItems`, and a slug the `Database` does not declare falls through to
|
|
61
|
+
* the untyped overload.
|
|
62
|
+
*/
|
|
63
|
+
export declare const typedTableBySlug: () => Promise<{
|
|
64
|
+
sku: string;
|
|
65
|
+
byAccessor: import("./table.js").TableClient<{
|
|
66
|
+
id: string;
|
|
67
|
+
order_id: string;
|
|
68
|
+
sku: string;
|
|
69
|
+
}, {
|
|
70
|
+
order_id: string;
|
|
71
|
+
sku: string;
|
|
72
|
+
}, {
|
|
73
|
+
sku?: string;
|
|
74
|
+
}, import("@rebasepro/types").IncludeSpec>;
|
|
75
|
+
untyped: import("./table.js").TableClient<Record<string, unknown>, Partial<Record<string, unknown>>, Partial<Record<string, unknown>>, import("@rebasepro/types").IncludeSpec>;
|
|
76
|
+
}>;
|
|
77
|
+
/**
|
|
78
|
+
* The backend's data is addressed as a table: `data.collection(slug)` and the
|
|
79
|
+
* top-level `client.collection(slug)` are gone, with no alias left behind.
|
|
80
|
+
*/
|
|
81
|
+
export declare const noCollectionAccessor: () => void;
|
|
57
82
|
export {};
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Client-side logic error (e.g. accessing an unknown
|
|
2
|
+
* Client-side logic error (e.g. accessing an unknown table when a typed
|
|
3
3
|
* dictionary is available). A subclass of {@link RebaseApiError}, so a single
|
|
4
4
|
* `catch (e) { if (e instanceof RebaseApiError) ... }` covers it too.
|
|
5
5
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,9 @@ import { createAuth, CreateAuthOptions } from "./auth.js";
|
|
|
3
3
|
import { createAdmin, CreateAdminOptions } from "./admin.js";
|
|
4
4
|
import { createCron, CreateCronOptions } from "./cron.js";
|
|
5
5
|
import { createBackups } from "./backups.js";
|
|
6
|
+
import { createSchema } from "./schema.js";
|
|
6
7
|
import { createApiKeys, CreateApiKeysOptions, createPersonalKeys, CreatePersonalKeysOptions } from "./api-keys.js";
|
|
7
|
-
import {
|
|
8
|
+
import { TableClient } from "./table.js";
|
|
8
9
|
import { createFunctionsClient } from "./functions.js";
|
|
9
10
|
import { RebaseWebSocketClient } from "./websocket.js";
|
|
10
11
|
import { RebaseRealtimeChannel, type ChannelOptions } from "./realtime-channel.js";
|
|
@@ -13,9 +14,9 @@ import { type AccessSimulation, type BatchOperation, type BatchResult, type Incl
|
|
|
13
14
|
export { RebaseApiError } from "./transport.js";
|
|
14
15
|
export { RebaseClientError } from "./errors.js";
|
|
15
16
|
export type { RebaseErrorCode } from "@rebasepro/types";
|
|
16
|
-
export type { RebaseClientConfig, RealtimeClientOptions, FindParams
|
|
17
|
-
export type {
|
|
18
|
-
export type { FindResult,
|
|
17
|
+
export type { RebaseClientConfig, RealtimeClientOptions, FindParams } from "./transport.js";
|
|
18
|
+
export type { TableClient, RestoreOptions, TrashClient } from "./table.js";
|
|
19
|
+
export type { FindResult, SDKTableClient, SDKQueryBuilderInterface, PaginationMeta } from "@rebasepro/types";
|
|
19
20
|
export type { IterateParams, FindAllParams, PageWalkOptions, CursorSpec } from "@rebasepro/types";
|
|
20
21
|
export { RebasePaginationError } from "@rebasepro/common";
|
|
21
22
|
export type { PaginationErrorCode } from "@rebasepro/common";
|
|
@@ -31,6 +32,8 @@ export type { CreateAdminOptions, ListGuestsOptions, ListUsersOptions } from "./
|
|
|
31
32
|
export type { AdminUser } from "./admin.js";
|
|
32
33
|
export type { CreateCronOptions } from "./cron.js";
|
|
33
34
|
export type { BackupStream } from "./backups.js";
|
|
35
|
+
export { SCHEMA_UNAVAILABLE, isSchemaUnavailable } from "./schema.js";
|
|
36
|
+
export type { SchemaAPI, SchemaTablesOptions, TableDescriptor } from "@rebasepro/types";
|
|
34
37
|
export type { ApiKeyKind, ApiKeyMasked, ApiKeyWithSecret, CreateApiKeyRequest, CreateApiKeysOptions, CreatePersonalKeyRequest, CreatePersonalKeysOptions, UpdateApiKeyRequest } from "./api-keys.js";
|
|
35
38
|
export type { FunctionInvokeOptions, FunctionsClient } from "./functions.js";
|
|
36
39
|
export { RebaseWebSocketClient } from "./websocket.js";
|
|
@@ -38,8 +41,8 @@ export { RebaseRealtimeChannel } from "./realtime-channel.js";
|
|
|
38
41
|
export type { PresenceState, PresenceDiff, BroadcastEvent, ChannelTransport, ChannelOptions, ChannelHistoryEntry, ChannelHistoryResult } from "./realtime-channel.js";
|
|
39
42
|
export type { ConflictResolution, OfflineApi, OfflineConfig, OfflineQueueOptions, OfflineStatus } from "./offline.js";
|
|
40
43
|
export { isOfflineError } from "./offline-errors.js";
|
|
41
|
-
export type { LiveResult, ObserveByIdOptions, ObserveOptions, RowSnapshotMeta } from "./
|
|
42
|
-
export { etagOf } from "./
|
|
44
|
+
export type { LiveResult, ObserveByIdOptions, ObserveOptions, RowSnapshotMeta } from "./table.js";
|
|
45
|
+
export { etagOf } from "./table.js";
|
|
43
46
|
export type { BatchOperation, BatchRef, BatchResult, FieldOperation, UpdateValues, UpsertOptions } from "@rebasepro/types";
|
|
44
47
|
export type { WriteOptions, WhereFilterOp, WhereFor, WhereConditionFor, WhereValueFor, FilterValues, FieldPath, OrderBySpec, LogicalCondition, LogicalConditionFor, FilterCondition, FilterConditionFor, AggregateParams, AggregateSelect, AggregateRow, AggregateResult, AggregateMeta, IncludeSpec, IncludeOptions, QueryComputedFields, RowOf, InsertOf, UpdateOf, StorageSource, ClientStorageSource, ClientUploadFileProps, UploadFileResult } from "@rebasepro/types";
|
|
45
48
|
export type { OfflineStore, OfflineCacheEntry, OfflineCacheRecord, PendingMutation, MutationRollback } from "./offline-store.js";
|
|
@@ -59,19 +62,19 @@ export interface CreateRebaseClientOptions extends RebaseClientConfig {
|
|
|
59
62
|
*/
|
|
60
63
|
storageSources?: StorageSourceDefinition[];
|
|
61
64
|
/**
|
|
62
|
-
* Maps each `client.data` accessor to the
|
|
65
|
+
* Maps each `client.data` accessor to the table slug the server
|
|
63
66
|
* serves (e.g. `{ companyMembers: "company-members" }`): the generated
|
|
64
|
-
* `
|
|
67
|
+
* `tablesDictionary`.
|
|
65
68
|
*
|
|
66
69
|
* **Required for a typed client** (`createRebaseClient<Database>`). The
|
|
67
70
|
* types offer every accessor, but without the map the proxy sends
|
|
68
71
|
* `client.data.companyMembers` to `/data/company_members`, so a kebab-case
|
|
69
|
-
* slug or a renamed accessor (`
|
|
72
|
+
* slug or a renamed accessor (`tableTable`) answers 404; a
|
|
70
73
|
* one-time warning names the accessor. With the map, an unknown accessor
|
|
71
|
-
* throws `
|
|
74
|
+
* throws `UNKNOWN_TABLE` with a suggestion. A later version will make
|
|
72
75
|
* it required in the types when `Database` is supplied.
|
|
73
76
|
*/
|
|
74
|
-
|
|
77
|
+
tables?: Record<string, string>;
|
|
75
78
|
/**
|
|
76
79
|
* Local-first sync for the data layer.
|
|
77
80
|
*
|
|
@@ -110,16 +113,16 @@ type DBEntry<DB, S extends string> = [
|
|
|
110
113
|
AccessorOfSlug<DB, S>
|
|
111
114
|
] extends [never] ? (KebabToCamelCase<S> extends keyof DB ? DB[KebabToCamelCase<S>] : unknown) : DB[AccessorOfSlug<DB, S>];
|
|
112
115
|
type TypedDataLayer<DB> = {
|
|
113
|
-
|
|
116
|
+
table<S extends string>(slug: S): TableClient<RowOf<DBEntry<DB, S>>, InsertOf<DBEntry<DB, S>>, UpdateOf<DBEntry<DB, S>>, IncludeOf<DBEntry<DB, S>, DB>>;
|
|
114
117
|
} & {
|
|
115
|
-
[K in keyof DB]:
|
|
116
|
-
} & (string extends keyof DB ? RebaseSdkData : Pick<RebaseSdkData, "
|
|
118
|
+
[K in keyof DB]: TableClient<RowOf<DB[K]>, InsertOf<DB[K]>, UpdateOf<DB[K]>, IncludeOf<DB[K], DB>>;
|
|
119
|
+
} & (string extends keyof DB ? RebaseSdkData : Pick<RebaseSdkData, "table"> & Pick<RebaseSdkData<DB>, "batch">);
|
|
117
120
|
/**
|
|
118
121
|
* The return type of `createRebaseClient<DB>()`.
|
|
119
122
|
*
|
|
120
123
|
* This is `RebaseClient` (from `@rebasepro/types`) with all optional
|
|
121
124
|
* capabilities populated and the `data` layer narrowed to provide
|
|
122
|
-
* typed
|
|
125
|
+
* typed table accessors when a `DB` schema generic is supplied.
|
|
123
126
|
*/
|
|
124
127
|
export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<RebaseClient<DB>, "data" | "email" | "simulate"> & {
|
|
125
128
|
/**
|
|
@@ -129,7 +132,7 @@ export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<Rebase
|
|
|
129
132
|
* {@link RebaseClient.simulate} for what the server honours and refuses.
|
|
130
133
|
*
|
|
131
134
|
* Always present here, typed by the same `Database` (it is built with the
|
|
132
|
-
* same `
|
|
135
|
+
* same `tables` dictionary), and closable: it is a client of its own,
|
|
133
136
|
* so release it with `close()` when done. On `RebaseClient` it is optional,
|
|
134
137
|
* because a server-side client has none.
|
|
135
138
|
*/
|
|
@@ -168,6 +171,8 @@ export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<Rebase
|
|
|
168
171
|
admin: ReturnType<typeof createAdmin>;
|
|
169
172
|
cron: ReturnType<typeof createCron>;
|
|
170
173
|
backups: ReturnType<typeof createBackups>;
|
|
174
|
+
/** The backend's tables, as `GET /api/schema/tables` serves them to the caller. */
|
|
175
|
+
schema: ReturnType<typeof createSchema>;
|
|
171
176
|
apiKeys: ReturnType<typeof createApiKeys>;
|
|
172
177
|
personalKeys: ReturnType<typeof createPersonalKeys>;
|
|
173
178
|
functions: ReturnType<typeof createFunctionsClient>;
|
|
@@ -227,18 +232,18 @@ export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<Rebase
|
|
|
227
232
|
*/
|
|
228
233
|
call: <T = unknown>(endpoint: string, payload?: unknown) => Promise<T>;
|
|
229
234
|
/**
|
|
230
|
-
* A
|
|
235
|
+
* A table by slug — the same client `data.table(slug)` returns,
|
|
231
236
|
* typed from the generated `Database` when the slug is one of its
|
|
232
|
-
*
|
|
237
|
+
* tables, or by the row type passed explicitly.
|
|
233
238
|
*/
|
|
234
|
-
|
|
235
|
-
<S extends string>(slug: S):
|
|
236
|
-
<M extends Record<string, unknown> = Record<string, unknown>>(slug: string):
|
|
239
|
+
table: {
|
|
240
|
+
<S extends string>(slug: S): TableClient<RowOf<DBEntry<DB, S>>, InsertOf<DBEntry<DB, S>>, UpdateOf<DBEntry<DB, S>>, IncludeOf<DBEntry<DB, S>, DB>>;
|
|
241
|
+
<M extends Record<string, unknown> = Record<string, unknown>>(slug: string): TableClient<M>;
|
|
237
242
|
};
|
|
238
243
|
/**
|
|
239
|
-
* Write across
|
|
244
|
+
* Write across tables in one transaction.
|
|
240
245
|
*
|
|
241
|
-
* `createMany` and friends are one
|
|
246
|
+
* `createMany` and friends are one table at a time, which is the wrong
|
|
242
247
|
* shape for the writes that most need to be atomic: an order and its line
|
|
243
248
|
* items, a user and their membership row, a document and its audit entry.
|
|
244
249
|
* Sent as separate calls those can half-succeed, and the recovery — read
|
|
@@ -257,18 +262,18 @@ export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<Rebase
|
|
|
257
262
|
* `data` is aligned to `operations`: the written row for a create, upsert
|
|
258
263
|
* or update, and `null` for a delete.
|
|
259
264
|
*
|
|
260
|
-
* `
|
|
265
|
+
* `table` is the accessor `client.data.<accessor>` takes — `orderItems`
|
|
261
266
|
* for the slug `order_items` — and is sent as the slug through the
|
|
262
|
-
* `
|
|
267
|
+
* `tables` dictionary. A name that is not an accessor goes out as
|
|
263
268
|
* written, so an untyped client can still pass the slug.
|
|
264
269
|
*
|
|
265
270
|
* @example
|
|
266
271
|
* ```ts
|
|
267
272
|
* await client.batch([
|
|
268
|
-
* { op: "create",
|
|
269
|
-
* { op: "create",
|
|
273
|
+
* { op: "create", table: "orders", values: { total: 40 }, ref: "order" },
|
|
274
|
+
* { op: "create", table: "orderItems",
|
|
270
275
|
* values: { orderId: { $ref: "order.id" }, sku: "A-1" } },
|
|
271
|
-
* { op: "update",
|
|
276
|
+
* { op: "update", table: "stock", id: "A-1", values: { count: { $inc: -1 } } }
|
|
272
277
|
* ]);
|
|
273
278
|
* ```
|
|
274
279
|
*/
|