From f82d02cc8742b595939b58e2eae0a86bb1cec6b1 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 7 Jun 2023 07:33:25 +0100 Subject: [PATCH] fix: restore empty object default (#228) To make the type opt-in restore the empty object, otherwise extending classes become very verbose. --- packages/interface-blockstore/src/index.ts | 14 ++++++++++---- packages/interface-datastore/src/index.ts | 20 +++++++++++++------- packages/interface-store/src/index.ts | 13 +++++++++---- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/packages/interface-blockstore/src/index.ts b/packages/interface-blockstore/src/index.ts index eedf1e84..68662013 100644 --- a/packages/interface-blockstore/src/index.ts +++ b/packages/interface-blockstore/src/index.ts @@ -1,3 +1,9 @@ +/* eslint-disable @typescript-eslint/ban-types */ +// this ignore is so we can use {} as the default value for the options +// extensions below - it normally means "any non-nullish value" but here +// we are using it as an intersection type - see the aside at the bottom: +// https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492 + import type { AbortOptions, AwaitIterable, @@ -10,10 +16,10 @@ export interface Pair { block: Uint8Array } -export interface Blockstore extends Store extends Store { diff --git a/packages/interface-datastore/src/index.ts b/packages/interface-datastore/src/index.ts index 91cc7f4b..251495c3 100644 --- a/packages/interface-datastore/src/index.ts +++ b/packages/interface-datastore/src/index.ts @@ -1,3 +1,9 @@ +/* eslint-disable @typescript-eslint/ban-types */ +// this ignore is so we can use {} as the default value for the options +// extensions below - it normally means "any non-nullish value" but here +// we are using it as an intersection type - see the aside at the bottom: +// https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492 + import { Key } from './key.js' import type { Await, @@ -11,18 +17,18 @@ export interface Pair { value: Uint8Array } -export interface Batch { +export interface Batch { put: (key: Key, value: Uint8Array) => void delete: (key: Key) => void commit: (options?: AbortOptions & BatchOptionsExtension) => Await } -export interface Datastore extends Store { +export interface Store { /** * Check for the existence of a value for the passed key *