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

Commit

Permalink
chore: move create-s3-repo to examples folder (#33)
Browse files Browse the repository at this point in the history
* 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.

* chore: update readme

* chore: also do not shard all the datastores by default

* docs: remove code example for createRepo

Co-authored-by: Jacob Heun <jacobheun@gmail.com>
  • Loading branch information
achingbrain and jacobheun authored Apr 15, 2021
1 parent 29423d1 commit 9a6691c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 52 deletions.
22 changes: 6 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# js-datastore-s3
# js-datastore-s3 <!-- omit in toc -->

[![](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/)
Expand All @@ -9,13 +9,15 @@

> Datastore implementation backed by s3.
## Lead Maintainer
## Lead Maintainer <!-- omit in toc -->
[Jacob Heun](https://github.com/jacobheun)

## Table of Contents
## Table of Contents <!-- omit in toc -->

- [Install](#install)
- [Usage](#usage)
- [Create a Repo](#create-a-repo)
- [Examples](#examples)
- [Contribute](#contribute)
- [License](#license)

Expand All @@ -39,20 +41,8 @@ const store = new S3Store('.ipfs/datastore', {
```

### Create a Repo
You can 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'
})
})
```
See [examples/full-s3-repo](./examples/full-s3-repo) for how to quickly create an S3 backed repo using the `createRepo` convenience function.

### Examples
You can see examples of S3 backed ipfs in the [examples folder](examples/)
Expand Down
28 changes: 21 additions & 7 deletions src/s3-repo.js → examples/full-s3-repo/create-s3-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ const createRepo = (S3Store, options, s3Options) => {
accessKeyId,
secretAccessKey
}),
createIfMissing,
sharding: true
createIfMissing
}

// If no lock is given, create a mock lock
Expand All @@ -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
})
Expand Down
2 changes: 1 addition & 1 deletion examples/full-s3-repo/index.js
Original file line number Diff line number Diff line change
@@ -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
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 @@ -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"
}
}
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,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 <jacobheun@gmail.com>",
"achingbrain <alex@achingbrain.net>",
Expand Down
4 changes: 0 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const {
Key,
Errors
} = require('interface-datastore')
const createRepo = require('./s3-repo')

/**
* @typedef {import('interface-datastore').Pair} Pair
Expand Down Expand Up @@ -268,6 +267,3 @@ class S3Datastore extends Adapter {
}

module.exports = S3Datastore
module.exports.createRepo = (...args) => {
return createRepo(S3Datastore, ...args)
}
15 changes: 0 additions & 15 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 9a6691c

Please sign in to comment.