@rebasepro/client 0.21.0 → 0.21.1

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 CHANGED
@@ -9,8 +9,8 @@ pnpm add @rebasepro/client
9
9
  ```
10
10
 
11
11
  ESM-only: `"type": "module"` with no CommonJS build, so it is loaded with
12
- `import`. `require()` of it resolves only on Node 22.12+, which supports
13
- `require(esm)`.
12
+ `import`. It needs Node `>=22.22.0` (its `engines` floor), where `require()`
13
+ of it resolves too: Node has supported `require(esm)` since 22.12.
14
14
 
15
15
  ## What This Package Does
16
16
 
@@ -20,7 +20,7 @@ ESM-only: `"type": "module"` with no CommonJS build, so it is loaded with
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 collection and snapshot changes
23
+ - **Realtime** — WebSocket subscriptions for collection 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
@@ -32,8 +32,8 @@ ESM-only: `"type": "module"` with no CommonJS build, so it is loaded with
32
32
 
33
33
  | Export | Description |
34
34
  |---|---|
35
- | `createRebaseClient<DB>(options)` | Create a `RebaseClient` instance. Generic `DB` parameter enables type-safe `client.data.*` access. |
36
- | `RebaseClient<DB>` | The client type — includes `auth`, `admin`, `cron`, `functions`, `storage`, `ws`, `data`, `call`, and token management methods. |
35
+ | `createRebaseClient<DB>(options)` | Create a client instance. Generic `DB` parameter enables type-safe `client.data.*` access. |
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
37
  | `CreateRebaseClientOptions` | Extends `RebaseClientConfig` with `auth`, `admin`, and `cron` sub-configs. |
38
38
 
39
39
  ### Config
@@ -56,19 +56,19 @@ ESM-only: `"type": "module"` with no CommonJS build, so it is loaded with
56
56
 
57
57
  | Method | Description |
58
58
  |---|---|
59
- | `find(params?)` | Query with pagination. Returns `FindResponse<M>` (`{ data, meta }`) |
60
- | `findById(id)` | Fetch a single snapshot. Returns `Snapshot<M> \| undefined` |
61
- | `create(data, id?)` | Create snapshot. Returns `Snapshot<M>` |
62
- | `update(id, data)` | Update snapshot. Returns `Snapshot<M>` |
63
- | `delete(id)` | Delete snapshot |
64
- | `count(params?)` | Count matching snapshots |
59
+ | `find(params?)` | Query with pagination. Returns `FindResult<M>` (`{ data, meta }`, flat rows) |
60
+ | `findById(id)` | Fetch a single row. Returns `M \| undefined` |
61
+ | `create(data, id?)` | Create a row. Returns `M` |
62
+ | `update(id, data)` | Update a row. Returns `M` |
63
+ | `delete(id)` | Delete a row |
64
+ | `count(params?)` | Count matching rows |
65
65
  | `where(col, op, val)` | Start a fluent query — returns `QueryBuilder` |
66
66
  | `orderBy(col, dir?)` | Order results — returns `QueryBuilder` |
67
67
  | `limit(n)` / `offset(n)` | Pagination — returns `QueryBuilder` |
68
68
  | `search(str)` | Full-text search — returns `QueryBuilder` |
69
- | `include(...rels)` | Include related snapshots — returns `QueryBuilder` |
69
+ | `include(...rels)` | Include related rows — returns `QueryBuilder` |
70
70
  | `listen(params, onUpdate, onError?)` | Realtime subscription (requires WebSocket) |
71
- | `listenById(id, onUpdate, onError?)` | Realtime single-snapshot subscription |
71
+ | `listenById(id, onUpdate, onError?)` | Realtime single-row subscription |
72
72
  | `observe(params, onResult, onError?, options?)` | Live query — local-first when `offline` is on, otherwise fetch + `listen` |
73
73
  | `observeById(id, onResult, onError?, options?)` | Live query for a single row |
74
74
 
@@ -131,13 +131,16 @@ ESM-only: `"type": "module"` with no CommonJS build, so it is loaded with
131
131
  | `createCookieStorage(options?)` | Cookie-based auth storage adapter |
132
132
  | `createMemoryStorage()` | In-memory auth storage adapter |
133
133
  | `QueryBuilder` | Fluent query builder (also re-exported from `@rebasepro/common`) |
134
- | `Snapshot`, `FindResponse` | Re-exported from `@rebasepro/types` |
134
+ | `FindResult`, `FindParams`, `User`, | Re-exported from `@rebasepro/types` |
135
135
 
136
136
  ## Quick Start
137
137
 
138
138
  ```ts
139
139
  import { createRebaseClient } from "@rebasepro/client";
140
140
 
141
+ // Without a type argument every row is `Record<string, unknown>`. Pass the
142
+ // `Database` type `rebase generate-sdk` writes — `createRebaseClient<Database>(…)`
143
+ // — and every row, filter and sort below is checked.
141
144
  const client = createRebaseClient({
142
145
  baseUrl: "http://localhost:3001",
143
146
  });
@@ -148,8 +151,8 @@ await client.auth.signInWithEmail("user@example.com", "password");
148
151
  // CRUD
149
152
  const { data: products } = await client.data.products.find({ limit: 10 });
150
153
  const product = await client.data.products.create({ name: "Camera", price: 299 });
