Documentation / @sw-file-lib/xml / xml-schema
xml-schema
Module for working with Stormworks XML data.
This module provides classes and functions for defining XML schemas, which help conversion between Stormworks XML and TypeScript objects.
For tutorial-style guide, see XML Schema Guide
Classes
| Class | Description |
|---|---|
| BooleanSchema | A schema that parses XML attribute values as booleans. |
| ListSchema | A schema that parses XML list elements as JavaScript arrays. |
| ObjectListSchema | A list schema whose item schema is an object schema. |
| MetalistSchema | A schema that parses XML list elements that have attributes as JavaScript arrays. |
| ObjectMetalistSchema | A metalist schema whose item schema is an object schema. |
| NumberSchema | A schema that parses XML attribute values as numbers. |
| ObjectSchema | A schema that parses XML record elements as JavaScript objects. |
| OptionalSchema | A schema wrapper that accepts undefined values. |
| RecordSchema | A schema that parses XML children with arbitrary unique tags as a string-keyed object. |
| ObjectRecordSchema | A record schema whose item schema is an object schema. |
| StringSchema | A schema that parses XML attribute values as strings. |
| UnionSchema | A schema that tries multiple schemas from left to right. |
| SchemaError | An error thrown when a Stormworks XML value does not match a schema. |
| SchemaSerializeError | An error thrown when a JavaScript value cannot be serialized by a schema. |
Interfaces
| Interface | Description |
|---|---|
| SchemaIssueBase | - |
| SchemaIssueMap | - |
| SchemaSerializeIssue | - |
| SchemaParseContext | Context information provided to schema parsing callbacks. |
| SchemaParseOptions | Options controlling the behavior of schema parsing when the XML does not exactly match the schema. |
| SchemaSerializeFailResult | A failed schema serialization result. |
| Schema | A schema that parses a Stormworks XML node into a typed value. |
| ElementSchema | A schema that can parse and serialize a complete XML element. |
| UnknownObject | A string-keyed object used for untyped XML data. |
Type Aliases
| Type Alias | Description |
|---|---|
| InferMetalist | Infers the value produced by a metalist schema. |
| Metalist | - |
| SchemaTuple | The schema list accepted by a union schema. |
| InferUnion | Infers the value produced by any branch of a union schema. |
| ExpectedSchemaInputType | Describe the expected type of the value given to schema parse function. Used for error data. |
| SchemaIssue | - |
| AnySchemaIssue | Any schema validation issue produced by the parser. |
| UnknownFieldMode | Determines how an unknown attribute or child element is handled. |
| UnknownFieldData | The data passed to the UnknownFieldCallback. |
| UnknownFieldCallback | Callback invoked when an attribute or child element is not defined by the current schema. |
| DuplicateChildElementMode | Determines how a duplicate child element is handled when the schema expects at most one element with a given tag. |
| DuplicateChildElementData | - |
| DuplicateChildElementCallback | Callback invoked when multiple child elements are found for a schema field that expects a unique child element. |
| Result | A non-throwing operation result. |
| SwXmlPath | A path identifying an element in an XML document. |
| SchemaPath | A path identifying a value in the parsed JavaScript object. |
| SchemaInput | A value accepted by schemas. |
| SchemaParseFieldResult | The result of parsing one field from an XML record node. |
| SchemaParseFieldAttributeResult | The result of parsing one attribute-backed field. |
| SchemaParseFieldChildResult | The result of parsing one child-element-backed field. |
| WriteElementCallback | Writes an XML element with the supplied tag name. |
| ElementSchemaSerializeResult | The result of serializing a schema that produces XML elements. |
| SchemaSerializeResult | The result of serializing one schema field. |
| UnknownValue | A JSON-like value used for untyped XML data. |
| AnySchema | - |
| Shape | The field schema map used by object-like schemas. |
| Infer | Infers the TypeScript value accepted by a schema. |
| Immutable | - |
| InferImmutable | Infers the TypeScript value accepted by a schema, and makes it deeply readonly. |
| OptionalKeys | Keys whose fields are optional schemas. |
| RequiredKeys | Keys whose fields are required schemas. |
| InferShape | Infers the object value produced by a schema shape. |
| PartialShape | Converts every field in a shape into an optional schema. |
| ExtendShape | The shape produced by extending one shape with another. |
| ExtendObjectSchema | The object schema type produced by extending an object schema. |
| OmitObjectSchema | The object schema type produced by omitting keys from an object schema. |
| ObjectShape | Extracts the shape from an object schema. |
Functions
| Function | Description |
|---|---|
| boolean | Creates a schema that parses XML attribute values as booleans. |
| list | Creates a schema that parses repeated child elements as a JavaScript array. |
| metalist | Creates a schema for list elements that also carry metadata fields. |
| number | Creates a schema that parses XML attribute values as numbers. |
| object | Creates a schema that parses XML record elements as JavaScript objects. |
| partialObject | Creates an object schema where every field is optional. |
| record | Creates a schema that parses child tag names as keys and their elements as values. |
| string | Creates a schema that parses XML attribute values as strings. |
| union | Creates a schema that accepts any value accepted by one of the given schemas. |
| prependSchemaIssuePath | Prepends path segments to every issue in a schema error. |
| prependSchemaSerializeIssuePath | Prepends path segments to every issue in a schema serialization error. |
| formatSchemaPath | Formats a schema path for error messages. |