Class: Builder

RecordContent. Builder

new Builder()

A builder that allows the creation of RecordContent instances with a structure defined by metadata. Use this to generate updates for use with Session.topics#update.


Constructed by calling diffusion.metadata.RecordContent#builder.

Example
// Derive a builder from a metadata instance
var builder = metadata.builder();

// Add a record with a single field value
builder.add('foo', {
     bar : "hello world"
});

// Create a content instance
var content = builder.build();

Classes

Record

Methods

add(name, fields) → {RecordContent.Builder.Record}

Add a new record with a given name. Field values can be provided as an object of key/value pairs. If the metadata allows multiple records, this will add a new record up until the maximum limit.


If the metadata this builder was created for does not support the record name or field values provided, an exception will be thrown.

If the metadata for this record specifies a maximum diffusion.metadata.RecordContent.Occurs value, then an error will be thrown if a record is added that would exceed this limit.

Parameters:
Name Type Argument Description
name String The name to add a record for
fields Object <optional>
Optional set of named fields
Throws:
An Error if the supplied arguments are invalid for this builder
Returns:
A record builder
Type
RecordContent.Builder.Record
Examples
// Add a record and get the builder reference for it
var rbuilder = builder.add('foo');
// Add a record with provided field values
var rbuilder = builder.add('bar', {
    a : "hello",
    b : 123
});
// Add a record with repeating field values
builder.add('baz', {
   repeating : ["a", "b", "c"]
});

addAndBuild(name, fields) → {RecordContent}

Convenience function for adding records and building RecordContent in a single call.

See RecordContent.Builder#add and RecordContent.Builder#build.

Parameters:
Name Type Argument Description
name String The name to add a record for
fields Object <optional>
Optional set of named fields
Throws:
An Error if the supplied arguments are invalid for this builder
Returns:
the content
Type
RecordContent
Example
builder.addAndBuild('foo', { 'bar' : 'wibble', 'baz' : 'wobble' });

build() → {RecordContent}

Create a new RecordContent with the values set by this builder. Any records and fields that are required but have not been set, will use their default metadata values.
Returns:
the content
Type
RecordContent

set(name, fields, index) → {RecordContent.Builder.Record}

Sets a specific record with a given name and index. Field values can be provided as an object of key/value pairs. Field values may be overwritten on a field by field basis.


If a record does not exist for the specified index, it will be created with the given values.

If the metadata this builder was created for does not support the record name or field values provided, an exception will be thrown.

Parameters:
Name Type Argument Default Description
name String The name to set a record for
fields Object <optional>
Optional set of named fields
index Number <optional>
0 The record index to set values for
Throws:
An Error if the supplied arguments are unsupported by the associated metadata
Returns:
A record builder
Type
RecordContent.Builder.Record
Examples
// Override the existing record
builder.set('foo');
// Set a specific field for the first record.
builder.set('bar', {
    a : "world"
}, 0);

setAndBuild(name, fields, index) → {RecordContent}

Convenience function for setting records and building RecordContent in a single call.

See RecordContent.Builder#set and RecordContent.Builder#build.

Parameters:
Name Type Argument Default Description
name String The name to set a record for
fields Object <optional>
Optional set of named fields
index Number <optional>
0 The record index to set values for
Throws:
An Error if the supplied arguments are unsupported by the associated metadata
Returns:
the content
Type
RecordContent