@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.
Files changed (57) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +0 -1
  3. package/dist/serializerEnvelope/envelope.assert.d.ts +27 -0
  4. package/dist/serializerEnvelope/envelope.assert.js +69 -0
  5. package/dist/serializerEnvelope/envelope.core.d.ts +23 -17
  6. package/dist/serializerEnvelope/envelope.core.js +15 -39
  7. package/dist/serializerEnvelope/index.d.ts +1 -1
  8. package/dist/serializerEnvelope/index.js +0 -1
  9. package/dist/serializerJson/index.d.ts +0 -1
  10. package/dist/serializerJson/index.js +0 -1
  11. package/dist/serializerJson/jsonSerializer.core.d.ts +0 -1
  12. package/dist/serializerJson/jsonSerializer.core.js +0 -1
  13. package/dist/serializerJson/jsonSerializer.escape.d.ts +0 -1
  14. package/dist/serializerJson/jsonSerializer.escape.js +0 -1
  15. package/dist/serializerJson/jsonSerializer.keys.d.ts +0 -1
  16. package/dist/serializerJson/jsonSerializer.keys.js +0 -1
  17. package/dist/serializerJson/jsonSerializer.restore.d.ts +0 -1
  18. package/dist/serializerJson/jsonSerializer.restore.js +0 -1
  19. package/dist/serializerJson/jsonSerializer.transform.d.ts +0 -1
  20. package/dist/serializerJson/jsonSerializer.transform.js +0 -1
  21. package/dist/serializerRegistry/index.d.ts +0 -1
  22. package/dist/serializerRegistry/index.js +0 -1
  23. package/dist/serializerRegistry/serializerRegistry.core.d.ts +0 -1
  24. package/dist/serializerRegistry/serializerRegistry.core.js +0 -1
  25. package/dist/serializerRegistry/serializerRegistry.factory.d.ts +0 -1
  26. package/dist/serializerRegistry/serializerRegistry.factory.js +0 -1
  27. package/dist/serializerTransformPolicy/index.d.ts +0 -1
  28. package/dist/serializerTransformPolicy/index.js +0 -1
  29. package/dist/serializerTransformPolicy/transformerLookup.core.d.ts +0 -1
  30. package/dist/serializerTransformPolicy/transformerLookup.core.js +0 -1
  31. package/dist/serializerTransformPolicy/transformerOutput.helper.d.ts +0 -1
  32. package/dist/serializerTransformPolicy/transformerOutput.helper.js +0 -1
  33. package/dist/serializerTransforms/bigint.transformer.d.ts +0 -1
  34. package/dist/serializerTransforms/bigint.transformer.js +0 -1
  35. package/dist/serializerTransforms/date.transformer.d.ts +0 -1
  36. package/dist/serializerTransforms/date.transformer.js +0 -1
  37. package/dist/serializerTransforms/index.d.ts +0 -1
  38. package/dist/serializerTransforms/index.js +0 -1
  39. package/dist/serializerTransforms/map.transformer.d.ts +0 -1
  40. package/dist/serializerTransforms/map.transformer.js +0 -1
  41. package/dist/serializerTransforms/set.transformer.d.ts +0 -1
  42. package/dist/serializerTransforms/set.transformer.js +0 -1
  43. package/dist/serializerTransforms/transformerRegistry.core.d.ts +0 -1
  44. package/dist/serializerTransforms/transformerRegistry.core.js +0 -1
  45. package/dist/serializerTransformsExt/buffer.transformer.d.ts +0 -1
  46. package/dist/serializerTransformsExt/buffer.transformer.js +0 -1
  47. package/dist/serializerTransformsExt/encoding.utils.d.ts +0 -1
  48. package/dist/serializerTransformsExt/encoding.utils.js +0 -1
  49. package/dist/serializerTransformsExt/error.transformer.d.ts +0 -1
  50. package/dist/serializerTransformsExt/error.transformer.js +0 -1
  51. package/dist/serializerTransformsExt/index.d.ts +0 -1
  52. package/dist/serializerTransformsExt/index.js +0 -1
  53. package/dist/serializerTypes/index.d.ts +0 -1
  54. package/dist/serializerTypes/index.js +0 -1
  55. package/dist/serializerTypes/serializer.type.d.ts +17 -2
  56. package/dist/serializerTypes/serializer.type.js +0 -1
  57. 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: options.version ?? SERIALIZATION_SCHEMA_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
