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

chore: switch to esm #37

Merged
merged 3 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
69 changes: 69 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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/typescript-error-reporter-action@v1.0.8
- 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: [14, 16]
fail-fast: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npx aegir test -t node --cov --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: npm run pretest
- run: npx xvfb-maybe aegir test -t electron-main --bail -f dist/cjs/node-test/*js
test-electron-renderer:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npm run pretest
- run: npx xvfb-maybe aegir test -t electron-renderer --bail -f dist/cjs/browser-test/*js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ node_modules
lib
dist
docs
types
48 changes: 0 additions & 48 deletions .travis.yml

This file was deleted.

5 changes: 5 additions & 0 deletions LICENSE-APACHE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
12 changes: 5 additions & 7 deletions LICENSE → LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
MIT License

Copyright (c) 2017 IPFS
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -9,13 +7,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ $ npm install datastore-s3
If the flag `createIfMissing` is not set or is false, then the bucket must be created prior to using datastore-s3. Please see the AWS docs for information on how to configure the S3 instance. A bucket name is required to be set at the s3 instance level, see the below example.

```js
const S3 = require('aws-sdk').S3
import S3 from 'aws-sdk/clients/s3.js'
import { S3Datastore } from 'datastore-s3'

const s3Instance = new S3({ params: { Bucket: 'my-ipfs-bucket' } })
const S3Store = require('datastore-s3')
const store = new S3Store('.ipfs/datastore', {
const store = new S3Datastore('.ipfs/datastore', {
s3: s3Instance
createIfMissing: false
})
Expand All @@ -55,4 +56,4 @@ Small note: If editing the Readme, please conform to the [standard-readme](https

## License

MIT 2018 © IPFS
[Apache-2.0](LICENSE-APACHE) OR [MIT](LICENSE-MIT)
41 changes: 23 additions & 18 deletions examples/full-s3-repo/create-s3-repo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
'use strict'
import { S3Datastore } from 'datastore-s3'
import { createRepo } from 'ipfs-repo'
import { BlockstoreDatastoreAdapter } from 'blockstore-datastore-adapter'
import { ShardingDatastore } from 'datastore-core/sharding'
import { NextToLast } from 'datastore-core/shard'
import * as raw from 'multiformats/codecs/raw'
import * as json from 'multiformats/codecs/json'
import * as dagPb from '@ipld/dag-pb'
import * as dagCbor from '@ipld/dag-cbor'


const DatastoreS3 = require('datastore-s3')
const { createRepo } = require('ipfs-repo')
const BlockstoreDatastoreAdapter = require('blockstore-datastore-adapter')
const { ShardingDatastore, shard: { NextToLast } } = require('datastore-core')
const { codecs: { raw, json } } = require('multiformats/basics')
const dagPb = require('@ipld/dag-pb')
const dagCbor = require('@ipld/dag-cbor')
/**
* @typedef {import('multiformats/codecs/interface').BlockCodec<any, any>} BlockCodec
*/

