@zudojs/serialization 1.2.3 → 1.3.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/index.d.ts +1 -1
- package/dist/index.js +0 -1
- package/dist/serializerEnvelope/envelope.assert.d.ts +27 -0
- package/dist/serializerEnvelope/envelope.assert.js +69 -0
- package/dist/serializerEnvelope/envelope.core.d.ts +23 -17
- package/dist/serializerEnvelope/envelope.core.js +15 -39
- package/dist/serializerEnvelope/index.d.ts +1 -1
- package/dist/serializerEnvelope/index.js +0 -1
- package/dist/serializerJson/index.d.ts +0 -1
- package/dist/serializerJson/index.js +0 -1
- package/dist/serializerJson/jsonSerializer.core.d.ts +0 -1
- package/dist/serializerJson/jsonSerializer.core.js +0 -1
- package/dist/serializerJson/jsonSerializer.escape.d.ts +0 -1
- package/dist/serializerJson/jsonSerializer.escape.js +0 -1
- package/dist/serializerJson/jsonSerializer.keys.d.ts +0 -1
- package/dist/serializerJson/jsonSerializer.keys.js +0 -1
- package/dist/serializerJson/jsonSerializer.restore.d.ts +0 -1
- package/dist/serializerJson/jsonSerializer.restore.js +0 -1
- package/dist/serializerJson/jsonSerializer.transform.d.ts +0 -1
- package/dist/serializerJson/jsonSerializer.transform.js +0 -1
- package/dist/serializerRegistry/index.d.ts +0 -1
- package/dist/serializerRegistry/index.js +0 -1
- package/dist/serializerRegistry/serializerRegistry.core.d.ts +0 -1
- package/dist/serializerRegistry/serializerRegistry.core.js +0 -1
- package/dist/serializerRegistry/serializerRegistry.factory.d.ts +0 -1
- package/dist/serializerRegistry/serializerRegistry.factory.js +0 -1
- package/dist/serializerTransformPolicy/index.d.ts +0 -1
- package/dist/serializerTransformPolicy/index.js +0 -1
- package/dist/serializerTransformPolicy/transformerLookup.core.d.ts +0 -1
- package/dist/serializerTransformPolicy/transformerLookup.core.js +0 -1
- package/dist/serializerTransformPolicy/transformerOutput.helper.d.ts +0 -1
- package/dist/serializerTransformPolicy/transformerOutput.helper.js +0 -1
- package/dist/serializerTransforms/bigint.transformer.d.ts +0 -1
- package/dist/serializerTransforms/bigint.transformer.js +0 -1
- package/dist/serializerTransforms/date.transformer.d.ts +0 -1
- package/dist/serializerTransforms/date.transformer.js +0 -1
- package/dist/serializerTransforms/index.d.ts +0 -1
- package/dist/serializerTransforms/index.js +0 -1
- package/dist/serializerTransforms/map.transformer.d.ts +0 -1
- package/dist/serializerTransforms/map.transformer.js +0 -1
- package/dist/serializerTransforms/set.transformer.d.ts +0 -1
- package/dist/serializerTransforms/set.transformer.js +0 -1
- package/dist/serializerTransforms/transformerRegistry.core.d.ts +0 -1
- package/dist/serializerTransforms/transformerRegistry.core.js +0 -1
- package/dist/serializerTransformsExt/buffer.transformer.d.ts +0 -1
- package/dist/serializerTransformsExt/buffer.transformer.js +0 -1
- package/dist/serializerTransformsExt/encoding.utils.d.ts +0 -1
- package/dist/serializerTransformsExt/encoding.utils.js +0 -1
- package/dist/serializerTransformsExt/error.transformer.d.ts +0 -1
- package/dist/serializerTransformsExt/error.transformer.js +0 -1
- package/dist/serializerTransformsExt/index.d.ts +0 -1
- package/dist/serializerTransformsExt/index.js +0 -1
- package/dist/serializerTypes/index.d.ts +0 -1
- package/dist/serializerTypes/index.js +0 -1
- package/dist/serializerTypes/serializer.type.d.ts +17 -2
- package/dist/serializerTypes/serializer.type.js +0 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export { BufferTransformer } from "./serializerTransformsExt/index.js";
|
|
|
37
37
|
export { ErrorTransformer } from "./serializerTransformsExt/index.js";
|
|
38
38
|
export { toBase64, fromBase64, encodeUtf8, decodeUtf8, } from "./serializerTransformsExt/index.js";
|
|
39
39
|
export { createEnvelope, assertValidEnvelope, contentTypeForFormat, unwrapEnvelope, serializeToEnvelope, deserializeFromEnvelope, } from "./serializerEnvelope/index.js";
|
|
40
|
+
export type { EnvelopeMetadataOptions } from "./serializerEnvelope/index.js";
|
|
40
41
|
export { SerializerRegistry } from "./serializerRegistry/index.js";
|
|
41
42
|
export { createSerializer, createDefaultRegistry, } from "./serializerRegistry/index.js";
|
|
42
43
|
export type { CreateSerializerOptions } from "./serializerRegistry/index.js";
|
|
43
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -42,4 +42,3 @@ export { createEnvelope, assertValidEnvelope, contentTypeForFormat, unwrapEnvelo
|
|
|
42
42
|
// ─── Registry & Factory ───────────────────────────────────────
|
|
43
43
|
export { SerializerRegistry } from "./serializerRegistry/index.js";
|
|
44
44
|
export { createSerializer, createDefaultRegistry, } from "./serializerRegistry/index.js";
|
|
45
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zudojs/serialization — Envelope assertions.
|
|
3
|
+
*
|
|
4
|
+
* Shape and version checks for envelopes produced here and received from
|
|
5
|
+
* the wire.
|
|
6
|
+
*/
|
|
7
|
+
import type { SerializedEnvelope } from "../serializerTypes/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* Rejects a wire-format version this build cannot read back.
|
|
10
|
+
*
|
|
11
|
+
* `createEnvelope(data, "json", { version: 2 })` used to be accepted and
|
|
12
|
+
* then refused by `unwrapEnvelope` in the same process, because callers took
|
|
13
|
+
* `version` for their own schema version.
|
|
14
|
+
*
|
|
15
|
+
* @throws {SerializationError} for a non-integer, non-positive or too-new version.
|
|
16
|
+
*/
|
|
17
|
+
export declare function assertProducibleVersion(version: number): void;
|
|
18
|
+
/**
|
|
19
|
+
* Validates that a value received from the wire is a well-formed envelope.
|
|
20
|
+
*
|
|
21
|
+
* @param envelope - The candidate envelope.
|
|
22
|
+
* @throws {InvalidSerializedDataError} when the shape or schema version is
|
|
23
|
+
* unusable. Envelope payloads arrive from a queue or an RPC peer, so a
|
|
24
|
+
* rejection has to be distinguishable from an internal bug: a bare `Error`
|
|
25
|
+
* left callers unable to tell hostile input from a defect of their own.
|
|
26
|
+
*/
|
|
27
|
+
export declare function assertValidEnvelope(envelope: unknown): asserts envelope is SerializedEnvelope;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zudojs/serialization — Envelope assertions.
|
|
3
|
+
*
|
|
4
|
+
* Shape and version checks for envelopes produced here and received from
|
|
5
|
+
* the wire.
|
|
6
|
+
*/
|
|
7
|
+
import { SERIALIZATION_SCHEMA_VERSION } from "@zudojs/constants";
|
|
8
|
+
import { InvalidSerializedDataError, SerializationError } from "@zudojs/errors";
|
|
9
|
+
/**
|
|
10
|
+
* Rejects a wire-format version this build cannot read back.
|
|
11
|
+
*
|
|
12
|
+
* `createEnvelope(data, "json", { version: 2 })` used to be accepted and
|
|
13
|
+
* then refused by `unwrapEnvelope` in the same process, because callers took
|
|
14
|
+
* `version` for their own schema version.
|
|
15
|
+
*
|
|
16
|
+
* @throws {SerializationError} for a non-integer, non-positive or too-new version.
|
|
17
|
+
*/
|
|
18
|
+
export function assertProducibleVersion(version) {
|
|
19
|
+
if (!Number.isInteger(version) ||
|
|
20
|
+
version < 1 ||
|
|
21
|
+
version > SERIALIZATION_SCHEMA_VERSION) {
|
|
22
|
+
throw new SerializationError(`Envelope version must be an integer between 1 and ${SERIALIZATION_SCHEMA_VERSION} (the wire-format version); ` +
|
|
23
|
+
`got ${String(version)}. Put your message's own version in metadata.schemaVersion.`, { format: "envelope" });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validates that a value received from the wire is a well-formed envelope.
|
|
28
|
+
*
|
|
29
|
+
* @param envelope - The candidate envelope.
|
|
30
|
+
* @throws {InvalidSerializedDataError} when the shape or schema version is
|
|
31
|
+
* unusable. Envelope payloads arrive from a queue or an RPC peer, so a
|
|
32
|
+
* rejection has to be distinguishable from an internal bug: a bare `Error`
|
|
33
|
+
* left callers unable to tell hostile input from a defect of their own.
|
|
34
|
+
*/
|
|
35
|
+
export function assertValidEnvelope(envelope) {
|
|
36
|
+
if (typeof envelope !== "object" || envelope === null) {
|
|
37
|
+
throw new InvalidSerializedDataError(`Malformed envelope: expected an object, got ${envelope === null ? "null" : typeof envelope}`, { format: "envelope" });
|
|
38
|
+
}
|
|
39
|
+
const candidate = envelope;
|
|
40
|
+
if (typeof candidate.metadata !== "object" || candidate.metadata === null) {
|
|
41
|
+
throw new InvalidSerializedDataError("Malformed envelope: missing metadata", { format: "envelope" });
|
|
42
|
+
}
|
|
43
|
+
const metadata = candidate.metadata;
|
|
44
|
+
if (typeof metadata.format !== "string" || metadata.format.length === 0) {
|
|
45
|
+
throw new InvalidSerializedDataError("Malformed envelope: metadata.format is missing", { format: "envelope" });
|
|
46
|
+
}
|
|
47
|
+
if (typeof candidate.data !== "string" &&
|
|
48
|
+
!(candidate.data instanceof Uint8Array)) {
|
|
49
|
+
throw new InvalidSerializedDataError("Malformed envelope: data must be a string or Uint8Array", { format: "envelope" });
|
|
50
|
+
}
|
|
51
|
+
if (metadata.type !== undefined && typeof metadata.type !== "string") {
|
|
52
|
+
throw new InvalidSerializedDataError("Malformed envelope: metadata.type must be a string", { format: "envelope" });
|
|
53
|
+
}
|
|
54
|
+
if (metadata.schemaVersion !== undefined &&
|
|
55
|
+
typeof metadata.schemaVersion !== "string" &&
|
|
56
|
+
typeof metadata.schemaVersion !== "number") {
|
|
57
|
+
throw new InvalidSerializedDataError("Malformed envelope: metadata.schemaVersion must be a string or number", { format: "envelope" });
|
|
58
|
+
}
|
|
59
|
+
// The version exists so a future producer can be detected rather than
|
|
60
|
+
// silently misread. Older versions stay readable; newer ones do not.
|
|
61
|
+
if (metadata.version !== undefined) {
|
|
62
|
+
if (!Number.isInteger(metadata.version)) {
|
|
63
|
+
throw new InvalidSerializedDataError(`Malformed envelope: metadata.version must be an integer, got ${String(metadata.version)}`, { format: "envelope" });
|
|
64
|
+
}
|
|
65
|
+
if (metadata.version > SERIALIZATION_SCHEMA_VERSION) {
|
|
66
|
+
throw new InvalidSerializedDataError(`Unsupported envelope wire-format version ${metadata.version}: this build understands up to ${SERIALIZATION_SCHEMA_VERSION}`, { format: "envelope" });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -6,6 +6,23 @@
|
|
|
6
6
|
* messaging, queues, RPC, and cross-service communication.
|
|
7
7
|
*/
|
|
8
8
|
import type { SerializedEnvelope, SerializedValue, SerializeOptions, DeserializeOptions } from "../serializerTypes/index.js";
|
|
9
|
+
export { assertValidEnvelope } from "./envelope.assert.js";
|
|
10
|
+
/** Application-level metadata a producer may stamp on an envelope. */
|
|
11
|
+
export interface EnvelopeMetadataOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Wire-format version. Defaults to, and may not exceed,
|
|
14
|
+
* `SERIALIZATION_SCHEMA_VERSION`; pass a lower value only to produce an
|
|
15
|
+
* envelope for an older consumer. Not the version of your message shape:
|
|
16
|
+
* that is `schemaVersion`.
|
|
17
|
+
*/
|
|
18
|
+
readonly version?: number;
|
|
19
|
+
readonly contentType?: string;
|
|
20
|
+
readonly encoding?: string;
|
|
21
|
+
/** Name of the payload (`"OrderPlaced"`), carried verbatim. */
|
|
22
|
+
readonly type?: string;
|
|
23
|
+
/** Version of the payload's shape, carried verbatim. */
|
|
24
|
+
readonly schemaVersion?: number | string;
|
|
25
|
+
}
|
|
9
26
|
/**
|
|
10
27
|
* Create a serialization envelope wrapping data with metadata.
|
|
11
28
|
*
|
|
@@ -13,12 +30,10 @@ import type { SerializedEnvelope, SerializedValue, SerializeOptions, Deserialize
|
|
|
13
30
|
* @param format - The serialization format used (default: "json").
|
|
14
31
|
* @param options - Additional metadata options.
|
|
15
32
|
* @returns A SerializedEnvelope with metadata and data.
|
|
33
|
+
* @throws {SerializationError} when `options.version` is not a wire-format
|
|
34
|
+
* version this build can read back.
|
|
16
35
|
*/
|
|
17
|
-
export declare function createEnvelope(data: SerializedValue, format?: string, options?:
|
|
18
|
-
readonly version?: number;
|
|
19
|
-
readonly contentType?: string;
|
|
20
|
-
readonly encoding?: string;
|
|
21
|
-
}): SerializedEnvelope;
|
|
36
|
+
export declare function createEnvelope(data: SerializedValue, format?: string, options?: EnvelopeMetadataOptions): SerializedEnvelope;
|
|
22
37
|
/**
|
|
23
38
|
* Maps a format identifier to its MIME content type.
|
|
24
39
|
*
|
|
@@ -26,16 +41,6 @@ export declare function createEnvelope(data: SerializedValue, format?: string, o
|
|
|
26
41
|
* a msgpack payload ends up labelled as JSON on the wire.
|
|
27
42
|
*/
|
|
28
43
|
export declare function contentTypeForFormat(format: string): string;
|
|
29
|
-
/**
|
|
30
|
-
* Validates that a value received from the wire is a well-formed envelope.
|
|
31
|
-
*
|
|
32
|
-
* @param envelope - The candidate envelope.
|
|
33
|
-
* @throws {InvalidSerializedDataError} when the shape or schema version is
|
|
34
|
-
* unusable. Envelope payloads arrive from a queue or an RPC peer, so a
|
|
35
|
-
* rejection has to be distinguishable from an internal bug: a bare `Error`
|
|
36
|
-
* left callers unable to tell hostile input from a defect of their own.
|
|
37
|
-
*/
|
|
38
|
-
export declare function assertValidEnvelope(envelope: unknown): asserts envelope is SerializedEnvelope;
|
|
39
44
|
/**
|
|
40
45
|
* Extract the data from an envelope, validating metadata.
|
|
41
46
|
*
|
|
@@ -56,12 +61,14 @@ export declare function unwrapEnvelope(envelope: SerializedEnvelope, expectedFor
|
|
|
56
61
|
* the helper could only ever call `serialize(value)`, so `preserveTypes`,
|
|
57
62
|
* `pretty` and the size/depth limits were unreachable through an envelope
|
|
58
63
|
* unless they happened to be baked into the serializer instance.
|
|
64
|
+
* @param metadata - Application metadata (`type`, `schemaVersion`) to stamp
|
|
65
|
+
* on the envelope.
|
|
59
66
|
* @returns A SerializedEnvelope containing the serialized data.
|
|
60
67
|
*/
|
|
61
68
|
export declare function serializeToEnvelope<T>(value: T, serializer: {
|
|
62
69
|
serialize: (v: T, options?: SerializeOptions) => string;
|
|
63
70
|
contentType?: string;
|
|
64
|
-
}, format?: string, options?: SerializeOptions): SerializedEnvelope;
|
|
71
|
+
}, format?: string, options?: SerializeOptions, metadata?: Pick<EnvelopeMetadataOptions, "type" | "schemaVersion">): SerializedEnvelope;
|
|
65
72
|
/**
|
|
66
73
|
* Unwrap an envelope and deserialize the data.
|
|
67
74
|
*
|
|
@@ -77,4 +84,3 @@ export declare function serializeToEnvelope<T>(value: T, serializer: {
|
|
|
77
84
|
export declare function deserializeFromEnvelope<T>(envelope: SerializedEnvelope, deserializer: {
|
|
78
85
|
deserialize: <U>(v: string, options?: DeserializeOptions) => U;
|
|
79
86
|
}, expectedFormat?: string, options?: DeserializeOptions): T;
|
|
80
|
-
//# sourceMappingURL=envelope.core.d.ts.map
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
import { SerializationFormat, SerializationContentType, SERIALIZATION_SCHEMA_VERSION, } from "@zudojs/constants";
|
|
9
9
|
import { InvalidSerializedDataError } from "@zudojs/errors";
|
|
10
10
|
import { decodeUtf8 } from "../serializerTransformsExt/index.js";
|
|
11
|
+
import { assertProducibleVersion, assertValidEnvelope, } from "./envelope.assert.js";
|
|
12
|
+
export { assertValidEnvelope } from "./envelope.assert.js";
|
|
11
13
|
/**
|
|
12
14
|
* Create a serialization envelope wrapping data with metadata.
|
|
13
15
|
*
|
|
@@ -15,14 +17,22 @@ import { decodeUtf8 } from "../serializerTransformsExt/index.js";
|
|
|
15
17
|
* @param format - The serialization format used (default: "json").
|
|
16
18
|
* @param options - Additional metadata options.
|
|
17
19
|
* @returns A SerializedEnvelope with metadata and data.
|
|
20
|
+
* @throws {SerializationError} when `options.version` is not a wire-format
|
|
21
|
+
* version this build can read back.
|
|
18
22
|
*/
|
|
19
23
|
export function createEnvelope(data, format = SerializationFormat.JSON, options = {}) {
|
|
24
|
+
const version = options.version ?? SERIALIZATION_SCHEMA_VERSION;
|
|
25
|
+
assertProducibleVersion(version);
|
|
20
26
|
return {
|
|
21
27
|
metadata: {
|
|
22
28
|
format,
|
|
23
|
-
version
|
|
29
|
+
version,
|
|
24
30
|
contentType: options.contentType ?? contentTypeForFormat(format),
|
|
25
31
|
encoding: options.encoding ?? "utf-8",
|
|
32
|
+
...(options.type !== undefined ? { type: options.type } : {}),
|
|
33
|
+
...(options.schemaVersion !== undefined
|
|
34
|
+
? { schemaVersion: options.schemaVersion }
|
|
35
|
+
: {}),
|
|
26
36
|
},
|
|
27
37
|
data,
|
|
28
38
|
};
|
|
@@ -48,42 +58,6 @@ export function contentTypeForFormat(format) {
|
|
|
48
58
|
return "application/octet-stream";
|
|
49
59
|
}
|
|
50
60
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Validates that a value received from the wire is a well-formed envelope.
|
|
53
|
-
*
|
|
54
|
-
* @param envelope - The candidate envelope.
|
|
55
|
-
* @throws {InvalidSerializedDataError} when the shape or schema version is
|
|
56
|
-
* unusable. Envelope payloads arrive from a queue or an RPC peer, so a
|
|
57
|
-
* rejection has to be distinguishable from an internal bug: a bare `Error`
|
|
58
|
-
* left callers unable to tell hostile input from a defect of their own.
|
|
59
|
-
*/
|
|
60
|
-
export function assertValidEnvelope(envelope) {
|
|
61
|
-
if (typeof envelope !== "object" || envelope === null) {
|
|
62
|
-
throw new InvalidSerializedDataError(`Malformed envelope: expected an object, got ${envelope === null ? "null" : typeof envelope}`, { format: "envelope" });
|
|
63
|
-
}
|
|
64
|
-
const candidate = envelope;
|
|
65
|
-
if (typeof candidate.metadata !== "object" || candidate.metadata === null) {
|
|
66
|
-
throw new InvalidSerializedDataError("Malformed envelope: missing metadata", { format: "envelope" });
|
|
67
|
-
}
|
|
68
|
-
const metadata = candidate.metadata;
|
|
69
|
-
if (typeof metadata.format !== "string" || metadata.format.length === 0) {
|
|
70
|
-
throw new InvalidSerializedDataError("Malformed envelope: metadata.format is missing", { format: "envelope" });
|
|
71
|
-
}
|
|
72
|
-
if (typeof candidate.data !== "string" &&
|
|
73
|
-
!(candidate.data instanceof Uint8Array)) {
|
|
74
|
-
throw new InvalidSerializedDataError("Malformed envelope: data must be a string or Uint8Array", { format: "envelope" });
|
|
75
|
-
}
|
|
76
|
-
// The version exists so a future producer can be detected rather than
|
|
77
|
-
// silently misread. Older versions stay readable; newer ones do not.
|
|
78
|
-
if (metadata.version !== undefined) {
|
|
79
|
-
if (!Number.isInteger(metadata.version)) {
|
|
80
|
-
throw new InvalidSerializedDataError(`Malformed envelope: metadata.version must be an integer, got ${String(metadata.version)}`, { format: "envelope" });
|
|
81
|
-
}
|
|
82
|
-
if (metadata.version > SERIALIZATION_SCHEMA_VERSION) {
|
|
83
|
-
throw new InvalidSerializedDataError(`Unsupported envelope schema version ${metadata.version}: this build understands up to ${SERIALIZATION_SCHEMA_VERSION}`, { format: "envelope" });
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
61
|
/**
|
|
88
62
|
* Extract the data from an envelope, validating metadata.
|
|
89
63
|
*
|
|
@@ -110,11 +84,14 @@ export function unwrapEnvelope(envelope, expectedFormat) {
|
|
|
110
84
|
* the helper could only ever call `serialize(value)`, so `preserveTypes`,
|
|
111
85
|
* `pretty` and the size/depth limits were unreachable through an envelope
|
|
112
86
|
* unless they happened to be baked into the serializer instance.
|
|
87
|
+
* @param metadata - Application metadata (`type`, `schemaVersion`) to stamp
|
|
88
|
+
* on the envelope.
|
|
113
89
|
* @returns A SerializedEnvelope containing the serialized data.
|
|
114
90
|
*/
|
|
115
|
-
export function serializeToEnvelope(value, serializer, format = SerializationFormat.JSON, options) {
|
|
91
|
+
export function serializeToEnvelope(value, serializer, format = SerializationFormat.JSON, options, metadata = {}) {
|
|
116
92
|
const data = serializer.serialize(value, options);
|
|
117
93
|
return createEnvelope(data, format, {
|
|
94
|
+
...metadata,
|
|
118
95
|
contentType: serializer.contentType,
|
|
119
96
|
});
|
|
120
97
|
}
|
|
@@ -141,4 +118,3 @@ export function deserializeFromEnvelope(envelope, deserializer, expectedFormat,
|
|
|
141
118
|
}
|
|
142
119
|
return deserializer.deserialize(decodeUtf8(data), options);
|
|
143
120
|
}
|
|
144
|
-
//# sourceMappingURL=envelope.core.js.map
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* Wraps serialized data with metadata for cross-service communication.
|
|
5
5
|
*/
|
|
6
6
|
export { createEnvelope, assertValidEnvelope, contentTypeForFormat, unwrapEnvelope, serializeToEnvelope, deserializeFromEnvelope, } from "./envelope.core.js";
|
|
7
|
-
|
|
7
|
+
export type { EnvelopeMetadataOptions } from "./envelope.core.js";
|
|
@@ -32,4 +32,3 @@ export declare function escapeObject(body: Record<string, unknown>): Record<stri
|
|
|
32
32
|
* claims to be one but its `$value` is not a plain object.
|
|
33
33
|
*/
|
|
34
34
|
export declare function escapedBody(value: Record<string, unknown>): Record<string, unknown> | null | undefined;
|
|
35
|
-
//# sourceMappingURL=jsonSerializer.escape.d.ts.map
|
|
@@ -29,4 +29,3 @@ export declare function assertByteSize(json: string, maxSize: number, origin: "i
|
|
|
29
29
|
* unless the caller has explicitly opted in with `allowUnsafeKeys`.
|
|
30
30
|
*/
|
|
31
31
|
export declare function defineKey(target: Record<string, unknown>, key: string, value: unknown, allowUnsafeKeys: boolean): void;
|
|
32
|
-
//# sourceMappingURL=jsonSerializer.keys.d.ts.map
|
|
@@ -7,4 +7,3 @@
|
|
|
7
7
|
export { SerializerRegistry } from "./serializerRegistry.core.js";
|
|
8
8
|
export { createSerializer, createDefaultRegistry, } from "./serializerRegistry.factory.js";
|
|
9
9
|
export type { CreateSerializerOptions } from "./serializerRegistry.factory.js";
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -50,4 +50,3 @@ export declare function createSerializer(format: SerializationFormat, options?:
|
|
|
50
50
|
* @returns A SerializerRegistry with "json" registered.
|
|
51
51
|
*/
|
|
52
52
|
export declare function createDefaultRegistry(): SerializerRegistry;
|
|
53
|
-
//# sourceMappingURL=serializerRegistry.factory.d.ts.map
|
|
@@ -28,4 +28,3 @@ export declare function createBuiltinTransformers(): TransformerRegistry;
|
|
|
28
28
|
* seen too.
|
|
29
29
|
*/
|
|
30
30
|
export declare function layerTransformers(primary: TransformerLookup, fallback: TransformerLookup): TransformerLookup;
|
|
31
|
-
//# sourceMappingURL=transformerLookup.core.d.ts.map
|
|
@@ -24,4 +24,3 @@ export declare function toTaggedOutput(transformer: TypeTransformer, raw: unknow
|
|
|
24
24
|
* @throws {SerializeError} naming the type and how to fix it.
|
|
25
25
|
*/
|
|
26
26
|
export declare function assertNotLossy(value: object): void;
|
|
27
|
-
//# sourceMappingURL=transformerOutput.helper.d.ts.map
|
|
@@ -11,4 +11,3 @@ export declare function fromBase64(base64: string): Uint8Array;
|
|
|
11
11
|
export declare function encodeUtf8(text: string): Uint8Array;
|
|
12
12
|
/** Decode a Uint8Array to a string using UTF-8. */
|
|
13
13
|
export declare function decodeUtf8(data: Uint8Array): string;
|
|
14
|
-
//# sourceMappingURL=encoding.utils.d.ts.map
|
|
@@ -4,4 +4,3 @@
|
|
|
4
4
|
* Core contracts for serializers, transformers, and serialization options.
|
|
5
5
|
*/
|
|
6
6
|
export type { SerializationFormat, SerializedValue, SerializeOptions, DeserializeOptions, SerializationMetadata, SerializedEnvelope, Serializer, TypeTransformer, } from "./serializer.type.js";
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -63,12 +63,28 @@ export interface DeserializeOptions {
|
|
|
63
63
|
export interface SerializationMetadata {
|
|
64
64
|
/** The format used (e.g., "json"). */
|
|
65
65
|
readonly format: string;
|
|
66
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Version of the envelope's wire format, i.e. `SERIALIZATION_SCHEMA_VERSION`
|
|
68
|
+
* (currently 1). It is owned by this package, not by the application: a
|
|
69
|
+
* consumer refuses an envelope whose version is newer than it understands.
|
|
70
|
+
* The version of *your* message shape belongs in {@link schemaVersion}.
|
|
71
|
+
*/
|
|
67
72
|
readonly version?: number;
|
|
68
73
|
/** MIME content type (e.g., "application/json"). */
|
|
69
74
|
readonly contentType?: string;
|
|
70
75
|
/** Character encoding (e.g., "utf-8"). */
|
|
71
76
|
readonly encoding?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Application-level name of what the payload is (`"OrderPlaced"`), so a
|
|
79
|
+
* consumer can route an envelope without deserializing it first.
|
|
80
|
+
*/
|
|
81
|
+
readonly type?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Application-level version of the payload's shape (`2` or `"2026-01"`),
|
|
84
|
+
* for the consumer's own forward/backward compatibility handling. Carried
|
|
85
|
+
* verbatim; this package never interprets it.
|
|
86
|
+
*/
|
|
87
|
+
readonly schemaVersion?: number | string;
|
|
72
88
|
}
|
|
73
89
|
/** An envelope wrapping serialized data with metadata. */
|
|
74
90
|
export interface SerializedEnvelope {
|
|
@@ -116,4 +132,3 @@ export interface TypeTransformer<TValue = unknown> {
|
|
|
116
132
|
*/
|
|
117
133
|
deserialize(value: unknown, options?: DeserializeOptions): TValue;
|
|
118
134
|
}
|
|
119
|
-
//# sourceMappingURL=serializer.type.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zudojs/serialization",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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,10 +19,10 @@
|
|
|
19
19
|
"LICENSE"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@zudojs/constants": "1.
|
|
23
|
-
"@zudojs/errors": "1.
|
|
24
|
-
"@zudojs/types": "1.
|
|
25
|
-
"@zudojs/validation": "1.
|
|
22
|
+
"@zudojs/constants": "1.2.0",
|
|
23
|
+
"@zudojs/errors": "1.4.0",
|
|
24
|
+
"@zudojs/types": "1.3.0",
|
|
25
|
+
"@zudojs/validation": "1.2.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"typescript": "7.0.2",
|