Documentation / @sw-file-lib/xml / xml-schema / StringSchema
Class: StringSchema
class StringSchema {
constructor();
readonly name: "string";
safeParseValue(input: SchemaInput, _ctx: SchemaParseContext, _options?: SchemaParseOptions): Result<string, SchemaError>;
parseValue(input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions): string;
safeParseField(parent: SwXmlNode, key: string, ctx: SchemaParseContext, options?: SchemaParseOptions): SchemaParseFieldAttributeResult<string>;
serializeField(value: unknown): SchemaSerializeResult;
optional(): OptionalSchema<StringSchema>;
}Defined in: packages/xml/src/xml-schema/classes/string.ts:18
A schema that parses XML attribute values as strings.
Implements
Schema<string>
Constructors
Constructor
new StringSchema(): StringSchema;Returns
StringSchema
Properties
name
readonly name: "string" = "string";Defined in: packages/xml/src/xml-schema/classes/string.ts:19
Implementation of
Methods
safeParseValue()
safeParseValue(
input: SchemaInput,
_ctx: SchemaParseContext,
_options?: SchemaParseOptions): Result<string, SchemaError>;Defined in: packages/xml/src/xml-schema/classes/string.ts:21
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<string, SchemaError>
Implementation of
parseValue()
parseValue(
input: SchemaInput,
ctx: SchemaParseContext,
options?: SchemaParseOptions): string;Defined in: packages/xml/src/xml-schema/classes/string.ts:36
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
string
Throws
SchemaError when the value does not match the schema.
Implementation of
safeParseField()
safeParseField(
parent: SwXmlNode,
key: string,
ctx: SchemaParseContext,
options?: SchemaParseOptions): SchemaParseFieldAttributeResult<string>;Defined in: packages/xml/src/xml-schema/classes/string.ts:40
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
SchemaParseFieldAttributeResult<string>
Implementation of
serializeField()
serializeField(value: unknown): SchemaSerializeResult;Defined in: packages/xml/src/xml-schema/classes/string.ts:57
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<StringSchema>;Defined in: packages/xml/src/xml-schema/classes/string.ts:65
Returns a schema that accepts undefined values.
Returns
OptionalSchema<StringSchema>