@fluidframework/tree 2.82.0 → 2.83.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/README.md +33 -5
- package/api-report/tree.alpha.api.md +25 -21
- package/api-report/tree.beta.api.md +14 -2
- package/api-report/tree.legacy.beta.api.md +14 -2
- package/api-report/tree.legacy.public.api.md +1 -1
- package/api-report/tree.public.api.md +1 -1
- package/dist/alpha.d.ts +3 -3
- package/dist/beta.d.ts +1 -0
- package/dist/codec/codec.d.ts +3 -39
- package/dist/codec/codec.d.ts.map +1 -1
- package/dist/codec/codec.js +5 -50
- package/dist/codec/codec.js.map +1 -1
- package/dist/codec/index.d.ts +1 -1
- package/dist/codec/index.d.ts.map +1 -1
- package/dist/codec/index.js +1 -2
- package/dist/codec/index.js.map +1 -1
- package/dist/codec/versioned/codec.d.ts +20 -7
- package/dist/codec/versioned/codec.d.ts.map +1 -1
- package/dist/codec/versioned/codec.js +56 -30
- package/dist/codec/versioned/codec.js.map +1 -1
- package/dist/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -1
- package/dist/core/tree/detachedFieldIndexCodecs.js +6 -4
- package/dist/core/tree/detachedFieldIndexCodecs.js.map +1 -1
- package/dist/extensibleUnionNode.d.ts +97 -0
- package/dist/extensibleUnionNode.d.ts.map +1 -0
- package/dist/{extensibleSchemaUnion.js → extensibleUnionNode.js} +28 -18
- package/dist/extensibleUnionNode.js.map +1 -0
- package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts +1 -1
- package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/codecs.js +4 -4
- package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
- package/dist/feature-libraries/forest-summary/codec.d.ts.map +1 -1
- package/dist/feature-libraries/forest-summary/codec.js +7 -1
- package/dist/feature-libraries/forest-summary/codec.js.map +1 -1
- package/dist/feature-libraries/forest-summary/formatCommon.d.ts +3 -3
- package/dist/feature-libraries/forest-summary/formatCommon.d.ts.map +1 -1
- package/dist/feature-libraries/forest-summary/formatCommon.js.map +1 -1
- package/dist/feature-libraries/forest-summary/formatV1.d.ts +2 -3
- package/dist/feature-libraries/forest-summary/formatV1.d.ts.map +1 -1
- package/dist/feature-libraries/forest-summary/formatV1.js +1 -2
- package/dist/feature-libraries/forest-summary/formatV1.js.map +1 -1
- package/dist/feature-libraries/forest-summary/formatV2.d.ts +2 -3
- package/dist/feature-libraries/forest-summary/formatV2.d.ts.map +1 -1
- package/dist/feature-libraries/forest-summary/formatV2.js +1 -2
- package/dist/feature-libraries/forest-summary/formatV2.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeCodecV1.d.ts +2 -2
- package/dist/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js +4 -4
- package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -1
- package/dist/feature-libraries/schema-index/codec.d.ts.map +1 -1
- package/dist/feature-libraries/schema-index/codec.js +6 -4
- package/dist/feature-libraries/schema-index/codec.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/legacy.d.ts +1 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/shared-tree/sharedTreeChangeCodecs.js +1 -1
- package/dist/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
- package/dist/shared-tree/tree.d.ts +1 -1
- package/dist/shared-tree/tree.js.map +1 -1
- package/dist/shared-tree/treeAlpha.d.ts +1 -1
- package/dist/shared-tree/treeAlpha.js.map +1 -1
- package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
- package/dist/shared-tree/treeCheckout.js +2 -4
- package/dist/shared-tree/treeCheckout.js.map +1 -1
- package/dist/shared-tree-core/editManagerCodecsCommons.d.ts +3 -3
- package/dist/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -1
- package/dist/shared-tree-core/editManagerCodecsCommons.js +2 -2
- package/dist/shared-tree-core/editManagerCodecsCommons.js.map +1 -1
- package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts +2 -2
- package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -1
- package/dist/shared-tree-core/editManagerCodecsV1toV4.js +1 -1
- package/dist/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -1
- package/dist/shared-tree-core/editManagerCodecsVSharedBranches.d.ts +2 -2
- package/dist/shared-tree-core/editManagerCodecsVSharedBranches.d.ts.map +1 -1
- package/dist/shared-tree-core/editManagerCodecsVSharedBranches.js +1 -1
- package/dist/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
- package/dist/shared-tree-core/messageCodecs.d.ts.map +1 -1
- package/dist/shared-tree-core/messageCodecs.js +2 -2
- package/dist/shared-tree-core/messageCodecs.js.map +1 -1
- package/dist/simple-tree/api/index.d.ts +1 -1
- package/dist/simple-tree/api/index.d.ts.map +1 -1
- package/dist/simple-tree/api/index.js +2 -2
- package/dist/simple-tree/api/index.js.map +1 -1
- package/dist/simple-tree/api/snapshotCompatibilityChecker.d.ts +148 -29
- package/dist/simple-tree/api/snapshotCompatibilityChecker.d.ts.map +1 -1
- package/dist/simple-tree/api/snapshotCompatibilityChecker.js +180 -99
- package/dist/simple-tree/api/snapshotCompatibilityChecker.js.map +1 -1
- package/dist/simple-tree/api/tree.d.ts +1 -1
- package/dist/simple-tree/api/tree.js.map +1 -1
- package/dist/simple-tree/api/treeBeta.d.ts +1 -1
- package/dist/simple-tree/api/treeBeta.js.map +1 -1
- package/dist/simple-tree/core/allowedTypes.d.ts +1 -1
- package/dist/simple-tree/core/allowedTypes.js.map +1 -1
- package/dist/simple-tree/core/unhydratedFlexTree.d.ts +1 -0
- package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
- package/dist/simple-tree/core/unhydratedFlexTree.js +29 -0
- package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/dist/simple-tree/index.d.ts +1 -1
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js +2 -2
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.js +4 -13
- package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
- package/dist/simple-tree/unhydratedFlexTreeFromInsertable.d.ts.map +1 -1
- package/dist/simple-tree/unhydratedFlexTreeFromInsertable.js +33 -7
- package/dist/simple-tree/unhydratedFlexTreeFromInsertable.js.map +1 -1
- package/dist/text/textDomainFormatted.d.ts +3 -3
- package/dist/text/textDomainFormatted.d.ts.map +1 -1
- package/dist/text/textDomainFormatted.js +48 -32
- package/dist/text/textDomainFormatted.js.map +1 -1
- package/dist/util/bTreeUtils.d.ts.map +1 -1
- package/dist/util/bTreeUtils.js +6 -6
- package/dist/util/bTreeUtils.js.map +1 -1
- package/dist/util/rangeMap.d.ts.map +1 -1
- package/dist/util/rangeMap.js +5 -6
- package/dist/util/rangeMap.js.map +1 -1
- package/lib/alpha.d.ts +3 -3
- package/lib/beta.d.ts +1 -0
- package/lib/codec/codec.d.ts +3 -39
- package/lib/codec/codec.d.ts.map +1 -1
- package/lib/codec/codec.js +4 -47
- package/lib/codec/codec.js.map +1 -1
- package/lib/codec/index.d.ts +1 -1
- package/lib/codec/index.d.ts.map +1 -1
- package/lib/codec/index.js +1 -1
- package/lib/codec/index.js.map +1 -1
- package/lib/codec/versioned/codec.d.ts +20 -7
- package/lib/codec/versioned/codec.d.ts.map +1 -1
- package/lib/codec/versioned/codec.js +59 -33
- package/lib/codec/versioned/codec.js.map +1 -1
- package/lib/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -1
- package/lib/core/tree/detachedFieldIndexCodecs.js +6 -4
- package/lib/core/tree/detachedFieldIndexCodecs.js.map +1 -1
- package/lib/extensibleUnionNode.d.ts +97 -0
- package/lib/extensibleUnionNode.d.ts.map +1 -0
- package/lib/{extensibleSchemaUnion.js → extensibleUnionNode.js} +28 -18
- package/lib/extensibleUnionNode.js.map +1 -0
- package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts +1 -1
- package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/codecs.js +5 -5
- package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
- package/lib/feature-libraries/forest-summary/codec.d.ts.map +1 -1
- package/lib/feature-libraries/forest-summary/codec.js +8 -2
- package/lib/feature-libraries/forest-summary/codec.js.map +1 -1
- package/lib/feature-libraries/forest-summary/formatCommon.d.ts +3 -3
- package/lib/feature-libraries/forest-summary/formatCommon.d.ts.map +1 -1
- package/lib/feature-libraries/forest-summary/formatCommon.js.map +1 -1
- package/lib/feature-libraries/forest-summary/formatV1.d.ts +2 -3
- package/lib/feature-libraries/forest-summary/formatV1.d.ts.map +1 -1
- package/lib/feature-libraries/forest-summary/formatV1.js +1 -2
- package/lib/feature-libraries/forest-summary/formatV1.js.map +1 -1
- package/lib/feature-libraries/forest-summary/formatV2.d.ts +2 -3
- package/lib/feature-libraries/forest-summary/formatV2.d.ts.map +1 -1
- package/lib/feature-libraries/forest-summary/formatV2.js +1 -2
- package/lib/feature-libraries/forest-summary/formatV2.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeCodecV1.d.ts +2 -2
- package/lib/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js +4 -4
- package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -1
- package/lib/feature-libraries/schema-index/codec.d.ts.map +1 -1
- package/lib/feature-libraries/schema-index/codec.js +6 -4
- package/lib/feature-libraries/schema-index/codec.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/legacy.d.ts +1 -0
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/shared-tree/sharedTreeChangeCodecs.js +1 -1
- package/lib/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
- package/lib/shared-tree/tree.d.ts +1 -1
- package/lib/shared-tree/tree.js.map +1 -1
- package/lib/shared-tree/treeAlpha.d.ts +1 -1
- package/lib/shared-tree/treeAlpha.js.map +1 -1
- package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
- package/lib/shared-tree/treeCheckout.js +2 -4
- package/lib/shared-tree/treeCheckout.js.map +1 -1
- package/lib/shared-tree-core/editManagerCodecsCommons.d.ts +3 -3
- package/lib/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -1
- package/lib/shared-tree-core/editManagerCodecsCommons.js +2 -2
- package/lib/shared-tree-core/editManagerCodecsCommons.js.map +1 -1
- package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts +2 -2
- package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -1
- package/lib/shared-tree-core/editManagerCodecsV1toV4.js +2 -2
- package/lib/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -1
- package/lib/shared-tree-core/editManagerCodecsVSharedBranches.d.ts +2 -2
- package/lib/shared-tree-core/editManagerCodecsVSharedBranches.d.ts.map +1 -1
- package/lib/shared-tree-core/editManagerCodecsVSharedBranches.js +2 -2
- package/lib/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
- package/lib/shared-tree-core/messageCodecs.d.ts.map +1 -1
- package/lib/shared-tree-core/messageCodecs.js +2 -2
- package/lib/shared-tree-core/messageCodecs.js.map +1 -1
- package/lib/simple-tree/api/index.d.ts +1 -1
- package/lib/simple-tree/api/index.d.ts.map +1 -1
- package/lib/simple-tree/api/index.js +1 -1
- package/lib/simple-tree/api/index.js.map +1 -1
- package/lib/simple-tree/api/snapshotCompatibilityChecker.d.ts +148 -29
- package/lib/simple-tree/api/snapshotCompatibilityChecker.d.ts.map +1 -1
- package/lib/simple-tree/api/snapshotCompatibilityChecker.js +179 -98
- package/lib/simple-tree/api/snapshotCompatibilityChecker.js.map +1 -1
- package/lib/simple-tree/api/tree.d.ts +1 -1
- package/lib/simple-tree/api/tree.js.map +1 -1
- package/lib/simple-tree/api/treeBeta.d.ts +1 -1
- package/lib/simple-tree/api/treeBeta.js.map +1 -1
- package/lib/simple-tree/core/allowedTypes.d.ts +1 -1
- package/lib/simple-tree/core/allowedTypes.js.map +1 -1
- package/lib/simple-tree/core/unhydratedFlexTree.d.ts +1 -0
- package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
- package/lib/simple-tree/core/unhydratedFlexTree.js +29 -0
- package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/lib/simple-tree/index.d.ts +1 -1
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js +1 -1
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.js +5 -14
- package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
- package/lib/simple-tree/unhydratedFlexTreeFromInsertable.d.ts.map +1 -1
- package/lib/simple-tree/unhydratedFlexTreeFromInsertable.js +34 -8
- package/lib/simple-tree/unhydratedFlexTreeFromInsertable.js.map +1 -1
- package/lib/text/textDomainFormatted.d.ts +3 -3
- package/lib/text/textDomainFormatted.d.ts.map +1 -1
- package/lib/text/textDomainFormatted.js +30 -14
- package/lib/text/textDomainFormatted.js.map +1 -1
- package/lib/util/bTreeUtils.d.ts.map +1 -1
- package/lib/util/bTreeUtils.js +6 -6
- package/lib/util/bTreeUtils.js.map +1 -1
- package/lib/util/rangeMap.d.ts.map +1 -1
- package/lib/util/rangeMap.js +5 -6
- package/lib/util/rangeMap.js.map +1 -1
- package/package.json +23 -23
- package/src/codec/codec.ts +10 -112
- package/src/codec/index.ts +0 -3
- package/src/codec/versioned/codec.ts +119 -83
- package/src/core/tree/detachedFieldIndexCodecs.ts +6 -4
- package/src/{extensibleSchemaUnion.ts → extensibleUnionNode.ts} +61 -19
- package/src/feature-libraries/chunked-forest/codec/codecs.ts +5 -11
- package/src/feature-libraries/forest-summary/codec.ts +8 -7
- package/src/feature-libraries/forest-summary/formatCommon.ts +5 -3
- package/src/feature-libraries/forest-summary/formatV1.ts +1 -3
- package/src/feature-libraries/forest-summary/formatV2.ts +1 -3
- package/src/feature-libraries/modular-schema/modularChangeCodecV1.ts +5 -6
- package/src/feature-libraries/schema-index/codec.ts +6 -4
- package/src/index.ts +3 -3
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/sharedTreeChangeCodecs.ts +2 -2
- package/src/shared-tree/tree.ts +1 -1
- package/src/shared-tree/treeAlpha.ts +1 -1
- package/src/shared-tree/treeCheckout.ts +2 -4
- package/src/shared-tree-core/editManagerCodecsCommons.ts +7 -7
- package/src/shared-tree-core/editManagerCodecsV1toV4.ts +3 -10
- package/src/shared-tree-core/editManagerCodecsVSharedBranches.ts +3 -10
- package/src/shared-tree-core/messageCodecs.ts +2 -6
- package/src/simple-tree/api/index.ts +2 -2
- package/src/simple-tree/api/snapshotCompatibilityChecker.ts +344 -142
- package/src/simple-tree/api/tree.ts +1 -1
- package/src/simple-tree/api/treeBeta.ts +1 -1
- package/src/simple-tree/core/allowedTypes.ts +1 -1
- package/src/simple-tree/core/unhydratedFlexTree.ts +43 -1
- package/src/simple-tree/index.ts +2 -2
- package/src/simple-tree/node-kinds/array/arrayNode.ts +13 -19
- package/src/simple-tree/unhydratedFlexTreeFromInsertable.ts +51 -10
- package/src/text/textDomainFormatted.ts +37 -17
- package/src/util/bTreeUtils.ts +10 -6
- package/src/util/rangeMap.ts +9 -6
- package/api-extractor-lint.json +0 -4
- package/dist/extensibleSchemaUnion.d.ts +0 -72
- package/dist/extensibleSchemaUnion.d.ts.map +0 -1
- package/dist/extensibleSchemaUnion.js.map +0 -1
- package/lib/extensibleSchemaUnion.d.ts +0 -72
- package/lib/extensibleSchemaUnion.d.ts.map +0 -1
- package/lib/extensibleSchemaUnion.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../../src/codec/versioned/codec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EACN,uCAAuC,GAIvC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,IAAI,EAAgB,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAKrD,OAAO,EAIN,oBAAoB,EAKpB,oBAAoB,GAEpB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAOxC,SAAS,kBAAkB,CAM1B,iBAAqC,EACrC,EAAE,aAAa,EAAE,SAAS,EAAiB,EAC3C,KAA0D;IAE1D,MAAM,KAAK,GAAG;QACb,MAAM,EAAE,CAAC,IAAc,EAAE,OAAiB,EAAY,EAAE;YACvD,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC5C,MAAM,CACL,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,EACtC,KAAK,CAAC,+CAA+C,CACrD,CAAC;YACF,OAAO,OAAO,CAAC;QAChB,CAAC;QACD,MAAM,EAAE,CAAC,IAAe,EAAE,OAAiB,EAAY,EAAE;YACxD,MAAM,SAAS,GAAG,IAAiB,CAAC,CAAC,oCAAoC;YACzE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AED,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,MAAM,MAAM,GAAM,uCAAuC,CACxD,OAAO,CAAC,mBAAmB,EAC3B,QAAQ,CACR,CAAC;IACF,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CACnB,QAGG;IAEH,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AACnF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { MinimumVersionForCollab } from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tgetConfigForMinVersionForCollabIterable,\n\ttype ConfigMapEntry,\n\ttype MinimumMinorSemanticVersion,\n\ttype SemanticVersion,\n} from \"@fluidframework/runtime-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { Type, type TSchema } from \"@sinclair/typebox\";\nimport { gt } from \"semver-ts\";\n\nimport { pkgVersion } from \"../../packageVersion.js\";\nimport type {\n\tJsonCompatibleReadOnly,\n\tJsonCompatibleReadOnlyObject,\n} from \"../../util/index.js\";\nimport {\n\ttype ICodecFamily,\n\ttype ICodecOptions,\n\ttype IJsonCodec,\n\twithSchemaValidation,\n\ttype FormatVersion,\n\ttype CodecWriteOptions,\n\ttype IMultiFormatCodec,\n\ttype CodecName,\n\tensureBinaryEncoding,\n\ttype CodecTree,\n} from \"../codec.js\";\n\nimport { Versioned } from \"./format.js\";\n\n/**\n * Json compatible data with a format version.\n */\ntype VersionedJson = JsonCompatibleReadOnlyObject & Versioned;\n\nfunction makeVersionedCodec<\n\tTDecoded,\n\tTEncoded extends Versioned = VersionedJson,\n\tTValidate = TEncoded,\n\tTContext = void,\n>(\n\tsupportedVersions: Set<FormatVersion>,\n\t{ jsonValidator: validator }: ICodecOptions,\n\tinner: IJsonCodec<TDecoded, TEncoded, TValidate, TContext>,\n): IJsonCodec<TDecoded, TEncoded, TValidate, TContext> {\n\tconst codec = {\n\t\tencode: (data: TDecoded, context: TContext): TEncoded => {\n\t\t\tconst encoded = inner.encode(data, context);\n\t\t\tassert(\n\t\t\t\tsupportedVersions.has(encoded.version),\n\t\t\t\t0x88b /* version being encoded should be supported */,\n\t\t\t);\n\t\t\treturn encoded;\n\t\t},\n\t\tdecode: (data: TValidate, context: TContext): TDecoded => {\n\t\t\tconst versioned = data as Versioned; // Validated by withSchemaValidation\n\t\t\tif (!supportedVersions.has(versioned.version)) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Unsupported version ${versioned.version} encountered while decoding data. Supported versions for this data are: ${[...supportedVersions].join(\", \")}.\nThe client which encoded this data likely specified an \"minVersionForCollab\" value which corresponds to a version newer than the version of this client (\"${pkgVersion}\").`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst decoded = inner.decode(data, context);\n\t\t\treturn decoded;\n\t\t},\n\t};\n\n\treturn supportedVersions.has(undefined)\n\t\t? codec\n\t\t: withSchemaValidation(Versioned, codec, validator);\n}\n\n/**\n * TODO: users of this should migrate to {@link ClientVersionDispatchingCodecBuilder}.\n */\nexport function makeVersionedValidatedCodec<\n\tEncodedSchema extends TSchema,\n\tTDecoded,\n\tTEncoded extends Versioned = VersionedJson,\n\tTValidate = TEncoded,\n\tTContext = void,\n>(\n\toptions: ICodecOptions,\n\tsupportedVersions: Set<FormatVersion>,\n\tschema: EncodedSchema,\n\tcodec: IJsonCodec<TDecoded, TEncoded, TValidate, TContext>,\n): IJsonCodec<TDecoded, TEncoded, TValidate, TContext> {\n\treturn makeVersionedCodec(\n\t\tsupportedVersions,\n\t\toptions,\n\t\twithSchemaValidation(schema, codec, options.jsonValidator),\n\t);\n}\n\n/**\n * Creates a codec which always throws a UsageError when encoding or decoding, indicating that the format version is discontinued.\n *\n * TODO: {@link ClientVersionDispatchingCodecBuilder} should get support for extra decode only entries and/or unstable formats (codecs without a minVersionForCollab that will never be selected for write unless overridden).\n * Once done, users of this should migrate to ClientVersionDispatchingCodecBuilder and this function can be simplified.\n */\nexport function makeDiscontinuedCodecVersion<\n\tTDecoded,\n\tTEncoded extends Versioned = VersionedJson,\n\tTContext = unknown,\n>(\n\toptions: ICodecOptions,\n\tdiscontinuedVersion: FormatVersion,\n\tdiscontinuedSince: SemanticVersion,\n): IJsonCodec<TDecoded, TEncoded, TEncoded, TContext> {\n\tconst schema = Type.Object(\n\t\t{\n\t\t\tversion:\n\t\t\t\tdiscontinuedVersion === undefined\n\t\t\t\t\t? Type.Undefined()\n\t\t\t\t\t: Type.Literal(discontinuedVersion),\n\t\t},\n\t\t// Using `additionalProperties: true` allows this schema to be used when loading data encoded by older versions even though they contain additional properties.\n\t\t{ additionalProperties: true },\n\t);\n\tconst codec: IJsonCodec<TDecoded, TEncoded, TEncoded, TContext> = {\n\t\tencode: (_: TDecoded): TEncoded => {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Cannot encode data to format ${discontinuedVersion}. The codec was discontinued in Fluid Framework client version ${discontinuedSince}.`,\n\t\t\t);\n\t\t},\n\t\tdecode: (data: TEncoded): TDecoded => {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Cannot decode data to format ${data.version}. The codec was discontinued in Fluid Framework client version ${discontinuedSince}.`,\n\t\t\t);\n\t\t},\n\t};\n\treturn makeVersionedValidatedCodec(options, new Set([discontinuedVersion]), schema, codec);\n}\n\n/**\n * Creates a codec which dispatches to the appropriate member of a codec family based on the version of\n * data it encounters.\n * @remarks\n * Each member of the codec family must write an explicit version number into the data it encodes (implementing {@link Versioned}).\n *\n * TODO: Users of this should migrate to {@link ClientVersionDispatchingCodecBuilder} so that the actual format version used can be encapsulated.\n */\nexport function makeVersionDispatchingCodec<TDecoded, TContext>(\n\tfamily: ICodecFamily<TDecoded, TContext>,\n\toptions: ICodecOptions & { writeVersion: FormatVersion },\n): IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext> {\n\tconst writeCodec = family.resolve(options.writeVersion).json;\n\tconst supportedVersions = new Set(family.getSupportedFormats());\n\treturn makeVersionedCodec(supportedVersions, options, {\n\t\tencode(data, context): Versioned {\n\t\t\treturn writeCodec.encode(data, context) as Versioned;\n\t\t},\n\t\tdecode(data: Versioned, context) {\n\t\t\tconst codec = family.resolve(data.version);\n\t\t\treturn codec.json.decode(data, context);\n\t\t},\n\t});\n}\n\n/**\n * A friendly format for codec authors use to define their codec and schema for use in {@link CodecVersion}.\n * @remarks\n * The codec should not perform its own schema validation.\n * The schema validation gets added when normalizing to {@link NormalizedCodecVersion}.\n */\nexport type CodecAndSchema<TDecoded, TContext = void> = { readonly schema: TSchema } & (\n\t| IMultiFormatCodec<TDecoded, VersionedJson, JsonCompatibleReadOnly, TContext>\n\t| IJsonCodec<TDecoded, VersionedJson, JsonCompatibleReadOnly, TContext>\n);\n\n/**\n * A codec alongside its format version and schema.\n */\nexport interface CodecVersionBase<\n\tT = unknown,\n\tTFormatVersion extends FormatVersion = FormatVersion,\n> {\n\treadonly formatVersion: TFormatVersion;\n\treadonly codec: T;\n}\n\n/**\n * A particular version of a codec and when to use it.\n * @privateRemarks\n * This allows lazy building of the codec with options.\n * This option can likely be removed as the codec handling is made simpler and more consistent.\n * Removing support for this laziness would be nice to help prevent unexpected coupling and alteration to codec behavior,\n * helping ensure that tests and production code behave the same.\n */\nexport interface CodecVersion<\n\tTDecoded,\n\tTContext,\n\tTFormatVersion extends FormatVersion,\n\tTBuildOptions extends CodecWriteOptions,\n> extends CodecVersionBase<\n\t\t| CodecAndSchema<TDecoded, TContext>\n\t\t| ((options: TBuildOptions) => CodecAndSchema<TDecoded, TContext>),\n\t\tTFormatVersion\n\t> {}\n\n/**\n * {@link CodecVersion} after normalization into a consistent type.\n * @remarks\n * Produced by {@link normalizeCodecVersion}.\n * Includes schema validation.\n */\nexport interface NormalizedCodecVersion<\n\tTDecoded,\n\tTContext,\n\tTFormatVersion extends FormatVersion,\n\tTBuildOptions extends CodecWriteOptions,\n> extends CodecVersionBase<\n\t\t(\n\t\t\toptions: TBuildOptions,\n\t\t) => IJsonCodec<TDecoded, VersionedJson, JsonCompatibleReadOnly, TContext>,\n\t\tTFormatVersion\n\t> {}\n\n/**\n * {@link NormalizedCodecVersion} after applying the build options.\n * @remarks\n * Produced by {@link ClientVersionDispatchingCodecBuilder.applyOptions}.\n */\nexport interface EvaluatedCodecVersion<\n\tTDecoded,\n\tTContext,\n\tTFormatVersion extends FormatVersion,\n> extends CodecVersionBase<\n\t\tIJsonCodec<TDecoded, VersionedJson, JsonCompatibleReadOnly, TContext>,\n\t\tTFormatVersion\n\t> {}\n\n/**\n * Normalize the codec to a single format.\n * @remarks\n * Bakes in schema validation, so output no longer exposes the schema.\n */\nfunction normalizeCodecVersion<\n\tTDecoded,\n\tTContext,\n\tTFormatVersion extends FormatVersion,\n\tTBuildOptions extends CodecWriteOptions,\n>(\n\tcodecVersion: CodecVersion<TDecoded, TContext, TFormatVersion, TBuildOptions>,\n): NormalizedCodecVersion<TDecoded, TContext, TFormatVersion, TBuildOptions> {\n\tconst codecBuilder: (options: TBuildOptions) => CodecAndSchema<TDecoded, TContext> =\n\t\ttypeof codecVersion.codec === \"function\"\n\t\t\t? codecVersion.codec\n\t\t\t: () => codecVersion.codec as CodecAndSchema<TDecoded, TContext>;\n\tconst codec = (\n\t\toptions: TBuildOptions,\n\t): IJsonCodec<TDecoded, VersionedJson, JsonCompatibleReadOnly, TContext> => {\n\t\tconst built = codecBuilder(options);\n\t\t// We currently don't expose or use binary formats, but someday we might.\n\t\tconst multiFormat = ensureBinaryEncoding<TDecoded, TContext, VersionedJson>(built);\n\t\treturn makeVersionedValidatedCodec(\n\t\t\toptions,\n\t\t\tnew Set([codecVersion.formatVersion]),\n\t\t\tbuilt.schema,\n\t\t\tmultiFormat.json,\n\t\t);\n\t};\n\n\treturn {\n\t\tformatVersion: codecVersion.formatVersion,\n\t\tcodec,\n\t};\n}\n\n/**\n * Creates a codec which dispatches to the appropriate member of a codec family based on the `minVersionForCollab` for encode and the\n * version number in data it encounters for decode.\n * @privateRemarks\n * This is a two stage builder so the first stage can encapsulate all codec specific details and the second can bring in configuration.\n */\nexport class ClientVersionDispatchingCodecBuilder<\n\tName extends CodecName,\n\tTDecoded,\n\tTContext,\n\tTFormatVersion extends FormatVersion,\n\tTBuildOptions extends CodecWriteOptions,\n> {\n\tpublic readonly registry: ReadonlyMap<\n\t\tMinimumVersionForCollab,\n\t\tNormalizedCodecVersion<TDecoded, TContext, TFormatVersion, TBuildOptions>\n\t>;\n\n\t/**\n\t * Use {@link ClientVersionDispatchingCodecBuilder.build} to create an instance of this class.\n\t */\n\tprivate constructor(\n\t\t/**\n\t\t * See {@link CodecName}.\n\t\t */\n\t\tpublic readonly name: Name,\n\t\t/**\n\t\t * The registry of codecs which this builder can use to encode and decode data.\n\t\t */\n\t\tinputRegistry: ConfigMapEntry<\n\t\t\tCodecVersion<TDecoded, TContext, TFormatVersion, TBuildOptions>\n\t\t>,\n\t) {\n\t\ttype Normalized = NormalizedCodecVersion<\n\t\t\tTDecoded,\n\t\t\tTContext,\n\t\t\tTFormatVersion,\n\t\t\tTBuildOptions\n\t\t>;\n\t\tconst normalizedRegistry = new Map<MinimumVersionForCollab, Normalized>();\n\n\t\tfor (const [minVersionForCollab, codec] of Object.entries(inputRegistry) as Iterable<\n\t\t\t[\n\t\t\t\tMinimumVersionForCollab,\n\t\t\t\tCodecVersion<TDecoded, TContext, TFormatVersion, TBuildOptions>,\n\t\t\t]\n\t\t>) {\n\t\t\tconst normalizedCodec = normalizeCodecVersion(codec);\n\t\t\tnormalizedRegistry.set(minVersionForCollab, normalizedCodec);\n\t\t}\n\n\t\tthis.registry = normalizedRegistry;\n\t}\n\n\t/**\n\t * Applies the provided options to the codec registry to produce a list of evaluated codecs.\n\t * @remarks\n\t * This is used by build, which is what production code should use.\n\t * This is only exposed for testing purposes.\n\t */\n\tpublic applyOptions(\n\t\toptions: TBuildOptions,\n\t): [MinimumVersionForCollab, EvaluatedCodecVersion<TDecoded, TContext, TFormatVersion>][] {\n\t\treturn Array.from(\n\t\t\tthis.registry,\n\t\t\t([version, codec]) =>\n\t\t\t\t[\n\t\t\t\t\tversion,\n\t\t\t\t\t{\n\t\t\t\t\t\tformatVersion: codec.formatVersion,\n\t\t\t\t\t\tcodec: codec.codec(options),\n\t\t\t\t\t},\n\t\t\t\t] as const,\n\t\t);\n\t}\n\n\t/**\n\t * Produce a single codec which can read any supported format, and writes a version selected based on the provided options.\n\t */\n\tpublic build(\n\t\toptions: TBuildOptions,\n\t): IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext> {\n\t\tconst applied = this.applyOptions(options);\n\t\tconst writeVersion = getWriteVersion(this.name, options, applied);\n\t\tconst fromFormatVersion = new Map<\n\t\t\tFormatVersion,\n\t\t\tEvaluatedCodecVersion<TDecoded, TContext, TFormatVersion>\n\t\t>(applied.map(([_version, codec]) => [codec.formatVersion, codec]));\n\t\treturn {\n\t\t\tencode: (data: TDecoded, context: TContext): JsonCompatibleReadOnly => {\n\t\t\t\treturn writeVersion.codec.encode(data, context);\n\t\t\t},\n\t\t\tdecode: (data: JsonCompatibleReadOnly, context: TContext): TDecoded => {\n\t\t\t\tconst versioned = data as Partial<Versioned>;\n\t\t\t\tconst codec = fromFormatVersion.get(versioned.version);\n\t\t\t\tif (codec === undefined) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t`Unsupported version ${versioned.version} encountered while decoding ${this.name} data. Supported versions for this data are: ${versionList(applied)}.\nThe client which encoded this data likely specified an \"minVersionForCollab\" value which corresponds to a version newer than the version of this client (\"${pkgVersion}\").`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn codec.codec.decode(data, context);\n\t\t\t},\n\t\t};\n\t}\n\n\tpublic getCodecTree(clientVersion: MinimumVersionForCollab): CodecTree {\n\t\t// TODO: add support for children codecs.\n\t\tconst selected = getConfigForMinVersionForCollabIterable(clientVersion, this.registry);\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tversion: selected.formatVersion,\n\t\t};\n\t}\n\n\t/**\n\t * Builds a ClientVersionDispatchingCodecBuilder from the provided registry.\n\t * @remarks\n\t * This static method infers the types of the builder from the provided registry,\n\t * making it easier to create builders without needing to explicitly specify all type parameters.\n\t * This gets better type inference than the constructor.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tpublic static build<\n\t\tName extends CodecName,\n\t\tEntry extends CodecVersion<unknown, unknown, FormatVersion, never>,\n\t>(name: Name, inputRegistry: ConfigMapEntry<Entry>) {\n\t\ttype TDecoded2 =\n\t\t\tEntry extends CodecVersion<infer D, unknown, FormatVersion, never> ? D : never;\n\t\ttype TContext2 =\n\t\t\tEntry extends CodecVersion<unknown, infer C, FormatVersion, never> ? C : never;\n\t\ttype TFormatVersion2 =\n\t\t\tEntry extends CodecVersion<unknown, unknown, infer F, never> ? F : never;\n\t\ttype TBuildOptions2 =\n\t\t\tEntry extends CodecVersion<unknown, unknown, FormatVersion, infer B> ? B : never;\n\t\tconst builder = new ClientVersionDispatchingCodecBuilder(\n\t\t\tname,\n\t\t\tinputRegistry as ConfigMapEntry<unknown> as ConfigMapEntry<\n\t\t\t\tCodecVersion<\n\t\t\t\t\tTDecoded2,\n\t\t\t\t\t// If it does not matter what context is provided, undefined is fine, so allow it to be omitted.\n\t\t\t\t\tunknown extends TContext2 ? void : TContext2,\n\t\t\t\t\tTFormatVersion2,\n\t\t\t\t\tTBuildOptions2\n\t\t\t\t>\n\t\t\t>,\n\t\t);\n\t\treturn builder;\n\t}\n}\n\n/**\n * Selects which format should be used when writing data.\n * @remarks\n * This either uses the override specified in the options, or selects the newest format compatible with the provided minVersionForCollab.\n */\nfunction getWriteVersion<T extends CodecVersionBase>(\n\tname: CodecName,\n\toptions: CodecWriteOptions,\n\tversions: readonly [MinimumMinorSemanticVersion | MinimumVersionForCollab, T][],\n): T {\n\tif (options.writeVersionOverrides?.has(name) === true) {\n\t\tconst selectedFormatVersion = options.writeVersionOverrides.get(name);\n\t\tconst selected = versions.find(\n\t\t\t([_v, codec]) => codec.formatVersion === selectedFormatVersion,\n\t\t);\n\t\tif (selected === undefined) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Codec \"${name}\" does not support requested format version ${selectedFormatVersion}. Supported versions are: ${versionList(versions)}.`,\n\t\t\t);\n\t\t} else if (options.allowPossiblyIncompatibleWriteVersionOverrides !== true) {\n\t\t\tconst selectedMinVersionForCollab = selected[0];\n\t\t\t// Currently all versions must specify a minVersionForCollab, so undefined is not expected here.\n\t\t\t// TODO: It should be possible to have a version which would never be automatically selected for write (and thus does not have or need a minVersionForCollab), but can be selected via override.\n\t\t\t// Use-cases for this include experimental versions not yet stable, and discontinued or intermediate versions which are mainly being kept for read compatibility but still support writing (perhaps for round-trip testing).\n\t\t\t// For now, this check should never pass, and there is no way to create such a version yet.\n\t\t\tif (selectedMinVersionForCollab === undefined) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Codec \"${name}\" does not support requested format version ${selectedFormatVersion} because it does not specify a minVersionForCollab. Use \"allowPossiblyIncompatibleWriteVersionOverrides\" to suppress this error if appropriate.`,\n\t\t\t\t);\n\t\t\t} else if (gt(selectedMinVersionForCollab, options.minVersionForCollab)) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Codec \"${name}\" does not support requested format version ${selectedFormatVersion} because it is only compatible back to client version ${selectedMinVersionForCollab} and the requested oldest compatible client was ${options.minVersionForCollab}. Use \"allowPossiblyIncompatibleWriteVersionOverrides\" to suppress this error if appropriate.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn selected[1];\n\t}\n\tconst result: T = getConfigForMinVersionForCollabIterable(\n\t\toptions.minVersionForCollab,\n\t\tversions,\n\t);\n\treturn result;\n}\n\n/**\n * Formats a list of versions for use in UsageErrors.\n */\nfunction versionList(\n\tversions: readonly [\n\t\tMinimumMinorSemanticVersion | MinimumVersionForCollab,\n\t\tCodecVersionBase,\n\t][],\n): string {\n\treturn `${Array.from(versions, ([_v, codec]) => codec.formatVersion).join(\", \")}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../../src/codec/versioned/codec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAE1E,OAAO,EACN,uCAAuC,EACvC,yBAAyB,GAGzB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,IAAI,EAAgB,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAKrD,OAAO,EAIN,oBAAoB,GAKpB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAOxC,SAAS,kBAAkB,CAM1B,iBAAqC,EACrC,EAAE,aAAa,EAAE,SAAS,EAAiB,EAC3C,KAA0D;IAE1D,MAAM,KAAK,GAAG;QACb,MAAM,EAAE,CAAC,IAAc,EAAE,OAAiB,EAAY,EAAE;YACvD,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC5C,MAAM,CACL,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,EACtC,KAAK,CAAC,+CAA+C,CACrD,CAAC;YACF,OAAO,OAAO,CAAC;QAChB,CAAC;QACD,MAAM,EAAE,CAAC,IAAe,EAAE,OAAiB,EAAY,EAAE;YACxD,MAAM,SAAS,GAAG,IAAiB,CAAC,CAAC,oCAAo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CAAC,CAAC,CAAC;QAC7D,CAAC;IACF,CAAC;IAED,MAAM,MAAM,GAAM,uCAAuC,CACxD,mBAAmB,EACnB,cAAc,CACd,CAAC;IACF,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,QAAqC;IACzD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, debugAssert } from \"@fluidframework/core-utils/internal\";\nimport type { MinimumVersionForCollab } from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tgetConfigForMinVersionForCollabIterable,\n\tlowestMinVersionForCollab,\n\ttype MinimumMinorSemanticVersion,\n\ttype SemanticVersion,\n} from \"@fluidframework/runtime-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { Type, type TSchema } from \"@sinclair/typebox\";\nimport { gt } from \"semver-ts\";\n\nimport { pkgVersion } from \"../../packageVersion.js\";\nimport type {\n\tJsonCompatibleReadOnly,\n\tJsonCompatibleReadOnlyObject,\n} from \"../../util/index.js\";\nimport {\n\ttype ICodecFamily,\n\ttype ICodecOptions,\n\ttype IJsonCodec,\n\twithSchemaValidation,\n\ttype FormatVersion,\n\ttype CodecWriteOptions,\n\ttype CodecName,\n\ttype CodecTree,\n} from \"../codec.js\";\n\nimport { Versioned } from \"./format.js\";\n\n/**\n * Json compatible data with a format version.\n */\ntype VersionedJson = JsonCompatibleReadOnlyObject & Versioned;\n\nfunction makeVersionedCodec<\n\tTDecoded,\n\tTEncoded extends Versioned = VersionedJson,\n\tTValidate = TEncoded,\n\tTContext = void,\n>(\n\tsupportedVersions: Set<FormatVersion>,\n\t{ jsonValidator: validator }: ICodecOptions,\n\tinner: IJsonCodec<TDecoded, TEncoded, TValidate, TContext>,\n): IJsonCodec<TDecoded, TEncoded, TValidate, TContext> {\n\tconst codec = {\n\t\tencode: (data: TDecoded, context: TContext): TEncoded => {\n\t\t\tconst encoded = inner.encode(data, context);\n\t\t\tassert(\n\t\t\t\tsupportedVersions.has(encoded.version),\n\t\t\t\t0x88b /* version being encoded should be supported */,\n\t\t\t);\n\t\t\treturn encoded;\n\t\t},\n\t\tdecode: (data: TValidate, context: TContext): TDecoded => {\n\t\t\tconst versioned = data as Versioned; // Validated by withSchemaValidation\n\t\t\tif (!supportedVersions.has(versioned.version)) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Unsupported version ${versioned.version} encountered while decoding data. Supported versions for this data are: ${[...supportedVersions].join(\", \")}.\nThe client which encoded this data likely specified an \"minVersionForCollab\" value which corresponds to a version newer than the version of this client (\"${pkgVersion}\").`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst decoded = inner.decode(data, context);\n\t\t\treturn decoded;\n\t\t},\n\t};\n\n\treturn supportedVersions.has(undefined)\n\t\t? codec\n\t\t: withSchemaValidation(Versioned, codec, validator);\n}\n\n/**\n * TODO: users of this should migrate to {@link ClientVersionDispatchingCodecBuilder}.\n */\nexport function makeVersionedValidatedCodec<\n\tEncodedSchema extends TSchema,\n\tTDecoded,\n\tTEncoded extends Versioned = VersionedJson,\n\tTValidate = TEncoded,\n\tTContext = void,\n>(\n\toptions: ICodecOptions,\n\tsupportedVersions: Set<FormatVersion>,\n\tschema: EncodedSchema,\n\tcodec: IJsonCodec<TDecoded, TEncoded, TValidate, TContext>,\n): IJsonCodec<TDecoded, TEncoded, TValidate, TContext> {\n\treturn makeVersionedCodec(\n\t\tsupportedVersions,\n\t\toptions,\n\t\twithSchemaValidation(schema, codec, options.jsonValidator),\n\t);\n}\n\n/**\n * Creates a codec which always throws a UsageError when encoding or decoding, indicating that the format version is discontinued.\n *\n * TODO: {@link ClientVersionDispatchingCodecBuilder} should get support for extra decode only entries and/or unstable formats (codecs without a minVersionForCollab that will never be selected for write unless overridden).\n * Once done, users of this should migrate to ClientVersionDispatchingCodecBuilder and this function can be simplified.\n */\nexport function makeDiscontinuedCodecVersion<\n\tTDecoded,\n\tTEncoded extends Versioned = VersionedJson,\n\tTContext = unknown,\n>(\n\toptions: ICodecOptions,\n\tdiscontinuedVersion: FormatVersion,\n\tdiscontinuedSince: SemanticVersion,\n): IJsonCodec<TDecoded, TEncoded, TEncoded, TContext> {\n\tconst schema = Type.Object(\n\t\t{\n\t\t\tversion:\n\t\t\t\tdiscontinuedVersion === undefined\n\t\t\t\t\t? Type.Undefined()\n\t\t\t\t\t: Type.Literal(discontinuedVersion),\n\t\t},\n\t\t// Using `additionalProperties: true` allows this schema to be used when loading data encoded by older versions even though they contain additional properties.\n\t\t{ additionalProperties: true },\n\t);\n\tconst codec: IJsonCodec<TDecoded, TEncoded, TEncoded, TContext> = {\n\t\tencode: (_: TDecoded): TEncoded => {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Cannot encode data to format ${discontinuedVersion}. The codec was discontinued in Fluid Framework client version ${discontinuedSince}.`,\n\t\t\t);\n\t\t},\n\t\tdecode: (data: TEncoded): TDecoded => {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Cannot decode data to format ${data.version}. The codec was discontinued in Fluid Framework client version ${discontinuedSince}.`,\n\t\t\t);\n\t\t},\n\t};\n\treturn makeVersionedValidatedCodec(options, new Set([discontinuedVersion]), schema, codec);\n}\n\n/**\n * Creates a codec which dispatches to the appropriate member of a codec family based on the version of\n * data it encounters.\n * @remarks\n * Each member of the codec family must write an explicit version number into the data it encodes (implementing {@link Versioned}).\n *\n * TODO: Users of this should migrate to {@link ClientVersionDispatchingCodecBuilder} so that the actual format version used can be encapsulated.\n */\nexport function makeVersionDispatchingCodec<TDecoded, TContext>(\n\tfamily: ICodecFamily<TDecoded, TContext>,\n\toptions: ICodecOptions & { writeVersion: FormatVersion },\n): IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext> {\n\tconst writeCodec = family.resolve(options.writeVersion);\n\tconst supportedVersions = new Set(family.getSupportedFormats());\n\treturn makeVersionedCodec(supportedVersions, options, {\n\t\tencode(data, context): Versioned {\n\t\t\treturn writeCodec.encode(data, context) as Versioned;\n\t\t},\n\t\tdecode(data: Versioned, context) {\n\t\t\tconst codec = family.resolve(data.version);\n\t\t\treturn codec.decode(data, context);\n\t\t},\n\t});\n}\n\n/**\n * A friendly format for codec authors use to define their codec and schema for use in {@link CodecVersion}.\n * @remarks\n * The codec should not perform its own schema validation.\n * The schema validation gets added when normalizing to {@link NormalizedCodecVersion}.\n */\nexport type CodecAndSchema<TDecoded, TContext = void> = {\n\treadonly schema: TSchema;\n} & IJsonCodec<TDecoded, VersionedJson, JsonCompatibleReadOnly, TContext>;\n\n/**\n * A codec alongside its format version and schema.\n */\nexport interface CodecVersionBase<\n\tT = unknown,\n\tTFormatVersion extends FormatVersion = FormatVersion,\n> {\n\t/**\n\t * When `undefined` the codec will never be selected as a write version except via override.\n\t * @remarks\n\t * This format will be used for decode if data in it needs to be decoded, regardless of `minVersionForCollab`.\n\t * `undefined` should be used for unstable codec versions (with string FormatVersions),\n\t * as well as previously stabilized formats that are discontinued (meaning we always prefer to use some other format for encoding).\n\t */\n\treadonly minVersionForCollab: MinimumVersionForCollab | undefined;\n\treadonly formatVersion: TFormatVersion;\n\treadonly codec: T;\n}\n\n/**\n * A particular version of a codec and when to use it.\n * @privateRemarks\n * This allows lazy building of the codec with options.\n * This option can likely be removed as the codec handling is made simpler and more consistent.\n * Removing support for this laziness would be nice to help prevent unexpected coupling and alteration to codec behavior,\n * helping ensure that tests and production code behave the same.\n */\nexport interface CodecVersion<\n\tTDecoded,\n\tTContext,\n\tTFormatVersion extends FormatVersion,\n\tTBuildOptions extends CodecWriteOptions,\n> extends CodecVersionBase<\n\t\t| CodecAndSchema<TDecoded, TContext>\n\t\t| ((options: TBuildOptions) => CodecAndSchema<TDecoded, TContext>),\n\t\tTFormatVersion\n\t> {}\n\n/**\n * {@link CodecVersion} after normalization into a consistent type.\n * @remarks\n * Produced by {@link normalizeCodecVersion}.\n * Includes schema validation.\n */\nexport interface NormalizedCodecVersion<\n\tTDecoded,\n\tTContext,\n\tTFormatVersion extends FormatVersion,\n\tTBuildOptions extends CodecWriteOptions,\n> extends CodecVersionBase<\n\t\t(\n\t\t\toptions: TBuildOptions,\n\t\t) => IJsonCodec<TDecoded, VersionedJson, JsonCompatibleReadOnly, TContext>,\n\t\tTFormatVersion\n\t> {}\n\n/**\n * {@link NormalizedCodecVersion} after applying the build options.\n * @remarks\n * Produced by {@link ClientVersionDispatchingCodecBuilder.applyOptions}.\n */\ninterface EvaluatedCodecVersion<TDecoded, TContext, TFormatVersion extends FormatVersion>\n\textends CodecVersionBase<\n\t\tIJsonCodec<TDecoded, VersionedJson, JsonCompatibleReadOnly, TContext>,\n\t\tTFormatVersion\n\t> {}\n\n/**\n * Normalize the codec to a single format.\n * @remarks\n * Bakes in schema validation, so output no longer exposes the schema.\n */\nfunction normalizeCodecVersion<\n\tTDecoded,\n\tTContext,\n\tTFormatVersion extends FormatVersion,\n\tTBuildOptions extends CodecWriteOptions,\n>(\n\tcodecVersion: CodecVersion<TDecoded, TContext, TFormatVersion, TBuildOptions>,\n): NormalizedCodecVersion<TDecoded, TContext, TFormatVersion, TBuildOptions> {\n\tconst codecBuilder: (options: TBuildOptions) => CodecAndSchema<TDecoded, TContext> =\n\t\ttypeof codecVersion.codec === \"function\"\n\t\t\t? codecVersion.codec\n\t\t\t: () => codecVersion.codec as CodecAndSchema<TDecoded, TContext>;\n\tconst codec = (\n\t\toptions: TBuildOptions,\n\t): IJsonCodec<TDecoded, VersionedJson, JsonCompatibleReadOnly, TContext> => {\n\t\tconst built = codecBuilder(options);\n\t\treturn makeVersionedValidatedCodec(\n\t\t\toptions,\n\t\t\tnew Set([codecVersion.formatVersion]),\n\t\t\tbuilt.schema,\n\t\t\tbuilt,\n\t\t);\n\t};\n\n\treturn {\n\t\tminVersionForCollab: codecVersion.minVersionForCollab,\n\t\tformatVersion: codecVersion.formatVersion,\n\t\tcodec,\n\t};\n}\n\n/**\n * Creates a codec which dispatches to the appropriate member of a codec family based on the `minVersionForCollab` for encode and the\n * version number in data it encounters for decode.\n * @privateRemarks\n * This is a two stage builder so the first stage can encapsulate all codec specific details and the second can bring in configuration.\n */\nexport class ClientVersionDispatchingCodecBuilder<\n\tName extends CodecName,\n\tTDecoded,\n\tTContext,\n\tTFormatVersion extends FormatVersion,\n\tTBuildOptions extends CodecWriteOptions,\n> {\n\tpublic readonly registry: readonly NormalizedCodecVersion<\n\t\tTDecoded,\n\t\tTContext,\n\t\tTFormatVersion,\n\t\tTBuildOptions\n\t>[];\n\n\t/**\n\t * Use {@link ClientVersionDispatchingCodecBuilder.build} to create an instance of this class.\n\t * @remarks\n\t * Inputs to this are assumed to be constants in the code controlled by the developers of this package,\n\t * and constructed at least once during tests.\n\t * Because of this, the validation of these inputs done with debugAssert should be sufficient,\n\t * and using debugAssert avoids bloating the bundle size for production users.\n\t */\n\tprivate constructor(\n\t\t/**\n\t\t * See {@link CodecName}.\n\t\t */\n\t\tpublic readonly name: Name,\n\t\t/**\n\t\t * The registry of codecs which this builder can use to encode and decode data.\n\t\t */\n\t\tinputRegistry: readonly CodecVersion<TDecoded, TContext, TFormatVersion, TBuildOptions>[],\n\t) {\n\t\ttype Normalized = NormalizedCodecVersion<\n\t\t\tTDecoded,\n\t\t\tTContext,\n\t\t\tTFormatVersion,\n\t\t\tTBuildOptions\n\t\t>;\n\t\tconst normalizedRegistry: Normalized[] = [];\n\t\tconst formats: Set<FormatVersion> = new Set();\n\t\tconst versions: Set<string | undefined> = new Set();\n\n\t\tfor (const codec of inputRegistry) {\n\t\t\tdebugAssert(\n\t\t\t\t() =>\n\t\t\t\t\t!formats.has(codec.formatVersion) ||\n\t\t\t\t\t`duplicate codec format ${name} ${codec.formatVersion}`,\n\t\t\t);\n\t\t\tdebugAssert(\n\t\t\t\t() =>\n\t\t\t\t\tcodec.minVersionForCollab === undefined ||\n\t\t\t\t\ttypeof codec.formatVersion !== \"string\" ||\n\t\t\t\t\t`unstable format ${JSON.stringify(codec.formatVersion)} (string formats) must not have a minVersionForCollab in ${name}`,\n\t\t\t);\n\t\t\tformats.add(codec.formatVersion);\n\t\t\tconst normalizedCodec = normalizeCodecVersion(codec);\n\t\t\tnormalizedRegistry.push(normalizedCodec);\n\t\t\tif (codec.minVersionForCollab !== undefined) {\n\t\t\t\tdebugAssert(\n\t\t\t\t\t() =>\n\t\t\t\t\t\t!versions.has(codec.minVersionForCollab) ||\n\t\t\t\t\t\t`Codec ${name} has multiple entries for version ${JSON.stringify(codec.minVersionForCollab)}`,\n\t\t\t\t);\n\t\t\t\tversions.add(codec.minVersionForCollab);\n\t\t\t}\n\t\t}\n\n\t\tdebugAssert(\n\t\t\t() =>\n\t\t\t\tversions.has(lowestMinVersionForCollab) ||\n\t\t\t\t`Codec ${name} is missing entry for lowestMinVersionForCollab`,\n\t\t);\n\n\t\tthis.registry = normalizedRegistry;\n\t}\n\n\t/**\n\t * Applies the provided options to the codec registry to produce a list of evaluated codecs.\n\t * @remarks\n\t * This is used by build, which is what production code should use.\n\t * This is only exposed for testing purposes.\n\t */\n\tpublic applyOptions(\n\t\toptions: TBuildOptions,\n\t): EvaluatedCodecVersion<TDecoded, TContext, TFormatVersion>[] {\n\t\treturn this.registry.map((codec) => ({\n\t\t\tminVersionForCollab: codec.minVersionForCollab,\n\t\t\tformatVersion: codec.formatVersion,\n\t\t\tcodec: codec.codec(options),\n\t\t}));\n\t}\n\n\t/**\n\t * Produce a single codec which can read any supported format, and writes a version selected based on the provided options.\n\t */\n\tpublic build(\n\t\toptions: TBuildOptions,\n\t): IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext> {\n\t\tconst applied = this.applyOptions(options);\n\t\tconst writeVersion = getWriteVersion(this.name, options, applied);\n\t\tconst fromFormatVersion = new Map<\n\t\t\tFormatVersion,\n\t\t\tEvaluatedCodecVersion<TDecoded, TContext, TFormatVersion>\n\t\t>(applied.map((codec) => [codec.formatVersion, codec]));\n\t\treturn {\n\t\t\tencode: (data: TDecoded, context: TContext): JsonCompatibleReadOnly => {\n\t\t\t\treturn writeVersion.codec.encode(data, context);\n\t\t\t},\n\t\t\tdecode: (data: JsonCompatibleReadOnly, context: TContext): TDecoded => {\n\t\t\t\tconst versioned = data as Partial<Versioned>;\n\t\t\t\tconst codec = fromFormatVersion.get(versioned.version);\n\t\t\t\tif (codec === undefined) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t`Unsupported version ${versioned.version} encountered while decoding ${this.name} data. Supported versions for this data are: ${versionList(applied)}.\nThe client which encoded this data likely specified an \"minVersionForCollab\" value which corresponds to a version newer than the version of this client (\"${pkgVersion}\").`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn codec.codec.decode(data, context);\n\t\t\t},\n\t\t};\n\t}\n\n\tpublic getCodecTree(clientVersion: MinimumVersionForCollab): CodecTree {\n\t\t// TODO: add support for children codecs.\n\t\tconst selected = getWriteVersionNoOverrides(this.registry, clientVersion);\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tversion: selected.formatVersion,\n\t\t};\n\t}\n\n\t/**\n\t * Builds a ClientVersionDispatchingCodecBuilder from the provided registry.\n\t * @remarks\n\t * This static method infers the types of the builder from the provided registry,\n\t * making it easier to create builders without needing to explicitly specify all type parameters.\n\t * This gets better type inference than the constructor.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tpublic static build<\n\t\tName extends CodecName,\n\t\tEntry extends CodecVersion<unknown, unknown, FormatVersion, never>,\n\t>(name: Name, inputRegistry: readonly Entry[]) {\n\t\ttype TDecoded2 =\n\t\t\tEntry extends CodecVersion<infer D, unknown, FormatVersion, never> ? D : never;\n\t\ttype TContext2 =\n\t\t\tEntry extends CodecVersion<unknown, infer C, FormatVersion, never> ? C : never;\n\t\ttype TFormatVersion2 =\n\t\t\tEntry extends CodecVersion<unknown, unknown, infer F, never> ? F : never;\n\t\ttype TBuildOptions2 =\n\t\t\tEntry extends CodecVersion<unknown, unknown, FormatVersion, infer B> ? B : never;\n\n\t\ttype CodecFinal = CodecVersion<\n\t\t\tTDecoded2,\n\t\t\t// If it does not matter what context is provided, undefined is fine, so allow it to be omitted.\n\t\t\tunknown extends TContext2 ? void : TContext2,\n\t\t\tTFormatVersion2,\n\t\t\tTBuildOptions2\n\t\t>;\n\n\t\tconst input = inputRegistry as readonly unknown[] as readonly CodecFinal[];\n\n\t\tconst builder = new ClientVersionDispatchingCodecBuilder<\n\t\t\tName,\n\t\t\tTDecoded2,\n\t\t\tunknown extends TContext2 ? void : TContext2,\n\t\t\tTFormatVersion2,\n\t\t\tTBuildOptions2\n\t\t>(name, input);\n\t\treturn builder;\n\t}\n}\n\n/**\n * Selects which format should be used when writing data.\n * @remarks\n * This either uses the override specified in the options, or selects the newest format compatible with the provided minVersionForCollab.\n */\nfunction getWriteVersion<T extends CodecVersionBase>(\n\tname: CodecName,\n\toptions: CodecWriteOptions,\n\tversions: readonly T[],\n): T {\n\tif (options.writeVersionOverrides?.has(name) === true) {\n\t\tconst selectedFormatVersion = options.writeVersionOverrides.get(name);\n\t\tconst selected = versions.find((codec) => codec.formatVersion === selectedFormatVersion);\n\t\tif (selected === undefined) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Codec \"${name}\" does not support requested format version ${JSON.stringify(selectedFormatVersion)}. Supported versions are: ${versionList(versions)}.`,\n\t\t\t);\n\t\t} else if (options.allowPossiblyIncompatibleWriteVersionOverrides !== true) {\n\t\t\tconst selectedMinVersionForCollab = selected.minVersionForCollab;\n\t\t\tif (selectedMinVersionForCollab === undefined) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Codec \"${name}\" does not support requested format version ${JSON.stringify(selectedFormatVersion)} because it has minVersionForCollab undefined. Use \"allowPossiblyIncompatibleWriteVersionOverrides\" to suppress this error if appropriate.`,\n\t\t\t\t);\n\t\t\t} else if (gt(selectedMinVersionForCollab, options.minVersionForCollab)) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Codec \"${name}\" does not support requested format version ${JSON.stringify(selectedFormatVersion)} because it is only compatible back to client version ${selectedMinVersionForCollab} and the requested oldest compatible client was ${options.minVersionForCollab}. Use \"allowPossiblyIncompatibleWriteVersionOverrides\" to suppress this error if appropriate.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn selected;\n\t}\n\n\treturn getWriteVersionNoOverrides(versions, options.minVersionForCollab);\n}\n\n/**\n * Selects which format should be used when writing data, without consider overrides.\n */\nfunction getWriteVersionNoOverrides<T extends CodecVersionBase>(\n\tversions: readonly T[],\n\tminVersionForCollab: MinimumVersionForCollab,\n): T {\n\tconst stableVersions: [MinimumMinorSemanticVersion | MinimumVersionForCollab, T][] = [];\n\tfor (const version of versions) {\n\t\tif (version.minVersionForCollab !== undefined) {\n\t\t\tstableVersions.push([version.minVersionForCollab, version]);\n\t\t}\n\t}\n\n\tconst result: T = getConfigForMinVersionForCollabIterable(\n\t\tminVersionForCollab,\n\t\tstableVersions,\n\t);\n\treturn result;\n}\n\n/**\n * Formats a list of versions for use in UsageErrors.\n */\nfunction versionList(versions: readonly CodecVersionBase[]): string {\n\treturn JSON.stringify(Array.from(versions, (codec) => codec.formatVersion));\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detachedFieldIndexCodecs.d.ts","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,EACN,oCAAoC,EACpC,KAAK,iBAAiB,EAEtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAW3D,eAAO,MAAM,8BAA8B;sBAJxB,gBAAgB;kBACpB,aAAa;
|
|
1
|
+
{"version":3,"file":"detachedFieldIndexCodecs.d.ts","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,EACN,oCAAoC,EACpC,KAAK,iBAAiB,EAEtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAW3D,eAAO,MAAM,8BAA8B;sBAJxB,gBAAgB;kBACpB,aAAa;EAmB3B,CAAC"}
|
|
@@ -7,14 +7,16 @@ import { ClientVersionDispatchingCodecBuilder, FluidClientVersion, } from "../..
|
|
|
7
7
|
import { makeDetachedNodeToFieldCodecV1 } from "./detachedFieldIndexCodecV1.js";
|
|
8
8
|
import { makeDetachedNodeToFieldCodecV2 } from "./detachedFieldIndexCodecV2.js";
|
|
9
9
|
import { DetachedFieldIndexFormatVersion } from "./detachedFieldIndexFormatCommon.js";
|
|
10
|
-
export const detachedFieldIndexCodecBuilder = ClientVersionDispatchingCodecBuilder.build("DetachedFieldIndex",
|
|
11
|
-
|
|
10
|
+
export const detachedFieldIndexCodecBuilder = ClientVersionDispatchingCodecBuilder.build("DetachedFieldIndex", [
|
|
11
|
+
{
|
|
12
|
+
minVersionForCollab: lowestMinVersionForCollab,
|
|
12
13
|
formatVersion: DetachedFieldIndexFormatVersion.v1,
|
|
13
14
|
codec: (buildData) => makeDetachedNodeToFieldCodecV1(buildData.revisionTagCodec, buildData.idCompressor),
|
|
14
15
|
},
|
|
15
|
-
|
|
16
|
+
{
|
|
17
|
+
minVersionForCollab: FluidClientVersion.v2_52,
|
|
16
18
|
formatVersion: DetachedFieldIndexFormatVersion.v2,
|
|
17
19
|
codec: (buildData) => makeDetachedNodeToFieldCodecV2(buildData.revisionTagCodec, buildData.idCompressor),
|
|
18
20
|
},
|
|
19
|
-
|
|
21
|
+
]);
|
|
20
22
|
//# sourceMappingURL=detachedFieldIndexCodecs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detachedFieldIndexCodecs.js","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AAEnF,OAAO,EACN,oCAAoC,EAEpC,kBAAkB,GAClB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAC;AAOtF,MAAM,CAAC,MAAM,8BAA8B,GAAG,oCAAoC,CAAC,KAAK,CACvF,oBAAoB,EACpB;IACC,
|
|
1
|
+
{"version":3,"file":"detachedFieldIndexCodecs.js","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndexCodecs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AAEnF,OAAO,EACN,oCAAoC,EAEpC,kBAAkB,GAClB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAC;AAOtF,MAAM,CAAC,MAAM,8BAA8B,GAAG,oCAAoC,CAAC,KAAK,CACvF,oBAAoB,EACpB;IACC;QACC,mBAAmB,EAAE,yBAAyB;QAC9C,aAAa,EAAE,+BAA+B,CAAC,EAAE;QACjD,KAAK,EAAE,CAAC,SAAoB,EAAE,EAAE,CAC/B,8BAA8B,CAAC,SAAS,CAAC,gBAAgB,EAAE,SAAS,CAAC,YAAY,CAAC;KACnF;IACD;QACC,mBAAmB,EAAE,kBAAkB,CAAC,KAAK;QAC7C,aAAa,EAAE,+BAA+B,CAAC,EAAE;QACjD,KAAK,EAAE,CAAC,SAAoB,EAAE,EAAE,CAC/B,8BAA8B,CAAC,SAAS,CAAC,gBAAgB,EAAE,SAAS,CAAC,YAAY,CAAC;KACnF;CACD,CACD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\nimport { lowestMinVersionForCollab } from \"@fluidframework/runtime-utils/internal\";\n\nimport {\n\tClientVersionDispatchingCodecBuilder,\n\ttype CodecWriteOptions,\n\tFluidClientVersion,\n} from \"../../codec/index.js\";\nimport type { RevisionTagCodec } from \"../rebase/index.js\";\n\nimport { makeDetachedNodeToFieldCodecV1 } from \"./detachedFieldIndexCodecV1.js\";\nimport { makeDetachedNodeToFieldCodecV2 } from \"./detachedFieldIndexCodecV2.js\";\nimport { DetachedFieldIndexFormatVersion } from \"./detachedFieldIndexFormatCommon.js\";\n\ntype BuildData = CodecWriteOptions & {\n\trevisionTagCodec: RevisionTagCodec;\n\tidCompressor: IIdCompressor;\n};\n\nexport const detachedFieldIndexCodecBuilder = ClientVersionDispatchingCodecBuilder.build(\n\t\"DetachedFieldIndex\",\n\t[\n\t\t{\n\t\t\tminVersionForCollab: lowestMinVersionForCollab,\n\t\t\tformatVersion: DetachedFieldIndexFormatVersion.v1,\n\t\t\tcodec: (buildData: BuildData) =>\n\t\t\t\tmakeDetachedNodeToFieldCodecV1(buildData.revisionTagCodec, buildData.idCompressor),\n\t\t},\n\t\t{\n\t\t\tminVersionForCollab: FluidClientVersion.v2_52,\n\t\t\tformatVersion: DetachedFieldIndexFormatVersion.v2,\n\t\t\tcodec: (buildData: BuildData) =>\n\t\t\t\tmakeDetachedNodeToFieldCodecV2(buildData.revisionTagCodec, buildData.idCompressor),\n\t\t},\n\t],\n);\n"]}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import type { TreeNodeSchema, TreeNodeFromImplicitAllowedTypes, TreeFieldFromImplicitField, SchemaFactoryBeta } from "./simple-tree/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Utilities for creating extensible unions using a node.
|
|
8
|
+
* @remarks
|
|
9
|
+
* Use {@link ExtensibleUnionNode.createSchema} to create the union schema.
|
|
10
|
+
*
|
|
11
|
+
* Unlike a schema union created using {@link SchemaStaticsBeta.staged | staged} allowed types, this union allows for unknown future types to exist in addition to the known types.
|
|
12
|
+
* This allows for faster roll-outs of new types without waiting for old clients to be updated to be aware of them.
|
|
13
|
+
* This does mean however that old clients may see types they do not know about, which are simply exposed as `undefined` children.
|
|
14
|
+
*
|
|
15
|
+
* `staged` types are lower overhead, and might gain support for `unknown` types in the future, so prefer them when possible.
|
|
16
|
+
* This is simply an alternative for when future compatibility with unknown types is required.
|
|
17
|
+
* It is built on top of the existing {@link ObjectSchemaOptions.allowUnknownOptionalFields | allowUnknownOptionalFields} feature.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const sf = new SchemaFactoryBeta("extensibleUnionNodeExample.items");
|
|
22
|
+
* class ItemA extends sf.object("A", { x: sf.string }) {}
|
|
23
|
+
* class ItemB extends sf.object("B", { x: sf.number }) {}
|
|
24
|
+
*
|
|
25
|
+
* class AnyItem extends ExtensibleUnionNode.createSchema(
|
|
26
|
+
* [ItemA, ItemB], // Future versions may add more members here
|
|
27
|
+
* sf,
|
|
28
|
+
* "ExtensibleUnion",
|
|
29
|
+
* ) {}
|
|
30
|
+
* // Instances of the union are created using `create`.
|
|
31
|
+
* const anyItem = AnyItem.create(new ItemA({ x: "hello" }));
|
|
32
|
+
* // Reading the content from the union is done via the `union` property,
|
|
33
|
+
* // which can be `undefined` to handle the case where a future version of this schema allows a type unknown to the current version.
|
|
34
|
+
* const childNode: ItemA | ItemB | undefined = anyItem.union;
|
|
35
|
+
* // To determine which member of the union was present, its schema can be inspected:
|
|
36
|
+
* const aSchema = Tree.schema(childNode ?? assert.fail("No child"));
|
|
37
|
+
* assert.equal(aSchema, ItemA);
|
|
38
|
+
* ```
|
|
39
|
+
* @beta
|
|
40
|
+
*/
|
|
41
|
+
export declare namespace ExtensibleUnionNode {
|
|
42
|
+
/**
|
|
43
|
+
* Members for classes created by {@link ExtensibleUnionNode.createSchema}.
|
|
44
|
+
* @beta
|
|
45
|
+
*/
|
|
46
|
+
interface Members<T> {
|
|
47
|
+
/**
|
|
48
|
+
* The child wrapped by this node has one of the types allowed by the union,
|
|
49
|
+
* or `undefined` if the type is one which was added to the union by a future version of this schema.
|
|
50
|
+
*
|
|
51
|
+
* @throws if {@link ExtensibleUnionNode.Members.isValid} is false.
|
|
52
|
+
*/
|
|
53
|
+
readonly union: T | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Returns true, unless this node is in an invalid state.
|
|
56
|
+
* @remarks
|
|
57
|
+
* A well behaved application should not need this API.
|
|
58
|
+
* If an application is hitting errors when accessing {@link ExtensibleUnionNode.Members.union},
|
|
59
|
+
* this API can be used to help detect and recover from the invalid state which causes those errors (for example by replacing the invalid nodes with new ones).
|
|
60
|
+
*
|
|
61
|
+
* In this context "invalid" means that the internal implementation details of this node have had their invariants violated.
|
|
62
|
+
* This can happen when:
|
|
63
|
+
* - Using weakly typed construction APIs like {@link (TreeBeta:interface).importConcise} or {@link (TreeAlpha:interface).importVerbose} to construct an invalid state directly.
|
|
64
|
+
* Using such APIs, even when not creating invalid nodes, is not supported for this schema,
|
|
65
|
+
* since doing so requires knowing the implementation details of this node which are subject to change.
|
|
66
|
+
* - By editing a document using a different client using a different schema for this node.
|
|
67
|
+
* - Violating the TypeScript types to directly manipulate the node internals.
|
|
68
|
+
* - A bug in this node's implementation (possibly in a different client) corrupted the node.
|
|
69
|
+
* - Corruption of the document this node is contained in.
|
|
70
|
+
*
|
|
71
|
+
* @privateRemarks
|
|
72
|
+
* We could support {@link (TreeBeta:interface).exportVerbose} using {@link KeyEncodingOptions.allStoredKeys}
|
|
73
|
+
* then {@link (TreeAlpha:interface).importVerbose} with {@link KeyEncodingOptions.knownStoredKeys}.
|
|
74
|
+
* However, even this will error (but will not produce an invalid node) if there is a node of an unknown type in the union.
|
|
75
|
+
*/
|
|
76
|
+
isValid(): boolean;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Statics for classes created by {@link ExtensibleUnionNode.createSchema}.
|
|
80
|
+
* @beta
|
|
81
|
+
*/
|
|
82
|
+
interface Statics<T extends readonly TreeNodeSchema[]> {
|
|
83
|
+
/**
|
|
84
|
+
* Create a {@link TreeNode} with `this` schema which wraps the provided child to create the union.
|
|
85
|
+
*/
|
|
86
|
+
create<TThis extends TreeNodeSchema>(this: TThis, child: TreeNodeFromImplicitAllowedTypes<T>): TreeFieldFromImplicitField<TThis>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create an extensible schema union which currently supports the types in `types`,
|
|
90
|
+
* but tolerates collaboration with future versions that may include additional types.
|
|
91
|
+
* @remarks
|
|
92
|
+
* See {@link ExtensibleUnionNode} for an example use.
|
|
93
|
+
* @beta
|
|
94
|
+
*/
|
|
95
|
+
function createSchema<const T extends readonly TreeNodeSchema[], const TScope extends string, const TName extends string>(types: T, inputSchemaFactory: SchemaFactoryBeta<TScope>, name: TName): Statics<T> & import("./simple-tree/index.js").TreeNodeSchemaCore<import("./simple-tree/index.js").ScopedSchemaName<`com.fluidframework.extensibleUnionNode<${TScope}>`, TName>, import("./simple-tree/index.js").NodeKind, false, unknown, never, unknown> & (new (data: import("./simple-tree/index.js").InternalTreeNode) => Members<TreeNodeFromImplicitAllowedTypes<T>> & import("./simple-tree/index.js").TreeNode & import("./simple-tree/index.js").WithType<import("./simple-tree/index.js").ScopedSchemaName<`com.fluidframework.extensibleUnionNode<${TScope}>`, TName>, import("./simple-tree/index.js").NodeKind, unknown>);
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=extensibleUnionNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extensibleUnionNode.d.ts","sourceRoot":"","sources":["../src/extensibleUnionNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EACX,cAAc,EACd,gCAAgC,EAChC,0BAA0B,EAG1B,iBAAiB,EACjB,MAAM,wBAAwB,CAAC;AAUhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,yBAAiB,mBAAmB,CAAC;IACpC;;;OAGG;IACH,UAAiB,OAAO,CAAC,CAAC;QACzB;;;;;WAKG;QACH,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC;QAE9B;;;;;;;;;;;;;;;;;;;;;WAqBG;QACH,OAAO,IAAI,OAAO,CAAC;KACnB;IAED;;;OAGG;IACH,UAAiB,OAAO,CAAC,CAAC,SAAS,SAAS,cAAc,EAAE;QAC3D;;WAEG;QACH,MAAM,CAAC,KAAK,SAAS,cAAc,EAClC,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,gCAAgC,CAAC,CAAC,CAAC,GACxC,0BAA0B,CAAC,KAAK,CAAC,CAAC;KACrC;IAED;;;;;;OAMG;IAEH,SAAgB,YAAY,CAC3B,KAAK,CAAC,CAAC,SAAS,SAAS,cAAc,EAAE,EACzC,KAAK,CAAC,MAAM,SAAS,MAAM,EAC3B,KAAK,CAAC,KAAK,SAAS,MAAM,EACzB,KAAK,EAAE,CAAC,EAAE,kBAAkB,EAAE,iBAAiB,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,2mBAkDrE;CACD"}
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
+
import { UsageError } from "@fluidframework/telemetry-utils/internal";
|
|
5
6
|
import { TreeAlpha, Tree } from "./shared-tree/index.js";
|
|
6
|
-
import { createCustomizedFluidFrameworkScopedFactory, eraseSchemaDetailsSubclassable, SchemaFactory, TreeBeta, } from "./simple-tree/index.js";
|
|
7
|
+
import { createCustomizedFluidFrameworkScopedFactory, eraseSchemaDetailsSubclassable, getInnerNode, SchemaFactory, TreeBeta, } from "./simple-tree/index.js";
|
|
7
8
|
/**
|
|
8
|
-
* Utilities for creating extensible
|
|
9
|
+
* Utilities for creating extensible unions using a node.
|
|
9
10
|
* @remarks
|
|
10
|
-
* Use {@link
|
|
11
|
+
* Use {@link ExtensibleUnionNode.createSchema} to create the union schema.
|
|
11
12
|
*
|
|
12
13
|
* Unlike a schema union created using {@link SchemaStaticsBeta.staged | staged} allowed types, this union allows for unknown future types to exist in addition to the known types.
|
|
13
14
|
* This allows for faster roll-outs of new types without waiting for old clients to be updated to be aware of them.
|
|
@@ -19,49 +20,58 @@ import { createCustomizedFluidFrameworkScopedFactory, eraseSchemaDetailsSubclass
|
|
|
19
20
|
*
|
|
20
21
|
* @example
|
|
21
22
|
* ```typescript
|
|
22
|
-
* const sf = new SchemaFactoryBeta("
|
|
23
|
+
* const sf = new SchemaFactoryBeta("extensibleUnionNodeExample.items");
|
|
23
24
|
* class ItemA extends sf.object("A", { x: sf.string }) {}
|
|
24
25
|
* class ItemB extends sf.object("B", { x: sf.number }) {}
|
|
25
26
|
*
|
|
26
|
-
* class AnyItem extends
|
|
27
|
+
* class AnyItem extends ExtensibleUnionNode.createSchema(
|
|
27
28
|
* [ItemA, ItemB], // Future versions may add more members here
|
|
28
29
|
* sf,
|
|
29
30
|
* "ExtensibleUnion",
|
|
30
31
|
* ) {}
|
|
31
32
|
* // Instances of the union are created using `create`.
|
|
32
33
|
* const anyItem = AnyItem.create(new ItemA({ x: "hello" }));
|
|
33
|
-
* // Reading the content from the union is done via `
|
|
34
|
+
* // Reading the content from the union is done via the `union` property,
|
|
34
35
|
* // which can be `undefined` to handle the case where a future version of this schema allows a type unknown to the current version.
|
|
35
|
-
* const childNode: ItemA | ItemB | undefined = anyItem.
|
|
36
|
+
* const childNode: ItemA | ItemB | undefined = anyItem.union;
|
|
36
37
|
* // To determine which member of the union was present, its schema can be inspected:
|
|
37
38
|
* const aSchema = Tree.schema(childNode ?? assert.fail("No child"));
|
|
38
39
|
* assert.equal(aSchema, ItemA);
|
|
39
40
|
* ```
|
|
40
|
-
* @
|
|
41
|
+
* @beta
|
|
41
42
|
*/
|
|
42
|
-
export var
|
|
43
|
-
(function (
|
|
43
|
+
export var ExtensibleUnionNode;
|
|
44
|
+
(function (ExtensibleUnionNode) {
|
|
44
45
|
/**
|
|
45
46
|
* Create an extensible schema union which currently supports the types in `types`,
|
|
46
47
|
* but tolerates collaboration with future versions that may include additional types.
|
|
47
48
|
* @remarks
|
|
48
|
-
* See {@link
|
|
49
|
-
* @
|
|
49
|
+
* See {@link ExtensibleUnionNode} for an example use.
|
|
50
|
+
* @beta
|
|
50
51
|
*/
|
|
51
52
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
52
|
-
function
|
|
53
|
+
function createSchema(types, inputSchemaFactory, name) {
|
|
53
54
|
const record = {};
|
|
54
55
|
for (const type of types) {
|
|
55
56
|
record[`_${type.identifier}`] = SchemaFactory.optional(type, { key: type.identifier });
|
|
56
57
|
}
|
|
57
|
-
const schemaFactory = createCustomizedFluidFrameworkScopedFactory(inputSchemaFactory, "
|
|
58
|
+
const schemaFactory = createCustomizedFluidFrameworkScopedFactory(inputSchemaFactory, "extensibleUnionNode");
|
|
58
59
|
class Union extends schemaFactory.object(name, record, { allowUnknownOptionalFields: true }) {
|
|
59
|
-
get
|
|
60
|
+
get union() {
|
|
61
|
+
if (!this.isValid()) {
|
|
62
|
+
throw new UsageError(`This ExtensibleUnionNode (${Union.identifier}) is in an invalid state. It must have been edited by another client using a different schema or been directly imported or constructed in an invalid state.`);
|
|
63
|
+
}
|
|
60
64
|
for (const [_key, child] of TreeAlpha.children(this)) {
|
|
61
65
|
return child;
|
|
62
66
|
}
|
|
63
67
|
return undefined;
|
|
64
68
|
}
|
|
69
|
+
isValid() {
|
|
70
|
+
// Use inner node, since it includes populated fields even when they are unknown.
|
|
71
|
+
const inner = getInnerNode(this);
|
|
72
|
+
// Fields only includes non-empty fields, so this is what we need to check the one child invariant.
|
|
73
|
+
return [...inner.fields].length === 1;
|
|
74
|
+
}
|
|
65
75
|
static create(child) {
|
|
66
76
|
const schema = Tree.schema(child);
|
|
67
77
|
return TreeBeta.create(this, {
|
|
@@ -71,6 +81,6 @@ export var ExtensibleSchemaUnion;
|
|
|
71
81
|
}
|
|
72
82
|
return eraseSchemaDetailsSubclassable()(Union);
|
|
73
83
|
}
|
|
74
|
-
|
|
75
|
-
})(
|
|
76
|
-
//# sourceMappingURL=
|
|
84
|
+
ExtensibleUnionNode.createSchema = createSchema;
|
|
85
|
+
})(ExtensibleUnionNode || (ExtensibleUnionNode = {}));
|
|
86
|
+
//# sourceMappingURL=extensibleUnionNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extensibleUnionNode.js","sourceRoot":"","sources":["../src/extensibleUnionNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AASzD,OAAO,EACN,2CAA2C,EAC3C,8BAA8B,EAC9B,YAAY,EACZ,aAAa,EACb,QAAQ,GACR,MAAM,wBAAwB,CAAC;AAGhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,KAAW,mBAAmB,CAoHnC;AApHD,WAAiB,mBAAmB;IAqDnC;;;;;;OAMG;IACH,4EAA4E;IAC5E,SAAgB,YAAY,CAI1B,K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,CAAC;YACJ,CAAC;SACD;QACD,OAAO,8BAA8B,EAGlC,CAAC,KAAK,CAAC,CAAC;IACZ,CAAC;IAtDe,gCAAY,eAsD3B,CAAA;AACF,CAAC,EApHgB,mBAAmB,KAAnB,mBAAmB,QAoHnC","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 { TreeAlpha, Tree } from \"./shared-tree/index.js\";\nimport type {\n\tTreeNodeSchema,\n\tTreeNodeFromImplicitAllowedTypes,\n\tTreeFieldFromImplicitField,\n\tImplicitFieldSchema,\n\tInsertableTreeFieldFromImplicitField,\n\tSchemaFactoryBeta,\n} from \"./simple-tree/index.js\";\nimport {\n\tcreateCustomizedFluidFrameworkScopedFactory,\n\teraseSchemaDetailsSubclassable,\n\tgetInnerNode,\n\tSchemaFactory,\n\tTreeBeta,\n} from \"./simple-tree/index.js\";\nimport type { UnionToIntersection } from \"./util/index.js\";\n\n/**\n * Utilities for creating extensible unions using a node.\n * @remarks\n * Use {@link ExtensibleUnionNode.createSchema} to create the union schema.\n *\n * Unlike a schema union created using {@link SchemaStaticsBeta.staged | staged} allowed types, this union allows for unknown future types to exist in addition to the known types.\n * This allows for faster roll-outs of new types without waiting for old clients to be updated to be aware of them.\n * This does mean however that old clients may see types they do not know about, which are simply exposed as `undefined` children.\n *\n * `staged` types are lower overhead, and might gain support for `unknown` types in the future, so prefer them when possible.\n * This is simply an alternative for when future compatibility with unknown types is required.\n * It is built on top of the existing {@link ObjectSchemaOptions.allowUnknownOptionalFields | allowUnknownOptionalFields} feature.\n *\n * @example\n * ```typescript\n * const sf = new SchemaFactoryBeta(\"extensibleUnionNodeExample.items\");\n * class ItemA extends sf.object(\"A\", { x: sf.string }) {}\n * class ItemB extends sf.object(\"B\", { x: sf.number }) {}\n *\n * class AnyItem extends ExtensibleUnionNode.createSchema(\n * \t[ItemA, ItemB], // Future versions may add more members here\n * \tsf,\n * \t\"ExtensibleUnion\",\n * ) {}\n * // Instances of the union are created using `create`.\n * const anyItem = AnyItem.create(new ItemA({ x: \"hello\" }));\n * // Reading the content from the union is done via the `union` property,\n * // which can be `undefined` to handle the case where a future version of this schema allows a type unknown to the current version.\n * const childNode: ItemA | ItemB | undefined = anyItem.union;\n * // To determine which member of the union was present, its schema can be inspected:\n * const aSchema = Tree.schema(childNode ?? assert.fail(\"No child\"));\n * assert.equal(aSchema, ItemA);\n * ```\n * @beta\n */\nexport namespace ExtensibleUnionNode {\n\t/**\n\t * Members for classes created by {@link ExtensibleUnionNode.createSchema}.\n\t * @beta\n\t */\n\texport interface Members<T> {\n\t\t/**\n\t\t * The child wrapped by this node has one of the types allowed by the union,\n\t\t * or `undefined` if the type is one which was added to the union by a future version of this schema.\n\t\t *\n\t\t * @throws if {@link ExtensibleUnionNode.Members.isValid} is false.\n\t\t */\n\t\treadonly union: T | undefined;\n\n\t\t/**\n\t\t * Returns true, unless this node is in an invalid state.\n\t\t * @remarks\n\t\t * A well behaved application should not need this API.\n\t\t * If an application is hitting errors when accessing {@link ExtensibleUnionNode.Members.union},\n\t\t * this API can be used to help detect and recover from the invalid state which causes those errors (for example by replacing the invalid nodes with new ones).\n\t\t *\n\t\t * In this context \"invalid\" means that the internal implementation details of this node have had their invariants violated.\n\t\t * This can happen when:\n\t\t * - Using weakly typed construction APIs like {@link (TreeBeta:interface).importConcise} or {@link (TreeAlpha:interface).importVerbose} to construct an invalid state directly.\n\t\t * Using such APIs, even when not creating invalid nodes, is not supported for this schema,\n\t\t * since doing so requires knowing the implementation details of this node which are subject to change.\n\t\t * - By editing a document using a different client using a different schema for this node.\n\t\t * - Violating the TypeScript types to directly manipulate the node internals.\n\t\t * - A bug in this node's implementation (possibly in a different client) corrupted the node.\n\t\t * - Corruption of the document this node is contained in.\n\t\t *\n\t\t * @privateRemarks\n\t\t * We could support {@link (TreeBeta:interface).exportVerbose} using {@link KeyEncodingOptions.allStoredKeys}\n\t\t * then {@link (TreeAlpha:interface).importVerbose} with {@link KeyEncodingOptions.knownStoredKeys}.\n\t\t * However, even this will error (but will not produce an invalid node) if there is a node of an unknown type in the union.\n\t\t */\n\t\tisValid(): boolean;\n\t}\n\n\t/**\n\t * Statics for classes created by {@link ExtensibleUnionNode.createSchema}.\n\t * @beta\n\t */\n\texport interface Statics<T extends readonly TreeNodeSchema[]> {\n\t\t/**\n\t\t * Create a {@link TreeNode} with `this` schema which wraps the provided child to create the union.\n\t\t */\n\t\tcreate<TThis extends TreeNodeSchema>(\n\t\t\tthis: TThis,\n\t\t\tchild: TreeNodeFromImplicitAllowedTypes<T>,\n\t\t): TreeFieldFromImplicitField<TThis>;\n\t}\n\n\t/**\n\t * Create an extensible schema union which currently supports the types in `types`,\n\t * but tolerates collaboration with future versions that may include additional types.\n\t * @remarks\n\t * See {@link ExtensibleUnionNode} for an example use.\n\t * @beta\n\t */\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\texport function createSchema<\n\t\tconst T extends readonly TreeNodeSchema[],\n\t\tconst TScope extends string,\n\t\tconst TName extends string,\n\t>(types: T, inputSchemaFactory: SchemaFactoryBeta<TScope>, name: TName) {\n\t\tconst record: Record<string, ImplicitFieldSchema> = {};\n\t\tfor (const type of types) {\n\t\t\trecord[`_${type.identifier}`] = SchemaFactory.optional(type, { key: type.identifier });\n\t\t}\n\t\tconst schemaFactory = createCustomizedFluidFrameworkScopedFactory(\n\t\t\tinputSchemaFactory,\n\t\t\t\"extensibleUnionNode\",\n\t\t);\n\n\t\tclass Union\n\t\t\textends schemaFactory.object(name, record, { allowUnknownOptionalFields: true })\n\t\t\timplements Members<TreeNodeFromImplicitAllowedTypes<T>>\n\t\t{\n\t\t\tpublic get union(): TreeNodeFromImplicitAllowedTypes<T> | undefined {\n\t\t\t\tif (!this.isValid()) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t`This ExtensibleUnionNode (${Union.identifier}) is in an invalid state. It must have been edited by another client using a different schema or been directly imported or constructed in an invalid state.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tfor (const [_key, child] of TreeAlpha.children(this)) {\n\t\t\t\t\treturn child as TreeNodeFromImplicitAllowedTypes<T>;\n\t\t\t\t}\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tpublic isValid(): boolean {\n\t\t\t\t// Use inner node, since it includes populated fields even when they are unknown.\n\t\t\t\tconst inner = getInnerNode(this);\n\t\t\t\t// Fields only includes non-empty fields, so this is what we need to check the one child invariant.\n\t\t\t\treturn [...inner.fields].length === 1;\n\t\t\t}\n\n\t\t\tpublic static create<TThis extends TreeNodeSchema>(\n\t\t\t\tthis: TThis,\n\t\t\t\tchild: TreeNodeFromImplicitAllowedTypes<T>,\n\t\t\t): TreeFieldFromImplicitField<TThis> {\n\t\t\t\tconst schema = Tree.schema(child);\n\t\t\t\treturn TreeBeta.create(this, {\n\t\t\t\t\t[`_${schema.identifier}`]: child,\n\t\t\t\t} as unknown as InsertableTreeFieldFromImplicitField<\n\t\t\t\t\tTThis,\n\t\t\t\t\tUnionToIntersection<TThis>\n\t\t\t\t>);\n\t\t\t}\n\t\t}\n\t\treturn eraseSchemaDetailsSubclassable<\n\t\t\tMembers<TreeNodeFromImplicitAllowedTypes<T>>,\n\t\t\tStatics<T>\n\t\t>()(Union);\n\t}\n}\n"]}
|
|
@@ -9,7 +9,7 @@ import { type ITreeCursorSynchronous, type SchemaAndPolicy, type TreeChunk } fro
|
|
|
9
9
|
import { type Brand, type JsonCompatibleReadOnly } from "../../../util/index.js";
|
|
10
10
|
import { TreeCompressionStrategy } from "../../treeCompressionUtils.js";
|
|
11
11
|
import type { FieldBatch } from "./fieldBatch.js";
|
|
12
|
-
import {
|
|
12
|
+
import { EncodedFieldBatch } from "./format.js";
|
|
13
13
|
import type { IncrementalEncodingPolicy } from "./incrementalEncodingPolicy.js";
|
|
14
14
|
/**
|
|
15
15
|
* Reference ID for a chunk that is incrementally encoded.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codecs.d.ts","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/codecs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAC;AAM5F,OAAO,EACN,KAAK,SAAS,EACd,KAAK,iBAAiB,EAEtB,KAAK,UAAU,EAEf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEN,KAAK,sBAAsB,EAC3B,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAGN,KAAK,KAAK,EACV,KAAK,sBAAsB,EAE3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAGxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,
|
|
1
|
+
{"version":3,"file":"codecs.d.ts","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/codecs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAC;AAM5F,OAAO,EACN,KAAK,SAAS,EACd,KAAK,iBAAiB,EAEtB,KAAK,UAAU,EAEf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEN,KAAK,sBAAsB,EAC3B,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAGN,KAAK,KAAK,EACV,KAAK,sBAAsB,EAE3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAGxE,OAAO,KAAK,EA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,aAAa,EAAE,uBAAuB,GACpC,SAAS,CAEX"}
|
|
@@ -8,7 +8,7 @@ import { FluidClientVersion, makeVersionedValidatedCodec, } from "../../../codec
|
|
|
8
8
|
import { brand, brandedNumberType, unbrand, } from "../../../util/index.js";
|
|
9
9
|
import { TreeCompressionStrategy } from "../../treeCompressionUtils.js";
|
|
10
10
|
import { decode } from "./chunkDecoding.js";
|
|
11
|
-
import { validVersions, FieldBatchFormatVersion
|
|
11
|
+
import { EncodedFieldBatch, validVersions, FieldBatchFormatVersion } from "./format.js";
|
|
12
12
|
import { schemaCompressedEncodeV1, schemaCompressedEncodeV2 } from "./schemaBasedEncode.js";
|
|
13
13
|
import { uncompressedEncodeV1, uncompressedEncodeV2 } from "./uncompressedEncode.js";
|
|
14
14
|
const ChunkReferenceId = brandedNumberType({ multipleOf: 1, minimum: 0 });
|
|
@@ -31,25 +31,25 @@ export function makeFieldBatchCodec(options) {
|
|
|
31
31
|
assert(validVersions.has(writeVersion), 0x935 /* Invalid write version for FieldBatch codec */);
|
|
32
32
|
let uncompressedEncodeFn;
|
|
33
33
|
let schemaCompressedEncodeFn;
|
|
34
|
-
let encodedFieldBatchType;
|
|
35
34
|
switch (writeVersion) {
|
|
36
35
|
case unbrand(FieldBatchFormatVersion.v1): {
|
|
37
36
|
uncompressedEncodeFn = uncompressedEncodeV1;
|
|
38
37
|
schemaCompressedEncodeFn = schemaCompressedEncodeV1;
|
|
39
|
-
encodedFieldBatchType = EncodedFieldBatchV1;
|
|
40
38
|
break;
|
|
41
39
|
}
|
|
42
40
|
case unbrand(FieldBatchFormatVersion.v2): {
|
|
43
41
|
uncompressedEncodeFn = uncompressedEncodeV2;
|
|
44
42
|
schemaCompressedEncodeFn = schemaCompressedEncodeV2;
|
|
45
|
-
encodedFieldBatchType = EncodedFieldBatchV2;
|
|
46
43
|
break;
|
|
47
44
|
}
|
|
48
45
|
default: {
|
|
49
46
|
unreachableCase(writeVersion);
|
|
50
47
|
}
|
|
51
48
|
}
|
|
52
|
-
|
|
49
|
+
// Both the encode and decode logic here support both v1 and v2, as does `validVersions` and `EncodedFieldBatch`.
|
|
50
|
+
// This makes this use of makeVersionedValidatedCodec atypical as it is a single call being used to make a codec that supports all versions,
|
|
51
|
+
// instead of one call per version, then using another utility to select between them based on version.
|
|
52
|
+
return makeVersionedValidatedCodec(options, validVersions, EncodedFieldBatch, {
|
|
53
53
|
encode: (data, context) => {
|
|
54
54
|
for (const cursor of data) {
|
|
55
55
|
assert(cursor.mode === 1 /* CursorLocationType.Fields */, 0x8a3 /* FieldBatch expects fields cursors */);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codecs.js","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/codecs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAG9E,OAAO,EACN,+BAA+B,EAC/B,yBAAyB,GACzB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAGN,kBAAkB,EAElB,2BAA2B,GAC3B,MAAM,yBAAyB,CAAC;AAOjC,OAAO,EACN,KAAK,EACL,iBAAiB,EAGjB,OAAO,GACP,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAExE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAEN,aAAa,EACb,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAC5F,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAMrF,MAAM,gBAAgB,GAAG,iBAAiB,CAAmB,EAAE,UAAU,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;AA6E5F;;;GAGG;AACH,S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AAM,CACZ,IAAI,EACJ;gBACC,YAAY,EAAE,OAAO,CAAC,YAAY;gBAClC,YAAY,EAAE,OAAO,CAAC,YAAY;aAClC,EACD,OAAO,CAAC,yBAAyB,CACjC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QAClC,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,+BAA+B,CAC9C,aAAsC;IAEtC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,gCAAgC,CAAC,aAAa,CAAC,EAAE,CAAC;AACzF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport type { IIdCompressor, SessionId } from \"@fluidframework/id-compressor\";\nimport type { MinimumVersionForCollab } from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tgetConfigForMinVersionForCollab,\n\tlowestMinVersionForCollab,\n} from \"@fluidframework/runtime-utils/internal\";\n\nimport {\n\ttype CodecTree,\n\ttype CodecWriteOptions,\n\tFluidClientVersion,\n\ttype IJsonCodec,\n\tmakeVersionedValidatedCodec,\n} from \"../../../codec/index.js\";\nimport {\n\tCursorLocationType,\n\ttype ITreeCursorSynchronous,\n\ttype SchemaAndPolicy,\n\ttype TreeChunk,\n} from \"../../../core/index.js\";\nimport {\n\tbrand,\n\tbrandedNumberType,\n\ttype Brand,\n\ttype JsonCompatibleReadOnly,\n\tunbrand,\n} from \"../../../util/index.js\";\nimport { TreeCompressionStrategy } from \"../../treeCompressionUtils.js\";\n\nimport { decode } from \"./chunkDecoding.js\";\nimport type { FieldBatch } from \"./fieldBatch.js\";\nimport {\n\ttype EncodedFieldBatch,\n\tvalidVersions,\n\tFieldBatchFormatVersion,\n\tEncodedFieldBatchV1,\n\tEncodedFieldBatchV2,\n} from \"./format.js\";\nimport type { IncrementalEncodingPolicy } from \"./incrementalEncodingPolicy.js\";\nimport { schemaCompressedEncodeV1, schemaCompressedEncodeV2 } from \"./schemaBasedEncode.js\";\nimport { uncompressedEncodeV1, uncompressedEncodeV2 } from \"./uncompressedEncode.js\";\n\n/**\n * Reference ID for a chunk that is incrementally encoded.\n */\nexport type ChunkReferenceId = Brand<number, \"forest.ChunkReferenceId\">;\nconst ChunkReferenceId = brandedNumberType<ChunkReferenceId>({ multipleOf: 1, minimum: 0 });\n\n/**\n * Properties for incremental encoding.\n * Fields that support incremental encoding will encode their chunks separately by calling `encodeIncrementalField`.\n * @remarks\n * This supports features like incremental summarization where the summary from these fields can be re-used if\n * unchanged between summaries.\n * Note that each of these chunks that are incrementally encoded is fully self-describing (contain its own shapes\n * list and identifier table) and does not rely on context from its parent.\n */\nexport interface IncrementalEncoder {\n\t/**\n\t * Returns whether a node / field should be incrementally encoded.\n\t * @remarks See {@link IncrementalEncodingPolicy}.\n\t */\n\tshouldEncodeIncrementally: IncrementalEncodingPolicy;\n\t/**\n\t * Called to encode an incremental field at the cursor.\n\t * The chunks for this field are encoded separately from the main buffer.\n\t * @param cursor - The cursor pointing to the field to encode.\n\t * @param chunkEncoder - A function that encodes the contents of the passed chunk in the field.\n\t * @returns The reference IDs of the encoded chunks in the field.\n\t * This is used to retrieve the encoded chunks later.\n\t */\n\tencodeIncrementalField(\n\t\tcursor: ITreeCursorSynchronous,\n\t\tchunkEncoder: (chunk: TreeChunk) => EncodedFieldBatch,\n\t): ChunkReferenceId[];\n}\n\n/**\n * Properties for incremental decoding.\n *\n * Fields that had their chunks incrementally encoded will retrieve them by calling `getEncodedIncrementalChunk`.\n * @remarks\n * See {@link IncrementalEncoder} for more details.\n */\nexport interface IncrementalDecoder {\n\t/**\n\t * Called to decode an incremental chunk with the given reference ID.\n\t * @param referenceId - The reference ID of the chunk to decode.\n\t * @param chunkDecoder - A function that decodes the chunk.\n\t * @returns The decoded chunk.\n\t */\n\tdecodeIncrementalChunk(\n\t\treferenceId: ChunkReferenceId,\n\t\tchunkDecoder: (encoded: EncodedFieldBatch) => TreeChunk,\n\t): TreeChunk;\n}\n/**\n * Combines the properties of {@link IncrementalEncoder} and {@link IncrementalDecoder}.\n */\nexport interface IncrementalEncoderDecoder extends IncrementalEncoder, IncrementalDecoder {}\n\nexport interface FieldBatchEncodingContext {\n\treadonly encodeType: TreeCompressionStrategy;\n\treadonly idCompressor: IIdCompressor;\n\treadonly originatorId: SessionId;\n\treadonly schema?: SchemaAndPolicy;\n\t/**\n\t * An encoder / decoder for encoding and decoding of incremental fields.\n\t * This will be defined if incremental encoding is supported and enabled.\n\t */\n\treadonly incrementalEncoderDecoder?: IncrementalEncoderDecoder;\n}\n/**\n * @remarks\n * Fields in this batch currently don't have field schema for the root, which limits optimizations.\n */\nexport type FieldBatchCodec = IJsonCodec<\n\tFieldBatch,\n\tEncodedFieldBatch,\n\tJsonCompatibleReadOnly,\n\tFieldBatchEncodingContext\n>;\n\n/**\n * Convert a MinimumVersionForCollab to write version for {@link FieldBatchCodec}.\n * @param clientVersion - The MinimumVersionForCollab to convert.\n */\nfunction clientVersionToFieldBatchVersion(\n\tclientVersion: MinimumVersionForCollab,\n): FieldBatchFormatVersion {\n\treturn brand(\n\t\tgetConfigForMinVersionForCollab(clientVersion, {\n\t\t\t[lowestMinVersionForCollab]: FieldBatchFormatVersion.v1,\n\t\t\t[FluidClientVersion.v2_73]: FieldBatchFormatVersion.v2,\n\t\t}),\n\t);\n}\n\nexport function makeFieldBatchCodec(options: CodecWriteOptions): FieldBatchCodec {\n\tconst writeVersion = clientVersionToFieldBatchVersion(options.minVersionForCollab);\n\t// Note: it's important that the decode function is schema-agnostic for this strategy/layering to work, since\n\t// the schema that an op was encoded in doesn't necessarily match the current schema for the document (e.g. if\n\t// decode is being run on a client that just submitted a schema change, but the op is from another client who has\n\t// yet to receive that change).\n\tassert(\n\t\tvalidVersions.has(writeVersion),\n\t\t0x935 /* Invalid write version for FieldBatch codec */,\n\t);\n\n\tlet uncompressedEncodeFn: typeof uncompressedEncodeV1 | typeof uncompressedEncodeV2;\n\tlet schemaCompressedEncodeFn:\n\t\t| typeof schemaCompressedEncodeV1\n\t\t| typeof schemaCompressedEncodeV2;\n\tlet encodedFieldBatchType: typeof EncodedFieldBatchV1 | typeof EncodedFieldBatchV2;\n\tswitch (writeVersion) {\n\t\tcase unbrand(FieldBatchFormatVersion.v1): {\n\t\t\tuncompressedEncodeFn = uncompressedEncodeV1;\n\t\t\tschemaCompressedEncodeFn = schemaCompressedEncodeV1;\n\t\t\tencodedFieldBatchType = EncodedFieldBatchV1;\n\t\t\tbreak;\n\t\t}\n\t\tcase unbrand(FieldBatchFormatVersion.v2): {\n\t\t\tuncompressedEncodeFn = uncompressedEncodeV2;\n\t\t\tschemaCompressedEncodeFn = schemaCompressedEncodeV2;\n\t\t\tencodedFieldBatchType = EncodedFieldBatchV2;\n\t\t\tbreak;\n\t\t}\n\t\tdefault: {\n\t\t\tunreachableCase(writeVersion);\n\t\t}\n\t}\n\n\treturn makeVersionedValidatedCodec(options, validVersions, encodedFieldBatchType, {\n\t\tencode: (data: FieldBatch, context: FieldBatchEncodingContext): EncodedFieldBatch => {\n\t\t\tfor (const cursor of data) {\n\t\t\t\tassert(\n\t\t\t\t\tcursor.mode === CursorLocationType.Fields,\n\t\t\t\t\t0x8a3 /* FieldBatch expects fields cursors */,\n\t\t\t\t);\n\t\t\t}\n\t\t\tlet encoded: EncodedFieldBatch;\n\t\t\tlet incrementalEncoder: IncrementalEncoder | undefined;\n\t\t\tswitch (context.encodeType) {\n\t\t\t\tcase TreeCompressionStrategy.Uncompressed: {\n\t\t\t\t\tencoded = uncompressedEncodeFn(data);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase TreeCompressionStrategy.CompressedIncremental: {\n\t\t\t\t\tassert(\n\t\t\t\t\t\twriteVersion >= FieldBatchFormatVersion.v2,\n\t\t\t\t\t\t0xca0 /* Unsupported FieldBatchFormatVersion for incremental encoding; must be v2 or higher */,\n\t\t\t\t\t);\n\t\t\t\t\t// Incremental encoding is only supported for CompressedIncremental.\n\t\t\t\t\tincrementalEncoder = context.incrementalEncoderDecoder;\n\t\t\t\t}\n\t\t\t\t// fallthrough\n\t\t\t\tcase TreeCompressionStrategy.Compressed: {\n\t\t\t\t\t// eslint-disable-next-line unicorn/prefer-ternary\n\t\t\t\t\tif (context.schema === undefined) {\n\t\t\t\t\t\t// TODO: consider enabling a somewhat compressed but not schema accelerated encode.\n\t\t\t\t\t\tencoded = uncompressedEncodeFn(data);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tencoded = schemaCompressedEncodeFn(\n\t\t\t\t\t\t\tcontext.schema.schema,\n\t\t\t\t\t\t\tcontext.schema.policy,\n\t\t\t\t\t\t\tdata,\n\t\t\t\t\t\t\tcontext.idCompressor,\n\t\t\t\t\t\t\tincrementalEncoder,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tunreachableCase(context.encodeType);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// TODO: consider checking input data was in schema.\n\t\t\treturn encoded;\n\t\t},\n\t\tdecode: (data: EncodedFieldBatch, context: FieldBatchEncodingContext): FieldBatch => {\n\t\t\t// TODO: consider checking data is in schema.\n\t\t\treturn decode(\n\t\t\t\tdata,\n\t\t\t\t{\n\t\t\t\t\tidCompressor: context.idCompressor,\n\t\t\t\t\toriginatorId: context.originatorId,\n\t\t\t\t},\n\t\t\t\tcontext.incrementalEncoderDecoder,\n\t\t\t).map((chunk) => chunk.cursor());\n\t\t},\n\t});\n}\n\nexport function getCodecTreeForFieldBatchFormat(\n\tclientVersion: MinimumVersionForCollab,\n): CodecTree {\n\treturn { name: \"FieldBatch\", version: clientVersionToFieldBatchVersion(clientVersion) };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"codecs.js","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/cod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BAAkB,GAAG,OAAO,CAAC,yBAAyB,CAAC;gBACxD,CAAC;gBACD,cAAc;gBACd,KAAK,uBAAuB,CAAC,UAAU,CAAC,CAAC,CAAC;oBACzC,kDAAkD;oBAClD,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;wBAClC,mFAAmF;wBACnF,OAAO,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC;oBACtC,CAAC;yBAAM,CAAC;wBACP,OAAO,GAAG,wBAAwB,CACjC,OAAO,CAAC,MAAM,CAAC,MAAM,EACrB,OAAO,CAAC,MAAM,CAAC,MAAM,EACrB,IAAI,EACJ,OAAO,CAAC,YAAY,EACpB,kBAAkB,CAClB,CAAC;oBACH,CAAC;oBAED,MAAM;gBACP,CAAC;gBACD,OAAO,CAAC,CAAC,CAAC;oBACT,eAAe,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;gBACrC,CAAC;YACF,CAAC;YAED,oDAAoD;YACpD,OAAO,OAAO,CAAC;QAChB,CAAC;QACD,MAAM,EAAE,CAAC,IAAuB,EAAE,OAAkC,EAAc,EAAE;YACnF,6CAA6C;YAC7C,OAAO,MAAM,CACZ,IAAI,EACJ;gBACC,YAAY,EAAE,OAAO,CAAC,YAAY;gBAClC,YAAY,EAAE,OAAO,CAAC,YAAY;aAClC,EACD,OAAO,CAAC,yBAAyB,CACjC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QAClC,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,+BAA+B,CAC9C,aAAsC;IAEtC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,gCAAgC,CAAC,aAAa,CAAC,EAAE,CAAC;AACzF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport type { IIdCompressor, SessionId } from \"@fluidframework/id-compressor\";\nimport type { MinimumVersionForCollab } from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tgetConfigForMinVersionForCollab,\n\tlowestMinVersionForCollab,\n} from \"@fluidframework/runtime-utils/internal\";\n\nimport {\n\ttype CodecTree,\n\ttype CodecWriteOptions,\n\tFluidClientVersion,\n\ttype IJsonCodec,\n\tmakeVersionedValidatedCodec,\n} from \"../../../codec/index.js\";\nimport {\n\tCursorLocationType,\n\ttype ITreeCursorSynchronous,\n\ttype SchemaAndPolicy,\n\ttype TreeChunk,\n} from \"../../../core/index.js\";\nimport {\n\tbrand,\n\tbrandedNumberType,\n\ttype Brand,\n\ttype JsonCompatibleReadOnly,\n\tunbrand,\n} from \"../../../util/index.js\";\nimport { TreeCompressionStrategy } from \"../../treeCompressionUtils.js\";\n\nimport { decode } from \"./chunkDecoding.js\";\nimport type { FieldBatch } from \"./fieldBatch.js\";\nimport { EncodedFieldBatch, validVersions, FieldBatchFormatVersion } from \"./format.js\";\nimport type { IncrementalEncodingPolicy } from \"./incrementalEncodingPolicy.js\";\nimport { schemaCompressedEncodeV1, schemaCompressedEncodeV2 } from \"./schemaBasedEncode.js\";\nimport { uncompressedEncodeV1, uncompressedEncodeV2 } from \"./uncompressedEncode.js\";\n\n/**\n * Reference ID for a chunk that is incrementally encoded.\n */\nexport type ChunkReferenceId = Brand<number, \"forest.ChunkReferenceId\">;\nconst ChunkReferenceId = brandedNumberType<ChunkReferenceId>({ multipleOf: 1, minimum: 0 });\n\n/**\n * Properties for incremental encoding.\n * Fields that support incremental encoding will encode their chunks separately by calling `encodeIncrementalField`.\n * @remarks\n * This supports features like incremental summarization where the summary from these fields can be re-used if\n * unchanged between summaries.\n * Note that each of these chunks that are incrementally encoded is fully self-describing (contain its own shapes\n * list and identifier table) and does not rely on context from its parent.\n */\nexport interface IncrementalEncoder {\n\t/**\n\t * Returns whether a node / field should be incrementally encoded.\n\t * @remarks See {@link IncrementalEncodingPolicy}.\n\t */\n\tshouldEncodeIncrementally: IncrementalEncodingPolicy;\n\t/**\n\t * Called to encode an incremental field at the cursor.\n\t * The chunks for this field are encoded separately from the main buffer.\n\t * @param cursor - The cursor pointing to the field to encode.\n\t * @param chunkEncoder - A function that encodes the contents of the passed chunk in the field.\n\t * @returns The reference IDs of the encoded chunks in the field.\n\t * This is used to retrieve the encoded chunks later.\n\t */\n\tencodeIncrementalField(\n\t\tcursor: ITreeCursorSynchronous,\n\t\tchunkEncoder: (chunk: TreeChunk) => EncodedFieldBatch,\n\t): ChunkReferenceId[];\n}\n\n/**\n * Properties for incremental decoding.\n *\n * Fields that had their chunks incrementally encoded will retrieve them by calling `getEncodedIncrementalChunk`.\n * @remarks\n * See {@link IncrementalEncoder} for more details.\n */\nexport interface IncrementalDecoder {\n\t/**\n\t * Called to decode an incremental chunk with the given reference ID.\n\t * @param referenceId - The reference ID of the chunk to decode.\n\t * @param chunkDecoder - A function that decodes the chunk.\n\t * @returns The decoded chunk.\n\t */\n\tdecodeIncrementalChunk(\n\t\treferenceId: ChunkReferenceId,\n\t\tchunkDecoder: (encoded: EncodedFieldBatch) => TreeChunk,\n\t): TreeChunk;\n}\n/**\n * Combines the properties of {@link IncrementalEncoder} and {@link IncrementalDecoder}.\n */\nexport interface IncrementalEncoderDecoder extends IncrementalEncoder, IncrementalDecoder {}\n\nexport interface FieldBatchEncodingContext {\n\treadonly encodeType: TreeCompressionStrategy;\n\treadonly idCompressor: IIdCompressor;\n\treadonly originatorId: SessionId;\n\treadonly schema?: SchemaAndPolicy;\n\t/**\n\t * An encoder / decoder for encoding and decoding of incremental fields.\n\t * This will be defined if incremental encoding is supported and enabled.\n\t */\n\treadonly incrementalEncoderDecoder?: IncrementalEncoderDecoder;\n}\n/**\n * @remarks\n * Fields in this batch currently don't have field schema for the root, which limits optimizations.\n */\nexport type FieldBatchCodec = IJsonCodec<\n\tFieldBatch,\n\tEncodedFieldBatch,\n\tJsonCompatibleReadOnly,\n\tFieldBatchEncodingContext\n>;\n\n/**\n * Convert a MinimumVersionForCollab to write version for {@link FieldBatchCodec}.\n * @param clientVersion - The MinimumVersionForCollab to convert.\n */\nfunction clientVersionToFieldBatchVersion(\n\tclientVersion: MinimumVersionForCollab,\n): FieldBatchFormatVersion {\n\treturn brand(\n\t\tgetConfigForMinVersionForCollab(clientVersion, {\n\t\t\t[lowestMinVersionForCollab]: FieldBatchFormatVersion.v1,\n\t\t\t[FluidClientVersion.v2_73]: FieldBatchFormatVersion.v2,\n\t\t}),\n\t);\n}\n\nexport function makeFieldBatchCodec(options: CodecWriteOptions): FieldBatchCodec {\n\tconst writeVersion = clientVersionToFieldBatchVersion(options.minVersionForCollab);\n\t// Note: it's important that the decode function is schema-agnostic for this strategy/layering to work, since\n\t// the schema that an op was encoded in doesn't necessarily match the current schema for the document (e.g. if\n\t// decode is being run on a client that just submitted a schema change, but the op is from another client who has\n\t// yet to receive that change).\n\tassert(\n\t\tvalidVersions.has(writeVersion),\n\t\t0x935 /* Invalid write version for FieldBatch codec */,\n\t);\n\n\tlet uncompressedEncodeFn: typeof uncompressedEncodeV1 | typeof uncompressedEncodeV2;\n\tlet schemaCompressedEncodeFn:\n\t\t| typeof schemaCompressedEncodeV1\n\t\t| typeof schemaCompressedEncodeV2;\n\tswitch (writeVersion) {\n\t\tcase unbrand(FieldBatchFormatVersion.v1): {\n\t\t\tuncompressedEncodeFn = uncompressedEncodeV1;\n\t\t\tschemaCompressedEncodeFn = schemaCompressedEncodeV1;\n\t\t\tbreak;\n\t\t}\n\t\tcase unbrand(FieldBatchFormatVersion.v2): {\n\t\t\tuncompressedEncodeFn = uncompressedEncodeV2;\n\t\t\tschemaCompressedEncodeFn = schemaCompressedEncodeV2;\n\t\t\tbreak;\n\t\t}\n\t\tdefault: {\n\t\t\tunreachableCase(writeVersion);\n\t\t}\n\t}\n\n\t// Both the encode and decode logic here support both v1 and v2, as does `validVersions` and `EncodedFieldBatch`.\n\t// This makes this use of makeVersionedValidatedCodec atypical as it is a single call being used to make a codec that supports all versions,\n\t// instead of one call per version, then using another utility to select between them based on version.\n\treturn makeVersionedValidatedCodec(options, validVersions, EncodedFieldBatch, {\n\t\tencode: (data: FieldBatch, context: FieldBatchEncodingContext): EncodedFieldBatch => {\n\t\t\tfor (const cursor of data) {\n\t\t\t\tassert(\n\t\t\t\t\tcursor.mode === CursorLocationType.Fields,\n\t\t\t\t\t0x8a3 /* FieldBatch expects fields cursors */,\n\t\t\t\t);\n\t\t\t}\n\t\t\tlet encoded: EncodedFieldBatch;\n\t\t\tlet incrementalEncoder: IncrementalEncoder | undefined;\n\t\t\tswitch (context.encodeType) {\n\t\t\t\tcase TreeCompressionStrategy.Uncompressed: {\n\t\t\t\t\tencoded = uncompressedEncodeFn(data);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase TreeCompressionStrategy.CompressedIncremental: {\n\t\t\t\t\tassert(\n\t\t\t\t\t\twriteVersion >= FieldBatchFormatVersion.v2,\n\t\t\t\t\t\t0xca0 /* Unsupported FieldBatchFormatVersion for incremental encoding; must be v2 or higher */,\n\t\t\t\t\t);\n\t\t\t\t\t// Incremental encoding is only supported for CompressedIncremental.\n\t\t\t\t\tincrementalEncoder = context.incrementalEncoderDecoder;\n\t\t\t\t}\n\t\t\t\t// fallthrough\n\t\t\t\tcase TreeCompressionStrategy.Compressed: {\n\t\t\t\t\t// eslint-disable-next-line unicorn/prefer-ternary\n\t\t\t\t\tif (context.schema === undefined) {\n\t\t\t\t\t\t// TODO: consider enabling a somewhat compressed but not schema accelerated encode.\n\t\t\t\t\t\tencoded = uncompressedEncodeFn(data);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tencoded = schemaCompressedEncodeFn(\n\t\t\t\t\t\t\tcontext.schema.schema,\n\t\t\t\t\t\t\tcontext.schema.policy,\n\t\t\t\t\t\t\tdata,\n\t\t\t\t\t\t\tcontext.idCompressor,\n\t\t\t\t\t\t\tincrementalEncoder,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tunreachableCase(context.encodeType);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// TODO: consider checking input data was in schema.\n\t\t\treturn encoded;\n\t\t},\n\t\tdecode: (data: EncodedFieldBatch, context: FieldBatchEncodingContext): FieldBatch => {\n\t\t\t// TODO: consider checking data is in schema.\n\t\t\treturn decode(\n\t\t\t\tdata,\n\t\t\t\t{\n\t\t\t\t\tidCompressor: context.idCompressor,\n\t\t\t\t\toriginatorId: context.originatorId,\n\t\t\t\t},\n\t\t\t\tcontext.incrementalEncoderDecoder,\n\t\t\t).map((chunk) => chunk.cursor());\n\t\t},\n\t});\n}\n\nexport function getCodecTreeForFieldBatchFormat(\n\tclientVersion: MinimumVersionForCollab,\n): CodecTree {\n\treturn { name: \"FieldBatch\", version: clientVersionToFieldBatchVersion(clientVersion) };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/forest-summary/codec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAC;
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/forest-summary/codec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAC;AAO5F,OAAO,EACN,KAAK,SAAS,EACd,KAAK,iBAAiB,EAEtB,KAAK,UAAU,EAEf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAS,KAAK,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAE7F,OAAO,EAAE,mBAAmB,EAAiB,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIpF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;AACrE,MAAM,MAAM,WAAW,GAAG,UAAU,CACnC,QAAQ,EACR,MAAM,EACN,sBAAsB,EACtB,yBAAyB,CACzB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kCAAkC,CACjD,aAAa,EAAE,uBAAuB,GACpC,mBAAmB,CAOrB;AAED,wBAAgB,yBAAyB,CACxC,OAAO,EAAE,iBAAiB,EAC1B,eAAe,EAAE,eAAe,GAC9B,WAAW,CA2Bb;AAED,wBAAgB,2BAA2B,CAC1C,aAAa,EAAE,uBAAuB,GACpC,SAAS,CAEX"}
|
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { assert, oob } from "@fluidframework/core-utils/internal";
|
|
6
6
|
import { getConfigForMinVersionForCollab, lowestMinVersionForCollab, } from "@fluidframework/runtime-utils/internal";
|
|
7
|
+
import { Type } from "@sinclair/typebox";
|
|
7
8
|
import { FluidClientVersion, makeVersionedValidatedCodec, } from "../../codec/index.js";
|
|
8
9
|
import { brand } from "../../util/index.js";
|
|
9
|
-
import { ForestFormatVersion, validVersions
|
|
10
|
+
import { ForestFormatVersion, validVersions } from "./formatCommon.js";
|
|
11
|
+
import { FormatV1 } from "./formatV1.js";
|
|
12
|
+
import { FormatV2 } from "./formatV2.js";
|
|
10
13
|
/**
|
|
11
14
|
* Convert a MinimumVersionForCollab to a ForestFormatVersion.
|
|
12
15
|
* @param clientVersion - The MinimumVersionForCollab to convert.
|
|
@@ -21,7 +24,10 @@ export function clientVersionToForestFormatVersion(clientVersion) {
|
|
|
21
24
|
export function makeForestSummarizerCodec(options, fieldBatchCodec) {
|
|
22
25
|
const inner = fieldBatchCodec;
|
|
23
26
|
const writeVersion = clientVersionToForestFormatVersion(options.minVersionForCollab);
|
|
24
|
-
const formatSchema =
|
|
27
|
+
const formatSchema = Type.Union([FormatV1, FormatV2]);
|
|
28
|
+
// Both the encode and decode logic here support both v1 and v2, as does `validVersions` and `formatSchema`.
|
|
29
|
+
// This makes this use of makeVersionedValidatedCodec atypical as it is a single call being used to make a codec that supports all versions,
|
|
30
|
+
// instead of one call per version, then using another utility to select between them based on version.
|
|
25
31
|
return makeVersionedValidatedCodec(options, validVersions, formatSchema, {
|
|
26
32
|
encode: (data, context) => {
|
|
27
33
|
const keys = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../../src/feature-libraries/forest-summary/codec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,EACN,+BAA+B,EAC/B,yBAAyB,GACzB,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../../src/feature-libraries/forest-summary/codec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,EACN,+BAA+B,EAC/B,yBAAyB,GACzB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAGN,kBAAkB,EAElB,2BAA2B,GAC3B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,KAAK,EAA+B,MAAM,qBAAqB,CAAC;AAGzE,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAe,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAazC;;;;GAIG;AACH,MAAM,UAAU,kCAAkC,CACjD,aAAsC;IAEtC,OAAO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AAI,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,wBAAwB,CAAC,CAAC;YAC3E,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;gBAC/C,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,EAAE,EAAE,KAAK,CAAC,CAAC;YAC3C,CAAC;YACD,OAAO,GAAG,CAAC;QACZ,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B,CAC1C,aAAsC;IAEtC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,kCAAkC,CAAC,aAAa,CAAC,EAAE,CAAC;AACvF,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 type { MinimumVersionForCollab } from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tgetConfigForMinVersionForCollab,\n\tlowestMinVersionForCollab,\n} from \"@fluidframework/runtime-utils/internal\";\nimport { Type } from \"@sinclair/typebox\";\n\nimport {\n\ttype CodecTree,\n\ttype CodecWriteOptions,\n\tFluidClientVersion,\n\ttype IJsonCodec,\n\tmakeVersionedValidatedCodec,\n} from \"../../codec/index.js\";\nimport type { FieldKey, ITreeCursorSynchronous } from \"../../core/index.js\";\nimport { brand, type JsonCompatibleReadOnly } from \"../../util/index.js\";\nimport type { FieldBatchCodec, FieldBatchEncodingContext } from \"../chunked-forest/index.js\";\n\nimport { ForestFormatVersion, validVersions, type Format } from \"./formatCommon.js\";\nimport { FormatV1 } from \"./formatV1.js\";\nimport { FormatV2 } from \"./formatV2.js\";\n\n/**\n * Uses field cursors\n */\nexport type FieldSet = ReadonlyMap<FieldKey, ITreeCursorSynchronous>;\nexport type ForestCodec = IJsonCodec<\n\tFieldSet,\n\tFormat,\n\tJsonCompatibleReadOnly,\n\tFieldBatchEncodingContext\n>;\n\n/**\n * Convert a MinimumVersionForCollab to a ForestFormatVersion.\n * @param clientVersion - The MinimumVersionForCollab to convert.\n * @returns The ForestFormatVersion that corresponds to the provided MinimumVersionForCollab.\n */\nexport function clientVersionToForestFormatVersion(\n\tclientVersion: MinimumVersionForCollab,\n): ForestFormatVersion {\n\treturn brand(\n\t\tgetConfigForMinVersionForCollab(clientVersion, {\n\t\t\t[lowestMinVersionForCollab]: ForestFormatVersion.v1,\n\t\t\t[FluidClientVersion.v2_74]: ForestFormatVersion.v2,\n\t\t}),\n\t);\n}\n\nexport function makeForestSummarizerCodec(\n\toptions: CodecWriteOptions,\n\tfieldBatchCodec: FieldBatchCodec,\n): ForestCodec {\n\tconst inner = fieldBatchCodec;\n\tconst writeVersion = clientVersionToForestFormatVersion(options.minVersionForCollab);\n\tconst formatSchema = Type.Union([FormatV1, FormatV2]);\n\t// Both the encode and decode logic here support both v1 and v2, as does `validVersions` and `formatSchema`.\n\t// This makes this use of makeVersionedValidatedCodec atypical as it is a single call being used to make a codec that supports all versions,\n\t// instead of one call per version, then using another utility to select between them based on version.\n\treturn makeVersionedValidatedCodec(options, validVersions, formatSchema, {\n\t\tencode: (data: FieldSet, context: FieldBatchEncodingContext): Format => {\n\t\t\tconst keys: FieldKey[] = [];\n\t\t\tconst fields: ITreeCursorSynchronous[] = [];\n\t\t\tfor (const [key, value] of data) {\n\t\t\t\tkeys.push(key);\n\t\t\t\tfields.push(value);\n\t\t\t}\n\t\t\treturn { keys, fields: inner.encode(fields, context), version: writeVersion };\n\t\t},\n\t\tdecode: (data: Format, context: FieldBatchEncodingContext): FieldSet => {\n\t\t\tconst out: Map<FieldKey, ITreeCursorSynchronous> = new Map();\n\t\t\tconst fields = inner.decode(data.fields, context);\n\t\t\tassert(data.keys.length === fields.length, 0x891 /* mismatched lengths */);\n\t\t\tfor (const [index, field] of fields.entries()) {\n\t\t\t\tout.set(data.keys[index] ?? oob(), field);\n\t\t\t}\n\t\t\treturn out;\n\t\t},\n\t});\n}\n\nexport function getCodecTreeForForestFormat(\n\tclientVersion: MinimumVersionForCollab,\n): CodecTree {\n\treturn { name: \"Forest\", version: clientVersionToForestFormatVersion(clientVersion) };\n}\n"]}
|
|
@@ -14,10 +14,10 @@ export declare const ForestFormatVersion: {
|
|
|
14
14
|
};
|
|
15
15
|
export type ForestFormatVersion = Values<typeof ForestFormatVersion>;
|
|
16
16
|
export declare const validVersions: Set<import("../../util/brand.js").Brand<1, "ForestFormatVersion"> | import("../../util/brand.js").Brand<2, "ForestFormatVersion">>;
|
|
17
|
-
export declare const FormatCommon: (version:
|
|
18
|
-
version: import("@sinclair/typebox").TLiteral<
|
|
17
|
+
export declare const FormatCommon: <const TVersion extends ForestFormatVersion>(version: TVersion) => import("@sinclair/typebox").TObject<{
|
|
18
|
+
version: import("@sinclair/typebox").TLiteral<TVersion>;
|
|
19
19
|
keys: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnsafe<schemaFormatV1.FieldKey>>;
|
|
20
20
|
fields: import("@sinclair/typebox").TUnsafe<import("../../util/utils.js").JsonCompatibleReadOnly>;
|
|
21
21
|
}>;
|
|
22
|
-
export type Format = Static<ReturnType<typeof FormatCommon
|
|
22
|
+
export type Format<TVersion extends ForestFormatVersion = ForestFormatVersion> = Static<ReturnType<typeof FormatCommon<TVersion>>>;
|
|
23
23
|
//# sourceMappingURL=formatCommon.d.ts.map
|