@fluidframework/sequence 2.0.0-internal.1.4.2 → 2.0.0-internal.2.0.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.
Files changed (117) hide show
  1. package/dist/defaultMap.d.ts.map +1 -1
  2. package/dist/defaultMap.js +1 -0
  3. package/dist/defaultMap.js.map +1 -1
  4. package/dist/index.d.ts +4 -5
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -4
  7. package/dist/index.js.map +1 -1
  8. package/dist/intervalCollection.d.ts +271 -34
  9. package/dist/intervalCollection.d.ts.map +1 -1
  10. package/dist/intervalCollection.js +343 -97
  11. package/dist/intervalCollection.js.map +1 -1
  12. package/dist/intervalTree.d.ts +72 -0
  13. package/dist/intervalTree.d.ts.map +1 -0
  14. package/dist/intervalTree.js +91 -0
  15. package/dist/intervalTree.js.map +1 -0
  16. package/dist/packageVersion.d.ts +1 -1
  17. package/dist/packageVersion.js +1 -1
  18. package/dist/packageVersion.js.map +1 -1
  19. package/dist/sequence.d.ts +66 -15
  20. package/dist/sequence.d.ts.map +1 -1
  21. package/dist/sequence.js +73 -19
  22. package/dist/sequence.js.map +1 -1
  23. package/dist/sequenceDeltaEvent.d.ts +15 -1
  24. package/dist/sequenceDeltaEvent.d.ts.map +1 -1
  25. package/dist/sequenceDeltaEvent.js +2 -1
  26. package/dist/sequenceDeltaEvent.js.map +1 -1
  27. package/dist/sequenceFactory.d.ts +0 -89
  28. package/dist/sequenceFactory.d.ts.map +1 -1
  29. package/dist/sequenceFactory.js +2 -142
  30. package/dist/sequenceFactory.js.map +1 -1
  31. package/dist/sharedIntervalCollection.d.ts +0 -6
  32. package/dist/sharedIntervalCollection.d.ts.map +1 -1
  33. package/dist/sharedIntervalCollection.js +0 -7
  34. package/dist/sharedIntervalCollection.js.map +1 -1
  35. package/dist/sharedSequence.d.ts +2 -2
  36. package/dist/sharedString.d.ts +16 -15
  37. package/dist/sharedString.d.ts.map +1 -1
  38. package/dist/sharedString.js +96 -15
  39. package/dist/sharedString.js.map +1 -1
  40. package/lib/defaultMap.d.ts.map +1 -1
  41. package/lib/defaultMap.js +1 -0
  42. package/lib/defaultMap.js.map +1 -1
  43. package/lib/index.d.ts +4 -5
  44. package/lib/index.d.ts.map +1 -1
  45. package/lib/index.js +2 -4
  46. package/lib/index.js.map +1 -1
  47. package/lib/intervalCollection.d.ts +271 -34
  48. package/lib/intervalCollection.d.ts.map +1 -1
  49. package/lib/intervalCollection.js +341 -98
  50. package/lib/intervalCollection.js.map +1 -1
  51. package/lib/intervalTree.d.ts +72 -0
  52. package/lib/intervalTree.d.ts.map +1 -0
  53. package/lib/intervalTree.js +86 -0
  54. package/lib/intervalTree.js.map +1 -0
  55. package/lib/packageVersion.d.ts +1 -1
  56. package/lib/packageVersion.js +1 -1
  57. package/lib/packageVersion.js.map +1 -1
  58. package/lib/sequence.d.ts +66 -15
  59. package/lib/sequence.d.ts.map +1 -1
  60. package/lib/sequence.js +73 -19
  61. package/lib/sequence.js.map +1 -1
  62. package/lib/sequenceDeltaEvent.d.ts +15 -1
  63. package/lib/sequenceDeltaEvent.d.ts.map +1 -1
  64. package/lib/sequenceDeltaEvent.js +2 -1
  65. package/lib/sequenceDeltaEvent.js.map +1 -1
  66. package/lib/sequenceFactory.d.ts +0 -89
  67. package/lib/sequenceFactory.d.ts.map +1 -1
  68. package/lib/sequenceFactory.js +1 -139
  69. package/lib/sequenceFactory.js.map +1 -1
  70. package/lib/sharedIntervalCollection.d.ts +0 -6
  71. package/lib/sharedIntervalCollection.d.ts.map +1 -1
  72. package/lib/sharedIntervalCollection.js +0 -7
  73. package/lib/sharedIntervalCollection.js.map +1 -1
  74. package/lib/sharedSequence.d.ts +2 -2
  75. package/lib/sharedString.d.ts +16 -15
  76. package/lib/sharedString.d.ts.map +1 -1
  77. package/lib/sharedString.js +97 -16
  78. package/lib/sharedString.js.map +1 -1
  79. package/package.json +99 -27
  80. package/src/defaultMap.ts +3 -0
  81. package/src/index.ts +4 -4
  82. package/src/intervalCollection.ts +486 -143
  83. package/src/intervalTree.ts +166 -0
  84. package/src/packageVersion.ts +1 -1
  85. package/src/sequence.ts +86 -30
  86. package/src/sequenceDeltaEvent.ts +18 -4
  87. package/src/sequenceFactory.ts +2 -163
  88. package/src/sharedIntervalCollection.ts +0 -11
  89. package/src/sharedString.ts +120 -23
  90. package/tsconfig.json +0 -1
  91. package/dist/sharedNumberSequence.d.ts +0 -50
  92. package/dist/sharedNumberSequence.d.ts.map +0 -1
  93. package/dist/sharedNumberSequence.js +0 -61
  94. package/dist/sharedNumberSequence.js.map +0 -1
  95. package/dist/sharedObjectSequence.d.ts +0 -50
  96. package/dist/sharedObjectSequence.d.ts.map +0 -1
  97. package/dist/sharedObjectSequence.js +0 -61
  98. package/dist/sharedObjectSequence.js.map +0 -1
  99. package/dist/sparsematrix.d.ts +0 -152
  100. package/dist/sparsematrix.d.ts.map +0 -1
  101. package/dist/sparsematrix.js +0 -343
  102. package/dist/sparsematrix.js.map +0 -1
  103. package/lib/sharedNumberSequence.d.ts +0 -50
  104. package/lib/sharedNumberSequence.d.ts.map +0 -1
  105. package/lib/sharedNumberSequence.js +0 -57
  106. package/lib/sharedNumberSequence.js.map +0 -1
  107. package/lib/sharedObjectSequence.d.ts +0 -50
  108. package/lib/sharedObjectSequence.d.ts.map +0 -1
  109. package/lib/sharedObjectSequence.js +0 -57
  110. package/lib/sharedObjectSequence.js.map +0 -1
  111. package/lib/sparsematrix.d.ts +0 -152
  112. package/lib/sparsematrix.d.ts.map +0 -1
  113. package/lib/sparsematrix.js +0 -334
  114. package/lib/sparsematrix.js.map +0 -1
  115. package/src/sharedNumberSequence.ts +0 -62
  116. package/src/sharedObjectSequence.ts +0 -62
  117. package/src/sparsematrix.ts +0 -434
