Module: datamodel¶
Aliases for Ceramic stream references.
Purpose¶
The datamodel
module exports a DataModel
class for runtime interactions with a published
data model, using aliases for Ceramic stream IDs.
Installation¶
npm install @glazed/datamodel
Common use-cases¶
Get the ID of a known alias¶
import { CeramicClient } from '@ceramicnetwork/http-client'
import { DataModel } from '@glazed/datamodel'
const ceramic = new CeramicClient()
const aliases = {
schemas: {
MySchema: 'ceramic://k2...ab',
},
definitions: {
myDefinition: 'k2...ef',
},
tiles: {},
}
const model = new DataModel({ ceramic, aliases })
function getMySchemaURL() {
return model.getSchemaURL('MySchema') // 'ceramic://k2...ab'
}
function getMyDefinitionID() {
return model.getDefinitionID('myDefinition') // 'k2...ef'
}
Load a tile by alias¶
import { CeramicClient } from '@ceramicnetwork/http-client'
import { DataModel } from '@glazed/datamodel'
const ceramic = new CeramicClient()
const aliases = {
schemas: {
MySchema: 'ceramic://k2...ab',
},
definitions: {},
tiles: {
myTile: 'k2...cd',
},
}
const model = new DataModel({ ceramic, aliases })
async function loadMyTile() {
return await model.loadTile('myTile')
}
Create a tile with a schema alias¶
import { CeramicClient } from '@ceramicnetwork/http-client'
import { DataModel } from '@glazed/datamodel'
const ceramic = new CeramicClient()
const aliases = {
schemas: {
MySchema: 'ceramic://k2...ab',
},
definitions: {},
tiles: {},
}
const model = new DataModel({ ceramic, aliases })
async function createTileWithMySchema(content) {
return await model.createTile('MySchema', content)
}
Classes¶
Type aliases¶
CreateOptions¶
Ƭ CreateOptions: CreateOpts
& { controller?
: string
}
DataModelParams¶
Ƭ DataModelParams<Aliases
>: Object
Type parameters¶
Name |
---|
Aliases |
Type declaration¶
Name | Type | Description |
---|---|---|
aliases |
Aliases |
The runtime model aliases to use |
cache? |
TileCache | boolean |
TileLoader cache parameter, only used if loader is not provided |
ceramic? |
CeramicApi |
A Ceramic client instance, only used if loader is not provided |
loader? |
TileLoader |
A TileLoader instance to use, must be provided if ceramic is not provided |