- //# sourceMappingURL=index.d.ts.map
7
+ export type { EnvelopeMetadataOptions } from "./envelope.core.js";
@@ -4,4 +4,3 @@
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
- //# sourceMappingURL=index.js.map
@@ -6,4 +6,3 @@
6
6
  */
7
7
  export { JSONSerializer, type JSONSerializerOptions, } from "./jsonSerializer.core.js";
8
8
  export { ESCAPED_OBJECT_TAG } from "./jsonSerializer.escape.js";
9
- //# sourceMappingURL=index.d.ts.map
@@ -6,4 +6,3 @@
6
6
  */
7
7
  export { JSONSerializer, } from "./jsonSerializer.core.js";
8
8
  export { ESCAPED_OBJECT_TAG } from "./jsonSerializer.escape.js";
9
- //# sourceMappingURL=index.js.map
@@ -50,4 +50,3 @@ export declare class JSONSerializer implements Serializer<unknown, string> {
50
50
  /** Parses JSON, reporting malformed input as a typed error. */
51
51
  private parse;
52
52
  }
53
- //# sourceMappingURL=jsonSerializer.core.d.ts.map
@@ -110,4 +110,3 @@ export class JSONSerializer {
110
110
  }
111
111
  }
112
112
  }
113
- //# sourceMappingURL=jsonSerializer.core.js.map
@@ -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
@@ -47,4 +47,3 @@ export function escapedBody(value) {
47
47
  const body = value[SerializationTags.VALUE];
48
48
  return isPlainObject(body) ? body : null;
49
49
  }
50
- //# sourceMappingURL=jsonSerializer.escape.js.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
@@ -52,4 +52,3 @@ export function defineKey(target, key, value, allowUnsafeKeys) {
52
52
  configurable: true,
53
53
  });
54
54
  }
55
- //# sourceMappingURL=jsonSerializer.keys.js.map
@@ -14,4 +14,3 @@ export interface RestoreWalk {
14
14
  }
15
15
  /** Rebuilds runtime values from their tagged JSON representation. */
16
16
  export declare function restoreValue(walk: RestoreWalk, value: unknown, depth: number): unknown;
17
- //# sourceMappingURL=jsonSerializer.restore.d.ts.map
@@ -87,4 +87,3 @@ function restoreEntries(walk, obj, depth, verbatimKey) {
87
87
  }
88
88
  return result;
89
89
  }
90
- //# sourceMappingURL=jsonSerializer.restore.js.map
@@ -14,4 +14,3 @@ export interface TransformWalk {
14
14
  }
15
15
  /** Converts a value into its JSON-safe, tagged representation. */
16
16
  export declare function transformValue(walk: TransformWalk, value: unknown, depth: number): unknown;
17
- //# sourceMappingURL=jsonSerializer.transform.d.ts.map
@@ -57,4 +57,3 @@ function transformEntries(walk, value, depth) {
57
57
  }
58
58
  return result;
59
59
  }
60
- //# sourceMappingURL=jsonSerializer.transform.js.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
@@ -6,4 +6,3 @@
6
6
  */
7
7
  export { SerializerRegistry } from "./serializerRegistry.core.js";
8
8
  export { createSerializer, createDefaultRegistry, } from "./serializerRegistry.factory.js";
9
- //# sourceMappingURL=index.js.map
@@ -28,4 +28,3 @@ export declare class SerializerRegistry {
28
28
  /** Number of registered serializers. */
29
29
  get size(): number;
30
30
  }
