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.cjs.js CHANGED
@@ -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
  }
@@ -8845,6 +8852,7 @@ class Resource extends EventEmitter {
8845
8852
  partitions: {},
8846
8853
  paranoid: true,
8847
8854
  // Security flag for dangerous operations
8855
+ allNestedObjectsOptional: options.allNestedObjectsOptional ?? false,
8848
8856
  ...options
8849
8857
  };
8850
8858
  this.hooks = {
@@ -8879,7 +8887,10 @@ class Resource extends EventEmitter {
8879
8887
  attributes: this.attributes,
8880
8888
  passphrase,
8881
8889
  version: this.version,
8882
- options: this.options
8890
+ options: {
8891
+ ...this.options,
8892
+ allNestedObjectsOptional: this.options.allNestedObjectsOptional ?? false
8893
+ }
8883
8894
  });
8884
8895
  this.validatePartitions();
8885
8896
  this.setupPartitionHooks();
@@ -9806,7 +9817,7 @@ class Database extends EventEmitter {
9806
9817
  this.version = "1";
9807
9818
  this.s3dbVersion = (() => {
9808
9819
  try {
9809
- return true ? "4.1.2" : "latest";
9820
+ return true ? "4.1.3" : "latest";
9810
9821
  } catch (e) {
9811
9822
  return "latest";
9812
9823
  }