@fluidframework/tree 2.51.0-347100 → 2.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/.eslintrc.cjs +3 -2
  2. package/CHANGELOG.md +49 -0
  3. package/dist/feature-libraries/index.d.ts +1 -1
  4. package/dist/feature-libraries/index.d.ts.map +1 -1
  5. package/dist/feature-libraries/index.js +2 -8
  6. package/dist/feature-libraries/index.js.map +1 -1
  7. package/dist/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  8. package/dist/feature-libraries/modular-schema/comparison.js +0 -3
  9. package/dist/feature-libraries/modular-schema/comparison.js.map +1 -1
  10. package/dist/feature-libraries/modular-schema/index.d.ts +0 -1
  11. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  12. package/dist/feature-libraries/modular-schema/index.js +1 -8
  13. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  14. package/dist/packageVersion.d.ts +1 -1
  15. package/dist/packageVersion.d.ts.map +1 -1
  16. package/dist/packageVersion.js +1 -1
  17. package/dist/packageVersion.js.map +1 -1
  18. package/dist/shared-tree/schematizeTree.d.ts +1 -1
  19. package/dist/shared-tree/schematizeTree.d.ts.map +1 -1
  20. package/dist/shared-tree/schematizeTree.js +5 -4
  21. package/dist/shared-tree/schematizeTree.js.map +1 -1
  22. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  23. package/dist/shared-tree/schematizingTreeView.js +2 -2
  24. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  25. package/dist/shared-tree/tree.js +1 -1
  26. package/dist/shared-tree/tree.js.map +1 -1
  27. package/dist/shared-tree/treeCheckout.js +1 -1
  28. package/dist/shared-tree/treeCheckout.js.map +1 -1
  29. package/dist/simple-tree/api/schemaCompatibilityTester.d.ts +3 -18
  30. package/dist/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
  31. package/dist/simple-tree/api/schemaCompatibilityTester.js +31 -82
  32. package/dist/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
  33. package/dist/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  34. package/dist/simple-tree/api/schemaCreationUtilities.js +2 -2
  35. package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  36. package/dist/simple-tree/api/storedSchema.d.ts.map +1 -1
  37. package/dist/simple-tree/api/storedSchema.js +1 -1
  38. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  39. package/dist/{feature-libraries/modular-schema → simple-tree}/discrepancies.d.ts +22 -29
  40. package/dist/simple-tree/discrepancies.d.ts.map +1 -0
  41. package/dist/simple-tree/discrepancies.js +382 -0
  42. package/dist/simple-tree/discrepancies.js.map +1 -0
  43. package/dist/simple-tree/index.d.ts +2 -1
  44. package/dist/simple-tree/index.d.ts.map +1 -1
  45. package/dist/simple-tree/index.js +7 -1
  46. package/dist/simple-tree/index.js.map +1 -1
  47. package/dist/simple-tree/node-kinds/index.d.ts +1 -1
  48. package/dist/simple-tree/node-kinds/index.d.ts.map +1 -1
  49. package/dist/simple-tree/node-kinds/index.js.map +1 -1
  50. package/dist/simple-tree/node-kinds/object/index.d.ts +1 -1
  51. package/dist/simple-tree/node-kinds/object/index.d.ts.map +1 -1
  52. package/dist/simple-tree/node-kinds/object/index.js.map +1 -1
  53. package/lib/feature-libraries/index.d.ts +1 -1
  54. package/lib/feature-libraries/index.d.ts.map +1 -1
  55. package/lib/feature-libraries/index.js +1 -1
  56. package/lib/feature-libraries/index.js.map +1 -1
  57. package/lib/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  58. package/lib/feature-libraries/modular-schema/comparison.js +0 -3
  59. package/lib/feature-libraries/modular-schema/comparison.js.map +1 -1
  60. package/lib/feature-libraries/modular-schema/index.d.ts +0 -1
  61. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  62. package/lib/feature-libraries/modular-schema/index.js +0 -1
  63. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  64. package/lib/packageVersion.d.ts +1 -1
  65. package/lib/packageVersion.d.ts.map +1 -1
  66. package/lib/packageVersion.js +1 -1
  67. package/lib/packageVersion.js.map +1 -1
  68. package/lib/shared-tree/schematizeTree.d.ts +1 -1
  69. package/lib/shared-tree/schematizeTree.d.ts.map +1 -1
  70. package/lib/shared-tree/schematizeTree.js +3 -2
  71. package/lib/shared-tree/schematizeTree.js.map +1 -1
  72. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  73. package/lib/shared-tree/schematizingTreeView.js +3 -3
  74. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  75. package/lib/shared-tree/tree.js +1 -1
  76. package/lib/shared-tree/tree.js.map +1 -1
  77. package/lib/shared-tree/treeCheckout.js +1 -1
  78. package/lib/shared-tree/treeCheckout.js.map +1 -1
  79. package/lib/simple-tree/api/schemaCompatibilityTester.d.ts +3 -18
  80. package/lib/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
  81. package/lib/simple-tree/api/schemaCompatibilityTester.js +25 -76
  82. package/lib/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
  83. package/lib/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  84. package/lib/simple-tree/api/schemaCreationUtilities.js +2 -2
  85. package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  86. package/lib/simple-tree/api/storedSchema.d.ts.map +1 -1
  87. package/lib/simple-tree/api/storedSchema.js +1 -1
  88. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  89. package/lib/{feature-libraries/modular-schema → simple-tree}/discrepancies.d.ts +22 -29
  90. package/lib/simple-tree/discrepancies.d.ts.map +1 -0
  91. package/lib/simple-tree/discrepancies.js +376 -0
  92. package/lib/simple-tree/discrepancies.js.map +1 -0
  93. package/lib/simple-tree/index.d.ts +2 -1
  94. package/lib/simple-tree/index.d.ts.map +1 -1
  95. package/lib/simple-tree/index.js +2 -1
  96. package/lib/simple-tree/index.js.map +1 -1
  97. package/lib/simple-tree/node-kinds/index.d.ts +1 -1
  98. package/lib/simple-tree/node-kinds/index.d.ts.map +1 -1
  99. package/lib/simple-tree/node-kinds/index.js.map +1 -1
  100. package/lib/simple-tree/node-kinds/object/index.d.ts +1 -1
  101. package/lib/simple-tree/node-kinds/object/index.d.ts.map +1 -1
  102. package/lib/simple-tree/node-kinds/object/index.js.map +1 -1
  103. package/package.json +20 -20
  104. package/src/feature-libraries/index.ts +0 -15
  105. package/src/feature-libraries/modular-schema/comparison.ts +0 -4
  106. package/src/feature-libraries/modular-schema/index.ts +0 -17
  107. package/src/packageVersion.ts +1 -1
  108. package/src/shared-tree/schematizeTree.ts +3 -3
  109. package/src/shared-tree/schematizingTreeView.ts +3 -6
  110. package/src/shared-tree/tree.ts +1 -1
  111. package/src/shared-tree/treeCheckout.ts +1 -1
  112. package/src/simple-tree/api/schemaCompatibilityTester.ts +37 -127
  113. package/src/simple-tree/api/schemaCreationUtilities.ts +5 -2
  114. package/src/simple-tree/api/storedSchema.ts +0 -1
  115. package/src/simple-tree/discrepancies.ts +648 -0
  116. package/src/simple-tree/index.ts +9 -1
  117. package/src/simple-tree/node-kinds/index.ts +1 -0
  118. package/src/simple-tree/node-kinds/object/index.ts +1 -0
  119. package/dist/feature-libraries/modular-schema/discrepancies.d.ts.map +0 -1
  120. package/dist/feature-libraries/modular-schema/discrepancies.js +0 -361
  121. package/dist/feature-libraries/modular-schema/discrepancies.js.map +0 -1
  122. package/lib/feature-libraries/modular-schema/discrepancies.d.ts.map +0 -1
  123. package/lib/feature-libraries/modular-schema/discrepancies.js +0 -354
  124. package/lib/feature-libraries/modular-schema/discrepancies.js.map +0 -1
  125. package/src/feature-libraries/modular-schema/discrepancies.ts +0 -567