@@ -0,0 +1,72 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IIntegerRange, RBNode, IRBAugmentation, IRBMatcher, RedBlackTree } from "@fluidframework/merge-tree";
6
+ import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
7
+ export interface AugmentedIntervalNode {
8
+ minmax: IInterval;
9
+ }
10
+ export declare const integerRangeToString: (range: IIntegerRange) => string;
11
+ /**
12
+ * Basic interval abstraction
13
+ */
14
+ export interface IInterval {
15
+ /**
16
+ * @returns a new interval object with identical semantics.
17
+ */
18
+ clone(): IInterval;
19
+ /**
20
+ * Compares this interval to `b` with standard comparator semantics:
21
+ * - returns -1 if this is less than `b`
22
+ * - returns 1 if this is greater than `b`
23
+ * - returns 0 if this is equivalent to `b`
24
+ * @param b - Interval to compare against
25
+ */
26
+ compare(b: IInterval): number;
27
+ /**
28
+ * Compares the start endpoint of this interval to `b`'s start endpoint.
29
+ * Standard comparator semantics apply.
30
+ * @param b - Interval to compare against
31
+ */
32
+ compareStart(b: IInterval): number;
33
+ /**
34
+ * Compares the end endpoint of this interval to `b`'s end endpoint.
35
+ * Standard comparator semantics apply.
36
+ * @param b - Interval to compare against
37
+ */
38
+ compareEnd(b: IInterval): number;
39
+ /**
40
+ * Modifies one or more of the endpoints of this interval, returning a new interval representing the result.
41
+ * @internal
42
+ */
43
+ modify(label: string, start: number | undefined, end: number | undefined, op?: ISequencedDocumentMessage, localSeq?: number): IInterval | undefined;
44
+ /**
45
+ * @returns whether this interval overlaps with `b`.
46
+ * Since intervals are inclusive, this includes cases where endpoints are equal.
47
+ */
48
+ overlaps(b: IInterval): boolean;
49
+ /**
50
+ * Unions this interval with `b`, returning a new interval.
51
+ * The union operates as a convex hull, i.e. if the two intervals are disjoint, the return value includes
52
+ * intermediate values between the two intervals.
53
+ * @internal
54
+ */
55
+ union(b: IInterval): IInterval;
56
+ }
57
+ export declare type IntervalNode<T extends IInterval> = RBNode<T, AugmentedIntervalNode>;
58
+ export declare type IntervalConflictResolver<TInterval> = (a: TInterval, b: TInterval) => TInterval;
59
+ export declare class IntervalTree<T extends IInterval> implements IRBAugmentation<T, AugmentedIntervalNode>, IRBMatcher<T, AugmentedIntervalNode> {
60
+ intervals: RedBlackTree<T, AugmentedIntervalNode>;
61
+ remove(x: T): void;
62
+ removeExisting(x: T): void;
63
+ put(x: T, conflict?: IntervalConflictResolver<T>): void;
64
+ map(fn: (x: T) => void): void;
65
+ mapUntil(fn: (X: T) => boolean): void;
66
+ mapBackward(fn: (x: T) => void): void;
67
+ match(x: T): RBNode<T, AugmentedIntervalNode>[];
68
+ matchNode(node: IntervalNode<T> | undefined, key: T): boolean;
69
+ continueSubtree(node: IntervalNode<T> | undefined, key: T): boolean;
70
+ update(node: IntervalNode<T>): void;
71
+ }
72
+ //# sourceMappingURL=intervalTree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intervalTree.d.ts","sourceRoot":"","sources":["../src/intervalTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,aAAa,EACb,MAAM,EACN,eAAe,EACf,UAAU,EACV,YAAY,EAGf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAEjF,MAAM,WAAW,qBAAqB;IAClC,MAAM,EAAE,SAAS,CAAC;CACrB;AAED,eAAO,MAAM,oBAAoB,UAAW,aAAa,WAAoC,CAAC;AAE9F;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB;;OAEG;IACH,KAAK,IAAI,SAAS,CAAC;IACnB;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IAC9B;;;;OAIG;IACH,YAAY,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IACnC;;;;OAIG;IACH,UAAU,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IACjC;;;OAGG;IACH,MAAM,CACF,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,EAAE,CAAC,EAAE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+1,86 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { RedBlackTree, } from "@fluidframework/merge-tree";
6
+ export const integerRangeToString = (range) => `[${range.start},${range.end})`;
7
+ const intervalComparer = (a, b) => a.compare(b);
8
+ export class IntervalTree {
9
+ constructor() {
10
+ this.intervals = new RedBlackTree(intervalComparer, this);
11
+ }
12
+ remove(x) {
13
+ this.intervals.remove(x);
14
+ }
15
+ removeExisting(x) {
16
+ this.intervals.removeExisting(x);
17
+ }
18
+ put(x, conflict) {
19
+ let rbConflict;
20
+ if (conflict) {
21
+ rbConflict = (key, currentKey) => {
22
+ const ival = conflict(key, currentKey);
23
+ return {
24
+ key: ival,
25
+ };
26
+ };
27
+ }
28
+ this.intervals.put(x, { minmax: x.clone() }, rbConflict);
29
+ }
30
+ map(fn) {
31
+ const actions = {
32
+ infix: (node) => {
33
+ fn(node.key);
34
+ return true;
35
+ },
36
+ showStructure: true,
37
+ };
38
+ this.intervals.walk(actions);
39
+ }
40
+ mapUntil(fn) {
41
+ const actions = {
42
+ infix: (node) => {
43
+ return fn(node.key);
44
+ },
45
+ showStructure: true,
46
+ };
47
+ this.intervals.walk(actions);
48
+ }
49
+ mapBackward(fn) {
50
+ const actions = {
51
+ infix: (node) => {
52
+ fn(node.key);
53
+ return true;
54
+ },
55
+ showStructure: true,
56
+ };
57
+ this.intervals.walkBackward(actions);
58
+ }
59
+ // TODO: toString()
60
+ match(x) {
61
+ return this.intervals.gather(x, this);
62
+ }
63
+ matchNode(node, key) {
64
+ return !!node && node.key.overlaps(key);
65
+ }
66
+ continueSubtree(node, key) {
67
+ return !!node && node.data.minmax.overlaps(key);
68
+ }
69
+ update(node) {
70
+ if (node.left && node.right) {
71
+ node.data.minmax = node.key.union(node.left.data.minmax.union(node.right.data.minmax));
72
+ }
73
+ else {
74
+ if (node.left) {
75
+ node.data.minmax = node.key.union(node.left.data.minmax);
76
+ }
77
+ else if (node.right) {
78
+ node.data.minmax = node.key.union(node.right.data.minmax);
79
+ }
80
+ else {
81
+ node.data.minmax = node.key.clone();
82
+ }
83
+ }
84
+ }
85
+ }
86
+ //# sourceMappingURL=intervalTree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intervalTree.js","sourceRoot":"","sources":["../src/intervalTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAKH,YAAY,GAGf,MAAM,4BAA4B,CAAC;AAOpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAoB,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,GAAG,CAAC;AAuD9F,MAAM,gBAAgB,GAAG,CAAC,CAAY,EAAE,CAAY,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAMtE,MAAM,OAAO,YAAY;IAAzB;QAEW,cAAS,GAAG,IAAI,YAAY,CAA2B,gBAAgB,EAAE,IAAI,CAAC,CAAC;IAkF1F,CAAC;IAhFU,MAAM,CAAC,CAAI;QACd,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;IAEM,cAAc,CAAC,CAAI;QACtB,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC;IAEM,GAAG,CAAC,CAAI,EAAE,QAAsC;QACnD,IAAI,UAAgE,CAAC;QACrE,IAAI,QAAQ,EAAE;YACV,UAAU,GAAG,CAAC,GAAM,EAAE,UAAa,EAAE,EAAE;gBACnC,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;gBACvC,OAAO;oBACH,GAAG,EAAE,IAAI;iBACZ,CAAC;YACN,CAAC,CAAC;SACL;QACD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE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AI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACpD,CAAC;IAEM,MAAM,CAAC,IAAqB;QAC/B,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE;YACzB,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAC7B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;SAC5D;aAAM;YACH,IAAI,IAAI,CAAC,IAAI,EAAE;gBACX,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;aAC5D;iBAAM,IAAI,IAAI,CAAC,KAAK,EAAE;gBACnB,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;aAC7D;iBAAM;gBACH,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;aACvC;SACJ;IACL,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IIntegerRange,\n RBNode,\n IRBAugmentation,\n IRBMatcher,\n RedBlackTree,\n ConflictAction,\n RBNodeActions,\n} from \"@fluidframework/merge-tree\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\n\nexport interface AugmentedIntervalNode {\n minmax: IInterval;\n}\n\nexport const integerRangeToString = (range: IIntegerRange) => `[${range.start},${range.end})`;\n\n/**\n * Basic interval abstraction\n */\nexport interface IInterval {\n /**\n * @returns a new interval object with identical semantics.\n */\n clone(): IInterval;\n /**\n * Compares this interval to `b` with standard comparator semantics:\n * - returns -1 if this is less than `b`\n * - returns 1 if this is greater than `b`\n * - returns 0 if this is equivalent to `b`\n * @param b - Interval to compare against\n */\n compare(b: IInterval): number;\n /**\n * Compares the start endpoint of this interval to `b`'s start endpoint.\n * Standard comparator semantics apply.\n * @param b - Interval to compare against\n */\n compareStart(b: IInterval): number;\n /**\n * Compares the end endpoint of this interval to `b`'s end endpoint.\n * Standard comparator semantics apply.\n * @param b - Interval to compare against\n */\n compareEnd(b: IInterval): number;\n /**\n * Modifies one or more of the endpoints of this interval, returning a new interval representing the result.\n * @internal\n */\n modify(\n label: string,\n start: number | undefined,\n end: number | undefined,\n op?: ISequencedDocumentMessage,\n localSeq?: number\n ): IInterval | undefined;\n /**\n * @returns whether this interval overlaps with `b`.\n * Since intervals are inclusive, this includes cases where endpoints are equal.\n */\n overlaps(b: IInterval): boolean;\n /**\n * Unions this interval with `b`, returning a new interval.\n * The union operates as a convex hull, i.e. if the two intervals are disjoint, the return value includes\n * intermediate values between the two intervals.\n * @internal\n */\n union(b: IInterval): IInterval;\n}\n\nconst intervalComparer = (a: IInterval, b: IInterval) => a.compare(b);\n\nexport type IntervalNode<T extends IInterval> = RBNode<T, AugmentedIntervalNode>;\n\nexport type IntervalConflictResolver<TInterval> = (a: TInterval, b: TInterval) => TInterval;\n\nexport class IntervalTree<T extends IInterval> implements IRBAugmentation<T, AugmentedIntervalNode>,\n IRBMatcher<T, AugmentedIntervalNode> {\n public intervals = new RedBlackTree<T, AugmentedIntervalNode>(intervalComparer, this);\n\n public remove(x: T) {\n this.intervals.remove(x);\n }\n\n public removeExisting(x: T) {\n this.intervals.removeExisting(x);\n }\n\n public put(x: T, conflict?: IntervalConflictResolver<T>) {\n let rbConflict: ConflictAction<T, AugmentedIntervalNode> | undefined;\n if (conflict) {\n rbConflict = (key: T, currentKey: T) => {\n const ival = conflict(key, currentKey);\n return {\n key: ival,\n };\n };\n }\n this.intervals.put(x, { minmax: x.clone() }, rbConflict);\n }\n\n public map(fn: (x: T) => void) {\n const actions: RBNodeActions<T, AugmentedIntervalNode> = {\n infix: (node) => {\n fn(node.key);\n return true;\n },\n showStructure: true,\n };\n this.intervals.walk(actions);\n }\n\n public mapUntil(fn: (X: T) => boolean) {\n const actions: RBNodeActions<T, AugmentedIntervalNode> = {\n infix: (node) => {\n return fn(node.key);\n },\n showStructure: true,\n };\n this.intervals.walk(actions);\n }\n\n public mapBackward(fn: (x: T) => void) {\n const actions: RBNodeActions<T, AugmentedIntervalNode> = {\n infix: (node) => {\n fn(node.key);\n return true;\n },\n showStructure: true,\n };\n this.intervals.walkBackward(actions);\n }\n\n // TODO: toString()\n public match(x: T) {\n return this.intervals.gather(x, this);\n }\n\n public matchNode(node: IntervalNode<T> | undefined, key: T) {\n return !!node && node.key.overlaps(key);\n }\n\n public continueSubtree(node: IntervalNode<T> | undefined, key: T) {\n return !!node && node.data.minmax.overlaps(key);\n }\n\n public update(node: IntervalNode<T>) {\n if (node.left && node.right) {\n node.data.minmax = node.key.union(\n node.left.data.minmax.union(node.right.data.minmax));\n } else {\n if (node.left) {\n node.data.minmax = node.key.union(node.left.data.minmax);\n } else if (node.right) {\n node.data.minmax = node.key.union(node.right.data.minmax);\n } else {\n node.data.minmax = node.key.clone();\n }\n }\n }\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/sequence";
8
- export declare const pkgVersion = "2.0.0-internal.1.4.2";
8
+ export declare const pkgVersion = "2.0.0-internal.2.0.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluidframework/sequence";
8
- export const pkgVersion = "2.0.0-internal.1.4.2";
8
+ export const pkgVersion = "2.0.0-internal.2.0.0";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,0BAA0B,CAAC;AAClD,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/sequence\";\nexport const pkgVersion = \"2.0.0-internal.1.4.2\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,0BAA0B,CAAC;AAClD,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/sequence\";\nexport const pkgVersion = \"2.0.0-internal.2.0.0\";\n"]}
package/lib/sequence.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  import { Deferred } from "@fluidframework/common-utils";
6
6
  import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