151
- await client.data.products.update(product.id, { price: 249 });
152
- await client.data.products.delete(product.id);
154
+ await client.data.products.update(42, { price: 249 });
155
+ await client.data.products.delete(42);
153
156
 
154
157
  // Fluent queries
155
158
  const { data: expensive } = await client.data.products
@@ -171,6 +174,6 @@ const unsubscribe = client.data.products.listen(
171
174
  ## Related Packages
172
175
 
173
176
  - [`@rebasepro/common`](../common) — `QueryBuilder`, `buildRebaseData`, shared utilities
174
- - [`@rebasepro/types`](../types) — `Snapshot`, `FindResponse`, `CollectionAccessor`, etc.
177
+ - [`@rebasepro/types`](../types) — `Entity`, `FindResult`, `CollectionAccessor`, etc.
175
178
  - [`@rebasepro/utils`](../utils) — `toSnakeCase` and other helpers
176
- - [`@rebasepro/app`](../auth) — React hook adapter that wraps `client.auth` for CMS integration
179
+ - [`@rebasepro/app`](../app) — React hook adapter that wraps `client.auth` for CMS integration
package/dist/index.es.js CHANGED
@@ -2475,6 +2475,20 @@ function extractMessageError(message) {
2475
2475
  };
2476
2476
  }
2477
2477
  /**
2478
+ * The error an `ERROR` frame describes, with the server's `details` when it
2479
+ * sent them — `{ stage, path }` for a collection-callback refusal, the object
2480
+ * the REST envelope carries for the same veto. `status` stays `undefined`:
2481
+ * a frame is not an HTTP response (see `RebaseErrorInit.status`).
2482
+ */
2483
+ function frameError(message) {
2484
+ const { errorMessage, errorCode } = extractMessageError(message);
2485
+ const errPayload = message.payload?.error;
2486
+ return new RebaseApiError$1(errorMessage, {
2487
+ code: errorCode,
2488
+ details: typeof errPayload === "object" && errPayload !== null ? errPayload.details : void 0
2489
+ });
2490
+ }
2491
+ /**
2478
2492
  * Broadcast and presence frames.
2479
2493
  *
2480
2494
  * Fire-and-forget (the server sends no response envelope), and exempt from the
@@ -2868,8 +2882,7 @@ var RebaseWebSocketClient = class {
2868
2882
  else this.sendEntitySubscribe(subscriptionKey);
2869
2883
  return;
2870
2884
  }
2871
- const { errorMessage, errorCode } = extractMessageError(message);
2872
- const error = new RebaseApiError$1(errorMessage, { code: errorCode });
2885
+ const error = frameError(message);
2873
2886
  if (messageType === "subscribe_collection") this.failCollectionSubscription(subscriptionKey, error);
2874
2887
  else this.failEntitySubscription(subscriptionKey, error);
2875
2888
  }).catch((err) => {
@@ -2886,17 +2899,13 @@ var RebaseWebSocketClient = class {
2886
2899
  this.pendingRequests.delete(requestId);
2887
2900
  this.handleAuthFailure().then((refreshed) => {
2888
2901
  if (refreshed && pendingReq.message) this.doSendMessage(pendingReq.message, pendingReq.resolve, pendingReq.reject).catch(pendingReq.reject);
2889
- else {
2890
- const { errorMessage, errorCode } = extractMessageError(message);
2891
- pendingReq.reject(new RebaseApiError$1(errorMessage, { code: errorCode }));
2892
- }
2902
+ else pendingReq.reject(frameError(message));
2893
2903
  }).catch((err) => {
2894
2904
  pendingReq.reject(err);
2895
2905
  });
2896
2906
  } else {
2897
2907
  this.pendingRequests.delete(requestId);
2898
- const { errorMessage, errorCode } = extractMessageError(message);
2899
- pendingReq.reject(new RebaseApiError$1(errorMessage, { code: errorCode }));
2908
+ pendingReq.reject(frameError(message));
2900
2909
  }
2901
2910
  else {
2902
2911
  this.pendingRequests.delete(requestId);
@@ -2980,8 +2989,7 @@ var RebaseWebSocketClient = class {
2980
2989
  if (collectionSub.subscribeTimeout) clearTimeout(collectionSub.subscribeTimeout);
2981
2990
  collectionSub.subscribeTimeout = void 0;
2982
2991
  collectionSub.subscribeInFlight = false;
2983
- const { errorMessage, errorCode } = extractMessageError(message);
2984
- const error = new RebaseApiError$1(errorMessage, { code: errorCode });
2992
+ const error = frameError(message);
2985
2993
  collectionSub.callbacks.forEach((callback) => {
2986
2994
  if (callback.onError) callback.onError(error);
2987
2995
  });
@@ -2999,8 +3007,7 @@ var RebaseWebSocketClient = class {
2999
3007
  if (entitySub.subscribeTimeout) clearTimeout(entitySub.subscribeTimeout);
3000
3008
  entitySub.subscribeTimeout = void 0;
3001
3009
  entitySub.subscribeInFlight = false;
3002
- const { errorMessage, errorCode } = extractMessageError(message);
3003
- const error = new RebaseApiError$1(errorMessage, { code: errorCode });
3010
+ const error = frameError(message);
3004
3011
  entitySub.callbacks.forEach((callback) => {
3005
3012
  if (callback.onError) callback.onError(error);
3006
3013
  });