@fluidframework/tree 2.3.0 → 2.4.0-294316

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/api-report/tree.alpha.api.md +21 -12
  2. package/api-report/tree.beta.api.md +14 -5
  3. package/api-report/tree.legacy.alpha.api.md +14 -5
  4. package/api-report/tree.legacy.public.api.md +14 -5
  5. package/api-report/tree.public.api.md +14 -5
  6. package/dist/alpha.d.ts +1 -0
  7. package/dist/beta.d.ts +1 -0
  8. package/dist/core/index.d.ts +1 -1
  9. package/dist/core/index.d.ts.map +1 -1
  10. package/dist/core/index.js +2 -1
  11. package/dist/core/index.js.map +1 -1
  12. package/dist/core/rebase/index.d.ts +1 -1
  13. package/dist/core/rebase/index.d.ts.map +1 -1
  14. package/dist/core/rebase/index.js +2 -1
  15. package/dist/core/rebase/index.js.map +1 -1
  16. package/dist/core/rebase/types.d.ts +1 -0
  17. package/dist/core/rebase/types.d.ts.map +1 -1
  18. package/dist/core/rebase/types.js +8 -1
  19. package/dist/core/rebase/types.js.map +1 -1
  20. package/dist/core/schema-stored/schema.d.ts.map +1 -1
  21. package/dist/core/schema-stored/schema.js.map +1 -1
  22. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +7 -0
  23. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  24. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +61 -17
  25. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  26. package/dist/feature-libraries/sequence-field/compose.d.ts.map +1 -1
  27. package/dist/feature-libraries/sequence-field/compose.js +3 -0
  28. package/dist/feature-libraries/sequence-field/compose.js.map +1 -1
  29. package/dist/feature-libraries/sequence-field/utils.d.ts.map +1 -1
  30. package/dist/feature-libraries/sequence-field/utils.js +1 -4
  31. package/dist/feature-libraries/sequence-field/utils.js.map +1 -1
  32. package/dist/index.d.ts +1 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/legacy.d.ts +1 -0
  36. package/dist/packageVersion.d.ts +1 -1
  37. package/dist/packageVersion.d.ts.map +1 -1
  38. package/dist/packageVersion.js +1 -1
  39. package/dist/packageVersion.js.map +1 -1
  40. package/dist/public.d.ts +1 -0
  41. package/dist/shared-tree/schematizingTreeView.d.ts +1 -0
  42. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  43. package/dist/shared-tree/schematizingTreeView.js +3 -0
  44. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  45. package/dist/simple-tree/api/jsonSchema.d.ts +13 -14
  46. package/dist/simple-tree/api/jsonSchema.d.ts.map +1 -1
  47. package/dist/simple-tree/api/jsonSchema.js.map +1 -1
  48. package/dist/simple-tree/api/schemaFactory.d.ts +8 -2
  49. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  50. package/dist/simple-tree/api/schemaFactory.js +6 -0
  51. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  52. package/dist/simple-tree/api/simpleSchema.d.ts +4 -0
  53. package/dist/simple-tree/api/simpleSchema.d.ts.map +1 -1
  54. package/dist/simple-tree/api/simpleSchema.js.map +1 -1
  55. package/dist/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
  56. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +30 -17
  57. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  58. package/dist/simple-tree/api/tree.d.ts +4 -0
  59. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  60. package/dist/simple-tree/api/tree.js.map +1 -1
  61. package/dist/simple-tree/api/viewSchemaToSimpleSchema.js +4 -0
  62. package/dist/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
  63. package/dist/simple-tree/index.d.ts +1 -1
  64. package/dist/simple-tree/index.d.ts.map +1 -1
  65. package/dist/simple-tree/index.js.map +1 -1
  66. package/dist/simple-tree/schemaTypes.d.ts +44 -4
  67. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  68. package/dist/simple-tree/schemaTypes.js +10 -0
  69. package/dist/simple-tree/schemaTypes.js.map +1 -1
  70. package/lib/alpha.d.ts +1 -0
  71. package/lib/beta.d.ts +1 -0
  72. package/lib/core/index.d.ts +1 -1
  73. package/lib/core/index.d.ts.map +1 -1
  74. package/lib/core/index.js +1 -1
  75. package/lib/core/index.js.map +1 -1
  76. package/lib/core/rebase/index.d.ts +1 -1
  77. package/lib/core/rebase/index.d.ts.map +1 -1
  78. package/lib/core/rebase/index.js +1 -1
  79. package/lib/core/rebase/index.js.map +1 -1
  80. package/lib/core/rebase/types.d.ts +1 -0
  81. package/lib/core/rebase/types.d.ts.map +1 -1
  82. package/lib/core/rebase/types.js +6 -0
  83. package/lib/core/rebase/types.js.map +1 -1
  84. package/lib/core/schema-stored/schema.d.ts.map +1 -1
  85. package/lib/core/schema-stored/schema.js.map +1 -1
  86. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +7 -0
  87. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  88. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +62 -18
  89. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  90. package/lib/feature-libraries/sequence-field/compose.d.ts.map +1 -1
  91. package/lib/feature-libraries/sequence-field/compose.js +3 -0
  92. package/lib/feature-libraries/sequence-field/compose.js.map +1 -1
  93. package/lib/feature-libraries/sequence-field/utils.d.ts.map +1 -1
  94. package/lib/feature-libraries/sequence-field/utils.js +2 -5
  95. package/lib/feature-libraries/sequence-field/utils.js.map +1 -1
  96. package/lib/index.d.ts +1 -1
  97. package/lib/index.d.ts.map +1 -1
  98. package/lib/index.js.map +1 -1
  99. package/lib/legacy.d.ts +1 -0
  100. package/lib/packageVersion.d.ts +1 -1
  101. package/lib/packageVersion.d.ts.map +1 -1
  102. package/lib/packageVersion.js +1 -1
  103. package/lib/packageVersion.js.map +1 -1
  104. package/lib/public.d.ts +1 -0
  105. package/lib/shared-tree/schematizingTreeView.d.ts +1 -0
  106. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  107. package/lib/shared-tree/schematizingTreeView.js +3 -0
  108. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  109. package/lib/simple-tree/api/jsonSchema.d.ts +13 -14
  110. package/lib/simple-tree/api/jsonSchema.d.ts.map +1 -1
  111. package/lib/simple-tree/api/jsonSchema.js.map +1 -1
  112. package/lib/simple-tree/api/schemaFactory.d.ts +8 -2
  113. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  114. package/lib/simple-tree/api/schemaFactory.js +6 -0
  115. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  116. package/lib/simple-tree/api/simpleSchema.d.ts +4 -0
  117. package/lib/simple-tree/api/simpleSchema.d.ts.map +1 -1
  118. package/lib/simple-tree/api/simpleSchema.js.map +1 -1
  119. package/lib/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
  120. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +31 -18
  121. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  122. package/lib/simple-tree/api/tree.d.ts +4 -0
  123. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  124. package/lib/simple-tree/api/tree.js.map +1 -1
  125. package/lib/simple-tree/api/viewSchemaToSimpleSchema.js +4 -0
  126. package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
  127. package/lib/simple-tree/index.d.ts +1 -1
  128. package/lib/simple-tree/index.d.ts.map +1 -1
  129. package/lib/simple-tree/index.js.map +1 -1
  130. package/lib/simple-tree/schemaTypes.d.ts +44 -4
  131. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  132. package/lib/simple-tree/schemaTypes.js +10 -0
  133. package/lib/simple-tree/schemaTypes.js.map +1 -1
  134. package/package.json +32 -22
  135. package/src/core/index.ts +1 -0
  136. package/src/core/rebase/index.ts +1 -0
  137. package/src/core/rebase/types.ts +11 -0
  138. package/src/core/schema-stored/schema.ts +1 -0
  139. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +97 -10
  140. package/src/feature-libraries/sequence-field/compose.ts +3 -0
  141. package/src/feature-libraries/sequence-field/utils.ts +2 -4
  142. package/src/index.ts +1 -0
  143. package/src/packageVersion.ts +1 -1
  144. package/src/shared-tree/schematizingTreeView.ts +4 -0
  145. package/src/simple-tree/api/jsonSchema.ts +19 -17
  146. package/src/simple-tree/api/schemaFactory.ts +12 -6
  147. package/src/simple-tree/api/simpleSchema.ts +5 -0
  148. package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +40 -19
  149. package/src/simple-tree/api/tree.ts +5 -0
  150. package/src/simple-tree/api/viewSchemaToSimpleSchema.ts +7 -2
  151. package/src/simple-tree/index.ts +1 -0
  152. package/src/simple-tree/schemaTypes.ts +55 -5
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/core/schema-stored/schema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAoB,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAIN,oBAAoB,GAGpB,MAAM,aAAa,CAAC;AAGrB;;;GAGG;AACH,MAAM,CAAN,IAAY,WAMX;AAND,WAAY,WAAW;IACtB,iDAAM,CAAA;IACN,iDAAM,CAAA;IACN,mDAAO,CAAA;IACP,2DAAW,CAAA;IACX,6CAAI,CAAA;AACL,CAAC,EANW,WAAW,KAAX,WAAW,QAMtB;AAiFD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,WAAW,CAAC;AAExD;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAA0B;IAC5D,4CAA4C;IAC5C,IAAI,EAAE,KAAK,CAAC,4BAA4B,CAAC;IACzC,qFAAqF;IACrF,KAAK,EAAE,IA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,EAAE,oBAAoB,CAAC,OAAO,CAAC;IACnD,CAAC,WAAW,CAAC,WAAW,EAAE,oBAAoB,CAAC,WAAW,CAAC;IAC3D,CAAC,WAAW,CAAC,IAAI,EAAE,oBAAoB,CAAC,IAAI,CAAC;CAC7C,CAAC,CAAC;AAEH,MAAM,iBAAiB,GAAG,SAAS,CAAC,iBAAiB,CAAC,CAAC;AAEvD,SAAS,iBAAiB,CAAC,QAAqB;IAC/C,OAAO,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,8BAA8B,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,iBAAiB,CAAC,QAA8B;IACxD,OAAO,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,qBAAqB,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAA6B;IAC9D,OAAO;QACN,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,iHAAiH;QACjH,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE;KAC/B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAyB;IAC1D,MAAM,GAAG,GAA0B;QAClC,kFAAkF;QAClF,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;KAC5B,CAAC;IACF,OAAO,GAAG,CAAC;AACZ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ErasedType } from \"@fluidframework/core-interfaces\";\nimport { DiscriminatedUnionDispatcher } from \"../../codec/index.js\";\nimport { type MakeNominal, brand, fail, invertMap } from \"../../util/index.js\";\nimport {\n\ttype FieldKey,\n\ttype FieldKindIdentifier,\n\ttype FieldSchemaFormat,\n\tPersistedValueSchema,\n\ttype TreeNodeSchemaDataFormat,\n\ttype TreeNodeSchemaIdentifier,\n} from \"./format.js\";\nimport type { Multiplicity } from \"./multiplicity.js\";\n\n/**\n * Schema for what {@link TreeValue} is allowed on a Leaf node.\n * @internal\n */\nexport enum ValueSchema {\n\tNumber,\n\tString,\n\tBoolean,\n\tFluidHandle,\n\tNull,\n}\n\n/**\n * Set of allowed tree types.\n * Providing multiple values here allows polymorphism, tagged union style.\n *\n * In the future, this could be extended to allow inlining a TreeNodeStoredSchema here\n * (or some similar structural schema system).\n * For structural types which could go here, there are a few interesting options:\n *\n * - Allow replacing the whole set with a structural type for terminal / non-tree data,\n * and use this as a replacement for values on the tree nodes.\n *\n * - Allow expression structural constraints for child trees, for example requiring specific traits\n * (ex: via TreeNodeStoredSchema), instead of by type.\n *\n * There are two ways this could work:\n *\n * - Constrain the child nodes based on their shape:\n * this makes schema safe editing difficult because nodes would incur extra editing constraints to prevent them\n * from going out of schema based on their location in such a field.\n *\n * - Constrain the types allowed based on which types guarantee their data will always meet the constraints.\n *\n * Care would need to be taken to make sure this is sound for the schema updating mechanisms.\n * @internal\n */\nexport type TreeTypeSet = ReadonlySet<TreeNodeSchemaIdentifier>;\n\n/**\n * Declarative portion of a Field Kind.\n *\n * @remarks\n * Enough info about a field kind to know if a given tree is is schema.\n */\nexport interface FieldKindData {\n\treadonly identifier: FieldKindIdentifier;\n\treadonly multiplicity: Multiplicity;\n}\n\n/**\n * Everything needed to define what it means for a tree to be in schema.\n */\nexport interface SchemaAndPolicy {\n\treadonly schema: StoredSchemaCollection;\n\treadonly policy: SchemaPolicy;\n}\n\n/**\n * Extra data needed to interpret schema.\n */\nexport interface SchemaPolicy {\n\t/**\n\t * Policy information about FieldKinds:\n\t * This is typically stored as code, not in documents, and defines how to handle fields based on their kind.\n\t * It is assumed that all users of a document will have exactly the same FieldKind policies,\n\t * though older applications might be missing some,\n\t * and will be unable to process any changes that use those FieldKinds.\n\t */\n\treadonly fieldKinds: ReadonlyMap<FieldKindIdentifier, FieldKindData>;\n\n\t/**\n\t * If true, new content inserted into the tree should be validated against the stored schema.\n\t */\n\treadonly validateSchema: boolean;\n}\n\n/**\n * Schema for a field.\n * Object implementing this interface should never be modified.\n * @internal\n */\nexport interface TreeFieldStoredSchema {\n\treadonly kind: FieldKindIdentifier;\n\t/**\n\t * The set of allowed child types.\n\t * If not specified, types are unconstrained.\n\t */\n\treadonly types: TreeTypeSet;\n}\n\n/**\n * Identifier used for the FieldKind for fields which must be empty.\n *\n * @remarks\n * This mainly show up in:\n * 1. The root default field for documents.\n * 2. The schema used for out of schema fields (which thus must be empty/not exist) on object and leaf nodes.\n */\nexport const forbiddenFieldKindIdentifier = \"Forbidden\";\n\n/**\n * A schema for empty fields (fields which must always be empty).\n * There are multiple ways this could be encoded, but this is the most explicit.\n */\nexport const storedEmptyFieldSchema: TreeFieldStoredSchema = {\n\t// This kind requires the field to be empty.\n\tkind: brand(forbiddenFieldKindIdentifier),\n\t// This type set also forces the field to be empty not not allowing any types as all.\n\ttypes: new Set(),\n};\n\n/**\n * Identifier used for the FieldKind for fields of type identifier.\n */\nexport const identifierFieldKindIdentifier = \"Identifier\";\n\n/**\n * Opaque type erased handle to the encoded representation of the contents of a stored schema.\n * @internal\n */\nexport interface ErasedTreeNodeSchemaDataFormat\n\textends ErasedType<\"TreeNodeSchemaDataFormat\"> {}\n\nfunction toErasedTreeNodeSchemaDataFormat(\n\tdata: TreeNodeSchemaDataFormat,\n): ErasedTreeNodeSchemaDataFormat {\n\treturn data as unknown as ErasedTreeNodeSchemaDataFormat;\n}\n\nexport function toTreeNodeSchemaDataFormat(\n\tdata: ErasedTreeNodeSchemaDataFormat,\n): TreeNodeSchemaDataFormat {\n\treturn data as unknown as TreeNodeSchemaDataFormat;\n}\n\n/**\n * @internal\n */\nexport abstract class TreeNodeStoredSchema {\n\tprotected _typeCheck!: MakeNominal;\n\n\t/**\n\t * @privateRemarks\n\t * Returns TreeNodeSchemaDataFormat.\n\t * This is uses an opaque type to avoid leaking these types out of the package,\n\t * and is runtime validated by the codec.\n\t */\n\tpublic abstract encode(): ErasedTreeNodeSchemaDataFormat;\n}\n\n/**\n * @internal\n */\nexport class ObjectNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param objectNodeFields -\n\t * Schema for fields with keys scoped to this TreeNodeStoredSchema.\n\t * This refers to the TreeFieldStoredSchema directly\n\t * (as opposed to just supporting FieldSchemaIdentifier and having a central FieldKey -\\> TreeFieldStoredSchema map).\n\t * This allows us short friendly field keys which can be ergonomically used as field names in code.\n\t * It also interoperates well with mapFields being used as a map with arbitrary data as keys.\n\t */\n\tpublic constructor(\n\t\tpublic readonly objectNodeFields: ReadonlyMap<FieldKey, TreeFieldStoredSchema>,\n\t) {\n\t\tsuper();\n\t}\n\n\tpublic override encode(): ErasedTreeNodeSchemaDataFormat {\n\t\tconst fieldsObject: Record<string, FieldSchemaFormat> = Object.create(null);\n\t\t// Sort fields to ensure output is identical for for equivalent schema (since field order is not considered significant).\n\t\t// This makes comparing schema easier, and ensures chunk reuse for schema summaries isn't needlessly broken.\n\t\tfor (const key of [...this.objectNodeFields.keys()].sort()) {\n\t\t\tObject.defineProperty(fieldsObject, key, {\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t\twritable: true,\n\t\t\t\tvalue: encodeFieldSchema(this.objectNodeFields.get(key) ?? fail(\"missing field\")),\n\t\t\t});\n\t\t}\n\t\treturn toErasedTreeNodeSchemaDataFormat({\n\t\t\tobject: fieldsObject,\n\t\t});\n\t}\n}\n\n/**\n * @internal\n */\nexport class MapNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param mapFields -\n\t * Allows using the fields as a map, with the keys being\n\t * FieldKeys and the values being constrained by this TreeFieldStoredSchema.\n\t * Usually `FieldKind.Value` should NOT be used here\n\t * since no nodes can ever be in schema if you use `FieldKind.Value` here\n\t * (that would require infinite children).\n\t */\n\tpublic constructor(public readonly mapFields: TreeFieldStoredSchema) {\n\t\tsuper();\n\t}\n\n\tpublic override encode(): ErasedTreeNodeSchemaDataFormat {\n\t\treturn toErasedTreeNodeSchemaDataFormat({\n\t\t\tmap: encodeFieldSchema(this.mapFields),\n\t\t});\n\t}\n}\n\n/**\n * @internal\n */\nexport class LeafNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param leafValue -\n\t * There are several approaches for how to store actual data in the tree\n\t * (special node types, special field contents, data on nodes etc.)\n\t * as well as several options about how the data should be modeled at this level\n\t * (byte sequence? javascript type? json?),\n\t * as well as options for how much of this would be exposed in the schema language\n\t * (ex: would all nodes with values be special built-ins, or could any schema add them?)\n\t * A simple easy to do in javascript approach is taken here:\n\t * this is not intended to be a suggestion of what approach to take, or what to expose in the schema language.\n\t * This is simply one approach that can work for modeling them in the internal schema representation.\n\t */\n\tpublic constructor(public readonly leafValue: ValueSchema) {\n\t\tsuper();\n\t}\n\n\tpublic override encode(): ErasedTreeNodeSchemaDataFormat {\n\t\treturn toErasedTreeNodeSchemaDataFormat({\n\t\t\tleaf: encodeValueSchema(this.leafValue),\n\t\t});\n\t}\n}\n\nexport const storedSchemaDecodeDispatcher: DiscriminatedUnionDispatcher<\n\tTreeNodeSchemaDataFormat,\n\t[],\n\tTreeNodeStoredSchema\n> = new DiscriminatedUnionDispatcher({\n\tleaf: (data: PersistedValueSchema) => new LeafNodeStoredSchema(decodeValueSchema(data)),\n\tobject: (\n\t\tdata: Record<TreeNodeSchemaIdentifier, FieldSchemaFormat>,\n\t): TreeNodeStoredSchema => {\n\t\tconst map = new Map();\n\t\tfor (const [key, value] of Object.entries(data)) {\n\t\t\tmap.set(key, decodeFieldSchema(value));\n\t\t}\n\t\treturn new ObjectNodeStoredSchema(map);\n\t},\n\tmap: (data: FieldSchemaFormat) => new MapNodeStoredSchema(decodeFieldSchema(data)),\n});\n\nconst valueSchemaEncode = new Map([\n\t[ValueSchema.Number, PersistedValueSchema.Number],\n\t[ValueSchema.String, PersistedValueSchema.String],\n\t[ValueSchema.Boolean, PersistedValueSchema.Boolean],\n\t[ValueSchema.FluidHandle, PersistedValueSchema.FluidHandle],\n\t[ValueSchema.Null, PersistedValueSchema.Null],\n]);\n\nconst valueSchemaDecode = invertMap(valueSchemaEncode);\n\nfunction encodeValueSchema(inMemory: ValueSchema): PersistedValueSchema {\n\treturn valueSchemaEncode.get(inMemory) ?? fail(\"missing PersistedValueSchema\");\n}\n\nfunction decodeValueSchema(inMemory: PersistedValueSchema): ValueSchema {\n\treturn valueSchemaDecode.get(inMemory) ?? fail(\"missing ValueSchema\");\n}\n\nexport function encodeFieldSchema(schema: TreeFieldStoredSchema): FieldSchemaFormat {\n\treturn {\n\t\tkind: schema.kind,\n\t\t// Types are sorted by identifier to improve stability of persisted data to increase chance of schema blob reuse.\n\t\ttypes: [...schema.types].sort(),\n\t};\n}\n\nexport function decodeFieldSchema(schema: FieldSchemaFormat): TreeFieldStoredSchema {\n\tconst out: TreeFieldStoredSchema = {\n\t\t// TODO: maybe provide actual FieldKind objects here, error on unrecognized kinds.\n\t\tkind: schema.kind,\n\t\ttypes: new Set(schema.types),\n\t};\n\treturn out;\n}\n\n/**\n * Document schema data that can be stored in a document.\n *\n * @remarks\n * Note: the owner of this may modify it over time:\n * thus if needing to hand onto a specific version, make a copy.\n * @internal\n */\nexport interface TreeStoredSchema extends StoredSchemaCollection {\n\t/**\n\t * Schema for the root field which contains the whole tree.\n\t */\n\treadonly rootFieldSchema: TreeFieldStoredSchema;\n}\n\n/**\n * Collection of TreeNodeSchema data that can be stored in a document.\n *\n * @remarks\n * Note: the owner of this may modify it over time:\n * thus if needing to hang onto a specific version, make a copy.\n * @internal\n */\nexport interface StoredSchemaCollection {\n\t/**\n\t * {@inheritdoc StoredSchemaCollection}\n\t */\n\treadonly nodeSchema: ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>;\n}\n"]}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/core/schema-stored/schema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAA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,KAAK,CAAC,CAAC,IAAI,EAAE;KAC/B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAyB;IAC1D,MAAM,GAAG,GAA0B;QAClC,kFAAkF;QAClF,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;KAC5B,CAAC;IACF,OAAO,GAAG,CAAC;AACZ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ErasedType } from \"@fluidframework/core-interfaces\";\nimport { DiscriminatedUnionDispatcher } from \"../../codec/index.js\";\nimport { type MakeNominal, brand, fail, invertMap } from \"../../util/index.js\";\nimport {\n\ttype FieldKey,\n\ttype FieldKindIdentifier,\n\ttype FieldSchemaFormat,\n\tPersistedValueSchema,\n\ttype TreeNodeSchemaDataFormat,\n\ttype TreeNodeSchemaIdentifier,\n} from \"./format.js\";\nimport type { Multiplicity } from \"./multiplicity.js\";\n\n/**\n * Schema for what {@link TreeValue} is allowed on a Leaf node.\n * @internal\n */\nexport enum ValueSchema {\n\tNumber,\n\tString,\n\tBoolean,\n\tFluidHandle,\n\tNull,\n}\n\n/**\n * Set of allowed tree types.\n * Providing multiple values here allows polymorphism, tagged union style.\n *\n * In the future, this could be extended to allow inlining a TreeNodeStoredSchema here\n * (or some similar structural schema system).\n * For structural types which could go here, there are a few interesting options:\n *\n * - Allow replacing the whole set with a structural type for terminal / non-tree data,\n * and use this as a replacement for values on the tree nodes.\n *\n * - Allow expression structural constraints for child trees, for example requiring specific traits\n * (ex: via TreeNodeStoredSchema), instead of by type.\n *\n * There are two ways this could work:\n *\n * - Constrain the child nodes based on their shape:\n * this makes schema safe editing difficult because nodes would incur extra editing constraints to prevent them\n * from going out of schema based on their location in such a field.\n *\n * - Constrain the types allowed based on which types guarantee their data will always meet the constraints.\n *\n * Care would need to be taken to make sure this is sound for the schema updating mechanisms.\n * @internal\n */\nexport type TreeTypeSet = ReadonlySet<TreeNodeSchemaIdentifier>;\n\n/**\n * Declarative portion of a Field Kind.\n *\n * @remarks\n * Enough info about a field kind to know if a given tree is is schema.\n */\nexport interface FieldKindData {\n\treadonly identifier: FieldKindIdentifier;\n\treadonly multiplicity: Multiplicity;\n}\n\n/**\n * Everything needed to define what it means for a tree to be in schema.\n */\nexport interface SchemaAndPolicy {\n\treadonly schema: StoredSchemaCollection;\n\treadonly policy: SchemaPolicy;\n}\n\n/**\n * Extra data needed to interpret schema.\n */\nexport interface SchemaPolicy {\n\t/**\n\t * Policy information about FieldKinds:\n\t * This is typically stored as code, not in documents, and defines how to handle fields based on their kind.\n\t * It is assumed that all users of a document will have exactly the same FieldKind policies,\n\t * though older applications might be missing some,\n\t * and will be unable to process any changes that use those FieldKinds.\n\t */\n\treadonly fieldKinds: ReadonlyMap<FieldKindIdentifier, FieldKindData>;\n\n\t/**\n\t * If true, new content inserted into the tree should be validated against the stored schema.\n\t */\n\treadonly validateSchema: boolean;\n}\n\n/**\n * Schema for a field.\n * Object implementing this interface should never be modified.\n * @internal\n */\nexport interface TreeFieldStoredSchema {\n\treadonly kind: FieldKindIdentifier;\n\n\t/**\n\t * The set of allowed child types.\n\t * If not specified, types are unconstrained.\n\t */\n\treadonly types: TreeTypeSet;\n}\n\n/**\n * Identifier used for the FieldKind for fields which must be empty.\n *\n * @remarks\n * This mainly show up in:\n * 1. The root default field for documents.\n * 2. The schema used for out of schema fields (which thus must be empty/not exist) on object and leaf nodes.\n */\nexport const forbiddenFieldKindIdentifier = \"Forbidden\";\n\n/**\n * A schema for empty fields (fields which must always be empty).\n * There are multiple ways this could be encoded, but this is the most explicit.\n */\nexport const storedEmptyFieldSchema: TreeFieldStoredSchema = {\n\t// This kind requires the field to be empty.\n\tkind: brand(forbiddenFieldKindIdentifier),\n\t// This type set also forces the field to be empty not not allowing any types as all.\n\ttypes: new Set(),\n};\n\n/**\n * Identifier used for the FieldKind for fields of type identifier.\n */\nexport const identifierFieldKindIdentifier = \"Identifier\";\n\n/**\n * Opaque type erased handle to the encoded representation of the contents of a stored schema.\n * @internal\n */\nexport interface ErasedTreeNodeSchemaDataFormat\n\textends ErasedType<\"TreeNodeSchemaDataFormat\"> {}\n\nfunction toErasedTreeNodeSchemaDataFormat(\n\tdata: TreeNodeSchemaDataFormat,\n): ErasedTreeNodeSchemaDataFormat {\n\treturn data as unknown as ErasedTreeNodeSchemaDataFormat;\n}\n\nexport function toTreeNodeSchemaDataFormat(\n\tdata: ErasedTreeNodeSchemaDataFormat,\n): TreeNodeSchemaDataFormat {\n\treturn data as unknown as TreeNodeSchemaDataFormat;\n}\n\n/**\n * @internal\n */\nexport abstract class TreeNodeStoredSchema {\n\tprotected _typeCheck!: MakeNominal;\n\n\t/**\n\t * @privateRemarks\n\t * Returns TreeNodeSchemaDataFormat.\n\t * This is uses an opaque type to avoid leaking these types out of the package,\n\t * and is runtime validated by the codec.\n\t */\n\tpublic abstract encode(): ErasedTreeNodeSchemaDataFormat;\n}\n\n/**\n * @internal\n */\nexport class ObjectNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param objectNodeFields -\n\t * Schema for fields with keys scoped to this TreeNodeStoredSchema.\n\t * This refers to the TreeFieldStoredSchema directly\n\t * (as opposed to just supporting FieldSchemaIdentifier and having a central FieldKey -\\> TreeFieldStoredSchema map).\n\t * This allows us short friendly field keys which can be ergonomically used as field names in code.\n\t * It also interoperates well with mapFields being used as a map with arbitrary data as keys.\n\t */\n\tpublic constructor(\n\t\tpublic readonly objectNodeFields: ReadonlyMap<FieldKey, TreeFieldStoredSchema>,\n\t) {\n\t\tsuper();\n\t}\n\n\tpublic override encode(): ErasedTreeNodeSchemaDataFormat {\n\t\tconst fieldsObject: Record<string, FieldSchemaFormat> = Object.create(null);\n\t\t// Sort fields to ensure output is identical for for equivalent schema (since field order is not considered significant).\n\t\t// This makes comparing schema easier, and ensures chunk reuse for schema summaries isn't needlessly broken.\n\t\tfor (const key of [...this.objectNodeFields.keys()].sort()) {\n\t\t\tObject.defineProperty(fieldsObject, key, {\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t\twritable: true,\n\t\t\t\tvalue: encodeFieldSchema(this.objectNodeFields.get(key) ?? fail(\"missing field\")),\n\t\t\t});\n\t\t}\n\t\treturn toErasedTreeNodeSchemaDataFormat({\n\t\t\tobject: fieldsObject,\n\t\t});\n\t}\n}\n\n/**\n * @internal\n */\nexport class MapNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param mapFields -\n\t * Allows using the fields as a map, with the keys being\n\t * FieldKeys and the values being constrained by this TreeFieldStoredSchema.\n\t * Usually `FieldKind.Value` should NOT be used here\n\t * since no nodes can ever be in schema if you use `FieldKind.Value` here\n\t * (that would require infinite children).\n\t */\n\tpublic constructor(public readonly mapFields: TreeFieldStoredSchema) {\n\t\tsuper();\n\t}\n\n\tpublic override encode(): ErasedTreeNodeSchemaDataFormat {\n\t\treturn toErasedTreeNodeSchemaDataFormat({\n\t\t\tmap: encodeFieldSchema(this.mapFields),\n\t\t});\n\t}\n}\n\n/**\n * @internal\n */\nexport class LeafNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param leafValue -\n\t * There are several approaches for how to store actual data in the tree\n\t * (special node types, special field contents, data on nodes etc.)\n\t * as well as several options about how the data should be modeled at this level\n\t * (byte sequence? javascript type? json?),\n\t * as well as options for how much of this would be exposed in the schema language\n\t * (ex: would all nodes with values be special built-ins, or could any schema add them?)\n\t * A simple easy to do in javascript approach is taken here:\n\t * this is not intended to be a suggestion of what approach to take, or what to expose in the schema language.\n\t * This is simply one approach that can work for modeling them in the internal schema representation.\n\t */\n\tpublic constructor(public readonly leafValue: ValueSchema) {\n\t\tsuper();\n\t}\n\n\tpublic override encode(): ErasedTreeNodeSchemaDataFormat {\n\t\treturn toErasedTreeNodeSchemaDataFormat({\n\t\t\tleaf: encodeValueSchema(this.leafValue),\n\t\t});\n\t}\n}\n\nexport const storedSchemaDecodeDispatcher: DiscriminatedUnionDispatcher<\n\tTreeNodeSchemaDataFormat,\n\t[],\n\tTreeNodeStoredSchema\n> = new DiscriminatedUnionDispatcher({\n\tleaf: (data: PersistedValueSchema) => new LeafNodeStoredSchema(decodeValueSchema(data)),\n\tobject: (\n\t\tdata: Record<TreeNodeSchemaIdentifier, FieldSchemaFormat>,\n\t): TreeNodeStoredSchema => {\n\t\tconst map = new Map();\n\t\tfor (const [key, value] of Object.entries(data)) {\n\t\t\tmap.set(key, decodeFieldSchema(value));\n\t\t}\n\t\treturn new ObjectNodeStoredSchema(map);\n\t},\n\tmap: (data: FieldSchemaFormat) => new MapNodeStoredSchema(decodeFieldSchema(data)),\n});\n\nconst valueSchemaEncode = new Map([\n\t[ValueSchema.Number, PersistedValueSchema.Number],\n\t[ValueSchema.String, PersistedValueSchema.String],\n\t[ValueSchema.Boolean, PersistedValueSchema.Boolean],\n\t[ValueSchema.FluidHandle, PersistedValueSchema.FluidHandle],\n\t[ValueSchema.Null, PersistedValueSchema.Null],\n]);\n\nconst valueSchemaDecode = invertMap(valueSchemaEncode);\n\nfunction encodeValueSchema(inMemory: ValueSchema): PersistedValueSchema {\n\treturn valueSchemaEncode.get(inMemory) ?? fail(\"missing PersistedValueSchema\");\n}\n\nfunction decodeValueSchema(inMemory: PersistedValueSchema): ValueSchema {\n\treturn valueSchemaDecode.get(inMemory) ?? fail(\"missing ValueSchema\");\n}\n\nexport function encodeFieldSchema(schema: TreeFieldStoredSchema): FieldSchemaFormat {\n\treturn {\n\t\tkind: schema.kind,\n\t\t// Types are sorted by identifier to improve stability of persisted data to increase chance of schema blob reuse.\n\t\ttypes: [...schema.types].sort(),\n\t};\n}\n\nexport function decodeFieldSchema(schema: FieldSchemaFormat): TreeFieldStoredSchema {\n\tconst out: TreeFieldStoredSchema = {\n\t\t// TODO: maybe provide actual FieldKind objects here, error on unrecognized kinds.\n\t\tkind: schema.kind,\n\t\ttypes: new Set(schema.types),\n\t};\n\treturn out;\n}\n\n/**\n * Document schema data that can be stored in a document.\n *\n * @remarks\n * Note: the owner of this may modify it over time:\n * thus if needing to hand onto a specific version, make a copy.\n * @internal\n */\nexport interface TreeStoredSchema extends StoredSchemaCollection {\n\t/**\n\t * Schema for the root field which contains the whole tree.\n\t */\n\treadonly rootFieldSchema: TreeFieldStoredSchema;\n}\n\n/**\n * Collection of TreeNodeSchema data that can be stored in a document.\n *\n * @remarks\n * Note: the owner of this may modify it over time:\n * thus if needing to hang onto a specific version, make a copy.\n * @internal\n */\nexport interface StoredSchemaCollection {\n\t/**\n\t * {@inheritdoc StoredSchemaCollection}\n\t */\n\treadonly nodeSchema: ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>;\n}\n"]}
@@ -101,6 +101,13 @@ export declare class ModularChangeFamily implements ChangeFamily<ModularEditBuil
101
101
  private populateCrossFieldKeyTableForFieldMap;
