@fluid-experimental/tree 1.2.1 → 2.0.0-internal.1.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.
- package/.prettierignore +6 -0
- package/dist/Checkout.d.ts +9 -4
- package/dist/Checkout.d.ts.map +1 -1
- package/dist/Checkout.js +34 -25
- package/dist/Checkout.js.map +1 -1
- package/dist/Common.d.ts +31 -18
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js +32 -22
- package/dist/Common.js.map +1 -1
- package/dist/EditUtilities.d.ts +5 -0
- package/dist/EditUtilities.d.ts.map +1 -1
- package/dist/EditUtilities.js +4 -3
- package/dist/EditUtilities.js.map +1 -1
- package/dist/HistoryEditFactory.d.ts +5 -3
- package/dist/HistoryEditFactory.d.ts.map +1 -1
- package/dist/HistoryEditFactory.js +18 -3
- package/dist/HistoryEditFactory.js.map +1 -1
- package/dist/SharedTree.d.ts +6 -3
- package/dist/SharedTree.d.ts.map +1 -1
- package/dist/SharedTree.js +4 -4
- package/dist/SharedTree.js.map +1 -1
- package/dist/Transaction.d.ts +2 -2
- package/dist/Transaction.d.ts.map +1 -1
- package/dist/Transaction.js +3 -2
- package/dist/Transaction.js.map +1 -1
- package/lib/Checkout.d.ts +9 -4
- package/lib/Checkout.d.ts.map +1 -1
- package/lib/Checkout.js +36 -27
- package/lib/Checkout.js.map +1 -1
- package/lib/Common.d.ts +31 -18
- package/lib/Common.d.ts.map +1 -1
- package/lib/Common.js +30 -21
- package/lib/Common.js.map +1 -1
- package/lib/EditUtilities.d.ts +5 -0
- package/lib/EditUtilities.d.ts.map +1 -1
- package/lib/EditUtilities.js +4 -3
- package/lib/EditUtilities.js.map +1 -1
- package/lib/HistoryEditFactory.d.ts +5 -3
- package/lib/HistoryEditFactory.d.ts.map +1 -1
- package/lib/HistoryEditFactory.js +18 -3
- package/lib/HistoryEditFactory.js.map +1 -1
- package/lib/SharedTree.d.ts +6 -3
- package/lib/SharedTree.d.ts.map +1 -1
- package/lib/SharedTree.js +5 -5
- package/lib/SharedTree.js.map +1 -1
- package/lib/Transaction.d.ts +2 -2
- package/lib/Transaction.d.ts.map +1 -1
- package/lib/Transaction.js +3 -2
- package/lib/Transaction.js.map +1 -1
- package/lib/test/Checkout.tests.d.ts.map +1 -1
- package/lib/test/Checkout.tests.js +39 -10
- package/lib/test/Checkout.tests.js.map +1 -1
- package/lib/test/Common.tests.js +20 -1
- package/lib/test/Common.tests.js.map +1 -1
- package/lib/test/HistoryEditFactory.tests.js +48 -9
- package/lib/test/HistoryEditFactory.tests.js.map +1 -1
- package/lib/test/utilities/SharedTreeTests.d.ts.map +1 -1
- package/lib/test/utilities/SharedTreeTests.js +35 -26
- package/lib/test/utilities/SharedTreeTests.js.map +1 -1
- package/lib/test/utilities/TestUtilities.d.ts +5 -0
- package/lib/test/utilities/TestUtilities.d.ts.map +1 -1
- package/lib/test/utilities/TestUtilities.js +4 -3
- package/lib/test/utilities/TestUtilities.js.map +1 -1
- package/lib/test/utilities/UndoRedoTests.js +3 -2
- package/lib/test/utilities/UndoRedoTests.js.map +1 -1
- package/package.json +22 -20
- package/src/Checkout.ts +56 -14
- package/src/Common.ts +38 -21
- package/src/EditUtilities.ts +3 -3
- package/src/HistoryEditFactory.ts +24 -3
- package/src/SharedTree.ts +19 -8
- package/src/Transaction.ts +5 -4
package/dist/Transaction.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../src/Transaction.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAAiE;AACjE,uDAAqE;AACrE,mDAA4C;AAI5C,+DAAgF;AAChF,2CAA+C;
|
|
1
|
+
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../src/Transaction.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAAiE;AACjE,uDAAqE;AACrE,mDAA4C;AAI5C,+DAAgF;AAChF,2CAA+C;AAC/C,qCAA0D;AAE1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C,aAAa,CAAC,gBAAgB,CAAC,UAAU,CAAC,GAAG,CAAC;oBACnD,CAAC,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,EAC7C;oBACD,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,YAAY,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;iBACvE;aACD;SACD;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,cAAc;QACpB,IAAI,IAAI,CAAC,MAAM,EAAE;YAChB,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;gBACxC,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;gBACxC,MAAM,IAAI,GAAyB,EAAE,EAAE,EAAE,IAAA,yBAAS,GAAE,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;gBAChF,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,YAAY,4BAAgB,EAAE;oBAChD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;iBACpD;gBACD,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAClC;SACD;IACF,CAAC;CACD;AAlFD,kCAkFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IErrorEvent } from '@fluidframework/common-definitions';\nimport { TypedEventEmitter } from '@fluidframework/common-utils';\nimport { ChangeInternal, Edit, EditStatus } from './persisted-types';\nimport { newEditId } from './EditUtilities';\nimport { TreeView } from './TreeView';\nimport { Change } from './ChangeTypes';\nimport { SharedTree } from './SharedTree';\nimport { GenericTransaction, TransactionInternal } from './TransactionInternal';\nimport { CachingLogViewer } from './LogViewer';\nimport { RestOrArray, unwrapRestOrArray } from './Common';\n\n/**\n * An event emitted by a `Transaction` to indicate a state change. See {@link TransactionEvents} for event argument information.\n * @public\n */\nexport enum TransactionEvent {\n\t/**\n\t * `currentView` has changed from `before` to `after`\n\t */\n\tViewChange = 'viewChange',\n}\n\n/**\n * Events which may be emitted by `Transaction`\n * @public\n */\nexport interface TransactionEvents extends IErrorEvent {\n\t(event: TransactionEvent.ViewChange, listener: (before: TreeView, after: TreeView) => void);\n}\n\n/**\n * Buffers changes to be applied to an isolated view of a `SharedTree` over time before applying them directly to the tree itself as a\n * single edit\n */\nexport class Transaction extends TypedEventEmitter<TransactionEvents> {\n\t/** The view of the tree when this transaction was created */\n\tpublic readonly startingView: TreeView;\n\tprivate readonly transaction: GenericTransaction;\n\n\t/**\n\t * Create a new transaction over the given tree. The tree's `currentView` at this time will become the `startingView` for this\n\t * transaction.\n\t * @param tree - the `SharedTree` that this transaction applies changes to\n\t */\n\tpublic constructor(public readonly tree: SharedTree) {\n\t\tsuper();\n\t\tconst { currentView } = tree;\n\t\tthis.transaction = new GenericTransaction(currentView, new TransactionInternal.Policy());\n\t\tthis.startingView = currentView;\n\t}\n\n\t/**\n\t * True if this transaction is open, false if it is closed. A transaction may be closed manually via `closeAndApplyEdit()`, or may\n\t * be automatically closed by a change in this transaction failing to apply (see `applyChange()`).\n\t */\n\tpublic get isOpen(): boolean {\n\t\treturn this.transaction.isOpen && this.status === EditStatus.Applied;\n\t}\n\n\t/**\n\t * The status of the most recently applied change in this transaction\n\t */\n\tpublic get status(): EditStatus {\n\t\treturn this.transaction.status;\n\t}\n\n\t/**\n\t * The state of the tree following the most change that was successfully applied. If no changes have been applied, this is the same as\n\t * `startingView`.\n\t */\n\tpublic get currentView(): TreeView {\n\t\treturn this.transaction.view;\n\t}\n\n\t/**\n\t * Attempt to apply a sequence of changes in this transaction. The `currentView` will be updated to reflect the new tree state after all\n\t * applied changes. If any change fails to apply, the remaining changes will be ignored and this transaction will be automatically\n\t * closed (see `isOpen`). If this transaction is already closed, this method has no effect. This method will emit a\n\t * `TransactionEvent.ViewChange` event at most once per call.\n\t * @param changes - the changes to apply\n\t * @returns either the `EditStatus` of the given changes or the `EditStatus` of the last change before the transaction was closed\n\t */\n\tpublic apply(...changes: readonly Change[]): EditStatus;\n\tpublic apply(changes: readonly Change[]): EditStatus;\n\tpublic apply(...changesOrArray: RestOrArray<Change>): EditStatus {\n\t\tif (this.isOpen) {\n\t\t\tconst changes = unwrapRestOrArray(changesOrArray);\n\t\t\tif (changes.length > 0) {\n\t\t\t\tconst previousView = this.currentView;\n\t\t\t\tthis.transaction.applyChanges(changes.map((c) => this.tree.internalizeChange(c)));\n\t\t\t\tif (\n\t\t\t\t\tthis.listenerCount(TransactionEvent.ViewChange) > 0 &&\n\t\t\t\t\t!previousView.hasEqualForest(this.currentView)\n\t\t\t\t) {\n\t\t\t\t\tthis.emit(TransactionEvent.ViewChange, previousView, this.currentView);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn this.status;\n\t}\n\n\t/**\n\t * Close this transaction and apply its changes to the `SharedTree`. If this transaction is already closed, this method has no effect.\n\t */\n\tpublic closeAndCommit(): void {\n\t\tif (this.isOpen) {\n\t\t\tif (this.transaction.changes.length > 0) {\n\t\t\t\tconst result = this.transaction.close();\n\t\t\t\tconst edit: Edit<ChangeInternal> = { id: newEditId(), changes: result.changes };\n\t\t\t\tif (this.tree.edits instanceof CachingLogViewer) {\n\t\t\t\t\tthis.tree.edits.setKnownEditingResult(edit, result);\n\t\t\t\t}\n\t\t\t\tthis.tree.applyEditInternal(edit);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
package/lib/Checkout.d.ts
CHANGED
|
@@ -99,6 +99,7 @@ export declare abstract class Checkout extends EventEmitterWithErrorHandling<ICh
|
|
|
99
99
|
* operations that modify `currentEdit.view` must call `emitChange` to handle invalidation.
|
|
100
100
|
*/
|
|
101
101
|
private currentEdit?;
|
|
102
|
+
private readonly logger;
|
|
102
103
|
disposed: boolean;
|
|
103
104
|
protected constructor(tree: SharedTree, currentView: RevisionView, onEditCommitted: EditCommittedHandler);
|
|
104
105
|
/**
|
|
@@ -142,24 +143,28 @@ export declare abstract class Checkout extends EventEmitterWithErrorHandling<ICh
|
|
|
142
143
|
* Must be called during an ongoing edit (see `openEdit()`/`closeEdit()`).
|
|
143
144
|
* `changes` must be well-formed and valid: it is an error if they do not apply cleanly.
|
|
144
145
|
*/
|
|
145
|
-
applyChanges(
|
|
146
|
+
applyChanges(changes: readonly Change[]): void;
|
|
147
|
+
applyChanges(...changes: readonly Change[]): void;
|
|
146
148
|
/**
|
|
147
149
|
* Applies the supplied changes to the tree and emits a change event.
|
|
148
150
|
* Must be called during an ongoing edit (see `openEdit()`/`closeEdit()`).
|
|
149
151
|
* `changes` must be well-formed and valid: it is an error if they do not apply cleanly.
|
|
150
152
|
*/
|
|
151
|
-
protected tryApplyChangesInternal(
|
|
153
|
+
protected tryApplyChangesInternal(changes: readonly ChangeInternal[]): EditStatus;
|
|
154
|
+
protected tryApplyChangesInternal(...changes: readonly ChangeInternal[]): EditStatus;
|
|
152
155
|
/**
|
|
153
156
|
* Convenience helper for applying an edit containing the given changes.
|
|
154
157
|
* Opens an edit, applies the given changes, and closes the edit. See (`openEdit()`/`applyChanges()`/`closeEdit()`).
|
|
155
158
|
*/
|
|
156
|
-
applyEdit(
|
|
159
|
+
applyEdit(changes: readonly Change[]): EditId;
|
|
160
|
+
applyEdit(...changes: readonly Change[]): EditId;
|
|
157
161
|
/**
|
|
158
162
|
* Apply an edit, if valid, otherwise does nothing (the edit is not added to the history).
|
|
159
163
|
* If the edit applied, its changes will be immediately visible on this checkout, though it still may end up invalid once sequenced due to concurrent edits.
|
|
160
164
|
* @returns The EditId if the edit was valid and thus applied, and undefined if it was invalid and thus not applied.
|
|
161
165
|
*/
|
|
162
|
-
tryApplyEdit(
|
|
166
|
+
tryApplyEdit(changes: readonly Change[]): EditId | undefined;
|
|
167
|
+
tryApplyEdit(...changes: readonly Change[]): EditId | undefined;
|
|
163
168
|
/**
|
|
164
169
|
* Rebases the ongoing edit to the latest revision loaded by this 'Checkout'.
|
|
165
170
|
* If the rebase succeeds (none of the changes in the ongoing edit became invalid), the ongoing edit will remain open and the current
|
package/lib/Checkout.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkout.d.ts","sourceRoot":"","sources":["../src/Checkout.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"Checkout.d.ts","sourceRoot":"","sources":["../src/Checkout.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAe,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAC7F,OAAO,EAAE,WAAW,EAAE,WAAW,EAA0C,MAAM,oCAAoC,CAAC;AAEtH,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAA2C,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACpG,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGrE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC;;;GAGG;AACH,oBAAY,aAAa;IACxB;;;OAGG;IACH,UAAU,eAAe;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,eAAgB,SAAQ,WAAW;IACnD,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,KAAK,IAAI,OAAE;CAC7E;AAED;;;GAGG;AACH,oBAAY,oBAAoB;IAC/B;;;;OAIG;IACH,SAAS,IAAA;IACT;;;;OAIG;IACH,OAAO,IAAA;IACP;;OAEG;IACH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S,cAAc,EAAE,GAAG,UAAU;IACjF,SAAS,CAAC,uBAAuB,CAAC,GAAG,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,UAAU;IAWpF;;;OAGG;IACI,SAAS,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAC7C,SAAS,CAAC,GAAG,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAQvD;;;;OAIG;IACI,YAAY,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS;IAC5D,YAAY,CAAC,GAAG,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS;IAgBtE;;;;;;;;;;OAUG;IACI,iBAAiB,IAAI,oBAAoB,CAAC,KAAK,GAAG,oBAAoB,CAAC,OAAO;IAuBrF;;;OAGG;IACI,SAAS,IAAI,IAAI;IAOxB;;;;OAIG;IACI,aAAa,IAAI,UAAU;IAQlC;;;OAGG;IACI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAWnC;;;;OAIG;IACH,SAAS,CAAC,UAAU,IAAI,IAAI;IAU5B;;OAEG;aACa,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IAEtD;;;OAGG;aACa,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAErD;;;OAGG;IACI,OAAO,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI;CAUnC"}
|
package/lib/Checkout.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { EventEmitterWithErrorHandling } from '@fluidframework/telemetry-utils';
|
|
6
|
-
import { assert } from './Common';
|
|
5
|
+
import { ChildLogger, EventEmitterWithErrorHandling } from '@fluidframework/telemetry-utils';
|
|
6
|
+
import { assert, fail, unwrapRestOrArray } from './Common';
|
|
7
7
|
import { CachingLogViewer } from './LogViewer';
|
|
8
8
|
import { TransactionInternal } from './TransactionInternal';
|
|
9
9
|
import { EditStatus } from './persisted-types';
|
|
@@ -66,6 +66,7 @@ export class Checkout extends EventEmitterWithErrorHandling {
|
|
|
66
66
|
});
|
|
67
67
|
this.disposed = false;
|
|
68
68
|
this.tree = tree;
|
|
69
|
+
this.logger = ChildLogger.create(this.tree.logger, 'Checkout');
|
|
69
70
|
if (tree.logViewer instanceof CachingLogViewer) {
|
|
70
71
|
this.cachingLogViewer = tree.logViewer;
|
|
71
72
|
}
|
|
@@ -110,7 +111,30 @@ export class Checkout extends EventEmitterWithErrorHandling {
|
|
|
110
111
|
assert(currentEdit !== undefined, 'An edit is not open.');
|
|
111
112
|
this.currentEdit = undefined;
|
|
112
113
|
const editingResult = currentEdit.close();
|
|
113
|
-
|
|
114
|
+
if (editingResult.status !== EditStatus.Applied) {
|
|
115
|
+
const { failure } = editingResult;
|
|
116
|
+
const additionalProps = {};
|
|
117
|
+
switch (failure.kind) {
|
|
118
|
+
case TransactionInternal.FailureKind.BadPlace:
|
|
119
|
+
additionalProps.placeFailure = failure.placeFailure;
|
|
120
|
+
break;
|
|
121
|
+
case TransactionInternal.FailureKind.BadRange: {
|
|
122
|
+
const { rangeFailure } = failure;
|
|
123
|
+
if (typeof rangeFailure === 'string') {
|
|
124
|
+
additionalProps.rangeFailure = rangeFailure;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
additionalProps.rangeFailure = rangeFailure.kind;
|
|
128
|
+
additionalProps.rangeEndpointFailure = rangeFailure.placeFailure;
|
|
129
|
+
}
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
default:
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
this.logger.sendErrorEvent(Object.assign({ eventName: 'FailedLocalEdit', status: editingResult.status === 0 ? 'Malformed' : 'Invalid', failureKind: editingResult.failure.kind }, additionalProps));
|
|
136
|
+
fail('Locally constructed edits must be well-formed and valid');
|
|
137
|
+
}
|
|
114
138
|
const id = newEditId();
|
|
115
139
|
this.handleNewEdit(id, editingResult);
|
|
116
140
|
return id;
|
|
@@ -138,48 +162,33 @@ export class Checkout extends EventEmitterWithErrorHandling {
|
|
|
138
162
|
// (which processLocalEdit will do, including invalidation).
|
|
139
163
|
this.tree.applyEditInternal(edit);
|
|
140
164
|
}
|
|
141
|
-
/**
|
|
142
|
-
* Applies the supplied changes to the tree and emits a change event.
|
|
143
|
-
* Must be called during an ongoing edit (see `openEdit()`/`closeEdit()`).
|
|
144
|
-
* `changes` must be well-formed and valid: it is an error if they do not apply cleanly.
|
|
145
|
-
*/
|
|
146
165
|
applyChanges(...changes) {
|
|
147
166
|
assert(this.currentEdit, 'Changes must be applied as part of an ongoing edit.');
|
|
148
|
-
const
|
|
167
|
+
const changeArray = unwrapRestOrArray(changes);
|
|
168
|
+
const { status } = this.currentEdit.applyChanges(changeArray.map((c) => this.tree.internalizeChange(c)));
|
|
149
169
|
assert(status === EditStatus.Applied, 'Locally constructed edits must be well-formed and valid.');
|
|
150
170
|
this.emitChange();
|
|
151
171
|
}
|
|
152
|
-
/**
|
|
153
|
-
* Applies the supplied changes to the tree and emits a change event.
|
|
154
|
-
* Must be called during an ongoing edit (see `openEdit()`/`closeEdit()`).
|
|
155
|
-
* `changes` must be well-formed and valid: it is an error if they do not apply cleanly.
|
|
156
|
-
*/
|
|
157
172
|
tryApplyChangesInternal(...changes) {
|
|
158
173
|
assert(this.currentEdit, 'Changes must be applied as part of an ongoing edit.');
|
|
159
|
-
const
|
|
174
|
+
const changeArray = unwrapRestOrArray(changes);
|
|
175
|
+
const { status } = this.currentEdit.applyChanges(changeArray);
|
|
160
176
|
if (status === EditStatus.Applied) {
|
|
161
177
|
this.emitChange();
|
|
162
178
|
}
|
|
163
179
|
return status;
|
|
164
180
|
}
|
|
165
|
-
/**
|
|
166
|
-
* Convenience helper for applying an edit containing the given changes.
|
|
167
|
-
* Opens an edit, applies the given changes, and closes the edit. See (`openEdit()`/`applyChanges()`/`closeEdit()`).
|
|
168
|
-
*/
|
|
169
181
|
applyEdit(...changes) {
|
|
170
182
|
this.openEdit();
|
|
171
|
-
|
|
183
|
+
const changeArray = unwrapRestOrArray(changes);
|
|
184
|
+
this.applyChanges(changeArray);
|
|
172
185
|
return this.closeEdit();
|
|
173
186
|
}
|
|
174
|
-
/**
|
|
175
|
-
* Apply an edit, if valid, otherwise does nothing (the edit is not added to the history).
|
|
176
|
-
* If the edit applied, its changes will be immediately visible on this checkout, though it still may end up invalid once sequenced due to concurrent edits.
|
|
177
|
-
* @returns The EditId if the edit was valid and thus applied, and undefined if it was invalid and thus not applied.
|
|
178
|
-
*/
|
|
179
187
|
tryApplyEdit(...changes) {
|
|
180
188
|
this.openEdit();
|
|
181
189
|
assert(this.currentEdit, 'Changes must be applied as part of an ongoing edit.');
|
|
182
|
-
const
|
|
190
|
+
const changeArray = unwrapRestOrArray(changes);
|
|
191
|
+
const { status } = this.currentEdit.applyChanges(changeArray.map((c) => this.tree.internalizeChange(c)));
|
|
183
192
|
if (status === EditStatus.Applied) {
|
|
184
193
|
this.emitChange();
|
|
185
194
|
return this.closeEdit();
|
|
@@ -251,7 +260,7 @@ export class Checkout extends EventEmitterWithErrorHandling {
|
|
|
251
260
|
const before = this.tree.logViewer.getRevisionViewInSession(index);
|
|
252
261
|
const changes = this.tree.revertChanges(edit.changes, before);
|
|
253
262
|
if (changes !== undefined) {
|
|
254
|
-
this.tryApplyChangesInternal(
|
|
263
|
+
this.tryApplyChangesInternal(changes);
|
|
255
264
|
}
|
|
256
265
|
}
|
|
257
266
|
/**
|
package/lib/Checkout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkout.js","sourceRoot":"","sources":["../src/Checkout.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAEhF,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AA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C,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE;YAC5C,6GAA6G;YAC7G,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC;YAC5B,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;SACvD;IACF,CAAC;IAaD;;;OAGG;IACI,OAAO,CAAC,KAAa;QAC3B,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClB,OAAO;SACP;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QAErB,6BAA6B;QAC7B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,aAAa,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACzE,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitterWithErrorHandling } from '@fluidframework/telemetry-utils';\nimport { IDisposable, IErrorEvent } from '@fluidframework/common-definitions';\nimport { assert } from './Common';\nimport { EditId } from './Identifiers';\nimport { CachingLogViewer } from './LogViewer';\nimport { TreeView } from './TreeView';\nimport { RevisionView } from './RevisionView';\nimport { EditCommittedHandler, SharedTree } from './SharedTree';\nimport { GenericTransaction, TransactionInternal, ValidEditingResult } from './TransactionInternal';\nimport { ChangeInternal, Edit, EditStatus } from './persisted-types';\nimport { SharedTreeEvent } from './EventTypes';\nimport { newEditId } from './EditUtilities';\nimport { Change } from './ChangeTypes';\n\n/**\n * An event emitted by a `Checkout` to indicate a state change. See {@link ICheckoutEvents} for event argument information.\n * @public\n */\nexport enum CheckoutEvent {\n\t/**\n\t * `currentView` has changed.\n\t * Passed a before and after TreeView.\n\t */\n\tViewChange = 'viewChange',\n}\n\n/**\n * Events which may be emitted by `Checkout`. See {@link CheckoutEvent} for documentation of event semantics.\n */\nexport interface ICheckoutEvents extends IErrorEvent {\n\t(event: 'viewChange', listener: (before: TreeView, after: TreeView) => void);\n}\n\n/**\n * The result of validation of an Edit.\n * @public\n */\nexport enum EditValidationResult {\n\t/**\n\t * The edit contained one or more malformed changes (e.g. was missing required fields such as `id`),\n\t * or contained a sequence of changes that could not possibly be applied sequentially without error\n\t * (e.g. an edit which tries to insert the same detached node twice).\n\t */\n\tMalformed,\n\t/**\n\t * The edit is well-formed but cannot be applied to the current view, generally because concurrent changes\n\t * caused one or more merge conflicts.\n\t * For example, the edit refers to the `StablePlace` after node `C`, but `C` has since been deleted.\n\t */\n\tInvalid,\n\t/**\n\t * The edit is well-formed and can be applied to the current view.\n\t */\n\tValid,\n}\n\n/**\n * A mutable Checkout of a SharedTree, allowing viewing and interactive transactional editing.\n * Provides {@link https://en.wikipedia.org/wiki/Snapshot_isolation | snapshot-isolation} while editing.\n *\n * A Checkout always shows a consistent sequence of versions of the SharedTree, but it may skip intermediate versions, and may fall behind.\n * In this case consistent means the sequence of versions could occur with fully synchronous shared tree access,\n * though the timing of sequenced edits arriving to the Checkout may be later than they actually arrive in the SharedTree.\n * Specifically no sequenced edits will arrive during an ongoing edit (to implement snapshot isolation):\n * they will be applied asynchronously some time after the ongoing edit is ended.\n *\n * Events emitted by `Checkout` are documented in {@link CheckoutEvent}.\n * Exceptions thrown during event handling will be emitted as error events, which are automatically surfaced as error events on the\n * `SharedTree` used at construction time.\n * @public\n */\nexport abstract class Checkout extends EventEmitterWithErrorHandling<ICheckoutEvents> implements IDisposable {\n\t/**\n\t * The view of the latest committed revision.\n\t * Does not include changes from any open edits.\n\t *\n\t * When this changes, emitChange must be called.\n\t */\n\tprotected abstract get latestCommittedView(): RevisionView;\n\n\t/**\n\t * The last view for which invalidation was sent.\n\t * Updated by emitChange.\n\t */\n\tprivate previousView: TreeView;\n\n\t/**\n\t * A handler for 'committedEdit' SharedTreeEvent\n\t */\n\tprivate readonly editCommittedHandler: EditCommittedHandler;\n\n\t/**\n\t * The shared tree this checkout views/edits.\n\t */\n\tpublic readonly tree: SharedTree;\n\n\t/**\n\t * `tree`'s log viewer as a CachingLogViewer if it is one, otherwise undefined.\n\t * Used for optimizations if provided.\n\t */\n\tprivate readonly cachingLogViewer?: CachingLogViewer;\n\n\t/**\n\t * Holds the state required to manage the currently open edit.\n\t * Undefined if there is currently not an open edit.\n\t *\n\t * Since `currentView` exposes the the intermediate state from this edit,\n\t * operations that modify `currentEdit.view` must call `emitChange` to handle invalidation.\n\t */\n\tprivate currentEdit?: GenericTransaction;\n\n\tpublic disposed: boolean = false;\n\n\tprotected constructor(tree: SharedTree, currentView: RevisionView, onEditCommitted: EditCommittedHandler) {\n\t\tsuper((_event, error: unknown) => {\n\t\t\tthis.tree.emit('error', error);\n\t\t});\n\t\tthis.tree = tree;\n\t\tif (tree.logViewer instanceof CachingLogViewer) {\n\t\t\tthis.cachingLogViewer = tree.logViewer;\n\t\t}\n\t\tthis.previousView = currentView;\n\t\tthis.editCommittedHandler = onEditCommitted;\n\n\t\t// If there is an ongoing edit, emitChange will no-op, which is fine.\n\t\tthis.tree.on(SharedTreeEvent.EditCommitted, this.editCommittedHandler);\n\t}\n\n\t/**\n\t * @returns the current view of the tree, including the result of changes applied so far during an edit.\n\t * Note that any external edits (from other clients) will not added to view while there is a `currentEdit`.\n\t */\n\tpublic get currentView(): TreeView {\n\t\treturn this.currentEdit?.view ?? this.latestCommittedView;\n\t}\n\n\t/**\n\t * @returns true iff there is an open edit.\n\t * @internal\n\t */\n\tpublic hasOpenEdit(): boolean {\n\t\treturn this.currentEdit !== undefined;\n\t}\n\n\t/**\n\t * Opens a new edit operation.\n\t * Changes accumulate in the edit via calls to `applyChanges()`.\n\t */\n\tpublic openEdit(): void {\n\t\tassert(this.currentEdit === undefined, 'An edit is already open.');\n\t\tthis.currentEdit = TransactionInternal.factory(this.latestCommittedView);\n\t}\n\n\t/**\n\t * Ends the ongoing edit operation and commits it to the history.\n\t *\n\t * Malformed edits are considered an error, and will assert:\n\t * All named detached sequences must have been used or theEdit is malformed.\n\t *\n\t * @returns the `id` of the committed edit\n\t */\n\tpublic closeEdit(): EditId {\n\t\tconst { currentEdit } = this;\n\t\tassert(currentEdit !== undefined, 'An edit is not open.');\n\t\tthis.currentEdit = undefined;\n\t\tconst editingResult = currentEdit.close();\n\t\tassert(editingResult.status === EditStatus.Applied, 'Locally constructed edits must be well-formed and valid');\n\n\t\tconst id: EditId = newEditId();\n\n\t\tthis.handleNewEdit(id, editingResult);\n\t\treturn id;\n\t}\n\n\t/**\n\t * Inform the Checkout that a particular edit is know to have a specific result when applied to a particular TreeView.\n\t * This may be used as a caching hint to avoid recomputation.\n\t */\n\tprotected hintKnownEditingResult(edit: Edit<ChangeInternal>, result: ValidEditingResult): void {\n\t\t// As an optimization, inform logViewer of this editing result so it can reuse it if applied to the same before revision.\n\t\tthis.cachingLogViewer?.setKnownEditingResult(edit, result);\n\t}\n\n\t/**\n\t * Take any needed action between when an edit is completed.\n\t * Usually this will include submitting it to a SharedTree.\n\t *\n\t * Override this to customize.\n\t */\n\tprotected handleNewEdit(id: EditId, result: ValidEditingResult): void {\n\t\tconst edit: Edit<ChangeInternal> = { id, changes: result.changes };\n\n\t\tthis.hintKnownEditingResult(edit, result);\n\n\t\t// Since external edits could have been applied while currentEdit was pending,\n\t\t// do not use the produced view: just go to the newest revision\n\t\t// (which processLocalEdit will do, including invalidation).\n\t\tthis.tree.applyEditInternal(edit);\n\t}\n\n\t/**\n\t * Applies the supplied changes to the tree and emits a change event.\n\t * Must be called during an ongoing edit (see `openEdit()`/`closeEdit()`).\n\t * `changes` must be well-formed and valid: it is an error if they do not apply cleanly.\n\t */\n\tpublic applyChanges(...changes: Change[]): void {\n\t\tassert(this.currentEdit, 'Changes must be applied as part of an ongoing edit.');\n\t\tconst { status } = this.currentEdit.applyChanges(changes.map((c) => this.tree.internalizeChange(c)));\n\t\tassert(status === EditStatus.Applied, 'Locally constructed edits must be well-formed and valid.');\n\t\tthis.emitChange();\n\t}\n\n\t/**\n\t * Applies the supplied changes to the tree and emits a change event.\n\t * Must be called during an ongoing edit (see `openEdit()`/`closeEdit()`).\n\t * `changes` must be well-formed and valid: it is an error if they do not apply cleanly.\n\t */\n\tprotected tryApplyChangesInternal(...changes: ChangeInternal[]): EditStatus {\n\t\tassert(this.currentEdit, 'Changes must be applied as part of an ongoing edit.');\n\t\tconst { status } = this.currentEdit.applyChanges(changes);\n\t\tif (status === EditStatus.Applied) {\n\t\t\tthis.emitChange();\n\t\t}\n\t\treturn status;\n\t}\n\n\t/**\n\t * Convenience helper for applying an edit containing the given changes.\n\t * Opens an edit, applies the given changes, and closes the edit. See (`openEdit()`/`applyChanges()`/`closeEdit()`).\n\t */\n\tpublic applyEdit(...changes: Change[]): EditId {\n\t\tthis.openEdit();\n\t\tthis.applyChanges(...changes);\n\t\treturn this.closeEdit();\n\t}\n\n\t/**\n\t * Apply an edit, if valid, otherwise does nothing (the edit is not added to the history).\n\t * If the edit applied, its changes will be immediately visible on this checkout, though it still may end up invalid once sequenced due to concurrent edits.\n\t * @returns The EditId if the edit was valid and thus applied, and undefined if it was invalid and thus not applied.\n\t */\n\tpublic tryApplyEdit(...changes: Change[]): EditId | undefined {\n\t\tthis.openEdit();\n\n\t\tassert(this.currentEdit, 'Changes must be applied as part of an ongoing edit.');\n\t\tconst { status } = this.currentEdit.applyChanges(changes.map((c) => this.tree.internalizeChange(c)));\n\t\tif (status === EditStatus.Applied) {\n\t\t\tthis.emitChange();\n\t\t\treturn this.closeEdit();\n\t\t}\n\n\t\tthis.abortEdit();\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Rebases the ongoing edit to the latest revision loaded by this 'Checkout'.\n\t * If the rebase succeeds (none of the changes in the ongoing edit became invalid), the ongoing edit will remain open and the current\n\t * view will reflect those changes.\n\t *\n\t * If the rebase fails (changes become invalid), the ongoing edit will be aborted and\n\t * currentView will return to showing the newest committed revision as it always does when there is no ongoing edit.\n\t *\n\t * Must only be called during an open edit.\n\t * @returns - the result of the rebase.\n\t */\n\tpublic rebaseCurrentEdit(): EditValidationResult.Valid | EditValidationResult.Invalid {\n\t\tassert(this.currentEdit !== undefined, 'An edit is not open.');\n\t\tassert(this.currentEdit.status === EditStatus.Applied, 'Local edits should always be valid.');\n\t\t// When closed, the result might indicate Malformed due to unused detached entities.\n\t\t// This is not an error, as the edit was still open and can still use those entities.\n\t\tconst priorResults = this.currentEdit.close();\n\t\tconst rebasedEdit = TransactionInternal.factory(this.latestCommittedView).applyChanges(priorResults.changes);\n\t\tassert(\n\t\t\trebasedEdit.status !== EditStatus.Malformed,\n\t\t\t'Malformed changes should have been caught on original application.'\n\t\t);\n\t\tlet status: EditValidationResult.Valid | EditValidationResult.Invalid;\n\t\tif (rebasedEdit.status === EditStatus.Invalid) {\n\t\t\tstatus = EditValidationResult.Invalid;\n\t\t\tthis.currentEdit = undefined;\n\t\t} else {\n\t\t\tstatus = EditValidationResult.Valid;\n\t\t\tthis.currentEdit = rebasedEdit;\n\t\t}\n\t\tthis.emitChange();\n\t\treturn status;\n\t}\n\n\t/**\n\t * Ends the ongoing edit operation without committing it to the history.\n\t * Can only be called if an edit is open.\n\t */\n\tpublic abortEdit(): void {\n\t\tconst { currentEdit } = this;\n\t\tassert(currentEdit !== undefined, 'An edit is not open.');\n\t\tthis.currentEdit = undefined;\n\t\tthis.emitChange();\n\t}\n\n\t/**\n\t * @returns the {@link EditStatus} of the current edit.\n\t * Has no side effects.\n\t * Can only be called if an edit is open.\n\t */\n\tpublic getEditStatus(): EditStatus {\n\t\tconst { currentEdit } = this;\n\t\tassert(currentEdit !== undefined, 'An edit is not open.');\n\t\t// TODO: could this ever be anything other than 'Applied'\n\t\t// TODO: shouldn't this be an EditValidationResult since 'Applied' does not indicate the edit has been applied?\n\t\treturn currentEdit.status;\n\t}\n\n\t/**\n\t * Reverts a collection of edits.\n\t * @param editIds - the edits to revert\n\t */\n\tpublic revert(editId: EditId): void {\n\t\tassert(this.currentEdit !== undefined);\n\t\tconst index = this.tree.edits.getIndexOfId(editId);\n\t\tconst edit = this.tree.edits.getEditInSessionAtIndex(index);\n\t\tconst before = this.tree.logViewer.getRevisionViewInSession(index);\n\t\tconst changes = this.tree.revertChanges(edit.changes, before);\n\t\tif (changes !== undefined) {\n\t\t\tthis.tryApplyChangesInternal(...changes);\n\t\t}\n\t}\n\n\t/**\n\t * Send invalidation message for all changes since last call to emitChange.\n\t * This must be called every time `currentView` could have changed.\n\t * It is ok to make excessive calls to this: change notifications will be cheaply de-duplicated.\n\t */\n\tprotected emitChange(): void {\n\t\tconst current = this.currentView;\n\t\tconst previous = this.previousView;\n\t\tif (!previous.hasEqualForest(current, true)) {\n\t\t\t// Set previousView before calling emit to make reentrant case work (where the event handler causes an edit).\n\t\t\tthis.previousView = current;\n\t\t\tthis.emit(CheckoutEvent.ViewChange, previous, current);\n\t\t}\n\t}\n\n\t/**\n\t * @returns a Promise which completes after all currently known edits are available in this checkout.\n\t */\n\tpublic abstract waitForPendingUpdates(): Promise<void>;\n\n\t/**\n\t * @returns a Promise which completes after edits that were closed on this checkout (before calling this) have been\n\t * submitted to Fluid. This does NOT wait for the Fluid service to ack them\n\t */\n\tpublic abstract waitForEditsToSubmit(): Promise<void>;\n\n\t/**\n\t * release all unmanaged resources\n\t * e.g. unregister event listeners\n\t */\n\tpublic dispose(error?: Error): void {\n\t\tif (this.disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.disposed = true;\n\n\t\t// remove registered listener\n\t\tthis.tree.off(SharedTreeEvent.EditCommitted, this.editCommittedHandler);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Checkout.js","sourceRoot":"","sources":["../src/Checkout.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAE7F,OAAO,EAAE,MAAM,EAAE,IAAI,EAAe,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAI/C,OAAO,EAAsB,mBAAmB,EA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AAE,QAAQ,EAAE,OAAO,CAAC,CAAC;SACvD;IACF,CAAC;IAaD;;;OAGG;IACI,OAAO,CAAC,KAAa;QAC3B,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClB,OAAO;SACP;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QAErB,6BAA6B;QAC7B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,aAAa,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACzE,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ChildLogger, EventEmitterWithErrorHandling } from '@fluidframework/telemetry-utils';\nimport { IDisposable, IErrorEvent, ITelemetryLogger, ITelemetryProperties } from '@fluidframework/common-definitions';\nimport { assert, fail, RestOrArray, unwrapRestOrArray } from './Common';\nimport { EditId } from './Identifiers';\nimport { CachingLogViewer } from './LogViewer';\nimport { TreeView } from './TreeView';\nimport { RevisionView } from './RevisionView';\nimport { EditCommittedHandler, SharedTree } from './SharedTree';\nimport { GenericTransaction, TransactionInternal, ValidEditingResult } from './TransactionInternal';\nimport { ChangeInternal, Edit, EditStatus } from './persisted-types';\nimport { SharedTreeEvent } from './EventTypes';\nimport { newEditId } from './EditUtilities';\nimport { Change } from './ChangeTypes';\n\n/**\n * An event emitted by a `Checkout` to indicate a state change. See {@link ICheckoutEvents} for event argument information.\n * @public\n */\nexport enum CheckoutEvent {\n\t/**\n\t * `currentView` has changed.\n\t * Passed a before and after TreeView.\n\t */\n\tViewChange = 'viewChange',\n}\n\n/**\n * Events which may be emitted by `Checkout`. See {@link CheckoutEvent} for documentation of event semantics.\n */\nexport interface ICheckoutEvents extends IErrorEvent {\n\t(event: 'viewChange', listener: (before: TreeView, after: TreeView) => void);\n}\n\n/**\n * The result of validation of an Edit.\n * @public\n */\nexport enum EditValidationResult {\n\t/**\n\t * The edit contained one or more malformed changes (e.g. was missing required fields such as `id`),\n\t * or contained a sequence of changes that could not possibly be applied sequentially without error\n\t * (e.g. an edit which tries to insert the same detached node twice).\n\t */\n\tMalformed,\n\t/**\n\t * The edit is well-formed but cannot be applied to the current view, generally because concurrent changes\n\t * caused one or more merge conflicts.\n\t * For example, the edit refers to the `StablePlace` after node `C`, but `C` has since been deleted.\n\t */\n\tInvalid,\n\t/**\n\t * The edit is well-formed and can be applied to the current view.\n\t */\n\tValid,\n}\n\n/**\n * A mutable Checkout of a SharedTree, allowing viewing and interactive transactional editing.\n * Provides {@link https://en.wikipedia.org/wiki/Snapshot_isolation | snapshot-isolation} while editing.\n *\n * A Checkout always shows a consistent sequence of versions of the SharedTree, but it may skip intermediate versions, and may fall behind.\n * In this case consistent means the sequence of versions could occur with fully synchronous shared tree access,\n * though the timing of sequenced edits arriving to the Checkout may be later than they actually arrive in the SharedTree.\n * Specifically no sequenced edits will arrive during an ongoing edit (to implement snapshot isolation):\n * they will be applied asynchronously some time after the ongoing edit is ended.\n *\n * Events emitted by `Checkout` are documented in {@link CheckoutEvent}.\n * Exceptions thrown during event handling will be emitted as error events, which are automatically surfaced as error events on the\n * `SharedTree` used at construction time.\n * @public\n */\nexport abstract class Checkout extends EventEmitterWithErrorHandling<ICheckoutEvents> implements IDisposable {\n\t/**\n\t * The view of the latest committed revision.\n\t * Does not include changes from any open edits.\n\t *\n\t * When this changes, emitChange must be called.\n\t */\n\tprotected abstract get latestCommittedView(): RevisionView;\n\n\t/**\n\t * The last view for which invalidation was sent.\n\t * Updated by emitChange.\n\t */\n\tprivate previousView: TreeView;\n\n\t/**\n\t * A handler for 'committedEdit' SharedTreeEvent\n\t */\n\tprivate readonly editCommittedHandler: EditCommittedHandler;\n\n\t/**\n\t * The shared tree this checkout views/edits.\n\t */\n\tpublic readonly tree: SharedTree;\n\n\t/**\n\t * `tree`'s log viewer as a CachingLogViewer if it is one, otherwise undefined.\n\t * Used for optimizations if provided.\n\t */\n\tprivate readonly cachingLogViewer?: CachingLogViewer;\n\n\t/**\n\t * Holds the state required to manage the currently open edit.\n\t * Undefined if there is currently not an open edit.\n\t *\n\t * Since `currentView` exposes the the intermediate state from this edit,\n\t * operations that modify `currentEdit.view` must call `emitChange` to handle invalidation.\n\t */\n\tprivate currentEdit?: GenericTransaction;\n\n\tprivate readonly logger: ITelemetryLogger;\n\n\tpublic disposed: boolean = false;\n\n\tprotected constructor(tree: SharedTree, currentView: RevisionView, onEditCommitted: EditCommittedHandler) {\n\t\tsuper((_event, error: unknown) => {\n\t\t\tthis.tree.emit('error', error);\n\t\t});\n\t\tthis.tree = tree;\n\t\tthis.logger = ChildLogger.create(this.tree.logger, 'Checkout');\n\t\tif (tree.logViewer instanceof CachingLogViewer) {\n\t\t\tthis.cachingLogViewer = tree.logViewer;\n\t\t}\n\t\tthis.previousView = currentView;\n\t\tthis.editCommittedHandler = onEditCommitted;\n\n\t\t// If there is an ongoing edit, emitChange will no-op, which is fine.\n\t\tthis.tree.on(SharedTreeEvent.EditCommitted, this.editCommittedHandler);\n\t}\n\n\t/**\n\t * @returns the current view of the tree, including the result of changes applied so far during an edit.\n\t * Note that any external edits (from other clients) will not added to view while there is a `currentEdit`.\n\t */\n\tpublic get currentView(): TreeView {\n\t\treturn this.currentEdit?.view ?? this.latestCommittedView;\n\t}\n\n\t/**\n\t * @returns true iff there is an open edit.\n\t * @internal\n\t */\n\tpublic hasOpenEdit(): boolean {\n\t\treturn this.currentEdit !== undefined;\n\t}\n\n\t/**\n\t * Opens a new edit operation.\n\t * Changes accumulate in the edit via calls to `applyChanges()`.\n\t */\n\tpublic openEdit(): void {\n\t\tassert(this.currentEdit === undefined, 'An edit is already open.');\n\t\tthis.currentEdit = TransactionInternal.factory(this.latestCommittedView);\n\t}\n\n\t/**\n\t * Ends the ongoing edit operation and commits it to the history.\n\t *\n\t * Malformed edits are considered an error, and will assert:\n\t * All named detached sequences must have been used or theEdit is malformed.\n\t *\n\t * @returns the `id` of the committed edit\n\t */\n\tpublic closeEdit(): EditId {\n\t\tconst { currentEdit } = this;\n\t\tassert(currentEdit !== undefined, 'An edit is not open.');\n\t\tthis.currentEdit = undefined;\n\t\tconst editingResult = currentEdit.close();\n\t\tif (editingResult.status !== EditStatus.Applied) {\n\t\t\tconst { failure } = editingResult;\n\t\t\tconst additionalProps: ITelemetryProperties = {};\n\t\t\tswitch (failure.kind) {\n\t\t\t\tcase TransactionInternal.FailureKind.BadPlace:\n\t\t\t\t\tadditionalProps.placeFailure = failure.placeFailure;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TransactionInternal.FailureKind.BadRange: {\n\t\t\t\t\tconst { rangeFailure } = failure;\n\t\t\t\t\tif (typeof rangeFailure === 'string') {\n\t\t\t\t\t\tadditionalProps.rangeFailure = rangeFailure;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tadditionalProps.rangeFailure = rangeFailure.kind;\n\t\t\t\t\t\tadditionalProps.rangeEndpointFailure = rangeFailure.placeFailure;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\teventName: 'FailedLocalEdit',\n\t\t\t\tstatus: editingResult.status === 0 ? 'Malformed' : 'Invalid',\n\t\t\t\tfailureKind: editingResult.failure.kind,\n\t\t\t\t...additionalProps,\n\t\t\t});\n\t\t\tfail('Locally constructed edits must be well-formed and valid');\n\t\t}\n\n\t\tconst id: EditId = newEditId();\n\t\tthis.handleNewEdit(id, editingResult);\n\t\treturn id;\n\t}\n\n\t/**\n\t * Inform the Checkout that a particular edit is know to have a specific result when applied to a particular TreeView.\n\t * This may be used as a caching hint to avoid recomputation.\n\t */\n\tprotected hintKnownEditingResult(edit: Edit<ChangeInternal>, result: ValidEditingResult): void {\n\t\t// As an optimization, inform logViewer of this editing result so it can reuse it if applied to the same before revision.\n\t\tthis.cachingLogViewer?.setKnownEditingResult(edit, result);\n\t}\n\n\t/**\n\t * Take any needed action between when an edit is completed.\n\t * Usually this will include submitting it to a SharedTree.\n\t *\n\t * Override this to customize.\n\t */\n\tprotected handleNewEdit(id: EditId, result: ValidEditingResult): void {\n\t\tconst edit: Edit<ChangeInternal> = { id, changes: result.changes };\n\n\t\tthis.hintKnownEditingResult(edit, result);\n\n\t\t// Since external edits could have been applied while currentEdit was pending,\n\t\t// do not use the produced view: just go to the newest revision\n\t\t// (which processLocalEdit will do, including invalidation).\n\t\tthis.tree.applyEditInternal(edit);\n\t}\n\n\t/**\n\t * Applies the supplied changes to the tree and emits a change event.\n\t * Must be called during an ongoing edit (see `openEdit()`/`closeEdit()`).\n\t * `changes` must be well-formed and valid: it is an error if they do not apply cleanly.\n\t */\n\tpublic applyChanges(changes: readonly Change[]): void;\n\tpublic applyChanges(...changes: readonly Change[]): void;\n\tpublic applyChanges(...changes: RestOrArray<Change>): void {\n\t\tassert(this.currentEdit, 'Changes must be applied as part of an ongoing edit.');\n\t\tconst changeArray = unwrapRestOrArray(changes);\n\t\tconst { status } = this.currentEdit.applyChanges(changeArray.map((c) => this.tree.internalizeChange(c)));\n\t\tassert(status === EditStatus.Applied, 'Locally constructed edits must be well-formed and valid.');\n\t\tthis.emitChange();\n\t}\n\n\t/**\n\t * Applies the supplied changes to the tree and emits a change event.\n\t * Must be called during an ongoing edit (see `openEdit()`/`closeEdit()`).\n\t * `changes` must be well-formed and valid: it is an error if they do not apply cleanly.\n\t */\n\tprotected tryApplyChangesInternal(changes: readonly ChangeInternal[]): EditStatus;\n\tprotected tryApplyChangesInternal(...changes: readonly ChangeInternal[]): EditStatus;\n\tprotected tryApplyChangesInternal(...changes: RestOrArray<ChangeInternal>): EditStatus {\n\t\tassert(this.currentEdit, 'Changes must be applied as part of an ongoing edit.');\n\t\tconst changeArray = unwrapRestOrArray(changes);\n\t\tconst { status } = this.currentEdit.applyChanges(changeArray);\n\t\tif (status === EditStatus.Applied) {\n\t\t\tthis.emitChange();\n\t\t}\n\t\treturn status;\n\t}\n\n\t/**\n\t * Convenience helper for applying an edit containing the given changes.\n\t * Opens an edit, applies the given changes, and closes the edit. See (`openEdit()`/`applyChanges()`/`closeEdit()`).\n\t */\n\tpublic applyEdit(changes: readonly Change[]): EditId;\n\tpublic applyEdit(...changes: readonly Change[]): EditId;\n\tpublic applyEdit(...changes: RestOrArray<Change>): EditId {\n\t\tthis.openEdit();\n\t\tconst changeArray = unwrapRestOrArray(changes);\n\t\tthis.applyChanges(changeArray);\n\t\treturn this.closeEdit();\n\t}\n\n\t/**\n\t * Apply an edit, if valid, otherwise does nothing (the edit is not added to the history).\n\t * If the edit applied, its changes will be immediately visible on this checkout, though it still may end up invalid once sequenced due to concurrent edits.\n\t * @returns The EditId if the edit was valid and thus applied, and undefined if it was invalid and thus not applied.\n\t */\n\tpublic tryApplyEdit(changes: readonly Change[]): EditId | undefined;\n\tpublic tryApplyEdit(...changes: readonly Change[]): EditId | undefined;\n\tpublic tryApplyEdit(...changes: RestOrArray<Change>): EditId | undefined {\n\t\tthis.openEdit();\n\n\t\tassert(this.currentEdit, 'Changes must be applied as part of an ongoing edit.');\n\t\tconst changeArray = unwrapRestOrArray(changes);\n\t\tconst { status } = this.currentEdit.applyChanges(changeArray.map((c) => this.tree.internalizeChange(c)));\n\t\tif (status === EditStatus.Applied) {\n\t\t\tthis.emitChange();\n\t\t\treturn this.closeEdit();\n\t\t}\n\n\t\tthis.abortEdit();\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Rebases the ongoing edit to the latest revision loaded by this 'Checkout'.\n\t * If the rebase succeeds (none of the changes in the ongoing edit became invalid), the ongoing edit will remain open and the current\n\t * view will reflect those changes.\n\t *\n\t * If the rebase fails (changes become invalid), the ongoing edit will be aborted and\n\t * currentView will return to showing the newest committed revision as it always does when there is no ongoing edit.\n\t *\n\t * Must only be called during an open edit.\n\t * @returns - the result of the rebase.\n\t */\n\tpublic rebaseCurrentEdit(): EditValidationResult.Valid | EditValidationResult.Invalid {\n\t\tassert(this.currentEdit !== undefined, 'An edit is not open.');\n\t\tassert(this.currentEdit.status === EditStatus.Applied, 'Local edits should always be valid.');\n\t\t// When closed, the result might indicate Malformed due to unused detached entities.\n\t\t// This is not an error, as the edit was still open and can still use those entities.\n\t\tconst priorResults = this.currentEdit.close();\n\t\tconst rebasedEdit = TransactionInternal.factory(this.latestCommittedView).applyChanges(priorResults.changes);\n\t\tassert(\n\t\t\trebasedEdit.status !== EditStatus.Malformed,\n\t\t\t'Malformed changes should have been caught on original application.'\n\t\t);\n\t\tlet status: EditValidationResult.Valid | EditValidationResult.Invalid;\n\t\tif (rebasedEdit.status === EditStatus.Invalid) {\n\t\t\tstatus = EditValidationResult.Invalid;\n\t\t\tthis.currentEdit = undefined;\n\t\t} else {\n\t\t\tstatus = EditValidationResult.Valid;\n\t\t\tthis.currentEdit = rebasedEdit;\n\t\t}\n\t\tthis.emitChange();\n\t\treturn status;\n\t}\n\n\t/**\n\t * Ends the ongoing edit operation without committing it to the history.\n\t * Can only be called if an edit is open.\n\t */\n\tpublic abortEdit(): void {\n\t\tconst { currentEdit } = this;\n\t\tassert(currentEdit !== undefined, 'An edit is not open.');\n\t\tthis.currentEdit = undefined;\n\t\tthis.emitChange();\n\t}\n\n\t/**\n\t * @returns the {@link EditStatus} of the current edit.\n\t * Has no side effects.\n\t * Can only be called if an edit is open.\n\t */\n\tpublic getEditStatus(): EditStatus {\n\t\tconst { currentEdit } = this;\n\t\tassert(currentEdit !== undefined, 'An edit is not open.');\n\t\t// TODO: could this ever be anything other than 'Applied'\n\t\t// TODO: shouldn't this be an EditValidationResult since 'Applied' does not indicate the edit has been applied?\n\t\treturn currentEdit.status;\n\t}\n\n\t/**\n\t * Reverts a collection of edits.\n\t * @param editIds - the edits to revert\n\t */\n\tpublic revert(editId: EditId): void {\n\t\tassert(this.currentEdit !== undefined);\n\t\tconst index = this.tree.edits.getIndexOfId(editId);\n\t\tconst edit = this.tree.edits.getEditInSessionAtIndex(index);\n\t\tconst before = this.tree.logViewer.getRevisionViewInSession(index);\n\t\tconst changes = this.tree.revertChanges(edit.changes, before);\n\t\tif (changes !== undefined) {\n\t\t\tthis.tryApplyChangesInternal(changes);\n\t\t}\n\t}\n\n\t/**\n\t * Send invalidation message for all changes since last call to emitChange.\n\t * This must be called every time `currentView` could have changed.\n\t * It is ok to make excessive calls to this: change notifications will be cheaply de-duplicated.\n\t */\n\tprotected emitChange(): void {\n\t\tconst current = this.currentView;\n\t\tconst previous = this.previousView;\n\t\tif (!previous.hasEqualForest(current, true)) {\n\t\t\t// Set previousView before calling emit to make reentrant case work (where the event handler causes an edit).\n\t\t\tthis.previousView = current;\n\t\t\tthis.emit(CheckoutEvent.ViewChange, previous, current);\n\t\t}\n\t}\n\n\t/**\n\t * @returns a Promise which completes after all currently known edits are available in this checkout.\n\t */\n\tpublic abstract waitForPendingUpdates(): Promise<void>;\n\n\t/**\n\t * @returns a Promise which completes after edits that were closed on this checkout (before calling this) have been\n\t * submitted to Fluid. This does NOT wait for the Fluid service to ack them\n\t */\n\tpublic abstract waitForEditsToSubmit(): Promise<void>;\n\n\t/**\n\t * release all unmanaged resources\n\t * e.g. unregister event listeners\n\t */\n\tpublic dispose(error?: Error): void {\n\t\tif (this.disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.disposed = true;\n\n\t\t// remove registered listener\n\t\tthis.tree.off(SharedTreeEvent.EditCommitted, this.editCommittedHandler);\n\t}\n}\n"]}
|
package/lib/Common.d.ts
CHANGED
|
@@ -81,15 +81,15 @@ export declare function fail(message?: string, containsPII?: boolean): never;
|
|
|
81
81
|
export declare function assertNotUndefined<T>(value: T | undefined, message?: string): T;
|
|
82
82
|
/**
|
|
83
83
|
* Asserts an array contains a single value and returns the value.
|
|
84
|
-
* @param array -
|
|
84
|
+
* @param array - Array to assert contains a single value.
|
|
85
85
|
* @param message - Message to be printed if assertion fails.
|
|
86
86
|
*/
|
|
87
87
|
export declare function assertArrayOfOne<T>(array: readonly T[], message?: string): T;
|
|
88
88
|
/**
|
|
89
89
|
* Assign a property and value to a given object.
|
|
90
|
-
* @param object -
|
|
91
|
-
* @param property -
|
|
92
|
-
* @param value -
|
|
90
|
+
* @param object - The object to add the property to
|
|
91
|
+
* @param property - The property key
|
|
92
|
+
* @param value - The value of the property
|
|
93
93
|
* @returns `object` after assigning `value` to the property `property`.
|
|
94
94
|
*/
|
|
95
95
|
export declare function assign<T, K extends keyof never, V>(object: T, property: K, value: V): With<T, K, V>;
|
|
@@ -106,9 +106,9 @@ export declare function assign<T, K extends keyof never, V>(object: T, property:
|
|
|
106
106
|
* }
|
|
107
107
|
* }
|
|
108
108
|
* ```
|
|
109
|
-
* @param object -
|
|
110
|
-
* @param propName -
|
|
111
|
-
* @param value -
|
|
109
|
+
* @param object - The object containing the property
|
|
110
|
+
* @param propName - The name of the property on the object
|
|
111
|
+
* @param value - The value of the property
|
|
112
112
|
*/
|
|
113
113
|
export declare function memoizeGetter<T, K extends keyof T>(object: T, propName: K, value: T[K]): T[K];
|
|
114
114
|
/**
|
|
@@ -129,32 +129,32 @@ export declare function reduce<T>(sequence: Iterable<T>, reduce: (previous: T, c
|
|
|
129
129
|
export declare function find<T>(sequence: Iterable<T>, find: (t: T) => boolean): T | undefined;
|
|
130
130
|
/**
|
|
131
131
|
* Iterate through two iterables and return true if they yield equivalent elements in the same order.
|
|
132
|
-
* @param iterableA -
|
|
133
|
-
* @param iterableB -
|
|
134
|
-
* @param elementComparator -
|
|
132
|
+
* @param iterableA - The first iterable to compare
|
|
133
|
+
* @param iterableB - The second iterable to compare
|
|
134
|
+
* @param elementComparator - The function used to check if two `T`s are equivalent.
|
|
135
135
|
* Defaults to `Object.is()` equality (a shallow compare)
|
|
136
136
|
*/
|
|
137
137
|
export declare function compareIterables<T>(iterableA: Iterable<T>, iterableB: Iterable<T>, elementComparator?: (a: T, b: T) => boolean): boolean;
|
|
138
138
|
/**
|
|
139
139
|
* Compare two arrays and return true if their elements are equivalent and in the same order.
|
|
140
|
-
* @param arrayA -
|
|
141
|
-
* @param arrayB -
|
|
142
|
-
* @param elementComparator -
|
|
140
|
+
* @param arrayA - The first array to compare
|
|
141
|
+
* @param arrayB - The second array to compare
|
|
142
|
+
* @param elementComparator - The function used to check if two `T`s are equivalent.
|
|
143
143
|
* Defaults to `Object.is()` equality (a shallow compare)
|
|
144
144
|
*/
|
|
145
145
|
export declare function compareArrays<T>(arrayA: readonly T[], arrayB: readonly T[], elementComparator?: (a: T, b: T) => boolean): boolean;
|
|
146
146
|
/**
|
|
147
147
|
* Compare two maps and return true if their contents are equivalent.
|
|
148
|
-
* @param mapA -
|
|
149
|
-
* @param mapB -
|
|
150
|
-
* @param elementComparator -
|
|
148
|
+
* @param mapA - The first array to compare
|
|
149
|
+
* @param mapB - The second array to compare
|
|
150
|
+
* @param elementComparator - The function used to check if two `T`s are equivalent.
|
|
151
151
|
* Defaults to `Object.is()` equality (a shallow compare)
|
|
152
152
|
*/
|
|
153
153
|
export declare function compareMaps<K, V>(mapA: ReadonlyMap<K, V>, mapB: ReadonlyMap<K, V>, elementComparator?: (a: V, b: V) => boolean): boolean;
|
|
154
154
|
/**
|
|
155
155
|
* Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.
|
|
156
|
-
* @param map -
|
|
157
|
-
* @param key -
|
|
156
|
+
* @param map - The map to query/update
|
|
157
|
+
* @param key - The key to lookup in the map
|
|
158
158
|
* @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists
|
|
159
159
|
* @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)
|
|
160
160
|
*/
|
|
@@ -296,5 +296,18 @@ export declare function hasExactlyLength<T, Len extends TakeWholeNumbers<16>>(ar
|
|
|
296
296
|
* Fails if `array` does not have at least `length` elements
|
|
297
297
|
*/
|
|
298
298
|
export declare function hasLength<T, Len extends TakeWholeNumbers<16>>(array: readonly T[], length: Len): array is [...ArrayOfLength<T, Len>, ...T[]];
|
|
299
|
+
/**
|
|
300
|
+
* Type for a rest parameter which can accept many values, or a single array.
|
|
301
|
+
* Since a callee cannot modify an array passed as a rest parameter with the spread operator,
|
|
302
|
+
* an array passed directly should be readonly for consistency (caller retains ownership).
|
|
303
|
+
*/
|
|
304
|
+
export declare type RestOrArray<T> = readonly T[] | [readonly T[]];
|
|
305
|
+
/**
|
|
306
|
+
* When value is a one-element array containing another array, unwraps and returns the inner array.
|
|
307
|
+
* Otherwise, returns the provided array.
|
|
308
|
+
* Useful for implementing functions with a `RestOrArray` parameter.
|
|
309
|
+
* T must not be implemented with an array (`Array.isArray(t)` must return false)
|
|
310
|
+
*/
|
|
311
|
+
export declare function unwrapRestOrArray<T>(value: [any[]] extends [T] ? never : RestOrArray<T>): readonly T[];
|
|
299
312
|
export {};
|
|
300
313
|
//# sourceMappingURL=Common.d.ts.map
|
package/lib/Common.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Common.d.ts","sourceRoot":"","sources":["../src/Common.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC/F,OAAO,KAAK,MAAM,cAAc,CAAC;AAIjC;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,wBAAwB,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,6BAA8B,SAAQ,oBAAoB;IAC1E,QAAQ,CAAC,iBAAiB,EAAE,IAAI,CAAC;CACjC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAErE;AAgBD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAEzE;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAEjF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,CA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AAG,aAAa,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAE7C;AAED;;;;GAIG;AACH,oBAAY,WAAW,CAAC,CAAC,IAAI,SAAS,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;AAE3D;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,CAEtG"}
|
package/lib/Common.js
CHANGED
|
@@ -109,7 +109,7 @@ export function assertNotUndefined(value, message = 'value must not be undefined
|
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
111
|
* Asserts an array contains a single value and returns the value.
|
|
112
|
-
* @param array -
|
|
112
|
+
* @param array - Array to assert contains a single value.
|
|
113
113
|
* @param message - Message to be printed if assertion fails.
|
|
114
114
|
*/
|
|
115
115
|
export function assertArrayOfOne(array, message = 'array value must contain exactly one item') {
|
|
@@ -118,9 +118,9 @@ export function assertArrayOfOne(array, message = 'array value must contain exac
|
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
120
|
* Assign a property and value to a given object.
|
|
121
|
-
* @param object -
|
|
122
|
-
* @param property -
|
|
123
|
-
* @param value -
|
|
121
|
+
* @param object - The object to add the property to
|
|
122
|
+
* @param property - The property key
|
|
123
|
+
* @param value - The value of the property
|
|
124
124
|
* @returns `object` after assigning `value` to the property `property`.
|
|
125
125
|
*/
|
|
126
126
|
export function assign(object, property, value) {
|
|
@@ -139,9 +139,9 @@ export function assign(object, property, value) {
|
|
|
139
139
|
* }
|
|
140
140
|
* }
|
|
141
141
|
* ```
|
|
142
|
-
* @param object -
|
|
143
|
-
* @param propName -
|
|
144
|
-
* @param value -
|
|
142
|
+
* @param object - The object containing the property
|
|
143
|
+
* @param propName - The name of the property on the object
|
|
144
|
+
* @param value - The value of the property
|
|
145
145
|
*/
|
|
146
146
|
export function memoizeGetter(object, propName, value) {
|
|
147
147
|
Object.defineProperty(object, propName, {
|
|
@@ -202,9 +202,9 @@ export function find(sequence, find) {
|
|
|
202
202
|
}
|
|
203
203
|
/**
|
|
204
204
|
* Iterate through two iterables and return true if they yield equivalent elements in the same order.
|
|
205
|
-
* @param iterableA -
|
|
206
|
-
* @param iterableB -
|
|
207
|
-
* @param elementComparator -
|
|
205
|
+
* @param iterableA - The first iterable to compare
|
|
206
|
+
* @param iterableB - The second iterable to compare
|
|
207
|
+
* @param elementComparator - The function used to check if two `T`s are equivalent.
|
|
208
208
|
* Defaults to `Object.is()` equality (a shallow compare)
|
|
209
209
|
*/
|
|
210
210
|
export function compareIterables(iterableA, iterableB, elementComparator = Object.is) {
|
|
@@ -212,9 +212,9 @@ export function compareIterables(iterableA, iterableB, elementComparator = Objec
|
|
|
212
212
|
}
|
|
213
213
|
/**
|
|
214
214
|
* Iterate through two iterators and return true if they yield equivalent elements in the same order.
|
|
215
|
-
* @param iteratorA -
|
|
216
|
-
* @param iteratorB -
|
|
217
|
-
* @param elementComparator -
|
|
215
|
+
* @param iteratorA - The first iterator to compare
|
|
216
|
+
* @param iteratorB - The second iterator to compare
|
|
217
|
+
* @param elementComparator - The function used to check if two `T`s are equivalent.
|
|
218
218
|
* Defaults to `Object.is()` equality (a shallow compare)
|
|
219
219
|
*/
|
|
220
220
|
function compareIterators(iteratorA, iteratorB, elementComparator = Object.is) {
|
|
@@ -234,9 +234,9 @@ function compareIterators(iteratorA, iteratorB, elementComparator = Object.is) {
|
|
|
234
234
|
}
|
|
235
235
|
/**
|
|
236
236
|
* Compare two arrays and return true if their elements are equivalent and in the same order.
|
|
237
|
-
* @param arrayA -
|
|
238
|
-
* @param arrayB -
|
|
239
|
-
* @param elementComparator -
|
|
237
|
+
* @param arrayA - The first array to compare
|
|
238
|
+
* @param arrayB - The second array to compare
|
|
239
|
+
* @param elementComparator - The function used to check if two `T`s are equivalent.
|
|
240
240
|
* Defaults to `Object.is()` equality (a shallow compare)
|
|
241
241
|
*/
|
|
242
242
|
export function compareArrays(arrayA, arrayB, elementComparator = Object.is) {
|
|
@@ -252,9 +252,9 @@ export function compareArrays(arrayA, arrayB, elementComparator = Object.is) {
|
|
|
252
252
|
}
|
|
253
253
|
/**
|
|
254
254
|
* Compare two maps and return true if their contents are equivalent.
|
|
255
|
-
* @param mapA -
|
|
256
|
-
* @param mapB -
|
|
257
|
-
* @param elementComparator -
|
|
255
|
+
* @param mapA - The first array to compare
|
|
256
|
+
* @param mapB - The second array to compare
|
|
257
|
+
* @param elementComparator - The function used to check if two `T`s are equivalent.
|
|
258
258
|
* Defaults to `Object.is()` equality (a shallow compare)
|
|
259
259
|
*/
|
|
260
260
|
export function compareMaps(mapA, mapB, elementComparator = Object.is) {
|
|
@@ -271,8 +271,8 @@ export function compareMaps(mapA, mapB, elementComparator = Object.is) {
|
|
|
271
271
|
}
|
|
272
272
|
/**
|
|
273
273
|
* Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.
|
|
274
|
-
* @param map -
|
|
275
|
-
* @param key -
|
|
274
|
+
* @param map - The map to query/update
|
|
275
|
+
* @param key - The key to lookup in the map
|
|
276
276
|
* @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists
|
|
277
277
|
* @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)
|
|
278
278
|
*/
|
|
@@ -424,4 +424,13 @@ export function hasExactlyLength(array, length) {
|
|
|
424
424
|
export function hasLength(array, length) {
|
|
425
425
|
return array.length >= length;
|
|
426
426
|
}
|
|
427
|
+
/**
|
|
428
|
+
* When value is a one-element array containing another array, unwraps and returns the inner array.
|
|
429
|
+
* Otherwise, returns the provided array.
|
|
430
|
+
* Useful for implementing functions with a `RestOrArray` parameter.
|
|
431
|
+
* T must not be implemented with an array (`Array.isArray(t)` must return false)
|
|
432
|
+
*/
|
|
433
|
+
export function unwrapRestOrArray(value) {
|
|
434
|
+
return value.length === 1 && Array.isArray(value[0]) ? value[0] : value;
|
|
435
|
+
}
|
|
427
436
|
//# sourceMappingURL=Common.js.map
|