Skip to content

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

Class: ListSchema<S, T> ​

ts
class ListSchema {
  constructor(itemTag: string, itemSchema: S);
  readonly name: "list";
  readonly itemTag: string;
  readonly itemSchema: S;
  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>;
  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;
  optional(): OptionalSchema<ListSchema<S, T>>;
  renameItemTag(itemTag: string): ListSchema<S, T>;
  create(itemTag: string, itemSchema: S): ListSchema<S, Infer<S>[]>;
}

Defined in: packages/xml/src/xml-schema/classes/list.ts:40

A schema that parses XML list elements as JavaScript arrays.

Extended by ​

Type Parameters ​

Type ParameterDefault type
S extends ElementSchema<any>-
T extends any[]Infer<S>[]

Implements ​

Constructors ​

Constructor ​

ts
protected new ListSchema<S, T>(itemTag: string, itemSchema: S): ListSchema<S, T>;

Defined in: packages/xml/src/xml-schema/classes/list.ts:46

Parameters ​

ParameterType
itemTagstring
itemSchemaS

Returns ​

ListSchema<S, T>

Properties ​

name ​

ts
readonly name: "list" = "list";

Defined in: packages/xml/src/xml-schema/classes/list.ts:44

Implementation of ​

ElementSchema.name


itemTag ​

ts
readonly itemTag: string;

Defined in: packages/xml/src/xml-schema/classes/list.ts:47


itemSchema ​

ts
readonly itemSchema: S;

Defined in: packages/xml/src/xml-schema/classes/list.ts:48

Methods ​

safeParseValue() ​

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

Defined in: packages/xml/src/xml-schema/classes/list.ts:55

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.

Parameters ​

ParameterType
inputSchemaInput
ctxSchemaParseContext
options?SchemaParseOptions

Returns ​

Result<T, SchemaError>

Implementation of ​

ElementSchema.safeParseValue


parseValue() ​

ts
parseValue(
   input: SchemaInput, 
   ctx: SchemaParseContext, 
   options?: SchemaParseOptions): T;

Defined in: packages/xml/src/xml-schema/classes/list.ts:83

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.

Parameters ​

ParameterType
inputSchemaInput
ctxSchemaParseContext
options?SchemaParseOptions

Returns ​

T

Throws ​

SchemaError when the value does not match the schema.

Implementation of ​

ElementSchema.parseValue


safeParseField() ​

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

Defined in: packages/xml/src/xml-schema/classes/list.ts:87

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.

Parameters ​

ParameterType
parentSwXmlNode
keystring
ctxSchemaParseContext
options?SchemaParseOptions

Returns ​

SchemaParseFieldResult<T>

Implementation of ​

ElementSchema.safeParseField


safeParse() ​

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

Defined in: packages/xml/src/xml-schema/classes/list.ts:96

Parses a complete XML tree without throwing schema errors.

The root element must have the supplied tag name.

Parameters ​

ParameterType
tree| string | SwXmlNodeList | Uint8Array<ArrayBufferLike>
rootTagstring
options?SchemaParseOptions

Returns ​

Result<T, SchemaError>

Implementation of ​

ElementSchema.safeParse


parse() ​

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

Defined in: packages/xml/src/xml-schema/classes/list.ts:104

Parses a complete XML tree.

The root element must have the supplied tag name.

Parameters ​

ParameterType
tree| string | SwXmlNodeList | Uint8Array<ArrayBufferLike>
rootTagstring
options?SchemaParseOptions

Returns ​

T

Throws ​

SchemaError when the value does not match the schema.

Implementation of ​

ElementSchema.parse


serializeField() ​

ts
serializeField(value: unknown): ElementSchemaSerializeResult;

Defined in: packages/xml/src/xml-schema/classes/list.ts:112

Serializes an element value without throwing.

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

Parameters ​

ParameterType
valueunknown

Returns ​

ElementSchemaSerializeResult

Implementation of ​

ElementSchema.serializeField


safeSerialize() ​

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

Defined in: packages/xml/src/xml-schema/classes/list.ts:149

Serializes an array value into an XML element without throwing.

Parameters ​

ParameterType
dataImmutable<T>
rootTagstring
writer?| XmlWriterOptions | XmlWriter

Returns ​

Result<XmlWriter, SchemaSerializeError>

Implementation of ​

ElementSchema.safeSerialize


serialize() ​

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

Defined in: packages/xml/src/xml-schema/classes/list.ts:163

Serializes an array value into an XML element.

Parameters ​

ParameterType
dataImmutable<T>
rootTagstring
writer?| XmlWriterOptions | XmlWriter

Returns ​

XmlWriter

Throws ​

SchemaSerializeError when the value or any item cannot be serialized.

Implementation of ​

ElementSchema.serialize


optional() ​

ts
optional(): OptionalSchema<ListSchema<S, T>>;

Defined in: packages/xml/src/xml-schema/classes/list.ts:170

Returns an optional version of this list schema.

Returns ​

OptionalSchema<ListSchema<S, T>>

Implementation of ​

ElementSchema.optional


renameItemTag() ​

ts
renameItemTag(itemTag: string): ListSchema<S, T>;

Defined in: packages/xml/src/xml-schema/classes/list.ts:177

Returns a new list schema with the name of item tags changed.

Parameters ​

ParameterType
itemTagstring

Returns ​

ListSchema<S, T>


create() ​

ts
static create<S>(itemTag: string, itemSchema: S): ListSchema<S, Infer<S>[]>;

Defined in: packages/xml/src/xml-schema/classes/list.ts:51

Type Parameters ​

Type Parameter
S extends ElementSchema<any>

Parameters ​

ParameterType
itemTagstring
itemSchemaS

Returns ​

ListSchema<S, Infer<S>[]>