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

Commit 9a6691c

Browse files
chore: move create-s3-repo to examples folder (#33)
* 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 <[email protected]>
1 parent 29423d1 commit 9a6691c

File tree

7 files changed

+32
-52
lines changed

7 files changed

+32
-52
lines changed

README.md

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# js-datastore-s3
1+
# js-datastore-s3 <!-- omit in toc -->
22

33
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](https://protocol.ai/)
44
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
@@ -9,13 +9,15 @@
99

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

15-
## Table of Contents
15+
## Table of Contents <!-- omit in toc -->
1616

1717
- [Install](#install)
1818
- [Usage](#usage)
19+
- [Create a Repo](#create-a-repo)
20+
- [Examples](#examples)
1921
- [Contribute](#contribute)
2022
- [License](#license)
2123

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

4143
### Create a Repo
42-
You can quickly create an S3 backed repo using the `createRepo` convenience function.
4344

44-
```js
45-
const IPFS = require('ipfs')
46-
const { createRepo } = require('datastore-s3')
47-
48-
const ipfs = new IPFS({
49-
repo: createRepo({
50-
path: '/my/ipfs'
51-
}, {
52-
bucket: 'MyS3Bucket'
53-
})
54-
})
55-
```
45+
See [examples/full-s3-repo](./examples/full-s3-repo) for how to quickly create an S3 backed repo using the `createRepo` convenience function.
5646

5747
### Examples
5848
You can see examples of S3 backed ipfs in the [examples folder](examples/)

src/s3-repo.js renamed to examples/full-s3-repo/create-s3-repo.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ const createRepo = (S3Store, options, s3Options) => {
4444
accessKeyId,
4545
secretAccessKey
4646
}),
47-
createIfMissing,
48-
sharding: true
47+
createIfMissing
4948
}
5049

5150
// If no lock is given, create a mock lock
@@ -60,11 +59,26 @@ const createRepo = (S3Store, options, s3Options) => {
6059
pins: S3Store
6160
},
6261
storageBackendOptions: {
63-
root: storeConfig,
64-
blocks: storeConfig,
65-
keys: storeConfig,
66-
datastore: storeConfig,
67-
pins: storeConfig
62+
root: {
63+
...storeConfig,
64+
sharding: false
65+
},
66+
blocks: {
67+
...storeConfig,
68+
sharding: true
69+
},
70+
keys: {
71+
...storeConfig,
72+
sharding: false
73+
},
74+
datastore: {
75+
...storeConfig,
76+
sharding: false
77+
},
78+
pins: {
79+
...storeConfig,
80+
sharding: true
81+
}
6882
},
6983
lock: lock
7084
})

examples/full-s3-repo/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict'
22

33
const IPFS = require('ipfs')
4-
const { createRepo } = require('datastore-s3')
54
const toBuffer = require('it-to-buffer')
5+
const createRepo = require('./create-s3-repo')
66

77
;(async () => {
88
// Create the repo

examples/full-s3-repo/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"author": "",
1111
"license": "ISC",
1212
"dependencies": {
13-
"aws-sdk": "^2.579.0",
13+
"aws-sdk": "^2.885.0",
1414
"datastore-s3": "../../",
15-
"ipfs": "^0.50.2",
16-
"ipfs-repo": "^6.0.3",
17-
"it-to-buffer": "^1.0.2"
15+
"ipfs": "^0.54.4",
16+
"ipfs-repo": "^9.0.0",
17+
"it-to-buffer": "^2.0.0"
1818
}
1919
}

package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@
4646
"aws-sdk": "^2.579.0",
4747
"chai": "^4.2.0",
4848
"dirty-chai": "^2.0.1",
49-
"ipfs-repo": "9.0.0",
5049
"stand-in": "^4.2.0",
5150
"util": "^0.12.3"
5251
},
53-
"peerDependencies": {
54-
"aws-sdk": "2.x",
55-
"ipfs-repo": "^9.0.0"
56-
},
5752
"contributors": [
5853
"Jacob Heun <[email protected]>",
5954
"achingbrain <[email protected]>",

src/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const {
77
Key,
88
Errors
99
} = require('interface-datastore')
10-
const createRepo = require('./s3-repo')
1110

1211
/**
1312
* @typedef {import('interface-datastore').Pair} Pair
@@ -268,6 +267,3 @@ class S3Datastore extends Adapter {
268267
}
269268

270269
module.exports = S3Datastore
271-
module.exports.createRepo = (...args) => {
272-
return createRepo(S3Datastore, ...args)
273-
}

test/index.spec.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const S3 = require('aws-sdk').S3
1313
const S3Mock = require('./utils/s3-mock')
1414
const { s3Resolve, s3Reject, S3Error } = S3Mock
1515
const S3Store = require('../src')
16-
const { createRepo } = require('../src')
1716

1817
describe('S3Datastore', () => {
1918
describe('construction', () => {
@@ -202,20 +201,6 @@ describe('S3Datastore', () => {
202201
})
203202
})
204203

205-
describe('createRepo', () => {
206-
it('should be able to create a repo', () => {
207-
const path = '.ipfs'
208-
const repo = createRepo({
209-
path
210-
}, {
211-
bucket: 'my-ipfs-bucket'
212-
})
213-
214-
expect(repo).to.exist()
215-
expect(repo.path).to.eql(path)
216-
})
217-
})
218-
219204
describe('interface-datastore', () => {
220205
require('interface-datastore/src/tests')({
221206
setup () {

0 commit comments

Comments
 (0)