Documentation / @sw-file-lib/xml / xml-schema / RecordSchema
Class: RecordSchema<S, T>
class RecordSchema {
constructor(itemSchema: S);
readonly name: "record";
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<RecordSchema<S, T>>;
create(itemSchema: S): RecordSchema<S, Record<string, Infer<S>>>;
}Defined in: packages/xml/src/xml-schema/classes/record.ts:53
A schema that parses XML children with arbitrary unique tags as a string-keyed object.
Extended by
Type Parameters
| Type Parameter | Default type |
|---|---|
S extends ElementSchema<any> | - |
T extends Record<string, any> | Record<string, Infer<S>> |
Implements
Constructors
Constructor
protected new RecordSchema<S, T>(itemSchema: S): RecordSchema<S, T>;Defined in: packages/xml/src/xml-schema/classes/record.ts:59
Parameters
| Parameter | Type |
|---|---|
itemSchema | S |
Returns
RecordSchema<S, T>
Properties
name
readonly name: "record" = "record";Defined in: packages/xml/src/xml-schema/classes/record.ts:57
Implementation of
itemSchema
readonly itemSchema: S;Defined in: packages/xml/src/xml-schema/classes/record.ts:59
Methods
safeParseValue()
safeParseValue(
input: SchemaInput,
ctx: SchemaParseContext,
options?: SchemaParseOptions): Result<T, SchemaError>;Defined in: packages/xml/src/xml-schema/classes/record.ts:65
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/record.ts:118
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/record.ts:122
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/record.ts:131
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/record.ts:139
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/record.ts:147
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/record.ts:197
Serializes a record 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/record.ts:211
Serializes a record 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<RecordSchema<S, T>>;Defined in: packages/xml/src/xml-schema/classes/record.ts:218
Returns an optional version of this record schema.
Returns
OptionalSchema<RecordSchema<S, T>>
Implementation of
create()
static create<S>(itemSchema: S): RecordSchema<S, Record<string, Infer<S>>>;Defined in: packages/xml/src/xml-schema/classes/record.ts:61
Type Parameters
| Type Parameter |
|---|
S extends ElementSchema<any> |
Parameters
| Parameter | Type |
|---|---|
itemSchema | S |
Returns
RecordSchema<S, Record<string, Infer<S>>>