Skip to main content

SchemaFactoryBeta Class

SchemaFactory with additional beta APIs.

This API is provided as a beta preview and may change without notice.

To use, import via fluid-framework/beta.

For more information about our API support guarantees, see here.

Signature

export declare class SchemaFactoryBeta<out TScope extends string | undefined = string | undefined, TName extends number | string = string> extends SchemaFactory<TScope, TName>

Extends: SchemaFactory<TScope, TName>

Type Parameters

Parameter Constraint Default Description
TScope string | undefined string | undefined
TName number | string string

Methods

Method Alerts Return Type Description
object(name, fields, options) Beta TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Object, TreeObjectNode<T, ScopedSchemaName<TScope, Name>>, object & InsertableObjectFromSchemaRecord<T>, true, T> Define a TreeNodeSchemaClass for a TreeObjectNode.
objectRecursive(name, t, options) Beta TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Object, System_Unsafe.TreeObjectNodeUnsafe<T, ScopedSchemaName<TScope, Name>>, object & System_Unsafe.InsertableObjectFromSchemaRecordUnsafe<T>, false, T>
record(allowedTypes) Beta TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Record<${string}>`>, NodeKind.Record, TreeRecordNode<T> & WithType<ScopedSchemaName<TScope, `Record<${string}>`>, NodeKind.Record>, RecordNodeInsertableData<T>, true, T, undefined> Define a structurally typed TreeNodeSchema for a TreeRecordNode.
record(name, allowedTypes) Beta TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Record, TreeRecordNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Record>, RecordNodeInsertableData<T>, true, T, undefined> Define (and add to this library) a TreeNodeSchemaClass for a TreeRecordNode.
recordRecursive(name, allowedTypes, options) Beta TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Record, TreeRecordNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Record, unknown>, { readonly [x: string]: System_Unsafe.InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>; }, false, T, undefined, TCustomMetadata> record(name, allowedTypes) except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety.
scopedFactory(name) Beta SchemaFactoryBeta<ScopedSchemaName<TScope, T>, TNameInner> Create a SchemaFactory with a scope which is a combination of this factory's scope and the provided name.

Method Details

object

Define a TreeNodeSchemaClass for a TreeObjectNode.

This API is provided as a beta preview and may change without notice.

For more information about our API support guarantees, see here.

Signature
object<const Name extends TName, const T extends RestrictiveStringRecord<ImplicitFieldSchema>, const TCustomMetadata = unknown>(name: Name, fields: T, options?: ObjectSchemaOptions<TCustomMetadata>): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Object, TreeObjectNode<T, ScopedSchemaName<TScope, Name>>, object & InsertableObjectFromSchemaRecord<T>, true, T>;
Type Parameters
Parameter Constraint Default Description
Name TName
T RestrictiveStringRecord<ImplicitFieldSchema>
TCustomMetadata unknown

Parameters

Parameter Modifiers Type Description
name Name Unique identifier for this schema within this factory's scope.
fields T Schema for fields of the object node's schema. Defines what children can be placed under each key.
options optional ObjectSchemaOptions<TCustomMetadata> Additional options for the schema.

Returns

Return type: TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Object, TreeObjectNode<T, ScopedSchemaName<TScope, Name>>, object & InsertableObjectFromSchemaRecord<T>, true, T>

objectRecursive

This API is provided as a beta preview and may change without notice.

For more information about our API support guarantees, see here.

Signature
objectRecursive<const Name extends TName, const T extends RestrictiveStringRecord<System_Unsafe.ImplicitFieldSchemaUnsafe>, const TCustomMetadata = unknown>(name: Name, t: T, options?: ObjectSchemaOptions<TCustomMetadata>): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Object, System_Unsafe.TreeObjectNodeUnsafe<T, ScopedSchemaName<TScope, Name>>, object & System_Unsafe.InsertableObjectFromSchemaRecordUnsafe<T>, false, T>;
Type Parameters
Parameter Constraint Default Description
Name TName
T RestrictiveStringRecord<System_Unsafe.ImplicitFieldSchemaUnsafe>
TCustomMetadata unknown

Parameters

Parameter Modifiers Type Description
name Name
t T
options optional ObjectSchemaOptions<TCustomMetadata>

Returns

Return type: TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Object, System_Unsafe.TreeObjectNodeUnsafe<T, ScopedSchemaName<TScope, Name>>, object & System_Unsafe.InsertableObjectFromSchemaRecordUnsafe<T>, false, T>

record

Define a structurally typed TreeNodeSchema for a TreeRecordNode.

This API is provided as a beta preview and may change without notice.

For more information about our API support guarantees, see here.

Signature
record<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Record<${string}>`>, NodeKind.Record, TreeRecordNode<T> & WithType<ScopedSchemaName<TScope, `Record<${string}>`>, NodeKind.Record>, RecordNodeInsertableData<T>, true, T, undefined>;
Type Parameters
Parameter Constraint Description
T TreeNodeSchema | readonly TreeNodeSchema[]
Remarks

