@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.
- package/.eslintrc.cjs +3 -2
- package/CHANGELOG.md +49 -0
- package/dist/feature-libraries/index.d.ts +1 -1
- package/dist/feature-libraries/index.d.ts.map +1 -1
- package/dist/feature-libraries/index.js +2 -8
- package/dist/feature-libraries/index.js.map +1 -1
- package/dist/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/comparison.js +0 -3
- package/dist/feature-libraries/modular-schema/comparison.js.map +1 -1
- package/dist/feature-libraries/modular-schema/index.d.ts +0 -1
- package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/index.js +1 -8
- package/dist/feature-libraries/modular-schema/index.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/shared-tree/schematizeTree.d.ts +1 -1
- package/dist/shared-tree/schematizeTree.d.ts.map +1 -1
- package/dist/shared-tree/schematizeTree.js +5 -4
- package/dist/shared-tree/schematizeTree.js.map +1 -1
- package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/dist/shared-tree/schematizingTreeView.js +2 -2
- package/dist/shared-tree/schematizingTreeView.js.map +1 -1
- package/dist/shared-tree/tree.js +1 -1
- package/dist/shared-tree/tree.js.map +1 -1
- package/dist/shared-tree/treeCheckout.js +1 -1
- package/dist/shared-tree/treeCheckout.js.map +1 -1
- package/dist/simple-tree/api/schemaCompatibilityTester.d.ts +3 -18
- package/dist/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaCompatibilityTester.js +31 -82
- package/dist/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
- package/dist/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaCreationUtilities.js +2 -2
- package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
- package/dist/simple-tree/api/storedSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/storedSchema.js +1 -1
- package/dist/simple-tree/api/storedSchema.js.map +1 -1
- package/dist/{feature-libraries/modular-schema → simple-tree}/discrepancies.d.ts +22 -29
- package/dist/simple-tree/discrepancies.d.ts.map +1 -0
- package/dist/simple-tree/discrepancies.js +382 -0
- package/dist/simple-tree/discrepancies.js.map +1 -0
- package/dist/simple-tree/index.d.ts +2 -1
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js +7 -1
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/node-kinds/index.d.ts +1 -1
- package/dist/simple-tree/node-kinds/index.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/index.js.map +1 -1
- package/dist/simple-tree/node-kinds/object/index.d.ts +1 -1
- package/dist/simple-tree/node-kinds/object/index.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/object/index.js.map +1 -1
- package/lib/feature-libraries/index.d.ts +1 -1
- package/lib/feature-libraries/index.d.ts.map +1 -1
- package/lib/feature-libraries/index.js +1 -1
- package/lib/feature-libraries/index.js.map +1 -1
- package/lib/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/comparison.js +0 -3
- package/lib/feature-libraries/modular-schema/comparison.js.map +1 -1
- package/lib/feature-libraries/modular-schema/index.d.ts +0 -1
- package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/index.js +0 -1
- package/lib/feature-libraries/modular-schema/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/shared-tree/schematizeTree.d.ts +1 -1
- package/lib/shared-tree/schematizeTree.d.ts.map +1 -1
- package/lib/shared-tree/schematizeTree.js +3 -2
- package/lib/shared-tree/schematizeTree.js.map +1 -1
- package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/lib/shared-tree/schematizingTreeView.js +3 -3
- package/lib/shared-tree/schematizingTreeView.js.map +1 -1
- package/lib/shared-tree/tree.js +1 -1
- package/lib/shared-tree/tree.js.map +1 -1
- package/lib/shared-tree/treeCheckout.js +1 -1
- package/lib/shared-tree/treeCheckout.js.map +1 -1
- package/lib/simple-tree/api/schemaCompatibilityTester.d.ts +3 -18
- package/lib/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaCompatibilityTester.js +25 -76
- package/lib/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
- package/lib/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaCreationUtilities.js +2 -2
- package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
- package/lib/simple-tree/api/storedSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/storedSchema.js +1 -1
- package/lib/simple-tree/api/storedSchema.js.map +1 -1
- package/lib/{feature-libraries/modular-schema → simple-tree}/discrepancies.d.ts +22 -29
- package/lib/simple-tree/discrepancies.d.ts.map +1 -0
- package/lib/simple-tree/discrepancies.js +376 -0
- package/lib/simple-tree/discrepancies.js.map +1 -0
- package/lib/simple-tree/index.d.ts +2 -1
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js +2 -1
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/node-kinds/index.d.ts +1 -1
- package/lib/simple-tree/node-kinds/index.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/index.js.map +1 -1
- package/lib/simple-tree/node-kinds/object/index.d.ts +1 -1
- package/lib/simple-tree/node-kinds/object/index.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/object/index.js.map +1 -1
- package/package.json +20 -20
- package/src/feature-libraries/index.ts +0 -15
- package/src/feature-libraries/modular-schema/comparison.ts +0 -4
- package/src/feature-libraries/modular-schema/index.ts +0 -17
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/schematizeTree.ts +3 -3
- package/src/shared-tree/schematizingTreeView.ts +3 -6
- package/src/shared-tree/tree.ts +1 -1
- package/src/shared-tree/treeCheckout.ts +1 -1
- package/src/simple-tree/api/schemaCompatibilityTester.ts +37 -127
- package/src/simple-tree/api/schemaCreationUtilities.ts +5 -2
- package/src/simple-tree/api/storedSchema.ts +0 -1
- package/src/simple-tree/discrepancies.ts +648 -0
- package/src/simple-tree/index.ts +9 -1
- package/src/simple-tree/node-kinds/index.ts +1 -0
- package/src/simple-tree/node-kinds/object/index.ts +1 -0
- package/dist/feature-libraries/modular-schema/discrepancies.d.ts.map +0 -1
- package/dist/feature-libraries/modular-schema/discrepancies.js +0 -361
- package/dist/feature-libraries/modular-schema/discrepancies.js.map +0 -1
- package/lib/feature-libraries/modular-schema/discrepancies.d.ts.map +0 -1
- package/lib/feature-libraries/modular-schema/discrepancies.js +0 -354
- package/lib/feature-libraries/modular-schema/discrepancies.js.map +0 -1
- package/src/feature-libraries/modular-schema/discrepancies.ts +0 -567
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/tree",
|
|
3
|
-
"version": "2.51.0
|
|
3
|
+
"version": "2.51.0",
|
|
4
4
|
"description": "Distributed tree",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -101,17 +101,17 @@
|
|
|
101
101
|
"temp-directory": "nyc/.nyc_output"
|
|
102
102
|
},
|
|
103
103
|
"dependencies": {
|
|
104
|
-
"@fluid-internal/client-utils": "2.51.0
|
|
105
|
-
"@fluidframework/container-runtime": "2.51.0
|
|
106
|
-
"@fluidframework/core-interfaces": "2.51.0
|
|
107
|
-
"@fluidframework/core-utils": "2.51.0
|
|
108
|
-
"@fluidframework/datastore-definitions": "2.51.0
|
|
109
|
-
"@fluidframework/driver-definitions": "2.51.0
|
|
110
|
-
"@fluidframework/id-compressor": "2.51.0
|
|
111
|
-
"@fluidframework/runtime-definitions": "2.51.0
|
|
112
|
-
"@fluidframework/runtime-utils": "2.51.0
|
|
113
|
-
"@fluidframework/shared-object-base": "2.51.0
|
|
114
|
-
"@fluidframework/telemetry-utils": "2.51.0
|
|
104
|
+
"@fluid-internal/client-utils": "~2.51.0",
|
|
105
|
+
"@fluidframework/container-runtime": "~2.51.0",
|
|
106
|
+
"@fluidframework/core-interfaces": "~2.51.0",
|
|
107
|
+
"@fluidframework/core-utils": "~2.51.0",
|
|
108
|
+
"@fluidframework/datastore-definitions": "~2.51.0",
|
|
109
|
+
"@fluidframework/driver-definitions": "~2.51.0",
|
|
110
|
+
"@fluidframework/id-compressor": "~2.51.0",
|
|
111
|
+
"@fluidframework/runtime-definitions": "~2.51.0",
|
|
112
|
+
"@fluidframework/runtime-utils": "~2.51.0",
|
|
113
|
+
"@fluidframework/shared-object-base": "~2.51.0",
|
|
114
|
+
"@fluidframework/telemetry-utils": "~2.51.0",
|
|
115
115
|
"@sinclair/typebox": "^0.34.13",
|
|
116
116
|
"@tylerbu/sorted-btree-es6": "^1.8.0",
|
|
117
117
|
"@types/ungap__structured-clone": "^1.2.0",
|
|
@@ -121,19 +121,19 @@
|
|
|
121
121
|
"devDependencies": {
|
|
122
122
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
123
123
|
"@biomejs/biome": "~1.9.3",
|
|
124
|
-
"@fluid-internal/mocha-test-setup": "2.51.0
|
|
125
|
-
"@fluid-private/stochastic-test-utils": "2.51.0
|
|
126
|
-
"@fluid-private/test-dds-utils": "2.51.0
|
|
127
|
-
"@fluid-private/test-drivers": "2.51.0
|
|
124
|
+
"@fluid-internal/mocha-test-setup": "~2.51.0",
|
|
125
|
+
"@fluid-private/stochastic-test-utils": "~2.51.0",
|
|
126
|
+
"@fluid-private/test-dds-utils": "~2.51.0",
|
|
127
|
+
"@fluid-private/test-drivers": "~2.51.0",
|
|
128
128
|
"@fluid-tools/benchmark": "^0.51.0",
|
|
129
129
|
"@fluid-tools/build-cli": "^0.56.0",
|
|
130
130
|
"@fluidframework/build-common": "^2.0.3",
|
|
131
131
|
"@fluidframework/build-tools": "^0.56.0",
|
|
132
|
-
"@fluidframework/container-definitions": "2.51.0
|
|
133
|
-
"@fluidframework/container-loader": "2.51.0
|
|
132
|
+
"@fluidframework/container-definitions": "~2.51.0",
|
|
133
|
+
"@fluidframework/container-loader": "~2.51.0",
|
|
134
134
|
"@fluidframework/eslint-config-fluid": "^5.7.4",
|
|
135
|
-
"@fluidframework/test-runtime-utils": "2.51.0
|
|
136
|
-
"@fluidframework/test-utils": "2.51.0
|
|
135
|
+
"@fluidframework/test-runtime-utils": "~2.51.0",
|
|
136
|
+
"@fluidframework/test-utils": "~2.51.0",
|
|
137
137
|
"@fluidframework/tree-previous": "npm:@fluidframework/tree@2.50.0",
|
|
138
138
|
"@microsoft/api-extractor": "7.52.8",
|
|
139
139
|
"@types/diff": "^3.5.1",
|
|
@@ -84,22 +84,7 @@ export {
|
|
|
84
84
|
type FieldChangeEncodingContext,
|
|
85
85
|
type FieldKindConfiguration,
|
|
86
86
|
type FieldKindConfigurationEntry,
|
|
87
|
-
getAllowedContentDiscrepancies,
|
|
88
|
-
isRepoSuperset,
|
|
89
|
-
type AllowedTypeDiscrepancy,
|
|
90
|
-
type FieldKindDiscrepancy,
|
|
91
|
-
type ValueSchemaDiscrepancy,
|
|
92
|
-
type FieldDiscrepancy,
|
|
93
|
-
type NodeDiscrepancy,
|
|
94
|
-
type NodeKindDiscrepancy,
|
|
95
|
-
type NodeFieldsDiscrepancy,
|
|
96
87
|
isNeverTree,
|
|
97
|
-
type LinearExtension,
|
|
98
|
-
type Realizer,
|
|
99
|
-
fieldRealizer,
|
|
100
|
-
PosetComparisonResult,
|
|
101
|
-
comparePosetElements,
|
|
102
|
-
posetLte,
|
|
103
88
|
} from "./modular-schema/index.js";
|
|
104
89
|
|
|
105
90
|
export { mapRootChanges } from "./deltaUtils.js";
|
|
@@ -22,10 +22,6 @@ import type { FullSchemaPolicy } from "./fieldKind.js";
|
|
|
22
22
|
import { withEditor } from "./fieldKindWithEditor.js";
|
|
23
23
|
import { isNeverTree } from "./isNeverTree.js";
|
|
24
24
|
|
|
25
|
-
// TODO:
|
|
26
|
-
// The comparisons in this file seem redundant with those in discrepancies.ts.
|
|
27
|
-
// 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.
|
|
28
|
-
|
|
29
25
|
/**
|
|
30
26
|
* @returns true iff `superset` is a superset of `original`.
|
|
31
27
|
*
|
|
@@ -77,20 +77,3 @@ export type {
|
|
|
77
77
|
FieldKindConfiguration,
|
|
78
78
|
FieldKindConfigurationEntry,
|
|
79
79
|
} from "./fieldKindConfiguration.js";
|
|
80
|
-
export {
|
|
81
|
-
getAllowedContentDiscrepancies,
|
|
82
|
-
isRepoSuperset,
|
|
83
|
-
type AllowedTypeDiscrepancy,
|
|
84
|
-
type FieldKindDiscrepancy,
|
|
85
|
-
type ValueSchemaDiscrepancy,
|
|
86
|
-
type FieldDiscrepancy,
|
|
87
|
-
type NodeDiscrepancy,
|
|
88
|
-
type NodeKindDiscrepancy,
|
|
89
|
-
type NodeFieldsDiscrepancy,
|
|
90
|
-
type LinearExtension,
|
|
91
|
-
type Realizer,
|
|
92
|
-
fieldRealizer,
|
|
93
|
-
PosetComparisonResult,
|
|
94
|
-
comparePosetElements,
|
|
95
|
-
posetLte,
|
|
96
|
-
} from "./discrepancies.js";
|
package/src/packageVersion.ts
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
defaultSchemaPolicy,
|
|
20
20
|
mapTreeFromCursor,
|
|
21
21
|
} from "../feature-libraries/index.js";
|
|
22
|
-
import type
|
|
22
|
+
import { toStoredSchema, type SchemaCompatibilityTester } from "../simple-tree/index.js";
|
|
23
23
|
import { isReadonlyArray } from "../util/index.js";
|
|
24
24
|
|
|
25
25
|
import type { ITreeCheckout } from "./treeCheckout.js";
|
|
@@ -75,7 +75,7 @@ export function initializeContent(
|
|
|
75
75
|
|
|
76
76
|
assert(
|
|
77
77
|
allowsRepoSuperset(defaultSchemaPolicy, newSchema, incrementalSchemaUpdate),
|
|
78
|
-
0x5c9 /* Incremental Schema during update should
|
|
78
|
+
0x5c9 /* Incremental Schema during update should allow a superset of the final schema */,
|
|
79
79
|
);
|
|
80
80
|
// Update to intermediate schema
|
|
81
81
|
schemaRepository.updateSchema(incrementalSchemaUpdate);
|
|
@@ -219,7 +219,7 @@ export function ensureSchema(
|
|
|
219
219
|
return false;
|
|
220
220
|
}
|
|
221
221
|
case UpdateType.SchemaCompatible: {
|
|
222
|
-
checkout.updateSchema(viewSchema.
|
|
222
|
+
checkout.updateSchema(toStoredSchema(viewSchema.viewSchemaRoot));
|
|
223
223
|
return true;
|
|
224
224
|
}
|
|
225
225
|
default: {
|
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
createUnknownOptionalFieldPolicy,
|
|
53
53
|
prepareForInsertionContextless,
|
|
54
54
|
type FieldSchema,
|
|
55
|
+
toStoredSchema,
|
|
55
56
|
tryDisposeTreeNode,
|
|
56
57
|
} from "../simple-tree/index.js";
|
|
57
58
|
import {
|
|
@@ -137,11 +138,7 @@ export class SchematizingSimpleTreeView<
|
|
|
137
138
|
allowUnknownOptionalFields: createUnknownOptionalFieldPolicy(this.rootFieldSchema),
|
|
138
139
|
};
|
|
139
140
|
|
|
140
|
-
this.viewSchema = new SchemaCompatibilityTester(
|
|
141
|
-
this.schemaPolicy,
|
|
142
|
-
{},
|
|
143
|
-
this.rootFieldSchema,
|
|
144
|
-
);
|
|
141
|
+
this.viewSchema = new SchemaCompatibilityTester(this.schemaPolicy, this.rootFieldSchema);
|
|
145
142
|
// This must be initialized before `update` can be called.
|
|
146
143
|
this.currentCompatibility = {
|
|
147
144
|
canView: false,
|
|
@@ -178,7 +175,7 @@ export class SchematizingSimpleTreeView<
|
|
|
178
175
|
}
|
|
179
176
|
|
|
180
177
|
this.runSchemaEdit(() => {
|
|
181
|
-
const schema = this.viewSchema.
|
|
178
|
+
const schema = toStoredSchema(this.viewSchema.viewSchemaRoot);
|
|
182
179
|
const mapTree = prepareForInsertionContextless(
|
|
183
180
|
content as InsertableContent | undefined,
|
|
184
181
|
this.rootFieldSchema,
|
package/src/shared-tree/tree.ts
CHANGED
|
@@ -450,7 +450,7 @@ export function runTransaction<
|
|
|
450
450
|
"Transactions cannot be run on Unhydrated nodes. Transactions apply to a TreeView and Unhydrated nodes are not part of a TreeView.",
|
|
451
451
|
);
|
|
452
452
|
}
|
|
453
|
-
assert(context instanceof Context,
|
|
453
|
+
assert(context instanceof Context, 0xbe3 /* Expected context to be a Context instance. */);
|
|
454
454
|
return runTransactionInCheckout(context.checkout, () => t(node), preconditions);
|
|
455
455
|
}
|
|
456
456
|
}
|
|
@@ -788,7 +788,7 @@ export class TreeCheckout implements ITreeCheckoutFork {
|
|
|
788
788
|
if (allowNonSupersetSchema !== true) {
|
|
789
789
|
assert(
|
|
790
790
|
allowsRepoSuperset(defaultSchemaPolicy, this.storedSchema.clone(), newSchema),
|
|
791
|
-
|
|
791
|
+
0xbe6 /* New schema must allow all documents allowed by old schema */,
|
|
792
792
|
);
|
|
793
793
|
}
|
|
794
794
|
this.editor.schema.setStoredSchema(this.storedSchema.clone(), newSchema);
|
|
@@ -3,30 +3,26 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { assert, unreachableCase } from "@fluidframework/core-utils/internal";
|
|
7
7
|
|
|
8
|
+
import type { TreeStoredSchema } from "../../core/index.js";
|
|
8
9
|
import {
|
|
9
|
-
|
|
10
|
-
type TreeNodeStoredSchema,
|
|
11
|
-
type Adapters,
|
|
12
|
-
type TreeFieldStoredSchema,
|
|
13
|
-
type TreeNodeSchemaIdentifier,
|
|
14
|
-
type TreeStoredSchema,
|
|
15
|
-
} from "../../core/index.js";
|
|
16
|
-
import {
|
|
10
|
+
allowsRepoSuperset,
|
|
17
11
|
FieldKinds,
|
|
18
12
|
type FullSchemaPolicy,
|
|
19
|
-
type FieldDiscrepancy,
|
|
20
|
-
getAllowedContentDiscrepancies,
|
|
21
13
|
isNeverTree,
|
|
22
|
-
PosetComparisonResult,
|
|
23
|
-
fieldRealizer,
|
|
24
|
-
comparePosetElements,
|
|
25
14
|
} from "../../feature-libraries/index.js";
|
|
26
15
|
import type { FieldSchema } from "../fieldSchema.js";
|
|
27
|
-
import { toStoredSchema } from "../toStoredSchema.js";
|
|
28
16
|
|
|
29
17
|
import type { SchemaCompatibilityStatus } from "./tree.js";
|
|
18
|
+
import {
|
|
19
|
+
comparePosetElements,
|
|
20
|
+
fieldRealizer,
|
|
21
|
+
getAllowedContentDiscrepancies,
|
|
22
|
+
PosetComparisonResult,
|
|
23
|
+
type FieldDiscrepancy,
|
|
24
|
+
} from "../discrepancies.js";
|
|
25
|
+
import { toStoredSchema } from "../toStoredSchema.js";
|
|
30
26
|
|
|
31
27
|
/**
|
|
32
28
|
* A collection of View information for schema, including policy.
|
|
@@ -34,21 +30,13 @@ import type { SchemaCompatibilityStatus } from "./tree.js";
|
|
|
34
30
|
* This contains everything needed to determine compatibility with a given stored schema.
|
|
35
31
|
*/
|
|
36
32
|
export class SchemaCompatibilityTester {
|
|
37
|
-
/**
|
|
38
|
-
* Cached conversion of the view schema in the stored schema format.
|
|
39
|
-
*/
|
|
40
|
-
public readonly viewSchemaAsStored: TreeStoredSchema;
|
|
41
|
-
|
|
42
33
|
/**
|
|
43
34
|
* @param viewSchemaRoot - Schema for the root field.
|
|
44
35
|
*/
|
|
45
36
|
public constructor(
|
|
46
37
|
public readonly policy: FullSchemaPolicy,
|
|
47
|
-
public readonly
|
|
48
|
-
|
|
49
|
-
) {
|
|
50
|
-
this.viewSchemaAsStored = toStoredSchema(viewSchemaRoot);
|
|
51
|
-
}
|
|
38
|
+
public readonly viewSchemaRoot: FieldSchema,
|
|
39
|
+
) {}
|
|
52
40
|
|
|
53
41
|
/**
|
|
54
42
|
* Determines the compatibility of a stored document
|
|
@@ -63,9 +51,6 @@ export class SchemaCompatibilityTester {
|
|
|
63
51
|
public checkCompatibility(
|
|
64
52
|
stored: TreeStoredSchema,
|
|
65
53
|
): Omit<SchemaCompatibilityStatus, "canInitialize"> {
|
|
66
|
-
// TODO: support adapters
|
|
67
|
-
// const adapted = this.adaptRepo(stored);
|
|
68
|
-
|
|
69
54
|
// View schema allows a subset of documents that stored schema does, and the discrepancies are allowed by policy
|
|
70
55
|
// determined by the view schema (i.e. objects with extra optional fields in the stored schema have opted into allowing this.
|
|
71
56
|
// In the future, this would also include things like:
|
|
@@ -92,16 +77,7 @@ export class SchemaCompatibilityTester {
|
|
|
92
77
|
canView = false;
|
|
93
78
|
}
|
|
94
79
|
|
|
95
|
-
if (
|
|
96
|
-
discrepancy.view.some(
|
|
97
|
-
(identifier) =>
|
|
98
|
-
!isNeverTree(
|
|
99
|
-
this.policy,
|
|
100
|
-
this.viewSchemaAsStored,
|
|
101
|
-
this.viewSchemaAsStored.nodeSchema.get(identifier),
|
|
102
|
-
),
|
|
103
|
-
)
|
|
104
|
-
) {
|
|
80
|
+
if (discrepancy.view.length > 0) {
|
|
105
81
|
// View schema has extra allowed types that the stored schema does not.
|
|
106
82
|
canView = false;
|
|
107
83
|
}
|
|
@@ -151,32 +127,24 @@ export class SchemaCompatibilityTester {
|
|
|
151
127
|
}
|
|
152
128
|
};
|
|
153
129
|
|
|
154
|
-
for (const discrepancy of getAllowedContentDiscrepancies(
|
|
155
|
-
this.viewSchemaAsStored,
|
|
156
|
-
stored,
|
|
157
|
-
)) {
|
|
130
|
+
for (const discrepancy of getAllowedContentDiscrepancies(this.viewSchemaRoot, stored)) {
|
|
158
131
|
if (!canView && !canUpgrade) {
|
|
159
132
|
break;
|
|
160
133
|
}
|
|
161
134
|
|
|
162
135
|
switch (discrepancy.mismatch) {
|
|
163
136
|
case "nodeKind": {
|
|
164
|
-
const viewNodeSchema = this.viewSchemaAsStored.nodeSchema.get(
|
|
165
|
-
discrepancy.identifier,
|
|
166
|
-
);
|
|
167
137
|
const storedNodeSchema = stored.nodeSchema.get(discrepancy.identifier);
|
|
168
138
|
// We conservatively do not allow node types to change.
|
|
169
139
|
// The only time this might be valid in the sense that the data canonically converts is converting an object node
|
|
170
140
|
// to a map node over the union of all the object fields' types.
|
|
171
141
|
if (discrepancy.stored === undefined) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
canView = false;
|
|
179
|
-
}
|
|
142
|
+
// View schema has added a node type that the stored schema doesn't know about.
|
|
143
|
+
// Note that all cases which trigger this should also trigger an AllowedTypeDiscrepancy (where the type is used).
|
|
144
|
+
// This means this case should be redundant and could be removed in the future if there is a reason to do so
|
|
145
|
+
// (like simplifying enablable type support).
|
|
146
|
+
// See the TODO in getAllowedContentDiscrepancies.
|
|
147
|
+
canView = false;
|
|
180
148
|
} else if (discrepancy.view === undefined) {
|
|
181
149
|
const storedIsNever =
|
|
182
150
|
storedNodeSchema !== undefined
|
|
@@ -184,22 +152,18 @@ export class SchemaCompatibilityTester {
|
|
|
184
152
|
: true;
|
|
185
153
|
if (!storedIsNever) {
|
|
186
154
|
// Stored schema has a node type that the view schema doesn't know about.
|
|
155
|
+
// The design of allowUnknownOptionalFields allows adding new optional content to types,
|
|
156
|
+
// and the new optional content can use new types.
|
|
157
|
+
// Therefore this case needs to be supported for viewing.
|
|
158
|
+
// However, it is not supported for upgrade as the stored document must be newer (or at least more general) than the view in this case.
|
|
159
|
+
// The fact that there might be removed trees with a root of this type which only appears in the stored schema is why this must set canUpgrade to false.
|
|
187
160
|
canUpgrade = false;
|
|
188
161
|
}
|
|
189
162
|
} else {
|
|
190
|
-
// Node type exists in both schemas but has changed. We conservatively never allow this.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
: true;
|
|
195
|
-
const viewIsNever =
|
|
196
|
-
viewNodeSchema !== undefined
|
|
197
|
-
? isNeverTree(this.policy, this.viewSchemaAsStored, viewNodeSchema)
|
|
198
|
-
: true;
|
|
199
|
-
if (!storedIsNever || !viewIsNever) {
|
|
200
|
-
canView = false;
|
|
201
|
-
canUpgrade = false;
|
|
202
|
-
}
|
|
163
|
+
// Node type exists in both schemas but kind has changed. We conservatively never allow this.
|
|
164
|
+
// See note above about cases where this could be allowed if needed.
|
|
165
|
+
canView = false;
|
|
166
|
+
canUpgrade = false;
|
|
203
167
|
}
|
|
204
168
|
break;
|
|
205
169
|
}
|
|
@@ -217,71 +181,17 @@ export class SchemaCompatibilityTester {
|
|
|
217
181
|
}
|
|
218
182
|
}
|
|
219
183
|
|
|
184
|
+
if (canUpgrade) {
|
|
185
|
+
assert(
|
|
186
|
+
allowsRepoSuperset(this.policy, stored, toStoredSchema(this.viewSchemaRoot)),
|
|
187
|
+
0xbf2 /* View schema must be a superset of the stored schema to allow upgrade */,
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
220
191
|
return {
|
|
221
192
|
canView,
|
|
222
193
|
canUpgrade,
|
|
223
194
|
isEquivalent: canView && canUpgrade,
|
|
224
195
|
};
|
|
225
196
|
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Compute a schema that `original` could be viewed as using adapters as needed.
|
|
229
|
-
*
|
|
230
|
-
* TODO: have a way for callers to get invalidated on schema updates.
|
|
231
|
-
*/
|
|
232
|
-
public adaptRepo(stored: TreeStoredSchema): AdaptedViewSchema {
|
|
233
|
-
// Sanity check on adapters:
|
|
234
|
-
// it's probably a bug if they use the never types,
|
|
235
|
-
// since there never is a reason to have a never type as an adapter input,
|
|
236
|
-
// and its impossible for an adapter to be correctly implemented if its output type is never
|
|
237
|
-
// (unless its input is also never).
|
|
238
|
-
|
|
239
|
-
for (const adapter of this.adapters?.tree ?? []) {
|
|
240
|
-
if (
|
|
241
|
-
isNeverTree(
|
|
242
|
-
this.policy,
|
|
243
|
-
this.viewSchemaAsStored,
|
|
244
|
-
this.viewSchemaAsStored.nodeSchema.get(adapter.output),
|
|
245
|
-
)
|
|
246
|
-
) {
|
|
247
|
-
fail(0xb3d /* tree adapter for stored adapter.output should not be never */);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const adapted = {
|
|
252
|
-
rootFieldSchema: this.adaptField(stored.rootFieldSchema),
|
|
253
|
-
nodeSchema: new Map<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>(),
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
for (const [key, schema] of stored.nodeSchema) {
|
|
257
|
-
const adapatedTree = this.adaptTree(schema);
|
|
258
|
-
adapted.nodeSchema.set(key, adapatedTree);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// TODO: subset these adapters to the ones that were needed/used.
|
|
262
|
-
return new AdaptedViewSchema(this.adapters, adapted);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Adapt original such that it allows member types which can be adapted to its specified types.
|
|
267
|
-
*/
|
|
268
|
-
private adaptField(original: TreeFieldStoredSchema): TreeFieldStoredSchema {
|
|
269
|
-
if (original.types !== undefined) {
|
|
270
|
-
const types: Set<TreeNodeSchemaIdentifier> = new Set(original.types);
|
|
271
|
-
for (const treeAdapter of this.adapters?.tree ?? []) {
|
|
272
|
-
if (types.has(treeAdapter.input)) {
|
|
273
|
-
types.delete(treeAdapter.input);
|
|
274
|
-
types.add(treeAdapter.output);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return { kind: original.kind, types, persistedMetadata: undefined };
|
|
279
|
-
}
|
|
280
|
-
return original;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
private adaptTree(original: TreeNodeStoredSchema): TreeNodeStoredSchema {
|
|
284
|
-
// TODO: support adapters like missing field adapters.
|
|
285
|
-
return original;
|
|
286
|
-
}
|
|
287
197
|
}
|
|
@@ -197,10 +197,13 @@ export function enumEntries(
|
|
|
197
197
|
}
|
|
198
198
|
// At this point, it is expected that all remaining cases are reverse mappings,
|
|
199
199
|
// but do some asserts to ensure that the above logic is sufficient.
|
|
200
|
-
assert(
|
|
200
|
+
assert(
|
|
201
|
+
typeof value === "string",
|
|
202
|
+
0xbe4 /* expected reverse mapping and thus a string value */,
|
|
203
|
+
);
|
|
201
204
|
assert(
|
|
202
205
|
Number.parseFloat(key).toString() === key,
|
|
203
|
-
|
|
206
|
+
0xbe5 /* expected reverse mapping and thus a key that is a normalized number */,
|
|
204
207
|
);
|
|
205
208
|
// Discard the reverse mapping.
|
|
206
209
|
return false;
|
|
@@ -103,7 +103,6 @@ export function comparePersistedSchema(
|
|
|
103
103
|
const stored = schemaCodec.decode(persisted as FormatV1);
|
|
104
104
|
const viewSchema = new SchemaCompatibilityTester(
|
|
105
105
|
defaultSchemaPolicy,
|
|
106
|
-
{},
|
|
107
106
|
normalizeFieldSchema(view),
|
|
108
107
|
);
|
|
109
108
|
return viewSchema.checkCompatibility(stored);
|