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/dist/s3db.es.js CHANGED
@@ -899,10 +899,10 @@ class Client extends EventEmitter {
899
899
  Bucket: this.config.bucket,
900
900
  Key: this.config.keyPrefix ? path.join(this.config.keyPrefix, key) : key,
901
901
  Metadata: { ...metadata },
902
- Body: body || "",
903
- ContentType: contentType,
904
- ContentEncoding: contentEncoding
902
+ Body: body || Buffer.alloc(0)
905
903
  };
904
+ if (contentType !== void 0) options2.ContentType = contentType;
905
+ if (contentEncoding !== void 0) options2.ContentEncoding = contentEncoding;
906
906
  try {
907
907
  const response = await this.sendCommand(new PutObjectCommand(options2));
908
908
  this.emit("putObject", response, options2);
@@ -3480,6 +3480,7 @@ class Schema {
3480
3480
  this.attributes = attributes || {};
3481
3481
  this.passphrase = passphrase ?? "secret";
3482
3482
  this.options = merge({}, this.defaultOptions(), options);
3483
+ this.allNestedObjectsOptional = this.options.allNestedObjectsOptional ?? false;
3483
3484
  const processedAttributes = this.preprocessAttributesForValidation(this.attributes);
3484
3485
  this.validator = new ValidatorManager({ autoEncrypt: false }).compile(merge(
3485
3486
  { $$async: true },
@@ -3677,11 +3678,17 @@ class Schema {
3677
3678
  const processed = {};
3678
3679
  for (const [key, value] of Object.entries(attributes)) {
3679
3680
  if (typeof value === "object" && value !== null && !Array.isArray(value)) {
3680
- processed[key] = {
3681
+ const isExplicitRequired = value.$$type && value.$$type.includes("required");
3682
+ const isExplicitOptional = value.$$type && value.$$type.includes("optional");
3683
+ const objectConfig = {
3681
3684
  type: "object",
3682
3685
  properties: this.preprocessAttributesForValidation(value),
3683
3686
  strict: false
3684
3687
  };
3688
+ if (isExplicitRequired) ; else if (isExplicitOptional || this.allNestedObjectsOptional) {
3689
+ objectConfig.optional = true;
3690
+ }
3691
+ processed[key] = objectConfig;
3685
3692
  } else {
3686
3693
  processed[key] = value;
3687
3694
  }
@@ -8491,12 +8498,16 @@ class ResourceWriter extends EventEmitter {
8491
8498
  }
8492
8499
  write(chunk) {
8493
8500
  this.buffer.push(chunk);
8494
- this._maybeWrite();
8501
+ this._maybeWrite().catch((error) => {
8502
+ this.emit("error", error);
8503
+ });
8495
8504
  return true;
8496
8505
  }
8497
8506
  end() {
8498
8507
  this.ended = true;
8499
- this._maybeWrite();
8508
+ this._maybeWrite().catch((error) => {
8509
+ this.emit("error", error);
8510
+ });
8500
8511
  }
8501
8512
  async _maybeWrite() {
8502
8513
  if (this.writing) return;
@@ -8593,7 +8604,7 @@ function calculateTotalSize(mappedObject) {
8593
8604
  return Object.values(sizes).reduce((total, size) => total + size, 0);
8594
8605
  }
8595
8606
 
8596
- const S3_METADATA_LIMIT_BYTES$3 = 2048;
8607
+ const S3_METADATA_LIMIT_BYTES$3 = 2e3;
8597
8608
  async function handleInsert$3({ resource, data, mappedData }) {
8598
8609
  const totalSize = calculateTotalSize(mappedData);
8599
8610
  if (totalSize > S3_METADATA_LIMIT_BYTES$3) {
@@ -8647,7 +8658,7 @@ var userManagement = /*#__PURE__*/Object.freeze({
8647
8658
  handleUpsert: handleUpsert$3
8648
8659
  });
8649
8660
 
8650
- const S3_METADATA_LIMIT_BYTES$2 = 2048;
8661
+ const S3_METADATA_LIMIT_BYTES$2 = 2e3;
8651
8662
  async function handleInsert$2({ resource, data, mappedData }) {
8652
8663
  const totalSize = calculateTotalSize(mappedData);
8653
8664
  if (totalSize > S3_METADATA_LIMIT_BYTES$2) {
@@ -8681,7 +8692,7 @@ var enforceLimits = /*#__PURE__*/Object.freeze({
8681
8692
  handleUpsert: handleUpsert$2
8682
8693
  });
8683
8694
 
8684
- const S3_METADATA_LIMIT_BYTES$1 = 2048;
8695
+ const S3_METADATA_LIMIT_BYTES$1 = 2e3;
8685
8696
  const TRUNCATE_SUFFIX = "...";
8686
8697
  const TRUNCATE_SUFFIX_BYTES = calculateUTF8Bytes(TRUNCATE_SUFFIX);
8687
8698
  async function handleInsert$1({ resource, data, mappedData }) {
@@ -8739,7 +8750,7 @@ var dataTruncate = /*#__PURE__*/Object.freeze({
8739
8750
  handleUpsert: handleUpsert$1
8740
8751
  });
8741
8752
 
8742
- const S3_METADATA_LIMIT_BYTES = 2048;
8753
+ const S3_METADATA_LIMIT_BYTES = 2e3;
8743
8754
  const OVERFLOW_FLAG = "$overflow";
8744
8755
  const OVERFLOW_FLAG_VALUE = "true";
8745
8756
  const OVERFLOW_FLAG_BYTES = calculateUTF8Bytes(OVERFLOW_FLAG) + calculateUTF8Bytes(OVERFLOW_FLAG_VALUE);
@@ -8843,6 +8854,7 @@ class Resource extends EventEmitter {
8843
8854
  partitions: {},
8844
8855
  paranoid: true,
8845
8856
  // Security flag for dangerous operations
8857
+ allNestedObjectsOptional: options.allNestedObjectsOptional ?? false,
8846
8858
  ...options
8847
8859
  };
8848
8860
  this.hooks = {
@@ -8877,7 +8889,10 @@ class Resource extends EventEmitter {
8877
8889
  attributes: this.attributes,
8878
8890
  passphrase,
8879
8891
  version: this.version,
8880
- options: this.options
8892
+ options: {
8893
+ ...this.options,
8894
+ allNestedObjectsOptional: this.options.allNestedObjectsOptional ?? false
8895
+ }
8881
8896
  });
8882
8897
  this.validatePartitions();
8883
8898
  this.setupPartitionHooks();
@@ -9804,7 +9819,7 @@ class Database extends EventEmitter {
9804
9819
  this.version = "1";
9805
9820
  this.s3dbVersion = (() => {
9806
9821
  try {
9807
- return true ? "4.1.2" : "latest";
9822
+ return true ? "4.1.4" : "latest";
9808
9823
  } catch (e) {
9809
9824
  return "latest";
9810
9825
  }