@fluidframework/tree 2.0.0-rc.3.0.0 → 2.0.0-rc.3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/api-report/tree.api.md +0 -3
  2. package/dist/packageVersion.d.ts +1 -1
  3. package/dist/packageVersion.js +1 -1
  4. package/dist/packageVersion.js.map +1 -1
  5. package/dist/simple-tree/schemaFactory.d.ts +0 -4
  6. package/dist/simple-tree/schemaFactory.d.ts.map +1 -1
  7. package/dist/simple-tree/schemaFactory.js +7 -6
  8. package/dist/simple-tree/schemaFactory.js.map +1 -1
  9. package/dist/simple-tree/schemaTypes.d.ts +1 -7
  10. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  11. package/dist/simple-tree/schemaTypes.js +7 -6
  12. package/dist/simple-tree/schemaTypes.js.map +1 -1
  13. package/dist/simple-tree/toFlexSchema.d.ts.map +1 -1
  14. package/dist/simple-tree/toFlexSchema.js +2 -1
  15. package/dist/simple-tree/toFlexSchema.js.map +1 -1
  16. package/dist/simple-tree/treeApi.d.ts +0 -5
  17. package/dist/simple-tree/treeApi.d.ts.map +1 -1
  18. package/dist/simple-tree/treeApi.js +13 -10
  19. package/dist/simple-tree/treeApi.js.map +1 -1
  20. package/lib/packageVersion.d.ts +1 -1
  21. package/lib/packageVersion.js +1 -1
  22. package/lib/packageVersion.js.map +1 -1
  23. package/lib/simple-tree/schemaFactory.d.ts +0 -4
  24. package/lib/simple-tree/schemaFactory.d.ts.map +1 -1
  25. package/lib/simple-tree/schemaFactory.js +7 -6
  26. package/lib/simple-tree/schemaFactory.js.map +1 -1
  27. package/lib/simple-tree/schemaTypes.d.ts +1 -7
  28. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  29. package/lib/simple-tree/schemaTypes.js +7 -6
  30. package/lib/simple-tree/schemaTypes.js.map +1 -1
  31. package/lib/simple-tree/toFlexSchema.d.ts.map +1 -1
  32. package/lib/simple-tree/toFlexSchema.js +2 -1
  33. package/lib/simple-tree/toFlexSchema.js.map +1 -1
  34. package/lib/simple-tree/treeApi.d.ts +0 -5
  35. package/lib/simple-tree/treeApi.d.ts.map +1 -1
  36. package/lib/simple-tree/treeApi.js +15 -12
  37. package/lib/simple-tree/treeApi.js.map +1 -1
  38. package/package.json +19 -19
  39. package/src/packageVersion.ts +1 -1
  40. package/src/simple-tree/schemaFactory.ts +7 -6
  41. package/src/simple-tree/schemaTypes.ts +7 -6
  42. package/src/simple-tree/toFlexSchema.ts +2 -1
  43. package/src/simple-tree/treeApi.ts +20 -20
@@ -463,7 +463,6 @@ export type FieldKey = Brand<string, "tree.FieldKey">;
463
463
 
464
464
  // @public
465
465
  export enum FieldKind {
466
- Identifier = 2,
467
466
  Optional = 0,
468
467
  Required = 1
469
468
  }
@@ -1586,7 +1585,6 @@ export class SchemaFactory<out TScope extends string | undefined = string | unde
1586
1585
  }, false, T>;
1587
1586
  readonly boolean: TreeNodeSchema<"com.fluidframework.leaf.boolean", NodeKind.Leaf, boolean, boolean>;
1588
1587
  readonly handle: TreeNodeSchema<"com.fluidframework.leaf.handle", NodeKind.Leaf, IFluidHandle<FluidObject & IFluidLoadable>, IFluidHandle<FluidObject & IFluidLoadable>>;
1589
- get identifier(): FieldSchema<FieldKind.Identifier>;
1590
1588
  map<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchema<ScopedSchemaName<TScope, `Map<${string}>`>, NodeKind.Map, TreeMapNode<T> & WithType<ScopedSchemaName<TScope, `Map<${string}>`>>, Iterable<[string, InsertableTreeNodeFromImplicitAllowedTypes<T>]>, true, T>;
1591
1589
  map<Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Map, TreeMapNode<T> & WithType<ScopedSchemaName<TScope, Name>>, Iterable<[string, InsertableTreeNodeFromImplicitAllowedTypes<T>]>, true, T>;
1592
1590
  mapRecursive<Name extends TName, const T extends Unenforced<ImplicitAllowedTypes>>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Map, TreeMapNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>>, {
@@ -1917,7 +1915,6 @@ export interface TreeNodeApi {
1917
1915
  on<K extends keyof TreeChangeEvents>(node: TreeNode, eventName: K, listener: TreeChangeEvents[K]): () => void;
1918
1916
  parent(node: TreeNode): TreeNode | undefined;
1919
1917
  schema<T extends TreeNode | TreeLeafValue>(node: T): TreeNodeSchema<string, NodeKind, unknown, T>;
1920
- shortId(node: TreeNode): number | undefined;
1921
1918
  readonly status: (node: TreeNode) => TreeStatus;
1922
1919
  }
1923
1920
 
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/tree";
8
- export declare const pkgVersion = "2.0.0-rc.3.0.0";
8
+ export declare const pkgVersion = "2.0.0-rc.3.0.2";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -8,5 +8,5 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.pkgVersion = exports.pkgName = void 0;
10
10
  exports.pkgName = "@fluidframework/tree";
11
- exports.pkgVersion = "2.0.0-rc.3.0.0";
11
+ exports.pkgVersion = "2.0.0-rc.3.0.2";
12
12
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,sBAAsB,CAAC;AACjC,QAAA,UAAU,GAAG,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/tree\";\nexport const pkgVersion = \"2.0.0-rc.3.0.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,sBAAsB,CAAC;AACjC,QAAA,UAAU,GAAG,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/tree\";\nexport const pkgVersion = \"2.0.0-rc.3.0.2\";\n"]}
@@ -259,10 +259,6 @@ export declare class SchemaFactory<out TScope extends string | undefined = strin
259
259
  * and allows associating custom {@link FieldProps | properties} with the field.
260
260
  */
261
261
  required<const T extends ImplicitAllowedTypes>(t: T, props?: FieldProps): FieldSchema<FieldKind.Required, T>;