102
102
  buildEditor(changeReceiver: (change: ModularChangeset) => void): ModularEditBuilder;
103
103
  private createEmptyFieldChange;
104
+ validateChangeset(change: ModularChangeset): void;
105
+ /**
106
+ * Asserts that each child and cross field key in each field has a correct entry in
107
+ * `nodeToParent` or `crossFieldKeyTable`.
108
+ * @returns the number of children found.
109
+ */
110
+ private validateFieldChanges;
104
111
  }
105
112
  /**
106
113
  * Returns the set of removed roots that should be in memory for the given change to be applied.
@@ -1 +1 @@
1
- {"version":3,"file":"modularChangeFamily.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/modular-schema/modularChangeFamily.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EAIrB,KAAK,mBAAmB,EAGxB,KAAK,SAAS,EACd,WAAW,EAEX,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB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O,CAIrF;AAED,wBAAgB,yBAAyB,CACxC,SAAS,EAAE,gBAAgB,EAC3B,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,kBAAkB,GAC/C,OAAO,EAAE,CA6BX;AA4FD,wBAAgB,qBAAqB,IAAI,kBAAkB,CAE1D;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,EAAE,CAAC,EAC5D,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAChB,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAElB"}
1
+ {"version":3,"file":"modularChangeFamily.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/modular-schema/modularChangeFamily.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EAIrB,KAAK,mBAAmB,EAGxB,KAAK,SAAS,EACd,WAAW,EAEX,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,MAAM,EAUX,MAAM,qBAAqB,CAAC;AAY7B,OAAO,EACN,KAAK,SAAS,EAId,MAAM,4BAA4B,CAAC;AAWpC,OAAO,EACN,KAAK,kBAAkB,EAEvB,KAAK,sBAAsB,EAC3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,mBAAmB,EAAc,MAAM,0BAA0B,CAAC;AAGhF,OAAO,KAAK,EACX,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAGlB,cAAc,EACd,OAAO,EACP,gBAAgB,EAEhB,MAAM,EACN,UAAU,EACV,MAAM,yBA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,CAAC,CAElB"}
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { assert } from "@fluidframework/core-utils/internal";
6
6
  import { BTree } from "@tylerbu/sorted-btree-es6";
7
- import { EditBuilder, isEmptyFieldChanges, makeAnonChange, makeDetachedNodeId, mapCursorField, replaceAtomRevisions, revisionMetadataSourceFromInfo, areEqualChangeAtomIds, } from "../../core/index.js";
7
+ import { EditBuilder, isEmptyFieldChanges, makeAnonChange, makeDetachedNodeId, mapCursorField, replaceAtomRevisions, revisionMetadataSourceFromInfo, areEqualChangeAtomIds, areEqualChangeAtomIdOpts, } from "../../core/index.js";
8
8
  import { brand, fail, idAllocatorFromMaxId, idAllocatorFromState, getOrAddInMapLazy, } from "../../util/index.js";
9
9
  import { chunkFieldSingle, chunkTree, defaultChunkPolicy, } from "../chunked-forest/index.js";
10
10
  import { cursorForMapTreeNode, mapTreeFromCursor } from "../mapTreeCursor.js";
@@ -102,7 +102,6 @@ export class ModularChangeFamily {
102
102
  }
103
103
  const genId = idAllocatorFromState(idState);
104
104
  const revisionMetadata = revisionMetadataSourceFromInfo(revInfos);
105
- const crossFieldTable = newComposeTable(change1, change2);
106
105
  // We merge nodeChanges, nodeToParent, and nodeAliases from the two changesets.
107
106
  // The merged tables will have correct entries for all nodes which are only referenced in one of the input changesets.
108
107
  // During composeFieldMaps and composeInvalidatedElements we will find all nodes referenced in both input changesets
@@ -114,7 +113,8 @@ export class ModularChangeFamily {
114
113
  const composedNodeChanges = brand(mergeBTrees(change1.nodeChanges, change2.nodeChanges));
115
114
  const composedNodeToParent = brand(mergeBTrees(change1.nodeToParent, change2.nodeToParent));
116
115
  const composedNodeAliases = brand(mergeBTrees(change1.nodeAliases, change2.nodeAliases));
117
- const composedFields = this.composeFieldMaps(change1.fieldChanges, change2.fieldChanges, genId, crossFieldTable, revisionMetadata);
116
+ const crossFieldTable = newComposeTable(change1, change2, composedNodeToParent);
117
+ const composedFields = this.composeFieldMaps(change1.fieldChanges, change2.fieldChanges, undefined, genId, crossFieldTable, revisionMetadata);
118
118
  this.composeInvalidatedElements(crossFieldTable, composedFields, composedNodeChanges, composedNodeToParent, composedNodeAliases, genId, revisionMetadata);
119
119
  // Currently no field kinds require making changes to cross-field keys during composition, so we can just merge the two tables.
120
120
  const composedCrossFieldKeys = mergeBTrees(change1.crossFieldKeys, change2.crossFieldKeys);
@@ -129,7 +129,7 @@ export class ModularChangeFamily {
129
129
  composeInvalidatedField(fieldChange, crossFieldTable, genId, revisionMetadata) {
130
130
  const context = crossFieldTable.fieldToContext.get(fieldChange);
131
131
  assert(context !== undefined, 0x8cc /* Should have context for every invalidated field */);
