import type { DefinitionContentType } from '@glazed/did-datastore' import type { ModelTypeAliases } from '@glazed/types' import type { ModelTypes as CoreModelTypes } from './__generated__/model.js' import type { Core } from './core.js' export type PublicIDParams = { /** {@linkcode Core} instance to use. */ core: Core /** DID string. */ id: string } /** * A PublicID instance provides a client associated to a specific DID. * * It is exported by the {@linkcode core} module. * * ```sh * import { PublicID } from '@self.id/core' * ``` */ export class PublicID< ModelTypes extends ModelTypeAliases = CoreModelTypes, Alias extends keyof ModelTypes['definitions'] = keyof ModelTypes['definitions'] > { #core: Core #id: string constructor(params: PublicIDParams) { this.#core = params.core this.#id = params.id } /** DID string associated to the PublicID instance. */ get id(): string { return this.#id } /** Load the record contents for a given definition alias. */ async get>( key: Key ): Promise { return await this.#core.dataStore.get(key, this.#id) } }