metano-runtime 2.7.2 → 2.8.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/system/equality.d.ts +17 -2
- package/dist/system/equality.js +20 -4
- package/dist/system/json/converters.js +14 -19
- package/dist/system/json/index.d.ts +2 -1
- package/dist/system/json/index.js +1 -0
- package/dist/system/json/json-serializer.d.ts +9 -1
- package/dist/system/json/json-serializer.js +26 -9
- package/dist/system/json/public-json-shape.d.ts +13 -0
- package/dist/system/json/public-json-shape.js +38 -0
- package/dist/system/json/serializer-context.d.ts +15 -1
- package/dist/system/json/serializer-context.js +16 -0
- package/dist/system/json/types.d.ts +23 -2
- package/package.json +1 -1
|
@@ -61,13 +61,28 @@ export declare const valueEquals: typeof equals;
|
|
|
61
61
|
* as C# arrays, lists, dictionaries and sets do.
|
|
62
62
|
*/
|
|
63
63
|
export declare function objectEquals(a: unknown, b: unknown): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* The element structure of a C# tuple, as the compiler emits it for
|
|
66
|
+
* {@link tupleEquals}'s `shape` argument: one entry per positional element, `null`
|
|
67
|
+
* for an element that is not a tuple, a nested `TupleShape` for an element that is
|
|
68
|
+
* itself a tuple (possibly nullable — `null` elements compare equal there). An
|
|
69
|
+
* empty array marks a nested tuple without tuple elements of its own.
|
|
70
|
+
*/
|
|
71
|
+
export type TupleShape = readonly (TupleShape | null)[];
|
|
64
72
|
/**
|
|
65
73
|
* C#'s `ValueTuple.Equals(other)` over the positional arrays C# tuples lower to: same
|
|
66
74
|
* length, and each element pair equal under {@link objectEquals} (C# compares each
|
|
67
75
|
* element with `EqualityComparer<T>.Default`, so a class element compares by reference).
|
|
68
|
-
*
|
|
76
|
+
*
|
|
77
|
+
* At runtime a nested tuple and a C# array are both JS arrays, which `objectEquals`
|
|
78
|
+
* cannot tell apart — so a call whose static tuple type has tuple elements passes the
|
|
79
|
+
* compiler-computed `shape`, and those elements compare element-wise (recursively)
|
|
80
|
+
* instead of by reference. A nullable tuple (or nullable tuple element) is the value
|
|
81
|
+
* or `null` here, so both operands are null-guarded: both `null` equal, one `null`
|
|
82
|
+
* unequal, otherwise element-wise — C#'s `Nullable<T>.Equals` and `object.Equals`
|
|
83
|
+
* answers for nullable tuples.
|
|
69
84
|
*/
|
|
70
|
-
export declare function tupleEquals(tuple:
|
|
85
|
+
export declare function tupleEquals(tuple: unknown, other: unknown, shape?: TupleShape): boolean;
|
|
71
86
|
/**
|
|
72
87
|
* Alias the compiler emits for every C# `GetHashCode()` call. Same contract as
|
|
73
88
|
* {@link hashCode}; the distinct name keeps a call site from colliding with a
|
package/dist/system/equality.js
CHANGED
|
@@ -220,12 +220,28 @@ export function objectEquals(a, b) {
|
|
|
220
220
|
* C#'s `ValueTuple.Equals(other)` over the positional arrays C# tuples lower to: same
|
|
221
221
|
* length, and each element pair equal under {@link objectEquals} (C# compares each
|
|
222
222
|
* element with `EqualityComparer<T>.Default`, so a class element compares by reference).
|
|
223
|
-
*
|
|
223
|
+
*
|
|
224
|
+
* At runtime a nested tuple and a C# array are both JS arrays, which `objectEquals`
|
|
225
|
+
* cannot tell apart — so a call whose static tuple type has tuple elements passes the
|
|
226
|
+
* compiler-computed `shape`, and those elements compare element-wise (recursively)
|
|
227
|
+
* instead of by reference. A nullable tuple (or nullable tuple element) is the value
|
|
228
|
+
* or `null` here, so both operands are null-guarded: both `null` equal, one `null`
|
|
229
|
+
* unequal, otherwise element-wise — C#'s `Nullable<T>.Equals` and `object.Equals`
|
|
230
|
+
* answers for nullable tuples.
|
|
224
231
|
*/
|
|
225
|
-
export function tupleEquals(tuple, other) {
|
|
226
|
-
if (
|
|
232
|
+
export function tupleEquals(tuple, other, shape) {
|
|
233
|
+
if (tuple == null || other == null) {
|
|
234
|
+
return tuple == null && other == null;
|
|
235
|
+
}
|
|
236
|
+
if (!Array.isArray(tuple) || !Array.isArray(other) || tuple.length !== other.length) {
|
|
227
237
|
return false;
|
|
228
|
-
|
|
238
|
+
}
|
|
239
|
+
return tuple.every((element, index) => {
|
|
240
|
+
const elementShape = shape?.[index];
|
|
241
|
+
return elementShape == null
|
|
242
|
+
? objectEquals(element, other[index])
|
|
243
|
+
: tupleEquals(element, other[index], elementShape);
|
|
244
|
+
});
|
|
229
245
|
}
|
|
230
246
|
function hasEqualsMethod(value) {
|
|
231
247
|
return "equals" in value && typeof value.equals === "function";
|
|
@@ -110,15 +110,19 @@ function mapConverter(descriptor, customConverters) {
|
|
|
110
110
|
},
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Writes any iterable (an array, a `Set`, a generator, a LINQ pipe for
|
|
115
|
+
* `IEnumerable<T>`) as a JSON array, converting each element (FR-038).
|
|
116
|
+
*/
|
|
117
|
+
function serializeIterable(value, elemConv) {
|
|
118
|
+
if (value == null)
|
|
119
|
+
return null;
|
|
120
|
+
return Array.from(value, (item) => elemConv.serialize(item));
|
|
121
|
+
}
|
|
114
122
|
function arrayConverter(descriptor, customConverters) {
|
|
115
123
|
const elemConv = resolveConverter(descriptor.element, customConverters);
|
|
116
124
|
return {
|
|
117
|
-
serialize: (value) =>
|
|
118
|
-
if (value == null)
|
|
119
|
-
return null;
|
|
120
|
-
return value.map((item) => elemConv.serialize(item));
|
|
121
|
-
},
|
|
125
|
+
serialize: (value) => serializeIterable(value, elemConv),
|
|
122
126
|
deserialize: (value) => {
|
|
123
127
|
if (value == null)
|
|
124
128
|
return null;
|
|
@@ -130,21 +134,12 @@ function arrayConverter(descriptor, customConverters) {
|
|
|
130
134
|
function hashSetConverter(descriptor, customConverters) {
|
|
131
135
|
const elemConv = resolveConverter(descriptor.element, customConverters);
|
|
132
136
|
return {
|
|
133
|
-
serialize: (value) =>
|
|
134
|
-
if (value == null)
|
|
135
|
-
return null;
|
|
136
|
-
const set = value;
|
|
137
|
-
const result = [];
|
|
138
|
-
for (const item of set) {
|
|
139
|
-
result.push(elemConv.serialize(item));
|
|
140
|
-
}
|
|
141
|
-
return result;
|
|
142
|
-
},
|
|
137
|
+
serialize: (value) => serializeIterable(value, elemConv),
|
|
143
138
|
deserialize: (value) => {
|
|
144
139
|
if (value == null)
|
|
145
140
|
return null;
|
|
146
|
-
const
|
|
147
|
-
return new HashSet(
|
|
141
|
+
const items = value.map((item) => elemConv.deserialize(item));
|
|
142
|
+
return new HashSet(items);
|
|
148
143
|
},
|
|
149
144
|
};
|
|
150
145
|
}
|
|
@@ -171,7 +166,7 @@ function enumConverter(descriptor) {
|
|
|
171
166
|
}
|
|
172
167
|
// ─── Enum (Numeric) ──────────────────────────────────────────────────────────
|
|
173
168
|
function numericEnumConverter(descriptor) {
|
|
174
|
-
const validValues = new Set(Object.values(descriptor.values));
|
|
169
|
+
const validValues = new Set(Object.values(descriptor.values).filter((value) => typeof value === "number"));
|
|
175
170
|
return {
|
|
176
171
|
serialize: (value) => value, // already a number
|
|
177
172
|
deserialize: (value) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export type { TypeDescriptor, PrimitiveDescriptor, RefDescriptor, TemporalDescriptor, DecimalDescriptor, MapDescriptor, ArrayDescriptor, HashSetDescriptor, BrandedDescriptor, EnumDescriptor, NumericEnumDescriptor, NullableDescriptor, PropertySpec, TypeSpec, JsonConverter, SerializerContextOptions, } from "./types.ts";
|
|
1
|
+
export type { TypeDescriptor, PrimitiveDescriptor, RefDescriptor, TemporalDescriptor, DecimalDescriptor, MapDescriptor, ArrayDescriptor, HashSetDescriptor, BrandedDescriptor, EnumDescriptor, NumericEnumDescriptor, NullableDescriptor, PropertySpec, TypeSpec, ValueSpec, JsonTypeInfo, JsonConverter, SerializerContextOptions, } from "./types.ts";
|
|
2
2
|
export { SerializerContext } from "./serializer-context.ts";
|
|
3
3
|
export { JsonSerializer, BoundSerializer } from "./json-serializer.ts";
|
|
4
4
|
export { PropertyNamingPolicy } from "./property-naming-policy.ts";
|
|
5
5
|
export { collectProperties } from "./converters.ts";
|
|
6
6
|
export { UnionGuardRegistry, registerUnionGuard, getUnionGuard, } from "./union-guard-registry.ts";
|
|
7
|
+
export { publicJsonShape } from "./public-json-shape.ts";
|
|
@@ -3,3 +3,4 @@ export { JsonSerializer, BoundSerializer } from "./json-serializer.js";
|
|
|
3
3
|
export { PropertyNamingPolicy } from "./property-naming-policy.js";
|
|
4
4
|
export { collectProperties } from "./converters.js";
|
|
5
5
|
export { UnionGuardRegistry, registerUnionGuard, getUnionGuard, } from "./union-guard-registry.js";
|
|
6
|
+
export { publicJsonShape } from "./public-json-shape.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TypeSpec, JsonConverter } from "./types.ts";
|
|
1
|
+
import type { TypeSpec, ValueSpec, JsonConverter } from "./types.ts";
|
|
2
2
|
import type { SerializerContext } from "./serializer-context.ts";
|
|
3
3
|
/**
|
|
4
4
|
* A bound serializer that uses a SerializerContext to resolve custom converters
|
|
@@ -9,8 +9,12 @@ export declare class BoundSerializer {
|
|
|
9
9
|
constructor(context: SerializerContext);
|
|
10
10
|
/** Serialize a TS object to a JSON-safe plain object. */
|
|
11
11
|
serialize<T>(value: T, spec: TypeSpec<T>): Record<string, unknown>;
|
|
12
|
+
/** Serialize a non-object root (collection, map, primitive, …) to a JSON-safe value. */
|
|
13
|
+
serialize<T>(value: T, spec: ValueSpec<T>): unknown;
|
|
12
14
|
/** Deserialize unknown data into a typed instance. */
|
|
13
15
|
deserialize<T>(data: unknown, spec: TypeSpec<T>): T;
|
|
16
|
+
/** Deserialize unknown data into a non-object root value. */
|
|
17
|
+
deserialize<T>(data: unknown, spec: ValueSpec<T>): T;
|
|
14
18
|
/** Resolve a spec by constructor — throws if not registered. */
|
|
15
19
|
specFor<T>(type: abstract new (...args: any[]) => T): TypeSpec<T>;
|
|
16
20
|
}
|
|
@@ -32,8 +36,12 @@ export declare class JsonSerializer {
|
|
|
32
36
|
private constructor();
|
|
33
37
|
/** Serialize a TS object to a JSON-safe plain object using the given spec. */
|
|
34
38
|
static serialize<T>(value: T, spec: TypeSpec<T>, converters?: readonly JsonConverter[]): Record<string, unknown>;
|
|
39
|
+
/** Serialize a non-object root (collection, map, primitive, …) to a JSON-safe value. */
|
|
40
|
+
static serialize<T>(value: T, spec: ValueSpec<T>, converters?: readonly JsonConverter[]): unknown;
|
|
35
41
|
/** Deserialize unknown data into a typed instance using the given spec. */
|
|
36
42
|
static deserialize<T>(data: unknown, spec: TypeSpec<T>, converters?: readonly JsonConverter[]): T;
|
|
43
|
+
/** Deserialize unknown data into a non-object root value using the given spec. */
|
|
44
|
+
static deserialize<T>(data: unknown, spec: ValueSpec<T>, converters?: readonly JsonConverter[]): T;
|
|
37
45
|
/** Create a bound serializer that uses the context's converters and registry. */
|
|
38
46
|
static withContext(context: SerializerContext): BoundSerializer;
|
|
39
47
|
}
|
|
@@ -1,4 +1,25 @@
|
|
|
1
|
-
import { serializeWithSpec, deserializeWithSpec } from "./converters.js";
|
|
1
|
+
import { serializeWithSpec, deserializeWithSpec, resolveConverter } from "./converters.js";
|
|
2
|
+
/** A `ValueSpec` carries a `descriptor`; a `TypeSpec` never does. */
|
|
3
|
+
function isValueSpec(spec) {
|
|
4
|
+
return "descriptor" in spec;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Serializes through either spec kind: an object contract walks its
|
|
8
|
+
* properties, a value root converts through its descriptor exactly as a
|
|
9
|
+
* property of that type would (custom converters still match by kind).
|
|
10
|
+
*/
|
|
11
|
+
function serializeWithInfo(value, spec, converters) {
|
|
12
|
+
if (isValueSpec(spec)) {
|
|
13
|
+
return resolveConverter(spec.descriptor, converters).serialize(value);
|
|
14
|
+
}
|
|
15
|
+
return serializeWithSpec(value, spec, converters);
|
|
16
|
+
}
|
|
17
|
+
function deserializeWithInfo(data, spec, converters) {
|
|
18
|
+
if (isValueSpec(spec)) {
|
|
19
|
+
return resolveConverter(spec.descriptor, converters).deserialize(data);
|
|
20
|
+
}
|
|
21
|
+
return deserializeWithSpec(data, spec, converters);
|
|
22
|
+
}
|
|
2
23
|
/**
|
|
3
24
|
* A bound serializer that uses a SerializerContext to resolve custom converters
|
|
4
25
|
* and look up specs by constructor.
|
|
@@ -8,13 +29,11 @@ export class BoundSerializer {
|
|
|
8
29
|
constructor(context) {
|
|
9
30
|
this.context = context;
|
|
10
31
|
}
|
|
11
|
-
/** Serialize a TS object to a JSON-safe plain object. */
|
|
12
32
|
serialize(value, spec) {
|
|
13
|
-
return
|
|
33
|
+
return serializeWithInfo(value, spec, this.context.converters);
|
|
14
34
|
}
|
|
15
|
-
/** Deserialize unknown data into a typed instance. */
|
|
16
35
|
deserialize(data, spec) {
|
|
17
|
-
return
|
|
36
|
+
return deserializeWithInfo(data, spec, this.context.converters);
|
|
18
37
|
}
|
|
19
38
|
/** Resolve a spec by constructor — throws if not registered. */
|
|
20
39
|
specFor(type) {
|
|
@@ -42,13 +61,11 @@ export class BoundSerializer {
|
|
|
42
61
|
*/
|
|
43
62
|
export class JsonSerializer {
|
|
44
63
|
constructor() { }
|
|
45
|
-
/** Serialize a TS object to a JSON-safe plain object using the given spec. */
|
|
46
64
|
static serialize(value, spec, converters) {
|
|
47
|
-
return
|
|
65
|
+
return serializeWithInfo(value, spec, converters);
|
|
48
66
|
}
|
|
49
|
-
/** Deserialize unknown data into a typed instance using the given spec. */
|
|
50
67
|
static deserialize(data, spec, converters) {
|
|
51
|
-
return
|
|
68
|
+
return deserializeWithInfo(data, spec, converters);
|
|
52
69
|
}
|
|
53
70
|
/** Create a bound serializer that uses the context's converters and registry. */
|
|
54
71
|
static withContext(context) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shape `JSON.stringify` produced for a transpiled instance while its overridable
|
|
3
|
+
* auto-properties were plain fields: one key per property, in declaration order, base
|
|
4
|
+
* classes first.
|
|
5
|
+
*
|
|
6
|
+
* Generated classes that keep such a property in a private backing field call this from
|
|
7
|
+
* `toJSON()`, because `JSON.stringify` would otherwise serialize the mangled field
|
|
8
|
+
* names. Every own property of the instance is visited; a backing field contributes its
|
|
9
|
+
* property name, read through the accessor so the most derived override answers, and the
|
|
10
|
+
* property is listed once however many classes of the chain declare a backing field for
|
|
11
|
+
* it. Any other own property passes through unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export declare function publicJsonShape(instance: object): Record<string, unknown>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The own-property name of a per-class backing field the transpiler emits for an
|
|
3
|
+
* overridable auto-property: `<property>$<Class>_<hash>` (`p$Shape_k3x9ab`), where the
|
|
4
|
+
* hash is six base-36 characters. `$` never appears in a C# identifier, so no
|
|
5
|
+
* property of the source type can be mistaken for one (a `[Name]` override that carries both a
|
|
6
|
+
* `$` and a six-character `_` suffix would be; do not name members that way).
|
|
7
|
+
*
|
|
8
|
+
* Kept in sync with the compiler side by the .NET golden test
|
|
9
|
+
* `PerClassBackingFieldTests.BackingFieldName_MatchesTheRuntimePublicJsonShapePattern`.
|
|
10
|
+
*/
|
|
11
|
+
const BACKING_FIELD_NAME = /^([^$]+)\$[^$]+_[0-9a-z]{6}$/;
|
|
12
|
+
/**
|
|
13
|
+
* The shape `JSON.stringify` produced for a transpiled instance while its overridable
|
|
14
|
+
* auto-properties were plain fields: one key per property, in declaration order, base
|
|
15
|
+
* classes first.
|
|
16
|
+
*
|
|
17
|
+
* Generated classes that keep such a property in a private backing field call this from
|
|
18
|
+
* `toJSON()`, because `JSON.stringify` would otherwise serialize the mangled field
|
|
19
|
+
* names. Every own property of the instance is visited; a backing field contributes its
|
|
20
|
+
* property name, read through the accessor so the most derived override answers, and the
|
|
21
|
+
* property is listed once however many classes of the chain declare a backing field for
|
|
22
|
+
* it. Any other own property passes through unchanged.
|
|
23
|
+
*/
|
|
24
|
+
export function publicJsonShape(instance) {
|
|
25
|
+
const source = instance;
|
|
26
|
+
// No prototype: a property named `constructor` or `__proto__` is an ordinary key.
|
|
27
|
+
const shape = Object.create(null);
|
|
28
|
+
for (const key of Object.keys(instance)) {
|
|
29
|
+
const name = publicNameOf(key);
|
|
30
|
+
if (!(name in shape)) {
|
|
31
|
+
shape[name] = source[name];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return shape;
|
|
35
|
+
}
|
|
36
|
+
function publicNameOf(ownKey) {
|
|
37
|
+
return BACKING_FIELD_NAME.exec(ownKey)?.[1] ?? ownKey;
|
|
38
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TypeSpec, SerializerContextOptions, JsonConverter } from "./types.ts";
|
|
1
|
+
import type { TypeSpec, ValueSpec, SerializerContextOptions, JsonConverter } from "./types.ts";
|
|
2
2
|
/**
|
|
3
3
|
* Base class for generated serializer contexts. Each context holds options
|
|
4
4
|
* (including custom converters) and a registry of type specs for lookup.
|
|
@@ -22,6 +22,20 @@ export declare abstract class SerializerContext {
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
protected createSpec<T>(spec: TypeSpec<T>): TypeSpec<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the spec of a non-object root (a collection, dictionary, set,
|
|
27
|
+
* primitive, enum, branded or nullable type). Intended to be called from
|
|
28
|
+
* lazy getters in generated subclasses:
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* get listEpisode(): ValueSpec<Episode[] | null> {
|
|
32
|
+
* return this._listEpisode ??= this.createValueSpec({ descriptor: { kind: "array", ... } });
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* Nothing is registered: a value spec has no constructor to resolve.
|
|
37
|
+
*/
|
|
38
|
+
protected createValueSpec<T>(spec: ValueSpec<T>): ValueSpec<T>;
|
|
25
39
|
/**
|
|
26
40
|
* Looks up a spec by constructor reference. Returns undefined if the type
|
|
27
41
|
* was not registered via createSpec().
|
|
@@ -33,6 +33,22 @@ export class SerializerContext {
|
|
|
33
33
|
}
|
|
34
34
|
return spec;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns the spec of a non-object root (a collection, dictionary, set,
|
|
38
|
+
* primitive, enum, branded or nullable type). Intended to be called from
|
|
39
|
+
* lazy getters in generated subclasses:
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* get listEpisode(): ValueSpec<Episode[] | null> {
|
|
43
|
+
* return this._listEpisode ??= this.createValueSpec({ descriptor: { kind: "array", ... } });
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* Nothing is registered: a value spec has no constructor to resolve.
|
|
48
|
+
*/
|
|
49
|
+
createValueSpec(spec) {
|
|
50
|
+
return spec;
|
|
51
|
+
}
|
|
36
52
|
/**
|
|
37
53
|
* Looks up a spec by constructor reference. Returns undefined if the type
|
|
38
54
|
* was not registered via createSpec().
|
|
@@ -56,10 +56,14 @@ export type EnumDescriptor = {
|
|
|
56
56
|
readonly kind: "enum";
|
|
57
57
|
readonly values: Record<string, string>;
|
|
58
58
|
};
|
|
59
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Numeric enum — passthrough both ways. `values` is the TS enum object itself,
|
|
61
|
+
* whose reverse mapping (`Level[0] === "Low"`) adds string values; only the
|
|
62
|
+
* numbers are valid members.
|
|
63
|
+
*/
|
|
60
64
|
export type NumericEnumDescriptor = {
|
|
61
65
|
readonly kind: "numericEnum";
|
|
62
|
-
readonly values: Record<string, number>;
|
|
66
|
+
readonly values: Record<string, string | number>;
|
|
63
67
|
};
|
|
64
68
|
/** Nullable wrapper — delegates to inner descriptor, passes null through */
|
|
65
69
|
export type NullableDescriptor = {
|
|
@@ -92,6 +96,23 @@ export interface TypeSpec<T = unknown> {
|
|
|
92
96
|
/** Own properties only (base properties come from base spec) */
|
|
93
97
|
readonly properties: readonly PropertySpec[];
|
|
94
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Spec of a non-object `[JsonSerializable]` root (a collection, dictionary,
|
|
101
|
+
* set, primitive, enum, branded or nullable type): the same descriptor that
|
|
102
|
+
* type gets as a property. `T` is the root's TS type and only types the
|
|
103
|
+
* `JsonSerializer` overloads; it has no runtime representation.
|
|
104
|
+
*/
|
|
105
|
+
export interface ValueSpec<T = unknown> {
|
|
106
|
+
/** How to convert the whole value between TS and JSON */
|
|
107
|
+
readonly descriptor: TypeDescriptor;
|
|
108
|
+
/**
|
|
109
|
+
* Phantom member that keeps `T` in the type; never set at runtime. Covariant
|
|
110
|
+
* like `TypeSpec<T>`, so any `ValueSpec<T>` is a `ValueSpec<unknown>`.
|
|
111
|
+
*/
|
|
112
|
+
readonly __type?: () => T;
|
|
113
|
+
}
|
|
114
|
+
/** Any spec the generated context exposes: an object contract or a value root. */
|
|
115
|
+
export type JsonTypeInfo<T = unknown> = TypeSpec<T> | ValueSpec<T>;
|
|
95
116
|
/** Custom converter — overrides built-in handling for a type descriptor kind */
|
|
96
117
|
export interface JsonConverter {
|
|
97
118
|
readonly kind: TypeDescriptor["kind"];
|