Skip to main content
Version: 0.4.x

Class: Composite

devtools.Composite

The Composite class provides APIs for managing composites (sets of Model streams) through their development lifecycle, including the creation of new Models, import and export of existing composites encoded as JSON, and compilation to the runtime format used by the ComposeClient class.

Composite instances are immutable, so methods affecting the contents of the internal composite definition will return new instances of the Composite class.

Composite class is exported by the devtools module.

import { Composite } from '@composedb/devtools'

Constructors

constructor

new Composite(params)

Parameters

NameType
paramsCompositeParams

Properties

VERSION

Static VERSION: string = '1.0'

Current version of the composites format.

Accessors

hash

get hash(): string

Stable hash of the internal definition, mostly used for comparisons.

Returns

string


modelIDs

get modelIDs(): string[]

StreamID of the Models used in the Composite.

Returns

string[]

Methods

copy

copy(models): Composite

Copy a given set of Models identified by their stream ID, name or alias into a new Composite.

Parameters

NameType
modelsstring[]

Returns

Composite


equals

equals(other): boolean

Check if the composite is equal to the other one provided as input.

Parameters

NameType
otherCompositeInput

Returns

boolean


merge

merge(other, options?): Composite

Merge the composite with the other one(s) into a new Composite.

Parameters

NameType
otherCompositeInput | CompositeInput[]
optionsCompositeOptions

Returns

Composite


setAliases

setAliases(aliases, replace?): Composite

Set aliases for the Models in the composite, merging with existing ones unless replace is true, and return a new Composite.

Parameters

NameTypeDefault value
aliasesRecord<string, string>undefined
replacebooleanfalse

Returns

Composite


setCommonEmbeds

setCommonEmbeds(names, replace?): Composite

Set common embeds for the Models in the composite, merging with existing ones unless replace is true, and return a new Composite.

Parameters

NameTypeDefault value
namesIterable<string>undefined
replacebooleanfalse

Returns

Composite


setViews

setViews(views, replace?): Composite

Set views for the Models in the composite, merging with existing ones unless replace is true, and return a new Composite.

Parameters

NameTypeDefault value
viewsCompositeViewsDefinitionundefined
replacebooleanfalse

Returns

Composite


startIndexingOn

startIndexingOn(ceramic): Promise<void>

Configure the Ceramic node to index the models defined in the composite. An authenticated DID set as admin in the Ceramic node configuration must be attached to the Ceramic instance.

Parameters

NameType
ceramicCeramicApi

Returns

Promise<void>


toJSON

toJSON(): EncodedCompositeDefinition

Return a JSON-encoded CompositeDefinition structure that can be shared and reused.

Returns

EncodedCompositeDefinition


toParams

toParams(): CompositeParams

Return a deep clone of the internal CompositeParams for safe external access.

Returns

CompositeParams


toRuntime

toRuntime(): RuntimeCompositeDefinition

Return a RuntimeCompositeDefinition to be used at runtime by the ComposeClient.

Returns

RuntimeCompositeDefinition


create

Static create(params): Promise<Composite>

Create new model streams based on the provided schema and group them in a composite wrapped in a Composite instance.

Parameters

NameType
paramsCreateParams

Returns

Promise<Composite>


from

Static from(composites, options?): Composite

Create a Composite instance by merging existing composites.

Parameters

NameType
compositesIterable<CompositeInput>
options?CompositeOptions

Returns

Composite


fromJSON

Static fromJSON(params): Promise<Composite>

Create a Composite instance from a JSON-encoded CompositeDefinition.

Parameters

NameType
paramsFromJSONParams

Returns

Promise<Composite>


fromModels

Static fromModels(params): Promise<Composite>

Create a Composite instance from a set of Model streams already present on a Ceramic node.

Parameters

NameType
paramsFromModelsParams

Returns

Promise<Composite>