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
): Composite
Parameters
Name | Type |
---|---|
params | CompositeParams |
Returns
Properties
VERSION
▪ Static
VERSION: string
= '1.1'
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
Name | Type |
---|---|
models | string [] |
Returns
equals
▸ equals(other
): boolean
Check if the composite is equal to the other one provided as input.
Parameters
Name | Type |
---|---|
other | CompositeInput |
Returns
boolean
merge
▸ merge(other
, options?
): Composite
Merge the composite with the other one(s) into a new Composite.
Parameters
Name | Type |
---|---|
other | CompositeInput | CompositeInput [] |
options | CompositeOptions |
Returns
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
Name | Type | Default value |
---|---|---|
aliases | Record <string , string > | undefined |
replace | boolean | false |
Returns
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
Name | Type | Default value |
---|---|---|
names | Iterable <string > | undefined |
replace | boolean | false |
Returns
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
Name | Type | Default value |
---|---|---|
views | CompositeViewsDefinition | undefined |
replace | boolean | false |
Returns
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
Name | Type |
---|---|
ceramic | CeramicApi |
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
toRuntime
▸ toRuntime(): RuntimeCompositeDefinition
Return a RuntimeCompositeDefinition
to be used at runtime by the
ComposeClient
.
Returns
RuntimeCompositeDefinition
create
▸ 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
Name | Type |
---|---|
params | CreateParams |
Returns
Promise
<Composite
>
from
▸ from(composites
, options?
): Composite
Create a Composite instance by merging existing composites.
Parameters
Name | Type |
---|---|
composites | Iterable <CompositeInput > |
options? | CompositeOptions |
Returns
fromJSON
▸ fromJSON(params
): Promise
<Composite
>
Create a Composite instance from a JSON-encoded CompositeDefinition
.
Parameters
Name | Type |
---|---|
params | FromJSONParams |
Returns
Promise
<Composite
>
fromModels
▸ fromModels(params
): Promise
<Composite
>
Create a Composite instance from a set of Model streams already present on a Ceramic node.
Parameters
Name | Type |
---|---|
params | FromModelsParams |
Returns
Promise
<Composite
>