s3db.js 5.0.0 → 5.2.0

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
@@ -3392,7 +3392,7 @@ function requireJsonStableStringify () {
3392
3392
  var jsonStableStringifyExports = requireJsonStableStringify();
3393
3393
  var jsonStableStringify = /*@__PURE__*/getDefaultExportFromCjs(jsonStableStringifyExports);
3394
3394
 
3395
- async function custom(actual, errors, schema) {
3395
+ async function secretHandler(actual, errors, schema) {
3396
3396
  if (!this.passphrase) {
3397
3397
  errors.push({ actual, type: "encryptionKeyMissing" });
3398
3398
  return actual;
@@ -3405,6 +3405,10 @@ async function custom(actual, errors, schema) {
3405
3405
  }
3406
3406
  return actual;
3407
3407
  }
3408
+ async function jsonHandler(actual, errors, schema) {
3409
+ if (lodashEs.isString(actual)) return actual;
3410
+ return JSON.stringify(actual);
3411
+ }
3408
3412
  class Validator extends FastestValidator {
3409
3413
  constructor({ options, passphrase, autoEncrypt = true } = {}) {
3410
3414
  super(lodashEs.merge({}, {
@@ -3426,7 +3430,7 @@ class Validator extends FastestValidator {
3426
3430
  this.autoEncrypt = autoEncrypt;
3427
3431
  this.alias("secret", {
3428
3432
  type: "string",
3429
- custom: this.autoEncrypt ? custom : void 0,
3433
+ custom: this.autoEncrypt ? secretHandler : void 0,
3430
3434
  messages: {
3431
3435
  string: "The '{field}' field must be a string.",
3432
3436
  stringMin: "This secret '{field}' field length must be at least {expected} long."
@@ -3434,11 +3438,15 @@ class Validator extends FastestValidator {
3434
3438
  });
3435
3439
  this.alias("secretAny", {
3436
3440
  type: "any",
3437
- custom: this.autoEncrypt ? custom : void 0
3441
+ custom: this.autoEncrypt ? secretHandler : void 0
3438
3442
  });
3439
3443
  this.alias("secretNumber", {
3440
3444
  type: "number",
3441
- custom: this.autoEncrypt ? custom : void 0
3445
+ custom: this.autoEncrypt ? secretHandler : void 0
3446
+ });
3447
+ this.alias("json", {
3448
+ type: "any",
3449
+ custom: this.autoEncrypt ? jsonHandler : void 0
3442
3450
  });
3443
3451
  }
3444
3452
  }
@@ -3608,24 +3616,27 @@ class Schema {
3608
3616
  if (definition.includes("array")) {
3609
3617
  this.addHook("beforeMap", name, "fromArray");
3610
3618
  this.addHook("afterUnmap", name, "toArray");
3611
- } else {
3612
- if (definition.includes("secret")) {
3613
- if (this.options.autoEncrypt) {
3614
- this.addHook("beforeMap", name, "encrypt");
3615
- }
3616
- if (this.options.autoDecrypt) {
3617
- this.addHook("afterUnmap", name, "decrypt");
3618
- }
3619
- }
3620
- if (definition.includes("number")) {
3621
- this.addHook("beforeMap", name, "toString");
3622
- this.addHook("afterUnmap", name, "toNumber");
3619
+ }
3620
+ if (definition.includes("secret")) {
3621
+ if (this.options.autoEncrypt) {
3622
+ this.addHook("beforeMap", name, "encrypt");
3623
3623
  }
3624
- if (definition.includes("boolean")) {
3625
- this.addHook("beforeMap", name, "fromBool");
3626
- this.addHook("afterUnmap", name, "toBool");
3624
+ if (this.options.autoDecrypt) {
3625
+ this.addHook("afterUnmap", name, "decrypt");
3627
3626
  }
3628
3627
  }
3628
+ if (definition.includes("number")) {
3629
+ this.addHook("beforeMap", name, "toString");
3630
+ this.addHook("afterUnmap", name, "toNumber");
3631
+ }
3632
+ if (definition.includes("boolean")) {
3633
+ this.addHook("beforeMap", name, "fromBool");
3634
+ this.addHook("afterUnmap", name, "toBool");
3635
+ }
3636
+ if (definition.includes("json")) {
3637
+ this.addHook("beforeMap", name, "toJSON");
3638
+ this.addHook("afterUnmap", name, "fromJSON");
3639
+ }
3629
3640
  }
3630
3641
  }
3631
3642
  static import(data) {