blockstore-core
Version:
Contains various implementations of the API contract described in interface-blockstore
61 lines • 1.86 kB
JavaScript
import { NotFoundError } from 'interface-store';
import { BaseBlockstore } from './base.js';
// https://github.com/multiformats/multicodec/blob/d06fc6194710e8909bac64273c43f16b56ca4c34/table.csv#L2
const IDENTITY_CODEC = 0x00;
export class IdentityBlockstore extends BaseBlockstore {
child;
constructor(child) {
super();
this.child = child;
}
put(key, block, options) {
if (key.multihash.code === IDENTITY_CODEC) {
options?.signal?.throwIfAborted();
return key;
}
if (this.child == null) {
options?.signal?.throwIfAborted();
return key;
}
return this.child.put(key, block, options);
}
get(key, options) {
if (key.multihash.code === IDENTITY_CODEC) {
options?.signal?.throwIfAborted();
return key.multihash.digest;
}
if (this.child == null) {
options?.signal?.throwIfAborted();
throw new NotFoundError();
}
return this.child.get(key, options);
}
has(key, options) {
if (key.multihash.code === IDENTITY_CODEC) {
options?.signal?.throwIfAborted();
return true;
}
if (this.child == null) {
options?.signal?.throwIfAborted();
return false;
}
return this.child.has(key, options);
}
delete(key, options) {
if (key.code === IDENTITY_CODEC) {
options?.signal?.throwIfAborted();
return;
}
if (this.child != null) {
return this.child.delete(key, options);
}
}
getAll(options) {
if (this.child != null) {
return this.child.getAll(options);
}
options?.signal?.throwIfAborted();
return [];
}
}
//# sourceMappingURL=identity.js.map