From 6826711c5f56b9f7ac574c9d2982aee041aee701 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Mon, 30 Nov 2020 17:09:55 +0000 Subject: [PATCH 01/36] feat: ts types, github ci and clean up - add ts types with jsdocs and aegir - remove travis and add github action - update deps and repo clean up (readme, package.json, etc.. ) --- .github/workflows/main.yml | 67 ++++++++++++++++++++++++++++++++++++ .travis.yml | 42 ----------------------- README.md | 32 +++++++---------- package.json | 23 +++++++++---- src/index.js | 14 ++++---- src/mount.js | 30 +++++++++++----- src/shard.js | 70 ++++++++++++++++++-------------------- src/types.ts | 7 ++++ tsconfig.json | 10 ++++++ 9 files changed, 177 insertions(+), 118 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 .travis.yml create mode 100644 src/types.ts create mode 100644 tsconfig.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..b94c65e --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,67 @@ +name: ci +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: yarn + - run: yarn lint + - run: yarn build + - uses: gozala/typescript-error-reporter-action@v1.0.4 + - run: yarn aegir dep-check -- -i aegir + - uses: ipfs/aegir/actions/bundle-size@master + name: size + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + test-node: + needs: check + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + node: [12, 14] + fail-fast: true + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + - run: yarn + - run: npx nyc --reporter=lcov npm run test:node -- --bail + - uses: codecov/codecov-action@v1 + test-chrome: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: yarn + - run: yarn aegir test -t browser -t webworker + test-firefox: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: yarn + - run: yarn aegir test -t browser -t webworker -- --browsers FirefoxHeadless + test-electron-main: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: yarn + - run: npx xvfb-maybe yarn aegir test -t electron-main --bail + test-electron-renderer: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: yarn + - run: npx xvfb-maybe yarn aegir test -t electron-renderer --bail \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 33b2eaf..0000000 --- a/.travis.yml +++ /dev/null @@ -1,42 +0,0 @@ -language: node_js -cache: npm -stages: - - check - - test - - cov - -node_js: - - '10' - - '12' - -os: - - linux - - osx - -script: npx nyc -s npm run test:node -- --bail -after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov - -jobs: - include: - - os: windows - cache: false - - - stage: check - script: - - npx aegir dep-check - - npm run lint - - - stage: test - name: chrome - addons: - chrome: stable - script: npx aegir test -t browser -t webworker - - - stage: test - name: firefox - addons: - firefox: latest - script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless - -notifications: - email: false \ No newline at end of file diff --git a/README.md b/README.md index 393420c..4ccc64c 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,25 @@ -# js-datastore-core +# js-datastore-core [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) -[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) -[![Build Status](https://flat.badgen.net/travis/ipfs/js-datastore-core)](https://travis-ci.com/ipfs/js-datastore-core) -[![Codecov](https://codecov.io/gh/ipfs/js-datastore-core/branch/master/graph/badge.svg)](https://codecov.io/gh/ipfs/js-datastore-core) -[![Dependency Status](https://david-dm.org/ipfs/js-datastore-core.svg?style=flat-square)](https://david-dm.org/ipfs/js-datastore-core) -[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) -![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square) -![](https://img.shields.io/badge/Node.js-%3E%3D8.0.0-orange.svg?style=flat-square) +[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-datastore-core.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-datastore-core) +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/ipfs/js-datastore-core/ci?label=ci&style=flat-square)](https://github.com/ipfs/js-datastore-core/actions?query=branch%3Amaster+workflow%3Aci+) > Wrapping implementations for [interface-datastore](https://github.com/ipfs/interface-datastore). -## Lead Maintainer +## Lead Maintainer [Alex Potsides](https://github.com/achingbrain) -## Table of Contents - -- [js-datastore-core](#js-datastore-core) - - [Lead Maintainer](#lead-maintainer) - - [Table of Contents](#table-of-contents) - - [Implementations](#implementations) - - [Install](#install) - - [Usage](#usage) - - [Wrapping Stores](#wrapping-stores) - - [Contribute](#contribute) - - [License](#license) +## Table of Contents + +- [Implementations](#implementations) +- [Install](#install) +- [Usage](#usage) + - [Wrapping Stores](#wrapping-stores) +- [Contribute](#contribute) +- [License](#license) ## Implementations diff --git a/package.json b/package.json index 8059e26..4a851bd 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,17 @@ "name": "datastore-core", "version": "2.0.1", "description": "Wrapper implmentation for interface-datastore", - "leadMaintainer": "Pedro Teixeira ", + "leadMaintainer": "Alex Potsides ", "main": "src/index.js", + "types": "dist/src/index.d.ts", + "typesVersions": { + "*": { + "src/*": [ + "dist/src/*", + "dist/src/*/index" + ] + } + }, "scripts": { "test": "aegir test", "test:node": "aegir test -t node", @@ -38,19 +47,21 @@ }, "homepage": "https://github.com/ipfs/js-datastore-core#readme", "devDependencies": { - "aegir": "^28.1.0", + "aegir": "^29.2.0", "async-iterator-all": "^1.0.0", "chai": "^4.2.0", "dirty-chai": "^2.0.1" }, "dependencies": { "debug": "^4.1.1", - "interface-datastore": "^2.0.0", - "ipfs-utils": "^4.0.1" + "interface-datastore": "ipfs/interface-datastore#feat/ts-types", + "ipfs-utils": "^5.0.1" }, "engines": { - "node": ">=6.0.0", - "npm": ">=3.0.0" + "node": ">=12.0.0" + }, + "eslintConfig": { + "extends": "ipfs" }, "contributors": [ "achingbrain ", diff --git a/src/index.js b/src/index.js index 39fac25..4f95d1f 100644 --- a/src/index.js +++ b/src/index.js @@ -7,9 +7,11 @@ const TieredDatastore = require('./tiered') const NamespaceDatastore = require('./namespace') const shard = require('./shard') -exports.KeytransformDatastore = KeytransformDatastore -exports.ShardingDatastore = ShardingDatastore -exports.MountDatastore = MountDatastore -exports.TieredDatastore = TieredDatastore -exports.NamespaceDatastore = NamespaceDatastore -exports.shard = shard +module.exports = { + KeytransformDatastore, + ShardingDatastore, + MountDatastore, + TieredDatastore, + NamespaceDatastore, + shard +} diff --git a/src/mount.js b/src/mount.js index 34f145c..f2f7914 100644 --- a/src/mount.js +++ b/src/mount.js @@ -12,19 +12,29 @@ const { const Keytransform = require('./keytransform') +/** + * @typedef {import('interface-datastore/src/types').IDatastore}IDatastore + * @typedef {import("interface-datastore/src/types").Options}Options + * @typedef {import('interface-datastore/src/key')} Key + */ + /** * A datastore that can combine multiple stores inside various * key prefixs. */ class MountDatastore extends Adapter { + /** + * + * @param {Array<{prefix: Key, datastore: IDatastore}>} mounts + */ constructor (mounts) { super() this.mounts = mounts.slice() } - open () { - return Promise.all(this.mounts.map((m) => m.datastore.open())) + async open () { + await Promise.all(this.mounts.map((m) => m.datastore.open())) } /** @@ -32,7 +42,7 @@ class MountDatastore extends Adapter { * * @private * @param {Key} key - * @returns {{Datastore, Key, Key}} + * @returns {{datastore: IDatastore, mountpoint: Key, rest: Key} | undefined} */ _lookup (key) { for (const mount of this.mounts) { @@ -64,10 +74,14 @@ class MountDatastore extends Adapter { return match.datastore.get(match.rest, options) } + /** + * @param {Key} key + * @param {Options} [options] + */ has (key, options) { const match = this._lookup(key) if (match == null) { - return false + return Promise.resolve(false) } return match.datastore.has(match.rest, options) } @@ -81,8 +95,8 @@ class MountDatastore extends Adapter { return match.datastore.delete(match.rest, options) } - close () { - return Promise.all(this.mounts.map((m) => { + async close () { + await Promise.all(this.mounts.map((m) => { return m.datastore.close() })) } @@ -115,8 +129,8 @@ class MountDatastore extends Adapter { const match = lookup(key) match.batch.delete(match.rest) }, - commit: (options) => { - return Promise.all(Object.keys(batchMounts).map(p => batchMounts[p].commit(options))) + commit: async (options) => { + await Promise.all(Object.keys(batchMounts).map(p => batchMounts[p].commit(options))) } } } diff --git a/src/shard.js b/src/shard.js index a62dd95..24b098d 100644 --- a/src/shard.js +++ b/src/shard.js @@ -1,77 +1,69 @@ -/* @flow */ 'use strict' const Key = require('interface-datastore').Key const { utf8Decoder } = require('../src/utils') - const readme = require('./shard-readme') -// eslint-disable-next-line -/*:: import type {Datastore, Callback} from 'interface-datastore' - -export interface ShardV1 { - name: string; - param: number; - fun(string): string; - toString(): string; -} -*/ +/** + * @typedef {import('./types').IShard} IShard + */ -const PREFIX = exports.PREFIX = '/repo/flatfs/shard/' -const SHARDING_FN = exports.SHARDING_FN = 'SHARDING' -exports.README_FN = '_README' +const PREFIX = '/repo/flatfs/shard/' +const SHARDING_FN = 'SHARDING' +const README_FN = '_README' +/** + * @implements {IShard} + */ class Shard { - /* :: name: string */ - /* :: param: number */ - /* :: _padding: string */ - - constructor (param /* : number */) { + constructor (param) { this.param = param + this.name = 'base' + this._padding = '' } - fun (str /* : string */) /* : string */ { + fun () { throw new Error('implement me') } - toString () /* : string */ { + toString () { return `${PREFIX}v1/${this.name}/${this.param}` } } class Prefix extends Shard { - constructor (prefixLen /* : number */) { + constructor (prefixLen) { super(prefixLen) this._padding = ''.padStart(prefixLen, '_') this.name = 'prefix' } - fun (noslash /* : string */) /* : string */ { + fun (noslash) { return (noslash + this._padding).slice(0, this.param) } } class Suffix extends Shard { - constructor (suffixLen /* : number */) { + constructor (suffixLen) { super(suffixLen) this._padding = ''.padStart(suffixLen, '_') this.name = 'suffix' } - fun (noslash /* : string */) /* : string */ { + fun (noslash) { const s = this._padding + noslash return s.slice(s.length - this.param) } } class NextToLast extends Shard { - constructor (suffixLen /* : number */) { + constructor (suffixLen) { super(suffixLen) this._padding = ''.padStart(suffixLen + 1, '_') this.name = 'next-to-last' } - fun (noslash /* : string */) /* : string */ { + fun (noslash) { const s = this._padding + noslash const offset = s.length - this.param - 1 return s.slice(offset, offset + this.param) @@ -82,9 +74,9 @@ class NextToLast extends Shard { * Convert a given string to the matching sharding function. * * @param {string} str - * @returns {ShardV1} + * @returns {IShard} */ -function parseShardFun (str /* : string */) { +function parseShardFun (str) { str = str.trim() if (str.length === 0) { @@ -122,15 +114,21 @@ function parseShardFun (str /* : string */) { } } -exports.readShardFun = async (path /* : string */, store) /* : Promise */ => { +const readShardFun = async (path, store) => { const key = new Key(path).child(new Key(SHARDING_FN)) const get = typeof store.getRaw === 'function' ? store.getRaw.bind(store) : store.get.bind(store) const res = await get(key) return parseShardFun(utf8Decoder.decode(res || '').trim()) } -exports.readme = readme -exports.parseShardFun = parseShardFun -exports.Prefix = Prefix -exports.Suffix = Suffix -exports.NextToLast = NextToLast +module.exports = { + readme, + parseShardFun, + readShardFun, + Prefix, + Suffix, + NextToLast, + README_FN, + SHARDING_FN, + PREFIX +} diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..8b262e1 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,7 @@ +export interface IShard { + name: string + param:number + _padding: string + fun(s: string): string| void + toString(): string +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..e605b61 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "./node_modules/aegir/src/config/tsconfig.aegir.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": [ + "test", // remove this line if you don't want to type-check tests + "src" + ] +} From 709e1153c34929e6d4917a61ff99315eaebf1928 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 3 Dec 2020 16:12:36 +0000 Subject: [PATCH 02/36] fix more types and ci --- .github/workflows/main.yml | 14 +++++----- package.json | 8 ++---- src/keytransform.js | 38 ++++++++++++++++++++++++++ src/mount.js | 36 +++++++++++++++++++++--- src/namespace.js | 20 ++++++++++++-- src/shard.js | 31 +++++++++++++-------- src/sharding.js | 56 ++++++++++++++++++++++++++++++++++++-- src/tiered.js | 39 ++++++++++++++++++++++++++ src/types.ts | 11 ++++++-- src/utils.js | 7 ----- test/keytransform.spec.js | 9 ++---- test/mount.spec.js | 29 ++++++++------------ test/namespace.spec.js | 14 +++------- test/shard.spec.js | 3 +- test/sharding.spec.js | 20 +++++--------- test/tiered.spec.js | 24 ++++++---------- 16 files changed, 253 insertions(+), 106 deletions(-) delete mode 100644 src/utils.js diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b94c65e..499a3f3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,9 +14,9 @@ jobs: - uses: actions/checkout@v2 - run: yarn - run: yarn lint - - run: yarn build - uses: gozala/typescript-error-reporter-action@v1.0.4 - - run: yarn aegir dep-check -- -i aegir + - run: yarn build + - run: yarn aegir dep-check - uses: ipfs/aegir/actions/bundle-size@master name: size with: @@ -35,7 +35,7 @@ jobs: with: node-version: ${{ matrix.node }} - run: yarn - - run: npx nyc --reporter=lcov npm run test:node -- --bail + - run: npx nyc --reporter=lcov aegir test -t node -- --bail - uses: codecov/codecov-action@v1 test-chrome: needs: check @@ -43,25 +43,25 @@ jobs: steps: - uses: actions/checkout@v2 - run: yarn - - run: yarn aegir test -t browser -t webworker + - run: npx aegir test -t browser -t webworker --bail test-firefox: needs: check runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - run: yarn - - run: yarn aegir test -t browser -t webworker -- --browsers FirefoxHeadless + - run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless test-electron-main: needs: check runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - run: yarn - - run: npx xvfb-maybe yarn aegir test -t electron-main --bail + - run: npx xvfb-maybe aegir test -t electron-main --bail test-electron-renderer: needs: check runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - run: yarn - - run: npx xvfb-maybe yarn aegir test -t electron-renderer --bail \ No newline at end of file + - run: npx xvfb-maybe aegir test -t electron-renderer --bail \ No newline at end of file diff --git a/package.json b/package.json index 4a851bd..47f3f2d 100644 --- a/package.json +++ b/package.json @@ -47,14 +47,12 @@ }, "homepage": "https://github.com/ipfs/js-datastore-core#readme", "devDependencies": { - "aegir": "^29.2.0", - "async-iterator-all": "^1.0.0", - "chai": "^4.2.0", - "dirty-chai": "^2.0.1" + "aegir": "^29.2.2", + "async-iterator-all": "^1.0.0" }, "dependencies": { "debug": "^4.1.1", - "interface-datastore": "ipfs/interface-datastore#feat/ts-types", + "interface-datastore": "github:ipfs/interface-datastore#feat/ts-types", "ipfs-utils": "^5.0.1" }, "engines": { diff --git a/src/keytransform.js b/src/keytransform.js index 389feaf..5318faf 100644 --- a/src/keytransform.js +++ b/src/keytransform.js @@ -2,13 +2,27 @@ const { Adapter, utils } = require('interface-datastore') const map = utils.map +/** + * @typedef {import('interface-datastore/src/types').Datastore}Datastore + * @typedef {import("interface-datastore/src/types").Options}Options + * @typedef {import("interface-datastore/src/types").Batch} Batch + * @typedef {import('interface-datastore/src/key')} Key + * @typedef {import('interface-datastore/src/adapter').Query} Query + * @typedef {import('./types').KeyTransform}KeyTransform + */ /** * A datastore shim, that wraps around a given datastore, changing * the way keys look to the user, for example namespacing * keys, reversing them, etc. + * + * @implements {Datastore} */ class KeyTransformDatastore extends Adapter { + /** + * @param {Datastore} child + * @param {KeyTransform} transform + */ constructor (child, transform) { super() @@ -20,22 +34,42 @@ class KeyTransformDatastore extends Adapter { return this.child.open() } + /** + * @param {Key} key + * @param {Uint8Array} val + * @param {Options | undefined} [options] + */ put (key, val, options) { return this.child.put(this.transform.convert(key), val, options) } + /** + * @param {Key} key + * @param {Options | undefined} [options] + */ get (key, options) { return this.child.get(this.transform.convert(key), options) } + /** + * @param {Key} key + * @param {Options | undefined} [options] + */ has (key, options) { return this.child.has(this.transform.convert(key), options) } + /** + * @param {Key} key + * @param {Options | undefined} [options] + */ delete (key, options) { return this.child.delete(this.transform.convert(key), options) } + /** + * @returns {Batch} + */ batch () { const b = this.child.batch() return { @@ -51,6 +85,10 @@ class KeyTransformDatastore extends Adapter { } } + /** + * @param {Query} q + * @param {Options} [options] + */ query (q, options) { return map(this.child.query(q, options), e => { e.key = this.transform.invert(e.key) diff --git a/src/mount.js b/src/mount.js index f2f7914..6ca583a 100644 --- a/src/mount.js +++ b/src/mount.js @@ -13,19 +13,23 @@ const { const Keytransform = require('./keytransform') /** - * @typedef {import('interface-datastore/src/types').IDatastore}IDatastore + * @typedef {import('interface-datastore/src/types').Datastore}Datastore * @typedef {import("interface-datastore/src/types").Options}Options + * @typedef {import("interface-datastore/src/types").Batch} Batch * @typedef {import('interface-datastore/src/key')} Key + * @typedef {import('interface-datastore/src/adapter').Query} Query */ /** * A datastore that can combine multiple stores inside various * key prefixs. + * + * @implements {Datastore} */ class MountDatastore extends Adapter { /** * - * @param {Array<{prefix: Key, datastore: IDatastore}>} mounts + * @param {Array<{prefix: Key, datastore: Datastore}>} mounts */ constructor (mounts) { super() @@ -42,7 +46,7 @@ class MountDatastore extends Adapter { * * @private * @param {Key} key - * @returns {{datastore: IDatastore, mountpoint: Key, rest: Key} | undefined} + * @returns {{datastore: Datastore, mountpoint: Key, rest: Key} | undefined} */ _lookup (key) { for (const mount of this.mounts) { @@ -57,6 +61,11 @@ class MountDatastore extends Adapter { } } + /** + * @param {Key} key + * @param {Uint8Array} value + * @param {Options} [options] + */ put (key, value, options) { const match = this._lookup(key) if (match == null) { @@ -66,6 +75,10 @@ class MountDatastore extends Adapter { return match.datastore.put(match.rest, value, options) } + /** + * @param {Key} key + * @param {Options} [options] + */ get (key, options) { const match = this._lookup(key) if (match == null) { @@ -86,6 +99,10 @@ class MountDatastore extends Adapter { return match.datastore.has(match.rest, options) } + /** + * @param {Key} key + * @param {Options} [options] + */ delete (key, options) { const match = this._lookup(key) if (match == null) { @@ -101,6 +118,9 @@ class MountDatastore extends Adapter { })) } + /** + * @returns {Batch} + */ batch () { const batchMounts = {} const lookup = (key) => { @@ -135,6 +155,10 @@ class MountDatastore extends Adapter { } } + /** + * @param {Query} q + * @param {Options} [options] + */ query (q, options) { const qs = this.mounts.map(m => { const ks = new Keytransform(m.datastore, { @@ -163,7 +187,7 @@ class MountDatastore extends Adapter { if (q.orders) q.orders.forEach(o => { it = sortAll(it, o) }) if (q.offset != null) { let i = 0 - it = filter(it, () => i++ >= q.offset) + it = filter(it, () => i++ >= /** @type {number} */ (q.offset)) } if (q.limit != null) it = take(it, q.limit) @@ -171,6 +195,10 @@ class MountDatastore extends Adapter { } } +/** + * @param {string | any[]} iterable + * @returns {AsyncIterable} + */ function _many (iterable) { return (async function * () { for (let i = 0; i < iterable.length; i++) { diff --git a/src/namespace.js b/src/namespace.js index a5fc264..7b67450 100644 --- a/src/namespace.js +++ b/src/namespace.js @@ -2,6 +2,14 @@ const Key = require('interface-datastore').Key const KeytransformDatastore = require('./keytransform') +/** + * @typedef {import('interface-datastore/src/types').Datastore}Datastore + * @typedef {import("interface-datastore/src/types").Options}Options + * @typedef {import("interface-datastore/src/types").Batch} Batch + * @typedef {import('interface-datastore/src/key')} Key + * @typedef {import('interface-datastore/src/adapter').Query} Query + * @typedef {import('./types').KeyTransform}KeyTransform + */ /** * Wraps a given datastore into a keytransform which @@ -13,6 +21,10 @@ const KeytransformDatastore = require('./keytransform') * */ class NamespaceDatastore extends KeytransformDatastore { + /** + * @param {Datastore} child + * @param {Key} prefix + */ constructor (child, prefix) { super(child, { convert (key) { @@ -34,13 +46,17 @@ class NamespaceDatastore extends KeytransformDatastore { this.prefix = prefix } - query (q) { + /** + * @param {Query} q + * @param {Options} [options] + */ + query (q, options) { if (q.prefix && this.prefix.toString() !== '/') { return super.query(Object.assign({}, q, { prefix: this.prefix.child(new Key(q.prefix)).toString() })) } - return super.query(q) + return super.query(q, options) } } diff --git a/src/shard.js b/src/shard.js index 24b098d..15b204e 100644 --- a/src/shard.js +++ b/src/shard.js @@ -1,11 +1,11 @@ 'use strict' -const Key = require('interface-datastore').Key -const { utf8Decoder } = require('../src/utils') +const { Key, utils: { utf8Decoder } } = require('interface-datastore') const readme = require('./shard-readme') /** - * @typedef {import('./types').IShard} IShard + * @typedef {import('./types').Shard} Shard + * @typedef {import('interface-datastore/src/types').Datastore}Datastore */ const PREFIX = '/repo/flatfs/shard/' @@ -13,25 +13,27 @@ const SHARDING_FN = 'SHARDING' const README_FN = '_README' /** - * @implements {IShard} + * @implements {Shard} */ -class Shard { +class ShardBase { constructor (param) { this.param = param this.name = 'base' this._padding = '' } - fun () { - throw new Error('implement me') + fun (s) { + return 'implement me' } toString () { return `${PREFIX}v1/${this.name}/${this.param}` } } - -class Prefix extends Shard { +/** + * @implements {Shard} + */ +class Prefix extends ShardBase { constructor (prefixLen) { super(prefixLen) this._padding = ''.padStart(prefixLen, '_') @@ -43,7 +45,7 @@ class Prefix extends Shard { } } -class Suffix extends Shard { +class Suffix extends ShardBase { constructor (suffixLen) { super(suffixLen) this._padding = ''.padStart(suffixLen, '_') @@ -56,7 +58,7 @@ class Suffix extends Shard { } } -class NextToLast extends Shard { +class NextToLast extends ShardBase { constructor (suffixLen) { super(suffixLen) this._padding = ''.padStart(suffixLen + 1, '_') @@ -74,7 +76,7 @@ class NextToLast extends Shard { * Convert a given string to the matching sharding function. * * @param {string} str - * @returns {IShard} + * @returns {Shard} */ function parseShardFun (str) { str = str.trim() @@ -114,8 +116,13 @@ function parseShardFun (str) { } } +/** + * @param {string | Uint8Array} path + * @param {Datastore} store + */ const readShardFun = async (path, store) => { const key = new Key(path).child(new Key(SHARDING_FN)) + // @ts-ignore const get = typeof store.getRaw === 'function' ? store.getRaw.bind(store) : store.get.bind(store) const res = await get(key) return parseShardFun(utf8Decoder.decode(res || '').trim()) diff --git a/src/sharding.js b/src/sharding.js index 87c4d3d..a78726b 100644 --- a/src/sharding.js +++ b/src/sharding.js @@ -1,12 +1,19 @@ 'use strict' -const { Adapter, Key } = require('interface-datastore') +const { Adapter, Key, utils: { utf8Encoder } } = require('interface-datastore') const sh = require('./shard') const KeytransformStore = require('./keytransform') -const { utf8Encoder } = require('../src/utils') const shardKey = new Key(sh.SHARDING_FN) const shardReadmeKey = new Key(sh.README_FN) +/** + * @typedef {import('interface-datastore/src/types').Datastore}Datastore + * @typedef {import("interface-datastore/src/types").Options}Options + * @typedef {import("interface-datastore/src/types").Batch} Batch + * @typedef {import('interface-datastore/src/key')} Key + * @typedef {import('interface-datastore/src/adapter').Query} Query + * @typedef {import('./types').Shard}Shard + */ /** * Backend independent abstraction of go-ds-flatfs. @@ -15,6 +22,10 @@ const shardReadmeKey = new Key(sh.README_FN) * sharded according to the given sharding function. */ class ShardingDatastore extends Adapter { + /** + * @param {Datastore} store + * @param {Shard} shard + */ constructor (store, shard) { super() @@ -29,6 +40,9 @@ class ShardingDatastore extends Adapter { return this.child.open() } + /** + * @param {Key} key + */ _convertKey (key) { const s = key.toString() if (s === shardKey.toString() || s === shardReadmeKey.toString()) { @@ -39,6 +53,9 @@ class ShardingDatastore extends Adapter { return parent.child(key) } + /** + * @param {Key} key + */ _invertKey (key) { const s = key.toString() if (s === shardKey.toString() || s === shardReadmeKey.toString()) { @@ -47,6 +64,10 @@ class ShardingDatastore extends Adapter { return Key.withNamespaces(key.list().slice(1)) } + /** + * @param {Datastore} store + * @param {Shard} shard + */ static async createOrOpen (store, shard) { try { await ShardingDatastore.create(store, shard) @@ -56,14 +77,22 @@ class ShardingDatastore extends Adapter { return ShardingDatastore.open(store) } + /** + * @param {Datastore} store + */ static async open (store) { const shard = await sh.readShardFun('/', store) return new ShardingDatastore(store, shard) } + /** + * @param {Datastore} store + * @param {Shard} shard + */ static async create (store, shard) { const exists = await store.has(shardKey) if (!exists) { + // @ts-ignore i have no idea what putRaw is or saw any implementation const put = typeof store.putRaw === 'function' ? store.putRaw.bind(store) : store.put.bind(store) return Promise.all([put(shardKey, utf8Encoder.encode(shard.toString() + '\n')), put(shardReadmeKey, utf8Encoder.encode(sh.readme))]) @@ -76,18 +105,35 @@ class ShardingDatastore extends Adapter { throw new Error('datastore exists') } + /** + * @param {Key} key + * @param {Uint8Array} val + * @param {Options | undefined} [options] + */ put (key, val, options) { return this.child.put(key, val, options) } + /** + * @param {Key} key + * @param {Options | undefined} [options] + */ get (key, options) { return this.child.get(key, options) } + /** + * @param {Key} key + * @param {Options | undefined} [options] + */ has (key, options) { return this.child.has(key, options) } + /** + * @param {Key} key + * @param {Options | undefined} [options] + */ delete (key, options) { return this.child.delete(key, options) } @@ -96,6 +142,10 @@ class ShardingDatastore extends Adapter { return this.child.batch() } + /** + * @param {Query} q + * @param {Options | undefined} [options] + */ query (q, options) { const tq = { keysOnly: q.keysOnly, @@ -109,7 +159,7 @@ class ShardingDatastore extends Adapter { if (q.prefix != null) { tq.filters.push((e) => { - return this._invertKey(e.key).toString().startsWith(q.prefix) + return this._invertKey(e.key).toString().startsWith(q.prefix ? q.prefix : '') }) } diff --git a/src/tiered.js b/src/tiered.js index 66b5277..75ad9d7 100644 --- a/src/tiered.js +++ b/src/tiered.js @@ -2,6 +2,13 @@ const { Adapter, Errors } = require('interface-datastore') const log = require('debug')('datastore:core:tiered') +/** + * @typedef {import('interface-datastore/src/types').Datastore}Datastore + * @typedef {import("interface-datastore/src/types").Options}Options + * @typedef {import("interface-datastore/src/types").Batch} Batch + * @typedef {import('interface-datastore/src/key')} Key + * @typedef {import('interface-datastore/src/adapter').Query} Query + */ /** * A datastore that can combine multiple stores. Puts and deletes @@ -11,6 +18,9 @@ const log = require('debug')('datastore:core:tiered') * */ class TieredDatastore extends Adapter { + /** + * @param {Datastore[]} stores + */ constructor (stores) { super() @@ -25,6 +35,10 @@ class TieredDatastore extends Adapter { } } + /** + * @param {Key} key + * @param {Uint8Array} value + */ async put (key, value) { try { await Promise.all(this.stores.map(store => store.put(key, value))) @@ -33,6 +47,10 @@ class TieredDatastore extends Adapter { } } + /** + * @param {Key} key + * @param {Options | undefined} [options] + */ async get (key, options) { for (const store of this.stores) { try { @@ -45,6 +63,10 @@ class TieredDatastore extends Adapter { throw Errors.notFoundError() } + /** + * @param {Key} key + * @param {Options | undefined} [options] + */ async has (key, options) { for (const s of this.stores) { if (await s.has(key, options)) { @@ -55,6 +77,10 @@ class TieredDatastore extends Adapter { return false } + /** + * @param {Key} key + * @param {Options | undefined} [options] + */ async delete (key, options) { try { await Promise.all(this.stores.map(store => store.delete(key, options))) @@ -67,14 +93,23 @@ class TieredDatastore extends Adapter { await Promise.all(this.stores.map(store => store.close())) } + /** + * @returns {Batch} + */ batch () { const batches = this.stores.map(store => store.batch()) return { put: (key, value) => { + /** + * @param {{ put: (arg0: any, arg1: any) => any; }} b + */ batches.forEach(b => b.put(key, value)) }, delete: (key) => { + /** + * @param {{ delete: (arg0: any) => any; }} b + */ batches.forEach(b => b.delete(key)) }, commit: async (options) => { @@ -85,6 +120,10 @@ class TieredDatastore extends Adapter { } } + /** + * @param {Query} q + * @param {Options | undefined} [options] + */ query (q, options) { return this.stores[this.stores.length - 1].query(q, options) } diff --git a/src/types.ts b/src/types.ts index 8b262e1..861a99d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,14 @@ -export interface IShard { +import Key from 'interface-datastore/src/key' + +export interface Shard { name: string param:number _padding: string - fun(s: string): string| void + fun(s: string): string toString(): string } + +export interface KeyTransform { + convert: (key: Key) => Key + invert: (key: Key) => Key +} diff --git a/src/utils.js b/src/utils.js deleted file mode 100644 index 15e1356..0000000 --- a/src/utils.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict' - -const TextEncoder = require('ipfs-utils/src/text-encoder') -const TextDecoder = require('ipfs-utils/src/text-decoder') - -module.exports.utf8Encoder = new TextEncoder('utf8') -module.exports.utf8Decoder = new TextDecoder('utf8') diff --git a/test/keytransform.spec.js b/test/keytransform.spec.js index dba5e81..96a2055 100644 --- a/test/keytransform.spec.js +++ b/test/keytransform.spec.js @@ -1,18 +1,15 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -chai.use(require('dirty-chai')) -const expect = chai.expect -const Memory = require('interface-datastore').MemoryDatastore -const Key = require('interface-datastore').Key +const { expect } = require('aegir/utils/chai') +const { Key, MemoryDatastore } = require('interface-datastore') const all = require('async-iterator-all') const KeytransformStore = require('../src/').KeytransformDatastore describe('KeyTransformDatastore', () => { it('basic', async () => { - const mStore = new Memory() + const mStore = new MemoryDatastore() const transform = { convert (key) { return new Key('/abc').child(key) diff --git a/test/mount.spec.js b/test/mount.spec.js index eb24a57..51515c6 100644 --- a/test/mount.spec.js +++ b/test/mount.spec.js @@ -2,16 +2,9 @@ /* eslint max-nested-callbacks: ["error", 8] */ 'use strict' -const chai = require('chai') -chai.use(require('dirty-chai')) -const assert = chai.assert -const expect = chai.expect +const { expect, assert } = require('aegir/utils/chai') const all = require('async-iterator-all') -const { utf8Encoder } = require('../src/utils') - -const Key = require('interface-datastore').Key -const MemoryStore = require('interface-datastore').MemoryDatastore - +const { Key, MemoryDatastore, utils: { utf8Encoder } } = require('interface-datastore') const MountStore = require('../src').MountDatastore describe('MountStore', () => { @@ -27,7 +20,7 @@ describe('MountStore', () => { it('put - wrong mount', async () => { const m = new MountStore([{ - datastore: new MemoryStore(), + datastore: new MemoryDatastore(), prefix: new Key('cool') }]) try { @@ -39,7 +32,7 @@ describe('MountStore', () => { }) it('put', async () => { - const mds = new MemoryStore() + const mds = new MemoryDatastore() const m = new MountStore([{ datastore: mds, prefix: new Key('cool') @@ -52,7 +45,7 @@ describe('MountStore', () => { }) it('get', async () => { - const mds = new MemoryStore() + const mds = new MemoryDatastore() const m = new MountStore([{ datastore: mds, prefix: new Key('cool') @@ -65,7 +58,7 @@ describe('MountStore', () => { }) it('has', async () => { - const mds = new MemoryStore() + const mds = new MemoryDatastore() const m = new MountStore([{ datastore: mds, prefix: new Key('cool') @@ -78,7 +71,7 @@ describe('MountStore', () => { }) it('delete', async () => { - const mds = new MemoryStore() + const mds = new MemoryDatastore() const m = new MountStore([{ datastore: mds, prefix: new Key('cool') @@ -94,7 +87,7 @@ describe('MountStore', () => { }) it('query simple', async () => { - const mds = new MemoryStore() + const mds = new MemoryDatastore() const m = new MountStore([{ datastore: mds, prefix: new Key('cool') @@ -111,13 +104,13 @@ describe('MountStore', () => { setup () { return new MountStore([{ prefix: new Key('/a'), - datastore: new MemoryStore() + datastore: new MemoryDatastore() }, { prefix: new Key('/z'), - datastore: new MemoryStore() + datastore: new MemoryDatastore() }, { prefix: new Key('/q'), - datastore: new MemoryStore() + datastore: new MemoryDatastore() }]) }, teardown () { } diff --git a/test/namespace.spec.js b/test/namespace.spec.js index 5c4782d..8262f3f 100644 --- a/test/namespace.spec.js +++ b/test/namespace.spec.js @@ -1,16 +1,10 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -chai.use(require('dirty-chai')) -const expect = chai.expect - -const Key = require('interface-datastore').Key -const MemoryStore = require('interface-datastore').MemoryDatastore - +const { expect } = require('aegir/utils/chai') +const { Key, MemoryDatastore, utils: { utf8Encoder } } = require('interface-datastore') const NamespaceStore = require('../src/').NamespaceDatastore const all = require('async-iterator-all') -const { utf8Encoder } = require('../src/utils') describe('KeyTransformDatastore', () => { const prefixes = [ @@ -18,7 +12,7 @@ describe('KeyTransformDatastore', () => { '' ] prefixes.forEach((prefix) => it(`basic '${prefix}'`, async () => { - const mStore = new MemoryStore() + const mStore = new MemoryDatastore() const store = new NamespaceStore(mStore, new Key(prefix)) const keys = [ @@ -54,7 +48,7 @@ describe('KeyTransformDatastore', () => { describe(`interface-datastore: '${prefix}'`, () => { require('interface-datastore/src/tests')({ setup () { - return new NamespaceStore(new MemoryStore(), new Key(prefix)) + return new NamespaceStore(new MemoryDatastore(), new Key(prefix)) }, async teardown () { } }) diff --git a/test/shard.spec.js b/test/shard.spec.js index 62454d3..231ffa5 100644 --- a/test/shard.spec.js +++ b/test/shard.spec.js @@ -1,8 +1,7 @@ /* eslint-env mocha */ 'use strict' -const expect = require('chai').expect - +const { expect } = require('aegir/utils/chai') const shard = require('../src').shard describe('shard', () => { diff --git a/test/sharding.spec.js b/test/sharding.spec.js index 7a481c1..3735cad 100644 --- a/test/sharding.spec.js +++ b/test/sharding.spec.js @@ -1,21 +1,15 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -chai.use(require('dirty-chai')) -const expect = chai.expect -const assert = chai.expect - -const Key = require('interface-datastore').Key -const MemoryStore = require('interface-datastore').MemoryDatastore +const { expect, assert } = require('aegir/utils/chai') +const { Key, MemoryDatastore, utils: { utf8Decoder, utf8Encoder } } = require('interface-datastore') const ShardingStore = require('../src').ShardingDatastore const sh = require('../src').shard -const { utf8Encoder, utf8Decoder } = require('../src/utils') describe('ShardingStore', () => { it('create', async () => { - const ms = new MemoryStore() + const ms = new MemoryDatastore() const shard = new sh.NextToLast(2) await ShardingStore.create(ms, shard) const res = await Promise.all([ms.get(new Key(sh.SHARDING_FN)), ms.get(new Key(sh.README_FN))]) @@ -24,7 +18,7 @@ describe('ShardingStore', () => { }) it('open - empty', async () => { - const ms = new MemoryStore() + const ms = new MemoryDatastore() try { await ShardingStore.open(ms) assert(false, 'Failed to throw error on ShardStore.open') @@ -34,7 +28,7 @@ describe('ShardingStore', () => { }) it('open - existing', async () => { - const ms = new MemoryStore() + const ms = new MemoryDatastore() const shard = new sh.NextToLast(2) await ShardingStore.create(ms, shard) @@ -42,7 +36,7 @@ describe('ShardingStore', () => { }) it('basics', async () => { - const ms = new MemoryStore() + const ms = new MemoryDatastore() const shard = new sh.NextToLast(2) const store = await ShardingStore.createOrOpen(ms, shard) expect(store).to.exist() @@ -56,7 +50,7 @@ describe('ShardingStore', () => { require('interface-datastore/src/tests')({ setup () { const shard = new sh.NextToLast(2) - return ShardingStore.createOrOpen(new MemoryStore(), shard) + return ShardingStore.createOrOpen(new MemoryDatastore(), shard) }, teardown () { } }) diff --git a/test/tiered.spec.js b/test/tiered.spec.js index fa308d2..be1a0d7 100644 --- a/test/tiered.spec.js +++ b/test/tiered.spec.js @@ -1,24 +1,18 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -chai.use(require('dirty-chai')) -const expect = chai.expect - -const Key = require('interface-datastore').Key -const MemoryStore = require('interface-datastore').MemoryDatastore - -const TieredStore = require('../src').TieredDatastore -const { utf8Encoder } = require('../src/utils') +const { expect } = require('aegir/utils/chai') +const { Key, MemoryDatastore, utils: { utf8Encoder } } = require('interface-datastore') +const { TieredDatastore } = require('../src') describe('Tiered', () => { describe('all stores', () => { const ms = [] let store beforeEach(() => { - ms.push(new MemoryStore()) - ms.push(new MemoryStore()) - store = new TieredStore(ms) + ms.push(new MemoryDatastore()) + ms.push(new MemoryDatastore()) + store = new TieredDatastore(ms) }) it('put', async () => { @@ -60,9 +54,9 @@ describe('Tiered', () => { describe('inteface-datastore-single', () => { require('interface-datastore/src/tests')({ setup () { - return new TieredStore([ - new MemoryStore(), - new MemoryStore() + return new TieredDatastore([ + new MemoryDatastore(), + new MemoryDatastore() ]) }, teardown () { } From e31f99232d10bf5d146026486e6750975a0d5532 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 15:58:41 +0000 Subject: [PATCH 03/36] Update src/keytransform.js Co-authored-by: Vasco Santos --- src/keytransform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/keytransform.js b/src/keytransform.js index 5318faf..07a1a11 100644 --- a/src/keytransform.js +++ b/src/keytransform.js @@ -3,7 +3,7 @@ const { Adapter, utils } = require('interface-datastore') const map = utils.map /** - * @typedef {import('interface-datastore/src/types').Datastore}Datastore + * @typedef {import('interface-datastore/src/types').Datastore} Datastore * @typedef {import("interface-datastore/src/types").Options}Options * @typedef {import("interface-datastore/src/types").Batch} Batch * @typedef {import('interface-datastore/src/key')} Key From f0e324ffac4e2cb79d06d6bea91e3ac00cffaa4e Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 15:58:56 +0000 Subject: [PATCH 04/36] Update src/keytransform.js Co-authored-by: Vasco Santos --- src/keytransform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/keytransform.js b/src/keytransform.js index 07a1a11..5a18e2a 100644 --- a/src/keytransform.js +++ b/src/keytransform.js @@ -4,7 +4,7 @@ const { Adapter, utils } = require('interface-datastore') const map = utils.map /** * @typedef {import('interface-datastore/src/types').Datastore} Datastore - * @typedef {import("interface-datastore/src/types").Options}Options + * @typedef {import("interface-datastore/src/types").Options} Options * @typedef {import("interface-datastore/src/types").Batch} Batch * @typedef {import('interface-datastore/src/key')} Key * @typedef {import('interface-datastore/src/adapter').Query} Query From 67a8162871a949d1545213a1b6abc636566ae93a Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 15:59:05 +0000 Subject: [PATCH 05/36] Update src/keytransform.js Co-authored-by: Vasco Santos --- src/keytransform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/keytransform.js b/src/keytransform.js index 5a18e2a..1913bb8 100644 --- a/src/keytransform.js +++ b/src/keytransform.js @@ -8,7 +8,7 @@ const map = utils.map * @typedef {import("interface-datastore/src/types").Batch} Batch * @typedef {import('interface-datastore/src/key')} Key * @typedef {import('interface-datastore/src/adapter').Query} Query - * @typedef {import('./types').KeyTransform}KeyTransform + * @typedef {import('./types').KeyTransform} KeyTransform */ /** From a6b241a7819881ab0101ca836f41b48582b696ad Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 15:59:13 +0000 Subject: [PATCH 06/36] Update src/mount.js Co-authored-by: Vasco Santos --- src/mount.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mount.js b/src/mount.js index 6ca583a..2c38794 100644 --- a/src/mount.js +++ b/src/mount.js @@ -13,7 +13,7 @@ const { const Keytransform = require('./keytransform') /** - * @typedef {import('interface-datastore/src/types').Datastore}Datastore + * @typedef {import('interface-datastore/src/types').Datastore} Datastore * @typedef {import("interface-datastore/src/types").Options}Options * @typedef {import("interface-datastore/src/types").Batch} Batch * @typedef {import('interface-datastore/src/key')} Key From bb89d0e9945e92b505d7dee02b27ac78b0747f71 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 15:59:21 +0000 Subject: [PATCH 07/36] Update src/mount.js Co-authored-by: Vasco Santos --- src/mount.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mount.js b/src/mount.js index 2c38794..15bbd27 100644 --- a/src/mount.js +++ b/src/mount.js @@ -14,7 +14,7 @@ const Keytransform = require('./keytransform') /** * @typedef {import('interface-datastore/src/types').Datastore} Datastore - * @typedef {import("interface-datastore/src/types").Options}Options + * @typedef {import("interface-datastore/src/types").Options} Options * @typedef {import("interface-datastore/src/types").Batch} Batch * @typedef {import('interface-datastore/src/key')} Key * @typedef {import('interface-datastore/src/adapter').Query} Query From 0096eaf95d13703bc888937f4c3b7e2a123250af Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:32:40 +0000 Subject: [PATCH 08/36] Update src/namespace.js Co-authored-by: Vasco Santos --- src/namespace.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/namespace.js b/src/namespace.js index 7b67450..0c26cda 100644 --- a/src/namespace.js +++ b/src/namespace.js @@ -3,7 +3,7 @@ const Key = require('interface-datastore').Key const KeytransformDatastore = require('./keytransform') /** - * @typedef {import('interface-datastore/src/types').Datastore}Datastore + * @typedef {import('interface-datastore/src/types').Datastore} Datastore * @typedef {import("interface-datastore/src/types").Options}Options * @typedef {import("interface-datastore/src/types").Batch} Batch * @typedef {import('interface-datastore/src/key')} Key From d710e978cb48c4fcc7c35d084e112928c2c6c160 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:32:58 +0000 Subject: [PATCH 09/36] Update src/namespace.js Co-authored-by: Vasco Santos --- src/namespace.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/namespace.js b/src/namespace.js index 0c26cda..8245afc 100644 --- a/src/namespace.js +++ b/src/namespace.js @@ -4,7 +4,7 @@ const Key = require('interface-datastore').Key const KeytransformDatastore = require('./keytransform') /** * @typedef {import('interface-datastore/src/types').Datastore} Datastore - * @typedef {import("interface-datastore/src/types").Options}Options + * @typedef {import("interface-datastore/src/types").Options} Options * @typedef {import("interface-datastore/src/types").Batch} Batch * @typedef {import('interface-datastore/src/key')} Key * @typedef {import('interface-datastore/src/adapter').Query} Query From c59d259288cc7d69f3a20961cb37ff288a0e34b0 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:33:08 +0000 Subject: [PATCH 10/36] Update src/shard.js Co-authored-by: Vasco Santos --- src/shard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shard.js b/src/shard.js index 15b204e..248f2f8 100644 --- a/src/shard.js +++ b/src/shard.js @@ -5,7 +5,7 @@ const readme = require('./shard-readme') /** * @typedef {import('./types').Shard} Shard - * @typedef {import('interface-datastore/src/types').Datastore}Datastore + * @typedef {import('interface-datastore/src/types').Datastore} Datastore */ const PREFIX = '/repo/flatfs/shard/' From d95855ed764f75f498e1a458c416ac1a1c9070ca Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:33:39 +0000 Subject: [PATCH 11/36] Update .github/workflows/main.yml Co-authored-by: Irakli Gozalishvili --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 499a3f3..438037f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v2 - run: yarn - run: yarn lint - - uses: gozala/typescript-error-reporter-action@v1.0.4 + - uses: gozala/typescript-error-reporter-action@v1.0.8 - run: yarn build - run: yarn aegir dep-check - uses: ipfs/aegir/actions/bundle-size@master @@ -64,4 +64,4 @@ jobs: steps: - uses: actions/checkout@v2 - run: yarn - - run: npx xvfb-maybe aegir test -t electron-renderer --bail \ No newline at end of file + - run: npx xvfb-maybe aegir test -t electron-renderer --bail From ecd45d9770fe2a345b15f95d9f6bb192a4a916e5 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:34:56 +0000 Subject: [PATCH 12/36] Update src/keytransform.js Co-authored-by: Irakli Gozalishvili --- src/keytransform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/keytransform.js b/src/keytransform.js index 1913bb8..e56d3ea 100644 --- a/src/keytransform.js +++ b/src/keytransform.js @@ -37,7 +37,7 @@ class KeyTransformDatastore extends Adapter { /** * @param {Key} key * @param {Uint8Array} val - * @param {Options | undefined} [options] + * @param {Options} [options] */ put (key, val, options) { return this.child.put(this.transform.convert(key), val, options) From d5312e62352834f98221d2a2c425353e38674607 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:35:06 +0000 Subject: [PATCH 13/36] Update src/keytransform.js Co-authored-by: Irakli Gozalishvili --- src/keytransform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/keytransform.js b/src/keytransform.js index e56d3ea..0788def 100644 --- a/src/keytransform.js +++ b/src/keytransform.js @@ -45,7 +45,7 @@ class KeyTransformDatastore extends Adapter { /** * @param {Key} key - * @param {Options | undefined} [options] + * @param {Options} [options] */ get (key, options) { return this.child.get(this.transform.convert(key), options) From 973c5871e31b004f2ffbb01febdaa61ec2d5095e Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:35:17 +0000 Subject: [PATCH 14/36] Update src/keytransform.js Co-authored-by: Irakli Gozalishvili --- src/keytransform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/keytransform.js b/src/keytransform.js index 0788def..422efa1 100644 --- a/src/keytransform.js +++ b/src/keytransform.js @@ -53,7 +53,7 @@ class KeyTransformDatastore extends Adapter { /** * @param {Key} key - * @param {Options | undefined} [options] + * @param {Options} [options] */ has (key, options) { return this.child.has(this.transform.convert(key), options) From 93065f528dbf0df402cf596a55bbd947a707cd45 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:35:33 +0000 Subject: [PATCH 15/36] Update src/keytransform.js Co-authored-by: Irakli Gozalishvili --- src/keytransform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/keytransform.js b/src/keytransform.js index 422efa1..d1b2f49 100644 --- a/src/keytransform.js +++ b/src/keytransform.js @@ -61,7 +61,7 @@ class KeyTransformDatastore extends Adapter { /** * @param {Key} key - * @param {Options | undefined} [options] + * @param {Options} [options] */ delete (key, options) { return this.child.delete(this.transform.convert(key), options) From dd6328bcf3d353e11778a1869744f7755da3e1d0 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:35:43 +0000 Subject: [PATCH 16/36] Update src/tiered.js Co-authored-by: Irakli Gozalishvili --- src/tiered.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tiered.js b/src/tiered.js index 75ad9d7..a075967 100644 --- a/src/tiered.js +++ b/src/tiered.js @@ -65,7 +65,7 @@ class TieredDatastore extends Adapter { /** * @param {Key} key - * @param {Options | undefined} [options] + * @param {Options} [options] */ async has (key, options) { for (const s of this.stores) { From c1787e116b83f618cb12f86faf3a11f0fb52ff17 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:36:40 +0000 Subject: [PATCH 17/36] Update src/tiered.js Co-authored-by: Irakli Gozalishvili --- src/tiered.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tiered.js b/src/tiered.js index a075967..37b9631 100644 --- a/src/tiered.js +++ b/src/tiered.js @@ -79,7 +79,7 @@ class TieredDatastore extends Adapter { /** * @param {Key} key - * @param {Options | undefined} [options] + * @param {Options} [options] */ async delete (key, options) { try { From 674c4de4759e546d805e1fef4ac6c873f9309c17 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:38:15 +0000 Subject: [PATCH 18/36] Update src/tiered.js Co-authored-by: Irakli Gozalishvili --- src/tiered.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tiered.js b/src/tiered.js index 37b9631..db37a6d 100644 --- a/src/tiered.js +++ b/src/tiered.js @@ -122,7 +122,7 @@ class TieredDatastore extends Adapter { /** * @param {Query} q - * @param {Options | undefined} [options] + * @param {Options} [options] */ query (q, options) { return this.stores[this.stores.length - 1].query(q, options) From 0e389f42166d4c69dd7d708ccd4f4840c21891c7 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:50:00 +0000 Subject: [PATCH 19/36] Update src/sharding.js Co-authored-by: Irakli Gozalishvili --- src/sharding.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sharding.js b/src/sharding.js index a78726b..0792080 100644 --- a/src/sharding.js +++ b/src/sharding.js @@ -108,7 +108,7 @@ class ShardingDatastore extends Adapter { /** * @param {Key} key * @param {Uint8Array} val - * @param {Options | undefined} [options] + * @param {Options} [options] */ put (key, val, options) { return this.child.put(key, val, options) From 78f9a9a5a3490de0671548d4b0a50ad13ff7fce5 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:50:20 +0000 Subject: [PATCH 20/36] Update src/sharding.js Co-authored-by: Irakli Gozalishvili --- src/sharding.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sharding.js b/src/sharding.js index 0792080..9a6537d 100644 --- a/src/sharding.js +++ b/src/sharding.js @@ -116,7 +116,7 @@ class ShardingDatastore extends Adapter { /** * @param {Key} key - * @param {Options | undefined} [options] + * @param {Options} [options] */ get (key, options) { return this.child.get(key, options) From 754de481ef796ce0300535ca92ac425ad33d01ed Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:50:52 +0000 Subject: [PATCH 21/36] Update src/sharding.js Co-authored-by: Irakli Gozalishvili --- src/sharding.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sharding.js b/src/sharding.js index 9a6537d..3825751 100644 --- a/src/sharding.js +++ b/src/sharding.js @@ -124,7 +124,7 @@ class ShardingDatastore extends Adapter { /** * @param {Key} key - * @param {Options | undefined} [options] + * @param {Options} [options] */ has (key, options) { return this.child.has(key, options) From 85b001999f75b5f06d260bc2975ad56c914c4d34 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:51:07 +0000 Subject: [PATCH 22/36] Update src/sharding.js Co-authored-by: Irakli Gozalishvili --- src/sharding.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sharding.js b/src/sharding.js index 3825751..0934ed3 100644 --- a/src/sharding.js +++ b/src/sharding.js @@ -132,7 +132,7 @@ class ShardingDatastore extends Adapter { /** * @param {Key} key - * @param {Options | undefined} [options] + * @param {Options} [options] */ delete (key, options) { return this.child.delete(key, options) From b203ccfcd265d28f9a54a5888f9d36f21e354f30 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:51:43 +0000 Subject: [PATCH 23/36] Update src/sharding.js Co-authored-by: Irakli Gozalishvili --- src/sharding.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sharding.js b/src/sharding.js index 0934ed3..5eb37d2 100644 --- a/src/sharding.js +++ b/src/sharding.js @@ -144,7 +144,7 @@ class ShardingDatastore extends Adapter { /** * @param {Query} q - * @param {Options | undefined} [options] + * @param {Options} [options] */ query (q, options) { const tq = { From 068759bc78ec76b439a3f1d68b9520d4567a1dca Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:53:19 +0000 Subject: [PATCH 24/36] Update src/sharding.js Co-authored-by: Irakli Gozalishvili --- src/sharding.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sharding.js b/src/sharding.js index 5eb37d2..27e6988 100644 --- a/src/sharding.js +++ b/src/sharding.js @@ -157,7 +157,8 @@ class ShardingDatastore extends Adapter { ] } - if (q.prefix != null) { + const { prefix } = q + if (prefix != null) { tq.filters.push((e) => { return this._invertKey(e.key).toString().startsWith(q.prefix ? q.prefix : '') }) From fd856317e3b4e8ba0c5f94bc53267ff629bdb425 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:53:34 +0000 Subject: [PATCH 25/36] Update src/sharding.js Co-authored-by: Irakli Gozalishvili --- src/sharding.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sharding.js b/src/sharding.js index 27e6988..d376fbc 100644 --- a/src/sharding.js +++ b/src/sharding.js @@ -160,7 +160,7 @@ class ShardingDatastore extends Adapter { const { prefix } = q if (prefix != null) { tq.filters.push((e) => { - return this._invertKey(e.key).toString().startsWith(q.prefix ? q.prefix : '') + return this._invertKey(e.key).toString().startsWith(prefix) }) } From ea63f1df6f0d672209029a1d3e072bbaa472bda1 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 16:53:49 +0000 Subject: [PATCH 26/36] Update src/tiered.js Co-authored-by: Irakli Gozalishvili --- src/tiered.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tiered.js b/src/tiered.js index db37a6d..2f0a38b 100644 --- a/src/tiered.js +++ b/src/tiered.js @@ -49,7 +49,7 @@ class TieredDatastore extends Adapter { /** * @param {Key} key - * @param {Options | undefined} [options] + * @param {Options} [options] */ async get (key, options) { for (const store of this.stores) { From d239031d529c807676a8d46ec0ac9e60b69f1349 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 17:00:28 +0000 Subject: [PATCH 27/36] fix: feedback --- src/mount.js | 10 ++++++++-- src/tiered.js | 6 ------ src/types.ts | 4 +++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/mount.js b/src/mount.js index 6ca583a..6d5913d 100644 --- a/src/mount.js +++ b/src/mount.js @@ -20,6 +20,11 @@ const Keytransform = require('./keytransform') * @typedef {import('interface-datastore/src/adapter').Query} Query */ +/** + * @template O + * @typedef {import('./types').AwaitIterable} AwaitIterable + */ + /** * A datastore that can combine multiple stores inside various * key prefixs. @@ -196,8 +201,9 @@ class MountDatastore extends Adapter { } /** - * @param {string | any[]} iterable - * @returns {AsyncIterable} + * @template T + * @param {ArrayLike>} iterable + * @returns {AsyncIterable} */ function _many (iterable) { return (async function * () { diff --git a/src/tiered.js b/src/tiered.js index 75ad9d7..16e1639 100644 --- a/src/tiered.js +++ b/src/tiered.js @@ -101,15 +101,9 @@ class TieredDatastore extends Adapter { return { put: (key, value) => { - /** - * @param {{ put: (arg0: any, arg1: any) => any; }} b - */ batches.forEach(b => b.put(key, value)) }, delete: (key) => { - /** - * @param {{ delete: (arg0: any) => any; }} b - */ batches.forEach(b => b.delete(key)) }, commit: async (options) => { diff --git a/src/types.ts b/src/types.ts index 861a99d..d3753e7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,7 +3,7 @@ import Key from 'interface-datastore/src/key' export interface Shard { name: string param:number - _padding: string + readonly _padding: string fun(s: string): string toString(): string } @@ -12,3 +12,5 @@ export interface KeyTransform { convert: (key: Key) => Key invert: (key: Key) => Key } + +export type AwaitIterable = Iterable | AsyncIterable From 5c53bc86a140393652d992ec96e072d78cb153fb Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 9 Dec 2020 17:12:53 +0000 Subject: [PATCH 28/36] chore: change ci to npm --- .github/workflows/main.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 438037f..f3b540a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,11 +12,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: yarn - - run: yarn lint + - run: npm install + - run: npm run lint - uses: gozala/typescript-error-reporter-action@v1.0.8 - - run: yarn build - - run: yarn aegir dep-check + - run: npm run build + - run: npx aegir dep-check - uses: ipfs/aegir/actions/bundle-size@master name: size with: @@ -34,7 +34,7 @@ jobs: - uses: actions/setup-node@v1 with: node-version: ${{ matrix.node }} - - run: yarn + - run: npm install - run: npx nyc --reporter=lcov aegir test -t node -- --bail - uses: codecov/codecov-action@v1 test-chrome: @@ -42,26 +42,26 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: yarn + - run: npm install - run: npx aegir test -t browser -t webworker --bail test-firefox: needs: check runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: yarn + - run: npm install - run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless test-electron-main: needs: check runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: yarn + - run: npm install - run: npx xvfb-maybe aegir test -t electron-main --bail test-electron-renderer: needs: check runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: yarn + - run: npm install - run: npx xvfb-maybe aegir test -t electron-renderer --bail From d4fbde515e40898f6402a3ec548d12972adbd99e Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Fri, 11 Dec 2020 11:02:21 +0000 Subject: [PATCH 29/36] chore:ci --- .github/workflows/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f3b540a..b08e965 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,9 +13,9 @@ jobs: steps: - uses: actions/checkout@v2 - run: npm install - - run: npm run lint - - uses: gozala/typescript-error-reporter-action@v1.0.8 - - run: npm run build + - run: npx aegir lint + - uses: gozala/typescript-error-reporter-action@v1 + - run: npx aegir build - run: npx aegir dep-check - uses: ipfs/aegir/actions/bundle-size@master name: size @@ -64,4 +64,4 @@ jobs: steps: - uses: actions/checkout@v2 - run: npm install - - run: npx xvfb-maybe aegir test -t electron-renderer --bail + - run: npx xvfb-maybe aegir test -t electron-renderer --bail \ No newline at end of file From e7b39e169abce0f4efe3618263d21322a536c9a0 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Fri, 11 Dec 2020 11:02:53 +0000 Subject: [PATCH 30/36] add prepare --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47f3f2d..7e07ec5 100644 --- a/package.json +++ b/package.json @@ -14,11 +14,11 @@ } }, "scripts": { + "prepare": "aegir build", "test": "aegir test", "test:node": "aegir test -t node", "test:browser": "aegir test -t browser", "test:webworker": "aegir test -t webworker", - "build": "aegir build", "lint": "aegir lint", "release": "aegir release", "release-minor": "aegir release --type minor", From edbaa19c89548448bc52e80af7bdba87874ab6c4 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Fri, 11 Dec 2020 11:06:53 +0000 Subject: [PATCH 31/36] ci --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b08e965..9e81b21 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v2 - run: npm install - run: npx aegir lint - - uses: gozala/typescript-error-reporter-action@v1 + - uses: gozala/typescript-error-reporter-action@v1.0.8 - run: npx aegir build - run: npx aegir dep-check - uses: ipfs/aegir/actions/bundle-size@master From 10ae98ed1a3ecd2388e76341b946c502be049228 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Fri, 11 Dec 2020 12:05:20 +0000 Subject: [PATCH 32/36] fix: ci --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7e07ec5..46ffcb6 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ }, "homepage": "https://github.com/ipfs/js-datastore-core#readme", "devDependencies": { - "aegir": "^29.2.2", + "aegir": "ipfs/aegir#feat/ts-4.1.x", "async-iterator-all": "^1.0.0" }, "dependencies": { From f5a3d56d476eaa66c9d96a1ea564f82cb3ff50a5 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Tue, 12 Jan 2021 14:49:14 +0000 Subject: [PATCH 33/36] fix: new aegir config and remove typesVersion --- package.json | 20 ++++++-------------- src/keytransform.js | 10 +++++----- src/mount.js | 17 ++++++++++------- src/namespace.js | 11 +++++------ src/shard.js | 26 +++++++++++++++++++++++++- src/sharding.js | 22 ++++++++++++++++------ src/tiered.js | 10 +++++----- src/types.ts | 17 +++++++++-------- test/keytransform.spec.js | 8 +++++++- test/mount.spec.js | 3 ++- test/namespace.spec.js | 3 ++- test/sharding.spec.js | 1 + test/tiered.spec.js | 6 ++++++ 13 files changed, 99 insertions(+), 55 deletions(-) diff --git a/package.json b/package.json index 46ffcb6..0503815 100644 --- a/package.json +++ b/package.json @@ -1,20 +1,12 @@ { "name": "datastore-core", "version": "2.0.1", - "description": "Wrapper implmentation for interface-datastore", + "description": "Wrapper implementation for interface-datastore", "leadMaintainer": "Alex Potsides ", "main": "src/index.js", "types": "dist/src/index.d.ts", - "typesVersions": { - "*": { - "src/*": [ - "dist/src/*", - "dist/src/*/index" - ] - } - }, "scripts": { - "prepare": "aegir build", + "prepare": "aegir build --no-bundle", "test": "aegir test", "test:node": "aegir test -t node", "test:browser": "aegir test -t browser", @@ -47,13 +39,13 @@ }, "homepage": "https://github.com/ipfs/js-datastore-core#readme", "devDependencies": { - "aegir": "ipfs/aegir#feat/ts-4.1.x", - "async-iterator-all": "^1.0.0" + "@types/debug": "^4.1.5", + "aegir": "^30.3.0", + "it-all": "^1.0.4" }, "dependencies": { "debug": "^4.1.1", - "interface-datastore": "github:ipfs/interface-datastore#feat/ts-types", - "ipfs-utils": "^5.0.1" + "interface-datastore": "github:ipfs/interface-datastore#feat/ts-types" }, "engines": { "node": ">=12.0.0" diff --git a/src/keytransform.js b/src/keytransform.js index d1b2f49..970a462 100644 --- a/src/keytransform.js +++ b/src/keytransform.js @@ -3,11 +3,11 @@ const { Adapter, utils } = require('interface-datastore') const map = utils.map /** - * @typedef {import('interface-datastore/src/types').Datastore} Datastore - * @typedef {import("interface-datastore/src/types").Options} Options - * @typedef {import("interface-datastore/src/types").Batch} Batch - * @typedef {import('interface-datastore/src/key')} Key - * @typedef {import('interface-datastore/src/adapter').Query} Query + * @typedef {import('interface-datastore/dist/src/types').Datastore} Datastore + * @typedef {import('interface-datastore/dist/src/types').Options} Options + * @typedef {import('interface-datastore/dist/src/types').Batch} Batch + * @typedef {import('interface-datastore/dist/src/types')} Query + * @typedef {InstanceType} Key * @typedef {import('./types').KeyTransform} KeyTransform */ diff --git a/src/mount.js b/src/mount.js index dc18e33..0ec0de5 100644 --- a/src/mount.js +++ b/src/mount.js @@ -13,16 +13,15 @@ const { const Keytransform = require('./keytransform') /** - * @typedef {import('interface-datastore/src/types').Datastore} Datastore - * @typedef {import("interface-datastore/src/types").Options} Options - * @typedef {import("interface-datastore/src/types").Batch} Batch - * @typedef {import('interface-datastore/src/key')} Key - * @typedef {import('interface-datastore/src/adapter').Query} Query + * @typedef {import('interface-datastore/dist/src/types').Datastore} Datastore + * @typedef {import('interface-datastore/dist/src/types').Options} Options + * @typedef {import('interface-datastore/dist/src/types').Batch} Batch + * @typedef {import('interface-datastore/dist/src/types').Query} Query */ /** - * @template O - * @typedef {import('./types').AwaitIterable} AwaitIterable + * @template TIterable + * @typedef {import('./types').AwaitIterable} AwaitIterable */ /** @@ -127,7 +126,11 @@ class MountDatastore extends Adapter { * @returns {Batch} */ batch () { + /** @type {Record} */ const batchMounts = {} + /** + * @param {Key} key + */ const lookup = (key) => { const match = this._lookup(key) if (match == null) { diff --git a/src/namespace.js b/src/namespace.js index 8245afc..669b08f 100644 --- a/src/namespace.js +++ b/src/namespace.js @@ -3,12 +3,11 @@ const Key = require('interface-datastore').Key const KeytransformDatastore = require('./keytransform') /** - * @typedef {import('interface-datastore/src/types').Datastore} Datastore - * @typedef {import("interface-datastore/src/types").Options} Options - * @typedef {import("interface-datastore/src/types").Batch} Batch - * @typedef {import('interface-datastore/src/key')} Key - * @typedef {import('interface-datastore/src/adapter').Query} Query - * @typedef {import('./types').KeyTransform}KeyTransform + * @typedef {import('interface-datastore/dist/src/types').Datastore} Datastore + * @typedef {import('interface-datastore/dist/src/types').Query} Query + * @typedef {import('interface-datastore/dist/src/types').Options} Options + * @typedef {import('interface-datastore/dist/src/types').Batch} Batch + * @typedef {import('./types').KeyTransform} KeyTransform */ /** diff --git a/src/shard.js b/src/shard.js index 248f2f8..17183c7 100644 --- a/src/shard.js +++ b/src/shard.js @@ -5,7 +5,7 @@ const readme = require('./shard-readme') /** * @typedef {import('./types').Shard} Shard - * @typedef {import('interface-datastore/src/types').Datastore} Datastore + * @typedef {import('interface-datastore/dist/src/types').Datastore} Datastore */ const PREFIX = '/repo/flatfs/shard/' @@ -16,12 +16,18 @@ const README_FN = '_README' * @implements {Shard} */ class ShardBase { + /** + * @param {any} param + */ constructor (param) { this.param = param this.name = 'base' this._padding = '' } + /** + * @param {string} s + */ fun (s) { return 'implement me' } @@ -34,24 +40,36 @@ class ShardBase { * @implements {Shard} */ class Prefix extends ShardBase { + /** + * @param {number} prefixLen + */ constructor (prefixLen) { super(prefixLen) this._padding = ''.padStart(prefixLen, '_') this.name = 'prefix' } + /** + * @param {string} noslash + */ fun (noslash) { return (noslash + this._padding).slice(0, this.param) } } class Suffix extends ShardBase { + /** + * @param {number} suffixLen + */ constructor (suffixLen) { super(suffixLen) this._padding = ''.padStart(suffixLen, '_') this.name = 'suffix' } + /** + * @param {string} noslash + */ fun (noslash) { const s = this._padding + noslash return s.slice(s.length - this.param) @@ -59,12 +77,18 @@ class Suffix extends ShardBase { } class NextToLast extends ShardBase { + /** + * @param {number} suffixLen + */ constructor (suffixLen) { super(suffixLen) this._padding = ''.padStart(suffixLen + 1, '_') this.name = 'next-to-last' } + /** + * @param {string} noslash + */ fun (noslash) { const s = this._padding + noslash const offset = s.length - this.param - 1 diff --git a/src/sharding.js b/src/sharding.js index d376fbc..c82054b 100644 --- a/src/sharding.js +++ b/src/sharding.js @@ -7,12 +7,17 @@ const KeytransformStore = require('./keytransform') const shardKey = new Key(sh.SHARDING_FN) const shardReadmeKey = new Key(sh.README_FN) /** - * @typedef {import('interface-datastore/src/types').Datastore}Datastore - * @typedef {import("interface-datastore/src/types").Options}Options - * @typedef {import("interface-datastore/src/types").Batch} Batch - * @typedef {import('interface-datastore/src/key')} Key - * @typedef {import('interface-datastore/src/adapter').Query} Query - * @typedef {import('./types').Shard}Shard + * @typedef {import('interface-datastore/dist/src/types').Datastore} Datastore + * @typedef {import('interface-datastore/dist/src/types').Options} Options + * @typedef {import('interface-datastore/dist/src/types').Batch} Batch + * @typedef {import('interface-datastore/dist/src/types').Query} Query + * @typedef {import('interface-datastore/dist/src/types').Pair} Pair + * @typedef {import('./types').Shard} Shard + * + */ +/** + * @template TValue + * @typedef {import('./types').Await } Await */ /** @@ -151,8 +156,12 @@ class ShardingDatastore extends Adapter { keysOnly: q.keysOnly, offset: q.offset, limit: q.limit, + /** @type Array<(items: Pair[]) => Await> */ + orders: [], filters: [ + /** @type {(item: Pair) => boolean} */ e => e.key.toString() !== shardKey.toString(), + /** @type {(item: Pair) => boolean} */ e => e.key.toString() !== shardReadmeKey.toString() ] } @@ -165,6 +174,7 @@ class ShardingDatastore extends Adapter { } if (q.filters != null) { + // @ts-ignore const filters = q.filters.map((f) => (e) => { return f(Object.assign({}, e, { key: this._invertKey(e.key) diff --git a/src/tiered.js b/src/tiered.js index c8b520f..649080b 100644 --- a/src/tiered.js +++ b/src/tiered.js @@ -3,11 +3,11 @@ const { Adapter, Errors } = require('interface-datastore') const log = require('debug')('datastore:core:tiered') /** - * @typedef {import('interface-datastore/src/types').Datastore}Datastore - * @typedef {import("interface-datastore/src/types").Options}Options - * @typedef {import("interface-datastore/src/types").Batch} Batch - * @typedef {import('interface-datastore/src/key')} Key - * @typedef {import('interface-datastore/src/adapter').Query} Query + * @typedef {import('interface-datastore/dist/src/types').Datastore} Datastore + * @typedef {import('interface-datastore/dist/src/types').Options} Options + * @typedef {import('interface-datastore/dist/src/types').Batch} Batch + * @typedef {import('interface-datastore/dist/src/types').Query} Query + * @typedef {InstanceType} Key */ /** diff --git a/src/types.ts b/src/types.ts index d3753e7..87fb613 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,16 +1,17 @@ -import Key from 'interface-datastore/src/key' +import type { Key } from 'interface-datastore' export interface Shard { - name: string - param:number - readonly _padding: string - fun(s: string): string - toString(): string + name: string + param: number + readonly _padding: string + fun: (s: string) => string + toString: () => string } export interface KeyTransform { - convert: (key: Key) => Key - invert: (key: Key) => Key + convert: (key: Key) => Key + invert: (key: Key) => Key } export type AwaitIterable = Iterable | AsyncIterable +export type Await = Promise | T diff --git a/test/keytransform.spec.js b/test/keytransform.spec.js index 96a2055..8fbe14c 100644 --- a/test/keytransform.spec.js +++ b/test/keytransform.spec.js @@ -3,7 +3,7 @@ const { expect } = require('aegir/utils/chai') const { Key, MemoryDatastore } = require('interface-datastore') -const all = require('async-iterator-all') +const all = require('it-all') const KeytransformStore = require('../src/').KeytransformDatastore @@ -11,9 +11,15 @@ describe('KeyTransformDatastore', () => { it('basic', async () => { const mStore = new MemoryDatastore() const transform = { + /** + * @param {Key} key + */ convert (key) { return new Key('/abc').child(key) }, + /** + * @param {Key} key + */ invert (key) { const l = key.list() if (l[0] !== 'abc') { diff --git a/test/mount.spec.js b/test/mount.spec.js index 51515c6..9dad023 100644 --- a/test/mount.spec.js +++ b/test/mount.spec.js @@ -3,7 +3,7 @@ 'use strict' const { expect, assert } = require('aegir/utils/chai') -const all = require('async-iterator-all') +const all = require('it-all') const { Key, MemoryDatastore, utils: { utf8Encoder } } = require('interface-datastore') const MountStore = require('../src').MountDatastore @@ -100,6 +100,7 @@ describe('MountStore', () => { }) describe('interface-datastore', () => { + // @ts-ignore require('interface-datastore/src/tests')({ setup () { return new MountStore([{ diff --git a/test/namespace.spec.js b/test/namespace.spec.js index 8262f3f..2f29cec 100644 --- a/test/namespace.spec.js +++ b/test/namespace.spec.js @@ -4,7 +4,7 @@ const { expect } = require('aegir/utils/chai') const { Key, MemoryDatastore, utils: { utf8Encoder } } = require('interface-datastore') const NamespaceStore = require('../src/').NamespaceDatastore -const all = require('async-iterator-all') +const all = require('it-all') describe('KeyTransformDatastore', () => { const prefixes = [ @@ -46,6 +46,7 @@ describe('KeyTransformDatastore', () => { prefixes.forEach((prefix) => { describe(`interface-datastore: '${prefix}'`, () => { + // @ts-ignore require('interface-datastore/src/tests')({ setup () { return new NamespaceStore(new MemoryDatastore(), new Key(prefix)) diff --git a/test/sharding.spec.js b/test/sharding.spec.js index 3735cad..94a8f80 100644 --- a/test/sharding.spec.js +++ b/test/sharding.spec.js @@ -47,6 +47,7 @@ describe('ShardingStore', () => { }) describe('interface-datastore', () => { + // @ts-ignore require('interface-datastore/src/tests')({ setup () { const shard = new sh.NextToLast(2) diff --git a/test/tiered.spec.js b/test/tiered.spec.js index be1a0d7..d7d7244 100644 --- a/test/tiered.spec.js +++ b/test/tiered.spec.js @@ -4,10 +4,15 @@ const { expect } = require('aegir/utils/chai') const { Key, MemoryDatastore, utils: { utf8Encoder } } = require('interface-datastore') const { TieredDatastore } = require('../src') +/** + * @typedef {import('interface-datastore/dist/src/types').Datastore} Datastore + */ describe('Tiered', () => { describe('all stores', () => { + /** @type {Datastore[]} */ const ms = [] + /** @type {TieredDatastore} */ let store beforeEach(() => { ms.push(new MemoryDatastore()) @@ -52,6 +57,7 @@ describe('Tiered', () => { }) describe('inteface-datastore-single', () => { + // @ts-ignore require('interface-datastore/src/tests')({ setup () { return new TieredDatastore([ From b727005d94f8296fda4b26271a71cfd470fb4e65 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 15 Jan 2021 16:16:20 +0000 Subject: [PATCH 34/36] chore: remove gh dep url --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0503815..f0f7975 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ }, "dependencies": { "debug": "^4.1.1", - "interface-datastore": "github:ipfs/interface-datastore#feat/ts-types" + "interface-datastore": "^3.0.0" }, "engines": { "node": ">=12.0.0" From cabcdea220b56acd3a1bc821ea581d4108051405 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Sat, 16 Jan 2021 13:27:58 +0000 Subject: [PATCH 35/36] fix: update interface-datastore --- package.json | 2 +- src/index.js | 5 +++++ src/keytransform.js | 10 +++++----- src/mount.js | 18 +++++++++--------- src/namespace.js | 8 ++++---- src/shard.js | 2 +- src/sharding.js | 12 ++++++------ src/tiered.js | 10 +++++----- 8 files changed, 36 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index f0f7975..ce6d128 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ }, "dependencies": { "debug": "^4.1.1", - "interface-datastore": "^3.0.0" + "interface-datastore": "ipfs/interface-datastore#chore/export-types-from-entrypoint" }, "engines": { "node": ">=12.0.0" diff --git a/src/index.js b/src/index.js index 4f95d1f..f764ea4 100644 --- a/src/index.js +++ b/src/index.js @@ -7,6 +7,11 @@ const TieredDatastore = require('./tiered') const NamespaceDatastore = require('./namespace') const shard = require('./shard') +/** + * @typedef {import("./types").Shard } Shard + * @typedef {import("./types").KeyTransform } KeyTransform + */ + module.exports = { KeytransformDatastore, ShardingDatastore, diff --git a/src/keytransform.js b/src/keytransform.js index 970a462..cefc301 100644 --- a/src/keytransform.js +++ b/src/keytransform.js @@ -3,11 +3,11 @@ const { Adapter, utils } = require('interface-datastore') const map = utils.map /** - * @typedef {import('interface-datastore/dist/src/types').Datastore} Datastore - * @typedef {import('interface-datastore/dist/src/types').Options} Options - * @typedef {import('interface-datastore/dist/src/types').Batch} Batch - * @typedef {import('interface-datastore/dist/src/types')} Query - * @typedef {InstanceType} Key + * @typedef {import('interface-datastore').Datastore} Datastore + * @typedef {import('interface-datastore').Options} Options + * @typedef {import('interface-datastore').Batch} Batch + * @typedef {import('interface-datastore').Query} Query + * @typedef {import('interface-datastore').Key} Key * @typedef {import('./types').KeyTransform} KeyTransform */ diff --git a/src/mount.js b/src/mount.js index 0ec0de5..261ce98 100644 --- a/src/mount.js +++ b/src/mount.js @@ -13,15 +13,16 @@ const { const Keytransform = require('./keytransform') /** - * @typedef {import('interface-datastore/dist/src/types').Datastore} Datastore - * @typedef {import('interface-datastore/dist/src/types').Options} Options - * @typedef {import('interface-datastore/dist/src/types').Batch} Batch - * @typedef {import('interface-datastore/dist/src/types').Query} Query + * @typedef {import('interface-datastore').Datastore} Datastore + * @typedef {import('interface-datastore').Options} Options + * @typedef {import('interface-datastore').Batch} Batch + * @typedef {import('interface-datastore').Query} Query + * @typedef {import('interface-datastore').Pair} Pair */ /** - * @template TIterable - * @typedef {import('./types').AwaitIterable} AwaitIterable + * @template TEntry + * @typedef {import('./types').AwaitIterable} AwaitIterable */ /** @@ -204,9 +205,8 @@ class MountDatastore extends Adapter { } /** - * @template T - * @param {ArrayLike>} iterable - * @returns {AsyncIterable} + * @param {ArrayLike>} iterable + * @returns {AsyncIterable} */ function _many (iterable) { return (async function * () { diff --git a/src/namespace.js b/src/namespace.js index 669b08f..40dab31 100644 --- a/src/namespace.js +++ b/src/namespace.js @@ -3,10 +3,10 @@ const Key = require('interface-datastore').Key const KeytransformDatastore = require('./keytransform') /** - * @typedef {import('interface-datastore/dist/src/types').Datastore} Datastore - * @typedef {import('interface-datastore/dist/src/types').Query} Query - * @typedef {import('interface-datastore/dist/src/types').Options} Options - * @typedef {import('interface-datastore/dist/src/types').Batch} Batch + * @typedef {import('interface-datastore').Datastore} Datastore + * @typedef {import('interface-datastore').Query} Query + * @typedef {import('interface-datastore').Options} Options + * @typedef {import('interface-datastore').Batch} Batch * @typedef {import('./types').KeyTransform} KeyTransform */ diff --git a/src/shard.js b/src/shard.js index 17183c7..4b95edb 100644 --- a/src/shard.js +++ b/src/shard.js @@ -4,8 +4,8 @@ const { Key, utils: { utf8Decoder } } = require('interface-datastore') const readme = require('./shard-readme') /** + * @typedef {import('interface-datastore').Datastore} Datastore * @typedef {import('./types').Shard} Shard - * @typedef {import('interface-datastore/dist/src/types').Datastore} Datastore */ const PREFIX = '/repo/flatfs/shard/' diff --git a/src/sharding.js b/src/sharding.js index c82054b..1b80ff6 100644 --- a/src/sharding.js +++ b/src/sharding.js @@ -7,11 +7,11 @@ const KeytransformStore = require('./keytransform') const shardKey = new Key(sh.SHARDING_FN) const shardReadmeKey = new Key(sh.README_FN) /** - * @typedef {import('interface-datastore/dist/src/types').Datastore} Datastore - * @typedef {import('interface-datastore/dist/src/types').Options} Options - * @typedef {import('interface-datastore/dist/src/types').Batch} Batch - * @typedef {import('interface-datastore/dist/src/types').Query} Query - * @typedef {import('interface-datastore/dist/src/types').Pair} Pair + * @typedef {import('interface-datastore').Datastore} Datastore + * @typedef {import('interface-datastore').Options} Options + * @typedef {import('interface-datastore').Batch} Batch + * @typedef {import('interface-datastore').Query} Query + * @typedef {import('interface-datastore').Pair} Pair * @typedef {import('./types').Shard} Shard * */ @@ -174,7 +174,7 @@ class ShardingDatastore extends Adapter { } if (q.filters != null) { - // @ts-ignore + // @ts-ignore - can't find a way to easily type this const filters = q.filters.map((f) => (e) => { return f(Object.assign({}, e, { key: this._invertKey(e.key) diff --git a/src/tiered.js b/src/tiered.js index 649080b..d7eb6be 100644 --- a/src/tiered.js +++ b/src/tiered.js @@ -3,11 +3,11 @@ const { Adapter, Errors } = require('interface-datastore') const log = require('debug')('datastore:core:tiered') /** - * @typedef {import('interface-datastore/dist/src/types').Datastore} Datastore - * @typedef {import('interface-datastore/dist/src/types').Options} Options - * @typedef {import('interface-datastore/dist/src/types').Batch} Batch - * @typedef {import('interface-datastore/dist/src/types').Query} Query - * @typedef {InstanceType} Key + * @typedef {import('interface-datastore').Datastore} Datastore + * @typedef {import('interface-datastore').Options} Options + * @typedef {import('interface-datastore').Batch} Batch + * @typedef {import('interface-datastore').Query} Query + * @typedef {import('interface-datastore').Key} Key */ /** From 2aab333866712a082b37c9361f1a815a89644a89 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Sun, 17 Jan 2021 10:58:02 +0000 Subject: [PATCH 36/36] chore: remove gh url --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ce6d128..e59aa35 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ }, "dependencies": { "debug": "^4.1.1", - "interface-datastore": "ipfs/interface-datastore#chore/export-types-from-entrypoint" + "interface-datastore": "^3.0.1" }, "engines": { "node": ">=12.0.0"