/**
* A convenience method for creating an S3 backed IPFS repo
Expand All @@ -16,13 +19,17 @@ const dagCbor = require('@ipld/dag-cbor')
* @param {import('aws-sdk/clients/s3')} s3
* @param {import('ipfs-repo').RepoLock} repoLock
*/
const createS3Repo = (path, s3, repoLock) => {
export const createS3Repo = (path, s3, repoLock) => {
const storeConfig = {
s3,
createIfMissing: true
}

// These are the codecs we want to support, you may wish to add others
/**
* These are the codecs we want to support, you may wish to add others
*
* @type {Record<string | number, BlockCodec>}
*/
const codecs = {
[raw.code]: raw,
[raw.name]: raw,
Expand All @@ -47,30 +54,28 @@ const createS3Repo = (path, s3, repoLock) => {

return createRepo(path, loadCodec, {
root: new ShardingDatastore(
new DatastoreS3(path, storeConfig),
new S3Datastore(path, storeConfig),
new NextToLast(2)
),
blocks: new BlockstoreDatastoreAdapter(
new ShardingDatastore(
new DatastoreS3(`${path}blocks`, storeConfig),
new S3Datastore(`${path}blocks`, storeConfig),
new NextToLast(2)
)
),
datastore: new ShardingDatastore(
new DatastoreS3(`${path}datastore`, storeConfig),
new S3Datastore(`${path}datastore`, storeConfig),
new NextToLast(2)
),
keys: new ShardingDatastore(
new DatastoreS3(`${path}keys`, storeConfig),
new S3Datastore(`${path}keys`, storeConfig),
new NextToLast(2)
),
pins: new ShardingDatastore(
new DatastoreS3(`${path}pins`, storeConfig),
new S3Datastore(`${path}pins`, storeConfig),
new NextToLast(2)
)
}, {
repoLock
})
}

module.exports = createS3Repo
14 changes: 6 additions & 8 deletions examples/full-s3-repo/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
'use strict'

const IPFS = require('ipfs')
const toBuffer = require('it-to-buffer')
const createRepo = require('./create-s3-repo')
const S3 = require('aws-sdk/clients/s3')
const S3Lock = require('./s3-lock')
import IPFS from 'ipfs-core'
import toBuffer from 'it-to-buffer'
import { createS3Repo } from './create-s3-repo'
import S3 from 'aws-sdk/clients/s3.js'
import { S3Lock } from './s3-lock'

async function main () {
// Configure S3 as normal
Expand All @@ -22,7 +20,7 @@ async function main () {
const repoLock = new S3Lock(s3)

// Create the repo
const s3Repo = createRepo('/', s3, repoLock)
const s3Repo = createS3Repo('/', s3, repoLock)

// Create a new IPFS node with our S3 backed Repo
console.log('Start ipfs')
Expand Down
8 changes: 4 additions & 4 deletions examples/full-s3-repo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"@ipld/dag-cbor": "^6.0.9",
"@ipld/dag-pb": "^2.1.9",
"aws-sdk": "^2.885.0",
"blockstore-datastore-adapter": "^1.0.0",
"datastore-core": "^5.0.1",
"blockstore-datastore-adapter": "^2.0.1",
"datastore-core": "^6.0.6",
"datastore-s3": "../../",
"ipfs": "^0.58.1",
"ipfs-repo": "^11.0.1",
"ipfs-core": "^0.10.6",
"ipfs-repo": "^12.0.0",
"it-to-buffer": "^2.0.0",
"multiformats": "^9.4.5"
}
Expand Down
8 changes: 3 additions & 5 deletions examples/full-s3-repo/s3-lock.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const PATH = require('path')
const { fromString: uint8ArrayFromString } = require('uint8arrays')
import PATH from 'path'
import { fromString as uint8ArrayFromString } from 'uint8arrays'

/**
* Uses an object in an S3 bucket as a lock to signal that an IPFS repo is in use.
Expand All @@ -13,7 +13,7 @@ const { fromString: uint8ArrayFromString } = require('uint8arrays')
* @typedef {import('ipfs-repo').LockCloser} LockCloser
*/

class S3Lock {
export class S3Lock {
/**
* @param {import('aws-sdk/clients/s3')} s3
*/
Expand Down Expand Up @@ -153,5 +153,3 @@ class S3Lock {
return true
}
}

module.exports = S3Lock
40 changes: 27 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@
"description": "IPFS datastore implementation backed by s3",
"leadMaintainer": "Jacob Heun<jacobheun@gmail.com>",
"main": "src/index.js",
"types": "dist/src/index.d.ts",
"type": "module",
"types": "types/src/index.d.ts",
"files": [
"dist",
"src"
"*",
"!**/*.tsbuildinfo"
],
"exports": {
".": {
"import": "./src/index.js"
}
},
"scripts": {
"clean": "rimraf dist types",
"prepare": "aegir build --no-bundle && cp -R types dist",
"lint": "aegir ts -p check && aegir lint",
"build": "aegir build",
"release": "aegir release --target node",
"release-minor": "aegir release --type minor --target node",
"release-major": "aegir release --type major --target node",
"pretest": "aegir build --esm-tests",
"test": "aegir test",
"test:node": "aegir test --target node",
"release": "aegir release --target node --docs",
"release-minor": "aegir release --type minor --target node --docs",
"release-major": "aegir release --type major --target node --docs",
"coverage": "nyc --reporter=text --reporter=lcov npm run test:node",
"docs": "aegir docs"
"dep-check": "aegir dep-check -i rimraf"
},
"repository": {
"type": "git",
Expand All @@ -30,15 +38,21 @@
"datastore",
"s3"
],
"license": "MIT",
"license": "(Apache-2.0 OR MIT)",
"bugs": {
"url": "https://github.com/ipfs/js-datastore-s3/issues"
},
"homepage": "https://github.com/ipfs/js-datastore-s3#readme",
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
"sourceType": "module"
}
},
"dependencies": {
"buffer": "^6.0.3",
"datastore-core": "^5.0.0",
"interface-datastore": "^5.1.1",
"datastore-core": "^6.0.5",
"interface-datastore": "^6.0.2",
"it-filter": "^1.0.2",
"it-to-buffer": "^2.0.0",
"uint8arrays": "^3.0.0"
Expand All @@ -47,7 +61,7 @@
"aegir": "^35.0.2",
"assert": "^2.0.0",
"aws-sdk": "^2.579.0",
"interface-datastore-tests": "^1.0.0",
"interface-datastore-tests": "^2.0.3",
"sinon": "^11.1.2",
"util": "^0.12.3"
},
Expand Down
Loading