Documentation / @sw-file-lib/xml / xml-schema / ObjectRecordSchema
Class: ObjectRecordSchema<S1, S2, T1, T2>
class ObjectRecordSchema extends RecordSchema<S2, T2> {
constructor(itemSchema: S2);
readonly name: "record";
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;
extendItem(shape: U | ((s: S1) => U)): ObjectRecordSchema<ExtendShape<S1, U>, ExtendObjectSchema<S1, U>>;
omitItem(keys: U[]): ObjectRecordSchema<Omit<S1, U>, OmitObjectSchema<S1, U>>;
optional(): OptionalSchema<ObjectRecordSchema<S1, S2, T1, T2>>;
create(itemSchema: S): RecordSchema<S, Record<string, Infer<S>>>;
createWithObjectSchema(itemSchema: S2): ObjectRecordSchema<S1, S2, InferShape<S1>, Record<string, Infer<S2>>>;
}Defined in: packages/xml/src/xml-schema/classes/record.ts:226
A record schema whose item schema is an object schema.
Extends
RecordSchema<S2,T2>
Type Parameters
| Type Parameter | Default type |
|---|---|
S1 extends Shape | - |
S2 extends ObjectSchema<S1, T1> | - |
T1 extends object | InferShape<S1> |
T2 extends Record<string, any> | Record<string, Infer<S2>> |
Constructors
Constructor
protected new ObjectRecordSchema<S1, S2, T1, T2>(itemSchema: S2): ObjectRecordSchema<S1, S2, T1, T2>;Defined in: packages/xml/src/xml-schema/classes/record.ts:59
Parameters
| Parameter | Type |
|---|---|
itemSchema | S2 |
Returns
ObjectRecordSchema<S1, S2, T1, T2>
Inherited from
Properties
name
readonly name: "record" = "record";Defined in: packages/xml/src/xml-schema/classes/record.ts:57
Inherited from
itemSchema
readonly itemSchema: S2;Defined in: packages/xml/src/xml-schema/classes/record.ts:59
Inherited from
Methods
safeParseValue()
safeParseValue(
input: SchemaInput,
ctx: SchemaParseContext,
options?: SchemaParseOptions): Result<T2, 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<T2, SchemaError>
Inherited from
parseValue()
parseValue(
input: SchemaInput,
ctx: SchemaParseContext,
options?: SchemaParseOptions): T2;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
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/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
Inherited from
safeParse()
safeParse(
tree:
| string
| SwXmlNodeList
| Uint8Array<ArrayBufferLike>,
rootTag: string,
options?: SchemaParseOptions): Result<T2, 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<T2, SchemaError>
Inherited from
parse()
parse(
tree:
| string
| SwXmlNodeList
| Uint8Array<ArrayBufferLike>,
rootTag: string,
options?: SchemaParseOptions): T2;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
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/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
Inherited from
safeSerialize()
safeSerialize(
data: Immutable<T2>,
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<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/record.ts:211
Serializes a record 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
extendItem()
extendItem<U>(shape: U | ((s: S1) => U)): ObjectRecordSchema<ExtendShape<S1, U>, ExtendObjectSchema<S1, U>>;Defined in: packages/xml/src/xml-schema/classes/record.ts:253
Returns a new record 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
ObjectRecordSchema<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[]): ObjectRecordSchema<Omit<S1, U>, OmitObjectSchema<S1, U>>;Defined in: packages/xml/src/xml-schema/classes/record.ts:262
Returns a new record 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
ObjectRecordSchema<Omit<S1, U>, OmitObjectSchema<S1, U>>
optional()
optional(): OptionalSchema<ObjectRecordSchema<S1, S2, T1, T2>>;Defined in: packages/xml/src/xml-schema/classes/record.ts:268
Returns an optional version of this record schema.
Returns
OptionalSchema<ObjectRecordSchema<S1, S2, T1, T2>>
Overrides
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>>>
Inherited from
createWithObjectSchema()
static createWithObjectSchema<S1, S2>(itemSchema: S2): ObjectRecordSchema<S1, S2, InferShape<S1>, Record<string, Infer<S2>>>;Defined in: packages/xml/src/xml-schema/classes/record.ts:232
Type Parameters
| Type Parameter |
|---|
S1 extends Shape |
S2 extends ObjectSchema<S1, InferShape<S1>> |
Parameters
| Parameter | Type |
|---|---|
itemSchema | S2 |
Returns
ObjectRecordSchema<S1, S2, InferShape<S1>, Record<string, Infer<S2>>>