@veryfront/ext-schema-zod 0.1.1277-rc.24389 → 0.1.1277
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/esm/adapter.d.ts.map +1 -1
- package/esm/adapter.js +28 -10
- package/package.json +3 -3
package/esm/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,OAAO,KAAK,EAUV,eAAe,EAIhB,MAAM,6BAA6B,CAAC;AAqyBrC;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,IAAI,eAAe,CAiGlD"}
|
package/esm/adapter.js
CHANGED
|
@@ -148,6 +148,7 @@ const JSON_INSTANCE_MAX_NODES = 100_000;
|
|
|
148
148
|
const JSON_INSTANCE_MAX_SERIALIZED_BYTES = 4 * 1024 * 1024;
|
|
149
149
|
const JSON_INSTANCE_MAX_STRING_BYTES = 1024 * 1024;
|
|
150
150
|
const JSON_INSTANCE_MAX_KEY_BYTES = 16 * 1024;
|
|
151
|
+
const JSON_INSTANCE_OVERRIDE_MAX_BYTES = 16 * 1024 * 1024;
|
|
151
152
|
const JSON_UTF8_ENCODER = new TextEncoder();
|
|
152
153
|
const JSON_SCHEMA_LIMITS = {
|
|
153
154
|
maxDepth: JSON_SCHEMA_MAX_DEPTH,
|
|
@@ -163,6 +164,21 @@ const JSON_INSTANCE_LIMITS = {
|
|
|
163
164
|
maxStringBytes: JSON_INSTANCE_MAX_STRING_BYTES,
|
|
164
165
|
maxKeyBytes: JSON_INSTANCE_MAX_KEY_BYTES,
|
|
165
166
|
};
|
|
167
|
+
function jsonInstanceLimits(options) {
|
|
168
|
+
const requested = options?.instanceLimits;
|
|
169
|
+
if (!requested)
|
|
170
|
+
return JSON_INSTANCE_LIMITS;
|
|
171
|
+
const { maxSerializedBytes, maxStringBytes } = requested;
|
|
172
|
+
for (const value of [maxSerializedBytes, maxStringBytes]) {
|
|
173
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > JSON_INSTANCE_OVERRIDE_MAX_BYTES) {
|
|
174
|
+
throw new RangeError("JSON Schema instance byte limits must be positive safe integers at most 16777216");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (maxStringBytes > maxSerializedBytes) {
|
|
178
|
+
throw new RangeError("JSON Schema string byte limit must not exceed its serialized byte limit");
|
|
179
|
+
}
|
|
180
|
+
return { ...JSON_INSTANCE_LIMITS, maxSerializedBytes, maxStringBytes };
|
|
181
|
+
}
|
|
166
182
|
const JSON_SCHEMA_COMPILER_OPTIONS = {
|
|
167
183
|
strict: true,
|
|
168
184
|
allErrors: true,
|
|
@@ -574,9 +590,9 @@ const DATA_ONLY_INPUT_FAILURE = Object.freeze({
|
|
|
574
590
|
}),
|
|
575
591
|
]),
|
|
576
592
|
});
|
|
577
|
-
function snapshotJsonInstance(input) {
|
|
593
|
+
function snapshotJsonInstance(input, limits) {
|
|
578
594
|
try {
|
|
579
|
-
return canonicalizeJsonValue(input,
|
|
595
|
+
return canonicalizeJsonValue(input, limits);
|
|
580
596
|
}
|
|
581
597
|
catch {
|
|
582
598
|
// Accessors, throwing/revoked Proxies, cycles, custom prototypes, and
|
|
@@ -596,10 +612,10 @@ function isPromiseLike(value) {
|
|
|
596
612
|
"then" in value &&
|
|
597
613
|
typeof value.then === "function";
|
|
598
614
|
}
|
|
599
|
-
function compileJsonSchemaValidator(schema) {
|
|
615
|
+
function compileJsonSchemaValidator(schema, limits) {
|
|
600
616
|
const validate = createJsonSchemaCompiler(schema).compile(schemaForCompilation(schema));
|
|
601
617
|
return (input) => {
|
|
602
|
-
const inputSnapshot = snapshotJsonInstance(input);
|
|
618
|
+
const inputSnapshot = snapshotJsonInstance(input, limits);
|
|
603
619
|
if (!inputSnapshot)
|
|
604
620
|
return DATA_ONLY_INPUT_FAILURE;
|
|
605
621
|
const acceptedInput = inputSnapshot.value;
|
|
@@ -618,15 +634,17 @@ function compileJsonSchemaValidator(schema) {
|
|
|
618
634
|
function createJsonSchemaCompilationCache() {
|
|
619
635
|
const cache = new Map();
|
|
620
636
|
let cacheWeight = 0;
|
|
621
|
-
return (schema) => {
|
|
637
|
+
return (schema, options) => {
|
|
638
|
+
const limits = jsonInstanceLimits(options);
|
|
622
639
|
const snapshot = snapshotJsonSchema(schema);
|
|
623
|
-
const
|
|
640
|
+
const key = `${limits.maxSerializedBytes}:${limits.maxStringBytes}:${snapshot.key}`;
|
|
641
|
+
const cached = cache.get(key);
|
|
624
642
|
if (cached) {
|
|
625
|
-
cache.delete(
|
|
626
|
-
cache.set(
|
|
643
|
+
cache.delete(key);
|
|
644
|
+
cache.set(key, cached);
|
|
627
645
|
return cached.validator;
|
|
628
646
|
}
|
|
629
|
-
const compiled = compileJsonSchemaValidator(snapshot.schema);
|
|
647
|
+
const compiled = compileJsonSchemaValidator(snapshot.schema, limits);
|
|
630
648
|
while (cache.size >= JSON_SCHEMA_VALIDATOR_CACHE_SIZE ||
|
|
631
649
|
cacheWeight + snapshot.cacheWeight > JSON_SCHEMA_VALIDATOR_CACHE_MAX_WEIGHT) {
|
|
632
650
|
const oldestKey = cache.keys().next().value;
|
|
@@ -637,7 +655,7 @@ function createJsonSchemaCompilationCache() {
|
|
|
637
655
|
if (oldest)
|
|
638
656
|
cacheWeight -= oldest.weight;
|
|
639
657
|
}
|
|
640
|
-
cache.set(
|
|
658
|
+
cache.set(key, { validator: compiled, weight: snapshot.cacheWeight });
|
|
641
659
|
cacheWeight += snapshot.cacheWeight;
|
|
642
660
|
return compiled;
|
|
643
661
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veryfront/ext-schema-zod",
|
|
3
|
-
"version": "0.1.1277
|
|
3
|
+
"version": "0.1.1277",
|
|
4
4
|
"description": "Veryfront first-party extension package for ext-schema-zod",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"veryfront",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"zod": "4.3.6"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"veryfront": "^0.1.1277
|
|
50
|
+
"veryfront": "^0.1.1277"
|
|
51
51
|
},
|
|
52
52
|
"type": "module",
|
|
53
53
|
"types": "./esm/index.d.ts",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"NOTICE",
|
|
58
58
|
"README.md"
|
|
59
59
|
],
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "476dab4c6f1ebde6478ff0e762298aa333abf1ac"
|
|
61
61
|
}
|