Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
feat: ts types, github ci and clean up (#39)
Browse files Browse the repository at this point in the history
- add ts types with jsdocs and aegir
- remove travis and add github action
- update deps and repo clean up (readme, package.json, etc.. )

Co-authored-by: Vasco Santos <[email protected]>
Co-authored-by: Irakli Gozalishvili <[email protected]>
Co-authored-by: achingbrain <[email protected]>
  • Loading branch information
4 people authored Jan 21, 2021
1 parent 5c732be commit bee45ae
Show file tree
Hide file tree
Showing 20 changed files with 470 additions and 212 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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: npm install
- run: npx aegir lint
- uses: gozala/[email protected]
- run: npx aegir build
- run: npx aegir dep-check
- 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: npm install
- run: npx nyc --reporter=lcov aegir test -t node -- --bail
- uses: codecov/codecov-action@v1
test-chrome:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- 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: 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: 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: npm install
- run: npx xvfb-maybe aegir test -t electron-renderer --bail
42 changes: 0 additions & 42 deletions .travis.yml

This file was deleted.

32 changes: 12 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
# js-datastore-core
# js-datastore-core <!-- omit in toc -->

[![](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 <!-- omit in toc -->

[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 <!-- omit in toc -->

- [Implementations](#implementations)
- [Install](#install)
- [Usage](#usage)
- [Wrapping Stores](#wrapping-stores)
- [Contribute](#contribute)
- [License](#license)

## Implementations

Expand Down
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "datastore-core",
"version": "2.0.1",
"description": "Wrapper implmentation for interface-datastore",
"leadMaintainer": "Pedro Teixeira <pedro@protocol.ai>",
"description": "Wrapper implementation for interface-datastore",
"leadMaintainer": "Alex Potsides <alex.potsides@protocol.ai>",
"main": "src/index.js",
"types": "dist/src/index.d.ts",
"scripts": {
"prepare": "aegir build --no-bundle",
"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",
Expand Down Expand Up @@ -38,19 +39,19 @@
},
"homepage": "https://github.com/ipfs/js-datastore-core#readme",
"devDependencies": {
"aegir": "^28.1.0",
"async-iterator-all": "^1.0.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1"
"@types/debug": "^4.1.5",
"aegir": "^30.3.0",
"it-all": "^1.0.4"
},
"dependencies": {
"debug": "^4.1.1",
"interface-datastore": "^2.0.0",
"ipfs-utils": "^4.0.1"
"interface-datastore": "^3.0.1"
},
"engines": {
"node": ">=6.0.0",
"npm": ">=3.0.0"
"node": ">=12.0.0"
},
"eslintConfig": {
"extends": "ipfs"
},
"contributors": [
"achingbrain <[email protected]>",
Expand Down
19 changes: 13 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ 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
/**
* @typedef {import("./types").Shard } Shard
* @typedef {import("./types").KeyTransform } KeyTransform
*/

module.exports = {
KeytransformDatastore,
ShardingDatastore,
MountDatastore,
TieredDatastore,
NamespaceDatastore,
shard
}
38 changes: 38 additions & 0 deletions src/keytransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@

const { Adapter, utils } = require('interface-datastore')
const map = utils.map
/**
* @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
*/

/**
* 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()

Expand All @@ -20,22 +34,42 @@ class KeyTransformDatastore extends Adapter {
return this.child.open()
}

/**
* @param {Key} key
* @param {Uint8Array} val
* @param {Options} [options]
*/
put (key, val, options) {
return this.child.put(this.transform.convert(key), val, options)
}

/**
* @param {Key} key
* @param {Options} [options]
*/
get (key, options) {
return this.child.get(this.transform.convert(key), options)
}

/**
* @param {Key} key
* @param {Options} [options]
*/
has (key, options) {
return this.child.has(this.transform.convert(key), options)
}

/**
* @param {Key} key
* @param {Options} [options]
*/
delete (key, options) {
return this.child.delete(this.transform.convert(key), options)
}

/**
* @returns {Batch}
*/
batch () {
const b = this.child.batch()
return {
Expand All @@ -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)
Expand Down
Loading

0 comments on commit bee45ae

Please sign in to comment.