@fluidframework/core-interfaces 2.41.0-338401 → 2.42.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/CHANGELOG.md +8 -0
- package/api-report/core-interfaces.legacy.alpha.api.md +6 -0
- package/dist/brandedType.d.ts +41 -0
- package/dist/brandedType.d.ts.map +1 -0
- package/dist/brandedType.js +7 -0
- package/dist/brandedType.js.map +1 -0
- package/dist/exposedInternalUtilityTypes.d.ts +64 -6
- package/dist/exposedInternalUtilityTypes.d.ts.map +1 -1
- package/dist/exposedInternalUtilityTypes.js.map +1 -1
- package/dist/exposedUtilityTypes.d.ts +1 -0
- package/dist/exposedUtilityTypes.d.ts.map +1 -1
- package/dist/exposedUtilityTypes.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +11 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/jsonSerializable.d.ts +2 -2
- package/dist/jsonSerializable.js.map +1 -1
- package/dist/jsonUtils.d.ts +70 -0
- package/dist/jsonUtils.d.ts.map +1 -0
- package/dist/jsonUtils.js +7 -0
- package/dist/jsonUtils.js.map +1 -0
- package/dist/legacy.d.ts +2 -1
- package/dist/messages.d.ts +22 -5
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js.map +1 -1
- package/dist/opaqueJson.d.ts +60 -0
- package/dist/opaqueJson.d.ts.map +1 -0
- package/dist/opaqueJson.js +8 -0
- package/dist/opaqueJson.js.map +1 -0
- package/lib/brandedType.d.ts +41 -0
- package/lib/brandedType.d.ts.map +1 -0
- package/lib/brandedType.js +6 -0
- package/lib/brandedType.js.map +1 -0
- package/lib/exposedInternalUtilityTypes.d.ts +64 -6
- package/lib/exposedInternalUtilityTypes.d.ts.map +1 -1
- package/lib/exposedInternalUtilityTypes.js.map +1 -1
- package/lib/exposedUtilityTypes.d.ts +1 -0
- package/lib/exposedUtilityTypes.d.ts.map +1 -1
- package/lib/exposedUtilityTypes.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/internal.d.ts +11 -0
- package/lib/internal.d.ts.map +1 -1
- package/lib/internal.js.map +1 -1
- package/lib/jsonSerializable.d.ts +2 -2
- package/lib/jsonSerializable.js.map +1 -1
- package/lib/jsonUtils.d.ts +70 -0
- package/lib/jsonUtils.d.ts.map +1 -0
- package/lib/jsonUtils.js +6 -0
- package/lib/jsonUtils.js.map +1 -0
- package/lib/legacy.d.ts +2 -1
- package/lib/messages.d.ts +22 -5
- package/lib/messages.d.ts.map +1 -1
- package/lib/messages.js.map +1 -1
- package/lib/opaqueJson.d.ts +60 -0
- package/lib/opaqueJson.d.ts.map +1 -0
- package/lib/opaqueJson.js +6 -0
- package/lib/opaqueJson.js.map +1 -0
- package/package.json +3 -3
- package/src/brandedType.ts +43 -0
- package/src/exposedInternalUtilityTypes.ts +200 -87
- package/src/exposedUtilityTypes.ts +1 -0
- package/src/index.ts +3 -1
- package/src/internal.ts +26 -0
- package/src/jsonSerializable.ts +2 -2
- package/src/jsonUtils.ts +90 -0
- package/src/messages.ts +24 -6
- package/src/opaqueJson.ts +87 -0
package/src/internal.ts
CHANGED
|
@@ -10,6 +10,8 @@ export * from "./index.js";
|
|
|
10
10
|
// index.js is listed as the runtime file. This is done so that all imports are
|
|
11
11
|
// using the same outer runtime file. (Could be changed if needed.)
|
|
12
12
|
|
|
13
|
+
export type { JsonTypeToOpaqueJson, OpaqueJsonToJsonType } from "./jsonUtils.js";
|
|
14
|
+
|
|
13
15
|
// Export set of utility types re-tagged as internal for FF client convenience.
|
|
14
16
|
// These types are not intended for direct use by customers and api-extractor will
|
|
15
17
|
// flag misuse. If an externally visible version of these types is needed, import
|
|
@@ -28,6 +30,10 @@ import type {
|
|
|
28
30
|
JsonTypeWith as ExposedJsonTypeWith,
|
|
29
31
|
ReadonlyNonNullJsonObjectWith as ExposedReadonlyNonNullJsonObjectWith,
|
|
30
32
|
} from "./jsonType.js";
|
|
33
|
+
import type {
|
|
34
|
+
OpaqueJsonDeserialized as ExposedOpaqueJsonDeserialized,
|
|
35
|
+
OpaqueJsonSerializable as ExposedOpaqueJsonSerializable,
|
|
36
|
+
} from "./opaqueJson.js";
|
|
31
37
|
|
|
32
38
|
// Note: There are no docs for these re-exports. `@inheritdoc` cannot be used as:
|
|
33
39
|
// 1. api-extractor does not support renames.
|
|
@@ -71,12 +77,32 @@ export type JsonTypeWith<T> = ExposedJsonTypeWith<T>;
|
|
|
71
77
|
*/
|
|
72
78
|
export type ReadonlyNonNullJsonObjectWith<T> = ExposedReadonlyNonNullJsonObjectWith<T>;
|
|
73
79
|
|
|
80
|
+
/**
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
export type OpaqueJsonDeserialized<
|
|
84
|
+
T,
|
|
85
|
+
Option_AllowExactly extends unknown[] = [],
|
|
86
|
+
Option_AllowExtensionOf = never,
|
|
87
|
+
> = ExposedOpaqueJsonDeserialized<T, Option_AllowExactly, Option_AllowExtensionOf>;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
export type OpaqueJsonSerializable<
|
|
93
|
+
T,
|
|
94
|
+
Option_AllowExactly extends unknown[] = [],
|
|
95
|
+
Option_AllowExtensionOf = never,
|
|
96
|
+
> = ExposedOpaqueJsonSerializable<T, Option_AllowExactly, Option_AllowExtensionOf>;
|
|
97
|
+
|
|
74
98
|
/**
|
|
75
99
|
* @internal
|
|
76
100
|
*/
|
|
77
101
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
78
102
|
export namespace InternalUtilityTypes {
|
|
79
103
|
/* eslint-disable jsdoc/require-jsdoc */
|
|
104
|
+
export type FlattenIntersection<T extends ExposedInternalUtilityTypes.AnyRecord> =
|
|
105
|
+
ExposedInternalUtilityTypes.FlattenIntersection<T>;
|
|
80
106
|
export type IfSameType<
|
|
81
107
|
X,
|
|
82
108
|
Y,
|
package/src/jsonSerializable.ts
CHANGED
|
@@ -89,8 +89,8 @@ export interface JsonSerializableOptions {
|
|
|
89
89
|
* Also, `JsonSerializable<T>` does not prevent the construction of circular references.
|
|
90
90
|
*
|
|
91
91
|
* Specifying `JsonSerializable<unknown>` or `JsonSerializable<any>` yields a type
|
|
92
|
-
* alias for {@link JsonTypeWith}`<never>`
|
|
93
|
-
* safety is desired.
|
|
92
|
+
* alias for {@link JsonTypeWith}`<never>` | {@link OpaqueJsonSerializable}`<unknown>`
|
|
93
|
+
* and should not be used if precise type safety is desired.
|
|
94
94
|
*
|
|
95
95
|
* Class instances are indistinguishable from general objects by type checking
|
|
96
96
|
* unless they have non-public members.
|
package/src/jsonUtils.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { JsonDeserialized } from "./jsonDeserialized.js";
|
|
7
|
+
import type { JsonSerializable, JsonSerializableOptions } from "./jsonSerializable.js";
|
|
8
|
+
import type { OpaqueJsonDeserialized, OpaqueJsonSerializable } from "./opaqueJson.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Helper to return an Opaque Json type version of Json type
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* To use this helper, create a helper function that filters type `T` through at
|
|
15
|
+
* least {@link JsonSerializable} and optionally {@link JsonDeserialized}. Then
|
|
16
|
+
* cast value through `unknown as JsonTypeToOpaqueJson<T, Options>`, where
|
|
17
|
+
* `Options` reflects the serialization capabilities of that area.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* function castToOpaqueJson<T>(value: JsonSerializable<T>): JsonTypeToOpaqueJson<T> {
|
|
22
|
+
* return value as unknown as JsonTypeToOpaqueJson<T>;
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export type JsonTypeToOpaqueJson<
|
|
29
|
+
T,
|
|
30
|
+
Options extends JsonSerializableOptions = {
|
|
31
|
+
AllowExactly: [];
|
|
32
|
+
AllowExtensionOf: never;
|
|
33
|
+
},
|
|
34
|
+
> = T extends JsonSerializable<T, Options> & JsonDeserialized<T, Options>
|
|
35
|
+
? OpaqueJsonSerializable<
|
|
36
|
+
T,
|
|
37
|
+
Options extends { AllowExactly: unknown[] } ? Options["AllowExactly"] : [],
|
|
38
|
+
Options extends { AllowExtensionOf: unknown } ? Options["AllowExtensionOf"] : never
|
|
39
|
+
> &
|
|
40
|
+
OpaqueJsonDeserialized<
|
|
41
|
+
T,
|
|
42
|
+
Options extends { AllowExactly: unknown[] } ? Options["AllowExactly"] : [],
|
|
43
|
+
Options extends { AllowExtensionOf: unknown } ? Options["AllowExtensionOf"] : never
|
|
44
|
+
>
|
|
45
|
+
: T extends JsonDeserialized<T, Options>
|
|
46
|
+
? OpaqueJsonDeserialized<
|
|
47
|
+
T,
|
|
48
|
+
Options extends { AllowExactly: unknown[] } ? Options["AllowExactly"] : [],
|
|
49
|
+
Options extends { AllowExtensionOf: unknown } ? Options["AllowExtensionOf"] : never
|
|
50
|
+
>
|
|
51
|
+
: T extends JsonSerializable<T, Options>
|
|
52
|
+
? OpaqueJsonSerializable<
|
|
53
|
+
T,
|
|
54
|
+
Options extends { AllowExactly: unknown[] } ? Options["AllowExactly"] : [],
|
|
55
|
+
Options extends { AllowExtensionOf: unknown } ? Options["AllowExtensionOf"] : never
|
|
56
|
+
>
|
|
57
|
+
: never;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Helper to extract Json type from an Opaque Json type
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* This type only works with basic serialization capabilities (options).
|
|
64
|
+
* Attempts to make `Options` generic resulted in infinite recursion
|
|
65
|
+
* in TypeScript compiler that was not understood, so this type only
|
|
66
|
+
* supports TJson (value type) variance.
|
|
67
|
+
*
|
|
68
|
+
* To use this helper, create a helper function that accepts
|
|
69
|
+
* `OpaqueJsonSerializable<unknown> | OpaqueJsonDeserialized<unknown>`.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* function exposeFromOpaqueJson<TOpaque extends OpaqueJsonSerializable<unknown> | OpaqueJsonDeserialized<unknown>>(
|
|
74
|
+
* opaque: TOpaque,
|
|
75
|
+
* ): OpaqueJsonToJsonType<TOpaque> {
|
|
76
|
+
* return opaque as unknown as OpaqueJsonToJsonType<TOpaque>;
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
export type OpaqueJsonToJsonType<
|
|
83
|
+
TOpaque extends OpaqueJsonSerializable<unknown> | OpaqueJsonDeserialized<unknown>,
|
|
84
|
+
> = TOpaque extends OpaqueJsonSerializable<infer TJson> & OpaqueJsonDeserialized<infer TJson>
|
|
85
|
+
? JsonSerializable<TJson> & JsonDeserialized<TJson>
|
|
86
|
+
: TOpaque extends OpaqueJsonDeserialized<infer TJson>
|
|
87
|
+
? JsonDeserialized<TJson>
|
|
88
|
+
: TOpaque extends OpaqueJsonSerializable<infer TJson>
|
|
89
|
+
? JsonSerializable<TJson>
|
|
90
|
+
: never;
|
package/src/messages.ts
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* A message that has a string `type` associated with `content`.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This type is meant to be used indirectly. Most commonly as a constraint
|
|
11
|
+
* for generics of message structures.
|
|
12
|
+
*
|
|
13
|
+
* @legacy
|
|
14
|
+
* @alpha
|
|
15
|
+
*/
|
|
16
|
+
export interface TypedMessage {
|
|
17
|
+
/**
|
|
18
|
+
* The type of the message.
|
|
19
|
+
*/
|
|
20
|
+
type: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The contents of the message.
|
|
24
|
+
*/
|
|
25
|
+
content: unknown;
|
|
26
|
+
}
|
|
27
|
+
|
|
6
28
|
/**
|
|
7
29
|
* @internal
|
|
8
30
|
*
|
|
@@ -13,7 +35,7 @@
|
|
|
13
35
|
*
|
|
14
36
|
* See at `server/routerlicious/packages/lambdas/src/utils/messageGenerator.ts`.
|
|
15
37
|
*/
|
|
16
|
-
export interface ISignalEnvelope {
|
|
38
|
+
export interface ISignalEnvelope<TMessage extends TypedMessage = TypedMessage> {
|
|
17
39
|
/**
|
|
18
40
|
* The target for the envelope, undefined for the container
|
|
19
41
|
*/
|
|
@@ -27,9 +49,5 @@ export interface ISignalEnvelope {
|
|
|
27
49
|
/**
|
|
28
50
|
* The contents of the envelope
|
|
29
51
|
*/
|
|
30
|
-
contents:
|
|
31
|
-
type: string;
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
-
content: any;
|
|
34
|
-
};
|
|
52
|
+
contents: TMessage;
|
|
35
53
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { BrandedType } from "./brandedType.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Placeholder for value that is known to be JSON because it has been
|
|
10
|
+
* deserialized (`T` filtered through {@link JsonDeserialized} as out value).
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Usage:
|
|
14
|
+
*
|
|
15
|
+
* - Cast to with `as unknown as OpaqueJsonDeserialized<T>` when value `T`
|
|
16
|
+
* has been filtered through {@link JsonDeserialized}.
|
|
17
|
+
*
|
|
18
|
+
* - Cast from with `as unknown as JsonDeserialized<T>` when "instance" will
|
|
19
|
+
* be read.
|
|
20
|
+
*
|
|
21
|
+
* @sealed
|
|
22
|
+
* @beta
|
|
23
|
+
*/
|
|
24
|
+
export declare class OpaqueJsonDeserialized<
|
|
25
|
+
T,
|
|
26
|
+
// These options are split from typical `JsonDeserializedOptions` as this type
|
|
27
|
+
// requires correct variance per the two options and AllowExactly has special
|
|
28
|
+
// variance and must be treated as invariant. In actuality, each member of the
|
|
29
|
+
// AllowExactly tuple is invariant, but tuple as a set is covariant. This is not
|
|
30
|
+
// expressible in TypeScript.
|
|
31
|
+
in out Option_AllowExactly extends unknown[] = [],
|
|
32
|
+
out Option_AllowExtensionOf = never,
|
|
33
|
+
> extends BrandedType<"JsonDeserialized"> {
|
|
34
|
+
protected readonly JsonDeserialized: {
|
|
35
|
+
Type: T;
|
|
36
|
+
Options: {
|
|
37
|
+
AllowExactly: Option_AllowExactly;
|
|
38
|
+
AllowExtensionOf: Option_AllowExtensionOf;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
// Option_AllowExactly is covariant from above. This removes covariance, leaving only invariance.
|
|
42
|
+
protected readonly Option_AllowExactly_Invariance: (
|
|
43
|
+
Option_AllowExactly: Option_AllowExactly,
|
|
44
|
+
) => void;
|
|
45
|
+
private constructor();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Placeholder for value that is known to be JSON because it will have been
|
|
50
|
+
* serialized checked (`T` filtered through {@link JsonSerializable} before "created").
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* Usage:
|
|
54
|
+
*
|
|
55
|
+
* - Cast to with `as unknown as OpaqueJsonSerializable<T>` when value `T`
|
|
56
|
+
* has been filtered through {@link JsonSerializable}.
|
|
57
|
+
*
|
|
58
|
+
* - Cast from with `as unknown as JsonSerializable<T>` or `as unknown as T`
|
|
59
|
+
* when "instance" will be forwarded along.
|
|
60
|
+
*
|
|
61
|
+
* @sealed
|
|
62
|
+
* @beta
|
|
63
|
+
*/
|
|
64
|
+
export declare class OpaqueJsonSerializable<
|
|
65
|
+
T,
|
|
66
|
+
// These options are split from typical `JsonSerializableOptions` as this type
|
|
67
|
+
// requires correct variance per the two options and AllowExactly has special
|
|
68
|
+
// variance and must be treated as invariant. In actuality, each member of the
|
|
69
|
+
// AllowExactly tuple is invariant, but tuple as a set is covariant. This is not
|
|
70
|
+
// expressible in TypeScript.
|
|
71
|
+
in out Option_AllowExactly extends unknown[] = [],
|
|
72
|
+
out Option_AllowExtensionOf = never,
|
|
73
|
+
// JsonSerializableOptions.IgnoreInaccessibleMembers is ignored
|
|
74
|
+
> extends BrandedType<"JsonSerializable"> {
|
|
75
|
+
protected readonly JsonSerializable: {
|
|
76
|
+
Type: T;
|
|
77
|
+
Options: {
|
|
78
|
+
AllowExactly: Option_AllowExactly;
|
|
79
|
+
AllowExtensionOf: Option_AllowExtensionOf;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
// Option_AllowExactly is covariant from above. This removes covariance, leaving only invariance.
|
|
83
|
+
protected readonly Option_AllowExactly_Invariance: (
|
|
84
|
+
Option_AllowExactly: Option_AllowExactly,
|
|
85
|
+
) => void;
|
|
86
|
+
private constructor();
|
|
87
|
+
}
|