Class: SchemaBuilder

diffusion.datatypes.RecordV2. SchemaBuilder

new SchemaBuilder()

Used to build an immutable diffusion.datatypes.RecordV2.Schema.

A schema defines the records and fields that may occur on record-based topic content.

The schema must declare at least one record type and every record must have at least one field type declared.

Every record type and field type has a 'multiplicity' which defines the number of times that the record or field may occur within the data. Multiplicity is specified as a 'minimum' and 'maximum' number of occurrences or where the minimum and maximum are the same (fixed multiplicity) then the multiplicity may be specified as a single 'occurs' value. If the minimum and maximum are different, this is referred to a 'variable' multiplicity. Only the last record declared or the last field within a record may have variable multiplicity. The maximum value may be declared as -1 to indicate that the record or field can have an unlimited number of occurrences.

The builder is used to add a record definition followed by the fields within it. After all fields have been added to a record another may then be added, and so on, and then finally #build() is called to create an immutable schema object.

Every call returns the builder instance allowing calls to be chained, for example:

const schema = builder.record("R1").string("S1").string("S2", 1, 5)
    .record("R2", 0, -1).decimal("D", 5).build();

A builder is obtained using the diffusion.datatypes.RecordV2DataType#schemaBuilder() method.

Since:
  • 6.0

Methods

build() → {diffusion.datatypes.RecordV2.Schema}

Build an immutable Schema.

At least one record with at least one field must have been added to the builder.

Returns:

a new immutable schema object representing the current state of the builder

Type
diffusion.datatypes.RecordV2.Schema

decimal(name, scale, min, max)

Add a decimal field to the current record.

A field may not be added after a field that has variable multiplicity (min != max)

Parameters:
Name Type Argument Default Description
name String

field name. This must not the same as any field already added

scale Number

the scale of the field (number of decimal places). This must be positive.

min Number <optional>
1

the minimum number of times the field should occur within the record

max Number <optional>
1

the maximum number of times the field should occur within the record. May be either -1 (indicating no upper limit) or a positive value that is not less than min

integer(name, min, max)

Add an integer field to the current record.

A field may not be added after a field that has variable multiplicity (min != max)

Parameters:
Name Type Argument Default Description
name String

field name. This must not the same as any field already added

min Number <optional>
1

the minimum number of times the field should occur within the record

max Number <optional>
1

the maximum number of times the field should occur within the record. May be either -1 (indicating no upper limit) or a positive value that is not less than min

record(name, min, max)

Add a new record to the schema

The record added must not have the same name as a previously added record.

A record may not be added after a record that has variable multiplicity (min != max)

A record may not be added directly after another record which has had no fields added.

Parameters:
Name Type Argument Default Description
name String

record name. This must not the same as any record already added

min Number <optional>
1

the minimum number of times the record should occur within the schema

max Number <optional>
1

the maximum number of times the record should occur within the schema. May be either -1 (indicating no upper limit) or a positive value that is not less than min

string(name, min, max)

Add a string field to the current record.

A field may not be added after a field that has variable multiplicity (min != max)

Parameters:
Name Type Argument Default Description
name String

field name. This must not the same as any field already added

min Number <optional>
1

the minimum number of times the field should occur within the record

max Number <optional>
1

the maximum number of times the field should occur within the record. May be either -1 (indicating no upper limit) or a positive value that is not less than min