Documentation / @sw-file-lib/xml / xml-schema / ObjectListSchema
Class: ObjectListSchema<S1, S2, T1, T2>
class ObjectListSchema extends ListSchema<S2, T2> {
constructor(itemTag: string, itemSchema: S2);
readonly name: "list";
readonly itemTag: string;
readonly itemSchema: S2;
safeParseValue(input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions): Result<T2, SchemaError>;
parseValue(input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions): T2;
safeParseField(parent: SwXmlNode, key: string, ctx: SchemaParseContext, options?: SchemaParseOptions): SchemaParseFieldResult<T2>;
safeParse(tree: string | SwXmlNodeList | Uint8Array<ArrayBufferLike>, rootTag: string, options?: SchemaParseOptions): Result<T2, SchemaError>;
parse(tree: string | SwXmlNodeList | Uint8Array<ArrayBufferLike>, rootTag: string, options?: SchemaParseOptions): T2;
serializeField(value: unknown): ElementSchemaSerializeResult;
safeSerialize(data: Immutable<T2>, rootTag: string, writer?: XmlWriterOptions | XmlWriter): Result<XmlWriter, SchemaSerializeError>;
serialize(data: Immutable<T2>, rootTag: string, writer?: XmlWriterOptions | XmlWriter): XmlWriter;
renameItemTag(itemTag: string): ListSchema<S2, T2>;
extendItem(shape: U | ((s: S1) => U)): ObjectListSchema<ExtendShape<S1, U>, ExtendObjectSchema<S1, U>>;
omitItem(keys: U[]): ObjectListSchema<Omit<S1, U>, OmitObjectSchema<S1, U>>;
optional(): OptionalSchema<ObjectListSchema<S1, S2, T1, T2>>;
create(itemTag: string, itemSchema: S): ListSchema<S, Infer<S>[]>;
createWithObjectSchema(itemTag: string, itemSchema: S2): ObjectListSchema<S1, S2, InferShape<S1>, Infer<S2>[]>;
}Defined in: packages/xml/src/xml-schema/classes/list.ts:185
A list schema whose item schema is an object schema.
Extends
ListSchema<S2,T2>
Type Parameters
| Type Parameter | Default type |
|---|---|
S1 extends Shape | - |
S2 extends ObjectSchema<S1, T1> | - |
T1 extends object | InferShape<S1> |
T2 extends any[] | Infer<S2>[] |
Constructors
Constructor
protected new ObjectListSchema<S1, S2, T1, T2>(itemTag: string, itemSchema: S2): ObjectListSchema<S1, S2, T1, T2>;Defined in: packages/xml/src/xml-schema/classes/list.ts:46
Parameters
| Parameter | Type |
|---|---|
itemTag | string |
itemSchema | S2 |
Returns
ObjectListSchema<S1, S2, T1, T2>
Inherited from
Properties
name
readonly name: "list" = "list";Defined in: packages/xml/src/xml-schema/classes/list.ts:44
Inherited from
itemTag
readonly itemTag: string;Defined in: packages/xml/src/xml-schema/classes/list.ts:47
Inherited from
itemSchema
readonly itemSchema: S2;Defined in: packages/xml/src/xml-schema/classes/list.ts:48
Inherited from
Methods
safeParseValue()
safeParseValue(
input: SchemaInput,
ctx: SchemaParseContext,
options?: SchemaParseOptions): Result<T2, 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<T2, SchemaError>
Inherited from
parseValue()
parseValue(
input: SchemaInput,
ctx: SchemaParseContext,
options?: SchemaParseOptions): T2;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
T2
Throws
SchemaError when the value does not match the schema.
Inherited from
safeParseField()
safeParseField(
parent: SwXmlNode,
key: string,
ctx: SchemaParseContext,
options?: SchemaParseOptions): SchemaParseFieldResult<T2>;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
Inherited from
safeParse()
safeParse(
tree:
| string
| SwXmlNodeList
| Uint8Array<ArrayBufferLike>,
rootTag: string,
options?: SchemaParseOptions): Result<T2, 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<T2, SchemaError>
Inherited from
parse()
parse(
tree:
| string
| SwXmlNodeList
| Uint8Array<ArrayBufferLike>,
rootTag: string,
options?: SchemaParseOptions): T2;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
T2
Throws
SchemaError when the value does not match the schema.
Inherited from
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
Inherited from
safeSerialize()
safeSerialize(
data: Immutable<T2>,
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<T2> |
rootTag | string |
writer? | | XmlWriterOptions | XmlWriter |
Returns
Result<XmlWriter, SchemaSerializeError>
Inherited from
serialize()
serialize(
data: Immutable<T2>,
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<T2> |
rootTag | string |
writer? | | XmlWriterOptions | XmlWriter |
Returns
Throws
SchemaSerializeError when the value or any item cannot be serialized.
Inherited from
renameItemTag()
renameItemTag(itemTag: string): ListSchema<S2, T2>;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<S2, T2>
Inherited from
extendItem()
extendItem<U>(shape: U | ((s: S1) => U)): ObjectListSchema<ExtendShape<S1, U>, ExtendObjectSchema<S1, U>>;Defined in: packages/xml/src/xml-schema/classes/list.ts:213
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
| Parameter | Type |
|---|---|
shape | U | ((s: S1) => U) |
Returns
ObjectListSchema<ExtendShape<S1, U>, ExtendObjectSchema<S1, U>>
Example
const withId = items.extendItem({ id: x.number() });
const withNestedZ = items.extendItem((s) => ({
position: s.position.extend({ z: x.number() }),
}));omitItem()
omitItem<U>(keys: U[]): ObjectListSchema<Omit<S1, U>, OmitObjectSchema<S1, U>>;Defined in: packages/xml/src/xml-schema/classes/list.ts:222
Returns a new list schema with specified keys are omitted from the item schema.
Type Parameters
| Type Parameter |
|---|
U extends string | number | symbol |
Parameters
| Parameter | Type |
|---|---|
keys | U[] |
Returns
ObjectListSchema<Omit<S1, U>, OmitObjectSchema<S1, U>>
optional()
optional(): OptionalSchema<ObjectListSchema<S1, S2, T1, T2>>;Defined in: packages/xml/src/xml-schema/classes/list.ts:226
Returns an optional version of this list schema.
Returns
OptionalSchema<ObjectListSchema<S1, S2, T1, T2>>
Overrides
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>[]>
Inherited from
createWithObjectSchema()
static createWithObjectSchema<S1, S2>(itemTag: string, itemSchema: S2): ObjectListSchema<S1, S2, InferShape<S1>, Infer<S2>[]>;Defined in: packages/xml/src/xml-schema/classes/list.ts:191
Type Parameters
| Type Parameter |
|---|
S1 extends Shape |
S2 extends ObjectSchema<S1, InferShape<S1>> |
Parameters
| Parameter | Type |
|---|---|
itemTag | string |
itemSchema | S2 |
Returns
ObjectListSchema<S1, S2, InferShape<S1>, Infer<S2>[]>