@lark-sh/client 0.1.5 → 0.1.6

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
@@ -600,16 +600,11 @@ interface PendingWrite {
600
600
  }
601
601
  declare class PendingWriteManager {
602
602
  private pending;
603
- private counter;
604
- /**
605
- * Generate a unique operation ID.
606
- * Format: op_{timestamp}_{counter}_{random}
607
- */
608
- generateOid(): string;
609
603
  /**
610
604
  * Track a new pending write operation.
605
+ * Uses the request ID as the tracking key.
611
606
  */
612
- trackWrite(oid: string, operation: WriteOperation, path: string, value?: unknown): void;
607
+ trackWrite(requestId: string, operation: WriteOperation, path: string, value?: unknown): void;
613
608
  /**
614
609
  * Called when a write is acknowledged by the server.
615
610
  * Removes the write from pending tracking.
package/dist/index.d.ts CHANGED
@@ -600,16 +600,11 @@ interface PendingWrite {
600
600
  }
601
601
  declare class PendingWriteManager {
602
602
  private pending;
603
- private counter;
604
- /**
605
- * Generate a unique operation ID.
606
- * Format: op_{timestamp}_{counter}_{random}
607
- */
608
- generateOid(): string;
609
603
  /**
610
604
  * Track a new pending write operation.
605
+ * Uses the request ID as the tracking key.
611
606
  */
612
- trackWrite(oid: string, operation: WriteOperation, path: string, value?: unknown): void;
607
+ trackWrite(requestId: string, operation: WriteOperation, path: string, value?: unknown): void;
613
608
  /**
614
609
  * Called when a write is acknowledged by the server.
615
610
  * Removes the write from pending tracking.
package/dist/index.js CHANGED
@@ -246,23 +246,14 @@ var MessageQueue = class {
246
246
  var PendingWriteManager = class {
247
247
  constructor() {
248
248
  this.pending = /* @__PURE__ */ new Map();
249
- this.counter = 0;
250
- }
251
- /**
252
- * Generate a unique operation ID.
253
- * Format: op_{timestamp}_{counter}_{random}
254
- */
255
- generateOid() {
256
- this.counter++;
257
- const random = Math.random().toString(36).slice(2, 8);
258
- return `op_${Date.now()}_${this.counter}_${random}`;
259
249
  }
260
250
  /**
261
251
  * Track a new pending write operation.
252
+ * Uses the request ID as the tracking key.
262
253
  */
263
- trackWrite(oid, operation, path, value) {
264
- this.pending.set(oid, {
265
- oid,
254
+ trackWrite(requestId, operation, path, value) {
255
+ this.pending.set(requestId, {
256
+ oid: requestId,
266
257
  operation,
267
258
  path,
268
259
  value,
@@ -2040,13 +2031,11 @@ var LarkDatabase = class {
2040
2031
  */
2041
2032
  async _sendTransaction(ops) {
2042
2033
  const requestId = this.messageQueue.nextRequestId();
2043
- const oid = this.pendingWrites.generateOid();
2044
- this.pendingWrites.trackWrite(oid, "transaction", "/", ops);
2034
+ this.pendingWrites.trackWrite(requestId, "transaction", "/", ops);
2045
2035
  const message = {
2046
2036
  o: "tx",
2047
2037
  ops,
2048
- r: requestId,
2049
- oid
2038
+ r: requestId
2050
2039
  };
2051
2040
  this.send(message);
2052
2041
  await this.messageQueue.registerRequest(requestId);
@@ -2093,10 +2082,10 @@ var LarkDatabase = class {
2093
2082
  this.ws?.send(JSON.stringify({ o: "po" }));
2094
2083
  return;
2095
2084
  }
2096
- if (isAckMessage(message) && message.oid) {
2097
- this.pendingWrites.onAck(message.oid);
2098
- } else if (isNackMessage(message) && message.oid) {
2099
- this.pendingWrites.onNack(message.oid);
2085
+ if (isAckMessage(message)) {
2086
+ this.pendingWrites.onAck(message.a);
2087
+ } else if (isNackMessage(message)) {
2088
+ this.pendingWrites.onNack(message.n);
2100
2089
  }
2101
2090
  if (this.messageQueue.handleMessage(message)) {
2102
2091
  return;
@@ -2130,15 +2119,13 @@ var LarkDatabase = class {
2130
2119
  */
2131
2120
  async _sendSet(path, value, priority) {
2132
2121
  const requestId = this.messageQueue.nextRequestId();
2133
- const oid = this.pendingWrites.generateOid();
2134
2122
  const normalizedPath = normalizePath(path) || "/";
2135
- this.pendingWrites.trackWrite(oid, "set", normalizedPath, value);
2123
+ this.pendingWrites.trackWrite(requestId, "set", normalizedPath, value);
2136
2124
  const message = {
2137
2125
  o: "s",
2138
2126
  p: normalizedPath,
2139
2127
  v: value,
2140
- r: requestId,
2141
- oid
2128
+ r: requestId
2142
2129
  };
2143
2130
  if (priority !== void 0) {
2144
2131
  message.y = priority;
@@ -2151,15 +2138,13 @@ var LarkDatabase = class {
2151
2138
  */
2152
2139
  async _sendUpdate(path, values) {
2153
2140
  const requestId = this.messageQueue.nextRequestId();
2154
- const oid = this.pendingWrites.generateOid();
2155
2141
  const normalizedPath = normalizePath(path) || "/";
2156
- this.pendingWrites.trackWrite(oid, "update", normalizedPath, values);
2142
+ this.pendingWrites.trackWrite(requestId, "update", normalizedPath, values);
2157
2143
  const message = {
2158
2144
  o: "u",
2159
2145
  p: normalizedPath,
2160
2146
  v: values,
2161
- r: requestId,
2162
- oid
2147
+ r: requestId
2163
2148
  };
2164
2149
  this.send(message);
2165
2150
  await this.messageQueue.registerRequest(requestId);
@@ -2169,14 +2154,12 @@ var LarkDatabase = class {
2169
2154
  */
2170
2155
  async _sendDelete(path) {
2171
2156
  const requestId = this.messageQueue.nextRequestId();
2172
- const oid = this.pendingWrites.generateOid();
2173
2157
  const normalizedPath = normalizePath(path) || "/";
2174
- this.pendingWrites.trackWrite(oid, "delete", normalizedPath);
2158
+ this.pendingWrites.trackWrite(requestId, "delete", normalizedPath);
2175
2159
  const message = {
2176
2160
  o: "d",
2177
2161
  p: normalizedPath,
2178
- r: requestId,
2179
- oid
2162
+ r: requestId
2180
2163
  };
2181
2164
  this.send(message);
2182
2165
  await this.messageQueue.registerRequest(requestId);
@@ -2186,15 +2169,13 @@ var LarkDatabase = class {
2186
2169
  */
2187
2170
  async _sendPush(path, value) {
2188
2171
  const requestId = this.messageQueue.nextRequestId();
2189
- const oid = this.pendingWrites.generateOid();
2190
2172
  const normalizedPath = normalizePath(path) || "/";
2191
- this.pendingWrites.trackWrite(oid, "push", normalizedPath, value);
2173
+ this.pendingWrites.trackWrite(requestId, "push", normalizedPath, value);
2192
2174
  const message = {
2193
2175
  o: "p",
2194
2176
  p: normalizedPath,
2195
2177
  v: value,
2196
- r: requestId,
2197
- oid
2178
+ r: requestId
2198
2179
  };
2199
2180
  this.send(message);
2200
2181
  const key = await this.messageQueue.registerRequest(requestId);