From e3e73df19d543afd98bfbf4cbb76537979bd1a3b Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 14 May 2021 12:12:58 +0100 Subject: [PATCH] chore: initial commit --- .gitignore | 3 + .npmrc | 1 + LICENSE-APACHE | 5 + LICENSE-MIT | 19 ++ README.md | 25 +++ lerna.json | 21 ++ package.json | 29 +++ packages/interface-blockstore/LICENSE-APACHE | 5 + packages/interface-blockstore/LICENSE-MIT | 19 ++ packages/interface-blockstore/README.md | 20 ++ packages/interface-blockstore/package.json | 26 +++ packages/interface-blockstore/src/index.d.ts | 10 + packages/interface-blockstore/src/index.js | 0 packages/interface-blockstore/tsconfig.json | 11 ++ packages/interface-store/LICENSE-APACHE | 5 + packages/interface-store/LICENSE-MIT | 19 ++ packages/interface-store/README.md | 20 ++ packages/interface-store/package.json | 22 +++ packages/interface-store/src/index.d.ts | 197 +++++++++++++++++++ packages/interface-store/src/index.js | 0 packages/interface-store/tsconfig.json | 11 ++ 21 files changed, 468 insertions(+) create mode 100644 .gitignore create mode 100644 .npmrc create mode 100644 LICENSE-APACHE create mode 100644 LICENSE-MIT create mode 100644 README.md create mode 100644 lerna.json create mode 100644 package.json create mode 100644 packages/interface-blockstore/LICENSE-APACHE create mode 100644 packages/interface-blockstore/LICENSE-MIT create mode 100644 packages/interface-blockstore/README.md create mode 100644 packages/interface-blockstore/package.json create mode 100644 packages/interface-blockstore/src/index.d.ts create mode 100644 packages/interface-blockstore/src/index.js create mode 100644 packages/interface-blockstore/tsconfig.json create mode 100644 packages/interface-store/LICENSE-APACHE create mode 100644 packages/interface-store/LICENSE-MIT create mode 100644 packages/interface-store/README.md create mode 100644 packages/interface-store/package.json create mode 100644 packages/interface-store/src/index.d.ts create mode 100644 packages/interface-store/src/index.js create mode 100644 packages/interface-store/tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..91a3983f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +dist +node_modules +package-lock.json diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..c42da845 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +engine-strict = true diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 00000000..14478a3b --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,5 @@ +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 00000000..749aa1ec --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,19 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 00000000..83fc280b --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# ipfs-interfaces + +> TypeScript interfaces used by IPFS internals + +## Table of Contents + +- [Packages](#packages) +- [Contribute](#contribute) +- [License](#license) + +## Packages + +See the [./packages](./packages) directory for the various interfaces. + +## Contribute + +Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfs-bitswap/issues)! + +This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). + +[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) + +## License + +[MIT](LICENSE) diff --git a/lerna.json b/lerna.json new file mode 100644 index 00000000..ea7a56de --- /dev/null +++ b/lerna.json @@ -0,0 +1,21 @@ +{ + "lerna": "3.22.0", + "packages": [ + "packages/*" + ], + "version": "independent", + "command": { + "run": { + "stream": true + }, + "publish": { + "message": "chore: publish", + "createRelease": "github", + "conventionalCommits": true, + "verifyAccess": false + }, + "version": { + "private": false + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..4e6ddb24 --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "name": "ipfs-interfaces", + "version": "1.0.0", + "description": "", + "main": "index.js", + "private": true, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "build": "lerna run build", + "lint": "lerna run lint", + "release": "lerna publish" + }, + "homepage": "https://github.com/ipfs/js-ipfs-interfaces/tree/master#readme", + "bugs": "https://github.com/ipfs/js-ipfs-interfaces/issues", + "license": "(Apache-2.0 OR MIT)", + "repository": { + "type": "git", + "url": "git+https://github.com/ipfs/js-ipfs-interfaces.git" + }, + "workspaces": [ + "packages/*" + ], + "dependencies": { + "lerna": "^4.0.0" + }, + "engines": { + "npm": ">=7.0.0" + } +} diff --git a/packages/interface-blockstore/LICENSE-APACHE b/packages/interface-blockstore/LICENSE-APACHE new file mode 100644 index 00000000..14478a3b --- /dev/null +++ b/packages/interface-blockstore/LICENSE-APACHE @@ -0,0 +1,5 @@ +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/packages/interface-blockstore/LICENSE-MIT b/packages/interface-blockstore/LICENSE-MIT new file mode 100644 index 00000000..749aa1ec --- /dev/null +++ b/packages/interface-blockstore/LICENSE-MIT @@ -0,0 +1,19 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/packages/interface-blockstore/README.md b/packages/interface-blockstore/README.md new file mode 100644 index 00000000..923d44a6 --- /dev/null +++ b/packages/interface-blockstore/README.md @@ -0,0 +1,20 @@ +# interface-blockstore + +> An interface for storing and retrieving blocks + +## Table of Contents + +- [Contribute](#contribute) +- [License](#license) + +## Contribute + +Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfs-bitswap/issues)! + +This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). + +[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) + +## License + +[MIT](LICENSE) diff --git a/packages/interface-blockstore/package.json b/packages/interface-blockstore/package.json new file mode 100644 index 00000000..17a9fe55 --- /dev/null +++ b/packages/interface-blockstore/package.json @@ -0,0 +1,26 @@ +{ + "name": "interface-blockstore", + "version": "0.0.1", + "description": "", + "main": "src/index.js", + "types": "dist/src/index.d.ts", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "lint": "aegir ts -p check && aegir lint", + "build": "aegir build" + }, + "license": "(Apache-2.0 OR MIT)", + "homepage": "https://github.com/ipfs/js-ipfs-interfaces/tree/master/packages/interface-blockstore#readme", + "bugs": "https://github.com/ipfs/js-ipfs-interfaces/issues", + "repository": { + "type": "git", + "url": "git+https://github.com/ipfs/js-ipfs-interfaces.git" + }, + "dependencies": { + "interface-store": "^0.0.1", + "multiformats": "^8.0.4" + }, + "devDependencies": { + "aegir": "^33.1.2" + } +} diff --git a/packages/interface-blockstore/src/index.d.ts b/packages/interface-blockstore/src/index.d.ts new file mode 100644 index 00000000..f1a6040a --- /dev/null +++ b/packages/interface-blockstore/src/index.d.ts @@ -0,0 +1,10 @@ +import { + Pair as StorePair +} from 'interface-store' +import { + CID +} from 'multiformats' + +export interface Pair extends StorePair { + +} \ No newline at end of file diff --git a/packages/interface-blockstore/src/index.js b/packages/interface-blockstore/src/index.js new file mode 100644 index 00000000..e69de29b diff --git a/packages/interface-blockstore/tsconfig.json b/packages/interface-blockstore/tsconfig.json new file mode 100644 index 00000000..3865f348 --- /dev/null +++ b/packages/interface-blockstore/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "aegir/src/config/tsconfig.aegir.json", + "compilerOptions": { + "outDir": "dist", + "skipLibCheck": false + }, + "include": [ + "test", + "src" + ] +} diff --git a/packages/interface-store/LICENSE-APACHE b/packages/interface-store/LICENSE-APACHE new file mode 100644 index 00000000..14478a3b --- /dev/null +++ b/packages/interface-store/LICENSE-APACHE @@ -0,0 +1,5 @@ +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/packages/interface-store/LICENSE-MIT b/packages/interface-store/LICENSE-MIT new file mode 100644 index 00000000..749aa1ec --- /dev/null +++ b/packages/interface-store/LICENSE-MIT @@ -0,0 +1,19 @@ +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/packages/interface-store/README.md b/packages/interface-store/README.md new file mode 100644 index 00000000..e659522d --- /dev/null +++ b/packages/interface-store/README.md @@ -0,0 +1,20 @@ +# interface-store + +> A generic interface for storing and retrieving data + +## Table of Contents + +- [Contribute](#contribute) +- [License](#license) + +## Contribute + +Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfs-bitswap/issues)! + +This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). + +[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) + +## License + +[MIT](LICENSE) diff --git a/packages/interface-store/package.json b/packages/interface-store/package.json new file mode 100644 index 00000000..860727e4 --- /dev/null +++ b/packages/interface-store/package.json @@ -0,0 +1,22 @@ +{ + "name": "interface-store", + "version": "0.0.1", + "description": "", + "main": "src/index.js", + "types": "dist/src/index.d.ts", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "lint": "aegir ts -p check && aegir lint", + "build": "aegir build" + }, + "homepage": "https://github.com/ipfs/js-ipfs-interfaces/tree/master/packages/interface-store#readme", + "bugs": "https://github.com/ipfs/js-ipfs-interfaces/issues", + "license": "(Apache-2.0 OR MIT)", + "repository": { + "type": "git", + "url": "git+https://github.com/ipfs/js-ipfs-interfaces.git" + }, + "devDependencies": { + "aegir": "^33.1.2" + } +} diff --git a/packages/interface-store/src/index.d.ts b/packages/interface-store/src/index.d.ts new file mode 100644 index 00000000..6d986365 --- /dev/null +++ b/packages/interface-store/src/index.d.ts @@ -0,0 +1,197 @@ + +export type AwaitIterable = Iterable | AsyncIterable +export type Await = Promise | T + +export interface Pair { + key: Key + value: Value +} + +/** + * Options for async operations. + */ +export interface Options { + signal?: AbortSignal +} + +export interface Batch { + put: (key: Key, value: Value) => void + delete: (key: Key) => void + commit: (options?: Options) => Promise +} + +export interface Store { + open: () => Promise + close: () => Promise + + /** + * 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 + + /** + * 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 + + /** + * Check for the existence of a value for the passed key + * + * @example + * ```js + *const exists = await store.has(new Key('awesome')) + * + *if (exists) { + * console.log('it is there') + *} else { + * console.log('it is not there') + *} + *``` + */ + has: (key: Key, options?: Options) => Promise + + /** + * Remove the record for the passed key + * + * @example + * + * ```js + * await store.delete(new Key('awesome')) + * console.log('deleted awesome content :(') + * ``` + */ + delete: (key: Key, options?: Options) => Promise + + /** + * Store the given key/value pairs + * + * @example + * ```js + * const source = [{ key: new Key('awesome'), value: new Uint8Array([0, 1, 2, 3]) }] + * + * for await (const { key, value } of store.putMany(source)) { + * console.info(`put content for key ${key}`) + * } + * ``` + */ + putMany: ( + source: AwaitIterable>, + options?: Options + ) => AsyncIterable> + + /** + * Retrieve values for the passed keys + * + * @example + * ```js + * for await (const value of store.getMany([new Key('awesome')])) { + * console.log('got content:', new TextDecoder('utf8').decode(value)) + * // => got content: datastore + * } + * ``` + */ + getMany: ( + source: AwaitIterable, + options?: Options + ) => AsyncIterable + + /** + * Remove values for the passed keys + * + * @example + * + * ```js + * const source = [new Key('awesome')] + * + * for await (const key of store.deleteMany(source)) { + * console.log(`deleted content with key ${key}`) + * } + * ``` + */ + deleteMany: ( + source: AwaitIterable, + options?: Options + ) => AsyncIterable + + /** + * This will return an object with which you can chain multiple operations together, with them only being executed on calling `commit`. + * + * @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 + + /** + * 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, options?: Options) => AsyncIterable> + + /** + * Query the store. + * + * @example + * ```js + * // retrieve __all__ keys from the store + * let list = [] + * for await (const key of store.queryKeys({})) { + * list.push(key) + * } + * console.log('ALL THE KEYS', key) + * ``` + */ + queryKeys: (query: KeyQuery, options?: Options) => AsyncIterable +} + +export type QueryFilter = (item: Pair) => boolean +export type QueryOrder = (a: Pair, b: Pair) => -1 | 0 | 1 + +export interface Query { + prefix?: string + filters?: QueryFilter[] + orders?: QueryOrder[] + limit?: number + offset?: number +} + +export type KeyQueryFilter = (item: Key) => boolean +export type KeyQueryOrder = (a: Key, b: Key) => -1 | 0 | 1 + +export interface KeyQuery { + prefix?: string + filters?: KeyQueryFilter[] + orders?: KeyQueryOrder[] + limit?: number + offset?: number +} diff --git a/packages/interface-store/src/index.js b/packages/interface-store/src/index.js new file mode 100644 index 00000000..e69de29b diff --git a/packages/interface-store/tsconfig.json b/packages/interface-store/tsconfig.json new file mode 100644 index 00000000..3865f348 --- /dev/null +++ b/packages/interface-store/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "aegir/src/config/tsconfig.aegir.json", + "compilerOptions": { + "outDir": "dist", + "skipLibCheck": false + }, + "include": [ + "test", + "src" + ] +}