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.cjs.js +30 -19
- package/dist/s3db.cjs.min.js +7 -7
- package/dist/s3db.es.js +30 -19
- package/dist/s3db.es.min.js +10 -10
- package/dist/s3db.iife.js +30 -19
- package/dist/s3db.iife.min.js +9 -9
- package/package.json +14 -14
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
|
|
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 ?
|
|
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 ?
|
|
3431
|
+
custom: this.autoEncrypt ? secretHandler : void 0
|
|
3428
3432
|
});
|
|
3429
3433
|
this.alias("secretNumber", {
|
|
3430
3434
|
type: "number",
|
|
3431
|
-
custom: this.autoEncrypt ?
|
|
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
|
-
}
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
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 (
|
|
3615
|
-
this.addHook("
|
|
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) {
|