@fluidframework/core-interfaces 2.23.0 → 2.30.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/.eslintrc.cjs +19 -1
- package/CHANGELOG.md +4 -0
- package/api-extractor/api-extractor-lint-bundle.json +1 -1
- package/dist/exposedInternalUtilityTypes.d.ts +547 -0
- package/dist/exposedInternalUtilityTypes.d.ts.map +1 -0
- package/dist/exposedInternalUtilityTypes.js +11 -0
- package/dist/exposedInternalUtilityTypes.js.map +1 -0
- package/dist/exposedUtilityTypes.d.ts +10 -0
- package/dist/exposedUtilityTypes.d.ts.map +1 -0
- package/dist/exposedUtilityTypes.js +7 -0
- package/dist/exposedUtilityTypes.js.map +1 -0
- package/dist/internal.d.ts +34 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +23 -0
- package/dist/internal.js.map +1 -0
- package/dist/jsonDeserialized.d.ts +112 -0
- package/dist/jsonDeserialized.d.ts.map +1 -0
- package/dist/jsonDeserialized.js +7 -0
- package/dist/jsonDeserialized.js.map +1 -0
- package/dist/jsonSerializable.d.ts +126 -0
- package/dist/jsonSerializable.d.ts.map +1 -0
- package/dist/jsonSerializable.js +7 -0
- package/dist/jsonSerializable.js.map +1 -0
- package/dist/jsonSerializationErrors.d.ts +31 -0
- package/dist/jsonSerializationErrors.d.ts.map +1 -0
- package/dist/jsonSerializationErrors.js +7 -0
- package/dist/jsonSerializationErrors.js.map +1 -0
- package/dist/jsonType.d.ts +30 -0
- package/dist/jsonType.d.ts.map +1 -0
- package/dist/jsonType.js +7 -0
- package/dist/jsonType.js.map +1 -0
- package/dist/package.json +16 -1
- package/internal/exposedUtilityTypes.d.ts +6 -0
- package/internal.d.ts +1 -6
- package/lib/exposedInternalUtilityTypes.d.ts +547 -0
- package/lib/exposedInternalUtilityTypes.d.ts.map +1 -0
- package/lib/exposedInternalUtilityTypes.js +10 -0
- package/lib/exposedInternalUtilityTypes.js.map +1 -0
- package/lib/exposedUtilityTypes.d.ts +10 -0
- package/lib/exposedUtilityTypes.d.ts.map +1 -0
- package/lib/exposedUtilityTypes.js +6 -0
- package/lib/exposedUtilityTypes.js.map +1 -0
- package/lib/internal.d.ts +34 -0
- package/lib/internal.d.ts.map +1 -0
- package/lib/internal.js +7 -0
- package/lib/internal.js.map +1 -0
- package/lib/jsonDeserialized.d.ts +112 -0
- package/lib/jsonDeserialized.d.ts.map +1 -0
- package/lib/jsonDeserialized.js +6 -0
- package/lib/jsonDeserialized.js.map +1 -0
- package/lib/jsonSerializable.d.ts +126 -0
- package/lib/jsonSerializable.d.ts.map +1 -0
- package/lib/jsonSerializable.js +6 -0
- package/lib/jsonSerializable.js.map +1 -0
- package/lib/jsonSerializationErrors.d.ts +31 -0
- package/lib/jsonSerializationErrors.d.ts.map +1 -0
- package/lib/jsonSerializationErrors.js +6 -0
- package/lib/jsonSerializationErrors.js.map +1 -0
- package/lib/jsonType.d.ts +30 -0
- package/lib/jsonType.d.ts.map +1 -0
- package/lib/jsonType.js +6 -0
- package/lib/jsonType.js.map +1 -0
- package/package.json +50 -7
- package/src/cjs/package.json +19 -0
- package/src/exposedInternalUtilityTypes.ts +1152 -0
- package/src/exposedUtilityTypes.ts +20 -0
- package/src/internal.ts +73 -0
- package/src/jsonDeserialized.ts +118 -0
- package/src/jsonSerializable.ts +133 -0
- package/src/jsonSerializationErrors.ts +34 -0
- package/src/jsonType.ts +37 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Usage: Access these types via /internal/exposedUtilityTypes import spec when
|
|
7
|
+
// system level but externally exposed version of utilities are needed.
|
|
8
|
+
// Import via /internal when use is not exposed externally.
|
|
9
|
+
// Should a customer need access to these types, export should be relocated to
|
|
10
|
+
// index.ts and retagged export from internal.ts may be removed.
|
|
11
|
+
|
|
12
|
+
export type { JsonDeserialized, JsonDeserializedOptions } from "./jsonDeserialized.js";
|
|
13
|
+
export type { JsonSerializable, JsonSerializableOptions } from "./jsonSerializable.js";
|
|
14
|
+
export type {
|
|
15
|
+
SerializationErrorPerNonPublicProperties,
|
|
16
|
+
SerializationErrorPerUndefinedArrayElement,
|
|
17
|
+
} from "./jsonSerializationErrors.js";
|
|
18
|
+
export type { JsonTypeWith, NonNullJsonObjectWith } from "./jsonType.js";
|
|
19
|
+
|
|
20
|
+
export type { InternalUtilityTypes } from "./exposedInternalUtilityTypes.js";
|
package/src/internal.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
7
|
+
export * from "./index.js";
|
|
8
|
+
|
|
9
|
+
// Important: all other exports must be type only exports. In package.json exports,
|
|
10
|
+
// index.js is listed as the runtime file. This is done so that all imports are
|
|
11
|
+
// using the same outer runtime file. (Could be changed if needed.)
|
|
12
|
+
|
|
13
|
+
// Export set of utility types re-tagged as internal for FF client convenience.
|
|
14
|
+
// These types are not intended for direct use by customers and api-extractor will
|
|
15
|
+
// flag misuse. If an externally visible version of these types is needed, import
|
|
16
|
+
// from via /internal/exposedUtilityTypes rather than /internal.
|
|
17
|
+
import type { InternalUtilityTypes as ExposedInternalUtilityTypes } from "./exposedInternalUtilityTypes.js";
|
|
18
|
+
import type {
|
|
19
|
+
JsonDeserialized as ExposedJsonDeserialized,
|
|
20
|
+
JsonDeserializedOptions,
|
|
21
|
+
} from "./jsonDeserialized.js";
|
|
22
|
+
import type {
|
|
23
|
+
JsonSerializable as ExposedJsonSerializable,
|
|
24
|
+
JsonSerializableOptions,
|
|
25
|
+
} from "./jsonSerializable.js";
|
|
26
|
+
import type { JsonTypeWith as ExposedJsonTypeWith } from "./jsonType.js";
|
|
27
|
+
|
|
28
|
+
// Note: There are no docs for these re-exports. `@inheritdoc` cannot be used as:
|
|
29
|
+
// 1. api-extractor does not support renames.
|
|
30
|
+
// 2. api-extractor does not support package paths. ("Import paths are not supported")
|
|
31
|
+
// Also not useful, at least in VS Code, as substitution is not made in place.
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export type JsonDeserialized<
|
|
37
|
+
T,
|
|
38
|
+
Options extends JsonDeserializedOptions = {
|
|
39
|
+
AllowExactly: [];
|
|
40
|
+
AllowExtensionOf: never;
|
|
41
|
+
},
|
|
42
|
+
> = ExposedJsonDeserialized<T, Options>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export type JsonSerializable<
|
|
48
|
+
T,
|
|
49
|
+
Options extends JsonSerializableOptions = {
|
|
50
|
+
AllowExactly: [];
|
|
51
|
+
AllowExtensionOf: never;
|
|
52
|
+
},
|
|
53
|
+
> = ExposedJsonSerializable<T, Options>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export type JsonTypeWith<T> = ExposedJsonTypeWith<T>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
64
|
+
export namespace InternalUtilityTypes {
|
|
65
|
+
/* eslint-disable jsdoc/require-jsdoc */
|
|
66
|
+
export type IfSameType<
|
|
67
|
+
X,
|
|
68
|
+
Y,
|
|
69
|
+
IfSame = unknown,
|
|
70
|
+
IfDifferent = never,
|
|
71
|
+
> = ExposedInternalUtilityTypes.IfSameType<X, Y, IfSame, IfDifferent>;
|
|
72
|
+
/* eslint-enable jsdoc/require-jsdoc */
|
|
73
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { InternalUtilityTypes } from "./exposedInternalUtilityTypes.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Options for {@link JsonDeserialized}.
|
|
10
|
+
*
|
|
11
|
+
* @beta
|
|
12
|
+
*/
|
|
13
|
+
export interface JsonDeserializedOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Tuple of exact types that are managed by custom deserialization logic (beyond
|
|
16
|
+
* {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse|JSON.parse}
|
|
17
|
+
* without a reviver). Only exact types matching specification will be
|
|
18
|
+
* preserved unaltered.
|
|
19
|
+
*
|
|
20
|
+
* The default value is `[]`.
|
|
21
|
+
*/
|
|
22
|
+
AllowExactly?: unknown[];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* General types that are managed by custom deserialization logic (beyond
|
|
26
|
+
* {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse|JSON.parse}
|
|
27
|
+
* without a reviver). Any type satisfying specification will be preserved
|
|
28
|
+
* unaltered.
|
|
29
|
+
*
|
|
30
|
+
* The default value is `never`.
|
|
31
|
+
*/
|
|
32
|
+
AllowExtensionOf?: unknown;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Produces a type that results from a type `T` serialized and deserialized
|
|
37
|
+
* through JSON using {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify|JSON.stringify}
|
|
38
|
+
* (without replacer) and {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse|JSON.parse}
|
|
39
|
+
* (without reviver), respectively as base model.
|
|
40
|
+
*
|
|
41
|
+
* @typeParam T - The type that was serialized.
|
|
42
|
+
* @typeParam Options - Options for the filter. See {@link JsonDeserializedOptions}.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* Before adding use of this utility type, consider using a utility like
|
|
46
|
+
* {@link https://github.com/sinclairzx81/typebox#readme | TypeBox} that allows
|
|
47
|
+
* for runtime validation.
|
|
48
|
+
*
|
|
49
|
+
* This filter can be used to derive the expected type of a JSON deserialized
|
|
50
|
+
* value whether or not the type of value serialized meets serialization
|
|
51
|
+
* constraints (see {@link JsonSerializable} including serialization pitfalls).
|
|
52
|
+
*
|
|
53
|
+
* When used as a filter to inferred generic `T`, a compile-time error can be
|
|
54
|
+
* produced trying to assign `JsonDeserialized<T>` to `T`.
|
|
55
|
+
*
|
|
56
|
+
* Simply deserialized JSON never contains `bigint`, `undefined`, `symbol`,
|
|
57
|
+
* or function values. (Object properties which had those types before encoding
|
|
58
|
+
* are omitted during serialization and thus won't be present after
|
|
59
|
+
* deserialization.) Therefore, through this filter, such properties:
|
|
60
|
+
*
|
|
61
|
+
* - become optional with those types excluded (when there are other supported
|
|
62
|
+
* types in union)
|
|
63
|
+
*
|
|
64
|
+
* - are removed (when nothing else in union is supported)
|
|
65
|
+
*
|
|
66
|
+
* - in an array are (1) replaced with `null` if `undefined`, `symbol`, and
|
|
67
|
+
* function values or (2) simply removed (become `never`) if `bigint` value as
|
|
68
|
+
* serialization attempts will throw.
|
|
69
|
+
*
|
|
70
|
+
* Examples results:
|
|
71
|
+
*
|
|
72
|
+
* | Before serialization | After deserialization | After in record | After in array |
|
|
73
|
+
* | --------------------- | --------------------- | ------------------ | --------------------:|
|
|
74
|
+
* | `undefined \| number` | `number` | `prop?: number` | `(number \| null)[]` |
|
|
75
|
+
* | `symbol \| number` | `number` | `prop?: number` | `(number \| null)[]` |
|
|
76
|
+
* | `bigint \| number` | `number` | `prop: number` | `number[]` |
|
|
77
|
+
* | `undefined` | N/A `never` | (prop not present) | `null[]` |
|
|
78
|
+
* | `symbol` | N/A `never` | (prop not present) | `null[]` |
|
|
79
|
+
* | `bigint` | N/A `never` | N/A (prop not present) | N/A `never[]` |
|
|
80
|
+
* | `bigint \| symbol` | N/A `never` | (prop not present) | `null[]` |
|
|
81
|
+
* | `bigint \| number \| symbol` | `number` | `prop?: number` | `(number \| null)[]` |
|
|
82
|
+
*
|
|
83
|
+
* Setter and getter properties become value properties after filtering
|
|
84
|
+
* although no data will be persisted assuming those properties are backed
|
|
85
|
+
* by functions. If an implementation of getter/setter interface uses a
|
|
86
|
+
* simple data member (of supported type), that will persist.
|
|
87
|
+
*
|
|
88
|
+
* Recursive types without any required modification are preserved intact.
|
|
89
|
+
* Recursive types that require modification are unrolled a limited number of
|
|
90
|
+
* times (currently 4) and then further instances of recursion are replaced with
|
|
91
|
+
* {@link JsonTypeWith|JsonTypeWith<Options.AllowExactly[number] "or" Options.AllowExtensionOf>}.
|
|
92
|
+
*
|
|
93
|
+
* Under basic serialization, class instances become simple data objects that
|
|
94
|
+
* lose hidden properties and prototypes that are required for `instanceof`
|
|
95
|
+
* runtime checks. An exception is made for classes that are intersected with
|
|
96
|
+
* primitive types (specifically `boolean`, `string`, and `number`) under the
|
|
97
|
+
* assumption that such classes are present only as type modifiers (as would
|
|
98
|
+
* be the case for branding) and not as require runtime values.
|
|
99
|
+
*
|
|
100
|
+
* The optional 'Options.AllowExactly' and 'Options.AllowExtensionOf'
|
|
101
|
+
* parameters may be used to permit additional leaf types handled by custom
|
|
102
|
+
* serialization/deserialization logic.
|
|
103
|
+
*
|
|
104
|
+
* @example Example usage
|
|
105
|
+
*
|
|
106
|
+
* ```typescript
|
|
107
|
+
* function foo<T>(): JsonDeserialized<T> { ... }
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @beta
|
|
111
|
+
*/
|
|
112
|
+
export type JsonDeserialized<
|
|
113
|
+
T,
|
|
114
|
+
Options extends JsonDeserializedOptions = {
|
|
115
|
+
AllowExactly: [];
|
|
116
|
+
AllowExtensionOf: never;
|
|
117
|
+
},
|
|
118
|
+
> = InternalUtilityTypes.JsonDeserializedImpl<T, Options>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { InternalUtilityTypes } from "./exposedInternalUtilityTypes.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Options for {@link JsonSerializable}.
|
|
10
|
+
*
|
|
11
|
+
* @beta
|
|
12
|
+
*/
|
|
13
|
+
export interface JsonSerializableOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Tuple of exact types that are managed by custom serialization logic (beyond
|
|
16
|
+
* {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify|JSON.stringify}
|
|
17
|
+
* without a replacer). Only exact types matching specification will be
|
|
18
|
+
* preserved unaltered.
|
|
19
|
+
*
|
|
20
|
+
* The default value is `[]`.
|
|
21
|
+
*/
|
|
22
|
+
AllowExactly?: unknown[];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* General types that are managed by custom serialization logic (beyond
|
|
26
|
+
* {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify|JSON.stringify}
|
|
27
|
+
* without a replacer). Any type satisfying specification will be preserved
|
|
28
|
+
* unaltered.
|
|
29
|
+
*
|
|
30
|
+
* The default value is `never`.
|
|
31
|
+
*/
|
|
32
|
+
AllowExtensionOf?: unknown;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* When set, inaccessible (protected and private) members throughout type T are
|
|
36
|
+
* ignored as if not present.
|
|
37
|
+
*
|
|
38
|
+
* The default value is not present.
|
|
39
|
+
*/
|
|
40
|
+
IgnoreInaccessibleMembers?: "ignore-inaccessible-members";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Used to constrain a type `T` to types that are serializable as JSON
|
|
45
|
+
* using {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify|JSON.stringify}
|
|
46
|
+
* (without a replacer) as base model.
|
|
47
|
+
*
|
|
48
|
+
* Under typical use a compile-time error is produced if `T` contains
|
|
49
|
+
* non-JsonSerializable members.
|
|
50
|
+
*
|
|
51
|
+
* @typeParam T - The type to be constrained.
|
|
52
|
+
* @typeParam Options - Options for the filter. See {@link JsonSerializableOptions}.
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* Before adding use of this utility type, consider using a utility like
|
|
56
|
+
* {@link https://github.com/sinclairzx81/typebox#readme | TypeBox} that allows
|
|
57
|
+
* for runtime validation.
|
|
58
|
+
*
|
|
59
|
+
* Note that this does NOT prevent use of values with non-JSON compatible data,
|
|
60
|
+
* it only prevents using values with types that include non-JSON compatible data.
|
|
61
|
+
* This means that one can, for example, pass in a value typed with JSON compatible
|
|
62
|
+
* interface into this filter, that could actually be a class with lots on non-JSON
|
|
63
|
+
* compatible fields and methods.
|
|
64
|
+
*
|
|
65
|
+
* Important: `T extends JsonSerializable<T>` is incorrect (does not even compile).
|
|
66
|
+
*
|
|
67
|
+
* The optional `Options.Allow*` parameters may be used to permit additional leaf types
|
|
68
|
+
* to support situations where a `replacer` is used to handle special values (e.g.,
|
|
69
|
+
* `JsonSerializable<{ x: IFluidHandle }, { AllowExtensionOf: IFluidHandle }>`).
|
|
70
|
+
*
|
|
71
|
+
* Note that `JsonSerializable<T>` does not protect against the following pitfalls
|
|
72
|
+
* when serializing with JSON.stringify():
|
|
73
|
+
*
|
|
74
|
+
* - Non-finite numbers (`NaN`, `+/-Infinity`) are coerced to `null`.
|
|
75
|
+
*
|
|
76
|
+
* - Prototypes and non-enumerable properties are lost.
|
|
77
|
+
*
|
|
78
|
+
* - `ArrayLike` types that are not arrays and are serialized as `{ length: number }`.
|
|
79
|
+
*
|
|
80
|
+
* - Getter and setters properties are lost. (Though appear supported.)
|
|
81
|
+
*
|
|
82
|
+
* - Functions with properties may be absent or the properties may be preserved
|
|
83
|
+
* depending on the runtime typo of the value. (If built via Object.assign the
|
|
84
|
+
* target member's type is preserved.) typeof =\> 'function' is lost whereas when
|
|
85
|
+
* typeof =\> 'object' the properties are preserved.
|
|
86
|
+
*
|
|
87
|
+
* - Sparse arrays are filled with `null`.
|
|
88
|
+
*
|
|
89
|
+
* Also, `JsonSerializable<T>` does not prevent the construction of circular references.
|
|
90
|
+
*
|
|
91
|
+
* Specifying `JsonSerializable<unknown>` or `JsonSerializable<any>` yields a type
|
|
92
|
+
* alias for {@link JsonTypeWith}`<never>` and should not be used if precise type
|
|
93
|
+
* safety is desired.
|
|
94
|
+
*
|
|
95
|
+
* Class instances are indistinguishable from general objects by type checking
|
|
96
|
+
* unless they have non-public members.
|
|
97
|
+
*
|
|
98
|
+
* - Unless `Option.IgnoreInaccessibleMembers` is used, types with non-public
|
|
99
|
+
* members will result in {@link SerializationErrorPerNonPublicProperties}.
|
|
100
|
+
* When `Option.IgnoreInaccessibleMembers` is `ignore-inaccessible-members`,
|
|
101
|
+
* non-public (non-function) members are preserved without error, but they are
|
|
102
|
+
* filtered away by the type filters and thus produce an incorrectly narrowed
|
|
103
|
+
* type compared to actual data. Though such a result may be customer desired.
|
|
104
|
+
*
|
|
105
|
+
* - An exception is made for classes that are intersected with primitives
|
|
106
|
+
* (specifically `boolean`, `number`, * and `string`). In these cases, it is
|
|
107
|
+
* assumed that the class only exists as a type modifier and not as a value
|
|
108
|
+
* at runtime, and thus the class is permitted as no serialization is required.
|
|
109
|
+
*
|
|
110
|
+
* Perhaps a https://github.com/microsoft/TypeScript/issues/22677 fix will
|
|
111
|
+
* enable better support.
|
|
112
|
+
*
|
|
113
|
+
* @example Typical usage
|
|
114
|
+
*
|
|
115
|
+
* ```typescript
|
|
116
|
+
* function foo<T>(value: JsonSerializable<T>) { ... }
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @privateRemarks
|
|
120
|
+
* Upon recursion, the original type T is preserved intact. This is done to prevent
|
|
121
|
+
* infinite recursion and produces a technically incorrect result type. However, with
|
|
122
|
+
* proper use, that will never be an issue as any filtering of types will happen
|
|
123
|
+
* before T recursion.
|
|
124
|
+
*
|
|
125
|
+
* @beta
|
|
126
|
+
*/
|
|
127
|
+
export type JsonSerializable<
|
|
128
|
+
T,
|
|
129
|
+
Options extends JsonSerializableOptions = {
|
|
130
|
+
AllowExactly: [];
|
|
131
|
+
AllowExtensionOf: never;
|
|
132
|
+
},
|
|
133
|
+
> = InternalUtilityTypes.JsonSerializableImpl<T, Options>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Type resulting from {@link JsonSerializable} use given an array with
|
|
8
|
+
* `undefined` elements.
|
|
9
|
+
*
|
|
10
|
+
* @privateRemarks type is used over interface; so inspection of type
|
|
11
|
+
* result can be more informative than just the type name.
|
|
12
|
+
*
|
|
13
|
+
* @beta
|
|
14
|
+
* @system
|
|
15
|
+
*/
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
17
|
+
export type SerializationErrorPerUndefinedArrayElement = {
|
|
18
|
+
"array serialization error": "undefined elements are not supported";
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Type resulting from {@link JsonSerializable} use given a class with
|
|
23
|
+
* non-public properties.
|
|
24
|
+
*
|
|
25
|
+
* @privateRemarks type is used over interface; so inspection of type
|
|
26
|
+
* result can be more informative than just the type name.
|
|
27
|
+
*
|
|
28
|
+
* @beta
|
|
29
|
+
* @system
|
|
30
|
+
*/
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
32
|
+
export type SerializationErrorPerNonPublicProperties = {
|
|
33
|
+
"object serialization error": "non-public properties are not supported";
|
|
34
|
+
};
|
package/src/jsonType.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Type constraint for types that are likely encodable as JSON, deserializable from JSON,
|
|
8
|
+
* or have a custom alternate type.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Use `JsonTypeWith<never>` for just JSON encodable/deserializable types.
|
|
12
|
+
* See {@link JsonSerializable} for encoding pitfalls.
|
|
13
|
+
*
|
|
14
|
+
* @privateRemarks
|
|
15
|
+
* Prefer using `JsonSerializable<unknown>` or `JsonDeserialized<unknown>` over this type that
|
|
16
|
+
* is an implementation detail.
|
|
17
|
+
*
|
|
18
|
+
* @beta
|
|
19
|
+
*/
|
|
20
|
+
export type JsonTypeWith<T> =
|
|
21
|
+
// eslint-disable-next-line @rushstack/no-new-null
|
|
22
|
+
| null
|
|
23
|
+
| boolean
|
|
24
|
+
| number
|
|
25
|
+
| string
|
|
26
|
+
| T
|
|
27
|
+
| { [key: string | number]: JsonTypeWith<T> }
|
|
28
|
+
| JsonTypeWith<T>[];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Portion of {@link JsonTypeWith} that is an object (including array) and not null.
|
|
32
|
+
*
|
|
33
|
+
* @beta
|
|
34
|
+
*/
|
|
35
|
+
export type NonNullJsonObjectWith<T> =
|
|
36
|
+
| { [key: string | number]: JsonTypeWith<T> }
|
|
37
|
+
| JsonTypeWith<T>[];
|