interface-store
Advanced tools
Comparing version 3.0.4 to 4.0.0
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.InterfaceStore = factory()}(typeof self !== 'undefined' ? self : this, function () { | ||
"use strict";var InterfaceStore=(()=>{var i=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var n=Object.prototype.hasOwnProperty;var s=(r,e,o,y)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of l(e))!n.call(r,t)&&t!==o&&i(r,t,{get:()=>e[t],enumerable:!(y=a(e,t))||y.enumerable});return r};var u=r=>s(i({},"__esModule",{value:!0}),r);var K={};return u(K);})(); | ||
"use strict";var InterfaceStore=(()=>{var o=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var l=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of p(e))!s.call(t,a)&&a!==n&&o(t,a,{get:()=>e[a],enumerable:!(i=r(e,a))||i.enumerable});return t};var y=t=>l(o({},"__esModule",{value:!0}),t);var A={};return y(A);})(); | ||
return InterfaceStore})); |
export type AwaitIterable<T> = Iterable<T> | AsyncIterable<T>; | ||
export type Await<T> = Promise<T> | T; | ||
export interface Pair<Key, Value> { | ||
key: Key; | ||
value: Value; | ||
} | ||
/** | ||
@@ -13,32 +9,4 @@ * Options for async operations. | ||
} | ||
export interface Batch<Key, Value> { | ||
put: (key: Key, value: Value) => void; | ||
delete: (key: Key) => void; | ||
commit: (options?: Options) => Promise<void>; | ||
} | ||
export interface Store<Key, Value> { | ||
open: () => Promise<void>; | ||
close: () => Promise<void>; | ||
export interface Store<Key, Value, Pair> { | ||
/** | ||
* Store the passed value under the passed key | ||
* | ||
* @example | ||
* | ||
* ```js | ||
* await store.put([{ key: new Key('awesome'), value: new Uint8Array([0, 1, 2, 3]) }]) | ||
* ``` | ||
*/ | ||
put: (key: Key, val: Value, options?: Options) => Promise<void>; | ||
/** | ||
* Retrieve the value stored under the given key | ||
* | ||
* @example | ||
* ```js | ||
* const value = await store.get(new Key('awesome')) | ||
* console.log('got content: %s', value.toString('utf8')) | ||
* // => got content: datastore | ||
* ``` | ||
*/ | ||
get: (key: Key, options?: Options) => Promise<Value>; | ||
/** | ||
* Check for the existence of a value for the passed key | ||
@@ -57,5 +25,5 @@ * | ||
*/ | ||
has: (key: Key, options?: Options) => Promise<boolean>; | ||
has: (key: Key, options?: Options) => Await<boolean>; | ||
/** | ||
* Remove the record for the passed key | ||
* Store the passed value under the passed key | ||
* | ||
@@ -65,7 +33,6 @@ * @example | ||
* ```js | ||
* await store.delete(new Key('awesome')) | ||
* console.log('deleted awesome content :(') | ||
* await store.put([{ key: new Key('awesome'), value: new Uint8Array([0, 1, 2, 3]) }]) | ||
* ``` | ||
*/ | ||
delete: (key: Key, options?: Options) => Promise<void>; | ||
put: (key: Key, val: Value, options?: Options) => Await<void>; | ||
/** | ||
@@ -83,4 +50,15 @@ * Store the given key/value pairs | ||
*/ | ||
putMany: (source: AwaitIterable<Pair<Key, Value>>, options?: Options) => AsyncIterable<Pair<Key, Value>>; | ||
putMany: (source: AwaitIterable<Pair>, options?: Options) => AwaitIterable<Pair>; | ||
/** | ||
* Retrieve the value stored under the given key | ||
* | ||
* @example | ||
* ```js | ||
* const value = await store.get(new Key('awesome')) | ||
* console.log('got content: %s', value.toString('utf8')) | ||
* // => got content: datastore | ||
* ``` | ||
*/ | ||
get: (key: Key, options?: Options) => Await<Value>; | ||
/** | ||
* Retrieve values for the passed keys | ||
@@ -96,5 +74,5 @@ * | ||
*/ | ||
getMany: (source: AwaitIterable<Key>, options?: Options) => AsyncIterable<Value>; | ||
getMany: (source: AwaitIterable<Key>, options?: Options) => AwaitIterable<Value>; | ||
/** | ||
* Remove values for the passed keys | ||
* Remove the record for the passed key | ||
* | ||
@@ -104,81 +82,22 @@ * @example | ||
* ```js | ||
* const source = [new Key('awesome')] | ||
* | ||
* for await (const key of store.deleteMany(source)) { | ||
* console.log(`deleted content with key ${key}`) | ||
* } | ||
* await store.delete(new Key('awesome')) | ||
* console.log('deleted awesome content :(') | ||
* ``` | ||
*/ | ||
deleteMany: (source: AwaitIterable<Key>, options?: Options) => AsyncIterable<Key>; | ||
delete: (key: Key, options?: Options) => Await<void>; | ||
/** | ||
* This will return an object with which you can chain multiple operations together, with them only being executed on calling `commit`. | ||
* Remove values for the passed keys | ||
* | ||
* @example | ||
* ```js | ||
* const b = store.batch() | ||
* | ||
* for (let i = 0; i < 100; i++) { | ||
* b.put(new Key(`hello${i}`), new TextEncoder('utf8').encode(`hello world ${i}`)) | ||
* } | ||
* | ||
* await b.commit() | ||
* console.log('put 100 values') | ||
* ``` | ||
*/ | ||
batch: () => Batch<Key, Value>; | ||
/** | ||
* Query the store. | ||
* | ||
* @example | ||
* ```js | ||
* // retrieve __all__ key/value pairs from the store | ||
* let list = [] | ||
* for await (const { key, value } of store.query({})) { | ||
* list.push(value) | ||
* } | ||
* console.log('ALL THE VALUES', list) | ||
* ``` | ||
*/ | ||
query: (query: Query<Key, Value>, options?: Options) => AsyncIterable<Pair<Key, Value>>; | ||
/** | ||
* Query the store. | ||
* const source = [new Key('awesome')] | ||
* | ||
* @example | ||
* ```js | ||
* // retrieve __all__ keys from the store | ||
* let list = [] | ||
* for await (const key of store.queryKeys({})) { | ||
* list.push(key) | ||
* for await (const key of store.deleteMany(source)) { | ||
* console.log(`deleted content with key ${key}`) | ||
* } | ||
* console.log('ALL THE KEYS', key) | ||
* ``` | ||
*/ | ||
queryKeys: (query: KeyQuery<Key>, options?: Options) => AsyncIterable<Key>; | ||
deleteMany: (source: AwaitIterable<Key>, options?: Options) => AwaitIterable<Key>; | ||
} | ||
export interface QueryFilter<Key, Value> { | ||
(item: Pair<Key, Value>): boolean; | ||
} | ||
export interface QueryOrder<Key, Value> { | ||
(a: Pair<Key, Value>, b: Pair<Key, Value>): -1 | 0 | 1; | ||
} | ||
export interface Query<Key, Value> { | ||
prefix?: string; | ||
filters?: Array<QueryFilter<Key, Value>>; | ||
orders?: Array<QueryOrder<Key, Value>>; | ||
limit?: number; | ||
offset?: number; | ||
} | ||
export interface KeyQueryFilter<Key> { | ||
(item: Key): boolean; | ||
} | ||
export interface KeyQueryOrder<Key> { | ||
(a: Key, b: Key): -1 | 0 | 1; | ||
} | ||
export interface KeyQuery<Key> { | ||
prefix?: string; | ||
filters?: Array<KeyQueryFilter<Key>>; | ||
orders?: Array<KeyQueryOrder<Key>>; | ||
limit?: number; | ||
offset?: number; | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"Batch": "https://ipfs.github.io/js-ipfs-interfaces/interfaces/interface_blockstore._internal_.Batch.html", | ||
"KeyQuery": "https://ipfs.github.io/js-ipfs-interfaces/interfaces/interface_blockstore._internal_.KeyQuery.html", | ||
"KeyQueryFilter": "https://ipfs.github.io/js-ipfs-interfaces/interfaces/interface_blockstore._internal_.KeyQueryFilter.html", | ||
"KeyQueryOrder": "https://ipfs.github.io/js-ipfs-interfaces/interfaces/interface_blockstore._internal_.KeyQueryOrder.html", | ||
"Options": "https://ipfs.github.io/js-ipfs-interfaces/interfaces/interface_blockstore._internal_.Options.html", | ||
"Pair": "https://ipfs.github.io/js-ipfs-interfaces/interfaces/interface_blockstore._internal_.Pair.html", | ||
"Query": "https://ipfs.github.io/js-ipfs-interfaces/interfaces/interface_blockstore._internal_.Query.html", | ||
"QueryFilter": "https://ipfs.github.io/js-ipfs-interfaces/interfaces/interface_blockstore._internal_.QueryFilter.html", | ||
"QueryOrder": "https://ipfs.github.io/js-ipfs-interfaces/interfaces/interface_blockstore._internal_.QueryOrder.html", | ||
"Store": "https://ipfs.github.io/js-ipfs-interfaces/interfaces/interface_blockstore._internal_.Store.html", | ||
"AwaitIterable": "https://ipfs.github.io/js-ipfs-interfaces/types/interface_blockstore._internal_.AwaitIterable.html", | ||
"Await": "https://ipfs.github.io/js-ipfs-interfaces/types/interface_store.Await.html" | ||
"Await": "https://ipfs.github.io/js-ipfs-interfaces/types/interface_blockstore._internal_.Await.html", | ||
"AwaitIterable": "https://ipfs.github.io/js-ipfs-interfaces/types/interface_blockstore._internal_.AwaitIterable.html" | ||
} |
{ | ||
"name": "interface-store", | ||
"version": "3.0.4", | ||
"version": "4.0.0", | ||
"description": "A generic interface for storing and retrieving data", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0 OR MIT", |
147
src/index.ts
@@ -5,7 +5,2 @@ | ||
export interface Pair<Key, Value> { | ||
key: Key | ||
value: Value | ||
} | ||
/** | ||
@@ -18,36 +13,4 @@ * Options for async operations. | ||
export interface Batch<Key, Value> { | ||
put: (key: Key, value: Value) => void | ||
delete: (key: Key) => void | ||
commit: (options?: Options) => Promise<void> | ||
} | ||
export interface Store<Key, Value> { | ||
open: () => Promise<void> | ||
close: () => Promise<void> | ||
export interface Store<Key, Value, Pair> { | ||
/** | ||
* Store the passed value under the passed key | ||
* | ||
* @example | ||
* | ||
* ```js | ||
* await store.put([{ key: new Key('awesome'), value: new Uint8Array([0, 1, 2, 3]) }]) | ||
* ``` | ||
*/ | ||
put: (key: Key, val: Value, options?: Options) => Promise<void> | ||
/** | ||
* Retrieve the value stored under the given key | ||
* | ||
* @example | ||
* ```js | ||
* const value = await store.get(new Key('awesome')) | ||
* console.log('got content: %s', value.toString('utf8')) | ||
* // => got content: datastore | ||
* ``` | ||
*/ | ||
get: (key: Key, options?: Options) => Promise<Value> | ||
/** | ||
* Check for the existence of a value for the passed key | ||
@@ -66,6 +29,6 @@ * | ||
*/ | ||
has: (key: Key, options?: Options) => Promise<boolean> | ||
has: (key: Key, options?: Options) => Await<boolean> | ||
/** | ||
* Remove the record for the passed key | ||
* Store the passed value under the passed key | ||
* | ||
@@ -75,7 +38,6 @@ * @example | ||
* ```js | ||
* await store.delete(new Key('awesome')) | ||
* console.log('deleted awesome content :(') | ||
* await store.put([{ key: new Key('awesome'), value: new Uint8Array([0, 1, 2, 3]) }]) | ||
* ``` | ||
*/ | ||
delete: (key: Key, options?: Options) => Promise<void> | ||
put: (key: Key, val: Value, options?: Options) => Await<void> | ||
@@ -95,7 +57,19 @@ /** | ||
putMany: ( | ||
source: AwaitIterable<Pair<Key, Value>>, | ||
source: AwaitIterable<Pair>, | ||
options?: Options | ||
) => AsyncIterable<Pair<Key, Value>> | ||
) => AwaitIterable<Pair> | ||
/** | ||
* Retrieve the value stored under the given key | ||
* | ||
* @example | ||
* ```js | ||
* const value = await store.get(new Key('awesome')) | ||
* console.log('got content: %s', value.toString('utf8')) | ||
* // => got content: datastore | ||
* ``` | ||
*/ | ||
get: (key: Key, options?: Options) => Await<Value> | ||
/** | ||
* Retrieve values for the passed keys | ||
@@ -114,6 +88,6 @@ * | ||
options?: Options | ||
) => AsyncIterable<Value> | ||
) => AwaitIterable<Value> | ||
/** | ||
* Remove values for the passed keys | ||
* Remove the record for the passed key | ||
* | ||
@@ -123,82 +97,25 @@ * @example | ||
* ```js | ||
* const source = [new Key('awesome')] | ||
* | ||
* for await (const key of store.deleteMany(source)) { | ||
* console.log(`deleted content with key ${key}`) | ||
* } | ||
* await store.delete(new Key('awesome')) | ||
* console.log('deleted awesome content :(') | ||
* ``` | ||
*/ | ||
deleteMany: ( | ||
source: AwaitIterable<Key>, | ||
options?: Options | ||
) => AsyncIterable<Key> | ||
delete: (key: Key, options?: Options) => Await<void> | ||
/** | ||
* This will return an object with which you can chain multiple operations together, with them only being executed on calling `commit`. | ||
* Remove values for the passed keys | ||
* | ||
* @example | ||
* ```js | ||
* const b = store.batch() | ||
* | ||
* for (let i = 0; i < 100; i++) { | ||
* b.put(new Key(`hello${i}`), new TextEncoder('utf8').encode(`hello world ${i}`)) | ||
* } | ||
* | ||
* await b.commit() | ||
* console.log('put 100 values') | ||
* ``` | ||
*/ | ||
batch: () => Batch<Key, Value> | ||
/** | ||
* Query the store. | ||
* | ||
* @example | ||
* ```js | ||
* // retrieve __all__ key/value pairs from the store | ||
* let list = [] | ||
* for await (const { key, value } of store.query({})) { | ||
* list.push(value) | ||
* } | ||
* console.log('ALL THE VALUES', list) | ||
* ``` | ||
*/ | ||
query: (query: Query<Key, Value>, options?: Options) => AsyncIterable<Pair<Key, Value>> | ||
/** | ||
* Query the store. | ||
* const source = [new Key('awesome')] | ||
* | ||
* @example | ||
* ```js | ||
* // retrieve __all__ keys from the store | ||
* let list = [] | ||
* for await (const key of store.queryKeys({})) { | ||
* list.push(key) | ||
* for await (const key of store.deleteMany(source)) { | ||
* console.log(`deleted content with key ${key}`) | ||
* } | ||
* console.log('ALL THE KEYS', key) | ||
* ``` | ||
*/ | ||
queryKeys: (query: KeyQuery<Key>, options?: Options) => AsyncIterable<Key> | ||
deleteMany: ( | ||
source: AwaitIterable<Key>, | ||
options?: Options | ||
) => AwaitIterable<Key> | ||
} | ||
export interface QueryFilter<Key, Value> { (item: Pair<Key, Value>): boolean } | ||
export interface QueryOrder<Key, Value> { (a: Pair<Key, Value>, b: Pair<Key, Value>): -1 | 0 | 1 } | ||
export interface Query<Key, Value> { | ||
prefix?: string | ||
filters?: Array<QueryFilter<Key, Value>> | ||
orders?: Array<QueryOrder<Key, Value>> | ||
limit?: number | ||
offset?: number | ||
} | ||
export interface KeyQueryFilter<Key> { (item: Key): boolean } | ||
export interface KeyQueryOrder<Key> { (a: Key, b: Key): -1 | 0 | 1 } | ||
export interface KeyQuery<Key> { | ||
prefix?: string | ||
filters?: Array<KeyQueryFilter<Key>> | ||
orders?: Array<KeyQueryOrder<Key>> | ||
limit?: number | ||
offset?: number | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41395
210