@zudojs/serialization 1.0.0 → 1.0.1
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/README.md
CHANGED
|
@@ -81,7 +81,9 @@ RPC peer or a request body.
|
|
|
81
81
|
is plain `JSON.parse`, where `__proto__` survives as an inert own property and
|
|
82
82
|
never reaches the prototype — but do not spread or deep-merge such an object
|
|
83
83
|
into another without screening its keys.
|
|
84
|
-
- **Input is size-bounded** by `maxSize`, and depth-bounded by `maxDepth`.
|
|
84
|
+
- **Input is size-bounded** by `maxSize`, and depth-bounded by `maxDepth`. On
|
|
85
|
+
the `preserveTypes` path the depth limit defaults to 128; on the fast path it
|
|
86
|
+
is enforced whenever you set it, per call or as an instance default.
|
|
85
87
|
- **An unrecognised `$type` tag is treated as ordinary data**, so a peer cannot
|
|
86
88
|
stop the consumer with `{"$type":"anything"}` and your own records may carry a
|
|
87
89
|
`$type` field. Pass `strict: true` to make an unknown tag an error instead.
|
|
@@ -49,6 +49,13 @@ export class JSONSerializer {
|
|
|
49
49
|
this.assertOutputSize(json, maxSize);
|
|
50
50
|
return json;
|
|
51
51
|
}
|
|
52
|
+
// The fast path stays a bare `JSON.stringify` by default, but a depth
|
|
53
|
+
// limit the caller asked for must still be enforced: `maxDepth` used to
|
|
54
|
+
// be read only when `preserveTypes` was on, so a per-call or per-instance
|
|
55
|
+
// limit was silently ignored on the path most callers use.
|
|
56
|
+
if (opts.maxDepth !== undefined) {
|
|
57
|
+
assertDepthWithinLimit(value, maxDepth);
|
|
58
|
+
}
|
|
52
59
|
const json = opts.pretty
|
|
53
60
|
? JSON.stringify(value, null, opts.indent ?? 2)
|
|
54
61
|
: JSON.stringify(value);
|
|
@@ -71,6 +78,11 @@ export class JSONSerializer {
|
|
|
71
78
|
assertDepthWithinLimit(parsed, maxDepth);
|
|
72
79
|
return this.restoreValue(parsed, 0, maxDepth, opts);
|
|
73
80
|
}
|
|
81
|
+
// Same contract on the fast path: an explicit `maxDepth` bounds input
|
|
82
|
+
// that arrives from the wire, whether or not types are being restored.
|
|
83
|
+
if (opts.maxDepth !== undefined) {
|
|
84
|
+
assertDepthWithinLimit(parsed, opts.maxDepth);
|
|
85
|
+
}
|
|
74
86
|
return parsed;
|
|
75
87
|
}
|
|
76
88
|
transformValue(value, depth, maxDepth, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zudojs/serialization",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Data translation layer with JSON serializer, type transformers, envelopes, and registry for Zudojs applications.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,16 +19,20 @@
|
|
|
19
19
|
"LICENSE"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@zudojs/constants": "1.0.
|
|
23
|
-
"@zudojs/errors": "1.0.
|
|
22
|
+
"@zudojs/constants": "1.0.1",
|
|
23
|
+
"@zudojs/errors": "1.0.1",
|
|
24
24
|
"@zudojs/types": "1.0.0",
|
|
25
|
-
"@zudojs/validation": "1.0.
|
|
25
|
+
"@zudojs/validation": "1.0.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"typescript": "7.0.2",
|
|
29
29
|
"vitest": "^4.1.11"
|
|
30
30
|
},
|
|
31
31
|
"license": "MIT",
|
|
32
|
+
"author": {
|
|
33
|
+
"name": "Oluwayemi Oyinlola",
|
|
34
|
+
"url": "https://github.com/oyinlola-tech"
|
|
35
|
+
},
|
|
32
36
|
"keywords": [
|
|
33
37
|
"zudojs",
|
|
34
38
|
"serialization",
|