The identifier for this record is defined as a function of the provided types. It is still scoped to this SchemaFactory, but multiple calls with the same arguments will return the same schema object, providing somewhat structural typing. This does not support recursive types.

If using these structurally named records, other types in this schema builder should avoid names of the form Record<${string}>.

The underlying data format for Record nodes is the same as that for Map nodes. Therefore, changing an existing Map schema to a Record schema (or vice versa) is a non-breaking change and does not require schema migration.

Example

The returned schema should be used as a schema directly:

const MyRecord = factory.record(factory.number);
type MyRecord = NodeFromSchema<typeof Record>;

Or inline:

factory.object("Foo", { myRecord: factory.record(factory.number) });

Parameters

Parameter Type Description
allowedTypes T The types that may appear in the record.

Returns

Return type: TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Record<${string}>`>, NodeKind.Record, TreeRecordNode<T> & WithType<ScopedSchemaName<TScope, `Record<${string}>`>, NodeKind.Record>, RecordNodeInsertableData<T>, true, T, undefined>

record

Define (and add to this library) a TreeNodeSchemaClass for a TreeRecordNode.

This API is provided as a beta preview and may change without notice.

For more information about our API support guarantees, see here.

Signature
record<const Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Record, TreeRecordNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Record>, RecordNodeInsertableData<T>, true, T, undefined>;
Type Parameters
Parameter Constraint Description
Name TName
T ImplicitAllowedTypes
Remarks

The underlying data format for Record nodes is the same as that for Map nodes. Therefore, changing an existing Map schema to a Record schema (or vice versa) is a non-breaking change and does not require schema migration.

Like TypeScript Records, record nodes have some potential pitfalls. For example: TypeScript makes assumptions about built-in keys being present (e.g. toString, hasOwnProperty, etc.). Since these are otherwise valid keys in a record, this can lead to unexpected behavior. To prevent inconsistent behavior, these built-ins are hidden by record nodes. This means that if you try to call these built-ins (e.g. toString()) on a record node, you will get an error.

Example
class NamedRecord extends factory.record("name", factory.number) {}

Parameters

Parameter Type Description
name Name Unique identifier for this schema within this factory's scope.
allowedTypes T The types that may appear in the record.

Returns

Return type: TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Record, TreeRecordNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Record>, RecordNodeInsertableData<T>, true, T, undefined>

recordRecursive

record(name, allowedTypes) except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety.

This API is provided as a beta preview and may change without notice.

For more information about our API support guarantees, see here.

Signature
recordRecursive<Name extends TName, const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(name: Name, allowedTypes: T, options?: NodeSchemaOptions<TCustomMetadata>): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Record, TreeRecordNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Record, unknown>, {
readonly [x: string]: System_Unsafe.InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>;
}, false, T, undefined, TCustomMetadata>;
Type Parameters
Parameter Constraint Default Description
Name TName
T System_Unsafe.ImplicitAllowedTypesUnsafe
TCustomMetadata unknown
Remarks

This version of SchemaFactory.record uses the same workarounds as objectRecursive(name, t). See ValidateRecursiveSchema for additional information about using recursive schema.

Parameters

Parameter Modifiers Type Description
name Name
allowedTypes T
options optional NodeSchemaOptions<TCustomMetadata>

Returns

Return type: TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Record, TreeRecordNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Record, unknown>, { readonly [x: string]: System_Unsafe.InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>; }, false, T, undefined, TCustomMetadata>

scopedFactory

Create a SchemaFactory with a scope which is a combination of this factory's scope and the provided name.

This API is provided as a beta preview and may change without notice.

For more information about our API support guarantees, see here.

Signature
scopedFactory<const T extends TName, TNameInner extends number | string = string>(name: T): SchemaFactoryBeta<ScopedSchemaName<TScope, T>, TNameInner>;
Type Parameters
Parameter Constraint Default Description
T TName
TNameInner number | string string
Remarks

The main use-case for this is when creating a collection of related schema (for example using a function that creates multiple schema). Creating such related schema using a sub-scope helps ensure they won't collide with other schema in the parent scope.

Parameters

Parameter Type Description
name T

Returns

Return type: SchemaFactoryBeta<ScopedSchemaName<TScope, T>, TNameInner>