Skip to content

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 ​

ClassDescription
BooleanSchemaA schema that parses XML attribute values as booleans.
ListSchemaA schema that parses XML list elements as JavaScript arrays.
ObjectListSchemaA list schema whose item schema is an object schema.
MetalistSchemaA schema that parses XML list elements that have attributes as JavaScript arrays.
ObjectMetalistSchemaA metalist schema whose item schema is an object schema.
NumberSchemaA schema that parses XML attribute values as numbers.
ObjectSchemaA schema that parses XML record elements as JavaScript objects.
OptionalSchemaA schema wrapper that accepts undefined values.
RecordSchemaA schema that parses XML children with arbitrary unique tags as a string-keyed object.
ObjectRecordSchemaA record schema whose item schema is an object schema.
StringSchemaA schema that parses XML attribute values as strings.
UnionSchemaA schema that tries multiple schemas from left to right.
SchemaErrorAn error thrown when a Stormworks XML value does not match a schema.
SchemaSerializeErrorAn error thrown when a JavaScript value cannot be serialized by a schema.

Interfaces ​

InterfaceDescription
SchemaIssueBase-
SchemaIssueMap-
SchemaSerializeIssue-
SchemaParseContextContext information provided to schema parsing callbacks.
SchemaParseOptionsOptions controlling the behavior of schema parsing when the XML does not exactly match the schema.
SchemaSerializeFailResultA failed schema serialization result.
SchemaA schema that parses a Stormworks XML node into a typed value.
ElementSchemaA schema that can parse and serialize a complete XML element.
UnknownObjectA string-keyed object used for untyped XML data.

Type Aliases ​

Type AliasDescription
InferMetalistInfers the value produced by a metalist schema.
Metalist-
SchemaTupleThe schema list accepted by a union schema.
InferUnionInfers the value produced by any branch of a union schema.
ExpectedSchemaInputTypeDescribe the expected type of the value given to schema parse function. Used for error data.
SchemaIssue-
AnySchemaIssueAny schema validation issue produced by the parser.
UnknownFieldModeDetermines how an unknown attribute or child element is handled.
UnknownFieldDataThe data passed to the UnknownFieldCallback.
UnknownFieldCallbackCallback invoked when an attribute or child element is not defined by the current schema.
DuplicateChildElementModeDetermines how a duplicate child element is handled when the schema expects at most one element with a given tag.
DuplicateChildElementData-
DuplicateChildElementCallbackCallback invoked when multiple child elements are found for a schema field that expects a unique child element.
ResultA non-throwing operation result.
SwXmlPathA path identifying an element in an XML document.
SchemaPathA path identifying a value in the parsed JavaScript object.
SchemaInputA value accepted by schemas.
SchemaParseFieldResultThe result of parsing one field from an XML record node.
SchemaParseFieldAttributeResultThe result of parsing one attribute-backed field.
SchemaParseFieldChildResultThe result of parsing one child-element-backed field.
WriteElementCallbackWrites an XML element with the supplied tag name.
ElementSchemaSerializeResultThe result of serializing a schema that produces XML elements.
SchemaSerializeResultThe result of serializing one schema field.
UnknownValueA JSON-like value used for untyped XML data.
AnySchema-
ShapeThe field schema map used by object-like schemas.
InferInfers the TypeScript value accepted by a schema.
Immutable-
InferImmutableInfers the TypeScript value accepted by a schema, and makes it deeply readonly.
OptionalKeysKeys whose fields are optional schemas.
RequiredKeysKeys whose fields are required schemas.
InferShapeInfers the object value produced by a schema shape.
PartialShapeConverts every field in a shape into an optional schema.
ExtendShapeThe shape produced by extending one shape with another.
ExtendObjectSchemaThe object schema type produced by extending an object schema.
OmitObjectSchemaThe object schema type produced by omitting keys from an object schema.
ObjectShapeExtracts the shape from an object schema.

Functions ​

FunctionDescription
booleanCreates a schema that parses XML attribute values as booleans.
listCreates a schema that parses repeated child elements as a JavaScript array.
metalistCreates a schema for list elements that also carry metadata fields.
numberCreates a schema that parses XML attribute values as numbers.
objectCreates a schema that parses XML record elements as JavaScript objects.
partialObjectCreates an object schema where every field is optional.
recordCreates a schema that parses child tag names as keys and their elements as values.
stringCreates a schema that parses XML attribute values as strings.
unionCreates a schema that accepts any value accepted by one of the given schemas.
prependSchemaIssuePathPrepends path segments to every issue in a schema error.
prependSchemaSerializeIssuePathPrepends path segments to every issue in a schema serialization error.
formatSchemaPathFormats a schema path for error messages.