From 4e334976af956445d9c0d6dc783cf444d1d949ed Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 13 Apr 2021 15:15:55 +0100 Subject: [PATCH 1/4] chore: move create-s3-repo to examples folder The `createRepo` convenience function has a dependency on `ipfs-repo` which can create weird dependency loops. Instead have it as an example of how to use this module then the user can copy it to their codebase and also becomes in charge of which version of `ipfs-repo` they use. --- README.md | 16 +++++++++++----- .../full-s3-repo/create-s3-repo.js | 0 examples/full-s3-repo/index.js | 2 +- examples/full-s3-repo/package.json | 8 ++++---- package.json | 5 ----- src/index.js | 5 ----- test/index.spec.js | 15 --------------- 7 files changed, 16 insertions(+), 35 deletions(-) rename src/s3-repo.js => examples/full-s3-repo/create-s3-repo.js (100%) diff --git a/README.md b/README.md index e777b06..3da719a 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,15 @@ ## Table of Contents -- [Install](#install) -- [Usage](#usage) -- [Contribute](#contribute) -- [License](#license) +- [js-datastore-s3](#js-datastore-s3) + - [Lead Maintainer](#lead-maintainer) + - [Table of Contents](#table-of-contents) + - [Install](#install) + - [Usage](#usage) + - [Create a Repo](#create-a-repo) + - [Examples](#examples) + - [Contribute](#contribute) + - [License](#license) ## Install @@ -39,7 +44,8 @@ const store = new S3Store('.ipfs/datastore', { ``` ### Create a Repo -You can quickly create an S3 backed repo using the `createRepo` convenience function. + +See [examples/full-s3-repo](./examples/full-s3-repo) for how to quickly create an S3 backed repo using the `createRepo` convenience function. ```js const IPFS = require('ipfs') diff --git a/src/s3-repo.js b/examples/full-s3-repo/create-s3-repo.js similarity index 100% rename from src/s3-repo.js rename to examples/full-s3-repo/create-s3-repo.js diff --git a/examples/full-s3-repo/index.js b/examples/full-s3-repo/index.js index e251c24..5942148 100644 --- a/examples/full-s3-repo/index.js +++ b/examples/full-s3-repo/index.js @@ -1,8 +1,8 @@ 'use strict' const IPFS = require('ipfs') -const { createRepo } = require('datastore-s3') const toBuffer = require('it-to-buffer') +const createRepo = require('./create-s3-repo') ;(async () => { // Create the repo diff --git a/examples/full-s3-repo/package.json b/examples/full-s3-repo/package.json index 7e9619e..59ce9ff 100644 --- a/examples/full-s3-repo/package.json +++ b/examples/full-s3-repo/package.json @@ -10,10 +10,10 @@ "author": "", "license": "ISC", "dependencies": { - "aws-sdk": "^2.579.0", + "aws-sdk": "^2.885.0", "datastore-s3": "../../", - "ipfs": "^0.50.2", - "ipfs-repo": "^6.0.3", - "it-to-buffer": "^1.0.2" + "ipfs": "^0.54.4", + "ipfs-repo": "^9.0.0", + "it-to-buffer": "^2.0.0" } } diff --git a/package.json b/package.json index 8e0e311..404566a 100644 --- a/package.json +++ b/package.json @@ -45,14 +45,9 @@ "aws-sdk": "^2.579.0", "chai": "^4.2.0", "dirty-chai": "^2.0.1", - "ipfs-repo": "9.0.0", "stand-in": "^4.2.0", "util": "^0.12.3" }, - "peerDependencies": { - "aws-sdk": "2.x", - "ipfs-repo": "^9.0.0" - }, "contributors": [ "Jacob Heun ", "achingbrain ", diff --git a/src/index.js b/src/index.js index 160a87a..2c2eaf4 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,6 @@ 'use strict' const { Buffer } = require('buffer') - const { Adapter, Key, @@ -10,7 +9,6 @@ const { filter } } = require('interface-datastore') -const createRepo = require('./s3-repo') /** * A datastore backed by the file system. @@ -254,6 +252,3 @@ class S3Datastore extends Adapter { } module.exports = S3Datastore -module.exports.createRepo = (...args) => { - return createRepo(S3Datastore, ...args) -} diff --git a/test/index.spec.js b/test/index.spec.js index 22de60a..d2eceb8 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -13,7 +13,6 @@ const S3 = require('aws-sdk').S3 const S3Mock = require('./utils/s3-mock') const { s3Resolve, s3Reject, S3Error } = S3Mock const S3Store = require('../src') -const { createRepo } = require('../src') describe('S3Datastore', () => { describe('construction', () => { @@ -202,20 +201,6 @@ describe('S3Datastore', () => { }) }) - describe('createRepo', () => { - it('should be able to create a repo', () => { - const path = '.ipfs' - const repo = createRepo({ - path - }, { - bucket: 'my-ipfs-bucket' - }) - - expect(repo).to.exist() - expect(repo.path).to.eql(path) - }) - }) - describe('interface-datastore', () => { require('interface-datastore/src/tests')({ setup () { From b49e1a9249ac1919d83fafe8c0fc1efb26c45eda Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 13 Apr 2021 15:19:34 +0100 Subject: [PATCH 2/4] chore: update readme --- README.md | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3da719a..aac11c2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# js-datastore-s3 +# js-datastore-s3 [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](https://protocol.ai/) [![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) @@ -9,20 +9,17 @@ > Datastore implementation backed by s3. -## Lead Maintainer +## Lead Maintainer [Jacob Heun](https://github.com/jacobheun) -## Table of Contents - -- [js-datastore-s3](#js-datastore-s3) - - [Lead Maintainer](#lead-maintainer) - - [Table of Contents](#table-of-contents) - - [Install](#install) - - [Usage](#usage) - - [Create a Repo](#create-a-repo) - - [Examples](#examples) - - [Contribute](#contribute) - - [License](#license) +## Table of Contents + +- [Install](#install) +- [Usage](#usage) + - [Create a Repo](#create-a-repo) + - [Examples](#examples) +- [Contribute](#contribute) +- [License](#license) ## Install From faae144a0ea154a52f23a91c2c9c735caa8e4a33 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 13 Apr 2021 17:11:28 +0100 Subject: [PATCH 3/4] chore: also do not shard all the datastores by default --- examples/full-s3-repo/create-s3-repo.js | 28 ++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/examples/full-s3-repo/create-s3-repo.js b/examples/full-s3-repo/create-s3-repo.js index 3013fde..5530532 100644 --- a/examples/full-s3-repo/create-s3-repo.js +++ b/examples/full-s3-repo/create-s3-repo.js @@ -44,8 +44,7 @@ const createRepo = (S3Store, options, s3Options) => { accessKeyId, secretAccessKey }), - createIfMissing, - sharding: true + createIfMissing } // If no lock is given, create a mock lock @@ -60,11 +59,26 @@ const createRepo = (S3Store, options, s3Options) => { pins: S3Store }, storageBackendOptions: { - root: storeConfig, - blocks: storeConfig, - keys: storeConfig, - datastore: storeConfig, - pins: storeConfig + root: { + ...storeConfig, + sharding: false + }, + blocks: { + ...storeConfig, + sharding: true + }, + keys: { + ...storeConfig, + sharding: false + }, + datastore: { + ...storeConfig, + sharding: false + }, + pins: { + ...storeConfig, + sharding: true + } }, lock: lock }) From e4d2dd2c7fdc77571f52d2dca187ff3d6d542b91 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Thu, 15 Apr 2021 16:09:01 +0200 Subject: [PATCH 4/4] docs: remove code example for createRepo --- README.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/README.md b/README.md index aac11c2..60658b3 100644 --- a/README.md +++ b/README.md @@ -44,19 +44,6 @@ const store = new S3Store('.ipfs/datastore', { See [examples/full-s3-repo](./examples/full-s3-repo) for how to quickly create an S3 backed repo using the `createRepo` convenience function. -```js -const IPFS = require('ipfs') -const { createRepo } = require('datastore-s3') - -const ipfs = new IPFS({ - repo: createRepo({ - path: '/my/ipfs' - }, { - bucket: 'MyS3Bucket' - }) -}) -``` - ### Examples You can see examples of S3 backed ipfs in the [examples folder](examples/)