s3db.js 4.1.3 → 4.1.5

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/README.md CHANGED
@@ -440,7 +440,7 @@ try {
440
440
  });
441
441
  } catch (error) {
442
442
  console.error("Operation failed:", error.message);
443
- // Error: S3 metadata size exceeds 2KB limit. Current size: 2500 bytes, limit: 2048 bytes
443
+ // Error: S3 metadata size exceeds 2KB limit. Current size: 2500 bytes, limit: 2000 bytes
444
444
  }
445
445
  ```
446
446
 
package/dist/s3db.cjs.js CHANGED
@@ -901,10 +901,10 @@ class Client extends EventEmitter {
901
901
  Bucket: this.config.bucket,
902
902
  Key: this.config.keyPrefix ? path.join(this.config.keyPrefix, key) : key,
903
903
  Metadata: { ...metadata },
904
- Body: body || "",
905
- ContentType: contentType,
906
- ContentEncoding: contentEncoding
904
+ Body: body || Buffer.alloc(0)
907
905
  };
906
+ if (contentType !== void 0) options2.ContentType = contentType;
907
+ if (contentEncoding !== void 0) options2.ContentEncoding = contentEncoding;
908
908
  try {
909
909
  const response = await this.sendCommand(new clientS3.PutObjectCommand(options2));
910
910
  this.emit("putObject", response, options2);
@@ -3482,6 +3482,7 @@ class Schema {
3482
3482
  this.attributes = attributes || {};
3483
3483
  this.passphrase = passphrase ?? "secret";
3484
3484
  this.options = lodashEs.merge({}, this.defaultOptions(), options);
3485
+ this.allNestedObjectsOptional = this.options.allNestedObjectsOptional ?? false;
3485
3486
  const processedAttributes = this.preprocessAttributesForValidation(this.attributes);
3486
3487
  this.validator = new ValidatorManager({ autoEncrypt: false }).compile(lodashEs.merge(
3487
3488
  { $$async: true },
@@ -3679,11 +3680,17 @@ class Schema {
3679
3680
  const processed = {};
3680
3681
  for (const [key, value] of Object.entries(attributes)) {
3681
3682
  if (typeof value === "object" && value !== null && !Array.isArray(value)) {
3682
- processed[key] = {
3683
+ const isExplicitRequired = value.$$type && value.$$type.includes("required");
3684
+ const isExplicitOptional = value.$$type && value.$$type.includes("optional");
3685
+ const objectConfig = {
3683
3686
  type: "object",
3684
3687
  properties: this.preprocessAttributesForValidation(value),
3685
3688
  strict: false
3686
3689
  };
3690
+ if (isExplicitRequired) ; else if (isExplicitOptional || this.allNestedObjectsOptional) {
3691
+ objectConfig.optional = true;
3692
+ }
3693
+ processed[key] = objectConfig;
3687
3694
  } else {
3688
3695
  processed[key] = value;
3689
3696
  }
@@ -8493,12 +8500,16 @@ class ResourceWriter extends EventEmitter {
8493
8500
  }
8494
8501
  write(chunk) {
8495
8502
  this.buffer.push(chunk);
8496
- this._maybeWrite();
8503
+ this._maybeWrite().catch((error) => {
8504
+ this.emit("error", error);
8505
+ });
8497
8506
  return true;
8498
8507
  }
8499
8508
  end() {
8500
8509
  this.ended = true;
8501
- this._maybeWrite();
8510
+ this._maybeWrite().catch((error) => {
8511
+ this.emit("error", error);
8512
+ });
8502
8513
  }
8503
8514
  async _maybeWrite() {
8504
8515
  if (this.writing) return;
@@ -8595,7 +8606,7 @@ function calculateTotalSize(mappedObject) {
8595
8606
  return Object.values(sizes).reduce((total, size) => total + size, 0);
8596
8607
  }
8597
8608
 
8598
- const S3_METADATA_LIMIT_BYTES$3 = 2048;
8609
+ const S3_METADATA_LIMIT_BYTES$3 = 2e3;
8599
8610
  async function handleInsert$3({ resource, data, mappedData }) {
8600
8611
  const totalSize = calculateTotalSize(mappedData);
8601
8612
  if (totalSize > S3_METADATA_LIMIT_BYTES$3) {
@@ -8649,7 +8660,7 @@ var userManagement = /*#__PURE__*/Object.freeze({
8649
8660
  handleUpsert: handleUpsert$3
8650
8661
  });
8651
8662
 
8652
- const S3_METADATA_LIMIT_BYTES$2 = 2048;
8663
+ const S3_METADATA_LIMIT_BYTES$2 = 2e3;
8653
8664
  async function handleInsert$2({ resource, data, mappedData }) {
8654
8665
  const totalSize = calculateTotalSize(mappedData);
8655
8666
  if (totalSize > S3_METADATA_LIMIT_BYTES$2) {
@@ -8683,7 +8694,7 @@ var enforceLimits = /*#__PURE__*/Object.freeze({
8683
8694
  handleUpsert: handleUpsert$2
8684
8695
  });
8685
8696
 
8686
- const S3_METADATA_LIMIT_BYTES$1 = 2048;
8697
+ const S3_METADATA_LIMIT_BYTES$1 = 2e3;
8687
8698
  const TRUNCATE_SUFFIX = "...";
8688
8699
  const TRUNCATE_SUFFIX_BYTES = calculateUTF8Bytes(TRUNCATE_SUFFIX);
8689
8700
  async function handleInsert$1({ resource, data, mappedData }) {
@@ -8741,7 +8752,7 @@ var dataTruncate = /*#__PURE__*/Object.freeze({
8741
8752
  handleUpsert: handleUpsert$1
8742
8753
  });
8743
8754
 
8744
- const S3_METADATA_LIMIT_BYTES = 2048;
8755
+ const S3_METADATA_LIMIT_BYTES = 2e3;
8745
8756
  const OVERFLOW_FLAG = "$overflow";
8746
8757
  const OVERFLOW_FLAG_VALUE = "true";
8747
8758
  const OVERFLOW_FLAG_BYTES = calculateUTF8Bytes(OVERFLOW_FLAG) + calculateUTF8Bytes(OVERFLOW_FLAG_VALUE);
@@ -8845,6 +8856,7 @@ class Resource extends EventEmitter {
8845
8856
  partitions: {},
8846
8857
  paranoid: true,
8847
8858
  // Security flag for dangerous operations
8859
+ allNestedObjectsOptional: options.allNestedObjectsOptional ?? false,
8848
8860
  ...options
8849
8861
  };
8850
8862
  this.hooks = {
@@ -8879,7 +8891,10 @@ class Resource extends EventEmitter {
8879
8891
  attributes: this.attributes,
8880
8892
  passphrase,
8881
8893
  version: this.version,
8882
- options: this.options
8894
+ options: {
8895
+ ...this.options,
8896
+ allNestedObjectsOptional: this.options.allNestedObjectsOptional ?? false
8897
+ }
8883
8898
  });
8884
8899
  this.validatePartitions();
8885
8900
  this.setupPartitionHooks();
@@ -9806,7 +9821,7 @@ class Database extends EventEmitter {
9806
9821
  this.version = "1";
9807
9822
  this.s3dbVersion = (() => {
9808
9823
  try {
9809
- return true ? "4.1.2" : "latest";
9824
+ return true ? "4.1.4" : "latest";
9810
9825
  } catch (e) {
9811
9826
  return "latest";
9812
9827
  }