@rebasepro/client 0.9.1-canary.f2f61da → 0.9.1-canary.fd3754b

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -74,20 +74,11 @@ export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<Rebase
74
74
  apiKeys: ReturnType<typeof createApiKeys>;
75
75
  functions: ReturnType<typeof createFunctionsClient>;
76
76
  ws?: RebaseWebSocketClient;
77
- /**
78
- * Release the realtime socket and its reconnect timer.
79
- *
80
- * An open socket keeps the Node event loop alive, so a script that does not
81
- * call this will not exit on its own. Safe when realtime was never started
82
- * (`realtime: false`), and safe to call twice.
83
- */
84
- close: () => void;
85
77
  storage: StorageSource;
86
78
  storageRegistry: StorageSourceRegistry;
87
79
  createStorageSource: (storageId: string) => StorageSource;
88
80
  fetchStorageSources: () => Promise<StorageSourceDefinition[]>;
89
81
  call: <T = unknown>(endpoint: string, payload?: unknown) => Promise<T>;
90
- collection: <M extends Record<string, unknown> = Record<string, unknown>>(slug: string) => CollectionClient<M>;
91
82
  data: TypedDataLayer<DB>;
92
83
  };
93
84
  export declare function createRebaseClient<DB = Record<string, unknown>>(options: CreateRebaseClientOptions): CreateRebaseClientResult<DB>;
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_STORAGE_SOURCE_KEY, EntityReference, EntityRelation, GeoPoint, PUBLIC_STORAGE_PREFIX, RebaseApiError, RebaseApiError as RebaseApiError$1, RebaseClientError, Vector, isPublicStoragePath } from "@rebasepro/types";
2
- import { COMPOSITE_ID_SEPARATOR, QueryBuilder, and, buildCompositeId, cond, or, serializeFilter, serializeLogicalCondition, serializeOrderBy } from "@rebasepro/common";
2
+ import { QueryBuilder, and, cond, or, serializeFilter, serializeLogicalCondition, serializeOrderBy } from "@rebasepro/common";
3
3
  import { toSnakeCase } from "@rebasepro/utils";
4
4
  //#region src/reviver.ts
5
5
  function rebaseReviver(_key, value) {
@@ -1035,7 +1035,7 @@ var SDKQueryBuilder = class {
1035
1035
  * Listen to realtime updates matching this query.
1036
1036
  */
1037
1037
  listen(onUpdate, onError) {
1038
- if (!this.collection.listen) throw new Error("Listen is only available when RebaseClient is configured with a websocketUrl, and not when it was created with realtime: false.");
1038
+ if (!this.collection.listen) throw new Error("Listen is only available when RebaseClient is configured with a websocketUrl.");
1039
1039
  return this.collection.listen(this.params, onUpdate, onError);
1040
1040
  }
1041
1041
  };
@@ -1070,17 +1070,6 @@ function createCollectionClient(transport, slug, ws) {
1070
1070
  body: JSON.stringify(body)
1071
1071
  });
1072
1072
  },
