s3db.js 4.1.3 → 4.1.4

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
@@ -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
  }
@@ -8843,6 +8850,7 @@ class Resource extends EventEmitter {
8843
8850
  partitions: {},
8844
8851
  paranoid: true,
8845
8852
  // Security flag for dangerous operations
8853
+ allNestedObjectsOptional: options.allNestedObjectsOptional ?? false,
8846
8854
  ...options
8847
8855
  };
8848
8856
  this.hooks = {
@@ -8877,7 +8885,10 @@ class Resource extends EventEmitter {
8877
8885
  attributes: this.attributes,
8878
8886
  passphrase,
8879
8887
  version: this.version,
8880
- options: this.options
8888
+ options: {
8889
+ ...this.options,
8890
+ allNestedObjectsOptional: this.options.allNestedObjectsOptional ?? false
8891
+ }
8881
8892
  });
8882
8893
  this.validatePartitions();
8883
8894
  this.setupPartitionHooks();
@@ -9804,7 +9815,7 @@ class Database extends EventEmitter {
9804
9815
  this.version = "1";
9805
9816
  this.s3dbVersion = (() => {
9806
9817
  try {
9807
- return true ? "4.1.2" : "latest";
9818
+ return true ? "4.1.3" : "latest";
9808
9819
  } catch (e) {
9809
9820
  return "latest";
9810
9821
  }