Skip to content

Commit

Permalink
fix: restore empty object default (#228)
Browse files Browse the repository at this point in the history
To make the type opt-in restore the empty object, otherwise extending
classes become very verbose.
  • Loading branch information
achingbrain committed Jun 7, 2023
1 parent 05f253f commit f82d02c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
14 changes: 10 additions & 4 deletions packages/interface-blockstore/src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -10,10 +16,10 @@ export interface Pair {
block: Uint8Array
}

export interface Blockstore <HasOptionsExtension = unknown,
PutOptionsExtension = unknown, PutManyOptionsExtension = unknown,
GetOptionsExtension = unknown, GetManyOptionsExtension = unknown, GetAllOptionsExtension = unknown,
DeleteOptionsExtension = unknown, DeleteManyOptionsExtension = unknown> extends Store<CID, Uint8Array, Pair, HasOptionsExtension,
export interface Blockstore <HasOptionsExtension = {},
PutOptionsExtension = {}, PutManyOptionsExtension = {},
GetOptionsExtension = {}, GetManyOptionsExtension = {}, GetAllOptionsExtension = {},
DeleteOptionsExtension = {}, DeleteManyOptionsExtension = {}> extends Store<CID, Uint8Array, Pair, HasOptionsExtension,
PutOptionsExtension, PutManyOptionsExtension,
GetOptionsExtension, GetManyOptionsExtension,
DeleteOptionsExtension, DeleteManyOptionsExtension> {
Expand Down
20 changes: 13 additions & 7 deletions packages/interface-datastore/src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -11,18 +17,18 @@ export interface Pair {
value: Uint8Array
}

export interface Batch<BatchOptionsExtension = unknown> {
export interface Batch<BatchOptionsExtension = {}> {
put: (key: Key, value: Uint8Array) => void
delete: (key: Key) => void
commit: (options?: AbortOptions & BatchOptionsExtension) => Await<void>
}

export interface Datastore <HasOptionsExtension = unknown,
PutOptionsExtension = unknown, PutManyOptionsExtension = unknown,
GetOptionsExtension = unknown, GetManyOptionsExtension = unknown,
DeleteOptionsExtension = unknown, DeleteManyOptionsExtension = unknown,
QueryOptionsExtension = unknown, QueryKeysOptionsExtension = unknown,
BatchOptionsExtension = unknown
export interface Datastore <HasOptionsExtension = {},
PutOptionsExtension = {}, PutManyOptionsExtension = {},
GetOptionsExtension = {}, GetManyOptionsExtension = {},
DeleteOptionsExtension = {}, DeleteManyOptionsExtension = {},
QueryOptionsExtension = {}, QueryKeysOptionsExtension = {},
BatchOptionsExtension = {}
> extends Store<Key, Uint8Array, Pair, HasOptionsExtension,
PutOptionsExtension, PutManyOptionsExtension,
GetOptionsExtension, GetManyOptionsExtension,
Expand Down
13 changes: 9 additions & 4 deletions packages/interface-store/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* 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

/**
* An iterable or async iterable of values
Expand All @@ -16,10 +21,10 @@ export interface AbortOptions {
signal?: AbortSignal
}

export interface Store<Key, Value, Pair, HasOptionsExtension = unknown,
PutOptionsExtension = unknown, PutManyOptionsExtension = unknown,
GetOptionsExtension = unknown, GetManyOptionsExtension = unknown,
DeleteOptionsExtension = unknown, DeleteManyOptionsExtension = unknown> {
export interface Store<Key, Value, Pair, HasOptionsExtension = {},
PutOptionsExtension = {}, PutManyOptionsExtension = {},
GetOptionsExtension = {}, GetManyOptionsExtension = {},
DeleteOptionsExtension = {}, DeleteManyOptionsExtension = {}> {
/**
* Check for the existence of a value for the passed key
*
Expand Down

0 comments on commit f82d02c

Please sign in to comment.