UNPKG

@self.id/core

Version:

Read public records in Node and browsers environments

68 lines (67 loc) 2.88 kB
import { CeramicClient } from '@ceramicnetwork/http-client'; import { DataModel } from '@glazed/datamodel'; import { DIDDataStore } from '@glazed/did-datastore'; import type { DefinitionContentType } from '@glazed/did-datastore'; import { TileLoader } from '@glazed/tile-loader'; import type { TileCache } from '@glazed/tile-loader'; import type { ModelTypeAliases, ModelTypesToAliases } from '@glazed/types'; import { Resolver } from 'did-resolver'; import type { CeramicNetwork, CoreModelTypes } from './types.js'; /** @internal */ export declare const CERAMIC_URLS: Record<CeramicNetwork, string>; export declare type CoreParams<ModelTypes extends ModelTypeAliases = CoreModelTypes> = { /** Data model aliases to use instead of the default ones. */ aliases?: ModelTypesToAliases<ModelTypes>; /** * Cache interface to use or `true` to use a default cache. If `false` or undefined (default), * no cache is used. */ cache?: TileCache | boolean; /** Predefined {@linkcode CeramicNetwork} configuration value of Ceramic server URL. */ ceramic: CeramicNetwork | string; /** Tile loader instance to use. If provided, the `cache` parameter will be ignored. */ loader?: TileLoader; }; /** * Core client for the Self.ID SDK, exported by the {@linkcode core} module. * * ```sh * import { Core } from '@self.id/core' * ``` */ export declare class Core<ModelTypes extends ModelTypeAliases = CoreModelTypes, Alias extends keyof ModelTypes['definitions'] = keyof ModelTypes['definitions']> { #private; /** @internal */ _ceramic: CeramicClient; /** @internal */ _dataStore: DIDDataStore<ModelTypes>; constructor(params: CoreParams<ModelTypes>); /** Ceramic HTTP Client instance used internally. */ get ceramic(): CeramicClient; /** DataModel runtime instance used internally. */ get dataModel(): DataModel<ModelTypes>; /** DID DataStore instance used internally. */ get dataStore(): DIDDataStore<ModelTypes>; /** DID resolver instance used internally. */ get resolver(): Resolver; /** Tile loader instance used internally. */ get tileLoader(): TileLoader; /** * Load the DID string for a given CAIP-10 account using a CAIP-10 link, or throw an error if * not linked. */ getAccountDID(account: string): Promise<string>; /** * Turn a DID or CAIP-10 string into a DID string. * * If the input is a DID string, it will be returned as-is, otherwise * {@linkcode getAccountDID} will be used. */ toDID(accountOrDID: string): Promise<string>; /** * Load the record content for a given definition alias and account. * * Uses {@linkcode toDID} to resolve the account. */ get<Key extends Alias, ContentType = DefinitionContentType<ModelTypes, Key>>(key: Key, id: string): Promise<ContentType | null>; }