@fluidframework/tree 2.0.2 → 2.1.0-276326
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 +16 -0
- package/README.md +6 -9
- package/api-report/tree.alpha.api.md +0 -15
- package/api-report/tree.beta.api.md +0 -12
- package/api-report/tree.public.api.md +0 -12
- package/dist/core/tree/anchorSet.js +2 -2
- package/dist/core/tree/anchorSet.js.map +1 -1
- package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +1 -1
- package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.d.ts +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +4 -0
- package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFormat.d.ts +4 -0
- package/dist/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFormat.js +4 -0
- package/dist/feature-libraries/modular-schema/modularChangeFormat.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/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/index.d.ts +1 -1
- package/dist/shared-tree/index.d.ts.map +1 -1
- package/dist/shared-tree/index.js.map +1 -1
- package/dist/shared-tree/schematizingTreeView.d.ts +4 -6
- package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/dist/shared-tree/schematizingTreeView.js +16 -12
- package/dist/shared-tree/schematizingTreeView.js.map +1 -1
- package/dist/shared-tree/sharedTree.d.ts +1 -2
- package/dist/shared-tree/sharedTree.d.ts.map +1 -1
- package/dist/shared-tree/sharedTree.js +0 -10
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/treeApi.js.map +1 -1
- package/dist/shared-tree/treeView.d.ts +13 -6
- package/dist/shared-tree/treeView.d.ts.map +1 -1
- package/dist/shared-tree/treeView.js +0 -2
- package/dist/shared-tree/treeView.js.map +1 -1
- package/dist/simple-tree/index.d.ts +4 -3
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js +5 -3
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/objectNode.d.ts.map +1 -1
- package/dist/simple-tree/objectNode.js +4 -0
- package/dist/simple-tree/objectNode.js.map +1 -1
- package/dist/simple-tree/proxies.d.ts.map +1 -1
- package/dist/simple-tree/proxies.js +13 -16
- package/dist/simple-tree/proxies.js.map +1 -1
- package/dist/simple-tree/schemaFactory.d.ts.map +1 -1
- package/dist/simple-tree/schemaFactory.js +2 -24
- package/dist/simple-tree/schemaFactory.js.map +1 -1
- package/dist/simple-tree/toFlexSchema.d.ts +0 -15
- package/dist/simple-tree/toFlexSchema.d.ts.map +1 -1
- package/dist/simple-tree/toFlexSchema.js +1 -35
- package/dist/simple-tree/toFlexSchema.js.map +1 -1
- package/dist/simple-tree/tree.d.ts +0 -29
- package/dist/simple-tree/tree.d.ts.map +1 -1
- package/dist/simple-tree/tree.js +1 -24
- package/dist/simple-tree/tree.js.map +1 -1
- package/dist/treeFactory.d.ts +1 -1
- package/dist/treeFactory.js +1 -1
- package/dist/treeFactory.js.map +1 -1
- package/dist/util/brandedMap.d.ts +9 -2
- package/dist/util/brandedMap.d.ts.map +1 -1
- package/dist/util/brandedMap.js +3 -4
- package/dist/util/brandedMap.js.map +1 -1
- package/lib/core/tree/anchorSet.js +2 -2
- package/lib/core/tree/anchorSet.js.map +1 -1
- package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +1 -1
- package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.d.ts +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +4 -0
- package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFormat.d.ts +4 -0
- package/lib/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFormat.js +4 -0
- package/lib/feature-libraries/modular-schema/modularChangeFormat.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/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/index.d.ts +1 -1
- package/lib/shared-tree/index.d.ts.map +1 -1
- package/lib/shared-tree/index.js +1 -1
- package/lib/shared-tree/index.js.map +1 -1
- package/lib/shared-tree/schematizingTreeView.d.ts +4 -6
- package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/lib/shared-tree/schematizingTreeView.js +19 -15
- package/lib/shared-tree/schematizingTreeView.js.map +1 -1
- package/lib/shared-tree/sharedTree.d.ts +1 -2
- package/lib/shared-tree/sharedTree.d.ts.map +1 -1
- package/lib/shared-tree/sharedTree.js +0 -10
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/treeApi.js.map +1 -1
- package/lib/shared-tree/treeView.d.ts +13 -6
- package/lib/shared-tree/treeView.d.ts.map +1 -1
- package/lib/shared-tree/treeView.js +0 -2
- package/lib/shared-tree/treeView.js.map +1 -1
- package/lib/simple-tree/index.d.ts +4 -3
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js +4 -3
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/objectNode.d.ts.map +1 -1
- package/lib/simple-tree/objectNode.js +4 -0
- package/lib/simple-tree/objectNode.js.map +1 -1
- package/lib/simple-tree/proxies.d.ts.map +1 -1
- package/lib/simple-tree/proxies.js +14 -17
- package/lib/simple-tree/proxies.js.map +1 -1
- package/lib/simple-tree/schemaFactory.d.ts.map +1 -1
- package/lib/simple-tree/schemaFactory.js +3 -25
- package/lib/simple-tree/schemaFactory.js.map +1 -1
- package/lib/simple-tree/toFlexSchema.d.ts +0 -15
- package/lib/simple-tree/toFlexSchema.d.ts.map +1 -1
- package/lib/simple-tree/toFlexSchema.js +0 -33
- package/lib/simple-tree/toFlexSchema.js.map +1 -1
- package/lib/simple-tree/tree.d.ts +0 -29
- package/lib/simple-tree/tree.d.ts.map +1 -1
- package/lib/simple-tree/tree.js +0 -22
- package/lib/simple-tree/tree.js.map +1 -1
- package/lib/treeFactory.d.ts +1 -1
- package/lib/treeFactory.js +1 -1
- package/lib/treeFactory.js.map +1 -1
- package/lib/util/brandedMap.d.ts +9 -2
- package/lib/util/brandedMap.d.ts.map +1 -1
- package/lib/util/brandedMap.js +3 -4
- package/lib/util/brandedMap.js.map +1 -1
- package/package.json +23 -23
- package/src/core/tree/anchorSet.ts +3 -3
- package/src/feature-libraries/flex-tree/flexTreeTypes.ts +5 -1
- package/src/feature-libraries/flex-tree/lazyField.ts +8 -5
- package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +5 -0
- package/src/feature-libraries/modular-schema/modularChangeFormat.ts +4 -0
- package/src/index.ts +1 -0
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/index.ts +6 -1
- package/src/shared-tree/schematizingTreeView.ts +32 -26
- package/src/shared-tree/sharedTree.ts +0 -18
- package/src/shared-tree/treeApi.ts +2 -2
- package/src/shared-tree/treeView.ts +14 -8
- package/src/simple-tree/index.ts +7 -3
- package/src/simple-tree/objectNode.ts +6 -0
- package/src/simple-tree/proxies.ts +22 -20
- package/src/simple-tree/schemaFactory.ts +5 -41
- package/src/simple-tree/toFlexSchema.ts +0 -47
- package/src/simple-tree/tree.ts +0 -37
- package/src/treeFactory.ts +1 -1
- package/src/util/brandedMap.ts +18 -11
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.convertNodeSchema = exports.convertAllowedTypes = exports.convertField = exports.getFlexSchema = exports.toFlexSchema = exports.
|
|
7
|
+
exports.convertNodeSchema = exports.convertAllowedTypes = exports.convertField = exports.getFlexSchema = exports.toFlexSchema = exports.cursorFromUnhydratedRoot = void 0;
|
|
8
8
|
/* eslint-disable import/no-internal-modules */
|
|
9
9
|
const internal_1 = require("@fluidframework/core-utils/internal");
|
|
10
10
|
const index_js_1 = require("../feature-libraries/index.js");
|
|
@@ -13,8 +13,6 @@ const index_js_2 = require("../util/index.js");
|
|
|
13
13
|
const schemaCaching_js_1 = require("./schemaCaching.js");
|
|
14
14
|
const schemaTypes_js_1 = require("./schemaTypes.js");
|
|
15
15
|
const toMapTree_js_1 = require("./toMapTree.js");
|
|
16
|
-
// eslint-disable-next-line import/no-deprecated
|
|
17
|
-
const tree_js_1 = require("./tree.js");
|
|
18
16
|
/**
|
|
19
17
|
* Returns a cursor (in nodes mode) for the root node.
|
|
20
18
|
*
|
|
@@ -29,38 +27,6 @@ function cursorFromUnhydratedRoot(schema, tree, nodeKeyManager, schemaValidation
|
|
|
29
27
|
return ((0, toMapTree_js_1.cursorFromNodeData)(data, normalizedFieldSchema.allowedTypes, nodeKeyManager, schemaValidationPolicy) ?? (0, index_js_2.fail)("failed to decode tree"));
|
|
30
28
|
}
|
|
31
29
|
exports.cursorFromUnhydratedRoot = cursorFromUnhydratedRoot;
|
|
32
|
-
/* eslint-disable import/no-deprecated */
|
|
33
|
-
function isTreeConfiguration(config) {
|
|
34
|
-
return config instanceof tree_js_1.TreeConfiguration;
|
|
35
|
-
}
|
|
36
|
-
/* eslint-enable import/no-deprecated */
|
|
37
|
-
/**
|
|
38
|
-
* Generates a configuration object (schema + initial tree) for a FlexTree.
|
|
39
|
-
* @param config - Configuration for how to {@link ITree.schematize|schematize} a tree.
|
|
40
|
-
* @param nodeKeyManager - See {@link NodeKeyManager}.
|
|
41
|
-
* @param schemaValidationPolicy - Stored schema and policy for the tree. If the policy specifies
|
|
42
|
-
* `{@link SchemaPolicy.validateSchema} === true`, new content inserted into the tree will be validated using this
|
|
43
|
-
* object.
|
|
44
|
-
* @returns A configuration object for a FlexTree.
|
|
45
|
-
*
|
|
46
|
-
* @privateremarks
|
|
47
|
-
* I wrote these docs without a ton of context, they can probably be improved.
|
|
48
|
-
*/
|
|
49
|
-
function toFlexConfig(
|
|
50
|
-
// eslint-disable-next-line import/no-deprecated
|
|
51
|
-
config, nodeKeyManager, schemaValidationPolicy = undefined) {
|
|
52
|
-
const unhydrated = isTreeConfiguration(config) ? config.initialTree() : undefined;
|
|
53
|
-
const initialTree = unhydrated === undefined
|
|
54
|
-
? undefined
|
|
55
|
-
: [
|
|
56
|
-
cursorFromUnhydratedRoot(config.schema, unhydrated, nodeKeyManager, schemaValidationPolicy),
|
|
57
|
-
];
|
|
58
|
-
return {
|
|
59
|
-
schema: toFlexSchema(config.schema),
|
|
60
|
-
initialTree,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
exports.toFlexConfig = toFlexConfig;
|
|
64
30
|
/**
|
|
65
31
|
* Generate a {@link FlexTreeSchema} with `root` as the root field.
|
|
66
32
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toFlexSchema.js","sourceRoot":"","sources":["../../src/simple-tree/toFlexSchema.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+CAA+C;AAC/C,kEAA8E;AAO9E,4DAcuC;AACvC,+EAAuF;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;gBACC,IAAA,0BAAe,EAAC,IAAI,CAAC,CAAC;QACxB,CAAC;QACD,IAAA,iBAAM,EAAC,GAAG,YAAY,6BAAkB,EAAE,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAC/E,CAAC;YACA,MAAM,MAAM,GAAG,IAAA,kDAA+B,EAAC,MAAM,CAAC,CAAC;YACvD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBAC1B,IAAA,iBAAM,EACL,IAAA,kDAA+B,EAAC,MAAM,CAAC,KAAK,GAAG,EAC/C,KAAK,CAAC,gCAAgC,CACtC,CAAC;YACH,CAAC;iBAAM,CAAC;gBACP,IAAA,+CAA4B,EAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YAC3C,CAAC;QACF,CAAC;QACD,OAAO,GAAG,CAAC;IACZ,CAAC,CAAC;IACF,SAAS,CAAC,GAAG,CAAC,IAAA,gBAAK,EAAC,MAAM,CAAC,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACtE,OAAO,MAAM,CAAC;AACf,CAAC;AAvFD,8CAuFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable import/no-internal-modules */\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\n\nimport type {\n\tITreeCursorSynchronous,\n\tTreeNodeSchemaIdentifier,\n\tSchemaAndPolicy,\n} from \"../core/index.js\";\nimport {\n\tFieldKinds,\n\ttype FlexAllowedTypes,\n\ttype FlexFieldKind,\n\tFlexFieldNodeSchema,\n\tFlexFieldSchema,\n\tFlexMapNodeSchema,\n\tFlexObjectNodeSchema,\n\ttype FlexTreeNodeSchema,\n\ttype FlexTreeSchema,\n\ttype NodeKeyManager,\n\tTreeNodeSchemaBase,\n\tdefaultSchemaPolicy,\n\tschemaIsLeaf,\n} from \"../feature-libraries/index.js\";\nimport { normalizeFlexListEager } from \"../feature-libraries/typed-schema/flexList.js\";\nimport type { TreeContent } from \"../shared-tree/index.js\";\nimport { brand, fail, isReadonlyArray, mapIterable } from \"../util/index.js\";\n\nimport type { InsertableContent } from \"./proxies.js\";\nimport {\n\tcachedFlexSchemaFromClassSchema,\n\tsetFlexSchemaFromClassSchema,\n\ttryGetSimpleNodeSchema,\n} from \"./schemaCaching.js\";\nimport {\n\tFieldKind,\n\tFieldSchema,\n\ttype ImplicitAllowedTypes,\n\ttype ImplicitFieldSchema,\n\ttype InsertableTreeNodeFromImplicitAllowedTypes,\n\tNodeKind,\n\ttype TreeNodeSchema,\n\tnormalizeFieldSchema,\n\tgetStoredKey,\n} from \"./schemaTypes.js\";\nimport { cursorFromNodeData } from \"./toMapTree.js\";\n// eslint-disable-next-line import/no-deprecated\nimport { TreeConfiguration, type TreeViewConfiguration } from \"./tree.js\";\n\n/**\n * Returns a cursor (in nodes mode) for the root node.\n *\n * @privateRemarks\n * Ideally this would work on any node, not just the root,\n * and the schema would come from the unhydrated node.\n * For now though, this is the only case that's needed, and we do have the data to make it work, so this is fine.\n */\nexport function cursorFromUnhydratedRoot(\n\tschema: ImplicitFieldSchema,\n\ttree: InsertableTreeNodeFromImplicitAllowedTypes,\n\tnodeKeyManager: NodeKeyManager,\n\tschemaValidationPolicy: SchemaAndPolicy | undefined = undefined,\n): ITreeCursorSynchronous {\n\tconst data = tree as InsertableContent;\n\tconst normalizedFieldSchema = normalizeFieldSchema(schema);\n\treturn (\n\t\tcursorFromNodeData(\n\t\t\tdata,\n\t\t\tnormalizedFieldSchema.allowedTypes,\n\t\t\tnodeKeyManager,\n\t\t\tschemaValidationPolicy,\n\t\t) ?? fail(\"failed to decode tree\")\n\t);\n}\n\n/* eslint-disable import/no-deprecated */\nfunction isTreeConfiguration(\n\tconfig: TreeViewConfiguration | TreeConfiguration,\n): config is TreeConfiguration {\n\treturn config instanceof TreeConfiguration;\n}\n/* eslint-enable import/no-deprecated */\n\n/**\n * Generates a configuration object (schema + initial tree) for a FlexTree.\n * @param config - Configuration for how to {@link ITree.schematize|schematize} a tree.\n * @param nodeKeyManager - See {@link NodeKeyManager}.\n * @param schemaValidationPolicy - Stored schema and policy for the tree. If the policy specifies\n * `{@link SchemaPolicy.validateSchema} === true`, new content inserted into the tree will be validated using this\n * object.\n * @returns A configuration object for a FlexTree.\n *\n * @privateremarks\n * I wrote these docs without a ton of context, they can probably be improved.\n */\nexport function toFlexConfig(\n\t// eslint-disable-next-line import/no-deprecated\n\tconfig: TreeViewConfiguration | TreeConfiguration,\n\tnodeKeyManager: NodeKeyManager,\n\tschemaValidationPolicy: SchemaAndPolicy | undefined = undefined,\n): TreeContent {\n\tconst unhydrated = isTreeConfiguration(config) ? config.initialTree() : undefined;\n\tconst initialTree =\n\t\tunhydrated === undefined\n\t\t\t? undefined\n\t\t\t: [\n\t\t\t\t\tcursorFromUnhydratedRoot(\n\t\t\t\t\t\tconfig.schema,\n\t\t\t\t\t\tunhydrated,\n\t\t\t\t\t\tnodeKeyManager,\n\t\t\t\t\t\tschemaValidationPolicy,\n\t\t\t\t\t),\n\t\t\t\t];\n\treturn {\n\t\tschema: toFlexSchema(config.schema),\n\t\tinitialTree,\n\t};\n}\n\ninterface SchemaInfo {\n\ttoFlex: () => FlexTreeNodeSchema;\n\toriginal: TreeNodeSchema;\n}\n\ntype SchemaMap = Map<TreeNodeSchemaIdentifier, SchemaInfo>;\n\n/**\n * Generate a {@link FlexTreeSchema} with `root` as the root field.\n *\n * This also has the side effect of populating the cached view schema on the class-based schema.\n */\nexport function toFlexSchema(root: ImplicitFieldSchema): FlexTreeSchema {\n\tconst schemaMap: SchemaMap = new Map();\n\tconst field = convertField(schemaMap, root);\n\tconst nodeSchema = new Map(\n\t\tmapIterable(schemaMap, ([key, value]) => {\n\t\t\tconst schema = value.toFlex();\n\t\t\tconst classSchema = tryGetSimpleNodeSchema(schema);\n\t\t\tif (classSchema === undefined) {\n\t\t\t\tassert(schemaIsLeaf(schema), 0x83e /* invalid leaf */);\n\t\t\t} else {\n\t\t\t\tassert(\n\t\t\t\t\tcachedFlexSchemaFromClassSchema(classSchema) === schema,\n\t\t\t\t\t0x83f /* mismatched schema */,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn [key, schema];\n\t\t}),\n\t);\n\n\tconst typed: FlexTreeSchema = {\n\t\tnodeSchema,\n\t\tadapters: {},\n\t\trootFieldSchema: field,\n\t\tpolicy: defaultSchemaPolicy,\n\t};\n\treturn typed;\n}\n\n/**\n * Return a flex schema for the provided class schema.\n *\n * This also has the side effect of populating the cached view schema on the class based schema.\n */\nexport function getFlexSchema(root: TreeNodeSchema): FlexTreeNodeSchema {\n\tconst treeSchema = toFlexSchema(root);\n\treturn treeSchema.rootFieldSchema.monomorphicChildType ?? fail(\"root should be monomorphic\");\n}\n\n/**\n * Normalizes an {@link ImplicitFieldSchema} into a {@link TreeFieldSchema}.\n */\nexport function convertField(\n\tschemaMap: SchemaMap,\n\tschema: ImplicitFieldSchema,\n): FlexFieldSchema {\n\tlet kind: FlexFieldKind;\n\tlet types: ImplicitAllowedTypes;\n\tif (schema instanceof FieldSchema) {\n\t\tkind = convertFieldKind.get(schema.kind) ?? fail(\"Invalid field kind\");\n\t\ttypes = schema.allowedTypes;\n\t} else {\n\t\tkind = FieldKinds.required;\n\t\ttypes = schema;\n\t}\n\tconst allowedTypes = convertAllowedTypes(schemaMap, types);\n\treturn FlexFieldSchema.create(kind, allowedTypes);\n}\n\nconst convertFieldKind = new Map<FieldKind, FlexFieldKind>([\n\t[FieldKind.Optional, FieldKinds.optional],\n\t[FieldKind.Required, FieldKinds.required],\n\t[FieldKind.Identifier, FieldKinds.identifier],\n]);\n\n/**\n * Normalizes an {@link ImplicitAllowedTypes} into an {@link AllowedTypes}.\n */\nexport function convertAllowedTypes(\n\tschemaMap: SchemaMap,\n\tschema: ImplicitAllowedTypes,\n): FlexAllowedTypes {\n\tif (isReadonlyArray(schema)) {\n\t\treturn normalizeFlexListEager(schema).map((item) => convertNodeSchema(schemaMap, item));\n\t}\n\treturn [convertNodeSchema(schemaMap, schema)];\n}\n\nconst builder = { name: \"simple schema\" };\n\n/**\n * Converts a {@link TreeNodeSchema} into a {@link FlexTreeNodeSchema}.\n * Ensures all types reachable from `schema` are included in `schemaMap`.\n *\n * Return value (and entries in map) are lazy to allow recursive types to work.\n * This laziness does NOT extend to adding entries to `schemaMap`:\n * all referenced types are added to it before this function returns.\n */\nexport function convertNodeSchema(\n\tschemaMap: SchemaMap,\n\tschema: TreeNodeSchema,\n): () => FlexTreeNodeSchema {\n\tconst fromMap = schemaMap.get(brand(schema.identifier));\n\tif (fromMap !== undefined) {\n\t\tif (fromMap.original !== schema) {\n\t\t\t// Use JSON.stringify to quote and escape string.\n\t\t\tthrow new Error(\n\t\t\t\t`Multiple schema encountered with the identifier ${JSON.stringify(\n\t\t\t\t\tschema.identifier,\n\t\t\t\t)}. Remove or rename them to avoid the collision.`,\n\t\t\t);\n\t\t}\n\t\treturn fromMap.toFlex;\n\t}\n\n\tconst toFlex = (): FlexTreeNodeSchema => {\n\t\tlet out: FlexTreeNodeSchema;\n\t\tconst kind = schema.kind;\n\t\tswitch (kind) {\n\t\t\tcase NodeKind.Leaf: {\n\t\t\t\tconst cached =\n\t\t\t\t\tcachedFlexSchemaFromClassSchema(schema) ?? fail(\"leaf schema should be pre-cached\");\n\t\t\t\tassert(schemaIsLeaf(cached), 0x840 /* expected leaf */);\n\t\t\t\treturn cached;\n\t\t\t}\n\t\t\tcase NodeKind.Map: {\n\t\t\t\tconst fieldInfo = schema.info as ImplicitAllowedTypes;\n\t\t\t\tconst field = FlexFieldSchema.create(\n\t\t\t\t\tFieldKinds.optional,\n\t\t\t\t\tconvertAllowedTypes(schemaMap, fieldInfo),\n\t\t\t\t);\n\t\t\t\t// Lookup of cached schema is done here instead of before since walking the schema recursively to populate schemaMap is still required.\n\t\t\t\tconst cached = cachedFlexSchemaFromClassSchema(schema);\n\t\t\t\tout = cached ?? FlexMapNodeSchema.create(builder, brand(schema.identifier), field);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase NodeKind.Array: {\n\t\t\t\tconst fieldInfo = schema.info as ImplicitAllowedTypes;\n\t\t\t\tconst field = FlexFieldSchema.create(\n\t\t\t\t\tFieldKinds.sequence,\n\t\t\t\t\tconvertAllowedTypes(schemaMap, fieldInfo),\n\t\t\t\t);\n\t\t\t\tconst cached = cachedFlexSchemaFromClassSchema(schema);\n\t\t\t\tout = cached ?? FlexFieldNodeSchema.create(builder, brand(schema.identifier), field);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase NodeKind.Object: {\n\t\t\t\tconst info = schema.info as Record<string, ImplicitFieldSchema>;\n\t\t\t\tconst fields: Record<string, FlexFieldSchema> = Object.create(null);\n\t\t\t\tfor (const [viewKey, implicitFieldSchema] of Object.entries(info)) {\n\t\t\t\t\t// If a `stored key` was provided, use it as the key in the flex schema.\n\t\t\t\t\t// Otherwise, use the view key.\n\t\t\t\t\tconst flexKey = getStoredKey(viewKey, implicitFieldSchema);\n\n\t\t\t\t\t// This code has to be careful to avoid assigning to __proto__ or similar built-in fields.\n\t\t\t\t\tObject.defineProperty(fields, flexKey, {\n\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t\tconfigurable: false,\n\t\t\t\t\t\twritable: false,\n\t\t\t\t\t\tvalue: convertField(schemaMap, implicitFieldSchema),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tconst cached = cachedFlexSchemaFromClassSchema(schema);\n\t\t\t\tout = cached ?? FlexObjectNodeSchema.create(builder, brand(schema.identifier), fields);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tunreachableCase(kind);\n\t\t}\n\t\tassert(out instanceof TreeNodeSchemaBase, 0x841 /* invalid schema produced */);\n\t\t{\n\t\t\tconst cached = cachedFlexSchemaFromClassSchema(schema);\n\t\t\tif (cached !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tcachedFlexSchemaFromClassSchema(schema) === out,\n\t\t\t\t\t0x842 /* incorrect flexSchemaSymbol */,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tsetFlexSchemaFromClassSchema(schema, out);\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t};\n\tschemaMap.set(brand(schema.identifier), { original: schema, toFlex });\n\treturn toFlex;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"toFlexSchema.js","sourceRoot":"","sources":["../../src/simple-tree/toFlexSchema.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+CAA+C;AAC/C,kEAA8E;AAO9E,4DAcuC;AACvC,+EAAuF;AACvF,+CAA6E;AAG7E,yDAI4B;AAC5B,qDAU0B;AAC1B,iDAAoD;AAEpD;;;;;;;GAOG;AACH,SAAgB,wBAAwB,CACvC,MAA2B,EAC3B,IAAgD,EAChD,cAA8B,EAC9B,yBAAsD,SAAS;IAE/D,MAAM,IAAI,GAAG,IAAyB,CAAC;IACvC,MAAM,qBAAqB,GAAG,IAAA,qCAAoB,EAAC,MAAM,CAAC,CAAC;IAC3D,OAAO,CACN,IAAA,iCAAkB,EACjB,IAAI,EACJ,qBAAqB,CAAC,YAAY,EAClC,cAAc,EACd,sBAAsB,CACtB,IAAI,IAAA,eAAI,EAAC,uBAAuB,CAAC,CAClC,CAAC;AACH,CAAC;AAhBD,4DAgBC;AASD;;;;GAIG;AACH,SAAgB,YAAY,CAAC,IAAyB;IACrD,MAAM,SAAS,GAAc,IAAI,GAAG,EAAE,CAAC;IACvC,MAAM,KAAK,GAAG,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC5C,MAAM,UAAU,GAAG,IAAI,GAAG,CACzB,IAAA,sBAAW,EAAC,SAAS,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACvC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAC9B,MAAM,WAAW,GAAG,IAAA,yCAAsB,EAAC,MAAM,CAAC,CAAC;QACnD,IAAI,WAAW,KAAK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AAC,MAAM,CAAC,KAAK,GAAG,EAC/C,KAAK,CAAC,gCAAgC,CACtC,CAAC;YACH,CAAC;iBAAM,CAAC;gBACP,IAAA,+CAA4B,EAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YAC3C,CAAC;QACF,CAAC;QACD,OAAO,GAAG,CAAC;IACZ,CAAC,CAAC;IACF,SAAS,CAAC,GAAG,CAAC,IAAA,gBAAK,EAAC,MAAM,CAAC,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACtE,OAAO,MAAM,CAAC;AACf,CAAC;AAvFD,8CAuFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable import/no-internal-modules */\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\n\nimport type {\n\tITreeCursorSynchronous,\n\tTreeNodeSchemaIdentifier,\n\tSchemaAndPolicy,\n} from \"../core/index.js\";\nimport {\n\tFieldKinds,\n\ttype FlexAllowedTypes,\n\ttype FlexFieldKind,\n\tFlexFieldNodeSchema,\n\tFlexFieldSchema,\n\tFlexMapNodeSchema,\n\tFlexObjectNodeSchema,\n\ttype FlexTreeNodeSchema,\n\ttype FlexTreeSchema,\n\ttype NodeKeyManager,\n\tTreeNodeSchemaBase,\n\tdefaultSchemaPolicy,\n\tschemaIsLeaf,\n} from \"../feature-libraries/index.js\";\nimport { normalizeFlexListEager } from \"../feature-libraries/typed-schema/flexList.js\";\nimport { brand, fail, isReadonlyArray, mapIterable } from \"../util/index.js\";\n\nimport type { InsertableContent } from \"./proxies.js\";\nimport {\n\tcachedFlexSchemaFromClassSchema,\n\tsetFlexSchemaFromClassSchema,\n\ttryGetSimpleNodeSchema,\n} from \"./schemaCaching.js\";\nimport {\n\tFieldKind,\n\tFieldSchema,\n\ttype ImplicitAllowedTypes,\n\ttype ImplicitFieldSchema,\n\ttype InsertableTreeNodeFromImplicitAllowedTypes,\n\tNodeKind,\n\ttype TreeNodeSchema,\n\tnormalizeFieldSchema,\n\tgetStoredKey,\n} from \"./schemaTypes.js\";\nimport { cursorFromNodeData } from \"./toMapTree.js\";\n\n/**\n * Returns a cursor (in nodes mode) for the root node.\n *\n * @privateRemarks\n * Ideally this would work on any node, not just the root,\n * and the schema would come from the unhydrated node.\n * For now though, this is the only case that's needed, and we do have the data to make it work, so this is fine.\n */\nexport function cursorFromUnhydratedRoot(\n\tschema: ImplicitFieldSchema,\n\ttree: InsertableTreeNodeFromImplicitAllowedTypes,\n\tnodeKeyManager: NodeKeyManager,\n\tschemaValidationPolicy: SchemaAndPolicy | undefined = undefined,\n): ITreeCursorSynchronous {\n\tconst data = tree as InsertableContent;\n\tconst normalizedFieldSchema = normalizeFieldSchema(schema);\n\treturn (\n\t\tcursorFromNodeData(\n\t\t\tdata,\n\t\t\tnormalizedFieldSchema.allowedTypes,\n\t\t\tnodeKeyManager,\n\t\t\tschemaValidationPolicy,\n\t\t) ?? fail(\"failed to decode tree\")\n\t);\n}\n\ninterface SchemaInfo {\n\ttoFlex: () => FlexTreeNodeSchema;\n\toriginal: TreeNodeSchema;\n}\n\ntype SchemaMap = Map<TreeNodeSchemaIdentifier, SchemaInfo>;\n\n/**\n * Generate a {@link FlexTreeSchema} with `root` as the root field.\n *\n * This also has the side effect of populating the cached view schema on the class-based schema.\n */\nexport function toFlexSchema(root: ImplicitFieldSchema): FlexTreeSchema {\n\tconst schemaMap: SchemaMap = new Map();\n\tconst field = convertField(schemaMap, root);\n\tconst nodeSchema = new Map(\n\t\tmapIterable(schemaMap, ([key, value]) => {\n\t\t\tconst schema = value.toFlex();\n\t\t\tconst classSchema = tryGetSimpleNodeSchema(schema);\n\t\t\tif (classSchema === undefined) {\n\t\t\t\tassert(schemaIsLeaf(schema), 0x83e /* invalid leaf */);\n\t\t\t} else {\n\t\t\t\tassert(\n\t\t\t\t\tcachedFlexSchemaFromClassSchema(classSchema) === schema,\n\t\t\t\t\t0x83f /* mismatched schema */,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn [key, schema];\n\t\t}),\n\t);\n\n\tconst typed: FlexTreeSchema = {\n\t\tnodeSchema,\n\t\tadapters: {},\n\t\trootFieldSchema: field,\n\t\tpolicy: defaultSchemaPolicy,\n\t};\n\treturn typed;\n}\n\n/**\n * Return a flex schema for the provided class schema.\n *\n * This also has the side effect of populating the cached view schema on the class based schema.\n */\nexport function getFlexSchema(root: TreeNodeSchema): FlexTreeNodeSchema {\n\tconst treeSchema = toFlexSchema(root);\n\treturn treeSchema.rootFieldSchema.monomorphicChildType ?? fail(\"root should be monomorphic\");\n}\n\n/**\n * Normalizes an {@link ImplicitFieldSchema} into a {@link TreeFieldSchema}.\n */\nexport function convertField(\n\tschemaMap: SchemaMap,\n\tschema: ImplicitFieldSchema,\n): FlexFieldSchema {\n\tlet kind: FlexFieldKind;\n\tlet types: ImplicitAllowedTypes;\n\tif (schema instanceof FieldSchema) {\n\t\tkind = convertFieldKind.get(schema.kind) ?? fail(\"Invalid field kind\");\n\t\ttypes = schema.allowedTypes;\n\t} else {\n\t\tkind = FieldKinds.required;\n\t\ttypes = schema;\n\t}\n\tconst allowedTypes = convertAllowedTypes(schemaMap, types);\n\treturn FlexFieldSchema.create(kind, allowedTypes);\n}\n\nconst convertFieldKind = new Map<FieldKind, FlexFieldKind>([\n\t[FieldKind.Optional, FieldKinds.optional],\n\t[FieldKind.Required, FieldKinds.required],\n\t[FieldKind.Identifier, FieldKinds.identifier],\n]);\n\n/**\n * Normalizes an {@link ImplicitAllowedTypes} into an {@link AllowedTypes}.\n */\nexport function convertAllowedTypes(\n\tschemaMap: SchemaMap,\n\tschema: ImplicitAllowedTypes,\n): FlexAllowedTypes {\n\tif (isReadonlyArray(schema)) {\n\t\treturn normalizeFlexListEager(schema).map((item) => convertNodeSchema(schemaMap, item));\n\t}\n\treturn [convertNodeSchema(schemaMap, schema)];\n}\n\nconst builder = { name: \"simple schema\" };\n\n/**\n * Converts a {@link TreeNodeSchema} into a {@link FlexTreeNodeSchema}.\n * Ensures all types reachable from `schema` are included in `schemaMap`.\n *\n * Return value (and entries in map) are lazy to allow recursive types to work.\n * This laziness does NOT extend to adding entries to `schemaMap`:\n * all referenced types are added to it before this function returns.\n */\nexport function convertNodeSchema(\n\tschemaMap: SchemaMap,\n\tschema: TreeNodeSchema,\n): () => FlexTreeNodeSchema {\n\tconst fromMap = schemaMap.get(brand(schema.identifier));\n\tif (fromMap !== undefined) {\n\t\tif (fromMap.original !== schema) {\n\t\t\t// Use JSON.stringify to quote and escape string.\n\t\t\tthrow new Error(\n\t\t\t\t`Multiple schema encountered with the identifier ${JSON.stringify(\n\t\t\t\t\tschema.identifier,\n\t\t\t\t)}. Remove or rename them to avoid the collision.`,\n\t\t\t);\n\t\t}\n\t\treturn fromMap.toFlex;\n\t}\n\n\tconst toFlex = (): FlexTreeNodeSchema => {\n\t\tlet out: FlexTreeNodeSchema;\n\t\tconst kind = schema.kind;\n\t\tswitch (kind) {\n\t\t\tcase NodeKind.Leaf: {\n\t\t\t\tconst cached =\n\t\t\t\t\tcachedFlexSchemaFromClassSchema(schema) ?? fail(\"leaf schema should be pre-cached\");\n\t\t\t\tassert(schemaIsLeaf(cached), 0x840 /* expected leaf */);\n\t\t\t\treturn cached;\n\t\t\t}\n\t\t\tcase NodeKind.Map: {\n\t\t\t\tconst fieldInfo = schema.info as ImplicitAllowedTypes;\n\t\t\t\tconst field = FlexFieldSchema.create(\n\t\t\t\t\tFieldKinds.optional,\n\t\t\t\t\tconvertAllowedTypes(schemaMap, fieldInfo),\n\t\t\t\t);\n\t\t\t\t// Lookup of cached schema is done here instead of before since walking the schema recursively to populate schemaMap is still required.\n\t\t\t\tconst cached = cachedFlexSchemaFromClassSchema(schema);\n\t\t\t\tout = cached ?? FlexMapNodeSchema.create(builder, brand(schema.identifier), field);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase NodeKind.Array: {\n\t\t\t\tconst fieldInfo = schema.info as ImplicitAllowedTypes;\n\t\t\t\tconst field = FlexFieldSchema.create(\n\t\t\t\t\tFieldKinds.sequence,\n\t\t\t\t\tconvertAllowedTypes(schemaMap, fieldInfo),\n\t\t\t\t);\n\t\t\t\tconst cached = cachedFlexSchemaFromClassSchema(schema);\n\t\t\t\tout = cached ?? FlexFieldNodeSchema.create(builder, brand(schema.identifier), field);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase NodeKind.Object: {\n\t\t\t\tconst info = schema.info as Record<string, ImplicitFieldSchema>;\n\t\t\t\tconst fields: Record<string, FlexFieldSchema> = Object.create(null);\n\t\t\t\tfor (const [viewKey, implicitFieldSchema] of Object.entries(info)) {\n\t\t\t\t\t// If a `stored key` was provided, use it as the key in the flex schema.\n\t\t\t\t\t// Otherwise, use the view key.\n\t\t\t\t\tconst flexKey = getStoredKey(viewKey, implicitFieldSchema);\n\n\t\t\t\t\t// This code has to be careful to avoid assigning to __proto__ or similar built-in fields.\n\t\t\t\t\tObject.defineProperty(fields, flexKey, {\n\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t\tconfigurable: false,\n\t\t\t\t\t\twritable: false,\n\t\t\t\t\t\tvalue: convertField(schemaMap, implicitFieldSchema),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tconst cached = cachedFlexSchemaFromClassSchema(schema);\n\t\t\t\tout = cached ?? FlexObjectNodeSchema.create(builder, brand(schema.identifier), fields);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tunreachableCase(kind);\n\t\t}\n\t\tassert(out instanceof TreeNodeSchemaBase, 0x841 /* invalid schema produced */);\n\t\t{\n\t\t\tconst cached = cachedFlexSchemaFromClassSchema(schema);\n\t\t\tif (cached !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tcachedFlexSchemaFromClassSchema(schema) === out,\n\t\t\t\t\t0x842 /* incorrect flexSchemaSymbol */,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tsetFlexSchemaFromClassSchema(schema, out);\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t};\n\tschemaMap.set(brand(schema.identifier), { original: schema, toFlex });\n\treturn toFlex;\n}\n"]}
|
|
@@ -104,35 +104,6 @@ export declare class TreeViewConfiguration<TSchema extends ImplicitFieldSchema =
|
|
|
104
104
|
*/
|
|
105
105
|
constructor(props: ITreeViewConfiguration<TSchema>);
|
|
106
106
|
}
|
|
107
|
-
/**
|
|
108
|
-
* Configuration for how to {@link ITree.schematize | schematize} a tree.
|
|
109
|
-
* @sealed @public
|
|
110
|
-
* @deprecated Please migrate to use {@link TreeViewConfiguration} with {@link ITree.viewWith} instead.
|
|
111
|
-
*/
|
|
112
|
-
export declare class TreeConfiguration<TSchema extends ImplicitFieldSchema = ImplicitFieldSchema> {
|
|
113
|
-
readonly schema: TSchema;
|
|
114
|
-
readonly initialTree: () => InsertableTreeFieldFromImplicitField<TSchema>;
|
|
115
|
-
/**
|
|
116
|
-
* If `true`, the tree will validate new content against its stored schema at insertion time
|
|
117
|
-
* and throw an error if the new content doesn't match the expected schema.
|
|
118
|
-
*
|
|
119
|
-
* @defaultValue `false`.
|
|
120
|
-
*
|
|
121
|
-
* @remarks Enabling schema validation has a performance penalty when inserting new content into the tree because
|
|
122
|
-
* additional checks are done. Enable this option only in scenarios where you are ok with that operation being a
|
|
123
|
-
* bit slower.
|
|
124
|
-
*/
|
|
125
|
-
readonly enableSchemaValidation: boolean;
|
|
126
|
-
/**
|
|
127
|
-
* @param schema - The schema which the application wants to view the tree with.
|
|
128
|
-
* @param initialTree - A function that returns the default tree content to initialize the tree with iff the tree is uninitialized
|
|
129
|
-
* (meaning it does not even have any schema set at all).
|
|
130
|
-
* If `initialTree` returns any actual node instances, they should be recreated each time `initialTree` runs.
|
|
131
|
-
* This is because if the config is used a second time any nodes that were not recreated could error since nodes cannot be inserted into the tree multiple times.
|
|
132
|
-
* @param options - Additional options that can be specified when {@link ITree.schematize | schematizing } a tree.
|
|
133
|
-
*/
|
|
134
|
-
constructor(schema: TSchema, initialTree: () => InsertableTreeFieldFromImplicitField<TSchema>, options?: ITreeConfigurationOptions);
|
|
135
|
-
}
|
|
136
107
|
/**
|
|
137
108
|
* An editable view of a (version control style) branch of a shared tree based on some schema.
|
|
138
109
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../src/simple-tree/tree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAEnF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,KAAK,EACX,mBAAmB,EACnB,oCAAoC,EACpC,0BAA0B,EAC1B,MAAM,kBAAkB,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,WAAW,KAAM,SAAQ,cAAc;IAC5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,QAAQ,CAAC,KAAK,SAAS,mBAAmB,EACzC,MAAM,EAAE,qBAAqB,CAAC,KAAK,CAAC,GAClC,QAAQ,CAAC,KAAK,CAAC,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACzC;;;;;;;;;OASG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CACjC;AAMD;;;GAGG;AACH,MAAM,WAAW,sBAAsB,CACtC,OAAO,SAAS,mBAAmB,GAAG,mBAAmB;IAEzD;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAEzB;;;;;;;;;OASG;IACH,QAAQ,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAC1C;AAED;;;GAGG;AACH,qBAAa,qBAAqB,CAAC,OAAO,SAAS,mBAAmB,GAAG,mBAA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AI,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"}
|
package/dist/simple-tree/tree.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.TreeViewConfiguration = void 0;
|
|
8
8
|
const defaultTreeConfigurationOptions = {
|
|
9
9
|
enableSchemaValidation: false,
|
|
10
10
|
};
|
|
@@ -23,27 +23,4 @@ class TreeViewConfiguration {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.TreeViewConfiguration = TreeViewConfiguration;
|
|
26
|
-
/**
|
|
27
|
-
* Configuration for how to {@link ITree.schematize | schematize} a tree.
|
|
28
|
-
* @sealed @public
|
|
29
|
-
* @deprecated Please migrate to use {@link TreeViewConfiguration} with {@link ITree.viewWith} instead.
|
|
30
|
-
*/
|
|
31
|
-
class TreeConfiguration {
|
|
32
|
-
/**
|
|
33
|
-
* @param schema - The schema which the application wants to view the tree with.
|
|
34
|
-
* @param initialTree - A function that returns the default tree content to initialize the tree with iff the tree is uninitialized
|
|
35
|
-
* (meaning it does not even have any schema set at all).
|
|
36
|
-
* If `initialTree` returns any actual node instances, they should be recreated each time `initialTree` runs.
|
|
37
|
-
* This is because if the config is used a second time any nodes that were not recreated could error since nodes cannot be inserted into the tree multiple times.
|
|
38
|
-
* @param options - Additional options that can be specified when {@link ITree.schematize | schematizing } a tree.
|
|
39
|
-
*/
|
|
40
|
-
constructor(schema, initialTree, options) {
|
|
41
|
-
this.schema = schema;
|
|
42
|
-
this.initialTree = initialTree;
|
|
43
|
-
this.enableSchemaValidation =
|
|
44
|
-
options?.enableSchemaValidation ??
|
|
45
|
-
defaultTreeConfigurationOptions.enableSchemaValidation;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.TreeConfiguration = TreeConfiguration;
|
|
49
26
|
//# sourceMappingURL=tree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../src/simple-tree/tree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA4EH,MAAM,+BAA+B,GAAwC;IAC5E,sBAAsB,EAAE,KAAK;CAC7B,CAAC;AA2BF;;;GAGG;AACH,MAAa,qBAAqB;IAajC;;OAEG;IACH,YAAmB,KAAsC;QACxD,MAAM,MAAM,GAAG,EAAE,GAAG,+BAA+B,EAAE,GAAG,KAAK,EAAE,CAAC;QAChE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,sBAAsB,GAAG,MAAM,CAAC,sBAAsB,CAAC;IAC7D,CAAC;CACD;AArBD,sDAqBC;AAED;;;;GAIG;AACH,MAAa,iBAAiB;IAa7B;;;;;;;OAOG;IACH,YACiB,MAAe,EACf,WAAgE,EAChF,OAAmC;QAFnB,WAAM,GAAN,MAAM,CAAS;QACf,gBAAW,GAAX,WAAW,CAAqD;QAGhF,IAAI,CAAC,sBAAsB;YAC1B,OAAO,EAAE,sBAAsB;gBAC/B,+BAA+B,CAAC,sBAAsB,CAAC;IACzD,CAAC;CACD;AA9BD,8CA8BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidLoadable, IDisposable } from \"@fluidframework/core-interfaces\";\n\nimport type { CommitMetadata } from \"../core/index.js\";\nimport type { Listenable } from \"../events/index.js\";\nimport type { RevertibleFactory } from \"../shared-tree/index.js\";\n\nimport type {\n\tImplicitFieldSchema,\n\tInsertableTreeFieldFromImplicitField,\n\tTreeFieldFromImplicitField,\n} from \"./schemaTypes.js\";\n\n/**\n * Channel for a Fluid Tree DDS.\n * @remarks\n * Allows storing and collaboratively editing schema-aware hierarchial data.\n * @sealed @public\n */\nexport interface ITree extends IFluidLoadable {\n\t/**\n\t * Returns a {@link TreeView} using the provided schema.\n\t * If the stored schema is compatible with the view schema specified by `config`,\n\t * the returned {@link TreeView} will expose the root with a schema-aware API based on the provided view schema.\n\t * If the provided schema is incompatible with the stored schema, the view will instead expose a status indicating the incompatibility.\n\t *\n\t * @remarks\n\t * If the tree is uninitialized (has no schema and no content), use {@link TreeView.initialize} on the returned view to set the schema and content together.\n\t * Using `viewWith` followed by {@link TreeView.upgradeSchema} to initialize only the schema for a document is technically valid when the schema\n\t * permits trees with no content.\n\t *\n\t * Note that other clients can modify the document at any time, causing the view to change its compatibility status: see {@link TreeView.events} for how to handle invalidation in these cases.\n\t *\n\t * Only one schematized view may exist for a given ITree at a time.\n\t * If creating a second, the first must be disposed before calling `viewWith` again.\n\t *\n\t * @privateRemarks\n\t * TODO: Provide a way to make a generic view schema for any document.\n\t * TODO: Support adapters for handling out-of-schema data.\n\t *\n\t * Doing initialization here allows a small API that is hard to use incorrectly.\n\t * Other approaches tend to have easy-to-make mistakes.\n\t * For example, having a separate initialization function means apps can forget to call it, making an app that can only open existing documents,\n\t * or call it unconditionally leaving an app that can only create new documents.\n\t * It also would require the schema to be passed into separate places and could cause issues if they didn't match.\n\t * Since the initialization function couldn't return a typed tree, the type checking wouldn't help catch that.\n\t * Also, if an app manages to create a document, but the initialization fails to get persisted, an app that only calls the initialization function\n\t * on the create code-path (for example how a schematized factory might do it),\n\t * would leave the document in an unusable state which could not be repaired when it is reopened (by the same or other clients).\n\t * Additionally, once out of schema content adapters are properly supported (with lazy document updates),\n\t * this initialization could become just another out of schema content adapter and this initialization is no longer a special case.\n\t */\n\tviewWith<TRoot extends ImplicitFieldSchema>(\n\t\tconfig: TreeViewConfiguration<TRoot>,\n\t): TreeView<TRoot>;\n}\n\n/**\n * Options when constructing a tree view.\n * @public\n */\nexport interface ITreeConfigurationOptions {\n\t/**\n\t * If `true`, the tree will validate new content against its stored schema at insertion time\n\t * and throw an error if the new content doesn't match the expected schema.\n\t *\n\t * @defaultValue `false`.\n\t *\n\t * @remarks Enabling schema validation has a performance penalty when inserting new content into the tree because\n\t * additional checks are done. Enable this option only in scenarios where you are ok with that operation being a\n\t * bit slower.\n\t */\n\tenableSchemaValidation?: boolean;\n}\n\nconst defaultTreeConfigurationOptions: Required<ITreeConfigurationOptions> = {\n\tenableSchemaValidation: false,\n};\n\n/**\n * Property-bag configuration for {@link TreeViewConfiguration} construction.\n * @public\n */\nexport interface ITreeViewConfiguration<\n\tTSchema extends ImplicitFieldSchema = ImplicitFieldSchema,\n> {\n\t/**\n\t * The schema which the application wants to view the tree with.\n\t */\n\treadonly schema: TSchema;\n\n\t/**\n\t * If `true`, the tree will validate new content against its stored schema at insertion time\n\t * and throw an error if the new content doesn't match the expected schema.\n\t *\n\t * @defaultValue `false`.\n\t *\n\t * @remarks Enabling schema validation has a performance penalty when inserting new content into the tree because\n\t * additional checks are done. Enable this option only in scenarios where you are ok with that operation being a\n\t * bit slower.\n\t */\n\treadonly enableSchemaValidation?: boolean;\n}\n\n/**\n * Configuration for {@link ITree.viewWith}.\n * @sealed @public\n */\nexport class TreeViewConfiguration<TSchema extends ImplicitFieldSchema = ImplicitFieldSchema>\n\timplements Required<ITreeViewConfiguration<TSchema>>\n{\n\t/**\n\t * {@inheritDoc ITreeViewConfiguration.schema}\n\t */\n\tpublic readonly schema: TSchema;\n\n\t/**\n\t * {@inheritDoc ITreeViewConfiguration.enableSchemaValidation}\n\t */\n\tpublic readonly enableSchemaValidation: boolean;\n\n\t/**\n\t * @param props - Property bag of configuration options.\n\t */\n\tpublic constructor(props: ITreeViewConfiguration<TSchema>) {\n\t\tconst config = { ...defaultTreeConfigurationOptions, ...props };\n\t\tthis.schema = config.schema;\n\t\tthis.enableSchemaValidation = config.enableSchemaValidation;\n\t}\n}\n\n/**\n * Configuration for how to {@link ITree.schematize | schematize} a tree.\n * @sealed @public\n * @deprecated Please migrate to use {@link TreeViewConfiguration} with {@link ITree.viewWith} instead.\n */\nexport class TreeConfiguration<TSchema extends ImplicitFieldSchema = ImplicitFieldSchema> {\n\t/**\n\t * If `true`, the tree will validate new content against its stored schema at insertion time\n\t * and throw an error if the new content doesn't match the expected schema.\n\t *\n\t * @defaultValue `false`.\n\t *\n\t * @remarks Enabling schema validation has a performance penalty when inserting new content into the tree because\n\t * additional checks are done. Enable this option only in scenarios where you are ok with that operation being a\n\t * bit slower.\n\t */\n\tpublic readonly enableSchemaValidation: boolean;\n\n\t/**\n\t * @param schema - The schema which the application wants to view the tree with.\n\t * @param initialTree - A function that returns the default tree content to initialize the tree with iff the tree is uninitialized\n\t * (meaning it does not even have any schema set at all).\n\t * If `initialTree` returns any actual node instances, they should be recreated each time `initialTree` runs.\n\t * This is because if the config is used a second time any nodes that were not recreated could error since nodes cannot be inserted into the tree multiple times.\n\t * @param options - Additional options that can be specified when {@link ITree.schematize | schematizing } a tree.\n\t */\n\tpublic constructor(\n\t\tpublic readonly schema: TSchema,\n\t\tpublic readonly initialTree: () => InsertableTreeFieldFromImplicitField<TSchema>,\n\t\toptions?: ITreeConfigurationOptions,\n\t) {\n\t\tthis.enableSchemaValidation =\n\t\t\toptions?.enableSchemaValidation ??\n\t\t\tdefaultTreeConfigurationOptions.enableSchemaValidation;\n\t}\n}\n\n/**\n * An editable view of a (version control style) branch of a shared tree based on some schema.\n *\n * This schema--known as the view schema--may or may not align the stored schema of the document.\n * Information about discrepancies between the two schemas is available via {@link TreeView.compatibility | compatibility}.\n *\n * Application authors are encouraged to read [schema-evolution.md](../../docs/user-facing/schema-evolution.md) and\n * choose a schema compatibility policy that aligns with their application's needs.\n *\n * @privateRemarks\n * From an API design perspective, `upgradeSchema` could be merged into `viewWith` and/or `viewWith` could return errors explicitly on incompatible documents.\n * Such approaches would make it discoverable that out of schema handling may need to be done.\n * Doing that would however complicate trivial \"hello world\" style example slightly, as well as be a breaking API change.\n * It also seems more complex to handle invalidation with that pattern.\n * Thus this design was chosen at the risk of apps blindly accessing `root` then breaking unexpectedly when the document is incompatible.\n * @sealed @public\n */\nexport interface TreeView<TSchema extends ImplicitFieldSchema> extends IDisposable {\n\t/**\n\t * The current root of the tree.\n\t *\n\t * If the view schema not sufficiently compatible with the stored schema, accessing this will throw.\n\t * To handle this case, check {@link TreeView.compatibility | compatibility}'s {@link SchemaCompatibilityStatus.canView | canView} before using.\n\t *\n\t * To get notified about changes to this field,\n\t * use {@link TreeViewEvents.rootChanged} via `view.events.on(\"rootChanged\", callback)`.\n\t *\n\t * To get notified about changes to stored schema (which may affect compatibility between this view's schema and\n\t * the stored schema), use {@link TreeViewEvents.schemaChanged} via `view.events.on(\"schemaChanged\", callback)`.\n\t */\n\tget root(): TreeFieldFromImplicitField<TSchema>;\n\n\tset root(newRoot: InsertableTreeFieldFromImplicitField<TSchema>);\n\n\t/**\n\t * Description of the current compatibility status between the view schema and stored schema.\n\t *\n\t * {@link TreeViewEvents.schemaChanged} is fired when the compatibility status changes.\n\t */\n\treadonly compatibility: SchemaCompatibilityStatus;\n\n\t/**\n\t * When the schemas are not an exact match and {@link SchemaCompatibilityStatus.canUpgrade} is true,\n\t * this can be used to modify the stored schema to make it match the view schema.\n\t * This will update the compatibility state, and allow access to `root`.\n\t * Beware that this may impact other clients' ability to view the document depending on the application's schema compatibility policy!\n\t * @remarks\n\t * It is an error to call this when {@link SchemaCompatibilityStatus.canUpgrade} is false, and a no-op when the stored and view schema are already an exact match.\n\t * @privateRemarks\n\t * In the future, more upgrade options could be provided here.\n\t * Some options that could be added:\n\t * - check the actual document contents (not just the schema) and attempt an atomic document update if the data is compatible.\n\t * - apply converters and upgrade the document.\n\t * - apply converters to lazily to adapt the document to the requested view schema (with optional lazy schema updates or transparent conversions on write).\n\t */\n\tupgradeSchema(): void;\n\n\t/**\n\t * Initialize the tree, setting the stored schema to match this view's schema and setting the tree content.\n\t *\n\t * Only valid to call when this view's {@link SchemaCompatibilityStatus.canInitialize} is true.\n\t *\n\t * Applications should typically call this function before attaching a `SharedTree`.\n\t * @param content - The content to initialize the tree with.\n\t */\n\tinitialize(content: InsertableTreeFieldFromImplicitField<TSchema>): void;\n\n\t/**\n\t * Events for the tree.\n\t */\n\treadonly events: Listenable<TreeViewEvents>;\n}\n\n/**\n * Information about a view schema's compatibility with the document's stored schema.\n *\n * See SharedTree's README for more information about choosing a compatibility policy.\n * @sealed @public\n */\nexport interface SchemaCompatibilityStatus {\n\t/**\n\t * Whether the view schema allows exactly the same set of documents as the stored schema.\n\t *\n\t * @remarks\n\t * Equivalence here is defined in terms of allowed documents because there are some degenerate cases where schemas are not\n\t * exact matches in a strict (schema-based) sense but still allow the same documents, and the document notion is more useful to applications.\n\t *\n\t * Examples which are expressible where this may occur include:\n\t * - schema repository `A` has extra schema which schema `B` doesn't have, but they are unused (i.e. not reachable from the root schema)\n\t * - field in schema `A` has allowed field members which the corresponding field in schema `B` does not have, but those types are not constructible (ex: an object node type containing a required field with no allowed types)\n\t *\n\t * These cases are typically not interesting to applications.\n\t */\n\treadonly isEquivalent: boolean;\n\n\t/**\n\t * Whether the current view schema is sufficiently compatible with the stored schema to allow viewing tree data.\n\t * If false, {@link TreeView.root} will throw upon access.\n\t *\n\t * Currently, this field is true iff `isEquivalent` is true.\n\t * Do not rely on this:\n\t * there are near-term plans to extend support for viewing documents when the stored schema contains additional optional fields not present in the view schema.\n\t * The other two types of backward-compatible changes (field relaxations and addition of allowed field types) will eventually be supported as well,\n\t * likely through out-of-schema content adapters that the application can provide alongside their view schema.\n\t *\n\t * Be aware that even with these SharedTree limitations fixed, application logic may not correctly tolerate the documents allowable by the stored schema!\n\t * Application authors are encouraged to read docs/user-facing/schema-evolution.md and choose a schema compatibility policy that\n\t * aligns with their application's needs.\n\t *\n\t * @remarks\n\t * When the documents allowed by the view schema is a strict superset of those by the stored schema,\n\t * this is false because writes to the document using the view schema could make the document violate its stored schema.\n\t * In this case, the stored schema could be updated to match the provided view schema, allowing read-write access to the tree.\n\t * See {@link SchemaCompatibilityStatus.canUpgrade}.\n\t *\n\t * Future version of SharedTree may provide readonly access to the document in this case because that would be safe,\n\t * but this is not currently supported.\n\t *\n\t * @privateRemarks\n\t * A necessary condition for this to be true is that the documents allowed by the view schema are a subset of those allowed by the stored schema.\n\t * This is not sufficient: the simple-tree layer's read APIs do not tolerate out-of-schema data.\n\t * For example, if the view schema for a node has a required `Point` field but the stored schema has an optional `Point` field,\n\t * read APIs on the view schema do not work correctly when the document has a node with a missing `Point` field.\n\t * Similar issues happen when the view schema has a field with less allowed types than the stored schema and the document actually leverages those types.\n\t */\n\treadonly canView: boolean;\n\n\t/**\n\t * True iff the view schema supports all possible documents permitted by the stored schema.\n\t * When true, it is valid to call {@link TreeView.upgradeSchema} (though if the stored schema is already an exact match, this is a no-op).\n\t */\n\treadonly canUpgrade: boolean;\n\n\t/**\n\t * True iff the document is uninitialized (i.e. it has no schema and no content).\n\t *\n\t * To initialize the document, call {@link TreeView.initialize}.\n\t *\n\t * @remarks\n\t * It's not necessary to check this field before calling {@link TreeView.initialize} in most scenarios; application authors typically know from\n\t * context that they're in a flow which creates a new `SharedTree` and would like to initialize it.\n\t */\n\treadonly canInitialize: boolean;\n\n\t// TODO: Consider extending this status to include:\n\t// - application-defined metadata about the stored schema\n\t// - details about the differences between the stored and view schema sufficient for implementing \"safe mismatch\" policies\n}\n\n/**\n * Events for {@link TreeView}.\n * @sealed @public\n */\nexport interface TreeViewEvents {\n\t/**\n\t * Raised whenever {@link TreeView.root} is invalidated.\n\t *\n\t * This includes changes to the document schema.\n\t * It also includes changes to the field containing the root such as setting or clearing an optional root or changing which node is the root.\n\t * This does NOT include changes to the content (fields/children) of the root node: for that case subscribe to events on the root node.\n\t */\n\trootChanged(): void;\n\n\t/**\n\t * The stored schema for the document has changed.\n\t * This may affect the compatibility between the view schema and the stored schema, and thus the ability to use the view.\n\t *\n\t * @remarks\n\t * This event implies that the old {@link TreeView.root} is no longer valid, but applications need not handle that separately:\n\t * {@link TreeViewEvents.rootChanged} will be fired after this event.\n\t */\n\tschemaChanged(): void;\n\n\t/**\n\t * Fired when:\n\t * - a local commit is applied outside of a transaction\n\t * - a local transaction is committed\n\t *\n\t * The event is not fired when:\n\t * - a local commit is applied within a transaction\n\t * - a remote commit is applied\n\t *\n\t * @param data - information about the commit that was applied\n\t * @param getRevertible - a function provided that allows users to get a revertible for the commit that was applied. If not provided,\n\t * this commit is not revertible.\n\t */\n\tcommitApplied(data: CommitMetadata, getRevertible?: RevertibleFactory): void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../src/simple-tree/tree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA4EH,MAAM,+BAA+B,GAAwC;IAC5E,sBAAsB,EAAE,KAAK;CAC7B,CAAC;AA2BF;;;GAGG;AACH,MAAa,qBAAqB;IAajC;;OAEG;IACH,YAAmB,KAAsC;QACxD,MAAM,MAAM,GAAG,EAAE,GAAG,+BAA+B,EAAE,GAAG,KAAK,EAAE,CAAC;QAChE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,sBAAsB,GAAG,MAAM,CAAC,sBAAsB,CAAC;IAC7D,CAAC;CACD;AArBD,sDAqBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidLoadable, IDisposable } from \"@fluidframework/core-interfaces\";\n\nimport type { CommitMetadata } from \"../core/index.js\";\nimport type { Listenable } from \"../events/index.js\";\nimport type { RevertibleFactory } from \"../shared-tree/index.js\";\n\nimport type {\n\tImplicitFieldSchema,\n\tInsertableTreeFieldFromImplicitField,\n\tTreeFieldFromImplicitField,\n} from \"./schemaTypes.js\";\n\n/**\n * Channel for a Fluid Tree DDS.\n * @remarks\n * Allows storing and collaboratively editing schema-aware hierarchial data.\n * @sealed @public\n */\nexport interface ITree extends IFluidLoadable {\n\t/**\n\t * Returns a {@link TreeView} using the provided schema.\n\t * If the stored schema is compatible with the view schema specified by `config`,\n\t * the returned {@link TreeView} will expose the root with a schema-aware API based on the provided view schema.\n\t * If the provided schema is incompatible with the stored schema, the view will instead expose a status indicating the incompatibility.\n\t *\n\t * @remarks\n\t * If the tree is uninitialized (has no schema and no content), use {@link TreeView.initialize} on the returned view to set the schema and content together.\n\t * Using `viewWith` followed by {@link TreeView.upgradeSchema} to initialize only the schema for a document is technically valid when the schema\n\t * permits trees with no content.\n\t *\n\t * Note that other clients can modify the document at any time, causing the view to change its compatibility status: see {@link TreeView.events} for how to handle invalidation in these cases.\n\t *\n\t * Only one schematized view may exist for a given ITree at a time.\n\t * If creating a second, the first must be disposed before calling `viewWith` again.\n\t *\n\t * @privateRemarks\n\t * TODO: Provide a way to make a generic view schema for any document.\n\t * TODO: Support adapters for handling out-of-schema data.\n\t *\n\t * Doing initialization here allows a small API that is hard to use incorrectly.\n\t * Other approaches tend to have easy-to-make mistakes.\n\t * For example, having a separate initialization function means apps can forget to call it, making an app that can only open existing documents,\n\t * or call it unconditionally leaving an app that can only create new documents.\n\t * It also would require the schema to be passed into separate places and could cause issues if they didn't match.\n\t * Since the initialization function couldn't return a typed tree, the type checking wouldn't help catch that.\n\t * Also, if an app manages to create a document, but the initialization fails to get persisted, an app that only calls the initialization function\n\t * on the create code-path (for example how a schematized factory might do it),\n\t * would leave the document in an unusable state which could not be repaired when it is reopened (by the same or other clients).\n\t * Additionally, once out of schema content adapters are properly supported (with lazy document updates),\n\t * this initialization could become just another out of schema content adapter and this initialization is no longer a special case.\n\t */\n\tviewWith<TRoot extends ImplicitFieldSchema>(\n\t\tconfig: TreeViewConfiguration<TRoot>,\n\t): TreeView<TRoot>;\n}\n\n/**\n * Options when constructing a tree view.\n * @public\n */\nexport interface ITreeConfigurationOptions {\n\t/**\n\t * If `true`, the tree will validate new content against its stored schema at insertion time\n\t * and throw an error if the new content doesn't match the expected schema.\n\t *\n\t * @defaultValue `false`.\n\t *\n\t * @remarks Enabling schema validation has a performance penalty when inserting new content into the tree because\n\t * additional checks are done. Enable this option only in scenarios where you are ok with that operation being a\n\t * bit slower.\n\t */\n\tenableSchemaValidation?: boolean;\n}\n\nconst defaultTreeConfigurationOptions: Required<ITreeConfigurationOptions> = {\n\tenableSchemaValidation: false,\n};\n\n/**\n * Property-bag configuration for {@link TreeViewConfiguration} construction.\n * @public\n */\nexport interface ITreeViewConfiguration<\n\tTSchema extends ImplicitFieldSchema = ImplicitFieldSchema,\n> {\n\t/**\n\t * The schema which the application wants to view the tree with.\n\t */\n\treadonly schema: TSchema;\n\n\t/**\n\t * If `true`, the tree will validate new content against its stored schema at insertion time\n\t * and throw an error if the new content doesn't match the expected schema.\n\t *\n\t * @defaultValue `false`.\n\t *\n\t * @remarks Enabling schema validation has a performance penalty when inserting new content into the tree because\n\t * additional checks are done. Enable this option only in scenarios where you are ok with that operation being a\n\t * bit slower.\n\t */\n\treadonly enableSchemaValidation?: boolean;\n}\n\n/**\n * Configuration for {@link ITree.viewWith}.\n * @sealed @public\n */\nexport class TreeViewConfiguration<TSchema extends ImplicitFieldSchema = ImplicitFieldSchema>\n\timplements Required<ITreeViewConfiguration<TSchema>>\n{\n\t/**\n\t * {@inheritDoc ITreeViewConfiguration.schema}\n\t */\n\tpublic readonly schema: TSchema;\n\n\t/**\n\t * {@inheritDoc ITreeViewConfiguration.enableSchemaValidation}\n\t */\n\tpublic readonly enableSchemaValidation: boolean;\n\n\t/**\n\t * @param props - Property bag of configuration options.\n\t */\n\tpublic constructor(props: ITreeViewConfiguration<TSchema>) {\n\t\tconst config = { ...defaultTreeConfigurationOptions, ...props };\n\t\tthis.schema = config.schema;\n\t\tthis.enableSchemaValidation = config.enableSchemaValidation;\n\t}\n}\n\n/**\n * An editable view of a (version control style) branch of a shared tree based on some schema.\n *\n * This schema--known as the view schema--may or may not align the stored schema of the document.\n * Information about discrepancies between the two schemas is available via {@link TreeView.compatibility | compatibility}.\n *\n * Application authors are encouraged to read [schema-evolution.md](../../docs/user-facing/schema-evolution.md) and\n * choose a schema compatibility policy that aligns with their application's needs.\n *\n * @privateRemarks\n * From an API design perspective, `upgradeSchema` could be merged into `viewWith` and/or `viewWith` could return errors explicitly on incompatible documents.\n * Such approaches would make it discoverable that out of schema handling may need to be done.\n * Doing that would however complicate trivial \"hello world\" style example slightly, as well as be a breaking API change.\n * It also seems more complex to handle invalidation with that pattern.\n * Thus this design was chosen at the risk of apps blindly accessing `root` then breaking unexpectedly when the document is incompatible.\n * @sealed @public\n */\nexport interface TreeView<TSchema extends ImplicitFieldSchema> extends IDisposable {\n\t/**\n\t * The current root of the tree.\n\t *\n\t * If the view schema not sufficiently compatible with the stored schema, accessing this will throw.\n\t * To handle this case, check {@link TreeView.compatibility | compatibility}'s {@link SchemaCompatibilityStatus.canView | canView} before using.\n\t *\n\t * To get notified about changes to this field,\n\t * use {@link TreeViewEvents.rootChanged} via `view.events.on(\"rootChanged\", callback)`.\n\t *\n\t * To get notified about changes to stored schema (which may affect compatibility between this view's schema and\n\t * the stored schema), use {@link TreeViewEvents.schemaChanged} via `view.events.on(\"schemaChanged\", callback)`.\n\t */\n\tget root(): TreeFieldFromImplicitField<TSchema>;\n\n\tset root(newRoot: InsertableTreeFieldFromImplicitField<TSchema>);\n\n\t/**\n\t * Description of the current compatibility status between the view schema and stored schema.\n\t *\n\t * {@link TreeViewEvents.schemaChanged} is fired when the compatibility status changes.\n\t */\n\treadonly compatibility: SchemaCompatibilityStatus;\n\n\t/**\n\t * When the schemas are not an exact match and {@link SchemaCompatibilityStatus.canUpgrade} is true,\n\t * this can be used to modify the stored schema to make it match the view schema.\n\t * This will update the compatibility state, and allow access to `root`.\n\t * Beware that this may impact other clients' ability to view the document depending on the application's schema compatibility policy!\n\t * @remarks\n\t * It is an error to call this when {@link SchemaCompatibilityStatus.canUpgrade} is false, and a no-op when the stored and view schema are already an exact match.\n\t * @privateRemarks\n\t * In the future, more upgrade options could be provided here.\n\t * Some options that could be added:\n\t * - check the actual document contents (not just the schema) and attempt an atomic document update if the data is compatible.\n\t * - apply converters and upgrade the document.\n\t * - apply converters to lazily to adapt the document to the requested view schema (with optional lazy schema updates or transparent conversions on write).\n\t */\n\tupgradeSchema(): void;\n\n\t/**\n\t * Initialize the tree, setting the stored schema to match this view's schema and setting the tree content.\n\t *\n\t * Only valid to call when this view's {@link SchemaCompatibilityStatus.canInitialize} is true.\n\t *\n\t * Applications should typically call this function before attaching a `SharedTree`.\n\t * @param content - The content to initialize the tree with.\n\t */\n\tinitialize(content: InsertableTreeFieldFromImplicitField<TSchema>): void;\n\n\t/**\n\t * Events for the tree.\n\t */\n\treadonly events: Listenable<TreeViewEvents>;\n}\n\n/**\n * Information about a view schema's compatibility with the document's stored schema.\n *\n * See SharedTree's README for more information about choosing a compatibility policy.\n * @sealed @public\n */\nexport interface SchemaCompatibilityStatus {\n\t/**\n\t * Whether the view schema allows exactly the same set of documents as the stored schema.\n\t *\n\t * @remarks\n\t * Equivalence here is defined in terms of allowed documents because there are some degenerate cases where schemas are not\n\t * exact matches in a strict (schema-based) sense but still allow the same documents, and the document notion is more useful to applications.\n\t *\n\t * Examples which are expressible where this may occur include:\n\t * - schema repository `A` has extra schema which schema `B` doesn't have, but they are unused (i.e. not reachable from the root schema)\n\t * - field in schema `A` has allowed field members which the corresponding field in schema `B` does not have, but those types are not constructible (ex: an object node type containing a required field with no allowed types)\n\t *\n\t * These cases are typically not interesting to applications.\n\t */\n\treadonly isEquivalent: boolean;\n\n\t/**\n\t * Whether the current view schema is sufficiently compatible with the stored schema to allow viewing tree data.\n\t * If false, {@link TreeView.root} will throw upon access.\n\t *\n\t * Currently, this field is true iff `isEquivalent` is true.\n\t * Do not rely on this:\n\t * there are near-term plans to extend support for viewing documents when the stored schema contains additional optional fields not present in the view schema.\n\t * The other two types of backward-compatible changes (field relaxations and addition of allowed field types) will eventually be supported as well,\n\t * likely through out-of-schema content adapters that the application can provide alongside their view schema.\n\t *\n\t * Be aware that even with these SharedTree limitations fixed, application logic may not correctly tolerate the documents allowable by the stored schema!\n\t * Application authors are encouraged to read docs/user-facing/schema-evolution.md and choose a schema compatibility policy that\n\t * aligns with their application's needs.\n\t *\n\t * @remarks\n\t * When the documents allowed by the view schema is a strict superset of those by the stored schema,\n\t * this is false because writes to the document using the view schema could make the document violate its stored schema.\n\t * In this case, the stored schema could be updated to match the provided view schema, allowing read-write access to the tree.\n\t * See {@link SchemaCompatibilityStatus.canUpgrade}.\n\t *\n\t * Future version of SharedTree may provide readonly access to the document in this case because that would be safe,\n\t * but this is not currently supported.\n\t *\n\t * @privateRemarks\n\t * A necessary condition for this to be true is that the documents allowed by the view schema are a subset of those allowed by the stored schema.\n\t * This is not sufficient: the simple-tree layer's read APIs do not tolerate out-of-schema data.\n\t * For example, if the view schema for a node has a required `Point` field but the stored schema has an optional `Point` field,\n\t * read APIs on the view schema do not work correctly when the document has a node with a missing `Point` field.\n\t * Similar issues happen when the view schema has a field with less allowed types than the stored schema and the document actually leverages those types.\n\t */\n\treadonly canView: boolean;\n\n\t/**\n\t * True iff the view schema supports all possible documents permitted by the stored schema.\n\t * When true, it is valid to call {@link TreeView.upgradeSchema} (though if the stored schema is already an exact match, this is a no-op).\n\t */\n\treadonly canUpgrade: boolean;\n\n\t/**\n\t * True iff the document is uninitialized (i.e. it has no schema and no content).\n\t *\n\t * To initialize the document, call {@link TreeView.initialize}.\n\t *\n\t * @remarks\n\t * It's not necessary to check this field before calling {@link TreeView.initialize} in most scenarios; application authors typically know from\n\t * context that they're in a flow which creates a new `SharedTree` and would like to initialize it.\n\t */\n\treadonly canInitialize: boolean;\n\n\t// TODO: Consider extending this status to include:\n\t// - application-defined metadata about the stored schema\n\t// - details about the differences between the stored and view schema sufficient for implementing \"safe mismatch\" policies\n}\n\n/**\n * Events for {@link TreeView}.\n * @sealed @public\n */\nexport interface TreeViewEvents {\n\t/**\n\t * Raised whenever {@link TreeView.root} is invalidated.\n\t *\n\t * This includes changes to the document schema.\n\t * It also includes changes to the field containing the root such as setting or clearing an optional root or changing which node is the root.\n\t * This does NOT include changes to the content (fields/children) of the root node: for that case subscribe to events on the root node.\n\t */\n\trootChanged(): void;\n\n\t/**\n\t * The stored schema for the document has changed.\n\t * This may affect the compatibility between the view schema and the stored schema, and thus the ability to use the view.\n\t *\n\t * @remarks\n\t * This event implies that the old {@link TreeView.root} is no longer valid, but applications need not handle that separately:\n\t * {@link TreeViewEvents.rootChanged} will be fired after this event.\n\t */\n\tschemaChanged(): void;\n\n\t/**\n\t * Fired when:\n\t * - a local commit is applied outside of a transaction\n\t * - a local transaction is committed\n\t *\n\t * The event is not fired when:\n\t * - a local commit is applied within a transaction\n\t * - a remote commit is applied\n\t *\n\t * @param data - information about the commit that was applied\n\t * @param getRevertible - a function provided that allows users to get a revertible for the commit that was applied. If not provided,\n\t * this commit is not revertible.\n\t */\n\tcommitApplied(data: CommitMetadata, getRevertible?: RevertibleFactory): void;\n}\n"]}
|
package/dist/treeFactory.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare class TreeFactory implements IChannelFactory<ITree> {
|
|
|
23
23
|
/**
|
|
24
24
|
* SharedTree is a hierarchical data structure for collaboratively editing strongly typed JSON-like trees
|
|
25
25
|
* of objects, arrays, and other data types.
|
|
26
|
-
* @
|
|
26
|
+
* @internal
|
|
27
27
|
*/
|
|
28
28
|
export declare const SharedTree: ISharedObjectKind<ITree> & SharedObjectKind<ITree>;
|
|
29
29
|
/**
|
package/dist/treeFactory.js
CHANGED
|
@@ -40,7 +40,7 @@ TreeFactory.attributes = {
|
|
|
40
40
|
/**
|
|
41
41
|
* SharedTree is a hierarchical data structure for collaboratively editing strongly typed JSON-like trees
|
|
42
42
|
* of objects, arrays, and other data types.
|
|
43
|
-
* @
|
|
43
|
+
* @internal
|
|
44
44
|
*/
|
|
45
45
|
exports.SharedTree = configuredSharedTree({});
|
|
46
46
|
/**
|
package/dist/treeFactory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"treeFactory.js","sourceRoot":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ACD,OAAO,IAAA,iCAAsB,EAAQ,iBAAiB,CAAC,CAAC;AACzD,CAAC;AATD,oDASC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tIChannelAttributes,\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport type { SharedObjectKind } from \"@fluidframework/shared-object-base\";\nimport {\n\ttype ISharedObjectKind,\n\tcreateSharedObjectKind,\n} from \"@fluidframework/shared-object-base/internal\";\n\nimport { pkgVersion } from \"./packageVersion.js\";\nimport { SharedTree as SharedTreeImpl, type SharedTreeOptions } from \"./shared-tree/index.js\";\nimport type { ITree } from \"./simple-tree/index.js\";\n\n/**\n * A channel factory that creates an {@link ITree}.\n */\nexport class TreeFactory implements IChannelFactory<ITree> {\n\tpublic static readonly Type = \"https://graph.microsoft.com/types/tree\";\n\tpublic static readonly attributes: IChannelAttributes = {\n\t\ttype: this.Type,\n\t\tsnapshotFormatVersion: \"0.0.0\",\n\t\tpackageVersion: pkgVersion,\n\t};\n\n\tpublic readonly type = TreeFactory.Type;\n\tpublic readonly attributes: IChannelAttributes = TreeFactory.attributes;\n\n\tpublic constructor(private readonly options: SharedTreeOptions) {}\n\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tchannelAttributes: Readonly<IChannelAttributes>,\n\t): Promise<SharedTreeImpl> {\n\t\tconst tree = new SharedTreeImpl(id, runtime, channelAttributes, this.options);\n\t\tawait tree.load(services);\n\t\treturn tree;\n\t}\n\n\tpublic create(runtime: IFluidDataStoreRuntime, id: string): SharedTreeImpl {\n\t\tconst tree = new SharedTreeImpl(id, runtime, this.attributes, this.options);\n\t\ttree.initializeLocal();\n\t\treturn tree;\n\t}\n}\n\n/**\n * SharedTree is a hierarchical data structure for collaboratively editing strongly typed JSON-like trees\n * of objects, arrays, and other data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C,KAAK,CAAC,OAAO,CAAC,CAAC;QAChB,CAAC;KACD;IACD,OAAO,IAAA,iCAAsB,EAAQ,iBAAiB,CAAC,CAAC;AACzD,CAAC;AATD,oDASC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tIChannelAttributes,\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport type { SharedObjectKind } from \"@fluidframework/shared-object-base\";\nimport {\n\ttype ISharedObjectKind,\n\tcreateSharedObjectKind,\n} from \"@fluidframework/shared-object-base/internal\";\n\nimport { pkgVersion } from \"./packageVersion.js\";\nimport { SharedTree as SharedTreeImpl, type SharedTreeOptions } from \"./shared-tree/index.js\";\nimport type { ITree } from \"./simple-tree/index.js\";\n\n/**\n * A channel factory that creates an {@link ITree}.\n */\nexport class TreeFactory implements IChannelFactory<ITree> {\n\tpublic static readonly Type = \"https://graph.microsoft.com/types/tree\";\n\tpublic static readonly attributes: IChannelAttributes = {\n\t\ttype: this.Type,\n\t\tsnapshotFormatVersion: \"0.0.0\",\n\t\tpackageVersion: pkgVersion,\n\t};\n\n\tpublic readonly type = TreeFactory.Type;\n\tpublic readonly attributes: IChannelAttributes = TreeFactory.attributes;\n\n\tpublic constructor(private readonly options: SharedTreeOptions) {}\n\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tchannelAttributes: Readonly<IChannelAttributes>,\n\t): Promise<SharedTreeImpl> {\n\t\tconst tree = new SharedTreeImpl(id, runtime, channelAttributes, this.options);\n\t\tawait tree.load(services);\n\t\treturn tree;\n\t}\n\n\tpublic create(runtime: IFluidDataStoreRuntime, id: string): SharedTreeImpl {\n\t\tconst tree = new SharedTreeImpl(id, runtime, this.attributes, this.options);\n\t\ttree.initializeLocal();\n\t\treturn tree;\n\t}\n}\n\n/**\n * SharedTree is a hierarchical data structure for collaboratively editing strongly typed JSON-like trees\n * of objects, arrays, and other data types.\n * @internal\n */\nexport const SharedTree = configuredSharedTree({});\n\n/**\n * {@link SharedTree} but allowing a non-default configuration.\n * @remarks\n * This is useful for debugging and testing to opt into extra validation or see if opting out of some optimizations fixes an issue.\n * @example\n * ```typescript\n * import {\n * \tForestType,\n * \tTreeCompressionStrategy,\n * \tconfiguredSharedTree,\n * \ttypeboxValidator,\n * \t// eslint-disable-next-line import/no-internal-modules\n * } from \"@fluidframework/tree/internal\";\n * const SharedTree = configuredSharedTree({\n * \tforest: ForestType.Reference,\n * \tjsonValidator: typeboxValidator,\n * \ttreeEncodeType: TreeCompressionStrategy.Uncompressed,\n * });\n * ```\n * @privateRemarks\n * TODO:\n * Expose Ajv validator for better error message quality somehow.\n * Maybe as part of a test utils or dev-tool package?\n * @internal\n */\nexport function configuredSharedTree(\n\toptions: SharedTreeOptions,\n): ISharedObjectKind<ITree> & SharedObjectKind<ITree> {\n\tclass ConfiguredFactory extends TreeFactory {\n\t\tpublic constructor() {\n\t\t\tsuper(options);\n\t\t}\n\t}\n\treturn createSharedObjectKind<ITree>(ConfiguredFactory);\n}\n"]}
|
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
+
import type { Brand } from "./brand.js";
|
|
6
|
+
import type { Opaque } from "./opaque.js";
|
|
5
7
|
import type { Invariant } from "./typeCheck.js";
|
|
6
8
|
/**
|
|
7
9
|
* Key in a {@link BrandedMapSubset}.
|
|
10
|
+
* @remarks
|
|
11
|
+
* Due to the `TContent` type parameter being invariant (which it has to be since keys are used to both read and write data),
|
|
12
|
+
* generic collections end up needing to constrain their key's `TContent` to `any`.
|
|
8
13
|
* @internal
|
|
9
14
|
*/
|
|
10
15
|
export type BrandedKey<TKey, TContent> = TKey & Invariant<TContent>;
|
|
@@ -36,11 +41,13 @@ export interface BrandedMapSubset<K extends BrandedKey<unknown, any>> {
|
|
|
36
41
|
}
|
|
37
42
|
/**
|
|
38
43
|
* Version of {@link getOrCreate} with better typing for {@link BrandedMapSubset}.
|
|
44
|
+
* @privateRemarks
|
|
45
|
+
* Only infers type from key to avoid inferring `any` from map's key.
|
|
39
46
|
*/
|
|
40
|
-
export declare function getOrCreateSlotContent<
|
|
47
|
+
export declare function getOrCreateSlotContent<K, V>(map: NoInfer<BrandedMapSubset<BrandedKey<K, V>>>, key: BrandedKey<K, V>, defaultValue: NoInfer<(key: BrandedKey<K, V>) => V>): V;
|
|
41
48
|
/**
|
|
42
49
|
* Define a strongly typed slot in which data can be stored in a {@link BrandedMapSubset}.
|
|
43
50
|
* @internal
|
|
44
51
|
*/
|
|
45
|
-
export declare function brandedSlot<TSlot extends BrandedKey<
|
|
52
|
+
export declare function brandedSlot<TSlot extends BrandedKey<number | Opaque<Brand<number, string>>, any>>(): TSlot;
|
|
46
53
|
//# sourceMappingURL=brandedMap.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brandedMap.d.ts","sourceRoot":"","sources":["../../src/util/brandedMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD
|
|
1
|
+
{"version":3,"file":"brandedMap.d.ts","sourceRoot":"","sources":["../../src/util/brandedMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,CAAC,IAAI,EAAE,QAAQ,IAAI,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAEpE;;GAEG;AAEH,MAAM,MAAM,iB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9
|
/**
|
|
10
10
|
* Version of {@link getOrCreate} with better typing for {@link BrandedMapSubset}.
|
|
11
|
+
* @privateRemarks
|
|
12
|
+
* Only infers type from key to avoid inferring `any` from map's key.
|
|
11
13
|
*/
|
|
12
14
|
function getOrCreateSlotContent(map, key, defaultValue) {
|
|
13
|
-
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
15
|
-
return result;
|
|
15
|
+
return (0, utils_js_1.getOrCreate)(map, key, defaultValue);
|
|
16
16
|
}
|
|
17
17
|
exports.getOrCreateSlotContent = getOrCreateSlotContent;
|
|
18
18
|
/**
|
|
@@ -25,7 +25,6 @@ let slotCounter = 0;
|
|
|
25
25
|
* Define a strongly typed slot in which data can be stored in a {@link BrandedMapSubset}.
|
|
26
26
|
* @internal
|
|
27
27
|
*/
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
28
|
function brandedSlot() {
|
|
30
29
|
return slotCounter++;
|
|
31
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brandedMap.js","sourceRoot":"","sources":["../../src/util/brandedMap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"brandedMap.js","sourceRoot":"","sources":["../../src/util/brandedMap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,yCAAyC;AA8CzC;;;;GAIG;AACH,SAAgB,sBAAsB,CACrC,GAAgD,EAChD,GAAqB,EACrB,YAAmD;IAEnD,OAAO,IAAA,sBAAW,EAAsB,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;AACjE,CAAC;AAND,wDAMC;AAED;;;;GAIG;AACH,IAAI,WAAW,GAAG,CAAC,CAAC;AAEpB;;;GAGG;AACH,SAAgB,WAAW;IAK1B,OAAO,WAAW,EAAW,CAAC;AAC/B,CAAC;AAND,kCAMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { Brand } from \"./brand.js\";\nimport type { Opaque } from \"./opaque.js\";\nimport type { Invariant } from \"./typeCheck.js\";\nimport { getOrCreate } from \"./utils.js\";\n\n/**\n * Key in a {@link BrandedMapSubset}.\n * @remarks\n * Due to the `TContent` type parameter being invariant (which it has to be since keys are used to both read and write data),\n * generic collections end up needing to constrain their key's `TContent` to `any`.\n * @internal\n */\nexport type BrandedKey<TKey, TContent> = TKey & Invariant<TContent>;\n\n/**\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type BrandedKeyContent<TKey extends BrandedKey<unknown, any>> = TKey extends BrandedKey<\n\tunknown,\n\tinfer TContent\n>\n\t? TContent\n\t: never;\n\n/**\n * A Map where the keys carry the types of values which they correspond to.\n *\n * Example usage:\n * ```typescript\n * type FooSlot<TContent> = BrandedKey<Opaque<Brand<number, \"FooSlot\">>, TContent>;\n * const counterSlot = brandedSlot<FooSlot<number>>();\n * const slots: BrandedMapSubset<FooSlot<any>> = new Map();\n * slots.set(counterSlot, slots.get(counterSlot) ?? 0 + 1);\n * ```\n *\n * @remarks\n * These APIs are designed so that a Map can be used to implement this type.\n *\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface BrandedMapSubset<K extends BrandedKey<unknown, any>> {\n\tget<K2 extends K>(key: K2): BrandedKeyContent<K2> | undefined;\n\thas(key: K): boolean;\n\tset<K2 extends K>(key: K2, value: BrandedKeyContent<K2>): this;\n\tdelete(key: K): boolean;\n}\n\n/**\n * Version of {@link getOrCreate} with better typing for {@link BrandedMapSubset}.\n * @privateRemarks\n * Only infers type from key to avoid inferring `any` from map's key.\n */\nexport function getOrCreateSlotContent<K, V>(\n\tmap: NoInfer<BrandedMapSubset<BrandedKey<K, V>>>,\n\tkey: BrandedKey<K, V>,\n\tdefaultValue: NoInfer<(key: BrandedKey<K, V>) => V>,\n): V {\n\treturn getOrCreate<BrandedKey<K, V>, V>(map, key, defaultValue);\n}\n\n/**\n * A counter used to allocate unique numbers (See {@link brandedSlot}) to use as {@link BrandedKey}s.\n * This allows the keys to be small integers, which are efficient to use as keys in maps.\n * See {@link BrandedMapSubset}.\n */\nlet slotCounter = 0;\n\n/**\n * Define a strongly typed slot in which data can be stored in a {@link BrandedMapSubset}.\n * @internal\n */\nexport function brandedSlot<\n\t// See note on BrandedKey.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTSlot extends BrandedKey<number | Opaque<Brand<number, string>>, any>,\n>(): TSlot {\n\treturn slotCounter++ as TSlot;\n}\n"]}
|
|
@@ -81,7 +81,7 @@ export class AnchorSet {
|
|
|
81
81
|
* @privateRemarks
|
|
82
82
|
* This forwards to the slots of the special above root anchor which locate can't access.
|
|
83
83
|
*/
|
|
84
|
-
//
|
|
84
|
+
// See note on BrandedKey.
|
|
85
85
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
86
|
get slots() {
|
|
87
87
|
return this.root.slots;
|
|
@@ -800,7 +800,7 @@ class PathNode extends ReferenceCountedBase {
|
|
|
800
800
|
* but is possible to do.
|
|
801
801
|
*/
|
|
802
802
|
this.children = new Map();
|
|
803
|
-
//
|
|
803
|
+
// See note on BrandedKey.
|
|
804
804
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
805
805
|
this.slots = new Map();
|
|
806
806
|
}
|