262
- /**
263
- * Make a field of type identifier instead of the default which is required.
264
- */
265
- get identifier(): FieldSchema<FieldKind.Identifier>;
266
262
  /**
267
263
  * {@link SchemaFactory.object} except tweaked to work better for recursive types.
268
264
  * Use with {@link ValidateRecursiveSchema} for improved type safety.
@@ -1 +1 @@
1
- {"version":3,"file":"schemaFactory.d.ts","sourceRoot":"","sources":["../../src/simple-tree/schemaFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAEN,UAAU,EAKV,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAgC,MAAM,kBAAkB,CAAC;AAW3F,OAAO,EACN,SAAS,EACT,WAAW,EACX,oBAAoB,EACpB,mBAAmB,EACnB,0CAA0C,EAC1C,QAAQ,EACR,cAAc,EACd,mBAAmB,EACnB,QAAQ,EAER,KAAK,UAAU,EACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAe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K,CAAC,CAAC,SAAS,MAAM,EACpD,cAAc,EAAE,CAAC,EACjB,YAAY,EAAE,cAAc,GAAG,SAAS,cAAc,EAAE,GACtD,GAAG,CAAC,IAAI,MAAM,GAAG,CAkBnB"}
@@ -261,12 +261,13 @@ class SchemaFactory {
261
261
  required(t, props) {
262
262
  return new schemaTypes_js_1.FieldSchema(schemaTypes_js_1.FieldKind.Required, t, props);
263
263
  }
264
- /**
265
- * Make a field of type identifier instead of the default which is required.
266
- */
267
- get identifier() {
268
- return new schemaTypes_js_1.FieldSchema(schemaTypes_js_1.FieldKind.Identifier, this.string);
269
- }
264
+ // TODO:#7734,7736: Re-enable when persisted document format is optimized
265
+ // /**
266
+ // * Make a field of type identifier instead of the default which is required.
267
+ // */
268
+ // public get identifier(): FieldSchema<FieldKind.Identifier> {
269
+ // return createFieldSchema(FieldKind.Identifier, this.string);
270
+ // }
270
271
  /**
271
272
  * {@link SchemaFactory.object} except tweaked to work better for recursive types.
272
273
  * Use with {@link ValidateRecursiveSchema} for improved type safety.
@@ -1 +1 @@
1
- {"version":3,"file":"schemaFactory.js","sourceRoot":"","sources":["../../src/simple-tree/schemaFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA8E;AAC9E,uEAAsE;AAGtE,4DAOuC;AACvC,+CAA2F;AAE3F,2DAM6B;AAC7B,6CAA0C;AAC1C,yDAA4D;AAC5D,qDAY0B;AAC1B,iDAA4D;AAC5D,yCAAsC;AACtC,mDAAiG;AACjG,6CAAsD;AAQtD,2EAAsE;AAEtE;;GAEG;AACH,SAAgB,eAAe,CAAC,KAAgB;IAC/C,QAAQ,OAAO,KAAK,EAAE;QACrB,KAAK,SAAS;YACb,OAAO,iCAAa,CAAC;QACtB,KAAK,QAAQ;YACZ,OAAO,gCAAY,CAAC;QACrB,KAAK,QAAQ;YACZ,OAAO,gCAAY,CAAC;QACrB,KAAK,QAAQ,CAAC,CAAC;YACd,IAAI,KAAK,KAAK,IAAI,EAAE;gBACnB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ED,SAAgB,cAAc,CAC7B,cAAiB,EACjB,YAAwD;IAExD,IAAI,KAAa,CAAC;IAClB,IAAI,CAAC,IAAA,0BAAe,EAAC,YAAY,CAAC,EAAE;QACnC,OAAO,cAAc,CAAC,cAAc,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;KACtD;SAAM;QACN,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAU,EAAE;YAC5C,8DAA8D;YAC9D,IAAA,iBAAM,EAAC,CAAC,IAAA,iBAAM,EAAC,CAAC,CAAC,EAAE,KAAK,CAAC,2BAA2B,CAAC,CAAC;YACtD,OAAO,CAAC,CAAC,UAAU,CAAC;QACrB,CAAC,CAAC,CAAC;QACH,mCAAmC;QACnC,KAAK,CAAC,IAAI,EAAE,CAAC;QACb,8FAA8F;QAC9F,iDAAiD;QACjD,iIAAiI;QACjI,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;KAC9B;IACD,OAAO,GAAG,cAAc,IAAI,KAAK,GAAG,CAAC;AACtC,CAAC;AArBD,wCAqBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { TreeValue } from \"../core/index.js\";\nimport {\n\tFlexTreeNode,\n\tUnenforced,\n\tisFlexTreeNode,\n\tisFluidHandle,\n\tisLazy,\n\tmarkEager,\n} from \"../feature-libraries/index.js\";\nimport { RestrictiveReadonlyRecord, getOrCreate, isReadonlyArray } from \"../util/index.js\";\n\nimport {\n\tbooleanSchema,\n\thandleSchema,\n\tnullSchema,\n\tnumberSchema,\n\tstringSchema,\n} from \"./leafNodeSchema.js\";\nimport { isTreeNode } from \"./proxies.js\";\nimport { tryGetSimpleNodeSchema } from \"./schemaCaching.js\";\nimport {\n\tFieldKind,\n\tFieldSchema,\n\tImplicitAllowedTypes,\n\tImplicitFieldSchema,\n\tInsertableTreeNodeFromImplicitAllowedTypes,\n\tNodeKind,\n\tTreeNodeSchema,\n\tTreeNodeSchemaClass,\n\tWithType,\n\ttype,\n\ttype FieldProps,\n} from \"./schemaTypes.js\";\nimport { TreeArrayNode, arraySchema } from \"./arrayNode.js\";\nimport { TreeNode } from \"./types.js\";\nimport { InsertableObjectFromSchemaRecord, TreeObjectNode, objectSchema } from \"./objectNode.js\";\nimport { TreeMapNode, mapSchema } from \"./mapNode.js\";\nimport {\n\tInsertableObjectFromSchemaRecordUnsafe,\n\tInsertableTreeNodeFromImplicitAllowedTypesUnsafe,\n\tTreeArrayNodeUnsafe,\n\tTreeMapNodeUnsafe,\n\tTreeObjectNodeUnsafe,\n} from \"./typesUnsafe.js\";\nimport { createFieldSchemaUnsafe } from \"./schemaFactoryRecursive.js\";\n\n/**\n * Gets the leaf domain schema compatible with a given {@link TreeValue}.\n */\nexport function schemaFromValue(value: TreeValue): TreeNodeSchema {\n\tswitch (typeof value) {\n\t\tcase \"boolean\":\n\t\t\treturn booleanSchema;\n\t\tcase \"number\":\n\t\t\treturn numberSchema;\n\t\tcase \"string\":\n\t\t\treturn stringSchema;\n\t\tcase \"object\": {\n\t\t\tif (value === null) {\n\t\t\t\treturn nullSchema;\n\t\t\t}\n\t\t\tassert(isFluidHandle(value), 0x87e /* invalid TreeValue */);\n\t\t\treturn handleSchema;\n\t\t}\n\t\tdefault:\n\t\t\tunreachableCase(value);\n\t}\n}\n\n/**\n * The name of a schema produced by {@link SchemaFactory}, including its optional scope prefix.\n *\n * @public\n */\nexport type ScopedSchemaName<\n\tTScope extends string | undefined,\n\tTName extends number | string,\n> = TScope extends undefined ? `${TName}` : `${TScope}.${TName}`;\n// > = `${TScope extends undefined ? \"\" : `${TScope}.`}${TName}`;\n\n// TODO:\n// SchemaFactory.array references should link to the correct overloads, however the syntax for this does not seems to work currently for methods unless the they are not qualified with the class.\n// API-Extractor requires such links to be qualified with the class, so it can't work.\n// Since linking the overload set as a whole also doesn't work, these have been made non-links for now.\n/**\n * Creates various types of {@link TreeNodeSchema|schema} for {@link TreeNode}s.\n *\n * @typeParam TScope - Scope added as a prefix to the name of every schema produced by this factory.\n * @typeParam TName - Type of names used to identify each schema produced in this factory.\n * Typically this is just `string` but it is also possible to use `string` or `number` based enums if you prefer to identify your types that way.\n *\n * @remarks\n * All schema produced by this factory get a {@link TreeNodeSchemaCore.identifier|unique identifier} by {@link ScopedSchemaName|combining} the {@link SchemaFactory.scope} with the schema's `Name`.\n * The `Name` part may be explicitly provided as a parameter, or inferred as a structural combination of the provided types.\n * The APIs which use this second approach, structural naming, also deduplicate all equivalent calls.\n * Therefor two calls to `array(allowedTypes)` with the same allowedTypes will return the same {@link TreeNodeSchema} instance.\n * On the other hand, two calls to `array(name, allowedTypes)` will always return different {@link TreeNodeSchema} instances\n * and it is an error to use both in the same tree (since their identifiers are not unique).\n *\n * Note:\n * POJO stands for Plain Old JavaScript Object.\n * This means an object that works like a `{}` style object literal.\n * In this case it means the prototype is `Object.prototype` and acts like a set of key value pairs (data, not methods).\n * The usage below generalizes this to include array and map like objects as well.\n *\n * There are two ways to use these APIs:\n * | | Customizable | POJO Emulation |\n * | ------------------- | ------------ |--------------- |\n * | Declaration | `class X extends schemaFactory.object(\"x\", {}) {}` | `const X = schemaFactory.object(\"x\", {}); type X = NodeFromSchema<typeof X>; `\n * | Allows adding \"local\" (non-persisted) members | Yes. Members (including methods) can be added to class. | No. Attempting to set non-field members will error. |\n * | Prototype | The user defined class | `Object.prototype`, `Map.prototype` or `Array.prototype` depending on node kind |\n * | Structurally named Schema | Not Supported | Supported |\n * | Explicitly named Objects | Supported | Supported |\n * | Explicitly named Maps and Arrays | Supported: Both declaration approaches can be used | Not Supported |\n * | node.js assert.deepEqual | Compares like class instances: equal to other nodes of the same type with the same content, including custom local fields. | Compares like plain objects: equal to plain JavaScript objects with the same fields, and other nodes with the same fields, even if the types are different. |\n * | IntelliSense | Shows and links to user defined class by name: `X` | Shows internal type generation logic: `object & TreeNode & ObjectFromSchemaRecord<{}> & WithType<\"test.x\">` |\n * | Recursion | Supported with special declaration patterns. | Unsupported: Generated d.ts files replace recursive references with `any`, breaking use of recursive schema across compilation boundaries |\n *\n * Note that while \"POJO Emulation\" nodes act a lot like POJO objects, they are not true POJO objects:\n *\n * - Adding new arbitrary fields will error, as well some cases of invalid edits.\n *\n * - They are implemented using proxies.\n *\n * - They have state that is not exposed via enumerable own properties, including a {@link TreeNodeSchema}.\n * This makes libraries like node.js `assert.deepEqual` fail to detect differences in type.\n *\n * - Assigning members has side effects (in this case editing the persisted/shared tree).\n *\n * - Not all operations implied by the prototype will work correctly: stick to the APIs explicitly declared in the TypeScript types.\n *\n * @privateRemarks\n * It's perfectly possible to make `POJO Emulation` mode (or even just hiding the prototype) selectable even when using the custom user class declaration syntax.\n * When doing this, it's still possible to make `instanceof` perform correctly.\n * Allowing (or banning) custom/out-of-schema properties on the class is also possible in both modes: it could be orthogonal.\n * Also for consistency, if keeping the current approach to detecting `POJO Emulation` mode it might make sense to make explicitly named Maps and Arrays do the detection the same as how object does it.\n *\n * @sealed @public\n */\nexport class SchemaFactory<\n\tout TScope extends string | undefined = string | undefined,\n\tTName extends number | string = string,\n> {\n\tprivate readonly structuralTypes: Map<string, TreeNodeSchema> = new Map();\n\n\t/**\n\t * @param scope - Prefix appended to the identifiers of all {@link TreeNodeSchema} produced by this builder.\n\t * Use of [Reverse domain name notation](https://en.wikipedia.org/wiki/Reverse_domain_name_notation) or a UUIDv4 is recommended to avoid collisions.\n\t * You may opt out of using a scope by passing `undefined`, but note that this increases the risk of collisions.\n\t */\n\tpublic constructor(public readonly scope: TScope) {}\n\n\tprivate scoped<Name extends TName | string>(name: Name): ScopedSchemaName<TScope, Name> {\n\t\treturn (this.scope === undefined ? `${name}` : `${this.scope}.${name}`) as ScopedSchemaName<\n\t\t\tTScope,\n\t\t\tName\n\t\t>;\n\t}\n\n\t/**\n\t * {@link TreeNodeSchema} for holding a JavaScript `string`.\n\t *\n\t * @remarks\n\t * Strings containing unpaired UTF-16 surrogate pair code units may not be handled correctly.\n\t *\n\t * These limitations come from the use of UTF-8 encoding of the strings, which requires them to be valid unicode.\n\t * JavaScript does not make this requirement for its strings so not all possible JavaScript strings are supported.\n\t * @privateRemarks\n\t * TODO:\n\t * We should be much more clear about what happens if you use problematic values.\n\t * We should validate and/or normalize them when inserting content.\n\t */\n\tpublic readonly string = stringSchema;\n\n\t/**\n\t * {@link TreeNodeSchema} for holding a JavaScript `number`.\n\t *\n\t * @remarks\n\t * The number is a [double-precision 64-bit binary format IEEE 754](https://en.wikipedia.org/wiki/Double-precision_floating-point_format) value, however there are some exceptions:\n\t * - `NaN`, and the infinities are converted to `null` (and may therefore only be used where `null` is allowed by the schema).\n\t * - `-0` may be converted to `0` in some cases.\n\t *\n\t * These limitations match the limitations of JSON.\n\t * @privateRemarks\n\t * TODO:\n\t * We should be much more clear about what happens if you use problematic values.\n\t * We should validate and/or normalize them when inserting content.\n\t */\n\tpublic readonly number = numberSchema;\n\n\t/**\n\t * {@link TreeNodeSchema} for holding a boolean.\n\t */\n\tpublic readonly boolean = booleanSchema;\n\n\t/**\n\t * {@link TreeNodeSchema} for JavaScript `null`.\n\t *\n\t * @remarks\n\t * There are good [reasons to avoid using null](https://www.npmjs.com/package/%40rushstack/eslint-plugin#rushstackno-new-null) in JavaScript, however sometimes it is desired.\n\t * This {@link TreeNodeSchema} node provides the option to include nulls in trees when desired.\n\t * Unless directly inter-operating with existing data using null, consider other approaches, like wrapping the value in an optional field, or using a more specifically named empty object node.\n\t */\n\tpublic readonly null = nullSchema;\n\n\t/**\n\t * {@link TreeNodeSchema} for holding an {@link @fluidframework/core-interfaces#(IFluidHandle:interface)}.\n\t */\n\tpublic readonly handle = handleSchema;\n\n\t/**\n\t * Construct a class that provides the common parts all TreeNodeSchemaClass share.\n\t * More specific schema extend this class.\n\t */\n\tprivate nodeSchema<\n\t\tconst Name extends TName | string,\n\t\tconst TKind extends NodeKind,\n\t\tT,\n\t\tconst TImplicitlyConstructable extends boolean,\n\t>(\n\t\tname: Name,\n\t\tkind: TKind,\n\t\tt: T,\n\t\timplicitlyConstructable: TImplicitlyConstructable,\n\t): TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, Name>,\n\t\tTKind,\n\t\tTreeNode & WithType<ScopedSchemaName<TScope, Name>>,\n\t\tFlexTreeNode | unknown,\n\t\tTImplicitlyConstructable,\n\t\tT\n\t> {\n\t\tconst identifier = this.scoped(name);\n\t\tclass schema extends TreeNode implements WithType<ScopedSchemaName<TScope, Name>> {\n\t\t\tpublic static readonly identifier = identifier;\n\t\t\tpublic static readonly kind = kind;\n\t\t\tpublic static readonly info = t;\n\t\t\tpublic static readonly implicitlyConstructable: TImplicitlyConstructable =\n\t\t\t\timplicitlyConstructable;\n\t\t\t/**\n\t\t\t * This constructor only does validation of the input, and should be passed the argument from the derived type unchanged.\n\t\t\t * It is up to the derived type to actually do something with this value.\n\t\t\t */\n\t\t\tpublic constructor(input: FlexTreeNode | unknown) {\n\t\t\t\tsuper();\n\t\t\t\t// Currently this just does validation. All other logic is in the subclass.\n\t\t\t\tif (isFlexTreeNode(input)) {\n\t\t\t\t\tassert(\n\t\t\t\t\t\ttryGetSimpleNodeSchema(input.schema) === this.constructor,\n\t\t\t\t\t\t0x83b /* building node with wrong schema */,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (isTreeNode(input)) {\n\t\t\t\t\t// TODO: update this once we have better support for deep-copying and move operations.\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"Existing nodes may not be used as the constructor parameter for a new node. The existing node may be used directly instead of creating a new one, used as a child of the new node (if it has not yet been inserted into the tree). If the desired result is copying the provided node, it must be deep copied (since any child node would be parented under both the new and old nodes). Currently no API is provided to make deep copies, but it can be done manually with object spreads - for example `new Foo({...oldFoo})` will work if all fields of `oldFoo` are leaf nodes.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic get [type](): ScopedSchemaName<TScope, Name> {\n\t\t\t\treturn identifier;\n\t\t\t}\n\t\t}\n\t\t// Class objects are functions (callable), so we need a strong way to distinguish between `schema` and `() => schema` when used as a `LazyItem`.\n\t\tmarkEager(schema);\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Define a {@link TreeNodeSchema} for a {@link TreeObjectNode}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t * @param fields - Schema for fields of the object node's schema. Defines what children can be placed under each key.\n\t */\n\tpublic object<\n\t\tconst Name extends TName,\n\t\tconst T extends RestrictiveReadonlyRecord<string, ImplicitFieldSchema>,\n\t>(\n\t\tname: Name,\n\t\tfields: T,\n\t): TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, Name>,\n\t\tNodeKind.Object,\n\t\tTreeObjectNode<T, ScopedSchemaName<TScope, Name>>,\n\t\tobject & InsertableObjectFromSchemaRecord<T>,\n\t\ttrue,\n\t\tT\n\t> {\n\t\treturn objectSchema(this.nodeSchema(name, NodeKind.Object, fields, true));\n\t}\n\n\t/**\n\t * Define a structurally typed {@link TreeNodeSchema} for a {@link TreeMapNode}.\n\t *\n\t * @remarks\n\t * The unique identifier for this Map is defined as a function of the provided types.\n\t * It is still scoped to this SchemaBuilder, but multiple calls with the same arguments will return the same schema object, providing somewhat structural typing.\n\t * This does not support recursive types.\n\t *\n\t * If using these structurally named maps, other types in this schema builder should avoid names of the form `Map<${string}>`.\n\t *\n\t * @example\n\t * The returned schema should be used as a schema directly:\n\t * ```typescript\n\t * const MyMap = factory.map(factory.number);\n\t * type MyMap = NodeFromSchema<typeof MyMap>;\n\t * ```\n\t * Or inline:\n\t * ```typescript\n\t * factory.object(\"Foo\", {myMap: factory.map(factory.number)});\n\t * ```\n\t * @privateRemarks\n\t * See note on array.\n\t */\n\tpublic map<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(\n\t\tallowedTypes: T,\n\t): TreeNodeSchema<\n\t\tScopedSchemaName<TScope, `Map<${string}>`>,\n\t\tNodeKind.Map,\n\t\tTreeMapNode<T> & WithType<ScopedSchemaName<TScope, `Map<${string}>`>>,\n\t\tIterable<[string, InsertableTreeNodeFromImplicitAllowedTypes<T>]>,\n\t\ttrue,\n\t\tT\n\t>;\n\n\t/**\n\t * Define a {@link TreeNodeSchema} for a {@link TreeMapNode}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t *\n\t * @example\n\t * ```typescript\n\t * class NamedMap extends factory.map(\"name\", factory.number) {}\n\t * ```\n\t */\n\tpublic map<Name extends TName, const T extends ImplicitAllowedTypes>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t): TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, Name>,\n\t\tNodeKind.Map,\n\t\tTreeMapNode<T> & WithType<ScopedSchemaName<TScope, Name>>,\n\t\tIterable<[string, InsertableTreeNodeFromImplicitAllowedTypes<T>]>,\n\t\ttrue,\n\t\tT\n\t>;\n\n\tpublic map<const T extends ImplicitAllowedTypes>(\n\t\tnameOrAllowedTypes: TName | ((T & TreeNodeSchema) | readonly TreeNodeSchema[]),\n\t\tallowedTypes?: T,\n\t): TreeNodeSchema<\n\t\tstring,\n\t\tNodeKind.Map,\n\t\tTreeMapNode<T>,\n\t\tIterable<[string, InsertableTreeNodeFromImplicitAllowedTypes<T>]>,\n\t\ttrue,\n\t\tT\n\t> {\n\t\tif (allowedTypes === undefined) {\n\t\t\tconst types = nameOrAllowedTypes as (T & TreeNodeSchema) | readonly TreeNodeSchema[];\n\t\t\tconst fullName = structuralName(\"Map\", types);\n\t\t\treturn getOrCreate(\n\t\t\t\tthis.structuralTypes,\n\t\t\t\tfullName,\n\t\t\t\t() =>\n\t\t\t\t\tthis.namedMap(\n\t\t\t\t\t\tfullName as TName,\n\t\t\t\t\t\tnameOrAllowedTypes as T,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t) as TreeNodeSchema,\n\t\t\t) as TreeNodeSchemaClass<\n\t\t\t\tstring,\n\t\t\t\tNodeKind.Map,\n\t\t\t\tTreeMapNode<T>,\n\t\t\t\tIterable<[string, InsertableTreeNodeFromImplicitAllowedTypes<T>]>,\n\t\t\t\ttrue,\n\t\t\t\tT\n\t\t\t>;\n\t\t}\n\t\treturn this.namedMap(nameOrAllowedTypes as TName, allowedTypes, true, true);\n\t}\n\n\t/**\n\t * Define a {@link TreeNodeSchema} for a {@link (TreeMapNode:interface)}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t */\n\tprivate namedMap<\n\t\tName extends TName | string,\n\t\tconst T extends ImplicitAllowedTypes,\n\t\tconst ImplicitlyConstructable extends boolean,\n\t>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t\tcustomizable: boolean,\n\t\timplicitlyConstructable: ImplicitlyConstructable,\n\t): TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, Name>,\n\t\tNodeKind.Map,\n\t\tTreeMapNode<T> & WithType<ScopedSchemaName<TScope, Name>>,\n\t\tIterable<[string, InsertableTreeNodeFromImplicitAllowedTypes<T>]>,\n\t\tImplicitlyConstructable,\n\t\tT\n\t> {\n\t\treturn mapSchema(\n\t\t\tthis.nodeSchema(name, NodeKind.Map, allowedTypes, implicitlyConstructable),\n\t\t\tcustomizable,\n\t\t);\n\t}\n\n\t/**\n\t * Define a structurally typed {@link TreeNodeSchema} for a {@link (TreeArrayNode:interface)}.\n\t *\n\t * @remarks\n\t * The identifier for this Array is defined as a function of the provided types.\n\t * It is still scoped to this SchemaFactory, but multiple calls with the same arguments will return the same schema object, providing somewhat structural typing.\n\t * This does not support recursive types.\n\t *\n\t * If using these structurally named arrays, other types in this schema builder should avoid names of the form `Array<${string}>`.\n\t *\n\t * @example\n\t * The returned schema should be used as a schema directly:\n\t * ```typescript\n\t * const MyArray = factory.array(factory.number);\n\t * type MyArray = NodeFromSchema<typeof MyArray>;\n\t * ```\n\t * Or inline:\n\t * ```typescript\n\t * factory.object(\"Foo\", {myArray: factory.array(factory.number)});\n\t * ```\n\t * @privateRemarks\n\t * The name produced at the type level here is not as specific as it could be, however doing type level sorting and escaping is a real mess.\n\t * There are cases where not having this full type provided will be less than ideal since TypeScript's structural types.\n\t * For example attempts to narrow unions of structural arrays by name won't work.\n\t * Planned future changes to move to a class based schema system as well as factor function based node construction should mostly avoid these issues,\n\t * though there may still be some problematic cases even after that work is done.\n\t *\n\t * The return value is a class, but its the type is intentionally not specific enough to indicate it is a class.\n\t * This prevents callers of this from sub-classing it, which is unlikely to work well (due to the ease of accidentally giving two different calls o this different subclasses)\n\t * when working with structural typing.\n\t *\n\t * {@label STRUCTURAL}\n\t */\n\tpublic array<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(\n\t\tallowedTypes: T,\n\t): TreeNodeSchema<\n\t\tScopedSchemaName<TScope, `Array<${string}>`>,\n\t\tNodeKind.Array,\n\t\tTreeArrayNode<T> & WithType<ScopedSchemaName<TScope, `Array<${string}>`>>,\n\t\tIterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,\n\t\ttrue,\n\t\tT\n\t>;\n\n\t/**\n\t * Define (and add to this library) a {@link TreeNodeSchemaClass} for a {@link (TreeArrayNode:interface)}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t *\n\t * @example\n\t * ```typescript\n\t * class NamedArray extends factory.array(\"name\", factory.number) {}\n\t * ```\n\t *\n\t * {@label NAMED}\n\t */\n\tpublic array<const Name extends TName, const T extends ImplicitAllowedTypes>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t): TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, Name>,\n\t\tNodeKind.Array,\n\t\tTreeArrayNode<T> & WithType<ScopedSchemaName<TScope, Name>>,\n\t\tIterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,\n\t\ttrue,\n\t\tT\n\t>;\n\n\tpublic array<const T extends ImplicitAllowedTypes>(\n\t\tnameOrAllowedTypes: TName | ((T & TreeNodeSchema) | readonly TreeNodeSchema[]),\n\t\tallowedTypes?: T,\n\t): TreeNodeSchema<\n\t\tScopedSchemaName<TScope, string>,\n\t\tNodeKind.Array,\n\t\tTreeArrayNode<T>,\n\t\tIterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,\n\t\ttrue,\n\t\tT\n\t> {\n\t\tif (allowedTypes === undefined) {\n\t\t\tconst types = nameOrAllowedTypes as (T & TreeNodeSchema) | readonly TreeNodeSchema[];\n\t\t\tconst fullName = structuralName(\"Array\", types);\n\t\t\treturn getOrCreate(this.structuralTypes, fullName, () =>\n\t\t\t\tthis.namedArray(fullName, nameOrAllowedTypes as T, false, true),\n\t\t\t) as TreeNodeSchemaClass<\n\t\t\t\tScopedSchemaName<TScope, string>,\n\t\t\t\tNodeKind.Array,\n\t\t\t\tTreeArrayNode<T>,\n\t\t\t\tIterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,\n\t\t\t\ttrue,\n\t\t\t\tT\n\t\t\t>;\n\t\t}\n\t\treturn this.namedArray(nameOrAllowedTypes as TName, allowedTypes, true, true);\n\t}\n\n\t/**\n\t * Define a {@link TreeNodeSchema} for a {@link (TreeArrayNode:interface)}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t *\n\t * @remarks\n\t * This is not intended to be used directly, use the overload of `array` which takes a name instead.\n\t * This is only public to work around a compiler limitation.\n\t */\n\tprivate namedArray<\n\t\tName extends TName | string,\n\t\tconst T extends ImplicitAllowedTypes,\n\t\tconst ImplicitlyConstructable extends boolean,\n\t>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t\tcustomizable: boolean,\n\t\timplicitlyConstructable: ImplicitlyConstructable,\n\t): TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, Name>,\n\t\tNodeKind.Array,\n\t\tTreeArrayNode<T> & WithType<ScopedSchemaName<TScope, string>>,\n\t\tIterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,\n\t\tImplicitlyConstructable,\n\t\tT\n\t> {\n\t\treturn arraySchema(\n\t\t\tthis.nodeSchema(name, NodeKind.Array, allowedTypes, implicitlyConstructable),\n\t\t\tcustomizable,\n\t\t);\n\t}\n\n\t/**\n\t * Make a field optional instead of the default, which is required.\n\t *\n\t * @param t - The types allowed under the field.\n\t * @param props - Optional properties to associate with the field.\n\t */\n\tpublic optional<const T extends ImplicitAllowedTypes>(\n\t\tt: T,\n\t\tprops?: FieldProps,\n\t): FieldSchema<FieldKind.Optional, T> {\n\t\treturn new FieldSchema(FieldKind.Optional, t, props);\n\t}\n\n\t/**\n\t * Make a field explicitly required.\n\t *\n\t * @param t - The types allowed under the field.\n\t * @param props - Optional properties to associate with the field.\n\t *\n\t * @remarks\n\t * Fields are required by default, but this API can be used to make the required nature explicit in the schema,\n\t * and allows associating custom {@link FieldProps | properties} with the field.\n\t */\n\tpublic required<const T extends ImplicitAllowedTypes>(\n\t\tt: T,\n\t\tprops?: FieldProps,\n\t): FieldSchema<FieldKind.Required, T> {\n\t\treturn new FieldSchema(FieldKind.Required, t, props);\n\t}\n\n\t/**\n\t * Make a field of type identifier instead of the default which is required.\n\t */\n\tpublic get identifier(): FieldSchema<FieldKind.Identifier> {\n\t\treturn new FieldSchema(FieldKind.Identifier, this.string);\n\t}\n\n\t/**\n\t * {@link SchemaFactory.object} except tweaked to work better for recursive types.\n\t * Use with {@link ValidateRecursiveSchema} for improved type safety.\n\t * @remarks\n\t * This version of {@link SchemaFactory.object} has fewer type constraints to work around TypeScript limitations, see {@link Unenforced}.\n\t * See {@link ValidateRecursiveSchema} for additional information about using recursive schema.\n\t *\n\t * Additionally `ImplicitlyConstructable` is disabled (forcing use of constructor) to avoid\n\t * `error TS2589: Type instantiation is excessively deep and possibly infinite.`\n\t * which otherwise gets reported at sometimes incorrect source locations that vary based on incremental builds.\n\t */\n\tpublic objectRecursive<\n\t\tconst Name extends TName,\n\t\tconst T extends Unenforced<RestrictiveReadonlyRecord<string, ImplicitFieldSchema>>,\n\t>(name: Name, t: T) {\n\t\ttype TScopedName = ScopedSchemaName<TScope, Name>;\n\t\treturn this.object(\n\t\t\tname,\n\t\t\tt as T & RestrictiveReadonlyRecord<string, ImplicitFieldSchema>,\n\t\t) as unknown as TreeNodeSchemaClass<\n\t\t\tTScopedName,\n\t\t\tNodeKind.Object,\n\t\t\tTreeObjectNodeUnsafe<T, TScopedName>,\n\t\t\tobject & InsertableObjectFromSchemaRecordUnsafe<T>,\n\t\t\tfalse,\n\t\t\tT\n\t\t>;\n\t}\n\n\t/**\n\t * {@link SchemaFactory.optional} except tweaked to work better for recursive types.\n\t * Use with {@link ValidateRecursiveSchema} for improved type safety.\n\t * @remarks\n\t * This version of {@link SchemaFactory.optional} has fewer type constraints to work around TypeScript limitations, see {@link Unenforced}.\n\t * See {@link ValidateRecursiveSchema} for additional information about using recursive schema.\n\t */\n\tpublic optionalRecursive<const T extends Unenforced<readonly (() => TreeNodeSchema)[]>>(t: T) {\n\t\treturn createFieldSchemaUnsafe(FieldKind.Optional, t);\n\t}\n\n\t/**\n\t * `SchemaFactory.array` except tweaked to work better for recursive types.\n\t * Use with {@link ValidateRecursiveSchema} for improved type safety.\n\t * @remarks\n\t * This version of `SchemaFactory.array` uses the same workarounds as {@link SchemaFactory.objectRecursive}.\n\t * See {@link ValidateRecursiveSchema} for additional information about using recursive schema.\n\t */\n\tpublic arrayRecursive<\n\t\tconst Name extends TName,\n\t\tconst T extends Unenforced<ImplicitAllowedTypes>,\n\t>(name: Name, allowedTypes: T) {\n\t\tclass RecursiveArray extends this.namedArray(\n\t\t\tname,\n\t\t\tallowedTypes as T & ImplicitAllowedTypes,\n\t\t\ttrue,\n\t\t\tfalse,\n\t\t) {\n\t\t\tpublic constructor(\n\t\t\t\tdata:\n\t\t\t\t\t| Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T & ImplicitAllowedTypes>>\n\t\t\t\t\t| FlexTreeNode,\n\t\t\t) {\n\t\t\t\tif (isFlexTreeNode(data)) {\n\t\t\t\t\tsuper(data as any);\n\t\t\t\t} else {\n\t\t\t\t\tsuper(data);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn RecursiveArray as TreeNodeSchemaClass<\n\t\t\tScopedSchemaName<TScope, Name>,\n\t\t\tNodeKind.Array,\n\t\t\tTreeArrayNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>>,\n\t\t\t{\n\t\t\t\t/**\n\t\t\t\t * Iterator for the iterable of content for this node.\n\t\t\t\t * @privateRemarks\n\t\t\t\t * Wrapping the constructor parameter for recursive arrays and maps in an inlined object type avoids (for unknown reasons)\n\t\t\t\t * the following compile error when declaring the recursive schema:\n\t\t\t\t * `Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.`\n\t\t\t\t * To benefit from this without impacting the API, the definition of `Iterable` has been inlined as such an object.\n\t\t\t\t *\n\t\t\t\t * If this workaround is kept, ideally this comment would be deduplicated with the other instance of it.\n\t\t\t\t * Unfortunately attempts to do this failed to avoid the compile error this was introduced to solve.\n\t\t\t\t */\n\t\t\t\t[Symbol.iterator](): Iterator<InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>>;\n\t\t\t},\n\t\t\tfalse,\n\t\t\tT\n\t\t>;\n\t}\n\n\t/**\n\t * `SchemaFactory.map` except tweaked to work better for recursive types.\n\t * Use with {@link ValidateRecursiveSchema} for improved type safety.\n\t * @remarks\n\t * This version of `SchemaFactory.map` uses the same workarounds as {@link SchemaFactory.objectRecursive}.\n\t * See {@link ValidateRecursiveSchema} for additional information about using recursive schema.\n\t */\n\tpublic mapRecursive<Name extends TName, const T extends Unenforced<ImplicitAllowedTypes>>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t) {\n\t\tclass MapSchema extends this.namedMap(\n\t\t\tname,\n\t\t\tallowedTypes as T & ImplicitAllowedTypes,\n\t\t\ttrue,\n\t\t\tfalse,\n\t\t) {\n\t\t\tpublic constructor(\n\t\t\t\tdata:\n\t\t\t\t\t| Iterable<\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\tstring,\n\t\t\t\t\t\t\t\tInsertableTreeNodeFromImplicitAllowedTypes<\n\t\t\t\t\t\t\t\t\tT & ImplicitAllowedTypes\n\t\t\t\t\t\t\t\t>,\n\t\t\t\t\t\t\t]\n\t\t\t\t\t >\n\t\t\t\t\t| FlexTreeNode,\n\t\t\t) {\n\t\t\t\tif (isFlexTreeNode(data)) {\n\t\t\t\t\tsuper(data as any);\n\t\t\t\t} else {\n\t\t\t\t\tsuper(new Map(data));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn MapSchema as TreeNodeSchemaClass<\n\t\t\tScopedSchemaName<TScope, Name>,\n\t\t\tNodeKind.Map,\n\t\t\tTreeMapNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>>,\n\t\t\t{\n\t\t\t\t/**\n\t\t\t\t * Iterator for the iterable of content for this node.\n\t\t\t\t * @privateRemarks\n\t\t\t\t * Wrapping the constructor parameter for recursive arrays and maps in an inlined object type avoids (for unknown reasons)\n\t\t\t\t * the following compile error when declaring the recursive schema:\n\t\t\t\t * `Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.`\n\t\t\t\t * To benefit from this without impacting the API, the definition of `Iterable` has been inlined as such an object.\n\t\t\t\t *\n\t\t\t\t * If this workaround is kept, ideally this comment would be deduplicated with the other instance of it.\n\t\t\t\t * Unfortunately attempts to do this failed to avoid the compile error this was introduced to solve.\n\t\t\t\t */\n\t\t\t\t[Symbol.iterator](): Iterator<\n\t\t\t\t\t[string, InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>]\n\t\t\t\t>;\n\t\t\t},\n\t\t\tfalse,\n\t\t\tT\n\t\t>;\n\t}\n}\n\nexport function structuralName<const T extends string>(\n\tcollectionName: T,\n\tallowedTypes: TreeNodeSchema | readonly TreeNodeSchema[],\n): `${T}<${string}>` {\n\tlet inner: string;\n\tif (!isReadonlyArray(allowedTypes)) {\n\t\treturn structuralName(collectionName, [allowedTypes]);\n\t} else {\n\t\tconst names = allowedTypes.map((t): string => {\n\t\t\t// Ensure that lazy types (functions) don't slip through here.\n\t\t\tassert(!isLazy(t), 0x83d /* invalid type provided */);\n\t\t\treturn t.identifier;\n\t\t});\n\t\t// Ensure name is order independent\n\t\tnames.sort();\n\t\t// Ensure name can't have collisions by quoting and escaping any quotes in the names of types.\n\t\t// Using JSON is a simple way to accomplish this.\n\t\t// The outer `[]` around the result are also needed so that a single type name \"Any\" would not collide with the \"any\" case above.\n\t\tinner = JSON.stringify(names);\n\t}\n\treturn `${collectionName}<${inner}>`;\n}\n"]}
1
+ {"version":3,"file":"schemaFactory.js","sourceRoot":"","sources":["../../src/simple-tree/schemaFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA8E;AAC9E,uEAAsE;AAGtE,4DAOuC;AACvC,+CAA2F;AAE3F,2DAM6B;AAC7B,6CAA0C;AAC1C,yDAA4D;AAC5D,qDAY0B;AAC1B,iDAA4D;AAC5D,yCAAsC;AACtC,mDAAiG;AACjG,6CAAsD;AAQtD,2EAAsE;AAEtE;;GAEG;AACH,SAAgB,eAAe,CAAC,KAAgB;IAC/C,QAAQ,OAAO,KAAK,EAAE;QACrB,KAAK,SAAS;YACb,OAAO,iCAAa,CAAC;QACtB,KAAK,QAAQ;YACZ,OAAO,gCAAY,CAAC;QACrB,KAAK,QAAQ;YACZ,OAAO,gCAAY,CAAC;QACrB,KAAK,QAAQ,CAAC,CAAC;YACd,IAAI,KAAK,KAAK,IAAI,EAAE;gBACnB,OAAO,8BAAU,CAAC;aAClB;YACD,IAAA,iBAAM,EAAC,IAAA,wBAAa,EAAC,KAAK,CAAC,EAAE,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC5D,OAAO,gCAAY,CAAC;SACpB;QACD;YACC,IAAA,0BAAe,EAAC,KAAK,CAAC,CAAC;KACxB;AACF,CAAC;AAlBD,0CAkBC;AAWD,iEAAiE;AAEjE,QAAQ;AACR,kMAA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M,EAAC,CAAC,IAAA,iBAAM,EAAC,CAAC,CAAC,EAAE,KAAK,CAAC,2BAA2B,CAAC,CAAC;YACtD,OAAO,CAAC,CAAC,UAAU,CAAC;QACrB,CAAC,CAAC,CAAC;QACH,mCAAmC;QACnC,KAAK,CAAC,IAAI,EAAE,CAAC;QACb,8FAA8F;QAC9F,iDAAiD;QACjD,iIAAiI;QACjI,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;KAC9B;IACD,OAAO,GAAG,cAAc,IAAI,KAAK,GAAG,CAAC;AACtC,CAAC;AArBD,wCAqBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { TreeValue } from \"../core/index.js\";\nimport {\n\tFlexTreeNode,\n\tUnenforced,\n\tisFlexTreeNode,\n\tisFluidHandle,\n\tisLazy,\n\tmarkEager,\n} from \"../feature-libraries/index.js\";\nimport { RestrictiveReadonlyRecord, getOrCreate, isReadonlyArray } from \"../util/index.js\";\n\nimport {\n\tbooleanSchema,\n\thandleSchema,\n\tnullSchema,\n\tnumberSchema,\n\tstringSchema,\n} from \"./leafNodeSchema.js\";\nimport { isTreeNode } from \"./proxies.js\";\nimport { tryGetSimpleNodeSchema } from \"./schemaCaching.js\";\nimport {\n\tFieldKind,\n\tFieldSchema,\n\tImplicitAllowedTypes,\n\tImplicitFieldSchema,\n\tInsertableTreeNodeFromImplicitAllowedTypes,\n\tNodeKind,\n\tTreeNodeSchema,\n\tTreeNodeSchemaClass,\n\tWithType,\n\ttype,\n\ttype FieldProps,\n} from \"./schemaTypes.js\";\nimport { TreeArrayNode, arraySchema } from \"./arrayNode.js\";\nimport { TreeNode } from \"./types.js\";\nimport { InsertableObjectFromSchemaRecord, TreeObjectNode, objectSchema } from \"./objectNode.js\";\nimport { TreeMapNode, mapSchema } from \"./mapNode.js\";\nimport {\n\tInsertableObjectFromSchemaRecordUnsafe,\n\tInsertableTreeNodeFromImplicitAllowedTypesUnsafe,\n\tTreeArrayNodeUnsafe,\n\tTreeMapNodeUnsafe,\n\tTreeObjectNodeUnsafe,\n} from \"./typesUnsafe.js\";\nimport { createFieldSchemaUnsafe } from \"./schemaFactoryRecursive.js\";\n\n/**\n * Gets the leaf domain schema compatible with a given {@link TreeValue}.\n */\nexport function schemaFromValue(value: TreeValue): TreeNodeSchema {\n\tswitch (typeof value) {\n\t\tcase \"boolean\":\n\t\t\treturn booleanSchema;\n\t\tcase \"number\":\n\t\t\treturn numberSchema;\n\t\tcase \"string\":\n\t\t\treturn stringSchema;\n\t\tcase \"object\": {\n\t\t\tif (value === null) {\n\t\t\t\treturn nullSchema;\n\t\t\t}\n\t\t\tassert(isFluidHandle(value), 0x87e /* invalid TreeValue */);\n\t\t\treturn handleSchema;\n\t\t}\n\t\tdefault:\n\t\t\tunreachableCase(value);\n\t}\n}\n\n/**\n * The name of a schema produced by {@link SchemaFactory}, including its optional scope prefix.\n *\n * @public\n */\nexport type ScopedSchemaName<\n\tTScope extends string | undefined,\n\tTName extends number | string,\n> = TScope extends undefined ? `${TName}` : `${TScope}.${TName}`;\n// > = `${TScope extends undefined ? \"\" : `${TScope}.`}${TName}`;\n\n// TODO:\n// SchemaFactory.array references should link to the correct overloads, however the syntax for this does not seems to work currently for methods unless the they are not qualified with the class.\n// API-Extractor requires such links to be qualified with the class, so it can't work.\n// Since linking the overload set as a whole also doesn't work, these have been made non-links for now.\n/**\n * Creates various types of {@link TreeNodeSchema|schema} for {@link TreeNode}s.\n *\n * @typeParam TScope - Scope added as a prefix to the name of every schema produced by this factory.\n * @typeParam TName - Type of names used to identify each schema produced in this factory.\n * Typically this is just `string` but it is also possible to use `string` or `number` based enums if you prefer to identify your types that way.\n *\n * @remarks\n * All schema produced by this factory get a {@link TreeNodeSchemaCore.identifier|unique identifier} by {@link ScopedSchemaName|combining} the {@link SchemaFactory.scope} with the schema's `Name`.\n * The `Name` part may be explicitly provided as a parameter, or inferred as a structural combination of the provided types.\n * The APIs which use this second approach, structural naming, also deduplicate all equivalent calls.\n * Therefor two calls to `array(allowedTypes)` with the same allowedTypes will return the same {@link TreeNodeSchema} instance.\n * On the other hand, two calls to `array(name, allowedTypes)` will always return different {@link TreeNodeSchema} instances\n * and it is an error to use both in the same tree (since their identifiers are not unique).\n *\n * Note:\n * POJO stands for Plain Old JavaScript Object.\n * This means an object that works like a `{}` style object literal.\n * In this case it means the prototype is `Object.prototype` and acts like a set of key value pairs (data, not methods).\n * The usage below generalizes this to include array and map like objects as well.\n *\n * There are two ways to use these APIs:\n * | | Customizable | POJO Emulation |\n * | ------------------- | ------------ |--------------- |\n * | Declaration | `class X extends schemaFactory.object(\"x\", {}) {}` | `const X = schemaFactory.object(\"x\", {}); type X = NodeFromSchema<typeof X>; `\n * | Allows adding \"local\" (non-persisted) members | Yes. Members (including methods) can be added to class. | No. Attempting to set non-field members will error. |\n * | Prototype | The user defined class | `Object.prototype`, `Map.prototype` or `Array.prototype` depending on node kind |\n * | Structurally named Schema | Not Supported | Supported |\n * | Explicitly named Objects | Supported | Supported |\n * | Explicitly named Maps and Arrays | Supported: Both declaration approaches can be used | Not Supported |\n * | node.js assert.deepEqual | Compares like class instances: equal to other nodes of the same type with the same content, including custom local fields. | Compares like plain objects: equal to plain JavaScript objects with the same fields, and other nodes with the same fields, even if the types are different. |\n * | IntelliSense | Shows and links to user defined class by name: `X` | Shows internal type generation logic: `object & TreeNode & ObjectFromSchemaRecord<{}> & WithType<\"test.x\">` |\n * | Recursion | Supported with special declaration patterns. | Unsupported: Generated d.ts files replace recursive references with `any`, breaking use of recursive schema across compilation boundaries |\n *\n * Note that while \"POJO Emulation\" nodes act a lot like POJO objects, they are not true POJO objects:\n *\n * - Adding new arbitrary fields will error, as well some cases of invalid edits.\n *\n * - They are implemented using proxies.\n *\n * - They have state that is not exposed via enumerable own properties, including a {@link TreeNodeSchema}.\n * This makes libraries like node.js `assert.deepEqual` fail to detect differences in type.\n *\n * - Assigning members has side effects (in this case editing the persisted/shared tree).\n *\n * - Not all operations implied by the prototype will work correctly: stick to the APIs explicitly declared in the TypeScript types.\n *\n * @privateRemarks\n * It's perfectly possible to make `POJO Emulation` mode (or even just hiding the prototype) selectable even when using the custom user class declaration syntax.\n * When doing this, it's still possible to make `instanceof` perform correctly.\n * Allowing (or banning) custom/out-of-schema properties on the class is also possible in both modes: it could be orthogonal.\n * Also for consistency, if keeping the current approach to detecting `POJO Emulation` mode it might make sense to make explicitly named Maps and Arrays do the detection the same as how object does it.\n *\n * @sealed @public\n */\nexport class SchemaFactory<\n\tout TScope extends string | undefined = string | undefined,\n\tTName extends number | string = string,\n> {\n\tprivate readonly structuralTypes: Map<string, TreeNodeSchema> = new Map();\n\n\t/**\n\t * @param scope - Prefix appended to the identifiers of all {@link TreeNodeSchema} produced by this builder.\n\t * Use of [Reverse domain name notation](https://en.wikipedia.org/wiki/Reverse_domain_name_notation) or a UUIDv4 is recommended to avoid collisions.\n\t * You may opt out of using a scope by passing `undefined`, but note that this increases the risk of collisions.\n\t */\n\tpublic constructor(public readonly scope: TScope) {}\n\n\tprivate scoped<Name extends TName | string>(name: Name): ScopedSchemaName<TScope, Name> {\n\t\treturn (this.scope === undefined ? `${name}` : `${this.scope}.${name}`) as ScopedSchemaName<\n\t\t\tTScope,\n\t\t\tName\n\t\t>;\n\t}\n\n\t/**\n\t * {@link TreeNodeSchema} for holding a JavaScript `string`.\n\t *\n\t * @remarks\n\t * Strings containing unpaired UTF-16 surrogate pair code units may not be handled correctly.\n\t *\n\t * These limitations come from the use of UTF-8 encoding of the strings, which requires them to be valid unicode.\n\t * JavaScript does not make this requirement for its strings so not all possible JavaScript strings are supported.\n\t * @privateRemarks\n\t * TODO:\n\t * We should be much more clear about what happens if you use problematic values.\n\t * We should validate and/or normalize them when inserting content.\n\t */\n\tpublic readonly string = stringSchema;\n\n\t/**\n\t * {@link TreeNodeSchema} for holding a JavaScript `number`.\n\t *\n\t * @remarks\n\t * The number is a [double-precision 64-bit binary format IEEE 754](https://en.wikipedia.org/wiki/Double-precision_floating-point_format) value, however there are some exceptions:\n\t * - `NaN`, and the infinities are converted to `null` (and may therefore only be used where `null` is allowed by the schema).\n\t * - `-0` may be converted to `0` in some cases.\n\t *\n\t * These limitations match the limitations of JSON.\n\t * @privateRemarks\n\t * TODO:\n\t * We should be much more clear about what happens if you use problematic values.\n\t * We should validate and/or normalize them when inserting content.\n\t */\n\tpublic readonly number = numberSchema;\n\n\t/**\n\t * {@link TreeNodeSchema} for holding a boolean.\n\t */\n\tpublic readonly boolean = booleanSchema;\n\n\t/**\n\t * {@link TreeNodeSchema} for JavaScript `null`.\n\t *\n\t * @remarks\n\t * There are good [reasons to avoid using null](https://www.npmjs.com/package/%40rushstack/eslint-plugin#rushstackno-new-null) in JavaScript, however sometimes it is desired.\n\t * This {@link TreeNodeSchema} node provides the option to include nulls in trees when desired.\n\t * Unless directly inter-operating with existing data using null, consider other approaches, like wrapping the value in an optional field, or using a more specifically named empty object node.\n\t */\n\tpublic readonly null = nullSchema;\n\n\t/**\n\t * {@link TreeNodeSchema} for holding an {@link @fluidframework/core-interfaces#(IFluidHandle:interface)}.\n\t */\n\tpublic readonly handle = handleSchema;\n\n\t/**\n\t * Construct a class that provides the common parts all TreeNodeSchemaClass share.\n\t * More specific schema extend this class.\n\t */\n\tprivate nodeSchema<\n\t\tconst Name extends TName | string,\n\t\tconst TKind extends NodeKind,\n\t\tT,\n\t\tconst TImplicitlyConstructable extends boolean,\n\t>(\n\t\tname: Name,\n\t\tkind: TKind,\n\t\tt: T,\n\t\timplicitlyConstructable: TImplicitlyConstructable,\n\t): TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, Name>,\n\t\tTKind,\n\t\tTreeNode & WithType<ScopedSchemaName<TScope, Name>>,\n\t\tFlexTreeNode | unknown,\n\t\tTImplicitlyConstructable,\n\t\tT\n\t> {\n\t\tconst identifier = this.scoped(name);\n\t\tclass schema extends TreeNode implements WithType<ScopedSchemaName<TScope, Name>> {\n\t\t\tpublic static readonly identifier = identifier;\n\t\t\tpublic static readonly kind = kind;\n\t\t\tpublic static readonly info = t;\n\t\t\tpublic static readonly implicitlyConstructable: TImplicitlyConstructable =\n\t\t\t\timplicitlyConstructable;\n\t\t\t/**\n\t\t\t * This constructor only does validation of the input, and should be passed the argument from the derived type unchanged.\n\t\t\t * It is up to the derived type to actually do something with this value.\n\t\t\t */\n\t\t\tpublic constructor(input: FlexTreeNode | unknown) {\n\t\t\t\tsuper();\n\t\t\t\t// Currently this just does validation. All other logic is in the subclass.\n\t\t\t\tif (isFlexTreeNode(input)) {\n\t\t\t\t\tassert(\n\t\t\t\t\t\ttryGetSimpleNodeSchema(input.schema) === this.constructor,\n\t\t\t\t\t\t0x83b /* building node with wrong schema */,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (isTreeNode(input)) {\n\t\t\t\t\t// TODO: update this once we have better support for deep-copying and move operations.\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"Existing nodes may not be used as the constructor parameter for a new node. The existing node may be used directly instead of creating a new one, used as a child of the new node (if it has not yet been inserted into the tree). If the desired result is copying the provided node, it must be deep copied (since any child node would be parented under both the new and old nodes). Currently no API is provided to make deep copies, but it can be done manually with object spreads - for example `new Foo({...oldFoo})` will work if all fields of `oldFoo` are leaf nodes.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic get [type](): ScopedSchemaName<TScope, Name> {\n\t\t\t\treturn identifier;\n\t\t\t}\n\t\t}\n\t\t// Class objects are functions (callable), so we need a strong way to distinguish between `schema` and `() => schema` when used as a `LazyItem`.\n\t\tmarkEager(schema);\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Define a {@link TreeNodeSchema} for a {@link TreeObjectNode}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t * @param fields - Schema for fields of the object node's schema. Defines what children can be placed under each key.\n\t */\n\tpublic object<\n\t\tconst Name extends TName,\n\t\tconst T extends RestrictiveReadonlyRecord<string, ImplicitFieldSchema>,\n\t>(\n\t\tname: Name,\n\t\tfields: T,\n\t): TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, Name>,\n\t\tNodeKind.Object,\n\t\tTreeObjectNode<T, ScopedSchemaName<TScope, Name>>,\n\t\tobject & InsertableObjectFromSchemaRecord<T>,\n\t\ttrue,\n\t\tT\n\t> {\n\t\treturn objectSchema(this.nodeSchema(name, NodeKind.Object, fields, true));\n\t}\n\n\t/**\n\t * Define a structurally typed {@link TreeNodeSchema} for a {@link TreeMapNode}.\n\t *\n\t * @remarks\n\t * The unique identifier for this Map is defined as a function of the provided types.\n\t * It is still scoped to this SchemaBuilder, but multiple calls with the same arguments will return the same schema object, providing somewhat structural typing.\n\t * This does not support recursive types.\n\t *\n\t * If using these structurally named maps, other types in this schema builder should avoid names of the form `Map<${string}>`.\n\t *\n\t * @example\n\t * The returned schema should be used as a schema directly:\n\t * ```typescript\n\t * const MyMap = factory.map(factory.number);\n\t * type MyMap = NodeFromSchema<typeof MyMap>;\n\t * ```\n\t * Or inline:\n\t * ```typescript\n\t * factory.object(\"Foo\", {myMap: factory.map(factory.number)});\n\t * ```\n\t * @privateRemarks\n\t * See note on array.\n\t */\n\tpublic map<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(\n\t\tallowedTypes: T,\n\t): TreeNodeSchema<\n\t\tScopedSchemaName<TScope, `Map<${string}>`>,\n\t\tNodeKind.Map,\n\t\tTreeMapNode<T> & WithType<ScopedSchemaName<TScope, `Map<${string}>`>>,\n\t\tIterable<[string, InsertableTreeNodeFromImplicitAllowedTypes<T>]>,\n\t\ttrue,\n\t\tT\n\t>;\n\n\t/**\n\t * Define a {@link TreeNodeSchema} for a {@link TreeMapNode}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t *\n\t * @example\n\t * ```typescript\n\t * class NamedMap extends factory.map(\"name\", factory.number) {}\n\t * ```\n\t */\n\tpublic map<Name extends TName, const T extends ImplicitAllowedTypes>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t): TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, Name>,\n\t\tNodeKind.Map,\n\t\tTreeMapNode<T> & WithType<ScopedSchemaName<TScope, Name>>,\n\t\tIterable<[string, InsertableTreeNodeFromImplicitAllowedTypes<T>]>,\n\t\ttrue,\n\t\tT\n\t>;\n\n\tpublic map<const T extends ImplicitAllowedTypes>(\n\t\tnameOrAllowedTypes: TName | ((T & TreeNodeSchema) | readonly TreeNodeSchema[]),\n\t\tallowedTypes?: T,\n\t): TreeNodeSchema<\n\t\tstring,\n\t\tNodeKind.Map,\n\t\tTreeMapNode<T>,\n\t\tIterable<[string, InsertableTreeNodeFromImplicitAllowedTypes<T>]>,\n\t\ttrue,\n\t\tT\n\t> {\n\t\tif (allowedTypes === undefined) {\n\t\t\tconst types = nameOrAllowedTypes as (T & TreeNodeSchema) | readonly TreeNodeSchema[];\n\t\t\tconst fullName = structuralName(\"Map\", types);\n\t\t\treturn getOrCreate(\n\t\t\t\tthis.structuralTypes,\n\t\t\t\tfullName,\n\t\t\t\t() =>\n\t\t\t\t\tthis.namedMap(\n\t\t\t\t\t\tfullName as TName,\n\t\t\t\t\t\tnameOrAllowedTypes as T,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t) as TreeNodeSchema,\n\t\t\t) as TreeNodeSchemaClass<\n\t\t\t\tstring,\n\t\t\t\tNodeKind.Map,\n\t\t\t\tTreeMapNode<T>,\n\t\t\t\tIterable<[string, InsertableTreeNodeFromImplicitAllowedTypes<T>]>,\n\t\t\t\ttrue,\n\t\t\t\tT\n\t\t\t>;\n\t\t}\n\t\treturn this.namedMap(nameOrAllowedTypes as TName, allowedTypes, true, true);\n\t}\n\n\t/**\n\t * Define a {@link TreeNodeSchema} for a {@link (TreeMapNode:interface)}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t */\n\tprivate namedMap<\n\t\tName extends TName | string,\n\t\tconst T extends ImplicitAllowedTypes,\n\t\tconst ImplicitlyConstructable extends boolean,\n\t>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t\tcustomizable: boolean,\n\t\timplicitlyConstructable: ImplicitlyConstructable,\n\t): TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, Name>,\n\t\tNodeKind.Map,\n\t\tTreeMapNode<T> & WithType<ScopedSchemaName<TScope, Name>>,\n\t\tIterable<[string, InsertableTreeNodeFromImplicitAllowedTypes<T>]>,\n\t\tImplicitlyConstructable,\n\t\tT\n\t> {\n\t\treturn mapSchema(\n\t\t\tthis.nodeSchema(name, NodeKind.Map, allowedTypes, implicitlyConstructable),\n\t\t\tcustomizable,\n\t\t);\n\t}\n\n\t/**\n\t * Define a structurally typed {@link TreeNodeSchema} for a {@link (TreeArrayNode:interface)}.\n\t *\n\t * @remarks\n\t * The identifier for this Array is defined as a function of the provided types.\n\t * It is still scoped to this SchemaFactory, but multiple calls with the same arguments will return the same schema object, providing somewhat structural typing.\n\t * This does not support recursive types.\n\t *\n\t * If using these structurally named arrays, other types in this schema builder should avoid names of the form `Array<${string}>`.\n\t *\n\t * @example\n\t * The returned schema should be used as a schema directly:\n\t * ```typescript\n\t * const MyArray = factory.array(factory.number);\n\t * type MyArray = NodeFromSchema<typeof MyArray>;\n\t * ```\n\t * Or inline:\n\t * ```typescript\n\t * factory.object(\"Foo\", {myArray: factory.array(factory.number)});\n\t * ```\n\t * @privateRemarks\n\t * The name produced at the type level here is not as specific as it could be, however doing type level sorting and escaping is a real mess.\n\t * There are cases where not having this full type provided will be less than ideal since TypeScript's structural types.\n\t * For example attempts to narrow unions of structural arrays by name won't work.\n\t * Planned future changes to move to a class based schema system as well as factor function based node construction should mostly avoid these issues,\n\t * though there may still be some problematic cases even after that work is done.\n\t *\n\t * The return value is a class, but its the type is intentionally not specific enough to indicate it is a class.\n\t * This prevents callers of this from sub-classing it, which is unlikely to work well (due to the ease of accidentally giving two different calls o this different subclasses)\n\t * when working with structural typing.\n\t *\n\t * {@label STRUCTURAL}\n\t */\n\tpublic array<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(\n\t\tallowedTypes: T,\n\t): TreeNodeSchema<\n\t\tScopedSchemaName<TScope, `Array<${string}>`>,\n\t\tNodeKind.Array,\n\t\tTreeArrayNode<T> & WithType<ScopedSchemaName<TScope, `Array<${string}>`>>,\n\t\tIterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,\n\t\ttrue,\n\t\tT\n\t>;\n\n\t/**\n\t * Define (and add to this library) a {@link TreeNodeSchemaClass} for a {@link (TreeArrayNode:interface)}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t *\n\t * @example\n\t * ```typescript\n\t * class NamedArray extends factory.array(\"name\", factory.number) {}\n\t * ```\n\t *\n\t * {@label NAMED}\n\t */\n\tpublic array<const Name extends TName, const T extends ImplicitAllowedTypes>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t): TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, Name>,\n\t\tNodeKind.Array,\n\t\tTreeArrayNode<T> & WithType<ScopedSchemaName<TScope, Name>>,\n\t\tIterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,\n\t\ttrue,\n\t\tT\n\t>;\n\n\tpublic array<const T extends ImplicitAllowedTypes>(\n\t\tnameOrAllowedTypes: TName | ((T & TreeNodeSchema) | readonly TreeNodeSchema[]),\n\t\tallowedTypes?: T,\n\t): TreeNodeSchema<\n\t\tScopedSchemaName<TScope, string>,\n\t\tNodeKind.Array,\n\t\tTreeArrayNode<T>,\n\t\tIterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,\n\t\ttrue,\n\t\tT\n\t> {\n\t\tif (allowedTypes === undefined) {\n\t\t\tconst types = nameOrAllowedTypes as (T & TreeNodeSchema) | readonly TreeNodeSchema[];\n\t\t\tconst fullName = structuralName(\"Array\", types);\n\t\t\treturn getOrCreate(this.structuralTypes, fullName, () =>\n\t\t\t\tthis.namedArray(fullName, nameOrAllowedTypes as T, false, true),\n\t\t\t) as TreeNodeSchemaClass<\n\t\t\t\tScopedSchemaName<TScope, string>,\n\t\t\t\tNodeKind.Array,\n\t\t\t\tTreeArrayNode<T>,\n\t\t\t\tIterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,\n\t\t\t\ttrue,\n\t\t\t\tT\n\t\t\t>;\n\t\t}\n\t\treturn this.namedArray(nameOrAllowedTypes as TName, allowedTypes, true, true);\n\t}\n\n\t/**\n\t * Define a {@link TreeNodeSchema} for a {@link (TreeArrayNode:interface)}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t *\n\t * @remarks\n\t * This is not intended to be used directly, use the overload of `array` which takes a name instead.\n\t * This is only public to work around a compiler limitation.\n\t */\n\tprivate namedArray<\n\t\tName extends TName | string,\n\t\tconst T extends ImplicitAllowedTypes,\n\t\tconst ImplicitlyConstructable extends boolean,\n\t>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t\tcustomizable: boolean,\n\t\timplicitlyConstructable: ImplicitlyConstructable,\n\t): TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, Name>,\n\t\tNodeKind.Array,\n\t\tTreeArrayNode<T> & WithType<ScopedSchemaName<TScope, string>>,\n\t\tIterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,\n\t\tImplicitlyConstructable,\n\t\tT\n\t> {\n\t\treturn arraySchema(\n\t\t\tthis.nodeSchema(name, NodeKind.Array, allowedTypes, implicitlyConstructable),\n\t\t\tcustomizable,\n\t\t);\n\t}\n\n\t/**\n\t * Make a field optional instead of the default, which is required.\n\t *\n\t * @param t - The types allowed under the field.\n\t * @param props - Optional properties to associate with the field.\n\t */\n\tpublic optional<const T extends ImplicitAllowedTypes>(\n\t\tt: T,\n\t\tprops?: FieldProps,\n\t): FieldSchema<FieldKind.Optional, T> {\n\t\treturn new FieldSchema(FieldKind.Optional, t, props);\n\t}\n\n\t/**\n\t * Make a field explicitly required.\n\t *\n\t * @param t - The types allowed under the field.\n\t * @param props - Optional properties to associate with the field.\n\t *\n\t * @remarks\n\t * Fields are required by default, but this API can be used to make the required nature explicit in the schema,\n\t * and allows associating custom {@link FieldProps | properties} with the field.\n\t */\n\tpublic required<const T extends ImplicitAllowedTypes>(\n\t\tt: T,\n\t\tprops?: FieldProps,\n\t): FieldSchema<FieldKind.Required, T> {\n\t\treturn new FieldSchema(FieldKind.Required, t, props);\n\t}\n\n\t// TODO:#7734,7736: Re-enable when persisted document format is optimized\n\t// /**\n\t// * Make a field of type identifier instead of the default which is required.\n\t// */\n\t// public get identifier(): FieldSchema<FieldKind.Identifier> {\n\t// \treturn createFieldSchema(FieldKind.Identifier, this.string);\n\t// }\n\n\t/**\n\t * {@link SchemaFactory.object} except tweaked to work better for recursive types.\n\t * Use with {@link ValidateRecursiveSchema} for improved type safety.\n\t * @remarks\n\t * This version of {@link SchemaFactory.object} has fewer type constraints to work around TypeScript limitations, see {@link Unenforced}.\n\t * See {@link ValidateRecursiveSchema} for additional information about using recursive schema.\n\t *\n\t * Additionally `ImplicitlyConstructable` is disabled (forcing use of constructor) to avoid\n\t * `error TS2589: Type instantiation is excessively deep and possibly infinite.`\n\t * which otherwise gets reported at sometimes incorrect source locations that vary based on incremental builds.\n\t */\n\tpublic objectRecursive<\n\t\tconst Name extends TName,\n\t\tconst T extends Unenforced<RestrictiveReadonlyRecord<string, ImplicitFieldSchema>>,\n\t>(name: Name, t: T) {\n\t\ttype TScopedName = ScopedSchemaName<TScope, Name>;\n\t\treturn this.object(\n\t\t\tname,\n\t\t\tt as T & RestrictiveReadonlyRecord<string, ImplicitFieldSchema>,\n\t\t) as unknown as TreeNodeSchemaClass<\n\t\t\tTScopedName,\n\t\t\tNodeKind.Object,\n\t\t\tTreeObjectNodeUnsafe<T, TScopedName>,\n\t\t\tobject & InsertableObjectFromSchemaRecordUnsafe<T>,\n\t\t\tfalse,\n\t\t\tT\n\t\t>;\n\t}\n\n\t/**\n\t * {@link SchemaFactory.optional} except tweaked to work better for recursive types.\n\t * Use with {@link ValidateRecursiveSchema} for improved type safety.\n\t * @remarks\n\t * This version of {@link SchemaFactory.optional} has fewer type constraints to work around TypeScript limitations, see {@link Unenforced}.\n\t * See {@link ValidateRecursiveSchema} for additional information about using recursive schema.\n\t */\n\tpublic optionalRecursive<const T extends Unenforced<readonly (() => TreeNodeSchema)[]>>(t: T) {\n\t\treturn createFieldSchemaUnsafe(FieldKind.Optional, t);\n\t}\n\n\t/**\n\t * `SchemaFactory.array` except tweaked to work better for recursive types.\n\t * Use with {@link ValidateRecursiveSchema} for improved type safety.\n\t * @remarks\n\t * This version of `SchemaFactory.array` uses the same workarounds as {@link SchemaFactory.objectRecursive}.\n\t * See {@link ValidateRecursiveSchema} for additional information about using recursive schema.\n\t */\n\tpublic arrayRecursive<\n\t\tconst Name extends TName,\n\t\tconst T extends Unenforced<ImplicitAllowedTypes>,\n\t>(name: Name, allowedTypes: T) {\n\t\tclass RecursiveArray extends this.namedArray(\n\t\t\tname,\n\t\t\tallowedTypes as T & ImplicitAllowedTypes,\n\t\t\ttrue,\n\t\t\tfalse,\n\t\t) {\n\t\t\tpublic constructor(\n\t\t\t\tdata:\n\t\t\t\t\t| Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T & ImplicitAllowedTypes>>\n\t\t\t\t\t| FlexTreeNode,\n\t\t\t) {\n\t\t\t\tif (isFlexTreeNode(data)) {\n\t\t\t\t\tsuper(data as any);\n\t\t\t\t} else {\n\t\t\t\t\tsuper(data);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn RecursiveArray as TreeNodeSchemaClass<\n\t\t\tScopedSchemaName<TScope, Name>,\n\t\t\tNodeKind.Array,\n\t\t\tTreeArrayNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>>,\n\t\t\t{\n\t\t\t\t/**\n\t\t\t\t * Iterator for the iterable of content for this node.\n\t\t\t\t * @privateRemarks\n\t\t\t\t * Wrapping the constructor parameter for recursive arrays and maps in an inlined object type avoids (for unknown reasons)\n\t\t\t\t * the following compile error when declaring the recursive schema:\n\t\t\t\t * `Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.`\n\t\t\t\t * To benefit from this without impacting the API, the definition of `Iterable` has been inlined as such an object.\n\t\t\t\t *\n\t\t\t\t * If this workaround is kept, ideally this comment would be deduplicated with the other instance of it.\n\t\t\t\t * Unfortunately attempts to do this failed to avoid the compile error this was introduced to solve.\n\t\t\t\t */\n\t\t\t\t[Symbol.iterator](): Iterator<InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>>;\n\t\t\t},\n\t\t\tfalse,\n\t\t\tT\n\t\t>;\n\t}\n\n\t/**\n\t * `SchemaFactory.map` except tweaked to work better for recursive types.\n\t * Use with {@link ValidateRecursiveSchema} for improved type safety.\n\t * @remarks\n\t * This version of `SchemaFactory.map` uses the same workarounds as {@link SchemaFactory.objectRecursive}.\n\t * See {@link ValidateRecursiveSchema} for additional information about using recursive schema.\n\t */\n\tpublic mapRecursive<Name extends TName, const T extends Unenforced<ImplicitAllowedTypes>>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t) {\n\t\tclass MapSchema extends this.namedMap(\n\t\t\tname,\n\t\t\tallowedTypes as T & ImplicitAllowedTypes,\n\t\t\ttrue,\n\t\t\tfalse,\n\t\t) {\n\t\t\tpublic constructor(\n\t\t\t\tdata:\n\t\t\t\t\t| Iterable<\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\tstring,\n\t\t\t\t\t\t\t\tInsertableTreeNodeFromImplicitAllowedTypes<\n\t\t\t\t\t\t\t\t\tT & ImplicitAllowedTypes\n\t\t\t\t\t\t\t\t>,\n\t\t\t\t\t\t\t]\n\t\t\t\t\t >\n\t\t\t\t\t| FlexTreeNode,\n\t\t\t) {\n\t\t\t\tif (isFlexTreeNode(data)) {\n\t\t\t\t\tsuper(data as any);\n\t\t\t\t} else {\n\t\t\t\t\tsuper(new Map(data));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn MapSchema as TreeNodeSchemaClass<\n\t\t\tScopedSchemaName<TScope, Name>,\n\t\t\tNodeKind.Map,\n\t\t\tTreeMapNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>>,\n\t\t\t{\n\t\t\t\t/**\n\t\t\t\t * Iterator for the iterable of content for this node.\n\t\t\t\t * @privateRemarks\n\t\t\t\t * Wrapping the constructor parameter for recursive arrays and maps in an inlined object type avoids (for unknown reasons)\n\t\t\t\t * the following compile error when declaring the recursive schema:\n\t\t\t\t * `Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.`\n\t\t\t\t * To benefit from this without impacting the API, the definition of `Iterable` has been inlined as such an object.\n\t\t\t\t *\n\t\t\t\t * If this workaround is kept, ideally this comment would be deduplicated with the other instance of it.\n\t\t\t\t * Unfortunately attempts to do this failed to avoid the compile error this was introduced to solve.\n\t\t\t\t */\n\t\t\t\t[Symbol.iterator](): Iterator<\n\t\t\t\t\t[string, InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>]\n\t\t\t\t>;\n\t\t\t},\n\t\t\tfalse,\n\t\t\tT\n\t\t>;\n\t}\n}\n\nexport function structuralName<const T extends string>(\n\tcollectionName: T,\n\tallowedTypes: TreeNodeSchema | readonly TreeNodeSchema[],\n): `${T}<${string}>` {\n\tlet inner: string;\n\tif (!isReadonlyArray(allowedTypes)) {\n\t\treturn structuralName(collectionName, [allowedTypes]);\n\t} else {\n\t\tconst names = allowedTypes.map((t): string => {\n\t\t\t// Ensure that lazy types (functions) don't slip through here.\n\t\t\tassert(!isLazy(t), 0x83d /* invalid type provided */);\n\t\t\treturn t.identifier;\n\t\t});\n\t\t// Ensure name is order independent\n\t\tnames.sort();\n\t\t// Ensure name can't have collisions by quoting and escaping any quotes in the names of types.\n\t\t// Using JSON is a simple way to accomplish this.\n\t\t// The outer `[]` around the result are also needed so that a single type name \"Any\" would not collide with the \"any\" case above.\n\t\tinner = JSON.stringify(names);\n\t}\n\treturn `${collectionName}<${inner}>`;\n}\n"]}
@@ -98,13 +98,7 @@ export declare enum FieldKind {
98
98
  * @remarks
99
99
  * Only allows exactly one child.
100
100
  */
101
- Required = 1,
102
- /**
103
- * A special field used for node identifiers.
104
- * @remarks
105
- * Only allows exactly one child.
106
- */
107
- Identifier = 2
101
+ Required = 1
108
102
  }
109
103
  /**
110
104
  * Kind of tree node.
@@ -1 +1 @@
1
- {"version":3,"file":"schemaTypes.d.ts","sourceRoot":"","sources":["../../src/simple-tree/schemaTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAI/D,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAU,MAAM,+BAA+B,CAAC;AAClF,OAAO,EAAE,WAAW,EAA0B,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,MAAM,MAAM,cAAc,CACzB,IAAI,SAAS,MAAM,GAAG,MAAM,EAC5B,IAAI,SAAS,QAAQ,GAAG,QAAQ,EAChC,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,KAAK,EACd,uBAAuB,SAAS,OAAO,GAAG,OAAO,EACjD,IAAI,GAAG,OAAO,IAEZ,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,EAAE,IAAI,CAAC,GAC7E,sBAAsB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,EAAE,IAAI,CAAC,CAAC;AAEpF;;;;;;;GAOG;AACH,MAAM,WAAW,sBAAsB,CACtC,GAAG,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM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C,SAAS,cAAc,IAAI,CAAC,SAAS,cAAc,CAC9E,MAAM,EACN,QAAQ,EACR,MAAM,KAAK,CACX,GACE,KAAK,GACL,KAAK,CAAC;AAET;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,cAAc,IACrD,CAAC,CAAC,SAAS;IAAE,uBAAuB,EAAE,IAAI,CAAA;CAAE,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAC1E,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AAEjC;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI,CAAC,SAAS,cAAc,CAC/E,MAAM,EACN,QAAQ,EACR,OAAO,EACP,MAAM,MAAM,CACZ,GACE,MAAM,GACN,KAAK,CAAC;AAET;;;GAGG;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,YAAY,GAAG,IAAI,CAAC;AAE5E;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,IAAI,EAAE,OAAO,MAAgC,CAAC;AAE3D;;;GAGG;AACH,MAAM,WAAW,QAAQ,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM;IACtD;;OAEG;IACH,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC;CACpB"}
@@ -27,12 +27,13 @@ var FieldKind;
27
27
  * Only allows exactly one child.
28
28
  */
29
29
  FieldKind[FieldKind["Required"] = 1] = "Required";
30
- /**
31
- * A special field used for node identifiers.
32
- * @remarks
33
- * Only allows exactly one child.
34
- */
35
- FieldKind[FieldKind["Identifier"] = 2] = "Identifier";
30
+ // TODO:#7734,7736: Re-enable when persisted document format is optimized
31
+ // /**
32
+ // * A special field used for node identifiers.
33
+ // * @remarks
34
+ // * Only allows exactly one child.
35
+ // */
36
+ // Identifier,
36
37
  })(FieldKind || (exports.FieldKind = FieldKind = {}));
