@fluid-experimental/tree 0.56.7 → 0.57.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +1 -1
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js +1 -2
- package/dist/Common.js.map +1 -1
- package/dist/Forest.d.ts.map +1 -1
- package/dist/Forest.js +0 -1
- package/dist/Forest.js.map +1 -1
- package/dist/RevisionValueCache.d.ts.map +1 -1
- package/dist/RevisionValueCache.js +0 -2
- package/dist/RevisionValueCache.js.map +1 -1
- package/dist/Snapshot.d.ts.map +1 -1
- package/dist/Snapshot.js.map +1 -1
- package/dist/TreeNodeHandle.d.ts.map +1 -1
- package/dist/TreeNodeHandle.js +0 -1
- package/dist/TreeNodeHandle.js.map +1 -1
- package/dist/default-edits/HistoryEditFactory.d.ts.map +1 -1
- package/dist/default-edits/HistoryEditFactory.js +1 -1
- package/dist/default-edits/HistoryEditFactory.js.map +1 -1
- package/dist/default-edits/PersistedTypes.d.ts.map +1 -1
- package/dist/default-edits/PersistedTypes.js +0 -1
- package/dist/default-edits/PersistedTypes.js.map +1 -1
- package/dist/default-edits/Transaction.d.ts.map +1 -1
- package/dist/default-edits/Transaction.js.map +1 -1
- package/dist/default-edits/UndoRedoHandler.d.ts +1 -1
- package/dist/default-edits/UndoRedoHandler.d.ts.map +1 -1
- package/dist/default-edits/UndoRedoHandler.js +0 -4
- package/dist/default-edits/UndoRedoHandler.js.map +1 -1
- package/dist/generic/GenericSharedTree.d.ts +0 -4
- package/dist/generic/GenericSharedTree.d.ts.map +1 -1
- package/dist/generic/GenericSharedTree.js +0 -6
- package/dist/generic/GenericSharedTree.js.map +1 -1
- package/dist/generic/GenericTransaction.js +0 -1
- package/dist/generic/GenericTransaction.js.map +1 -1
- package/lib/Common.d.ts.map +1 -1
- package/lib/Common.js +1 -2
- package/lib/Common.js.map +1 -1
- package/lib/Forest.d.ts.map +1 -1
- package/lib/Forest.js +0 -1
- package/lib/Forest.js.map +1 -1
- package/lib/RevisionValueCache.d.ts.map +1 -1
- package/lib/RevisionValueCache.js +0 -2
- package/lib/RevisionValueCache.js.map +1 -1
- package/lib/Snapshot.d.ts.map +1 -1
- package/lib/Snapshot.js.map +1 -1
- package/lib/TreeNodeHandle.d.ts.map +1 -1
- package/lib/TreeNodeHandle.js +0 -1
- package/lib/TreeNodeHandle.js.map +1 -1
- package/lib/default-edits/HistoryEditFactory.d.ts.map +1 -1
- package/lib/default-edits/HistoryEditFactory.js +1 -1
- package/lib/default-edits/HistoryEditFactory.js.map +1 -1
- package/lib/default-edits/PersistedTypes.d.ts.map +1 -1
- package/lib/default-edits/PersistedTypes.js +0 -1
- package/lib/default-edits/PersistedTypes.js.map +1 -1
- package/lib/default-edits/Transaction.d.ts.map +1 -1
- package/lib/default-edits/Transaction.js.map +1 -1
- package/lib/default-edits/UndoRedoHandler.d.ts +1 -1
- package/lib/default-edits/UndoRedoHandler.d.ts.map +1 -1
- package/lib/default-edits/UndoRedoHandler.js +0 -4
- package/lib/default-edits/UndoRedoHandler.js.map +1 -1
- package/lib/generic/GenericSharedTree.d.ts +0 -4
- package/lib/generic/GenericSharedTree.d.ts.map +1 -1
- package/lib/generic/GenericSharedTree.js +0 -6
- package/lib/generic/GenericSharedTree.js.map +1 -1
- package/lib/generic/GenericTransaction.js +0 -1
- package/lib/generic/GenericTransaction.js.map +1 -1
- package/lib/test/SnapshotUtilities.tests.js +0 -3
- package/lib/test/SnapshotUtilities.tests.js.map +1 -1
- package/lib/test/undoRedoStackManager.d.ts.map +1 -1
- package/lib/test/undoRedoStackManager.js +0 -1
- package/lib/test/undoRedoStackManager.js.map +1 -1
- package/package.json +13 -13
- package/src/Common.ts +1 -2
- package/src/Forest.ts +0 -1
- package/src/RevisionValueCache.ts +0 -2
- package/src/Snapshot.ts +1 -0
- package/src/TreeNodeHandle.ts +0 -1
- package/src/default-edits/HistoryEditFactory.ts +1 -1
- package/src/default-edits/PersistedTypes.ts +0 -1
- package/src/default-edits/Transaction.ts +1 -0
- package/src/default-edits/UndoRedoHandler.ts +1 -5
- package/src/generic/GenericSharedTree.ts +0 -7
- package/src/generic/GenericTransaction.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenericTransaction.js","sourceRoot":"","sources":["../../src/generic/GenericTransaction.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AA2B9C;;;;;;;;;;;;GAYG;AACH,MAAM,OAAgB,kBAAkB;IAQvC;;;OAGG;IACH,YAAmB,IAAc;QATvB,YAAO,GAAe,UAAU,CAAC,OAAO,CAAC;QAChC,YAAO,GAAc,EAAE,CAAC;QACxB,UAAK,GAAoC,EAAE,CAAC;QACrD,WAAM,GAAG,IAAI,CAAC;QAOvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,oHAAoH;IACpH,IAAW,IAAI;QACd,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAED,0DAA0D;IAC1D,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED,oFAAoF;IAC7E,KAAK;QACX,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,qCAAqC,CAAC,CAAC;QAC3D,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,IAAI,CAAC,MAAM,KAAK,UAAU,CAAC,OAAO,EAAE;YACvC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;SACtC;QACD,IAAI,IAAI,CAAC,MAAM,KAAK,UAAU,CAAC,OAAO,EAAE;YACvC,OAAO;gBACN,MAAM,EAAE,UAAU,CAAC,OAAO;gBAC1B,MAAM,EAAE,IAAI,CAAC,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,EAAE;YACjC,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;YAClC,OAAO,IAAI,CAAC;SACZ;QACD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;QACnD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,cAAc,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC;IACb,CAAC;CAGD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, fail } from '../Common';\nimport { ReconciliationChange, ReconciliationPath } from '../ReconciliationPath';\nimport { Snapshot } from '../Snapshot';\nimport { EditStatus } from './PersistedTypes';\n\n/**\n * Result of applying a transaction.\n * @public\n */\nexport type EditingResult<TChange> =\n\t| {\n\t\t\treadonly status: EditStatus.Invalid | EditStatus.Malformed;\n\t\t\treadonly changes: readonly TChange[];\n\t\t\treadonly steps?: undefined;\n\t\t\treadonly before: Snapshot;\n\t }\n\t| ValidEditingResult<TChange>;\n\n/**\n * Result of applying a valid transaction.\n * @public\n */\nexport interface ValidEditingResult<TChange> {\n\treadonly status: EditStatus.Applied;\n\treadonly changes: readonly TChange[];\n\treadonly steps: readonly { resolvedChange: TChange; after: Snapshot }[];\n\treadonly before: Snapshot;\n\treadonly after: Snapshot;\n}\n\n/**\n * A mutable transaction for applying sequences of changes to a Snapshot.\n * Allows viewing the intermediate states.\n *\n * Contains necessary state to apply changes within an edit to a Snapshot.\n *\n * May have any number of changes applied to make up the edit.\n * Use `close` to complete the transaction, returning the array of changes and an EditingResult showing the\n * results of applying the changes as an Edit to the initial Snapshot (passed to the constructor).\n *\n * No data outside the Transaction is modified by Transaction:\n * the results from `close` must be used to actually submit an `Edit`.\n */\nexport abstract class GenericTransaction<TChange> {\n\tprotected readonly before: Snapshot;\n\tprotected _view: Snapshot;\n\tprotected _status: EditStatus = EditStatus.Applied;\n\tprotected readonly changes: TChange[] = [];\n\tprotected readonly steps: ReconciliationChange<TChange>[] = [];\n\tprotected isOpen = true;\n\n\t/**\n\t * Create and open an edit of the provided `Snapshot`. After applying 0 or more changes, this editor should be closed via `close()`.\n\t * @param view - the `Snapshot` at which this edit begins. The first change will be applied against this view.\n\t */\n\tpublic constructor(view: Snapshot) {\n\t\tthis._view = view;\n\t\tthis.before = view;\n\t}\n\n\t/** The most up-to-date `Snapshot` for this edit. This is the state of the tree after all changes applied so far. */\n\tpublic get view(): Snapshot {\n\t\treturn this._view;\n\t}\n\n\t/** The status code of the most recent attempted change */\n\tpublic get status(): EditStatus {\n\t\treturn this._status;\n\t}\n\n\t/** @returns the final `EditStatus` and `Snapshot` after all changes are applied. */\n\tpublic close(): EditingResult<TChange> {\n\t\tassert(this.isOpen, 'transaction has already been closed');\n\t\tthis.isOpen = false;\n\t\tif (this.status === EditStatus.Applied) {\n\t\t\tthis._status = this.validateOnClose();\n\t\t}\n\t\tif (this.status === EditStatus.Applied) {\n\t\t\treturn {\n\t\t\t\tstatus: EditStatus.Applied,\n\t\t\t\tbefore: this.before,\n\t\t\t\tafter: this._view,\n\t\t\t\tchanges: this.changes,\n\t\t\t\tsteps: this.steps,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tstatus: this.status,\n\t\t\tchanges: this.changes,\n\t\t\tbefore: this.before,\n\t\t};\n\t}\n\n\t/**\n\t * Override to provide additional transaction validation when the transaction is closed.\n\t * Only invoked when a transaction is otherwise valid.\n\t */\n\tprotected abstract validateOnClose(): EditStatus;\n\n\t/**\n\t * A helper to apply a sequence of changes. Changes will be applied one after the other. If a change fails to apply,\n\t * the remaining changes in `changes` will be ignored.\n\t * @param changes - the sequence of changes to apply.\n\t * @param path - the reconciliation path for the first change.\n\t * @returns this\n\t */\n\tpublic applyChanges(changes: Iterable<TChange>, path: ReconciliationPath<TChange> = []): this {\n\t\tconst iter = changes[Symbol.iterator]();\n\t\tconst firstChange = iter.next().value;\n\t\tlet iterResult = iter.next();\n\t\tif (iterResult.done === true) {\n\t\t\tfor (const change of changes) {\n\t\t\t\tif (this.applyChange(change, path).status !== EditStatus.Applied) {\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tif (this.applyChange(firstChange, path).status !== EditStatus.Applied) {\n\t\t\treturn this;\n\t\t}\n\n\t\tconst ongoingEdit = {\n\t\t\t0: this.steps[this.steps.length - 1],\n\t\t\tbefore: this.view,\n\t\t\tafter: this.view,\n\t\t\tlength: 1,\n\t\t};\n\n\t\t/**\n\t\t * We use a Proxy instead of `{ ...path, ...objectWithOngoingEdit }` to avoid eagerly demanding all parts of the path, which may\n\t\t * require extensive computation.\n\t\t */\n\t\tconst pathWithOngoingEdit = new Proxy(path, {\n\t\t\tget: (\n\t\t\t\ttarget: ReconciliationPath<TChange>,\n\t\t\t\tprop: string\n\t\t\t): ReconciliationPath<TChange>[number | 'length'] => {\n\t\t\t\tif (prop === 'length') {\n\t\t\t\t\treturn target.length + 1;\n\t\t\t\t}\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\t\t\treturn prop === String(target.length) ? ongoingEdit : target[prop];\n\t\t\t},\n\t\t});\n\n\t\twhile (iterResult.done !== true) {\n\t\t\tif (this.applyChange(iterResult.value, pathWithOngoingEdit).status !== EditStatus.Applied) {\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tongoingEdit[ongoingEdit.length] = this.steps[this.steps.length - 1];\n\t\t\tongoingEdit.length += 1;\n\t\t\tongoingEdit.after = this.view;\n\t\t\titerResult = iter.next();\n\t\t}\n\t\treturn this;\n\t}\n\n\tprotected tryResolveChange(change: TChange, path: ReconciliationPath<TChange>): TChange | undefined {\n\t\treturn change;\n\t}\n\n\t/**\n\t * Attempt to apply the given change as part of this edit. This method should not be called if a previous change in this edit failed to\n\t * apply.\n\t * @param change - the change to apply\n\t * @param path - the reconciliation path for the change.\n\t * @returns this\n\t */\n\tpublic applyChange(change: TChange, path: ReconciliationPath<TChange> = []): this {\n\t\tassert(this.isOpen, 'Editor must be open to apply changes.');\n\t\tif (this.status !== EditStatus.Applied) {\n\t\t\tfail('Cannot apply change to an edit unless all previous changes have applied');\n\t\t}\n\t\tconst resolvedChange = this.tryResolveChange(change, path);\n\t\tif (resolvedChange === undefined) {\n\t\t\tthis._status = EditStatus.Invalid;\n\t\t\treturn this;\n\t\t}\n\t\tthis.changes.push(change);\n\t\tthis._status = this.dispatchChange(resolvedChange);\n\t\tthis.steps.push({ resolvedChange, after: this.view });\n\t\treturn this;\n\t}\n\n\tprotected abstract dispatchChange(change: TChange): EditStatus;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"GenericTransaction.js","sourceRoot":"","sources":["../../src/generic/GenericTransaction.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AA2B9C;;;;;;;;;;;;GAYG;AACH,MAAM,OAAgB,kBAAkB;IAQvC;;;OAGG;IACH,YAAmB,IAAc;QATvB,YAAO,GAAe,UAAU,CAAC,OAAO,CAAC;QAChC,YAAO,GAAc,EAAE,CAAC;QACxB,UAAK,GAAoC,EAAE,CAAC;QACrD,WAAM,GAAG,IAAI,CAAC;QAOvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,oHAAoH;IACpH,IAAW,IAAI;QACd,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAED,0DAA0D;IAC1D,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED,oFAAoF;IAC7E,KAAK;QACX,MAAM,CAAC,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IAED;;;;;;OAMG;IACI,WAAW,CAAC,MAAe,EAAE,OAAoC,EAAE;QACzE,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,uCAAuC,CAAC,CAAC;QAC7D,IAAI,IAAI,CAAC,MAAM,KAAK,UAAU,CAAC,OAAO,EAAE;YACvC,IAAI,CAAC,yEAAyE,CAAC,CAAC;SAChF;QACD,MAAM,cAAc,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC3D,IAAI,cAAc,KAAK,SAAS,EAAE;YACjC,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;YAClC,OAAO,IAAI,CAAC;SACZ;QACD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;QACnD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,cAAc,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC;IACb,CAAC;CAGD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, fail } from '../Common';\nimport { ReconciliationChange, ReconciliationPath } from '../ReconciliationPath';\nimport { Snapshot } from '../Snapshot';\nimport { EditStatus } from './PersistedTypes';\n\n/**\n * Result of applying a transaction.\n * @public\n */\nexport type EditingResult<TChange> =\n\t| {\n\t\t\treadonly status: EditStatus.Invalid | EditStatus.Malformed;\n\t\t\treadonly changes: readonly TChange[];\n\t\t\treadonly steps?: undefined;\n\t\t\treadonly before: Snapshot;\n\t }\n\t| ValidEditingResult<TChange>;\n\n/**\n * Result of applying a valid transaction.\n * @public\n */\nexport interface ValidEditingResult<TChange> {\n\treadonly status: EditStatus.Applied;\n\treadonly changes: readonly TChange[];\n\treadonly steps: readonly { resolvedChange: TChange; after: Snapshot }[];\n\treadonly before: Snapshot;\n\treadonly after: Snapshot;\n}\n\n/**\n * A mutable transaction for applying sequences of changes to a Snapshot.\n * Allows viewing the intermediate states.\n *\n * Contains necessary state to apply changes within an edit to a Snapshot.\n *\n * May have any number of changes applied to make up the edit.\n * Use `close` to complete the transaction, returning the array of changes and an EditingResult showing the\n * results of applying the changes as an Edit to the initial Snapshot (passed to the constructor).\n *\n * No data outside the Transaction is modified by Transaction:\n * the results from `close` must be used to actually submit an `Edit`.\n */\nexport abstract class GenericTransaction<TChange> {\n\tprotected readonly before: Snapshot;\n\tprotected _view: Snapshot;\n\tprotected _status: EditStatus = EditStatus.Applied;\n\tprotected readonly changes: TChange[] = [];\n\tprotected readonly steps: ReconciliationChange<TChange>[] = [];\n\tprotected isOpen = true;\n\n\t/**\n\t * Create and open an edit of the provided `Snapshot`. After applying 0 or more changes, this editor should be closed via `close()`.\n\t * @param view - the `Snapshot` at which this edit begins. The first change will be applied against this view.\n\t */\n\tpublic constructor(view: Snapshot) {\n\t\tthis._view = view;\n\t\tthis.before = view;\n\t}\n\n\t/** The most up-to-date `Snapshot` for this edit. This is the state of the tree after all changes applied so far. */\n\tpublic get view(): Snapshot {\n\t\treturn this._view;\n\t}\n\n\t/** The status code of the most recent attempted change */\n\tpublic get status(): EditStatus {\n\t\treturn this._status;\n\t}\n\n\t/** @returns the final `EditStatus` and `Snapshot` after all changes are applied. */\n\tpublic close(): EditingResult<TChange> {\n\t\tassert(this.isOpen, 'transaction has already been closed');\n\t\tthis.isOpen = false;\n\t\tif (this.status === EditStatus.Applied) {\n\t\t\tthis._status = this.validateOnClose();\n\t\t}\n\t\tif (this.status === EditStatus.Applied) {\n\t\t\treturn {\n\t\t\t\tstatus: EditStatus.Applied,\n\t\t\t\tbefore: this.before,\n\t\t\t\tafter: this._view,\n\t\t\t\tchanges: this.changes,\n\t\t\t\tsteps: this.steps,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tstatus: this.status,\n\t\t\tchanges: this.changes,\n\t\t\tbefore: this.before,\n\t\t};\n\t}\n\n\t/**\n\t * Override to provide additional transaction validation when the transaction is closed.\n\t * Only invoked when a transaction is otherwise valid.\n\t */\n\tprotected abstract validateOnClose(): EditStatus;\n\n\t/**\n\t * A helper to apply a sequence of changes. Changes will be applied one after the other. If a change fails to apply,\n\t * the remaining changes in `changes` will be ignored.\n\t * @param changes - the sequence of changes to apply.\n\t * @param path - the reconciliation path for the first change.\n\t * @returns this\n\t */\n\tpublic applyChanges(changes: Iterable<TChange>, path: ReconciliationPath<TChange> = []): this {\n\t\tconst iter = changes[Symbol.iterator]();\n\t\tconst firstChange = iter.next().value;\n\t\tlet iterResult = iter.next();\n\t\tif (iterResult.done === true) {\n\t\t\tfor (const change of changes) {\n\t\t\t\tif (this.applyChange(change, path).status !== EditStatus.Applied) {\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tif (this.applyChange(firstChange, path).status !== EditStatus.Applied) {\n\t\t\treturn this;\n\t\t}\n\n\t\tconst ongoingEdit = {\n\t\t\t0: this.steps[this.steps.length - 1],\n\t\t\tbefore: this.view,\n\t\t\tafter: this.view,\n\t\t\tlength: 1,\n\t\t};\n\n\t\t/**\n\t\t * We use a Proxy instead of `{ ...path, ...objectWithOngoingEdit }` to avoid eagerly demanding all parts of the path, which may\n\t\t * require extensive computation.\n\t\t */\n\t\tconst pathWithOngoingEdit = new Proxy(path, {\n\t\t\tget: (\n\t\t\t\ttarget: ReconciliationPath<TChange>,\n\t\t\t\tprop: string\n\t\t\t): ReconciliationPath<TChange>[number | 'length'] => {\n\t\t\t\tif (prop === 'length') {\n\t\t\t\t\treturn target.length + 1;\n\t\t\t\t}\n\n\t\t\t\treturn prop === String(target.length) ? ongoingEdit : target[prop];\n\t\t\t},\n\t\t});\n\n\t\twhile (iterResult.done !== true) {\n\t\t\tif (this.applyChange(iterResult.value, pathWithOngoingEdit).status !== EditStatus.Applied) {\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tongoingEdit[ongoingEdit.length] = this.steps[this.steps.length - 1];\n\t\t\tongoingEdit.length += 1;\n\t\t\tongoingEdit.after = this.view;\n\t\t\titerResult = iter.next();\n\t\t}\n\t\treturn this;\n\t}\n\n\tprotected tryResolveChange(change: TChange, path: ReconciliationPath<TChange>): TChange | undefined {\n\t\treturn change;\n\t}\n\n\t/**\n\t * Attempt to apply the given change as part of this edit. This method should not be called if a previous change in this edit failed to\n\t * apply.\n\t * @param change - the change to apply\n\t * @param path - the reconciliation path for the change.\n\t * @returns this\n\t */\n\tpublic applyChange(change: TChange, path: ReconciliationPath<TChange> = []): this {\n\t\tassert(this.isOpen, 'Editor must be open to apply changes.');\n\t\tif (this.status !== EditStatus.Applied) {\n\t\t\tfail('Cannot apply change to an edit unless all previous changes have applied');\n\t\t}\n\t\tconst resolvedChange = this.tryResolveChange(change, path);\n\t\tif (resolvedChange === undefined) {\n\t\t\tthis._status = EditStatus.Invalid;\n\t\t\treturn this;\n\t\t}\n\t\tthis.changes.push(change);\n\t\tthis._status = this.dispatchChange(resolvedChange);\n\t\tthis.steps.push({ resolvedChange, after: this.view });\n\t\treturn this;\n\t}\n\n\tprotected abstract dispatchChange(change: TChange): EditStatus;\n}\n"]}
|
|
@@ -108,12 +108,10 @@ describe('SnapshotUtilities', () => {
|
|
|
108
108
|
it('compares mixed types', () => {
|
|
109
109
|
check({ 0: 1 }, [1], allUnequal);
|
|
110
110
|
// Rationale: 'undefined' is reserved for future use (see 'SetValue' interface)
|
|
111
|
-
/* eslint-disable no-null/no-null */
|
|
112
111
|
check(null, 'null', allUnequal);
|
|
113
112
|
check(null, 'null', allUnequal);
|
|
114
113
|
check(1, '1', allUnequal);
|
|
115
114
|
check(null, 0, allUnequal);
|
|
116
|
-
/* eslint-enable no-null/no-null */
|
|
117
115
|
check('', 0, allUnequal);
|
|
118
116
|
});
|
|
119
117
|
const sameAfter = {
|
|
@@ -163,7 +161,6 @@ describe('SnapshotUtilities', () => {
|
|
|
163
161
|
it.skip('strange cases', () => {
|
|
164
162
|
// Top level undefined fails in JSON.parse.
|
|
165
163
|
// Rationale: 'undefined' is reserved for future use (see 'SetValue' interface.)
|
|
166
|
-
// eslint-disable-next-line no-null/no-null
|
|
167
164
|
check(undefined, null, sameAfter);
|
|
168
165
|
});
|
|
169
166
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnapshotUtilities.tests.js","sourceRoot":"","sources":["../../src/test/SnapshotUtilities.tests.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAG5C,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAClC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;QAChC,MAAM,UAAU,GAAG,IAAI,eAAe,CAAC,IAAI,yBAAyB,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACtG,MAAM,MAAM,GAAiB,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,EAA6B,CAAC;QAEhF,IAAK,QAIJ;QAJD,WAAK,QAAQ;YACZ,yCAAK,CAAA;YACL,6CAAO,CAAA;YACP,qDAAW,CAAA;QACZ,CAAC,EAJI,QAAQ,KAAR,QAAQ,QAIZ;QAED,SAAS,aAAa,CAAC,KAAc,EAAE,QAAkB;YACxD,IAAI,QAAQ,KAAK,QAAQ,CAAC,WAAW,EAAE;gBACtC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,KAAK,CAAC,CAAC;aAClD;QACF,CAAC;QAED,SAAS,KAAK,CACb,CAAU,E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e,EAAE,GAAG,EAAE;YAC7B,2CAA2C;YAC3C,gFAAgF;YAChF,2CAA2C;YAC3C,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle } from '@fluidframework/core-interfaces';\nimport { FluidSerializer } from '@fluidframework/shared-object-base';\nimport { MockFluidDataStoreRuntime } from '@fluidframework/test-runtime-utils';\nimport { expect } from 'chai';\nimport { comparePayloads } from '../Common';\nimport { Payload } from '../generic';\n\ndescribe('SnapshotUtilities', () => {\n\tdescribe('comparePayloads', () => {\n\t\tconst serializer = new FluidSerializer(new MockFluidDataStoreRuntime().IFluidHandleContext, () => {});\n\t\tconst binder: IFluidHandle = { bind: () => void {} } as unknown as IFluidHandle;\n\n\t\tenum Equality {\n\t\t\tEqual,\n\t\t\tUnequal,\n\t\t\tUnspecified,\n\t\t}\n\n\t\tfunction checkEquality(equal: boolean, equality: Equality): void {\n\t\t\tif (equality !== Equality.Unspecified) {\n\t\t\t\texpect(equal).equals(equality === Equality.Equal);\n\t\t\t}\n\t\t}\n\n\t\tfunction check(\n\t\t\ta: Payload,\n\t\t\tb: Payload,\n\t\t\tflags: { initial: Equality; serialized: Equality; deserialized: Equality; roundtrip: Equality }\n\t\t): void {\n\t\t\t// Check reflexive\n\t\t\texpect(comparePayloads(a, a)).equal(true);\n\t\t\texpect(comparePayloads(b, b)).equal(true);\n\n\t\t\tcheckEquality(comparePayloads(a, b), flags.initial);\n\t\t\t// Check commutative\n\t\t\tcheckEquality(comparePayloads(b, a), flags.initial);\n\n\t\t\tconst [aString, aDeserialized] = checkSerialization(a, flags.roundtrip);\n\t\t\tconst [bString, bDeserialized] = checkSerialization(b, flags.roundtrip);\n\n\t\t\tcheckEquality(aString === bString, flags.serialized);\n\t\t\tcheckEquality(comparePayloads(aDeserialized, bDeserialized), flags.deserialized);\n\t\t\t// Check commutative\n\t\t\tcheckEquality(comparePayloads(bDeserialized, aDeserialized), flags.deserialized);\n\t\t}\n\n\t\tfunction checkSerialization(a: Payload, roundtrip: Equality): [string, Payload] {\n\t\t\tconst aString = serializer.stringify(a, binder);\n\t\t\tconst a2: Payload = serializer.parse(aString);\n\t\t\tconst aString2 = serializer.stringify(a2, binder);\n\t\t\texpect(aString2).equal(aString);\n\t\t\tcheckEquality(comparePayloads(a, a2), roundtrip);\n\n\t\t\t// Check second round trip, should always be equal\n\t\t\tconst a3: Payload = serializer.parse(aString2);\n\t\t\texpect(comparePayloads(a3, a2)).true;\n\n\t\t\treturn [aString, a2];\n\t\t}\n\n\t\tconst allEqual = {\n\t\t\tinitial: Equality.Equal,\n\t\t\tserialized: Equality.Equal,\n\t\t\tdeserialized: Equality.Equal,\n\t\t\troundtrip: Equality.Equal,\n\t\t};\n\n\t\t// For when the inputs are logically equal, but may serialize differently due to field ordering.\n\t\tconst allEqualUnstable = {\n\t\t\tinitial: Equality.Equal,\n\t\t\tserialized: Equality.Unspecified,\n\t\t\tdeserialized: Equality.Equal,\n\t\t\troundtrip: Equality.Equal,\n\t\t};\n\n\t\tconst allUnequal = {\n\t\t\tinitial: Equality.Unequal,\n\t\t\tserialized: Equality.Unequal,\n\t\t\tdeserialized: Equality.Unequal,\n\t\t\troundtrip: Equality.Equal,\n\t\t};\n\n\t\tit('compares numbers correctly', () => {\n\t\t\tcheck(0, 0, allEqual);\n\t\t\tcheck(1, 1, allEqual);\n\t\t\tcheck(0, 1, allUnequal);\n\t\t\tcheck(-1, 1, allUnequal);\n\t\t\tcheck(5.2, 5.200000001, allUnequal);\n\t\t});\n\n\t\tit('compares strings', () => {\n\t\t\tcheck('', '', allEqual);\n\t\t\tcheck(' ', '', allUnequal);\n\t\t\tcheck('1', '+1', allUnequal);\n\t\t\t// This character makes sure multi-byte utf-8 and multi-word utf-16 at least somewhat work\n\t\t\t// Cases like unicode normalization are not covered here here. Normalization or not will be considered ok.\n\t\t\tcheck('𤭢', '𤭢', allEqual);\n\t\t\tcheck('𤭢', '', allUnequal);\n\t\t\tcheck('several characters', 'several characters', allEqual);\n\t\t\tcheck('several characters', 'several_characters', allUnequal);\n\t\t});\n\n\t\tit('compares arrays', () => {\n\t\t\tcheck([], [], allEqual);\n\t\t\tcheck([1], [1], allEqual);\n\t\t\tcheck([[1]], [[1]], allEqual);\n\t\t\tcheck([[1]], [[2]], allUnequal);\n\t\t\tcheck([], [1], allUnequal);\n\t\t\tcheck([1, 2], [2, 1], allUnequal);\n\t\t});\n\n\t\tit('compares objects', () => {\n\t\t\tcheck({ 1: 'x' }, { 1: 'x' }, allEqual);\n\t\t\tcheck({ x: 'x' }, { y: 'x' }, allUnequal);\n\t\t\tcheck({ x: 'x' }, { x: {} }, allUnequal);\n\t\t\tcheck({ x: {} }, { x: {} }, allEqual);\n\t\t\tcheck({ x: [1, 2, 3, 5] }, { x: [1, 2, 3, 4] }, allUnequal);\n\t\t\tcheck({ 1: 'x' }, {}, allUnequal);\n\t\t\tcheck({ x: 'x' }, { x: 'x', y: 'x' }, allUnequal);\n\t\t\tcheck({ field: 'a' }, { field: 'b' }, allUnequal);\n\n\t\t\t// Fluid Serialization arbitrarily orders fields.\n\t\t\t// Thus any object with more than one field may have non-deterministic serialization.\n\t\t\t// However objects have field order, and we need to check comparePayloads is not impacted by it.\n\t\t\tcheck({ y: 'a', x: 'b' }, { x: 'b', y: 'a' }, allEqualUnstable);\n\t\t});\n\n\t\tit('compares mixed types', () => {\n\t\t\tcheck({ 0: 1 }, [1], allUnequal);\n\t\t\t// Rationale: 'undefined' is reserved for future use (see 'SetValue' interface)\n\t\t\t/* eslint-disable no-null/no-null */\n\t\t\tcheck(null, 'null', allUnequal);\n\t\t\tcheck(null, 'null', allUnequal);\n\t\t\tcheck(1, '1', allUnequal);\n\t\t\tcheck(null, 0, allUnequal);\n\t\t\t/* eslint-enable no-null/no-null */\n\t\t\tcheck('', 0, allUnequal);\n\t\t});\n\n\t\tconst sameAfter = {\n\t\t\tinitial: Equality.Unspecified,\n\t\t\tserialized: Equality.Unspecified,\n\t\t\tdeserialized: Equality.Equal,\n\t\t\troundtrip: Equality.Unspecified,\n\t\t};\n\t\tconst differentAfter = {\n\t\t\tinitial: Equality.Unequal,\n\t\t\tserialized: Equality.Unequal,\n\t\t\tdeserialized: Equality.Unequal,\n\t\t\troundtrip: Equality.Unspecified,\n\t\t};\n\n\t\tit('lossy cases', () => {\n\t\t\t// Undefined fields are omitted in json, and thus lost on the round trip.\n\t\t\tcheck({ x: undefined }, { y: undefined }, sameAfter);\n\t\t\tcheck({ x: undefined }, {}, sameAfter);\n\n\t\t\t// NaN and Infinity become null\n\t\t\tcheck(NaN, NaN, sameAfter);\n\t\t\tcheck(NaN, 7, differentAfter);\n\t\t\tcheck(Infinity, Infinity, sameAfter);\n\t\t\tcheck(-Infinity, Infinity, sameAfter);\n\t\t\tcheck(NaN, 'NaN', differentAfter);\n\n\t\t\t// json loses -0 on round trip\n\t\t\tcheck(-0, -0, sameAfter);\n\t\t});\n\n\t\tit('compares handles', () => {\n\t\t\tfunction makeMockHandle(data: string): IFluidHandle {\n\t\t\t\tconst handleObject = { absolutePath: data, IFluidHandle: undefined as unknown };\n\t\t\t\thandleObject.IFluidHandle = handleObject;\n\t\t\t\tconst handle = handleObject as IFluidHandle;\n\t\t\t\t// Handle gets modified by serializing. This is probably because handle is malformed.\n\t\t\t\t// To avoid this being an issue, round trip it.\n\t\t\t\tconst serialized = serializer.stringify(handle, binder);\n\t\t\t\tconst finalHandle: IFluidHandle = serializer.parse(serialized);\n\t\t\t\treturn finalHandle;\n\t\t\t}\n\t\t\t// Theoretically handles serialize as objects with 2 fields and thus serialization is allowed to be non-deterministic\n\t\t\t// so use allEqualUnstable not allEqual.\n\t\t\tcheck(makeMockHandle('x'), makeMockHandle('x'), allEqualUnstable);\n\t\t\tcheck(makeMockHandle('x'), makeMockHandle('y'), allUnequal);\n\t\t\tcheck({ x: makeMockHandle('x') }, makeMockHandle('x'), allUnequal);\n\t\t});\n\n\t\t// These are cases that are allowed by the type system and produce unexpected results due to Json serialization.\n\t\t// Clear documentation and/or adjustments to equality, type checking or serialization would help with these cases.\n\t\tit.skip('strange cases', () => {\n\t\t\t// Top level undefined fails in JSON.parse.\n\t\t\t// Rationale: 'undefined' is reserved for future use (see 'SetValue' interface.)\n\t\t\t// eslint-disable-next-line no-null/no-null\n\t\t\tcheck(undefined, null, sameAfter);\n\t\t});\n\t});\n});\n"]}
|
|
1
|
+
{"version":3,"file":"SnapshotUtilities.tests.js","sourceRoot":"","sources":["../../src/test/SnapshotUtilities.tests.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAG5C,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAClC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;QAChC,MAAM,UAAU,GAAG,IAAI,eAAe,CAAC,IAAI,yBAAyB,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACtG,MAAM,MAAM,GAAiB,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,EAA6B,CAAC;QAEhF,IAAK,QAIJ;QAJD,WAAK,QAAQ;YACZ,yCAAK,CAAA;YACL,6CAAO,CAAA;YACP,qDAAW,CAAA;QACZ,CAAC,EAJI,QAAQ,KAAR,QAAQ,QAIZ;QAED,SAAS,aAAa,CAAC,KAAc,EAAE,QAAkB;YACxD,IAAI,QAAQ,KAAK,QAAQ,CAAC,WAAW,EAAE;gBACtC,MAAM,CAAC,KA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C;QACpE,CAAC,CAAC,CAAC;QAEH,gHAAgH;QAChH,kHAAkH;QAClH,EAAE,CAAC,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE;YAC7B,2CAA2C;YAC3C,gFAAgF;YAChF,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle } from '@fluidframework/core-interfaces';\nimport { FluidSerializer } from '@fluidframework/shared-object-base';\nimport { MockFluidDataStoreRuntime } from '@fluidframework/test-runtime-utils';\nimport { expect } from 'chai';\nimport { comparePayloads } from '../Common';\nimport { Payload } from '../generic';\n\ndescribe('SnapshotUtilities', () => {\n\tdescribe('comparePayloads', () => {\n\t\tconst serializer = new FluidSerializer(new MockFluidDataStoreRuntime().IFluidHandleContext, () => {});\n\t\tconst binder: IFluidHandle = { bind: () => void {} } as unknown as IFluidHandle;\n\n\t\tenum Equality {\n\t\t\tEqual,\n\t\t\tUnequal,\n\t\t\tUnspecified,\n\t\t}\n\n\t\tfunction checkEquality(equal: boolean, equality: Equality): void {\n\t\t\tif (equality !== Equality.Unspecified) {\n\t\t\t\texpect(equal).equals(equality === Equality.Equal);\n\t\t\t}\n\t\t}\n\n\t\tfunction check(\n\t\t\ta: Payload,\n\t\t\tb: Payload,\n\t\t\tflags: { initial: Equality; serialized: Equality; deserialized: Equality; roundtrip: Equality }\n\t\t): void {\n\t\t\t// Check reflexive\n\t\t\texpect(comparePayloads(a, a)).equal(true);\n\t\t\texpect(comparePayloads(b, b)).equal(true);\n\n\t\t\tcheckEquality(comparePayloads(a, b), flags.initial);\n\t\t\t// Check commutative\n\t\t\tcheckEquality(comparePayloads(b, a), flags.initial);\n\n\t\t\tconst [aString, aDeserialized] = checkSerialization(a, flags.roundtrip);\n\t\t\tconst [bString, bDeserialized] = checkSerialization(b, flags.roundtrip);\n\n\t\t\tcheckEquality(aString === bString, flags.serialized);\n\t\t\tcheckEquality(comparePayloads(aDeserialized, bDeserialized), flags.deserialized);\n\t\t\t// Check commutative\n\t\t\tcheckEquality(comparePayloads(bDeserialized, aDeserialized), flags.deserialized);\n\t\t}\n\n\t\tfunction checkSerialization(a: Payload, roundtrip: Equality): [string, Payload] {\n\t\t\tconst aString = serializer.stringify(a, binder);\n\t\t\tconst a2: Payload = serializer.parse(aString);\n\t\t\tconst aString2 = serializer.stringify(a2, binder);\n\t\t\texpect(aString2).equal(aString);\n\t\t\tcheckEquality(comparePayloads(a, a2), roundtrip);\n\n\t\t\t// Check second round trip, should always be equal\n\t\t\tconst a3: Payload = serializer.parse(aString2);\n\t\t\texpect(comparePayloads(a3, a2)).true;\n\n\t\t\treturn [aString, a2];\n\t\t}\n\n\t\tconst allEqual = {\n\t\t\tinitial: Equality.Equal,\n\t\t\tserialized: Equality.Equal,\n\t\t\tdeserialized: Equality.Equal,\n\t\t\troundtrip: Equality.Equal,\n\t\t};\n\n\t\t// For when the inputs are logically equal, but may serialize differently due to field ordering.\n\t\tconst allEqualUnstable = {\n\t\t\tinitial: Equality.Equal,\n\t\t\tserialized: Equality.Unspecified,\n\t\t\tdeserialized: Equality.Equal,\n\t\t\troundtrip: Equality.Equal,\n\t\t};\n\n\t\tconst allUnequal = {\n\t\t\tinitial: Equality.Unequal,\n\t\t\tserialized: Equality.Unequal,\n\t\t\tdeserialized: Equality.Unequal,\n\t\t\troundtrip: Equality.Equal,\n\t\t};\n\n\t\tit('compares numbers correctly', () => {\n\t\t\tcheck(0, 0, allEqual);\n\t\t\tcheck(1, 1, allEqual);\n\t\t\tcheck(0, 1, allUnequal);\n\t\t\tcheck(-1, 1, allUnequal);\n\t\t\tcheck(5.2, 5.200000001, allUnequal);\n\t\t});\n\n\t\tit('compares strings', () => {\n\t\t\tcheck('', '', allEqual);\n\t\t\tcheck(' ', '', allUnequal);\n\t\t\tcheck('1', '+1', allUnequal);\n\t\t\t// This character makes sure multi-byte utf-8 and multi-word utf-16 at least somewhat work\n\t\t\t// Cases like unicode normalization are not covered here here. Normalization or not will be considered ok.\n\t\t\tcheck('𤭢', '𤭢', allEqual);\n\t\t\tcheck('𤭢', '', allUnequal);\n\t\t\tcheck('several characters', 'several characters', allEqual);\n\t\t\tcheck('several characters', 'several_characters', allUnequal);\n\t\t});\n\n\t\tit('compares arrays', () => {\n\t\t\tcheck([], [], allEqual);\n\t\t\tcheck([1], [1], allEqual);\n\t\t\tcheck([[1]], [[1]], allEqual);\n\t\t\tcheck([[1]], [[2]], allUnequal);\n\t\t\tcheck([], [1], allUnequal);\n\t\t\tcheck([1, 2], [2, 1], allUnequal);\n\t\t});\n\n\t\tit('compares objects', () => {\n\t\t\tcheck({ 1: 'x' }, { 1: 'x' }, allEqual);\n\t\t\tcheck({ x: 'x' }, { y: 'x' }, allUnequal);\n\t\t\tcheck({ x: 'x' }, { x: {} }, allUnequal);\n\t\t\tcheck({ x: {} }, { x: {} }, allEqual);\n\t\t\tcheck({ x: [1, 2, 3, 5] }, { x: [1, 2, 3, 4] }, allUnequal);\n\t\t\tcheck({ 1: 'x' }, {}, allUnequal);\n\t\t\tcheck({ x: 'x' }, { x: 'x', y: 'x' }, allUnequal);\n\t\t\tcheck({ field: 'a' }, { field: 'b' }, allUnequal);\n\n\t\t\t// Fluid Serialization arbitrarily orders fields.\n\t\t\t// Thus any object with more than one field may have non-deterministic serialization.\n\t\t\t// However objects have field order, and we need to check comparePayloads is not impacted by it.\n\t\t\tcheck({ y: 'a', x: 'b' }, { x: 'b', y: 'a' }, allEqualUnstable);\n\t\t});\n\n\t\tit('compares mixed types', () => {\n\t\t\tcheck({ 0: 1 }, [1], allUnequal);\n\t\t\t// Rationale: 'undefined' is reserved for future use (see 'SetValue' interface)\n\t\t\tcheck(null, 'null', allUnequal);\n\t\t\tcheck(null, 'null', allUnequal);\n\t\t\tcheck(1, '1', allUnequal);\n\t\t\tcheck(null, 0, allUnequal);\n\t\t\tcheck('', 0, allUnequal);\n\t\t});\n\n\t\tconst sameAfter = {\n\t\t\tinitial: Equality.Unspecified,\n\t\t\tserialized: Equality.Unspecified,\n\t\t\tdeserialized: Equality.Equal,\n\t\t\troundtrip: Equality.Unspecified,\n\t\t};\n\t\tconst differentAfter = {\n\t\t\tinitial: Equality.Unequal,\n\t\t\tserialized: Equality.Unequal,\n\t\t\tdeserialized: Equality.Unequal,\n\t\t\troundtrip: Equality.Unspecified,\n\t\t};\n\n\t\tit('lossy cases', () => {\n\t\t\t// Undefined fields are omitted in json, and thus lost on the round trip.\n\t\t\tcheck({ x: undefined }, { y: undefined }, sameAfter);\n\t\t\tcheck({ x: undefined }, {}, sameAfter);\n\n\t\t\t// NaN and Infinity become null\n\t\t\tcheck(NaN, NaN, sameAfter);\n\t\t\tcheck(NaN, 7, differentAfter);\n\t\t\tcheck(Infinity, Infinity, sameAfter);\n\t\t\tcheck(-Infinity, Infinity, sameAfter);\n\t\t\tcheck(NaN, 'NaN', differentAfter);\n\n\t\t\t// json loses -0 on round trip\n\t\t\tcheck(-0, -0, sameAfter);\n\t\t});\n\n\t\tit('compares handles', () => {\n\t\t\tfunction makeMockHandle(data: string): IFluidHandle {\n\t\t\t\tconst handleObject = { absolutePath: data, IFluidHandle: undefined as unknown };\n\t\t\t\thandleObject.IFluidHandle = handleObject;\n\t\t\t\tconst handle = handleObject as IFluidHandle;\n\t\t\t\t// Handle gets modified by serializing. This is probably because handle is malformed.\n\t\t\t\t// To avoid this being an issue, round trip it.\n\t\t\t\tconst serialized = serializer.stringify(handle, binder);\n\t\t\t\tconst finalHandle: IFluidHandle = serializer.parse(serialized);\n\t\t\t\treturn finalHandle;\n\t\t\t}\n\t\t\t// Theoretically handles serialize as objects with 2 fields and thus serialization is allowed to be non-deterministic\n\t\t\t// so use allEqualUnstable not allEqual.\n\t\t\tcheck(makeMockHandle('x'), makeMockHandle('x'), allEqualUnstable);\n\t\t\tcheck(makeMockHandle('x'), makeMockHandle('y'), allUnequal);\n\t\t\tcheck({ x: makeMockHandle('x') }, makeMockHandle('x'), allUnequal);\n\t\t});\n\n\t\t// These are cases that are allowed by the type system and produce unexpected results due to Json serialization.\n\t\t// Clear documentation and/or adjustments to equality, type checking or serialization would help with these cases.\n\t\tit.skip('strange cases', () => {\n\t\t\t// Top level undefined fails in JSON.parse.\n\t\t\t// Rationale: 'undefined' is reserved for future use (see 'SetValue' interface.)\n\t\t\tcheck(undefined, null, sameAfter);\n\t\t});\n\t});\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undoRedoStackManager.d.ts","sourceRoot":"","sources":["../../src/test/undoRedoStackManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"undoRedoStackManager.d.ts","sourceRoot":"","sources":["../../src/test/undoRedoStackManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAmE/D;;;;GAIG;AACH,qBAAa,oBAAoB;IAChC,OAAO,CAAC,MAAM,CAAC,MAAM;IA+BrB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuB;IACjD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuB;IACjD,OAAO,CAAC,IAAI,CAAmC;IAC/C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsB;;IAO5C,qBAAqB;IAMrB,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,IAAI;IAG9C,cAAc,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,IAAI;IAI1D,aAAa,IAAI,OAAO;IAUxB,aAAa,IAAI,OAAO;IAUxB,sBAAsB,CAAC,UAAU,EAAE,WAAW;IA4BrD,OAAO,CAAC,cAAc;CAatB"}
|
|
@@ -1 +1 @@
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AAE,CAAC;oBAC9C,IAAI,aAAa,KAAK,SAAS,EAAE;wBAChC,aAAa,CAAC,OAAO,EAAE,CAAC;qBACxB;iBACD;aACD;SACD;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// TODO: This is a temporary copy of the 'UndoRedoStackManager' from 'framework/undo-redo'\n// to unblock testing of SharedMatrix undo while we decide on the correct layering\n// for undo.\n\nimport { EventEmitter } from 'events';\nimport { IRevertible } from '../default-edits/UndoRedoHandler';\n\nenum UndoRedoMode {\n\tNone,\n\tRedo,\n\tUndo,\n}\n\n/**\n * Helper class for createing a stack over an array\n */\nclass Stack<T> {\n\tpublic itemPushedCallback: (() => void) | undefined;\n\tprivate readonly items: T[] = [];\n\tconstructor(...items: T[]) {\n\t\tif (items !== undefined) {\n\t\t\titems.forEach((item) => this.push(item));\n\t\t}\n\t}\n\n\tpublic empty(): boolean {\n\t\treturn this.items.length === 0;\n\t}\n\tpublic top(): T | undefined {\n\t\tif (!this.empty()) {\n\t\t\treturn this.items[0];\n\t\t}\n\t\treturn undefined;\n\t}\n\tpublic pop(): T | undefined {\n\t\treturn this.items.shift();\n\t}\n\n\tpublic push(item: T) {\n\t\tthis.items.unshift(item);\n\t\tif (this.itemPushedCallback !== undefined) {\n\t\t\tthis.itemPushedCallback();\n\t\t}\n\t}\n}\n\n/**\n * Helper class for creating the Undo and Redo stacks\n */\nclass UndoRedoStack extends Stack<Stack<IRevertible> | undefined> {\n\tpublic push(item: Stack<IRevertible> | undefined) {\n\t\tif (item !== undefined) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\t\t\titem.itemPushedCallback = () => this.callItemPushedCallback;\n\t\t}\n\t\tsuper.push(item);\n\t}\n\n\tpublic closeCurrentOperationIfInProgress() {\n\t\tif (this.top() !== undefined) {\n\t\t\tthis.push(undefined);\n\t\t} else {\n\t\t\tthis.callItemPushedCallback();\n\t\t}\n\t}\n\n\tprivate callItemPushedCallback() {\n\t\tif (this.itemPushedCallback !== undefined) {\n\t\t\tthis.itemPushedCallback();\n\t\t}\n\t}\n}\n\n/**\n * Manages the Undo and Redo stacks, and operations withing those stacks.\n * Allows adding items to the current operation on the stack, closing the current operation,\n * and issuing and undo or a redo.\n */\nexport class UndoRedoStackManager {\n\tprivate static revert(revertStack: UndoRedoStack, pushStack: UndoRedoStack) {\n\t\t// Close the pushStack, as it could get new ops\n\t\t// from the revert, and we don't want those combined\n\t\t// with any existing operation\n\t\tpushStack.closeCurrentOperationIfInProgress();\n\n\t\t// Search the revert stack for the first defined operation stack\n\t\twhile (!revertStack.empty() && revertStack.top() === undefined) {\n\t\t\trevertStack.pop();\n\t\t}\n\n\t\t// If there is a defined operation stack, revert it\n\t\tif (!revertStack.empty()) {\n\t\t\tconst operationStack = revertStack.pop();\n\t\t\tif (operationStack !== undefined) {\n\t\t\t\twhile (!operationStack.empty()) {\n\t\t\t\t\tconst operation = operationStack.pop();\n\t\t\t\t\tif (operation !== undefined) {\n\t\t\t\t\t\toperation.revert();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Make sure both stacks have any open operations\n\t\t// closed, since we won't want anything added to those\n\t\t//\n\t\trevertStack.closeCurrentOperationIfInProgress();\n\t\tpushStack.closeCurrentOperationIfInProgress();\n\t}\n\n\tprivate readonly undoStack = new UndoRedoStack();\n\tprivate readonly redoStack = new UndoRedoStack();\n\tprivate mode: UndoRedoMode = UndoRedoMode.None;\n\tprivate readonly eventEmitter = new EventEmitter();\n\n\tconstructor() {\n\t\tthis.undoStack.itemPushedCallback = () => this.eventEmitter.emit('changePushed');\n\t\tthis.redoStack.itemPushedCallback = () => this.eventEmitter.emit('changePushed');\n\t}\n\n\tpublic closeCurrentOperation() {\n\t\tif (this.mode === UndoRedoMode.None) {\n\t\t\tthis.undoStack.closeCurrentOperationIfInProgress();\n\t\t}\n\t}\n\n\tpublic on(event: 'changePushed', listener: () => void) {\n\t\tthis.eventEmitter.on(event, listener);\n\t}\n\tpublic removeListener(event: 'changePushed', listener: () => void) {\n\t\tthis.eventEmitter.removeListener(event, listener);\n\t}\n\n\tpublic undoOperation(): boolean {\n\t\tif (this.undoStack.empty()) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.mode = UndoRedoMode.Undo;\n\t\tUndoRedoStackManager.revert(this.undoStack, this.redoStack);\n\t\tthis.mode = UndoRedoMode.None;\n\t\treturn true;\n\t}\n\n\tpublic redoOperation(): boolean {\n\t\tif (this.redoStack.empty()) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.mode = UndoRedoMode.Redo;\n\t\tUndoRedoStackManager.revert(this.redoStack, this.undoStack);\n\t\tthis.mode = UndoRedoMode.None;\n\t\treturn true;\n\t}\n\n\tpublic pushToCurrentOperation(revertible: IRevertible) {\n\t\tlet currentStack: UndoRedoStack;\n\n\t\tswitch (this.mode) {\n\t\t\tcase UndoRedoMode.None:\n\t\t\t\tcurrentStack = this.undoStack;\n\t\t\t\tthis.clearRedoStack();\n\t\t\t\tbreak;\n\n\t\t\tcase UndoRedoMode.Redo:\n\t\t\t\tcurrentStack = this.undoStack;\n\t\t\t\tbreak;\n\n\t\t\tcase UndoRedoMode.Undo:\n\t\t\t\tcurrentStack = this.redoStack;\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tthrow new Error('unknown mode');\n\t\t}\n\t\tconst operationStack = currentStack.top();\n\t\tif (operationStack === undefined) {\n\t\t\tcurrentStack.push(new Stack<IRevertible>(revertible));\n\t\t} else {\n\t\t\toperationStack.push(revertible);\n\t\t}\n\t}\n\n\tprivate clearRedoStack() {\n\t\twhile (!this.redoStack.empty()) {\n\t\t\tconst redoOpertionStack = this.redoStack.pop();\n\t\t\tif (redoOpertionStack !== undefined) {\n\t\t\t\twhile (!redoOpertionStack.empty()) {\n\t\t\t\t\tconst redoOperation = redoOpertionStack.pop();\n\t\t\t\t\tif (redoOperation !== undefined) {\n\t\t\t\t\t\tredoOperation.discard();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"undoRedoStackManager.js","sourceRoot":"","sources":["../../src/test/undoRedoStackManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0FAA0F;AAC1F,wFAAwF;AACxF,kBAAkB;AAElB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,IAAK,YAIJ;AAJD,WAAK,YAAY;IAChB,+CAAI,CAAA;IACJ,+CAAI,CAAA;IACJ,+CAAI,CAAA;AACL,CAAC,EAJI,YAAY,KAAZ,YAAY,QAIhB;AAED;;GAEG;AACH,MAAM,KAAK;IAGV,YAAY,GAAG,KAAU;QADR,UAAK,GAAQ,EAAE,CAAC;QAEhC,IAAI,KAAK,KAAK,SAAS,EAAE;YACxB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;SACzC;IACF,CAAC;IAEM,KAAK;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;IAChC,CAAC;IACM,GAAG;QACT,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE;YAClB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACrB;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;IACM,GAAG;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IAEM,IAAI,CAAC,IAAO;QAClB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,IAAI,CAAC,kBAAkB,KAAK,SAAS,EAAE;YAC1C,IAAI,CAAC,kBAAkB,EAAE,CAAC;SAC1B;IACF,CAAC;CACD;AAED;;GAEG;AACH,MAAM,aAAc,SAAQ,KAAqC;IACzD,IAAI,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AAK,EAAE,EAAE;oBAClC,MAAM,aAAa,GAAG,iBAAiB,CAAC,GAAG,EAAE,CAAC;oBAC9C,IAAI,aAAa,KAAK,SAAS,EAAE;wBAChC,aAAa,CAAC,OAAO,EAAE,CAAC;qBACxB;iBACD;aACD;SACD;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// TODO: This is a temporary copy of the 'UndoRedoStackManager' from 'framework/undo-redo'\n// to unblock testing of SharedMatrix undo while we decide on the correct layering\n// for undo.\n\nimport { EventEmitter } from 'events';\nimport { IRevertible } from '../default-edits/UndoRedoHandler';\n\nenum UndoRedoMode {\n\tNone,\n\tRedo,\n\tUndo,\n}\n\n/**\n * Helper class for createing a stack over an array\n */\nclass Stack<T> {\n\tpublic itemPushedCallback: (() => void) | undefined;\n\tprivate readonly items: T[] = [];\n\tconstructor(...items: T[]) {\n\t\tif (items !== undefined) {\n\t\t\titems.forEach((item) => this.push(item));\n\t\t}\n\t}\n\n\tpublic empty(): boolean {\n\t\treturn this.items.length === 0;\n\t}\n\tpublic top(): T | undefined {\n\t\tif (!this.empty()) {\n\t\t\treturn this.items[0];\n\t\t}\n\t\treturn undefined;\n\t}\n\tpublic pop(): T | undefined {\n\t\treturn this.items.shift();\n\t}\n\n\tpublic push(item: T) {\n\t\tthis.items.unshift(item);\n\t\tif (this.itemPushedCallback !== undefined) {\n\t\t\tthis.itemPushedCallback();\n\t\t}\n\t}\n}\n\n/**\n * Helper class for creating the Undo and Redo stacks\n */\nclass UndoRedoStack extends Stack<Stack<IRevertible> | undefined> {\n\tpublic push(item: Stack<IRevertible> | undefined) {\n\t\tif (item !== undefined) {\n\t\t\titem.itemPushedCallback = () => this.callItemPushedCallback;\n\t\t}\n\t\tsuper.push(item);\n\t}\n\n\tpublic closeCurrentOperationIfInProgress() {\n\t\tif (this.top() !== undefined) {\n\t\t\tthis.push(undefined);\n\t\t} else {\n\t\t\tthis.callItemPushedCallback();\n\t\t}\n\t}\n\n\tprivate callItemPushedCallback() {\n\t\tif (this.itemPushedCallback !== undefined) {\n\t\t\tthis.itemPushedCallback();\n\t\t}\n\t}\n}\n\n/**\n * Manages the Undo and Redo stacks, and operations withing those stacks.\n * Allows adding items to the current operation on the stack, closing the current operation,\n * and issuing and undo or a redo.\n */\nexport class UndoRedoStackManager {\n\tprivate static revert(revertStack: UndoRedoStack, pushStack: UndoRedoStack) {\n\t\t// Close the pushStack, as it could get new ops\n\t\t// from the revert, and we don't want those combined\n\t\t// with any existing operation\n\t\tpushStack.closeCurrentOperationIfInProgress();\n\n\t\t// Search the revert stack for the first defined operation stack\n\t\twhile (!revertStack.empty() && revertStack.top() === undefined) {\n\t\t\trevertStack.pop();\n\t\t}\n\n\t\t// If there is a defined operation stack, revert it\n\t\tif (!revertStack.empty()) {\n\t\t\tconst operationStack = revertStack.pop();\n\t\t\tif (operationStack !== undefined) {\n\t\t\t\twhile (!operationStack.empty()) {\n\t\t\t\t\tconst operation = operationStack.pop();\n\t\t\t\t\tif (operation !== undefined) {\n\t\t\t\t\t\toperation.revert();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Make sure both stacks have any open operations\n\t\t// closed, since we won't want anything added to those\n\t\t//\n\t\trevertStack.closeCurrentOperationIfInProgress();\n\t\tpushStack.closeCurrentOperationIfInProgress();\n\t}\n\n\tprivate readonly undoStack = new UndoRedoStack();\n\tprivate readonly redoStack = new UndoRedoStack();\n\tprivate mode: UndoRedoMode = UndoRedoMode.None;\n\tprivate readonly eventEmitter = new EventEmitter();\n\n\tconstructor() {\n\t\tthis.undoStack.itemPushedCallback = () => this.eventEmitter.emit('changePushed');\n\t\tthis.redoStack.itemPushedCallback = () => this.eventEmitter.emit('changePushed');\n\t}\n\n\tpublic closeCurrentOperation() {\n\t\tif (this.mode === UndoRedoMode.None) {\n\t\t\tthis.undoStack.closeCurrentOperationIfInProgress();\n\t\t}\n\t}\n\n\tpublic on(event: 'changePushed', listener: () => void) {\n\t\tthis.eventEmitter.on(event, listener);\n\t}\n\tpublic removeListener(event: 'changePushed', listener: () => void) {\n\t\tthis.eventEmitter.removeListener(event, listener);\n\t}\n\n\tpublic undoOperation(): boolean {\n\t\tif (this.undoStack.empty()) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.mode = UndoRedoMode.Undo;\n\t\tUndoRedoStackManager.revert(this.undoStack, this.redoStack);\n\t\tthis.mode = UndoRedoMode.None;\n\t\treturn true;\n\t}\n\n\tpublic redoOperation(): boolean {\n\t\tif (this.redoStack.empty()) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.mode = UndoRedoMode.Redo;\n\t\tUndoRedoStackManager.revert(this.redoStack, this.undoStack);\n\t\tthis.mode = UndoRedoMode.None;\n\t\treturn true;\n\t}\n\n\tpublic pushToCurrentOperation(revertible: IRevertible) {\n\t\tlet currentStack: UndoRedoStack;\n\n\t\tswitch (this.mode) {\n\t\t\tcase UndoRedoMode.None:\n\t\t\t\tcurrentStack = this.undoStack;\n\t\t\t\tthis.clearRedoStack();\n\t\t\t\tbreak;\n\n\t\t\tcase UndoRedoMode.Redo:\n\t\t\t\tcurrentStack = this.undoStack;\n\t\t\t\tbreak;\n\n\t\t\tcase UndoRedoMode.Undo:\n\t\t\t\tcurrentStack = this.redoStack;\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tthrow new Error('unknown mode');\n\t\t}\n\t\tconst operationStack = currentStack.top();\n\t\tif (operationStack === undefined) {\n\t\t\tcurrentStack.push(new Stack<IRevertible>(revertible));\n\t\t} else {\n\t\t\toperationStack.push(revertible);\n\t\t}\n\t}\n\n\tprivate clearRedoStack() {\n\t\twhile (!this.redoStack.empty()) {\n\t\t\tconst redoOpertionStack = this.redoStack.pop();\n\t\t\tif (redoOpertionStack !== undefined) {\n\t\t\t\twhile (!redoOpertionStack.empty()) {\n\t\t\t\t\tconst redoOperation = redoOpertionStack.pop();\n\t\t\t\t\tif (redoOperation !== undefined) {\n\t\t\t\t\t\tredoOperation.discard();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-experimental/tree",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.57.1",
|
|
4
4
|
"description": "Distributed tree",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": "https://github.com/microsoft/FluidFramework",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@fluidframework/common-definitions": "^0.20.1",
|
|
34
34
|
"@fluidframework/common-utils": "^0.32.1",
|
|
35
|
-
"@fluidframework/container-definitions": "^0.
|
|
35
|
+
"@fluidframework/container-definitions": "^0.46.0",
|
|
36
36
|
"@fluidframework/core-interfaces": "^0.42.0",
|
|
37
|
-
"@fluidframework/datastore-definitions": "^0.
|
|
37
|
+
"@fluidframework/datastore-definitions": "^0.57.1",
|
|
38
38
|
"@fluidframework/protocol-definitions": "^0.1026.0",
|
|
39
|
-
"@fluidframework/runtime-definitions": "^0.
|
|
40
|
-
"@fluidframework/shared-object-base": "^0.
|
|
41
|
-
"@fluidframework/telemetry-utils": "^0.
|
|
39
|
+
"@fluidframework/runtime-definitions": "^0.57.1",
|
|
40
|
+
"@fluidframework/shared-object-base": "^0.57.1",
|
|
41
|
+
"@fluidframework/telemetry-utils": "^0.57.1",
|
|
42
42
|
"buffer": "^6.0.3",
|
|
43
43
|
"denque": "^1.5.0",
|
|
44
44
|
"lru-cache": "^6.0.0",
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@fluidframework/build-common": "^0.23.0",
|
|
50
|
-
"@fluidframework/container-loader": "^0.
|
|
51
|
-
"@fluidframework/eslint-config-fluid": "^0.
|
|
52
|
-
"@fluidframework/mocha-test-setup": "^0.
|
|
53
|
-
"@fluidframework/runtime-utils": "^0.
|
|
54
|
-
"@fluidframework/test-drivers": "^0.
|
|
55
|
-
"@fluidframework/test-runtime-utils": "^0.
|
|
56
|
-
"@fluidframework/test-utils": "^0.
|
|
50
|
+
"@fluidframework/container-loader": "^0.57.1",
|
|
51
|
+
"@fluidframework/eslint-config-fluid": "^0.26.0",
|
|
52
|
+
"@fluidframework/mocha-test-setup": "^0.57.1",
|
|
53
|
+
"@fluidframework/runtime-utils": "^0.57.1",
|
|
54
|
+
"@fluidframework/test-drivers": "^0.57.1",
|
|
55
|
+
"@fluidframework/test-runtime-utils": "^0.57.1",
|
|
56
|
+
"@fluidframework/test-utils": "^0.57.1",
|
|
57
57
|
"@microsoft/api-extractor": "^7.16.1",
|
|
58
58
|
"@rushstack/eslint-config": "^2.5.1",
|
|
59
59
|
"@types/lru-cache": "^5.1.0",
|
package/src/Common.ts
CHANGED
|
@@ -100,7 +100,6 @@ export function comparePayloads(a: Payload, b: Payload): boolean {
|
|
|
100
100
|
// null is of type object, and needs to be treated as distinct from the empty object.
|
|
101
101
|
// Handling it early also avoids type errors trying to access its keys.
|
|
102
102
|
// Rationale: 'undefined' payloads are reserved for future use (see 'SetValue' interface).
|
|
103
|
-
// eslint-disable-next-line no-null/no-null
|
|
104
103
|
if (a === null || b === null) {
|
|
105
104
|
return false;
|
|
106
105
|
}
|
|
@@ -173,7 +172,6 @@ export function comparePayloads(a: Payload, b: Payload): boolean {
|
|
|
173
172
|
* @param containsPII - boolean flag for whether the message passed in contains personally identifying information (PII).
|
|
174
173
|
*/
|
|
175
174
|
export function assert(condition: unknown, message?: string, containsPII = false): asserts condition {
|
|
176
|
-
// Rationale: Assert condition is permitted to be truthy.
|
|
177
175
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
178
176
|
if (!condition) {
|
|
179
177
|
fail(message, containsPII);
|
|
@@ -188,6 +186,7 @@ export function assert(condition: unknown, message?: string, containsPII = false
|
|
|
188
186
|
*/
|
|
189
187
|
export function fail(message: string = defaultFailMessage, containsPII = false): never {
|
|
190
188
|
if (process.env.NODE_ENV !== 'production') {
|
|
189
|
+
// eslint-disable-next-line no-debugger
|
|
191
190
|
debugger;
|
|
192
191
|
console.error(message);
|
|
193
192
|
}
|
package/src/Forest.ts
CHANGED
|
@@ -285,7 +285,6 @@ export class Forest {
|
|
|
285
285
|
assert(node, 'can not replace payload for node that does not exist');
|
|
286
286
|
const mutableNodes = this.nodes.clone();
|
|
287
287
|
const newNode = { ...node };
|
|
288
|
-
/* eslint-disable-next-line no-null/no-null */
|
|
289
288
|
if (value !== null) {
|
|
290
289
|
newNode.payload = value;
|
|
291
290
|
} else {
|
|
@@ -47,8 +47,6 @@ export class RevisionValueCache<TValue> {
|
|
|
47
47
|
* The first revision within the retention window. All entries with revisions >= retentionWindowStart will be retained.
|
|
48
48
|
* Must be >= 0.
|
|
49
49
|
*/
|
|
50
|
-
// False positive
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly
|
|
52
50
|
private retentionWindowStart: Revision,
|
|
53
51
|
/**
|
|
54
52
|
* Optional list of entries to permanently retain.
|
package/src/Snapshot.ts
CHANGED
|
@@ -103,6 +103,7 @@ export class Snapshot {
|
|
|
103
103
|
function insertNodeRecursive(node: ChangeNode, newSnapshotNodes: Map<NodeId, SnapshotNode>): NodeId {
|
|
104
104
|
const { identifier, definition } = node;
|
|
105
105
|
const traits: Map<TraitLabel, readonly NodeId[]> = new Map();
|
|
106
|
+
|
|
106
107
|
// eslint-disable-next-line no-restricted-syntax
|
|
107
108
|
for (const key in node.traits) {
|
|
108
109
|
if (Object.prototype.hasOwnProperty.call(node.traits, key)) {
|
package/src/TreeNodeHandle.ts
CHANGED
|
@@ -87,6 +87,7 @@ export function revert(changes: readonly Change[], before: Snapshot): Change[] {
|
|
|
87
87
|
case ChangeType.Constraint:
|
|
88
88
|
// TODO:#46759: Support Constraint in reverts
|
|
89
89
|
fail('Revert currently does not support Constraints');
|
|
90
|
+
break;
|
|
90
91
|
default:
|
|
91
92
|
fail('Revert does not support the change type.');
|
|
92
93
|
}
|
|
@@ -207,7 +208,6 @@ function createInvertedSetValue(setValue: SetValue, revisionBeforeEdit: Snapshot
|
|
|
207
208
|
const oldPayload = revisionBeforeEdit.getSnapshotNode(nodeToModify).payload;
|
|
208
209
|
|
|
209
210
|
// Rationale: 'undefined' is reserved for future use (see 'SetValue' interface)
|
|
210
|
-
// eslint-disable-next-line no-null/no-null
|
|
211
211
|
if (oldPayload !== null) {
|
|
212
212
|
return [Change.setPayload(nodeToModify, oldPayload)];
|
|
213
213
|
}
|
|
@@ -246,7 +246,6 @@ export const Change = {
|
|
|
246
246
|
clearPayload: (nodeToModify: NodeId): SetValue => ({
|
|
247
247
|
nodeToModify,
|
|
248
248
|
// Rationale: 'undefined' is reserved for future use (see 'SetValue' interface above.)
|
|
249
|
-
// eslint-disable-next-line no-null/no-null
|
|
250
249
|
payload: null,
|
|
251
250
|
type: ChangeType.SetValue,
|
|
252
251
|
}),
|
|
@@ -209,6 +209,7 @@ export class Transaction extends GenericTransaction<Change> {
|
|
|
209
209
|
const node = unprocessed.pop();
|
|
210
210
|
assert(node !== undefined && !isDetachedSequenceId(node));
|
|
211
211
|
const traits = new Map<TraitLabel, readonly NodeId[]>();
|
|
212
|
+
|
|
212
213
|
// eslint-disable-next-line no-restricted-syntax
|
|
213
214
|
for (const key in node.traits) {
|
|
214
215
|
if (Object.prototype.hasOwnProperty.call(node.traits, key)) {
|
|
@@ -25,9 +25,7 @@ export interface IUndoConsumer {
|
|
|
25
25
|
* undo redo stack manager
|
|
26
26
|
*/
|
|
27
27
|
export class SharedTreeUndoRedoHandler {
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly
|
|
30
|
-
constructor(private stackManager: IUndoConsumer) {}
|
|
28
|
+
constructor(private readonly stackManager: IUndoConsumer) {}
|
|
31
29
|
|
|
32
30
|
public attachTree(tree: SharedTree) {
|
|
33
31
|
tree.on(SharedTreeEvent.EditCommitted, this.treeDeltaHandler);
|
|
@@ -57,8 +55,6 @@ export class SharedTreeUndoRedoHandler {
|
|
|
57
55
|
* Tracks a change on a shared tree and allows reverting it
|
|
58
56
|
*/
|
|
59
57
|
export class SharedTreeRevertible implements IRevertible {
|
|
60
|
-
// False positive
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly
|
|
62
58
|
constructor(private editId: EditId, private readonly tree: SharedTree) {}
|
|
63
59
|
|
|
64
60
|
public revert() {
|
|
@@ -512,13 +512,6 @@ export abstract class GenericSharedTree<TChange> extends SharedObject<ISharedTre
|
|
|
512
512
|
}
|
|
513
513
|
}
|
|
514
514
|
|
|
515
|
-
/**
|
|
516
|
-
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.registerCore}
|
|
517
|
-
*/
|
|
518
|
-
protected registerCore(): void {
|
|
519
|
-
// Do nothing
|
|
520
|
-
}
|
|
521
|
-
|
|
522
515
|
/**
|
|
523
516
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}
|
|
524
517
|
*/
|
|
@@ -145,7 +145,7 @@ export abstract class GenericTransaction<TChange> {
|
|
|
145
145
|
if (prop === 'length') {
|
|
146
146
|
return target.length + 1;
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
|
|
149
149
|
return prop === String(target.length) ? ongoingEdit : target[prop];
|
|
150
150
|
},
|
|
151
151
|
});
|