@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.mjs CHANGED
@@ -1777,8 +1777,15 @@ var DatabaseReference = class _DatabaseReference {
1777
1777
  // ============================================
1778
1778
  /**
1779
1779
  * Set the data at this location, overwriting any existing data.
1780
+ *
1781
+ * For volatile paths (high-frequency updates), this is fire-and-forget
1782
+ * and resolves immediately without waiting for server confirmation.
1780
1783
  */
1781
1784
  async set(value) {
1785
+ if (this._db.isVolatilePath(this._path)) {
1786
+ this._db._sendVolatileSet(this._path, value);
1787
+ return;
1788
+ }
1782
1789
  await this._db._sendSet(this._path, value);
1783
1790
  }
1784
1791
  /**
@@ -1815,13 +1822,23 @@ var DatabaseReference = class _DatabaseReference {
1815
1822
  }
1816
1823
  await this._db._sendTransaction(ops);
1817
1824
  } else {
1825
+ if (this._db.isVolatilePath(this._path)) {
1826
+ this._db._sendVolatileUpdate(this._path, values);
1827
+ return;
1828
+ }
1818
1829
  await this._db._sendUpdate(this._path, values);
1819
1830
  }
1820
1831
  }
1821
1832
  /**
1822
1833
  * Remove the data at this location.
1834
+ *
1835
+ * For volatile paths, this is fire-and-forget.
1823
1836
  */
1824
1837
  async remove() {
1838
+ if (this._db.isVolatilePath(this._path)) {
1839
+ this._db._sendVolatileDelete(this._path);
1840
+ return;
1841
+ }
1825
1842
  await this._db._sendDelete(this._path);
1826
1843
  }
1827
1844
  /**
@@ -2274,6 +2291,28 @@ function decodeJwtPayload(token) {
2274
2291
  return JSON.parse(decoded);
2275
2292
  }
2276
2293
 
2294
+ // src/utils/volatile.ts
2295
+ function isVolatilePath(path, patterns) {
2296
+ if (!patterns || patterns.length === 0) {
2297
+ return false;
2298
+ }
2299
+ const segments = path.replace(/^\//, "").split("/").filter((s) => s.length > 0);
2300
+ return patterns.some((pattern) => {
2301
+ const patternSegments = pattern.replace(/^\//, "").split("/").filter((s) => s.length > 0);
2302
+ if (segments.length < patternSegments.length) {
2303
+ return false;
2304
+ }
2305
+ for (let i = 0; i < patternSegments.length; i++) {
2306
+ const p = patternSegments[i];
2307
+ const s = segments[i];
2308
+ if (p !== "*" && p !== s) {
2309
+ return false;
2310
+ }
2311
+ }
2312
+ return true;
2313
+ });
2314
+ }
2315
+
2277
2316
  // src/LarkDatabase.ts
2278
2317
  var RECONNECT_BASE_DELAY_MS = 1e3;
2279
2318
  var RECONNECT_MAX_DELAY_MS = 3e4;
@@ -2897,6 +2936,62 @@ var LarkDatabase = class {
2897
2936
  this.send(message);
2898
2937
  await this.messageQueue.registerRequest(requestId);
2899
2938
  }
2939
+ // ============================================
2940
+ // Volatile Write Operations (Fire-and-Forget)
2941
+ // ============================================
2942
+ /**
2943
+ * @internal Send a volatile set operation (fire-and-forget).
2944
+ *
2945
+ * Volatile writes skip:
2946
+ * - Recovery checks (volatile paths don't participate in recovery)
2947
+ * - Request ID generation (no ack expected)
2948
+ * - Pending write tracking (no retry on reconnect)
2949
+ * - pw field (no dependency tracking)
2950
+ *
2951
+ * The write is applied optimistically to local cache for UI feedback,
2952
+ * but we don't await server confirmation.
2953
+ */
2954
+ _sendVolatileSet(path, value) {
2955
+ const normalizedPath = normalizePath(path) || "/";
2956
+ this.subscriptionManager.applyOptimisticWrite(normalizedPath, value, "", "set");
2957
+ const message = {
2958
+ o: "s",
2959
+ p: normalizedPath,
2960
+ v: value
2961
+ };
2962
+ this.send(message);
2963
+ }
2964
+ /**
2965
+ * @internal Send a volatile update operation (fire-and-forget).
2966
+ */
2967
+ _sendVolatileUpdate(path, values) {
2968
+ const normalizedPath = normalizePath(path) || "/";
2969
+ this.subscriptionManager.applyOptimisticWrite(normalizedPath, values, "", "update");
2970
+ const message = {
2971
+ o: "u",
2972
+ p: normalizedPath,
2973
+ v: values
2974
+ };
2975
+ this.send(message);
2976
+ }
2977
+ /**
2978
+ * @internal Send a volatile delete operation (fire-and-forget).
2979
+ */
2980
+ _sendVolatileDelete(path) {
2981
+ const normalizedPath = normalizePath(path) || "/";
2982
+ this.subscriptionManager.applyOptimisticWrite(normalizedPath, null, "", "delete");
2983
+ const message = {
2984
+ o: "d",
2985
+ p: normalizedPath
2986
+ };
2987
+ this.send(message);
2988
+ }
2989
+ /**
2990
+ * Check if a path is a volatile path (high-frequency, fire-and-forget).
2991
+ */
2992
+ isVolatilePath(path) {
2993
+ return isVolatilePath(path, this._volatilePaths);
2994
+ }
2900
2995
  /**
2901
2996
  * @internal Send a once (read) operation.
2902
2997
  *
@@ -3005,21 +3100,6 @@ var LarkDatabase = class {
3005
3100
  this.subscriptionManager.unsubscribeAll(path);
3006
3101
  }
3007
3102
  };
3008
-
3009
- // src/utils/volatile.ts
3010
- function isVolatilePath(path, patterns) {
3011
- if (!patterns || patterns.length === 0) {
3012
- return false;
3013
- }
3014
- const segments = path.replace(/^\//, "").split("/");
3015
- return patterns.some((pattern) => {
3016
- const patternSegments = pattern.split("/");
3017
- if (segments.length !== patternSegments.length) {
3018
- return false;
3019
- }
3020
- return patternSegments.every((p, i) => p === "*" || p === segments[i]);
3021
- });
3022
- }
3023
3103
  export {
3024
3104
  DataSnapshot,
3025
3105
  DatabaseReference,