@fluidframework/tree 2.31.1 → 2.32.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/.vscode/settings.json +1 -1
- package/CHANGELOG.md +44 -0
- package/api-extractor/api-extractor.current.json +5 -1
- package/api-report/tree.alpha.api.md +44 -20
- package/dist/alpha.d.ts +6 -2
- package/dist/feature-libraries/flex-tree/context.d.ts +1 -1
- package/dist/feature-libraries/flex-tree/context.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/context.js +1 -2
- package/dist/feature-libraries/flex-tree/context.js.map +1 -1
- package/dist/feature-libraries/flex-tree/index.d.ts +1 -1
- package/dist/feature-libraries/flex-tree/index.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/index.js +1 -2
- package/dist/feature-libraries/flex-tree/index.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyEntity.d.ts +6 -15
- package/dist/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyEntity.js +9 -18
- package/dist/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.d.ts +3 -3
- package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.js +14 -14
- package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts +4 -4
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.js +12 -12
- package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- 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 +1 -2
- package/dist/feature-libraries/index.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/shared-tree/sharedTree.js +2 -2
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/treeApiAlpha.d.ts +6 -6
- package/dist/shared-tree/treeApiAlpha.d.ts.map +1 -1
- package/dist/shared-tree/treeApiAlpha.js.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.d.ts +0 -6
- package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js +0 -17
- package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/dist/simple-tree/api/conciseTree.d.ts +2 -2
- package/dist/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/conciseTree.js.map +1 -1
- package/dist/simple-tree/api/customTree.d.ts +14 -12
- package/dist/simple-tree/api/customTree.d.ts.map +1 -1
- package/dist/simple-tree/api/customTree.js.map +1 -1
- package/dist/simple-tree/api/getJsonSchema.d.ts +21 -7
- package/dist/simple-tree/api/getJsonSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/getJsonSchema.js +8 -16
- package/dist/simple-tree/api/getJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/getSimpleSchema.d.ts +3 -10
- package/dist/simple-tree/api/getSimpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/getSimpleSchema.js +4 -16
- package/dist/simple-tree/api/getSimpleSchema.js.map +1 -1
- package/dist/simple-tree/api/index.d.ts +4 -3
- package/dist/simple-tree/api/index.d.ts.map +1 -1
- package/dist/simple-tree/api/index.js +2 -1
- package/dist/simple-tree/api/index.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +17 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.js +4 -0
- package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/dist/simple-tree/api/schemaFromSimple.d.ts +5 -2
- package/dist/simple-tree/api/schemaFromSimple.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFromSimple.js +24 -8
- package/dist/simple-tree/api/schemaFromSimple.js.map +1 -1
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.d.ts +11 -3
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +40 -28
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/tree.d.ts +32 -5
- package/dist/simple-tree/api/tree.d.ts.map +1 -1
- package/dist/simple-tree/api/tree.js +17 -1
- package/dist/simple-tree/api/tree.js.map +1 -1
- package/dist/simple-tree/api/verboseTree.d.ts +4 -28
- package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/verboseTree.js.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js +7 -3
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.js +7 -6
- package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
- package/dist/simple-tree/core/unhydratedFlexTree.js +12 -1
- package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/dist/simple-tree/index.d.ts +1 -1
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js +3 -2
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/simpleSchema.d.ts +4 -11
- package/dist/simple-tree/simpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/simpleSchema.js.map +1 -1
- package/dist/tableSchema.d.ts +227 -0
- package/dist/tableSchema.d.ts.map +1 -0
- package/dist/tableSchema.js +234 -0
- package/dist/tableSchema.js.map +1 -0
- package/dist/treeFactory.d.ts +4 -4
- package/dist/treeFactory.d.ts.map +1 -1
- package/dist/treeFactory.js.map +1 -1
- package/dist/util/breakable.d.ts.map +1 -1
- package/dist/util/breakable.js +9 -7
- package/dist/util/breakable.js.map +1 -1
- package/lib/alpha.d.ts +6 -2
- package/lib/feature-libraries/flex-tree/context.d.ts +1 -1
- package/lib/feature-libraries/flex-tree/context.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/context.js +1 -2
- package/lib/feature-libraries/flex-tree/context.js.map +1 -1
- package/lib/feature-libraries/flex-tree/index.d.ts +1 -1
- package/lib/feature-libraries/flex-tree/index.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/index.js +1 -1
- package/lib/feature-libraries/flex-tree/index.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyEntity.d.ts +6 -15
- package/lib/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyEntity.js +8 -17
- package/lib/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.d.ts +3 -3
- package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.js +15 -15
- package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts +4 -4
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.js +13 -13
- package/lib/feature-libraries/flex-tree/lazyNode.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/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/shared-tree/sharedTree.js +2 -2
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/treeApiAlpha.d.ts +6 -6
- package/lib/shared-tree/treeApiAlpha.d.ts.map +1 -1
- package/lib/shared-tree/treeApiAlpha.js.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.d.ts +0 -6
- package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js +0 -17
- package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/lib/simple-tree/api/conciseTree.d.ts +2 -2
- package/lib/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/conciseTree.js.map +1 -1
- package/lib/simple-tree/api/customTree.d.ts +14 -12
- package/lib/simple-tree/api/customTree.d.ts.map +1 -1
- package/lib/simple-tree/api/customTree.js.map +1 -1
- package/lib/simple-tree/api/getJsonSchema.d.ts +21 -7
- package/lib/simple-tree/api/getJsonSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/getJsonSchema.js +8 -16
- package/lib/simple-tree/api/getJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/getSimpleSchema.d.ts +3 -10
- package/lib/simple-tree/api/getSimpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/getSimpleSchema.js +4 -16
- package/lib/simple-tree/api/getSimpleSchema.js.map +1 -1
- package/lib/simple-tree/api/index.d.ts +4 -3
- package/lib/simple-tree/api/index.d.ts.map +1 -1
- package/lib/simple-tree/api/index.js +1 -1
- package/lib/simple-tree/api/index.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +17 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.js +4 -0
- package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/lib/simple-tree/api/schemaFromSimple.d.ts +5 -2
- package/lib/simple-tree/api/schemaFromSimple.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFromSimple.js +24 -8
- package/lib/simple-tree/api/schemaFromSimple.js.map +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.d.ts +11 -3
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +41 -29
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/tree.d.ts +32 -5
- package/lib/simple-tree/api/tree.d.ts.map +1 -1
- package/lib/simple-tree/api/tree.js +16 -1
- package/lib/simple-tree/api/tree.js.map +1 -1
- package/lib/simple-tree/api/verboseTree.d.ts +4 -28
- package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/verboseTree.js.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js +7 -3
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.js +8 -7
- package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
- package/lib/simple-tree/core/unhydratedFlexTree.js +12 -1
- package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/lib/simple-tree/index.d.ts +1 -1
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js +1 -1
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/simpleSchema.d.ts +4 -11
- package/lib/simple-tree/simpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/simpleSchema.js.map +1 -1
- package/lib/tableSchema.d.ts +227 -0
- package/lib/tableSchema.d.ts.map +1 -0
- package/lib/tableSchema.js +231 -0
- package/lib/tableSchema.js.map +1 -0
- package/lib/treeFactory.d.ts +4 -4
- package/lib/treeFactory.d.ts.map +1 -1
- package/lib/treeFactory.js.map +1 -1
- package/lib/util/breakable.d.ts.map +1 -1
- package/lib/util/breakable.js +9 -7
- package/lib/util/breakable.js.map +1 -1
- package/package.json +23 -22
- package/src/feature-libraries/flex-tree/context.ts +2 -2
- package/src/feature-libraries/flex-tree/index.ts +0 -1
- package/src/feature-libraries/flex-tree/lazyEntity.ts +11 -21
- package/src/feature-libraries/flex-tree/lazyField.ts +17 -26
- package/src/feature-libraries/flex-tree/lazyNode.ts +13 -19
- package/src/feature-libraries/index.ts +0 -1
- package/src/index.ts +6 -2
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/sharedTree.ts +2 -2
- package/src/shared-tree/treeApiAlpha.ts +17 -15
- package/src/shared-tree-core/sharedTreeCore.ts +0 -23
- package/src/simple-tree/api/conciseTree.ts +4 -4
- package/src/simple-tree/api/customTree.ts +16 -14
- package/src/simple-tree/api/getJsonSchema.ts +25 -16
- package/src/simple-tree/api/getSimpleSchema.ts +4 -18
- package/src/simple-tree/api/index.ts +4 -2
- package/src/simple-tree/api/schemaFactoryAlpha.ts +18 -1
- package/src/simple-tree/api/schemaFromSimple.ts +45 -16
- package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +53 -34
- package/src/simple-tree/api/tree.ts +51 -4
- package/src/simple-tree/api/verboseTree.ts +7 -32
- package/src/simple-tree/api/viewSchemaToSimpleSchema.ts +8 -3
- package/src/simple-tree/core/treeNodeKernel.ts +11 -7
- package/src/simple-tree/core/unhydratedFlexTree.ts +17 -4
- package/src/simple-tree/index.ts +4 -2
- package/src/simple-tree/simpleSchema.ts +4 -12
- package/src/tableSchema.ts +609 -0
- package/src/treeFactory.ts +4 -3
- package/src/util/breakable.ts +9 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaFromSimple.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFromSimple.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"schemaFromSimple.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFromSimple.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,OAAO,KAAK,EAGX,gBAAgB,EAChB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAI5C;;;;;;;;;;;;;GAaG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU,CAmBnF"}
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
import { unreachableCase, fail } from "@fluidframework/core-utils/internal";
|
|
6
6
|
import { NodeKind } from "../core/index.js";
|
|
7
7
|
import { FieldKind, } from "../schemaTypes.js";
|
|
8
|
-
import { SchemaFactory } from "./schemaFactory.js";
|
|
9
8
|
import { SchemaFactoryAlpha } from "./schemaFactoryAlpha.js";
|
|
10
9
|
const factory = new SchemaFactoryAlpha(undefined);
|
|
11
10
|
/**
|
|
@@ -17,6 +16,9 @@ const factory = new SchemaFactoryAlpha(undefined);
|
|
|
17
16
|
* will produce a poor TypeScript typing experience which is subject to change.
|
|
18
17
|
*
|
|
19
18
|
* Editing through a view produced using this schema can easily violate invariants other users of the document might expect and must be done with great care.
|
|
19
|
+
*
|
|
20
|
+
* This API bakes in some arbitrary policy choices for how to handle data that is not included in the SimpleTreeSchema API, for example the value of `allowUnknownOptionalFields`.
|
|
21
|
+
* If any particular choice is required for such cases, this API should not be used.
|
|
20
22
|
* @alpha
|
|
21
23
|
*/
|
|
22
24
|
export function generateSchemaFromSimpleSchema(simple) {
|
|
@@ -25,18 +27,30 @@ export function generateSchemaFromSimpleSchema(simple) {
|
|
|
25
27
|
// This relies on the caching in evaluateLazySchema so that it only runs once.
|
|
26
28
|
() => generateNode(id, schema, context),
|
|
27
29
|
]));
|
|
28
|
-
|
|
30
|
+
const root = generateFieldSchema(simple.root, context, undefined);
|
|
31
|
+
const definitions = new Map();
|
|
32
|
+
for (const [id, lazy] of context) {
|
|
33
|
+
definitions.set(id, lazy());
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
root,
|
|
37
|
+
definitions,
|
|
38
|
+
};
|
|
29
39
|
}
|
|
30
|
-
function generateFieldSchema(simple, context) {
|
|
40
|
+
function generateFieldSchema(simple, context, storedKey) {
|
|
31
41
|
const allowed = generateAllowedTypes(simple.allowedTypesIdentifiers, context);
|
|
42
|
+
const props = {
|
|
43
|
+
metadata: simple.metadata,
|
|
44
|
+
key: storedKey,
|
|
45
|
+
};
|
|
32
46
|
// Using createFieldSchema could work, but would require setting up the default providers.
|
|
33
47
|
switch (simple.kind) {
|
|
34
48
|
case FieldKind.Identifier:
|
|
35
|
-
return SchemaFactoryAlpha.identifier(
|
|
49
|
+
return SchemaFactoryAlpha.identifier(props);
|
|
36
50
|
case FieldKind.Optional:
|
|
37
|
-
return SchemaFactoryAlpha.optional(allowed,
|
|
51
|
+
return SchemaFactoryAlpha.optional(allowed, props);
|
|
38
52
|
case FieldKind.Required:
|
|
39
|
-
return SchemaFactoryAlpha.required(allowed,
|
|
53
|
+
return SchemaFactoryAlpha.required(allowed, props);
|
|
40
54
|
default:
|
|
41
55
|
return unreachableCase(simple.kind);
|
|
42
56
|
}
|
|
@@ -49,8 +63,10 @@ function generateNode(id, schema, context) {
|
|
|
49
63
|
case NodeKind.Object: {
|
|
50
64
|
const fields = {};
|
|
51
65
|
for (const [key, field] of schema.fields) {
|
|
52
|
-
fields[key] = generateFieldSchema(field, context);
|
|
66
|
+
fields[key] = generateFieldSchema(field, context, field.storedKey);
|
|
53
67
|
}
|
|
68
|
+
// Here allowUnknownOptionalFields is implicitly defaulting. This is a subjective policy choice:
|
|
69
|
+
// users of this code are expected to handle what ever choice this code makes for cases like this.
|
|
54
70
|
return factory.object(id, fields, { metadata: schema.metadata });
|
|
55
71
|
}
|
|
56
72
|
case NodeKind.Array:
|
|
@@ -58,7 +74,7 @@ function generateNode(id, schema, context) {
|
|
|
58
74
|
case NodeKind.Map:
|
|
59
75
|
return factory.mapAlpha(id, generateAllowedTypes(schema.allowedTypesIdentifiers, context), { metadata: schema.metadata });
|
|
60
76
|
case NodeKind.Leaf:
|
|
61
|
-
return (
|
|
77
|
+
return (SchemaFactoryAlpha.leaves.find((leaf) => leaf.identifier === id) ??
|
|
62
78
|
fail(0xb5b /* Missing schema */));
|
|
63
79
|
default:
|
|
64
80
|
return unreachableCase(schema);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaFromSimple.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFromSimple.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAuB,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAIN,SAAS,
|
|
1
|
+
{"version":3,"file":"schemaFromSimple.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFromSimple.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAuB,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAIN,SAAS,GAET,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,SAAS,CAAC,CAAC;AAElD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,8BAA8B,CAAC,MAAwB;IACtE,MAAM,OAAO,GAAY,IAAI,GAAG,CAC/B,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,CAC1B,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,EAAqD,EAAE,CAAC;QACpE,EAAE;QACF,8EAA8E;QAC9E,GAAG,EA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B,CAAC,CAChC,CAAC;QACH;YACC,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { unreachableCase, fail } from \"@fluidframework/core-utils/internal\";\nimport { NodeKind, type TreeNodeSchema } from \"../core/index.js\";\nimport {\n\ttype FieldSchema,\n\ttype AllowedTypes,\n\ttype FieldSchemaAlpha,\n\tFieldKind,\n\ttype FieldProps,\n} from \"../schemaTypes.js\";\nimport type {\n\tSimpleFieldSchema,\n\tSimpleNodeSchema,\n\tSimpleTreeSchema,\n} from \"../simpleSchema.js\";\nimport { SchemaFactoryAlpha } from \"./schemaFactoryAlpha.js\";\nimport type { TreeSchema } from \"./tree.js\";\n\nconst factory = new SchemaFactoryAlpha(undefined);\n\n/**\n * Create {@link FieldSchema} from a SimpleTreeSchema.\n * @remarks\n * Only use this API if hand written schema (produced using {@link SchemaFactory} cannot be provided.\n *\n * Using generated schema with schema aware APIs (designed to work with strongly typed schema) like {@link TreeViewConfiguration}\n * will produce a poor TypeScript typing experience which is subject to change.\n *\n * Editing through a view produced using this schema can easily violate invariants other users of the document might expect and must be done with great care.\n *\n * This API bakes in some arbitrary policy choices for how to handle data that is not included in the SimpleTreeSchema API, for example the value of `allowUnknownOptionalFields`.\n * If any particular choice is required for such cases, this API should not be used.\n * @alpha\n */\nexport function generateSchemaFromSimpleSchema(simple: SimpleTreeSchema): TreeSchema {\n\tconst context: Context = new Map(\n\t\t[...simple.definitions].map(\n\t\t\t([id, schema]): [string, () => TreeNodeSchema & SimpleNodeSchema] => [\n\t\t\t\tid,\n\t\t\t\t// This relies on the caching in evaluateLazySchema so that it only runs once.\n\t\t\t\t() => generateNode(id, schema, context),\n\t\t\t],\n\t\t),\n\t);\n\tconst root = generateFieldSchema(simple.root, context, undefined);\n\tconst definitions = new Map<string, TreeNodeSchema & SimpleNodeSchema>();\n\tfor (const [id, lazy] of context) {\n\t\tdefinitions.set(id, lazy());\n\t}\n\treturn {\n\t\troot,\n\t\tdefinitions,\n\t};\n}\n\ntype Context = ReadonlyMap<string, () => TreeNodeSchema & SimpleNodeSchema>;\n\nfunction generateFieldSchema(\n\tsimple: SimpleFieldSchema,\n\tcontext: Context,\n\tstoredKey: string | undefined,\n): FieldSchemaAlpha {\n\tconst allowed = generateAllowedTypes(simple.allowedTypesIdentifiers, context);\n\tconst props: Omit<FieldProps, \"defaultProvider\"> = {\n\t\tmetadata: simple.metadata,\n\t\tkey: storedKey,\n\t};\n\n\t// Using createFieldSchema could work, but would require setting up the default providers.\n\tswitch (simple.kind) {\n\t\tcase FieldKind.Identifier:\n\t\t\treturn SchemaFactoryAlpha.identifier(props);\n\t\tcase FieldKind.Optional:\n\t\t\treturn SchemaFactoryAlpha.optional(allowed, props);\n\t\tcase FieldKind.Required:\n\t\t\treturn SchemaFactoryAlpha.required(allowed, props);\n\t\tdefault:\n\t\t\treturn unreachableCase(simple.kind);\n\t}\n}\n\nfunction generateAllowedTypes(allowed: ReadonlySet<string>, context: Context): AllowedTypes {\n\treturn [...allowed].map((id) => context.get(id) ?? fail(0xb5a /* Missing schema */));\n}\n\nfunction generateNode(\n\tid: string,\n\tschema: SimpleNodeSchema,\n\tcontext: Context,\n): TreeNodeSchema & SimpleNodeSchema {\n\tswitch (schema.kind) {\n\t\tcase NodeKind.Object: {\n\t\t\tconst fields: Record<string, FieldSchema> = {};\n\t\t\tfor (const [key, field] of schema.fields) {\n\t\t\t\tfields[key] = generateFieldSchema(field, context, field.storedKey);\n\t\t\t}\n\t\t\t// Here allowUnknownOptionalFields is implicitly defaulting. This is a subjective policy choice:\n\t\t\t// users of this code are expected to handle what ever choice this code makes for cases like this.\n\t\t\treturn factory.object(id, fields, { metadata: schema.metadata });\n\t\t}\n\t\tcase NodeKind.Array:\n\t\t\treturn factory.arrayAlpha(\n\t\t\t\tid,\n\t\t\t\tgenerateAllowedTypes(schema.allowedTypesIdentifiers, context),\n\t\t\t\t{ metadata: schema.metadata },\n\t\t\t);\n\t\tcase NodeKind.Map:\n\t\t\treturn factory.mapAlpha(\n\t\t\t\tid,\n\t\t\t\tgenerateAllowedTypes(schema.allowedTypesIdentifiers, context),\n\t\t\t\t{ metadata: schema.metadata },\n\t\t\t);\n\t\tcase NodeKind.Leaf:\n\t\t\treturn (\n\t\t\t\tSchemaFactoryAlpha.leaves.find((leaf) => leaf.identifier === id) ??\n\t\t\t\tfail(0xb5b /* Missing schema */)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn unreachableCase(schema);\n\t}\n}\n"]}
|
|
@@ -3,11 +3,19 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import type { JsonObjectNodeSchema, JsonTreeSchema } from "./jsonSchema.js";
|
|
6
|
-
import type {
|
|
6
|
+
import type { TreeSchema } from "./tree.js";
|
|
7
|
+
import type { TreeSchemaEncodingOptions } from "./getJsonSchema.js";
|
|
8
|
+
import { ObjectNodeSchema } from "../objectNodeTypes.js";
|
|
7
9
|
/**
|
|
8
10
|
* Generates a JSON Schema representation from a simple tree schema.
|
|
11
|
+
* @remarks
|
|
12
|
+
* This expects the data to be in the {@link ConciseTree} format.
|
|
13
|
+
*
|
|
14
|
+
* This cannot handle the case where the root is undefined since undefined is not a concept in JSON.
|
|
15
|
+
* This also cannot handle {@link SchemaStatics.handle} since they also are not supported in JSON.
|
|
16
|
+
*
|
|
9
17
|
* @internal
|
|
10
18
|
*/
|
|
11
|
-
export declare function toJsonSchema(schema:
|
|
12
|
-
export declare function convertObjectNodeSchema(schema:
|
|
19
|
+
export declare function toJsonSchema(schema: TreeSchema, options: Required<TreeSchemaEncodingOptions>): JsonTreeSchema;
|
|
20
|
+
export declare function convertObjectNodeSchema(schema: ObjectNodeSchema, options: Required<TreeSchemaEncodingOptions>): JsonObjectNodeSchema;
|
|
13
21
|
//# sourceMappingURL=simpleSchemaToJsonSchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simpleSchemaToJsonSchema.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/simpleSchemaToJsonSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAQX,oBAAoB,EACpB,cAAc,EAEd,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"simpleSchemaToJsonSchema.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/simpleSchemaToJsonSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAQX,oBAAoB,EACpB,cAAc,EAEd,MAAM,iBAAiB,CAAC;AAQzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAKzD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC3B,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAC1C,cAAc,CAoBhB;AAkFD,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAC1C,oBAAoB,CAwCtB"}
|
|
@@ -5,19 +5,32 @@
|
|
|
5
5
|
import { unreachableCase } from "@fluidframework/core-utils/internal";
|
|
6
6
|
import { UsageError } from "@fluidframework/telemetry-utils/internal";
|
|
7
7
|
import { ValueSchema } from "../../core/index.js";
|
|
8
|
-
import { copyProperty,
|
|
8
|
+
import { copyProperty, hasSingle } from "../../util/index.js";
|
|
9
9
|
import { FieldKind } from "../schemaTypes.js";
|
|
10
10
|
import { NodeKind } from "../core/index.js";
|
|
11
|
+
import { ObjectNodeSchema } from "../objectNodeTypes.js";
|
|
12
|
+
import { ArrayNodeSchema } from "../arrayNodeTypes.js";
|
|
13
|
+
import { MapNodeSchema } from "../mapNodeTypes.js";
|
|
14
|
+
import { LeafNodeSchema } from "../leafNodeSchema.js";
|
|
11
15
|
/**
|
|
12
16
|
* Generates a JSON Schema representation from a simple tree schema.
|
|
17
|
+
* @remarks
|
|
18
|
+
* This expects the data to be in the {@link ConciseTree} format.
|
|
19
|
+
*
|
|
20
|
+
* This cannot handle the case where the root is undefined since undefined is not a concept in JSON.
|
|
21
|
+
* This also cannot handle {@link SchemaStatics.handle} since they also are not supported in JSON.
|
|
22
|
+
*
|
|
13
23
|
* @internal
|
|
14
24
|
*/
|
|
15
|
-
export function toJsonSchema(schema) {
|
|
16
|
-
const definitions = convertDefinitions(schema.definitions);
|
|
25
|
+
export function toJsonSchema(schema, options) {
|
|
26
|
+
const definitions = convertDefinitions(schema.definitions, options);
|
|
17
27
|
const allowedTypes = [];
|
|
18
|
-
for (const allowedType of schema.allowedTypesIdentifiers) {
|
|
28
|
+
for (const allowedType of schema.root.allowedTypesIdentifiers) {
|
|
19
29
|
allowedTypes.push(createSchemaRef(allowedType));
|
|
20
30
|
}
|
|
31
|
+
// TODO: deduplicate field handling logic from convertObjectNodeSchema: at least include metadata's description.
|
|
32
|
+
// TODO: maybe account for consider schema.kind, or just take in ImplicitAllowedTypes
|
|
33
|
+
// TODO: handle case where allowedTypes is empty.
|
|
21
34
|
return hasSingle(allowedTypes)
|
|
22
35
|
? {
|
|
23
36
|
...allowedTypes[0],
|
|
@@ -28,37 +41,32 @@ export function toJsonSchema(schema) {
|
|
|
28
41
|
anyOf: allowedTypes,
|
|
29
42
|
};
|
|
30
43
|
}
|
|
31
|
-
function convertDefinitions(definitions) {
|
|
44
|
+
function convertDefinitions(definitions, options) {
|
|
32
45
|
const result = {};
|
|
33
46
|
for (const [key, value] of definitions) {
|
|
34
|
-
result[key] = convertNodeSchema(value);
|
|
47
|
+
result[key] = convertNodeSchema(value, options);
|
|
35
48
|
}
|
|
36
49
|
return result;
|
|
37
50
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Private symbol under which the results of {@link convertNodeSchema} are cached on an input {@link SimpleNodeSchema}.
|
|
40
|
-
*/
|
|
41
|
-
const nodeJsonSchemaCache = new WeakMap();
|
|
42
51
|
/**
|
|
43
52
|
* Converts an input {@link SimpleNodeSchema} to a {@link JsonNodeSchema}.
|
|
44
53
|
*
|
|
45
54
|
* @remarks Caches the result on the input schema for future calls.
|
|
46
55
|
*/
|
|
47
|
-
function convertNodeSchema(schema) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
56
|
+
function convertNodeSchema(schema, options) {
|
|
57
|
+
if (schema instanceof ArrayNodeSchema) {
|
|
58
|
+
return convertArrayNodeSchema(schema);
|
|
59
|
+
}
|
|
60
|
+
else if (schema instanceof MapNodeSchema) {
|
|
61
|
+
return convertMapNodeSchema(schema);
|
|
62
|
+
}
|
|
63
|
+
else if (schema instanceof ObjectNodeSchema) {
|
|
64
|
+
return convertObjectNodeSchema(schema, options);
|
|
65
|
+
}
|
|
66
|
+
else if (schema instanceof LeafNodeSchema) {
|
|
67
|
+
return convertLeafNodeSchema(schema);
|
|
68
|
+
}
|
|
69
|
+
throw new TypeError(`Unknown node schema kind: ${schema.kind}`);
|
|
62
70
|
}
|
|
63
71
|
function convertArrayNodeSchema(schema) {
|
|
64
72
|
const allowedTypes = [];
|
|
@@ -101,10 +109,11 @@ function convertLeafNodeSchema(schema) {
|
|
|
101
109
|
_treeNodeSchemaKind: NodeKind.Leaf,
|
|
102
110
|
};
|
|
103
111
|
}
|
|
104
|
-
export function convertObjectNodeSchema(schema) {
|
|
112
|
+
export function convertObjectNodeSchema(schema, options) {
|
|
105
113
|
const properties = {};
|
|
106
114
|
const required = [];
|
|
107
|
-
for (const [
|
|
115
|
+
for (const [propertyKey, fieldSchema] of schema.fields) {
|
|
116
|
+
const key = options.useStoredKeys ? fieldSchema.storedKey : propertyKey;
|
|
108
117
|
const allowedTypes = [];
|
|
109
118
|
for (const allowedType of fieldSchema.allowedTypesIdentifiers) {
|
|
110
119
|
allowedTypes.push(createSchemaRef(allowedType));
|
|
@@ -116,8 +125,11 @@ export function convertObjectNodeSchema(schema) {
|
|
|
116
125
|
};
|
|
117
126
|
copyProperty(fieldSchema.metadata, "description", output);
|
|
118
127
|
properties[key] = output;
|
|
119
|
-
if (fieldSchema.kind
|
|
120
|
-
|
|
128
|
+
if (fieldSchema.kind !== FieldKind.Optional) {
|
|
129
|
+
if (options.requireFieldsWithDefaults ||
|
|
130
|
+
fieldSchema.props?.defaultProvider === undefined) {
|
|
131
|
+
required.push(key);
|
|
132
|
+
}
|
|
121
133
|
}
|
|
122
134
|
}
|
|
123
135
|
const transformedNode = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simpleSchemaToJsonSchema.js","sourceRoot":"","sources":["../../../src/simple-tree/api/simpleSchemaToJsonSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAgB,MAAM,qBAAqB,CAAC;AAazF,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAS9C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,MAAwB;IACpD,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAE3D,MAAM,YAAY,GAAoB,EAAE,CAAC;IACzC,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,uBAAuB,EAA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,CAAC,CAAC;IAEH,MAAM,MAAM,GAA+B;QAC1C,IAAI,EAAE,QAAQ;QACd,mBAAmB,EAAE,QAAQ,CAAC,GAAG;QACjC,iBAAiB,EAAE;YAClB,MAAM,EAAE,SAAS,CAAC,YAAY,CAAC;gBAC9B,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;gBACjB,CAAC,CAAC;oBACA,KAAK,EAAE,YAAY;iBACnB;SACH;KACD,CAAC;IAEF,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;IAErD,OAAO,MAAM,CAAC;AACf,CAAC;AAED,SAAS,eAAe,CAAC,QAAgB;IACxC,OAAO;QACN,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC;KAC/B,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,QAAgB;IACtC,OAAO,WAAW,QAAQ,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { ValueSchema } from \"../../core/index.js\";\nimport { copyProperty, getOrCreate, hasSingle, type Mutable } from \"../../util/index.js\";\nimport type {\n\tJsonArrayNodeSchema,\n\tJsonFieldSchema,\n\tJsonSchemaRef,\n\tJsonRefPath,\n\tJsonLeafNodeSchema,\n\tJsonMapNodeSchema,\n\tJsonNodeSchema,\n\tJsonObjectNodeSchema,\n\tJsonTreeSchema,\n\tJsonLeafSchemaType,\n} from \"./jsonSchema.js\";\nimport { FieldKind } from \"../schemaTypes.js\";\nimport type {\n\tSimpleArrayNodeSchema,\n\tSimpleLeafNodeSchema,\n\tSimpleMapNodeSchema,\n\tSimpleNodeSchema,\n\tSimpleObjectNodeSchema,\n\tSimpleTreeSchema,\n} from \"../simpleSchema.js\";\nimport { NodeKind } from \"../core/index.js\";\n\n/**\n * Generates a JSON Schema representation from a simple tree schema.\n * @internal\n */\nexport function toJsonSchema(schema: SimpleTreeSchema): JsonTreeSchema {\n\tconst definitions = convertDefinitions(schema.definitions);\n\n\tconst allowedTypes: JsonSchemaRef[] = [];\n\tfor (const allowedType of schema.allowedTypesIdentifiers) {\n\t\tallowedTypes.push(createSchemaRef(allowedType));\n\t}\n\n\treturn hasSingle(allowedTypes)\n\t\t? {\n\t\t\t\t...allowedTypes[0],\n\t\t\t\t$defs: definitions,\n\t\t\t}\n\t\t: {\n\t\t\t\t$defs: definitions,\n\t\t\t\tanyOf: allowedTypes,\n\t\t\t};\n}\n\nfunction convertDefinitions(\n\tdefinitions: ReadonlyMap<string, SimpleNodeSchema>,\n): Record<string, JsonNodeSchema> {\n\tconst result: Record<string, JsonNodeSchema> = {};\n\tfor (const [key, value] of definitions) {\n\t\tresult[key] = convertNodeSchema(value);\n\t}\n\treturn result;\n}\n\n/**\n * Private symbol under which the results of {@link convertNodeSchema} are cached on an input {@link SimpleNodeSchema}.\n */\nconst nodeJsonSchemaCache = new WeakMap<SimpleNodeSchema, JsonNodeSchema>();\n\n/**\n * Converts an input {@link SimpleNodeSchema} to a {@link JsonNodeSchema}.\n *\n * @remarks Caches the result on the input schema for future calls.\n */\nfunction convertNodeSchema(schema: SimpleNodeSchema): JsonNodeSchema {\n\treturn getOrCreate(nodeJsonSchemaCache, schema, () => {\n\t\tswitch (schema.kind) {\n\t\t\tcase NodeKind.Array:\n\t\t\t\treturn convertArrayNodeSchema(schema);\n\t\t\tcase NodeKind.Leaf:\n\t\t\t\treturn convertLeafNodeSchema(schema);\n\t\t\tcase NodeKind.Map:\n\t\t\t\treturn convertMapNodeSchema(schema);\n\t\t\tcase NodeKind.Object:\n\t\t\t\treturn convertObjectNodeSchema(schema);\n\t\t\tdefault:\n\t\t\t\tthrow new TypeError(`Unknown node schema kind: ${(schema as SimpleNodeSchema).kind}`);\n\t\t}\n\t});\n}\n\nfunction convertArrayNodeSchema(schema: SimpleArrayNodeSchema): JsonArrayNodeSchema {\n\tconst allowedTypes: JsonSchemaRef[] = [];\n\tschema.allowedTypesIdentifiers.forEach((type) => {\n\t\tallowedTypes.push(createSchemaRef(type));\n\t});\n\n\tconst items: JsonFieldSchema = hasSingle(allowedTypes)\n\t\t? allowedTypes[0]\n\t\t: { anyOf: allowedTypes };\n\n\tconst output: Mutable<JsonArrayNodeSchema> = {\n\t\ttype: \"array\",\n\t\t_treeNodeSchemaKind: NodeKind.Array,\n\t\titems,\n\t};\n\n\tcopyProperty(schema.metadata, \"description\", output);\n\n\treturn output;\n}\n\nfunction convertLeafNodeSchema(schema: SimpleLeafNodeSchema): JsonLeafNodeSchema {\n\tlet type: JsonLeafSchemaType;\n\tswitch (schema.leafKind) {\n\t\tcase ValueSchema.String:\n\t\t\ttype = \"string\";\n\t\t\tbreak;\n\t\tcase ValueSchema.Number:\n\t\t\ttype = \"number\";\n\t\t\tbreak;\n\t\tcase ValueSchema.Boolean:\n\t\t\ttype = \"boolean\";\n\t\t\tbreak;\n\t\tcase ValueSchema.Null:\n\t\t\ttype = \"null\";\n\t\t\tbreak;\n\t\tcase ValueSchema.FluidHandle:\n\t\t\tthrow new UsageError(\"Fluid handles are not supported via JSON Schema.\");\n\t\tdefault:\n\t\t\tunreachableCase(schema.leafKind);\n\t}\n\n\treturn {\n\t\ttype,\n\t\t_treeNodeSchemaKind: NodeKind.Leaf,\n\t};\n}\n\nexport function convertObjectNodeSchema(schema: SimpleObjectNodeSchema): JsonObjectNodeSchema {\n\tconst properties: Record<string, JsonFieldSchema> = {};\n\tconst required: string[] = [];\n\tfor (const [key, fieldSchema] of schema.fields) {\n\t\tconst allowedTypes: JsonSchemaRef[] = [];\n\t\tfor (const allowedType of fieldSchema.allowedTypesIdentifiers) {\n\t\t\tallowedTypes.push(createSchemaRef(allowedType));\n\t\t}\n\n\t\tconst output: Mutable<JsonFieldSchema> = hasSingle(allowedTypes)\n\t\t\t? allowedTypes[0]\n\t\t\t: {\n\t\t\t\t\tanyOf: allowedTypes,\n\t\t\t\t};\n\n\t\tcopyProperty(fieldSchema.metadata, \"description\", output);\n\t\tproperties[key] = output;\n\n\t\tif (fieldSchema.kind === FieldKind.Required) {\n\t\t\trequired.push(key);\n\t\t}\n\t}\n\n\tconst transformedNode: Mutable<JsonObjectNodeSchema> = {\n\t\ttype: \"object\",\n\t\t_treeNodeSchemaKind: NodeKind.Object,\n\t\tproperties,\n\t\trequired,\n\t\tadditionalProperties: false,\n\t};\n\n\tcopyProperty(schema.metadata, \"description\", transformedNode);\n\n\treturn transformedNode;\n}\n\nfunction convertMapNodeSchema(schema: SimpleMapNodeSchema): JsonMapNodeSchema {\n\tconst allowedTypes: JsonSchemaRef[] = [];\n\tschema.allowedTypesIdentifiers.forEach((type) => {\n\t\tallowedTypes.push(createSchemaRef(type));\n\t});\n\n\tconst output: Mutable<JsonMapNodeSchema> = {\n\t\ttype: \"object\",\n\t\t_treeNodeSchemaKind: NodeKind.Map,\n\t\tpatternProperties: {\n\t\t\t\"^.*$\": hasSingle(allowedTypes)\n\t\t\t\t? allowedTypes[0]\n\t\t\t\t: {\n\t\t\t\t\t\tanyOf: allowedTypes,\n\t\t\t\t\t},\n\t\t},\n\t};\n\n\tcopyProperty(schema.metadata, \"description\", output);\n\n\treturn output;\n}\n\nfunction createSchemaRef(schemaId: string): JsonSchemaRef {\n\treturn {\n\t\t\"$ref\": createRefPath(schemaId),\n\t};\n}\n\nfunction createRefPath(schemaId: string): JsonRefPath {\n\treturn `#/$defs/${schemaId}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"simpleSchemaToJsonSchema.js","sourceRoot":"","sources":["../../../src/simple-tree/api/simpleSchemaToJsonSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,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CAAC,QAAgB;IACxC,OAAO;QACN,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC;KAC/B,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,QAAgB;IACtC,OAAO,WAAW,QAAQ,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { ValueSchema } from \"../../core/index.js\";\nimport { copyProperty, hasSingle, type Mutable } from \"../../util/index.js\";\nimport type {\n\tJsonArrayNodeSchema,\n\tJsonFieldSchema,\n\tJsonSchemaRef,\n\tJsonRefPath,\n\tJsonLeafNodeSchema,\n\tJsonMapNodeSchema,\n\tJsonNodeSchema,\n\tJsonObjectNodeSchema,\n\tJsonTreeSchema,\n\tJsonLeafSchemaType,\n} from \"./jsonSchema.js\";\nimport { FieldKind } from \"../schemaTypes.js\";\nimport type {\n\tSimpleArrayNodeSchema,\n\tSimpleLeafNodeSchema,\n\tSimpleMapNodeSchema,\n} from \"../simpleSchema.js\";\nimport { NodeKind, type TreeNodeSchema } from \"../core/index.js\";\nimport type { TreeSchema } from \"./tree.js\";\nimport type { TreeSchemaEncodingOptions } from \"./getJsonSchema.js\";\nimport { ObjectNodeSchema } from \"../objectNodeTypes.js\";\nimport { ArrayNodeSchema } from \"../arrayNodeTypes.js\";\nimport { MapNodeSchema } from \"../mapNodeTypes.js\";\nimport { LeafNodeSchema } from \"../leafNodeSchema.js\";\n\n/**\n * Generates a JSON Schema representation from a simple tree schema.\n * @remarks\n * This expects the data to be in the {@link ConciseTree} format.\n *\n * This cannot handle the case where the root is undefined since undefined is not a concept in JSON.\n * This also cannot handle {@link SchemaStatics.handle} since they also are not supported in JSON.\n *\n * @internal\n */\nexport function toJsonSchema(\n\tschema: TreeSchema,\n\toptions: Required<TreeSchemaEncodingOptions>,\n): JsonTreeSchema {\n\tconst definitions = convertDefinitions(schema.definitions, options);\n\n\tconst allowedTypes: JsonSchemaRef[] = [];\n\tfor (const allowedType of schema.root.allowedTypesIdentifiers) {\n\t\tallowedTypes.push(createSchemaRef(allowedType));\n\t}\n\n\t// TODO: deduplicate field handling logic from convertObjectNodeSchema: at least include metadata's description.\n\t// TODO: maybe account for consider schema.kind, or just take in ImplicitAllowedTypes\n\t// TODO: handle case where allowedTypes is empty.\n\treturn hasSingle(allowedTypes)\n\t\t? {\n\t\t\t\t...allowedTypes[0],\n\t\t\t\t$defs: definitions,\n\t\t\t}\n\t\t: {\n\t\t\t\t$defs: definitions,\n\t\t\t\tanyOf: allowedTypes,\n\t\t\t};\n}\n\nfunction convertDefinitions(\n\tdefinitions: ReadonlyMap<string, TreeNodeSchema>,\n\toptions: Required<TreeSchemaEncodingOptions>,\n): Record<string, JsonNodeSchema> {\n\tconst result: Record<string, JsonNodeSchema> = {};\n\tfor (const [key, value] of definitions) {\n\t\tresult[key] = convertNodeSchema(value, options);\n\t}\n\treturn result;\n}\n\n/**\n * Converts an input {@link SimpleNodeSchema} to a {@link JsonNodeSchema}.\n *\n * @remarks Caches the result on the input schema for future calls.\n */\nfunction convertNodeSchema(\n\tschema: TreeNodeSchema,\n\toptions: Required<TreeSchemaEncodingOptions>,\n): JsonNodeSchema {\n\tif (schema instanceof ArrayNodeSchema) {\n\t\treturn convertArrayNodeSchema(schema);\n\t} else if (schema instanceof MapNodeSchema) {\n\t\treturn convertMapNodeSchema(schema);\n\t} else if (schema instanceof ObjectNodeSchema) {\n\t\treturn convertObjectNodeSchema(schema, options);\n\t} else if (schema instanceof LeafNodeSchema) {\n\t\treturn convertLeafNodeSchema(schema);\n\t}\n\tthrow new TypeError(`Unknown node schema kind: ${schema.kind}`);\n}\n\nfunction convertArrayNodeSchema(schema: SimpleArrayNodeSchema): JsonArrayNodeSchema {\n\tconst allowedTypes: JsonSchemaRef[] = [];\n\tschema.allowedTypesIdentifiers.forEach((type) => {\n\t\tallowedTypes.push(createSchemaRef(type));\n\t});\n\n\tconst items: JsonFieldSchema = hasSingle(allowedTypes)\n\t\t? allowedTypes[0]\n\t\t: { anyOf: allowedTypes };\n\n\tconst output: Mutable<JsonArrayNodeSchema> = {\n\t\ttype: \"array\",\n\t\t_treeNodeSchemaKind: NodeKind.Array,\n\t\titems,\n\t};\n\n\tcopyProperty(schema.metadata, \"description\", output);\n\n\treturn output;\n}\n\nfunction convertLeafNodeSchema(schema: SimpleLeafNodeSchema): JsonLeafNodeSchema {\n\tlet type: JsonLeafSchemaType;\n\tswitch (schema.leafKind) {\n\t\tcase ValueSchema.String:\n\t\t\ttype = \"string\";\n\t\t\tbreak;\n\t\tcase ValueSchema.Number:\n\t\t\ttype = \"number\";\n\t\t\tbreak;\n\t\tcase ValueSchema.Boolean:\n\t\t\ttype = \"boolean\";\n\t\t\tbreak;\n\t\tcase ValueSchema.Null:\n\t\t\ttype = \"null\";\n\t\t\tbreak;\n\t\tcase ValueSchema.FluidHandle:\n\t\t\tthrow new UsageError(\"Fluid handles are not supported via JSON Schema.\");\n\t\tdefault:\n\t\t\tunreachableCase(schema.leafKind);\n\t}\n\n\treturn {\n\t\ttype,\n\t\t_treeNodeSchemaKind: NodeKind.Leaf,\n\t};\n}\n\nexport function convertObjectNodeSchema(\n\tschema: ObjectNodeSchema,\n\toptions: Required<TreeSchemaEncodingOptions>,\n): JsonObjectNodeSchema {\n\tconst properties: Record<string, JsonFieldSchema> = {};\n\tconst required: string[] = [];\n\tfor (const [propertyKey, fieldSchema] of schema.fields) {\n\t\tconst key = options.useStoredKeys ? fieldSchema.storedKey : propertyKey;\n\t\tconst allowedTypes: JsonSchemaRef[] = [];\n\t\tfor (const allowedType of fieldSchema.allowedTypesIdentifiers) {\n\t\t\tallowedTypes.push(createSchemaRef(allowedType));\n\t\t}\n\n\t\tconst output: Mutable<JsonFieldSchema> = hasSingle(allowedTypes)\n\t\t\t? allowedTypes[0]\n\t\t\t: {\n\t\t\t\t\tanyOf: allowedTypes,\n\t\t\t\t};\n\n\t\tcopyProperty(fieldSchema.metadata, \"description\", output);\n\t\tproperties[key] = output;\n\n\t\tif (fieldSchema.kind !== FieldKind.Optional) {\n\t\t\tif (\n\t\t\t\toptions.requireFieldsWithDefaults ||\n\t\t\t\tfieldSchema.props?.defaultProvider === undefined\n\t\t\t) {\n\t\t\t\trequired.push(key);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst transformedNode: Mutable<JsonObjectNodeSchema> = {\n\t\ttype: \"object\",\n\t\t_treeNodeSchemaKind: NodeKind.Object,\n\t\tproperties,\n\t\trequired,\n\t\tadditionalProperties: false,\n\t};\n\n\tcopyProperty(schema.metadata, \"description\", transformedNode);\n\n\treturn transformedNode;\n}\n\nfunction convertMapNodeSchema(schema: SimpleMapNodeSchema): JsonMapNodeSchema {\n\tconst allowedTypes: JsonSchemaRef[] = [];\n\tschema.allowedTypesIdentifiers.forEach((type) => {\n\t\tallowedTypes.push(createSchemaRef(type));\n\t});\n\n\tconst output: Mutable<JsonMapNodeSchema> = {\n\t\ttype: \"object\",\n\t\t_treeNodeSchemaKind: NodeKind.Map,\n\t\tpatternProperties: {\n\t\t\t\"^.*$\": hasSingle(allowedTypes)\n\t\t\t\t? allowedTypes[0]\n\t\t\t\t: {\n\t\t\t\t\t\tanyOf: allowedTypes,\n\t\t\t\t\t},\n\t\t},\n\t};\n\n\tcopyProperty(schema.metadata, \"description\", output);\n\n\treturn output;\n}\n\nfunction createSchemaRef(schemaId: string): JsonSchemaRef {\n\treturn {\n\t\t\"$ref\": createRefPath(schemaId),\n\t};\n}\n\nfunction createRefPath(schemaId: string): JsonRefPath {\n\treturn `#/$defs/${schemaId}`;\n}\n"]}
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { IFluidLoadable, IDisposable, Listenable } from "@fluidframework/core-interfaces";
|
|
6
6
|
import type { CommitMetadata, RevertibleAlphaFactory, RevertibleFactory } from "../../core/index.js";
|
|
7
|
-
import { type ImplicitFieldSchema, type InsertableField, type InsertableTreeFieldFromImplicitField, type ReadableField, type ReadSchema, type TreeFieldFromImplicitField, type UnsafeUnknownSchema } from "../schemaTypes.js";
|
|
7
|
+
import { type FieldSchemaAlpha, type ImplicitFieldSchema, type InsertableField, type InsertableTreeFieldFromImplicitField, type ReadableField, type ReadSchema, type TreeFieldFromImplicitField, type UnsafeUnknownSchema } from "../schemaTypes.js";
|
|
8
8
|
import { type TreeNodeSchema } from "../core/index.js";
|
|
9
9
|
import type { MakeNominal } from "../../util/index.js";
|
|
10
10
|
import type { VerboseTree } from "./verboseTree.js";
|
|
11
|
-
import type { SimpleTreeSchema } from "../simpleSchema.js";
|
|
11
|
+
import type { SimpleNodeSchema, SimpleTreeSchema } from "../simpleSchema.js";
|
|
12
12
|
import type { RunTransactionParams, TransactionCallbackStatus, TransactionResult, TransactionResultExt, VoidTransactionCallbackStatus } from "./transactionTypes.js";
|
|
13
13
|
/**
|
|
14
14
|
* A tree from which a {@link TreeView} can be created.
|
|
@@ -67,9 +67,7 @@ export interface ITree extends ViewableTree, IFluidLoadable {
|
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* {@link ITree} extended with some alpha APIs.
|
|
70
|
-
* @
|
|
71
|
-
* TODO: Promote this to alpha.
|
|
72
|
-
* @internal
|
|
70
|
+
* @sealed @alpha
|
|
73
71
|
*/
|
|
74
72
|
export interface ITreeAlpha extends ITree {
|
|
75
73
|
/**
|
|
@@ -220,6 +218,35 @@ export declare class TreeViewConfiguration<const TSchema extends ImplicitFieldSc
|
|
|
220
218
|
*/
|
|
221
219
|
constructor(props: ITreeViewConfiguration<TSchema>);
|
|
222
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* {@link TreeViewConfiguration} extended with some alpha APIs.
|
|
223
|
+
* @sealed @alpha
|
|
224
|
+
*/
|
|
225
|
+
export declare class TreeViewConfigurationAlpha<const TSchema extends ImplicitFieldSchema = ImplicitFieldSchema> extends TreeViewConfiguration<TSchema> implements TreeSchema {
|
|
226
|
+
/**
|
|
227
|
+
* {@inheritDoc TreeSchema.root}
|
|
228
|
+
*/
|
|
229
|
+
readonly root: FieldSchemaAlpha;
|
|
230
|
+
/**
|
|
231
|
+
* {@inheritDoc TreeSchema.definitions}
|
|
232
|
+
*/
|
|
233
|
+
readonly definitions: ReadonlyMap<string, SimpleNodeSchema & TreeNodeSchema>;
|
|
234
|
+
constructor(props: ITreeViewConfiguration<TSchema>);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* {@link TreeViewConfigurationAlpha}
|
|
238
|
+
* @sealed @alpha
|
|
239
|
+
*/
|
|
240
|
+
export interface TreeSchema extends SimpleTreeSchema {
|
|
241
|
+
/**
|
|
242
|
+
* {@inheritDoc SimpleTreeSchema.root}
|
|
243
|
+
*/
|
|
244
|
+
readonly root: FieldSchemaAlpha;
|
|
245
|
+
/**
|
|
246
|
+
* {@inheritDoc SimpleTreeSchema.definitions}
|
|
247
|
+
*/
|
|
248
|
+
readonly definitions: ReadonlyMap<string, SimpleNodeSchema & TreeNodeSchema>;
|
|
249
|
+
}
|
|
223
250
|
/**
|
|
224
251
|
* Detect cases documented in {@link ITreeConfigurationOptions.preventAmbiguity}.
|
|
225
252
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/tree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAG/F,OAAO,KAAK,EACX,cAAc,EACd,sBAAsB,EACtB,iBAAiB,EACjB,MAAM,qBAAqB,CAAC;AAQ7B,OAAO,EACN,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,oCAAoC,EACzC,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,
|
|
1
|
+
{"version":3,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AC,EAAE,oBAAoB,GAC3B,iBAAiB,CAAC;CACrB;AAED;;;;;GAKG;AACH,MAAM,WAAW,yBAAyB;IACzC;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B;;;;;;;;OAQG;IACH,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;CAKhC;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC;IAC9E;;;;;;;OAOG;IACH,OAAO,CAAC,IAAI,EAAE,cAAc,EAAE,aAAa,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAE5E;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,IAAI,EAAE,cAAc,EAAE,aAAa,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAC;CAClF;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B;;;;;;OAMG;IACH,WAAW,IAAI,IAAI,CAAC;IAEpB;;;;;;;OAOG;IACH,aAAa,IAAI,IAAI,CAAC;IAEtB;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,IAAI,EAAE,cAAc,EAAE,aAAa,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;CAC7E;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,mBAAmB,EAClE,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GACrB,aAAa,CAAC,OAAO,CAAC,CAExB"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { assert, fail } from "@fluidframework/core-utils/internal";
|
|
6
6
|
import { UsageError } from "@fluidframework/telemetry-utils/internal";
|
|
7
|
-
import { FieldKind, markSchemaMostDerived, } from "../schemaTypes.js";
|
|
7
|
+
import { FieldKind, markSchemaMostDerived, normalizeFieldSchema, } from "../schemaTypes.js";
|
|
8
8
|
import { NodeKind } from "../core/index.js";
|
|
9
9
|
import { toStoredSchema } from "../toStoredSchema.js";
|
|
10
10
|
import { LeafNodeSchema } from "../leafNodeSchema.js";
|
|
@@ -60,6 +60,21 @@ export class TreeViewConfiguration {
|
|
|
60
60
|
toStoredSchema(config.schema);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* {@link TreeViewConfiguration} extended with some alpha APIs.
|
|
65
|
+
* @sealed @alpha
|
|
66
|
+
*/
|
|
67
|
+
export class TreeViewConfigurationAlpha extends TreeViewConfiguration {
|
|
68
|
+
constructor(props) {
|
|
69
|
+
super(props);
|
|
70
|
+
this.root = normalizeFieldSchema(props.schema);
|
|
71
|
+
const definitions = new Map();
|
|
72
|
+
walkFieldSchema(props.schema, {
|
|
73
|
+
node: (schema) => definitions.set(schema.identifier, schema),
|
|
74
|
+
});
|
|
75
|
+
this.definitions = definitions;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
63
78
|
/**
|
|
64
79
|
* Pretty print a set of types for use in error messages.
|
|
65
80
|
*/
|