@abraca/dabra 1.8.0 → 1.8.2

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/index.d.ts CHANGED
@@ -826,6 +826,13 @@ declare class AbracadabraProvider extends AbracadabraBaseProvider {
826
826
  * the offline store is disabled or when no snapshot has been saved yet.
827
827
  */
828
828
  readonly ready: Promise<void>;
829
+ /**
830
+ * True once `_initFromOfflineStore()` has applied a non-empty snapshot or
831
+ * at least one pending update to the Y.Doc. Lets the UI decide to render
832
+ * cached content immediately instead of waiting for a server round-trip.
833
+ * Only meaningful after `await ready`.
834
+ */
835
+ hasCachedContent: boolean;
829
836
  constructor(configuration: AbracadabraProviderConfiguration);
830
837
  /**
831
838
  * Extract the server hostname from the provider configuration.
@@ -1157,6 +1164,7 @@ type onServerErrorParameters = {
1157
1164
  source: string;
1158
1165
  code: string;
1159
1166
  message: string;
1167
+ meta?: Record<string, unknown>;
1160
1168
  };
1161
1169
  type StatesArray = {
1162
1170
  clientId: number;
@@ -1446,7 +1454,14 @@ interface CompleteAbracadabraWSConfiguration {
1446
1454
  */
1447
1455
  WebSocketPolyfill: any;
1448
1456
  /**
1449
- * Disconnect when no message is received for the defined amount of milliseconds.
1457
+ * Disconnect and reconnect when no message is received for the defined amount
1458
+ * of milliseconds.
1459
+ *
1460
+ * Defaults to 30000 ms to match y-protocols/awareness `Awareness.outdatedTime`
1461
+ * (also 30 s). Awareness heartbeats are what normally keep this timer
1462
+ * resetting, so this value should be ≥ the largest `outdatedTime` of any
1463
+ * awareness instance attached to this socket. If you pass a custom awareness
1464
+ * with a non-default `outdatedTime`, pass the matching value here too.
1450
1465
  */
1451
1466
  messageReconnectTimeout: number;
1452
1467
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abraca/dabra",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "abracadabra provider",
5
5
  "keywords": [
6
6
  "abracadabra",
@@ -375,9 +375,9 @@ export class AbracadabraBaseProvider extends EventEmitter {
375
375
  try {
376
376
  const parsed = JSON.parse(payload);
377
377
  if (parsed?.type === "error" && parsed.source && parsed.code) {
378
- const { source, code, message } = parsed;
379
- console.warn(`[Abracadabra] Server error: ${source} (${code}) — ${message}`);
380
- this.emit("serverError", { source, code, message: message ?? "" });
378
+ const { source, code, message, meta } = parsed;
379
+ console.warn(`[Abracadabra] Server error: ${source} (${code}) — ${message}`, meta ?? "");
380
+ this.emit("serverError", { source, code, message: message ?? "", meta });
381
381
  return;
382
382
  }
383
383
  } catch {
@@ -129,6 +129,14 @@ export class AbracadabraProvider extends AbracadabraBaseProvider {
129
129
  */
130
130
  public readonly ready: Promise<void>;
131
131
 
132
+ /**
133
+ * True once `_initFromOfflineStore()` has applied a non-empty snapshot or
134
+ * at least one pending update to the Y.Doc. Lets the UI decide to render
135
+ * cached content immediately instead of waiting for a server round-trip.
136
+ * Only meaningful after `await ready`.
137
+ */
138
+ public hasCachedContent = false;
139
+
132
140
  constructor(configuration: AbracadabraProviderConfiguration) {
133
141
  // Derive URL and token from client when not explicitly set.
134
142
  const resolved = { ...configuration } as AbracadabraBaseProviderConfiguration;
@@ -225,9 +233,11 @@ export class AbracadabraProvider extends AbracadabraBaseProvider {
225
233
 
226
234
  if (snapshot) {
227
235
  Y.applyUpdate(this.document, snapshot, this.offlineStore);
236
+ this.hasCachedContent = true;
228
237
  }
229
238
  for (const update of pending) {
230
239
  Y.applyUpdate(this.document, update, this.offlineStore);
240
+ this.hasCachedContent = true;
231
241
  }
232
242
  }
233
243
 
@@ -55,7 +55,14 @@ export interface CompleteAbracadabraWSConfiguration {
55
55
  WebSocketPolyfill: any;
56
56
 
57
57
  /**
58
- * Disconnect when no message is received for the defined amount of milliseconds.
58
+ * Disconnect and reconnect when no message is received for the defined amount
59
+ * of milliseconds.
60
+ *
61
+ * Defaults to 30000 ms to match y-protocols/awareness `Awareness.outdatedTime`
62
+ * (also 30 s). Awareness heartbeats are what normally keep this timer
63
+ * resetting, so this value should be ≥ the largest `outdatedTime` of any
64
+ * awareness instance attached to this socket. If you pass a custom awareness
65
+ * with a non-default `outdatedTime`, pass the matching value here too.
59
66
  */
60
67
  messageReconnectTimeout: number;
61
68
  /**
@@ -121,7 +128,8 @@ export class AbracadabraWS extends EventEmitter {
121
128
  // @ts-ignore
122
129
  document: undefined,
123
130
  WebSocketPolyfill: undefined,
124
- // TODO: this should depend on awareness.outdatedTime
131
+ // Matches y-protocols/awareness Awareness.outdatedTime default (30 s).
132
+ // See the `messageReconnectTimeout` JSDoc on CompleteAbracadabraWSConfiguration.
125
133
  messageReconnectTimeout: 30000,
126
134
  // 1 second
127
135
  delay: 1000,
package/src/types.ts CHANGED
@@ -128,6 +128,7 @@ export type onServerErrorParameters = {
128
128
  source: string;
129
129
  code: string;
130
130
  message: string;
131
+ meta?: Record<string, unknown>;
131
132
  };
132
133
 
133
134
  export type StatesArray = { clientId: number; [key: string | number]: any }[];