@lark-sh/client 0.1.7 → 0.1.8

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
@@ -89,6 +89,9 @@ declare class DatabaseReference {
89
89
  child(path: string): DatabaseReference;
90
90
  /**
91
91
  * Set the data at this location, overwriting any existing data.
92
+ *
93
+ * For volatile paths (high-frequency updates), this is fire-and-forget
94
+ * and resolves immediately without waiting for server confirmation.
92
95
  */
93
96
  set(value: unknown): Promise<void>;
94
97
  /**
@@ -113,6 +116,8 @@ declare class DatabaseReference {
113
116
  update(values: Record<string, unknown>): Promise<void>;
114
117
  /**
115
118
  * Remove the data at this location.
119
+ *
120
+ * For volatile paths, this is fire-and-forget.
116
121
  */
117
122
  remove(): Promise<void>;
118
123
  /**
@@ -587,6 +592,31 @@ declare class LarkDatabase {
587
592
  * @internal Send a delete operation.
588
593
  */
589
594
  _sendDelete(path: string): Promise<void>;
595
+ /**
596
+ * @internal Send a volatile set operation (fire-and-forget).
597
+ *
598
+ * Volatile writes skip:
599
+ * - Recovery checks (volatile paths don't participate in recovery)
600
+ * - Request ID generation (no ack expected)
601
+ * - Pending write tracking (no retry on reconnect)
602
+ * - pw field (no dependency tracking)
603
+ *
604
+ * The write is applied optimistically to local cache for UI feedback,
605
+ * but we don't await server confirmation.
606
+ */
607
+ _sendVolatileSet(path: string, value: unknown): void;
608
+ /**
609
+ * @internal Send a volatile update operation (fire-and-forget).
610
+ */
611
+ _sendVolatileUpdate(path: string, values: Record<string, unknown>): void;
612
+ /**
613
+ * @internal Send a volatile delete operation (fire-and-forget).
614
+ */
615
+ _sendVolatileDelete(path: string): void;
616
+ /**
617
+ * Check if a path is a volatile path (high-frequency, fire-and-forget).
618
+ */
619
+ isVolatilePath(path: string): boolean;
590
620
  /**
591
621
  * @internal Send a once (read) operation.
592
622
  *
@@ -726,17 +756,18 @@ declare function generatePushId(): string;
726
756
  * Volatile path matching utilities.
727
757
  *
728
758
  * Volatile paths are patterns where a wildcard matches exactly one path segment.
729
- * These paths use unreliable transport for better performance (UDP when available).
759
+ * These paths use unreliable transport for better performance (WebTransport datagrams when available).
730
760
  */
731
761
  /**
732
762
  * Check if a path matches any of the volatile path patterns.
733
763
  *
734
764
  * Pattern matching rules:
735
- * - Wildcard matches exactly one path segment (not zero, not multiple)
765
+ * - Wildcard matches exactly one path segment
736
766
  * - Patterns and paths are compared segment by segment
737
- * - Path must have the same number of segments as the pattern
767
+ * - If pattern is exhausted before path, it's still a match (descendant rule)
768
+ * - If path is exhausted before pattern, no match
738
769
  *
739
- * @param path - The path to check (e.g., "/players/abc/position")
770
+ * @param path - The path to check
740
771
  * @param patterns - Array of volatile patterns with wildcards
741
772
  * @returns true if the path matches any pattern
742
773
  */
package/dist/index.d.ts CHANGED
@@ -89,6 +89,9 @@ declare class DatabaseReference {
89
89
  child(path: string): DatabaseReference;
90
90
  /**
91
91
  * Set the data at this location, overwriting any existing data.
92
+ *
93
+ * For volatile paths (high-frequency updates), this is fire-and-forget
94
+ * and resolves immediately without waiting for server confirmation.
92
95
  */
93
96
  set(value: unknown): Promise<void>;
94
97
  /**
@@ -113,6 +116,8 @@ declare class DatabaseReference {
113
116
  update(values: Record<string, unknown>): Promise<void>;
114
117
  /**
115
118
  * Remove the data at this location.
119
+ *
120
+ * For volatile paths, this is fire-and-forget.
116
121
  */
117
122
  remove(): Promise<void>;
118
123
  /**
@@ -587,6 +592,31 @@ declare class LarkDatabase {
587
592
  * @internal Send a delete operation.
588
593
  */
589
594
  _sendDelete(path: string): Promise<void>;
595
+ /**
596
+ * @internal Send a volatile set operation (fire-and-forget).
597
+ *
598
+ * Volatile writes skip:
599
+ * - Recovery checks (volatile paths don't participate in recovery)
600
+ * - Request ID generation (no ack expected)
601
+ * - Pending write tracking (no retry on reconnect)
602
+ * - pw field (no dependency tracking)
603
+ *
604
+ * The write is applied optimistically to local cache for UI feedback,
605
+ * but we don't await server confirmation.
606
+ */
607
+ _sendVolatileSet(path: string, value: unknown): void;
608
+ /**
609
+ * @internal Send a volatile update operation (fire-and-forget).
610
+ */
611
+ _sendVolatileUpdate(path: string, values: Record<string, unknown>): void;
612
+ /**
613
+ * @internal Send a volatile delete operation (fire-and-forget).
614
+ */
615
+ _sendVolatileDelete(path: string): void;
616
+ /**
617
+ * Check if a path is a volatile path (high-frequency, fire-and-forget).
618
+ */
619
+ isVolatilePath(path: string): boolean;
590
620
  /**
591
621
  * @internal Send a once (read) operation.
592
622
  *
@@ -726,17 +756,18 @@ declare function generatePushId(): string;
726
756
  * Volatile path matching utilities.
727
757
  *
728
758
  * Volatile paths are patterns where a wildcard matches exactly one path segment.
729
- * These paths use unreliable transport for better performance (UDP when available).
759
+ * These paths use unreliable transport for better performance (WebTransport datagrams when available).
730
760
  */
731
761
  /**
732
762
  * Check if a path matches any of the volatile path patterns.
733
763
  *
734
764
  * Pattern matching rules:
735
- * - Wildcard matches exactly one path segment (not zero, not multiple)
765
+ * - Wildcard matches exactly one path segment
736
766
  * - Patterns and paths are compared segment by segment
737
- * - Path must have the same number of segments as the pattern
767
+ * - If pattern is exhausted before path, it's still a match (descendant rule)
768
+ * - If path is exhausted before pattern, no match
738
769
  *
739
- * @param path - The path to check (e.g., "/players/abc/position")
770
+ * @param path - The path to check
740
771
  * @param patterns - Array of volatile patterns with wildcards
741
772
  * @returns true if the path matches any pattern
742
773
  */
package/dist/index.js CHANGED
@@ -1820,8 +1820,15 @@ var DatabaseReference = class _DatabaseReference {
1820
1820
  // ============================================
1821
1821
  /**
1822
1822
  * Set the data at this location, overwriting any existing data.
1823
+ *
1824
+ * For volatile paths (high-frequency updates), this is fire-and-forget
1825
+ * and resolves immediately without waiting for server confirmation.
1823
1826
  */
1824
1827
  async set(value) {
1828
+ if (this._db.isVolatilePath(this._path)) {
1829
+ this._db._sendVolatileSet(this._path, value);
1830
+ return;
1831
+ }
1825
1832
  await this._db._sendSet(this._path, value);
1826
1833
  }
1827
1834
  /**
@@ -1858,13 +1865,23 @@ var DatabaseReference = class _DatabaseReference {
1858
1865
  }
1859
1866
  await this._db._sendTransaction(ops);
1860
1867
  } else {
1868
+ if (this._db.isVolatilePath(this._path)) {
1869
+ this._db._sendVolatileUpdate(this._path, values);
1870
+ return;
1871
+ }
1861
1872
  await this._db._sendUpdate(this._path, values);
1862
1873
  }
1863
1874
  }
1864
1875
  /**
1865
1876
  * Remove the data at this location.
1877
+ *
1878
+ * For volatile paths, this is fire-and-forget.
1866
1879
  */
1867
1880
  async remove() {
1881
+ if (this._db.isVolatilePath(this._path)) {
1882
+ this._db._sendVolatileDelete(this._path);
1883
+ return;
1884
+ }
1868
1885
  await this._db._sendDelete(this._path);
1869
1886
  }
1870
1887
  /**
@@ -2317,6 +2334,28 @@ function decodeJwtPayload(token) {
2317
2334
  return JSON.parse(decoded);
2318
2335
  }
2319
2336
 
2337
+ // src/utils/volatile.ts
2338
+ function isVolatilePath(path, patterns) {
2339
+ if (!patterns || patterns.length === 0) {
2340
+ return false;
2341
+ }
2342
+ const segments = path.replace(/^\//, "").split("/").filter((s) => s.length > 0);
2343
+ return patterns.some((pattern) => {
2344
+ const patternSegments = pattern.replace(/^\//, "").split("/").filter((s) => s.length > 0);
2345
+ if (segments.length < patternSegments.length) {
2346
+ return false;
2347
+ }
2348
+ for (let i = 0; i < patternSegments.length; i++) {
2349
+ const p = patternSegments[i];
2350
+ const s = segments[i];
2351
+ if (p !== "*" && p !== s) {
2352
+ return false;
2353
+ }
2354
+ }
2355
+ return true;
2356
+ });
2357
+ }
2358
+
2320
2359
  // src/LarkDatabase.ts
2321
2360
  var RECONNECT_BASE_DELAY_MS = 1e3;
2322
2361
  var RECONNECT_MAX_DELAY_MS = 3e4;
@@ -2940,6 +2979,62 @@ var LarkDatabase = class {
2940
2979
  this.send(message);
2941
2980
  await this.messageQueue.registerRequest(requestId);
2942
2981
  }
2982
+ // ============================================
2983
+ // Volatile Write Operations (Fire-and-Forget)
2984
+ // ============================================
2985
+ /**
2986
+ * @internal Send a volatile set operation (fire-and-forget).
2987
+ *
2988
+ * Volatile writes skip:
2989
+ * - Recovery checks (volatile paths don't participate in recovery)
2990
+ * - Request ID generation (no ack expected)
2991
+ * - Pending write tracking (no retry on reconnect)
2992
+ * - pw field (no dependency tracking)
2993
+ *
2994
+ * The write is applied optimistically to local cache for UI feedback,
2995
+ * but we don't await server confirmation.
2996
+ */
2997
+ _sendVolatileSet(path, value) {
2998
+ const normalizedPath = normalizePath(path) || "/";
2999
+ this.subscriptionManager.applyOptimisticWrite(normalizedPath, value, "", "set");
3000
+ const message = {
3001
+ o: "s",
3002
+ p: normalizedPath,
3003
+ v: value
3004
+ };
3005
+ this.send(message);
3006
+ }
3007
+ /**
3008
+ * @internal Send a volatile update operation (fire-and-forget).
3009
+ */
3010
+ _sendVolatileUpdate(path, values) {
3011
+ const normalizedPath = normalizePath(path) || "/";
3012
+ this.subscriptionManager.applyOptimisticWrite(normalizedPath, values, "", "update");
3013
+ const message = {
3014
+ o: "u",
3015
+ p: normalizedPath,
3016
+ v: values
3017
+ };
3018
+ this.send(message);
3019
+ }
3020
+ /**
3021
+ * @internal Send a volatile delete operation (fire-and-forget).
3022
+ */
3023
+ _sendVolatileDelete(path) {
3024
+ const normalizedPath = normalizePath(path) || "/";
3025
+ this.subscriptionManager.applyOptimisticWrite(normalizedPath, null, "", "delete");
3026
+ const message = {
3027
+ o: "d",
3028
+ p: normalizedPath
3029
+ };
3030
+ this.send(message);
3031
+ }
3032
+ /**
3033
+ * Check if a path is a volatile path (high-frequency, fire-and-forget).
3034
+ */
3035
+ isVolatilePath(path) {
3036
+ return isVolatilePath(path, this._volatilePaths);
3037
+ }
2943
3038
  /**
2944
3039
  * @internal Send a once (read) operation.
2945
3040
  *
@@ -3048,21 +3143,6 @@ var LarkDatabase = class {
3048
3143
  this.subscriptionManager.unsubscribeAll(path);
3049
3144
  }
3050
3145
  };
3051
-
3052
- // src/utils/volatile.ts
3053
- function isVolatilePath(path, patterns) {
3054
- if (!patterns || patterns.length === 0) {
3055
- return false;
3056
- }
3057
- const segments = path.replace(/^\//, "").split("/");
3058
- return patterns.some((pattern) => {
3059
- const patternSegments = pattern.split("/");
3060
- if (segments.length !== patternSegments.length) {
3061
- return false;
3062
- }
3063
- return patternSegments.every((p, i) => p === "*" || p === segments[i]);
3064
- });
3065
- }
3066
3146
  // Annotate the CommonJS export names for ESM import in node:
3067
3147
  0 && (module.exports = {
3068
3148
  DataSnapshot,