Skip to content

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

Class: MetalistSchema<MS, IS, MT, IT> ​

ts
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 ParameterDefault type
MS extends Shape-
IS extends ElementSchema<any>-
MT extends objectInferShape<MS>
IT extends any[]Infer<IS>[]

Implements ​

Constructors ​

Constructor ​

ts
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 ​

ParameterType
itemTagstring
metaShapeMS
itemSchemaIS

Returns ​

MetalistSchema<MS, IS, MT, IT>

Properties ​

name ​

ts
readonly name: "metalist" = "metalist";

Defined in: packages/xml/src/xml-schema/classes/metalist.ts:61

Implementation of ​

ElementSchema.name


itemTag ​

ts
readonly itemTag: string;

Defined in: packages/xml/src/xml-schema/classes/metalist.ts:64


metaShape ​

ts
readonly metaShape: MS;

Defined in: packages/xml/src/xml-schema/classes/metalist.ts:65


itemSchema ​

ts
readonly itemSchema: IS;

Defined in: packages/xml/src/xml-schema/classes/metalist.ts:66

Methods ​

safeParseValue() ​

ts
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 ​

ParameterType
inputSchemaInput
ctxSchemaParseContext
options?SchemaParseOptions

Returns ​

Result<Metalist<MT, IT>, SchemaError>

Implementation of ​

ElementSchema.safeParseValue


parseValue() ​

ts
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 ​

ParameterType
inputSchemaInput
ctxSchemaParseContext
options?SchemaParseOptions

Returns ​

Metalist<MT, IT>

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<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 ​

ParameterType
parentSwXmlNode
keystring
ctxSchemaParseContext
options?SchemaParseOptions

Returns ​

SchemaParseFieldResult<Metalist<MT, IT>>

Implementation of ​

ElementSchema.safeParseField


safeParse() ​

ts
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 ​

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

Returns ​

Result<Metalist<MT, IT>, SchemaError>

Implementation of ​

ElementSchema.safeParse


parse() ​

ts
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 ​

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

Returns ​

Metalist<MT, IT>

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/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 ​

ParameterType
valueunknown

Returns ​

ElementSchemaSerializeResult

Implementation of ​

ElementSchema.serializeField


safeSerialize() ​

ts
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 ​

ParameterType
data{ meta: Immutable; items: Immutable; }
data.metaImmutable
data.itemsImmutable
rootTag?string
writer?| XmlWriterOptions | XmlWriter

Returns ​

Result<XmlWriter, SchemaSerializeError>

Implementation of ​

ElementSchema.safeSerialize


serialize() ​

ts
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 ​

ParameterType
data{ meta: Immutable; items: Immutable; }
data.metaImmutable
data.itemsImmutable
rootTag?string
writer?| XmlWriterOptions | XmlWriter

Returns ​

XmlWriter

Throws ​

SchemaSerializeError when metadata or any item cannot be serialized.

Implementation of ​

ElementSchema.serialize


optional() ​

ts
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 ​

ElementSchema.optional


renameItemTag() ​

ts
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 ​

ParameterType
itemTagstring

Returns ​

MetalistSchema<MS, IS>


extendMeta() ​

ts
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 ​

ParameterType
shapeU | ((s: MS) => U)

Returns ​

MetalistSchema<ExtendShape<MS, U>, IS>

Example ​

ts
const withName = list.extendMeta({ name: x.string() });
const withNestedZ = list.extendMeta((s) => ({
  position: s.position.extend({ z: x.number() }),
}));

omitMeta() ​

ts
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 ​

ParameterType
keysU[]

Returns ​

MetalistSchema<Omit<MS, U>, IS>


create() ​

ts
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 ​

ParameterType
itemTagstring
metaShapeMS
itemSchemaIS

Returns ​

MetalistSchema<MS, IS, InferShape<MS>, Infer<IS>[]>