Documentation / @sw-file-lib/xml / xml-schema / UnionSchema
Class: UnionSchema<T>
class UnionSchema {
constructor(schemas: T);
readonly name: "union";
readonly schemas: T;
safeParseValue(input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions): Result<Infer<T[number]>, SchemaError>;
parseValue(value: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions): Infer<T[number]>;
safeParseField(parent: SwXmlNode, key: string, ctx: SchemaParseContext, options?: SchemaParseOptions): SchemaParseFieldResult<Infer<T[number]>>;
serializeField(value: unknown): SchemaSerializeResult;
optional(): OptionalSchema<UnionSchema<T>>;
}Defined in: packages/xml/src/xml-schema/classes/union.ts:34
A schema that tries multiple schemas from left to right.
Parsing succeeds with the first branch that matches. Parse errors keep the errors returned by each branch, and serialization errors report the direct branch schema names as the expected value.
Type Parameters
| Type Parameter |
|---|
T extends SchemaTuple |
Implements
Schema<InferUnion<T>>
Constructors
Constructor
new UnionSchema<T>(schemas: T): UnionSchema<T>;Defined in: packages/xml/src/xml-schema/classes/union.ts:37
Parameters
| Parameter | Type |
|---|---|
schemas | T |
Returns
UnionSchema<T>
Properties
name
readonly name: "union" = "union";Defined in: packages/xml/src/xml-schema/classes/union.ts:35
Implementation of
schemas
readonly schemas: T;Defined in: packages/xml/src/xml-schema/classes/union.ts:37
Methods
safeParseValue()
safeParseValue(
input: SchemaInput,
ctx: SchemaParseContext,
options?: SchemaParseOptions): Result<Infer<T[number]>, SchemaError>;Defined in: packages/xml/src/xml-schema/classes/union.ts:39
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<Infer<T[number]>, SchemaError>
Implementation of
parseValue()
parseValue(
value: SchemaInput,
ctx: SchemaParseContext,
options?: SchemaParseOptions): Infer<T[number]>;Defined in: packages/xml/src/xml-schema/classes/union.ts:67
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 |
|---|---|
value | SchemaInput |
ctx | SchemaParseContext |
options? | SchemaParseOptions |
Returns
Infer<T[number]>
Throws
SchemaError when the value does not match the schema.
Implementation of
safeParseField()
safeParseField(
parent: SwXmlNode,
key: string,
ctx: SchemaParseContext,
options?: SchemaParseOptions): SchemaParseFieldResult<Infer<T[number]>>;Defined in: packages/xml/src/xml-schema/classes/union.ts:75
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<Infer<T[number]>>
Implementation of
serializeField()
serializeField(value: unknown): SchemaSerializeResult;Defined in: packages/xml/src/xml-schema/classes/union.ts:104
Serializes one field without throwing.
This is primarily intended for schema implementations. Most callers should use ElementSchema.safeSerialize or ElementSchema.serialize on a top-level element schema instead.
Parameters
| Parameter | Type |
|---|---|
value | unknown |
Returns
Implementation of
optional()
optional(): OptionalSchema<UnionSchema<T>>;Defined in: packages/xml/src/xml-schema/classes/union.ts:130
Returns a schema that accepts undefined values.
Returns
OptionalSchema<UnionSchema<T>>