@fluidframework/tree 2.20.0 → 2.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/api-report/tree.legacy.alpha.api.md +6 -0
  3. package/dist/feature-libraries/treeCursorUtils.d.ts.map +1 -1
  4. package/dist/feature-libraries/treeCursorUtils.js +1 -1
  5. package/dist/feature-libraries/treeCursorUtils.js.map +1 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +3 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/legacy.d.ts +3 -1
  11. package/dist/packageVersion.d.ts +1 -1
  12. package/dist/packageVersion.js +1 -1
  13. package/dist/packageVersion.js.map +1 -1
  14. package/dist/shared-tree/index.d.ts +1 -0
  15. package/dist/shared-tree/index.d.ts.map +1 -1
  16. package/dist/shared-tree/index.js +4 -1
  17. package/dist/shared-tree/index.js.map +1 -1
  18. package/dist/shared-tree/publicContracts.d.ts +18 -0
  19. package/dist/shared-tree/publicContracts.d.ts.map +1 -0
  20. package/dist/shared-tree/publicContracts.js +24 -0
  21. package/dist/shared-tree/publicContracts.js.map +1 -0
  22. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  23. package/dist/shared-tree/sharedTree.js +3 -6
  24. package/dist/shared-tree/sharedTree.js.map +1 -1
  25. package/dist/simple-tree/api/schemaFactory.d.ts +2 -0
  26. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  27. package/dist/simple-tree/api/schemaFactory.js +2 -0
  28. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  29. package/dist/simple-tree/api/tree.d.ts +4 -0
  30. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  31. package/dist/simple-tree/api/tree.js.map +1 -1
  32. package/dist/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
  33. package/dist/simple-tree/core/getOrCreateNode.js +1 -1
  34. package/dist/simple-tree/core/getOrCreateNode.js.map +1 -1
  35. package/dist/simple-tree/core/index.d.ts +1 -1
  36. package/dist/simple-tree/core/index.d.ts.map +1 -1
  37. package/dist/simple-tree/core/index.js +2 -2
  38. package/dist/simple-tree/core/index.js.map +1 -1
  39. package/dist/simple-tree/core/treeNodeKernel.d.ts +2 -6
  40. package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  41. package/dist/simple-tree/core/treeNodeKernel.js +10 -13
  42. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  43. package/dist/simple-tree/proxies.js +1 -1
  44. package/dist/simple-tree/proxies.js.map +1 -1
  45. package/dist/util/rangeMap.d.ts +10 -1
  46. package/dist/util/rangeMap.d.ts.map +1 -1
  47. package/dist/util/rangeMap.js +35 -7
  48. package/dist/util/rangeMap.js.map +1 -1
  49. package/lib/feature-libraries/treeCursorUtils.d.ts.map +1 -1
  50. package/lib/feature-libraries/treeCursorUtils.js +2 -2
  51. package/lib/feature-libraries/treeCursorUtils.js.map +1 -1
  52. package/lib/index.d.ts +1 -1
  53. package/lib/index.d.ts.map +1 -1
  54. package/lib/index.js +1 -1
  55. package/lib/index.js.map +1 -1
  56. package/lib/legacy.d.ts +3 -1
  57. package/lib/packageVersion.d.ts +1 -1
  58. package/lib/packageVersion.js +1 -1
  59. package/lib/packageVersion.js.map +1 -1
  60. package/lib/shared-tree/index.d.ts +1 -0
  61. package/lib/shared-tree/index.d.ts.map +1 -1
  62. package/lib/shared-tree/index.js +1 -0
  63. package/lib/shared-tree/index.js.map +1 -1
  64. package/lib/shared-tree/publicContracts.d.ts +18 -0
  65. package/lib/shared-tree/publicContracts.d.ts.map +1 -0
  66. package/lib/shared-tree/publicContracts.js +21 -0
  67. package/lib/shared-tree/publicContracts.js.map +1 -0
  68. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  69. package/lib/shared-tree/sharedTree.js +3 -6
  70. package/lib/shared-tree/sharedTree.js.map +1 -1
  71. package/lib/simple-tree/api/schemaFactory.d.ts +2 -0
  72. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  73. package/lib/simple-tree/api/schemaFactory.js +2 -0
  74. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  75. package/lib/simple-tree/api/tree.d.ts +4 -0
  76. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  77. package/lib/simple-tree/api/tree.js.map +1 -1
  78. package/lib/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
  79. package/lib/simple-tree/core/getOrCreateNode.js +2 -2
  80. package/lib/simple-tree/core/getOrCreateNode.js.map +1 -1
  81. package/lib/simple-tree/core/index.d.ts +1 -1
  82. package/lib/simple-tree/core/index.d.ts.map +1 -1
  83. package/lib/simple-tree/core/index.js +1 -1
  84. package/lib/simple-tree/core/index.js.map +1 -1
  85. package/lib/simple-tree/core/treeNodeKernel.d.ts +2 -6
  86. package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  87. package/lib/simple-tree/core/treeNodeKernel.js +9 -11
  88. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  89. package/lib/simple-tree/proxies.js +2 -2
  90. package/lib/simple-tree/proxies.js.map +1 -1
  91. package/lib/util/rangeMap.d.ts +10 -1
  92. package/lib/util/rangeMap.d.ts.map +1 -1
  93. package/lib/util/rangeMap.js +35 -7
  94. package/lib/util/rangeMap.js.map +1 -1
  95. package/package.json +23 -23
  96. package/src/feature-libraries/treeCursorUtils.ts +4 -2
  97. package/src/index.ts +2 -0
  98. package/src/packageVersion.ts +1 -1
  99. package/src/shared-tree/index.ts +5 -0
  100. package/src/shared-tree/publicContracts.ts +24 -0
  101. package/src/shared-tree/sharedTree.ts +3 -6
  102. package/src/simple-tree/api/schemaFactory.ts +2 -0
  103. package/src/simple-tree/api/tree.ts +4 -0
  104. package/src/simple-tree/core/getOrCreateNode.ts +6 -2
  105. package/src/simple-tree/core/index.ts +1 -1
  106. package/src/simple-tree/core/treeNodeKernel.ts +16 -14
  107. package/src/simple-tree/proxies.ts +2 -2
  108. package/src/util/rangeMap.ts +35 -6
