@unikvs/allow-repair
Middleware that controls whether read-time repair writes are allowed.
Overview
@unikvs/allow-repair is a plugin that allows or denies read-time repair writes.Middleware
It extends PassThrough and passes data through without conversion. Use it to temporarily stop repair writes to earlier storages in a multi-storage setup.
nameisAllowRepair.isOpenis alwaystrue.open()is unnecessary.- Repair is allowed initially.
disable()switches to denying.
Install with:
npm install @unikvs/allow-repairpnpm add @unikvs/allow-repairyarn add @unikvs/allow-repairbun add @unikvs/allow-repairnub add @unikvs/allow-repairaube add @unikvs/allow-repairUsage
AllowRepair implements IMiddleware. Pass it to UniKvs with use().
import { AllowRepair } from "@unikvs/allow-repair";
The following reads with repair denied, then re-reads after allowing it:
import { AllowRepair } from "@unikvs/allow-repair";
import { Memory } from "@unikvs/memory";
import * as unikvs from "unikvs";
const gate = new AllowRepair();
const kvs = new unikvs.Builder<{ foo: unikvs.Value<Uint8Array> }>()
.use(gate)
.persist(new Memory())
.build();
await kvs.open();
await kvs.set("foo", new Uint8Array([0, 1, 2]));
gate.disable();
try {
await kvs.get("foo", { repair: true });
} catch {
console.log("repair was denied");
}
gate.enable();
const bytes = await kvs.get("foo", { repair: true });
console.log(bytes); // Uint8Array(3) [0, 1, 2]
await kvs.close();
Data types
| Method | Input | Output |
|---|---|---|
encode |
TData |
TData |
decode |
TData |
TData |
encodeStream |
TChunk |
TChunk |
decodeStream |
TChunk |
TChunk |
encodeoutputs the input data unchanged.decodeoutputs the input data unchanged.encodeStreamoutputs the input stream unchanged.decodeStreamoutputs the input stream unchanged.useonly decides repair eligibility forgetandstream; it never changes data.
Errors
This package has no package-specific errors.
use() throws RepairNotAllowedError when repair is denied. It never throws when enabled is true or when the read has repair disabled.