@self.id/core
Version:
Read public records in Node and browsers environments
70 lines (69 loc) • 2.47 kB
JavaScript
function _checkPrivateRedeclaration(obj, privateCollection) {
if (privateCollection.has(obj)) {
throw new TypeError("Cannot initialize the same private elements twice on an object");
}
}
function _classApplyDescriptorGet(receiver, descriptor) {
if (descriptor.get) {
return descriptor.get.call(receiver);
}
return descriptor.value;
}
function _classApplyDescriptorSet(receiver, descriptor, value) {
if (descriptor.set) {
descriptor.set.call(receiver, value);
} else {
if (!descriptor.writable) {
throw new TypeError("attempted to set read only private field");
}
descriptor.value = value;
}
}
function _classExtractFieldDescriptor(receiver, privateMap, action) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to " + action + " private field on non-instance");
}
return privateMap.get(receiver);
}
function _classPrivateFieldGet(receiver, privateMap) {
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
return _classApplyDescriptorGet(receiver, descriptor);
}
function _classPrivateFieldInit(obj, privateMap, value) {
_checkPrivateRedeclaration(obj, privateMap);
privateMap.set(obj, value);
}
function _classPrivateFieldSet(receiver, privateMap, value) {
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");
_classApplyDescriptorSet(receiver, descriptor, value);
return value;
}
var _core = /*#__PURE__*/ new WeakMap(), _id = /*#__PURE__*/ new WeakMap();
/**
* 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 {
/** DID string associated to the PublicID instance. */ get id() {
return _classPrivateFieldGet(this, _id);
}
/** Load the record contents for a given definition alias. */ async get(key) {
return await _classPrivateFieldGet(this, _core).dataStore.get(key, _classPrivateFieldGet(this, _id));
}
constructor(params){
_classPrivateFieldInit(this, _core, {
writable: true,
value: void 0
});
_classPrivateFieldInit(this, _id, {
writable: true,
value: void 0
});
_classPrivateFieldSet(this, _core, params.core);
_classPrivateFieldSet(this, _id, params.id);
}
}