Documentation / @sw-file-lib/xml / xml-schema / MetalistSchema
Class: MetalistSchema<MS, IS, MT, IT>
class MetalistSchema {
constructor(itemTag: string, metaShape: MS, itemSchema: IS);
readonly name: "metalist";
readonly itemTag: string;
readonly metaShape: MS;
readonly itemSchema: IS;
safeParseValue(input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions): Result<Metalist<MT, IT>, SchemaError>;
parseValue(input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions): Metalist<MT, IT>;
safeParseField(parent: SwXmlNode, key: string, ctx: SchemaParseContext, options?: SchemaParseOptions): SchemaParseFieldResult<Metalist<MT, IT>>;
safeParse(tree: string | SwXmlNodeList | Uint8Array<ArrayBufferLike>, rootTag: string, options?: SchemaParseOptions): Result<Metalist<MT, IT>, SchemaError>;
parse(tree: string | SwXmlNodeList | Uint8Array<ArrayBufferLike>, rootTag: string, options?: SchemaParseOptions): Metalist<MT, IT>;
serializeField(value: unknown): ElementSchemaSerializeResult;
safeSerialize(data: { meta: Immutable; items: Immutable }, rootTag: string, writer?: XmlWriterOptions | XmlWriter): Result<XmlWriter, SchemaSerializeError>;
serialize(data: { meta: Immutable; items: Immutable }, rootTag: string, writer?: XmlWriterOptions | XmlWriter): XmlWriter;
optional(): OptionalSchema<MetalistSchema<MS, IS, MT, IT>>;
renameItemTag(itemTag: string): MetalistSchema<MS, IS>;
extendMeta(shape: U | ((s: MS) => U)): MetalistSchema<ExtendShape<MS, U>, IS>;
omitMeta(keys: U[]): MetalistSchema<Omit<MS, U>, IS>;
create(itemTag: string, metaShape: MS, itemSchema: IS): MetalistSchema<MS, IS, InferShape<MS>, Infer<IS>[]>;
}Defined in: packages/xml/src/xml-schema/classes/metalist.ts:55
A schema that parses XML list elements that have attributes as JavaScript arrays.
Extended by
Type Parameters
| Type Parameter | Default type |
|---|---|
MS extends Shape | - |
IS extends ElementSchema<any> | - |
MT extends object | InferShape<MS> |
IT extends any[] | Infer<IS>[] |
Implements
ElementSchema<Metalist<MT,IT>>
Constructors
Constructor
protected new MetalistSchema<MS, IS, MT, IT>(
itemTag: string,
metaShape: MS,
itemSchema: IS): MetalistSchema<MS, IS, MT, IT>;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:63
Parameters
| Parameter | Type |
|---|---|
itemTag | string |
metaShape | MS |
itemSchema | IS |
Returns
MetalistSchema<MS, IS, MT, IT>
Properties
name
readonly name: "metalist" = "metalist";Defined in: packages/xml/src/xml-schema/classes/metalist.ts:61
Implementation of
itemTag
readonly itemTag: string;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:64
metaShape
readonly metaShape: MS;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:65
itemSchema
readonly itemSchema: IS;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:66
Methods
safeParseValue()
safeParseValue(
input: SchemaInput,
ctx: SchemaParseContext,
options?: SchemaParseOptions): Result<Metalist<MT, IT>, SchemaError>;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:77
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<Metalist<MT, IT>, SchemaError>
Implementation of
parseValue()
parseValue(
input: SchemaInput,
ctx: SchemaParseContext,
options?: SchemaParseOptions): Metalist<MT, IT>;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:117
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
Metalist<MT, IT>
Throws
SchemaError when the value does not match the schema.
Implementation of
safeParseField()
safeParseField(
parent: SwXmlNode,
key: string,
ctx: SchemaParseContext,
options?: SchemaParseOptions): SchemaParseFieldResult<Metalist<MT, IT>>;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:125
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
SchemaParseFieldResult<Metalist<MT, IT>>
Implementation of
safeParse()
safeParse(
tree:
| string
| SwXmlNodeList
| Uint8Array<ArrayBufferLike>,
rootTag: string,
options?: SchemaParseOptions): Result<Metalist<MT, IT>, SchemaError>;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:134
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<Metalist<MT, IT>, SchemaError>
Implementation of
parse()
parse(
tree:
| string
| SwXmlNodeList
| Uint8Array<ArrayBufferLike>,
rootTag: string,
options?: SchemaParseOptions): Metalist<MT, IT>;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:142
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
Metalist<MT, IT>
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/metalist.ts:150
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: {
meta: Immutable;
items: Immutable;
},
rootTag: string,
writer?:
| XmlWriterOptions
| XmlWriter): Result<XmlWriter, SchemaSerializeError>;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:218
Serializes a metalist value into an XML element without throwing.
Parameters
| Parameter | Type |
|---|---|
data | { meta: Immutable; items: Immutable; } |
data.meta | Immutable |
data.items | Immutable |
rootTag? | string |
writer? | | XmlWriterOptions | XmlWriter |
Returns
Result<XmlWriter, SchemaSerializeError>
Implementation of
serialize()
serialize(
data: {
meta: Immutable;
items: Immutable;
},
rootTag: string,
writer?:
| XmlWriterOptions
| XmlWriter): XmlWriter;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:232
Serializes a metalist value into an XML element.
Parameters
| Parameter | Type |
|---|---|
data | { meta: Immutable; items: Immutable; } |
data.meta | Immutable |
data.items | Immutable |
rootTag? | string |
writer? | | XmlWriterOptions | XmlWriter |
Returns
Throws
SchemaSerializeError when metadata or any item cannot be serialized.
Implementation of
optional()
optional(): OptionalSchema<MetalistSchema<MS, IS, MT, IT>>;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:240
Returns a schema that accepts undefined values.
Returns
OptionalSchema<MetalistSchema<MS, IS, MT, IT>>
Implementation of
renameItemTag()
renameItemTag(itemTag: string): MetalistSchema<MS, IS>;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:247
Returns a new metalist schema with the name of item tags changed.
Parameters
| Parameter | Type |
|---|---|
itemTag | string |
Returns
MetalistSchema<MS, IS>
extendMeta()
extendMeta<U>(shape: U | ((s: MS) => U)): MetalistSchema<ExtendShape<MS, U>, IS>;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:266
Returns a new metalist schema by adding new fields or overwriting existing fields to the meta schema.
Pass a shape object directly when the new metadata fields do not depend on the existing metadata shape. Pass a callback when you need to reference existing metadata fields.
Type Parameters
| Type Parameter |
|---|
U extends Shape |
Parameters
| Parameter | Type |
|---|---|
shape | U | ((s: MS) => U) |
Returns
MetalistSchema<ExtendShape<MS, U>, IS>
Example
const withName = list.extendMeta({ name: x.string() });
const withNestedZ = list.extendMeta((s) => ({
position: s.position.extend({ z: x.number() }),
}));omitMeta()
omitMeta<U>(keys: U[]): MetalistSchema<Omit<MS, U>, IS>;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:277
Returns a new list schema with specified keys are omitted from the meta schema.
Type Parameters
| Type Parameter |
|---|
U extends string | number | symbol |
Parameters
| Parameter | Type |
|---|---|
keys | U[] |
Returns
MetalistSchema<Omit<MS, U>, IS>
create()
static create<MS, IS>(
itemTag: string,
metaShape: MS,
itemSchema: IS): MetalistSchema<MS, IS, InferShape<MS>, Infer<IS>[]>;Defined in: packages/xml/src/xml-schema/classes/metalist.ts:69
Type Parameters
| Type Parameter |
|---|
MS extends Shape |
IS extends ElementSchema<any> |
Parameters
| Parameter | Type |
|---|---|
itemTag | string |
metaShape | MS |
itemSchema | IS |
Returns
MetalistSchema<MS, IS, InferShape<MS>, Infer<IS>[]>