@fluidframework/merge-tree 3.0.2 → 3.2.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 (79) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +30 -34
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +6 -7
  5. package/dist/client.js.map +1 -1
  6. package/dist/index.d.ts +1 -2
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +2 -7
  9. package/dist/index.js.map +1 -1
  10. package/dist/mergeTreeNodes.d.ts +0 -8
  11. package/dist/mergeTreeNodes.d.ts.map +1 -1
  12. package/dist/mergeTreeNodes.js +1 -11
  13. package/dist/mergeTreeNodes.js.map +1 -1
  14. package/dist/referencePositions.d.ts +0 -10
  15. package/dist/referencePositions.d.ts.map +1 -1
  16. package/dist/referencePositions.js +0 -16
  17. package/dist/referencePositions.js.map +1 -1
  18. package/dist/test/beastTest.spec.d.ts +0 -3
  19. package/dist/test/beastTest.spec.d.ts.map +1 -1
  20. package/dist/test/beastTest.spec.js +0 -201
  21. package/dist/test/beastTest.spec.js.map +1 -1
  22. package/dist/test/index.d.ts +1 -1
  23. package/dist/test/index.d.ts.map +1 -1
  24. package/dist/test/index.js +2 -5
  25. package/dist/test/index.js.map +1 -1
  26. package/dist/test/testServer.d.ts +1 -2
  27. package/dist/test/testServer.d.ts.map +1 -1
  28. package/dist/test/testServer.js +3 -6
  29. package/dist/test/testServer.js.map +1 -1
  30. package/lib/client.d.ts.map +1 -1
  31. package/lib/client.js +7 -8
  32. package/lib/client.js.map +1 -1
  33. package/lib/index.d.ts +1 -2
  34. package/lib/index.d.ts.map +1 -1
  35. package/lib/index.js +1 -2
  36. package/lib/index.js.map +1 -1
  37. package/lib/mergeTreeNodes.d.ts +0 -8
  38. package/lib/mergeTreeNodes.d.ts.map +1 -1
  39. package/lib/mergeTreeNodes.js +0 -8
  40. package/lib/mergeTreeNodes.js.map +1 -1
  41. package/lib/referencePositions.d.ts +0 -10
  42. package/lib/referencePositions.d.ts.map +1 -1
  43. package/lib/referencePositions.js +0 -14
  44. package/lib/referencePositions.js.map +1 -1
  45. package/lib/test/beastTest.spec.d.ts +0 -3
  46. package/lib/test/beastTest.spec.d.ts.map +1 -1
  47. package/lib/test/beastTest.spec.js +1 -199
  48. package/lib/test/beastTest.spec.js.map +1 -1
  49. package/lib/test/index.d.ts +1 -1
  50. package/lib/test/index.d.ts.map +1 -1
  51. package/lib/test/index.js +1 -1
  52. package/lib/test/index.js.map +1 -1
  53. package/lib/test/testServer.d.ts +1 -2
  54. package/lib/test/testServer.d.ts.map +1 -1
  55. package/lib/test/testServer.js +3 -6
  56. package/lib/test/testServer.js.map +1 -1
  57. package/package.json +16 -16
  58. package/src/client.ts +6 -8
  59. package/src/index.ts +0 -17
  60. package/src/mergeTreeNodes.ts +0 -10
  61. package/src/referencePositions.ts +0 -16
  62. package/dist/collections/index.d.ts +0 -6
  63. package/dist/collections/index.d.ts.map +0 -1
  64. package/dist/collections/index.js +0 -11
  65. package/dist/collections/index.js.map +0 -1
  66. package/dist/collections/rbTree.d.ts +0 -160
  67. package/dist/collections/rbTree.d.ts.map +0 -1
  68. package/dist/collections/rbTree.js +0 -496
  69. package/dist/collections/rbTree.js.map +0 -1
  70. package/lib/collections/index.d.ts +0 -6
  71. package/lib/collections/index.d.ts.map +0 -1
  72. package/lib/collections/index.js +0 -6
  73. package/lib/collections/index.js.map +0 -1
  74. package/lib/collections/rbTree.d.ts +0 -160
  75. package/lib/collections/rbTree.d.ts.map +0 -1
  76. package/lib/collections/rbTree.js +0 -492
  77. package/lib/collections/rbTree.js.map +0 -1
  78. package/src/collections/index.ts +0 -20
  79. package/src/collections/rbTree.ts +0 -721
