Skip to content

Documentation / @sw-file-lib/xml / xml-schema / ElementSchema

Interface: ElementSchema<T> ​

ts
interface ElementSchema extends Schema<T> {
  readonly name: string;
  safeParseValue: (input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions) => Result<T, SchemaError>;
  parseValue: (input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions) => T;
  safeParseField: (parent: SwXmlNode, key: string, ctx: SchemaParseContext, options?: SchemaParseOptions) => SchemaParseFieldResult<T>;
  optional: () => OptionalSchema<Schema<T>>;
  safeParse: (tree: string | SwXmlNodeList | Uint8Array<ArrayBufferLike>, rootTag: string, options?: SchemaParseOptions) => Result<T, SchemaError>;
  parse: (tree: string | SwXmlNodeList | Uint8Array<ArrayBufferLike>, rootTag: string, options?: SchemaParseOptions) => T;
  serializeField: (value: unknown) => ElementSchemaSerializeResult;
  safeSerialize: (data: Immutable<T>, rootTag: string, writer?: XmlWriterOptions | XmlWriter) => Result<XmlWriter, SchemaSerializeError>;
  serialize: (data: Immutable<T>, rootTag: string, writer?: XmlWriterOptions | XmlWriter) => XmlWriter;
}

Defined in: packages/xml/src/xml-schema/types.ts:205

A schema that can parse and serialize a complete XML element.

Extends ​

Type Parameters ​

Type Parameter
T

Properties ​

PropertyModifierTypeDescriptionOverridesInherited from

name

readonly

string

‐

‐

Schema.name

safeParseValue

public

(input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions) => Result<T, SchemaError>

Parses a Stormworks XML node or attribute value without throwing schema errors.

This is a low-level operation used by schema implementations. For parsing a full XML tree, prefer ElementSchema.safeParse.

‐

Schema.safeParseValue

parseValue

public

(input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions) => T

Parses a Stormworks XML node or attribute value.

This is a low-level operation used by schema implementations. For parsing a full XML tree, prefer ElementSchema.parse.

Throws

SchemaError when the value does not match the schema.

‐

Schema.parseValue

safeParseField

public

(parent: SwXmlNode, key: string, ctx: SchemaParseContext, options?: SchemaParseOptions) => SchemaParseFieldResult<T>

Parses one field from an XML record node.

Primitive schemas read attributes. Element schemas read child elements.

This is primarily intended for schema implementations. Most callers should use ElementSchema.safeParse on a top-level element schema instead.

‐

Schema.safeParseField

optional

public

() => OptionalSchema<Schema<T>>

Returns a schema that accepts undefined values.

‐

Schema.optional

safeParse

public

(tree: | string | SwXmlNodeList | Uint8Array<ArrayBufferLike>, rootTag: string, options?: SchemaParseOptions) => Result<T, SchemaError>

Parses a complete XML tree without throwing schema errors.

The root element must have the supplied tag name.

‐

‐

parse

public

(tree: | string | SwXmlNodeList | Uint8Array<ArrayBufferLike>, rootTag: string, options?: SchemaParseOptions) => T

Parses a complete XML tree.

The root element must have the supplied tag name.

Throws

SchemaError when the value does not match the schema.

‐

‐

serializeField

public

(value: unknown) => ElementSchemaSerializeResult

Serializes an element value without throwing.

This is primarily intended for schema implementations. Most callers should use safeSerialize or serialize instead.

Schema.serializeField

‐

safeSerialize

public

(data: Immutable<T>, rootTag: string, writer?: | XmlWriterOptions | XmlWriter) => Result<XmlWriter, SchemaSerializeError>

Serializes data into an XmlWriter without throwing an error.

‐

‐

serialize

public

(data: Immutable<T>, rootTag: string, writer?: | XmlWriterOptions | XmlWriter) => XmlWriter

Serializes data into an XmlWriter.

Throws

SchemaSerializeError when the value cannot be serialized by the schema.

‐

‐