37
38
  /**
38
39
  * Kind of tree node.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AK,GAAL,KAAK,CAAa;QAElC,IAAI,CAAC,SAAS,GAAG,IAAI,eAAI,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3E,CAAC;CACD;AArCD,kCAqCC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,MAA2B;IAC/D,OAAO,MAAM,YAAY,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC7F,CAAC;AAFD,oDAEC;AACD;;;;;;GAMG;AACH,SAAgB,qBAAqB,CAAC,KAA2B;IAChE,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC7C,IAAI,IAAA,0BAAe,EAAC,KAAK,CAAC,EAAE;QAC3B,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE;YAC7B,UAAU,CAAC,GAAG,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC;SAC7C;KACD;SAAM;QACN,UAAU,CAAC,GAAG,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;KAC1C;IACD,OAAO,UAAU,CAAC;AACnB,CAAC;AAVD,sDAUC;AAED,SAAS,kBAAkB,CAAC,KAA+B;IAC1D,MAAM,eAAe,GAAG,IAAA,iBAAM,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IACxD,IAAI,eAAe,KAAK,SAAS,EAAE;QAClC,MAAM,IAAI,qBAAU,CACnB,iHAAiH,CACjH,CAAC;KACF;IACD,OAAO,eAAe,CAAC;AACxB,CAAC;AAwHD;;;;;;;;;;;;GAYG;AACU,QAAA,IAAI,GAAkB,MAAM,CAAC,eAAe,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { Lazy } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { FlexListToUnion, LazyItem, isLazy } from \"../feature-libraries/index.js\";\nimport { MakeNominal, brand, isReadonlyArray } from \"../util/index.js\";\nimport { Unhydrated } from \"./types.js\";\nimport { FieldKey } from \"../core/index.js\";\n\n/**\n * Schema for a tree node.\n * @typeParam Name - The full (including scope) name/identifier for the schema.\n * @typeParam Kind - Which kind of node this schema is for.\n * @typeParam TNode - API for nodes that use this schema.\n * @typeParam TBuild - Data which can be used to construct an {@link Unhydrated} node of this type.\n * @typeParam Info - Data used when defining this schema.\n * @remarks\n * Captures the schema both as runtime data and compile time type information.\n * @public\n */\nexport type TreeNodeSchema<\n\tName extends string = string,\n\tKind extends NodeKind = NodeKind,\n\tTNode = unknown,\n\tTBuild = never,\n\tImplicitlyConstructable extends boolean = boolean,\n\tInfo = unknown,\n> =\n\t| TreeNodeSchemaClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>\n\t| TreeNodeSchemaNonClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>;\n\n/**\n * Schema which is not a class.\n * @remarks\n * This is used for schema which cannot have their instances constructed using constructors, like leaf schema.\n * @privateRemarks\n * Non-class based schema can have issues with recursive types due to https://github.com/microsoft/TypeScript/issues/55832.\n * @public\n */\nexport interface TreeNodeSchemaNonClass<\n\tout Name extends string = string,\n\tout Kind extends NodeKind = NodeKind,\n\tout TNode = unknown,\n\tin TInsertable = never,\n\tout ImplicitlyConstructable extends boolean = boolean,\n\tout Info = unknown,\n> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {\n\tcreate(data: TInsertable): TNode;\n}\n\n/**\n * Tree node schema which is implemented using a class.\n * @remarks\n * Instances of this class are nodes in the tree.\n * This is also a constructor so that it can be subclassed.\n *\n * Using classes in this way allows introducing a named type and a named value at the same time, helping keep the runtime and compile time information together and easy to refer to un a uniform way.\n * Additionally, this works around https://github.com/microsoft/TypeScript/issues/55832 which causes similar patterns with less explicit types to infer \"any\" in the d.ts file.\n * @public\n */\nexport interface TreeNodeSchemaClass<\n\tout Name extends string = string,\n\tout Kind extends NodeKind = NodeKind,\n\tout TNode = unknown,\n\tin TInsertable = never,\n\tout ImplicitlyConstructable extends boolean = boolean,\n\tout Info = unknown,\n> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {\n\t/**\n\t * Constructs an {@link Unhydrated} node with this schema.\n\t * @remarks\n\t * This constructor is also used internally to construct hydrated nodes with a different parameter type.\n\t * Therefor overriding this constructor is not type-safe and is not supported.\n\t * @sealed\n\t */\n\tnew (data: TInsertable): Unhydrated<TNode>;\n}\n\n/**\n * Data common to all tree node schema.\n * @public\n */\nexport interface TreeNodeSchemaCore<\n\tout Name extends string,\n\tout Kind extends NodeKind,\n\tout ImplicitlyConstructable extends boolean,\n\tout Info = unknown,\n> {\n\treadonly identifier: Name;\n\treadonly kind: Kind;\n\n\t/**\n\t * Data used to define this schema.\n\t *\n\t * @remarks\n\t * The format depends on the kind of node it is for.\n\t * For example, the \"object\" node kind could store the field schema here.\n\t */\n\treadonly info: Info;\n\n\t/**\n\t * When constructing insertable content,\n\t * data that could be passed to the node's constructor can be used instead of an {@link Unhydrated} node\n\t * iff implicitlyConstructable is true.\n\t * @privateRemarks\n\t * Currently the logic for traversing insertable content,\n\t * both to build trees and to hydrate them does not defer to the schema classes to handle the policy,\n\t * so if their constructors differ from what is supported, some cases will not work.\n\t * Setting this to false adjusts the insertable types to disallow cases which could be impacted by these inconsistencies.\n\t */\n\treadonly implicitlyConstructable: ImplicitlyConstructable;\n}\n\n/**\n * Types for use in fields.\n * @public\n */\nexport type AllowedTypes = readonly LazyItem<TreeNodeSchema>[];\n\n/**\n * Kind of a field on a node.\n * @public\n */\nexport enum FieldKind {\n\t/**\n\t * A field which can be empty or filled.\n\t * @remarks\n\t * Allows 0 or one child.\n\t */\n\tOptional,\n\t/**\n\t * A field which must always be filled.\n\t * @remarks\n\t * Only allows exactly one child.\n\t */\n\tRequired,\n\t/**\n\t * A special field used for node identifiers.\n\t * @remarks\n\t * Only allows exactly one child.\n\t */\n\tIdentifier,\n}\n\n/**\n * Kind of tree node.\n * @public\n */\nexport enum NodeKind {\n\t/**\n\t * A node which serves as a map, storing children under string keys.\n\t */\n\tMap,\n\t/**\n\t * A node which serves as an array, storing children in an ordered sequence.\n\t */\n\tArray,\n\t/**\n\t * A node which stores a heterogenous collection of children in named fields.\n\t * @remarks\n\t * Each field gets its own schema.\n\t */\n\tObject,\n\t/**\n\t * A node which stores a single leaf value.\n\t */\n\tLeaf,\n}\n\n/**\n * Maps from a view key to its corresponding {@link FieldProps.key | stored key} for the provided\n * {@link ImplicitFieldSchema | field schema}.\n *\n * @remarks\n * If an explicit stored key was specified in the schema, it will be used.\n * Otherwise, the stored key is the same as the view key.\n */\nexport function getStoredKey(viewKey: string, fieldSchema: ImplicitFieldSchema): FieldKey {\n\treturn brand(getExplicitStoredKey(fieldSchema) ?? viewKey);\n}\n\n/**\n * Gets the {@link FieldProps.key | stored key} specified by the schema, if one was explicitly specified.\n * Otherwise, returns undefined.\n */\nexport function getExplicitStoredKey(fieldSchema: ImplicitFieldSchema): string | undefined {\n\treturn fieldSchema instanceof FieldSchema ? fieldSchema.props?.key : undefined;\n}\n\n/**\n * Additional information to provide to a {@link FieldSchema}.\n *\n * @public\n */\nexport interface FieldProps {\n\t/**\n\t * The unique identifier of a field, used in the persisted form of the tree.\n\t *\n\t * @remarks\n\t * If not explicitly set via the schema, this is the same as the schema's property key.\n\t *\n\t * Specifying a stored key that differs from the property key is particularly useful in refactoring scenarios.\n\t * To update the developer-facing API, while maintaining backwards compatibility with existing SharedTree data,\n\t * you can change the property key and specify the previous property key as the stored key.\n\t *\n\t * Notes:\n\t *\n\t * - Stored keys have no impact on standard JavaScript behavior, on tree nodes. For example, `Object.keys`\n\t * will always return the property keys specified in the schema, ignoring any stored keys that differ from\n\t * the property keys.\n\t *\n\t * - When specifying stored keys in an object schema, you must ensure that the final set of stored keys\n\t * (accounting for those implicitly derived from property keys) contains no duplicates.\n\t * This is validated at runtime.\n\t *\n\t * @example Refactoring code without breaking compatibility with existing data\n\t *\n\t * Consider some existing object schema:\n\t *\n\t * ```TypeScript\n\t * class Point extends schemaFactory.object(\"Point\", {\n\t * \txPosition: schemaFactory.number,\n\t * \tyPosition: schemaFactory.number,\n\t * \tzPosition: schemaFactory.optional(schemaFactory.number),\n\t * });\n\t * ```\n\t *\n\t * Developers using nodes of this type would access the the `xPosition` property as `point.xPosition`.\n\t *\n\t * We would like to refactor the schema to omit \"Position\" from the property keys, but application data has\n\t * already been persisted using the original property keys. To maintain compatibility with existing data,\n\t * we can refactor the schema as follows:\n\t *\n\t * ```TypeScript\n\t * class Point extends schemaFactory.object(\"Point\", {\n\t * \tx: schemaFactory.required(schemaFactory.number, { key: \"xPosition\" }),\n\t * \ty: schemaFactory.required(schemaFactory.number, { key: \"yPosition\" }),\n\t * \tz: schemaFactory.optional(schemaFactory.number, { key: \"zPosition\" }),\n\t * });\n\t * ```\n\t *\n\t * Now, developers can access the `x` property as `point.x`, while existing data can still be collaborated on.\n\t *\n\t * @defaultValue If not specified, the key that is persisted is the property key that was specified in the schema.\n\t */\n\treadonly key?: string;\n}\n\n/**\n * All policy for a specific field,\n * including functionality that does not have to be kept consistent across versions or deterministic.\n *\n * This can include policy for how to use this schema for \"view\" purposes, and well as how to expose editing APIs.\n * @sealed @public\n */\nexport class FieldSchema<\n\tout Kind extends FieldKind = FieldKind,\n\tout Types extends ImplicitAllowedTypes = ImplicitAllowedTypes,\n> {\n\t/**\n\t * This class is used with instanceof, and therefore should have nominal typing.\n\t * This field enforces that.\n\t */\n\tprotected _typeCheck?: MakeNominal;\n\n\tprivate readonly lazyTypes: Lazy<ReadonlySet<TreeNodeSchema>>;\n\n\t/**\n\t * What types of tree nodes are allowed in this field.\n\t * @remarks Counterpart to {@link FieldSchema.allowedTypes}, with any lazy definitions evaluated.\n\t */\n\tpublic get allowedTypeSet(): ReadonlySet<TreeNodeSchema> {\n\t\treturn this.lazyTypes.value;\n\t}\n\n\tpublic constructor(\n\t\t/**\n\t\t * The {@link https://en.wikipedia.org/wiki/Kind_(type_theory) | kind } of this field.\n\t\t * Determines the multiplicity, viewing and editing APIs as well as the merge resolution policy.\n\t\t */\n\t\tpublic readonly kind: Kind,\n\t\t/**\n\t\t * What types of tree nodes are allowed in this field.\n\t\t */\n\t\tpublic readonly allowedTypes: Types,\n\t\t/**\n\t\t * Optional properties associated with the field.\n\t\t */\n\t\tpublic readonly props?: FieldProps,\n\t) {\n\t\tthis.lazyTypes = new Lazy(() => normalizeAllowedTypes(this.allowedTypes));\n\t}\n}\n\n/**\n * Normalizes a {@link ImplicitFieldSchema} to a {@link FieldSchema}.\n */\nexport function normalizeFieldSchema(schema: ImplicitFieldSchema): FieldSchema {\n\treturn schema instanceof FieldSchema ? schema : new FieldSchema(FieldKind.Required, schema);\n}\n/**\n * Normalizes a {@link ImplicitAllowedTypes} to a set of {@link TreeNodeSchema}s, by eagerly evaluating any\n * lazy schema declarations.\n *\n * @remarks Note: this must only be called after all required schemas have been declared, otherwise evaluation of\n * recursive schemas may fail.\n */\nexport function normalizeAllowedTypes(types: ImplicitAllowedTypes): ReadonlySet<TreeNodeSchema> {\n\tconst normalized = new Set<TreeNodeSchema>();\n\tif (isReadonlyArray(types)) {\n\t\tfor (const lazyType of types) {\n\t\t\tnormalized.add(evaluateLazySchema(lazyType));\n\t\t}\n\t} else {\n\t\tnormalized.add(evaluateLazySchema(types));\n\t}\n\treturn normalized;\n}\n\nfunction evaluateLazySchema(value: LazyItem<TreeNodeSchema>): TreeNodeSchema {\n\tconst evaluatedSchema = isLazy(value) ? value() : value;\n\tif (evaluatedSchema === undefined) {\n\t\tthrow new UsageError(\n\t\t\t`Encountered an undefined schema. This could indicate that some referenced schema has not yet been instantiated.`,\n\t\t);\n\t}\n\treturn evaluatedSchema;\n}\n\n/**\n * Types allowed in a field.\n * @remarks\n * Implicitly treats a single type as an array of one type.\n * @public\n */\nexport type ImplicitAllowedTypes = AllowedTypes | TreeNodeSchema;\n\n/**\n * Schema for a field of a tree node.\n * @remarks\n * Implicitly treats {@link ImplicitAllowedTypes} as a Required field of that type.\n * @public\n */\nexport type ImplicitFieldSchema = FieldSchema | ImplicitAllowedTypes;\n\n/**\n * Converts ImplicitFieldSchema to the corresponding tree node's field type.\n * @public\n */\nexport type TreeFieldFromImplicitField<TSchema extends ImplicitFieldSchema = FieldSchema> =\n\tTSchema extends FieldSchema<infer Kind, infer Types>\n\t\t? ApplyKind<TreeNodeFromImplicitAllowedTypes<Types>, Kind>\n\t\t: TSchema extends ImplicitAllowedTypes\n\t\t? TreeNodeFromImplicitAllowedTypes<TSchema>\n\t\t: unknown;\n\n/**\n * Type of content that can be inserted into the tree for a field of the given schema.\n * @public\n */\nexport type InsertableTreeFieldFromImplicitField<\n\tTSchema extends ImplicitFieldSchema = FieldSchema,\n> = TSchema extends FieldSchema<infer Kind, infer Types>\n\t? ApplyKind<InsertableTreeNodeFromImplicitAllowedTypes<Types>, Kind>\n\t: TSchema extends ImplicitAllowedTypes\n\t? InsertableTreeNodeFromImplicitAllowedTypes<TSchema>\n\t: unknown;\n\n/**\n * Suitable for output.\n * For input must error on side of excluding undefined instead.\n * @public\n */\nexport type ApplyKind<T, Kind extends FieldKind> = Kind extends FieldKind.Required\n\t? T\n\t: undefined | T;\n\n/**\n * Type of of tree node for a field of the given schema.\n * @public\n */\nexport type TreeNodeFromImplicitAllowedTypes<\n\tTSchema extends ImplicitAllowedTypes = TreeNodeSchema,\n> = TSchema extends TreeNodeSchema\n\t? NodeFromSchema<TSchema>\n\t: TSchema extends AllowedTypes\n\t? NodeFromSchema<FlexListToUnion<TSchema>>\n\t: unknown;\n\n/**\n * Type of content that can be inserted into the tree for a node of the given schema.\n * @public\n */\nexport type InsertableTreeNodeFromImplicitAllowedTypes<\n\tTSchema extends ImplicitAllowedTypes = TreeNodeSchema,\n> = TSchema extends TreeNodeSchema\n\t? InsertableTypedNode<TSchema>\n\t: TSchema extends AllowedTypes\n\t? InsertableTypedNode<FlexListToUnion<TSchema>>\n\t: never;\n\n/**\n * Takes in `TreeNodeSchema[]` and returns a TypedNode union.\n * @public\n */\nexport type NodeFromSchema<T extends TreeNodeSchema> = T extends TreeNodeSchema<\n\tstring,\n\tNodeKind,\n\tinfer TNode\n>\n\t? TNode\n\t: never;\n\n/**\n * Data which can be used as a node to be inserted.\n * Either an unhydrated node, or content to build a new node.\n * @public\n */\nexport type InsertableTypedNode<T extends TreeNodeSchema> =\n\t| (T extends { implicitlyConstructable: true } ? NodeBuilderData<T> : never)\n\t| Unhydrated<NodeFromSchema<T>>;\n\n/**\n * Given a node's schema, return the corresponding object from which the node could be built.\n * @privateRemarks\n * Currently this assumes factory functions take exactly one argument.\n * This could be changed if needed.\n *\n * These factory functions can also take a FlexTreeNode, but this is not exposed in the public facing types.\n * @public\n */\nexport type NodeBuilderData<T extends TreeNodeSchema> = T extends TreeNodeSchema<\n\tstring,\n\tNodeKind,\n\tunknown,\n\tinfer TBuild\n>\n\t? TBuild\n\t: never;\n\n/**\n * Value that may be stored as a leaf node.\n * @public\n */\n// eslint-disable-next-line @rushstack/no-new-null\nexport type TreeLeafValue = number | string | boolean | IFluidHandle | null;\n\n/**\n * The type of a {@link TreeNode}.\n * For moore information about the type, use `Tree.schema(theNode)` instead.\n * @remarks\n * This symbol mainly exists on nodes to allow TypeScript to provide more accurate type checking.\n * `Tree.is` and `Tree.schema` provide a superset of this information in more friendly ways.\n *\n * This symbol should not manually be added to objects as doing so allows the object to be invalidly used where nodes are expected.\n * Instead construct a real node of the desired type using its constructor.\n * @privateRemarks\n * This prevents non-nodes from being accidentally used as nodes, as well as allows the type checker to distinguish different node types.\n * @public\n */\nexport const type: unique symbol = Symbol(\"TreeNode Type\");\n\n/**\n * Adds a {@link \"type\"} field.\n * @public\n */\nexport interface WithType<TName extends string = string> {\n\t/**\n\t * {@inheritdoc \"type\"}\n\t */\n\tget [type](): TName;\n}\n"]}