@@ -1 +1 @@
1
- {"version":3,"file":"proxies.js","sourceRoot":"","sources":["../../src/simple-tree/proxies.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EACN,QAAQ,GAKR,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,UAAU,EAEV,cAAc,GAGd,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAgB,IAAI,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EACN,SAAS,EAET,yBAAyB,EACzB,4BAA4B,EAC5B,yBAAyB,GACzB,MAAM,iBAAiB,CAAC;AAEzB;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAoB;IACvD,SAAS,gBAAgB,CACxB,SAAwD;QAExD,MAAM,YAAY,GAAG,SAAS,CAAC,OAAO,CAAC;QACvC,OAAO,cAAc,CAAC,YAAY,CAAC;YAClC,CAAC,CAAC,4BAA4B,CAAC,YAAY,CAAC;YAC5C,CAAC,CAAC,YAAY,CAAC;IACjB,CAAC;IACD,QAAQ,KAAK,CAAC,MAAM,EAAE,CAAC;QACtB,KAAK,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;YACrC,MAAM,UAAU,GAAG,KAA8B,CAAC;YAClD,OAAO,gBAAgB,CAAC,UAAU,CAAC,CAAC;QACrC,CAAC;QACD,KAAK,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;YACrC,MAAM,UAAU,GAAG,KAA8B,CAAC;YAClD,OAAO,gBAAgB,CAAC,UAAU,CAAC,CAAC;QACrC,CAAC;QACD,KAAK,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;YACvC,4DAA4D;YAC5D,OAAQ,KAA+B,CAAC,OAAiB,CAAC;QAC3D,CAAC;QAED;YACC,IAAI,CAAC,oBAAoB,CA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,CAAC,OAA2B,EAAE,MAA2B;IAC5E,sIAAsI;IACtI,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,8GAA8G;QAC9G,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,uBAAuB,EAAE,CAAC,QAAQ,EAAE,EAAE;YAClE,4DAA4D;YAC5D,oEAAoE;YACnE,OAAO,CAAC,CAAC,CAAE,CAAC,QAA4B,CAAC,WAAW,GAAG,QAAQ,CAAC;YACjE,4DAA4D;YAC5D,oEAAoE;YACpE,KAAK,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,OAAO,CAAC,CAAC,CAAE,CAAC,UAAU,EAAE,CAAC;gBACtD,SAAS,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACpD,CAAC;YACD,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC;gBAC5B,GAAG,EAAE,CAAC;YACP,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;AACF,CAAC;AAED,iDAAiD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tEmptyKey,\n\ttype IForestSubscription,\n\ttype MapTree,\n\ttype TreeValue,\n\ttype UpPath,\n} from \"../core/index.js\";\n\nimport {\n\tFieldKinds,\n\ttype FlexTreeField,\n\tisFlexTreeNode,\n\ttype FlexTreeRequiredField,\n\ttype FlexTreeOptionalField,\n} from \"../feature-libraries/index.js\";\nimport { type Mutable, fail, isReadonlyArray } from \"../util/index.js\";\nimport {\n\tgetKernel,\n\ttype TreeNode,\n\ttryGetTreeNodeFromMapNode,\n\tgetOrCreateNodeFromInnerNode,\n\ttryUnhydratedFlexTreeNode,\n} from \"./core/index.js\";\n\n/**\n * Retrieve the associated {@link TreeNode} for the given field's content.\n */\nexport function getTreeNodeForField(field: FlexTreeField): TreeNode | TreeValue | undefined {\n\tfunction tryToUnboxLeaves(\n\t\tflexField: FlexTreeOptionalField | FlexTreeRequiredField,\n\t): TreeNode | TreeValue | undefined {\n\t\tconst maybeContent = flexField.content;\n\t\treturn isFlexTreeNode(maybeContent)\n\t\t\t? getOrCreateNodeFromInnerNode(maybeContent)\n\t\t\t: maybeContent;\n\t}\n\tswitch (field.schema) {\n\t\tcase FieldKinds.required.identifier: {\n\t\t\tconst typedField = field as FlexTreeRequiredField;\n\t\t\treturn tryToUnboxLeaves(typedField);\n\t\t}\n\t\tcase FieldKinds.optional.identifier: {\n\t\t\tconst typedField = field as FlexTreeOptionalField;\n\t\t\treturn tryToUnboxLeaves(typedField);\n\t\t}\n\t\tcase FieldKinds.identifier.identifier: {\n\t\t\t// Identifier fields are just value fields that hold strings\n\t\t\treturn (field as FlexTreeRequiredField).content as string;\n\t\t}\n\n\t\tdefault:\n\t\t\tfail(\"invalid field kind\");\n\t}\n}\n\n// #region Content insertion and proxy binding\n\n/** The path of a proxy, relative to the root of the content tree that the proxy belongs to */\ninterface RelativeProxyPath {\n\treadonly path: UpPath;\n\treadonly proxy: TreeNode;\n}\n\n/** All {@link RelativeProxyPath}s that are under the given root path */\ninterface RootedProxyPaths {\n\treadonly rootPath: UpPath;\n\treadonly proxyPaths: RelativeProxyPath[];\n}\n\n/**\n * Records any proxies in the given content tree and does the necessary bookkeeping to ensure they are synchronized with subsequent reads of the tree.\n * @remarks If the content tree contains any proxies, this function must be called just prior to inserting the content into the tree.\n * Specifically, no other content may be inserted into the tree between the invocation of this function and the insertion of `content`.\n * The insertion of `content` must occur or else this function will cause memory leaks.\n * @param content - the tree of content to be inserted, of which any of its object/map/array nodes might be a proxy\n * @param anchors - the {@link AnchorSet} for the tree\n * @returns The content after having all proxies replaced inline with plain javascript objects.\n * See {@link extractFactoryContent} for more details.\n */\nexport function prepareContentForHydration(\n\tcontent: MapTree | readonly MapTree[] | undefined,\n\tforest: IForestSubscription,\n): void {\n\tif (isReadonlyArray(content)) {\n\t\treturn prepareArrayContentForHydration(content, forest);\n\t}\n\n\tif (content !== undefined) {\n\t\tconst proxies: RootedProxyPaths = {\n\t\t\trootPath: { parent: undefined, parentField: EmptyKey, parentIndex: 0 },\n\t\t\tproxyPaths: [],\n\t\t};\n\n\t\twalkMapTree(content, proxies.rootPath, (p, proxy) => {\n\t\t\tproxies.proxyPaths.push({ path: p, proxy });\n\t\t});\n\n\t\tbindProxies([proxies], forest);\n\t}\n}\n\nfunction prepareArrayContentForHydration(\n\tcontent: readonly MapTree[],\n\tforest: IForestSubscription,\n): void {\n\tconst proxyPaths: RootedProxyPaths[] = [];\n\tfor (const item of content) {\n\t\tconst proxyPath: RootedProxyPaths = {\n\t\t\trootPath: {\n\t\t\t\tparent: undefined,\n\t\t\t\tparentField: EmptyKey,\n\t\t\t\tparentIndex: 0,\n\t\t\t},\n\t\t\tproxyPaths: [],\n\t\t};\n\t\tproxyPaths.push(proxyPath);\n\t\twalkMapTree(item, proxyPath.rootPath, (p, proxy) => {\n\t\t\tproxyPath.proxyPaths.push({ path: p, proxy });\n\t\t});\n\t}\n\n\tbindProxies(proxyPaths, forest);\n}\n\nfunction walkMapTree(\n\tmapTree: MapTree,\n\tpath: UpPath,\n\tonVisitTreeNode: (path: UpPath, treeNode: TreeNode) => void,\n): void {\n\tif (tryUnhydratedFlexTreeNode(mapTree)?.parentField.parent.parent !== undefined) {\n\t\tthrow new UsageError(\n\t\t\t\"Attempted to insert a node which is already under a parent. If this is desired, remove the node from its parent before inserting it elsewhere.\",\n\t\t);\n\t}\n\n\ttype Next = [path: UpPath, tree: MapTree];\n\tconst nexts: Next[] = [];\n\tfor (let next: Next | undefined = [path, mapTree]; next !== undefined; next = nexts.pop()) {\n\t\tconst [p, m] = next;\n\t\tconst mapTreeNode = tryUnhydratedFlexTreeNode(m);\n\t\tif (mapTreeNode !== undefined) {\n\t\t\tconst treeNode = tryGetTreeNodeFromMapNode(mapTreeNode);\n\t\t\tif (treeNode !== undefined) {\n\t\t\t\tonVisitTreeNode(p, treeNode);\n\t\t\t}\n\t\t}\n\n\t\tfor (const [key, field] of m.fields) {\n\t\t\tfor (const [i, child] of field.entries()) {\n\t\t\t\tnexts.push([\n\t\t\t\t\t{\n\t\t\t\t\t\tparent: p,\n\t\t\t\t\t\tparentField: key,\n\t\t\t\t\t\tparentIndex: i,\n\t\t\t\t\t},\n\t\t\t\t\tchild,\n\t\t\t\t]);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction bindProxies(proxies: RootedProxyPaths[], forest: IForestSubscription): void {\n\t// Only subscribe to the event if there is at least one proxy tree to hydrate - this is not the case when inserting an empty array [].\n\tif (proxies.length > 0) {\n\t\t// Creating a new array emits one event per element in the array, so listen to the event once for each element\n\t\tlet i = 0;\n\t\tconst off = forest.events.on(\"afterRootFieldCreated\", (fieldKey) => {\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t(proxies[i]!.rootPath as Mutable<UpPath>).parentField = fieldKey;\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tfor (const { path, proxy } of proxies[i]!.proxyPaths) {\n\t\t\t\tgetKernel(proxy).anchorProxy(forest.anchors, path);\n\t\t\t}\n\t\t\tif (++i === proxies.length) {\n\t\t\t\toff();\n\t\t\t}\n\t\t});\n\t}\n}\n\n// #endregion Content insertion and proxy binding\n"]}
1
+ {"version":3,"file":"proxies.js","sourceRoot":"","sources":["../../src/simple-tree/proxies.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EACN,QAAQ,GAKR,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,UAAU,EAEV,cAAc,GAGd,M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oE;YACnE,OAAO,CAAC,CAAC,CAAE,CAAC,QAA4B,CAAC,WAAW,GAAG,QAAQ,CAAC;YACjE,4DAA4D;YAC5D,oEAAoE;YACpE,KAAK,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,OAAO,CAAC,CAAC,CAAE,CAAC,UAAU,EAAE,CAAC;gBACtD,SAAS,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACpD,CAAC;YACD,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC;gBAC5B,GAAG,EAAE,CAAC;YACP,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;AACF,CAAC;AAED,iDAAiD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tEmptyKey,\n\ttype IForestSubscription,\n\ttype MapTree,\n\ttype TreeValue,\n\ttype UpPath,\n} from \"../core/index.js\";\n\nimport {\n\tFieldKinds,\n\ttype FlexTreeField,\n\tisFlexTreeNode,\n\ttype FlexTreeRequiredField,\n\ttype FlexTreeOptionalField,\n} from \"../feature-libraries/index.js\";\nimport { type Mutable, fail, isReadonlyArray } from \"../util/index.js\";\nimport {\n\tgetKernel,\n\ttype TreeNode,\n\tgetOrCreateNodeFromInnerNode,\n\ttryUnhydratedFlexTreeNode,\n\tunhydratedFlexTreeNodeToTreeNode,\n} from \"./core/index.js\";\n\n/**\n * Retrieve the associated {@link TreeNode} for the given field's content.\n */\nexport function getTreeNodeForField(field: FlexTreeField): TreeNode | TreeValue | undefined {\n\tfunction tryToUnboxLeaves(\n\t\tflexField: FlexTreeOptionalField | FlexTreeRequiredField,\n\t): TreeNode | TreeValue | undefined {\n\t\tconst maybeContent = flexField.content;\n\t\treturn isFlexTreeNode(maybeContent)\n\t\t\t? getOrCreateNodeFromInnerNode(maybeContent)\n\t\t\t: maybeContent;\n\t}\n\tswitch (field.schema) {\n\t\tcase FieldKinds.required.identifier: {\n\t\t\tconst typedField = field as FlexTreeRequiredField;\n\t\t\treturn tryToUnboxLeaves(typedField);\n\t\t}\n\t\tcase FieldKinds.optional.identifier: {\n\t\t\tconst typedField = field as FlexTreeOptionalField;\n\t\t\treturn tryToUnboxLeaves(typedField);\n\t\t}\n\t\tcase FieldKinds.identifier.identifier: {\n\t\t\t// Identifier fields are just value fields that hold strings\n\t\t\treturn (field as FlexTreeRequiredField).content as string;\n\t\t}\n\n\t\tdefault:\n\t\t\tfail(\"invalid field kind\");\n\t}\n}\n\n// #region Content insertion and proxy binding\n\n/** The path of a proxy, relative to the root of the content tree that the proxy belongs to */\ninterface RelativeProxyPath {\n\treadonly path: UpPath;\n\treadonly proxy: TreeNode;\n}\n\n/** All {@link RelativeProxyPath}s that are under the given root path */\ninterface RootedProxyPaths {\n\treadonly rootPath: UpPath;\n\treadonly proxyPaths: RelativeProxyPath[];\n}\n\n/**\n * Records any proxies in the given content tree and does the necessary bookkeeping to ensure they are synchronized with subsequent reads of the tree.\n * @remarks If the content tree contains any proxies, this function must be called just prior to inserting the content into the tree.\n * Specifically, no other content may be inserted into the tree between the invocation of this function and the insertion of `content`.\n * The insertion of `content` must occur or else this function will cause memory leaks.\n * @param content - the tree of content to be inserted, of which any of its object/map/array nodes might be a proxy\n * @param anchors - the {@link AnchorSet} for the tree\n * @returns The content after having all proxies replaced inline with plain javascript objects.\n * See {@link extractFactoryContent} for more details.\n */\nexport function prepareContentForHydration(\n\tcontent: MapTree | readonly MapTree[] | undefined,\n\tforest: IForestSubscription,\n): void {\n\tif (isReadonlyArray(content)) {\n\t\treturn prepareArrayContentForHydration(content, forest);\n\t}\n\n\tif (content !== undefined) {\n\t\tconst proxies: RootedProxyPaths = {\n\t\t\trootPath: { parent: undefined, parentField: EmptyKey, parentIndex: 0 },\n\t\t\tproxyPaths: [],\n\t\t};\n\n\t\twalkMapTree(content, proxies.rootPath, (p, proxy) => {\n\t\t\tproxies.proxyPaths.push({ path: p, proxy });\n\t\t});\n\n\t\tbindProxies([proxies], forest);\n\t}\n}\n\nfunction prepareArrayContentForHydration(\n\tcontent: readonly MapTree[],\n\tforest: IForestSubscription,\n): void {\n\tconst proxyPaths: RootedProxyPaths[] = [];\n\tfor (const item of content) {\n\t\tconst proxyPath: RootedProxyPaths = {\n\t\t\trootPath: {\n\t\t\t\tparent: undefined,\n\t\t\t\tparentField: EmptyKey,\n\t\t\t\tparentIndex: 0,\n\t\t\t},\n\t\t\tproxyPaths: [],\n\t\t};\n\t\tproxyPaths.push(proxyPath);\n\t\twalkMapTree(item, proxyPath.rootPath, (p, proxy) => {\n\t\t\tproxyPath.proxyPaths.push({ path: p, proxy });\n\t\t});\n\t}\n\n\tbindProxies(proxyPaths, forest);\n}\n\nfunction walkMapTree(\n\tmapTree: MapTree,\n\tpath: UpPath,\n\tonVisitTreeNode: (path: UpPath, treeNode: TreeNode) => void,\n): void {\n\tif (tryUnhydratedFlexTreeNode(mapTree)?.parentField.parent.parent !== undefined) {\n\t\tthrow new UsageError(\n\t\t\t\"Attempted to insert a node which is already under a parent. If this is desired, remove the node from its parent before inserting it elsewhere.\",\n\t\t);\n\t}\n\n\ttype Next = [path: UpPath, tree: MapTree];\n\tconst nexts: Next[] = [];\n\tfor (let next: Next | undefined = [path, mapTree]; next !== undefined; next = nexts.pop()) {\n\t\tconst [p, m] = next;\n\t\tconst mapTreeNode = tryUnhydratedFlexTreeNode(m);\n\t\tif (mapTreeNode !== undefined) {\n\t\t\tconst treeNode = unhydratedFlexTreeNodeToTreeNode.get(mapTreeNode);\n\t\t\tif (treeNode !== undefined) {\n\t\t\t\tonVisitTreeNode(p, treeNode);\n\t\t\t}\n\t\t}\n\n\t\tfor (const [key, field] of m.fields) {\n\t\t\tfor (const [i, child] of field.entries()) {\n\t\t\t\tnexts.push([\n\t\t\t\t\t{\n\t\t\t\t\t\tparent: p,\n\t\t\t\t\t\tparentField: key,\n\t\t\t\t\t\tparentIndex: i,\n\t\t\t\t\t},\n\t\t\t\t\tchild,\n\t\t\t\t]);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction bindProxies(proxies: RootedProxyPaths[], forest: IForestSubscription): void {\n\t// Only subscribe to the event if there is at least one proxy tree to hydrate - this is not the case when inserting an empty array [].\n\tif (proxies.length > 0) {\n\t\t// Creating a new array emits one event per element in the array, so listen to the event once for each element\n\t\tlet i = 0;\n\t\tconst off = forest.events.on(\"afterRootFieldCreated\", (fieldKey) => {\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t(proxies[i]!.rootPath as Mutable<UpPath>).parentField = fieldKey;\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tfor (const { path, proxy } of proxies[i]!.proxyPaths) {\n\t\t\t\tgetKernel(proxy).anchorProxy(forest.anchors, path);\n\t\t\t}\n\t\t\tif (++i === proxies.length) {\n\t\t\t\toff();\n\t\t\t}\n\t\t});\n\t}\n}\n\n// #endregion Content insertion and proxy binding\n"]}
@@ -12,6 +12,7 @@
12
12
  export declare class RangeMap<K, V> {
13
13
  private readonly offsetKey;
14
14
  private readonly subtractKeys;
15
+ readonly offsetValue: (value: V, offset: number) => V;
15
16
  private tree;
16
17
  /**
17
18
  * @param offsetKey - Function which returns a new key which is `offset` keys after `key`.
@@ -21,8 +22,16 @@ export declare class RangeMap<K, V> {
21
22
  * Offsetting `b` by this difference should return `a`.
22
23
  * The difference can be infinite if `a` cannot be reached from `b` by offsetting,
23
24
  * but the difference should still be positive if `a` is larger than `b` and negative if smaller.
25
+ *
26
+ * @param offsetValue - Function used to associate a range of values with a range of keys.
27
+ * When writing to a range of keys starting with `start`, the value of the nth key is interpreted to be
28
+ * `offsetValue(firstValue, n - 1)`.
29
+ * The same logic should be used when interpreting the values for keys after the first in a
30
+ * `RangeQueryResult` or `RangeQueryEntry`.
31
+ *
32
+ * If `offsetValue` is left unspecified, all keys in a block will be given the same value.
24
33
  */
25
- constructor(offsetKey: (key: K, offset: number) => K, subtractKeys: (a: K, b: K) => number);
34
+ constructor(offsetKey: (key: K, offset: number) => K, subtractKeys: (a: K, b: K) => number, offsetValue?: (value: V, offset: number) => V);
26
35
  /**
27
36
  * Retrieves all entries from the RangeMap.
28
37
  */
@@ -1 +1 @@
1
- {"version":3,"file":"rangeMap.d.ts","sourceRoot":"","sources":["../../src/util/rangeMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH;;;;;;GAMG;AACH,qBAAa,QAAQ,CAAC,CAAC,EAAE,CAAC;IAaxB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAb9B,OAAO,CAAC,IAAI,CAA0B;IAEtC;;;;;;;;OAQG;gBAEe,SAAS,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC,EACxC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM;IAKtD;;OAEG;IACI,OAAO,IAAI,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;IASlC,KAAK,IAAI,IAAI;IAIpB;;;;;;;OAOG;IACI,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;IAuBhE;;;;;;;OAOG;IACI,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC;IAiCjE;;;;;;OAMG;IACI,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,IAAI;IAOhE;;;;;;;;;;;;;;;;;;;OAmBG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AAE;IAIV,OAAO,CAAC,EAAE;IAIV,OAAO,CAAC,EAAE;IAIV,OAAO,CAAC,EAAE;CAGV;AAiBD;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,EAAE,CAAC;IACrC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAElB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC;IAE9B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,eAAe,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC;IACpE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CAClB;AAED,wBAAgB,kBAAkB,CAAC,CAAC,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAE3D"}
@@ -20,10 +20,19 @@ export class RangeMap {
20
20
  * Offsetting `b` by this difference should return `a`.
21
21
  * The difference can be infinite if `a` cannot be reached from `b` by offsetting,
22
22
  * but the difference should still be positive if `a` is larger than `b` and negative if smaller.
23
+ *
24
+ * @param offsetValue - Function used to associate a range of values with a range of keys.
25
+ * When writing to a range of keys starting with `start`, the value of the nth key is interpreted to be
26
+ * `offsetValue(firstValue, n - 1)`.
27
+ * The same logic should be used when interpreting the values for keys after the first in a
28
+ * `RangeQueryResult` or `RangeQueryEntry`.
29
+ *
30
+ * If `offsetValue` is left unspecified, all keys in a block will be given the same value.
23
31
  */
24
- constructor(offsetKey, subtractKeys) {
32
+ constructor(offsetKey, subtractKeys, offsetValue = defaultValueOffsetFn) {
25
33
  this.offsetKey = offsetKey;
26
34
  this.subtractKeys = subtractKeys;
35
+ this.offsetValue = offsetValue;
27
36
  this.tree = new BTree(undefined, subtractKeys);
28
37
  }
29
38
  /**
@@ -55,7 +64,11 @@ export class RangeMap {
55
64
  const firstEntry = entries[0] ?? oob();
56
65
  const lengthBefore = this.subtractKeys(start, firstEntry.start);
57
66
  if (lengthBefore > 0) {
58
- entries[0] = { ...firstEntry, start, length: firstEntry.length - lengthBefore };
67
+ entries[0] = {
68
+ start,
69
+ length: firstEntry.length - lengthBefore,
70
+ value: this.offsetValue(firstEntry.value, lengthBefore),
71
+ };
59
72
  }
60
73
  const lastEntry = entries[entries.length - 1] ?? oob();
61
74
  const lastEntryKey = this.offsetKey(lastEntry.start, lastEntry.length - 1);
@@ -82,9 +95,14 @@ export class RangeMap {
82
95
  const entryKey = entry[0];
83
96
  const { value, length: entryLength } = entry[1];
84
97
  const entryLastKey = this.offsetKey(entryKey, entryLength - 1);
98
+ const lengthBeforeQuery = this.subtractKeys(start, entryKey);
85
99
  const overlappingLength = Math.min(this.subtractKeys(entryLastKey, start) + 1, length);
86
100
  if (overlappingLength > 0) {
87
- return { value, start, length: overlappingLength };
101
+ return {
102
+ value: this.offsetValue(value, lengthBeforeQuery),
103
+ start,
104
+ length: overlappingLength,
105
+ };
88
106
  }
89
107
  }
90
108
  }
@@ -148,12 +166,17 @@ export class RangeMap {
148
166
  const lengthAfter = this.subtractKeys(lastEntryKey, lastDeleteKey);
149
167
  if (lengthAfter > 0) {
150
168
  // A portion of this entry comes after the deletion range, so we reinsert that portion.
151
- this.tree.set(this.offsetKey(lastDeleteKey, 1), { length: lengthAfter, value });
169
+ const newKey = this.offsetKey(lastDeleteKey, 1);
170
+ const difference = this.subtractKeys(newKey, key);
171
+ this.tree.set(newKey, {
172
+ length: lengthAfter,
173
+ value: this.offsetValue(value, difference),
174
+ });
152
175
  }
153
176
  }
154
177
  }
155
178
  clone() {
156
- const cloned = new RangeMap(this.offsetKey, this.subtractKeys);
179
+ const cloned = new RangeMap(this.offsetKey, this.subtractKeys, this.offsetValue);
157
180
  cloned.tree = this.tree.clone();
158
181
  return cloned;
159
182
  }
@@ -161,8 +184,10 @@ export class RangeMap {
161
184
  * Returns a new map which contains the entries from both input maps.
162
185
  */
163
186
  static union(a, b) {
164
- assert(a.offsetKey === b.offsetKey && a.subtractKeys === b.subtractKeys, 0xaae /* Maps should have the same behavior */);
165
- const merged = new RangeMap(a.offsetKey, a.subtractKeys);
187
+ assert(a.offsetKey === b.offsetKey &&
188
+ a.subtractKeys === b.subtractKeys &&
189
+ a.offsetValue === b.offsetValue, 0xaae /* Maps should have the same behavior */);
190
+ const merged = new RangeMap(a.offsetKey, a.subtractKeys, a.offsetValue);
166
191
  // TODO: Is there a good pattern that lets us make `tree` readonly?
167
192
  merged.tree = a.tree.clone();
168
193
  for (const [key, value] of b.tree.entries()) {
@@ -222,4 +247,7 @@ function offsetInteger(key, offset) {
222
247
  function subtractIntegers(a, b) {
223
248
  return a - b;
224
249
  }
250
+ function defaultValueOffsetFn(value, offset) {
251
+ return value;
252
+ }
225
253
  //# sourceMappingURL=rangeMap.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rangeMap.js","sourceRoot":"","sources":["../../src/util/rangeMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,OAAO,QAAQ;IAGpB;;;;;;;;OAQG;IACH,YACkB,SAAwC,EACxC,YAAoC;QADpC,cAAS,GAAT,SAAS,CAA+B;QACxC,iBAAY,GAAZ,YAAY,CAAwB;QAErD,IAAI,CAAC,IAAI,GAAG,IAAI,KAAK,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACI,OAAO;QACb,MAAM,OAAO,GAA4B,EAAE,CAAC;QAC5C,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YAClD,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EA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M,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;gBACzD,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;YAChD,CAAC;QACF,CAAC;QAED,OAAO,OAAO,CAAC;IAChB,CAAC;IAEO,EAAE,CAAC,CAAI,EAAE,CAAI;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;IAEO,EAAE,CAAC,CAAI,EAAE,CAAI;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAEO,EAAE,CAAC,CAAI,EAAE,CAAI;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;IAEO,EAAE,CAAC,CAAI,EAAE,CAAI;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;CACD;AA4CD,MAAM,UAAU,kBAAkB;IACjC,OAAO,IAAI,QAAQ,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,aAAa,CAAC,GAAW,EAAE,MAAc;IACjD,OAAO,GAAG,GAAG,MAAM,CAAC;AACrB,CAAC;AAED,SAAS,gBAAgB,CAAC,CAAS,EAAE,CAAS;IAC7C,OAAO,CAAC,GAAG,CAAC,CAAC;AACd,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\nimport { BTree } from \"@tylerbu/sorted-btree-es6\";\n\n/**\n * RangeMap represents a mapping from keys of type K to values of type V or undefined.\n * The set of all possible keys is assumed to be fully ordered,\n * and for each key there should be a single next higher key.\n * The values for a range of consecutive keys can be changed or queried in a single operation.\n * The structure of the keys is described by the `offsetKey` and `subtractKeys` functions provided in the constructor.\n */\nexport class RangeMap<K, V> {\n\tprivate tree: BTree<K, RangeEntry<V>>;\n\n\t/**\n\t * @param offsetKey - Function which returns a new key which is `offset` keys after `key`.\n\t * When `offset` is negative, the returned key should come before `key`.\n\t *\n\t * @param subtractKeys - Function which returns the difference between `b` and `a`.\n\t * Offsetting `b` by this difference should return `a`.\n\t * The difference can be infinite if `a` cannot be reached from `b` by offsetting,\n\t * but the difference should still be positive if `a` is larger than `b` and negative if smaller.\n\t */\n\tpublic constructor(\n\t\tprivate readonly offsetKey: (key: K, offset: number) => K,\n\t\tprivate readonly subtractKeys: (a: K, b: K) => number,\n\t) {\n\t\tthis.tree = new BTree(undefined, subtractKeys);\n\t}\n\n\t/**\n\t * Retrieves all entries from the RangeMap.\n\t */\n\tpublic entries(): RangeQueryEntry<K, V>[] {\n\t\tconst entries: RangeQueryEntry<K, V>[] = [];\n\t\tfor (const [start, entry] of this.tree.entries()) {\n\t\t\tentries.push({ start, length: entry.length, value: entry.value });\n\t\t}\n\n\t\treturn entries;\n\t}\n\n\tpublic clear(): void {\n\t\tthis.tree.clear();\n\t}\n\n\t/**\n\t * Retrieves the values for all keys in the query range.\n\t *\n\t * @param start - The first key in the range being queried\n\t * @param length - The length of the query range\n\t * @returns A list of entries, each describing the value for some subrange of the query.\n\t * The entries are in the same order as the keys, and there is an entry for every key with a non `undefined` value.\n\t */\n\tpublic getAll(start: K, length: number): RangeQueryEntry<K, V>[] {\n\t\tconst entries = this.getIntersectingEntries(start, length);\n\t\tif (entries.length === 0) {\n\t\t\treturn entries;\n\t\t}\n\n\t\tconst firstEntry = entries[0] ?? oob();\n\t\tconst lengthBefore = this.subtractKeys(start, firstEntry.start);\n\t\tif (lengthBefore > 0) {\n\t\t\tentries[0] = { ...firstEntry, start, length: firstEntry.length - lengthBefore };\n\t\t}\n\n\t\tconst lastEntry = entries[entries.length - 1] ?? oob();\n\t\tconst lastEntryKey = this.offsetKey(lastEntry.start, lastEntry.length - 1);\n\t\tconst lastQueryKey = this.offsetKey(start, length - 1);\n\t\tconst lengthAfter = this.subtractKeys(lastEntryKey, lastQueryKey);\n\t\tif (lengthAfter > 0) {\n\t\t\tentries[entries.length - 1] = { ...lastEntry, length: lastEntry.length - lengthAfter };\n\t\t}\n\n\t\treturn entries;\n\t}\n\n\t/**\n\t * Retrieves the value for some prefix of the query range.\n\t *\n\t * @param start - The first key in the query range.\n\t * @param length - The length of the query range.\n\t * @returns A RangeQueryResult containing the value associated with `start`,\n\t * and the number of consecutive keys with that same value (at least 1, at most `length`).\n\t */\n\tpublic getFirst(start: K, length: number): RangeQueryResult<K, V> {\n\t\t{\n\t\t\t// We first check for an entry with a key less than or equal to `start`.\n\t\t\tconst entry = this.tree.getPairOrNextLower(start);\n\t\t\tif (entry !== undefined) {\n\t\t\t\tconst entryKey = entry[0];\n\t\t\t\tconst { value, length: entryLength } = entry[1];\n\n\t\t\t\tconst entryLastKey = this.offsetKey(entryKey, entryLength - 1);\n\t\t\t\tconst overlappingLength = Math.min(this.subtractKeys(entryLastKey, start) + 1, length);\n\t\t\t\tif (overlappingLength > 0) {\n\t\t\t\t\treturn { value, start, length: overlappingLength };\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t{\n\t\t\t// There is no value associated with `start`.\n\t\t\t// Now we need to determine how many of the following keys are also undefined.\n\t\t\tconst key = this.tree.nextHigherKey(start);\n\t\t\tif (key !== undefined) {\n\t\t\t\tconst entryKey = key;\n\n\t\t\t\tconst lastQueryKey = this.offsetKey(start, length - 1);\n\t\t\t\tif (this.le(entryKey, lastQueryKey)) {\n\t\t\t\t\treturn { value: undefined, start, length: this.subtractKeys(entryKey, start) };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { value: undefined, start, length };\n\t\t}\n\t}\n\n\t/**\n\t * Sets the value for a specified range.\n\t *\n\t * @param start - The first key in the range being set.\n\t * @param length - The length of the range.\n\t * @param value - The value to associate with the range.\n\t */\n\tpublic set(start: K, length: number, value: V | undefined): void {\n\t\tthis.delete(start, length);\n\t\tif (value !== undefined) {\n\t\t\tthis.tree.set(start, { value, length });\n\t\t}\n\t}\n\n\t/**\n\t * Deletes values within a specified range, updating or removing existing entries.\n\t *\n\t * 1. If an entry is completely included in the deletion range, the whole entry will be deleted\n\t * e.g.: map = [[1, 2], [4, 6]], delete range: [3, 6]\n\t * map becomes [[1, 2]] after deletion\n\t * (Note: the notation [a, b] represents start = a, end = b for simpler visualization, instead of `b`\n\t * representing the length)\n\t *\n\t * 2. If an entry is partially overlapped with the deletion range, the start or end point will be shifted\n\t * e.g.: map = [[1, 2], [4, 6]], delete range: [2, 4]\n\t * map becomes [[1, 1], [5, 6]] after deletion\n\t *\n\t * 3. If an entry completely includes the deletion range, the original entry may be split into two.\n\t * e.g.: map = [[1, 6]], delete range: [2, 4]\n\t * map becomes [[1, 1], [5, 6]]\n\t *\n\t * @param start - The start of the range to delete (inclusive).\n\t * @param length - The length of the range to delete.\n\t */\n\tpublic delete(start: K, length: number): void {\n\t\tconst lastDeleteKey = this.offsetKey(start, length - 1);\n\t\tfor (const { start: key, length: entryLength, value } of this.getIntersectingEntries(\n\t\t\tstart,\n\t\t\tlength,\n\t\t)) {\n\t\t\tthis.tree.delete(key);\n\t\t\tconst lengthBefore = this.subtractKeys(start, key);\n\t\t\tif (lengthBefore > 0) {\n\t\t\t\t// A portion of this entry comes before the deletion range, so we reinsert that portion.\n\t\t\t\tthis.tree.set(key, { length: lengthBefore, value });\n\t\t\t}\n\n\t\t\tconst lastEntryKey = this.offsetKey(key, entryLength - 1);\n\t\t\tconst lengthAfter = this.subtractKeys(lastEntryKey, lastDeleteKey);\n\t\t\tif (lengthAfter > 0) {\n\t\t\t\t// A portion of this entry comes after the deletion range, so we reinsert that portion.\n\t\t\t\tthis.tree.set(this.offsetKey(lastDeleteKey, 1), { length: lengthAfter, value });\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic clone(): RangeMap<K, V> {\n\t\tconst cloned = new RangeMap<K, V>(this.offsetKey, this.subtractKeys);\n\t\tcloned.tree = this.tree.clone();\n\t\treturn cloned;\n\t}\n\n\t/**\n\t * Returns a new map which contains the entries from both input maps.\n\t */\n\tpublic static union<K, V>(a: RangeMap<K, V>, b: RangeMap<K, V>): RangeMap<K, V> {\n\t\tassert(\n\t\t\ta.offsetKey === b.offsetKey && a.subtractKeys === b.subtractKeys,\n\t\t\t0xaae /* Maps should have the same behavior */,\n\t\t);\n\n\t\tconst merged = new RangeMap<K, V>(a.offsetKey, a.subtractKeys);\n\n\t\t// TODO: Is there a good pattern that lets us make `tree` readonly?\n\t\tmerged.tree = a.tree.clone();\n\t\tfor (const [key, value] of b.tree.entries()) {\n\t\t\t// TODO: Handle key collisions\n\t\t\tmerged.tree.set(key, value);\n\t\t}\n\n\t\treturn merged;\n\t}\n\n\tprivate getIntersectingEntries(start: K, length: number): RangeQueryEntry<K, V>[] {\n\t\tconst entries: RangeQueryEntry<K, V>[] = [];\n\t\tconst lastQueryKey = this.offsetKey(start, length - 1);\n\t\t{\n\t\t\tconst entry = this.tree.getPairOrNextLower(start);\n\t\t\tif (entry !== undefined) {\n\t\t\t\tconst key = entry[0];\n\t\t\t\tconst { length: entryLength, value } = entry[1];\n\t\t\t\tconst lastEntryKey = this.offsetKey(key, entryLength - 1);\n\t\t\t\tif (this.ge(lastEntryKey, start)) {\n\t\t\t\t\tentries.push({ start: key, length: entryLength, value });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t{\n\t\t\tlet entry = this.tree.nextHigherPair(start);\n\t\t\twhile (entry !== undefined) {\n\t\t\t\tconst key = entry[0];\n\t\t\t\tif (this.gt(key, lastQueryKey)) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst { length: entryLength, value } = entry[1];\n\t\t\t\tconst lastEntryKey = this.offsetKey(key, entryLength - 1);\n\n\t\t\t\tentries.push({ start: key, length: entryLength, value });\n\t\t\t\tentry = this.tree.nextHigherPair(lastEntryKey);\n\t\t\t}\n\t\t}\n\n\t\treturn entries;\n\t}\n\n\tprivate gt(a: K, b: K): boolean {\n\t\treturn this.subtractKeys(a, b) > 0;\n\t}\n\n\tprivate ge(a: K, b: K): boolean {\n\t\treturn this.subtractKeys(a, b) >= 0;\n\t}\n\n\tprivate lt(a: K, b: K): boolean {\n\t\treturn this.subtractKeys(a, b) < 0;\n\t}\n\n\tprivate le(a: K, b: K): boolean {\n\t\treturn this.subtractKeys(a, b) <= 0;\n\t}\n}\n\n/**\n * Represents a contiguous range of values in the RangeMap.\n */\ninterface RangeEntry<V> {\n\t/**\n\t * The length of the range.\n\t */\n\treadonly length: number;\n\n\t/**\n\t * The value associated with this range.\n\t */\n\treadonly value: V;\n}\n\n/**\n * Describes the result of a range query, including the value and length of the matching prefix.\n */\nexport interface RangeQueryResult<K, V> {\n\t/**\n\t * The key for the first element in the range.\n\t */\n\treadonly start: K;\n\n\t/**\n\t * The value of the first key in the query range.\n\t * If no matching range is found, this will be undefined.\n\t */\n\treadonly value: V | undefined;\n\n\t/**\n\t * The length of the prefix of the query range which has the same value.\n\t * For example, if a RangeMap has the same value for keys 5, 6, and 7,\n\t * a query about the range [5, 10] would give a result with length 3.\n\t */\n\treadonly length: number;\n}\n\nexport interface RangeQueryEntry<K, V> extends RangeQueryResult<K, V> {\n\treadonly value: V;\n}\n\nexport function newIntegerRangeMap<V>(): RangeMap<number, V> {\n\treturn new RangeMap(offsetInteger, subtractIntegers);\n}\n\nfunction offsetInteger(key: number, offset: number): number {\n\treturn key + offset;\n}\n\nfunction subtractIntegers(a: number, b: number): number {\n\treturn a - b;\n}\n"]}
1
+ {"version":3,"file":"rangeMap.js","sourceRoot":"","sources":["../../src/util/rangeMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAElD;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AAC,CAAI,EAAE,CAAI;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;IAEO,EAAE,CAAC,CAAI,EAAE,CAAI;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAEO,EAAE,CAAC,CAAI,EAAE,CAAI;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;IAEO,EAAE,CAAC,CAAI,EAAE,CAAI;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;CACD;AA4CD,MAAM,UAAU,kBAAkB;IACjC,OAAO,IAAI,QAAQ,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,aAAa,CAAC,GAAW,EAAE,MAAc;IACjD,OAAO,GAAG,GAAG,MAAM,CAAC;AACrB,CAAC;AAED,SAAS,gBAAgB,CAAC,CAAS,EAAE,CAAS;IAC7C,OAAO,CAAC,GAAG,CAAC,CAAC;AACd,CAAC;AAED,SAAS,oBAAoB,CAAI,KAAQ,EAAE,MAAc;IACxD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\nimport { BTree } from \"@tylerbu/sorted-btree-es6\";\n\n/**\n * RangeMap represents a mapping from keys of type K to values of type V or undefined.\n * The set of all possible keys is assumed to be fully ordered,\n * and for each key there should be a single next higher key.\n * The values for a range of consecutive keys can be changed or queried in a single operation.\n * The structure of the keys is described by the `offsetKey` and `subtractKeys` functions provided in the constructor.\n */\nexport class RangeMap<K, V> {\n\tprivate tree: BTree<K, RangeEntry<V>>;\n\n\t/**\n\t * @param offsetKey - Function which returns a new key which is `offset` keys after `key`.\n\t * When `offset` is negative, the returned key should come before `key`.\n\t *\n\t * @param subtractKeys - Function which returns the difference between `b` and `a`.\n\t * Offsetting `b` by this difference should return `a`.\n\t * The difference can be infinite if `a` cannot be reached from `b` by offsetting,\n\t * but the difference should still be positive if `a` is larger than `b` and negative if smaller.\n\t *\n\t * @param offsetValue - Function used to associate a range of values with a range of keys.\n\t * When writing to a range of keys starting with `start`, the value of the nth key is interpreted to be\n\t * `offsetValue(firstValue, n - 1)`.\n\t * The same logic should be used when interpreting the values for keys after the first in a\n\t * `RangeQueryResult` or `RangeQueryEntry`.\n\t *\n\t * If `offsetValue` is left unspecified, all keys in a block will be given the same value.\n\t */\n\tpublic constructor(\n\t\tprivate readonly offsetKey: (key: K, offset: number) => K,\n\t\tprivate readonly subtractKeys: (a: K, b: K) => number,\n\t\tpublic readonly offsetValue: (value: V, offset: number) => V = defaultValueOffsetFn,\n\t) {\n\t\tthis.tree = new BTree(undefined, subtractKeys);\n\t}\n\n\t/**\n\t * Retrieves all entries from the RangeMap.\n\t */\n\tpublic entries(): RangeQueryEntry<K, V>[] {\n\t\tconst entries: RangeQueryEntry<K, V>[] = [];\n\t\tfor (const [start, entry] of this.tree.entries()) {\n\t\t\tentries.push({ start, length: entry.length, value: entry.value });\n\t\t}\n\n\t\treturn entries;\n\t}\n\n\tpublic clear(): void {\n\t\tthis.tree.clear();\n\t}\n\n\t/**\n\t * Retrieves the values for all keys in the query range.\n\t *\n\t * @param start - The first key in the range being queried\n\t * @param length - The length of the query range\n\t * @returns A list of entries, each describing the value for some subrange of the query.\n\t * The entries are in the same order as the keys, and there is an entry for every key with a non `undefined` value.\n\t */\n\tpublic getAll(start: K, length: number): RangeQueryEntry<K, V>[] {\n\t\tconst entries = this.getIntersectingEntries(start, length);\n\t\tif (entries.length === 0) {\n\t\t\treturn entries;\n\t\t}\n\n\t\tconst firstEntry = entries[0] ?? oob();\n\t\tconst lengthBefore = this.subtractKeys(start, firstEntry.start);\n\t\tif (lengthBefore > 0) {\n\t\t\tentries[0] = {\n\t\t\t\tstart,\n\t\t\t\tlength: firstEntry.length - lengthBefore,\n\t\t\t\tvalue: this.offsetValue(firstEntry.value, lengthBefore),\n\t\t\t};\n\t\t}\n\n\t\tconst lastEntry = entries[entries.length - 1] ?? oob();\n\t\tconst lastEntryKey = this.offsetKey(lastEntry.start, lastEntry.length - 1);\n\t\tconst lastQueryKey = this.offsetKey(start, length - 1);\n\t\tconst lengthAfter = this.subtractKeys(lastEntryKey, lastQueryKey);\n\t\tif (lengthAfter > 0) {\n\t\t\tentries[entries.length - 1] = { ...lastEntry, length: lastEntry.length - lengthAfter };\n\t\t}\n\n\t\treturn entries;\n\t}\n\n\t/**\n\t * Retrieves the value for some prefix of the query range.\n\t *\n\t * @param start - The first key in the query range.\n\t * @param length - The length of the query range.\n\t * @returns A RangeQueryResult containing the value associated with `start`,\n\t * and the number of consecutive keys with that same value (at least 1, at most `length`).\n\t */\n\tpublic getFirst(start: K, length: number): RangeQueryResult<K, V> {\n\t\t{\n\t\t\t// We first check for an entry with a key less than or equal to `start`.\n\t\t\tconst entry = this.tree.getPairOrNextLower(start);\n\t\t\tif (entry !== undefined) {\n\t\t\t\tconst entryKey = entry[0];\n\t\t\t\tconst { value, length: entryLength } = entry[1];\n\n\t\t\t\tconst entryLastKey = this.offsetKey(entryKey, entryLength - 1);\n\t\t\t\tconst lengthBeforeQuery = this.subtractKeys(start, entryKey);\n\t\t\t\tconst overlappingLength = Math.min(this.subtractKeys(entryLastKey, start) + 1, length);\n\t\t\t\tif (overlappingLength > 0) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tvalue: this.offsetValue(value, lengthBeforeQuery),\n\t\t\t\t\t\tstart,\n\t\t\t\t\t\tlength: overlappingLength,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t{\n\t\t\t// There is no value associated with `start`.\n\t\t\t// Now we need to determine how many of the following keys are also undefined.\n\t\t\tconst key = this.tree.nextHigherKey(start);\n\t\t\tif (key !== undefined) {\n\t\t\t\tconst entryKey = key;\n\n\t\t\t\tconst lastQueryKey = this.offsetKey(start, length - 1);\n\t\t\t\tif (this.le(entryKey, lastQueryKey)) {\n\t\t\t\t\treturn { value: undefined, start, length: this.subtractKeys(entryKey, start) };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { value: undefined, start, length };\n\t\t}\n\t}\n\n\t/**\n\t * Sets the value for a specified range.\n\t *\n\t * @param start - The first key in the range being set.\n\t * @param length - The length of the range.\n\t * @param value - The value to associate with the range.\n\t */\n\tpublic set(start: K, length: number, value: V | undefined): void {\n\t\tthis.delete(start, length);\n\t\tif (value !== undefined) {\n\t\t\tthis.tree.set(start, { value, length });\n\t\t}\n\t}\n\n\t/**\n\t * Deletes values within a specified range, updating or removing existing entries.\n\t *\n\t * 1. If an entry is completely included in the deletion range, the whole entry will be deleted\n\t * e.g.: map = [[1, 2], [4, 6]], delete range: [3, 6]\n\t * map becomes [[1, 2]] after deletion\n\t * (Note: the notation [a, b] represents start = a, end = b for simpler visualization, instead of `b`\n\t * representing the length)\n\t *\n\t * 2. If an entry is partially overlapped with the deletion range, the start or end point will be shifted\n\t * e.g.: map = [[1, 2], [4, 6]], delete range: [2, 4]\n\t * map becomes [[1, 1], [5, 6]] after deletion\n\t *\n\t * 3. If an entry completely includes the deletion range, the original entry may be split into two.\n\t * e.g.: map = [[1, 6]], delete range: [2, 4]\n\t * map becomes [[1, 1], [5, 6]]\n\t *\n\t * @param start - The start of the range to delete (inclusive).\n\t * @param length - The length of the range to delete.\n\t */\n\tpublic delete(start: K, length: number): void {\n\t\tconst lastDeleteKey = this.offsetKey(start, length - 1);\n\t\tfor (const { start: key, length: entryLength, value } of this.getIntersectingEntries(\n\t\t\tstart,\n\t\t\tlength,\n\t\t)) {\n\t\t\tthis.tree.delete(key);\n\t\t\tconst lengthBefore = this.subtractKeys(start, key);\n\t\t\tif (lengthBefore > 0) {\n\t\t\t\t// A portion of this entry comes before the deletion range, so we reinsert that portion.\n\t\t\t\tthis.tree.set(key, { length: lengthBefore, value });\n\t\t\t}\n\n\t\t\tconst lastEntryKey = this.offsetKey(key, entryLength - 1);\n\t\t\tconst lengthAfter = this.subtractKeys(lastEntryKey, lastDeleteKey);\n\t\t\tif (lengthAfter > 0) {\n\t\t\t\t// A portion of this entry comes after the deletion range, so we reinsert that portion.\n\t\t\t\tconst newKey = this.offsetKey(lastDeleteKey, 1);\n\t\t\t\tconst difference = this.subtractKeys(newKey, key);\n\t\t\t\tthis.tree.set(newKey, {\n\t\t\t\t\tlength: lengthAfter,\n\t\t\t\t\tvalue: this.offsetValue(value, difference),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic clone(): RangeMap<K, V> {\n\t\tconst cloned = new RangeMap<K, V>(this.offsetKey, this.subtractKeys, this.offsetValue);\n\t\tcloned.tree = this.tree.clone();\n\t\treturn cloned;\n\t}\n\n\t/**\n\t * Returns a new map which contains the entries from both input maps.\n\t */\n\tpublic static union<K, V>(a: RangeMap<K, V>, b: RangeMap<K, V>): RangeMap<K, V> {\n\t\tassert(\n\t\t\ta.offsetKey === b.offsetKey &&\n\t\t\t\ta.subtractKeys === b.subtractKeys &&\n\t\t\t\ta.offsetValue === b.offsetValue,\n\t\t\t0xaae /* Maps should have the same behavior */,\n\t\t);\n\n\t\tconst merged = new RangeMap<K, V>(a.offsetKey, a.subtractKeys, a.offsetValue);\n\n\t\t// TODO: Is there a good pattern that lets us make `tree` readonly?\n\t\tmerged.tree = a.tree.clone();\n\t\tfor (const [key, value] of b.tree.entries()) {\n\t\t\t// TODO: Handle key collisions\n\t\t\tmerged.tree.set(key, value);\n\t\t}\n\n\t\treturn merged;\n\t}\n\n\tprivate getIntersectingEntries(start: K, length: number): RangeQueryEntry<K, V>[] {\n\t\tconst entries: RangeQueryEntry<K, V>[] = [];\n\t\tconst lastQueryKey = this.offsetKey(start, length - 1);\n\t\t{\n\t\t\tconst entry = this.tree.getPairOrNextLower(start);\n\t\t\tif (entry !== undefined) {\n\t\t\t\tconst key = entry[0];\n\t\t\t\tconst { length: entryLength, value } = entry[1];\n\t\t\t\tconst lastEntryKey = this.offsetKey(key, entryLength - 1);\n\t\t\t\tif (this.ge(lastEntryKey, start)) {\n\t\t\t\t\tentries.push({ start: key, length: entryLength, value });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t{\n\t\t\tlet entry = this.tree.nextHigherPair(start);\n\t\t\twhile (entry !== undefined) {\n\t\t\t\tconst key = entry[0];\n\t\t\t\tif (this.gt(key, lastQueryKey)) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst { length: entryLength, value } = entry[1];\n\t\t\t\tconst lastEntryKey = this.offsetKey(key, entryLength - 1);\n\n\t\t\t\tentries.push({ start: key, length: entryLength, value });\n\t\t\t\tentry = this.tree.nextHigherPair(lastEntryKey);\n\t\t\t}\n\t\t}\n\n\t\treturn entries;\n\t}\n\n\tprivate gt(a: K, b: K): boolean {\n\t\treturn this.subtractKeys(a, b) > 0;\n\t}\n\n\tprivate ge(a: K, b: K): boolean {\n\t\treturn this.subtractKeys(a, b) >= 0;\n\t}\n\n\tprivate lt(a: K, b: K): boolean {\n\t\treturn this.subtractKeys(a, b) < 0;\n\t}\n\n\tprivate le(a: K, b: K): boolean {\n\t\treturn this.subtractKeys(a, b) <= 0;\n\t}\n}\n\n/**\n * Represents a contiguous range of values in the RangeMap.\n */\ninterface RangeEntry<V> {\n\t/**\n\t * The length of the range.\n\t */\n\treadonly length: number;\n\n\t/**\n\t * The value associated with this range.\n\t */\n\treadonly value: V;\n}\n\n/**\n * Describes the result of a range query, including the value and length of the matching prefix.\n */\nexport interface RangeQueryResult<K, V> {\n\t/**\n\t * The key for the first element in the range.\n\t */\n\treadonly start: K;\n\n\t/**\n\t * The value of the first key in the query range.\n\t * If no matching range is found, this will be undefined.\n\t */\n\treadonly value: V | undefined;\n\n\t/**\n\t * The length of the prefix of the query range which has the same value.\n\t * For example, if a RangeMap has the same value for keys 5, 6, and 7,\n\t * a query about the range [5, 10] would give a result with length 3.\n\t */\n\treadonly length: number;\n}\n\nexport interface RangeQueryEntry<K, V> extends RangeQueryResult<K, V> {\n\treadonly value: V;\n}\n\nexport function newIntegerRangeMap<V>(): RangeMap<number, V> {\n\treturn new RangeMap(offsetInteger, subtractIntegers);\n}\n\nfunction offsetInteger(key: number, offset: number): number {\n\treturn key + offset;\n}\n\nfunction subtractIntegers(a: number, b: number): number {\n\treturn a - b;\n}\n\nfunction defaultValueOffsetFn<T>(value: T, offset: number): T {\n\treturn value;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/tree",
3
- "version": "2.20.0",
3
+ "version": "2.21.0",
4
4
  "description": "Distributed tree",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -89,17 +89,17 @@
89
89
  "temp-directory": "nyc/.nyc_output"
90
90
  },
91
91
  "dependencies": {
92
- "@fluid-internal/client-utils": "~2.20.0",
93
- "@fluidframework/container-runtime": "~2.20.0",
94
- "@fluidframework/core-interfaces": "~2.20.0",
95
- "@fluidframework/core-utils": "~2.20.0",
96
- "@fluidframework/datastore-definitions": "~2.20.0",
97
- "@fluidframework/driver-definitions": "~2.20.0",
98
- "@fluidframework/id-compressor": "~2.20.0",
99
- "@fluidframework/runtime-definitions": "~2.20.0",
100
- "@fluidframework/runtime-utils": "~2.20.0",
101
- "@fluidframework/shared-object-base": "~2.20.0",
102
- "@fluidframework/telemetry-utils": "~2.20.0",
92
+ "@fluid-internal/client-utils": "~2.21.0",
93
+ "@fluidframework/container-runtime": "~2.21.0",
94
+ "@fluidframework/core-interfaces": "~2.21.0",
95
+ "@fluidframework/core-utils": "~2.21.0",
96
+ "@fluidframework/datastore-definitions": "~2.21.0",
97
+ "@fluidframework/driver-definitions": "~2.21.0",
98
+ "@fluidframework/id-compressor": "~2.21.0",
99
+ "@fluidframework/runtime-definitions": "~2.21.0",
100
+ "@fluidframework/runtime-utils": "~2.21.0",
101
+ "@fluidframework/shared-object-base": "~2.21.0",
102
+ "@fluidframework/telemetry-utils": "~2.21.0",
103
103
  "@sinclair/typebox": "^0.34.13",
104
104
  "@tylerbu/sorted-btree-es6": "^1.8.0",
105
105
  "@types/ungap__structured-clone": "^1.2.0",
@@ -109,20 +109,20 @@
109
109
  "devDependencies": {
110
110
  "@arethetypeswrong/cli": "^0.17.1",
111
111
  "@biomejs/biome": "~1.9.3",
112
- "@fluid-internal/mocha-test-setup": "~2.20.0",
113
- "@fluid-private/stochastic-test-utils": "~2.20.0",
114
- "@fluid-private/test-dds-utils": "~2.20.0",
115
- "@fluid-private/test-drivers": "~2.20.0",
112
+ "@fluid-internal/mocha-test-setup": "~2.21.0",
113
+ "@fluid-private/stochastic-test-utils": "~2.21.0",
114
+ "@fluid-private/test-dds-utils": "~2.21.0",
115
+ "@fluid-private/test-drivers": "~2.21.0",
116
116
  "@fluid-tools/benchmark": "^0.50.0",
117
117
  "@fluid-tools/build-cli": "^0.51.0",
118
118
  "@fluidframework/build-common": "^2.0.3",
119
119
  "@fluidframework/build-tools": "^0.51.0",
120
- "@fluidframework/container-definitions": "~2.20.0",
121
- "@fluidframework/container-loader": "~2.20.0",
122
- "@fluidframework/eslint-config-fluid": "^5.6.0",
123
- "@fluidframework/test-runtime-utils": "~2.20.0",
124
- "@fluidframework/test-utils": "~2.20.0",
125
- "@fluidframework/tree-previous": "npm:@fluidframework/tree@2.13.0",
120
+ "@fluidframework/container-definitions": "~2.21.0",
121
+ "@fluidframework/container-loader": "~2.21.0",
122
+ "@fluidframework/eslint-config-fluid": "^5.7.3",
123
+ "@fluidframework/test-runtime-utils": "~2.21.0",
124
+ "@fluidframework/test-utils": "~2.21.0",
125
+ "@fluidframework/tree-previous": "npm:@fluidframework/tree@2.20.0",
126
126
  "@microsoft/api-extractor": "7.47.8",
127
127
  "@types/diff": "^3.5.1",
128
128
  "@types/easy-table": "^0.0.32",
@@ -202,7 +202,7 @@
202
202
  "ci:build:api-reports:current": "api-extractor run --config api-extractor/api-extractor.current.json",
203
203
  "ci:build:api-reports:legacy": "api-extractor run --config api-extractor/api-extractor.legacy.json",
204
204
  "ci:build:docs": "api-extractor run",
205
- "clean": "rimraf --glob dist lib \"*.d.ts\" \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
205
+ "clean": "rimraf --glob dist lib {alpha,beta,internal,legacy}.d.ts \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
206
206
  "depcruise": "depcruise src/ --ignore-known",
207
207
  "depcruise:regen-known-issues": "depcruise-baseline src",
208
208
  "eslint": "eslint --format stylish src",
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { assert, oob } from "@fluidframework/core-utils/internal";
6
+ import { assert, oob, debugAssert } from "@fluidframework/core-utils/internal";
7
7
 
8
8
  import {
9
9
  CursorLocationType,
@@ -147,7 +147,9 @@ class StackCursor<TNode> extends SynchronousCursor implements CursorWithNode<TNo
147
147
  }
148
148
 
149
149
  public getFieldKey(): FieldKey {
150
- // assert(this.mode === CursorLocationType.Fields, "must be in fields mode");
150
+ debugAssert(() =>
151
+ this.mode === CursorLocationType.Fields ? true : "must be in fields mode",
152
+ );
151
153
  return this.siblings[this.index] as FieldKey;
152
154
  }
153
155
 
package/src/index.ts CHANGED
@@ -83,6 +83,8 @@ export {
83
83
  ForestTypeOptimized,
84
84
  ForestTypeExpensiveDebug,
85
85
  ForestTypeReference,
86
+ SharedTreeAttributes,
87
+ SharedTreeFactoryType,
86
88
  } from "./shared-tree/index.js";
87
89
 
88
90
  export {
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/tree";
9
- export const pkgVersion = "2.20.0";
9
+ export const pkgVersion = "2.21.0";
@@ -22,6 +22,11 @@ export {
22
22
  ForestTypeReference,
23
23
  } from "./sharedTree.js";
24
24
 
25
+ export {
26
+ SharedTreeAttributes,
27
+ SharedTreeFactoryType,
28
+ } from "./publicContracts.js";
29
+
25
30
  export {
26
31
  createTreeCheckout,
27
32
  TreeCheckout,
@@ -0,0 +1,24 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import type { IChannelAttributes } from "@fluidframework/datastore-definitions/internal";
7
+
8
+ /**
9
+ * {@inheritDoc @fluidframework/shared-object-base#ISharedObjectFactory."type"}
10
+ * @alpha
11
+ * @legacy
12
+ */
13
+ export const SharedTreeFactoryType = "https://graph.microsoft.com/types/tree";
14
+
15
+ /**
16
+ * {@inheritDoc @fluidframework/shared-object-base#ISharedObjectFactory.attributes}
17
+ * @alpha
18
+ * @legacy
19
+ */
20
+ export const SharedTreeAttributes: IChannelAttributes = {
21
+ type: SharedTreeFactoryType,
22
+ snapshotFormatVersion: "0.0.0",
23
+ packageVersion: "0.0.0",
24
+ };
@@ -84,6 +84,7 @@ import type { SharedTreeEditBuilder } from "./sharedTreeEditBuilder.js";
84
84
  import { type TreeCheckout, type BranchableTree, createTreeCheckout } from "./treeCheckout.js";
85
85
  import { breakingClass, fail, throwIfBroken } from "../util/index.js";
86
86
  import type { IIdCompressor } from "@fluidframework/id-compressor";
87
+ import { SharedTreeAttributes, SharedTreeFactoryType } from "./publicContracts.js";
87
88
 
88
89
  /**
89
90
  * Copy of data from an {@link ISharedTree} at some point in time.
@@ -645,13 +646,9 @@ export const defaultSharedTreeOptions: Required<SharedTreeOptionsInternal> = {
645
646
  * A channel factory that creates {@link ISharedTree}s.
646
647
  */
647
648
  export class SharedTreeFactory implements IChannelFactory<ISharedTree> {
648
- public readonly type: string = "https://graph.microsoft.com/types/tree";
649
+ public readonly type: string = SharedTreeFactoryType;
649
650
 
650
- public readonly attributes: IChannelAttributes = {
651
- type: this.type,
652
- snapshotFormatVersion: "0.0.0",
653
- packageVersion: "0.0.0",
654
- };
651
+ public readonly attributes: IChannelAttributes = SharedTreeAttributes;
655
652
 
656
653
  public constructor(private readonly options: SharedTreeOptionsInternal = {}) {}
657
654
 
@@ -263,6 +263,8 @@ export type ScopedSchemaName<
263
263
  *
264
264
  * Note: the comparison between the customizable and POJO modes is not done in a table because TSDoc does not currently have support for embedded markdown.
265
265
  *
266
+ * @see {@link SchemaFactoryAlpha}
267
+ *
266
268
  * @sealed @public
267
269
  */
268
270
  export class SchemaFactory<
@@ -467,6 +467,10 @@ export interface TreeBranch extends IDisposable {
467
467
  * Doing that would however complicate trivial "hello world" style example slightly, as well as be a breaking API change.
468
468
  * It also seems more complex to handle invalidation with that pattern.
469
469
  * Thus this design was chosen at the risk of apps blindly accessing `root` then breaking unexpectedly when the document is incompatible.
470
+ *
471
+ * @see {@link TreeViewAlpha}
472
+ * @see {@link asTreeViewAlpha}
473
+ *
470
474
  * @sealed @public
471
475
  */
472
476
  export interface TreeView<in out TSchema extends ImplicitFieldSchema> extends IDisposable {
@@ -6,7 +6,11 @@
6
6
  import type { TreeValue } from "../../core/index.js";
7
7
  import type { FlexTreeNode } from "../../feature-libraries/index.js";
8
8
  import { fail } from "../../util/index.js";
9
- import { type InnerNode, mapTreeNodeToProxy, proxySlot } from "./treeNodeKernel.js";
9
+ import {
10
+ type InnerNode,
11
+ unhydratedFlexTreeNodeToTreeNode,
12
+ proxySlot,
13
+ } from "./treeNodeKernel.js";
10
14
  import { getSimpleNodeSchemaFromInnerNode } from "./schemaCaching.js";
11
15
  import type { TreeNode, InternalTreeNode } from "./types.js";
12
16
  import { UnhydratedFlexTreeNode } from "./unhydratedFlexTree.js";
@@ -20,7 +24,7 @@ import { UnhydratedFlexTreeNode } from "./unhydratedFlexTree.js";
20
24
  export function getOrCreateNodeFromInnerNode(flexNode: InnerNode): TreeNode | TreeValue {
21
25
  const cached =
22
26
  flexNode instanceof UnhydratedFlexTreeNode
23
- ? mapTreeNodeToProxy.get(flexNode)
27
+ ? unhydratedFlexTreeNodeToTreeNode.get(flexNode)
24
28
  : flexNode.anchorNode.slots.get(proxySlot);
25
29
 
26
30
  if (cached !== undefined) {
@@ -10,7 +10,7 @@ export {
10
10
  tryGetTreeNodeSchema,
11
11
  type InnerNode,
12
12
  tryDisposeTreeNode,
13
- tryGetTreeNodeFromMapNode,
13
+ unhydratedFlexTreeNodeToTreeNode,
14
14
  getOrCreateInnerNode,
15
15
  treeNodeFromAnchor,
16
16
  } from "./treeNodeKernel.js";
@@ -146,7 +146,7 @@ export class TreeNodeKernel {
146
146
 
147
147
  if (innerNode instanceof UnhydratedFlexTreeNode) {
148
148
  // Unhydrated case
149
- mapTreeNodeToProxy.set(innerNode, node);
149
+ unhydratedFlexTreeNodeToTreeNodeInternal.set(innerNode, node);
150
150
  // Register for change events from the unhydrated flex node.
151
151
  // These will be fired if the unhydrated node is edited, and will also be forwarded later to the hydrated node.
152
152
  this.#hydrationState = {
@@ -158,7 +158,7 @@ export class TreeNodeKernel {
158
158
 
159
159
  let n: UnhydratedFlexTreeNode | undefined = innerNode;
160
160
  while (n !== undefined) {
161
- const treeNode = mapTreeNodeToProxy.get(n);
161
+ const treeNode = unhydratedFlexTreeNodeToTreeNodeInternal.get(n);
162
162
  if (treeNode !== undefined) {
163
163
  const kernel = getKernel(treeNode);
164
164
  kernel.#unhydratedEvents.value.emit("subtreeChangedAfterBatch");
@@ -200,7 +200,7 @@ export class TreeNodeKernel {
200
200
  private hydrate(anchorNode: AnchorNode): void {
201
201
  assert(!this.disposed, 0xa2a /* cannot hydrate a disposed node */);
202
202
  assert(!isHydrated(this.#hydrationState), 0xa2b /* hydration should only happen once */);
203
- mapTreeNodeToProxy.delete(this.#hydrationState.innerNode);
203
+ unhydratedFlexTreeNodeToTreeNodeInternal.delete(this.#hydrationState.innerNode);
204
204
  this.#hydrationState = this.createHydratedState(anchorNode);
205
205
 
206
206
  // If needed, register forwarding emitters for events from before hydration
@@ -389,9 +389,20 @@ type KernelEvents = Pick<AnchorEvents, (typeof kernelEvents)[number]>;
389
389
  export type InnerNode = FlexTreeNode | UnhydratedFlexTreeNode;
390
390
 
391
391
  /**
392
- * {@inheritdoc proxyToMapTreeNode}
392
+ * Associates a given {@link UnhydratedFlexTreeNode} with a {@link TreeNode}.
393
393
  */
394
- export const mapTreeNodeToProxy = new WeakMap<UnhydratedFlexTreeNode, TreeNode>();
394
+ const unhydratedFlexTreeNodeToTreeNodeInternal = new WeakMap<
395
+ UnhydratedFlexTreeNode,
396
+ TreeNode
397
+ >();
398
+ /**
399
+ * Retrieves the {@link TreeNode} associated with the given {@link UnhydratedFlexTreeNode} if any.
400
+ */
401
+ export const unhydratedFlexTreeNodeToTreeNode =
402
+ unhydratedFlexTreeNodeToTreeNodeInternal as Pick<
403
+ WeakMap<UnhydratedFlexTreeNode, TreeNode>,
404
+ "get"
405
+ >;
395
406
 
396
407
  /**
397
408
  * An anchor slot which associates an anchor with its corresponding TreeNode, if there is one.
@@ -401,15 +412,6 @@ export const mapTreeNodeToProxy = new WeakMap<UnhydratedFlexTreeNode, TreeNode>(
401
412
  */
402
413
  export const proxySlot = anchorSlot<TreeNode>();
403
414
 
404
- /**
405
- * Retrieves the node associated with the given MapTreeNode node if any.
406
- */
407
- export function tryGetTreeNodeFromMapNode(
408
- flexNode: UnhydratedFlexTreeNode,
409
- ): TreeNode | undefined {
410
- return mapTreeNodeToProxy.get(flexNode);
411
- }
412
-
413
415
  export function tryDisposeTreeNode(anchorNode: AnchorNode): void {
414
416
  const treeNode = anchorNode.slots.get(proxySlot);
415
417
  if (treeNode !== undefined) {
@@ -24,9 +24,9 @@ import { type Mutable, fail, isReadonlyArray } from "../util/index.js";
24
24
  import {
25
25
  getKernel,
26
26
  type TreeNode,
27
- tryGetTreeNodeFromMapNode,
28
27
  getOrCreateNodeFromInnerNode,
29
28
  tryUnhydratedFlexTreeNode,
29
+ unhydratedFlexTreeNodeToTreeNode,
30
30
  } from "./core/index.js";
31
31
 
32
32
  /**
@@ -146,7 +146,7 @@ function walkMapTree(
146
146
  const [p, m] = next;
147
147
  const mapTreeNode = tryUnhydratedFlexTreeNode(m);
148
148
  if (mapTreeNode !== undefined) {
149
- const treeNode = tryGetTreeNodeFromMapNode(mapTreeNode);
149
+ const treeNode = unhydratedFlexTreeNodeToTreeNode.get(mapTreeNode);
150
150
  if (treeNode !== undefined) {
151
151
  onVisitTreeNode(p, treeNode);
152
152
  }