@fluidframework/core-interfaces 2.62.0 → 2.63.0-359286
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/exposedInternalUtilityTypes.d.ts +6 -1
- package/dist/exposedInternalUtilityTypes.d.ts.map +1 -1
- package/dist/exposedInternalUtilityTypes.js.map +1 -1
- package/dist/internal.d.ts +2 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +4 -0
- package/dist/internal.js.map +1 -1
- package/dist/jsonSerializable.d.ts +10 -2
- package/dist/jsonSerializable.d.ts.map +1 -1
- package/dist/jsonSerializable.js.map +1 -1
- package/dist/jsonString.d.ts +103 -0
- package/dist/jsonString.d.ts.map +1 -0
- package/dist/jsonString.js +30 -0
- package/dist/jsonString.js.map +1 -0
- package/dist/package.json +1 -1
- package/lib/exposedInternalUtilityTypes.d.ts +6 -1
- package/lib/exposedInternalUtilityTypes.d.ts.map +1 -1
- package/lib/exposedInternalUtilityTypes.js.map +1 -1
- package/lib/internal.d.ts +2 -0
- package/lib/internal.d.ts.map +1 -1
- package/lib/internal.js +1 -0
- package/lib/internal.js.map +1 -1
- package/lib/jsonSerializable.d.ts +10 -2
- package/lib/jsonSerializable.d.ts.map +1 -1
- package/lib/jsonSerializable.js.map +1 -1
- package/lib/jsonString.d.ts +103 -0
- package/lib/jsonString.d.ts.map +1 -0
- package/lib/jsonString.js +27 -0
- package/lib/jsonString.js.map +1 -0
- package/package.json +4 -4
- package/src/cjs/package.json +1 -1
- package/src/exposedInternalUtilityTypes.ts +4 -1
- package/src/internal.ts +2 -3
- package/src/jsonSerializable.ts +10 -2
- package/src/jsonString.ts +126 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Performs basic JSON serialization using `JSON.stringify` and brands the result as {@link JsonString}`<T>`.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Parameter `value` must be JSON-serializable and thus type T is put through filter {@link JsonSerializable}.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export const JsonStringify = JSON.stringify;
|
|
14
|
+
/**
|
|
15
|
+
* Performs basic JSON parsing using `JSON.parse` given a {@link JsonString}`<T>` (`string`).
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Return type is filtered through {@link JsonDeserialized}`<T>` for best accuracy.
|
|
19
|
+
*
|
|
20
|
+
* Note that `JsonParse` cannot verify at runtime that the input is valid JSON
|
|
21
|
+
* or that it matches type T. It is the caller's responsibility to ensure that
|
|
22
|
+
* the input is valid JSON and the output conforms to the expected type.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
export const JsonParse = JSON.parse;
|
|
27
|
+
//# sourceMappingURL=jsonString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonString.js","sourceRoot":"","sources":["../src/jsonString.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAyFH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC,SAShB,CAAC;AAEnB;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC,KAEoC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports -- incorrect rule: misunderstands `declare`d types.\nimport type { BrandedType } from \"./brandedType.js\";\nimport type { InternalUtilityTypes } from \"./exposedInternalUtilityTypes.js\";\nimport type { JsonDeserialized } from \"./jsonDeserialized.js\";\nimport type { JsonSerializable, JsonSerializableOptions } from \"./jsonSerializable.js\";\n\n/**\n * Brand for JSON that has been stringified.\n *\n * Usage: Intersect with another type to apply branding.\n *\n * @sealed\n */\ndeclare class JsonStringBrand<T> extends BrandedType<JsonString<unknown>> {\n\tpublic toString(): string;\n\tprotected readonly EncodedValue: T;\n\tprivate constructor();\n}\n\n/**\n * Distributes `JsonStringBrand` over union elements of T.\n *\n * @remarks\n * This is useful to allow `JsonString<A | B>` to be assigned to `JsonString<A> | JsonString<B>`.\n *\n * The downside is that enums are expanded to union of members and thus cannot be\n * reconstituted exactly (even if IntelliSense shows the original enum type). This\n * can be removed if exact enum preservation is found to be more important.\n */\ntype DistributeJsonStringBrand<T> = T extends unknown ? JsonStringBrand<T> : never;\n\n/**\n * Distributes branding over union elements of T unless result could prevent T\n * from being reconstituted (as in the case of an enum type), in which case it\n * falls back to a single JsonStringBrand for the entire T.\n *\n * @remarks\n * Note that an enum unioned with anything else will be distributed. It seems\n * however that TypeScript can/will reconstitute the enum type in that case.\n */\ntype BrandForJsonString<T> = InternalUtilityTypes.IfSameType<\n\tDistributeJsonStringBrand<T> extends JsonStringBrand<infer U> ? U : never,\n\tT,\n\tDistributeJsonStringBrand<T>,\n\tJsonStringBrand<T>\n>;\n\n/**\n * Branded `string` for JSON that has been stringified.\n *\n * @remarks\n *\n * Use {@link JsonStringify} to encode JSON producing values of this type and\n * {@link JsonParse} to decode them.\n *\n * For custom encoding/decoding:\n *\n * - cast to with `as unknown as JsonString<T>` when value of type `T` has been stringified.\n *\n * - use a form of {@link JsonDeserialized} for safety when parsing.\n *\n * @sealed\n * @internal\n */\nexport type JsonString<T> = string & BrandForJsonString<T>;\n\n/**\n * Compile options for {@link JsonStringify}.\n *\n * @remarks\n * This only impacts type checking -- it has no impact on runtime.\n *\n * The options are currently a subset of {@link JsonSerializableOptions}, specifically\n * only `IgnoreInaccessibleMembers` is supported.\n *\n * No instance of this should ever exist at runtime.\n *\n * @privateRemarks\n * Consider adding `AllowUnknown` option to allow precisely `unknown` types to\n * be passed through. With `unknown` expected successful serialization could not\n * be checked at compile time. At deserialization time, `unknown` does not\n * guarantee any type and thus allowing does not erode type safety.\n *\n * @internal\n */\nexport type JsonStringifyOptions = Pick<JsonSerializableOptions, \"IgnoreInaccessibleMembers\">;\n\n/**\n * Performs basic JSON serialization using `JSON.stringify` and brands the result as {@link JsonString}`<T>`.\n *\n * @remarks\n * Parameter `value` must be JSON-serializable and thus type T is put through filter {@link JsonSerializable}.\n *\n * @internal\n */\nexport const JsonStringify = JSON.stringify as <\n\tT,\n\tOptions extends JsonStringifyOptions = Record<never, never>,\n>(\n\tvalue: JsonSerializable<\n\t\tT,\n\t\t// Make sure only options that are known are passed through.\n\t\tPick<Options, Extract<keyof JsonStringifyOptions, keyof Options>>\n\t>,\n) => JsonString<T>;\n\n/**\n * Performs basic JSON parsing using `JSON.parse` given a {@link JsonString}`<T>` (`string`).\n *\n * @remarks\n * Return type is filtered through {@link JsonDeserialized}`<T>` for best accuracy.\n *\n * Note that `JsonParse` cannot verify at runtime that the input is valid JSON\n * or that it matches type T. It is the caller's responsibility to ensure that\n * the input is valid JSON and the output conforms to the expected type.\n *\n * @internal\n */\nexport const JsonParse = JSON.parse as <T extends JsonString<unknown>>(\n\ttext: T,\n) => T extends JsonString<infer U> ? JsonDeserialized<U> : unknown;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/core-interfaces",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.63.0-359286",
|
|
4
4
|
"description": "Fluid object interfaces",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"./internal": {
|
|
37
37
|
"import": {
|
|
38
38
|
"types": "./lib/internal.d.ts",
|
|
39
|
-
"default": "./lib/
|
|
39
|
+
"default": "./lib/internal.js"
|
|
40
40
|
},
|
|
41
41
|
"require": {
|
|
42
42
|
"types": "./dist/internal.d.ts",
|
|
43
|
-
"default": "./dist/
|
|
43
|
+
"default": "./dist/internal.js"
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"./internal/exposedUtilityTypes": {
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"@fluid-tools/build-cli": "^0.58.3",
|
|
77
77
|
"@fluidframework/build-common": "^2.0.3",
|
|
78
78
|
"@fluidframework/build-tools": "^0.58.3",
|
|
79
|
-
"@fluidframework/core-interfaces-previous": "npm:@fluidframework/core-interfaces@2.
|
|
79
|
+
"@fluidframework/core-interfaces-previous": "npm:@fluidframework/core-interfaces@2.62.0",
|
|
80
80
|
"@fluidframework/eslint-config-fluid": "^6.0.0",
|
|
81
81
|
"@microsoft/api-extractor": "7.52.11",
|
|
82
82
|
"@types/mocha": "^10.0.10",
|
package/src/cjs/package.json
CHANGED
|
@@ -871,6 +871,9 @@ export namespace InternalUtilityTypes {
|
|
|
871
871
|
export type JsonSerializableImpl<
|
|
872
872
|
T,
|
|
873
873
|
Options extends Partial<FilterControls> & {
|
|
874
|
+
/**
|
|
875
|
+
* See {@link JsonSerializableOptions} for meaning and expected use.
|
|
876
|
+
*/
|
|
874
877
|
IgnoreInaccessibleMembers?: "ignore-inaccessible-members";
|
|
875
878
|
},
|
|
876
879
|
TAncestorTypes extends unknown[] = [],
|
|
@@ -903,7 +906,7 @@ export namespace InternalUtilityTypes {
|
|
|
903
906
|
Controls extends FilterControlsWithSubstitution
|
|
904
907
|
? /* test for 'any' */ boolean extends (T extends never ? true : false)
|
|
905
908
|
? /* 'any' => */ Controls["DegenerateSubstitute"]
|
|
906
|
-
: Options
|
|
909
|
+
: Options extends { IgnoreInaccessibleMembers: "ignore-inaccessible-members" }
|
|
907
910
|
? JsonSerializableFilter<T, Controls, TAncestorTypes, TNextAncestor>
|
|
908
911
|
: /* test for non-public properties (class instance type) */
|
|
909
912
|
IfNonPublicProperties<
|
package/src/internal.ts
CHANGED
|
@@ -7,9 +7,8 @@
|
|
|
7
7
|
// eslint-disable-next-line no-restricted-syntax, @typescript-eslint/no-restricted-imports
|
|
8
8
|
export * from "./index.js";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// using the same outer runtime file. (Could be changed if needed.)
|
|
10
|
+
export type { JsonString, JsonStringifyOptions } from "./jsonString.js";
|
|
11
|
+
export { JsonStringify, JsonParse } from "./jsonString.js";
|
|
13
12
|
|
|
14
13
|
export type { JsonTypeToOpaqueJson, OpaqueJsonToJsonType } from "./jsonUtils.js";
|
|
15
14
|
|
package/src/jsonSerializable.ts
CHANGED
|
@@ -33,9 +33,17 @@ export interface JsonSerializableOptions {
|
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* When set, inaccessible (protected and private) members throughout type T are
|
|
36
|
-
* ignored as if not present.
|
|
36
|
+
* ignored as if not present. Otherwise, inaccessible members are considered
|
|
37
|
+
* an error (type checking will mention `SerializationErrorPerNonPublicProperties`).
|
|
37
38
|
*
|
|
38
|
-
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* For this option to be set and accurately filter inaccessible members, all
|
|
41
|
+
* inaccessible members (if any) must be either inherited, symbol keyed, or
|
|
42
|
+
* non-enumerable.
|
|
43
|
+
*
|
|
44
|
+
* The default is that `IgnoreInaccessibleMembers` property is not specified,
|
|
45
|
+
* which means that inaccessible members are considered an error, even if
|
|
46
|
+
* they would not be serialized at runtime.
|
|
39
47
|
*/
|
|
40
48
|
IgnoreInaccessibleMembers?: "ignore-inaccessible-members";
|
|
41
49
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports -- incorrect rule: misunderstands `declare`d types.
|
|
7
|
+
import type { BrandedType } from "./brandedType.js";
|
|
8
|
+
import type { InternalUtilityTypes } from "./exposedInternalUtilityTypes.js";
|
|
9
|
+
import type { JsonDeserialized } from "./jsonDeserialized.js";
|
|
10
|
+
import type { JsonSerializable, JsonSerializableOptions } from "./jsonSerializable.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Brand for JSON that has been stringified.
|
|
14
|
+
*
|
|
15
|
+
* Usage: Intersect with another type to apply branding.
|
|
16
|
+
*
|
|
17
|
+
* @sealed
|
|
18
|
+
*/
|
|
19
|
+
declare class JsonStringBrand<T> extends BrandedType<JsonString<unknown>> {
|
|
20
|
+
public toString(): string;
|
|
21
|
+
protected readonly EncodedValue: T;
|
|
22
|
+
private constructor();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Distributes `JsonStringBrand` over union elements of T.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* This is useful to allow `JsonString<A | B>` to be assigned to `JsonString<A> | JsonString<B>`.
|
|
30
|
+
*
|
|
31
|
+
* The downside is that enums are expanded to union of members and thus cannot be
|
|
32
|
+
* reconstituted exactly (even if IntelliSense shows the original enum type). This
|
|
33
|
+
* can be removed if exact enum preservation is found to be more important.
|
|
34
|
+
*/
|
|
35
|
+
type DistributeJsonStringBrand<T> = T extends unknown ? JsonStringBrand<T> : never;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Distributes branding over union elements of T unless result could prevent T
|
|
39
|
+
* from being reconstituted (as in the case of an enum type), in which case it
|
|
40
|
+
* falls back to a single JsonStringBrand for the entire T.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* Note that an enum unioned with anything else will be distributed. It seems
|
|
44
|
+
* however that TypeScript can/will reconstitute the enum type in that case.
|
|
45
|
+
*/
|
|
46
|
+
type BrandForJsonString<T> = InternalUtilityTypes.IfSameType<
|
|
47
|
+
DistributeJsonStringBrand<T> extends JsonStringBrand<infer U> ? U : never,
|
|
48
|
+
T,
|
|
49
|
+
DistributeJsonStringBrand<T>,
|
|
50
|
+
JsonStringBrand<T>
|
|
51
|
+
>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Branded `string` for JSON that has been stringified.
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
*
|
|
58
|
+
* Use {@link JsonStringify} to encode JSON producing values of this type and
|
|
59
|
+
* {@link JsonParse} to decode them.
|
|
60
|
+
*
|
|
61
|
+
* For custom encoding/decoding:
|
|
62
|
+
*
|
|
63
|
+
* - cast to with `as unknown as JsonString<T>` when value of type `T` has been stringified.
|
|
64
|
+
*
|
|
65
|
+
* - use a form of {@link JsonDeserialized} for safety when parsing.
|
|
66
|
+
*
|
|
67
|
+
* @sealed
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
export type JsonString<T> = string & BrandForJsonString<T>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Compile options for {@link JsonStringify}.
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* This only impacts type checking -- it has no impact on runtime.
|
|
77
|
+
*
|
|
78
|
+
* The options are currently a subset of {@link JsonSerializableOptions}, specifically
|
|
79
|
+
* only `IgnoreInaccessibleMembers` is supported.
|
|
80
|
+
*
|
|
81
|
+
* No instance of this should ever exist at runtime.
|
|
82
|
+
*
|
|
83
|
+
* @privateRemarks
|
|
84
|
+
* Consider adding `AllowUnknown` option to allow precisely `unknown` types to
|
|
85
|
+
* be passed through. With `unknown` expected successful serialization could not
|
|
86
|
+
* be checked at compile time. At deserialization time, `unknown` does not
|
|
87
|
+
* guarantee any type and thus allowing does not erode type safety.
|
|
88
|
+
*
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
export type JsonStringifyOptions = Pick<JsonSerializableOptions, "IgnoreInaccessibleMembers">;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Performs basic JSON serialization using `JSON.stringify` and brands the result as {@link JsonString}`<T>`.
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
* Parameter `value` must be JSON-serializable and thus type T is put through filter {@link JsonSerializable}.
|
|
98
|
+
*
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
export const JsonStringify = JSON.stringify as <
|
|
102
|
+
T,
|
|
103
|
+
Options extends JsonStringifyOptions = Record<never, never>,
|
|
104
|
+
>(
|
|
105
|
+
value: JsonSerializable<
|
|
106
|
+
T,
|
|
107
|
+
// Make sure only options that are known are passed through.
|
|
108
|
+
Pick<Options, Extract<keyof JsonStringifyOptions, keyof Options>>
|
|
109
|
+
>,
|
|
110
|
+
) => JsonString<T>;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Performs basic JSON parsing using `JSON.parse` given a {@link JsonString}`<T>` (`string`).
|
|
114
|
+
*
|
|
115
|
+
* @remarks
|
|
116
|
+
* Return type is filtered through {@link JsonDeserialized}`<T>` for best accuracy.
|
|
117
|
+
*
|
|
118
|
+
* Note that `JsonParse` cannot verify at runtime that the input is valid JSON
|
|
119
|
+
* or that it matches type T. It is the caller's responsibility to ensure that
|
|
120
|
+
* the input is valid JSON and the output conforms to the expected type.
|
|
121
|
+
*
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
export const JsonParse = JSON.parse as <T extends JsonString<unknown>>(
|
|
125
|
+
text: T,
|
|
126
|
+
) => T extends JsonString<infer U> ? JsonDeserialized<U> : unknown;
|