Skip to content

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

Class: ObjectMetalistSchema<M, IS1, IS2, IT> ​

ts
class ObjectMetalistSchema extends MetalistSchema<M, IS2> {
  constructor(itemTag: string, metaShape: M, itemSchema: IS2);
  readonly name: "metalist";
  readonly itemTag: string;
  readonly metaShape: M;
  readonly itemSchema: IS2;
  safeParseValue(input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions): Result<Metalist<InferShape<M>, Infer<IS2>[]>, SchemaError>;
  parseValue(input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions): Metalist<InferShape<M>, Infer<IS2>[]>;
  safeParseField(parent: SwXmlNode, key: string, ctx: SchemaParseContext, options?: SchemaParseOptions): SchemaParseFieldResult<Metalist<InferShape<M>, Infer<IS2>[]>>;
  safeParse(tree: string | SwXmlNodeList | Uint8Array<ArrayBufferLike>, rootTag: string, options?: SchemaParseOptions): Result<Metalist<InferShape<M>, Infer<IS2>[]>, SchemaError>;
  parse(tree: string | SwXmlNodeList | Uint8Array<ArrayBufferLike>, rootTag: string, options?: SchemaParseOptions): Metalist<InferShape<M>, Infer<IS2>[]>;
  serializeField(value: unknown): ElementSchemaSerializeResult;
  safeSerialize(data: { meta: Immutable; items: readonly Immutable<Infer<IS2>>[] }, rootTag: string, writer?: XmlWriterOptions | XmlWriter): Result<XmlWriter, SchemaSerializeError>;
  serialize(data: { meta: Immutable; items: readonly Immutable<Infer<IS2>>[] }, rootTag: string, writer?: XmlWriterOptions | XmlWriter): XmlWriter;
  optional(): OptionalSchema<MetalistSchema<M, IS2, InferShape<M>, Infer<IS2>[]>>;
  renameItemTag(itemTag: string): MetalistSchema<M, IS2>;
  extendMeta(shape: U | ((s: M) => U)): MetalistSchema<ExtendShape<M, U>, IS2>;
  omitMeta(keys: U[]): MetalistSchema<Omit<M, U>, IS2>;
  extendItem(shape: U | ((s: IS1) => U)): ObjectMetalistSchema<M, ExtendShape<IS1, U>, ExtendObjectSchema<IS1, U>>;
  omitItem(keys: U[]): ObjectMetalistSchema<M, Omit<IS1, U>, OmitObjectSchema<IS1, U>>;
  create(itemTag: string, metaShape: MS, itemSchema: IS): MetalistSchema<MS, IS, InferShape<MS>, Infer<IS>[]>;
  createWithObjectSchema(itemTag: string, metaShape: M, itemSchema: IS2): ObjectMetalistSchema<M, IS1, IS2, InferShape<IS1>>;
}

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

A metalist schema whose item schema is an object schema.

Extends ​

Type Parameters ​

Type ParameterDefault type
M extends Shape-
IS1 extends Shape-
IS2 extends ObjectSchema<IS1, IT>-
IT extends objectInferShape<IS1>

Constructors ​

Constructor ​

ts
protected new ObjectMetalistSchema<M, IS1, IS2, IT>(
   itemTag: string, 
   metaShape: M, 
itemSchema: IS2): ObjectMetalistSchema<M, IS1, IS2, IT>;

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

Parameters ​

ParameterType
itemTagstring
metaShapeM
itemSchemaIS2

Returns ​

ObjectMetalistSchema<M, IS1, IS2, IT>

Inherited from ​

MetalistSchema.constructor

Properties ​

name ​

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

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

Inherited from ​

MetalistSchema.name


itemTag ​

ts
readonly itemTag: string;

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

Inherited from ​

MetalistSchema.itemTag


metaShape ​

ts
readonly metaShape: M;

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

Inherited from ​

MetalistSchema.metaShape


itemSchema ​

ts
readonly itemSchema: IS2;

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

Inherited from ​

MetalistSchema.itemSchema

Methods ​

safeParseValue() ​

ts
safeParseValue(
   input: SchemaInput, 
   ctx: SchemaParseContext, 
options?: SchemaParseOptions): Result<Metalist<InferShape<M>, Infer<IS2>[]>, 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<InferShape<M>, Infer<IS2>[]>, SchemaError>

Inherited from ​

MetalistSchema.safeParseValue


parseValue() ​

ts
parseValue(
   input: SchemaInput, 
   ctx: SchemaParseContext, 
options?: SchemaParseOptions): Metalist<InferShape<M>, Infer<IS2>[]>;

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<InferShape<M>, Infer<IS2>[]>

Throws ​

SchemaError when the value does not match the schema.

Inherited from ​

MetalistSchema.parseValue


safeParseField() ​

ts
safeParseField(
   parent: SwXmlNode, 
   key: string, 
   ctx: SchemaParseContext, 
options?: SchemaParseOptions): SchemaParseFieldResult<Metalist<InferShape<M>, Infer<IS2>[]>>;

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<InferShape<M>, Infer<IS2>[]>>