31
- //# sourceMappingURL=serializerRegistry.core.d.ts.map
@@ -45,4 +45,3 @@ export class SerializerRegistry {
45
45
  return this.serializers.size;
46
46
  }
47
47
  }
48
- //# sourceMappingURL=serializerRegistry.core.js.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
@@ -37,4 +37,3 @@ export function createDefaultRegistry() {
37
37
  registry.register(createSerializer(Format.JSON));
38
38
  return registry;
39
39
  }
40
- //# sourceMappingURL=serializerRegistry.factory.js.map
@@ -7,4 +7,3 @@
7
7
  */
8
8
  export { createBuiltinTransformers, layerTransformers, type TransformerLookup, } from "./transformerLookup.core.js";
9
9
  export { assertNotLossy, toTaggedOutput } from "./transformerOutput.helper.js";
10
- //# sourceMappingURL=index.d.ts.map
@@ -7,4 +7,3 @@
7
7
  */
8
8
  export { createBuiltinTransformers, layerTransformers, } from "./transformerLookup.core.js";
9
9
  export { assertNotLossy, toTaggedOutput } from "./transformerOutput.helper.js";
10
- //# sourceMappingURL=index.js.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
@@ -34,4 +34,3 @@ export function layerTransformers(primary, fallback) {
34
34
  get: (type) => (primary.has(type) ? primary.get(type) : fallback.get(type)),
35
35
  };
36
36
  }
37
- //# sourceMappingURL=transformerLookup.core.js.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
@@ -75,4 +75,3 @@ export function assertNotLossy(value) {
75
75
  }
76
76
  }
77
77
  }
78
- //# sourceMappingURL=transformerOutput.helper.js.map
@@ -7,4 +7,3 @@
7
7
  import type { TypeTransformer } from "../serializerTypes/index.js";
8
8
  /** Transformer that handles BigInt round-trips. */
9
9
  export declare const BigIntTransformer: TypeTransformer<bigint>;
10
- //# sourceMappingURL=bigint.transformer.d.ts.map
@@ -46,4 +46,3 @@ export const BigIntTransformer = {
46
46
  return BigInt(raw);
47
47
  },
48
48
  };
49
- //# sourceMappingURL=bigint.transformer.js.map
@@ -7,4 +7,3 @@
7
7
  import type { TypeTransformer } from "../serializerTypes/index.js";
8
8
  /** Transformer that handles Date round-trips. */
9
9
  export declare const DateTransformer: TypeTransformer<Date>;
10
- //# sourceMappingURL=date.transformer.d.ts.map
@@ -35,4 +35,3 @@ export const DateTransformer = {
35
35
  return date;
36
36
  },
37
37
  };
38
- //# sourceMappingURL=date.transformer.js.map
@@ -8,4 +8,3 @@ export { DateTransformer } from "./date.transformer.js";
8
8
  export { BigIntTransformer } from "./bigint.transformer.js";
9
9
  export { MapTransformer } from "./map.transformer.js";
10
10
  export { SetTransformer } from "./set.transformer.js";
11
- //# sourceMappingURL=index.d.ts.map
@@ -8,4 +8,3 @@ export { DateTransformer } from "./date.transformer.js";
8
8
  export { BigIntTransformer } from "./bigint.transformer.js";
9
9
  export { MapTransformer } from "./map.transformer.js";
10
10
  export { SetTransformer } from "./set.transformer.js";
11
- //# sourceMappingURL=index.js.map
@@ -7,4 +7,3 @@
7
7
  import type { TypeTransformer } from "../serializerTypes/index.js";
8
8
  /** Transformer that handles Map round-trips. */
9
9
  export declare const MapTransformer: TypeTransformer<Map<unknown, unknown>>;