132
- const { change1: fieldChange1, change2: fieldChange2, composedChange } = context;
132
+ const { fieldId, change1: fieldChange1, change2: fieldChange2, composedChange } = context;
133
133
  const rebaser = getChangeHandler(this.fieldKinds, composedChange.fieldKind).rebaser;
134
134
  const composeNodes = (child1, child2) => {
135
135
  if (child1 !== undefined &&
@@ -140,7 +140,7 @@ export class ModularChangeFamily {
140
140
  }
141
141
  return child1 ?? child2 ?? fail("Should not compose two undefined nodes");
142
142
  };
143
- const amendedChange = rebaser.compose(fieldChange1, fieldChange2, composeNodes, genId, new ComposeManager(crossFieldTable, fieldChange, false), revisionMetadata);
143
+ const amendedChange = rebaser.compose(fieldChange1, fieldChange2, composeNodes, genId, new ComposeManager(crossFieldTable, fieldChange, fieldId, false), revisionMetadata);
144
144
  composedChange.change = brand(amendedChange);
145
145
  }
146
146
  /**
@@ -202,7 +202,7 @@ export class ModularChangeFamily {
202
202
  const [change1, change2] = areBaseFields
203
203
  ? [fieldChange, emptyChange]
204
204
  : [emptyChange, fieldChange];
205
- const composedField = this.composeFieldChanges(change1, change2, genId, table, metadata);
205
+ const composedField = this.composeFieldChanges(fieldId, change1, change2, genId, table, metadata);
206
206
  if (fieldId.nodeId === undefined) {
207
207
  composedFields.set(fieldId.field, composedField);
208
208
  continue;
@@ -220,15 +220,16 @@ export class ModularChangeFamily {
220
220
  }
221
221
  affectedFields.clear();
222
222
  }
223
- composeFieldMaps(change1, change2, genId, crossFieldTable, revisionMetadata) {
223
+ composeFieldMaps(change1, change2, parentId, genId, crossFieldTable, revisionMetadata) {
224
224
  const composedFields = new Map();
225
225
  if (change1 === undefined || change2 === undefined) {
226
226
  return change1 ?? change2 ?? composedFields;
227
227
  }
228
228
  for (const [field, fieldChange1] of change1) {
229
+ const fieldId = { nodeId: parentId, field };
229
230
  const fieldChange2 = change2.get(field);
230
231
  const composedField = fieldChange2 !== undefined
231
- ? this.composeFieldChanges(fieldChange1, fieldChange2, genId, crossFieldTable, revisionMetadata)
232
+ ? this.composeFieldChanges(fieldId, fieldChange1, fieldChange2, genId, crossFieldTable, revisionMetadata)
232
233
  : fieldChange1;
233
234
  composedFields.set(field, composedField);
234
235
  }
@@ -250,9 +251,9 @@ export class ModularChangeFamily {
250
251
  *
251
252
  * Any composed `FieldChange` which is invalidated by new cross-field information will be added to `crossFieldTable.invalidatedFields`.
252
253
  */
