Class: SelfID<ModelTypes, Alias>¶
web.SelfID
A SelfID instance provides a client for an authenticated DID. Beyond loading records, it also allows to mutate them.
It is exported by the web module.
import { SelfID } from '@self.id/web'
Type parameters¶
| Name | Type |
|---|---|
ModelTypes |
extends ModelTypeAliases = CoreModelTypes |
Alias |
extends keyof ModelTypes["definitions"] = keyof ModelTypes["definitions"] |
Constructors¶
constructor¶
• new SelfID<ModelTypes, Alias>(params)
Type parameters¶
| Name | Type |
|---|---|
ModelTypes |
extends ModelTypeAliases<Record<string, any>, Record<string, string>, Record<string, string>> = ModelTypes |
Alias |
extends string | number | symbol = keyof ModelTypes["definitions"] |
Parameters¶
| Name | Type |
|---|---|
params |
SelfIDParams<ModelTypes> |
Accessors¶
client¶
• get client(): WebClient<ModelTypes>
WebClient instance used internally.
Returns¶
WebClient<ModelTypes>
did¶
• get did(): DID
DID instance used internally.
Returns¶
DID
id¶
• get id(): string
DID string associated to the SelfID instance.
Returns¶
string
Methods¶
get¶
▸ get<Key, ContentType>(key): Promise<null | ContentType>
Load the record contents for a given definition alias.
Type parameters¶
| Name | Type |
|---|---|
Key |
extends string | number | symbol |
ContentType |
DefinitionContentType<ModelTypes, Key> |
Parameters¶
| Name | Type |
|---|---|
key |
Key |
Returns¶
Promise<null | ContentType>
merge¶
▸ merge<Key, ContentType>(key, content): Promise<StreamID>
Merge the record contents for a given definition alias. If no content exists, the record will be created.
⚠️ This method only performs a shallow (one level) merge using Object.assign. For a deep merge or a specific merging strategy, you will need to implement custom logic.
Type parameters¶
| Name | Type |
|---|---|
Key |
extends string | number | symbol |
ContentType |
DefinitionContentType<ModelTypes, Key> |
Parameters¶
| Name | Type |
|---|---|
key |
Key |
content |
ContentType |
Returns¶
Promise<StreamID>
set¶
▸ set<Key, ContentType>(key, content): Promise<StreamID>
Set the record contents for a given definition alias.
⚠️ Using this method will replace any existing content. If you only want to write some
fields and leave existing ones unchanged, you can use the merge method instead.
Type parameters¶
| Name | Type |
|---|---|
Key |
extends string | number | symbol |
ContentType |
DefinitionContentType<ModelTypes, Key> |
Parameters¶
| Name | Type |
|---|---|
key |
Key |
content |
ContentType |
Returns¶
Promise<StreamID>
authenticate¶
▸ Static authenticate<ModelTypes>(params): Promise<SelfID<ModelTypes, keyof ModelTypes["definitions"]>>
Create a SelfID instance by authenticating using the given provider.
Type parameters¶
| Name | Type |
|---|---|
ModelTypes |
extends ModelTypeAliases<Record<string, any>, Record<string, string>, Record<string, string>> = ModelTypes |
Parameters¶
| Name | Type |
|---|---|
params |
AuthenticateParams<ModelTypes> |
Returns¶
Promise<SelfID<ModelTypes, keyof ModelTypes["definitions"]>>