@lark-sh/client 0.1.3 → 0.1.4

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.mts CHANGED
@@ -283,6 +283,7 @@ declare class LarkDatabase {
283
283
  private _auth;
284
284
  private _databaseId;
285
285
  private _coordinatorUrl;
286
+ private _volatilePaths;
286
287
  private ws;
287
288
  private messageQueue;
288
289
  private subscriptionManager;
@@ -302,6 +303,12 @@ declare class LarkDatabase {
302
303
  * @internal Get the base URL for reference toString().
303
304
  */
304
305
  _getBaseUrl(): string;
306
+ /**
307
+ * Get the volatile path patterns from the server.
308
+ * These patterns indicate which paths should use unreliable transport.
309
+ * WebSocket always uses reliable transport, but this is stored for future UDP support.
310
+ */
311
+ get volatilePaths(): string[];
305
312
  /**
306
313
  * Connect to a database.
307
314
  *
@@ -424,4 +431,24 @@ declare class LarkError extends Error {
424
431
  */
425
432
  declare function generatePushId(): string;
426
433
 
427
- export { type AuthInfo, type ConnectOptions, DataSnapshot, DatabaseReference, type EventType, LarkDatabase, LarkError, OnDisconnect, type QueryState, type SnapshotCallback$1 as SnapshotCallback, generatePushId };
434
+ /**
435
+ * Volatile path matching utilities.
436
+ *
437
+ * Volatile paths are patterns where a wildcard matches exactly one path segment.
438
+ * These paths use unreliable transport for better performance (UDP when available).
439
+ */
440
+ /**
441
+ * Check if a path matches any of the volatile path patterns.
442
+ *
443
+ * Pattern matching rules:
444
+ * - Wildcard matches exactly one path segment (not zero, not multiple)
445
+ * - Patterns and paths are compared segment by segment
446
+ * - Path must have the same number of segments as the pattern
447
+ *
448
+ * @param path - The path to check (e.g., "/players/abc/position")
449
+ * @param patterns - Array of volatile patterns with wildcards
450
+ * @returns true if the path matches any pattern
451
+ */
452
+ declare function isVolatilePath(path: string, patterns: string[] | null | undefined): boolean;
453
+
454
+ export { type AuthInfo, type ConnectOptions, DataSnapshot, DatabaseReference, type EventType, LarkDatabase, LarkError, OnDisconnect, type QueryState, type SnapshotCallback$1 as SnapshotCallback, generatePushId, isVolatilePath };
package/dist/index.d.ts CHANGED
@@ -283,6 +283,7 @@ declare class LarkDatabase {
283
283
  private _auth;
284
284
  private _databaseId;
285
285
  private _coordinatorUrl;
286
+ private _volatilePaths;
286
287
  private ws;
287
288
  private messageQueue;
288
289
  private subscriptionManager;
@@ -302,6 +303,12 @@ declare class LarkDatabase {
302
303
  * @internal Get the base URL for reference toString().
303
304
  */
304
305
  _getBaseUrl(): string;
306
+ /**
307
+ * Get the volatile path patterns from the server.
308
+ * These patterns indicate which paths should use unreliable transport.
309
+ * WebSocket always uses reliable transport, but this is stored for future UDP support.
310
+ */
311
+ get volatilePaths(): string[];
305
312
  /**
306
313
  * Connect to a database.
307
314
  *
@@ -424,4 +431,24 @@ declare class LarkError extends Error {
424
431
  */
425
432
  declare function generatePushId(): string;
426
433
 
427
- export { type AuthInfo, type ConnectOptions, DataSnapshot, DatabaseReference, type EventType, LarkDatabase, LarkError, OnDisconnect, type QueryState, type SnapshotCallback$1 as SnapshotCallback, generatePushId };
434
+ /**
435
+ * Volatile path matching utilities.
436
+ *
437
+ * Volatile paths are patterns where a wildcard matches exactly one path segment.
438
+ * These paths use unreliable transport for better performance (UDP when available).
439
+ */
440
+ /**
441
+ * Check if a path matches any of the volatile path patterns.
442
+ *
443
+ * Pattern matching rules:
444
+ * - Wildcard matches exactly one path segment (not zero, not multiple)
445
+ * - Patterns and paths are compared segment by segment
446
+ * - Path must have the same number of segments as the pattern
447
+ *
448
+ * @param path - The path to check (e.g., "/players/abc/position")
449
+ * @param patterns - Array of volatile patterns with wildcards
450
+ * @returns true if the path matches any pattern
451
+ */
452
+ declare function isVolatilePath(path: string, patterns: string[] | null | undefined): boolean;
453
+
454
+ export { type AuthInfo, type ConnectOptions, DataSnapshot, DatabaseReference, type EventType, LarkDatabase, LarkError, OnDisconnect, type QueryState, type SnapshotCallback$1 as SnapshotCallback, generatePushId, isVolatilePath };
package/dist/index.js CHANGED
@@ -35,7 +35,8 @@ __export(index_exports, {
35
35
  LarkDatabase: () => LarkDatabase,
36
36
  LarkError: () => LarkError,
37
37
  OnDisconnect: () => OnDisconnect,
38
- generatePushId: () => generatePushId
38
+ generatePushId: () => generatePushId,
39
+ isVolatilePath: () => isVolatilePath
39
40
  });
40
41
  module.exports = __toCommonJS(index_exports);
41
42
 
@@ -119,10 +120,10 @@ var LarkError = class _LarkError extends Error {
119
120
 
120
121
  // src/protocol/messages.ts
121
122
  function isAckMessage(msg) {
122
- return "a" in msg && !("uid" in msg);
123
+ return "a" in msg;
123
124
  }
124
- function isJoinAckMessage(msg) {
125
- return "a" in msg && "uid" in msg;
125
+ function isJoinCompleteMessage(msg) {
126
+ return "jc" in msg;
126
127
  }
127
128
  function isNackMessage(msg) {
128
129
  return "n" in msg;
@@ -178,16 +179,12 @@ var MessageQueue = class {
178
179
  * @returns true if the message was handled (was a response), false otherwise
179
180
  */
180
181
  handleMessage(message) {
181
- if (isJoinAckMessage(message)) {
182
- const pending = this.pending.get(message.a);
182
+ if (isJoinCompleteMessage(message)) {
183
+ const pending = this.pending.get(message.jc);
183
184
  if (pending) {
184
185
  clearTimeout(pending.timeout);
185
- this.pending.delete(message.a);
186
- pending.resolve({
187
- uid: message.uid,
188
- provider: message.provider,
189
- token: message.token
190
- });
186
+ this.pending.delete(message.jc);
187
+ pending.resolve(message.vp || []);
191
188
  return true;
192
189
  }
193
190
  }
@@ -1279,6 +1276,7 @@ var LarkDatabase = class {
1279
1276
  this._auth = null;
1280
1277
  this._databaseId = null;
1281
1278
  this._coordinatorUrl = null;
1279
+ this._volatilePaths = [];
1282
1280
  this.ws = null;
1283
1281
  // Event callbacks
1284
1282
  this.connectCallbacks = /* @__PURE__ */ new Set();
@@ -1311,6 +1309,14 @@ var LarkDatabase = class {
1311
1309
  }
1312
1310
  return "lark://";
1313
1311
  }
1312
+ /**
1313
+ * Get the volatile path patterns from the server.
1314
+ * These patterns indicate which paths should use unreliable transport.
1315
+ * WebSocket always uses reliable transport, but this is stored for future UDP support.
1316
+ */
1317
+ get volatilePaths() {
1318
+ return this._volatilePaths;
1319
+ }
1314
1320
  // ============================================
1315
1321
  // Connection Management
1316
1322
  // ============================================
@@ -1351,7 +1357,8 @@ var LarkDatabase = class {
1351
1357
  r: requestId
1352
1358
  };
1353
1359
  this.send(joinMessage);
1354
- await this.messageQueue.registerRequest(requestId);
1360
+ const volatilePaths = await this.messageQueue.registerRequest(requestId);
1361
+ this._volatilePaths = volatilePaths || [];
1355
1362
  const jwtPayload = decodeJwtPayload(connectResponse.token);
1356
1363
  this._auth = {
1357
1364
  uid: jwtPayload.sub,
@@ -1404,6 +1411,7 @@ var LarkDatabase = class {
1404
1411
  this._state = "disconnected";
1405
1412
  this._auth = null;
1406
1413
  this._databaseId = null;
1414
+ this._volatilePaths = [];
1407
1415
  this._coordinatorUrl = null;
1408
1416
  this.subscriptionManager.clear();
1409
1417
  this.messageQueue.rejectAll(new Error("Connection closed"));
@@ -1653,6 +1661,21 @@ var LarkDatabase = class {
1653
1661
  this.subscriptionManager.unsubscribeAll(path);
1654
1662
  }
1655
1663
  };
1664
+
1665
+ // src/utils/volatile.ts
1666
+ function isVolatilePath(path, patterns) {
1667
+ if (!patterns || patterns.length === 0) {
1668
+ return false;
1669
+ }
1670
+ const segments = path.replace(/^\//, "").split("/");
1671
+ return patterns.some((pattern) => {
1672
+ const patternSegments = pattern.split("/");
1673
+ if (segments.length !== patternSegments.length) {
1674
+ return false;
1675
+ }
1676
+ return patternSegments.every((p, i) => p === "*" || p === segments[i]);
1677
+ });
1678
+ }
1656
1679
  // Annotate the CommonJS export names for ESM import in node:
1657
1680
  0 && (module.exports = {
1658
1681
  DataSnapshot,
@@ -1660,6 +1683,7 @@ var LarkDatabase = class {
1660
1683
  LarkDatabase,
1661
1684
  LarkError,
1662
1685
  OnDisconnect,
1663
- generatePushId
1686
+ generatePushId,
1687
+ isVolatilePath
1664
1688
  });
1665
1689
  //# sourceMappingURL=index.js.map