@fluid-experimental/tree 0.59.2001 → 0.59.3000
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 +2 -0
- package/.vscode/SharedTree.code-workspace +15 -0
- package/.vscode/settings.json +6 -0
- package/dist/ChangeCompression.js +9 -9
- package/dist/ChangeCompression.js.map +1 -1
- package/dist/ChangeTypes.d.ts +1 -6
- package/dist/ChangeTypes.d.ts.map +1 -1
- package/dist/ChangeTypes.js +5 -5
- package/dist/ChangeTypes.js.map +1 -1
- package/dist/Checkout.js +14 -14
- package/dist/Checkout.js.map +1 -1
- package/dist/Common.d.ts +21 -3
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js +29 -4
- package/dist/Common.js.map +1 -1
- package/dist/EditLog.js +26 -25
- package/dist/EditLog.js.map +1 -1
- package/dist/EditUtilities.js +17 -17
- package/dist/EditUtilities.js.map +1 -1
- package/dist/Forest.js +31 -31
- package/dist/Forest.js.map +1 -1
- package/dist/HistoryEditFactory.js +9 -9
- package/dist/HistoryEditFactory.js.map +1 -1
- package/dist/IdConversion.js +9 -9
- package/dist/IdConversion.js.map +1 -1
- package/dist/Identifiers.d.ts +4 -0
- package/dist/Identifiers.d.ts.map +1 -1
- package/dist/Identifiers.js.map +1 -1
- package/dist/LogViewer.d.ts +1 -5
- package/dist/LogViewer.d.ts.map +1 -1
- package/dist/LogViewer.js +11 -19
- package/dist/LogViewer.js.map +1 -1
- package/dist/MergeHealth.js +2 -2
- package/dist/MergeHealth.js.map +1 -1
- package/dist/NodeIdUtilities.js +2 -2
- package/dist/NodeIdUtilities.js.map +1 -1
- package/dist/PayloadUtilities.js +1 -1
- package/dist/PayloadUtilities.js.map +1 -1
- package/dist/RevisionValueCache.d.ts +13 -10
- package/dist/RevisionValueCache.d.ts.map +1 -1
- package/dist/RevisionValueCache.js +14 -11
- package/dist/RevisionValueCache.js.map +1 -1
- package/dist/RevisionView.js +4 -4
- package/dist/RevisionView.js.map +1 -1
- package/dist/SerializationUtilities.js +4 -4
- package/dist/SerializationUtilities.js.map +1 -1
- package/dist/SharedTree.d.ts +93 -31
- package/dist/SharedTree.d.ts.map +1 -1
- package/dist/SharedTree.js +160 -131
- package/dist/SharedTree.js.map +1 -1
- package/dist/SharedTreeEncoder.d.ts +3 -3
- package/dist/SharedTreeEncoder.d.ts.map +1 -1
- package/dist/SharedTreeEncoder.js +36 -36
- package/dist/SharedTreeEncoder.js.map +1 -1
- package/dist/StringInterner.js +1 -1
- package/dist/StringInterner.js.map +1 -1
- package/dist/Summary.js +1 -1
- package/dist/Summary.js.map +1 -1
- package/dist/SummaryBackCompatibility.js +8 -8
- package/dist/SummaryBackCompatibility.js.map +1 -1
- package/dist/Transaction.js +1 -1
- package/dist/Transaction.js.map +1 -1
- package/dist/TransactionInternal.js +17 -17
- package/dist/TransactionInternal.js.map +1 -1
- package/dist/TreeCompressor.d.ts.map +1 -1
- package/dist/TreeCompressor.js +6 -8
- package/dist/TreeCompressor.js.map +1 -1
- package/dist/TreeNodeHandle.js +4 -4
- package/dist/TreeNodeHandle.js.map +1 -1
- package/dist/TreeView.js +7 -7
- package/dist/TreeView.js.map +1 -1
- package/dist/TreeViewUtilities.js +2 -2
- package/dist/TreeViewUtilities.js.map +1 -1
- package/dist/UndoRedoHandler.js +1 -1
- package/dist/UndoRedoHandler.js.map +1 -1
- package/dist/UuidUtilities.d.ts +30 -0
- package/dist/UuidUtilities.d.ts.map +1 -0
- package/dist/UuidUtilities.js +106 -0
- package/dist/UuidUtilities.js.map +1 -0
- package/dist/id-compressor/AppendOnlySortedMap.d.ts +52 -28
- package/dist/id-compressor/AppendOnlySortedMap.d.ts.map +1 -1
- package/dist/id-compressor/AppendOnlySortedMap.js +167 -90
- package/dist/id-compressor/AppendOnlySortedMap.js.map +1 -1
- package/dist/id-compressor/IdCompressor.d.ts +43 -42
- package/dist/id-compressor/IdCompressor.d.ts.map +1 -1
- package/dist/id-compressor/IdCompressor.js +179 -177
- package/dist/id-compressor/IdCompressor.js.map +1 -1
- package/dist/id-compressor/IdRange.js +1 -1
- package/dist/id-compressor/IdRange.js.map +1 -1
- package/dist/id-compressor/NumericUuid.d.ts +6 -14
- package/dist/id-compressor/NumericUuid.d.ts.map +1 -1
- package/dist/id-compressor/NumericUuid.js +15 -76
- package/dist/id-compressor/NumericUuid.js.map +1 -1
- package/dist/id-compressor/SessionIdNormalizer.d.ts +122 -0
- package/dist/id-compressor/SessionIdNormalizer.d.ts.map +1 -0
- package/dist/id-compressor/SessionIdNormalizer.js +418 -0
- package/dist/id-compressor/SessionIdNormalizer.js.map +1 -0
- package/dist/id-compressor/persisted-types/0.0.1.d.ts +6 -13
- package/dist/id-compressor/persisted-types/0.0.1.d.ts.map +1 -1
- package/dist/id-compressor/persisted-types/0.0.1.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/persisted-types/0.1.1.d.ts +1 -6
- package/dist/persisted-types/0.1.1.d.ts.map +1 -1
- package/dist/persisted-types/0.1.1.js +3 -3
- package/dist/persisted-types/0.1.1.js.map +1 -1
- package/lib/ChangeTypes.d.ts +1 -6
- package/lib/ChangeTypes.d.ts.map +1 -1
- package/lib/Checkout.js.map +1 -1
- package/lib/Common.d.ts +21 -3
- package/lib/Common.d.ts.map +1 -1
- package/lib/Common.js +25 -3
- package/lib/Common.js.map +1 -1
- package/lib/EditLog.js +2 -1
- package/lib/EditLog.js.map +1 -1
- package/lib/EditUtilities.js.map +1 -1
- package/lib/Forest.js.map +1 -1
- package/lib/HistoryEditFactory.js.map +1 -1
- package/lib/Identifiers.d.ts +4 -0
- package/lib/Identifiers.d.ts.map +1 -1
- package/lib/Identifiers.js.map +1 -1
- package/lib/LogViewer.d.ts +1 -5
- package/lib/LogViewer.d.ts.map +1 -1
- package/lib/LogViewer.js +5 -13
- package/lib/LogViewer.js.map +1 -1
- package/lib/MergeHealth.js.map +1 -1
- package/lib/NodeIdUtilities.js.map +1 -1
- package/lib/RevisionValueCache.d.ts +13 -10
- package/lib/RevisionValueCache.d.ts.map +1 -1
- package/lib/RevisionValueCache.js +10 -7
- package/lib/RevisionValueCache.js.map +1 -1
- package/lib/RevisionView.js.map +1 -1
- package/lib/SharedTree.d.ts +93 -31
- package/lib/SharedTree.d.ts.map +1 -1
- package/lib/SharedTree.js +107 -78
- package/lib/SharedTree.js.map +1 -1
- package/lib/SharedTreeEncoder.d.ts +3 -3
- package/lib/SharedTreeEncoder.d.ts.map +1 -1
- package/lib/SharedTreeEncoder.js +4 -4
- package/lib/SharedTreeEncoder.js.map +1 -1
- package/lib/StringInterner.js.map +1 -1
- package/lib/Summary.js.map +1 -1
- package/lib/TreeCompressor.d.ts.map +1 -1
- package/lib/TreeCompressor.js +1 -3
- package/lib/TreeCompressor.js.map +1 -1
- package/lib/TreeNodeHandle.js.map +1 -1
- package/lib/TreeView.js.map +1 -1
- package/lib/TreeViewUtilities.js.map +1 -1
- package/lib/UuidUtilities.d.ts +30 -0
- package/lib/UuidUtilities.d.ts.map +1 -0
- package/lib/UuidUtilities.js +98 -0
- package/lib/UuidUtilities.js.map +1 -0
- package/lib/id-compressor/AppendOnlySortedMap.d.ts +52 -28
- package/lib/id-compressor/AppendOnlySortedMap.d.ts.map +1 -1
- package/lib/id-compressor/AppendOnlySortedMap.js +165 -88
- package/lib/id-compressor/AppendOnlySortedMap.js.map +1 -1
- package/lib/id-compressor/IdCompressor.d.ts +43 -42
- package/lib/id-compressor/IdCompressor.d.ts.map +1 -1
- package/lib/id-compressor/IdCompressor.js +97 -95
- package/lib/id-compressor/IdCompressor.js.map +1 -1
- package/lib/id-compressor/NumericUuid.d.ts +6 -14
- package/lib/id-compressor/NumericUuid.d.ts.map +1 -1
- package/lib/id-compressor/NumericUuid.js +11 -70
- package/lib/id-compressor/NumericUuid.js.map +1 -1
- package/lib/id-compressor/SessionIdNormalizer.d.ts +122 -0
- package/lib/id-compressor/SessionIdNormalizer.d.ts.map +1 -0
- package/lib/id-compressor/SessionIdNormalizer.js +414 -0
- package/lib/id-compressor/SessionIdNormalizer.js.map +1 -0
- package/lib/id-compressor/persisted-types/0.0.1.d.ts +6 -13
- package/lib/id-compressor/persisted-types/0.0.1.d.ts.map +1 -1
- package/lib/id-compressor/persisted-types/0.0.1.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/persisted-types/0.1.1.d.ts +1 -6
- package/lib/persisted-types/0.1.1.d.ts.map +1 -1
- package/lib/persisted-types/0.1.1.js.map +1 -1
- package/lib/test/AppendOnlySortedMap.perf.tests.d.ts +6 -0
- package/lib/test/AppendOnlySortedMap.perf.tests.d.ts.map +1 -0
- package/lib/test/AppendOnlySortedMap.perf.tests.js +49 -0
- package/lib/test/AppendOnlySortedMap.perf.tests.js.map +1 -0
- package/lib/test/AppendOnlySortedMap.tests.js +56 -14
- package/lib/test/AppendOnlySortedMap.tests.js.map +1 -1
- package/lib/test/Checkout.tests.js +2 -2
- package/lib/test/Checkout.tests.js.map +1 -1
- package/lib/test/Forest.tests.js.map +1 -1
- package/lib/test/IdCompressor.perf.tests.js +8 -2
- package/lib/test/IdCompressor.perf.tests.js.map +1 -1
- package/lib/test/IdCompressor.tests.js +75 -24
- package/lib/test/IdCompressor.tests.js.map +1 -1
- package/lib/test/LogViewer.tests.js +3 -5
- package/lib/test/LogViewer.tests.js.map +1 -1
- package/lib/test/NumericUuid.perf.tests.js +4 -4
- package/lib/test/NumericUuid.perf.tests.js.map +1 -1
- package/lib/test/NumericUuid.tests.js +5 -4
- package/lib/test/NumericUuid.tests.js.map +1 -1
- package/lib/test/RevisionValueCache.tests.js.map +1 -1
- package/lib/test/RevisionView.tests.js.map +1 -1
- package/lib/test/SessionIdNormalizer.tests.d.ts +6 -0
- package/lib/test/SessionIdNormalizer.tests.d.ts.map +1 -0
- package/lib/test/SessionIdNormalizer.tests.js +299 -0
- package/lib/test/SessionIdNormalizer.tests.js.map +1 -0
- package/lib/test/Summary.tests.js +1 -1
- package/lib/test/Summary.tests.js.map +1 -1
- package/lib/test/TreeCompression.tests.js +1 -1
- package/lib/test/TreeCompression.tests.js.map +1 -1
- package/lib/test/Virtualization.tests.js +1 -1
- package/lib/test/Virtualization.tests.js.map +1 -1
- package/lib/test/fuzz/Generators.d.ts +3 -14
- package/lib/test/fuzz/Generators.d.ts.map +1 -1
- package/lib/test/fuzz/Generators.js +60 -151
- package/lib/test/fuzz/Generators.js.map +1 -1
- package/lib/test/fuzz/SharedTreeFuzzTests.d.ts +10 -7
- package/lib/test/fuzz/SharedTreeFuzzTests.d.ts.map +1 -1
- package/lib/test/fuzz/SharedTreeFuzzTests.js +94 -104
- package/lib/test/fuzz/SharedTreeFuzzTests.js.map +1 -1
- package/lib/test/fuzz/Types.d.ts +2 -9
- package/lib/test/fuzz/Types.d.ts.map +1 -1
- package/lib/test/fuzz/Types.js +1 -1
- package/lib/test/fuzz/Types.js.map +1 -1
- package/lib/test/utilities/IdCompressorTestUtilities.d.ts +57 -11
- package/lib/test/utilities/IdCompressorTestUtilities.d.ts.map +1 -1
- package/lib/test/utilities/IdCompressorTestUtilities.js +112 -98
- package/lib/test/utilities/IdCompressorTestUtilities.js.map +1 -1
- package/lib/test/utilities/PendingLocalStateTests.d.ts.map +1 -1
- package/lib/test/utilities/PendingLocalStateTests.js +2 -1
- package/lib/test/utilities/PendingLocalStateTests.js.map +1 -1
- package/lib/test/utilities/SharedTreeTests.d.ts.map +1 -1
- package/lib/test/utilities/SharedTreeTests.js +30 -1
- package/lib/test/utilities/SharedTreeTests.js.map +1 -1
- package/lib/test/utilities/SharedTreeVersioningTests.d.ts.map +1 -1
- package/lib/test/utilities/SharedTreeVersioningTests.js +20 -0
- package/lib/test/utilities/SharedTreeVersioningTests.js.map +1 -1
- package/lib/test/utilities/SummaryLoadPerfTests.d.ts.map +1 -1
- package/lib/test/utilities/SummaryLoadPerfTests.js +6 -3
- package/lib/test/utilities/SummaryLoadPerfTests.js.map +1 -1
- package/lib/test/utilities/TestNode.js.map +1 -1
- package/lib/test/utilities/TestUtilities.d.ts +9 -1
- package/lib/test/utilities/TestUtilities.d.ts.map +1 -1
- package/lib/test/utilities/TestUtilities.js +27 -13
- package/lib/test/utilities/TestUtilities.js.map +1 -1
- package/package.json +19 -17
- package/src/Common.ts +42 -4
- package/src/EditLog.ts +1 -1
- package/src/Identifiers.ts +5 -0
- package/src/LogViewer.ts +4 -20
- package/src/RevisionValueCache.ts +11 -8
- package/src/SharedTree.ts +222 -75
- package/src/SharedTreeEncoder.ts +17 -11
- package/src/TreeCompressor.ts +2 -4
- package/src/UuidUtilities.ts +123 -0
- package/src/id-compressor/AppendOnlySortedMap.ts +183 -94
- package/src/id-compressor/IdCompressor.ts +144 -132
- package/src/id-compressor/NumericUuid.ts +11 -80
- package/src/id-compressor/SessionIdNormalizer.ts +497 -0
- package/src/id-compressor/persisted-types/0.0.1.ts +12 -15
- package/src/index.ts +5 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SharedTreeEncoder.js","sourceRoot":"","sources":["../src/SharedTreeEncoder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAEN,gBAAgB,EAKhB,iBAAiB,EACjB,qBAAqB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAC9F,OAAO,EAEN,cAAc,EAEd,WAAW,EAIX,gBAAgB,EAGhB,kBAAk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E,WAAW,CAAC,MAAM;SAC3B,CAAC;IACH,CAAC;IACD;;OAEG;IACK,qBAAqB,CAC5B,KAA8B,EAC9B,WAAyB,EACzB,WAA4B;QAE5B,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAE1D,MAAM,cAAc,GAAiC,EAAE,CAAC;QACxD,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;YAChC,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE;gBACxB,IAAI,CAAC,+CAA+C,CAAC,CAAC;aACtD;iBAAM;gBACN,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;;oBAC7B,cAAc,CAAC,IAAI,CAClB,cAAc,CACb;wBACC,OAAO;wBACP,EAAE,QAAE,OAAO,CAAC,OAAO,EAAE,CAAC,mCAAI,IAAI,CAAC,kDAAkD,CAAC;qBAClF,EACD,CAAC,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAC7C,CACD,CAAC;gBACH,CAAC,CAAC,CAAC;aACH;QACF,CAAC,CAAC,CAAC;QAEH,OAAO;YACN,WAAW,EAAE,2BAA2B,CAAC,WAAW,EAAE,WAAW,CAAC;YAClE,cAAc;YACd,OAAO,EAAE,WAAW,CAAC,MAAM;SAC3B,CAAC;IACH,CAAC;CACD;AAED,SAAS,YAAY,CAAC,KAA0D;IAC/E,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IsoBuffer } from '@fluidframework/common-utils';\nimport { assert, fail } from './Common';\nimport { EditLog } from './EditLog';\nimport { convertTreeNodes, newEdit } from './EditUtilities';\nimport { DetachedSequenceId, FinalNodeId, OpSpaceNodeId, TraitLabel } from './Identifiers';\nimport { initialTree } from './InitialTree';\nimport {\n\tContextualizedNodeIdNormalizer,\n\tgetNodeIdContext,\n\tNodeIdContext,\n\tNodeIdConverter,\n\tNodeIdGenerator,\n\tNodeIdNormalizer,\n\tscopeIdNormalizer,\n\tsequencedIdNormalizer,\n} from './NodeIdUtilities';\nimport { getChangeNodeFromView, getChangeNode_0_0_2FromView } from './SerializationUtilities';\nimport {\n\tCompressedChangeInternal,\n\tChangeInternal,\n\tSharedTreeSummary_0_0_2,\n\tWriteFormat,\n\tChangeNode,\n\tEdit,\n\tSharedTreeEditOp,\n\tSharedTreeOpType,\n\tSharedTreeSummary,\n\tEditWithoutId,\n\tChangeTypeInternal,\n\tChangeInternal_0_0_2,\n\tSharedTreeEditOp_0_0_2,\n\treservedIdCount,\n\tChangeNode_0_0_2,\n\tEditChunkContents,\n\tEditLogSummary,\n\tEditChunkContents_0_1_1,\n\tFluidEditHandle,\n\tStablePlaceInternal,\n\tSide,\n} from './persisted-types';\nimport { RevisionView } from './RevisionView';\nimport { MutableStringInterner, StringInterner } from './StringInterner';\nimport { SummaryContents } from './Summary';\nimport { InterningTreeCompressor } from './TreeCompressor';\nimport {\n\tcreateSessionId,\n\thasOngoingSession,\n\tIdCompressor,\n\tIdCreationRange,\n\tSerializedIdCompressorWithNoSession,\n} from './id-compressor';\nimport { ChangeCompressor, compressEdit, decompressEdit } from './ChangeCompression';\nimport { convertEditIds, convertNodeDataIds } from './IdConversion';\n\n/**\n * Object capable of converting between the current internal representation for 0.1.1 edits and their wire format.\n * @internal\n */\nexport class SharedTreeEncoder_0_1_1 {\n\tprivate readonly treeCompressor = new InterningTreeCompressor<never>();\n\tprivate readonly changeCompressor = new ChangeCompressor(this.treeCompressor);\n\n\tpublic constructor(private readonly summarizeHistory: boolean) {}\n\n\t/**\n\t * Encodes an edit op to be sent.\n\t * @param edit - edit to encode.\n\t * @param fluidSerialize - Callback which serializes Fluid handles contained in a JSON-serializable object, returning the result.\n\t * Should be invoked on the edit contents at some point before op encoding is complete.\n\t * This is because edit contents may have Payloads needing to be serialized.\n\t */\n\tpublic encodeEditOp(\n\t\tedit: Edit<ChangeInternal>,\n\t\tfluidSerialize: (\n\t\t\tedit: Edit<CompressedChangeInternal<OpSpaceNodeId>>\n\t\t) => Edit<CompressedChangeInternal<OpSpaceNodeId>>,\n\t\tidRange: IdCreationRange,\n\t\tidNormalizer: NodeIdNormalizer<OpSpaceNodeId>,\n\t\tinterner: StringInterner\n\t): SharedTreeEditOp {\n\t\t// IFluidHandles are not allowed in Ops.\n\t\t// Ops can contain Fluid's Serializable (for payloads) which allows IFluidHandles.\n\t\t// So replace the handles by encoding before sending:\n\t\tconst semiSerialized = fluidSerialize(\n\t\t\tcompressEdit(this.changeCompressor, interner, scopeIdNormalizer(idNormalizer, idRange.sessionId), edit)\n\t\t);\n\n\t\treturn {\n\t\t\ttype: SharedTreeOpType.Edit,\n\t\t\tedit: semiSerialized,\n\t\t\tversion: WriteFormat.v0_1_1,\n\t\t\tidRange,\n\t\t};\n\t}\n\n\t/**\n\t * Decodes an edit op encoded with `encodeEditOp`.\n\t * @param op - op to decode.\n\t * @param fluidDeserialize - Callback which deserializes Fluid handles contained in a JSON-serializable object.\n\t * Should be invoked on the semi-serialized edit contents at some point before decoding is complete.\n\t * This will rehydrate any serialized Fluid handles into usable IFluidHandle objects.\n\t */\n\tpublic decodeEditOp(\n\t\top: SharedTreeEditOp,\n\t\tfluidDeserialize: (\n\t\t\tsemiSerializedEdit: Edit<CompressedChangeInternal<OpSpaceNodeId>>\n\t\t) => Edit<CompressedChangeInternal<OpSpaceNodeId>>,\n\t\tidNormalizer: NodeIdNormalizer<OpSpaceNodeId>,\n\t\tinterner: StringInterner\n\t): Edit<ChangeInternal> {\n\t\tconst { edit: semiSerializedEdit } = op;\n\t\tconst parsedEdit = fluidDeserialize(semiSerializedEdit);\n\t\treturn decompressEdit(\n\t\t\tthis.changeCompressor,\n\t\t\tinterner,\n\t\t\tscopeIdNormalizer(idNormalizer, op.idRange.sessionId),\n\t\t\tparsedEdit\n\t\t);\n\t}\n\n\t/**\n\t * Encodes a summary.\n\t */\n\tpublic encodeSummary(\n\t\tedits: EditLog<ChangeInternal>,\n\t\tcurrentView: RevisionView,\n\t\tidContext: NodeIdContext,\n\t\tidNormalizer: NodeIdNormalizer<OpSpaceNodeId>,\n\t\tinterner: StringInterner,\n\t\tserializedIdCompressor: SerializedIdCompressorWithNoSession\n\t): SharedTreeSummary {\n\t\tif (this.summarizeHistory) {\n\t\t\treturn this.fullHistorySummarizer(edits, currentView, idNormalizer, interner, serializedIdCompressor);\n\t\t} else {\n\t\t\treturn this.noHistorySummarizer(\n\t\t\t\tedits,\n\t\t\t\tcurrentView,\n\t\t\t\tidContext,\n\t\t\t\tidNormalizer,\n\t\t\t\tinterner,\n\t\t\t\tserializedIdCompressor\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Decodes an encoded summary.\n\t */\n\tpublic decodeSummary({\n\t\teditHistory,\n\t\tcurrentTree: compressedTree,\n\t\tinternedStrings,\n\t\tidCompressor: serializedIdCompressor,\n\t\tversion,\n\t}: SharedTreeSummary): SummaryContents {\n\t\tassert(version === WriteFormat.v0_1_1, `Invalid summary version to decode: ${version}, expected: 0.1.1`);\n\t\tassert(typeof editHistory === 'object', '0.1.1 summary encountered with non-object edit history.');\n\n\t\tconst idCompressor = hasOngoingSession(serializedIdCompressor)\n\t\t\t? IdCompressor.deserialize(serializedIdCompressor)\n\t\t\t: IdCompressor.deserialize(serializedIdCompressor, createSessionId()); // TODO attribution\n\n\t\tconst interner = new MutableStringInterner(internedStrings);\n\t\tconst sequencedNormalizer = sequencedIdNormalizer(getNodeIdContext(idCompressor));\n\t\tconst decompressedTree: ChangeNode | undefined =\n\t\t\tcompressedTree !== undefined\n\t\t\t\t? this.treeCompressor.decompress(compressedTree, interner, sequencedNormalizer)\n\t\t\t\t: undefined;\n\t\tconst { editChunks, editIds } = editHistory;\n\t\tassert(editChunks !== undefined, 'Missing editChunks on 0.1.1 summary.');\n\t\tassert(editIds !== undefined, 'Missing editIds on 0.1.1 summary.');\n\n\t\tconst uncompressedChunks = editChunks.map(({ startRevision, chunk }) => ({\n\t\t\tstartRevision,\n\t\t\tchunk: isEditHandle(chunk)\n\t\t\t\t? {\n\t\t\t\t\t\tget: async () => {\n\t\t\t\t\t\t\tconst baseHandle = chunk;\n\t\t\t\t\t\t\tconst contents: EditChunkContents = JSON.parse(\n\t\t\t\t\t\t\t\tIsoBuffer.from(await baseHandle.get()).toString()\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t// Note: any interned IDs referenced in chunks taken at the time of summarization must be included\n\t\t\t\t\t\t\t// in the summary. So this interner is sufficient.\n\t\t\t\t\t\t\treturn this.decodeEditChunk(contents, sequencedNormalizer, interner);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbaseHandle: chunk,\n\t\t\t\t }\n\t\t\t\t: chunk.map((edit) => decompressEdit(this.changeCompressor, interner, sequencedNormalizer, edit)),\n\t\t}));\n\t\treturn {\n\t\t\tcurrentTree: decompressedTree,\n\t\t\teditHistory: { editIds, editChunks: uncompressedChunks },\n\t\t\tidCompressor,\n\t\t\tinterner,\n\t\t};\n\t}\n\n\t/**\n\t * Does not preserve (persist) history at all.\n\t * Instead, the history returned in the summary will contain a single edit that creates a revision identical to the supplied view.\n\t * Writes summary format 0.1.1 which does not store the currentView for no history summaries.\n\t */\n\tprivate noHistorySummarizer<TChange>(\n\t\t_edits: EditLog<TChange>,\n\t\tcurrentView: RevisionView,\n\t\tidContext: NodeIdContext,\n\t\tidNormalizer: NodeIdNormalizer<OpSpaceNodeId>,\n\t\tinterner: StringInterner,\n\t\tserializedIdCompressor: SerializedIdCompressorWithNoSession\n\t): SharedTreeSummary {\n\t\tconst currentTree = getChangeNodeFromView(currentView);\n\t\tconst initialTreeId = idContext.convertToNodeId(initialTree.identifier);\n\t\tconst changes: ChangeInternal[] = [];\n\t\t// Generate a set of changes to set the root node's children to that of the root in the currentTree\n\t\tObject.entries(currentTree.traits).forEach(([label, children]) => {\n\t\t\tconst id = 0 as DetachedSequenceId;\n\t\t\tchanges.push(\n\t\t\t\tChangeInternal.build(children, id),\n\t\t\t\tChangeInternal.insert(\n\t\t\t\t\tid,\n\t\t\t\t\tStablePlaceInternal.atStartOf({ parent: initialTreeId, label: label as TraitLabel })\n\t\t\t\t)\n\t\t\t);\n\t\t});\n\n\t\tif (currentTree.payload !== undefined) {\n\t\t\tchanges.push(ChangeInternal.setPayload(initialTreeId, currentTree.payload));\n\t\t}\n\n\t\tassert(\n\t\t\tcurrentTree.identifier === initialTreeId && currentTree.definition === initialTree.definition,\n\t\t\t'root definition and identifier should be immutable.'\n\t\t);\n\t\tconst edit = newEdit(changes);\n\t\tconst compressedChanges = edit.changes.map((change) =>\n\t\t\tthis.changeCompressor.compress(change, interner, sequencedIdNormalizer(idNormalizer))\n\t\t);\n\t\treturn {\n\t\t\teditHistory: {\n\t\t\t\teditChunks: [{ startRevision: 0, chunk: [{ changes: compressedChanges }] }],\n\t\t\t\teditIds: [edit.id],\n\t\t\t},\n\t\t\tversion: WriteFormat.v0_1_1,\n\t\t\tinternedStrings: interner.getSerializable(),\n\t\t\tidCompressor: serializedIdCompressor,\n\t\t};\n\t}\n\n\t/**\n\t * Generates a summary with format version 0.1.1. This will prefer handles over edits in edit chunks where possible,\n\t * and string interning and tree compression will be applied.\n\t */\n\tprivate fullHistorySummarizer(\n\t\tedits: EditLog<ChangeInternal>,\n\t\tcurrentView: RevisionView,\n\t\tidNormalizer: NodeIdNormalizer<OpSpaceNodeId>,\n\t\tinterner: StringInterner,\n\t\tserializedIdCompressor: SerializedIdCompressorWithNoSession\n\t): SharedTreeSummary {\n\t\tconst sequencedNormalizer = sequencedIdNormalizer(idNormalizer);\n\t\tconst currentTree = this.treeCompressor.compress(\n\t\t\tgetChangeNodeFromView(currentView),\n\t\t\tinterner,\n\t\t\tsequencedNormalizer\n\t\t);\n\n\t\treturn {\n\t\t\tcurrentTree,\n\t\t\teditHistory: edits.getEditLogSummary((edit) =>\n\t\t\t\tcompressEdit(this.changeCompressor, interner, sequencedNormalizer, edit)\n\t\t\t),\n\t\t\tversion: WriteFormat.v0_1_1,\n\t\t\tinternedStrings: interner.getSerializable(),\n\t\t\tidCompressor: serializedIdCompressor,\n\t\t};\n\t}\n\n\tpublic encodeEditChunk(\n\t\tedits: readonly EditWithoutId<ChangeInternal>[],\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<FinalNodeId>,\n\t\tinterner: StringInterner\n\t): EditChunkContents_0_1_1 {\n\t\tconst compressedEdits = edits.map((edit) => compressEdit(this.changeCompressor, interner, idNormalizer, edit));\n\t\treturn {\n\t\t\tversion: WriteFormat.v0_1_1,\n\t\t\tedits: compressedEdits,\n\t\t};\n\t}\n\n\tpublic decodeEditChunk(\n\t\tcontents: EditChunkContents,\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<FinalNodeId>,\n\t\tinterner: StringInterner\n\t): EditWithoutId<ChangeInternal>[] {\n\t\tassert(\n\t\t\tcontents.version === WriteFormat.v0_1_1,\n\t\t\t`Invalid editChunk to decode: ${contents.version}. Expected 0.1.1.`\n\t\t);\n\t\treturn contents.edits.map((edit) => decompressEdit(this.changeCompressor, interner, idNormalizer, edit));\n\t}\n}\n\n/**\n * Object capable of converting between the current internal representation for 0.0.2 edits and their wire format.\n * @internal\n */\nexport class SharedTreeEncoder_0_0_2 {\n\tpublic constructor(private readonly summarizeHistory: boolean) {}\n\n\t/**\n\t * Encodes an edit op to be sent.\n\t * @param edit - edit to encode.\n\t * @param fluidSerialize - Callback which serializes Fluid handles contained in a JSON-serializable object, returning the result.\n\t * Should be invoked on the edit contents at some point before op encoding is complete.\n\t * This is because edit contents may have Payloads needing to be serialized.\n\t */\n\tpublic encodeEditOp(\n\t\tedit: Edit<ChangeInternal>,\n\t\tfluidSerialize: (edit: Edit<ChangeInternal_0_0_2>) => Edit<ChangeInternal_0_0_2>,\n\t\tidConverter: NodeIdConverter\n\t): SharedTreeEditOp_0_0_2 {\n\t\t// IFluidHandles are not allowed in Ops.\n\t\t// Ops can contain Fluid's Serializable (for payloads) which allows IFluidHandles.\n\t\t// So replace the handles by encoding before sending:\n\t\tconst semiSerialized = fluidSerialize(convertEditIds(edit, (id) => idConverter.convertToStableNodeId(id)));\n\n\t\treturn {\n\t\t\ttype: SharedTreeOpType.Edit,\n\t\t\tedit: semiSerialized,\n\t\t\tversion: WriteFormat.v0_0_2,\n\t\t};\n\t}\n\n\t/**\n\t * Decodes an edit op encoded with `encodeEditOp`.\n\t * @param op - op to decode.\n\t * @param fluidDeserialize - Callback which deserializes Fluid handles contained in a JSON-serializable object.\n\t * Should be invoked on the semi-serialized edit contents at some point before decoding is complete.\n\t * This will rehydrate any serialized Fluid handles into usable IFluidHandle objects.\n\t */\n\tpublic decodeEditOp(\n\t\top: SharedTreeEditOp_0_0_2,\n\t\tfluidDeserialize: (semiSerializedEdit: Edit<ChangeInternal_0_0_2>) => Edit<ChangeInternal_0_0_2>,\n\t\tidGenerator: NodeIdGenerator\n\t): Edit<ChangeInternal> {\n\t\tconst { edit: semiSerializedEdit } = op;\n\t\tconst parsedEdit = fluidDeserialize(semiSerializedEdit);\n\t\treturn convertEditIds(parsedEdit, (id) => idGenerator.generateNodeId(id));\n\t}\n\n\t/**\n\t * Encodes a summary.\n\t */\n\tpublic encodeSummary(\n\t\tedits: EditLog<ChangeInternal>,\n\t\tcurrentView: RevisionView,\n\t\tidConverter: NodeIdConverter\n\t): SharedTreeSummary_0_0_2 {\n\t\tif (this.summarizeHistory) {\n\t\t\treturn this.fullHistorySummarizer(edits, currentView, idConverter);\n\t\t} else {\n\t\t\treturn this.noHistorySummarizer(edits, currentView, idConverter);\n\t\t}\n\t}\n\n\t/**\n\t * Decodes an encoded summary.\n\t */\n\tpublic decodeSummary({ currentTree, sequencedEdits }: SharedTreeSummary_0_0_2): SummaryContents {\n\t\tassert(sequencedEdits !== undefined, '0.0.2 summary encountered with missing sequencedEdits field.');\n\t\tconst idCompressor = new IdCompressor(createSessionId(), reservedIdCount);\n\t\tconst idGenerator = getNodeIdContext(idCompressor);\n\t\tconst generateId = (id) => idGenerator.generateNodeId(id);\n\n\t\t// This saves all of the edits in the summary as part of the first chunk.\n\t\tconst temporaryLog = new EditLog<ChangeInternal>();\n\t\tsequencedEdits.forEach((edit) =>\n\t\t\ttemporaryLog.addSequencedEdit(convertEditIds(edit, generateId), {\n\t\t\t\tsequenceNumber: 1,\n\t\t\t\treferenceSequenceNumber: 0,\n\t\t\t})\n\t\t);\n\n\t\treturn {\n\t\t\tcurrentTree: convertTreeNodes<ChangeNode_0_0_2, ChangeNode>(currentTree, (node) =>\n\t\t\t\tconvertNodeDataIds(node, generateId)\n\t\t\t),\n\t\t\tidCompressor,\n\t\t\tinterner: new MutableStringInterner(),\n\t\t\t// This cast is valid because we just constructed this log and gave it only in-session edits.\n\t\t\teditHistory: temporaryLog.getEditLogSummary() as EditLogSummary<ChangeInternal, never>,\n\t\t};\n\t}\n\n\t/**\n\t * Does not preserve (persist) history at all.\n\t * Instead, the history returned in the summary will contain a single edit that creates a revision identical to the supplied view.\n\t * @param stable - Generates the single edit with a stable edit ID. False by default, used for testing.\n\t */\n\tprivate noHistorySummarizer<TChange>(\n\t\t_edits: EditLog<TChange>,\n\t\tcurrentView: RevisionView,\n\t\tidConverter: NodeIdConverter\n\t): SharedTreeSummary_0_0_2 {\n\t\tconst currentTree = getChangeNode_0_0_2FromView(currentView, idConverter);\n\t\tconst changes: ChangeInternal_0_0_2[] = [];\n\t\t// Generate a set of changes to set the root node's children to that of the root in the currentTree\n\t\tObject.entries(currentTree.traits).forEach(([label, children]) => {\n\t\t\tconst id = 0 as DetachedSequenceId;\n\t\t\tchanges.push(\n\t\t\t\t{ type: ChangeTypeInternal.Build, source: children, destination: id },\n\t\t\t\t{\n\t\t\t\t\ttype: ChangeTypeInternal.Insert,\n\t\t\t\t\tsource: id,\n\t\t\t\t\tdestination: {\n\t\t\t\t\t\tside: Side.After,\n\t\t\t\t\t\treferenceTrait: { label: label as TraitLabel, parent: initialTree.identifier },\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t);\n\t\t});\n\n\t\tif (currentTree.payload !== undefined) {\n\t\t\tchanges.push({\n\t\t\t\ttype: ChangeTypeInternal.SetValue,\n\t\t\t\tnodeToModify: initialTree.identifier,\n\t\t\t\tpayload: currentTree.payload,\n\t\t\t});\n\t\t}\n\n\t\tassert(\n\t\t\tcurrentTree.identifier === initialTree.identifier && currentTree.definition === initialTree.definition,\n\t\t\t'root definition and identifier should be immutable.'\n\t\t);\n\t\tconst edit = newEdit(changes);\n\n\t\treturn {\n\t\t\tcurrentTree,\n\t\t\tsequencedEdits: [\n\t\t\t\t{\n\t\t\t\t\tid: edit.id,\n\t\t\t\t\tchanges: edit.changes,\n\t\t\t\t},\n\t\t\t],\n\t\t\tversion: WriteFormat.v0_0_2,\n\t\t};\n\t}\n\t/**\n\t * Preserves the full history in the generated summary.\n\t */\n\tprivate fullHistorySummarizer(\n\t\tedits: EditLog<ChangeInternal>,\n\t\tcurrentView: RevisionView,\n\t\tidConverter: NodeIdConverter\n\t): SharedTreeSummary_0_0_2 {\n\t\tconst { editChunks, editIds } = edits.getEditLogSummary();\n\n\t\tconst sequencedEdits: Edit<ChangeInternal_0_0_2>[] = [];\n\t\tlet idIndex = 0;\n\t\teditChunks.forEach(({ chunk }) => {\n\t\t\tif (isEditHandle(chunk)) {\n\t\t\t\tfail('Cannot write handles to summary version 0.0.2');\n\t\t\t} else {\n\t\t\t\tchunk.forEach(({ changes }) => {\n\t\t\t\t\tsequencedEdits.push(\n\t\t\t\t\t\tconvertEditIds(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tchanges,\n\t\t\t\t\t\t\t\tid: editIds[idIndex++] ?? fail('Number of edits should match number of edit IDs.'),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t(id) => idConverter.convertToStableNodeId(id)\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\treturn {\n\t\t\tcurrentTree: getChangeNode_0_0_2FromView(currentView, idConverter),\n\t\t\tsequencedEdits,\n\t\t\tversion: WriteFormat.v0_0_2,\n\t\t};\n\t}\n}\n\nfunction isEditHandle(chunk: FluidEditHandle | readonly EditWithoutId<unknown>[]): chunk is FluidEditHandle {\n\treturn !Array.isArray(chunk);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SharedTreeEncoder.js","sourceRoot":"","sources":["../src/SharedTreeEncoder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAEN,gBAAgB,EAKhB,iBAAiB,EACjB,qBAAqB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAC9F,OAAO,EAEN,cAAc,EAEd,WAAW,EAIX,gBAAgB,EAGhB,kBAAkB,EAGlB,eAAe,EAMf,mBAAmB,EACnB,IAAI,GACJ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,qBAAqB,EAAkB,MAAM,kBAAkB,CAAC;AAEzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EACN,eAAe,EACf,iBAAiB,EACjB,YAAY,GAGZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,EAA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AK,EAAE,EAAE,EAAE;YAChC,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE;gBACxB,IAAI,CAAC,+CAA+C,CAAC,CAAC;aACtD;iBAAM;gBACN,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;;oBAC7B,cAAc,CAAC,IAAI,CAClB,cAAc,CACb;wBACC,OAAO;wBACP,EAAE,EAAE,MAAA,OAAO,CAAC,OAAO,EAAE,CAAC,mCAAI,IAAI,CAAC,kDAAkD,CAAC;qBAClF,EACD,CAAC,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAC7C,CACD,CAAC;gBACH,CAAC,CAAC,CAAC;aACH;QACF,CAAC,CAAC,CAAC;QAEH,OAAO;YACN,WAAW,EAAE,2BAA2B,CAAC,WAAW,EAAE,WAAW,CAAC;YAClE,cAAc;YACd,OAAO,EAAE,WAAW,CAAC,MAAM;SAC3B,CAAC;IACH,CAAC;CACD;AAED,SAAS,YAAY,CAAC,KAA0D;IAC/E,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IsoBuffer } from '@fluidframework/common-utils';\nimport { assert, fail } from './Common';\nimport { EditLog } from './EditLog';\nimport { convertTreeNodes, newEdit } from './EditUtilities';\nimport { AttributionId, DetachedSequenceId, FinalNodeId, OpSpaceNodeId, TraitLabel } from './Identifiers';\nimport { initialTree } from './InitialTree';\nimport {\n\tContextualizedNodeIdNormalizer,\n\tgetNodeIdContext,\n\tNodeIdContext,\n\tNodeIdConverter,\n\tNodeIdGenerator,\n\tNodeIdNormalizer,\n\tscopeIdNormalizer,\n\tsequencedIdNormalizer,\n} from './NodeIdUtilities';\nimport { getChangeNodeFromView, getChangeNode_0_0_2FromView } from './SerializationUtilities';\nimport {\n\tCompressedChangeInternal,\n\tChangeInternal,\n\tSharedTreeSummary_0_0_2,\n\tWriteFormat,\n\tChangeNode,\n\tEdit,\n\tSharedTreeEditOp,\n\tSharedTreeOpType,\n\tSharedTreeSummary,\n\tEditWithoutId,\n\tChangeTypeInternal,\n\tChangeInternal_0_0_2,\n\tSharedTreeEditOp_0_0_2,\n\treservedIdCount,\n\tChangeNode_0_0_2,\n\tEditChunkContents,\n\tEditLogSummary,\n\tEditChunkContents_0_1_1,\n\tFluidEditHandle,\n\tStablePlaceInternal,\n\tSide,\n} from './persisted-types';\nimport { RevisionView } from './RevisionView';\nimport { MutableStringInterner, StringInterner } from './StringInterner';\nimport { SummaryContents } from './Summary';\nimport { InterningTreeCompressor } from './TreeCompressor';\nimport {\n\tcreateSessionId,\n\thasOngoingSession,\n\tIdCompressor,\n\tIdCreationRange,\n\tSerializedIdCompressorWithNoSession,\n} from './id-compressor';\nimport { ChangeCompressor, compressEdit, decompressEdit } from './ChangeCompression';\nimport { convertEditIds, convertNodeDataIds } from './IdConversion';\n\n/**\n * Object capable of converting between the current internal representation for 0.1.1 edits and their wire format.\n * @internal\n */\nexport class SharedTreeEncoder_0_1_1 {\n\tprivate readonly treeCompressor = new InterningTreeCompressor<never>();\n\tprivate readonly changeCompressor = new ChangeCompressor(this.treeCompressor);\n\n\tpublic constructor(private readonly summarizeHistory: boolean) {}\n\n\t/**\n\t * Encodes an edit op to be sent.\n\t * @param edit - edit to encode.\n\t * @param fluidSerialize - Callback which serializes Fluid handles contained in a JSON-serializable object, returning the result.\n\t * Should be invoked on the edit contents at some point before op encoding is complete.\n\t * This is because edit contents may have Payloads needing to be serialized.\n\t */\n\tpublic encodeEditOp(\n\t\tedit: Edit<ChangeInternal>,\n\t\tfluidSerialize: (\n\t\t\tedit: Edit<CompressedChangeInternal<OpSpaceNodeId>>\n\t\t) => Edit<CompressedChangeInternal<OpSpaceNodeId>>,\n\t\tidRange: IdCreationRange,\n\t\tidNormalizer: NodeIdNormalizer<OpSpaceNodeId>,\n\t\tinterner: StringInterner\n\t): SharedTreeEditOp {\n\t\t// IFluidHandles are not allowed in Ops.\n\t\t// Ops can contain Fluid's Serializable (for payloads) which allows IFluidHandles.\n\t\t// So replace the handles by encoding before sending:\n\t\tconst semiSerialized = fluidSerialize(\n\t\t\tcompressEdit(this.changeCompressor, interner, scopeIdNormalizer(idNormalizer, idRange.sessionId), edit)\n\t\t);\n\n\t\treturn {\n\t\t\ttype: SharedTreeOpType.Edit,\n\t\t\tedit: semiSerialized,\n\t\t\tversion: WriteFormat.v0_1_1,\n\t\t\tidRange,\n\t\t};\n\t}\n\n\t/**\n\t * Decodes an edit op encoded with `encodeEditOp`.\n\t * @param op - op to decode.\n\t * @param fluidDeserialize - Callback which deserializes Fluid handles contained in a JSON-serializable object.\n\t * Should be invoked on the semi-serialized edit contents at some point before decoding is complete.\n\t * This will rehydrate any serialized Fluid handles into usable IFluidHandle objects.\n\t */\n\tpublic decodeEditOp(\n\t\top: SharedTreeEditOp,\n\t\tfluidDeserialize: (\n\t\t\tsemiSerializedEdit: Edit<CompressedChangeInternal<OpSpaceNodeId>>\n\t\t) => Edit<CompressedChangeInternal<OpSpaceNodeId>>,\n\t\tidNormalizer: NodeIdNormalizer<OpSpaceNodeId>,\n\t\tinterner: StringInterner\n\t): Edit<ChangeInternal> {\n\t\tconst { edit: semiSerializedEdit } = op;\n\t\tconst parsedEdit = fluidDeserialize(semiSerializedEdit);\n\t\treturn decompressEdit(\n\t\t\tthis.changeCompressor,\n\t\t\tinterner,\n\t\t\tscopeIdNormalizer(idNormalizer, op.idRange.sessionId),\n\t\t\tparsedEdit\n\t\t);\n\t}\n\n\t/**\n\t * Encodes a summary.\n\t */\n\tpublic encodeSummary(\n\t\tedits: EditLog<ChangeInternal>,\n\t\tcurrentView: RevisionView,\n\t\tidContext: NodeIdContext,\n\t\tidNormalizer: NodeIdNormalizer<OpSpaceNodeId>,\n\t\tinterner: StringInterner,\n\t\tserializedIdCompressor: SerializedIdCompressorWithNoSession\n\t): SharedTreeSummary {\n\t\tif (this.summarizeHistory) {\n\t\t\treturn this.fullHistorySummarizer(edits, currentView, idNormalizer, interner, serializedIdCompressor);\n\t\t} else {\n\t\t\treturn this.noHistorySummarizer(\n\t\t\t\tedits,\n\t\t\t\tcurrentView,\n\t\t\t\tidContext,\n\t\t\t\tidNormalizer,\n\t\t\t\tinterner,\n\t\t\t\tserializedIdCompressor\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Decodes an encoded summary.\n\t */\n\tpublic decodeSummary(\n\t\t{\n\t\t\teditHistory,\n\t\t\tcurrentTree: compressedTree,\n\t\t\tinternedStrings,\n\t\t\tidCompressor: serializedIdCompressor,\n\t\t\tversion,\n\t\t}: SharedTreeSummary,\n\t\tattributionId: AttributionId\n\t): SummaryContents {\n\t\tassert(version === WriteFormat.v0_1_1, `Invalid summary version to decode: ${version}, expected: 0.1.1`);\n\t\tassert(typeof editHistory === 'object', '0.1.1 summary encountered with non-object edit history.');\n\n\t\tconst idCompressor = hasOngoingSession(serializedIdCompressor)\n\t\t\t? IdCompressor.deserialize(serializedIdCompressor)\n\t\t\t: IdCompressor.deserialize(serializedIdCompressor, createSessionId(), attributionId);\n\n\t\tconst interner = new MutableStringInterner(internedStrings);\n\t\tconst sequencedNormalizer = sequencedIdNormalizer(getNodeIdContext(idCompressor));\n\t\tconst decompressedTree: ChangeNode | undefined =\n\t\t\tcompressedTree !== undefined\n\t\t\t\t? this.treeCompressor.decompress(compressedTree, interner, sequencedNormalizer)\n\t\t\t\t: undefined;\n\t\tconst { editChunks, editIds } = editHistory;\n\t\tassert(editChunks !== undefined, 'Missing editChunks on 0.1.1 summary.');\n\t\tassert(editIds !== undefined, 'Missing editIds on 0.1.1 summary.');\n\n\t\tconst uncompressedChunks = editChunks.map(({ startRevision, chunk }) => ({\n\t\t\tstartRevision,\n\t\t\tchunk: isEditHandle(chunk)\n\t\t\t\t? {\n\t\t\t\t\t\tget: async () => {\n\t\t\t\t\t\t\tconst baseHandle = chunk;\n\t\t\t\t\t\t\tconst contents: EditChunkContents = JSON.parse(\n\t\t\t\t\t\t\t\tIsoBuffer.from(await baseHandle.get()).toString()\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t// Note: any interned IDs referenced in chunks taken at the time of summarization must be included\n\t\t\t\t\t\t\t// in the summary. So this interner is sufficient.\n\t\t\t\t\t\t\treturn this.decodeEditChunk(contents, sequencedNormalizer, interner);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbaseHandle: chunk,\n\t\t\t\t }\n\t\t\t\t: chunk.map((edit) => decompressEdit(this.changeCompressor, interner, sequencedNormalizer, edit)),\n\t\t}));\n\t\treturn {\n\t\t\tcurrentTree: decompressedTree,\n\t\t\teditHistory: { editIds, editChunks: uncompressedChunks },\n\t\t\tidCompressor,\n\t\t\tinterner,\n\t\t};\n\t}\n\n\t/**\n\t * Does not preserve (persist) history at all.\n\t * Instead, the history returned in the summary will contain a single edit that creates a revision identical to the supplied view.\n\t * Writes summary format 0.1.1 which does not store the currentView for no history summaries.\n\t */\n\tprivate noHistorySummarizer<TChange>(\n\t\t_edits: EditLog<TChange>,\n\t\tcurrentView: RevisionView,\n\t\tidContext: NodeIdContext,\n\t\tidNormalizer: NodeIdNormalizer<OpSpaceNodeId>,\n\t\tinterner: StringInterner,\n\t\tserializedIdCompressor: SerializedIdCompressorWithNoSession\n\t): SharedTreeSummary {\n\t\tconst currentTree = getChangeNodeFromView(currentView);\n\t\tconst initialTreeId = idContext.convertToNodeId(initialTree.identifier);\n\t\tconst changes: ChangeInternal[] = [];\n\t\t// Generate a set of changes to set the root node's children to that of the root in the currentTree\n\t\tObject.entries(currentTree.traits).forEach(([label, children]) => {\n\t\t\tconst id = 0 as DetachedSequenceId;\n\t\t\tchanges.push(\n\t\t\t\tChangeInternal.build(children, id),\n\t\t\t\tChangeInternal.insert(\n\t\t\t\t\tid,\n\t\t\t\t\tStablePlaceInternal.atStartOf({ parent: initialTreeId, label: label as TraitLabel })\n\t\t\t\t)\n\t\t\t);\n\t\t});\n\n\t\tif (currentTree.payload !== undefined) {\n\t\t\tchanges.push(ChangeInternal.setPayload(initialTreeId, currentTree.payload));\n\t\t}\n\n\t\tassert(\n\t\t\tcurrentTree.identifier === initialTreeId && currentTree.definition === initialTree.definition,\n\t\t\t'root definition and identifier should be immutable.'\n\t\t);\n\t\tconst edit = newEdit(changes);\n\t\tconst compressedChanges = edit.changes.map((change) =>\n\t\t\tthis.changeCompressor.compress(change, interner, sequencedIdNormalizer(idNormalizer))\n\t\t);\n\t\treturn {\n\t\t\teditHistory: {\n\t\t\t\teditChunks: [{ startRevision: 0, chunk: [{ changes: compressedChanges }] }],\n\t\t\t\teditIds: [edit.id],\n\t\t\t},\n\t\t\tversion: WriteFormat.v0_1_1,\n\t\t\tinternedStrings: interner.getSerializable(),\n\t\t\tidCompressor: serializedIdCompressor,\n\t\t};\n\t}\n\n\t/**\n\t * Generates a summary with format version 0.1.1. This will prefer handles over edits in edit chunks where possible,\n\t * and string interning and tree compression will be applied.\n\t */\n\tprivate fullHistorySummarizer(\n\t\tedits: EditLog<ChangeInternal>,\n\t\tcurrentView: RevisionView,\n\t\tidNormalizer: NodeIdNormalizer<OpSpaceNodeId>,\n\t\tinterner: StringInterner,\n\t\tserializedIdCompressor: SerializedIdCompressorWithNoSession\n\t): SharedTreeSummary {\n\t\tconst sequencedNormalizer = sequencedIdNormalizer(idNormalizer);\n\t\tconst currentTree = this.treeCompressor.compress(\n\t\t\tgetChangeNodeFromView(currentView),\n\t\t\tinterner,\n\t\t\tsequencedNormalizer\n\t\t);\n\n\t\treturn {\n\t\t\tcurrentTree,\n\t\t\teditHistory: edits.getEditLogSummary((edit) =>\n\t\t\t\tcompressEdit(this.changeCompressor, interner, sequencedNormalizer, edit)\n\t\t\t),\n\t\t\tversion: WriteFormat.v0_1_1,\n\t\t\tinternedStrings: interner.getSerializable(),\n\t\t\tidCompressor: serializedIdCompressor,\n\t\t};\n\t}\n\n\tpublic encodeEditChunk(\n\t\tedits: readonly EditWithoutId<ChangeInternal>[],\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<FinalNodeId>,\n\t\tinterner: StringInterner\n\t): EditChunkContents_0_1_1 {\n\t\tconst compressedEdits = edits.map((edit) => compressEdit(this.changeCompressor, interner, idNormalizer, edit));\n\t\treturn {\n\t\t\tversion: WriteFormat.v0_1_1,\n\t\t\tedits: compressedEdits,\n\t\t};\n\t}\n\n\tpublic decodeEditChunk(\n\t\tcontents: EditChunkContents,\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<FinalNodeId>,\n\t\tinterner: StringInterner\n\t): EditWithoutId<ChangeInternal>[] {\n\t\tassert(\n\t\t\tcontents.version === WriteFormat.v0_1_1,\n\t\t\t`Invalid editChunk to decode: ${contents.version}. Expected 0.1.1.`\n\t\t);\n\t\treturn contents.edits.map((edit) => decompressEdit(this.changeCompressor, interner, idNormalizer, edit));\n\t}\n}\n\n/**\n * Object capable of converting between the current internal representation for 0.0.2 edits and their wire format.\n * @internal\n */\nexport class SharedTreeEncoder_0_0_2 {\n\tpublic constructor(private readonly summarizeHistory: boolean) {}\n\n\t/**\n\t * Encodes an edit op to be sent.\n\t * @param edit - edit to encode.\n\t * @param fluidSerialize - Callback which serializes Fluid handles contained in a JSON-serializable object, returning the result.\n\t * Should be invoked on the edit contents at some point before op encoding is complete.\n\t * This is because edit contents may have Payloads needing to be serialized.\n\t */\n\tpublic encodeEditOp(\n\t\tedit: Edit<ChangeInternal>,\n\t\tfluidSerialize: (edit: Edit<ChangeInternal_0_0_2>) => Edit<ChangeInternal_0_0_2>,\n\t\tidConverter: NodeIdConverter\n\t): SharedTreeEditOp_0_0_2 {\n\t\t// IFluidHandles are not allowed in Ops.\n\t\t// Ops can contain Fluid's Serializable (for payloads) which allows IFluidHandles.\n\t\t// So replace the handles by encoding before sending:\n\t\tconst semiSerialized = fluidSerialize(convertEditIds(edit, (id) => idConverter.convertToStableNodeId(id)));\n\n\t\treturn {\n\t\t\ttype: SharedTreeOpType.Edit,\n\t\t\tedit: semiSerialized,\n\t\t\tversion: WriteFormat.v0_0_2,\n\t\t};\n\t}\n\n\t/**\n\t * Decodes an edit op encoded with `encodeEditOp`.\n\t * @param op - op to decode.\n\t * @param fluidDeserialize - Callback which deserializes Fluid handles contained in a JSON-serializable object.\n\t * Should be invoked on the semi-serialized edit contents at some point before decoding is complete.\n\t * This will rehydrate any serialized Fluid handles into usable IFluidHandle objects.\n\t */\n\tpublic decodeEditOp(\n\t\top: SharedTreeEditOp_0_0_2,\n\t\tfluidDeserialize: (semiSerializedEdit: Edit<ChangeInternal_0_0_2>) => Edit<ChangeInternal_0_0_2>,\n\t\tidGenerator: NodeIdGenerator\n\t): Edit<ChangeInternal> {\n\t\tconst { edit: semiSerializedEdit } = op;\n\t\tconst parsedEdit = fluidDeserialize(semiSerializedEdit);\n\t\treturn convertEditIds(parsedEdit, (id) => idGenerator.generateNodeId(id));\n\t}\n\n\t/**\n\t * Encodes a summary.\n\t */\n\tpublic encodeSummary(\n\t\tedits: EditLog<ChangeInternal>,\n\t\tcurrentView: RevisionView,\n\t\tidConverter: NodeIdConverter\n\t): SharedTreeSummary_0_0_2 {\n\t\tif (this.summarizeHistory) {\n\t\t\treturn this.fullHistorySummarizer(edits, currentView, idConverter);\n\t\t} else {\n\t\t\treturn this.noHistorySummarizer(edits, currentView, idConverter);\n\t\t}\n\t}\n\n\t/**\n\t * Decodes an encoded summary.\n\t */\n\tpublic decodeSummary(\n\t\t{ currentTree, sequencedEdits }: SharedTreeSummary_0_0_2,\n\t\tattributionId?: AttributionId\n\t): SummaryContents {\n\t\tassert(sequencedEdits !== undefined, '0.0.2 summary encountered with missing sequencedEdits field.');\n\t\tconst idCompressor = new IdCompressor(createSessionId(), reservedIdCount, attributionId);\n\t\tconst idGenerator = getNodeIdContext(idCompressor);\n\t\tconst generateId = (id) => idGenerator.generateNodeId(id);\n\n\t\t// This saves all of the edits in the summary as part of the first chunk.\n\t\tconst temporaryLog = new EditLog<ChangeInternal>();\n\t\tsequencedEdits.forEach((edit) =>\n\t\t\ttemporaryLog.addSequencedEdit(convertEditIds(edit, generateId), {\n\t\t\t\tsequenceNumber: 1,\n\t\t\t\treferenceSequenceNumber: 0,\n\t\t\t})\n\t\t);\n\n\t\treturn {\n\t\t\tcurrentTree: convertTreeNodes<ChangeNode_0_0_2, ChangeNode>(currentTree, (node) =>\n\t\t\t\tconvertNodeDataIds(node, generateId)\n\t\t\t),\n\t\t\tidCompressor,\n\t\t\tinterner: new MutableStringInterner(),\n\t\t\t// This cast is valid because we just constructed this log and gave it only in-session edits.\n\t\t\teditHistory: temporaryLog.getEditLogSummary() as EditLogSummary<ChangeInternal, never>,\n\t\t};\n\t}\n\n\t/**\n\t * Does not preserve (persist) history at all.\n\t * Instead, the history returned in the summary will contain a single edit that creates a revision identical to the supplied view.\n\t * @param stable - Generates the single edit with a stable edit ID. False by default, used for testing.\n\t */\n\tprivate noHistorySummarizer<TChange>(\n\t\t_edits: EditLog<TChange>,\n\t\tcurrentView: RevisionView,\n\t\tidConverter: NodeIdConverter\n\t): SharedTreeSummary_0_0_2 {\n\t\tconst currentTree = getChangeNode_0_0_2FromView(currentView, idConverter);\n\t\tconst changes: ChangeInternal_0_0_2[] = [];\n\t\t// Generate a set of changes to set the root node's children to that of the root in the currentTree\n\t\tObject.entries(currentTree.traits).forEach(([label, children]) => {\n\t\t\tconst id = 0 as DetachedSequenceId;\n\t\t\tchanges.push(\n\t\t\t\t{ type: ChangeTypeInternal.Build, source: children, destination: id },\n\t\t\t\t{\n\t\t\t\t\ttype: ChangeTypeInternal.Insert,\n\t\t\t\t\tsource: id,\n\t\t\t\t\tdestination: {\n\t\t\t\t\t\tside: Side.After,\n\t\t\t\t\t\treferenceTrait: { label: label as TraitLabel, parent: initialTree.identifier },\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t);\n\t\t});\n\n\t\tif (currentTree.payload !== undefined) {\n\t\t\tchanges.push({\n\t\t\t\ttype: ChangeTypeInternal.SetValue,\n\t\t\t\tnodeToModify: initialTree.identifier,\n\t\t\t\tpayload: currentTree.payload,\n\t\t\t});\n\t\t}\n\n\t\tassert(\n\t\t\tcurrentTree.identifier === initialTree.identifier && currentTree.definition === initialTree.definition,\n\t\t\t'root definition and identifier should be immutable.'\n\t\t);\n\t\tconst edit = newEdit(changes);\n\n\t\treturn {\n\t\t\tcurrentTree,\n\t\t\tsequencedEdits: [\n\t\t\t\t{\n\t\t\t\t\tid: edit.id,\n\t\t\t\t\tchanges: edit.changes,\n\t\t\t\t},\n\t\t\t],\n\t\t\tversion: WriteFormat.v0_0_2,\n\t\t};\n\t}\n\t/**\n\t * Preserves the full history in the generated summary.\n\t */\n\tprivate fullHistorySummarizer(\n\t\tedits: EditLog<ChangeInternal>,\n\t\tcurrentView: RevisionView,\n\t\tidConverter: NodeIdConverter\n\t): SharedTreeSummary_0_0_2 {\n\t\tconst { editChunks, editIds } = edits.getEditLogSummary();\n\n\t\tconst sequencedEdits: Edit<ChangeInternal_0_0_2>[] = [];\n\t\tlet idIndex = 0;\n\t\teditChunks.forEach(({ chunk }) => {\n\t\t\tif (isEditHandle(chunk)) {\n\t\t\t\tfail('Cannot write handles to summary version 0.0.2');\n\t\t\t} else {\n\t\t\t\tchunk.forEach(({ changes }) => {\n\t\t\t\t\tsequencedEdits.push(\n\t\t\t\t\t\tconvertEditIds(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tchanges,\n\t\t\t\t\t\t\t\tid: editIds[idIndex++] ?? fail('Number of edits should match number of edit IDs.'),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t(id) => idConverter.convertToStableNodeId(id)\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\treturn {\n\t\t\tcurrentTree: getChangeNode_0_0_2FromView(currentView, idConverter),\n\t\t\tsequencedEdits,\n\t\t\tversion: WriteFormat.v0_0_2,\n\t\t};\n\t}\n}\n\nfunction isEditHandle(chunk: FluidEditHandle | readonly EditWithoutId<unknown>[]): chunk is FluidEditHandle {\n\treturn !Array.isArray(chunk);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringInterner.js","sourceRoot":"","sources":["../src/StringInterner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAYhC;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IAIjC;;;OAGG;IACH,YAAY,eAAkC,EAAE;QAP/B,0BAAqB,GAAG,IAAI,GAAG,EAA4B,CAAC;QAC5D,oBAAe,GAAa,EAAE,CAAC;QAO/C,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE;YACjC,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;SAClC;IACF,CAAC;IAED;;;OAGG;IACI,qBAAqB,CAAC,KAAa;;QACzC,
|
|
1
|
+
{"version":3,"file":"StringInterner.js","sourceRoot":"","sources":["../src/StringInterner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAYhC;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IAIjC;;;OAGG;IACH,YAAY,eAAkC,EAAE;QAP/B,0BAAqB,GAAG,IAAI,GAAG,EAA4B,CAAC;QAC5D,oBAAe,GAAa,EAAE,CAAC;QAO/C,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE;YACjC,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;SAClC;IACF,CAAC;IAED;;;OAGG;IACI,qBAAqB,CAAC,KAAa;;QACzC,OAAO,MAAA,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,mCAAI,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC7D,CAAC;IAEM,aAAa,CAAC,KAAa;QACjC,OAAO,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,QAAgB;;QAChC,OAAO,MAAA,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,mCAAI,IAAI,CAAC,6BAA6B,QAAQ,GAAG,CAAC,CAAC;IACzF,CAAC;IAED;;OAEG;IACI,eAAe;QACrB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC7B,CAAC;IAED,+GAA+G;IACvG,WAAW,CAAC,KAAa;QAChC,MAAM,UAAU,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAwB,CAAC;QACvE,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAClD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjC,OAAO,UAAU,CAAC;IACnB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { fail } from './Common';\nimport type { InternedStringId } from './Identifiers';\n\n/**\n * Interns strings as integers.\n */\nexport interface StringInterner {\n\tgetInternedId(input: string): InternedStringId | undefined;\n\tgetString(internedId: number): string;\n\tgetSerializable(): readonly string[];\n}\n\n/**\n * Interns strings as integers.\n * Given a string, this class will produce a unique integer associated with that string that can then be used to retrieve the string.\n */\nexport class MutableStringInterner implements StringInterner {\n\tprivate readonly stringToInternedIdMap = new Map<string, InternedStringId>();\n\tprivate readonly internedStrings: string[] = [];\n\n\t/**\n\t * @param inputStrings - A list of strings to intern in the order given. Can be used to rehydrate from a previous\n\t * `StringInterner`'s {@link StringInterner.getSerializable} return value.\n\t */\n\tconstructor(inputStrings: readonly string[] = []) {\n\t\tfor (const value of inputStrings) {\n\t\t\tthis.getOrCreateInternedId(value);\n\t\t}\n\t}\n\n\t/**\n\t * @param input - The string to get the associated intern ID for\n\t * @returns an intern ID that is uniquely associated with the input string\n\t */\n\tpublic getOrCreateInternedId(input: string): InternedStringId {\n\t\treturn this.getInternedId(input) ?? this.createNewId(input);\n\t}\n\n\tpublic getInternedId(input: string): InternedStringId | undefined {\n\t\treturn this.stringToInternedIdMap.get(input);\n\t}\n\n\t/**\n\t *\n\t * @param internId - The intern ID to get the associated string for. Can only retrieve strings that have been used as inputs to\n\t * calls of `getInternId`.\n\t * @returns a string that is uniquely associated with the given intern ID\n\t */\n\tpublic getString(internId: number): string {\n\t\treturn this.internedStrings[internId] ?? fail(`No string associated with ${internId}.`);\n\t}\n\n\t/**\n\t * @returns the list of strings interned where the indices map to the associated {@link InternedStringId} of each string\n\t */\n\tpublic getSerializable(): readonly string[] {\n\t\treturn this.internedStrings;\n\t}\n\n\t/** Create a new interned id. Assumes without validation that the input doesn't already have an interned id. */\n\tprivate createNewId(input: string): InternedStringId {\n\t\tconst internedId = this.stringToInternedIdMap.size as InternedStringId;\n\t\tthis.stringToInternedIdMap.set(input, internedId);\n\t\tthis.internedStrings.push(input);\n\t\treturn internedId;\n\t}\n}\n"]}
|
package/lib/Summary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Summary.js","sourceRoot":"","sources":["../src/Summary.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAoB,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACxF,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AA8BhC;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,OAA8B,EAAE,UAA4B,EAAE,IAAkB;;IACzG,
|
|
1
|
+
{"version":3,"file":"Summary.js","sourceRoot":"","sources":["../src/Summary.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAoB,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACxF,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AA8BhC;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,OAA8B,EAAE,UAA4B,EAAE,IAAkB;;IACzG,OAAO,MAAA,gBAAgB,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,mCAAI,IAAI,EAAE,CAAC;AAC9D,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidHandle } from '@fluidframework/core-interfaces';\nimport { IFluidSerializer, serializeHandles } from '@fluidframework/shared-object-base';\nimport { fail } from './Common';\nimport type { IdCompressor } from './id-compressor';\nimport type { EditLogSummary, SharedTreeSummaryBase, ChangeNode, ChangeInternal } from './persisted-types';\nimport type { EditHandle } from './EditLog';\nimport type { MutableStringInterner } from './StringInterner';\n\n/**\n * The contents of a SharedTree summary, converted to a common internal format that can be\n * loaded into a SharedTree.\n * @internal\n */\nexport interface SummaryContents {\n\treadonly currentTree?: ChangeNode;\n\n\t/**\n\t * Information that can populate an edit log.\n\t */\n\treadonly editHistory: EditLogSummary<ChangeInternal, EditHandle<ChangeInternal>>;\n\n\t/**\n\t * Information about all IDs compressed in the summary\n\t */\n\treadonly idCompressor: IdCompressor;\n\n\t/**\n\t * Interner pre-loaded with all definitions and labels from the summary.\n\t */\n\treadonly interner: MutableStringInterner;\n}\n\n/**\n * Serializes a SharedTree summary into a JSON string. This may later be used to initialize a SharedTree's state via `deserialize()`\n * Also replaces handle objects with their serialized form.\n *\n * @param summary - The SharedTree summary to serialize.\n * @param serializer - The serializer required to serialize handles in the summary.\n * @param bind - The object handle required to serialize handles in the summary\n */\nexport function serialize(summary: SharedTreeSummaryBase, serializer: IFluidSerializer, bind: IFluidHandle): string {\n\treturn serializeHandles(summary, serializer, bind) ?? fail();\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeCompressor.d.ts","sourceRoot":"","sources":["../src/TreeCompressor.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAc,kBAAkB,EAAoB,aAAa,EAAc,MAAM,eAAe,CAAC;AACjH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,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,OAAO,CAAC,UAAU,CAAC,CAAgB;IAE5B,UAAU,CAAC,GAAG,SAAS,aAAa,EAC1C,IAAI,EAAE,yBAAyB,CAAC,GAAG,EAAE,YAAY,CAAC,EAClD,QAAQ,EAAE,cAAc,EACxB,YAAY,EAAE,8BAA8B,CAAC,GAAG,CAAC,GAC/C,eAAe,CAAC,YAAY,CAAC;IAUhC,OAAO,CAAC,WAAW;CAmFnB"}
|
package/lib/TreeCompressor.js
CHANGED
|
@@ -70,14 +70,12 @@ export class InterningTreeCompressor {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
else {
|
|
73
|
-
// TODO: This cast can be removed on typescript 4.6
|
|
74
73
|
compressedTraits = idOrPayloadTraits;
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
76
|
const definition = typeof maybeInternedDefinition === 'string'
|
|
78
77
|
? maybeInternedDefinition
|
|
79
|
-
:
|
|
80
|
-
interner.getString(maybeInternedDefinition);
|
|
78
|
+
: interner.getString(maybeInternedDefinition);
|
|
81
79
|
let identifier;
|
|
82
80
|
if (compressedId !== undefined) {
|
|
83
81
|
identifier = compressedId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeCompressor.js","sourceRoot":"","sources":["../src/TreeCompressor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAKrD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAW,MAAM,UAAU,CAAC;AA6BjD;;;;;GAKG;AACH,MAAM,OAAO,uBAAuB;IAG5B,QAAQ,CACd,IAAmC,EACnC,QAAwB,EACxB,YAAiD;QAEjD,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;IACrD,CAAC;IAEO,SAAS,CAChB,IAAmC,EACnC,QAAwB,EACxB,YAAiD;;QAEjD,IAAI,oB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CAAC,CAC/C,CAAC;gBAEF,MAAM,KAAK,GACV,OAAO,oBAAoB,KAAK,QAAQ;oBACvC,CAAC,CAAC,oBAAoB;oBACtB,CAAC,CAAE,QAAQ,CAAC,SAAS,CAAC,oBAAoB,CAAgB,CAAC;gBAC7D,MAAM,CAAC,KAAK,CAAC,GAAG,kBAAkB,CAAC;aACnC;SACD;QAED,MAAM,gBAAgB,GAA2C;YAChE,UAAU,EAAE,YAAY,CAAC,uBAAuB,CAAC,UAAU,CAAC;YAC5D,UAAU;YACV,MAAM;SACN,CAAC;QAEF,IAAI,OAAO,KAAK,SAAS,EAAE;YAC1B,gBAAgB,CAAC,OAAO,GAAG,OAAO,CAAC;SACnC;QAED,OAAO,gBAAgB,CAAC;IACzB,CAAC;CACD;AAED,SAAS,UAAU,CAA4B,UAA2B,EAAE,EAAO;IAClF,IAAI,UAAU,KAAK,SAAS,EAAE;QAC7B,OAAO,KAAK,CAAC;KACb;IAED,MAAM,SAAS,GAAW,UAAU,CAAC;IACrC,IAAI,SAAS,GAAG,CAAC,EAAE;QAClB,OAAO,EAAE,KAAK,SAAS,GAAG,CAAC,CAAC;KAC5B;IAED,OAAO,EAAE,KAAK,SAAS,GAAG,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { isDetachedSequenceId } from './Identifiers';\nimport type { Definition, DetachedSequenceId, InternedStringId, OpSpaceNodeId, TraitLabel } from './Identifiers';\nimport type { StringInterner } from './StringInterner';\nimport type { CompressedTraits, CompressedPlaceholderTree, PlaceholderTree, Payload } from './persisted-types';\nimport type { ContextualizedNodeIdNormalizer } from './NodeIdUtilities';\nimport { assert, fail, Mutable } from './Common';\n\n/**\n * Compresses a given {@link PlaceholderTree} into a more compact serializable format.\n */\nexport interface TreeCompressor<TPlaceholder extends DetachedSequenceId | never> {\n\t/**\n\t * @param node - The {@link PlaceholderTree} to compress.\n\t * @param interner - The StringInterner to use to intern strings.\n\t * @param idNormalizer - A normalizer to transform node IDs into op-space\n\t */\n\tcompress<TId extends OpSpaceNodeId>(\n\t\tnode: PlaceholderTree<TPlaceholder>,\n\t\tinterner: StringInterner,\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<TId>\n\t): CompressedPlaceholderTree<TId, TPlaceholder>;\n\n\t/**\n\t * @param node - The {@link PlaceholderTree} to compress.\n\t * @param interner - The StringInterner to use to intern strings.\n\t * @param idNormalizer - A normalizer to transform node IDs into op-space\n\t */\n\tdecompress<TId extends OpSpaceNodeId>(\n\t\tnode: CompressedPlaceholderTree<TId, TPlaceholder>,\n\t\tinterner: StringInterner,\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<TId>\n\t): PlaceholderTree<TPlaceholder>;\n}\n\n/**\n * Compresses a given {@link PlaceholderTree}\n * (Such as a {@link ChangeNode} or {@link BuildNode}) into an array,\n * while also string interning all node {@link Definition}s and {@link TraitLabel}s.\n * See {@link CompressedPlaceholderTree} for format.\n */\nexport class InterningTreeCompressor<TPlaceholder extends DetachedSequenceId | never>\n\timplements TreeCompressor<TPlaceholder>\n{\n\tpublic compress<TId extends OpSpaceNodeId>(\n\t\tnode: PlaceholderTree<TPlaceholder>,\n\t\tinterner: StringInterner,\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<TId>\n\t): CompressedPlaceholderTree<TId, TPlaceholder> {\n\t\tthis.previousId = undefined;\n\t\treturn this.compressI(node, interner, idNormalizer);\n\t}\n\n\tprivate compressI<TId extends OpSpaceNodeId>(\n\t\tnode: PlaceholderTree<TPlaceholder>,\n\t\tinterner: StringInterner,\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<TId>\n\t): CompressedPlaceholderTree<TId, TPlaceholder> {\n\t\tif (isDetachedSequenceId(node)) {\n\t\t\treturn node;\n\t\t}\n\n\t\tconst internedDefinition = interner.getInternedId(node.definition) ?? node.definition;\n\t\tconst normalizedId = idNormalizer.normalizeToOpSpace(node.identifier);\n\t\tconst compressedId = canElideId(this.previousId, normalizedId) ? undefined : normalizedId;\n\t\tthis.previousId = normalizedId;\n\t\tconst compressedTraits: CompressedTraits<TId, TPlaceholder> = [];\n\n\t\t// Omit traits if empty and payload is undefined.\n\t\tconst traits = Object.entries(node.traits).sort();\n\t\tif (traits.length > 0 || node.payload !== undefined) {\n\t\t\tfor (const [label, trait] of traits) {\n\t\t\t\tcompressedTraits.push(\n\t\t\t\t\tinterner.getInternedId(label) ?? (label as TraitLabel),\n\t\t\t\t\ttrait.map((child) => this.compressI(child, interner, idNormalizer))\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst payloadTraits = node.payload !== undefined ? [node.payload, ...compressedTraits] : compressedTraits;\n\t\tif (payloadTraits.length > 0) {\n\t\t\tif (compressedId !== undefined) {\n\t\t\t\treturn [internedDefinition, compressedId, payloadTraits];\n\t\t\t}\n\t\t\treturn [internedDefinition, payloadTraits];\n\t\t}\n\n\t\tif (compressedId !== undefined) {\n\t\t\treturn [internedDefinition, compressedId];\n\t\t}\n\n\t\treturn [internedDefinition];\n\t}\n\n\t/** The ID that was compressed or decompressed most recently */\n\tprivate previousId?: OpSpaceNodeId;\n\n\tpublic decompress<TId extends OpSpaceNodeId>(\n\t\tnode: CompressedPlaceholderTree<TId, TPlaceholder>,\n\t\tinterner: StringInterner,\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<TId>\n\t): PlaceholderTree<TPlaceholder> {\n\t\tif (isDetachedSequenceId(node)) {\n\t\t\treturn node;\n\t\t}\n\t\tconst rootId = node[1];\n\t\tassert(typeof rootId === 'number', 'Root node was compressed with no ID');\n\t\tthis.previousId = rootId;\n\t\treturn this.decompressI(node, interner, idNormalizer);\n\t}\n\n\tprivate decompressI<TId extends OpSpaceNodeId>(\n\t\tnode: CompressedPlaceholderTree<TId, TPlaceholder>,\n\t\tinterner: StringInterner,\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<TId>\n\t): PlaceholderTree<TPlaceholder> {\n\t\tif (isDetachedSequenceId(node)) {\n\t\t\treturn node;\n\t\t}\n\n\t\tlet compressedId: TId | undefined;\n\t\tlet compressedTraits:\n\t\t\t| [Payload, ...CompressedTraits<TId, TPlaceholder>]\n\t\t\t| CompressedTraits<TId, TPlaceholder>\n\t\t\t| undefined;\n\t\tlet payload: Payload | undefined;\n\t\tconst [maybeInternedDefinition, idOrPayloadTraits, payloadTraits] = node;\n\t\tif (idOrPayloadTraits !== undefined) {\n\t\t\tif (typeof idOrPayloadTraits === 'number') {\n\t\t\t\tcompressedId = idOrPayloadTraits;\n\t\t\t\tif (payloadTraits !== undefined) {\n\t\t\t\t\tcompressedTraits = payloadTraits;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// TODO: This cast can be removed on typescript 4.6\n\t\t\t\tcompressedTraits = idOrPayloadTraits as typeof compressedTraits;\n\t\t\t}\n\t\t}\n\n\t\tconst definition =\n\t\t\ttypeof maybeInternedDefinition === 'string'\n\t\t\t\t? maybeInternedDefinition\n\t\t\t\t: // TODO: This cast can be removed on typescript 4.6\n\t\t\t\t (interner.getString(maybeInternedDefinition as number) as Definition);\n\n\t\tlet identifier: TId;\n\t\tif (compressedId !== undefined) {\n\t\t\tidentifier = compressedId;\n\t\t} else {\n\t\t\tconst prevId = this.previousId ?? fail();\n\t\t\tidentifier = prevId < 0 ? ((prevId - 1) as TId) : (((prevId as number) + 1) as TId);\n\t\t}\n\t\tthis.previousId = identifier;\n\n\t\tconst traits = {};\n\t\tif (compressedTraits !== undefined) {\n\t\t\tlet offset: number;\n\t\t\tif (compressedTraits.length % 2 === 1) {\n\t\t\t\toffset = 1;\n\t\t\t\tpayload = compressedTraits[0];\n\t\t\t} else {\n\t\t\t\toffset = 0;\n\t\t\t}\n\t\t\tconst traitsLength = compressedTraits.length - offset;\n\t\t\tfor (let i = 0; i < traitsLength; i += 2) {\n\t\t\t\tconst offsetIndex = i + offset;\n\t\t\t\tconst maybeCompressedLabel = compressedTraits[offsetIndex] as InternedStringId;\n\t\t\t\tconst compressedChildren = compressedTraits[offsetIndex + 1] as (\n\t\t\t\t\t| TPlaceholder\n\t\t\t\t\t| CompressedPlaceholderTree<TId, TPlaceholder>\n\t\t\t\t)[];\n\n\t\t\t\tconst decompressedTraits = compressedChildren.map((child) =>\n\t\t\t\t\tthis.decompressI(child, interner, idNormalizer)\n\t\t\t\t);\n\n\t\t\t\tconst label =\n\t\t\t\t\ttypeof maybeCompressedLabel === 'string'\n\t\t\t\t\t\t? maybeCompressedLabel\n\t\t\t\t\t\t: (interner.getString(maybeCompressedLabel) as TraitLabel);\n\t\t\t\ttraits[label] = decompressedTraits;\n\t\t\t}\n\t\t}\n\n\t\tconst decompressedNode: Mutable<PlaceholderTree<TPlaceholder>> = {\n\t\t\tidentifier: idNormalizer.normalizeToSessionSpace(identifier),\n\t\t\tdefinition,\n\t\t\ttraits,\n\t\t};\n\n\t\tif (payload !== undefined) {\n\t\t\tdecompressedNode.payload = payload;\n\t\t}\n\n\t\treturn decompressedNode;\n\t}\n}\n\nfunction canElideId<TId extends OpSpaceNodeId>(previousId: TId | undefined, id: TId): boolean {\n\tif (previousId === undefined) {\n\t\treturn false;\n\t}\n\n\tconst numericId: number = previousId;\n\tif (numericId < 0) {\n\t\treturn id === numericId - 1;\n\t}\n\n\treturn id === numericId + 1;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeCompressor.js","sourceRoot":"","sources":["../src/TreeCompressor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAKrD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAW,MAAM,UAAU,CAAC;AA6BjD;;;;;GAKG;AACH,MAAM,OAAO,uBAAuB;IAG5B,QAAQ,CACd,IAAmC,EACnC,QAAwB,EACxB,YAAiD;QAEjD,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,CAA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,EAAE,EAAE,CAC3D,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,YAAY,CAAC,CAC/C,CAAC;gBAEF,MAAM,KAAK,GACV,OAAO,oBAAoB,KAAK,QAAQ;oBACvC,CAAC,CAAC,oBAAoB;oBACtB,CAAC,CAAE,QAAQ,CAAC,SAAS,CAAC,oBAAoB,CAAgB,CAAC;gBAC7D,MAAM,CAAC,KAAK,CAAC,GAAG,kBAAkB,CAAC;aACnC;SACD;QAED,MAAM,gBAAgB,GAA2C;YAChE,UAAU,EAAE,YAAY,CAAC,uBAAuB,CAAC,UAAU,CAAC;YAC5D,UAAU;YACV,MAAM;SACN,CAAC;QAEF,IAAI,OAAO,KAAK,SAAS,EAAE;YAC1B,gBAAgB,CAAC,OAAO,GAAG,OAAO,CAAC;SACnC;QAED,OAAO,gBAAgB,CAAC;IACzB,CAAC;CACD;AAED,SAAS,UAAU,CAA4B,UAA2B,EAAE,EAAO;IAClF,IAAI,UAAU,KAAK,SAAS,EAAE;QAC7B,OAAO,KAAK,CAAC;KACb;IAED,MAAM,SAAS,GAAW,UAAU,CAAC;IACrC,IAAI,SAAS,GAAG,CAAC,EAAE;QAClB,OAAO,EAAE,KAAK,SAAS,GAAG,CAAC,CAAC;KAC5B;IAED,OAAO,EAAE,KAAK,SAAS,GAAG,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { isDetachedSequenceId } from './Identifiers';\nimport type { Definition, DetachedSequenceId, InternedStringId, OpSpaceNodeId, TraitLabel } from './Identifiers';\nimport type { StringInterner } from './StringInterner';\nimport type { CompressedTraits, CompressedPlaceholderTree, PlaceholderTree, Payload } from './persisted-types';\nimport type { ContextualizedNodeIdNormalizer } from './NodeIdUtilities';\nimport { assert, fail, Mutable } from './Common';\n\n/**\n * Compresses a given {@link PlaceholderTree} into a more compact serializable format.\n */\nexport interface TreeCompressor<TPlaceholder extends DetachedSequenceId | never> {\n\t/**\n\t * @param node - The {@link PlaceholderTree} to compress.\n\t * @param interner - The StringInterner to use to intern strings.\n\t * @param idNormalizer - A normalizer to transform node IDs into op-space\n\t */\n\tcompress<TId extends OpSpaceNodeId>(\n\t\tnode: PlaceholderTree<TPlaceholder>,\n\t\tinterner: StringInterner,\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<TId>\n\t): CompressedPlaceholderTree<TId, TPlaceholder>;\n\n\t/**\n\t * @param node - The {@link PlaceholderTree} to compress.\n\t * @param interner - The StringInterner to use to intern strings.\n\t * @param idNormalizer - A normalizer to transform node IDs into op-space\n\t */\n\tdecompress<TId extends OpSpaceNodeId>(\n\t\tnode: CompressedPlaceholderTree<TId, TPlaceholder>,\n\t\tinterner: StringInterner,\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<TId>\n\t): PlaceholderTree<TPlaceholder>;\n}\n\n/**\n * Compresses a given {@link PlaceholderTree}\n * (Such as a {@link ChangeNode} or {@link BuildNode}) into an array,\n * while also string interning all node {@link Definition}s and {@link TraitLabel}s.\n * See {@link CompressedPlaceholderTree} for format.\n */\nexport class InterningTreeCompressor<TPlaceholder extends DetachedSequenceId | never>\n\timplements TreeCompressor<TPlaceholder>\n{\n\tpublic compress<TId extends OpSpaceNodeId>(\n\t\tnode: PlaceholderTree<TPlaceholder>,\n\t\tinterner: StringInterner,\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<TId>\n\t): CompressedPlaceholderTree<TId, TPlaceholder> {\n\t\tthis.previousId = undefined;\n\t\treturn this.compressI(node, interner, idNormalizer);\n\t}\n\n\tprivate compressI<TId extends OpSpaceNodeId>(\n\t\tnode: PlaceholderTree<TPlaceholder>,\n\t\tinterner: StringInterner,\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<TId>\n\t): CompressedPlaceholderTree<TId, TPlaceholder> {\n\t\tif (isDetachedSequenceId(node)) {\n\t\t\treturn node;\n\t\t}\n\n\t\tconst internedDefinition = interner.getInternedId(node.definition) ?? node.definition;\n\t\tconst normalizedId = idNormalizer.normalizeToOpSpace(node.identifier);\n\t\tconst compressedId = canElideId(this.previousId, normalizedId) ? undefined : normalizedId;\n\t\tthis.previousId = normalizedId;\n\t\tconst compressedTraits: CompressedTraits<TId, TPlaceholder> = [];\n\n\t\t// Omit traits if empty and payload is undefined.\n\t\tconst traits = Object.entries(node.traits).sort();\n\t\tif (traits.length > 0 || node.payload !== undefined) {\n\t\t\tfor (const [label, trait] of traits) {\n\t\t\t\tcompressedTraits.push(\n\t\t\t\t\tinterner.getInternedId(label) ?? (label as TraitLabel),\n\t\t\t\t\ttrait.map((child) => this.compressI(child, interner, idNormalizer))\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst payloadTraits = node.payload !== undefined ? [node.payload, ...compressedTraits] : compressedTraits;\n\t\tif (payloadTraits.length > 0) {\n\t\t\tif (compressedId !== undefined) {\n\t\t\t\treturn [internedDefinition, compressedId, payloadTraits];\n\t\t\t}\n\t\t\treturn [internedDefinition, payloadTraits];\n\t\t}\n\n\t\tif (compressedId !== undefined) {\n\t\t\treturn [internedDefinition, compressedId];\n\t\t}\n\n\t\treturn [internedDefinition];\n\t}\n\n\t/** The ID that was compressed or decompressed most recently */\n\tprivate previousId?: OpSpaceNodeId;\n\n\tpublic decompress<TId extends OpSpaceNodeId>(\n\t\tnode: CompressedPlaceholderTree<TId, TPlaceholder>,\n\t\tinterner: StringInterner,\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<TId>\n\t): PlaceholderTree<TPlaceholder> {\n\t\tif (isDetachedSequenceId(node)) {\n\t\t\treturn node;\n\t\t}\n\t\tconst rootId = node[1];\n\t\tassert(typeof rootId === 'number', 'Root node was compressed with no ID');\n\t\tthis.previousId = rootId;\n\t\treturn this.decompressI(node, interner, idNormalizer);\n\t}\n\n\tprivate decompressI<TId extends OpSpaceNodeId>(\n\t\tnode: CompressedPlaceholderTree<TId, TPlaceholder>,\n\t\tinterner: StringInterner,\n\t\tidNormalizer: ContextualizedNodeIdNormalizer<TId>\n\t): PlaceholderTree<TPlaceholder> {\n\t\tif (isDetachedSequenceId(node)) {\n\t\t\treturn node;\n\t\t}\n\n\t\tlet compressedId: TId | undefined;\n\t\tlet compressedTraits:\n\t\t\t| [Payload, ...CompressedTraits<TId, TPlaceholder>]\n\t\t\t| CompressedTraits<TId, TPlaceholder>\n\t\t\t| undefined;\n\t\tlet payload: Payload | undefined;\n\t\tconst [maybeInternedDefinition, idOrPayloadTraits, payloadTraits] = node;\n\t\tif (idOrPayloadTraits !== undefined) {\n\t\t\tif (typeof idOrPayloadTraits === 'number') {\n\t\t\t\tcompressedId = idOrPayloadTraits;\n\t\t\t\tif (payloadTraits !== undefined) {\n\t\t\t\t\tcompressedTraits = payloadTraits;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcompressedTraits = idOrPayloadTraits;\n\t\t\t}\n\t\t}\n\n\t\tconst definition =\n\t\t\ttypeof maybeInternedDefinition === 'string'\n\t\t\t\t? maybeInternedDefinition\n\t\t\t\t: (interner.getString(maybeInternedDefinition) as Definition);\n\n\t\tlet identifier: TId;\n\t\tif (compressedId !== undefined) {\n\t\t\tidentifier = compressedId;\n\t\t} else {\n\t\t\tconst prevId = this.previousId ?? fail();\n\t\t\tidentifier = prevId < 0 ? ((prevId - 1) as TId) : (((prevId as number) + 1) as TId);\n\t\t}\n\t\tthis.previousId = identifier;\n\n\t\tconst traits = {};\n\t\tif (compressedTraits !== undefined) {\n\t\t\tlet offset: number;\n\t\t\tif (compressedTraits.length % 2 === 1) {\n\t\t\t\toffset = 1;\n\t\t\t\tpayload = compressedTraits[0];\n\t\t\t} else {\n\t\t\t\toffset = 0;\n\t\t\t}\n\t\t\tconst traitsLength = compressedTraits.length - offset;\n\t\t\tfor (let i = 0; i < traitsLength; i += 2) {\n\t\t\t\tconst offsetIndex = i + offset;\n\t\t\t\tconst maybeCompressedLabel = compressedTraits[offsetIndex] as InternedStringId;\n\t\t\t\tconst compressedChildren = compressedTraits[offsetIndex + 1] as (\n\t\t\t\t\t| TPlaceholder\n\t\t\t\t\t| CompressedPlaceholderTree<TId, TPlaceholder>\n\t\t\t\t)[];\n\n\t\t\t\tconst decompressedTraits = compressedChildren.map((child) =>\n\t\t\t\t\tthis.decompressI(child, interner, idNormalizer)\n\t\t\t\t);\n\n\t\t\t\tconst label =\n\t\t\t\t\ttypeof maybeCompressedLabel === 'string'\n\t\t\t\t\t\t? maybeCompressedLabel\n\t\t\t\t\t\t: (interner.getString(maybeCompressedLabel) as TraitLabel);\n\t\t\t\ttraits[label] = decompressedTraits;\n\t\t\t}\n\t\t}\n\n\t\tconst decompressedNode: Mutable<PlaceholderTree<TPlaceholder>> = {\n\t\t\tidentifier: idNormalizer.normalizeToSessionSpace(identifier),\n\t\t\tdefinition,\n\t\t\ttraits,\n\t\t};\n\n\t\tif (payload !== undefined) {\n\t\t\tdecompressedNode.payload = payload;\n\t\t}\n\n\t\treturn decompressedNode;\n\t}\n}\n\nfunction canElideId<TId extends OpSpaceNodeId>(previousId: TId | undefined, id: TId): boolean {\n\tif (previousId === undefined) {\n\t\treturn false;\n\t}\n\n\tconst numericId: number = previousId;\n\tif (numericId < 0) {\n\t\treturn id === numericId - 1;\n\t}\n\n\treturn id === numericId + 1;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeHandle.js","sourceRoot":"","sources":["../src/TreeNodeHandle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAI/C;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IAI1B,6FAA6F;IAC7F,YAAmB,IAAc,EAAE,MAAc;;QAChD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"TreeNodeHandle.js","sourceRoot":"","sources":["../src/TreeNodeHandle.ts"],"names":[],"mappings":"A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AED;;OAEG;IACH,IAAW,IAAI;QACd,OAAO,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnD,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Definition, NodeId } from './Identifiers';\nimport { fail, memoizeGetter } from './Common';\nimport { Payload, TraitMap, TreeNode } from './persisted-types';\nimport { TreeView, TreeViewNode } from './TreeView';\n\n/**\n * A handle to a `TreeNode` that exists within a specific `TreeView`. This type provides a convenient\n * API for traversing trees of nodes in a TreeView and is not designed to provide maximum runtime\n * performance; if performance is a concern, consider using the TreeView and TreeViewNode APIs directly.\n * @public\n */\nexport class TreeNodeHandle implements TreeNode<TreeNodeHandle, NodeId> {\n\tprivate readonly view: TreeView;\n\tprivate readonly viewNode: TreeViewNode;\n\n\t/** Construct a handle which references the node with the given id in the given `TreeView` */\n\tpublic constructor(view: TreeView, nodeId: NodeId) {\n\t\tthis.view = view;\n\t\tthis.viewNode = view.tryGetViewNode(nodeId) ?? fail('Failed to create handle: node is not present in view');\n\t}\n\n\tpublic get payload(): Payload | undefined {\n\t\treturn this.node.payload;\n\t}\n\n\tpublic get definition(): Definition {\n\t\treturn this.node.definition;\n\t}\n\n\tpublic get identifier(): NodeId {\n\t\treturn this.node.identifier;\n\t}\n\n\tpublic get traits(): TraitMap<TreeNodeHandle> {\n\t\t// Construct a new trait map that wraps each node in each trait in a handle\n\t\tconst traitMap: TraitMap<TreeNodeHandle> = {};\n\t\tconst { view } = this;\n\t\tfor (const [label, trait] of this.node.traits.entries()) {\n\t\t\tObject.defineProperty(traitMap, label, {\n\t\t\t\tget() {\n\t\t\t\t\tconst handleTrait = trait.map((node) => new TreeNodeHandle(view, node));\n\t\t\t\t\treturn memoizeGetter(this as TraitMap<TreeNodeHandle>, label, handleTrait);\n\t\t\t\t},\n\t\t\t\tconfigurable: true,\n\t\t\t\tenumerable: true,\n\t\t\t});\n\t\t}\n\n\t\treturn memoizeGetter(this, 'traits', traitMap);\n\t}\n\n\t/**\n\t * Get a `TreeViewNode` for the tree view node that this handle references\n\t */\n\tpublic get node(): TreeViewNode {\n\t\treturn memoizeGetter(this, 'node', this.viewNode);\n\t}\n}\n"]}
|
package/lib/TreeView.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeView.js","sourceRoot":"","sources":["../src/TreeView.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAE/D,OAAO,EAAiB,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAY,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAsEnD;;;GAGG;AACH,MAAM,OAAgB,QAAQ;IAY7B,YAAsB,IAAY,EAAE,MAAc;QACjD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED,gDAAgD;IAChD,IAAW,IAAI;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IACzB,CAAC;IAED,qEAAqE;IAC9D,OAAO,CAAC,EAAU;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACI,oBAAoB,CAAC,KAAoB;QAC/C,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE;YAChC,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;SACpD;QACD,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,C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AO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;CACD;AAED,SAAS,QAAQ,CAAC,IAAU,EAAE,KAAqB;IAClD,qEAAqE;IACrE,OAAO,CAAC,IAAI,GAAG,KAAK,CAAe,CAAC;AACrC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, copyPropertyIfDefined, fail } from './Common';\nimport { NodeId, TraitLabel } from './Identifiers';\nimport { Delta, Forest, isParentedForestNode } from './Forest';\nimport { NodeData, Side } from './persisted-types';\n\n/**\n * Specifies the location of a trait (a labeled sequence of nodes) within the tree.\n * @public\n */\nexport interface TraitLocation {\n\treadonly parent: NodeId;\n\treadonly label: TraitLabel;\n}\n\n/**\n * An immutable view of a distributed tree node.\n * @public\n */\nexport interface TreeViewNode extends NodeData<NodeId> {\n\t/** The IDs of the children under this node */\n\treadonly traits: ReadonlyMap<TraitLabel, readonly NodeId[]>;\n\t/** The parent and trait under which this node resides. Undefined iff this is the root node of the tree (i.e. {@link initialTree}). */\n\treadonly parentage?: TraitLocation;\n}\n\n/**\n * Index of a place within a trait.\n * 0 = before all nodes,\n * 1 = after first node,\n * etc.\n * @public\n */\nexport type PlaceIndex = number & { readonly PlaceIndex: unique symbol };\n\n/**\n * Index of a node within a trait.\n * 0 = first node,\n * 1 = second node,\n * etc.\n * @public\n */\nexport type TraitNodeIndex = number & { readonly TraitNodeIndex: unique symbol };\n\n/**\n * A place within a particular `TreeView` that is anchored relative to a specific node in the tree, or relative to the outside of the trait.\n * Valid iff 'trait' is valid and, if provided, sibling is in the Location specified by 'trait'.\n * @public\n */\nexport interface TreeViewPlace {\n\treadonly sibling?: NodeId;\n\treadonly side: Side;\n\treadonly trait: TraitLocation;\n}\n\n/**\n * Specifies the range of nodes from `start` to `end` within a trait within a particular `TreeView`.\n * Valid iff start and end are valid and are within the same trait.\n * @public\n */\nexport interface TreeViewRange {\n\treadonly start: TreeViewPlace;\n\treadonly end: TreeViewPlace;\n}\n\n/**\n * Contains some redundant information. Use only in computations between edits. Do not store.\n * @public\n */\nexport interface NodeInTrait {\n\treadonly trait: TraitLocation;\n\treadonly index: TraitNodeIndex;\n}\n\n/**\n * A view of a distributed tree.\n * @public\n */\nexport abstract class TreeView {\n\tpublic readonly root: NodeId;\n\tprotected readonly forest: Forest;\n\tprivate readonly rootNode: TreeViewNode;\n\n\t/**\n\t * A cache of node's index within their parent trait.\n\t * Used to avoid redundant linear scans of traits.\n\t * Not shared across views; initialized to empty each time a TreeView is created.\n\t */\n\tprivate traitIndicesCache?: Map<NodeId, TraitNodeIndex>;\n\n\tprotected constructor(root: NodeId, forest: Forest) {\n\t\tthis.root = root;\n\t\tthis.forest = forest;\n\t\tthis.rootNode = this.getViewNode(root);\n\t}\n\n\t/** @returns the number of nodes in this view */\n\tpublic get size(): number {\n\t\treturn this.forest.size;\n\t}\n\n\t/** @returns true iff a node with the given id exists in this view */\n\tpublic hasNode(id: NodeId): boolean {\n\t\treturn this.forest.has(id);\n\t}\n\n\t/**\n\t * @returns the index just after place (which specifies a location between items).\n\t * Performance note: this is O(siblings in trait).\n\t */\n\tpublic findIndexWithinTrait(place: TreeViewPlace): PlaceIndex {\n\t\tif (place.sibling === undefined) {\n\t\t\treturn this.getIndexOfSide(place.side, place.trait);\n\t\t}\n\t\treturn getIndex(place.side, this.getIndexInTrait(place.sibling));\n\t}\n\n\t/** @returns the node associated with the given id in this view. Fails if the node does not exist in this view. */\n\tpublic getViewNode(id: NodeId): TreeViewNode {\n\t\treturn this.tryGetViewNode(id) ?? fail('NodeId not found');\n\t}\n\n\t/** @returns the node associated with the given id in this view, or undefined if the node does not exist in this view */\n\tpublic tryGetViewNode(id: NodeId): TreeViewNode | undefined {\n\t\tconst forestNode = this.forest.tryGet(id);\n\t\tif (forestNode !== undefined && isParentedForestNode(forestNode)) {\n\t\t\tconst viewNode: TreeViewNode = {\n\t\t\t\tdefinition: forestNode.definition,\n\t\t\t\tidentifier: forestNode.identifier,\n\t\t\t\ttraits: forestNode.traits,\n\t\t\t\tparentage: {\n\t\t\t\t\tlabel: forestNode.traitParent,\n\t\t\t\t\tparent: forestNode.parentId,\n\t\t\t\t},\n\t\t\t};\n\t\t\tcopyPropertyIfDefined(forestNode, viewNode, 'payload');\n\t\t\treturn viewNode;\n\t\t}\n\n\t\treturn forestNode;\n\t}\n\n\t/**\n\t * @returns the label of the trait under which a node with the given id resides. Fails if the node does not exist in this view or if\n\t * it is the root node.\n\t */\n\tpublic getTraitLabel(id: NodeId): TraitLabel {\n\t\treturn this.forest.getParent(id).traitParent;\n\t}\n\n\t/**\n\t * @returns the label of the trait under which a node with the given id resides, or undefined if the node is not present in this\n\t * view or if it is the root node\n\t */\n\tpublic tryGetTraitLabel(id: NodeId): TraitLabel | undefined {\n\t\treturn this.forest.tryGetParent(id)?.traitParent;\n\t}\n\n\t/**\n\t * @returns the parent of the node with the given id. Fails if the node does not exist in this view or if it is the root node.\n\t */\n\tpublic getParentViewNode(id: NodeId): TreeViewNode {\n\t\tconst parentInfo = this.forest.getParent(id);\n\t\treturn this.getViewNode(parentInfo.parentId);\n\t}\n\n\t/**\n\t * @returns the parent of the node with the given id. Returns undefined if the node does not exist in this view or if it is the root\n\t * node.\n\t */\n\tpublic tryGetParentViewNode(id: NodeId): TreeViewNode | undefined {\n\t\tconst parentInfo = this.forest.tryGetParent(id);\n\t\tif (parentInfo === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.getViewNode(parentInfo.parentId);\n\t}\n\n\t/**\n\t * @returns the trait location of the node with the given id. Fails if the node does not exist in this view or of it is the root\n\t * node\n\t */\n\tpublic getTraitLocation(id: NodeId): TraitLocation {\n\t\tconst parentData = this.forest.getParent(id);\n\t\treturn {\n\t\t\tparent: parentData.parentId,\n\t\t\tlabel: parentData.traitParent,\n\t\t};\n\t}\n\n\t/**\n\t * @returns the trait location of the node with the given id, or undefined if the node does not exist in this view or if it is the root\n\t * node\n\t */\n\tpublic tryGetTraitLocation(id: NodeId): TraitLocation | undefined {\n\t\tconst parentData = this.forest.tryGetParent(id);\n\t\tif (parentData === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tparent: parentData.parentId,\n\t\t\tlabel: parentData.traitParent,\n\t\t};\n\t}\n\n\t/**\n\t * @returns the index within the trait under which the node with the given id resides. The node must exist in this view and must have a\n\t * parent.\n\t * Performance note: this is O(siblings in trait).\n\t */\n\tpublic getIndexInTrait(id: NodeId): TraitNodeIndex {\n\t\tconst index = this.tryGetIndexInTrait(id);\n\t\treturn index ?? fail('ID does not exist in the forest.');\n\t}\n\n\t/**\n\t * @returns the index within the trait under which the node with the given id resides, or undefined if the node does not exist in this\n\t * view or does not have a parent.\n\t * Performance note: this is O(siblings in trait).\n\t */\n\tpublic tryGetIndexInTrait(id: NodeId): TraitNodeIndex | undefined {\n\t\tconst cachedIndex = this.traitIndicesCache?.get(id);\n\t\tif (cachedIndex !== undefined) {\n\t\t\treturn cachedIndex;\n\t\t}\n\n\t\tconst parentData = this.forest.tryGetParent(id);\n\t\tif (parentData === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst parent = this.forest.tryGet(parentData.parentId);\n\t\tif (parent === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst trait = parent.traits.get(parentData.traitParent) ?? fail('inconsistent forest: trait parent not found');\n\t\tlet foundIndex: TraitNodeIndex | undefined;\n\t\tif (trait.length === 0) {\n\t\t\treturn foundIndex;\n\t\t}\n\n\t\tthis.traitIndicesCache ??= new Map();\n\t\tfor (let i = 0; i < trait.length; i++) {\n\t\t\tconst nodeInTrait = trait[i];\n\t\t\tconst index = i as TraitNodeIndex;\n\t\t\tthis.traitIndicesCache.set(nodeInTrait, index);\n\t\t\tif (nodeInTrait === id) {\n\t\t\t\tfoundIndex = index;\n\t\t\t}\n\t\t}\n\n\t\treturn foundIndex;\n\t}\n\n\t/**\n\t * @returns the trait at the given location. If no such trait exists, returns an empty trait.\n\t */\n\tpublic getTrait(traitLocation: TraitLocation): readonly NodeId[] {\n\t\treturn this.getViewNode(traitLocation.parent).traits.get(traitLocation.label) ?? [];\n\t}\n\n\t/** Asserts that the view's internal state is consistent. Useful for testing/validation. */\n\tpublic assertConsistent(): void {\n\t\tthis.forest.assertConsistent();\n\t}\n\n\tpublic [Symbol.iterator](): IterableIterator<TreeViewNode> {\n\t\treturn this.iterateNodeDescendants(this.rootNode);\n\t}\n\n\t/** @returns true iff the given view is equal to this view */\n\tpublic abstract equals(view: TreeView): boolean;\n\n\t/**\n\t * @returns true iff the given view's forest of nodes is equivalent to this view's forest of nodes\n\t * @param strict - if true, the views' forests must be the same object, otherwise they must merely be equivalent\n\t */\n\tpublic hasEqualForest(view: TreeView, strict = false): boolean {\n\t\tif (this.root === view.root) {\n\t\t\t// TODO:#49100:Perf: make this faster and/or remove use by PrefetchingCheckout.\n\t\t\treturn strict ? this.forest === view.forest : this.forest.equals(view.forest);\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tprivate *iterateNodeDescendants(node: TreeViewNode): IterableIterator<TreeViewNode> {\n\t\tyield node;\n\t\tfor (const label of [...node.traits.keys()].sort()) {\n\t\t\tconst trait = node.traits.get(label);\n\t\t\tfor (const childId of trait ?? fail('Expected trait with label')) {\n\t\t\t\tconst child = this.getViewNode(childId);\n\t\t\t\tyield* this.iterateNodeDescendants(child);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getIndexOfSide(side: Side, traitLocation: TraitLocation): PlaceIndex {\n\t\treturn side === Side.After ? (0 as PlaceIndex) : (this.getTrait(traitLocation).length as PlaceIndex);\n\t}\n\n\t/**\n\t * Calculate the difference between two `TreeView`s\n\t * @param view - the other view to compare to this one\n\t * @returns A {@link Delta} which nodes must be changed, added, and removed to get from `this` to `view`.\n\t * The views must share a root.\n\t */\n\tpublic delta(view: TreeView): Delta<NodeId> {\n\t\tassert(this.root === view.root, 'Delta can only be calculated between views that share a root');\n\t\treturn this.forest.delta(view.forest);\n\t}\n}\n\nfunction getIndex(side: Side, index: TraitNodeIndex): PlaceIndex {\n\t// eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n\treturn (side + index) as PlaceIndex;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeView.js","sourceRoot":"","sources":["../src/TreeView.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAE/D,OAAO,EAAiB,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAY,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAsEnD;;;GAGG;AACH,MAAM,OAAgB,QAAQ;IAY7B,YAAsB,IAAY,EAAE,MAAc;QACjD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED,gDAAgD;IAChD,IAAW,IAAI;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IACzB,CAAC;IAED,qEAAqE;IAC9D,OAAO,CAAC,EAAU;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACI,oBAAoB,CAAC,KAAoB;QAC/C,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE;YAChC,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;SACpD;QACD,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IAClE,CAAC;IAED,kHAAkH;IAC3G,WAAW,CAAC,EAAU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AK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;CACD;AAED,SAAS,QAAQ,CAAC,IAAU,EAAE,KAAqB;IAClD,qEAAqE;IACrE,OAAO,CAAC,IAAI,GAAG,KAAK,CAAe,CAAC;AACrC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, copyPropertyIfDefined, fail } from './Common';\nimport { NodeId, TraitLabel } from './Identifiers';\nimport { Delta, Forest, isParentedForestNode } from './Forest';\nimport { NodeData, Side } from './persisted-types';\n\n/**\n * Specifies the location of a trait (a labeled sequence of nodes) within the tree.\n * @public\n */\nexport interface TraitLocation {\n\treadonly parent: NodeId;\n\treadonly label: TraitLabel;\n}\n\n/**\n * An immutable view of a distributed tree node.\n * @public\n */\nexport interface TreeViewNode extends NodeData<NodeId> {\n\t/** The IDs of the children under this node */\n\treadonly traits: ReadonlyMap<TraitLabel, readonly NodeId[]>;\n\t/** The parent and trait under which this node resides. Undefined iff this is the root node of the tree (i.e. {@link initialTree}). */\n\treadonly parentage?: TraitLocation;\n}\n\n/**\n * Index of a place within a trait.\n * 0 = before all nodes,\n * 1 = after first node,\n * etc.\n * @public\n */\nexport type PlaceIndex = number & { readonly PlaceIndex: unique symbol };\n\n/**\n * Index of a node within a trait.\n * 0 = first node,\n * 1 = second node,\n * etc.\n * @public\n */\nexport type TraitNodeIndex = number & { readonly TraitNodeIndex: unique symbol };\n\n/**\n * A place within a particular `TreeView` that is anchored relative to a specific node in the tree, or relative to the outside of the trait.\n * Valid iff 'trait' is valid and, if provided, sibling is in the Location specified by 'trait'.\n * @public\n */\nexport interface TreeViewPlace {\n\treadonly sibling?: NodeId;\n\treadonly side: Side;\n\treadonly trait: TraitLocation;\n}\n\n/**\n * Specifies the range of nodes from `start` to `end` within a trait within a particular `TreeView`.\n * Valid iff start and end are valid and are within the same trait.\n * @public\n */\nexport interface TreeViewRange {\n\treadonly start: TreeViewPlace;\n\treadonly end: TreeViewPlace;\n}\n\n/**\n * Contains some redundant information. Use only in computations between edits. Do not store.\n * @public\n */\nexport interface NodeInTrait {\n\treadonly trait: TraitLocation;\n\treadonly index: TraitNodeIndex;\n}\n\n/**\n * A view of a distributed tree.\n * @public\n */\nexport abstract class TreeView {\n\tpublic readonly root: NodeId;\n\tprotected readonly forest: Forest;\n\tprivate readonly rootNode: TreeViewNode;\n\n\t/**\n\t * A cache of node's index within their parent trait.\n\t * Used to avoid redundant linear scans of traits.\n\t * Not shared across views; initialized to empty each time a TreeView is created.\n\t */\n\tprivate traitIndicesCache?: Map<NodeId, TraitNodeIndex>;\n\n\tprotected constructor(root: NodeId, forest: Forest) {\n\t\tthis.root = root;\n\t\tthis.forest = forest;\n\t\tthis.rootNode = this.getViewNode(root);\n\t}\n\n\t/** @returns the number of nodes in this view */\n\tpublic get size(): number {\n\t\treturn this.forest.size;\n\t}\n\n\t/** @returns true iff a node with the given id exists in this view */\n\tpublic hasNode(id: NodeId): boolean {\n\t\treturn this.forest.has(id);\n\t}\n\n\t/**\n\t * @returns the index just after place (which specifies a location between items).\n\t * Performance note: this is O(siblings in trait).\n\t */\n\tpublic findIndexWithinTrait(place: TreeViewPlace): PlaceIndex {\n\t\tif (place.sibling === undefined) {\n\t\t\treturn this.getIndexOfSide(place.side, place.trait);\n\t\t}\n\t\treturn getIndex(place.side, this.getIndexInTrait(place.sibling));\n\t}\n\n\t/** @returns the node associated with the given id in this view. Fails if the node does not exist in this view. */\n\tpublic getViewNode(id: NodeId): TreeViewNode {\n\t\treturn this.tryGetViewNode(id) ?? fail('NodeId not found');\n\t}\n\n\t/** @returns the node associated with the given id in this view, or undefined if the node does not exist in this view */\n\tpublic tryGetViewNode(id: NodeId): TreeViewNode | undefined {\n\t\tconst forestNode = this.forest.tryGet(id);\n\t\tif (forestNode !== undefined && isParentedForestNode(forestNode)) {\n\t\t\tconst viewNode: TreeViewNode = {\n\t\t\t\tdefinition: forestNode.definition,\n\t\t\t\tidentifier: forestNode.identifier,\n\t\t\t\ttraits: forestNode.traits,\n\t\t\t\tparentage: {\n\t\t\t\t\tlabel: forestNode.traitParent,\n\t\t\t\t\tparent: forestNode.parentId,\n\t\t\t\t},\n\t\t\t};\n\t\t\tcopyPropertyIfDefined(forestNode, viewNode, 'payload');\n\t\t\treturn viewNode;\n\t\t}\n\n\t\treturn forestNode;\n\t}\n\n\t/**\n\t * @returns the label of the trait under which a node with the given id resides. Fails if the node does not exist in this view or if\n\t * it is the root node.\n\t */\n\tpublic getTraitLabel(id: NodeId): TraitLabel {\n\t\treturn this.forest.getParent(id).traitParent;\n\t}\n\n\t/**\n\t * @returns the label of the trait under which a node with the given id resides, or undefined if the node is not present in this\n\t * view or if it is the root node\n\t */\n\tpublic tryGetTraitLabel(id: NodeId): TraitLabel | undefined {\n\t\treturn this.forest.tryGetParent(id)?.traitParent;\n\t}\n\n\t/**\n\t * @returns the parent of the node with the given id. Fails if the node does not exist in this view or if it is the root node.\n\t */\n\tpublic getParentViewNode(id: NodeId): TreeViewNode {\n\t\tconst parentInfo = this.forest.getParent(id);\n\t\treturn this.getViewNode(parentInfo.parentId);\n\t}\n\n\t/**\n\t * @returns the parent of the node with the given id. Returns undefined if the node does not exist in this view or if it is the root\n\t * node.\n\t */\n\tpublic tryGetParentViewNode(id: NodeId): TreeViewNode | undefined {\n\t\tconst parentInfo = this.forest.tryGetParent(id);\n\t\tif (parentInfo === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.getViewNode(parentInfo.parentId);\n\t}\n\n\t/**\n\t * @returns the trait location of the node with the given id. Fails if the node does not exist in this view or of it is the root\n\t * node\n\t */\n\tpublic getTraitLocation(id: NodeId): TraitLocation {\n\t\tconst parentData = this.forest.getParent(id);\n\t\treturn {\n\t\t\tparent: parentData.parentId,\n\t\t\tlabel: parentData.traitParent,\n\t\t};\n\t}\n\n\t/**\n\t * @returns the trait location of the node with the given id, or undefined if the node does not exist in this view or if it is the root\n\t * node\n\t */\n\tpublic tryGetTraitLocation(id: NodeId): TraitLocation | undefined {\n\t\tconst parentData = this.forest.tryGetParent(id);\n\t\tif (parentData === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tparent: parentData.parentId,\n\t\t\tlabel: parentData.traitParent,\n\t\t};\n\t}\n\n\t/**\n\t * @returns the index within the trait under which the node with the given id resides. The node must exist in this view and must have a\n\t * parent.\n\t * Performance note: this is O(siblings in trait).\n\t */\n\tpublic getIndexInTrait(id: NodeId): TraitNodeIndex {\n\t\tconst index = this.tryGetIndexInTrait(id);\n\t\treturn index ?? fail('ID does not exist in the forest.');\n\t}\n\n\t/**\n\t * @returns the index within the trait under which the node with the given id resides, or undefined if the node does not exist in this\n\t * view or does not have a parent.\n\t * Performance note: this is O(siblings in trait).\n\t */\n\tpublic tryGetIndexInTrait(id: NodeId): TraitNodeIndex | undefined {\n\t\tconst cachedIndex = this.traitIndicesCache?.get(id);\n\t\tif (cachedIndex !== undefined) {\n\t\t\treturn cachedIndex;\n\t\t}\n\n\t\tconst parentData = this.forest.tryGetParent(id);\n\t\tif (parentData === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst parent = this.forest.tryGet(parentData.parentId);\n\t\tif (parent === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst trait = parent.traits.get(parentData.traitParent) ?? fail('inconsistent forest: trait parent not found');\n\t\tlet foundIndex: TraitNodeIndex | undefined;\n\t\tif (trait.length === 0) {\n\t\t\treturn foundIndex;\n\t\t}\n\n\t\tthis.traitIndicesCache ??= new Map();\n\t\tfor (let i = 0; i < trait.length; i++) {\n\t\t\tconst nodeInTrait = trait[i];\n\t\t\tconst index = i as TraitNodeIndex;\n\t\t\tthis.traitIndicesCache.set(nodeInTrait, index);\n\t\t\tif (nodeInTrait === id) {\n\t\t\t\tfoundIndex = index;\n\t\t\t}\n\t\t}\n\n\t\treturn foundIndex;\n\t}\n\n\t/**\n\t * @returns the trait at the given location. If no such trait exists, returns an empty trait.\n\t */\n\tpublic getTrait(traitLocation: TraitLocation): readonly NodeId[] {\n\t\treturn this.getViewNode(traitLocation.parent).traits.get(traitLocation.label) ?? [];\n\t}\n\n\t/** Asserts that the view's internal state is consistent. Useful for testing/validation. */\n\tpublic assertConsistent(): void {\n\t\tthis.forest.assertConsistent();\n\t}\n\n\tpublic [Symbol.iterator](): IterableIterator<TreeViewNode> {\n\t\treturn this.iterateNodeDescendants(this.rootNode);\n\t}\n\n\t/** @returns true iff the given view is equal to this view */\n\tpublic abstract equals(view: TreeView): boolean;\n\n\t/**\n\t * @returns true iff the given view's forest of nodes is equivalent to this view's forest of nodes\n\t * @param strict - if true, the views' forests must be the same object, otherwise they must merely be equivalent\n\t */\n\tpublic hasEqualForest(view: TreeView, strict = false): boolean {\n\t\tif (this.root === view.root) {\n\t\t\t// TODO:#49100:Perf: make this faster and/or remove use by PrefetchingCheckout.\n\t\t\treturn strict ? this.forest === view.forest : this.forest.equals(view.forest);\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tprivate *iterateNodeDescendants(node: TreeViewNode): IterableIterator<TreeViewNode> {\n\t\tyield node;\n\t\tfor (const label of [...node.traits.keys()].sort()) {\n\t\t\tconst trait = node.traits.get(label);\n\t\t\tfor (const childId of trait ?? fail('Expected trait with label')) {\n\t\t\t\tconst child = this.getViewNode(childId);\n\t\t\t\tyield* this.iterateNodeDescendants(child);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getIndexOfSide(side: Side, traitLocation: TraitLocation): PlaceIndex {\n\t\treturn side === Side.After ? (0 as PlaceIndex) : (this.getTrait(traitLocation).length as PlaceIndex);\n\t}\n\n\t/**\n\t * Calculate the difference between two `TreeView`s\n\t * @param view - the other view to compare to this one\n\t * @returns A {@link Delta} which nodes must be changed, added, and removed to get from `this` to `view`.\n\t * The views must share a root.\n\t */\n\tpublic delta(view: TreeView): Delta<NodeId> {\n\t\tassert(this.root === view.root, 'Delta can only be calculated between views that share a root');\n\t\treturn this.forest.delta(view.forest);\n\t}\n}\n\nfunction getIndex(side: Side, index: TraitNodeIndex): PlaceIndex {\n\t// eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n\treturn (side + index) as PlaceIndex;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeViewUtilities.js","sourceRoot":"","sources":["../src/TreeViewUtilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGxC;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAc,EAAE,KAAkB;IACtE,MAAM,QAAQ,GAAG,uBAAuB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACtD,qDAAqD;IACrD,OAAO;QACN,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC;QACtD,GAAG,EAAE,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,GAAG,EAAE,QAAQ,CAAC;KAClD,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAc,EAAE,WAAwB;IAC5E,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC;IAC7B,IAAI,WAAW,CAAC,gBAAgB,KAAK,SAAS,EAAE;QAC/C,MAAM,CAAC,WAAW,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC;QACjD,OAAO;YACN,KAAK,EAAE,WAAW,CAAC,cAAc;YACjC,IAAI;SACJ,CAAC;KACF;IACD,OAAO;QACN,KAAK,EAAE,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,gBAAgB,CAAC;QAC1D,IAAI,EAAE,WAAW,CAAC,IAAI;QACtB,OAAO,EAAE,WAAW,CAAC,gBAAgB;KACrC,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAc,EAAE,KAAkB;;IACzE,MAAM,cAAc,
|
|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A,MAAA,KAAK,CAAC,KAAK,CAAC,gBAAgB,mCAAI,KAAK,CAAC,GAAG,CAAC,gBAAgB,mCAAI,IAAI,CAAC,yCAAyC,CAAC,CAAC;IAC/G,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,WAAW,CAAC,KAAkB,EAAE,WAAwB,EAAE,KAAoB;IACtF,MAAM,eAAe,GAAG,WAAW,KAAK,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC;IACpF,OAAO;QACN,KAAK;QACL,IAAI,EAAE,eAAe,CAAC,IAAI;QAC1B,OAAO,EAAE,eAAe,CAAC,gBAAgB;KACzC,CAAC;AACH,CAAC;AAED;;GAEG;AACH,IAAK,WASJ;AATD,WAAK,WAAW;IACf;;OAEG;IACH,+CAAS,CAAA;IACT;;OAEG;IACH,2CAAO,CAAA;AACR,CAAC,EATI,WAAW,KAAX,WAAW,QASf","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { StablePlace, StableRange } from './ChangeTypes';\nimport { assert, fail } from './Common';\nimport { TraitLocation, TreeView, TreeViewPlace, TreeViewRange } from './TreeView';\n\n/**\n * Express the given {@link (StableRange:interface)} as a {@link TreeViewRange}\n */\nexport function rangeFromStableRange(view: TreeView, range: StableRange): TreeViewRange {\n\tconst location = getTraitLocationOfRange(view, range);\n\t// This can be optimized for better constant factors.\n\treturn {\n\t\tstart: sideOfRange(range, SideOfRange.Start, location),\n\t\tend: sideOfRange(range, SideOfRange.End, location),\n\t};\n}\n\n/**\n * Express the given {@link (StablePlace:interface)} as a {@link TreeViewPlace}\n */\nexport function placeFromStablePlace(view: TreeView, stablePlace: StablePlace): TreeViewPlace {\n\tconst { side } = stablePlace;\n\tif (stablePlace.referenceSibling === undefined) {\n\t\tassert(stablePlace.referenceTrait !== undefined);\n\t\treturn {\n\t\t\ttrait: stablePlace.referenceTrait,\n\t\t\tside,\n\t\t};\n\t}\n\treturn {\n\t\ttrait: view.getTraitLocation(stablePlace.referenceSibling),\n\t\tside: stablePlace.side,\n\t\tsibling: stablePlace.referenceSibling,\n\t};\n}\n\n/**\n * Return the trait under which the given range resides\n * @param view - the {@link TreeView} within which to retrieve the trait location\n * @param range - must be well formed and valid\n */\nexport function getTraitLocationOfRange(view: TreeView, range: StableRange): TraitLocation {\n\tconst referenceTrait = range.start.referenceTrait ?? range.end.referenceTrait;\n\tif (referenceTrait) {\n\t\treturn referenceTrait;\n\t}\n\tconst sibling =\n\t\trange.start.referenceSibling ?? range.end.referenceSibling ?? fail('malformed range does not indicate trait');\n\treturn view.getTraitLocation(sibling);\n}\n\nfunction sideOfRange(range: StableRange, sideOfRange: SideOfRange, trait: TraitLocation): TreeViewPlace {\n\tconst siblingRelative = sideOfRange === SideOfRange.Start ? range.start : range.end;\n\treturn {\n\t\ttrait,\n\t\tside: siblingRelative.side,\n\t\tsibling: siblingRelative.referenceSibling,\n\t};\n}\n\n/**\n * Denotes either the start or end of a range\n */\nenum SideOfRange {\n\t/**\n\t * The start of the range\n\t */\n\tStart = 0,\n\t/**\n\t * The end of the range\n\t */\n\tEnd = 1,\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { StableId, UuidString } from './Identifiers';
|
|
6
|
+
/** The null (lowest/all-zeros) UUID */
|
|
7
|
+
export declare const nilUuid: UuidString;
|
|
8
|
+
/**
|
|
9
|
+
* Asserts that the given string is a UUID
|
|
10
|
+
*/
|
|
11
|
+
export declare function assertIsUuidString(uuidString: string): UuidString;
|
|
12
|
+
/**
|
|
13
|
+
* Returns true iff the given string is a valid UUID-like string of hexadecimal characters
|
|
14
|
+
* 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
15
|
+
*/
|
|
16
|
+
export declare function isUuidString(str: string): str is UuidString;
|
|
17
|
+
/**
|
|
18
|
+
* Generate a random stable ID
|
|
19
|
+
*/
|
|
20
|
+
export declare function generateStableId(): StableId;
|
|
21
|
+
/**
|
|
22
|
+
* Asserts that the given string is a stable ID.
|
|
23
|
+
*/
|
|
24
|
+
export declare function assertIsStableId(stableId: string): StableId;
|
|
25
|
+
/**
|
|
26
|
+
* Returns true iff the given string is a valid Version 4, variant 2 UUID
|
|
27
|
+
* 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'
|
|
28
|
+
*/
|
|
29
|
+
export declare function isStableId(str: string): str is StableId;
|
|
30
|
+
//# sourceMappingURL=UuidUtilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UuidUtilities.d.ts","sourceRoot":"","sources":["../src/UuidUtilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAmBrD,uCAAuC;AACvC,eAAO,MAAM,OAAO,YAA0B,CAAC;AAE/C;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAGjE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,IAAI,UAAU,CAqB3D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,QAAQ,CAE3C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAG3D;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,IAAI,QAAQ,CAuCvD"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { v4, NIL } from 'uuid';
|
|
6
|
+
import { assert } from './Common';
|
|
7
|
+
const hexadecimalCharCodes = Array.from('09afAF').map((c) => c.charCodeAt(0));
|
|
8
|
+
function isHexadecimalCharacter(charCode) {
|
|
9
|
+
return ((charCode >= hexadecimalCharCodes[0] && charCode <= hexadecimalCharCodes[1]) ||
|
|
10
|
+
(charCode >= hexadecimalCharCodes[2] && charCode <= hexadecimalCharCodes[3]) ||
|
|
11
|
+
(charCode >= hexadecimalCharCodes[4] && charCode <= hexadecimalCharCodes[5]));
|
|
12
|
+
}
|
|
13
|
+
/** The null (lowest/all-zeros) UUID */
|
|
14
|
+
export const nilUuid = assertIsUuidString(NIL);
|
|
15
|
+
/**
|
|
16
|
+
* Asserts that the given string is a UUID
|
|
17
|
+
*/
|
|
18
|
+
export function assertIsUuidString(uuidString) {
|
|
19
|
+
assert(isUuidString(uuidString), `${uuidString} is not an UuidString`);
|
|
20
|
+
return uuidString;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns true iff the given string is a valid UUID-like string of hexadecimal characters
|
|
24
|
+
* 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
|
25
|
+
*/
|
|
26
|
+
export function isUuidString(str) {
|
|
27
|
+
for (let i = 0; i < str.length; i++) {
|
|
28
|
+
switch (i) {
|
|
29
|
+
case 8:
|
|
30
|
+
case 13:
|
|
31
|
+
case 18:
|
|
32
|
+
case 23:
|
|
33
|
+
if (str.charAt(i) !== '-') {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
if (!isHexadecimalCharacter(str.charCodeAt(i))) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Generate a random stable ID
|
|
48
|
+
*/
|
|
49
|
+
export function generateStableId() {
|
|
50
|
+
return assertIsStableId(v4());
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Asserts that the given string is a stable ID.
|
|
54
|
+
*/
|
|
55
|
+
export function assertIsStableId(stableId) {
|
|
56
|
+
assert(isStableId(stableId), `${stableId} is not a StableId.`);
|
|
57
|
+
return stableId;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns true iff the given string is a valid Version 4, variant 2 UUID
|
|
61
|
+
* 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'
|
|
62
|
+
*/
|
|
63
|
+
export function isStableId(str) {
|
|
64
|
+
if (str.length !== 36) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
for (let i = 0; i < str.length; i++) {
|
|
68
|
+
switch (i) {
|
|
69
|
+
case 8:
|
|
70
|
+
case 13:
|
|
71
|
+
case 18:
|
|
72
|
+
case 23:
|
|
73
|
+
if (str.charAt(i) !== '-') {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
case 14:
|
|
78
|
+
if (str.charAt(i) !== '4') {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
case 19: {
|
|
83
|
+
const char = str.charAt(i);
|
|
84
|
+
if (char !== '8' && char !== '9' && char !== 'a' && char !== 'b') {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
default:
|
|
90
|
+
if (!isHexadecimalCharacter(str.charCodeAt(i))) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=UuidUtilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UuidUtilities.js","sourceRoot":"","sources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AG,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,EAAE;oBACjE,OAAO,KAAK,CAAC;iBACb;gBACD,MAAM;aACN;YAED;gBACC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE;oBAC/C,OAAO,KAAK,CAAC;iBACb;gBACD,MAAM;SACP;KACD;IAED,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4, NIL } from 'uuid';\nimport { assert } from './Common';\nimport { StableId, UuidString } from './Identifiers';\n\nconst hexadecimalCharCodes = Array.from('09afAF').map((c) => c.charCodeAt(0)) as [\n\tzero: number,\n\tnine: number,\n\ta: number,\n\tf: number,\n\tA: number,\n\tF: number\n];\n\nfunction isHexadecimalCharacter(charCode: number): boolean {\n\treturn (\n\t\t(charCode >= hexadecimalCharCodes[0] && charCode <= hexadecimalCharCodes[1]) ||\n\t\t(charCode >= hexadecimalCharCodes[2] && charCode <= hexadecimalCharCodes[3]) ||\n\t\t(charCode >= hexadecimalCharCodes[4] && charCode <= hexadecimalCharCodes[5])\n\t);\n}\n\n/** The null (lowest/all-zeros) UUID */\nexport const nilUuid = assertIsUuidString(NIL);\n\n/**\n * Asserts that the given string is a UUID\n */\nexport function assertIsUuidString(uuidString: string): UuidString {\n\tassert(isUuidString(uuidString), `${uuidString} is not an UuidString`);\n\treturn uuidString;\n}\n\n/**\n * Returns true iff the given string is a valid UUID-like string of hexadecimal characters\n * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'\n */\nexport function isUuidString(str: string): str is UuidString {\n\tfor (let i = 0; i < str.length; i++) {\n\t\tswitch (i) {\n\t\t\tcase 8:\n\t\t\tcase 13:\n\t\t\tcase 18:\n\t\t\tcase 23:\n\t\t\t\tif (str.charAt(i) !== '-') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tif (!isHexadecimalCharacter(str.charCodeAt(i))) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/**\n * Generate a random stable ID\n */\nexport function generateStableId(): StableId {\n\treturn assertIsStableId(v4());\n}\n\n/**\n * Asserts that the given string is a stable ID.\n */\nexport function assertIsStableId(stableId: string): StableId {\n\tassert(isStableId(stableId), `${stableId} is not a StableId.`);\n\treturn stableId;\n}\n\n/**\n * Returns true iff the given string is a valid Version 4, variant 2 UUID\n * 'xxxxxxxx-xxxx-4xxx-vxxx-xxxxxxxxxxxx'\n */\nexport function isStableId(str: string): str is StableId {\n\tif (str.length !== 36) {\n\t\treturn false;\n\t}\n\n\tfor (let i = 0; i < str.length; i++) {\n\t\tswitch (i) {\n\t\t\tcase 8:\n\t\t\tcase 13:\n\t\t\tcase 18:\n\t\t\tcase 23:\n\t\t\t\tif (str.charAt(i) !== '-') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 14:\n\t\t\t\tif (str.charAt(i) !== '4') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase 19: {\n\t\t\t\tconst char = str.charAt(i);\n\t\t\t\tif (char !== '8' && char !== '9' && char !== 'a' && char !== 'b') {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tif (!isHexadecimalCharacter(str.charCodeAt(i))) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn true;\n}\n"]}
|