@@ -1 +1 @@
1
- {"version":3,"file":"testServer.js","sourceRoot":"","sources":["../../src/test/testServer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAkB,MAAM,qCAAqC,CAAC;AA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AAC;4BACtC,GAAG,CAAC,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC;4BAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;wBAC7B,CAAC;oBACF,CAAC;oBACD,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;wBACnC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;oBACxB,CAAC;gBACF,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,MAAM;YACP,CAAC;YACD,SAAS,EAAE,CAAC;QACb,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;CACD;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CACrC,WAA6B,EAC7B,MAAkB,EAClB,GAA8B;IAE9B,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IACpD,MAAM,UAAU,GAAG,IAAI,mBAAmB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAClF,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC;IAC5C,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;QACrD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,gEAAgE;QAChE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzC,gEAAgE;QAChE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC;IACb,CAAC;IACD,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 { Heap, type IComparer } from \"@fluidframework/core-utils/internal\";\nimport type { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\n\nimport { MergeTreeTextHelper } from \"../MergeTreeTextHelper.js\";\nimport { RedBlackTree } from \"../collections/index.js\";\nimport { compareNumbers } from \"../mergeTreeNodes.js\";\nimport { PriorPerspective } from \"../perspective.js\";\nimport type { PropertySet } from \"../properties.js\";\n\nimport { TestClient } from \"./testClient.js\";\n\ninterface ClientSeq {\n\trefSeq: number;\n\tclientId: string;\n}\n\nconst clientSeqComparer: IComparer<ClientSeq> = {\n\tmin: { refSeq: -1, clientId: \"\" },\n\tcompare: (a, b) => a.refSeq - b.refSeq,\n};\n\n/**\n * Server for tests. Simulates client communication by directing placing\n * messages in client queues.\n */\nexport class TestServer extends TestClient {\n\tseq = 1;\n\tclients: TestClient[] = [];\n\tclientSeqNumbers: Heap<ClientSeq> = new Heap<ClientSeq>(clientSeqComparer);\n\tupstreamMap: RedBlackTree<number, number> = new RedBlackTree<number, number>(compareNumbers);\n\tconstructor(options?: PropertySet) {\n\t\tsuper(options);\n\t}\n\n\taddClients(clients: TestClient[]): void {\n\t\tthis.clientSeqNumbers = new Heap<ClientSeq>(clientSeqComparer);\n\t\tthis.clients = clients;\n\t\tfor (const client of clients) {\n\t\t\tthis.clientSeqNumbers.add({\n\t\t\t\trefSeq: client.getCurrentSeq(),\n\t\t\t\tclientId: client.longClientId ?? \"\",\n\t\t\t});\n\t\t}\n\t}\n\n\tapplyMsg(msg: ISequencedDocumentMessage): boolean {\n\t\tsuper.applyMsg(msg);\n\t\tif (TestClient.useCheckQ) {\n\t\t\tconst clientId = this.getShortClientId(msg.clientId as string);\n\t\t\tconst perspective = new PriorPerspective(msg.referenceSequenceNumber, clientId);\n\t\t\treturn checkTextMatchRelative(perspective, this, msg);\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t// TODO: remove mappings when no longer needed using min seq\n\t// in upstream message\n\ttransformUpstreamMessage(msg: ISequencedDocumentMessage): void {\n\t\tif (msg.referenceSequenceNumber > 0) {\n\t\t\tmsg.referenceSequenceNumber =\n\t\t\t\tthis.upstreamMap.get(msg.referenceSequenceNumber)?.data ?? 0;\n\t\t}\n\t\tmsg.origin = {\n\t\t\tid: \"A\",\n\t\t\tsequenceNumber: msg.sequenceNumber,\n\t\t\tminimumSequenceNumber: msg.minimumSequenceNumber,\n\t\t};\n\t\tthis.upstreamMap.put(msg.sequenceNumber, this.seq);\n\t\tmsg.sequenceNumber = -1;\n\t}\n\n\tcopyMsg(msg: ISequencedDocumentMessage): ISequencedDocumentMessage {\n\t\treturn {\n\t\t\tclientId: msg.clientId,\n\t\t\tclientSequenceNumber: msg.clientSequenceNumber,\n\t\t\tcontents: msg.contents,\n\t\t\tminimumSequenceNumber: msg.minimumSequenceNumber,\n\t\t\treferenceSequenceNumber: msg.referenceSequenceNumber,\n\t\t\tsequenceNumber: msg.sequenceNumber,\n\t\t\ttype: msg.type,\n\t\t} as unknown as ISequencedDocumentMessage;\n\t}\n\n\tprivate minSeq = 0;\n\n\tapplyMessages(msgCount: number): boolean {\n\t\tlet _msgCount = msgCount;\n\t\twhile (_msgCount > 0) {\n\t\t\tconst msg = this.dequeueMsg();\n\t\t\tif (msg) {\n\t\t\t\tif (msg.sequenceNumber >= 0) {\n\t\t\t\t\tthis.transformUpstreamMessage(msg);\n\t\t\t\t}\n\t\t\t\tmsg.sequenceNumber = this.seq++;\n\t\t\t\tmsg.minimumSequenceNumber = this.minSeq;\n\t\t\t\tif (this.applyMsg(msg)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tif (this.clients) {\n\t\t\t\t\tlet minCli = this.clientSeqNumbers.peek()?.value;\n\t\t\t\t\tif (\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- TODO: ADO#58520 Code owners should verify if this code change is safe and make it if so or update this comment otherwise\n\t\t\t\t\t\tminCli &&\n\t\t\t\t\t\tminCli.clientId === msg.clientId &&\n\t\t\t\t\t\tminCli.refSeq < msg.referenceSequenceNumber\n\t\t\t\t\t) {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\tconst cliSeq = this.clientSeqNumbers.get()!;\n\t\t\t\t\t\tconst oldSeq = cliSeq.refSeq;\n\t\t\t\t\t\tcliSeq.refSeq = msg.referenceSequenceNumber;\n\t\t\t\t\t\tthis.clientSeqNumbers.add(cliSeq);\n\t\t\t\t\t\tminCli = this.clientSeqNumbers.peek()?.value;\n\t\t\t\t\t\tif (minCli && minCli.refSeq > oldSeq) {\n\t\t\t\t\t\t\tmsg.minimumSequenceNumber = minCli.refSeq;\n\t\t\t\t\t\t\tthis.minSeq = minCli.refSeq;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (const client of this.clients) {\n\t\t\t\t\t\tclient.enqueueMsg(msg);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t_msgCount--;\n\t\t}\n\t\treturn false;\n\t}\n}\n\n/**\n * Used for in-memory testing. This will queue a reference string for each client message.\n */\nexport function checkTextMatchRelative(\n\tperspective: PriorPerspective,\n\tserver: TestServer,\n\tmsg: ISequencedDocumentMessage,\n): boolean {\n\tconst client = server.clients[perspective.clientId];\n\tconst serverText = new MergeTreeTextHelper(server.mergeTree).getText(perspective);\n\tconst cliText = client.checkQ.shift()?.data;\n\tif (cliText === undefined || cliText !== serverText) {\n\t\tconsole.log(`mismatch `);\n\t\tconsole.log(msg);\n\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\tconsole.log(server.mergeTree.toString());\n\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\tconsole.log(client.mergeTree.toString());\n\t\treturn true;\n\t}\n\treturn false;\n}\n"]}
1
+ {"version":3,"file":"testServer.js","sourceRoot":"","sources":["../../src/test/testServer.ts"],"names":[],"mappings":"AAAA;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C1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;wBAC7B,CAAC;oBACF,CAAC;oBACD,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;wBACnC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;oBACxB,CAAC;gBACF,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,MAAM;YACP,CAAC;YACD,SAAS,EAAE,CAAC;QACb,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;CACD;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CACrC,WAA6B,EAC7B,MAAkB,EAClB,GAA8B;IAE9B,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IACpD,MAAM,UAAU,GAAG,IAAI,mBAAmB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAClF,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC;IAC5C,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;QACrD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,gEAAgE;QAChE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzC,gEAAgE;QAChE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC;IACb,CAAC;IACD,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 { Heap, type IComparer } from \"@fluidframework/core-utils/internal\";\nimport type { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\n\nimport { MergeTreeTextHelper } from \"../MergeTreeTextHelper.js\";\nimport { PriorPerspective } from \"../perspective.js\";\nimport type { PropertySet } from \"../properties.js\";\n\nimport { TestClient } from \"./testClient.js\";\n\ninterface ClientSeq {\n\trefSeq: number;\n\tclientId: string;\n}\n\nconst clientSeqComparer: IComparer<ClientSeq> = {\n\tmin: { refSeq: -1, clientId: \"\" },\n\tcompare: (a, b) => a.refSeq - b.refSeq,\n};\n\n/**\n * Server for tests. Simulates client communication by directing placing\n * messages in client queues.\n */\nexport class TestServer extends TestClient {\n\tseq = 1;\n\tclients: TestClient[] = [];\n\tclientSeqNumbers: Heap<ClientSeq> = new Heap<ClientSeq>(clientSeqComparer);\n\tupstreamMap: Map<number, number> = new Map<number, number>();\n\tconstructor(options?: PropertySet) {\n\t\tsuper(options);\n\t}\n\n\taddClients(clients: TestClient[]): void {\n\t\tthis.clientSeqNumbers = new Heap<ClientSeq>(clientSeqComparer);\n\t\tthis.clients = clients;\n\t\tfor (const client of clients) {\n\t\t\tthis.clientSeqNumbers.add({\n\t\t\t\trefSeq: client.getCurrentSeq(),\n\t\t\t\tclientId: client.longClientId ?? \"\",\n\t\t\t});\n\t\t}\n\t}\n\n\tapplyMsg(msg: ISequencedDocumentMessage): boolean {\n\t\tsuper.applyMsg(msg);\n\t\tif (TestClient.useCheckQ) {\n\t\t\tconst clientId = this.getShortClientId(msg.clientId as string);\n\t\t\tconst perspective = new PriorPerspective(msg.referenceSequenceNumber, clientId);\n\t\t\treturn checkTextMatchRelative(perspective, this, msg);\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t// TODO: remove mappings when no longer needed using min seq\n\t// in upstream message\n\ttransformUpstreamMessage(msg: ISequencedDocumentMessage): void {\n\t\tif (msg.referenceSequenceNumber > 0) {\n\t\t\tmsg.referenceSequenceNumber = this.upstreamMap.get(msg.referenceSequenceNumber) ?? 0;\n\t\t}\n\t\tmsg.origin = {\n\t\t\tid: \"A\",\n\t\t\tsequenceNumber: msg.sequenceNumber,\n\t\t\tminimumSequenceNumber: msg.minimumSequenceNumber,\n\t\t};\n\t\tthis.upstreamMap.set(msg.sequenceNumber, this.seq);\n\t\tmsg.sequenceNumber = -1;\n\t}\n\n\tcopyMsg(msg: ISequencedDocumentMessage): ISequencedDocumentMessage {\n\t\treturn {\n\t\t\tclientId: msg.clientId,\n\t\t\tclientSequenceNumber: msg.clientSequenceNumber,\n\t\t\tcontents: msg.contents,\n\t\t\tminimumSequenceNumber: msg.minimumSequenceNumber,\n\t\t\treferenceSequenceNumber: msg.referenceSequenceNumber,\n\t\t\tsequenceNumber: msg.sequenceNumber,\n\t\t\ttype: msg.type,\n\t\t} as unknown as ISequencedDocumentMessage;\n\t}\n\n\tprivate minSeq = 0;\n\n\tapplyMessages(msgCount: number): boolean {\n\t\tlet _msgCount = msgCount;\n\t\twhile (_msgCount > 0) {\n\t\t\tconst msg = this.dequeueMsg();\n\t\t\tif (msg) {\n\t\t\t\tif (msg.sequenceNumber >= 0) {\n\t\t\t\t\tthis.transformUpstreamMessage(msg);\n\t\t\t\t}\n\t\t\t\tmsg.sequenceNumber = this.seq++;\n\t\t\t\tmsg.minimumSequenceNumber = this.minSeq;\n\t\t\t\tif (this.applyMsg(msg)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tif (this.clients) {\n\t\t\t\t\tlet minCli = this.clientSeqNumbers.peek()?.value;\n\t\t\t\t\tif (\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- TODO: ADO#58520 Code owners should verify if this code change is safe and make it if so or update this comment otherwise\n\t\t\t\t\t\tminCli &&\n\t\t\t\t\t\tminCli.clientId === msg.clientId &&\n\t\t\t\t\t\tminCli.refSeq < msg.referenceSequenceNumber\n\t\t\t\t\t) {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\tconst cliSeq = this.clientSeqNumbers.get()!;\n\t\t\t\t\t\tconst oldSeq = cliSeq.refSeq;\n\t\t\t\t\t\tcliSeq.refSeq = msg.referenceSequenceNumber;\n\t\t\t\t\t\tthis.clientSeqNumbers.add(cliSeq);\n\t\t\t\t\t\tminCli = this.clientSeqNumbers.peek()?.value;\n\t\t\t\t\t\tif (minCli && minCli.refSeq > oldSeq) {\n\t\t\t\t\t\t\tmsg.minimumSequenceNumber = minCli.refSeq;\n\t\t\t\t\t\t\tthis.minSeq = minCli.refSeq;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (const client of this.clients) {\n\t\t\t\t\t\tclient.enqueueMsg(msg);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t_msgCount--;\n\t\t}\n\t\treturn false;\n\t}\n}\n\n/**\n * Used for in-memory testing. This will queue a reference string for each client message.\n */\nexport function checkTextMatchRelative(\n\tperspective: PriorPerspective,\n\tserver: TestServer,\n\tmsg: ISequencedDocumentMessage,\n): boolean {\n\tconst client = server.clients[perspective.clientId];\n\tconst serverText = new MergeTreeTextHelper(server.mergeTree).getText(perspective);\n\tconst cliText = client.checkQ.shift()?.data;\n\tif (cliText === undefined || cliText !== serverText) {\n\t\tconsole.log(`mismatch `);\n\t\tconsole.log(msg);\n\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\tconsole.log(server.mergeTree.toString());\n\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\tconsole.log(client.mergeTree.toString());\n\t\treturn true;\n\t}\n\treturn false;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/merge-tree",
3
- "version": "3.0.2",
3
+ "version": "3.2.0",
4
4
  "description": "Merge tree",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -61,30 +61,30 @@
61
61
  "temp-directory": "nyc/.nyc_output"
62
62
  },
