@fluidframework/sequence 2.23.0 → 2.31.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 +510 -495
- package/api-report/sequence.legacy.alpha.api.md +67 -5
- package/dist/IntervalCollectionValues.d.ts +3 -51
- package/dist/IntervalCollectionValues.d.ts.map +1 -1
- package/dist/IntervalCollectionValues.js +6 -49
- package/dist/IntervalCollectionValues.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -8
- package/dist/index.js.map +1 -1
- package/dist/intervalCollection.d.ts +292 -63
- package/dist/intervalCollection.d.ts.map +1 -1
- package/dist/intervalCollection.js +111 -193
- package/dist/intervalCollection.js.map +1 -1
- package/dist/intervalCollectionMap.d.ts +11 -32
- package/dist/intervalCollectionMap.d.ts.map +1 -1
- package/dist/intervalCollectionMap.js +37 -90
- package/dist/intervalCollectionMap.js.map +1 -1
- package/dist/intervalCollectionMapInterfaces.d.ts +10 -83
- package/dist/intervalCollectionMapInterfaces.d.ts.map +1 -1
- package/dist/intervalCollectionMapInterfaces.js.map +1 -1
- package/dist/intervalIndex/endpointInRangeIndex.d.ts +10 -11
- package/dist/intervalIndex/endpointInRangeIndex.d.ts.map +1 -1
- package/dist/intervalIndex/endpointInRangeIndex.js +4 -5
- package/dist/intervalIndex/endpointInRangeIndex.js.map +1 -1
- package/dist/intervalIndex/endpointIndex.d.ts +12 -13
- package/dist/intervalIndex/endpointIndex.d.ts.map +1 -1
- package/dist/intervalIndex/endpointIndex.js +4 -5
- package/dist/intervalIndex/endpointIndex.js.map +1 -1
- package/dist/intervalIndex/idIntervalIndex.d.ts +6 -12
- package/dist/intervalIndex/idIntervalIndex.d.ts.map +1 -1
- package/dist/intervalIndex/idIntervalIndex.js +0 -3
- package/dist/intervalIndex/idIntervalIndex.js.map +1 -1
- package/dist/intervalIndex/index.d.ts +2 -2
- package/dist/intervalIndex/index.d.ts.map +1 -1
- package/dist/intervalIndex/index.js.map +1 -1
- package/dist/intervalIndex/intervalIndex.d.ts +28 -1
- package/dist/intervalIndex/intervalIndex.d.ts.map +1 -1
- package/dist/intervalIndex/intervalIndex.js.map +1 -1
- package/dist/intervalIndex/overlappingIntervalsIndex.d.ts +30 -13
- package/dist/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -1
- package/dist/intervalIndex/overlappingIntervalsIndex.js +4 -5
- package/dist/intervalIndex/overlappingIntervalsIndex.js.map +1 -1
- package/dist/intervalIndex/overlappingSequenceIntervalsIndex.d.ts.map +1 -1
- package/dist/intervalIndex/overlappingSequenceIntervalsIndex.js +1 -1
- package/dist/intervalIndex/overlappingSequenceIntervalsIndex.js.map +1 -1
- package/dist/intervalIndex/sequenceIntervalIndexes.d.ts +2 -2
- package/dist/intervalIndex/sequenceIntervalIndexes.d.ts.map +1 -1
- package/dist/intervalIndex/sequenceIntervalIndexes.js.map +1 -1
- package/dist/intervalIndex/startpointInRangeIndex.d.ts +10 -11
- package/dist/intervalIndex/startpointInRangeIndex.d.ts.map +1 -1
- package/dist/intervalIndex/startpointInRangeIndex.js +4 -5
- package/dist/intervalIndex/startpointInRangeIndex.js.map +1 -1
- package/dist/intervals/index.d.ts +2 -3
- package/dist/intervals/index.d.ts.map +1 -1
- package/dist/intervals/index.js +1 -6
- package/dist/intervals/index.js.map +1 -1
- package/dist/intervals/intervalUtils.d.ts +3 -25
- package/dist/intervals/intervalUtils.d.ts.map +1 -1
- package/dist/intervals/intervalUtils.js.map +1 -1
- package/dist/intervals/sequenceInterval.d.ts +3 -8
- package/dist/intervals/sequenceInterval.d.ts.map +1 -1
- package/dist/intervals/sequenceInterval.js +1 -9
- package/dist/intervals/sequenceInterval.js.map +1 -1
- package/dist/legacy.d.ts +4 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/sequence.d.ts +4 -6
- package/dist/sequence.d.ts.map +1 -1
- package/dist/sequence.js +3 -5
- package/dist/sequence.js.map +1 -1
- package/dist/sharedIntervalCollection.d.ts +2 -63
- package/dist/sharedIntervalCollection.d.ts.map +1 -1
- package/dist/sharedIntervalCollection.js +0 -113
- package/dist/sharedIntervalCollection.js.map +1 -1
- package/dist/sharedString.d.ts.map +1 -1
- package/dist/sharedString.js +6 -6
- package/dist/sharedString.js.map +1 -1
- package/lib/IntervalCollectionValues.d.ts +3 -51
- package/lib/IntervalCollectionValues.d.ts.map +1 -1
- package/lib/IntervalCollectionValues.js +5 -47
- package/lib/IntervalCollectionValues.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -3
- package/lib/index.js.map +1 -1
- package/lib/intervalCollection.d.ts +292 -63
- package/lib/intervalCollection.d.ts.map +1 -1
- package/lib/intervalCollection.js +113 -191
- package/lib/intervalCollection.js.map +1 -1
- package/lib/intervalCollectionMap.d.ts +11 -32
- package/lib/intervalCollectionMap.d.ts.map +1 -1
- package/lib/intervalCollectionMap.js +39 -92
- package/lib/intervalCollectionMap.js.map +1 -1
- package/lib/intervalCollectionMapInterfaces.d.ts +10 -83
- package/lib/intervalCollectionMapInterfaces.d.ts.map +1 -1
- package/lib/intervalCollectionMapInterfaces.js.map +1 -1
- package/lib/intervalIndex/endpointInRangeIndex.d.ts +10 -11
- package/lib/intervalIndex/endpointInRangeIndex.d.ts.map +1 -1
- package/lib/intervalIndex/endpointInRangeIndex.js +5 -6
- package/lib/intervalIndex/endpointInRangeIndex.js.map +1 -1
- package/lib/intervalIndex/endpointIndex.d.ts +12 -13
- package/lib/intervalIndex/endpointIndex.d.ts.map +1 -1
- package/lib/intervalIndex/endpointIndex.js +5 -6
- package/lib/intervalIndex/endpointIndex.js.map +1 -1
- package/lib/intervalIndex/idIntervalIndex.d.ts +6 -12
- package/lib/intervalIndex/idIntervalIndex.d.ts.map +1 -1
- package/lib/intervalIndex/idIntervalIndex.js +0 -3
- package/lib/intervalIndex/idIntervalIndex.js.map +1 -1
- package/lib/intervalIndex/index.d.ts +2 -2
- package/lib/intervalIndex/index.d.ts.map +1 -1
- package/lib/intervalIndex/index.js.map +1 -1
- package/lib/intervalIndex/intervalIndex.d.ts +28 -1
- package/lib/intervalIndex/intervalIndex.d.ts.map +1 -1
- package/lib/intervalIndex/intervalIndex.js.map +1 -1
- package/lib/intervalIndex/overlappingIntervalsIndex.d.ts +30 -13
- package/lib/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -1
- package/lib/intervalIndex/overlappingIntervalsIndex.js +5 -6
- package/lib/intervalIndex/overlappingIntervalsIndex.js.map +1 -1
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.ts.map +1 -1
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.js +2 -2
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.js.map +1 -1
- package/lib/intervalIndex/sequenceIntervalIndexes.d.ts +2 -2
- package/lib/intervalIndex/sequenceIntervalIndexes.d.ts.map +1 -1
- package/lib/intervalIndex/sequenceIntervalIndexes.js.map +1 -1
- package/lib/intervalIndex/startpointInRangeIndex.d.ts +10 -11
- package/lib/intervalIndex/startpointInRangeIndex.d.ts.map +1 -1
- package/lib/intervalIndex/startpointInRangeIndex.js +5 -6
- package/lib/intervalIndex/startpointInRangeIndex.js.map +1 -1
- package/lib/intervals/index.d.ts +2 -3
- package/lib/intervals/index.d.ts.map +1 -1
- package/lib/intervals/index.js +1 -2
- package/lib/intervals/index.js.map +1 -1
- package/lib/intervals/intervalUtils.d.ts +3 -25
- package/lib/intervals/intervalUtils.d.ts.map +1 -1
- package/lib/intervals/intervalUtils.js.map +1 -1
- package/lib/intervals/sequenceInterval.d.ts +3 -8
- package/lib/intervals/sequenceInterval.d.ts.map +1 -1
- package/lib/intervals/sequenceInterval.js +0 -8
- package/lib/intervals/sequenceInterval.js.map +1 -1
- package/lib/legacy.d.ts +4 -0
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/sequence.d.ts +4 -6
- package/lib/sequence.d.ts.map +1 -1
- package/lib/sequence.js +3 -5
- package/lib/sequence.js.map +1 -1
- package/lib/sharedIntervalCollection.d.ts +2 -63
- package/lib/sharedIntervalCollection.d.ts.map +1 -1
- package/lib/sharedIntervalCollection.js +1 -110
- package/lib/sharedIntervalCollection.js.map +1 -1
- package/lib/sharedString.d.ts.map +1 -1
- package/lib/sharedString.js +6 -6
- package/lib/sharedString.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/package.json +20 -23
- package/src/IntervalCollectionValues.ts +10 -93
- package/src/index.ts +6 -17
- package/src/intervalCollection.ts +524 -343
- package/src/intervalCollectionMap.ts +72 -140
- package/src/intervalCollectionMapInterfaces.ts +13 -104
- package/src/intervalIndex/endpointInRangeIndex.ts +17 -29
- package/src/intervalIndex/endpointIndex.ts +19 -31
- package/src/intervalIndex/idIntervalIndex.ts +15 -25
- package/src/intervalIndex/index.ts +2 -1
- package/src/intervalIndex/intervalIndex.ts +30 -1
- package/src/intervalIndex/overlappingIntervalsIndex.ts +50 -27
- package/src/intervalIndex/overlappingSequenceIntervalsIndex.ts +2 -3
- package/src/intervalIndex/sequenceIntervalIndexes.ts +2 -2
- package/src/intervalIndex/startpointInRangeIndex.ts +17 -29
- package/src/intervals/index.ts +0 -3
- package/src/intervals/intervalUtils.ts +3 -38
- package/src/intervals/sequenceInterval.ts +2 -12
- package/src/packageVersion.ts +1 -1
- package/src/sequence.ts +8 -20
- package/src/sharedIntervalCollection.ts +5 -183
- package/src/sharedString.ts +6 -24
- package/dist/intervals/interval.d.ts +0 -76
- package/dist/intervals/interval.d.ts.map +0 -1
- package/dist/intervals/interval.js +0 -167
- package/dist/intervals/interval.js.map +0 -1
- package/lib/intervals/interval.d.ts +0 -76
- package/lib/intervals/interval.d.ts.map +0 -1
- package/lib/intervals/interval.js +0 -162
- package/lib/intervals/interval.js.map +0 -1
- package/prettier.config.cjs +0 -8
- package/src/intervals/interval.ts +0 -226
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { TypedEventEmitter } from "@fluid-internal/client-utils";
|
|
6
5
|
import { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
6
|
+
import type { IEvent, IEventProvider } from "@fluidframework/core-interfaces";
|
|
7
7
|
import { ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
|
|
8
8
|
import { IFluidSerializer } from "@fluidframework/shared-object-base/internal";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { type ISerializableInterval } from "./intervals/index.js";
|
|
9
|
+
import { IntervalCollection } from "./intervalCollection.js";
|
|
10
|
+
import { IIntervalCollectionTypeOperationValue, IMapMessageLocalMetadata, ISerializableIntervalCollection, SequenceOptions } from "./intervalCollectionMapInterfaces.js";
|
|
12
11
|
/**
|
|
13
12
|
* Description of a map delta operation
|
|
14
13
|
*/
|
|
@@ -33,6 +32,9 @@ export interface IMapOperation {
|
|
|
33
32
|
export interface IMapDataObjectSerializable {
|
|
34
33
|
[key: string]: ISerializableIntervalCollection;
|
|
35
34
|
}
|
|
35
|
+
export interface IntervalCollectionMapEvents extends IEvent {
|
|
36
|
+
(event: "createIntervalCollection", listener: (key: string, local: boolean) => void): void;
|
|
37
|
+
}
|
|
36
38
|
/**
|
|
37
39
|
* A DefaultMap is a map-like distributed data structure, supporting operations on values stored by
|
|
38
40
|
* string key locations.
|
|
@@ -40,25 +42,21 @@ export interface IMapDataObjectSerializable {
|
|
|
40
42
|
* Creation of values is implicit on access (either via `get` or a remote op application referring to
|
|
41
43
|
* a collection that wasn't previously known)
|
|
42
44
|
*/
|
|
43
|
-
export declare class IntervalCollectionMap
|
|
45
|
+
export declare class IntervalCollectionMap {
|
|
44
46
|
private readonly serializer;
|
|
45
47
|
private readonly handle;
|
|
46
48
|
private readonly submitMessage;
|
|
47
|
-
private readonly type;
|
|
48
49
|
private readonly options?;
|
|
49
|
-
readonly eventEmitter: TypedEventEmitter<ISharedDefaultMapEvents>;
|
|
50
50
|
/**
|
|
51
51
|
* The number of key/value pairs stored in the map.
|
|
52
52
|
*/
|
|
53
53
|
get size(): number;
|
|
54
|
-
/**
|
|
55
|
-
* Mapping of op types to message handlers.
|
|
56
|
-
*/
|
|
57
|
-
private readonly messageHandler;
|
|
58
54
|
/**
|
|
59
55
|
* The in-memory data the map is storing.
|
|
60
56
|
*/
|
|
61
57
|
private readonly data;
|
|
58
|
+
private readonly eventEmitter;
|
|
59
|
+
get events(): IEventProvider<IntervalCollectionMapEvents>;
|
|
62
60
|
/**
|
|
63
61
|
* Create a new default map.
|
|
64
62
|
* @param serializer - The serializer to serialize / parse handles
|
|
@@ -67,7 +65,7 @@ export declare class IntervalCollectionMap<T extends ISerializableInterval> {
|
|
|
67
65
|
* @param type - The value type to create at values of this map
|
|
68
66
|
* @param eventEmitter - The object that will emit map events
|
|
69
67
|
*/
|
|
70
|
-
constructor(serializer: IFluidSerializer, handle: IFluidHandle, submitMessage: (op: IMapOperation, localOpMetadata: IMapMessageLocalMetadata) => void,
|
|
68
|
+
constructor(serializer: IFluidSerializer, handle: IFluidHandle, submitMessage: (op: IMapOperation, localOpMetadata: IMapMessageLocalMetadata) => void, options?: Partial<SequenceOptions> | undefined);
|
|
71
69
|
/**
|
|
72
70
|
* Get an iterator over the keys in this map.
|
|
73
71
|
* @returns The iterator
|
|
@@ -81,8 +79,7 @@ export declare class IntervalCollectionMap<T extends ISerializableInterval> {
|
|
|
81
79
|
/**
|
|
82
80
|
* {@inheritDoc ISharedMap.get}
|
|
83
81
|
*/
|
|
84
|
-
get(key: string): IntervalCollection
|
|
85
|
-
getSerializableStorage(serializer: IFluidSerializer): IMapDataObjectSerializable;
|
|
82
|
+
get(key: string): IntervalCollection;
|
|
86
83
|
serialize(serializer: IFluidSerializer): string;
|
|
87
84
|
/**
|
|
88
85
|
* Populate the kernel with the given map data.
|
|
@@ -120,25 +117,7 @@ export declare class IntervalCollectionMap<T extends ISerializableInterval> {
|
|
|
120
117
|
* Initializes a default ValueType at the provided key.
|
|
121
118
|
* Should be used when a map operation incurs creation.
|
|
122
119
|
* @param key - The key being initialized
|
|
123
|
-
* @param local - Whether the message originated from the local client
|
|
124
120
|
*/
|
|
125
121
|
private createCore;
|
|
126
|
-
/**
|
|
127
|
-
* The remote ISerializableValue we're receiving (either as a result of a load or an incoming set op) will
|
|
128
|
-
* have the information we need to create a real object, but will not be the real object yet. For example,
|
|
129
|
-
* we might know it's a map and the map's ID but not have the actual map or its data yet. makeLocal's
|
|
130
|
-
* job is to convert that information into a real object for local usage.
|
|
131
|
-
* @param key - The key that the caller intends to store the local value into (used for ops later). But
|
|
132
|
-
* doesn't actually store the local value into that key. So better not lie!
|
|
133
|
-
* @param serializable - The remote information that we can convert into a real object
|
|
134
|
-
* @returns The local value that was produced
|
|
135
|
-
*/
|
|
136
|
-
private makeLocal;
|
|
137
|
-
/**
|
|
138
|
-
* Create an emitter for a value type to emit ops from the given key.
|
|
139
|
-
* @param key - The key of the map that the value type will be stored on
|
|
140
|
-
* @returns A value op emitter for the given key
|
|
141
|
-
*/
|
|
142
|
-
private makeMapValueOpEmitter;
|
|
143
122
|
}
|
|
144
123
|
//# sourceMappingURL=intervalCollectionMap.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intervalCollectionMap.d.ts","sourceRoot":"","sources":["../src/intervalCollectionMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"intervalCollectionMap.d.ts","sourceRoot":"","sources":["../src/intervalCollectionMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAE9E,OAA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,wBAAwB,KACrC,IAAI,EACQ,OAAO,CAAC,sCAA0B;IAGpD;;;OAGG;IACI,IAAI,IAAI,gBAAgB,CAAC,MAAM,CAAC;IAIvC;;;OAGG;IACI,MAAM,IAAI,gBAAgB,CAAC,GAAG,CAAC;IAetC;;OAEG;IACI,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB;IAMpC,SAAS,CAAC,UAAU,EAAE,gBAAgB,GAAG,MAAM;IAatD;;;;OAIG;IACI,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IA6BzC;;;;;;;OAOG;IACI,kBAAkB,CAAC,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,wBAAwB,GAAG,OAAO;IAiBnF,iBAAiB,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO;IAsC9C;;;;;;;;;;;;;;OAcG;IACI,iBAAiB,CACvB,EAAE,EAAE,OAAO,EACX,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,yBAAyB,EAClC,eAAe,EAAE,OAAO,GACtB,OAAO;IAkBV;;;;OAIG;IACH,OAAO,CAAC,UAAU;CAyBlB"}
|
|
@@ -27,6 +27,9 @@ class IntervalCollectionMap {
|
|
|
27
27
|
get size() {
|
|
28
28
|
return this.data.size;
|
|
29
29
|
}
|
|
30
|
+
get events() {
|
|
31
|
+
return this.eventEmitter;
|
|
32
|
+
}
|
|
30
33
|
/**
|
|
31
34
|
* Create a new default map.
|
|
32
35
|
* @param serializer - The serializer to serialize / parse handles
|
|
@@ -35,44 +38,16 @@ class IntervalCollectionMap {
|
|
|
35
38
|
* @param type - The value type to create at values of this map
|
|
36
39
|
* @param eventEmitter - The object that will emit map events
|
|
37
40
|
*/
|
|
38
|
-
constructor(serializer, handle, submitMessage,
|
|
41
|
+
constructor(serializer, handle, submitMessage, options) {
|
|
39
42
|
this.serializer = serializer;
|
|
40
43
|
this.handle = handle;
|
|
41
44
|
this.submitMessage = submitMessage;
|
|
42
|
-
this.type = type;
|
|
43
45
|
this.options = options;
|
|
44
|
-
this.eventEmitter = eventEmitter;
|
|
45
|
-
/**
|
|
46
|
-
* Mapping of op types to message handlers.
|
|
47
|
-
*/
|
|
48
|
-
this.messageHandler = {
|
|
49
|
-
process: (op, local, message, localOpMetadata) => {
|
|
50
|
-
const localValue = this.data.get(op.key) ?? this.createCore(op.key, local);
|
|
51
|
-
const handler = localValue.getOpHandler(op.value.opName);
|
|
52
|
-
const previousValue = localValue.value;
|
|
53
|
-
const translatedValue = op.value.value;
|
|
54
|
-
handler.process(previousValue, translatedValue, local, message, localOpMetadata);
|
|
55
|
-
const event = { key: op.key, previousValue };
|
|
56
|
-
this.eventEmitter.emit("valueChanged", event, local, message, this.eventEmitter);
|
|
57
|
-
},
|
|
58
|
-
submit: (op, localOpMetadata) => {
|
|
59
|
-
this.submitMessage(op, localOpMetadata);
|
|
60
|
-
},
|
|
61
|
-
resubmit: (op, localOpMetadata) => {
|
|
62
|
-
const localValue = this.data.get(op.key);
|
|
63
|
-
(0, internal_1.assert)(localValue !== undefined, 0x3f8 /* Local value expected on resubmission */);
|
|
64
|
-
const handler = localValue.getOpHandler(op.value.opName);
|
|
65
|
-
const rebased = handler.rebase(localValue.value, op.value, localOpMetadata);
|
|
66
|
-
if (rebased !== undefined) {
|
|
67
|
-
const { rebasedOp, rebasedLocalOpMetadata } = rebased;
|
|
68
|
-
this.submitMessage({ ...op, value: rebasedOp }, rebasedLocalOpMetadata);
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
46
|
/**
|
|
73
47
|
* The in-memory data the map is storing.
|
|
74
48
|
*/
|
|
75
49
|
this.data = new Map();
|
|
50
|
+
this.eventEmitter = new client_utils_1.TypedEventEmitter();
|
|
76
51
|
}
|
|
77
52
|
/**
|
|
78
53
|
* Get an iterator over the keys in this map.
|
|
@@ -92,7 +67,7 @@ class IntervalCollectionMap {
|
|
|
92
67
|
const nextVal = localValuesIterator.next();
|
|
93
68
|
return nextVal.done
|
|
94
69
|
? { value: undefined, done: true }
|
|
95
|
-
: { value: nextVal.value
|
|
70
|
+
: { value: nextVal.value, done: false }; // Unpack the stored value
|
|
96
71
|
},
|
|
97
72
|
[Symbol.iterator]() {
|
|
98
73
|
return this;
|
|
@@ -105,17 +80,14 @@ class IntervalCollectionMap {
|
|
|
105
80
|
*/
|
|
106
81
|
get(key) {
|
|
107
82
|
const localValue = this.data.get(key) ?? this.createCore(key, true);
|
|
108
|
-
return localValue
|
|
83
|
+
return localValue;
|
|
109
84
|
}
|
|
110
|
-
|
|
85
|
+
serialize(serializer) {
|
|
111
86
|
const serializableMapData = {};
|
|
112
87
|
this.data.forEach((localValue, key) => {
|
|
113
|
-
serializableMapData[key] = (0, IntervalCollectionValues_js_1.makeSerializable)(localValue, serializer, this.handle);
|
|
88
|
+
serializableMapData[key] = (0, IntervalCollectionValues_js_1.makeSerializable)(localValue, serializer, this.handle, this.options?.intervalSerializationFormat ?? "2");
|
|
114
89
|
});
|
|
115
|
-
return serializableMapData;
|
|
116
|
-
}
|
|
117
|
-
serialize(serializer) {
|
|
118
|
-
return JSON.stringify(this.getSerializableStorage(serializer));
|
|
90
|
+
return JSON.stringify(serializableMapData);
|
|
119
91
|
}
|
|
120
92
|
/**
|
|
121
93
|
* Populate the kernel with the given map data.
|
|
@@ -136,11 +108,9 @@ class IntervalCollectionMap {
|
|
|
136
108
|
// access its value, as well as those trying to match a create message to its underlying
|
|
137
109
|
// collection. See https://github.com/microsoft/FluidFramework/issues/10557 for more context.
|
|
138
110
|
const normalizedKey = key.startsWith("intervalCollections/") ? key.substring(20) : key;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
};
|
|
143
|
-
this.data.set(localValue.key, localValue.value);
|
|
111
|
+
(0, internal_1.assert)(serializable.type !== internal_2.ValueType[internal_2.ValueType.Plain] &&
|
|
112
|
+
serializable.type !== internal_2.ValueType[internal_2.ValueType.Shared], 0x2e1 /* "Support for plain value types removed." */);
|
|
113
|
+
this.createCore(normalizedKey, false, serializable.value);
|
|
144
114
|
}
|
|
145
115
|
}
|
|
146
116
|
/**
|
|
@@ -153,7 +123,14 @@ class IntervalCollectionMap {
|
|
|
153
123
|
*/
|
|
154
124
|
tryResubmitMessage(op, localOpMetadata) {
|
|
155
125
|
if (isMapOperation(op)) {
|
|
156
|
-
this.
|
|
126
|
+
const localValue = this.data.get(op.key);
|
|
127
|
+
(0, internal_1.assert)(localValue !== undefined, 0x3f8 /* Local value expected on resubmission */);
|
|
128
|
+
const handler = intervalCollection_js_1.opsMap[op.value.opName];
|
|
129
|
+
const rebased = handler.rebase(localValue, op.value, localOpMetadata);
|
|
130
|
+
if (rebased !== undefined) {
|
|
131
|
+
const { rebasedOp, rebasedLocalOpMetadata } = rebased;
|
|
132
|
+
this.submitMessage({ ...op, value: rebasedOp }, rebasedLocalOpMetadata);
|
|
133
|
+
}
|
|
157
134
|
return true;
|
|
158
135
|
}
|
|
159
136
|
return false;
|
|
@@ -211,7 +188,11 @@ class IntervalCollectionMap {
|
|
|
211
188
|
*/
|
|
212
189
|
tryProcessMessage(op, local, message, localOpMetadata) {
|
|
213
190
|
if (isMapOperation(op)) {
|
|
214
|
-
this.
|
|
191
|
+
const localValue = this.data.get(op.key) ?? this.createCore(op.key, local);
|
|
192
|
+
const handler = intervalCollection_js_1.opsMap[op.value.opName];
|
|
193
|
+
const previousValue = localValue;
|
|
194
|
+
const translatedValue = op.value.value;
|
|
195
|
+
handler.process(previousValue, translatedValue, local, message, localOpMetadata);
|
|
215
196
|
return true;
|
|
216
197
|
}
|
|
217
198
|
return false;
|
|
@@ -220,55 +201,21 @@ class IntervalCollectionMap {
|
|
|
220
201
|
* Initializes a default ValueType at the provided key.
|
|
221
202
|
* Should be used when a map operation incurs creation.
|
|
222
203
|
* @param key - The key being initialized
|
|
223
|
-
* @param local - Whether the message originated from the local client
|
|
224
204
|
*/
|
|
225
|
-
createCore(key, local) {
|
|
226
|
-
const localValue = new
|
|
227
|
-
|
|
205
|
+
createCore(key, local, serializedIntervals) {
|
|
206
|
+
const localValue = new intervalCollection_js_1.IntervalCollection((op, md) => {
|
|
207
|
+
{
|
|
208
|
+
this.submitMessage({
|
|
209
|
+
key,
|
|
210
|
+
type: "act",
|
|
211
|
+
value: op,
|
|
212
|
+
}, md);
|
|
213
|
+
}
|
|
214
|
+
}, serializedIntervals ?? [], this.options);
|
|
228
215
|
this.data.set(key, localValue);
|
|
229
|
-
|
|
230
|
-
this.eventEmitter.emit("create", event, local, this.eventEmitter);
|
|
216
|
+
this.eventEmitter.emit("createIntervalCollection", key, local, this.eventEmitter);
|
|
231
217
|
return localValue;
|
|
232
218
|
}
|
|
233
|
-
/**
|
|
234
|
-
* The remote ISerializableValue we're receiving (either as a result of a load or an incoming set op) will
|
|
235
|
-
* have the information we need to create a real object, but will not be the real object yet. For example,
|
|
236
|
-
* we might know it's a map and the map's ID but not have the actual map or its data yet. makeLocal's
|
|
237
|
-
* job is to convert that information into a real object for local usage.
|
|
238
|
-
* @param key - The key that the caller intends to store the local value into (used for ops later). But
|
|
239
|
-
* doesn't actually store the local value into that key. So better not lie!
|
|
240
|
-
* @param serializable - The remote information that we can convert into a real object
|
|
241
|
-
* @returns The local value that was produced
|
|
242
|
-
*/
|
|
243
|
-
makeLocal(key, serializable) {
|
|
244
|
-
(0, internal_1.assert)(serializable.type !== internal_2.ValueType[internal_2.ValueType.Plain] &&
|
|
245
|
-
serializable.type !== internal_2.ValueType[internal_2.ValueType.Shared], 0x2e1 /* "Support for plain value types removed." */);
|
|
246
|
-
const localValue = this.type.factory.load(this.makeMapValueOpEmitter(key), serializable.value, this.options);
|
|
247
|
-
return new IntervalCollectionValues_js_1.IntervalCollectionTypeLocalValue(localValue, this.type);
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Create an emitter for a value type to emit ops from the given key.
|
|
251
|
-
* @param key - The key of the map that the value type will be stored on
|
|
252
|
-
* @returns A value op emitter for the given key
|
|
253
|
-
*/
|
|
254
|
-
// eslint-disable-next-line import/no-deprecated
|
|
255
|
-
makeMapValueOpEmitter(key) {
|
|
256
|
-
// eslint-disable-next-line import/no-deprecated
|
|
257
|
-
const emit = (opName, previousValue, params, localOpMetadata) => {
|
|
258
|
-
const op = {
|
|
259
|
-
key,
|
|
260
|
-
type: "act",
|
|
261
|
-
value: {
|
|
262
|
-
opName,
|
|
263
|
-
value: params,
|
|
264
|
-
},
|
|
265
|
-
};
|
|
266
|
-
this.submitMessage(op, localOpMetadata);
|
|
267
|
-
const event = { key, previousValue };
|
|
268
|
-
this.eventEmitter.emit("valueChanged", event, true, null, this.eventEmitter);
|
|
269
|
-
};
|
|
270
|
-
return { emit };
|
|
271
|
-
}
|
|
272
219
|
}
|
|
273
220
|
exports.IntervalCollectionMap = IntervalCollectionMap;
|
|
274
221
|
//# sourceMappingURL=intervalCollectionMap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intervalCollectionMap.js","sourceRoot":"","sources":["../src/intervalCollectionMap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AAEjE,kEAA6D;AAE7D,0EAA0F;AAE1F,+EAGuC;AACvC,mEAKiC;AAkBjC,SAAS,cAAc,CAAC,EAAW;IAClC,OAAO,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,KAAK,IAAI,IAAI,MAAM,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,KAAK,KAAK,CAAC;AACnF,CAAC;AA6BD;;;;;;GAMG;AACH,MAAa,qBAAqB;IACjC;;OAEG;IACH,IAAW,IAAI;QACd,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACvB,CAAC;IA0CD;;;;;;;OAOG;IACH,YACkB,UAA4B,EAC5B,MAAoB,EACpB,aAGR,EACQ,IAAgC,EAChC,OAAkC,EACnC,eAAe,IAAI,gCAAiB,EAA2B;QAR9D,eAAU,GAAV,UAAU,CAAkB;QAC5B,WAAM,GAAN,MAAM,CAAc;QACpB,kBAAa,GAAb,aAAa,C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IAAI,EAAE,KAAK;gBACX,KAAK,EAAE;oBACN,MAAM;oBACN,KAAK,EAAE,MAAM;iBACb;aACD,CAAC;YAEF,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,eAAe,CAAC,CAAC;YAExC,MAAM,KAAK,GAAkB,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC;YACpD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC9E,CAAC,CAAC;QAEF,OAAO,EAAE,IAAI,EAAE,CAAC;IACjB,CAAC;CACD;AAzTD,sDAyTC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport { ValueType, IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\n\nimport {\n\tIntervalCollectionTypeLocalValue,\n\tmakeSerializable,\n} from \"./IntervalCollectionValues.js\";\nimport {\n\ttype IntervalCollection,\n\treservedIntervalIdKey,\n\ttoOptionalSequencePlace,\n\ttoSequencePlace,\n} from \"./intervalCollection.js\";\nimport {\n\tIIntervalCollectionType,\n\tIIntervalCollectionTypeOperationValue,\n\tIMapMessageLocalMetadata,\n\tISerializableIntervalCollection,\n\tISharedDefaultMapEvents,\n\tIValueChanged,\n\t// eslint-disable-next-line import/no-deprecated\n\tIValueOpEmitter,\n\tSequenceOptions,\n} from \"./intervalCollectionMapInterfaces.js\";\nimport {\n\ttype ISerializableInterval,\n\tIntervalDeltaOpType,\n\tSerializedIntervalDelta,\n} from \"./intervals/index.js\";\n\nfunction isMapOperation(op: unknown): op is IMapOperation {\n\treturn typeof op === \"object\" && op !== null && \"type\" in op && op.type === \"act\";\n}\n\n/**\n * Description of a map delta operation\n */\nexport interface IMapOperation {\n\t/**\n\t * String identifier of the operation type.\n\t */\n\ttype: \"act\";\n\n\t/**\n\t * Map key being modified.\n\t */\n\tkey: string;\n\n\t/**\n\t * Value of the operation, specific to the value type.\n\t */\n\tvalue: IIntervalCollectionTypeOperationValue;\n}\n/**\n * Defines the in-memory object structure to be used for the conversion to/from serialized.\n * Directly used in JSON.stringify, direct result from JSON.parse\n */\nexport interface IMapDataObjectSerializable {\n\t[key: string]: ISerializableIntervalCollection;\n}\n\n/**\n * A DefaultMap is a map-like distributed data structure, supporting operations on values stored by\n * string key locations.\n *\n * Creation of values is implicit on access (either via `get` or a remote op application referring to\n * a collection that wasn't previously known)\n */\nexport class IntervalCollectionMap<T extends ISerializableInterval> {\n\t/**\n\t * The number of key/value pairs stored in the map.\n\t */\n\tpublic get size(): number {\n\t\treturn this.data.size;\n\t}\n\n\t/**\n\t * Mapping of op types to message handlers.\n\t */\n\tprivate readonly messageHandler = {\n\t\tprocess: (\n\t\t\top: IMapOperation,\n\t\t\tlocal: boolean,\n\t\t\tmessage: ISequencedDocumentMessage,\n\t\t\tlocalOpMetadata: IMapMessageLocalMetadata,\n\t\t) => {\n\t\t\tconst localValue = this.data.get(op.key) ?? this.createCore(op.key, local);\n\t\t\tconst handler = localValue.getOpHandler(op.value.opName);\n\t\t\tconst previousValue = localValue.value;\n\t\t\tconst translatedValue = op.value.value as any;\n\t\t\thandler.process(previousValue, translatedValue, local, message, localOpMetadata);\n\t\t\tconst event: IValueChanged = { key: op.key, previousValue };\n\t\t\tthis.eventEmitter.emit(\"valueChanged\", event, local, message, this.eventEmitter);\n\t\t},\n\t\tsubmit: (op: IMapOperation, localOpMetadata: IMapMessageLocalMetadata) => {\n\t\t\tthis.submitMessage(op, localOpMetadata);\n\t\t},\n\t\tresubmit: (op: IMapOperation, localOpMetadata: IMapMessageLocalMetadata) => {\n\t\t\tconst localValue = this.data.get(op.key);\n\n\t\t\tassert(localValue !== undefined, 0x3f8 /* Local value expected on resubmission */);\n\n\t\t\tconst handler = localValue.getOpHandler(op.value.opName);\n\t\t\tconst rebased = handler.rebase(localValue.value, op.value, localOpMetadata);\n\t\t\tif (rebased !== undefined) {\n\t\t\t\tconst { rebasedOp, rebasedLocalOpMetadata } = rebased;\n\t\t\t\tthis.submitMessage({ ...op, value: rebasedOp }, rebasedLocalOpMetadata);\n\t\t\t}\n\t\t},\n\t};\n\n\t/**\n\t * The in-memory data the map is storing.\n\t */\n\tprivate readonly data = new Map<string, IntervalCollectionTypeLocalValue<T>>();\n\n\t/**\n\t * Create a new default map.\n\t * @param serializer - The serializer to serialize / parse handles\n\t * @param handle - The handle of the shared object using the kernel\n\t * @param submitMessage - A callback to submit a message through the shared object\n\t * @param type - The value type to create at values of this map\n\t * @param eventEmitter - The object that will emit map events\n\t */\n\tconstructor(\n\t\tprivate readonly serializer: IFluidSerializer,\n\t\tprivate readonly handle: IFluidHandle,\n\t\tprivate readonly submitMessage: (\n\t\t\top: IMapOperation,\n\t\t\tlocalOpMetadata: IMapMessageLocalMetadata,\n\t\t) => void,\n\t\tprivate readonly type: IIntervalCollectionType<T>,\n\t\tprivate readonly options?: Partial<SequenceOptions>,\n\t\tpublic readonly eventEmitter = new TypedEventEmitter<ISharedDefaultMapEvents>(),\n\t) {}\n\n\t/**\n\t * Get an iterator over the keys in this map.\n\t * @returns The iterator\n\t */\n\tpublic keys(): IterableIterator<string> {\n\t\treturn this.data.keys();\n\t}\n\n\t/**\n\t * Get an iterator over the values in this map.\n\t * @returns The iterator\n\t */\n\tpublic values(): IterableIterator<any> {\n\t\tconst localValuesIterator = this.data.values();\n\t\tconst iterator = {\n\t\t\tnext(): IteratorResult<any> {\n\t\t\t\tconst nextVal = localValuesIterator.next();\n\t\t\t\treturn nextVal.done\n\t\t\t\t\t? { value: undefined, done: true }\n\t\t\t\t\t: { value: nextVal.value.value, done: false }; // Unpack the stored value\n\t\t\t},\n\t\t\t[Symbol.iterator]() {\n\t\t\t\treturn this;\n\t\t\t},\n\t\t};\n\t\treturn iterator;\n\t}\n\t/**\n\t * {@inheritDoc ISharedMap.get}\n\t */\n\tpublic get(key: string): IntervalCollection<T> {\n\t\tconst localValue = this.data.get(key) ?? this.createCore(key, true);\n\n\t\treturn localValue.value;\n\t}\n\n\tpublic getSerializableStorage(serializer: IFluidSerializer): IMapDataObjectSerializable {\n\t\tconst serializableMapData: IMapDataObjectSerializable = {};\n\t\tthis.data.forEach((localValue, key) => {\n\t\t\tserializableMapData[key] = makeSerializable(localValue, serializer, this.handle);\n\t\t});\n\t\treturn serializableMapData;\n\t}\n\n\tpublic serialize(serializer: IFluidSerializer): string {\n\t\treturn JSON.stringify(this.getSerializableStorage(serializer));\n\t}\n\n\t/**\n\t * Populate the kernel with the given map data.\n\t *\n\t * @param serialized - A JSON string containing serialized map data\n\t */\n\tpublic populate(serialized: string): void {\n\t\tconst parsed = this.serializer.parse(serialized) as IMapDataObjectSerializable;\n\n\t\tfor (const [key, serializable] of Object.entries(parsed)) {\n\t\t\t// Back-compat: legacy documents may have handles to an intervalCollection map kernel.\n\t\t\t// These collections should be empty, and ValueTypes are no longer supported.\n\t\t\tif (\n\t\t\t\tserializable.type === ValueType[ValueType.Plain] ||\n\t\t\t\tserializable.type === ValueType[ValueType.Shared]\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Back-compat: Sequence previously arbitrarily prefixed all interval collection keys with\n\t\t\t// \"intervalCollections/\". This would burden users trying to iterate the collection and\n\t\t\t// access its value, as well as those trying to match a create message to its underlying\n\t\t\t// collection. See https://github.com/microsoft/FluidFramework/issues/10557 for more context.\n\t\t\tconst normalizedKey = key.startsWith(\"intervalCollections/\") ? key.substring(20) : key;\n\n\t\t\tconst localValue = {\n\t\t\t\tkey: normalizedKey,\n\t\t\t\tvalue: this.makeLocal(key, serializable),\n\t\t\t};\n\n\t\t\tthis.data.set(localValue.key, localValue.value);\n\t\t}\n\t}\n\n\t/**\n\t * Submit the given op if a handler is registered.\n\t * @param op - The operation to attempt to submit\n\t * @param localOpMetadata - The local metadata associated with the op. This is kept locally by the runtime\n\t * and not sent to the server. This will be sent back when this message is received back from the server. This is\n\t * also sent if we are asked to resubmit the message.\n\t * @returns True if the operation was submitted, false otherwise.\n\t */\n\tpublic tryResubmitMessage(op: unknown, localOpMetadata: IMapMessageLocalMetadata): boolean {\n\t\tif (isMapOperation(op)) {\n\t\t\tthis.messageHandler.resubmit(op, localOpMetadata);\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tpublic tryApplyStashedOp(op: unknown): boolean {\n\t\tif (isMapOperation(op)) {\n\t\t\tconst { value, key } = op;\n\t\t\tconst map = this.get(key);\n\n\t\t\tswitch (value.opName) {\n\t\t\t\tcase \"add\": {\n\t\t\t\t\tmap.add({\n\t\t\t\t\t\t// Todo: we should improve typing so we know add ops always have start and end\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\tstart: toSequencePlace(value.value.start!, value.value.startSide),\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\tend: toSequencePlace(value.value.end!, value.value.endSide),\n\t\t\t\t\t\tprops: value.value.properties,\n\t\t\t\t\t});\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tcase \"change\": {\n\t\t\t\t\tconst { [reservedIntervalIdKey]: id, ...props } = value.value.properties ?? {};\n\t\t\t\t\tmap.change(id, {\n\t\t\t\t\t\tstart: toOptionalSequencePlace(value.value.start, value.value.startSide),\n\t\t\t\t\t\tend: toOptionalSequencePlace(value.value.end, value.value.endSide),\n\t\t\t\t\t\tprops,\n\t\t\t\t\t});\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tcase \"delete\": {\n\t\t\t\t\tconst { [reservedIntervalIdKey]: id } = value.value.properties ?? {};\n\t\t\t\t\tmap.removeIntervalById(id);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"unknown ops should not be stashed\");\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Process the given op if a handler is registered.\n\t * @param message - The message to process\n\t * @param local - Whether the message originated from the local client\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t * @returns True if the operation was recognized and thus processed, false otherwise.\n\t *\n\t * @remarks\n\t * When this returns false and the caller doesn't handle the op itself, then the op could be from a different version of this code.\n\t * In such a case, not applying the op would result in this client becoming out of sync with clients that do handle the op\n\t * and could result in data corruption or data loss as well.\n\t * Therefore, in such cases the caller should typically throw an error, ensuring that this client treats the situation as data corruption\n\t * (since its data no longer matches what other clients think the data should be) and will avoid overriding document content or misleading the users into thinking their current state is accurate.\n\t */\n\tpublic tryProcessMessage(\n\t\top: unknown,\n\t\tlocal: boolean,\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocalOpMetadata: unknown,\n\t): boolean {\n\t\tif (isMapOperation(op)) {\n\t\t\tthis.messageHandler.process(\n\t\t\t\top,\n\t\t\t\tlocal,\n\t\t\t\tmessage,\n\t\t\t\tlocalOpMetadata as IMapMessageLocalMetadata,\n\t\t\t);\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Initializes a default ValueType at the provided key.\n\t * Should be used when a map operation incurs creation.\n\t * @param key - The key being initialized\n\t * @param local - Whether the message originated from the local client\n\t */\n\tprivate createCore(key: string, local: boolean): IntervalCollectionTypeLocalValue<T> {\n\t\tconst localValue = new IntervalCollectionTypeLocalValue(\n\t\t\tthis.type.factory.load(this.makeMapValueOpEmitter(key), undefined, this.options),\n\t\t\tthis.type,\n\t\t);\n\t\tconst previousValue = this.data.get(key);\n\t\tthis.data.set(key, localValue);\n\t\tconst event: IValueChanged = { key, previousValue };\n\t\tthis.eventEmitter.emit(\"create\", event, local, this.eventEmitter);\n\t\treturn localValue;\n\t}\n\n\t/**\n\t * The remote ISerializableValue we're receiving (either as a result of a load or an incoming set op) will\n\t * have the information we need to create a real object, but will not be the real object yet. For example,\n\t * we might know it's a map and the map's ID but not have the actual map or its data yet. makeLocal's\n\t * job is to convert that information into a real object for local usage.\n\t * @param key - The key that the caller intends to store the local value into (used for ops later). But\n\t * doesn't actually store the local value into that key. So better not lie!\n\t * @param serializable - The remote information that we can convert into a real object\n\t * @returns The local value that was produced\n\t */\n\tprivate makeLocal(\n\t\tkey: string,\n\t\tserializable: ISerializableIntervalCollection,\n\t): IntervalCollectionTypeLocalValue<T> {\n\t\tassert(\n\t\t\tserializable.type !== ValueType[ValueType.Plain] &&\n\t\t\t\tserializable.type !== ValueType[ValueType.Shared],\n\t\t\t0x2e1 /* \"Support for plain value types removed.\" */,\n\t\t);\n\n\t\tconst localValue = this.type.factory.load(\n\t\t\tthis.makeMapValueOpEmitter(key),\n\t\t\tserializable.value,\n\t\t\tthis.options,\n\t\t);\n\t\treturn new IntervalCollectionTypeLocalValue(localValue, this.type);\n\t}\n\n\t/**\n\t * Create an emitter for a value type to emit ops from the given key.\n\t * @param key - The key of the map that the value type will be stored on\n\t * @returns A value op emitter for the given key\n\t */\n\t// eslint-disable-next-line import/no-deprecated\n\tprivate makeMapValueOpEmitter(key: string): IValueOpEmitter {\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tconst emit: IValueOpEmitter[\"emit\"] = (\n\t\t\topName: IntervalDeltaOpType,\n\t\t\tpreviousValue: unknown,\n\t\t\tparams: SerializedIntervalDelta,\n\t\t\tlocalOpMetadata: IMapMessageLocalMetadata,\n\t\t): void => {\n\t\t\tconst op: IMapOperation = {\n\t\t\t\tkey,\n\t\t\t\ttype: \"act\",\n\t\t\t\tvalue: {\n\t\t\t\t\topName,\n\t\t\t\t\tvalue: params,\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tthis.submitMessage(op, localOpMetadata);\n\n\t\t\tconst event: IValueChanged = { key, previousValue };\n\t\t\tthis.eventEmitter.emit(\"valueChanged\", event, true, null, this.eventEmitter);\n\t\t};\n\n\t\treturn { emit };\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"intervalCollectionMap.js","sourceRoot":"","sources":["../src/intervalCollectionMap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AAGjE,kEAA6D;AAE7D,0EAA0F;AAE1F,+EAAiE;AACjE,mEAQiC;AAQjC,SAAS,cAAc,CAAC,EAAW;IAClC,OAAO,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,KAAK,IAAI,IAAI,MAAM,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,KAAK,KAAK,CAAC;AACnF,CAAC;AAiCD;;;;;;GAMG;AACH,MAAa,qBAAqB;IACjC;;OAEG;IACH,IAAW,IAAI;QACd,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACvB,CAAC;IAQD,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAED;;;;;;;OAOG;IACH,YACkB,UAA4B,EAC5B,MAAoB,EACpB,aAGR,EACQ,OAAkC;QANlC,eAAU,GAAV,UAAU,CAAkB;QAC5B,WAAM,GAAN,MAAM,CAAc;QACpB,kBAAa,GAAb,aAAa,CAGrB;QACQ,YAAO,GAAP,OAAO,CAA2B;QAzBpD;;WAEG;QACc,SAAI,GAAG,IAAI,GAAG,EAA8B,CAAC;QAE7C,iBAAY,GAAG,IAAI,gCAAiB,EAA+B,CAAC;IAqBlF,CAAC;IAEJ;;;OAGG;IACI,IAAI;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IAED;;;OAGG;IACI,MAAM;QACZ,MAAM,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QAC/C,MAAM,QAAQ,GAAG;YAChB,IAAI;gBACH,MAAM,OAAO,GAAG,mBAAmB,CAAC,IAAI,EAAE,CA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AAC,EAAE,EAAE,EAAE,EAAE,EAAE;YACV,CAAC;gBACA,IAAI,CAAC,aAAa,CACjB;oBACC,GAAG;oBACH,IAAI,EAAE,KAAK;oBACX,KAAK,EAAE,EAAE;iBACT,EACD,EAAE,CACF,CAAC;YACH,CAAC;QACF,CAAC,EACD,mBAAmB,IAAI,EAAE,EACzB,IAAI,CAAC,OAAO,CACZ,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAC/B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,0BAA0B,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAClF,OAAO,UAAU,CAAC;IACnB,CAAC;CACD;AA1PD,sDA0PC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport type { IEvent, IEventProvider } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport { ValueType, IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\n\nimport { makeSerializable } from \"./IntervalCollectionValues.js\";\nimport {\n\tIntervalCollection,\n\topsMap,\n\treservedIntervalIdKey,\n\ttoOptionalSequencePlace,\n\ttoSequencePlace,\n\ttype ISerializedIntervalCollectionV1,\n\ttype ISerializedIntervalCollectionV2,\n} from \"./intervalCollection.js\";\nimport {\n\tIIntervalCollectionTypeOperationValue,\n\tIMapMessageLocalMetadata,\n\tISerializableIntervalCollection,\n\tSequenceOptions,\n} from \"./intervalCollectionMapInterfaces.js\";\n\nfunction isMapOperation(op: unknown): op is IMapOperation {\n\treturn typeof op === \"object\" && op !== null && \"type\" in op && op.type === \"act\";\n}\n\n/**\n * Description of a map delta operation\n */\nexport interface IMapOperation {\n\t/**\n\t * String identifier of the operation type.\n\t */\n\ttype: \"act\";\n\n\t/**\n\t * Map key being modified.\n\t */\n\tkey: string;\n\n\t/**\n\t * Value of the operation, specific to the value type.\n\t */\n\tvalue: IIntervalCollectionTypeOperationValue;\n}\n/**\n * Defines the in-memory object structure to be used for the conversion to/from serialized.\n * Directly used in JSON.stringify, direct result from JSON.parse\n */\nexport interface IMapDataObjectSerializable {\n\t[key: string]: ISerializableIntervalCollection;\n}\n\nexport interface IntervalCollectionMapEvents extends IEvent {\n\t(event: \"createIntervalCollection\", listener: (key: string, local: boolean) => void): void;\n}\n\n/**\n * A DefaultMap is a map-like distributed data structure, supporting operations on values stored by\n * string key locations.\n *\n * Creation of values is implicit on access (either via `get` or a remote op application referring to\n * a collection that wasn't previously known)\n */\nexport class IntervalCollectionMap {\n\t/**\n\t * The number of key/value pairs stored in the map.\n\t */\n\tpublic get size(): number {\n\t\treturn this.data.size;\n\t}\n\n\t/**\n\t * The in-memory data the map is storing.\n\t */\n\tprivate readonly data = new Map<string, IntervalCollection>();\n\n\tprivate readonly eventEmitter = new TypedEventEmitter<IntervalCollectionMapEvents>();\n\tpublic get events(): IEventProvider<IntervalCollectionMapEvents> {\n\t\treturn this.eventEmitter;\n\t}\n\n\t/**\n\t * Create a new default map.\n\t * @param serializer - The serializer to serialize / parse handles\n\t * @param handle - The handle of the shared object using the kernel\n\t * @param submitMessage - A callback to submit a message through the shared object\n\t * @param type - The value type to create at values of this map\n\t * @param eventEmitter - The object that will emit map events\n\t */\n\tconstructor(\n\t\tprivate readonly serializer: IFluidSerializer,\n\t\tprivate readonly handle: IFluidHandle,\n\t\tprivate readonly submitMessage: (\n\t\t\top: IMapOperation,\n\t\t\tlocalOpMetadata: IMapMessageLocalMetadata,\n\t\t) => void,\n\t\tprivate readonly options?: Partial<SequenceOptions>,\n\t) {}\n\n\t/**\n\t * Get an iterator over the keys in this map.\n\t * @returns The iterator\n\t */\n\tpublic keys(): IterableIterator<string> {\n\t\treturn this.data.keys();\n\t}\n\n\t/**\n\t * Get an iterator over the values in this map.\n\t * @returns The iterator\n\t */\n\tpublic values(): IterableIterator<any> {\n\t\tconst localValuesIterator = this.data.values();\n\t\tconst iterator = {\n\t\t\tnext(): IteratorResult<any> {\n\t\t\t\tconst nextVal = localValuesIterator.next();\n\t\t\t\treturn nextVal.done\n\t\t\t\t\t? { value: undefined, done: true }\n\t\t\t\t\t: { value: nextVal.value, done: false }; // Unpack the stored value\n\t\t\t},\n\t\t\t[Symbol.iterator]() {\n\t\t\t\treturn this;\n\t\t\t},\n\t\t};\n\t\treturn iterator;\n\t}\n\t/**\n\t * {@inheritDoc ISharedMap.get}\n\t */\n\tpublic get(key: string): IntervalCollection {\n\t\tconst localValue = this.data.get(key) ?? this.createCore(key, true);\n\n\t\treturn localValue;\n\t}\n\n\tpublic serialize(serializer: IFluidSerializer): string {\n\t\tconst serializableMapData: IMapDataObjectSerializable = {};\n\t\tthis.data.forEach((localValue, key) => {\n\t\t\tserializableMapData[key] = makeSerializable(\n\t\t\t\tlocalValue,\n\t\t\t\tserializer,\n\t\t\t\tthis.handle,\n\t\t\t\tthis.options?.intervalSerializationFormat ?? \"2\",\n\t\t\t);\n\t\t});\n\t\treturn JSON.stringify(serializableMapData);\n\t}\n\n\t/**\n\t * Populate the kernel with the given map data.\n\t *\n\t * @param serialized - A JSON string containing serialized map data\n\t */\n\tpublic populate(serialized: string): void {\n\t\tconst parsed = this.serializer.parse(serialized) as IMapDataObjectSerializable;\n\n\t\tfor (const [key, serializable] of Object.entries(parsed)) {\n\t\t\t// Back-compat: legacy documents may have handles to an intervalCollection map kernel.\n\t\t\t// These collections should be empty, and ValueTypes are no longer supported.\n\t\t\tif (\n\t\t\t\tserializable.type === ValueType[ValueType.Plain] ||\n\t\t\t\tserializable.type === ValueType[ValueType.Shared]\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Back-compat: Sequence previously arbitrarily prefixed all interval collection keys with\n\t\t\t// \"intervalCollections/\". This would burden users trying to iterate the collection and\n\t\t\t// access its value, as well as those trying to match a create message to its underlying\n\t\t\t// collection. See https://github.com/microsoft/FluidFramework/issues/10557 for more context.\n\t\t\tconst normalizedKey = key.startsWith(\"intervalCollections/\") ? key.substring(20) : key;\n\n\t\t\tassert(\n\t\t\t\tserializable.type !== ValueType[ValueType.Plain] &&\n\t\t\t\t\tserializable.type !== ValueType[ValueType.Shared],\n\t\t\t\t0x2e1 /* \"Support for plain value types removed.\" */,\n\t\t\t);\n\n\t\t\tthis.createCore(normalizedKey, false, serializable.value);\n\t\t}\n\t}\n\n\t/**\n\t * Submit the given op if a handler is registered.\n\t * @param op - The operation to attempt to submit\n\t * @param localOpMetadata - The local metadata associated with the op. This is kept locally by the runtime\n\t * and not sent to the server. This will be sent back when this message is received back from the server. This is\n\t * also sent if we are asked to resubmit the message.\n\t * @returns True if the operation was submitted, false otherwise.\n\t */\n\tpublic tryResubmitMessage(op: unknown, localOpMetadata: IMapMessageLocalMetadata): boolean {\n\t\tif (isMapOperation(op)) {\n\t\t\tconst localValue = this.data.get(op.key);\n\n\t\t\tassert(localValue !== undefined, 0x3f8 /* Local value expected on resubmission */);\n\n\t\t\tconst handler = opsMap[op.value.opName];\n\t\t\tconst rebased = handler.rebase(localValue, op.value, localOpMetadata);\n\t\t\tif (rebased !== undefined) {\n\t\t\t\tconst { rebasedOp, rebasedLocalOpMetadata } = rebased;\n\t\t\t\tthis.submitMessage({ ...op, value: rebasedOp }, rebasedLocalOpMetadata);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tpublic tryApplyStashedOp(op: unknown): boolean {\n\t\tif (isMapOperation(op)) {\n\t\t\tconst { value, key } = op;\n\t\t\tconst map = this.get(key);\n\n\t\t\tswitch (value.opName) {\n\t\t\t\tcase \"add\": {\n\t\t\t\t\tmap.add({\n\t\t\t\t\t\t// Todo: we should improve typing so we know add ops always have start and end\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\tstart: toSequencePlace(value.value.start!, value.value.startSide),\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\tend: toSequencePlace(value.value.end!, value.value.endSide),\n\t\t\t\t\t\tprops: value.value.properties,\n\t\t\t\t\t});\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tcase \"change\": {\n\t\t\t\t\tconst { [reservedIntervalIdKey]: id, ...props } = value.value.properties ?? {};\n\t\t\t\t\tmap.change(id, {\n\t\t\t\t\t\tstart: toOptionalSequencePlace(value.value.start, value.value.startSide),\n\t\t\t\t\t\tend: toOptionalSequencePlace(value.value.end, value.value.endSide),\n\t\t\t\t\t\tprops,\n\t\t\t\t\t});\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tcase \"delete\": {\n\t\t\t\t\tconst { [reservedIntervalIdKey]: id } = value.value.properties ?? {};\n\t\t\t\t\tmap.removeIntervalById(id);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"unknown ops should not be stashed\");\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Process the given op if a handler is registered.\n\t * @param message - The message to process\n\t * @param local - Whether the message originated from the local client\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t * @returns True if the operation was recognized and thus processed, false otherwise.\n\t *\n\t * @remarks\n\t * When this returns false and the caller doesn't handle the op itself, then the op could be from a different version of this code.\n\t * In such a case, not applying the op would result in this client becoming out of sync with clients that do handle the op\n\t * and could result in data corruption or data loss as well.\n\t * Therefore, in such cases the caller should typically throw an error, ensuring that this client treats the situation as data corruption\n\t * (since its data no longer matches what other clients think the data should be) and will avoid overriding document content or misleading the users into thinking their current state is accurate.\n\t */\n\tpublic tryProcessMessage(\n\t\top: unknown,\n\t\tlocal: boolean,\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocalOpMetadata: unknown,\n\t): boolean {\n\t\tif (isMapOperation(op)) {\n\t\t\tconst localValue = this.data.get(op.key) ?? this.createCore(op.key, local);\n\t\t\tconst handler = opsMap[op.value.opName];\n\t\t\tconst previousValue = localValue;\n\t\t\tconst translatedValue = op.value.value as any;\n\t\t\thandler.process(\n\t\t\t\tpreviousValue,\n\t\t\t\ttranslatedValue,\n\t\t\t\tlocal,\n\t\t\t\tmessage,\n\t\t\t\tlocalOpMetadata as IMapMessageLocalMetadata,\n\t\t\t);\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Initializes a default ValueType at the provided key.\n\t * Should be used when a map operation incurs creation.\n\t * @param key - The key being initialized\n\t */\n\tprivate createCore(\n\t\tkey: string,\n\t\tlocal: boolean,\n\t\tserializedIntervals?: ISerializedIntervalCollectionV1 | ISerializedIntervalCollectionV2,\n\t): IntervalCollection {\n\t\tconst localValue = new IntervalCollection(\n\t\t\t(op, md) => {\n\t\t\t\t{\n\t\t\t\t\tthis.submitMessage(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\ttype: \"act\",\n\t\t\t\t\t\t\tvalue: op,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tmd,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t},\n\t\t\tserializedIntervals ?? [],\n\t\t\tthis.options,\n\t\t);\n\t\tthis.data.set(key, localValue);\n\t\tthis.eventEmitter.emit(\"createIntervalCollection\", key, local, this.eventEmitter);\n\t\treturn localValue;\n\t}\n}\n"]}
|
|
@@ -2,42 +2,10 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { IEventThisPlaceHolder } from "@fluidframework/core-interfaces";
|
|
6
5
|
import { ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
|
|
7
6
|
import type { IMergeTreeOptions } from "@fluidframework/merge-tree/internal";
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import { type ISerializableInterval, ISerializedInterval, IntervalDeltaOpType, IntervalOpType, SerializedIntervalDelta } from "./intervals/index.js";
|
|
11
|
-
/**
|
|
12
|
-
* Type of "valueChanged" event parameter.
|
|
13
|
-
*/
|
|
14
|
-
export interface IValueChanged {
|
|
15
|
-
/**
|
|
16
|
-
* The key storing the value that changed.
|
|
17
|
-
*/
|
|
18
|
-
key: string;
|
|
19
|
-
/**
|
|
20
|
-
* The value that was stored at the key prior to the change.
|
|
21
|
-
*/
|
|
22
|
-
previousValue: any;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Value types are given an IValueOpEmitter to emit their ops through the container type that holds them.
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
export interface IValueOpEmitter {
|
|
29
|
-
/**
|
|
30
|
-
* Called by the value type to emit a value type operation through the container type holding it.
|
|
31
|
-
* @param opName - Name of the emitted operation
|
|
32
|
-
* @param previousValue - JSONable previous value as defined by the value type @deprecated unused
|
|
33
|
-
* @param params - JSONable params for the operation as defined by the value type
|
|
34
|
-
* @param localOpMetadata - JSONable local metadata which should be submitted with the op
|
|
35
|
-
*/
|
|
36
|
-
emit(opName: IntervalOpType, previousValue: undefined, params: SerializedIntervalDelta, localOpMetadata: IMapMessageLocalMetadata): void;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @internal
|
|
40
|
-
*/
|
|
7
|
+
import type { IntervalCollection, ISerializedIntervalCollectionV1, ISerializedIntervalCollectionV2 } from "./intervalCollection.js";
|
|
8
|
+
import { ISerializedInterval, IntervalDeltaOpType, SerializedIntervalDelta } from "./intervals/index.js";
|
|
41
9
|
export interface IMapMessageLocalMetadata {
|
|
42
10
|
localSeq: number;
|
|
43
11
|
}
|
|
@@ -60,35 +28,16 @@ export interface SequenceOptions extends Pick<IMergeTreeOptions, "mergeTreeRefer
|
|
|
60
28
|
* The default value is false.
|
|
61
29
|
*/
|
|
62
30
|
intervalStickinessEnabled: boolean;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* A value factory is used to serialize/deserialize value types to a map
|
|
66
|
-
* @legacy
|
|
67
|
-
* @alpha
|
|
68
|
-
*/
|
|
69
|
-
export interface IIntervalCollectionFactory<T extends ISerializableInterval> {
|
|
70
|
-
/**
|
|
71
|
-
* Create a new value type. Used both in creation of new value types, as well as in loading existing ones
|
|
72
|
-
* from remote.
|
|
73
|
-
* @param emitter - Emitter object that the created value type will use to emit operations
|
|
74
|
-
* @param raw - Initialization parameters as defined by the value type
|
|
75
|
-
* @returns The new value type
|
|
76
|
-
*/
|
|
77
|
-
load(emitter: IValueOpEmitter, raw: any, options?: Partial<SequenceOptions>): IntervalCollection<T>;
|
|
78
31
|
/**
|
|
79
|
-
*
|
|
80
|
-
* loadable using the load method of its factory.
|
|
81
|
-
* @param value - The value type to serialize
|
|
82
|
-
* @returns The JSONable form of the value type
|
|
32
|
+
* This is for testing, and allows us to output intervals in the older formats.
|
|
83
33
|
*/
|
|
84
|
-
|
|
34
|
+
intervalSerializationFormat: "1" | "2";
|
|
85
35
|
}
|
|
86
36
|
/**
|
|
87
37
|
* Defines an operation that a value type is able to handle.
|
|
88
|
-
*
|
|
89
|
-
* @alpha
|
|
38
|
+
*
|
|
90
39
|
*/
|
|
91
|
-
export interface IIntervalCollectionOperation
|
|
40
|
+
export interface IIntervalCollectionOperation {
|
|
92
41
|
/**
|
|
93
42
|
* Performs the actual processing on the incoming operation.
|
|
94
43
|
* @param value - The current value stored at the given key, which should be the value type
|
|
@@ -97,7 +46,7 @@ export interface IIntervalCollectionOperation<T extends ISerializableInterval> {
|
|
|
97
46
|
* @param message - The operation itself
|
|
98
47
|
* @param localOpMetadata - any local metadata submitted by `IValueOpEmitter.emit`.
|
|
99
48
|
*/
|
|
100
|
-
process(value: IntervalCollection
|
|
49
|
+
process(value: IntervalCollection, params: ISerializedInterval, local: boolean, message: ISequencedDocumentMessage | undefined, localOpMetadata: IMapMessageLocalMetadata | undefined): void;
|
|
101
50
|
/**
|
|
102
51
|
* Rebases an `op` on `value` from its original perspective (ref/local seq) to the current
|
|
103
52
|
* perspective. Should be invoked on reconnection.
|
|
@@ -106,31 +55,11 @@ export interface IIntervalCollectionOperation<T extends ISerializableInterval> {
|
|
|
106
55
|
* @param localOpMetadata - Any local metadata that was originally submitted with the op.
|
|
107
56
|
* @returns A rebased version of the op and any local metadata that should be submitted with it.
|
|
108
57
|
*/
|
|
109
|
-
rebase(value: IntervalCollection
|
|
58
|
+
rebase(value: IntervalCollection, op: IIntervalCollectionTypeOperationValue, localOpMetadata: IMapMessageLocalMetadata): {
|
|
110
59
|
rebasedOp: IIntervalCollectionTypeOperationValue;
|
|
111
60
|
rebasedLocalOpMetadata: IMapMessageLocalMetadata;
|
|
112
61
|
} | undefined;
|
|
113
62
|
}
|
|
114
|
-
/**
|
|
115
|
-
* Defines a value type that can be registered on a container type.
|
|
116
|
-
*/
|
|
117
|
-
export interface IIntervalCollectionType<T extends ISerializableInterval> {
|
|
118
|
-
/**
|
|
119
|
-
* Name of the value type.
|
|
120
|
-
*/
|
|
121
|
-
name: string;
|
|
122
|
-
/**
|
|
123
|
-
* Factory method used to convert to/from a JSON form of the type.
|
|
124
|
-
*/
|
|
125
|
-
factory: IIntervalCollectionFactory<T>;
|
|
126
|
-
/**
|
|
127
|
-
* Operations that can be applied to the value type.
|
|
128
|
-
*/
|
|
129
|
-
ops: Map<IntervalOpType, IIntervalCollectionOperation<T>>;
|
|
130
|
-
}
|
|
131
|
-
export interface ISharedDefaultMapEvents extends ISharedObjectEvents {
|
|
132
|
-
(event: "valueChanged" | "create", listener: (changed: IValueChanged, local: boolean, target: IEventThisPlaceHolder) => void): void;
|
|
133
|
-
}
|
|
134
63
|
/**
|
|
135
64
|
* The _ready-for-serialization_ format of values contained in DDS contents. This allows us to use
|
|
136
65
|
* ISerializableValue.type to understand whether they're storing a Plain JS object, a SharedObject, or a value type.
|
|
@@ -146,11 +75,11 @@ export interface ISerializableIntervalCollection {
|
|
|
146
75
|
/**
|
|
147
76
|
* A type annotation to help indicate how the value serializes.
|
|
148
77
|
*/
|
|
149
|
-
type:
|
|
78
|
+
type: "sharedStringIntervalCollection";
|
|
150
79
|
/**
|
|
151
80
|
* The JSONable representation of the value.
|
|
152
81
|
*/
|
|
153
|
-
value:
|
|
82
|
+
value: ISerializedIntervalCollectionV1 | ISerializedIntervalCollectionV2;
|
|
154
83
|
}
|
|
155
84
|
export interface ISerializedIntervalCollection {
|
|
156
85
|
/**
|
|
@@ -169,8 +98,6 @@ export interface ISerializedIntervalCollection {
|
|
|
169
98
|
* value is whatever params the ValueType needs to complete that operation. Similar to ISerializableValue, it is
|
|
170
99
|
* serializable via JSON.stringify/parse but differs in that it has no equivalency with an in-memory value - rather
|
|
171
100
|
* it just describes an operation to be applied to an already-in-memory value.
|
|
172
|
-
* @legacy
|
|
173
|
-
* @alpha
|
|
174
101
|
*/
|
|
175
102
|
export interface IIntervalCollectionTypeOperationValue {
|
|
176
103
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intervalCollectionMapInterfaces.d.ts","sourceRoot":"","sources":["../src/intervalCollectionMapInterfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"intervalCollectionMapInterfaces.d.ts","sourceRoot":"","sources":["../src/intervalCollectionMapInterfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AACxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAE7E,OAAO,KAAK,EACX,kBAAkB,EAClB,+BAA+B,EAC/B,+BAA+B,EAC/B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,E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 @@
|
|
|
1
|
-
{"version":3,"file":"intervalCollectionMapInterfaces.js","sourceRoot":"","sources":["../src/intervalCollectionMapInterfaces.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {
|
|
1
|
+
{"version":3,"file":"intervalCollectionMapInterfaces.js","sourceRoot":"","sources":["../src/intervalCollectionMapInterfaces.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport type { IMergeTreeOptions } from \"@fluidframework/merge-tree/internal\";\n\nimport type {\n\tIntervalCollection,\n\tISerializedIntervalCollectionV1,\n\tISerializedIntervalCollectionV2,\n} from \"./intervalCollection.js\";\nimport {\n\tISerializedInterval,\n\tIntervalDeltaOpType,\n\tSerializedIntervalDelta,\n} from \"./intervals/index.js\";\n\nexport interface IMapMessageLocalMetadata {\n\tlocalSeq: number;\n}\n\n/**\n * Optional flags that configure options for sequence DDSs\n * @internal\n */\nexport interface SequenceOptions\n\textends Pick<\n\t\tIMergeTreeOptions,\n\t\t| \"mergeTreeReferencesCanSlideToEndpoint\"\n\t\t| \"mergeTreeEnableObliterate\"\n\t\t| \"mergeTreeEnableSidedObliterate\"\n\t\t| \"mergeTreeEnableAnnotateAdjust\"\n\t> {\n\t/**\n\t * Enable the ability to use interval APIs that rely on positions before and\n\t * after individual characters, referred to as \"sides\". See {@link @fluidframework/merge-tree#SequencePlace}\n\t * for additional context.\n\t *\n\t * This flag must be enabled to pass instances of {@link @fluidframework/merge-tree#SequencePlace} to\n\t * any IIntervalCollection API.\n\t *\n\t * Also see the feature flag `mergeTreeReferencesCanSlideToEndpoint` to allow\n\t * endpoints to slide to the special endpoint segments.\n\t *\n\t * The default value is false.\n\t */\n\tintervalStickinessEnabled: boolean;\n\n\t/**\n\t * This is for testing, and allows us to output intervals in the older formats.\n\t */\n\tintervalSerializationFormat: \"1\" | \"2\";\n}\n\n/**\n * Defines an operation that a value type is able to handle.\n *\n */\nexport interface IIntervalCollectionOperation {\n\t/**\n\t * Performs the actual processing on the incoming operation.\n\t * @param value - The current value stored at the given key, which should be the value type\n\t * @param params - The params on the incoming operation\n\t * @param local - Whether the operation originated from this client\n\t * @param message - The operation itself\n\t * @param localOpMetadata - any local metadata submitted by `IValueOpEmitter.emit`.\n\t */\n\tprocess(\n\t\tvalue: IntervalCollection,\n\t\tparams: ISerializedInterval,\n\t\tlocal: boolean,\n\t\tmessage: ISequencedDocumentMessage | undefined,\n\t\tlocalOpMetadata: IMapMessageLocalMetadata | undefined,\n\t): void;\n\n\t/**\n\t * Rebases an `op` on `value` from its original perspective (ref/local seq) to the current\n\t * perspective. Should be invoked on reconnection.\n\t * @param value - The current value stored at the given key, which should be the value type.\n\t * @param op - The op to be rebased.\n\t * @param localOpMetadata - Any local metadata that was originally submitted with the op.\n\t * @returns A rebased version of the op and any local metadata that should be submitted with it.\n\t */\n\trebase(\n\t\tvalue: IntervalCollection,\n\t\top: IIntervalCollectionTypeOperationValue,\n\t\tlocalOpMetadata: IMapMessageLocalMetadata,\n\t):\n\t\t| {\n\t\t\t\trebasedOp: IIntervalCollectionTypeOperationValue;\n\t\t\t\trebasedLocalOpMetadata: IMapMessageLocalMetadata;\n\t\t }\n\t\t| undefined;\n}\n\n/**\n * The _ready-for-serialization_ format of values contained in DDS contents. This allows us to use\n * ISerializableValue.type to understand whether they're storing a Plain JS object, a SharedObject, or a value type.\n * Note that the in-memory equivalent of ISerializableValue is ILocalValue (similarly holding a type, but with\n * the _in-memory representation_ of the value instead). An ISerializableValue is what gets passed to\n * JSON.stringify and comes out of JSON.parse. This format is used both for snapshots (loadCore/populate)\n * and ops (set).\n *\n * The DefaultMap implementation for sequence has been specialized to only support a single ValueType, which serializes\n * and deserializes via .store() and .load().\n */\nexport interface ISerializableIntervalCollection {\n\t/**\n\t * A type annotation to help indicate how the value serializes.\n\t */\n\ttype: \"sharedStringIntervalCollection\";\n\n\t/**\n\t * The JSONable representation of the value.\n\t */\n\tvalue: ISerializedIntervalCollectionV1 | ISerializedIntervalCollectionV2;\n}\n\nexport interface ISerializedIntervalCollection {\n\t/**\n\t * A type annotation to help indicate how the value serializes.\n\t */\n\ttype: string;\n\n\t/**\n\t * String representation of the value.\n\t */\n\tvalue: string | undefined;\n}\n\n/**\n * ValueTypes handle ops slightly differently from SharedObjects or plain JS objects. Since the Map/Directory doesn't\n * know how to handle the ValueType's ops, those ops are instead passed along to the ValueType for processing.\n * IValueTypeOperationValue is that passed-along op. The opName on it is the ValueType-specific operation and the\n * value is whatever params the ValueType needs to complete that operation. Similar to ISerializableValue, it is\n * serializable via JSON.stringify/parse but differs in that it has no equivalency with an in-memory value - rather\n * it just describes an operation to be applied to an already-in-memory value.\n */\nexport interface IIntervalCollectionTypeOperationValue {\n\t/**\n\t * The name of the operation.\n\t */\n\topName: IntervalDeltaOpType;\n\n\t/**\n\t * The payload that is submitted along with the operation.\n\t */\n\tvalue: SerializedIntervalDelta;\n}\n"]}
|