@fluidframework/tree 2.70.0 → 2.71.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/api-report/tree.alpha.api.md +25 -4
- package/api-report/tree.beta.api.md +3 -0
- package/api-report/tree.legacy.beta.api.md +3 -0
- package/dist/alpha.d.ts +3 -0
- package/dist/beta.d.ts +1 -0
- package/dist/codec/discriminatedUnions.d.ts +1 -1
- package/dist/codec/discriminatedUnions.js +1 -1
- package/dist/codec/discriminatedUnions.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/legacy.d.ts +1 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/shared-tree/independentView.d.ts +74 -5
- package/dist/shared-tree/independentView.d.ts.map +1 -1
- package/dist/shared-tree/independentView.js +104 -38
- package/dist/shared-tree/independentView.js.map +1 -1
- package/dist/shared-tree/index.d.ts +2 -1
- package/dist/shared-tree/index.d.ts.map +1 -1
- package/dist/shared-tree/index.js +6 -1
- package/dist/shared-tree/index.js.map +1 -1
- package/dist/shared-tree/sharedTree.d.ts.map +1 -1
- package/dist/shared-tree/sharedTree.js +18 -3
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/simple-tree/api/schemaFactory.d.ts +2 -2
- package/dist/simple-tree/api/schemaFactory.js +2 -2
- package/dist/simple-tree/api/schemaFactory.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryRecursive.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactoryRecursive.js +1 -0
- package/dist/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
- package/dist/simple-tree/api/schemaFromSimple.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFromSimple.js +9 -5
- package/dist/simple-tree/api/schemaFromSimple.js.map +1 -1
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +4 -2
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts +2 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js +31 -10
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/dist/simple-tree/core/allowedTypes.d.ts +9 -4
- package/dist/simple-tree/core/allowedTypes.d.ts.map +1 -1
- package/dist/simple-tree/core/allowedTypes.js +17 -4
- package/dist/simple-tree/core/allowedTypes.js.map +1 -1
- package/dist/simple-tree/fieldSchema.d.ts +2 -1
- package/dist/simple-tree/fieldSchema.d.ts.map +1 -1
- package/dist/simple-tree/fieldSchema.js +10 -0
- package/dist/simple-tree/fieldSchema.js.map +1 -1
- package/dist/simple-tree/index.d.ts +1 -1
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.js +6 -0
- package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/map/mapNode.js +6 -0
- package/dist/simple-tree/node-kinds/map/mapNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/object/objectNode.d.ts +17 -0
- package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/object/objectNode.js +19 -6
- package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/record/recordNode.js +6 -0
- package/dist/simple-tree/node-kinds/record/recordNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/record/recordNodeTypes.d.ts +16 -0
- package/dist/simple-tree/node-kinds/record/recordNodeTypes.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/record/recordNodeTypes.js.map +1 -1
- package/dist/simple-tree/simpleSchema.d.ts +21 -5
- package/dist/simple-tree/simpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/simpleSchema.js.map +1 -1
- package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
- package/dist/simple-tree/toStoredSchema.js +6 -3
- package/dist/simple-tree/toStoredSchema.js.map +1 -1
- package/dist/util/referenceCounting.d.ts.map +1 -1
- package/dist/util/referenceCounting.js +1 -0
- package/dist/util/referenceCounting.js.map +1 -1
- package/lib/alpha.d.ts +3 -0
- package/lib/beta.d.ts +1 -0
- package/lib/codec/discriminatedUnions.d.ts +1 -1
- package/lib/codec/discriminatedUnions.js +1 -1
- package/lib/codec/discriminatedUnions.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/legacy.d.ts +1 -0
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/shared-tree/independentView.d.ts +74 -5
- package/lib/shared-tree/independentView.d.ts.map +1 -1
- package/lib/shared-tree/independentView.js +103 -38
- package/lib/shared-tree/independentView.js.map +1 -1
- package/lib/shared-tree/index.d.ts +2 -1
- package/lib/shared-tree/index.d.ts.map +1 -1
- package/lib/shared-tree/index.js +2 -1
- package/lib/shared-tree/index.js.map +1 -1
- package/lib/shared-tree/sharedTree.d.ts.map +1 -1
- package/lib/shared-tree/sharedTree.js +18 -3
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/simple-tree/api/schemaFactory.d.ts +2 -2
- package/lib/simple-tree/api/schemaFactory.js +2 -2
- package/lib/simple-tree/api/schemaFactory.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryRecursive.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactoryRecursive.js +1 -0
- package/lib/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
- package/lib/simple-tree/api/schemaFromSimple.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFromSimple.js +9 -5
- package/lib/simple-tree/api/schemaFromSimple.js.map +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +4 -2
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts +2 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js +31 -10
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/lib/simple-tree/core/allowedTypes.d.ts +9 -4
- package/lib/simple-tree/core/allowedTypes.d.ts.map +1 -1
- package/lib/simple-tree/core/allowedTypes.js +18 -5
- package/lib/simple-tree/core/allowedTypes.js.map +1 -1
- package/lib/simple-tree/fieldSchema.d.ts +2 -1
- package/lib/simple-tree/fieldSchema.d.ts.map +1 -1
- package/lib/simple-tree/fieldSchema.js +10 -0
- package/lib/simple-tree/fieldSchema.js.map +1 -1
- package/lib/simple-tree/index.d.ts +1 -1
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.js +7 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/map/mapNode.js +7 -1
- package/lib/simple-tree/node-kinds/map/mapNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/object/objectNode.d.ts +17 -0
- package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/object/objectNode.js +19 -6
- package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/record/recordNode.js +7 -1
- package/lib/simple-tree/node-kinds/record/recordNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/record/recordNodeTypes.d.ts +16 -0
- package/lib/simple-tree/node-kinds/record/recordNodeTypes.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/record/recordNodeTypes.js.map +1 -1
- package/lib/simple-tree/simpleSchema.d.ts +21 -5
- package/lib/simple-tree/simpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/simpleSchema.js.map +1 -1
- package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
- package/lib/simple-tree/toStoredSchema.js +6 -3
- package/lib/simple-tree/toStoredSchema.js.map +1 -1
- package/lib/util/referenceCounting.d.ts.map +1 -1
- package/lib/util/referenceCounting.js +1 -0
- package/lib/util/referenceCounting.js.map +1 -1
- package/package.json +24 -24
- package/src/codec/discriminatedUnions.ts +1 -1
- package/src/index.ts +3 -0
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/independentView.ts +147 -72
- package/src/shared-tree/index.ts +4 -0
- package/src/shared-tree/sharedTree.ts +25 -3
- package/src/simple-tree/api/schemaFactory.ts +2 -2
- package/src/simple-tree/api/schemaFactoryRecursive.ts +2 -0
- package/src/simple-tree/api/schemaFromSimple.ts +17 -14
- package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +8 -2
- package/src/simple-tree/api/viewSchemaToSimpleSchema.ts +44 -8
- package/src/simple-tree/core/allowedTypes.ts +26 -13
- package/src/simple-tree/fieldSchema.ts +14 -1
- package/src/simple-tree/index.ts +1 -0
- package/src/simple-tree/node-kinds/array/arrayNode.ts +9 -0
- package/src/simple-tree/node-kinds/map/mapNode.ts +9 -0
- package/src/simple-tree/node-kinds/object/objectNode.ts +54 -18
- package/src/simple-tree/node-kinds/record/recordNode.ts +9 -0
- package/src/simple-tree/node-kinds/record/recordNodeTypes.ts +16 -0
- package/src/simple-tree/simpleSchema.ts +22 -5
- package/src/simple-tree/toStoredSchema.ts +12 -3
- package/src/util/referenceCounting.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaFactoryRecursive.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFactoryRecursive.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA+OH;;;;;;;;;;GAUG;AACH,SAAgB,WAAW,CAAI,CAAK,IAAS,CAAC;AAA9C,kCAA8C","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { RestrictiveStringRecord } from \"../../util/index.js\";\nimport type {\n\tNodeKind,\n\tTreeNodeSchema,\n\tWithType,\n\tTreeNode,\n\tImplicitAllowedTypes,\n\tInsertableTreeNodeFromImplicitAllowedTypes,\n\tTreeNodeSchemaClass,\n} from \"../core/index.js\";\nimport type { InsertableObjectFromSchemaRecord } from \"../node-kinds/index.js\";\nimport type { ImplicitFieldSchema } from \"../fieldSchema.js\";\n\n/**\n * Compile time check for validity of a recursive schema.\n * This type also serves as a central location for documenting the requirements and issues related to recursive schema.\n *\n * @example\n * ```typescript\n * class Test extends sf.arrayRecursive(\"Test\", [() => Test]) {}\n * {\n * type _check = ValidateRecursiveSchema<typeof Test>;\n * }\n * ```\n * @remarks\n * In this context recursive schema are defined as all {@link FieldSchema} and {@link TreeNodeSchema} schema which are part of a cycle such that walking down through each {@link TreeNodeSchemaCore.childTypes} the given starting schema can be reached again.\n * Schema referencing the recursive schema and schema they reference that are not part of a cycle are not considered recursive.\n *\n * TypeScript puts a lot of limitations on the typing of recursive schema.\n * To help avoid running into these limitations and thus getting schema that do not type check (or only type checks sometimes!),\n * {@link SchemaFactory} provides APIs (postfixed with `Recursive`) for writing recursive schema.\n * These APIs when combined with the patterns documented below should ensure that the schema provide robust type checking.\n * These special patterns (other than {@link LazyItem} forward references which are not recursion specific)\n * are not required for correct runtime behavior: they exist entirely to mitigate TypeScript type checking limitations and bugs.\n * Ideally TypeScript's type checker would be able to handle all of these cases and more, removing the need for recursive type specific guidance, rules and APIs.\n * Currently however there are open issues preventing this:\n * {@link https://github.com/microsoft/TypeScript/issues/59550 | 1},\n * {@link https://github.com/microsoft/TypeScript/issues/55832 | 2},\n * {@link https://github.com/microsoft/TypeScript/issues/55758 | 3}.\n * Note that the proposed resolution to some of these issues is for the compiler to error rather than allow the case,\n * so even if these are all resolved the recursive type workarounds may still be needed.\n *\n * # Patterns\n *\n * Below are patterns for how to use recursive schema.\n *\n * ## General Patterns\n *\n * When defining a recursive {@link TreeNodeSchema}, use the `*Recursive` {@link SchemaFactory} methods.\n * The returned class should be used as the base class for the recursive schema, which should then be passed to {@link ValidateRecursiveSchema}.\n *\n * Using {@link ValidateRecursiveSchema} will provide compile error for some of the cases of malformed schema.\n * This can be used to help mitigate the issue that recursive schema definitions are {@link Unenforced}.\n * If an issue is encountered where a mistake in a recursive schema is made which produces an invalid schema but is not rejected by this checker,\n * it should be considered a bug and this should be updated to handle that case (or have a disclaimer added to these docs that it misses that case).\n *\n * The non-recursive versions of the schema building methods will run into several issues when used recursively.\n * Consider the following example:\n *\n * ```typescript\n * const Test = sf.array(Test); // Bad\n * ```\n *\n * This has several issues:\n *\n * 1. It is a structurally named schema.\n * Structurally named schema derive their name from the names of their child types, which is not possible when the type is recursive since its name would include itself.\n * Instead a name must be explicitly provided.\n *\n * 2. The schema accesses itself before it's defined.\n * This would be a runtime error if the TypeScript compiler allowed it.\n * This can be fixed by wrapping the type in a function, which also requires explicitly listing the allowed types in an array (`[() => Test]`).\n *\n * 3. TypeScript fails to infer the recursive type and falls back to `any` with this warning or error (depending on the compiler configuration):\n * `'Test' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)`.\n * This issue is what the specialized recursive schema building methods fix.\n * This fix comes at a cost: to make the recursive cases work, the `extends` clauses had to be removed.\n * This means that mistakes declaring recursive schema often don't give compile errors in the schema.\n * Additionally support for implicit construction had to be disabled.\n * This means that new nested {@link Unhydrated} nodes can not be created like `new Test([[]])`.\n * Instead the nested nodes must be created explicitly using the construction like`new Test([new Test([])])`.\n *\n * 4. It is using \"POJO\" mode since it's not explicitly declaring a new class.\n * This means that the generated d.ts files for the schema replace recursive references with `any`, breaking use of recursive schema across compilation boundaries.\n * This is fixed by explicitly creating a class which extends the returned schema.\n *\n * All together, the fixed version looks like:\n * ```typescript\n * class Test extends sf.arrayRecursive(\"Test\", [() => Test]) {} // Good\n * ```\n *\n * Be very careful when declaring recursive schema.\n * Due to the removed extends clauses, subtle mistakes will compile just fine but cause strange errors when the schema is used.\n *\n * For example if a reference to a schema is malformed (in this case boxed inside an object):\n *\n * ```typescript\n * class Test extends sf.arrayRecursive(\"Test\", [() => ({ Test })]) {} // Bad\n * ```\n * This schema will still compile, and some (but not all) usages of it may look like they work correctly while other usages will produce generally unintelligible compile errors.\n * This issue can be partially mitigated using {@link ValidateRecursiveSchema}:\n *\n * ```typescript\n * class Test extends sf.arrayRecursive(\"Test\", [() => ({ Test })]) {} // Bad\n * {\n * type _check = ValidateRecursiveSchema<typeof Test>; // Reports compile error due to invalid schema above.\n * }\n * ```\n *\n * If your TypeScript configuration objects to this patten due to the unused local, you can use {@link allowUnused} to suppress the error:\n *\n * ```typescript\n * class Test extends sf.arrayRecursive(\"Test\", [() => ({ Test })]) {} // Bad\n * allowUnused<ValidateRecursiveSchema<typeof Test>>(); // Reports compile error due to invalid schema above.\n * ```\n *\n * ## Object Schema\n *\n * When defining fields, if the fields is part of the recursive cycle, use the `*Recursive` {@link SchemaFactory} methods for defining the {@link FieldSchema}.\n *\n * ## Array Schema\n *\n * See {@link FixRecursiveArraySchema} for array specific details.\n *\n * @privateRemarks\n * There are probably mistakes this misses: it's hard to guess all the wrong things people will accidentally do and defend against them.\n * Hopefully over time this can grow toward being robust, at least for common mistakes.\n *\n * This check duplicates logic that ideally would be entirely decided by the actual schema building methods.\n * Therefore changes to those methods may require updating `ValidateRecursiveSchema`.\n *\n * TODO: this currently does not reject `any`, but ideally should.\n * @public\n */\nexport type ValidateRecursiveSchema<T extends ValidateRecursiveSchemaTemplate<T>> = true;\n\n/**\n * Validation logic used by {@link ValidateRecursiveSchema}.\n * @privateRemarks\n * Recursive types should always be using TreeNodeSchemaClass (not TreeNodeSchemaNonClass) as that's part of the requirements for the type to work across compilation boundaries correctly.\n * @system @public\n */\nexport type ValidateRecursiveSchemaTemplate<T extends TreeNodeSchemaClass> =\n\tTreeNodeSchemaClass<\n\t\t// Name: This validator places no restrictions on the name other than that it's a string (as required by TreeNodeSchemaClass).\n\t\tstring,\n\t\t// NodeKind: These are the NodeKinds which currently can be used recursively.\n\t\tNodeKind.Array | NodeKind.Map | NodeKind.Object | NodeKind.Record,\n\t\t// TNode: The produced node API. This is pretty minimal validation: more could be added if similar to how TInsertable works below if needed.\n\t\tTreeNode & WithType<T[\"identifier\"], T[\"kind\"]>,\n\t\t// TInsertable: What can be passed to the constructor. This should be enough to catch most issues with incorrect schema.\n\t\t// These match whats defined in the recursive methods on `SchemaFactory` except they do not use `Unenforced`.\n\t\t{\n\t\t\t[NodeKind.Object]: T[\"info\"] extends RestrictiveStringRecord<ImplicitFieldSchema>\n\t\t\t\t? InsertableObjectFromSchemaRecord<T[\"info\"]>\n\t\t\t\t: unknown;\n\t\t\t[NodeKind.Array]: T[\"info\"] extends ImplicitAllowedTypes\n\t\t\t\t? Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T[\"info\"]>>\n\t\t\t\t: unknown;\n\t\t\t[NodeKind.Map]: T[\"info\"] extends ImplicitAllowedTypes\n\t\t\t\t? Iterable<[string, InsertableTreeNodeFromImplicitAllowedTypes<T[\"info\"]>]>\n\t\t\t\t: unknown;\n\t\t\t[NodeKind.Record]: {\n\t\t\t\treadonly [P in string]: InsertableTreeNodeFromImplicitAllowedTypes<T>;\n\t\t\t};\n\t\t\t[NodeKind.Leaf]: unknown;\n\t\t}[T[\"kind\"]],\n\t\t// ImplicitlyConstructable: recursive types are currently not implicitly constructable.\n\t\tfalse,\n\t\t// Info: What's passed to the method to create the schema. Constraining these here should be about as effective as if the actual constraints existed on the actual method itself.\n\t\t{\n\t\t\t[NodeKind.Object]: RestrictiveStringRecord<ImplicitFieldSchema>;\n\t\t\t[NodeKind.Array]: ImplicitAllowedTypes;\n\t\t\t[NodeKind.Map]: ImplicitAllowedTypes;\n\t\t\t[NodeKind.Record]: ImplicitAllowedTypes;\n\t\t\t[NodeKind.Leaf]: unknown;\n\t\t}[T[\"kind\"]]\n\t>;\n\n/**\n * Workaround for \"Type instantiation is excessively deep and possibly infinite.ts\" errors.\n * @remarks\n *\n * Generally this workaround should be avoided if possible,\n * especially for exported types, as it is likely to result in issues when exporting or importing schema where the user will be forced to use the workaround as well.\n * This is particularly problematic since in some cases it may not be possible for the user to replicate the pattern.\n * Additionally, which cases hit these limits may vary based on TypeScript version and implementation details of this library.\n *\n * This workaround is provided and documented as a last resort to be able to keep an app compiling.\n * Future version of SharedTree should provide schema type erasure functionality as a better alternative for most cases.\n *\n * When TypeScript gives the error \"Error (TS2589) Type instantiation is excessively deep and possibly infinite.\" on the invocation of `ValidateRecursiveSchema`\n * for a large schema, it can sometimes be worked around by repeating the usage of the type multiple times.\n * This works because the TypeScript compiler caches some of the intermediate results from the first usage, and thus can get further on the second.\n *\n * This utility can be referenced when applying this pattern.\n * For recursive types this can be used directly:\n *\n * ```typescript\n * {\n * // @ts-expect-error Recursion limit\n * type _check1 = FixRecursiveRecursionLimit<typeof LargeType>;\n * type _check2 = FixRecursiveRecursionLimit<typeof LargeType>;\n * type _check3 = ValidateRecursiveSchemaTemplate<typeof LargeType>;\n * }\n * ```\n *\n * For non-recursive types, they can be ported to the more flexible recursive APIs and use the pattern above.\n *\n * Non-recursive types can also use this workaround by making a duplicate copy of the problematic schema written using the recursive APIs.\n * Then this pattern can be applied to the duplicate copy.\n *\n * ```typescript\n * // Workaround TypeScript recursion limit\n * \t{\n * \t\tclass LargeUnionObjectNode_Fix extends schema.objectRecursive(\"ObjectNode\", {\n * \t\t\tx: largeUnion,\n * \t\t}) {}\n *\n * \t\t// @ts-expect-error Recursion limit\n * \t\tallowUnused<FixRecursiveRecursionLimit<typeof LargeUnionObjectNode_Fix>>();\n * \t\tallowUnused<FixRecursiveRecursionLimit<typeof LargeUnionObjectNode_Fix>>();\n * \t\tallowUnused<ValidateRecursiveSchema<typeof LargeUnionObjectNode_Fix>>();\n * \t\t}\n *\n * \t// Fails to compile without the above workaround.\n * \tclass LargeUnionObjectNode extends schema.object(\"ObjectNode\", { x: largeUnion }) {}\n * ```\n * @privateRemarks\n * Using this is real sketchy, and leads to a lot of issues (errors which depend on how the schema is compiled, making different build setups produce different results and complicating exports).\n * This is being kept as internal for now: if a customer really needs it, we have this as a documented workaround, but it would be much better to find an alternative solution before using this one.\n * This uses ValidateRecursiveSchemaTemplate since it was found to evaluate enough of the type to work.\n * @internal\n */\nexport type FixRecursiveRecursionLimit<T extends TreeNodeSchemaClass> =\n\tT extends ValidateRecursiveSchemaTemplate<T> ? undefined : undefined;\n\n/**\n * Does nothing with the provided value, but appears to use it to make unused locals warnings and errors go away.\n *\n * @remarks\n * When TypeScript is configured with \"noUnusedLocals\", it will produce an error if a local variable is declared but never used.\n * When you want to have this check enabled, but not follow it for a specific variable, you can pass the type or value to this function.\n *\n * Instead of using this, consider disabling \"noUnusedLocals\" in your tsconfig.json file, and enabling a similar check via a linter.\n * This will allow you to still have the check, but have more control over it, for example being able to suppress it, or enable patterns like allowing unused locals with an \"_\" prefix.\n * @alpha\n */\nexport function allowUnused<T>(t?: T): void {}\n\n/**\n * Workaround for fixing errors resulting from an issue with recursive ArrayNode schema exports.\n * @remarks\n * Importing a recursive ArrayNode schema via a d.ts file can produce an error like\n * `error TS2310: Type 'RecursiveArray' recursively references itself as a base type.`\n * if using a tsconfig with `\"skipLibCheck\": false`.\n *\n * This error occurs due to the TypeScript compiler splitting the class definition into two separate declarations in the d.ts file (one for the base, and one for the actual class).\n * For unknown reasons, splitting the class declaration in this way breaks the recursive type handling, leading to the mentioned error.\n *\n * This type always evaluates to `undefined` to ensure the dummy export (which doesn't exist at runtime) is typed correctly.\n *\n * {@link https://github.com/microsoft/TypeScript/issues/59550|TypeScript Issue 59550} tracks a suggestion which would make this workaround unnecessary.\n *\n * @example Usage\n * Since recursive type handling in TypeScript is order dependent, putting just the right kind of usages of the type before the declarations can cause it to not hit this error.\n * For the case of ArrayNodes, this can be done via usage that looks like this:\n *\n * This example should use a doc comment to ensure the workaround comment shows up in the intellisense for the dummy export,\n * however doing so is impossible due to how this example is included in a doc comment.\n * ```typescript\n * // Workaround to avoid\n * // `error TS2310: Type 'RecursiveArray' recursively references itself as a base type.` in the d.ts file.\n * export declare type _RecursiveArrayWorkaround = FixRecursiveArraySchema<typeof RecursiveArray>;\n * export class RecursiveArray extends schema.arrayRecursive(\"RA\", [() => RecursiveArray]) {}\n * {\n * \ttype _check = ValidateRecursiveSchema<typeof RecursiveArray>;\n * }\n * ```\n *\n * @beta\n */\nexport type FixRecursiveArraySchema<T> = T extends TreeNodeSchema ? undefined : undefined;\n"]}
|
|
1
|
+
{"version":3,"file":"schemaFactoryRecursive.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFactoryRecursive.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA+OH,mEAAmE;AAEnE;;;;;;;;;;GAUG;AACH,SAAgB,WAAW,CAAI,CAAK,IAAS,CAAC;AAA9C,kCAA8C","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { RestrictiveStringRecord } from \"../../util/index.js\";\nimport type {\n\tNodeKind,\n\tTreeNodeSchema,\n\tWithType,\n\tTreeNode,\n\tImplicitAllowedTypes,\n\tInsertableTreeNodeFromImplicitAllowedTypes,\n\tTreeNodeSchemaClass,\n} from \"../core/index.js\";\nimport type { InsertableObjectFromSchemaRecord } from \"../node-kinds/index.js\";\nimport type { ImplicitFieldSchema } from \"../fieldSchema.js\";\n\n/**\n * Compile time check for validity of a recursive schema.\n * This type also serves as a central location for documenting the requirements and issues related to recursive schema.\n *\n * @example\n * ```typescript\n * class Test extends sf.arrayRecursive(\"Test\", [() => Test]) {}\n * {\n * type _check = ValidateRecursiveSchema<typeof Test>;\n * }\n * ```\n * @remarks\n * In this context recursive schema are defined as all {@link FieldSchema} and {@link TreeNodeSchema} schema which are part of a cycle such that walking down through each {@link TreeNodeSchemaCore.childTypes} the given starting schema can be reached again.\n * Schema referencing the recursive schema and schema they reference that are not part of a cycle are not considered recursive.\n *\n * TypeScript puts a lot of limitations on the typing of recursive schema.\n * To help avoid running into these limitations and thus getting schema that do not type check (or only type checks sometimes!),\n * {@link SchemaFactory} provides APIs (postfixed with `Recursive`) for writing recursive schema.\n * These APIs when combined with the patterns documented below should ensure that the schema provide robust type checking.\n * These special patterns (other than {@link LazyItem} forward references which are not recursion specific)\n * are not required for correct runtime behavior: they exist entirely to mitigate TypeScript type checking limitations and bugs.\n * Ideally TypeScript's type checker would be able to handle all of these cases and more, removing the need for recursive type specific guidance, rules and APIs.\n * Currently however there are open issues preventing this:\n * {@link https://github.com/microsoft/TypeScript/issues/59550 | 1},\n * {@link https://github.com/microsoft/TypeScript/issues/55832 | 2},\n * {@link https://github.com/microsoft/TypeScript/issues/55758 | 3}.\n * Note that the proposed resolution to some of these issues is for the compiler to error rather than allow the case,\n * so even if these are all resolved the recursive type workarounds may still be needed.\n *\n * # Patterns\n *\n * Below are patterns for how to use recursive schema.\n *\n * ## General Patterns\n *\n * When defining a recursive {@link TreeNodeSchema}, use the `*Recursive` {@link SchemaFactory} methods.\n * The returned class should be used as the base class for the recursive schema, which should then be passed to {@link ValidateRecursiveSchema}.\n *\n * Using {@link ValidateRecursiveSchema} will provide compile error for some of the cases of malformed schema.\n * This can be used to help mitigate the issue that recursive schema definitions are {@link Unenforced}.\n * If an issue is encountered where a mistake in a recursive schema is made which produces an invalid schema but is not rejected by this checker,\n * it should be considered a bug and this should be updated to handle that case (or have a disclaimer added to these docs that it misses that case).\n *\n * The non-recursive versions of the schema building methods will run into several issues when used recursively.\n * Consider the following example:\n *\n * ```typescript\n * const Test = sf.array(Test); // Bad\n * ```\n *\n * This has several issues:\n *\n * 1. It is a structurally named schema.\n * Structurally named schema derive their name from the names of their child types, which is not possible when the type is recursive since its name would include itself.\n * Instead a name must be explicitly provided.\n *\n * 2. The schema accesses itself before it's defined.\n * This would be a runtime error if the TypeScript compiler allowed it.\n * This can be fixed by wrapping the type in a function, which also requires explicitly listing the allowed types in an array (`[() => Test]`).\n *\n * 3. TypeScript fails to infer the recursive type and falls back to `any` with this warning or error (depending on the compiler configuration):\n * `'Test' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)`.\n * This issue is what the specialized recursive schema building methods fix.\n * This fix comes at a cost: to make the recursive cases work, the `extends` clauses had to be removed.\n * This means that mistakes declaring recursive schema often don't give compile errors in the schema.\n * Additionally support for implicit construction had to be disabled.\n * This means that new nested {@link Unhydrated} nodes can not be created like `new Test([[]])`.\n * Instead the nested nodes must be created explicitly using the construction like`new Test([new Test([])])`.\n *\n * 4. It is using \"POJO\" mode since it's not explicitly declaring a new class.\n * This means that the generated d.ts files for the schema replace recursive references with `any`, breaking use of recursive schema across compilation boundaries.\n * This is fixed by explicitly creating a class which extends the returned schema.\n *\n * All together, the fixed version looks like:\n * ```typescript\n * class Test extends sf.arrayRecursive(\"Test\", [() => Test]) {} // Good\n * ```\n *\n * Be very careful when declaring recursive schema.\n * Due to the removed extends clauses, subtle mistakes will compile just fine but cause strange errors when the schema is used.\n *\n * For example if a reference to a schema is malformed (in this case boxed inside an object):\n *\n * ```typescript\n * class Test extends sf.arrayRecursive(\"Test\", [() => ({ Test })]) {} // Bad\n * ```\n * This schema will still compile, and some (but not all) usages of it may look like they work correctly while other usages will produce generally unintelligible compile errors.\n * This issue can be partially mitigated using {@link ValidateRecursiveSchema}:\n *\n * ```typescript\n * class Test extends sf.arrayRecursive(\"Test\", [() => ({ Test })]) {} // Bad\n * {\n * type _check = ValidateRecursiveSchema<typeof Test>; // Reports compile error due to invalid schema above.\n * }\n * ```\n *\n * If your TypeScript configuration objects to this patten due to the unused local, you can use {@link allowUnused} to suppress the error:\n *\n * ```typescript\n * class Test extends sf.arrayRecursive(\"Test\", [() => ({ Test })]) {} // Bad\n * allowUnused<ValidateRecursiveSchema<typeof Test>>(); // Reports compile error due to invalid schema above.\n * ```\n *\n * ## Object Schema\n *\n * When defining fields, if the fields is part of the recursive cycle, use the `*Recursive` {@link SchemaFactory} methods for defining the {@link FieldSchema}.\n *\n * ## Array Schema\n *\n * See {@link FixRecursiveArraySchema} for array specific details.\n *\n * @privateRemarks\n * There are probably mistakes this misses: it's hard to guess all the wrong things people will accidentally do and defend against them.\n * Hopefully over time this can grow toward being robust, at least for common mistakes.\n *\n * This check duplicates logic that ideally would be entirely decided by the actual schema building methods.\n * Therefore changes to those methods may require updating `ValidateRecursiveSchema`.\n *\n * TODO: this currently does not reject `any`, but ideally should.\n * @public\n */\nexport type ValidateRecursiveSchema<T extends ValidateRecursiveSchemaTemplate<T>> = true;\n\n/**\n * Validation logic used by {@link ValidateRecursiveSchema}.\n * @privateRemarks\n * Recursive types should always be using TreeNodeSchemaClass (not TreeNodeSchemaNonClass) as that's part of the requirements for the type to work across compilation boundaries correctly.\n * @system @public\n */\nexport type ValidateRecursiveSchemaTemplate<T extends TreeNodeSchemaClass> =\n\tTreeNodeSchemaClass<\n\t\t// Name: This validator places no restrictions on the name other than that it's a string (as required by TreeNodeSchemaClass).\n\t\tstring,\n\t\t// NodeKind: These are the NodeKinds which currently can be used recursively.\n\t\tNodeKind.Array | NodeKind.Map | NodeKind.Object | NodeKind.Record,\n\t\t// TNode: The produced node API. This is pretty minimal validation: more could be added if similar to how TInsertable works below if needed.\n\t\tTreeNode & WithType<T[\"identifier\"], T[\"kind\"]>,\n\t\t// TInsertable: What can be passed to the constructor. This should be enough to catch most issues with incorrect schema.\n\t\t// These match whats defined in the recursive methods on `SchemaFactory` except they do not use `Unenforced`.\n\t\t{\n\t\t\t[NodeKind.Object]: T[\"info\"] extends RestrictiveStringRecord<ImplicitFieldSchema>\n\t\t\t\t? InsertableObjectFromSchemaRecord<T[\"info\"]>\n\t\t\t\t: unknown;\n\t\t\t[NodeKind.Array]: T[\"info\"] extends ImplicitAllowedTypes\n\t\t\t\t? Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T[\"info\"]>>\n\t\t\t\t: unknown;\n\t\t\t[NodeKind.Map]: T[\"info\"] extends ImplicitAllowedTypes\n\t\t\t\t? Iterable<[string, InsertableTreeNodeFromImplicitAllowedTypes<T[\"info\"]>]>\n\t\t\t\t: unknown;\n\t\t\t[NodeKind.Record]: {\n\t\t\t\treadonly [P in string]: InsertableTreeNodeFromImplicitAllowedTypes<T>;\n\t\t\t};\n\t\t\t[NodeKind.Leaf]: unknown;\n\t\t}[T[\"kind\"]],\n\t\t// ImplicitlyConstructable: recursive types are currently not implicitly constructable.\n\t\tfalse,\n\t\t// Info: What's passed to the method to create the schema. Constraining these here should be about as effective as if the actual constraints existed on the actual method itself.\n\t\t{\n\t\t\t[NodeKind.Object]: RestrictiveStringRecord<ImplicitFieldSchema>;\n\t\t\t[NodeKind.Array]: ImplicitAllowedTypes;\n\t\t\t[NodeKind.Map]: ImplicitAllowedTypes;\n\t\t\t[NodeKind.Record]: ImplicitAllowedTypes;\n\t\t\t[NodeKind.Leaf]: unknown;\n\t\t}[T[\"kind\"]]\n\t>;\n\n/* eslint-disable @fluid-internal/fluid/no-hyphen-after-jsdoc-tag -- false positive AB#50920 */\n/**\n * Workaround for \"Type instantiation is excessively deep and possibly infinite.ts\" errors.\n * @remarks\n *\n * Generally this workaround should be avoided if possible,\n * especially for exported types, as it is likely to result in issues when exporting or importing schema where the user will be forced to use the workaround as well.\n * This is particularly problematic since in some cases it may not be possible for the user to replicate the pattern.\n * Additionally, which cases hit these limits may vary based on TypeScript version and implementation details of this library.\n *\n * This workaround is provided and documented as a last resort to be able to keep an app compiling.\n * Future version of SharedTree should provide schema type erasure functionality as a better alternative for most cases.\n *\n * When TypeScript gives the error \"Error (TS2589) Type instantiation is excessively deep and possibly infinite.\" on the invocation of `ValidateRecursiveSchema`\n * for a large schema, it can sometimes be worked around by repeating the usage of the type multiple times.\n * This works because the TypeScript compiler caches some of the intermediate results from the first usage, and thus can get further on the second.\n *\n * This utility can be referenced when applying this pattern.\n * For recursive types this can be used directly:\n *\n * ```typescript\n * {\n * // @ts-expect-error Recursion limit\n * type _check1 = FixRecursiveRecursionLimit<typeof LargeType>;\n * type _check2 = FixRecursiveRecursionLimit<typeof LargeType>;\n * type _check3 = ValidateRecursiveSchemaTemplate<typeof LargeType>;\n * }\n * ```\n *\n * For non-recursive types, they can be ported to the more flexible recursive APIs and use the pattern above.\n *\n * Non-recursive types can also use this workaround by making a duplicate copy of the problematic schema written using the recursive APIs.\n * Then this pattern can be applied to the duplicate copy.\n *\n * ```typescript\n * // Workaround TypeScript recursion limit\n * \t{\n * \t\tclass LargeUnionObjectNode_Fix extends schema.objectRecursive(\"ObjectNode\", {\n * \t\t\tx: largeUnion,\n * \t\t}) {}\n *\n * \t\t// @ts-expect-error Recursion limit\n * \t\tallowUnused<FixRecursiveRecursionLimit<typeof LargeUnionObjectNode_Fix>>();\n * \t\tallowUnused<FixRecursiveRecursionLimit<typeof LargeUnionObjectNode_Fix>>();\n * \t\tallowUnused<ValidateRecursiveSchema<typeof LargeUnionObjectNode_Fix>>();\n * \t\t}\n *\n * \t// Fails to compile without the above workaround.\n * \tclass LargeUnionObjectNode extends schema.object(\"ObjectNode\", { x: largeUnion }) {}\n * ```\n * @privateRemarks\n * Using this is real sketchy, and leads to a lot of issues (errors which depend on how the schema is compiled, making different build setups produce different results and complicating exports).\n * This is being kept as internal for now: if a customer really needs it, we have this as a documented workaround, but it would be much better to find an alternative solution before using this one.\n * This uses ValidateRecursiveSchemaTemplate since it was found to evaluate enough of the type to work.\n * @internal\n */\nexport type FixRecursiveRecursionLimit<T extends TreeNodeSchemaClass> =\n\tT extends ValidateRecursiveSchemaTemplate<T> ? undefined : undefined;\n/* eslint-enable @fluid-internal/fluid/no-hyphen-after-jsdoc-tag */\n\n/**\n * Does nothing with the provided value, but appears to use it to make unused locals warnings and errors go away.\n *\n * @remarks\n * When TypeScript is configured with \"noUnusedLocals\", it will produce an error if a local variable is declared but never used.\n * When you want to have this check enabled, but not follow it for a specific variable, you can pass the type or value to this function.\n *\n * Instead of using this, consider disabling \"noUnusedLocals\" in your tsconfig.json file, and enabling a similar check via a linter.\n * This will allow you to still have the check, but have more control over it, for example being able to suppress it, or enable patterns like allowing unused locals with an \"_\" prefix.\n * @alpha\n */\nexport function allowUnused<T>(t?: T): void {}\n\n/**\n * Workaround for fixing errors resulting from an issue with recursive ArrayNode schema exports.\n * @remarks\n * Importing a recursive ArrayNode schema via a d.ts file can produce an error like\n * `error TS2310: Type 'RecursiveArray' recursively references itself as a base type.`\n * if using a tsconfig with `\"skipLibCheck\": false`.\n *\n * This error occurs due to the TypeScript compiler splitting the class definition into two separate declarations in the d.ts file (one for the base, and one for the actual class).\n * For unknown reasons, splitting the class declaration in this way breaks the recursive type handling, leading to the mentioned error.\n *\n * This type always evaluates to `undefined` to ensure the dummy export (which doesn't exist at runtime) is typed correctly.\n *\n * {@link https://github.com/microsoft/TypeScript/issues/59550|TypeScript Issue 59550} tracks a suggestion which would make this workaround unnecessary.\n *\n * @example Usage\n * Since recursive type handling in TypeScript is order dependent, putting just the right kind of usages of the type before the declarations can cause it to not hit this error.\n * For the case of ArrayNodes, this can be done via usage that looks like this:\n *\n * This example should use a doc comment to ensure the workaround comment shows up in the intellisense for the dummy export,\n * however doing so is impossible due to how this example is included in a doc comment.\n * ```typescript\n * // Workaround to avoid\n * // `error TS2310: Type 'RecursiveArray' recursively references itself as a base type.` in the d.ts file.\n * export declare type _RecursiveArrayWorkaround = FixRecursiveArraySchema<typeof RecursiveArray>;\n * export class RecursiveArray extends schema.arrayRecursive(\"RA\", [() => RecursiveArray]) {}\n * {\n * \ttype _check = ValidateRecursiveSchema<typeof RecursiveArray>;\n * }\n * ```\n *\n * @beta\n */\nexport type FixRecursiveArraySchema<T> = T extends TreeNodeSchema ? undefined : undefined;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaFromSimple.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFromSimple.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"schemaFromSimple.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFromSimple.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,OAAO,KAAK,EAIX,gBAAgB,EAChB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAKrD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU,CAmBnF"}
|
|
@@ -42,7 +42,7 @@ function generateSchemaFromSimpleSchema(simple) {
|
|
|
42
42
|
}
|
|
43
43
|
exports.generateSchemaFromSimpleSchema = generateSchemaFromSimpleSchema;
|
|
44
44
|
function generateFieldSchema(simple, context, storedKey) {
|
|
45
|
-
const allowed = generateAllowedTypes(simple.
|
|
45
|
+
const allowed = generateAllowedTypes(simple.simpleAllowedTypes, context);
|
|
46
46
|
const props = {
|
|
47
47
|
metadata: simple.metadata,
|
|
48
48
|
key: storedKey,
|
|
@@ -60,7 +60,7 @@ function generateFieldSchema(simple, context, storedKey) {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
function generateAllowedTypes(allowed, context) {
|
|
63
|
-
return
|
|
63
|
+
return Array.from(allowed.keys(), (id) => context.get(id) ?? (0, internal_1.fail)(0xb5a /* Missing schema */));
|
|
64
64
|
}
|
|
65
65
|
function generateNode(id, schema, context) {
|
|
66
66
|
switch (schema.kind) {
|
|
@@ -74,11 +74,15 @@ function generateNode(id, schema, context) {
|
|
|
74
74
|
return factory.objectAlpha(id, fields, { metadata: schema.metadata });
|
|
75
75
|
}
|
|
76
76
|
case index_js_1.NodeKind.Array:
|
|
77
|
-
return factory.arrayAlpha(id, generateAllowedTypes(schema.
|
|
77
|
+
return factory.arrayAlpha(id, generateAllowedTypes(schema.simpleAllowedTypes, context), {
|
|
78
|
+
metadata: schema.metadata,
|
|
79
|
+
});
|
|
78
80
|
case index_js_1.NodeKind.Map:
|
|
79
|
-
return factory.mapAlpha(id, generateAllowedTypes(schema.
|
|
81
|
+
return factory.mapAlpha(id, generateAllowedTypes(schema.simpleAllowedTypes, context), {
|
|
82
|
+
metadata: schema.metadata,
|
|
83
|
+
});
|
|
80
84
|
case index_js_1.NodeKind.Record:
|
|
81
|
-
return factory.recordAlpha(id, generateAllowedTypes(schema.
|
|
85
|
+
return factory.recordAlpha(id, generateAllowedTypes(schema.simpleAllowedTypes, context), { metadata: schema.metadata });
|
|
82
86
|
case index_js_1.NodeKind.Leaf:
|
|
83
87
|
return (schemaFactoryAlpha_js_1.SchemaFactoryAlpha.leaves.find((leaf) => leaf.identifier === id) ??
|
|
84
88
|
(0, internal_1.fail)(0xb5b /* Missing schema */));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaFromSimple.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFromSimple.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA4E;AAE5E,+CAAoF;AACpF,sDAK2B;
|
|
1
|
+
{"version":3,"file":"schemaFromSimple.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFromSimple.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA4E;AAE5E,+CAAoF;AACpF,sDAK2B;AAS3B,mEAA6D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,CAAC,GAAG;YAChB,OAAO,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,oBAAoB,CAAC,MAAM,CAAC,kBAAkB,EAAE,OAAO,CAAC,EAAE;gBACrF,QAAQ,EAAE,MAAM,CAAC,QAAQ;aACzB,CAAC,CAAC;QACJ,KAAK,mBAAQ,CAAC,MAAM;YACnB,OAAO,OAAO,CAAC,WAAW,CACzB,EAAE,EACF,oBAAoB,CAAC,MAAM,CAAC,kBAAkB,EAAE,OAAO,CAAC,EACxD,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAC7B,CAAC;QACH,KAAK,mBAAQ,CAAC,IAAI;YACjB,OAAO,CACN,0CAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,KAAK,EAAE,CAAC;gBAChE,IAAA,eAAI,EAAC,KAAK,CAAC,oBAAoB,CAAC,CAChC,CAAC;QACH;YACC,OAAO,IAAA,0BAAe,EAAC,MAAM,CAAC,CAAC;IACjC,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { unreachableCase, fail } from \"@fluidframework/core-utils/internal\";\n\nimport { NodeKind, type TreeNodeSchema, type AllowedTypes } from \"../core/index.js\";\nimport {\n\ttype FieldSchema,\n\ttype FieldSchemaAlpha,\n\tFieldKind,\n\ttype FieldProps,\n} from \"../fieldSchema.js\";\nimport type {\n\tSimpleAllowedTypeAttributes,\n\tSimpleFieldSchema,\n\tSimpleNodeSchema,\n\tSimpleTreeSchema,\n} from \"../simpleSchema.js\";\n\nimport type { TreeSchema } from \"./configuration.js\";\nimport { SchemaFactoryAlpha } from \"./schemaFactoryAlpha.js\";\n\nconst factory = new SchemaFactoryAlpha(undefined);\n\n/**\n * Create {@link FieldSchema} from a SimpleTreeSchema.\n * @remarks\n * Only use this API if hand written schema (produced using {@link SchemaFactory} cannot be provided.\n *\n * Using generated schema with schema aware APIs (designed to work with strongly typed schema) like {@link TreeViewConfiguration}\n * will produce a poor TypeScript typing experience which is subject to change.\n *\n * Editing through a view produced using this schema can easily violate invariants other users of the document might expect and must be done with great care.\n *\n * This API bakes in some arbitrary policy choices for how to handle data that is not included in the SimpleTreeSchema API, for example the value of `allowUnknownOptionalFields`.\n * If any particular choice is required for such cases, this API should not be used.\n * @alpha\n */\nexport function generateSchemaFromSimpleSchema(simple: SimpleTreeSchema): TreeSchema {\n\tconst context: Context = new Map(\n\t\t[...simple.definitions].map(\n\t\t\t([id, schema]): [string, () => TreeNodeSchema & SimpleNodeSchema] => [\n\t\t\t\tid,\n\t\t\t\t// This relies on the caching in evaluateLazySchema so that it only runs once.\n\t\t\t\t() => generateNode(id, schema, context),\n\t\t\t],\n\t\t),\n\t);\n\tconst root = generateFieldSchema(simple.root, context, undefined);\n\tconst definitions = new Map<string, TreeNodeSchema & SimpleNodeSchema>();\n\tfor (const [id, lazy] of context) {\n\t\tdefinitions.set(id, lazy());\n\t}\n\treturn {\n\t\troot,\n\t\tdefinitions,\n\t};\n}\n\ntype Context = ReadonlyMap<string, () => TreeNodeSchema & SimpleNodeSchema>;\n\nfunction generateFieldSchema(\n\tsimple: SimpleFieldSchema,\n\tcontext: Context,\n\tstoredKey: string | undefined,\n): FieldSchemaAlpha {\n\tconst allowed = generateAllowedTypes(simple.simpleAllowedTypes, context);\n\tconst props: Omit<FieldProps, \"defaultProvider\"> = {\n\t\tmetadata: simple.metadata,\n\t\tkey: storedKey,\n\t};\n\n\t// Using createFieldSchema could work, but would require setting up the default providers.\n\tswitch (simple.kind) {\n\t\tcase FieldKind.Identifier:\n\t\t\treturn SchemaFactoryAlpha.identifier(props);\n\t\tcase FieldKind.Optional:\n\t\t\treturn SchemaFactoryAlpha.optional(allowed, props);\n\t\tcase FieldKind.Required:\n\t\t\treturn SchemaFactoryAlpha.required(allowed, props);\n\t\tdefault:\n\t\t\treturn unreachableCase(simple.kind);\n\t}\n}\n\nfunction generateAllowedTypes(\n\tallowed: ReadonlyMap<string, SimpleAllowedTypeAttributes>,\n\tcontext: Context,\n): AllowedTypes {\n\treturn Array.from(\n\t\tallowed.keys(),\n\t\t(id) => context.get(id) ?? fail(0xb5a /* Missing schema */),\n\t);\n}\n\nfunction generateNode(\n\tid: string,\n\tschema: SimpleNodeSchema,\n\tcontext: Context,\n): TreeNodeSchema & SimpleNodeSchema {\n\tswitch (schema.kind) {\n\t\tcase NodeKind.Object: {\n\t\t\tconst fields: Record<string, FieldSchema> = {};\n\t\t\tfor (const [key, field] of schema.fields) {\n\t\t\t\tfields[key] = generateFieldSchema(field, context, field.storedKey);\n\t\t\t}\n\t\t\t// Here allowUnknownOptionalFields is implicitly defaulting. This is a subjective policy choice:\n\t\t\t// users of this code are expected to handle what ever choice this code makes for cases like this.\n\t\t\treturn factory.objectAlpha(id, fields, { metadata: schema.metadata });\n\t\t}\n\t\tcase NodeKind.Array:\n\t\t\treturn factory.arrayAlpha(id, generateAllowedTypes(schema.simpleAllowedTypes, context), {\n\t\t\t\tmetadata: schema.metadata,\n\t\t\t});\n\t\tcase NodeKind.Map:\n\t\t\treturn factory.mapAlpha(id, generateAllowedTypes(schema.simpleAllowedTypes, context), {\n\t\t\t\tmetadata: schema.metadata,\n\t\t\t});\n\t\tcase NodeKind.Record:\n\t\t\treturn factory.recordAlpha(\n\t\t\t\tid,\n\t\t\t\tgenerateAllowedTypes(schema.simpleAllowedTypes, context),\n\t\t\t\t{ metadata: schema.metadata },\n\t\t\t);\n\t\tcase NodeKind.Leaf:\n\t\t\treturn (\n\t\t\t\tSchemaFactoryAlpha.leaves.find((leaf) => leaf.identifier === id) ??\n\t\t\t\tfail(0xb5b /* Missing schema */)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn unreachableCase(schema);\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simpleSchemaToJsonSchema.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/simpleSchemaToJsonSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAQX,oBAAoB,EACpB,cAAc,EAGd,MAAM,iBAAiB,CAAC;AASzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAIN,gBAAgB,EAChB,MAAM,wBAAwB,CAAC;AAIhC;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC3B,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAC1C,cAAc,CAqBhB;
|
|
1
|
+
{"version":3,"file":"simpleSchemaToJsonSchema.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/simpleSchemaToJsonSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAQX,oBAAoB,EACpB,cAAc,EAGd,MAAM,iBAAiB,CAAC;AASzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAIN,gBAAgB,EAChB,MAAM,wBAAwB,CAAC;AAIhC;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC3B,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAC1C,cAAc,CAqBhB;AAqFD,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,QAAQ,CAAC,yBAAyB,CAAC,GAC1C,oBAAoB,CA4CtB"}
|
|
@@ -72,7 +72,8 @@ function convertNodeSchema(schema, options) {
|
|
|
72
72
|
}
|
|
73
73
|
function convertArrayNodeSchema(schema) {
|
|
74
74
|
const allowedTypes = [];
|
|
75
|
-
schema.
|
|
75
|
+
const allowedTypesIdentifiers = new Set(schema.simpleAllowedTypes.keys());
|
|
76
|
+
allowedTypesIdentifiers.forEach((type) => {
|
|
76
77
|
allowedTypes.push(createSchemaRef(type));
|
|
77
78
|
});
|
|
78
79
|
const items = (0, index_js_2.hasSingle)(allowedTypes)
|
|
@@ -150,7 +151,8 @@ function convertObjectNodeSchema(schema, options) {
|
|
|
150
151
|
exports.convertObjectNodeSchema = convertObjectNodeSchema;
|
|
151
152
|
function convertRecordLikeNodeSchema(schema) {
|
|
152
153
|
const allowedTypes = [];
|
|
153
|
-
schema.
|
|
154
|
+
const allowedTypesIdentifiers = new Set(schema.simpleAllowedTypes.keys());
|
|
155
|
+
allowedTypesIdentifiers.forEach((type) => {
|
|
154
156
|
allowedTypes.push(createSchemaRef(type));
|
|
155
157
|
});
|
|
156
158
|
const output = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simpleSchemaToJsonSchema.js","sourceRoot":"","sources":["../../../src/simple-tree/api/simpleSchemaToJsonSchema.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAsE;AACtE,uEAAsE;AACtE,kDAAkD;AAClD,kDAA4E;AAc5E,sDAA8C;AAO9C,+CAAiE;AAGjE,qDAKgC;AAChC,4DAAsD;AACtD,mDAAqD;AAErD;;;;;;;GAOG;AACH,SAAgB,YAAY,CAC3B,MAAkB,EAClB,OAA4C;IAE5C,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAEpE,MAAM,YAAY,GAAoB,EAAE,CAAC;IACzC,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC/D,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,gHAAgH;IAChH,qFAAqF;IACrF,iDAAiD;IACjD,mDAAmD;IACnD,OAAO,IAAA,oBAAS,EAAC,YAAY,CAAC;QAC7B,CAAC,CAAC;YACA,G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D;IAEpD,MAAM,YAAY,GAAoB,EAAE,CAAC;IACzC,MAAM,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC/C,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG;QACd,IAAI,EAAE,QAAQ;QACd,mBAAmB,EAAE,MAAM,CAAC,IAAI;QAChC,iBAAiB,EAAE;YAClB,MAAM,EAAE,IAAA,oBAAS,EAAC,YAAY,CAAC;gBAC9B,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;gBACjB,CAAC,CAAC;oBACA,KAAK,EAAE,YAAY;iBACnB;SACH;KACQ,CAAC;IAEX,IAAA,uBAAY,EAAC,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;IAErD,OAAO,MAAM,CAAC;AACf,CAAC;AAED,SAAS,eAAe,CAAC,QAAgB;IACxC,OAAO;QACN,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC;KAC/B,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,QAAgB;IACtC,OAAO,WAAW,QAAQ,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { ValueSchema } from \"../../core/index.js\";\nimport { copyProperty, hasSingle, type Mutable } from \"../../util/index.js\";\nimport type {\n\tJsonArrayNodeSchema,\n\tJsonFieldSchema,\n\tJsonSchemaRef,\n\tJsonRefPath,\n\tJsonLeafNodeSchema,\n\tJsonMapNodeSchema,\n\tJsonNodeSchema,\n\tJsonObjectNodeSchema,\n\tJsonTreeSchema,\n\tJsonLeafSchemaType,\n\tJsonRecordNodeSchema,\n} from \"./jsonSchema.js\";\nimport { FieldKind } from \"../fieldSchema.js\";\nimport type {\n\tSimpleArrayNodeSchema,\n\tSimpleLeafNodeSchema,\n\tSimpleMapNodeSchema,\n\tSimpleRecordNodeSchema,\n} from \"../simpleSchema.js\";\nimport { NodeKind, type TreeNodeSchema } from \"../core/index.js\";\nimport type { TreeSchema } from \"./configuration.js\";\nimport type { TreeSchemaEncodingOptions } from \"./getJsonSchema.js\";\nimport {\n\tArrayNodeSchema,\n\tisMapNodeSchema,\n\tisRecordNodeSchema,\n\tObjectNodeSchema,\n} from \"../node-kinds/index.js\";\nimport { LeafNodeSchema } from \"../leafNodeSchema.js\";\nimport { KeyEncodingOptions } from \"./customTree.js\";\n\n/**\n * Generates a JSON Schema representation from a simple tree schema.\n * @remarks\n * This expects the data to be in the {@link ConciseTree} format.\n *\n * This cannot handle the case where the root is undefined since undefined is not a concept in JSON.\n * This also cannot handle {@link SchemaStatics.handle} since they also are not supported in JSON.\n */\nexport function toJsonSchema(\n\tschema: TreeSchema,\n\toptions: Required<TreeSchemaEncodingOptions>,\n): JsonTreeSchema {\n\tconst definitions = convertDefinitions(schema.definitions, options);\n\n\tconst allowedTypes: JsonSchemaRef[] = [];\n\tfor (const allowedType of schema.root.allowedTypesIdentifiers) {\n\t\tallowedTypes.push(createSchemaRef(allowedType));\n\t}\n\n\t// TODO: deduplicate field handling logic from convertObjectNodeSchema: at least include metadata's description.\n\t// TODO: maybe account for consider schema.kind, or just take in ImplicitAllowedTypes\n\t// TODO: handle case where allowedTypes is empty.\n\t// TODO: handle staged types in a controllable way.\n\treturn hasSingle(allowedTypes)\n\t\t? {\n\t\t\t\t...allowedTypes[0],\n\t\t\t\t$defs: definitions,\n\t\t\t}\n\t\t: {\n\t\t\t\t$defs: definitions,\n\t\t\t\tanyOf: allowedTypes,\n\t\t\t};\n}\n\nfunction convertDefinitions(\n\tdefinitions: ReadonlyMap<string, TreeNodeSchema>,\n\toptions: Required<TreeSchemaEncodingOptions>,\n): Record<string, JsonNodeSchema> {\n\tconst result: Record<string, JsonNodeSchema> = {};\n\tfor (const [key, value] of definitions) {\n\t\tresult[key] = convertNodeSchema(value, options);\n\t}\n\treturn result;\n}\n\n/**\n * Converts an input {@link SimpleNodeSchema} to a {@link JsonNodeSchema}.\n *\n * @remarks Caches the result on the input schema for future calls.\n */\nfunction convertNodeSchema(\n\tschema: TreeNodeSchema,\n\toptions: Required<TreeSchemaEncodingOptions>,\n): JsonNodeSchema {\n\tif (schema instanceof ArrayNodeSchema) {\n\t\treturn convertArrayNodeSchema(schema);\n\t} else if (isMapNodeSchema(schema) || isRecordNodeSchema(schema)) {\n\t\treturn convertRecordLikeNodeSchema(schema);\n\t} else if (schema instanceof ObjectNodeSchema) {\n\t\treturn convertObjectNodeSchema(schema, options);\n\t} else if (schema instanceof LeafNodeSchema) {\n\t\treturn convertLeafNodeSchema(schema);\n\t}\n\tthrow new TypeError(`Unknown node schema kind: ${schema.kind}`);\n}\n\nfunction convertArrayNodeSchema(schema: SimpleArrayNodeSchema): JsonArrayNodeSchema {\n\tconst allowedTypes: JsonSchemaRef[] = [];\n\tschema.allowedTypesIdentifiers.forEach((type) => {\n\t\tallowedTypes.push(createSchemaRef(type));\n\t});\n\n\tconst items: JsonFieldSchema = hasSingle(allowedTypes)\n\t\t? allowedTypes[0]\n\t\t: { anyOf: allowedTypes };\n\n\tconst output: Mutable<JsonArrayNodeSchema> = {\n\t\ttype: \"array\",\n\t\t_treeNodeSchemaKind: NodeKind.Array,\n\t\titems,\n\t};\n\n\tcopyProperty(schema.metadata, \"description\", output);\n\n\treturn output;\n}\n\nfunction convertLeafNodeSchema(schema: SimpleLeafNodeSchema): JsonLeafNodeSchema {\n\tlet type: JsonLeafSchemaType;\n\tswitch (schema.leafKind) {\n\t\tcase ValueSchema.String:\n\t\t\ttype = \"string\";\n\t\t\tbreak;\n\t\tcase ValueSchema.Number:\n\t\t\ttype = \"number\";\n\t\t\tbreak;\n\t\tcase ValueSchema.Boolean:\n\t\t\ttype = \"boolean\";\n\t\t\tbreak;\n\t\tcase ValueSchema.Null:\n\t\t\ttype = \"null\";\n\t\t\tbreak;\n\t\tcase ValueSchema.FluidHandle:\n\t\t\tthrow new UsageError(\"Fluid handles are not supported via JSON Schema.\");\n\t\tdefault:\n\t\t\tunreachableCase(schema.leafKind);\n\t}\n\n\treturn {\n\t\ttype,\n\t\t_treeNodeSchemaKind: NodeKind.Leaf,\n\t};\n}\n\nexport function convertObjectNodeSchema(\n\tschema: ObjectNodeSchema,\n\toptions: Required<TreeSchemaEncodingOptions>,\n): JsonObjectNodeSchema {\n\tconst properties: Record<string, JsonFieldSchema> = {};\n\tconst required: string[] = [];\n\tfor (const [propertyKey, fieldSchema] of schema.fields) {\n\t\tconst key =\n\t\t\toptions.keys === KeyEncodingOptions.usePropertyKeys\n\t\t\t\t? propertyKey\n\t\t\t\t: fieldSchema.storedKey;\n\t\tconst allowedTypes: JsonSchemaRef[] = [];\n\t\tfor (const allowedType of fieldSchema.allowedTypesIdentifiers) {\n\t\t\tallowedTypes.push(createSchemaRef(allowedType));\n\t\t}\n\n\t\tconst output: Mutable<JsonFieldSchema> = hasSingle(allowedTypes)\n\t\t\t? allowedTypes[0]\n\t\t\t: {\n\t\t\t\t\tanyOf: allowedTypes,\n\t\t\t\t};\n\n\t\tcopyProperty(fieldSchema.metadata, \"description\", output);\n\t\tproperties[key] = output;\n\n\t\tif (fieldSchema.kind !== FieldKind.Optional) {\n\t\t\tif (\n\t\t\t\toptions.requireFieldsWithDefaults ||\n\t\t\t\tfieldSchema.props?.defaultProvider === undefined\n\t\t\t) {\n\t\t\t\trequired.push(key);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst transformedNode: Mutable<JsonObjectNodeSchema> = {\n\t\ttype: \"object\",\n\t\t_treeNodeSchemaKind: NodeKind.Object,\n\t\tproperties,\n\t\trequired,\n\t\t// TODO: support unknown optional fields (only when using \"allStoredKeys\", and constrain the content to be in schema somehow)\n\t\tadditionalProperties: false,\n\t};\n\n\tcopyProperty(schema.metadata, \"description\", transformedNode);\n\n\treturn transformedNode;\n}\n\nfunction convertRecordLikeNodeSchema(\n\tschema: SimpleRecordNodeSchema | SimpleMapNodeSchema,\n): JsonMapNodeSchema | JsonRecordNodeSchema {\n\tconst allowedTypes: JsonSchemaRef[] = [];\n\tschema.allowedTypesIdentifiers.forEach((type) => {\n\t\tallowedTypes.push(createSchemaRef(type));\n\t});\n\n\tconst output = {\n\t\ttype: \"object\",\n\t\t_treeNodeSchemaKind: schema.kind,\n\t\tpatternProperties: {\n\t\t\t\"^.*$\": hasSingle(allowedTypes)\n\t\t\t\t? allowedTypes[0]\n\t\t\t\t: {\n\t\t\t\t\t\tanyOf: allowedTypes,\n\t\t\t\t\t},\n\t\t},\n\t} as const;\n\n\tcopyProperty(schema.metadata, \"description\", output);\n\n\treturn output;\n}\n\nfunction createSchemaRef(schemaId: string): JsonSchemaRef {\n\treturn {\n\t\t\"$ref\": createRefPath(schemaId),\n\t};\n}\n\nfunction createRefPath(schemaId: string): JsonRefPath {\n\treturn `#/$defs/${schemaId}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"simpleSchemaToJsonSchema.js","sourceRoot":"","sources":["../../../src/simple-tree/api/simpleSchemaToJsonSchema.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAsE;AACtE,uEAAsE;AACtE,kDAAkD;AAClD,kDAA4E;AAc5E,sDAA8C;AAO9C,+CAAiE;AAGjE,qDAKgC;AAChC,4DAAsD;AACtD,mDAAqD;AAErD;;;;;;;GAOG;AACH,SAAgB,YAAY,CAC3B,MAAkB,EAClB,OAA4C;IAE5C,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAEpE,MAAM,YAAY,GAAoB,EAAE,CAAC;IACzC,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC/D,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,C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;QACV,QAAQ;QACR,6HAA6H;QAC7H,oBAAoB,EAAE,KAAK;KAC3B,CAAC;IAEF,IAAA,uBAAY,EAAC,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,eAAe,CAAC,CAAC;IAE9D,OAAO,eAAe,CAAC;AACxB,CAAC;AA/CD,0DA+CC;AAED,SAAS,2BAA2B,CACnC,MAAoD;IAEpD,MAAM,YAAY,GAAoB,EAAE,CAAC;IACzC,MAAM,uBAAuB,GAAwB,IAAI,GAAG,CAC3D,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAChC,CAAC;IACF,uBAAuB,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACxC,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG;QACd,IAAI,EAAE,QAAQ;QACd,mBAAmB,EAAE,MAAM,CAAC,IAAI;QAChC,iBAAiB,EAAE;YAClB,MAAM,EAAE,IAAA,oBAAS,EAAC,YAAY,CAAC;gBAC9B,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;gBACjB,CAAC,CAAC;oBACA,KAAK,EAAE,YAAY;iBACnB;SACH;KACQ,CAAC;IAEX,IAAA,uBAAY,EAAC,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;IAErD,OAAO,MAAM,CAAC;AACf,CAAC;AAED,SAAS,eAAe,CAAC,QAAgB;IACxC,OAAO;QACN,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC;KAC/B,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,QAAgB;IACtC,OAAO,WAAW,QAAQ,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { ValueSchema } from \"../../core/index.js\";\nimport { copyProperty, hasSingle, type Mutable } from \"../../util/index.js\";\nimport type {\n\tJsonArrayNodeSchema,\n\tJsonFieldSchema,\n\tJsonSchemaRef,\n\tJsonRefPath,\n\tJsonLeafNodeSchema,\n\tJsonMapNodeSchema,\n\tJsonNodeSchema,\n\tJsonObjectNodeSchema,\n\tJsonTreeSchema,\n\tJsonLeafSchemaType,\n\tJsonRecordNodeSchema,\n} from \"./jsonSchema.js\";\nimport { FieldKind } from \"../fieldSchema.js\";\nimport type {\n\tSimpleArrayNodeSchema,\n\tSimpleLeafNodeSchema,\n\tSimpleMapNodeSchema,\n\tSimpleRecordNodeSchema,\n} from \"../simpleSchema.js\";\nimport { NodeKind, type TreeNodeSchema } from \"../core/index.js\";\nimport type { TreeSchema } from \"./configuration.js\";\nimport type { TreeSchemaEncodingOptions } from \"./getJsonSchema.js\";\nimport {\n\tArrayNodeSchema,\n\tisMapNodeSchema,\n\tisRecordNodeSchema,\n\tObjectNodeSchema,\n} from \"../node-kinds/index.js\";\nimport { LeafNodeSchema } from \"../leafNodeSchema.js\";\nimport { KeyEncodingOptions } from \"./customTree.js\";\n\n/**\n * Generates a JSON Schema representation from a simple tree schema.\n * @remarks\n * This expects the data to be in the {@link ConciseTree} format.\n *\n * This cannot handle the case where the root is undefined since undefined is not a concept in JSON.\n * This also cannot handle {@link SchemaStatics.handle} since they also are not supported in JSON.\n */\nexport function toJsonSchema(\n\tschema: TreeSchema,\n\toptions: Required<TreeSchemaEncodingOptions>,\n): JsonTreeSchema {\n\tconst definitions = convertDefinitions(schema.definitions, options);\n\n\tconst allowedTypes: JsonSchemaRef[] = [];\n\tfor (const allowedType of schema.root.allowedTypesIdentifiers) {\n\t\tallowedTypes.push(createSchemaRef(allowedType));\n\t}\n\n\t// TODO: deduplicate field handling logic from convertObjectNodeSchema: at least include metadata's description.\n\t// TODO: maybe account for consider schema.kind, or just take in ImplicitAllowedTypes\n\t// TODO: handle case where allowedTypes is empty.\n\t// TODO: handle staged types in a controllable way.\n\treturn hasSingle(allowedTypes)\n\t\t? {\n\t\t\t\t...allowedTypes[0],\n\t\t\t\t$defs: definitions,\n\t\t\t}\n\t\t: {\n\t\t\t\t$defs: definitions,\n\t\t\t\tanyOf: allowedTypes,\n\t\t\t};\n}\n\nfunction convertDefinitions(\n\tdefinitions: ReadonlyMap<string, TreeNodeSchema>,\n\toptions: Required<TreeSchemaEncodingOptions>,\n): Record<string, JsonNodeSchema> {\n\tconst result: Record<string, JsonNodeSchema> = {};\n\tfor (const [key, value] of definitions) {\n\t\tresult[key] = convertNodeSchema(value, options);\n\t}\n\treturn result;\n}\n\n/**\n * Converts an input {@link SimpleNodeSchema} to a {@link JsonNodeSchema}.\n *\n * @remarks Caches the result on the input schema for future calls.\n */\nfunction convertNodeSchema(\n\tschema: TreeNodeSchema,\n\toptions: Required<TreeSchemaEncodingOptions>,\n): JsonNodeSchema {\n\tif (schema instanceof ArrayNodeSchema) {\n\t\treturn convertArrayNodeSchema(schema);\n\t} else if (isMapNodeSchema(schema) || isRecordNodeSchema(schema)) {\n\t\treturn convertRecordLikeNodeSchema(schema);\n\t} else if (schema instanceof ObjectNodeSchema) {\n\t\treturn convertObjectNodeSchema(schema, options);\n\t} else if (schema instanceof LeafNodeSchema) {\n\t\treturn convertLeafNodeSchema(schema);\n\t}\n\tthrow new TypeError(`Unknown node schema kind: ${schema.kind}`);\n}\n\nfunction convertArrayNodeSchema(schema: SimpleArrayNodeSchema): JsonArrayNodeSchema {\n\tconst allowedTypes: JsonSchemaRef[] = [];\n\tconst allowedTypesIdentifiers: ReadonlySet<string> = new Set(\n\t\tschema.simpleAllowedTypes.keys(),\n\t);\n\tallowedTypesIdentifiers.forEach((type) => {\n\t\tallowedTypes.push(createSchemaRef(type));\n\t});\n\n\tconst items: JsonFieldSchema = hasSingle(allowedTypes)\n\t\t? allowedTypes[0]\n\t\t: { anyOf: allowedTypes };\n\n\tconst output: Mutable<JsonArrayNodeSchema> = {\n\t\ttype: \"array\",\n\t\t_treeNodeSchemaKind: NodeKind.Array,\n\t\titems,\n\t};\n\n\tcopyProperty(schema.metadata, \"description\", output);\n\n\treturn output;\n}\n\nfunction convertLeafNodeSchema(schema: SimpleLeafNodeSchema): JsonLeafNodeSchema {\n\tlet type: JsonLeafSchemaType;\n\tswitch (schema.leafKind) {\n\t\tcase ValueSchema.String:\n\t\t\ttype = \"string\";\n\t\t\tbreak;\n\t\tcase ValueSchema.Number:\n\t\t\ttype = \"number\";\n\t\t\tbreak;\n\t\tcase ValueSchema.Boolean:\n\t\t\ttype = \"boolean\";\n\t\t\tbreak;\n\t\tcase ValueSchema.Null:\n\t\t\ttype = \"null\";\n\t\t\tbreak;\n\t\tcase ValueSchema.FluidHandle:\n\t\t\tthrow new UsageError(\"Fluid handles are not supported via JSON Schema.\");\n\t\tdefault:\n\t\t\tunreachableCase(schema.leafKind);\n\t}\n\n\treturn {\n\t\ttype,\n\t\t_treeNodeSchemaKind: NodeKind.Leaf,\n\t};\n}\n\nexport function convertObjectNodeSchema(\n\tschema: ObjectNodeSchema,\n\toptions: Required<TreeSchemaEncodingOptions>,\n): JsonObjectNodeSchema {\n\tconst properties: Record<string, JsonFieldSchema> = {};\n\tconst required: string[] = [];\n\tfor (const [propertyKey, fieldSchema] of schema.fields) {\n\t\tconst key =\n\t\t\toptions.keys === KeyEncodingOptions.usePropertyKeys\n\t\t\t\t? propertyKey\n\t\t\t\t: fieldSchema.storedKey;\n\t\tconst allowedTypes: JsonSchemaRef[] = [];\n\t\tfor (const allowedType of fieldSchema.allowedTypesIdentifiers) {\n\t\t\tallowedTypes.push(createSchemaRef(allowedType));\n\t\t}\n\n\t\tconst output: Mutable<JsonFieldSchema> = hasSingle(allowedTypes)\n\t\t\t? allowedTypes[0]\n\t\t\t: {\n\t\t\t\t\tanyOf: allowedTypes,\n\t\t\t\t};\n\n\t\tcopyProperty(fieldSchema.metadata, \"description\", output);\n\t\tproperties[key] = output;\n\n\t\tif (fieldSchema.kind !== FieldKind.Optional) {\n\t\t\tif (\n\t\t\t\toptions.requireFieldsWithDefaults ||\n\t\t\t\tfieldSchema.props?.defaultProvider === undefined\n\t\t\t) {\n\t\t\t\trequired.push(key);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst transformedNode: Mutable<JsonObjectNodeSchema> = {\n\t\ttype: \"object\",\n\t\t_treeNodeSchemaKind: NodeKind.Object,\n\t\tproperties,\n\t\trequired,\n\t\t// TODO: support unknown optional fields (only when using \"allStoredKeys\", and constrain the content to be in schema somehow)\n\t\tadditionalProperties: false,\n\t};\n\n\tcopyProperty(schema.metadata, \"description\", transformedNode);\n\n\treturn transformedNode;\n}\n\nfunction convertRecordLikeNodeSchema(\n\tschema: SimpleRecordNodeSchema | SimpleMapNodeSchema,\n): JsonMapNodeSchema | JsonRecordNodeSchema {\n\tconst allowedTypes: JsonSchemaRef[] = [];\n\tconst allowedTypesIdentifiers: ReadonlySet<string> = new Set(\n\t\tschema.simpleAllowedTypes.keys(),\n\t);\n\tallowedTypesIdentifiers.forEach((type) => {\n\t\tallowedTypes.push(createSchemaRef(type));\n\t});\n\n\tconst output = {\n\t\ttype: \"object\",\n\t\t_treeNodeSchemaKind: schema.kind,\n\t\tpatternProperties: {\n\t\t\t\"^.*$\": hasSingle(allowedTypes)\n\t\t\t\t? allowedTypes[0]\n\t\t\t\t: {\n\t\t\t\t\t\tanyOf: allowedTypes,\n\t\t\t\t\t},\n\t\t},\n\t} as const;\n\n\tcopyProperty(schema.metadata, \"description\", output);\n\n\treturn output;\n}\n\nfunction createSchemaRef(schemaId: string): JsonSchemaRef {\n\treturn {\n\t\t\"$ref\": createRefPath(schemaId),\n\t};\n}\n\nfunction createRefPath(schemaId: string): JsonRefPath {\n\treturn `#/$defs/${schemaId}`;\n}\n"]}
|
|
@@ -9,6 +9,7 @@ import type { SimpleTreeSchema } from "../simpleSchema.js";
|
|
|
9
9
|
*
|
|
10
10
|
* @param schema - The schema to convert
|
|
11
11
|
* @param copySchemaObjects - If true, TreeNodeSchema and FieldSchema are copied into plain JavaScript objects. Either way, custom metadata is referenced and not copied.
|
|
12
|
+
* @param isViewSchema - If true (default), properties used by view schema but not part of stored schema (for example, `isStaged` on allowed types) are preserved in the output.
|
|
12
13
|
*
|
|
13
14
|
* @remarks
|
|
14
15
|
* Given that the Schema types used in {@link ImplicitFieldSchema} already implement the {@link SimpleNodeSchema} interfaces, there are limited use-cases for this function.
|
|
@@ -20,5 +21,5 @@ import type { SimpleTreeSchema } from "../simpleSchema.js";
|
|
|
20
21
|
* TODO: once SimpleTreeSchema is stable, {@link TreeViewConfiguration} could implement {@link SimpleTreeSchema} directly.
|
|
21
22
|
* That would provide the non-copying alternative that could expose the value type of the definitions map as {@link TreeNodeSchema}.
|
|
22
23
|
*/
|
|
23
|
-
export declare function toSimpleTreeSchema(schema: ImplicitFieldSchema, copySchemaObjects: boolean): SimpleTreeSchema;
|
|
24
|
+
export declare function toSimpleTreeSchema(schema: ImplicitFieldSchema, copySchemaObjects: boolean, isViewSchema?: boolean): SimpleTreeSchema;
|
|
24
25
|
//# sourceMappingURL=viewSchemaToSimpleSchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewSchemaToSimpleSchema.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/viewSchemaToSimpleSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAwB,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"viewSchemaToSimpleSchema.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/viewSchemaToSimpleSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAwB,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,KAAK,EAUX,gBAAgB,EAChB,MAAM,oBAAoB,CAAC;AAW5B;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CACjC,MAAM,EAAE,mBAAmB,EAC3B,iBAAiB,EAAE,OAAO,EAC1B,YAAY,GAAE,OAAc,GAC1B,gBAAgB,CAmClB"}
|
|
@@ -16,6 +16,7 @@ const leafNodeSchema_js_1 = require("../leafNodeSchema.js");
|
|
|
16
16
|
*
|
|
17
17
|
* @param schema - The schema to convert
|
|
18
18
|
* @param copySchemaObjects - If true, TreeNodeSchema and FieldSchema are copied into plain JavaScript objects. Either way, custom metadata is referenced and not copied.
|
|
19
|
+
* @param isViewSchema - If true (default), properties used by view schema but not part of stored schema (for example, `isStaged` on allowed types) are preserved in the output.
|
|
19
20
|
*
|
|
20
21
|
* @remarks
|
|
21
22
|
* Given that the Schema types used in {@link ImplicitFieldSchema} already implement the {@link SimpleNodeSchema} interfaces, there are limited use-cases for this function.
|
|
@@ -27,7 +28,7 @@ const leafNodeSchema_js_1 = require("../leafNodeSchema.js");
|
|
|
27
28
|
* TODO: once SimpleTreeSchema is stable, {@link TreeViewConfiguration} could implement {@link SimpleTreeSchema} directly.
|
|
28
29
|
* That would provide the non-copying alternative that could expose the value type of the definitions map as {@link TreeNodeSchema}.
|
|
29
30
|
*/
|
|
30
|
-
function toSimpleTreeSchema(schema, copySchemaObjects) {
|
|
31
|
+
function toSimpleTreeSchema(schema, copySchemaObjects, isViewSchema = true) {
|
|
31
32
|
const normalizedSchema = (0, fieldSchema_js_1.normalizeFieldSchema)(schema);
|
|
32
33
|
const definitions = new Map();
|
|
33
34
|
(0, walkFieldSchema_js_1.walkFieldSchema)(normalizedSchema, {
|
|
@@ -38,14 +39,16 @@ function toSimpleTreeSchema(schema, copySchemaObjects) {
|
|
|
38
39
|
nodeSchema instanceof leafNodeSchema_js_1.LeafNodeSchema ||
|
|
39
40
|
nodeSchema instanceof index_js_2.ObjectNodeSchema ||
|
|
40
41
|
nodeSchema instanceof index_js_2.RecordNodeSchema, 0xb60 /* Invalid schema */);
|
|
41
|
-
const outSchema = copySchemaObjects
|
|
42
|
+
const outSchema = copySchemaObjects
|
|
43
|
+
? copySimpleNodeSchema(nodeSchema, isViewSchema)
|
|
44
|
+
: nodeSchema;
|
|
42
45
|
definitions.set(nodeSchema.identifier, outSchema);
|
|
43
46
|
},
|
|
44
47
|
});
|
|
45
48
|
return {
|
|
46
49
|
root: copySchemaObjects
|
|
47
50
|
? ({
|
|
48
|
-
|
|
51
|
+
simpleAllowedTypes: normalizeSimpleAllowedTypes(normalizedSchema.simpleAllowedTypes, isViewSchema),
|
|
49
52
|
kind: normalizedSchema.kind,
|
|
50
53
|
metadata: normalizedSchema.metadata,
|
|
51
54
|
persistedMetadata: normalizedSchema.persistedMetadata,
|
|
@@ -55,12 +58,30 @@ function toSimpleTreeSchema(schema, copySchemaObjects) {
|
|
|
55
58
|
};
|
|
56
59
|
}
|
|
57
60
|
exports.toSimpleTreeSchema = toSimpleTreeSchema;
|
|
61
|
+
/**
|
|
62
|
+
* Normalizes the {@link SimpleAllowedTypeAttributes} by either preserving or omitting view-specific schema properties.
|
|
63
|
+
* @param simpleAllowedTypes - The simple allowed types to normalize.
|
|
64
|
+
* @param isViewSchema - If true, properties used by view schema but not part of stored schema (for example, `isStaged` on allowed types) are preserved in the output.
|
|
65
|
+
* @returns The normalized simple allowed types.
|
|
66
|
+
*/
|
|
67
|
+
function normalizeSimpleAllowedTypes(simpleAllowedTypes, isViewSchema) {
|
|
68
|
+
if (isViewSchema) {
|
|
69
|
+
return simpleAllowedTypes;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const normalized = new Map();
|
|
73
|
+
for (const [identifier, attributes] of simpleAllowedTypes.entries()) {
|
|
74
|
+
normalized.set(identifier, { ...attributes, isStaged: undefined });
|
|
75
|
+
}
|
|
76
|
+
return normalized;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
58
79
|
/**
|
|
59
80
|
* Copies a {@link SimpleNodeSchema} into a new plain JavaScript object.
|
|
60
81
|
*
|
|
61
82
|
* @remarks Caches the result on the input schema for future calls.
|
|
62
83
|
*/
|
|
63
|
-
function copySimpleNodeSchema(schema) {
|
|
84
|
+
function copySimpleNodeSchema(schema, isViewSchema) {
|
|
64
85
|
const kind = schema.kind;
|
|
65
86
|
switch (kind) {
|
|
66
87
|
case index_js_1.NodeKind.Leaf:
|
|
@@ -68,9 +89,9 @@ function copySimpleNodeSchema(schema) {
|
|
|
68
89
|
case index_js_1.NodeKind.Array:
|
|
69
90
|
case index_js_1.NodeKind.Map:
|
|
70
91
|
case index_js_1.NodeKind.Record:
|
|
71
|
-
return copySimpleSchemaWithAllowedTypes(schema);
|
|
92
|
+
return copySimpleSchemaWithAllowedTypes(schema, isViewSchema);
|
|
72
93
|
case index_js_1.NodeKind.Object:
|
|
73
|
-
return copySimpleObjectSchema(schema);
|
|
94
|
+
return copySimpleObjectSchema(schema, isViewSchema);
|
|
74
95
|
default:
|
|
75
96
|
(0, internal_1.unreachableCase)(kind);
|
|
76
97
|
}
|
|
@@ -83,21 +104,21 @@ function copySimpleLeafSchema(schema) {
|
|
|
83
104
|
persistedMetadata: schema.persistedMetadata,
|
|
84
105
|
};
|
|
85
106
|
}
|
|
86
|
-
function copySimpleSchemaWithAllowedTypes(schema) {
|
|
107
|
+
function copySimpleSchemaWithAllowedTypes(schema, isViewSchema) {
|
|
87
108
|
return {
|
|
88
109
|
kind: schema.kind,
|
|
89
|
-
|
|
110
|
+
simpleAllowedTypes: normalizeSimpleAllowedTypes(schema.simpleAllowedTypes, isViewSchema),
|
|
90
111
|
metadata: schema.metadata,
|
|
91
112
|
persistedMetadata: schema.persistedMetadata,
|
|
92
113
|
};
|
|
93
114
|
}
|
|
94
|
-
function copySimpleObjectSchema(schema) {
|
|
115
|
+
function copySimpleObjectSchema(schema, isViewSchema) {
|
|
95
116
|
const fields = new Map();
|
|
96
117
|
for (const [propertyKey, field] of schema.fields) {
|
|
97
118
|
// field already is a SimpleObjectFieldSchema, but copy the subset of the properties needed by this interface to get a clean simple object.
|
|
98
119
|
fields.set(propertyKey, {
|
|
99
120
|
kind: field.kind,
|
|
100
|
-
|
|
121
|
+
simpleAllowedTypes: normalizeSimpleAllowedTypes(field.simpleAllowedTypes, isViewSchema),
|
|
101
122
|
metadata: field.metadata,
|
|
102
123
|
persistedMetadata: field.persistedMetadata,
|
|
103
124
|
storedKey: field.storedKey,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewSchemaToSimpleSchema.js","sourceRoot":"","sources":["../../../src/simple-tree/api/viewSchemaToSimpleSchema.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA8E;AAC9E,sDAAmF;
|
|
1
|
+
{"version":3,"file":"viewSchemaToSimpleSchema.js","sourceRoot":"","sources":["../../../src/simple-tree/api/viewSchemaToSimpleSchema.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA8E;AAC9E,sDAAmF;AAanF,+CAA4C;AAC5C,qDAKgC;AAChC,8DAAwD;AACxD,4DAAsD;AAEtD;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,kBAAkB,CACjC,MAA2B,EAC3B,iBAA0B,EAC1B,eAAwB,IAAI;IAE5B,MAAM,gBAAgB,GAAG,IAAA,qCAAoB,EAAC,MAAM,CAAC,CAAC;IACtD,MAAM,WAAW,GAAG,IAAI,GAAG,EAA4B,CAAC;IACxD,IAAA,oCAAe,EAAC,gBAAgB,EAAE;QACjC,IAAI,EAAE,CAAC,UAAU,EAAE,EAAE;YACpB,iJAAiJ;YACjJ,IAAA,iBAAM,EACL,UAAU,YAAY,0BAAe;gBACpC,UAAU,YAAY,wBAAa;gBACnC,UAAU,YAAY,kCAAc;gBACpC,UAAU,YAAY,2BAAgB;gBACtC,UAAU,YAAY,2BAAgB,EACvC,KAAK,CAAC,oBAAoB,CAC1B,CAAC;YACF,MAAM,SAAS,GAAG,iBAAiB;gBAClC,CAAC,CAAC,oBAAoB,CAAC,UAAU,EAAE,YAAY,CAAC;gBAChD,CAAC,CAAC,UAAU,CAAC;YACd,WAAW,CAAC,GAA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QACrB,MAAM;QACN,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;KAC3C,CAAC;AACH,CAAC","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 { normalizeFieldSchema, type ImplicitFieldSchema } from \"../fieldSchema.js\";\nimport type {\n\tSimpleAllowedTypeAttributes,\n\tSimpleArrayNodeSchema,\n\tSimpleFieldSchema,\n\tSimpleLeafNodeSchema,\n\tSimpleMapNodeSchema,\n\tSimpleNodeSchema,\n\tSimpleObjectFieldSchema,\n\tSimpleObjectNodeSchema,\n\tSimpleRecordNodeSchema,\n\tSimpleTreeSchema,\n} from \"../simpleSchema.js\";\nimport { NodeKind } from \"../core/index.js\";\nimport {\n\tArrayNodeSchema,\n\tMapNodeSchema,\n\tObjectNodeSchema,\n\tRecordNodeSchema,\n} from \"../node-kinds/index.js\";\nimport { walkFieldSchema } from \"../walkFieldSchema.js\";\nimport { LeafNodeSchema } from \"../leafNodeSchema.js\";\n\n/**\n * Converts an {@link ImplicitFieldSchema} to a \"simple\" schema representation.\n *\n * @param schema - The schema to convert\n * @param copySchemaObjects - If true, TreeNodeSchema and FieldSchema are copied into plain JavaScript objects. Either way, custom metadata is referenced and not copied.\n * @param isViewSchema - If true (default), properties used by view schema but not part of stored schema (for example, `isStaged` on allowed types) are preserved in the output.\n *\n * @remarks\n * Given that the Schema types used in {@link ImplicitFieldSchema} already implement the {@link SimpleNodeSchema} interfaces, there are limited use-cases for this function.\n * One possible use-case is converting schema to a more serialization friendly format.\n * This format however is not JSON compatible due to use of Maps and Sets,\n * but it it does not rely on cyclic object references for handling recursive schema and instead uses the `definitions` map.\n *\n * @privateRemarks\n * TODO: once SimpleTreeSchema is stable, {@link TreeViewConfiguration} could implement {@link SimpleTreeSchema} directly.\n * That would provide the non-copying alternative that could expose the value type of the definitions map as {@link TreeNodeSchema}.\n */\nexport function toSimpleTreeSchema(\n\tschema: ImplicitFieldSchema,\n\tcopySchemaObjects: boolean,\n\tisViewSchema: boolean = true,\n): SimpleTreeSchema {\n\tconst normalizedSchema = normalizeFieldSchema(schema);\n\tconst definitions = new Map<string, SimpleNodeSchema>();\n\twalkFieldSchema(normalizedSchema, {\n\t\tnode: (nodeSchema) => {\n\t\t\t// The set of node kinds is extensible, but the typing of SimpleNodeSchema is not, so we need to check that the schema is one of the known kinds.\n\t\t\tassert(\n\t\t\t\tnodeSchema instanceof ArrayNodeSchema ||\n\t\t\t\t\tnodeSchema instanceof MapNodeSchema ||\n\t\t\t\t\tnodeSchema instanceof LeafNodeSchema ||\n\t\t\t\t\tnodeSchema instanceof ObjectNodeSchema ||\n\t\t\t\t\tnodeSchema instanceof RecordNodeSchema,\n\t\t\t\t0xb60 /* Invalid schema */,\n\t\t\t);\n\t\t\tconst outSchema = copySchemaObjects\n\t\t\t\t? copySimpleNodeSchema(nodeSchema, isViewSchema)\n\t\t\t\t: nodeSchema;\n\t\t\tdefinitions.set(nodeSchema.identifier, outSchema);\n\t\t},\n\t});\n\n\treturn {\n\t\troot: copySchemaObjects\n\t\t\t? ({\n\t\t\t\t\tsimpleAllowedTypes: normalizeSimpleAllowedTypes(\n\t\t\t\t\t\tnormalizedSchema.simpleAllowedTypes,\n\t\t\t\t\t\tisViewSchema,\n\t\t\t\t\t),\n\t\t\t\t\tkind: normalizedSchema.kind,\n\t\t\t\t\tmetadata: normalizedSchema.metadata,\n\t\t\t\t\tpersistedMetadata: normalizedSchema.persistedMetadata,\n\t\t\t\t} satisfies SimpleFieldSchema)\n\t\t\t: normalizedSchema,\n\t\tdefinitions,\n\t};\n}\n\n/**\n * Normalizes the {@link SimpleAllowedTypeAttributes} by either preserving or omitting view-specific schema properties.\n * @param simpleAllowedTypes - The simple allowed types to normalize.\n * @param isViewSchema - If true, properties used by view schema but not part of stored schema (for example, `isStaged` on allowed types) are preserved in the output.\n * @returns The normalized simple allowed types.\n */\nfunction normalizeSimpleAllowedTypes(\n\tsimpleAllowedTypes: ReadonlyMap<string, SimpleAllowedTypeAttributes>,\n\tisViewSchema: boolean,\n): ReadonlyMap<string, SimpleAllowedTypeAttributes> {\n\tif (isViewSchema) {\n\t\treturn simpleAllowedTypes;\n\t} else {\n\t\tconst normalized = new Map<string, SimpleAllowedTypeAttributes>();\n\t\tfor (const [identifier, attributes] of simpleAllowedTypes.entries()) {\n\t\t\tnormalized.set(identifier, { ...attributes, isStaged: undefined });\n\t\t}\n\t\treturn normalized;\n\t}\n}\n\n/**\n * Copies a {@link SimpleNodeSchema} into a new plain JavaScript object.\n *\n * @remarks Caches the result on the input schema for future calls.\n */\nfunction copySimpleNodeSchema(\n\tschema: SimpleNodeSchema,\n\tisViewSchema: boolean,\n): SimpleNodeSchema {\n\tconst kind = schema.kind;\n\tswitch (kind) {\n\t\tcase NodeKind.Leaf:\n\t\t\treturn copySimpleLeafSchema(schema);\n\t\tcase NodeKind.Array:\n\t\tcase NodeKind.Map:\n\t\tcase NodeKind.Record:\n\t\t\treturn copySimpleSchemaWithAllowedTypes(schema, isViewSchema);\n\t\tcase NodeKind.Object:\n\t\t\treturn copySimpleObjectSchema(schema, isViewSchema);\n\t\tdefault:\n\t\t\tunreachableCase(kind);\n\t}\n}\n\nfunction copySimpleLeafSchema(schema: SimpleLeafNodeSchema): SimpleLeafNodeSchema {\n\treturn {\n\t\tkind: NodeKind.Leaf,\n\t\tleafKind: schema.leafKind,\n\t\tmetadata: schema.metadata,\n\t\tpersistedMetadata: schema.persistedMetadata,\n\t};\n}\n\nfunction copySimpleSchemaWithAllowedTypes(\n\tschema: SimpleMapNodeSchema | SimpleArrayNodeSchema | SimpleRecordNodeSchema,\n\tisViewSchema: boolean,\n): SimpleMapNodeSchema | SimpleArrayNodeSchema | SimpleRecordNodeSchema {\n\treturn {\n\t\tkind: schema.kind,\n\t\tsimpleAllowedTypes: normalizeSimpleAllowedTypes(schema.simpleAllowedTypes, isViewSchema),\n\t\tmetadata: schema.metadata,\n\t\tpersistedMetadata: schema.persistedMetadata,\n\t};\n}\n\nfunction copySimpleObjectSchema(\n\tschema: SimpleObjectNodeSchema,\n\tisViewSchema: boolean,\n): SimpleObjectNodeSchema {\n\tconst fields: Map<string, SimpleObjectFieldSchema> = new Map();\n\tfor (const [propertyKey, field] of schema.fields) {\n\t\t// field already is a SimpleObjectFieldSchema, but copy the subset of the properties needed by this interface to get a clean simple object.\n\t\tfields.set(propertyKey, {\n\t\t\tkind: field.kind,\n\t\t\tsimpleAllowedTypes: normalizeSimpleAllowedTypes(field.simpleAllowedTypes, isViewSchema),\n\t\t\tmetadata: field.metadata,\n\t\t\tpersistedMetadata: field.persistedMetadata,\n\t\t\tstoredKey: field.storedKey,\n\t\t});\n\t}\n\n\treturn {\n\t\tkind: NodeKind.Object,\n\t\tfields,\n\t\tmetadata: schema.metadata,\n\t\tpersistedMetadata: schema.persistedMetadata,\n\t};\n}\n"]}
|
|
@@ -6,6 +6,7 @@ import { type ErasedBaseType, ErasedTypeImplementation } from "@fluidframework/c
|
|
|
6
6
|
import { type IsUnion, type MakeNominal } from "../../util/index.js";
|
|
7
7
|
import { type FlexListToUnion, type LazyItem } from "./flexList.js";
|
|
8
8
|
import { type InsertableTypedNode, type NodeFromSchema, type TreeNodeSchema } from "./treeNodeSchema.js";
|
|
9
|
+
import type { SimpleAllowedTypeAttributes } from "../simpleSchema.js";
|
|
9
10
|
/**
|
|
10
11
|
* Schema for types allowed in some location in a tree (like a field, map entry or array).
|
|
11
12
|
* @remarks
|
|
@@ -141,6 +142,10 @@ export declare class AnnotatedAllowedTypesInternal<T extends readonly AnnotatedA
|
|
|
141
142
|
evaluate(): AllowedTypesFullInternalEvaluated;
|
|
142
143
|
evaluateSet(): ReadonlySet<TreeNodeSchema>;
|
|
143
144
|
evaluateIdentifiers(): ReadonlySet<string>;
|
|
145
|
+
/**
|
|
146
|
+
* Get the {@link SimpleAllowedTypeAttributes} version of the allowed types set.
|
|
147
|
+
*/
|
|
148
|
+
static evaluateSimpleAllowedTypes(annotatedAllowedTypes: AnnotatedAllowedTypes): ReadonlyMap<string, SimpleAllowedTypeAttributes>;
|
|
144
149
|
static [Symbol.hasInstance]<TThis extends {
|
|
145
150
|
prototype: object;
|
|
146
151
|
}>(this: TThis, value: unknown): value is InstanceTypeRelaxed<TThis> & AnnotatedAllowedTypesInternal & AllowedTypesFull;
|
|
@@ -148,8 +153,8 @@ export declare class AnnotatedAllowedTypesInternal<T extends readonly AnnotatedA
|
|
|
148
153
|
prototype: object;
|
|
149
154
|
}>(this: TThis, value: ErasedBaseType | InstanceTypeRelaxed<TThis> | ImplicitAllowedTypes): asserts value is InstanceTypeRelaxed<TThis> & AnnotatedAllowedTypesInternal & AllowedTypesFull;
|
|
150
155
|
private static proxy;
|
|
151
|
-
static create<const T extends readonly AnnotatedAllowedType[]>(types: T, metadata?: AllowedTypesMetadata): AnnotatedAllowedTypesInternal<T
|
|
152
|
-
static createUnannotated<const T extends AllowedTypes>(types: T, metadata?: AllowedTypesMetadata): AnnotatedAllowedTypesInternal & T
|
|
156
|
+
static create<const T extends readonly AnnotatedAllowedType[]>(types: T, metadata?: AllowedTypesMetadata): AnnotatedAllowedTypesInternal<Readonly<T>> & AllowedTypesFull<Readonly<T>>;
|
|
157
|
+
static createUnannotated<const T extends AllowedTypes>(types: T, metadata?: AllowedTypesMetadata): AnnotatedAllowedTypesInternal & Readonly<T>;
|
|
153
158
|
static createMixed<const T extends readonly (AnnotatedAllowedType | LazyItem<TreeNodeSchema>)[]>(types: T, metadata?: AllowedTypesMetadata): AllowedTypesFullFromMixed<T>;
|
|
154
159
|
}
|
|
155
160
|
/**
|
|
@@ -314,8 +319,8 @@ export type TreeNodeFromImplicitAllowedTypes<TSchema extends ImplicitAllowedType
|
|
|
314
319
|
* This type exists only to be linked from documentation to provide a single linkable place to document some details of
|
|
315
320
|
* "Input" types and how they handle schema.
|
|
316
321
|
*
|
|
317
|
-
* When a schema is used to describe data which is an input into an API, the API is
|
|
318
|
-
* (See also
|
|
322
|
+
* When a schema is used to describe data which is an input into an API, the API is {@link https://en.wikipedia.org/wiki/Type_variance | contravariant}) over the schema.
|
|
323
|
+
* (See also {@link https://www.typescriptlang.org/docs/handbook/2/generics.html#variance-annotations | TypeScript Variance Annotations}).
|
|
319
324
|
*
|
|
320
325
|
* Since these schema are expressed using TypeScript types, it is possible for the user of the API to provide non-exact values of these types which has implications that depended on the variance.
|
|
321
326
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"allowedTypes.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/core/allowedTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EACN,KAAK,cAAc,EACnB,wBAAwB,EACxB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAGN,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAU,KAAK,eAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAEN,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"allowedTypes.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/core/allowedTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EACN,KAAK,cAAc,EACnB,wBAAwB,EACxB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAGN,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAU,KAAK,eAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAEN,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBA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;;;;GAUG;AACH,MAAM,MAAM,kCAAkC,CAAC,KAAK,SAAS,YAAY,IACxE,OAAO,CAAC,KAAK,CAAC,SAAS,IAAI,GACxB,KAAK,GACL;IACA,QAAQ,EAAE,QAAQ,IAAI,MAAM,KAAK,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,SAAS;QAC7D,QAAQ,CAAC,MAAM,OAAO,SAAS,cAAc,CAAC;KAC9C,GACE,mBAAmB,CAAC,OAAO,CAAC,GAC5B,KAAK;CACR,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;AAExB;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,CACrB,CAAC,EACD,WAAW,GAAG;IACb,QAAQ,EAAE,QAAQ,IAAI,MAAM,CAAC,IAAI,MAAM,SAAS,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ;CACtF,IACE,WAAW,CAAC,GAAG,MAAM,EAAE,GAAG,MAAM,WAAW,CAAC,CAAC"}
|
|
@@ -70,6 +70,18 @@ class AnnotatedAllowedTypesInternal extends internal_3.ErasedTypeImplementation
|
|
|
70
70
|
evaluateIdentifiers() {
|
|
71
71
|
return this.lazyEvaluate.value.identifiers;
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Get the {@link SimpleAllowedTypeAttributes} version of the allowed types set.
|
|
75
|
+
*/
|
|
76
|
+
static evaluateSimpleAllowedTypes(annotatedAllowedTypes) {
|
|
77
|
+
const simpleAllowedTypes = new Map();
|
|
78
|
+
for (const type of annotatedAllowedTypes.evaluate().types) {
|
|
79
|
+
simpleAllowedTypes.set(type.type.identifier, {
|
|
80
|
+
isStaged: type.metadata.stagedSchemaUpgrade !== undefined,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return simpleAllowedTypes;
|
|
84
|
+
}
|
|
73
85
|
static [Symbol.hasInstance](value) {
|
|
74
86
|
return internal_3.ErasedTypeImplementation[Symbol.hasInstance].call(this, value);
|
|
75
87
|
}
|
|
@@ -135,11 +147,13 @@ class AnnotatedAllowedTypesInternal extends internal_3.ErasedTypeImplementation
|
|
|
135
147
|
return result;
|
|
136
148
|
}
|
|
137
149
|
static createUnannotated(types, metadata = {}) {
|
|
150
|
+
Object.freeze(types);
|
|
138
151
|
const annotatedTypes = types.map(normalizeToAnnotatedAllowedType);
|
|
139
152
|
const result = AnnotatedAllowedTypesInternal.create(annotatedTypes, metadata);
|
|
140
153
|
return result;
|
|
141
154
|
}
|
|
142
155
|
static createMixed(types, metadata = {}) {
|
|
156
|
+
Object.freeze(types);
|
|
143
157
|
const annotatedTypes = types.map(normalizeToAnnotatedAllowedType);
|
|
144
158
|
const result = AnnotatedAllowedTypesInternal.create(annotatedTypes, metadata);
|
|
145
159
|
return result;
|
|
@@ -210,10 +224,9 @@ function normalizeAllowedTypesInternal(type) {
|
|
|
210
224
|
// Adding this cache improved the performance of the "large recursive union" test (which mostly just constructs a TreeConfiguration) by ~5 times.
|
|
211
225
|
// This cache is strictly a performance optimization: it is not required for correctness.
|
|
212
226
|
return (0, index_js_1.getOrCreate)(cachedNormalize, type, () => {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
const annotatedTypes = ((0, index_js_1.isReadonlyArray)(type) ? type : [type]).map(normalizeToAnnotatedAllowedType);
|
|
227
|
+
const inputArray = (0, index_js_1.isReadonlyArray)(type) ? type : [type];
|
|
228
|
+
Object.freeze(inputArray);
|
|
229
|
+
const annotatedTypes = inputArray.map(normalizeToAnnotatedAllowedType);
|
|
217
230
|
return AnnotatedAllowedTypesInternal.create(annotatedTypes);
|
|
218
231
|
});
|
|
219
232
|
}
|