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