63
63
  "dependencies": {
64
- "@fluid-internal/client-utils": "~3.0.2",
65
- "@fluidframework/container-definitions": "~3.0.2",
66
- "@fluidframework/core-interfaces": "~3.0.2",
67
- "@fluidframework/core-utils": "~3.0.2",
68
- "@fluidframework/datastore-definitions": "~3.0.2",
69
- "@fluidframework/driver-definitions": "~3.0.2",
70
- "@fluidframework/runtime-definitions": "~3.0.2",
71
- "@fluidframework/runtime-utils": "~3.0.2",
72
- "@fluidframework/shared-object-base": "~3.0.2",
73
- "@fluidframework/telemetry-utils": "~3.0.2"
64
+ "@fluid-internal/client-utils": "~3.2.0",
65
+ "@fluidframework/container-definitions": "~3.2.0",
66
+ "@fluidframework/core-interfaces": "~3.2.0",
67
+ "@fluidframework/core-utils": "~3.2.0",
68
+ "@fluidframework/datastore-definitions": "~3.2.0",
69
+ "@fluidframework/driver-definitions": "~3.2.0",
70
+ "@fluidframework/runtime-definitions": "~3.2.0",
71
+ "@fluidframework/runtime-utils": "~3.2.0",
72
+ "@fluidframework/shared-object-base": "~3.2.0",
73
+ "@fluidframework/telemetry-utils": "~3.2.0"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@arethetypeswrong/cli": "^0.18.5",
77
77
  "@biomejs/biome": "~2.4.5",
78
- "@fluid-internal/mocha-test-setup": "~3.0.2",
79
- "@fluid-private/stochastic-test-utils": "~3.0.2",
80
- "@fluid-private/test-pairwise-generator": "~3.0.2",
78
+ "@fluid-internal/mocha-test-setup": "~3.2.0",
79
+ "@fluid-private/stochastic-test-utils": "~3.2.0",
80
+ "@fluid-private/test-pairwise-generator": "~3.2.0",
81
81
  "@fluid-tools/benchmark": "^0.59.0",
82
82
  "@fluid-tools/build-cli": "^0.67.0",
83
83
  "@fluidframework/build-common": "^2.0.3",
84
84
  "@fluidframework/build-tools": "^0.67.0",
85
85
  "@fluidframework/eslint-config-fluid": "^14.0.0",
86
- "@fluidframework/merge-tree-previous": "npm:@fluidframework/merge-tree@2.116.0",
87
- "@fluidframework/test-runtime-utils": "~3.0.2",
86
+ "@fluidframework/merge-tree-previous": "npm:@fluidframework/merge-tree@3.1.0",
87
+ "@fluidframework/test-runtime-utils": "~3.2.0",
88
88
  "@microsoft/api-extractor": "7.58.1",
89
89
  "@types/diff": "^3.5.1",
90
90
  "@types/mocha": "^10.0.10",
package/src/client.ts CHANGED
@@ -31,7 +31,6 @@ import {
31
31
  } from "@fluidframework/telemetry-utils/internal";
32
32
 
33
33
  import { MergeTreeTextHelper, type IMergeTreeTextHelper } from "./MergeTreeTextHelper.js";
34
- import { RedBlackTree } from "./collections/index.js";
35
34
  import { NonCollabClient, SquashClient, UniversalSequenceNumber } from "./constants.js";
36
35
  import { type LocalReferencePosition, SlidingPreference } from "./localReference.js";
37
36
  import {
@@ -54,7 +53,6 @@ import {
54
53
  type ISegmentPrivate,
55
54
  type Marker,
56
55
  type SegmentGroup,
57
- compareStrings,
58
56
  isSegmentLeaf,
59
57
  type ISegmentInternal,
60
58
  type ISegmentLeaf,
@@ -173,7 +171,7 @@ export class Client extends TypedEventEmitter<IClientEvents> {
173
171
 
174
172
  private readonly _mergeTree: MergeTree;
175
173
 
176
- private readonly clientNameToIds = new RedBlackTree<string, number>(compareStrings);
174
+ private readonly clientNameToIds = new Map<string, number>();
177
175
  private readonly shortClientIdMap: string[] = [];
178
176
 
179
177
  /**
@@ -829,14 +827,14 @@ export class Client extends TypedEventEmitter<IClientEvents> {
829
827
  }
830
828
 
831
829
  getOrAddShortClientId(longClientId: string): number {
832
- if (!this.clientNameToIds.get(longClientId)) {
830
+ if (!this.clientNameToIds.has(longClientId)) {
833
831
  this.addLongClientId(longClientId);
834
832
  }
835
833
  return this.getShortClientId(longClientId);
836
834
  }
837
835
 
838
836
  protected getShortClientId(longClientId: string): number {
839
- return this.clientNameToIds.get(longClientId)!.data;
837
+ return this.clientNameToIds.get(longClientId)!;
840
838
  }
841
839
 
842
840
  getLongClientId(shortClientId: number): string {
@@ -844,7 +842,7 @@ export class Client extends TypedEventEmitter<IClientEvents> {
844
842
  }
845
843
 
846
844
  addLongClientId(longClientId: string): void {
847
- this.clientNameToIds.put(longClientId, this.shortClientIdMap.length);
845
+ this.clientNameToIds.set(longClientId, this.shortClientIdMap.length);
848
846
  this.shortClientIdMap.push(longClientId);
849
847
  }
850
848
 
@@ -1718,9 +1716,9 @@ export class Client extends TypedEventEmitter<IClientEvents> {
1718
1716
  );
1719
1717
  } else {
1720
1718
  const oldClientId = this.longClientId;
1721
- const oldData = this.clientNameToIds.get(oldClientId)!.data;
1719
+ const oldData = this.clientNameToIds.get(oldClientId)!;
1722
1720
  this.longClientId = longClientId;
1723
- this.clientNameToIds.put(longClientId, oldData);
1721
+ this.clientNameToIds.set(longClientId, oldData);
1724
1722
  this.shortClientIdMap[oldData] = longClientId;
1725
1723
  }
1726
1724
  }
package/src/index.ts CHANGED
@@ -16,21 +16,6 @@ export {
16
16
  createPropertyTrackingAndInsertionAttributionPolicyFactory,
17
17
  } from "./attributionPolicy.js";
18
18
  export { Client, type IClientEvents } from "./client.js";
19
- export {
20
- type ConflictAction,
21
- type Dictionary,
22
- type IRBAugmentation,
23
- type IRBMatcher,
24
- type KeyComparer,
25
- type Property,
26
- type PropertyAction,
27
- type QProperty,
28
- RBColor,
29
- type RBNode,
30
- type RBNodeActions,
31
- RedBlackTree,
32
- type SortedDictionary,
33
- } from "./collections/index.js";
34
19
  export { UnassignedSequenceNumber, UniversalSequenceNumber } from "./constants.js";
35
20
  export {
36
21
  createDetachedLocalReferencePosition,
@@ -108,8 +93,6 @@ export {
108
93
  export {
109
94
  compareReferencePositions,
110
95
  DetachedReferencePosition,
111
- maxReferencePosition,
112
- minReferencePosition,
113
96
  type ReferencePosition,
114
97
  refGetTileLabels,
115
98
  refHasTileLabel,
@@ -694,13 +694,3 @@ export class CollaborationWindow {
694
694
  };
695
695
  }
696
696
  }
697
-
698
- /**
699
- * Compares two numbers.
700
- */
701
- export const compareNumbers = (a: number, b: number): number => a - b;
702
-
703
- /**
704
- * Compares two strings.
705
- */
706
- export const compareStrings = (a: string, b: string): number => a.localeCompare(b);
@@ -103,22 +103,6 @@ export interface ReferencePosition {
103
103
  */
104
104
  export const DetachedReferencePosition = -1;
105
105
 
106
- /**
107
- * Finds the minimum reference position.
108
- * @internal
109
- */
110
- export function minReferencePosition<T extends ReferencePosition>(a: T, b: T): T {
111
- return compareReferencePositions(a, b) < 0 ? a : b;
112
- }
113
-
114
- /**
115
- * Finds the maximum reference position.
116
- * @internal
117
- */
118
- export function maxReferencePosition<T extends ReferencePosition>(a: T, b: T): T {
119
- return compareReferencePositions(a, b) > 0 ? a : b;
120
- }
121
-
122
106
  /**
123
107
  * Compares two reference positions.
124
108
  * @internal
@@ -1,6 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- export { type ConflictAction, type Dictionary, type IRBAugmentation, type IRBMatcher, type KeyComparer, type Property, type PropertyAction, type QProperty, RBColor, type RBNode, type RBNodeActions, RedBlackTree, type SortedDictionary, } from "./rbTree.js";
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/collections/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,OAAO,EACP,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,YAAY,EACZ,KAAK,gBAAgB,GACrB,MAAM,aAAa,CAAC"}
@@ -1,11 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.RedBlackTree = exports.RBColor = void 0;
8
- var rbTree_js_1 = require("./rbTree.js");
9
- Object.defineProperty(exports, "RBColor", { enumerable: true, get: function () { return rbTree_js_1.RBColor; } });
10
- Object.defineProperty(exports, "RedBlackTree", { enumerable: true, get: function () { return rbTree_js_1.RedBlackTree; } });
11
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/collections/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yCAcqB;AALpB,oGAAA,OAAO,OAAA;AAGP,yGAAA,YAAY,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\ttype ConflictAction,\n\ttype Dictionary,\n\ttype IRBAugmentation,\n\ttype IRBMatcher,\n\ttype KeyComparer,\n\ttype Property,\n\ttype PropertyAction,\n\ttype QProperty,\n\tRBColor,\n\ttype RBNode,\n\ttype RBNodeActions,\n\tRedBlackTree,\n\ttype SortedDictionary,\n} from \"./rbTree.js\";\n"]}
@@ -1,160 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- /**
6
- * @internal
7
- */
8
- export declare const RBColor: {
9
- readonly RED: 0;
10
- readonly BLACK: 1;
11
- };
12
- /**
13
- * @internal
14
- */
15
- export type RBColor = (typeof RBColor)[keyof typeof RBColor];
16
- /**
17
- * @internal
18
- */
19
- export interface RBNode<TKey, TData> {
20
- key: TKey;
21
- data: TData;
22
- left: RBNode<TKey, TData> | undefined;
23
- right: RBNode<TKey, TData> | undefined;
24
- color: RBColor;
25
- size: number;
26
- }
27
- /**
28
- * @internal
29
- */
30
- export interface IRBAugmentation<TKey, TData> {
31
- update(node: RBNode<TKey, TData>): void;
32
- }
33
- /**
34
- * @internal
35
- */
36
- export interface IRBMatcher<TKey, TData> {
37
- continueSubtree(node: RBNode<TKey, TData> | undefined, key: TKey): boolean;
38
- matchNode(node: RBNode<TKey, TData> | undefined, key: TKey): boolean;
39
- }
40
- /**
41
- * @internal
42
- */
43
- export interface RBNodeActions<TKey, TData> {
44
- infix?(node: RBNode<TKey, TData>): boolean;
45
- pre?(node: RBNode<TKey, TData>): boolean;
46
- post?(node: RBNode<TKey, TData>): boolean;
47
- showStructure?: boolean;
48
- }
49
- /**
50
- * @internal
51
- */
52
- export interface KeyComparer<TKey> {
53
- (a: TKey, b: TKey): number;
54
- }
55
- /**
56
- * @internal
57
- */
58
- export interface Property<TKey, TData> {
59
- key: TKey;
60
- data: TData;
61
- }
62
- /**
63
- * @internal
64
- */
65
- export interface PropertyAction<TKey, TData> {
66
- <TAccum>(p: Property<TKey, TData>, accum?: TAccum): boolean;
67
- }
68
- /**
69
- * @internal
70
- */
71
- export interface QProperty<TKey, TData> {
72
- key?: TKey;
73
- data?: TData;
74
- }
75
- /**
76
- * @internal
77
- */
78
- export type ConflictAction<TKey, TData> = (key: TKey, currentKey: TKey, data: TData, currentData: TData) => QProperty<TKey, TData>;
79
- /**
80
- * @internal
81
- */
82
- export interface SortedDictionary<TKey, TData> extends Dictionary<TKey, TData> {
83
- max(): Property<TKey, TData> | undefined;
84
- min(): Property<TKey, TData> | undefined;
85
- mapRange<TAccum>(action: PropertyAction<TKey, TData>, accum?: TAccum, start?: TKey, end?: TKey): void;
86
- }
87
- /**
88
- * @internal
89
- */
90
- export interface Dictionary<TKey, TData> {
91
- get(key: TKey): Property<TKey, TData> | undefined;
92
- put(key: TKey, data: TData, conflict?: ConflictAction<TKey, TData>): void;
93
- remove(key: TKey): void;
94
- map<TAccum>(action: PropertyAction<TKey, TData>, accum?: TAccum): void;
95
- }
96
- /**
97
- * @internal
98
- */
99
- export declare class RedBlackTree<TKey, TData> implements SortedDictionary<TKey, TData> {
100
- private readonly compareKeys;
101
- private readonly aug?;
102
- private root;
103
- constructor(compareKeys: KeyComparer<TKey>, aug?: IRBAugmentation<TKey, TData> | undefined);
104
- private makeNode;
105
- private isRed;
106
- private nodeSize;
107
- size(): number;
108
- isEmpty(): boolean;
109
- get(key: TKey): RBNode<TKey, TData> | undefined;
110
- private nodeGet;
111
- private contains;
112
- gather(key: TKey, matcher: IRBMatcher<TKey, TData>): RBNode<TKey, TData>[];
113
- private nodeGather;
114
- walkExactMatchesForward(compareFn: (node: RBNode<TKey, TData>) => number, actionFn: (node: RBNode<TKey, TData>) => void, continueLeftFn: (number: number) => boolean, continueRightFn: (number: number) => boolean): void;
115
- private nodeWalkExactMatchesForward;
116
- walkExactMatchesBackward(compareFn: (node: RBNode<TKey, TData>) => number, actionFn: (node: RBNode<TKey, TData>) => void, continueLeftFn: (number: number) => boolean, continueRightFn: (number: number) => boolean): void;
117
- private nodeWalkExactMatchesBackward;
118
- put(key: TKey, data: TData, conflict?: ConflictAction<TKey, TData>): void;
119
- private nodePut;
120
- private updateLocal;
121
- private nodeRemoveMin;
122
- remove(key: TKey): void;
123
- removeExisting(key: TKey): void;
124
- private nodeRemove;
125
- /**
126
- * Finds the largest node that is less than or equal to a given key.
127
- */
128
- floor(key: TKey): RBNode<TKey, TData> | undefined;
129
- private nodeFloor;
130
- /**
131
- * Finds the smallest node that is greater than or equal to a given key.
132
- */
133
- ceil(key: TKey): RBNode<TKey, TData> | undefined;
134
- private nodeCeil;
135
- min(): RBNode<TKey, TData> | undefined;
136
- private nodeMin;
137
- max(): RBNode<TKey, TData> | undefined;
138
- private nodeMax;
139
- private rotateRight;
140
- private rotateLeft;
141
- private oppositeColor;
142
- private flipColors;
143
- private moveRedLeft;
144
- private moveRedRight;
145
- private balance;
146
- mapRange<TAccum>(action: PropertyAction<TKey, TData>, accum?: TAccum, start?: TKey, end?: TKey): void;
147
- map<TAccum>(action: PropertyAction<TKey, TData>, accum?: TAccum): void;
148
- keys(): TKey[];
149
- /**
150
- * Depth-first traversal with custom action; if action returns
151
- * false, traversal is halted.
152
- * @param action - action to apply to each node
153
- */
154
- walk(actions: RBNodeActions<TKey, TData>): void;
155
- walkBackward(actions: RBNodeActions<TKey, TData>): void;
156
- private nodeWalk;
157
- private nodeWalkBackward;
158
- private nodeMap;
159
-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