1073
- async createMany(data, options) {
1074
- if (!Array.isArray(data)) throw new TypeError("createMany expects an array of records.");
1075
- if (data.length === 0) return [];
1076
- return (await transport.request(`${basePath}/bulk`, {
1077
- method: "POST",
1078
- body: JSON.stringify({
1079
- rows: data,
1080
- ...options?.upsert ? { upsert: true } : {}
1081
- })
1082
- })).data || [];
1083
- },
1084
1073
  async update(id, data) {
1085
1074
  return await transport.request(`${basePath}/${encodeURIComponent(String(id))}`, {
1086
1075
  method: "PUT",
@@ -1696,9 +1685,7 @@ var RebaseWebSocketClient = class {
1696
1685
  const collectionSub = this.collectionSubscriptions.get(subscriptionKey);
1697
1686
  if (collectionSub) {
1698
1687
  const incomingRows = message.rows || [];
1699
- const updatePks = message.pks;
1700
- if (updatePks) collectionSub.pks = updatePks;
1701
- const rows = this.mergeRows(collectionSub.latestData, incomingRows, collectionSub.pks);
1688
+ const rows = this.mergeRows(collectionSub.latestData, incomingRows);
1702
1689
  collectionSub.latestData = rows;
1703
1690
  collectionSub.lastUpdated = Date.now();
1704
1691
  collectionSub.isInitialDataReceived = true;
@@ -1720,14 +1707,12 @@ var RebaseWebSocketClient = class {
1720
1707
  const collectionSub = this.collectionSubscriptions.get(subscriptionKey);
1721
1708
  if (collectionSub && collectionSub.isInitialDataReceived && collectionSub.latestData) {
1722
1709
  const patchWireEntity = message.row ?? null;
1723
- const patchMessage = message;
1724
- const patchEntityId = patchMessage.id;
1725
- if (patchMessage.pks) collectionSub.pks = patchMessage.pks;
1710
+ const patchEntityId = message.id;
1726
1711
  const patchRow = patchWireEntity ? patchWireEntity : null;
1727
1712
  let updated;
1728
- if (patchRow === null) updated = collectionSub.latestData.filter((e) => this.rowAddress(e, collectionSub.pks) !== String(patchEntityId));
1713
+ if (patchRow === null) updated = collectionSub.latestData.filter((e) => String(e.id) !== String(patchEntityId));
1729
1714
  else {
1730
- const idx = collectionSub.latestData.findIndex((e) => this.rowAddress(e, collectionSub.pks) === String(patchEntityId));
1715
+ const idx = collectionSub.latestData.findIndex((e) => String(e.id) === String(patchRow.id));
1731
1716
  if (idx >= 0) {
1732
1717
  updated = [...collectionSub.latestData];
1733
1718
  updated[idx] = patchRow;
@@ -2077,39 +2062,17 @@ var RebaseWebSocketClient = class {
2077
2062
  return val;
2078
2063
  }
2079
2064
  /**
2080
- * The address of a row, for matching it against another copy of itself.
2081
- *
2082
- * A row is exactly its columns and carries no address, so it is derived
2083
- * from the key columns the server named — including the ordinary case where
2084
- * that key is `id`, which the server reports like any other.
2085
- *
2086
- * Undefined when there are no keys, which means the server could not
2087
- * resolve any: such rows genuinely cannot be recognised, and guessing at a
2088
- * column called `id` would be inventing an identity for a table that has
2089
- * none.
2090
- */
2091
- rowAddress(row, pks) {
2092
- if (!pks || pks.length === 0) return void 0;
2093
- const address = buildCompositeId(row, pks);
2094
- if (!address || address.split(COMPOSITE_ID_SEPARATOR).every((part) => part === "")) return void 0;
2095
- return address;
2096
- }
2097
- /**
2098
2065
  * Merge incoming rows with cached data, preserving cached references
2099
2066
  * for rows whose values haven't changed. This avoids unnecessary
2100
2067
  * React re-renders when the server refetches all rows but most
2101
2068
  * haven't actually changed.
2102
2069
  */
2103
- mergeRows(cached, incoming, pks) {
2070
+ mergeRows(cached, incoming) {
2104
2071
  if (!cached || cached.length === 0) return incoming;
2105
2072
  const cachedById = /* @__PURE__ */ new Map();
2106
- for (const row of cached) {
2107
- const address = this.rowAddress(row, pks);
2108
- if (address !== void 0) cachedById.set(address, row);
2109
- }
2073
+ for (const row of cached) cachedById.set(row.id, row);
2110
2074
  return incoming.map((incomingRow) => {
2111
- const address = this.rowAddress(incomingRow, pks);
2112
- const cachedRow = address === void 0 ? void 0 : cachedById.get(address);
2075
+ const cachedRow = cachedById.get(incomingRow.id);
2113
2076
  if (!cachedRow) return incomingRow;
2114
2077
  const normCached = this.normalizeForComparison(cachedRow);
2115
2078
  const normIncoming = this.normalizeForComparison(incomingRow);
@@ -2121,7 +2084,7 @@ var RebaseWebSocketClient = class {
2121
2084
  cached: normCached[key],
2122
2085
  incoming: normIncoming[key]
2123
2086
  };
2124
- console.debug(`[RebaseWS] Row ${address} refetch mismatch:\n`, JSON.stringify(mismatches, null, 2));
2087
+ console.debug(`[RebaseWS] Row ${incomingRow.id} refetch mismatch:\n`, JSON.stringify(mismatches, null, 2));
2125
2088
  }
2126
2089
  return incomingRow;
2127
2090
  });
@@ -2368,7 +2331,7 @@ function createRebaseClient(options) {
2368
2331
  });
2369
2332
  return storageSourcesPromise;
2370
2333
  };
2371
- const resolvedWsUrl = options.realtime !== false ? options.websocketUrl ?? deriveWebSocketUrl(options.baseUrl) : void 0;
2334
+ const resolvedWsUrl = options.websocketUrl ?? deriveWebSocketUrl(options.baseUrl);
2372
2335
  let ws;
2373
2336
  if (resolvedWsUrl) {
2374
2337
  ws = new RebaseWebSocketClient({
@@ -2480,16 +2443,6 @@ function createRebaseClient(options) {
2480
2443
  createStorageSource,
2481
2444
  fetchStorageSources,
2482
2445
  ws,
2483
- /**
2484
- * Release the realtime socket and its reconnect timer.
2485
- *
2486
- * Until this returns, the open socket keeps the Node event loop alive
2487
- * and the process will not exit on its own. Safe to call when realtime
2488
- * was never started, and safe to call twice.
2489
- */
2490
- close: () => {
2491
- ws?.disconnect();
2492
- },
2493
2446
  setToken: transport.setToken,
2494
2447
  setAuthTokenGetter: transport.setAuthTokenGetter,
2495
2448
  setOnUnauthorized: transport.setOnUnauthorized,