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.iife.js CHANGED
@@ -3382,7 +3382,7 @@ ${JSON.stringify(validation, null, 2)}`, {
3382
3382
  var jsonStableStringifyExports = requireJsonStableStringify();
3383
3383
  var jsonStableStringify = /*@__PURE__*/getDefaultExportFromCjs(jsonStableStringifyExports);
3384
3384
 
3385
- async function custom(actual, errors, schema) {
3385
+ async function secretHandler(actual, errors, schema) {
3386
3386
  if (!this.passphrase) {
3387
3387
  errors.push({ actual, type: "encryptionKeyMissing" });
3388
3388
  return actual;
@@ -3395,6 +3395,10 @@ ${JSON.stringify(validation, null, 2)}`, {
3395
3395
  }
3396
3396
  return actual;
3397
3397
  }
3398
+ async function jsonHandler(actual, errors, schema) {
3399
+ if (lodashEs.isString(actual)) return actual;
3400
+ return JSON.stringify(actual);
3401
+ }
3398
3402
  class Validator extends FastestValidator {
3399
3403
  constructor({ options, passphrase, autoEncrypt = true } = {}) {
3400
3404
  super(lodashEs.merge({}, {
@@ -3416,7 +3420,7 @@ ${JSON.stringify(validation, null, 2)}`, {
3416
3420
  this.autoEncrypt = autoEncrypt;
3417
3421
  this.alias("secret", {
3418
3422
  type: "string",
3419
- custom: this.autoEncrypt ? custom : void 0,
3423
+ custom: this.autoEncrypt ? secretHandler : void 0,
3420
3424
  messages: {
3421
3425
  string: "The '{field}' field must be a string.",
3422
3426
  stringMin: "This secret '{field}' field length must be at least {expected} long."
@@ -3424,11 +3428,15 @@ ${JSON.stringify(validation, null, 2)}`, {
3424
3428
  });
3425
3429
  this.alias("secretAny", {
3426
3430
  type: "any",
3427
- custom: this.autoEncrypt ? custom : void 0
3431
+ custom: this.autoEncrypt ? secretHandler : void 0
3428
3432
  });
3429
3433
  this.alias("secretNumber", {
3430
3434
  type: "number",
3431
- custom: this.autoEncrypt ? custom : void 0
3435
+ custom: this.autoEncrypt ? secretHandler : void 0
3436
+ });
3437
+ this.alias("json", {
3438
+ type: "any",
3439
+ custom: this.autoEncrypt ? jsonHandler : void 0
3432
3440
  });
3433
3441
  }
3434
3442
  }
@@ -3598,24 +3606,27 @@ ${JSON.stringify(validation, null, 2)}`, {
3598
3606
  if (definition.includes("array")) {
3599
3607
  this.addHook("beforeMap", name, "fromArray");
3600
3608
  this.addHook("afterUnmap", name, "toArray");
3601
- } else {
3602
- if (definition.includes("secret")) {
3603
- if (this.options.autoEncrypt) {
3604
- this.addHook("beforeMap", name, "encrypt");
3605
- }
3606
- if (this.options.autoDecrypt) {
3607
- this.addHook("afterUnmap", name, "decrypt");
3608
- }
3609
- }
3610
- if (definition.includes("number")) {
3611
- this.addHook("beforeMap", name, "toString");
3612
- this.addHook("afterUnmap", name, "toNumber");
3609
+ }
3610
+ if (definition.includes("secret")) {
3611
+ if (this.options.autoEncrypt) {
3612
+ this.addHook("beforeMap", name, "encrypt");
3613
3613
  }
3614
- if (definition.includes("boolean")) {
3615
- this.addHook("beforeMap", name, "fromBool");
3616
- this.addHook("afterUnmap", name, "toBool");
3614
+ if (this.options.autoDecrypt) {
3615
+ this.addHook("afterUnmap", name, "decrypt");
3617
3616
  }
3618
3617
  }
3618
+ if (definition.includes("number")) {
3619
+ this.addHook("beforeMap", name, "toString");
3620
+ this.addHook("afterUnmap", name, "toNumber");
3621
+ }
3622
+ if (definition.includes("boolean")) {
3623
+ this.addHook("beforeMap", name, "fromBool");
3624
+ this.addHook("afterUnmap", name, "toBool");
3625
+ }
3626
+ if (definition.includes("json")) {
3627
+ this.addHook("beforeMap", name, "toJSON");
3628
+ this.addHook("afterUnmap", name, "fromJSON");
3629
+ }
3619
3630
  }
3620
3631
  }
3621
3632
  static import(data) {