/ packages / store / abstract.ts
abstract.ts
 1  /** The interface for a store that is used to store and retrieve blocks */
 2  export abstract class AbstractStore {
 3    abstract get(key: Uint8Array): Promise<Uint8Array | undefined>;
 4    abstract set(key: Uint8Array, value: Uint8Array): Promise<void>;
 5    async append(key: Uint8Array, value: Uint8Array): Promise<void> {
 6      const existingValue = await this.get(key);
 7      if (existingValue) {
 8        return this.set(key, new Uint8Array([...existingValue, ...value]));
 9      } else {
10        return this.set(key, value);
11      }
12    }
13  }
14  
15  export type AbstractStoreConstructor = new (
16    ...params: ConstructorParameters<typeof AbstractStore>
17  ) => AbstractStore;