Skip to content

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

Interface: Schema<T> ​

ts
interface Schema {
  readonly name: string;
  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>;
  optional: () => OptionalSchema<Schema<T>>;
  serializeField(value: unknown): SchemaSerializeResult;
}

Defined in: packages/xml/src/xml-schema/types.ts:147

A schema that parses a Stormworks XML node into a typed value.

Extended by ​

Type Parameters ​

Type Parameter
T

Properties ​

PropertyModifierTypeDescription

name

readonly

string

‐

safeParseValue

public

(input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions) => Result<T, SchemaError>

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.

parseValue

public

(input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions) => T

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.

Throws

SchemaError when the value does not match the schema.

safeParseField

public

(parent: SwXmlNode, key: string, ctx: SchemaParseContext, options?: SchemaParseOptions) => SchemaParseFieldResult<T>

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.

optional

public

() => OptionalSchema<Schema<T>>

Returns a schema that accepts undefined values.

Methods ​

serializeField() ​

ts
serializeField(value: unknown): SchemaSerializeResult;

Defined in: packages/xml/src/xml-schema/types.ts:194

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 ​

ParameterType
valueunknown

Returns ​

SchemaSerializeResult