@ceramic-sdk/model-client v0.2.1 • Docs
Ceramic SDK / @ceramic-sdk/model-client / ModelClient
Represents a client for interacting with Ceramic models.
The ModelClient class extends the StreamClient class to provide additional
methods specific to working with Ceramic models, including fetching and creating
model definitions, retrieving initialization events, and decoding stream data.
new ModelClient(
params):ModelClient
Creates a new instance of StreamClient.
• params: StreamClientParams
Configuration object containing parameters for initializing the StreamClient.
getceramic():CeramicClient
Retrieves the Ceramic HTTP client instance used to interact with the Ceramic server.
This client is essential for executing API requests to fetch stream data.
The CeramicClient instance associated with this StreamClient.
createDefinition(
definition,signer?):Promise<StreamID>
Creates a model definition and returns the resulting stream ID.
• definition: MapIn<RequiredProps<object>, $TypeOf> & MapIn<OptionalProps<object>, $TypeOf> | MapIn<RequiredProps<object>, $TypeOf> & MapIn<OptionalProps<object>, $TypeOf>
The model JSON definition to post.
• signer?: DID
(Optional) A DID instance for signing the model definition.
Promise<StreamID>
A promise that resolves to the StreamID of the posted model.
Will throw an error if the definition is invalid or the signing process fails.
getDID(
provided?):DID
Retrieves a Decentralized Identifier (DID).
This method provides access to a DID, which is required for authentication or event signing operations. The caller can optionally provide a DID; if none is provided, the instance's DID is used instead.
• provided?: DID
An optional DID object to use. If not supplied, the instance's DID is returned.
DID
The DID object, either provided or attached to the instance.
Will throw an error if neither a provided DID nor an instance DID is available.
const did = client.getDID();
console.log(did.id); // Outputs the DID identifiergetDocumentModel(
streamID):Promise<string>
Retrieves the stringified model stream ID from a model instance document stream ID.
• streamID: string | StreamID
The document stream ID, either as a StreamID object or string.
Promise<string>
A promise that resolves to the stringified model stream ID.
Will throw an error if the stream ID or its state is invalid.
getInitEvent(
streamID):Promise<MapIn<RequiredProps<object>,$TypeOf> &MapIn<OptionalProps<object>,$TypeOf>>
Retrieves the signed initialization event of a model based on its stream ID.
• streamID: string | StreamID
The stream ID of the model, either as a StreamID object or string.
Promise<MapIn<RequiredProps<object>, $TypeOf> & MapIn<OptionalProps<object>, $TypeOf>>
A promise that resolves to the SignedEvent for the model.
Will throw an error if the stream ID is invalid or the request fails.
getModelDefinition(
streamID):Promise<MapIn<RequiredProps<object>,$TypeOf> &MapIn<OptionalProps<object>,$TypeOf> |MapIn<RequiredProps<object>,$TypeOf> &MapIn<OptionalProps<object>,$TypeOf>>
Retrieves a model's JSON definition based on the model's stream ID.
• streamID: string | StreamID
The stream ID of the model, either as a StreamID object or string.
Promise<MapIn<RequiredProps<object>, $TypeOf> & MapIn<OptionalProps<object>, $TypeOf> | MapIn<RequiredProps<object>, $TypeOf> & MapIn<OptionalProps<object>, $TypeOf>>
A promise that resolves to the ModelDefinition for the specified model.
Will throw an error if the stream ID is invalid or the data cannot be decoded.
getPayload(
streamID,verifier?):Promise<MapIn<object,$TypeOf>>
Retrieves the payload of the initialization event for a model based on its stream ID.
• streamID: string | StreamID
The stream ID of the model, either as a StreamID object or string.
• verifier?: DID
(Optional) A DID instance for verifying the event payload.
Promise<MapIn<object, $TypeOf>>
A promise that resolves to the ModelInitEventPayload.
Will throw an error if the event or payload is invalid or verification fails.
getStreamState(
streamId):Promise<StreamState>
Fetches the current stream state of a specific stream by its ID.
This method interacts with the Ceramic HTTP API to retrieve the state of a stream.
The stream ID can either be a multibase-encoded string or a StreamID object.
• streamId: string | StreamID
The unique identifier of the stream to fetch.
- Can be a multibase-encoded string or a
StreamIDobject.
Promise<StreamState>
A Promise that resolves to the StreamState object, representing the current state of the stream.
Will throw an error if the API request fails or returns an error response (if stream is not found).
const streamState = await client.getStreamState('kjzl6cwe1...');
console.log(streamState);