@lark-sh/client 0.1.18 → 0.1.19

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.
@@ -2829,6 +2829,8 @@ function generatePushId() {
2829
2829
  // src/utils/validation.ts
2830
2830
  var MAX_KEY_BYTES = 768;
2831
2831
  var MAX_STRING_VALUE_BYTES = 10 * 1024 * 1024;
2832
+ var MAX_WRITE_BYTES = 16 * 1024 * 1024;
2833
+ var MAX_VOLATILE_WRITE_BYTES = 2 * 1024;
2832
2834
  var INVALID_KEY_CHARS = /[.#$\[\]\/]/;
2833
2835
  var CONTROL_CHARS = /[\x00-\x1f\x7f]/;
2834
2836
  function hasControlChars(str) {
@@ -2946,6 +2948,30 @@ function validateValue(value, context, path = "") {
2946
2948
  function validateWriteData(value, context) {
2947
2949
  validateValue(value, context);
2948
2950
  }
2951
+ function getJsonByteSize(value) {
2952
+ const json = JSON.stringify(value);
2953
+ return getByteLength(json);
2954
+ }
2955
+ function validateWriteSize(value, context) {
2956
+ const byteSize = getJsonByteSize(value);
2957
+ if (byteSize > MAX_WRITE_BYTES) {
2958
+ const sizeMB = Math.round(byteSize / 1024 / 1024 * 100) / 100;
2959
+ throw new LarkError(
2960
+ ErrorCode.INVALID_DATA,
2961
+ `${context ? `${context}: ` : ""}write exceeds 16 MB limit (got ${sizeMB} MB)`
2962
+ );
2963
+ }
2964
+ }
2965
+ function validateVolatileWriteSize(value, context) {
2966
+ const byteSize = getJsonByteSize(value);
2967
+ if (byteSize > MAX_VOLATILE_WRITE_BYTES) {
2968
+ const sizeKB = Math.round(byteSize / 1024 * 100) / 100;
2969
+ throw new LarkError(
2970
+ ErrorCode.INVALID_DATA,
2971
+ `${context ? `${context}: ` : ""}volatile write exceeds 2 KB limit (got ${sizeKB} KB)`
2972
+ );
2973
+ }
2974
+ }
2949
2975
 
2950
2976
  // src/DatabaseReference.ts
2951
2977
  function isInfoPath(path) {
@@ -5062,6 +5088,7 @@ var LarkDatabase = class {
5062
5088
  if (!this.isAuthenticatedOrThrow()) await this.waitForAuthenticated();
5063
5089
  const normalizedPath = normalizePath(path) || "/";
5064
5090
  validateWriteData(value, normalizedPath);
5091
+ validateWriteSize(value, normalizedPath);
5065
5092
  const requestId = this.messageQueue.nextRequestId();
5066
5093
  const pendingWriteIds = this.subscriptionManager.getPendingWriteIdsForPath(normalizedPath);
5067
5094
  this.pendingWrites.trackWrite(requestId, "set", normalizedPath, value);
@@ -5090,6 +5117,7 @@ var LarkDatabase = class {
5090
5117
  const fullPath = key.startsWith("/") ? key : `${normalizedPath}/${key}`;
5091
5118
  validateWriteData(value, fullPath);
5092
5119
  }
5120
+ validateWriteSize(values, normalizedPath);
5093
5121
  const requestId = this.messageQueue.nextRequestId();
5094
5122
  const pendingWriteIds = this.subscriptionManager.getPendingWriteIdsForPath(normalizedPath);
5095
5123
  this.pendingWrites.trackWrite(requestId, "update", normalizedPath, values);
@@ -5151,6 +5179,7 @@ var LarkDatabase = class {
5151
5179
  */
5152
5180
  _sendVolatileSet(path, value) {
5153
5181
  const normalizedPath = normalizePath(path) || "/";
5182
+ validateVolatileWriteSize(value, normalizedPath);
5154
5183
  this.subscriptionManager.applyOptimisticWrite(normalizedPath, value, "", "set");
5155
5184
  if (this._state !== "authenticated" || !this.transport || !this.transport.connected) {
5156
5185
  return;
@@ -5167,6 +5196,7 @@ var LarkDatabase = class {
5167
5196
  */
5168
5197
  _sendVolatileUpdate(path, values) {
5169
5198
  const normalizedPath = normalizePath(path) || "/";
5199
+ validateVolatileWriteSize(values, normalizedPath);
5170
5200
  this.subscriptionManager.applyOptimisticWrite(normalizedPath, values, "", "update");
5171
5201
  if (this._state !== "authenticated" || !this.transport || !this.transport.connected) {
5172
5202
  return;
@@ -5350,4 +5380,4 @@ export {
5350
5380
  ServerValue,
5351
5381
  LarkDatabase
5352
5382
  };
5353
- //# sourceMappingURL=chunk-UVJBN3NR.mjs.map
5383
+ //# sourceMappingURL=chunk-UF3SZ62Y.mjs.map