10
- //# sourceMappingURL=map.transformer.d.ts.map
@@ -32,4 +32,3 @@ export const MapTransformer = {
32
32
  return new Map(raw);
33
33
  },
34
34
  };
35
- //# sourceMappingURL=map.transformer.js.map
@@ -7,4 +7,3 @@
7
7
  import type { TypeTransformer } from "../serializerTypes/index.js";
8
8
  /** Transformer that handles Set round-trips. */
9
9
  export declare const SetTransformer: TypeTransformer<Set<unknown>>;
10
- //# sourceMappingURL=set.transformer.d.ts.map
@@ -28,4 +28,3 @@ export const SetTransformer = {
28
28
  return new Set(raw);
29
29
  },
30
30
  };
31
- //# sourceMappingURL=set.transformer.js.map
@@ -34,4 +34,3 @@ export declare class TransformerRegistry {
34
34
  /** Number of registered transformers. */
35
35
  get size(): number;
36
36
  }
37
- //# sourceMappingURL=transformerRegistry.core.d.ts.map
@@ -61,4 +61,3 @@ export class TransformerRegistry {
61
61
  return this.transformers.size;
62
62
  }
63
63
  }
64
- //# sourceMappingURL=transformerRegistry.core.js.map
@@ -7,4 +7,3 @@
7
7
  import type { TypeTransformer } from "../serializerTypes/index.js";
8
8
  /** Transformer that handles Uint8Array round-trips. */
9
9
  export declare const BufferTransformer: TypeTransformer<Uint8Array>;
10
- //# sourceMappingURL=buffer.transformer.d.ts.map
@@ -30,4 +30,3 @@ export const BufferTransformer = {
30
30
  return fromBase64(raw);
31
31
  },
32
32
  };
33
- //# sourceMappingURL=buffer.transformer.js.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
@@ -40,4 +40,3 @@ export function decodeUtf8(data) {
40
40
  }
41
41
  return Buffer.from(data).toString("utf-8");
42
42
  }
43
- //# sourceMappingURL=encoding.utils.js.map
@@ -10,4 +10,3 @@
10
10
  import type { TypeTransformer } from "../serializerTypes/index.js";
11
11
  /** Transformer that handles Error round-trips. */
12
12
  export declare const ErrorTransformer: TypeTransformer<Error>;
13
- //# sourceMappingURL=error.transformer.d.ts.map
@@ -83,4 +83,3 @@ export const ErrorTransformer = {
83
83
  return error;
84
84
  },
85
85
  };
86
- //# sourceMappingURL=error.transformer.js.map
@@ -7,4 +7,3 @@
7
7
  export { BufferTransformer } from "./buffer.transformer.js";
8
8
  export { ErrorTransformer } from "./error.transformer.js";
9
9
  export { toBase64, fromBase64, encodeUtf8, decodeUtf8, } from "./encoding.utils.js";
10
- //# sourceMappingURL=index.d.ts.map
@@ -7,4 +7,3 @@
7
7
  export { BufferTransformer } from "./buffer.transformer.js";
8
8
  export { ErrorTransformer } from "./error.transformer.js";
9
9
  export { toBase64, fromBase64, encodeUtf8, decodeUtf8, } from "./encoding.utils.js";
10
- //# sourceMappingURL=index.js.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
@@ -4,4 +4,3 @@
4
4
  * Core contracts for serializers, transformers, and serialization options.
5
5
  */
6
6
  export {};
7
- //# sourceMappingURL=index.js.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
- /** Schema version for forward/backward compatibility. */
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
@@ -6,4 +6,3 @@
6
6
  * NOT available in @zudojs/types or @zudojs/constants.
7
7
  */
8
8
  export {};
9
- //# sourceMappingURL=serializer.type.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zudojs/serialization",
3
- "version": "1.2.3",
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.1.4",
23
- "@zudojs/errors": "1.3.2",
24
- "@zudojs/types": "1.2.0",
25
- "@zudojs/validation": "1.1.2"
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",