Seroval 1.9 removes the v export, gives every error a code, and changes how typed arrays are written in JSON. This page lists each breaking change and the steps to upgrade from 1.8. Binary mode is new in 1.9: see Binary mode.
Upgrade
Install the new versions together:
npm install seroval@^1.9.0 seroval-plugins@latest @seroval/transport@latestpnpm add seroval@^1.9.0 seroval-plugins@latest @seroval/transport@latestyarn add seroval@^1.9.0 seroval-plugins@latest @seroval/transport@latestbun add seroval@^1.9.0 seroval-plugins@latest @seroval/transport@latestImport the validators from
seroval/validator. See Thevexport is removed.Replace checks on error messages with checks on
code. See Errors have codes.Replace
cause instanceof RangeErrorafter an oversized buffer. See Oversized buffers.Upgrade the sender and the receiver of JSON together, and write stored JSON that holds typed arrays again. See Typed arrays in JSON.
Breaking changes
The v export is removed
seroval, seroval/read, seroval/write and seroval/shared no longer export v. The validators are only in seroval/validator.
Before:
import { v } from 'seroval';After:
import * as v from 'seroval/validator';@seroval/transport 0.1.3 and earlier read v from seroval/read. Update it to 0.1.4 or later together with seroval.
Errors have codes
Every error that seroval throws because of the data now extends SerovalError, and has a code such as SRV008. In 1.8, only the three step wrappers extended SerovalError. Existing instanceof checks still work.
| 1.8 | 1.9 | |
|---|---|---|
name | 'Error' | The class name, such as 'SerovalMalformedNodeError' |
code and step | none | A code from the codes table, and the step that failed |
| Production message | A step or error number, such as Seroval Error (step: 3) | The code, the step and a link, such as Seroval SRV008 (deserialize): https://seroval.pages.dev/docs/errors/SRV008 |
| Development message | A message per error | A message per error, rewritten, and for parse errors the path to the value |
Every message changed, so code that matches message text breaks. Check the code instead:
import { SerovalError, fromJSON } from 'seroval';
try {
fromJSON(body);
} catch (error) {
if (error instanceof SerovalError && error.code === 'SRV010') {
// The depth limit was reached.
}
}Errors describes the fields and the production format.
Oversized buffers
A buffer larger than maxBase64Length still throws a SerovalDeserializationError. Its cause was a RangeError and is now a SerovalBase64LimitError with the code SRV020.
Before:
if (error.cause instanceof RangeError) {
// The buffer was too large.
}After:
if (error.code === 'SRV020') {
// The buffer was too large.
}An invalid maxBase64Length option is still a RangeError, now with the code SRV019.
Typed arrays in JSON
A typed array node in JSON names its constructor with a numeric tag in s instead of a name in c. BigInt64Array and BigUint64Array nodes change the same way. This changes the output of toJSON, toJSONAsync, toCrossJSON and the other JSON functions.
1.8:
{ "t": 15, "i": 0, "c": "Uint8Array", "f": { "...": "..." }, "b": 0, "l": 2 }1.9:
{ "t": 15, "i": 0, "s": 4, "f": { "...": "..." }, "b": 0, "l": 2 }JSON with a typed array cannot cross versions. Seroval 1.9 rejects such JSON from 1.8 with a SerovalMalformedNodeError (SRV008), and 1.8 cannot read it from 1.9. JSON without typed arrays is not affected.
- Deploy the sender and the receiver with the same version.
- Decode stored JSON that holds typed arrays with 1.8, then write it again with 1.9.
Errored async iterables
When the stream behind a deserialized async iterable has already ended with an error, next() now returns a rejected promise. In 1.8 it threw synchronously. Code that awaits next() or uses for await sees no change.
seroval-plugins
Two errors in seroval-plugins were plain Error objects and now have codes:
- A value shared between two plugin values throws
SerovalPluginValidationError(SRV013), with the plugintagand thefield. - Decoding the node of the
AbortControllerfactory directly throwsSerovalMalformedNodeError(SRV008).
The code field needs seroval 1.9. With seroval 1.8, the same errors are thrown without a code.