253
- composeFieldChanges(change1, change2, idAllocator, crossFieldTable, revisionMetadata) {
254
+ composeFieldChanges(fieldId, change1, change2, idAllocator, crossFieldTable, revisionMetadata) {
254
255
  const { fieldKind, changeHandler, change1: change1Normalized, change2: change2Normalized, } = this.normalizeFieldChanges(change1, change2, idAllocator, revisionMetadata);
255
- const manager = new ComposeManager(crossFieldTable, change1);
256
+ const manager = new ComposeManager(crossFieldTable, change1, fieldId);
256
257
  const composedChange = changeHandler.rebaser.compose(change1Normalized, change2Normalized, (child1, child2) => {
257
258
  if (child1 !== undefined && child2 !== undefined) {
258
259
  setInChangeAtomIdMap(crossFieldTable.newToBaseNodeId, child2, child1);
@@ -265,6 +266,7 @@ export class ModularChangeFamily {
265
266
  change: brand(composedChange),
266
267
  };
267
268
  crossFieldTable.fieldToContext.set(change1, {
269
+ fieldId,
268
270
  change1: change1Normalized,
269
271
  change2: change2Normalized,
270
272
  composedChange: composedField,
@@ -275,7 +277,7 @@ export class ModularChangeFamily {
275
277
  composeNodesById(nodeChanges1, nodeChanges2, composedNodes, composedNodeToParent, nodeAliases, id1, id2, idAllocator, crossFieldTable, revisionMetadata) {
276
278
  const nodeChangeset1 = nodeChangeFromId(nodeChanges1, id1);
277
279
  const nodeChangeset2 = nodeChangeFromId(nodeChanges2, id2);
278
- const composedNodeChangeset = this.composeNodeChanges(nodeChangeset1, nodeChangeset2, idAllocator, crossFieldTable, revisionMetadata);
280
+ const composedNodeChangeset = this.composeNodeChanges(id1, nodeChangeset1, nodeChangeset2, idAllocator, crossFieldTable, revisionMetadata);
279
281
  setInChangeAtomIdMap(composedNodes, id1, composedNodeChangeset);
280
282
  if (!areEqualChangeAtomIds(id1, id2)) {
281
283
  composedNodes.delete([id2.revision, id2.localId]);
@@ -286,9 +288,9 @@ export class ModularChangeFamily {
286
288
  }
287
289
  crossFieldTable.composedNodes.add(composedNodeChangeset);
288
290
  }
289
- composeNodeChanges(change1, change2, genId, crossFieldTable, revisionMetadata) {
291
+ composeNodeChanges(nodeId, change1, change2, genId, crossFieldTable, revisionMetadata) {
290
292
  const nodeExistsConstraint = change1.nodeExistsConstraint ?? change2.nodeExistsConstraint;
291
- const composedFieldChanges = this.composeFieldMaps(change1.fieldChanges, change2.fieldChanges, genId, crossFieldTable, revisionMetadata);
293
+ const composedFieldChanges = this.composeFieldMaps(change1.fieldChanges, change2.fieldChanges, nodeId, genId, crossFieldTable, revisionMetadata);
292
294
  const composedNodeChange = {};
293
295
  if (composedFieldChanges.size > 0) {
294
296
  composedNodeChange.fieldChanges = composedFieldChanges;
@@ -396,7 +398,8 @@ export class ModularChangeFamily {
396
398
  const rebasedFields = this.rebaseIntersectingFields(crossFieldTable, rebasedNodes, genId, constraintState, rebaseMetadata);
397
399
  this.rebaseInvalidatedElements(rebasedFields, rebasedNodes, crossFieldTable, rebaseMetadata, genId);
398
400
  this.updateConstraintsForFields(rebasedFields, NodeAttachState.Attached, constraintState, rebasedNodes);
399
- return makeModularChangeset(this.pruneFieldMap(rebasedFields, rebasedNodes), rebasedNodes, crossFieldTable.rebasedNodeToParent, change.nodeAliases, crossFieldTable.rebasedCrossFieldKeys, idState.maxId, change.revisions, constraintState.violationCount, change.builds, change.destroys, change.refreshers);
401
+ const rebased = makeModularChangeset(this.pruneFieldMap(rebasedFields, rebasedNodes), rebasedNodes, crossFieldTable.rebasedNodeToParent, change.nodeAliases, crossFieldTable.rebasedCrossFieldKeys, idState.maxId, change.revisions, constraintState.violationCount, change.builds, change.destroys, change.refreshers);
402
+ return rebased;
400
403
  }
401
404
  // This performs a first pass on all fields which have both new and base changes.
402
405
  // TODO: Can we also handle additional passes in this method?
@@ -745,6 +748,42 @@ export class ModularChangeFamily {
745
748
  const emptyChange = getChangeHandler(this.fieldKinds, fieldKind).createEmpty();
746
749
  return { fieldKind, change: brand(emptyChange) };
747
750
  }
751
+ validateChangeset(change) {
752
+ let numNodes = this.validateFieldChanges(change, change.fieldChanges, undefined);
753
+ for (const [[revision, localId], node] of change.nodeChanges.entries()) {
754
+ if (node.fieldChanges === undefined) {
755
+ continue;
756
+ }
757
+ const nodeId = { revision, localId };
758
+ const numChildren = this.validateFieldChanges(change, node.fieldChanges, nodeId);
759
+ numNodes += numChildren;
760
+ }
761
+ assert(numNodes === change.nodeChanges.size, "Node table contains unparented nodes");
762
+ }
763
+ /**
764
+ * Asserts that each child and cross field key in each field has a correct entry in
765
+ * `nodeToParent` or `crossFieldKeyTable`.
766
+ * @returns the number of children found.
767
+ */
768
+ validateFieldChanges(change, fieldChanges, nodeParent) {
769
+ let numChildren = 0;
770
+ for (const [field, fieldChange] of fieldChanges.entries()) {
771
+ const fieldId = { nodeId: nodeParent, field };
772
+ const handler = getChangeHandler(this.fieldKinds, fieldChange.fieldKind);
773
+ for (const [child, _index] of handler.getNestedChanges(fieldChange.change)) {
774
+ const parentFieldId = getParentFieldId(change, child);
775
+ assert(areEqualFieldIds(parentFieldId, fieldId), "Inconsistent node parentage");
776
+ numChildren += 1;
777
+ }
778
+ for (const keyRange of handler.getCrossFieldKeys(fieldChange.change)) {
779
+ const fields = getFieldsForCrossFieldKey(change, keyRange);
780
+ assert(fields.length === 1 &&
781
+ fields[0] !== undefined &&
782
+ areEqualFieldIds(fields[0], fieldId), "Inconsistent cross field keys");
783
+ }
784
+ }
785
+ return numChildren;
786
+ }
748
787
  }
749
788
  ModularChangeFamily.emptyChange = makeModularChangeset();
750
789
  function replaceCrossFieldKeyTableRevisions(table, oldRevisions, newRevision, nodeAliases) {
@@ -1006,7 +1045,7 @@ export function getFieldKind(fieldKinds, kind) {
1006
1045
  export function getChangeHandler(fieldKinds, kind) {
1007
1046
  return getFieldKind(fieldKinds, kind).changeHandler;
1008
1047
  }
1009
- function newComposeTable(baseChange, newChange) {
1048
+ function newComposeTable(baseChange, newChange, composedNodeToParent) {
1010
1049
  return {
1011
1050
  ...newCrossFieldTable(),
1012
1051
  baseChange,
@@ -1015,6 +1054,7 @@ function newComposeTable(baseChange, newChange) {
1015
1054
  newFieldToBaseField: new Map(),
1016
1055
  newToBaseNodeId: newTupleBTree(),
1017
1056
  composedNodes: new Set(),
1057
+ composedNodeToParent,
1018
1058
  pendingCompositions: {
1019
1059
  nodeIdsToCompose: [],
1020
1060
  affectedBaseFields: newTupleBTree(),
@@ -1130,8 +1170,9 @@ class RebaseManager extends CrossFieldManagerI {
1130
1170
  }
1131
1171
  // TODO: Deduplicate this with RebaseTable
1132
1172
  class ComposeManager extends CrossFieldManagerI {
1133
- constructor(table, currentField, allowInval = true) {
1173
+ constructor(table, currentField, fieldId, allowInval = true) {
1134
1174
  super(table, currentField, allowInval);
1175
+ this.fieldId = fieldId;
1135
1176
  }
1136
1177
  set(target, revision, id, count, newValue, invalidateDependents) {
1137
1178
  if (invalidateDependents && this.allowInval) {
@@ -1162,10 +1203,10 @@ class ComposeManager extends CrossFieldManagerI {
1162
1203
  super.set(target, revision, id, count, newValue, invalidateDependents);
1163
1204
  }
1164
1205
  onMoveIn(id) {
1165
- throw new Error("Method not implemented.");
1206
+ setInChangeAtomIdMap(this.table.composedNodeToParent, id, this.fieldId);
1166
1207
  }
1167
1208
  moveKey(target, revision, id, count) {
1168
- throw new Error("Method not implemented.");
1209
+ throw new Error("Moving cross-field keys during compose is currently unsupported");
1169
1210
  }
1170
1211
  get table() {
1171
1212
  return this.crossFieldTable;
@@ -1544,4 +1585,7 @@ function getFromChangeAtomIdMap(map, id) {
1544
1585
  function setInChangeAtomIdMap(map, id, value) {
1545
1586
  map.set([id.revision, id.localId], value);
1546
1587
  }
1588
+ function areEqualFieldIds(a, b) {
1589
+ return areEqualChangeAtomIdOpts(a.nodeId, b.nodeId) && a.field === b.field;
1590
+ }
1547
1591
  //# sourceMappingURL=modularChangeFamily.js.map