@@ -1,361 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.posetLte = exports.comparePosetElements = exports.PosetComparisonResult = exports.fieldRealizer = exports.isRepoSuperset = exports.getAllowedContentDiscrepancies = void 0;
8
- const internal_1 = require("@fluidframework/core-utils/internal");
9
- const index_js_1 = require("../../core/index.js");
10
- const index_js_2 = require("../../util/index.js");
11
- function getNodeSchemaType(nodeSchema) {
12
- if (nodeSchema instanceof index_js_1.ObjectNodeStoredSchema) {
13
- return "object";
14
- }
15
- else if (nodeSchema instanceof index_js_1.MapNodeStoredSchema) {
16
- return "map";
17
- }
18
- else if (nodeSchema instanceof index_js_1.LeafNodeStoredSchema) {
19
- return "leaf";
20
- }
21
- throwUnsupportedNodeType(nodeSchema.constructor.name);
22
- }
23
- /**
24
- * Finds and reports discrepancies between a view schema and a stored schema.
25
- *
26
- * See documentation on {@link Discrepancy} for details of possible discrepancies.
27
- * @remarks
28
- * This function does not attempt to distinguish between equivalent representations of a node/field involving extraneous never trees.
29
- * For example, a Forbidden field with allowed type set `[]` is equivalent to an optional field with allowed type set `[]`,
30
- * as well as an optional field with an allowed type set containing only unconstructable types.
31
- *
32
- * It is up to the caller to determine whether such discrepancies matter.
33
- */
34
- function* getAllowedContentDiscrepancies(view, stored) {
35
- // check root schema discrepancies
36
- yield* getFieldDiscrepancies(view.rootFieldSchema, stored.rootFieldSchema, undefined, undefined);
37
- for (const result of compareMaps(view.nodeSchema, stored.nodeSchema)) {
38
- switch (result.type) {
39
- case "aExtra": {
40
- const viewType = getNodeSchemaType(result.value);
41
- yield {
42
- identifier: result.key,
43
- mismatch: "nodeKind",
44
- view: viewType,
45
- stored: undefined,
46
- };
47
- break;
48
- }
49
- case "bExtra": {
50
- const storedType = getNodeSchemaType(result.value);
51
- yield {
52
- identifier: result.key,
53
- mismatch: "nodeKind",
54
- view: undefined,
55
- stored: storedType,
56
- };
57
- break;
58
- }
59
- case "both": {
60
- yield* getNodeDiscrepancies(result.key, result.valueA, result.valueB);
61
- break;
62
- }
63
- default:
64
- break;
65
- }
66
- }
67
- }
68
- exports.getAllowedContentDiscrepancies = getAllowedContentDiscrepancies;
69
- function* getNodeDiscrepancies(identifier, view, stored) {
70
- const viewType = getNodeSchemaType(view);
71
- const storedType = getNodeSchemaType(stored);
72
- if (viewType !== storedType) {
73
- yield {
74
- identifier,
75
- mismatch: "nodeKind",
76
- view: viewType,
77
- stored: storedType,
78
- };
79
- return;
80
- }
81
- switch (viewType) {
82
- case "object": {
83
- const differences = Array.from(trackObjectNodeDiscrepancies(identifier, view, stored));
84
- if (differences.length > 0) {
85
- yield {
86
- identifier,
87
- mismatch: "fields",
88
- differences,
89
- };
90
- }
91
- break;
92
- }
93
- case "map":
94
- yield* getFieldDiscrepancies(view.mapFields, stored.mapFields, identifier, undefined);
95
- break;
96
- case "leaf": {
97
- const viewValue = view.leafValue;
98
- const storedValue = stored.leafValue;
99
- if (viewValue !== storedValue) {
100
- yield {
101
- identifier,
102
- mismatch: "valueSchema",
103
- view: viewValue,
104
- stored: storedValue,
105
- };
106
- }
107
- break;
108
- }
109
- default:
110
- break;
111
- }
112
- }
113
- /**
114
- * The function to track the discrepancies between two field stored schemas.
115
- *
116
- * @param keyOrRoot - If the key is missing, it indicates that this is the root field schema.
117
- */
118
- function* getFieldDiscrepancies(view, stored, identifier, fieldKey) {
119
- // Only track the symmetric differences of two sets.
120
- const findSetDiscrepancies = (a, b) => {
121
- const aDiff = [...a].filter((value) => !b.has(value));
122
- const bDiff = [...b].filter((value) => !a.has(value));
123
- return [aDiff, bDiff];
124
- };
125
- const [viewExtra, storedExtra] = findSetDiscrepancies(view.types, stored.types);
126
- if (viewExtra.length > 0 || storedExtra.length > 0) {
127
- yield {
128
- identifier,
129
- fieldKey,
130
- mismatch: "allowedTypes",
131
- view: viewExtra,
132
- stored: storedExtra,
133
- };
134
- }
135
- if (view.kind !== stored.kind) {
136
- yield {
137
- identifier,
138
- fieldKey,
139
- mismatch: "fieldKind",
140
- view: view.kind,
141
- stored: stored.kind,
142
- };
143
- }
144
- }
145
- function* trackObjectNodeDiscrepancies(identifier, view, stored) {
146
- /**
147
- * Similar to the logic used for tracking discrepancies between two node schemas, we will identify
148
- * three types of differences:
149
- * 1. Fields that exist in the view schema but not in the stored schema.
150
- * 2. Fields that exist in both schemas but have different contents.
151
- * 3. Fields that exist in the stored schema but not in the view schema.
152
- *
153
- * First, the view schema is iterated to track the first two types of differences.
154
- * Then, the stored schema is iterated to find the third type.
155
- */
156
- for (const result of compareMaps(view.objectNodeFields, stored.objectNodeFields)) {
157
- const fieldKey = result.key;
158
- switch (result.type) {
159
- case "aExtra": {
160
- if (result.value.kind === index_js_1.storedEmptyFieldSchema.kind) {
161
- // In one of view/stored, this field is explicitly forbidden, but in the other it is implicitly forbidden
162
- // (by way of omission). We treat these identically anyway.
163
- break;
164
- }
165
- yield {
166
- identifier,
167
- fieldKey,
168
- mismatch: "fieldKind",
169
- view: result.value.kind,
170
- stored: index_js_1.storedEmptyFieldSchema.kind,
171
- };
172
- break;
173
- }
174
- case "bExtra": {
175
- if (result.value.kind === index_js_1.storedEmptyFieldSchema.kind) {
176
- // In one of view/stored, this field is explicitly forbidden, but in the other it is implicitly forbidden
177
- // (by way of omission). We treat these identically anyway.
178
- break;
179
- }
180
- yield {
181
- identifier,
182
- fieldKey,
183
- mismatch: "fieldKind",
184
- view: index_js_1.storedEmptyFieldSchema.kind,
185
- stored: result.value.kind,
186
- };
187
- break;
188
- }
189
- case "both": {
190
- yield* getFieldDiscrepancies(result.valueA, result.valueB, identifier, fieldKey);
191
- break;
192
- }
193
- default:
194
- break;
195
- }
196
- }
197
- }
198
- function* compareMaps(a, b) {
199
- for (const [key, valueA] of a) {
200
- const valueB = b.get(key);
201
- yield valueB === undefined
202
- ? { type: "aExtra", key, value: valueA }
203
- : { type: "both", key, valueA, valueB };
204
- }
205
- for (const [key, valueB] of b) {
206
- if (!a.has(key)) {
207
- yield { type: "bExtra", key, value: valueB };
208
- }
209
- }
210
- }
211
- /**
212
- * @remarks
213
- *
214
- * This function uses incompatibilities to determine if changes to a document schema are backward-compatible, i.e., it determines
215
- * whether the `view` schema allows a superset of the documents that the `stored` schema allows.
216
- * According to the policy of schema evolution, `isRepoSuperset` supports three types of changes:
217
- * 1. Adding an optional field to an object node.
218
- * 2. Expanding the set of allowed types for a field.
219
- * 3. Relaxing a field kind to a more general field kind.
220
- *
221
- * Notes: We expect isRepoSuperset to return consistent results with allowsRepoSuperset. However, currently there are some scenarios
222
- * where the inconsistency will occur:
223
- *
224
- * - Different Node Kinds: If a and b have different node kinds (e.g., a is an objectNodeSchema and b is a mapNodeSchema),
225
- * `isRepoSuperset` will determine that a can never be the superset of b. In contrast, `allowsRepoSuperset` will continue
226
- * validating internal fields.
227
- */
228
- function isRepoSuperset(view, stored) {
229
- const discrepancies = getAllowedContentDiscrepancies(view, stored);
230
- for (const discrepancy of discrepancies) {
231
- switch (discrepancy.mismatch) {
232
- case "nodeKind": {
233
- if (discrepancy.stored !== undefined) {
234
- // It's fine for the view schema to know of a node type that the stored schema doesn't know about.
235
- return false;
236
- }
237
- break;
238
- }
239
- case "valueSchema":
240
- case "allowedTypes":
241
- case "fieldKind": {
242
- if (!isFieldDiscrepancyCompatible(discrepancy)) {
243
- return false;
244
- }
245
- break;
246
- }
247
- case "fields": {
248
- if (discrepancy.differences.some((difference) => !isFieldDiscrepancyCompatible(difference))) {
249
- return false;
250
- }
251
- break;
252
- }
253
- // No default
254
- }
255
- }
256
- return true;
257
- }
258
- exports.isRepoSuperset = isRepoSuperset;
259
- function isFieldDiscrepancyCompatible(discrepancy) {
260
- switch (discrepancy.mismatch) {
261
- case "allowedTypes": {
262
- // Since we only track the symmetric difference between the allowed types in the view and
263
- // stored schemas, it's sufficient to check if any extra allowed types still exist in the
264
- // stored schema.
265
- return discrepancy.stored.length === 0;
266
- }
267
- case "fieldKind": {
268
- return posetLte(discrepancy.stored, discrepancy.view, exports.fieldRealizer);
269
- }
270
- case "valueSchema": {
271
- return false;
272
- }
273
- // No default
274
- }
275
- return false;
276
- }
277
- /**
278
- * @privateRemarks
279
- * TODO: Knowledge of specific field kinds is not appropriate for modular schema.
280
- * This bit of field comparison should be dependency injected by default-schema if this comparison logic remains in modular-schema
281
- * (this is analogous to what is done in comparison.ts).
282
- */
283
- const FieldKindIdentifiers = {
284
- forbidden: (0, index_js_2.brand)("Forbidden"),
285
- required: (0, index_js_2.brand)("Value"),
286
- identifier: (0, index_js_2.brand)("Identifier"),
287
- optional: (0, index_js_2.brand)("Optional"),
288
- sequence: (0, index_js_2.brand)("Sequence"),
289
- };
290
- /**
291
- * A realizer for the partial order of field kind relaxability.
292
- *
293
- * It seems extremely likely that this partial order will remain dimension 2 over time (i.e. the set of allowed relaxations can be visualized
294
- * with a [dominance drawing](https://en.wikipedia.org/wiki/Dominance_drawing)), so this strategy allows efficient comarison between field kinds
295
- * without excessive casework.
296
- *
297
- * Hasse diagram for the partial order is shown below (lower fields can be relaxed to higher fields):
298
- * ```
299
- * sequence
300
- * |
301
- * optional
302
- * | \
303
- * required forbidden
304
- * |
305
- * identifier
306
- * ```
307
- */
308
- exports.fieldRealizer = [
309
- [
310
- FieldKindIdentifiers.forbidden,
311
- FieldKindIdentifiers.identifier,
312
- FieldKindIdentifiers.required,
313
- FieldKindIdentifiers.optional,
314
- FieldKindIdentifiers.sequence,
315
- ],
316
- [
317
- FieldKindIdentifiers.identifier,
318
- FieldKindIdentifiers.required,
319
- FieldKindIdentifiers.forbidden,
320
- FieldKindIdentifiers.optional,
321
- FieldKindIdentifiers.sequence,
322
- ],
323
- ].map((extension) => new Map(extension.map((identifier, index) => [identifier, index])));
324
- exports.PosetComparisonResult = {
325
- Less: "<",
326
- Greater: ">",
327
- Equal: "=",
328
- Incomparable: "||",
329
- };
330
- function comparePosetElements(a, b, realizer) {
331
- let hasLessThanResult = false;
332
- let hasGreaterThanResult = false;
333
- for (const extension of realizer) {
334
- const aIndex = extension.get(a);
335
- const bIndex = extension.get(b);
336
- (0, internal_1.assert)(aIndex !== undefined && bIndex !== undefined, 0xa72 /* Invalid realizer */);
337
- if (aIndex < bIndex) {
338
- hasLessThanResult = true;
339
- }
340
- else if (aIndex > bIndex) {
341
- hasGreaterThanResult = true;
342
- }
343
- }
344
- return hasLessThanResult
345
- ? hasGreaterThanResult
346
- ? exports.PosetComparisonResult.Incomparable
347
- : exports.PosetComparisonResult.Less
348
- : hasGreaterThanResult
349
- ? exports.PosetComparisonResult.Greater
350
- : exports.PosetComparisonResult.Equal;
351
- }
352
- exports.comparePosetElements = comparePosetElements;
353
- function posetLte(a, b, realizer) {
354
- const comparison = comparePosetElements(a, b, realizer);
355
- return (comparison === exports.PosetComparisonResult.Less || comparison === exports.PosetComparisonResult.Equal);
356
- }
357
- exports.posetLte = posetLte;
358
- function throwUnsupportedNodeType(type) {
359
- throw new TypeError(`Unsupported node stored schema type: ${type}`);
360
- }
361
- //# sourceMappingURL=discrepancies.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"discrepancies.js","sourceRoot":"","sources":["../../../src/feature-libraries/modular-schema/discrepancies.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAE7D,kDAa6B;AAC7B,kDAA4C;AAoH5C,SAAS,iBAAiB,CAAC,UAAgC;IAC1D,IAAI,UAAU,YAAY,iCAAsB,EAAE,CAAC;QAClD,OAAO,QAAQ,CAAC;IACjB,CAAC;SAAM,IAAI,UAAU,YAAY,8BAAmB,EAAE,CAAC;QACtD,OAAO,KAAK,CAAC;IACd,CAAC;SAAM,IAAI,UAAU,YAAY,+BAAoB,EAAE,CAAC;QACvD,OAAO,MAAM,CAAC;IACf,CAAC;IACD,wBAAwB,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;GAUG;AACH,QAAe,CAAC,CAAC,8BAA8B,CAC9C,IAAsB,EACtB,MAAwB;IAExB,kCAAkC;IAClC,KAAK,CAAC,CAAC,qBAAqB,CAC3B,IAAI,CAAC,eAAe,EACpB,MAAM,CAAC,eAAe,EACtB,SAAS,EACT,SAAS,CACT,CAAC;IAEF,KAAK,MAAM,MAAM,IAAI,WAA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AAU,KAAK,6BAAqB,CAAC,KAAK,CACvF,CAAC;AACH,CAAC;AALD,4BAKC;AAED,SAAS,wBAAwB,CAAC,IAAY;IAC7C,MAAM,IAAI,SAAS,CAAC,wCAAwC,IAAI,EAAE,CAAC,CAAC;AACrE,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\";\n\nimport {\n\ttype FieldKey,\n\ttype FieldKindIdentifier,\n\tLeafNodeStoredSchema,\n\tMapNodeStoredSchema,\n\tObjectNodeStoredSchema,\n\tstoredEmptyFieldSchema,\n\ttype TreeFieldStoredSchema,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeNodeStoredSchema,\n\ttype TreeStoredSchema,\n\ttype TreeTypeSet,\n\ttype ValueSchema,\n} from \"../../core/index.js\";\nimport { brand } from \"../../util/index.js\";\n\n// TODO:\n// The comparisons in this file seem redundant with those in comparison.ts.\n// Rather than both existing, one of which just returns boolean and the other which returns additional details, a simple comparison which returns everything needed should be used.\n\n/**\n * Discriminated union (keyed on `mismatch`) of discrepancies between a view and stored schema.\n * @remarks\n *\n * 1. FieldDiscrepancy\n *\n * `FieldDiscrepancy` represents the differences between two `TreeFieldStoredSchema` objects. It consists of\n * three types of incompatibilities:\n *\n * - FieldKindDiscrepancy: Indicates the differences in `FieldKindIdentifier` between two `TreeFieldStoredSchema`\n * objects (e.g., optional, required, sequence, etc.).\n * - AllowedTypesDiscrepancy: Indicates the differences in the allowed child types between the two schemas.\n * - ValueSchemaDiscrepancy: Specifically indicates the differences in the `ValueSchema` of two\n * `LeafNodeStoredSchema` objects.\n *\n * 2. NodeDiscrepancy\n *\n * `NodeDiscrepancy` represents the differences between two `TreeNodeStoredSchema` objects and includes:\n *\n * - NodeKindDiscrepancy: Indicates the differences in the types of `TreeNodeStoredSchema` (currently supports\n * `ObjectNodeStoredSchema`, `MapNodeStoredSchema`, and `LeafNodeStoredSchema`).\n * - NodeFieldsDiscrepancy: Indicates the `FieldDiscrepancy` of `TreeFieldStoredSchema` within two\n * `TreeNodeStoredSchema`. It includes an array of `FieldDiscrepancy` instances in the `differences` field.\n *\n * When comparing two nodes for compatibility, it only makes sense to compare their fields if the nodes are of\n * the same kind (map, object, leaf).\n *\n * 3. Discrepancy\n *\n * Discrepancy consists of both `NodeDiscrepancy` and `FieldDiscrepancy`, representing any kind of\n * schema differences. See {@link getAllowedContentDiscrepancies} for more details about how we process it\n * and the ordering.\n */\nexport type Discrepancy = FieldDiscrepancy | NodeDiscrepancy;\n\nexport type NodeDiscrepancy = NodeKindDiscrepancy | NodeFieldsDiscrepancy;\n\n/**\n * A discrepancy in the declaration of a field.\n */\nexport type FieldDiscrepancy =\n\t| AllowedTypeDiscrepancy\n\t| FieldKindDiscrepancy\n\t| ValueSchemaDiscrepancy;\n\n/**\n * Information about where a field discrepancy is located within a collection of schema.\n */\nexport interface FieldDiscrepancyLocation {\n\t/**\n\t * The {@link TreeNodeSchemaIdentifier} that contains the discrepancy.\n\t *\n\t * Undefined iff the discrepancy is part of the root field schema.\n\t */\n\tidentifier: TreeNodeSchemaIdentifier | undefined;\n\t/**\n\t * The {@link FieldKey} for the field that contains the discrepancy.\n\t * Undefined when:\n\t * - the discrepancy is part of the root field schema\n\t * - the discrepancy is for 'all fields' of a map node\n\t */\n\tfieldKey: FieldKey | undefined;\n}\n\n/**\n * A discrepancy in the allowed types of a field.\n *\n * @remarks\n * This reports the symmetric difference of allowed types in view/stored to enable more efficient checks for compatibility\n */\nexport interface AllowedTypeDiscrepancy extends FieldDiscrepancyLocation {\n\tmismatch: \"allowedTypes\";\n\t/**\n\t * List of allowed type identifiers in viewed schema which are not allowed in stored schema\n\t */\n\tview: TreeNodeSchemaIdentifier[];\n\t/**\n\t * List of allowed type identifiers in stored schema which are not allowed in view schema\n\t */\n\tstored: TreeNodeSchemaIdentifier[];\n}\n\nexport interface FieldKindDiscrepancy extends FieldDiscrepancyLocation {\n\tmismatch: \"fieldKind\";\n\tview: FieldKindIdentifier;\n\tstored: FieldKindIdentifier;\n}\n\nexport interface ValueSchemaDiscrepancy {\n\tidentifier: TreeNodeSchemaIdentifier;\n\tmismatch: \"valueSchema\";\n\tview: ValueSchema | undefined;\n\tstored: ValueSchema | undefined;\n}\n\nexport interface NodeKindDiscrepancy {\n\tidentifier: TreeNodeSchemaIdentifier;\n\tmismatch: \"nodeKind\";\n\tview: SchemaFactoryNodeKind | undefined;\n\tstored: SchemaFactoryNodeKind | undefined;\n}\n\nexport interface NodeFieldsDiscrepancy {\n\tidentifier: TreeNodeSchemaIdentifier;\n\tmismatch: \"fields\";\n\tdifferences: FieldDiscrepancy[];\n}\n\ntype SchemaFactoryNodeKind = \"object\" | \"leaf\" | \"map\";\n\nfunction getNodeSchemaType(nodeSchema: TreeNodeStoredSchema): SchemaFactoryNodeKind {\n\tif (nodeSchema instanceof ObjectNodeStoredSchema) {\n\t\treturn \"object\";\n\t} else if (nodeSchema instanceof MapNodeStoredSchema) {\n\t\treturn \"map\";\n\t} else if (nodeSchema instanceof LeafNodeStoredSchema) {\n\t\treturn \"leaf\";\n\t}\n\tthrowUnsupportedNodeType(nodeSchema.constructor.name);\n}\n\n/**\n * Finds and reports discrepancies between a view schema and a stored schema.\n *\n * See documentation on {@link Discrepancy} for details of possible discrepancies.\n * @remarks\n * This function does not attempt to distinguish between equivalent representations of a node/field involving extraneous never trees.\n * For example, a Forbidden field with allowed type set `[]` is equivalent to an optional field with allowed type set `[]`,\n * as well as an optional field with an allowed type set containing only unconstructable types.\n *\n * It is up to the caller to determine whether such discrepancies matter.\n */\nexport function* getAllowedContentDiscrepancies(\n\tview: TreeStoredSchema,\n\tstored: TreeStoredSchema,\n): Iterable<Discrepancy> {\n\t// check root schema discrepancies\n\tyield* getFieldDiscrepancies(\n\t\tview.rootFieldSchema,\n\t\tstored.rootFieldSchema,\n\t\tundefined,\n\t\tundefined,\n\t);\n\n\tfor (const result of compareMaps(view.nodeSchema, stored.nodeSchema)) {\n\t\tswitch (result.type) {\n\t\t\tcase \"aExtra\": {\n\t\t\t\tconst viewType = getNodeSchemaType(result.value);\n\t\t\t\tyield {\n\t\t\t\t\tidentifier: result.key,\n\t\t\t\t\tmismatch: \"nodeKind\",\n\t\t\t\t\tview: viewType,\n\t\t\t\t\tstored: undefined,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"bExtra\": {\n\t\t\t\tconst storedType = getNodeSchemaType(result.value);\n\t\t\t\tyield {\n\t\t\t\t\tidentifier: result.key,\n\t\t\t\t\tmismatch: \"nodeKind\",\n\t\t\t\t\tview: undefined,\n\t\t\t\t\tstored: storedType,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"both\": {\n\t\t\t\tyield* getNodeDiscrepancies(result.key, result.valueA, result.valueB);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\nfunction* getNodeDiscrepancies(\n\tidentifier: TreeNodeSchemaIdentifier,\n\tview: TreeNodeStoredSchema,\n\tstored: TreeNodeStoredSchema,\n): Iterable<Discrepancy> {\n\tconst viewType = getNodeSchemaType(view);\n\tconst storedType = getNodeSchemaType(stored);\n\tif (viewType !== storedType) {\n\t\tyield {\n\t\t\tidentifier,\n\t\t\tmismatch: \"nodeKind\",\n\t\t\tview: viewType,\n\t\t\tstored: storedType,\n\t\t};\n\t\treturn;\n\t}\n\n\tswitch (viewType) {\n\t\tcase \"object\": {\n\t\t\tconst differences = Array.from(\n\t\t\t\ttrackObjectNodeDiscrepancies(\n\t\t\t\t\tidentifier,\n\t\t\t\t\tview as ObjectNodeStoredSchema,\n\t\t\t\t\tstored as ObjectNodeStoredSchema,\n\t\t\t\t),\n\t\t\t);\n\t\t\tif (differences.length > 0) {\n\t\t\t\tyield {\n\t\t\t\t\tidentifier,\n\t\t\t\t\tmismatch: \"fields\",\n\t\t\t\t\tdifferences,\n\t\t\t\t} satisfies NodeFieldsDiscrepancy;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase \"map\":\n\t\t\tyield* getFieldDiscrepancies(\n\t\t\t\t(view as MapNodeStoredSchema).mapFields,\n\t\t\t\t(stored as MapNodeStoredSchema).mapFields,\n\t\t\t\tidentifier,\n\t\t\t\tundefined,\n\t\t\t);\n\t\t\tbreak;\n\t\tcase \"leaf\": {\n\t\t\tconst viewValue = (view as LeafNodeStoredSchema).leafValue;\n\t\t\tconst storedValue = (stored as LeafNodeStoredSchema).leafValue;\n\t\t\tif (viewValue !== storedValue) {\n\t\t\t\tyield {\n\t\t\t\t\tidentifier,\n\t\t\t\t\tmismatch: \"valueSchema\",\n\t\t\t\t\tview: viewValue,\n\t\t\t\t\tstored: storedValue,\n\t\t\t\t};\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tdefault:\n\t\t\tbreak;\n\t}\n}\n\n/**\n * The function to track the discrepancies between two field stored schemas.\n *\n * @param keyOrRoot - If the key is missing, it indicates that this is the root field schema.\n */\nfunction* getFieldDiscrepancies(\n\tview: TreeFieldStoredSchema,\n\tstored: TreeFieldStoredSchema,\n\tidentifier: TreeNodeSchemaIdentifier | undefined,\n\tfieldKey: FieldKey | undefined,\n): Iterable<FieldDiscrepancy> {\n\t// Only track the symmetric differences of two sets.\n\tconst findSetDiscrepancies = (\n\t\ta: TreeTypeSet,\n\t\tb: TreeTypeSet,\n\t): [TreeNodeSchemaIdentifier[], TreeNodeSchemaIdentifier[]] => {\n\t\tconst aDiff = [...a].filter((value) => !b.has(value));\n\t\tconst bDiff = [...b].filter((value) => !a.has(value));\n\t\treturn [aDiff, bDiff];\n\t};\n\n\tconst [viewExtra, storedExtra] = findSetDiscrepancies(view.types, stored.types);\n\tif (viewExtra.length > 0 || storedExtra.length > 0) {\n\t\tyield {\n\t\t\tidentifier,\n\t\t\tfieldKey,\n\t\t\tmismatch: \"allowedTypes\",\n\t\t\tview: viewExtra,\n\t\t\tstored: storedExtra,\n\t\t} satisfies AllowedTypeDiscrepancy;\n\t}\n\n\tif (view.kind !== stored.kind) {\n\t\tyield {\n\t\t\tidentifier,\n\t\t\tfieldKey,\n\t\t\tmismatch: \"fieldKind\",\n\t\t\tview: view.kind,\n\t\t\tstored: stored.kind,\n\t\t} satisfies FieldKindDiscrepancy;\n\t}\n}\n\nfunction* trackObjectNodeDiscrepancies(\n\tidentifier: TreeNodeSchemaIdentifier,\n\tview: ObjectNodeStoredSchema,\n\tstored: ObjectNodeStoredSchema,\n): Iterable<FieldDiscrepancy> {\n\t/**\n\t * Similar to the logic used for tracking discrepancies between two node schemas, we will identify\n\t * three types of differences:\n\t * 1. Fields that exist in the view schema but not in the stored schema.\n\t * 2. Fields that exist in both schemas but have different contents.\n\t * 3. Fields that exist in the stored schema but not in the view schema.\n\t *\n\t * First, the view schema is iterated to track the first two types of differences.\n\t * Then, the stored schema is iterated to find the third type.\n\t */\n\n\tfor (const result of compareMaps(view.objectNodeFields, stored.objectNodeFields)) {\n\t\tconst fieldKey = result.key;\n\t\tswitch (result.type) {\n\t\t\tcase \"aExtra\": {\n\t\t\t\tif (result.value.kind === storedEmptyFieldSchema.kind) {\n\t\t\t\t\t// In one of view/stored, this field is explicitly forbidden, but in the other it is implicitly forbidden\n\t\t\t\t\t// (by way of omission). We treat these identically anyway.\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tyield {\n\t\t\t\t\tidentifier,\n\t\t\t\t\tfieldKey,\n\t\t\t\t\tmismatch: \"fieldKind\",\n\t\t\t\t\tview: result.value.kind,\n\t\t\t\t\tstored: storedEmptyFieldSchema.kind,\n\t\t\t\t} satisfies FieldKindDiscrepancy;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"bExtra\": {\n\t\t\t\tif (result.value.kind === storedEmptyFieldSchema.kind) {\n\t\t\t\t\t// In one of view/stored, this field is explicitly forbidden, but in the other it is implicitly forbidden\n\t\t\t\t\t// (by way of omission). We treat these identically anyway.\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tyield {\n\t\t\t\t\tidentifier,\n\t\t\t\t\tfieldKey,\n\t\t\t\t\tmismatch: \"fieldKind\",\n\t\t\t\t\tview: storedEmptyFieldSchema.kind,\n\t\t\t\t\tstored: result.value.kind,\n\t\t\t\t} satisfies FieldKindDiscrepancy;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"both\": {\n\t\t\t\tyield* getFieldDiscrepancies(result.valueA, result.valueB, identifier, fieldKey);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\nfunction* compareMaps<K, V1, V2>(\n\ta: ReadonlyMap<K, V1>,\n\tb: ReadonlyMap<K, V2>,\n): Iterable<\n\t| { type: \"aExtra\"; key: K; value: V1 }\n\t| { type: \"bExtra\"; key: K; value: V2 }\n\t| { type: \"both\"; key: K; valueA: V1; valueB: V2 }\n> {\n\tfor (const [key, valueA] of a) {\n\t\tconst valueB = b.get(key);\n\t\tyield valueB === undefined\n\t\t\t? { type: \"aExtra\", key, value: valueA }\n\t\t\t: { type: \"both\", key, valueA, valueB };\n\t}\n\tfor (const [key, valueB] of b) {\n\t\tif (!a.has(key)) {\n\t\t\tyield { type: \"bExtra\", key, value: valueB };\n\t\t}\n\t}\n}\n/**\n * @remarks\n *\n * This function uses incompatibilities to determine if changes to a document schema are backward-compatible, i.e., it determines\n * whether the `view` schema allows a superset of the documents that the `stored` schema allows.\n * According to the policy of schema evolution, `isRepoSuperset` supports three types of changes:\n * 1. Adding an optional field to an object node.\n * 2. Expanding the set of allowed types for a field.\n * 3. Relaxing a field kind to a more general field kind.\n *\n * Notes: We expect isRepoSuperset to return consistent results with allowsRepoSuperset. However, currently there are some scenarios\n * where the inconsistency will occur:\n *\n * - Different Node Kinds: If a and b have different node kinds (e.g., a is an objectNodeSchema and b is a mapNodeSchema),\n * `isRepoSuperset` will determine that a can never be the superset of b. In contrast, `allowsRepoSuperset` will continue\n * validating internal fields.\n */\nexport function isRepoSuperset(view: TreeStoredSchema, stored: TreeStoredSchema): boolean {\n\tconst discrepancies = getAllowedContentDiscrepancies(view, stored);\n\n\tfor (const discrepancy of discrepancies) {\n\t\tswitch (discrepancy.mismatch) {\n\t\t\tcase \"nodeKind\": {\n\t\t\t\tif (discrepancy.stored !== undefined) {\n\t\t\t\t\t// It's fine for the view schema to know of a node type that the stored schema doesn't know about.\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"valueSchema\":\n\t\t\tcase \"allowedTypes\":\n\t\t\tcase \"fieldKind\": {\n\t\t\t\tif (!isFieldDiscrepancyCompatible(discrepancy)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"fields\": {\n\t\t\t\tif (\n\t\t\t\t\tdiscrepancy.differences.some(\n\t\t\t\t\t\t(difference) => !isFieldDiscrepancyCompatible(difference),\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t// No default\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction isFieldDiscrepancyCompatible(discrepancy: FieldDiscrepancy): boolean {\n\tswitch (discrepancy.mismatch) {\n\t\tcase \"allowedTypes\": {\n\t\t\t// Since we only track the symmetric difference between the allowed types in the view and\n\t\t\t// stored schemas, it's sufficient to check if any extra allowed types still exist in the\n\t\t\t// stored schema.\n\t\t\treturn discrepancy.stored.length === 0;\n\t\t}\n\t\tcase \"fieldKind\": {\n\t\t\treturn posetLte(discrepancy.stored, discrepancy.view, fieldRealizer);\n\t\t}\n\t\tcase \"valueSchema\": {\n\t\t\treturn false;\n\t\t}\n\t\t// No default\n\t}\n\treturn false;\n}\n\n/**\n * A linear extension of a partially-ordered set of `T`s. See:\n * https://en.wikipedia.org/wiki/Linear_extension\n *\n * The linear extension is represented as a lookup from each poset element to its index in the linear extension.\n */\nexport type LinearExtension<T> = Map<T, number>;\n\n/**\n * A realizer for a partially-ordered set. See:\n * https://en.wikipedia.org/wiki/Order_dimension\n */\nexport type Realizer<T> = LinearExtension<T>[];\n\n/**\n * @privateRemarks\n * TODO: Knowledge of specific field kinds is not appropriate for modular schema.\n * This bit of field comparison should be dependency injected by default-schema if this comparison logic remains in modular-schema\n * (this is analogous to what is done in comparison.ts).\n */\nconst FieldKindIdentifiers = {\n\tforbidden: brand<FieldKindIdentifier>(\"Forbidden\"),\n\trequired: brand<FieldKindIdentifier>(\"Value\"),\n\tidentifier: brand<FieldKindIdentifier>(\"Identifier\"),\n\toptional: brand<FieldKindIdentifier>(\"Optional\"),\n\tsequence: brand<FieldKindIdentifier>(\"Sequence\"),\n};\n\n/**\n * A realizer for the partial order of field kind relaxability.\n *\n * It seems extremely likely that this partial order will remain dimension 2 over time (i.e. the set of allowed relaxations can be visualized\n * with a [dominance drawing](https://en.wikipedia.org/wiki/Dominance_drawing)), so this strategy allows efficient comarison between field kinds\n * without excessive casework.\n *\n * Hasse diagram for the partial order is shown below (lower fields can be relaxed to higher fields):\n * ```\n * sequence\n * |\n * optional\n * | \\\n * required forbidden\n * |\n * identifier\n * ```\n */\nexport const fieldRealizer: Realizer<FieldKindIdentifier> = [\n\t[\n\t\tFieldKindIdentifiers.forbidden,\n\t\tFieldKindIdentifiers.identifier,\n\t\tFieldKindIdentifiers.required,\n\t\tFieldKindIdentifiers.optional,\n\t\tFieldKindIdentifiers.sequence,\n\t],\n\t[\n\t\tFieldKindIdentifiers.identifier,\n\t\tFieldKindIdentifiers.required,\n\t\tFieldKindIdentifiers.forbidden,\n\t\tFieldKindIdentifiers.optional,\n\t\tFieldKindIdentifiers.sequence,\n\t],\n].map((extension) => new Map(extension.map((identifier, index) => [identifier, index])));\n\nexport const PosetComparisonResult = {\n\tLess: \"<\",\n\tGreater: \">\",\n\tEqual: \"=\",\n\tIncomparable: \"||\",\n} as const;\ntype PosetComparisonResult =\n\t(typeof PosetComparisonResult)[keyof typeof PosetComparisonResult];\n\nexport function comparePosetElements<T>(\n\ta: T,\n\tb: T,\n\trealizer: Realizer<T>,\n): PosetComparisonResult {\n\tlet hasLessThanResult = false;\n\tlet hasGreaterThanResult = false;\n\tfor (const extension of realizer) {\n\t\tconst aIndex = extension.get(a);\n\t\tconst bIndex = extension.get(b);\n\t\tassert(aIndex !== undefined && bIndex !== undefined, 0xa72 /* Invalid realizer */);\n\t\tif (aIndex < bIndex) {\n\t\t\thasLessThanResult = true;\n\t\t} else if (aIndex > bIndex) {\n\t\t\thasGreaterThanResult = true;\n\t\t}\n\t}\n\n\treturn hasLessThanResult\n\t\t? hasGreaterThanResult\n\t\t\t? PosetComparisonResult.Incomparable\n\t\t\t: PosetComparisonResult.Less\n\t\t: hasGreaterThanResult\n\t\t\t? PosetComparisonResult.Greater\n\t\t\t: PosetComparisonResult.Equal;\n}\n\nexport function posetLte<T>(a: T, b: T, realizer: Realizer<T>): boolean {\n\tconst comparison = comparePosetElements(a, b, realizer);\n\treturn (\n\t\tcomparison === PosetComparisonResult.Less || comparison === PosetComparisonResult.Equal\n\t);\n}\n\nfunction throwUnsupportedNodeType(type: string): never {\n\tthrow new TypeError(`Unsupported node stored schema type: ${type}`);\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"discrepancies.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/modular-schema/discrepancies.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,KAAK,QAAQ,EACb,KAAK,mBAAmB,EAMxB,KAAK,wBAAwB,EAE7B,KAAK,gBAAgB,EAErB,KAAK,WAAW,EAChB,MAAM,qBAAqB,CAAC;AAO7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,MAAM,WAAW,GAAG,gBAAgB,GAAG,eAAe,CAAC;AAE7D,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG,qBAAqB,CAAC;AAE1E;;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