Skip to content

Commit

Permalink
fix: cleanup references to datastore in blockstores (#274)
Browse files Browse the repository at this point in the history
Docs code comments and specs refer to datastores within blockstore packages.

Theres also as small change to an error and exported type e3302b6

---------

Co-authored-by: aegir[bot] <aegir[bot]@users.noreply.github.com>
Co-authored-by: Alex Potsides <alex@achingbrain.net>
  • Loading branch information
3 people committed Dec 1, 2023
1 parent be4f27d commit f550624
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/blockstore-core/test/tiered.spec.ts
Expand Up @@ -54,7 +54,7 @@ describe('Tiered', () => {
})
})

describe('inteface-datastore-single', () => {
describe('inteface-blockstore-single', () => {
interfaceBlockstoreTests({
setup () {
return new TieredBlockstore([
Expand Down
2 changes: 1 addition & 1 deletion packages/blockstore-fs/src/index.ts
Expand Up @@ -257,7 +257,7 @@ export class FsBlockstore implements Blockstore {

yield pair
} catch (err: any) {
// if keys are removed from the datastore while the query is
// if keys are removed from the blockstore while the query is
// running, we may encounter missing files.
if (err.code !== 'ENOENT') {
throw err
Expand Down
4 changes: 2 additions & 2 deletions packages/blockstore-idb/src/index.ts
Expand Up @@ -25,7 +25,7 @@ import type { Pair } from 'interface-blockstore'
import type { AbortOptions, AwaitIterable } from 'interface-store'
import type { MultibaseCodec } from 'multiformats/bases/interface'

export interface IDBDatastoreInit {
export interface IDBBlockstoreInit {
/**
* A prefix to use for all database keys (default: '')
*/
Expand All @@ -49,7 +49,7 @@ export class IDBBlockstore extends BaseBlockstore {
private db?: IDBPDatabase
private readonly base: MultibaseCodec<string>

constructor (location: string, init: IDBDatastoreInit = {}) {
constructor (location: string, init: IDBBlockstoreInit = {}) {
super()

this.location = `${init.prefix ?? ''}${location}`
Expand Down
2 changes: 1 addition & 1 deletion packages/blockstore-level/src/index.ts
Expand Up @@ -34,7 +34,7 @@ export interface LevelBlockstoreInit extends DatabaseOptions<string, Uint8Array>
}

/**
* A datastore backed by leveldb
* A blockstore backed by leveldb
*/
export class LevelBlockstore extends BaseBlockstore {
public db: Level<string, Uint8Array>
Expand Down
2 changes: 1 addition & 1 deletion packages/blockstore-level/test/node.ts
Expand Up @@ -7,7 +7,7 @@ import { interfaceBlockstoreTests } from 'interface-blockstore-tests'
import tempdir from 'ipfs-utils/src/temp-dir.js'
import { LevelBlockstore } from '../src/index.js'

describe('LevelDatastore', () => {
describe('LevelBlockstore', () => {
describe('interface-blockstore (leveldown)', () => {
interfaceBlockstoreTests({
async setup () {
Expand Down
18 changes: 13 additions & 5 deletions packages/blockstore-s3/README.md
Expand Up @@ -14,14 +14,22 @@ A Blockstore implementation that stores blocks on Amazon S3.
If the flag `createIfMissing` is not set or is false, then the bucket must be created prior to using blockstore-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
import S3 from 'aws-sdk/clients/s3.js'
import { S3 } from '@aws-sdk/client-s3'
import { S3Blockstore } from 'blockstore-s3'

const s3Instance = new S3({ params: { Bucket: 'my-ipfs-bucket' } })
const store = new S3Blockstore('.ipfs/datastore', {
s3: s3Instance
createIfMissing: false
const s3 = new S3({
region: 'region',
credentials: {
accessKeyId: 'myaccesskey',
secretAccessKey: 'mysecretkey'
}
})

const store = new S3Blockstore(
s3,
'my-bucket',
{ createIfMissing: false }
)
```

## Example
Expand Down
4 changes: 2 additions & 2 deletions packages/blockstore-s3/examples/helia/README.md
@@ -1,7 +1,7 @@
Use with Helia
======

This example uses a Datastore S3 instance to serve as the entire backend for Helia.
This example uses a Blockstore S3 instance to serve as the entire backend for Helia.

## Running
The S3 parameters must be updated with an existing Bucket and credentials with access to it:
Expand All @@ -15,7 +15,7 @@ const s3 = new S3({
}
})

const datastore = new DatastoreS3(s3, 'my-bucket')
const blockstore = new BlockstoreS3(s3, 'my-bucket')
```

Once the S3 instance has its needed data, you can run the example:
Expand Down
6 changes: 3 additions & 3 deletions packages/blockstore-s3/examples/helia/index.js
Expand Up @@ -2,7 +2,7 @@ import { createHelia } from 'helia'
import { unixfs } from '@helia/unixfs'
import toBuffer from 'it-to-buffer'
import { S3 } from '@aws-sdk/client-s3'
import { DatastoreS3 } from 'datastore-s3'
import { BlockstoreS3 } from 'blockstore-s3'

async function main () {
// Configure S3 as normal
Expand All @@ -14,12 +14,12 @@ async function main () {
}
})

const datastore = new DatastoreS3(s3, 'my-bucket')
const blockstore = new BlockstoreS3(s3, 'my-bucket')

// Create a new Helia node with our S3 backed Repo
console.log('Start Helia')
const node = await createHelia({
datastore
blockstore
})

// Test out the repo by sending and fetching some data
Expand Down
2 changes: 1 addition & 1 deletion packages/blockstore-s3/examples/helia/package.json
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@aws-sdk/client-s3": "^3.297.0",
"@helia/unixfs": "^1.2.0",
"datastore-s3": "../../",
"blockstore-s3": "../../",
"helia": "^1.0.0",
"it-to-buffer": "^3.0.1"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/blockstore-s3/package.json
Expand Up @@ -12,7 +12,7 @@
"url": "https://github.com/ipfs/js-stores/issues"
},
"keywords": [
"datastore",
"blockstore",
"interface",
"ipfs",
"key-value",
Expand Down
18 changes: 13 additions & 5 deletions packages/blockstore-s3/src/index.ts
Expand Up @@ -8,14 +8,22 @@
* If the flag `createIfMissing` is not set or is false, then the bucket must be created prior to using blockstore-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
* import S3 from 'aws-sdk/clients/s3.js'
* import { S3 } from '@aws-sdk/client-s3'
* import { S3Blockstore } from 'blockstore-s3'
*
* const s3Instance = new S3({ params: { Bucket: 'my-ipfs-bucket' } })
* const store = new S3Blockstore('.ipfs/datastore', {
* s3: s3Instance
* createIfMissing: false
* const s3 = new S3({
* region: 'region',
* credentials: {
* accessKeyId: 'myaccesskey',
* secretAccessKey: 'mysecretkey'
* }
* })
*
* const store = new S3Blockstore(
* s3,
* 'my-bucket',
* { createIfMissing: false }
* )
* ```
*
* @example Using with Helia
Expand Down
2 changes: 1 addition & 1 deletion packages/blockstore-s3/test/utils/s3-mock.ts
Expand Up @@ -26,7 +26,7 @@ export const s3Reject = <T> (err: T): any => {
}

/**
* Mocks out the s3 calls made by datastore-s3
* Mocks out the s3 calls made by blockstore-s3
*/
export function s3Mock (s3: S3): S3 {
const mocks: any = {}
Expand Down
2 changes: 1 addition & 1 deletion packages/datastore-idb/src/index.ts
Expand Up @@ -96,7 +96,7 @@ export class IDBDatastore extends BaseDatastore {

async has (key: Key): Promise<boolean> {
if (this.db == null) {
throw new Error('Blockstore needs to be opened.')
throw new Error('Datastore needs to be opened.')
}

try {
Expand Down
18 changes: 13 additions & 5 deletions packages/datastore-s3/README.md
Expand Up @@ -14,14 +14,22 @@ A Datastore implementation that stores data on Amazon 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
import S3 from 'aws-sdk/clients/s3.js'
import { S3 } from '@aws-sdk/client-s3'
import { S3Datastore } from 'datastore-s3'

const s3Instance = new S3({ params: { Bucket: 'my-ipfs-bucket' } })
const store = new S3Datastore('.ipfs/datastore', {
s3: s3Instance
createIfMissing: false
const s3 = new S3({
region: 'region',
credentials: {
accessKeyId: 'myaccesskey',
secretAccessKey: 'mysecretkey'
}
})

const store = new S3Datastore(
s3,
'my-bucket',
{ path: '.ipfs/datastore', createIfMissing: false }
)
```

## Example
Expand Down
18 changes: 13 additions & 5 deletions packages/datastore-s3/src/index.ts
Expand Up @@ -8,14 +8,22 @@
* 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
* import S3 from 'aws-sdk/clients/s3.js'
* import { S3 } from '@aws-sdk/client-s3'
* import { S3Datastore } from 'datastore-s3'
*
* const s3Instance = new S3({ params: { Bucket: 'my-ipfs-bucket' } })
* const store = new S3Datastore('.ipfs/datastore', {
* s3: s3Instance
* createIfMissing: false
* const s3 = new S3({
* region: 'region',
* credentials: {
* accessKeyId: 'myaccesskey',
* secretAccessKey: 'mysecretkey'
* }
* })
*
* const store = new S3Datastore(
* s3,
* 'my-bucket',
* { path: '.ipfs/datastore', createIfMissing: false }
* )
* ```
*
* @example Using with Helia
Expand Down

0 comments on commit f550624

Please sign in to comment.