Class: ModelManager¶
devtools.ModelManager
The ModelManager class provides APIs for managing a data model so it can be used at runtime
using the DataModel runtime.
The ModelManager class is exported by the devtools module.
import { ModelManager } from '@glazed/devtools'
Constructors¶
constructor¶
• new ModelManager(config)
Parameters¶
| Name | Type |
|---|---|
config |
ModelManagerConfig |
Accessors¶
definitions¶
• get definitions(): string[]
Stream IDs of definitions included in the model.
Returns¶
string[]
model¶
• get model(): ManagedModel<DagJWSResult>
Managed model used internally.
Returns¶
ManagedModel<DagJWSResult>
schemas¶
• get schemas(): string[]
Stream IDs of schemas included in the model.
Returns¶
string[]
tiles¶
• get tiles(): string[]
Stream IDs of tiles included in the model.
Returns¶
string[]
Methods¶
addJSONModel¶
▸ addJSONModel(encoded): void
Add a JSON-encoded managed model to the internal model
used by the instance.
Parameters¶
| Name | Type |
|---|---|
encoded |
EncodedManagedModel |
Returns¶
void
addModel¶
▸ addModel(model): void
Add a managed model to the internal model used by the instance.
Parameters¶
| Name | Type |
|---|---|
model |
ManagedModel<DagJWSResult> |
Returns¶
void
create¶
▸ create<T, Content>(type, alias, content, meta?): Promise<string>
Create a new stream of the given type and add it to the managed model.
Type parameters¶
| Name | Type |
|---|---|
T |
extends keyof CreateContentType |
Content |
CreateContentType[T] |
Parameters¶
| Name | Type |
|---|---|
type |
T |
alias |
string |
content |
Content |
meta? |
Partial<StreamMetadata> |
Returns¶
Promise<string>
createDefinition¶
▸ createDefinition(alias, definition): Promise<string>
Create a new definition stream and add it to the managed model.
Parameters¶
| Name | Type |
|---|---|
alias |
string |
definition |
Definition<Record<string, any>> |
Returns¶
Promise<string>
createSchema¶
▸ createSchema(alias, schema): Promise<string>
Create a new schema stream and add it to the managed model.
Parameters¶
| Name | Type |
|---|---|
alias |
string |
schema |
Schema<Record<string, any>> |
Returns¶
Promise<string>
createTile¶
▸ createTile<T>(alias, contents, meta?): Promise<string>
Create a new tile stream and add it to the managed model.
Type parameters¶
| Name | Type |
|---|---|
T |
extends Record<string, unknown> |
Parameters¶
| Name | Type |
|---|---|
alias |
string |
contents |
T |
meta |
Partial<StreamMetadata> |
Returns¶
Promise<string>
deploy¶
▸ deploy(): Promise<ModelData<string>>
Deploy the managed model to the Ceramic node and return the types.ModelAliases to
be used by the DataModel runtime.
Returns¶
Promise<ModelData<string>>
getDefinition¶
▸ getDefinition(id): null | ManagedEntry<DagJWSResult>
Get the definition managed entry for a given ID.
Parameters¶
| Name | Type |
|---|---|
id |
string |
Returns¶
null | ManagedEntry<DagJWSResult>
getDefinitionID¶
▸ getDefinitionID(alias): null | string
Get the ID of given definition alias, if present in the model.
Parameters¶
| Name | Type |
|---|---|
alias |
string |
Returns¶
null | string
getSchema¶
▸ getSchema(id): null | ManagedSchema<DagJWSResult>
Get the managed schema for a given ID.
Parameters¶
| Name | Type |
|---|---|
id |
string |
Returns¶
null | ManagedSchema<DagJWSResult>
getSchemaByAlias¶
▸ getSchemaByAlias(alias): null | ManagedSchema<DagJWSResult>
Get the managed schema for a given alias.
Parameters¶
| Name | Type |
|---|---|
alias |
string |
Returns¶
null | ManagedSchema<DagJWSResult>
getSchemaID¶
▸ getSchemaID(alias): null | string
Get the ID of given schema alias, if present in the model.
Parameters¶
| Name | Type |
|---|---|
alias |
string |
Returns¶
null | string
getSchemaURL¶
▸ getSchemaURL(id): null | string
Get the schema commit URL for a given ID.
Parameters¶
| Name | Type |
|---|---|
id |
string |
Returns¶
null | string
getTile¶
▸ getTile(id): null | ManagedEntry<DagJWSResult>
Get the tile managed entry for a given ID.
Parameters¶
| Name | Type |
|---|---|
id |
string |
Returns¶
null | ManagedEntry<DagJWSResult>
getTileID¶
▸ getTileID(alias): null | string
Get the ID of given tile alias, if present in the model.
Parameters¶
| Name | Type |
|---|---|
alias |
string |
Returns¶
null | string
hasDefinitionAlias¶
▸ hasDefinitionAlias(alias): boolean
Parameters¶
| Name | Type |
|---|---|
alias |
string |
Returns¶
boolean
hasSchemaAlias¶
▸ hasSchemaAlias(alias): boolean
Parameters¶
| Name | Type |
|---|---|
alias |
string |
Returns¶
boolean
hasTileAlias¶
▸ hasTileAlias(alias): boolean
Parameters¶
| Name | Type |
|---|---|
alias |
string |
Returns¶
boolean
loadCommits¶
▸ loadCommits(id): Promise<DagJWSResult[]>
Load a stream commits.
Parameters¶
| Name | Type |
|---|---|
id |
string |
Returns¶
Promise<DagJWSResult[]>
loadSchema¶
▸ loadSchema(id, alias?): Promise<string>
Load a schema stream and other schemas it depends on.
Parameters¶
| Name | Type |
|---|---|
id |
string | StreamRef |
alias? |
string |
Returns¶
Promise<string>
loadSchemaDependencies¶
▸ loadSchemaDependencies(schema): Promise<Record<string, string[]>>
Extract and load a schema's dependencies.
Parameters¶
| Name | Type |
|---|---|
schema |
Schema<Record<string, any>> |
Returns¶
Promise<Record<string, string[]>>
loadStream¶
▸ loadStream(streamID): Promise<TileDocument<Record<string, any>>>
Load a stream, ensuring it can be used in a data model.
Parameters¶
| Name | Type |
|---|---|
streamID |
string | StreamRef |
Returns¶
Promise<TileDocument<Record<string, any>>>
toJSON¶
▸ toJSON(): EncodedManagedModel
Returns the JSON-encoded managed model so it can be
easily stored, shared and reused with the fromJSON static method.
Returns¶
EncodedManagedModel
useDeployed¶
▸ useDeployed<T, ID>(type, alias, id): Promise<string>
Load an already deployed stream of the given type from the Ceramic node and add it to the managed model.
Type parameters¶
| Name | Type |
|---|---|
T |
extends keyof UseDeployedIDType |
ID |
UseDeployedIDType[T] |
Parameters¶
| Name | Type |
|---|---|
type |
T |
alias |
string |
id |
ID |
Returns¶
Promise<string>
useDeployedDefinition¶
▸ useDeployedDefinition(alias, id): Promise<string>
Load an already deployed definition stream from the Ceramic node and add it to the managed model.
Parameters¶
| Name | Type |
|---|---|
alias |
string |
id |
string | StreamID |
Returns¶
Promise<string>
useDeployedSchema¶
▸ useDeployedSchema(alias, id): Promise<string>
Load an already deployed schema stream from the Ceramic node and add it to the managed model.
Parameters¶
| Name | Type |
|---|---|
alias |
string |
id |
string | StreamRef |
Returns¶
Promise<string>
useDeployedTile¶
▸ useDeployedTile(alias, id): Promise<string>
Load an already deployed tile stream from the Ceramic node and add it to the managed model.
Parameters¶
| Name | Type |
|---|---|
alias |
string |
id |
string | StreamID |
Returns¶
Promise<string>
fromJSON¶
▸ Static fromJSON(params): ModelManager
Create a ModelManager instance from a
JSON-encoded managed model.
Parameters¶
| Name | Type |
|---|---|
params |
FromJSONParams |