Inherited from ​

MetalistSchema.safeParseField


safeParse() ​

ts
safeParse(
   tree: 
  | string
  | SwXmlNodeList
  | Uint8Array<ArrayBufferLike>, 
   rootTag: string, 
options?: SchemaParseOptions): Result<Metalist<InferShape<M>, Infer<IS2>[]>, 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<InferShape<M>, Infer<IS2>[]>, SchemaError>

Inherited from ​

MetalistSchema.safeParse


parse() ​

ts
parse(
   tree: 
  | string
  | SwXmlNodeList
  | Uint8Array<ArrayBufferLike>, 
   rootTag: string, 
options?: SchemaParseOptions): Metalist<InferShape<M>, Infer<IS2>[]>;

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<InferShape<M>, Infer<IS2>[]>

Throws ​

SchemaError when the value does not match the schema.

Inherited from ​

MetalistSchema.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

Inherited from ​

MetalistSchema.serializeField


safeSerialize() ​

ts
safeSerialize(
   data: {
  meta: Immutable;
  items: readonly Immutable<Infer<IS2>>[];
}, 
   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: readonly Immutable<Infer<IS2>>[]; }
data.metaImmutable
data.itemsreadonly Immutable<Infer<IS2>>[]
rootTag?string
writer?| XmlWriterOptions | XmlWriter

Returns ​

Result<XmlWriter, SchemaSerializeError>

Inherited from ​

MetalistSchema.safeSerialize


serialize() ​

ts
serialize(
   data: {
  meta: Immutable;
  items: readonly Immutable<Infer<IS2>>[];
}, 
   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: readonly Immutable<Infer<IS2>>[]; }
data.metaImmutable
data.itemsreadonly Immutable<Infer<IS2>>[]
rootTag?string
writer?| XmlWriterOptions | XmlWriter

Returns ​

XmlWriter

Throws ​

SchemaSerializeError when metadata or any item cannot be serialized.

Inherited from ​

MetalistSchema.serialize


optional() ​

ts
optional(): OptionalSchema<MetalistSchema<M, IS2, InferShape<M>, Infer<IS2>[]>>;

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

Returns a schema that accepts undefined values.

Returns ​

OptionalSchema<MetalistSchema<M, IS2, InferShape<M>, Infer<IS2>[]>>

Inherited from ​

MetalistSchema.optional


renameItemTag() ​

ts
renameItemTag(itemTag: string): MetalistSchema<M, IS2>;

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<M, IS2>

Inherited from ​

MetalistSchema.renameItemTag


extendMeta() ​

ts
extendMeta<U>(shape: U | ((s: M) => U)): MetalistSchema<ExtendShape<M, U>, IS2>;

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: M) => U)

Returns ​

MetalistSchema<ExtendShape<M, U>, IS2>

Example ​

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

Inherited from ​

MetalistSchema.extendMeta


omitMeta() ​

ts
omitMeta<U>(keys: U[]): MetalistSchema<Omit<M, U>, IS2>;

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<M, U>, IS2>

Inherited from ​

MetalistSchema.omitMeta


extendItem() ​

ts
extendItem<U>(shape: U | ((s: IS1) => U)): ObjectMetalistSchema<M, ExtendShape<IS1, U>, ExtendObjectSchema<IS1, U>>;

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

Returns a new list schema by adding new fields or overwriting existing fields to the item schema.

Pass a shape object directly when the new item fields do not depend on the existing item shape. Pass a callback when you need to reference existing item fields.

Type Parameters ​

Type Parameter
U extends Shape

Parameters ​

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

Returns ​

ObjectMetalistSchema<M, ExtendShape<IS1, U>, ExtendObjectSchema<IS1, U>>

Example ​

ts
const withId = list.extendItem({ id: x.number() });
const withNestedZ = list.extendItem((s) => ({
  position: s.position.extend({ z: x.number() }),
}));

omitItem() ​

ts
omitItem<U>(keys: U[]): ObjectMetalistSchema<M, Omit<IS1, U>, OmitObjectSchema<IS1, U>>;

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

Returns a new list schema with specified keys are omitted from the item schema.

Type Parameters ​

Type Parameter
U extends string | number | symbol

Parameters ​

ParameterType
keysU[]

Returns ​

ObjectMetalistSchema<M, Omit<IS1, U>, OmitObjectSchema<IS1, U>>


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>[]>

Inherited from ​

MetalistSchema.create


createWithObjectSchema() ​

ts
static createWithObjectSchema<M, IS1, IS2>(
   itemTag: string, 
   metaShape: M, 
itemSchema: IS2): ObjectMetalistSchema<M, IS1, IS2, InferShape<IS1>>;

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

Type Parameters ​

Type Parameter
M extends Shape
IS1 extends Shape
IS2 extends ObjectSchema<IS1, InferShape<IS1>>

Parameters ​

ParameterType
itemTagstring
metaShapeM
itemSchemaIS2

Returns ​

ObjectMetalistSchema<M, IS1, IS2, InferShape<IS1>>