7
7
  import { IChannelAttributes, IFluidDataStoreRuntime, IChannelStorageService } from "@fluidframework/datastore-definitions";
8
- import { Client, ICombiningOp, IJSONSegment, IMergeTreeGroupMsg, IMergeTreeOp, IMergeTreeRemoveMsg, IRelativePosition, ISegment, ISegmentAction, LocalReferencePosition, PropertySet, RangeStackMap, ReferencePosition, ReferenceType } from "@fluidframework/merge-tree";
8
+ import { Client, ICombiningOp, IJSONSegment, IMergeTreeGroupMsg, IMergeTreeOp, IMergeTreeRemoveMsg, IRelativePosition, ISegment, ISegmentAction, LocalReferencePosition, PropertySet, RangeStackMap, ReferencePosition, ReferenceType, MergeTreeRevertibleDriver } from "@fluidframework/merge-tree";
9
9
  import { IFluidSerializer, SharedObject, ISharedObjectEvents, SummarySerializer } from "@fluidframework/shared-object-base";
10
10
  import { IEventThisPlaceHolder } from "@fluidframework/common-definitions";
11
11
  import { ISummaryTreeWithStats, ITelemetryContext } from "@fluidframework/runtime-definitions";
@@ -50,13 +50,14 @@ export interface ISharedSegmentSequenceEvents extends ISharedObjectEvents {
50
50
  (event: "sequenceDelta", listener: (event: SequenceDeltaEvent, target: IEventThisPlaceHolder) => void): any;
51
51
  (event: "maintenance", listener: (event: SequenceMaintenanceEvent, target: IEventThisPlaceHolder) => void): any;
52
52
  }
