@aouda/client 0.1.10 → 0.1.11

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.
@@ -1,4 +1,4 @@
1
- import { A as AoudaClient } from '../client-Dgenr-cE.cjs';
1
+ import { A as AoudaClient } from '../client-CT3GdrvA.cjs';
2
2
 
3
3
  /**
4
4
  * CLI for @aouda/client.
@@ -1,4 +1,4 @@
1
- import { A as AoudaClient } from '../client-Dgenr-cE.js';
1
+ import { A as AoudaClient } from '../client-CT3GdrvA.js';
2
2
 
3
3
  /**
4
4
  * CLI for @aouda/client.
package/dist/cli/index.js CHANGED
@@ -392,7 +392,7 @@ import { fileURLToPath } from "url";
392
392
  // package.json
393
393
  var package_default = {
394
394
  name: "@aouda/client",
395
- version: "0.1.10",
395
+ version: "0.1.11",
396
396
  description: "Official TypeScript/JavaScript client library for Aouda",
397
397
  type: "module",
398
398
  main: "./dist/index.cjs",
@@ -630,6 +630,7 @@ var AuthHandler = class {
630
630
  this._tokenExpiry = null;
631
631
  this._authenticated = false;
632
632
  this._refreshPromise = null;
633
+ this._onAccessTokenRefreshed = null;
633
634
  this._serverUrl = serverUrl.replace(/\/+$/, "");
634
635
  this._timeout = timeout;
635
636
  this._authBasePath = config.basePath;
@@ -879,10 +880,16 @@ var AuthHandler = class {
879
880
  const thresholdSeconds = this._refreshThresholdMs / 1e3;
880
881
  return this._tokenExpiry <= nowSeconds + thresholdSeconds;
881
882
  }
883
+ setOnAccessTokenRefreshed(handler) {
884
+ this._onAccessTokenRefreshed = handler;
885
+ }
882
886
  async _doRefresh() {
883
887
  try {
884
888
  const result = await this.callRefreshEndpoint();
885
889
  this.handleSignInResult(result);
890
+ if (result.accessToken) {
891
+ this._onAccessTokenRefreshed?.(result.accessToken);
892
+ }
886
893
  return true;
887
894
  } catch {
888
895
  return false;
@@ -2385,6 +2392,7 @@ var TableSubscription = class {
2385
2392
  this._startPromise = null;
2386
2393
  this._lastVersion = 0;
2387
2394
  this._pendingSnapshotRows = [];
2395
+ this._forceFreshSubscribe = false;
2388
2396
  this.id = createStreamingId("sub");
2389
2397
  this._transport = transport;
2390
2398
  this._tableName = tableName;
@@ -2392,6 +2400,7 @@ var TableSubscription = class {
2392
2400
  this._onSnapshot = options.onSnapshot;
2393
2401
  this._onChange = options.onChange;
2394
2402
  this._onError = options.onError;
2403
+ this._conflate = options.conflate;
2395
2404
  this._reconnectHandlerKey = `${this.id}::reconnect`;
2396
2405
  }
2397
2406
  get lastVersion() {
@@ -2442,7 +2451,8 @@ var TableSubscription = class {
2442
2451
  }
2443
2452
  try {
2444
2453
  this._pendingSnapshotRows = [];
2445
- const resumeFrom = this._lastVersion > 0 ? this._lastVersion : void 0;
2454
+ const resumeFrom = this._forceFreshSubscribe || this._lastVersion <= 0 ? void 0 : this._lastVersion;
2455
+ this._forceFreshSubscribe = false;
2446
2456
  await this._sendSubscribe(resumeFrom);
2447
2457
  } catch (error) {
2448
2458
  const wrapped = error instanceof Error ? error : new AoudaConnectionError("Subscription reconnect failed");
@@ -2462,6 +2472,9 @@ var TableSubscription = class {
2462
2472
  if (resumeFrom !== void 0) {
2463
2473
  message.resume_from = resumeFrom;
2464
2474
  }
2475
+ if (this._conflate !== void 0) {
2476
+ message.conflate = this._conflate;
2477
+ }
2465
2478
  await this._transport.send(message);
2466
2479
  }
2467
2480
  _handleMessage(message) {
@@ -2522,10 +2535,19 @@ var TableSubscription = class {
2522
2535
  key: message.key,
2523
2536
  version: message.version
2524
2537
  };
2538
+ if (message.values_skipped !== void 0) {
2539
+ event.values_skipped = message.values_skipped;
2540
+ }
2525
2541
  this._onChange?.(event);
2526
2542
  this._queue.push(event);
2527
2543
  }
2528
2544
  _handleServerError(message) {
2545
+ if (message.code === "SLOW_CONSUMER") {
2546
+ this._pendingSnapshotRows = [];
2547
+ this._lastVersion = 0;
2548
+ this._forceFreshSubscribe = true;
2549
+ return;
2550
+ }
2529
2551
  this._pendingSnapshotRows = [];
2530
2552
  const error = new AoudaConnectionError(
2531
2553
  `Subscription error (${message.code}): ${message.message}`
@@ -3239,7 +3261,8 @@ var TableQuery = class _TableQuery {
3239
3261
  {
3240
3262
  onSnapshot: options.onSnapshot,
3241
3263
  onChange: options.onChange,
3242
- onError: options.onError
3264
+ onError: options.onError,
3265
+ conflate: options.conflate
3243
3266
  },
3244
3267
  mergedFilter
3245
3268
  );
@@ -5099,6 +5122,7 @@ var WebSocketTransport = class {
5099
5122
  // Resolved/rejected when the auth handshake completes.
5100
5123
  this._authResolve = null;
5101
5124
  this._authReject = null;
5125
+ this._handshakeComplete = false;
5102
5126
  this._serverUrl = serverUrl;
5103
5127
  this._database = database;
5104
5128
  this._authHandler = options.authHandler;
@@ -5108,6 +5132,11 @@ var WebSocketTransport = class {
5108
5132
  this._maxMissedHeartbeats = options.maxMissedHeartbeats ?? DEFAULT_MAX_MISSED_HEARTBEATS;
5109
5133
  this._enableCompression = options.enableCompression ?? true;
5110
5134
  this._wireMode = options.wireMode ?? "json";
5135
+ this._authHandler?.setOnAccessTokenRefreshed((token) => {
5136
+ if (this._handshakeComplete && this._ws?.readyState === WS_READY_STATE_OPEN) {
5137
+ void this.send({ type: "re_auth", token });
5138
+ }
5139
+ });
5111
5140
  }
5112
5141
  // ─── Public API ────────────────────────────────────────────────────────────
5113
5142
  /** Latest version number from the most recent server `heartbeat` message. */
@@ -5280,6 +5309,7 @@ var WebSocketTransport = class {
5280
5309
  const resolve4 = this._authResolve;
5281
5310
  this._authResolve = null;
5282
5311
  this._authReject = null;
5312
+ this._handshakeComplete = true;
5283
5313
  if (resolve4) resolve4();
5284
5314
  break;
5285
5315
  }
@@ -5306,10 +5336,15 @@ var WebSocketTransport = class {
5306
5336
  break;
5307
5337
  }
5308
5338
  const id = "id" in msg ? msg.id : void 0;
5309
- if (id !== void 0 && id !== null) {
5339
+ if (id !== void 0 && id !== null && id !== "") {
5310
5340
  this._handlers.get(id)?.(msg);
5311
5341
  } else {
5312
5342
  this._handlers.get("__global__")?.(msg);
5343
+ for (const [key, handler] of this._handlers) {
5344
+ if (key !== "__global__") {
5345
+ handler(msg);
5346
+ }
5347
+ }
5313
5348
  }
5314
5349
  }
5315
5350
  // ─── Internal: reconnect ──────────────────────────────────────────────────