1
+ {"version":3,"file":"schemaTypes.js","sourceRoot":"","sources":["../../src/simple-tree/schemaTypes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAA2D;AAC3D,uEAAsE;AAEtE,4DAAkF;AAClF,+CAAuE;AAkHvE;;;GAGG;AACH,IAAY,SAoBX;AApBD,WAAY,SAAS;IACpB;;;;OAIG;IACH,iDAAQ,CAAA;IACR;;;;OAIG;IACH,iDAAQ,CAAA;IACR,yEAAyE;IACzE,MAAM;IACN,gDAAgD;IAChD,cAAc;IACd,oCAAoC;IACpC,MAAM;IACN,cAAc;AACf,CAAC,EApBW,SAAS,yBAAT,SAAS,QAoBpB;AAED;;;GAGG;AACH,IAAY,QAmBX;AAnBD,WAAY,QAAQ;IACnB;;OAEG;IACH,qCAAG,CAAA;IACH;;OAEG;IACH,yCAAK,CAAA;IACL;;;;OAIG;IACH,2CAAM,CAAA;IACN;;OAEG;IACH,uCAAI,CAAA;AACL,CAAC,EAnBW,QAAQ,wBAAR,QAAQ,QAmBnB;AAED;;;;;;;GAOG;AACH,SAAgB,YAAY,CAAC,OAAe,EAAE,WAAgC;IAC7E,OAAO,IAAA,gBAAK,EAAC,oBAAoB,CAAC,WAAW,CAAC,IAAI,OAAO,CAAC,CAAC;AAC5D,CAAC;AAFD,oCAEC;AAED;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,WAAgC;IACpE,OAAO,WAAW,YAAY,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AAChF,CAAC;AAFD,oDAEC;AA6DD;;;;;;GAMG;AACH,MAAa,WAAW;IAYvB;;;OAGG;IACH,IAAW,cAAc;QACxB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;IACC;;;OAGG;IACa,IAAU;IAC1B;;OAEG;IACa,YAAmB;IAC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AAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { Lazy } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { FlexListToUnion, LazyItem, isLazy } from \"../feature-libraries/index.js\";\nimport { MakeNominal, brand, isReadonlyArray } from \"../util/index.js\";\nimport { Unhydrated } from \"./types.js\";\nimport { FieldKey } from \"../core/index.js\";\n\n/**\n * Schema for a tree node.\n * @typeParam Name - The full (including scope) name/identifier for the schema.\n * @typeParam Kind - Which kind of node this schema is for.\n * @typeParam TNode - API for nodes that use this schema.\n * @typeParam TBuild - Data which can be used to construct an {@link Unhydrated} node of this type.\n * @typeParam Info - Data used when defining this schema.\n * @remarks\n * Captures the schema both as runtime data and compile time type information.\n * @public\n */\nexport type TreeNodeSchema<\n\tName extends string = string,\n\tKind extends NodeKind = NodeKind,\n\tTNode = unknown,\n\tTBuild = never,\n\tImplicitlyConstructable extends boolean = boolean,\n\tInfo = unknown,\n> =\n\t| TreeNodeSchemaClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>\n\t| TreeNodeSchemaNonClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>;\n\n/**\n * Schema which is not a class.\n * @remarks\n * This is used for schema which cannot have their instances constructed using constructors, like leaf schema.\n * @privateRemarks\n * Non-class based schema can have issues with recursive types due to https://github.com/microsoft/TypeScript/issues/55832.\n * @public\n */\nexport interface TreeNodeSchemaNonClass<\n\tout Name extends string = string,\n\tout Kind extends NodeKind = NodeKind,\n\tout TNode = unknown,\n\tin TInsertable = never,\n\tout ImplicitlyConstructable extends boolean = boolean,\n\tout Info = unknown,\n> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {\n\tcreate(data: TInsertable): TNode;\n}\n\n/**\n * Tree node schema which is implemented using a class.\n * @remarks\n * Instances of this class are nodes in the tree.\n * This is also a constructor so that it can be subclassed.\n *\n * Using classes in this way allows introducing a named type and a named value at the same time, helping keep the runtime and compile time information together and easy to refer to un a uniform way.\n * Additionally, this works around https://github.com/microsoft/TypeScript/issues/55832 which causes similar patterns with less explicit types to infer \"any\" in the d.ts file.\n * @public\n */\nexport interface TreeNodeSchemaClass<\n\tout Name extends string = string,\n\tout Kind extends NodeKind = NodeKind,\n\tout TNode = unknown,\n\tin TInsertable = never,\n\tout ImplicitlyConstructable extends boolean = boolean,\n\tout Info = unknown,\n> extends TreeNodeSchemaCore<Name, Kind, ImplicitlyConstructable, Info> {\n\t/**\n\t * Constructs an {@link Unhydrated} node with this schema.\n\t * @remarks\n\t * This constructor is also used internally to construct hydrated nodes with a different parameter type.\n\t * Therefor overriding this constructor is not type-safe and is not supported.\n\t * @sealed\n\t */\n\tnew (data: TInsertable): Unhydrated<TNode>;\n}\n\n/**\n * Data common to all tree node schema.\n * @public\n */\nexport interface TreeNodeSchemaCore<\n\tout Name extends string,\n\tout Kind extends NodeKind,\n\tout ImplicitlyConstructable extends boolean,\n\tout Info = unknown,\n> {\n\treadonly identifier: Name;\n\treadonly kind: Kind;\n\n\t/**\n\t * Data used to define this schema.\n\t *\n\t * @remarks\n\t * The format depends on the kind of node it is for.\n\t * For example, the \"object\" node kind could store the field schema here.\n\t */\n\treadonly info: Info;\n\n\t/**\n\t * When constructing insertable content,\n\t * data that could be passed to the node's constructor can be used instead of an {@link Unhydrated} node\n\t * iff implicitlyConstructable is true.\n\t * @privateRemarks\n\t * Currently the logic for traversing insertable content,\n\t * both to build trees and to hydrate them does not defer to the schema classes to handle the policy,\n\t * so if their constructors differ from what is supported, some cases will not work.\n\t * Setting this to false adjusts the insertable types to disallow cases which could be impacted by these inconsistencies.\n\t */\n\treadonly implicitlyConstructable: ImplicitlyConstructable;\n}\n\n/**\n * Types for use in fields.\n * @public\n */\nexport type AllowedTypes = readonly LazyItem<TreeNodeSchema>[];\n\n/**\n * Kind of a field on a node.\n * @public\n */\nexport enum FieldKind {\n\t/**\n\t * A field which can be empty or filled.\n\t * @remarks\n\t * Allows 0 or one child.\n\t */\n\tOptional,\n\t/**\n\t * A field which must always be filled.\n\t * @remarks\n\t * Only allows exactly one child.\n\t */\n\tRequired,\n\t// TODO:#7734,7736: Re-enable when persisted document format is optimized\n\t// /**\n\t// * A special field used for node identifiers.\n\t// * @remarks\n\t// * Only allows exactly one child.\n\t// */\n\t// Identifier,\n}\n\n/**\n * Kind of tree node.\n * @public\n */\nexport enum NodeKind {\n\t/**\n\t * A node which serves as a map, storing children under string keys.\n\t */\n\tMap,\n\t/**\n\t * A node which serves as an array, storing children in an ordered sequence.\n\t */\n\tArray,\n\t/**\n\t * A node which stores a heterogenous collection of children in named fields.\n\t * @remarks\n\t * Each field gets its own schema.\n\t */\n\tObject,\n\t/**\n\t * A node which stores a single leaf value.\n\t */\n\tLeaf,\n}\n\n/**\n * Maps from a view key to its corresponding {@link FieldProps.key | stored key} for the provided\n * {@link ImplicitFieldSchema | field schema}.\n *\n * @remarks\n * If an explicit stored key was specified in the schema, it will be used.\n * Otherwise, the stored key is the same as the view key.\n */\nexport function getStoredKey(viewKey: string, fieldSchema: ImplicitFieldSchema): FieldKey {\n\treturn brand(getExplicitStoredKey(fieldSchema) ?? viewKey);\n}\n\n/**\n * Gets the {@link FieldProps.key | stored key} specified by the schema, if one was explicitly specified.\n * Otherwise, returns undefined.\n */\nexport function getExplicitStoredKey(fieldSchema: ImplicitFieldSchema): string | undefined {\n\treturn fieldSchema instanceof FieldSchema ? fieldSchema.props?.key : undefined;\n}\n\n/**\n * Additional information to provide to a {@link FieldSchema}.\n *\n * @public\n */\nexport interface FieldProps {\n\t/**\n\t * The unique identifier of a field, used in the persisted form of the tree.\n\t *\n\t * @remarks\n\t * If not explicitly set via the schema, this is the same as the schema's property key.\n\t *\n\t * Specifying a stored key that differs from the property key is particularly useful in refactoring scenarios.\n\t * To update the developer-facing API, while maintaining backwards compatibility with existing SharedTree data,\n\t * you can change the property key and specify the previous property key as the stored key.\n\t *\n\t * Notes:\n\t *\n\t * - Stored keys have no impact on standard JavaScript behavior, on tree nodes. For example, `Object.keys`\n\t * will always return the property keys specified in the schema, ignoring any stored keys that differ from\n\t * the property keys.\n\t *\n\t * - When specifying stored keys in an object schema, you must ensure that the final set of stored keys\n\t * (accounting for those implicitly derived from property keys) contains no duplicates.\n\t * This is validated at runtime.\n\t *\n\t * @example Refactoring code without breaking compatibility with existing data\n\t *\n\t * Consider some existing object schema:\n\t *\n\t * ```TypeScript\n\t * class Point extends schemaFactory.object(\"Point\", {\n\t * \txPosition: schemaFactory.number,\n\t * \tyPosition: schemaFactory.number,\n\t * \tzPosition: schemaFactory.optional(schemaFactory.number),\n\t * });\n\t * ```\n\t *\n\t * Developers using nodes of this type would access the the `xPosition` property as `point.xPosition`.\n\t *\n\t * We would like to refactor the schema to omit \"Position\" from the property keys, but application data has\n\t * already been persisted using the original property keys. To maintain compatibility with existing data,\n\t * we can refactor the schema as follows:\n\t *\n\t * ```TypeScript\n\t * class Point extends schemaFactory.object(\"Point\", {\n\t * \tx: schemaFactory.required(schemaFactory.number, { key: \"xPosition\" }),\n\t * \ty: schemaFactory.required(schemaFactory.number, { key: \"yPosition\" }),\n\t * \tz: schemaFactory.optional(schemaFactory.number, { key: \"zPosition\" }),\n\t * });\n\t * ```\n\t *\n\t * Now, developers can access the `x` property as `point.x`, while existing data can still be collaborated on.\n\t *\n\t * @defaultValue If not specified, the key that is persisted is the property key that was specified in the schema.\n\t */\n\treadonly key?: string;\n}\n\n/**\n * All policy for a specific field,\n * including functionality that does not have to be kept consistent across versions or deterministic.\n *\n * This can include policy for how to use this schema for \"view\" purposes, and well as how to expose editing APIs.\n * @sealed @public\n */\nexport class FieldSchema<\n\tout Kind extends FieldKind = FieldKind,\n\tout Types extends ImplicitAllowedTypes = ImplicitAllowedTypes,\n> {\n\t/**\n\t * This class is used with instanceof, and therefore should have nominal typing.\n\t * This field enforces that.\n\t */\n\tprotected _typeCheck?: MakeNominal;\n\n\tprivate readonly lazyTypes: Lazy<ReadonlySet<TreeNodeSchema>>;\n\n\t/**\n\t * What types of tree nodes are allowed in this field.\n\t * @remarks Counterpart to {@link FieldSchema.allowedTypes}, with any lazy definitions evaluated.\n\t */\n\tpublic get allowedTypeSet(): ReadonlySet<TreeNodeSchema> {\n\t\treturn this.lazyTypes.value;\n\t}\n\n\tpublic constructor(\n\t\t/**\n\t\t * The {@link https://en.wikipedia.org/wiki/Kind_(type_theory) | kind } of this field.\n\t\t * Determines the multiplicity, viewing and editing APIs as well as the merge resolution policy.\n\t\t */\n\t\tpublic readonly kind: Kind,\n\t\t/**\n\t\t * What types of tree nodes are allowed in this field.\n\t\t */\n\t\tpublic readonly allowedTypes: Types,\n\t\t/**\n\t\t * Optional properties associated with the field.\n\t\t */\n\t\tpublic readonly props?: FieldProps,\n\t) {\n\t\tthis.lazyTypes = new Lazy(() => normalizeAllowedTypes(this.allowedTypes));\n\t}\n}\n\n/**\n * Normalizes a {@link ImplicitFieldSchema} to a {@link FieldSchema}.\n */\nexport function normalizeFieldSchema(schema: ImplicitFieldSchema): FieldSchema {\n\treturn schema instanceof FieldSchema ? schema : new FieldSchema(FieldKind.Required, schema);\n}\n/**\n * Normalizes a {@link ImplicitAllowedTypes} to a set of {@link TreeNodeSchema}s, by eagerly evaluating any\n * lazy schema declarations.\n *\n * @remarks Note: this must only be called after all required schemas have been declared, otherwise evaluation of\n * recursive schemas may fail.\n */\nexport function normalizeAllowedTypes(types: ImplicitAllowedTypes): ReadonlySet<TreeNodeSchema> {\n\tconst normalized = new Set<TreeNodeSchema>();\n\tif (isReadonlyArray(types)) {\n\t\tfor (const lazyType of types) {\n\t\t\tnormalized.add(evaluateLazySchema(lazyType));\n\t\t}\n\t} else {\n\t\tnormalized.add(evaluateLazySchema(types));\n\t}\n\treturn normalized;\n}\n\nfunction evaluateLazySchema(value: LazyItem<TreeNodeSchema>): TreeNodeSchema {\n\tconst evaluatedSchema = isLazy(value) ? value() : value;\n\tif (evaluatedSchema === undefined) {\n\t\tthrow new UsageError(\n\t\t\t`Encountered an undefined schema. This could indicate that some referenced schema has not yet been instantiated.`,\n\t\t);\n\t}\n\treturn evaluatedSchema;\n}\n\n/**\n * Types allowed in a field.\n * @remarks\n * Implicitly treats a single type as an array of one type.\n * @public\n */\nexport type ImplicitAllowedTypes = AllowedTypes | TreeNodeSchema;\n\n/**\n * Schema for a field of a tree node.\n * @remarks\n * Implicitly treats {@link ImplicitAllowedTypes} as a Required field of that type.\n * @public\n */\nexport type ImplicitFieldSchema = FieldSchema | ImplicitAllowedTypes;\n\n/**\n * Converts ImplicitFieldSchema to the corresponding tree node's field type.\n * @public\n */\nexport type TreeFieldFromImplicitField<TSchema extends ImplicitFieldSchema = FieldSchema> =\n\tTSchema extends FieldSchema<infer Kind, infer Types>\n\t\t? ApplyKind<TreeNodeFromImplicitAllowedTypes<Types>, Kind>\n\t\t: TSchema extends ImplicitAllowedTypes\n\t\t? TreeNodeFromImplicitAllowedTypes<TSchema>\n\t\t: unknown;\n\n/**\n * Type of content that can be inserted into the tree for a field of the given schema.\n * @public\n */\nexport type InsertableTreeFieldFromImplicitField<\n\tTSchema extends ImplicitFieldSchema = FieldSchema,\n> = TSchema extends FieldSchema<infer Kind, infer Types>\n\t? ApplyKind<InsertableTreeNodeFromImplicitAllowedTypes<Types>, Kind>\n\t: TSchema extends ImplicitAllowedTypes\n\t? InsertableTreeNodeFromImplicitAllowedTypes<TSchema>\n\t: unknown;\n\n/**\n * Suitable for output.\n * For input must error on side of excluding undefined instead.\n * @public\n */\nexport type ApplyKind<T, Kind extends FieldKind> = Kind extends FieldKind.Required\n\t? T\n\t: undefined | T;\n\n/**\n * Type of of tree node for a field of the given schema.\n * @public\n */\nexport type TreeNodeFromImplicitAllowedTypes<\n\tTSchema extends ImplicitAllowedTypes = TreeNodeSchema,\n> = TSchema extends TreeNodeSchema\n\t? NodeFromSchema<TSchema>\n\t: TSchema extends AllowedTypes\n\t? NodeFromSchema<FlexListToUnion<TSchema>>\n\t: unknown;\n\n/**\n * Type of content that can be inserted into the tree for a node of the given schema.\n * @public\n */\nexport type InsertableTreeNodeFromImplicitAllowedTypes<\n\tTSchema extends ImplicitAllowedTypes = TreeNodeSchema,\n> = TSchema extends TreeNodeSchema\n\t? InsertableTypedNode<TSchema>\n\t: TSchema extends AllowedTypes\n\t? InsertableTypedNode<FlexListToUnion<TSchema>>\n\t: never;\n\n/**\n * Takes in `TreeNodeSchema[]` and returns a TypedNode union.\n * @public\n */\nexport type NodeFromSchema<T extends TreeNodeSchema> = T extends TreeNodeSchema<\n\tstring,\n\tNodeKind,\n\tinfer TNode\n>\n\t? TNode\n\t: never;\n\n/**\n * Data which can be used as a node to be inserted.\n * Either an unhydrated node, or content to build a new node.\n * @public\n */\nexport type InsertableTypedNode<T extends TreeNodeSchema> =\n\t| (T extends { implicitlyConstructable: true } ? NodeBuilderData<T> : never)\n\t| Unhydrated<NodeFromSchema<T>>;\n\n/**\n * Given a node's schema, return the corresponding object from which the node could be built.\n * @privateRemarks\n * Currently this assumes factory functions take exactly one argument.\n * This could be changed if needed.\n *\n * These factory functions can also take a FlexTreeNode, but this is not exposed in the public facing types.\n * @public\n */\nexport type NodeBuilderData<T extends TreeNodeSchema> = T extends TreeNodeSchema<\n\tstring,\n\tNodeKind,\n\tunknown,\n\tinfer TBuild\n>\n\t? TBuild\n\t: never;\n\n/**\n * Value that may be stored as a leaf node.\n * @public\n */\n// eslint-disable-next-line @rushstack/no-new-null\nexport type TreeLeafValue = number | string | boolean | IFluidHandle | null;\n\n/**\n * The type of a {@link TreeNode}.\n * For moore information about the type, use `Tree.schema(theNode)` instead.\n * @remarks\n * This symbol mainly exists on nodes to allow TypeScript to provide more accurate type checking.\n * `Tree.is` and `Tree.schema` provide a superset of this information in more friendly ways.\n *\n * This symbol should not manually be added to objects as doing so allows the object to be invalidly used where nodes are expected.\n * Instead construct a real node of the desired type using its constructor.\n * @privateRemarks\n * This prevents non-nodes from being accidentally used as nodes, as well as allows the type checker to distinguish different node types.\n * @public\n */\nexport const type: unique symbol = Symbol(\"TreeNode Type\");\n\n/**\n * Adds a {@link \"type\"} field.\n * @public\n */\nexport interface WithType<TName extends string = string> {\n\t/**\n\t * {@inheritdoc \"type\"}\n\t */\n\tget [type](): TName;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"toFlexSchema.d.ts","sourceRoot":"","sources":["../../src/simple-tree/toFlexSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAA0B,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACpF,OAAO,EAEN,gBAAgB,EAGhB,eAAe,EAGf,kBAAkB,EAClB,cAAc,EAId,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAStD,OAAO,EAGN,oBAAoB,EACpB,mBAAmB,EAGnB,cAAc,EAGd,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAsB9C,wBAAgB,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,WAAW,CAUnE;AAED,UAAU,UAAU;IACnB,MAAM,EAAE,MAAM,kBAAkB,CAAC;IACjC,QAAQ,EAAE,cAAc,CAAC;CACzB;AAED,KAAK,SAAS,GAAG,GAAG,CAAC,wBAAwB,EAAE,UAAU,CAAC,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,mBAAmB,GAAG,cAAc,CA0BtE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,cAAc,GAAG,kBAAkB,CAGtE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,mBAAmB,GAAG,eAAe,CAY/F;AAQD;;GAEG;AACH,wBAAgB,mBAAmB,CAClC,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,oBAAoB,GAC1B,gBAAg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AM,EAAE,cAAc,GACpB,MAAM,kBAAkB,CAwF1B"}
@@ -98,7 +98,8 @@ exports.convertField = convertField;
98
98
  const convertFieldKind = new Map([
99
99
  [schemaTypes_js_1.FieldKind.Optional, index_js_1.FieldKinds.optional],
100
100
  [schemaTypes_js_1.FieldKind.Required, index_js_1.FieldKinds.required],
101
- [schemaTypes_js_1.FieldKind.Identifier, index_js_1.FieldKinds.identifier],
101
+ // TODO:#7734,7736: Re-enable when persisted document format is optimized
102
+ // [FieldKind.Identifier, FieldKinds.identifier],
102
103
  ]);
103
104
  /**
104
105
  * Normalizes an {@link ImplicitAllowedTypes} into an {@link AllowedTypes}.
@@ -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;AAG9E,4DAauC;AACvC,+EAAuF;AAEvF,+CAA6E;AAE7E,6CAAwE;AACxE,yDAI4B;AAC5B,qDAU0B;AAC1B,iDAAoD;AAGpD;;;;;;;GAOG;AACH,SAAS,wBAAwB,CAChC,MAA2B,EAC3B,IAAgD;IAEhD,MAAM,IAAI,GAAG,IAAA,kCAAqB,EAAC,IAAyB,CAAC,CAAC;IAC9D,MAAM,qBAAqB,GAAG,IAAA,qCAAoB,EAAC,MAAM,CAAC,CAAC;IAC3D,OAAO,CACN,IAAA,iCAAkB,EAAC,IAAI,EAAE,qBAAqB,CAAC,YAAY,CAAC;QAC5D,IAAA,eAAI,EAAC,uBAAuB,CAAC,CAC7B,CAAC;AACH,CAAC;AAED,SAAgB,YAAY,CAAC,MAAyB;IACrD,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IACxC,MAAM,WAAW,GAChB,UAAU,KAAK,SAAS;QACvB,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,CAAC,wBAAwB,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;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A,gBAAK,EAAC,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;gBACxE,MAAM;aACN;YACD;gBACC,IAAA,0BAAe,EAAC,IAAI,CAAC,CAAC;SACvB;QACD,IAAA,iBAAM,EAAC,GAAG,YAAY,6BAAkB,EAAE,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAC/E;YACC,MAAM,MAAM,GAAG,IAAA,kDAA+B,EAAC,MAAM,CAAC,CAAC;YACvD,IAAI,MAAM,KAAK,SAAS,EAAE;gBACzB,IAAA,iBAAM,EACL,IAAA,kDAA+B,EAAC,MAAM,CAAC,KAAK,GAAG,EAC/C,KAAK,CAAC,gCAAgC,CACtC,CAAC;aACF;iBAAM;gBACN,IAAA,+CAA4B,EAAC,MAAM,EAAE,GAAG,CAAC,CAAC;aAC1C;SACD;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;AA3FD,8CA2FC","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 { ITreeCursorSynchronous, TreeNodeSchemaIdentifier } from \"../core/index.js\";\nimport {\n\tFieldKinds,\n\tFlexAllowedTypes,\n\tFlexFieldKind,\n\tFlexFieldNodeSchema,\n\tFlexFieldSchema,\n\tFlexMapNodeSchema,\n\tFlexObjectNodeSchema,\n\tFlexTreeNodeSchema,\n\tFlexTreeSchema,\n\tTreeNodeSchemaBase,\n\tdefaultSchemaPolicy,\n\tschemaIsLeaf,\n} from \"../feature-libraries/index.js\";\nimport { normalizeFlexListEager } from \"../feature-libraries/typed-schema/flexList.js\";\nimport { TreeContent } from \"../shared-tree/index.js\";\nimport { brand, fail, isReadonlyArray, mapIterable } from \"../util/index.js\";\n\nimport { InsertableContent, extractFactoryContent } from \"./proxies.js\";\nimport {\n\tcachedFlexSchemaFromClassSchema,\n\tsetFlexSchemaFromClassSchema,\n\ttryGetSimpleNodeSchema,\n} from \"./schemaCaching.js\";\nimport {\n\tFieldKind,\n\tFieldSchema,\n\tImplicitAllowedTypes,\n\tImplicitFieldSchema,\n\tInsertableTreeNodeFromImplicitAllowedTypes,\n\tNodeKind,\n\tTreeNodeSchema,\n\tnormalizeFieldSchema,\n\tgetStoredKey,\n} from \"./schemaTypes.js\";\nimport { cursorFromNodeData } from \"./toMapTree.js\";\nimport { TreeConfiguration } 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 */\nfunction cursorFromUnhydratedRoot(\n\tschema: ImplicitFieldSchema,\n\ttree: InsertableTreeNodeFromImplicitAllowedTypes,\n): ITreeCursorSynchronous {\n\tconst data = extractFactoryContent(tree as InsertableContent);\n\tconst normalizedFieldSchema = normalizeFieldSchema(schema);\n\treturn (\n\t\tcursorFromNodeData(data, normalizedFieldSchema.allowedTypes) ??\n\t\tfail(\"failed to decode tree\")\n\t);\n}\n\nexport function toFlexConfig(config: TreeConfiguration): TreeContent {\n\tconst unhydrated = config.initialTree();\n\tconst initialTree =\n\t\tunhydrated === undefined\n\t\t\t? undefined\n\t\t\t: [cursorFromUnhydratedRoot(config.schema, unhydrated)];\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(schemaMap: SchemaMap, schema: ImplicitFieldSchema): 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 = () => {\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) ??\n\t\t\t\t\tfail(\"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 =\n\t\t\t\t\tcached ?? 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 =\n\t\t\t\t\tcached ??\n\t\t\t\t\tFlexObjectNodeSchema.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;AAG9E,4DAauC;AACvC,+EAAuF;AAEvF,+CAA6E;AAE7E,6CAAwE;AACxE,yDAI4B;AAC5B,qDAU0B;AAC1B,iDAAoD;AAGpD;;;;;;;GAOG;AACH,SAAS,wBAAwB,CAChC,MAA2B,EAC3B,IAAgD;IAEhD,MAAM,IAAI,GAAG,IAAA,kCAAqB,EAAC,IAAyB,CAAC,CAAC;IAC9D,MAAM,qBAAqB,GAAG,IAAA,qCAAoB,EAAC,MAAM,CAAC,CAAC;IAC3D,OAAO,CACN,IAAA,iCAAkB,EAAC,IAAI,EAAE,qBAAqB,CAAC,YAAY,CAAC;QAC5D,IAAA,eAAI,EAAC,uBAAuB,CAAC,CAC7B,CAAC;AACH,CAAC;AAED,SAAgB,YAAY,CAAC,MAAyB;IACrD,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IACxC,M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AA,kDAA+B,EAAC,MAAM,CAAC,CAAC;gBACvD,GAAG;oBACF,MAAM;wBACN,+BAAoB,CAAC,MAAM,CAAC,OAAO,EAAE,IAAA,gBAAK,EAAC,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;gBACxE,MAAM;aACN;YACD;gBACC,IAAA,0BAAe,EAAC,IAAI,CAAC,CAAC;SACvB;QACD,IAAA,iBAAM,EAAC,GAAG,YAAY,6BAAkB,EAAE,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAC/E;YACC,MAAM,MAAM,GAAG,IAAA,kDAA+B,EAAC,MAAM,CAAC,CAAC;YACvD,IAAI,MAAM,KAAK,SAAS,EAAE;gBACzB,IAAA,iBAAM,EACL,IAAA,kDAA+B,EAAC,MAAM,CAAC,KAAK,GAAG,EAC/C,KAAK,CAAC,gCAAgC,CACtC,CAAC;aACF;iBAAM;gBACN,IAAA,+CAA4B,EAAC,MAAM,EAAE,GAAG,CAAC,CAAC;aAC1C;SACD;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;AA3FD,8CA2FC","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 { ITreeCursorSynchronous, TreeNodeSchemaIdentifier } from \"../core/index.js\";\nimport {\n\tFieldKinds,\n\tFlexAllowedTypes,\n\tFlexFieldKind,\n\tFlexFieldNodeSchema,\n\tFlexFieldSchema,\n\tFlexMapNodeSchema,\n\tFlexObjectNodeSchema,\n\tFlexTreeNodeSchema,\n\tFlexTreeSchema,\n\tTreeNodeSchemaBase,\n\tdefaultSchemaPolicy,\n\tschemaIsLeaf,\n} from \"../feature-libraries/index.js\";\nimport { normalizeFlexListEager } from \"../feature-libraries/typed-schema/flexList.js\";\nimport { TreeContent } from \"../shared-tree/index.js\";\nimport { brand, fail, isReadonlyArray, mapIterable } from \"../util/index.js\";\n\nimport { InsertableContent, extractFactoryContent } from \"./proxies.js\";\nimport {\n\tcachedFlexSchemaFromClassSchema,\n\tsetFlexSchemaFromClassSchema,\n\ttryGetSimpleNodeSchema,\n} from \"./schemaCaching.js\";\nimport {\n\tFieldKind,\n\tFieldSchema,\n\tImplicitAllowedTypes,\n\tImplicitFieldSchema,\n\tInsertableTreeNodeFromImplicitAllowedTypes,\n\tNodeKind,\n\tTreeNodeSchema,\n\tnormalizeFieldSchema,\n\tgetStoredKey,\n} from \"./schemaTypes.js\";\nimport { cursorFromNodeData } from \"./toMapTree.js\";\nimport { TreeConfiguration } 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 */\nfunction cursorFromUnhydratedRoot(\n\tschema: ImplicitFieldSchema,\n\ttree: InsertableTreeNodeFromImplicitAllowedTypes,\n): ITreeCursorSynchronous {\n\tconst data = extractFactoryContent(tree as InsertableContent);\n\tconst normalizedFieldSchema = normalizeFieldSchema(schema);\n\treturn (\n\t\tcursorFromNodeData(data, normalizedFieldSchema.allowedTypes) ??\n\t\tfail(\"failed to decode tree\")\n\t);\n}\n\nexport function toFlexConfig(config: TreeConfiguration): TreeContent {\n\tconst unhydrated = config.initialTree();\n\tconst initialTree =\n\t\tunhydrated === undefined\n\t\t\t? undefined\n\t\t\t: [cursorFromUnhydratedRoot(config.schema, unhydrated)];\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(schemaMap: SchemaMap, schema: ImplicitFieldSchema): 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// TODO:#7734,7736: Re-enable when persisted document format is optimized\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 = () => {\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) ??\n\t\t\t\t\tfail(\"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 =\n\t\t\t\t\tcached ?? 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 =\n\t\t\t\t\tcached ??\n\t\t\t\t\tFlexObjectNodeSchema.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"]}
@@ -53,11 +53,6 @@ export interface TreeNodeApi {
53
53
  * Returns the {@link TreeStatus} of the given node.
54
54
  */
55
55
  readonly status: (node: TreeNode) => TreeStatus;
56
- /**
57
- * If the given node has an identifier specified by a field of kind "identifier" then this returns the compressed form of that identifier.
58
- * Otherwise returns undefined.
59
- */
60
- shortId(node: TreeNode): number | undefined;
61
56
  }
62
57
  /**
63
58
  * The `Tree` object holds various functions for analyzing {@link TreeNode}s.
@@ -1 +1 @@
1
- {"version":3,"file":"treeApi.d.ts","sourceRoot":"","sources":["../../src/simple-tree/treeApi.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAIN,UAAU,EAGV,MAAM,+BAA+B,CAAC;AAOvC,OAAO,EACN,cAAc,EACd,QAAQ,EACR,KAAK,aAAa,EAClB,cAAc,EAGd,MAAM,kBAAkB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AW,IAAI,IAAI,CAAC;IAEpB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,WAAW,IAAI,IAAI,CAAC;CACpB"}
@@ -81,16 +81,19 @@ exports.treeNodeApi = {
81
81
  }
82
82
  return (0, schemaCaching_js_1.tryGetSimpleNodeSchema)((0, proxyBinding_js_1.getFlexNode)(node).schema);
83
83
  },
84
- shortId(node) {
85
- const flexNode = (0, proxyBinding_js_1.getFlexNode)(node);
86
- for (const field of flexNode.boxedIterator()) {
87
- if (field.schema.kind === index_js_2.FieldKinds.identifier) {
88
- const identifier = field.boxedAt(0);
89
- (0, internal_1.assert)(identifier !== undefined, 0x927 /* The identifier must exist */);
90
- return (0, index_js_3.extractFromOpaque)(identifier.context.nodeKeys.localize(identifier.value));
91
- }
92
- }
93
- },
84
+ // TODO:#7734,7736: Re-enable when persisted document format is optimized
85
+ // shortId(node: TreeNode): number | undefined {
86
+ // const flexNode = getFlexNode(node);
87
+ // for (const field of flexNode.boxedIterator()) {
88
+ // if (field.schema.kind === FieldKinds.identifier) {
89
+ // const identifier = field.boxedAt(0);
90
+ // assert(identifier !== undefined, 0x927 /* The identifier must exist */);
91
+ // return extractFromOpaque(
92
+ // identifier.context.nodeKeys.localize(identifier.value as StableNodeKey),
93
+ // );
94
+ // }
95
+ // }
96
+ // },
94
97
  };
95
98
  /**
96
99
  * Gets the stored key with which the provided node is associated in the parent.