53
- export declare abstract class SharedSegmentSequence<T extends ISegment> extends SharedObject<ISharedSegmentSequenceEvents> implements ISharedIntervalCollection<SequenceInterval> {
53
+ export declare abstract class SharedSegmentSequence<T extends ISegment> extends SharedObject<ISharedSegmentSequenceEvents> implements ISharedIntervalCollection<SequenceInterval>, MergeTreeRevertibleDriver {
54
54
  private readonly dataStoreRuntime;
55
55
  id: string;
56
56
  readonly segmentFromSpec: (spec: IJSONSegment) => ISegment;
57
57
  get loaded(): Promise<void>;
58
58
  private static createOpsFromDelta;
59
59
  protected client: Client;
60
+ /** `Deferred` that triggers once the object is loaded */
60
61
  protected loadedDeferred: Deferred<void>;
61
62
  private readonly loadedDeferredOutgoingOps;
62
63
  private deferIncomingOps;
@@ -70,9 +71,14 @@ export declare abstract class SharedSegmentSequence<T extends ISegment> extends
70
71
  */
71
72
  removeRange(start: number, end: number): IMergeTreeRemoveMsg;
72
73
  groupOperation(groupOp: IMergeTreeGroupMsg): void;
74
+ /**
75
+ * Finds the segment information (i.e. segment + offset) corresponding to a character position in the SharedString.
76
+ * If the position is past the end of the string, `segment` and `offset` on the returned object may be undefined.
77
+ * @param pos - Character position (index) into the current local view of the SharedString.
78
+ */
73
79
  getContainingSegment(pos: number): {
74
- segment: T;
75
- offset: number;
80
+ segment: T | undefined;
81
+ offset: number | undefined;
76
82
  };
77
83
  /**
78
84
  * Returns the length of the current sequence for the client
@@ -94,13 +100,28 @@ export declare abstract class SharedSegmentSequence<T extends ISegment> extends
94
100
  *
95
101
  */
96
102
  annotateRange(start: number, end: number, props: PropertySet, combiningOp?: ICombiningOp): void;
97
- getPropertiesAtPosition(pos: number): PropertySet;
103
+ getPropertiesAtPosition(pos: number): PropertySet | undefined;
98
104
  getRangeExtentsOfPosition(pos: number): {
99
- posStart: number;
100
- posAfterEnd: number;
105
+ posStart: number | undefined;
106
+ posAfterEnd: number | undefined;
101
107
  };
108
+ /**
109
+ * Creates a `LocalReferencePosition` on this SharedString. If the refType does not include
110
+ * ReferenceType.Transient, the returned reference will be added to the localRefs on the provided segment.
111
+ * @param segment - Segment to add the local reference on
112
+ * @param offset - Offset on the segment at which to place the local reference
113
+ * @param refType - ReferenceType for the created local reference
114
+ * @param properties - PropertySet to place on the created local reference
115
+ */
102
116
  createLocalReferencePosition(segment: T, offset: number, refType: ReferenceType, properties: PropertySet | undefined): LocalReferencePosition;
117
+ /**
118
+ * Resolves a `ReferencePosition` into a character position using this client's perspective.
119
+ */
103
120
  localReferencePositionToPosition(lref: ReferencePosition): number;
121
+ /**
122
+ * Removes a `LocalReferencePosition` from this SharedString.
123
+ */
124
+ removeLocalReferencePosition(lref: LocalReferencePosition): LocalReferencePosition | undefined;
104
125
  /**
105
126
  * Resolves a remote client's position against the local sequence
106
127
  * and returns the remote client's position relative to the local
@@ -115,9 +136,8 @@ export declare abstract class SharedSegmentSequence<T extends ISegment> extends
115
136
  * @param remoteClientRefSeq - The reference sequence number of the remote client
116
137
  * @param remoteClientId - The client id of the remote client
117
138
  */
118
- resolveRemoteClientPosition(remoteClientPosition: number, remoteClientRefSeq: number, remoteClientId: string): number;
139
+ resolveRemoteClientPosition(remoteClientPosition: number, remoteClientRefSeq: number, remoteClientId: string): number | undefined;
119
140
  submitSequenceMessage(message: IMergeTreeOp): void;
120
- removeLocalReferencePosition(lref: LocalReferencePosition): LocalReferencePosition;
121
141
  /**
122
142
  * Given a position specified relative to a marker id, lookup the marker
123
143
  * and convert the position to a character position.
@@ -138,18 +158,28 @@ export declare abstract class SharedSegmentSequence<T extends ISegment> extends
138
158
  * @param splitRange - Optional. Splits boundary segments on the range boundaries
139
159
  */
140
160
  walkSegments<TClientData>(handler: ISegmentAction<TClientData>, start?: number, end?: number, accum?: TClientData, splitRange?: boolean): void;
161
+ getStackContext(startPos: number, rangeLabels: string[]): RangeStackMap;
141
162
  /**
142
- * @deprecated for internal use only. public export will be removed.
143
- * @internal
163
+ * @returns - The most recent sequence number which has been acked by the server and processed by this
164
+ * SharedSegmentSequence.
144
165
  */
145
- getStackContext(startPos: number, rangeLabels: string[]): RangeStackMap;
146
166
  getCurrentSeq(): number;
167
+ /**
168
+ * Inserts a segment directly before a `ReferencePosition`.
169
+ * @param refPos - The reference position to insert the segment at
170
+ * @param segment - The segment to insert
171
+ */
147
172
  insertAtReferencePosition(pos: ReferencePosition, segment: T): void;
148
173
  /**
149
- * @deprecated `IntervalCollection`s are created on a first-write wins basis, and concurrent creates
150
- * are supported. Use {@link SharedSegmentSequence.getIntervalCollection} instead.
174
+ * Inserts a segment
175
+ * @param start - The position to insert the segment at
176
+ * @param spec - The segment to inserts spec
177
+ */
178
+ insertFromSpec(pos: number, spec: IJSONSegment): void;
179
+ /**
180
+ * Retrieves the interval collection keyed on `label`. If no such interval collection exists,
181
+ * creates one.
151
182
  */
152
- waitIntervalCollection(label: string): Promise<IntervalCollection<SequenceInterval>>;
153
183
  getIntervalCollection(label: string): IntervalCollection<SequenceInterval>;
154
184
  /**
155
185
  * @returns An iterable object that enumerates the IntervalCollection labels.
@@ -163,6 +193,9 @@ export declare abstract class SharedSegmentSequence<T extends ISegment> extends
163
193
  * ```
164
194
  */
165
195
  getIntervalCollectionLabels(): IterableIterator<string>;
196
+ /**
197
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.summarizeCore}
198
+ */
166
199
  protected summarizeCore(serializer: IFluidSerializer, telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
167
200
  /**
168
201
  * Runs serializer over the GC data for this SharedMatrix.
@@ -179,15 +212,33 @@ export declare abstract class SharedSegmentSequence<T extends ISegment> extends
179
212
  * @param segment - The segment that will replace the range
180
213
  */
181
214
  protected replaceRange(start: number, end: number, segment: ISegment): void;
215
+ /**
216
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onConnect}
217
+ */
182
218
  protected onConnect(): void;
219
+ /**
220
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}
221
+ */
183
222
  protected onDisconnect(): void;
223
+ /**
224
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.reSubmitCore}
225
+ */
184
226
  protected reSubmitCore(content: any, localOpMetadata: unknown): void;
185
227
  /**
186
228
  * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
187
229
  */
188
230
  protected loadCore(storage: IChannelStorageService): Promise<void>;
231
+ /**
232
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.processCore}
233
+ */
189
234
  protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
235
+ /**
236
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.didAttach}
237
+ */
190
238
  protected didAttach(): void;
239
+ /**
240
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.initializeLocalCore}
241
+ */
191
242
  protected initializeLocalCore(): void;
192
243
  /**
193
244
  * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
@@ -1 +1 @@
1
- {"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAA0B,MAAM,8BAA8B,CAAC;AAEhF,OAAO,EACH,yBAAyB,EAE5B,MAAM,sC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IACH,SAAS,CAAC,SAAS;IAKnB;;OAEG;IACH,SAAS,CAAC,YAAY;IAEtB;;OAEG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,OAAO;IAS7D;;OAEG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB;IAuDxD;;OAEG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,yBAAyB,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO;IAsBlG;;OAEG;IACH,SAAS,CAAC,SAAS;IAQnB;;OAEG;IACH,SAAS,CAAC,mBAAmB;IAK7B;;OAEG;IACH,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;IAI/C,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,mBAAmB;IAuC3B,OAAO,CAAC,+BAA+B;IAYvC,OAAO,CAAC,YAAY;IA6BpB,OAAO,CAAC,6BAA6B;CAiBxC"}
package/lib/sequence.js CHANGED
@@ -8,8 +8,8 @@ import { MessageType, } from "@fluidframework/protocol-definitions";
8
8
  import { Client, createAnnotateRangeOp, createGroupOp, createInsertOp, createRemoveRangeOp, matchProperties, MergeTreeDeltaType, } from "@fluidframework/merge-tree";
9
9
  import { ObjectStoragePartition, SummaryTreeBuilder } from "@fluidframework/runtime-utils";
10
10
  import { makeHandlesSerializable, parseHandles, SharedObject, } from "@fluidframework/shared-object-base";
11
- import { SequenceIntervalCollectionValueType, } from "./intervalCollection";
12
11
  import { DefaultMap } from "./defaultMap";
12
+ import { SequenceIntervalCollectionValueType, } from "./intervalCollection";
13
13
  import { SequenceDeltaEvent, SequenceMaintenanceEvent } from "./sequenceDeltaEvent";
14
14
  const snapshotFileName = "header";
15
15
  const contentPath = "content";
@@ -19,7 +19,7 @@ export class SharedSegmentSequence extends SharedObject {
19
19
  this.dataStoreRuntime = dataStoreRuntime;
20
20
  this.id = id;
21
21
  this.segmentFromSpec = segmentFromSpec;
22
- // Deferred that triggers once the object is loaded
22
+ /** `Deferred` that triggers once the object is loaded */
23
23
  this.loadedDeferred = new Deferred();
24
24
  // cache out going ops created when partial loading
25
25
  this.loadedDeferredOutgoingOps = [];
@@ -97,6 +97,7 @@ export class SharedSegmentSequence extends SharedObject {
97
97
  case MergeTreeDeltaType.REMOVE: {
98
98
  const lastRem = ops[ops.length - 1];
99
99
  if ((lastRem === null || lastRem === void 0 ? void 0 : lastRem.pos1) === r.position) {
100
+ assert(lastRem.pos2 !== undefined, 0x3ff /* pos2 should not be undefined here */);
100
101
  lastRem.pos2 += r.segment.cachedLength;
101
102
  }
102
103
  else {
@@ -115,15 +116,18 @@ export class SharedSegmentSequence extends SharedObject {
115
116
  */
116
117
  removeRange(start, end) {
117
118
  const removeOp = this.client.removeRangeLocal(start, end);
118
- if (removeOp) {
119
- this.submitSequenceMessage(removeOp);
120
- }
119
+ this.submitSequenceMessage(removeOp);
121
120
  return removeOp;
122
121
  }
123
122
  groupOperation(groupOp) {
124
123
  this.client.localTransaction(groupOp);
125
124
  this.submitSequenceMessage(groupOp);
126
125
  }
126
+ /**
127
+ * Finds the segment information (i.e. segment + offset) corresponding to a character position in the SharedString.
128
+ * If the position is past the end of the string, `segment` and `offset` on the returned object may be undefined.
129
+ * @param pos - Character position (index) into the current local view of the SharedString.
130
+ */
127
131
  getContainingSegment(pos) {
128
132
  return this.client.getContainingSegment(pos);
129
133
  }
@@ -162,12 +166,29 @@ export class SharedSegmentSequence extends SharedObject {
162
166
  getRangeExtentsOfPosition(pos) {
163
167
  return this.client.getRangeExtentsOfPosition(pos);
164
168
  }
169
+ /**
170
+ * Creates a `LocalReferencePosition` on this SharedString. If the refType does not include
171
+ * ReferenceType.Transient, the returned reference will be added to the localRefs on the provided segment.
172
+ * @param segment - Segment to add the local reference on
173
+ * @param offset - Offset on the segment at which to place the local reference
174
+ * @param refType - ReferenceType for the created local reference
175
+ * @param properties - PropertySet to place on the created local reference
176
+ */
165
177
  createLocalReferencePosition(segment, offset, refType, properties) {
166
178
  return this.client.createLocalReferencePosition(segment, offset, refType, properties);
167
179
  }
180
+ /**
181
+ * Resolves a `ReferencePosition` into a character position using this client's perspective.
182
+ */
168
183
  localReferencePositionToPosition(lref) {
169
184
  return this.client.localReferencePositionToPosition(lref);
170
185
  }
186
+ /**
187
+ * Removes a `LocalReferencePosition` from this SharedString.
188
+ */
189
+ removeLocalReferencePosition(lref) {
190
+ return this.client.removeLocalReferencePosition(lref);
191
+ }
171
192
  /**
172
193
  * Resolves a remote client's position against the local sequence
173
194
  * and returns the remote client's position relative to the local
@@ -195,15 +216,12 @@ export class SharedSegmentSequence extends SharedObject {
195
216
  // local ops until loading is complete, and then
196
217
  // they will be resent
197
218
  if (!this.loadedDeferred.isCompleted) {
198
- this.loadedDeferredOutgoingOps.push([translated, metadata]);
219
+ this.loadedDeferredOutgoingOps.push(metadata ? [translated, metadata] : translated);
199
220
  }
200
221
  else {
201
222
  this.submitLocalMessage(translated, metadata);
202
223
  }
203
224
  }
204
- removeLocalReferencePosition(lref) {
205
- return this.client.removeLocalReferencePosition(lref);
206
- }
207
225
  /**
208
226
  * Given a position specified relative to a marker id, lookup the marker
209
227
  * and convert the position to a character position.
@@ -226,18 +244,23 @@ export class SharedSegmentSequence extends SharedObject {
226
244
  * @param splitRange - Optional. Splits boundary segments on the range boundaries
227
245
  */
228
246
  walkSegments(handler, start, end, accum, splitRange = false) {
229
- return this.client.walkSegments(handler, start, end, accum, splitRange);
247
+ this.client.walkSegments(handler, start, end, accum, splitRange);
230
248
  }
231
- /**
232
- * @deprecated for internal use only. public export will be removed.
233
- * @internal
234
- */
235
249
  getStackContext(startPos, rangeLabels) {
236
250
  return this.client.getStackContext(startPos, rangeLabels);
237
251
  }
252
+ /**
253
+ * @returns - The most recent sequence number which has been acked by the server and processed by this
254
+ * SharedSegmentSequence.
255
+ */
238
256
  getCurrentSeq() {
239
257
  return this.client.getCurrentSeq();
240
258
  }
259
+ /**
260
+ * Inserts a segment directly before a `ReferencePosition`.
261
+ * @param refPos - The reference position to insert the segment at
262
+ * @param segment - The segment to insert
263
+ */
241
264
  insertAtReferencePosition(pos, segment) {
242
265
  const insertOp = this.client.insertAtReferencePositionLocal(pos, segment);
243
266
  if (insertOp) {
@@ -245,12 +268,21 @@ export class SharedSegmentSequence extends SharedObject {
245
268
  }
246
269
  }
247
270
  /**
248
- * @deprecated `IntervalCollection`s are created on a first-write wins basis, and concurrent creates
249
- * are supported. Use {@link SharedSegmentSequence.getIntervalCollection} instead.
271
+ * Inserts a segment
272
+ * @param start - The position to insert the segment at
273
+ * @param spec - The segment to inserts spec
250
274
  */
251
- async waitIntervalCollection(label) {
252
- return this.intervalCollections.get(label);
275
+ insertFromSpec(pos, spec) {
276
+ const segment = this.segmentFromSpec(spec);
277
+ const insertOp = this.client.insertSegmentLocal(pos, segment);
278
+ if (insertOp) {
279
+ this.submitSequenceMessage(insertOp);
280
+ }
253
281
  }
282
+ /**
283
+ * Retrieves the interval collection keyed on `label`. If no such interval collection exists,
284
+ * creates one.
285
+ */
254
286
  getIntervalCollection(label) {
255
287
  return this.intervalCollections.get(label);
256
288
  }
@@ -268,6 +300,9 @@ export class SharedSegmentSequence extends SharedObject {
268
300
  getIntervalCollectionLabels() {
269
301
  return this.intervalCollections.keys();
270
302
  }
303
+ /**
304
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.summarizeCore}
305
+ */
271
306
  summarizeCore(serializer, telemetryContext) {
272
307
  const builder = new SummaryTreeBuilder();
273
308
  // conditionally write the interval collection blob
@@ -305,18 +340,28 @@ export class SharedSegmentSequence extends SharedObject {
305
340
  if (insert) {
306
341
  if (start < end) {
307
342
  const remove = this.client.removeRangeLocal(start, end);
308
- this.submitSequenceMessage(createGroupOp(insert, remove));
343
+ const op = remove ? createGroupOp(insert, remove) : insert;
344
+ this.submitSequenceMessage(op);
309
345
  }
310
346
  else {
311
347
  this.submitSequenceMessage(insert);
312
348
  }
313
349
  }
314
350
  }
351
+ /**
352
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onConnect}
353
+ */
315
354
  onConnect() {
316
355
  // Update merge tree collaboration information with new client ID and then resend pending ops
317
356
  this.client.startOrUpdateCollaboration(this.runtime.clientId);
318
357
  }
358
+ /**
359
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}
360
+ */
319
361
  onDisconnect() { }
362
+ /**
363
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.reSubmitCore}
364
+ */
320
365
  reSubmitCore(content, localOpMetadata) {
321
366
  if (!this.intervalCollections.tryResubmitMessage(content, localOpMetadata)) {
322
367
  this.submitSequenceMessage(this.client.regeneratePendingOp(content, localOpMetadata));
@@ -376,6 +421,9 @@ export class SharedSegmentSequence extends SharedObject {
376
421
  this.loadFinished(error);
377
422
  }
378
423
  }
424
+ /**
425
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.processCore}
426
+ */
379
427
  processCore(message, local, localOpMetadata) {
380
428
  // if loading isn't complete, we need to cache all
381
429
  // incoming ops to be applied after loading is complete
@@ -391,6 +439,9 @@ export class SharedSegmentSequence extends SharedObject {
391
439
  }
392
440
  }
393
441
  }
442
+ /**
443
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.didAttach}
444
+ */
394
445
  didAttach() {
395
446
  var _a;
396
447
  // If we are not local, and we've attached we need to start generating and sending ops
@@ -399,6 +450,9 @@ export class SharedSegmentSequence extends SharedObject {
399
450
  this.client.startOrUpdateCollaboration((_a = this.runtime.clientId) !== null && _a !== void 0 ? _a : "attached");
400
451
  }
401
452
  }
453
+ /**
454
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.initializeLocalCore}
455
+ */
402
456
  initializeLocalCore() {
403
457
  super.initializeLocalCore();
404
458
  this.loadFinished();