@fluidframework/legacy-dds 2.50.0-345060
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 +11 -0
- package/.mocharc.cjs +12 -0
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/api-extractor/api-extractor-lint-bundle.json +5 -0
- package/api-extractor/api-extractor-lint-legacy.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-legacy.esm.json +5 -0
- package/api-extractor/api-extractor-lint-public.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-public.esm.json +5 -0
- package/api-extractor/api-extractor.current.json +5 -0
- package/api-extractor/api-extractor.legacy.json +4 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +4 -0
- package/api-report/legacy-dds.beta.api.md +9 -0
- package/api-report/legacy-dds.legacy.alpha.api.md +140 -0
- package/api-report/legacy-dds.legacy.public.api.md +9 -0
- package/api-report/legacy-dds.public.api.md +9 -0
- package/biome.jsonc +4 -0
- package/dist/array/index.d.ts +10 -0
- package/dist/array/index.d.ts.map +1 -0
- package/dist/array/index.js +16 -0
- package/dist/array/index.js.map +1 -0
- package/dist/array/interfaces.d.ts +142 -0
- package/dist/array/interfaces.d.ts.map +1 -0
- package/dist/array/interfaces.js +7 -0
- package/dist/array/interfaces.js.map +1 -0
- package/dist/array/sharedArray.d.ts +175 -0
- package/dist/array/sharedArray.d.ts.map +1 -0
- package/dist/array/sharedArray.js +652 -0
- package/dist/array/sharedArray.js.map +1 -0
- package/dist/array/sharedArrayFactory.d.ts +31 -0
- package/dist/array/sharedArrayFactory.d.ts.map +1 -0
- package/dist/array/sharedArrayFactory.js +61 -0
- package/dist/array/sharedArrayFactory.js.map +1 -0
- package/dist/array/sharedArrayOperations.d.ts +77 -0
- package/dist/array/sharedArrayOperations.d.ts.map +1 -0
- package/dist/array/sharedArrayOperations.js +19 -0
- package/dist/array/sharedArrayOperations.js.map +1 -0
- package/dist/array/sharedArrayRevertible.d.ts +17 -0
- package/dist/array/sharedArrayRevertible.d.ts.map +1 -0
- package/dist/array/sharedArrayRevertible.js +47 -0
- package/dist/array/sharedArrayRevertible.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/legacy.d.ts +31 -0
- package/dist/package.json +4 -0
- package/dist/packageVersion.d.ts +9 -0
- package/dist/packageVersion.d.ts.map +1 -0
- package/dist/packageVersion.js +12 -0
- package/dist/packageVersion.js.map +1 -0
- package/dist/public.d.ts +12 -0
- package/dist/signal/index.d.ts +7 -0
- package/dist/signal/index.d.ts.map +1 -0
- package/dist/signal/index.js +11 -0
- package/dist/signal/index.js.map +1 -0
- package/dist/signal/interfaces.d.ts +36 -0
- package/dist/signal/interfaces.d.ts.map +1 -0
- package/dist/signal/interfaces.js +7 -0
- package/dist/signal/interfaces.js.map +1 -0
- package/dist/signal/sharedSignal.d.ts +68 -0
- package/dist/signal/sharedSignal.d.ts.map +1 -0
- package/dist/signal/sharedSignal.js +122 -0
- package/dist/signal/sharedSignal.js.map +1 -0
- package/dist/signal/sharedSignalFactory.d.ts +24 -0
- package/dist/signal/sharedSignalFactory.d.ts.map +1 -0
- package/dist/signal/sharedSignalFactory.js +45 -0
- package/dist/signal/sharedSignalFactory.js.map +1 -0
- package/internal.d.ts +11 -0
- package/legacy.d.ts +11 -0
- package/lib/array/index.d.ts +10 -0
- package/lib/array/index.d.ts.map +1 -0
- package/lib/array/index.js +8 -0
- package/lib/array/index.js.map +1 -0
- package/lib/array/interfaces.d.ts +142 -0
- package/lib/array/interfaces.d.ts.map +1 -0
- package/lib/array/interfaces.js +6 -0
- package/lib/array/interfaces.js.map +1 -0
- package/lib/array/sharedArray.d.ts +175 -0
- package/lib/array/sharedArray.d.ts.map +1 -0
- package/lib/array/sharedArray.js +648 -0
- package/lib/array/sharedArray.js.map +1 -0
- package/lib/array/sharedArrayFactory.d.ts +31 -0
- package/lib/array/sharedArrayFactory.d.ts.map +1 -0
- package/lib/array/sharedArrayFactory.js +56 -0
- package/lib/array/sharedArrayFactory.js.map +1 -0
- package/lib/array/sharedArrayOperations.d.ts +77 -0
- package/lib/array/sharedArrayOperations.d.ts.map +1 -0
- package/lib/array/sharedArrayOperations.js +16 -0
- package/lib/array/sharedArrayOperations.js.map +1 -0
- package/lib/array/sharedArrayRevertible.d.ts +17 -0
- package/lib/array/sharedArrayRevertible.d.ts.map +1 -0
- package/lib/array/sharedArrayRevertible.js +43 -0
- package/lib/array/sharedArrayRevertible.js.map +1 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -0
- package/lib/legacy.d.ts +31 -0
- package/lib/packageVersion.d.ts +9 -0
- package/lib/packageVersion.d.ts.map +1 -0
- package/lib/packageVersion.js +9 -0
- package/lib/packageVersion.js.map +1 -0
- package/lib/public.d.ts +12 -0
- package/lib/signal/index.d.ts +7 -0
- package/lib/signal/index.d.ts.map +1 -0
- package/lib/signal/index.js +6 -0
- package/lib/signal/index.js.map +1 -0
- package/lib/signal/interfaces.d.ts +36 -0
- package/lib/signal/interfaces.d.ts.map +1 -0
- package/lib/signal/interfaces.js +6 -0
- package/lib/signal/interfaces.js.map +1 -0
- package/lib/signal/sharedSignal.d.ts +68 -0
- package/lib/signal/sharedSignal.d.ts.map +1 -0
- package/lib/signal/sharedSignal.js +118 -0
- package/lib/signal/sharedSignal.js.map +1 -0
- package/lib/signal/sharedSignalFactory.d.ts +24 -0
- package/lib/signal/sharedSignalFactory.d.ts.map +1 -0
- package/lib/signal/sharedSignalFactory.js +41 -0
- package/lib/signal/sharedSignalFactory.js.map +1 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/package.json +158 -0
- package/src/array/README.md +32 -0
- package/src/array/index.ts +28 -0
- package/src/array/interfaces.ts +169 -0
- package/src/array/sharedArray.ts +835 -0
- package/src/array/sharedArrayFactory.ts +88 -0
- package/src/array/sharedArrayOperations.ts +89 -0
- package/src/array/sharedArrayRevertible.ts +50 -0
- package/src/index.ts +32 -0
- package/src/packageVersion.ts +9 -0
- package/src/signal/README.md +25 -0
- package/src/signal/index.ts +12 -0
- package/src/signal/interfaces.ts +53 -0
- package/src/signal/sharedSignal.ts +169 -0
- package/src/signal/sharedSignalFactory.ts +62 -0
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.json +10 -0
- package/tsdoc.json +4 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
IChannelServices,
|
|
8
|
+
IChannelAttributes,
|
|
9
|
+
IFluidDataStoreRuntime,
|
|
10
|
+
IChannelFactory,
|
|
11
|
+
} from "@fluidframework/datastore-definitions/internal";
|
|
12
|
+
import {
|
|
13
|
+
createSharedObjectKind,
|
|
14
|
+
type ISharedObjectKind,
|
|
15
|
+
type SharedObjectKind,
|
|
16
|
+
} from "@fluidframework/shared-object-base/internal";
|
|
17
|
+
|
|
18
|
+
import { pkgVersion } from "../packageVersion.js";
|
|
19
|
+
|
|
20
|
+
import type { ISharedArray, SerializableTypeForSharedArray } from "./interfaces.js";
|
|
21
|
+
import { SharedArrayClass } from "./sharedArray.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
export class SharedArrayFactory<T extends SerializableTypeForSharedArray>
|
|
27
|
+
implements IChannelFactory
|
|
28
|
+
{
|
|
29
|
+
public static readonly Type = "https://graph.microsoft.com/types/SharedArray";
|
|
30
|
+
|
|
31
|
+
public static readonly Attributes: IChannelAttributes = {
|
|
32
|
+
type: SharedArrayFactory.Type,
|
|
33
|
+
snapshotFormatVersion: "0.1",
|
|
34
|
+
packageVersion: pkgVersion,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
public get type(): string {
|
|
38
|
+
return SharedArrayFactory.Type;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public get attributes(): IChannelAttributes {
|
|
42
|
+
return SharedArrayFactory.Attributes;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public async load(
|
|
46
|
+
runtime: IFluidDataStoreRuntime,
|
|
47
|
+
id: string,
|
|
48
|
+
services: IChannelServices,
|
|
49
|
+
attributes: IChannelAttributes,
|
|
50
|
+
): Promise<ISharedArray<T>> {
|
|
51
|
+
/**
|
|
52
|
+
* * The SharedArray
|
|
53
|
+
*/
|
|
54
|
+
const sharedArray = new SharedArrayClass<T>(id, runtime, attributes);
|
|
55
|
+
await sharedArray.load(services);
|
|
56
|
+
return sharedArray;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public create(document: IFluidDataStoreRuntime, id: string): ISharedArray<T> {
|
|
60
|
+
/**
|
|
61
|
+
* * The SharedArray
|
|
62
|
+
*/
|
|
63
|
+
const sharedArray = new SharedArrayClass<T>(id, document, this.attributes);
|
|
64
|
+
sharedArray.initializeLocal();
|
|
65
|
+
return sharedArray;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Entrypoint for {@link ISharedArray} creation.
|
|
71
|
+
* @legacy
|
|
72
|
+
* @alpha
|
|
73
|
+
*/
|
|
74
|
+
export const SharedArray: ISharedObjectKind<ISharedArray<SerializableTypeForSharedArray>> &
|
|
75
|
+
SharedObjectKind<ISharedArray<SerializableTypeForSharedArray>> =
|
|
76
|
+
createSharedObjectKind<ISharedArray<SerializableTypeForSharedArray>>(SharedArrayFactory);
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Entrypoint for {@link ISharedArray} creation.
|
|
80
|
+
* @legacy
|
|
81
|
+
* @alpha
|
|
82
|
+
*/
|
|
83
|
+
export const SharedArrayBuilder = <
|
|
84
|
+
T extends SerializableTypeForSharedArray,
|
|
85
|
+
>(): ISharedObjectKind<ISharedArray<T>> & SharedObjectKind<ISharedArray<T>> => {
|
|
86
|
+
const factory = SharedArrayFactory<T>;
|
|
87
|
+
return createSharedObjectKind<ISharedArray<T>>(factory);
|
|
88
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @legacy
|
|
8
|
+
* @alpha
|
|
9
|
+
*/
|
|
10
|
+
export const OperationType = {
|
|
11
|
+
insertEntry: 0,
|
|
12
|
+
deleteEntry: 1,
|
|
13
|
+
moveEntry: 2,
|
|
14
|
+
toggle: 3,
|
|
15
|
+
toggleMove: 4,
|
|
16
|
+
} as const;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @legacy
|
|
20
|
+
* @alpha
|
|
21
|
+
*/
|
|
22
|
+
export type OperationType = (typeof OperationType)[keyof typeof OperationType];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @legacy
|
|
26
|
+
* @alpha
|
|
27
|
+
*/
|
|
28
|
+
export interface IInsertOperation<T = unknown> {
|
|
29
|
+
type: typeof OperationType.insertEntry;
|
|
30
|
+
entryId: string;
|
|
31
|
+
value: T;
|
|
32
|
+
insertAfterEntryId?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @legacy
|
|
37
|
+
* @alpha
|
|
38
|
+
*/
|
|
39
|
+
export interface IDeleteOperation {
|
|
40
|
+
type: typeof OperationType.deleteEntry;
|
|
41
|
+
entryId: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @legacy
|
|
46
|
+
* @alpha
|
|
47
|
+
*/
|
|
48
|
+
export interface IMoveOperation {
|
|
49
|
+
type: typeof OperationType.moveEntry;
|
|
50
|
+
entryId: string;
|
|
51
|
+
insertAfterEntryId?: string;
|
|
52
|
+
changedToEntryId: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @legacy
|
|
57
|
+
* @alpha
|
|
58
|
+
*/
|
|
59
|
+
export interface IToggleOperation {
|
|
60
|
+
type: typeof OperationType.toggle;
|
|
61
|
+
entryId: string;
|
|
62
|
+
isDeleted: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @legacy
|
|
67
|
+
* @alpha
|
|
68
|
+
*/
|
|
69
|
+
export interface IToggleMoveOperation {
|
|
70
|
+
type: typeof OperationType.toggleMove;
|
|
71
|
+
entryId: string;
|
|
72
|
+
changedToEntryId: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @legacy
|
|
77
|
+
* @alpha
|
|
78
|
+
*/
|
|
79
|
+
export type ISharedArrayRevertibleOperation = IToggleOperation | IToggleMoveOperation;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @legacy
|
|
83
|
+
* @alpha
|
|
84
|
+
*/
|
|
85
|
+
export type ISharedArrayOperation<T = unknown> =
|
|
86
|
+
| IInsertOperation<T>
|
|
87
|
+
| IDeleteOperation
|
|
88
|
+
| IMoveOperation
|
|
89
|
+
| ISharedArrayRevertibleOperation;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ISharedArrayRevertible, IRevertible } from "./interfaces.js";
|
|
7
|
+
import type { ISharedArrayOperation } from "./sharedArrayOperations.js";
|
|
8
|
+
import { OperationType } from "./sharedArrayOperations.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export class SharedArrayRevertible implements IRevertible {
|
|
14
|
+
private readonly sharedArray: ISharedArrayRevertible;
|
|
15
|
+
private readonly op: ISharedArrayOperation;
|
|
16
|
+
public constructor(sharedArray: ISharedArrayRevertible, op: ISharedArrayOperation) {
|
|
17
|
+
this.sharedArray = sharedArray;
|
|
18
|
+
this.op = op;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public revert(): void {
|
|
22
|
+
switch (this.op.type) {
|
|
23
|
+
case OperationType.insertEntry: {
|
|
24
|
+
this.sharedArray.toggle(this.op.entryId);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case OperationType.deleteEntry: {
|
|
28
|
+
this.sharedArray.toggle(this.op.entryId);
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
case OperationType.toggle: {
|
|
32
|
+
this.sharedArray.toggle(this.op.entryId);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case OperationType.moveEntry: {
|
|
36
|
+
this.sharedArray.toggleMove(this.op.entryId, this.op.changedToEntryId);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case OperationType.toggleMove: {
|
|
40
|
+
this.sharedArray.toggleMove(this.op.changedToEntryId, this.op.entryId);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
default: {
|
|
44
|
+
throw new Error(`Unknown operation type`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public dispose(): void {}
|
|
50
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type {
|
|
7
|
+
SerializableTypeForSharedSignal,
|
|
8
|
+
ISharedSignal,
|
|
9
|
+
ISharedSignalEvents,
|
|
10
|
+
ISignalOperation,
|
|
11
|
+
} from "./signal/index.js";
|
|
12
|
+
export { SharedSignal } from "./signal/index.js";
|
|
13
|
+
export { SharedSignalFactory } from "./signal/index.js";
|
|
14
|
+
export { SharedArray, SharedArrayBuilder, OperationType } from "./array/index.js";
|
|
15
|
+
export { SharedArrayFactory } from "./array/index.js";
|
|
16
|
+
export { SharedArrayRevertible } from "./array/index.js";
|
|
17
|
+
export type {
|
|
18
|
+
SerializableTypeForSharedArray,
|
|
19
|
+
ISharedArray,
|
|
20
|
+
ISharedArrayEvents,
|
|
21
|
+
ISharedArrayRevertible,
|
|
22
|
+
} from "./array/index.js";
|
|
23
|
+
export type {
|
|
24
|
+
ISharedArrayOperation,
|
|
25
|
+
IDeleteOperation,
|
|
26
|
+
IInsertOperation,
|
|
27
|
+
IMoveOperation,
|
|
28
|
+
ISharedArrayRevertibleOperation,
|
|
29
|
+
IToggleMoveOperation,
|
|
30
|
+
IToggleOperation,
|
|
31
|
+
} from "./array/index.js";
|
|
32
|
+
export type { IRevertible } from "./array/index.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const pkgName = "@fluidframework/legacy-dds";
|
|
9
|
+
export const pkgVersion = "2.50.0-345060";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @SharedSignal
|
|
2
|
+
|
|
3
|
+
## SharedSignal
|
|
4
|
+
|
|
5
|
+
A DDS created by Loop which we now take ownership. Following README content is provided by them. Last commit in the office bohemia repo before migrating: 8854bfbeb077433015c93de582d0eefa2c657fa7
|
|
6
|
+
|
|
7
|
+
The SharedSignal distributed data structure is used to handle local, remote ops and offline scenarios. Transactions are set up using this DDS to generate marker op. Example [DDS1 OP -> DDS2 OP -> DDS3 OP -> Shared Signal DDS op]
|
|
8
|
+
|
|
9
|
+
### Creation
|
|
10
|
+
|
|
11
|
+
To create a `SharedSignal`, call the static create method:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
|
|
15
|
+
const mySignal = SharedSignal.create(this.runtime, id);
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
#### `.notify()`
|
|
20
|
+
|
|
21
|
+
Used for generating a signal
|
|
22
|
+
|
|
23
|
+
### `.processCore()`
|
|
24
|
+
|
|
25
|
+
Used for processing a shared signal operation.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type {
|
|
7
|
+
SerializableTypeForSharedSignal,
|
|
8
|
+
ISharedSignal,
|
|
9
|
+
ISharedSignalEvents,
|
|
10
|
+
ISignalOperation,
|
|
11
|
+
} from "./interfaces.js";
|
|
12
|
+
export { SharedSignalFactory, SharedSignal } from "./sharedSignalFactory.js";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
7
|
+
import type {
|
|
8
|
+
ISharedObject,
|
|
9
|
+
ISharedObjectEvents,
|
|
10
|
+
} from "@fluidframework/shared-object-base/internal";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Basic types for the SharedSignal DDS
|
|
14
|
+
* It can be used as a generic constraint (`extends SerializableTypeForSharedSignal`) but is
|
|
15
|
+
* *never* meant to be a concrete/real type on its own.
|
|
16
|
+
* @legacy
|
|
17
|
+
* @alpha
|
|
18
|
+
*/
|
|
19
|
+
export type SerializableTypeForSharedSignal =
|
|
20
|
+
| boolean
|
|
21
|
+
| number
|
|
22
|
+
| string
|
|
23
|
+
| IFluidHandle
|
|
24
|
+
| object;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @legacy
|
|
28
|
+
* @alpha
|
|
29
|
+
*/
|
|
30
|
+
export interface ISharedSignalEvents<T extends SerializableTypeForSharedSignal>
|
|
31
|
+
extends ISharedObjectEvents {
|
|
32
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
-- TODO: Using 'any' type defeats the purpose of TypeScript. Consider replacing it with a concrete type, or 'unknown'. */
|
|
34
|
+
(event: "notify", listener: (value: T, isLocal: boolean) => void): any;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @legacy
|
|
39
|
+
* @alpha
|
|
40
|
+
*/
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
export interface ISharedSignal<T extends SerializableTypeForSharedSignal = any>
|
|
43
|
+
extends ISharedObject<ISharedSignalEvents<T>> {
|
|
44
|
+
notify(metadata?: T): void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
export interface ISignalOperation<out T = unknown> {
|
|
51
|
+
type: "signal";
|
|
52
|
+
readonly metadata?: T;
|
|
53
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
IChannelAttributes,
|
|
10
|
+
IFluidDataStoreRuntime,
|
|
11
|
+
IChannelStorageService,
|
|
12
|
+
IChannelFactory,
|
|
13
|
+
} from "@fluidframework/datastore-definitions/internal";
|
|
14
|
+
import { FileMode, MessageType, TreeEntry } from "@fluidframework/driver-definitions/internal";
|
|
15
|
+
import type {
|
|
16
|
+
ISequencedDocumentMessage,
|
|
17
|
+
ITree,
|
|
18
|
+
} from "@fluidframework/driver-definitions/internal";
|
|
19
|
+
import type { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions/internal";
|
|
20
|
+
import { convertToSummaryTreeWithStats } from "@fluidframework/runtime-utils/internal";
|
|
21
|
+
import type { IFluidSerializer } from "@fluidframework/shared-object-base/internal";
|
|
22
|
+
import { SharedObject } from "@fluidframework/shared-object-base/internal";
|
|
23
|
+
|
|
24
|
+
import type {
|
|
25
|
+
ISharedSignal,
|
|
26
|
+
ISharedSignalEvents,
|
|
27
|
+
ISignalOperation,
|
|
28
|
+
SerializableTypeForSharedSignal,
|
|
29
|
+
} from "./interfaces.js";
|
|
30
|
+
import { SharedSignalFactory } from "./sharedSignalFactory.js";
|
|
31
|
+
|
|
32
|
+
const snapshotFileName = "header";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Represents a shared signal that allows communication between distributed clients.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export class SharedSignalClass<T extends SerializableTypeForSharedSignal = any>
|
|
40
|
+
extends SharedObject<ISharedSignalEvents<T>>
|
|
41
|
+
implements ISharedSignal<T>
|
|
42
|
+
{
|
|
43
|
+
/**
|
|
44
|
+
* Create a new shared signal
|
|
45
|
+
*
|
|
46
|
+
* @param runtime - data store runtime the new shared signal belongs to
|
|
47
|
+
* @param id - optional name of the shared signal
|
|
48
|
+
* @returns newly create shared signal (but not attached yet)
|
|
49
|
+
*/
|
|
50
|
+
public static create(runtime: IFluidDataStoreRuntime, id?: string): SharedSignalClass {
|
|
51
|
+
return runtime.createChannel(id, SharedSignalFactory.Type) as SharedSignalClass;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Get a factory for SharedSignal to register with the data store.
|
|
56
|
+
*
|
|
57
|
+
* @returns a factory that creates and load SharedSignal
|
|
58
|
+
*/
|
|
59
|
+
public static getFactory(): IChannelFactory {
|
|
60
|
+
return new SharedSignalFactory();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Constructs a new shared signal. If the object is non-local an id and service interfaces will
|
|
65
|
+
* be provided
|
|
66
|
+
* @param id - optional name of the shared signal
|
|
67
|
+
* @param runtime - data store runtime the shared signal belongs to
|
|
68
|
+
* @param attributes - represents the attributes of a channel/DDS.
|
|
69
|
+
*/
|
|
70
|
+
public constructor(
|
|
71
|
+
id: string,
|
|
72
|
+
runtime: IFluidDataStoreRuntime,
|
|
73
|
+
attributes: IChannelAttributes,
|
|
74
|
+
) {
|
|
75
|
+
super(id, runtime, attributes, "loop_sharedSignal_" /* telemetryContextPrefix */);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Method used for generating a signal.
|
|
80
|
+
*/
|
|
81
|
+
public notify(metadata?: T): void {
|
|
82
|
+
// If we are not attached, don't submit the op.
|
|
83
|
+
if (!this.isAttached()) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const op: ISignalOperation<T> = {
|
|
88
|
+
type: "signal",
|
|
89
|
+
metadata,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
this.notifyCore(op, true);
|
|
93
|
+
|
|
94
|
+
this.submitLocalMessage(op);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
protected summarizeCore(_serializer: IFluidSerializer): ISummaryTreeWithStats {
|
|
98
|
+
const tree: ITree = {
|
|
99
|
+
entries: [
|
|
100
|
+
{
|
|
101
|
+
mode: FileMode.File,
|
|
102
|
+
path: snapshotFileName,
|
|
103
|
+
type: TreeEntry[TreeEntry.Blob],
|
|
104
|
+
value: {
|
|
105
|
+
contents: JSON.stringify(""),
|
|
106
|
+
// eslint-disable-next-line unicorn/text-encoding-identifier-case
|
|
107
|
+
encoding: "utf-8",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const summaryTreeWithStats = convertToSummaryTreeWithStats(tree);
|
|
114
|
+
|
|
115
|
+
return summaryTreeWithStats;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Load share signal from snapshot
|
|
120
|
+
*
|
|
121
|
+
* @param _storage - the storage to get the snapshot from
|
|
122
|
+
* @returns - promise that resolved when the load is completed
|
|
123
|
+
*/
|
|
124
|
+
protected async loadCore(_storage: IChannelStorageService): Promise<void> {}
|
|
125
|
+
|
|
126
|
+
protected override initializeLocalCore(): void {}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Callback on disconnect
|
|
130
|
+
*/
|
|
131
|
+
protected onDisconnect(): void {}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Process a shared signal operation
|
|
135
|
+
*
|
|
136
|
+
* @param message - the message to prepare
|
|
137
|
+
* @param local - whether the message was sent by the local client
|
|
138
|
+
* @param _localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
|
|
139
|
+
* For messages from a remote client, this will be undefined.
|
|
140
|
+
*/
|
|
141
|
+
protected processCore(
|
|
142
|
+
message: ISequencedDocumentMessage,
|
|
143
|
+
local: boolean,
|
|
144
|
+
_localOpMetadata: unknown,
|
|
145
|
+
): void {
|
|
146
|
+
if ((message.type as MessageType) === MessageType.Operation && !local) {
|
|
147
|
+
const op = message.contents as ISignalOperation<T>;
|
|
148
|
+
|
|
149
|
+
switch (op.type) {
|
|
150
|
+
case "signal": {
|
|
151
|
+
this.notifyCore(op, local);
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
default: {
|
|
156
|
+
throw new Error("Unknown operation");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private notifyCore(op: ISignalOperation<T>, isLocal: boolean): void {
|
|
163
|
+
this.emit("notify", op.metadata, isLocal);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
protected applyStashedOp(_content: unknown): void {
|
|
167
|
+
throw new Error("Not implemented");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
IChannelAttributes,
|
|
8
|
+
IFluidDataStoreRuntime,
|
|
9
|
+
IChannelFactory,
|
|
10
|
+
IChannelServices,
|
|
11
|
+
} from "@fluidframework/datastore-definitions/internal";
|
|
12
|
+
import { createSharedObjectKind } from "@fluidframework/shared-object-base/internal";
|
|
13
|
+
|
|
14
|
+
import { pkgVersion } from "../packageVersion.js";
|
|
15
|
+
|
|
16
|
+
import type { ISharedSignal } from "./interfaces.js";
|
|
17
|
+
import { SharedSignalClass } from "./sharedSignal.js";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export class SharedSignalFactory implements IChannelFactory<ISharedSignal> {
|
|
23
|
+
public static readonly Type: string = "https://graph.microsoft.com/types/signal";
|
|
24
|
+
|
|
25
|
+
public static readonly Attributes: IChannelAttributes = {
|
|
26
|
+
type: SharedSignalFactory.Type,
|
|
27
|
+
snapshotFormatVersion: "0.1",
|
|
28
|
+
packageVersion: pkgVersion,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
public get type(): string {
|
|
32
|
+
return SharedSignalFactory.Type;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public get attributes(): IChannelAttributes {
|
|
36
|
+
return SharedSignalFactory.Attributes;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public async load(
|
|
40
|
+
runtime: IFluidDataStoreRuntime,
|
|
41
|
+
id: string,
|
|
42
|
+
services: IChannelServices,
|
|
43
|
+
attributes: IChannelAttributes,
|
|
44
|
+
): Promise<ISharedSignal> {
|
|
45
|
+
const signal = new SharedSignalClass(id, runtime, attributes);
|
|
46
|
+
await signal.load(services);
|
|
47
|
+
return signal;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public create(document: IFluidDataStoreRuntime, id: string): ISharedSignal {
|
|
51
|
+
const signal = new SharedSignalClass(id, document, this.attributes);
|
|
52
|
+
signal.initializeLocal();
|
|
53
|
+
return signal;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Entrypoint for {@link ISharedSignal} creation.
|
|
59
|
+
* @legacy
|
|
60
|
+
* @alpha
|
|
61
|
+
*/
|
|
62
|
+
export const SharedSignal = createSharedObjectKind<ISharedSignal>(SharedSignalFactory);
|
package/tsconfig.json
ADDED
package/tsdoc.json
ADDED