Documentation / @sw-file-lib/xml / xml-schema / ListSchema
Class: ListSchema<S, T>
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 Parameter | Default type |
|---|---|
S extends ElementSchema<any> | - |
T extends any[] | Infer<S>[] |
Implements
Constructors
Constructor
protected new ListSchema<S, T>(itemTag: string, itemSchema: S): ListSchema<S, T>;Defined in: packages/xml/src/xml-schema/classes/list.ts:46
Parameters
| Parameter | Type |
|---|---|
itemTag | string |
itemSchema | S |
Returns
ListSchema<S, T>
Properties
name
readonly name: "list" = "list";Defined in: packages/xml/src/xml-schema/classes/list.ts:44
Implementation of
itemTag
readonly itemTag: string;Defined in: packages/xml/src/xml-schema/classes/list.ts:47
itemSchema
readonly itemSchema: S;Defined in: packages/xml/src/xml-schema/classes/list.ts:48
Methods
safeParseValue()
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
| Parameter | Type |
|---|---|
input | SchemaInput |
ctx | SchemaParseContext |
options? | SchemaParseOptions |
Returns
Result<T, SchemaError>
Implementation of
parseValue()
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
| Parameter | Type |
|---|---|
input | SchemaInput |
ctx | SchemaParseContext |
options? | SchemaParseOptions |
Returns
T
Throws
SchemaError when the value does not match the schema.
Implementation of
safeParseField()
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
| Parameter | Type |
|---|---|
parent | SwXmlNode |
key | string |
ctx | SchemaParseContext |
options? | SchemaParseOptions |
Returns
Implementation of
safeParse()
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
| Parameter | Type |
|---|---|
tree | | string | SwXmlNodeList | Uint8Array<ArrayBufferLike> |
rootTag | string |
options? | SchemaParseOptions |
Returns
Result<T, SchemaError>
Implementation of
parse()
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
| Parameter | Type |
|---|---|
tree | | string | SwXmlNodeList | Uint8Array<ArrayBufferLike> |
rootTag | string |
options? | SchemaParseOptions |
Returns
T
Throws
SchemaError when the value does not match the schema.
Implementation of
serializeField()
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
| Parameter | Type |
|---|---|
value | unknown |
Returns
Implementation of
safeSerialize()
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
| Parameter | Type |
|---|---|
data | Immutable<T> |
rootTag | string |
writer? | | XmlWriterOptions | XmlWriter |
Returns
Result<XmlWriter, SchemaSerializeError>
Implementation of
serialize()
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
| Parameter | Type |
|---|---|
data | Immutable<T> |
rootTag | string |
writer? | | XmlWriterOptions | XmlWriter |
Returns
Throws
SchemaSerializeError when the value or any item cannot be serialized.
Implementation of
optional()
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
renameItemTag()
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
| Parameter | Type |
|---|---|
itemTag | string |
Returns
ListSchema<S, T>
create()
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
| Parameter | Type |
|---|---|
itemTag | string |
itemSchema | S |
Returns
ListSchema<S, Infer<S>[]>