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

chore: rename for consistency #104

Merged
merged 1 commit 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
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function writeFile (path, contents) {
*
* @implements {Datastore}
*/
export class DatastoreFs extends BaseDatastore {
export class FsDatastore extends BaseDatastore {
/**
* @param {string} location
* @param {{ createIfMissing?: boolean, errorIfExists?: boolean, extension?: string, putManyConcurrency?: number } | undefined} [opts]
Expand Down
32 changes: 16 additions & 16 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { Key } from 'interface-datastore'
import { ShardingDatastore, shard } from 'datastore-core'
import { isNode, isElectronMain } from 'ipfs-utils/src/env.js'
import { interfaceDatastoreTests } from 'interface-datastore-tests'
import { DatastoreFs } from '../src/index.js'
import { FsDatastore } from '../src/index.js'
import tempdir from 'ipfs-utils/src/temp-dir.js'

const rimraf = promisify(rmrf)
const utf8Encoder = new TextEncoder()

describe('DatastoreFs', () => {
describe('FsDatastore', () => {
if (!(isNode || isElectronMain)) {
it('only supports node.js and electron main', () => {

Expand All @@ -28,23 +28,23 @@ describe('DatastoreFs', () => {
it('defaults - folder missing', () => {
const dir = tempdir()
expect(
() => new DatastoreFs(dir)
() => new FsDatastore(dir)
).to.not.throw()
})

it('defaults - folder exists', () => {
const dir = tempdir()
mkdirp.sync(dir)
expect(
() => new DatastoreFs(dir)
() => new FsDatastore(dir)
).to.not.throw()
})
})

describe('open', () => {
it('createIfMissing: false - folder missing', () => {
const dir = tempdir()
const store = new DatastoreFs(dir, { createIfMissing: false })
const store = new FsDatastore(dir, { createIfMissing: false })
expect(
() => store.open()
).to.throw()
Expand All @@ -53,7 +53,7 @@ describe('DatastoreFs', () => {
it('errorIfExists: true - folder exists', () => {
const dir = tempdir()
mkdirp.sync(dir)
const store = new DatastoreFs(dir, { errorIfExists: true })
const store = new FsDatastore(dir, { errorIfExists: true })
expect(
() => store.open()
).to.throw()
Expand All @@ -62,7 +62,7 @@ describe('DatastoreFs', () => {

it('_encode and _decode', () => {
const dir = tempdir()
const fs = new DatastoreFs(dir)
const fs = new FsDatastore(dir)

expect(
// @ts-ignore
Expand All @@ -82,7 +82,7 @@ describe('DatastoreFs', () => {

it('deleting files', async () => {
const dir = tempdir()
const fs = new DatastoreFs(dir)
const fs = new FsDatastore(dir)
const key = new Key('1234')

await fs.put(key, Uint8Array.from([0, 1, 2, 3]))
Expand All @@ -98,7 +98,7 @@ describe('DatastoreFs', () => {

it('deleting non-existent files', async () => {
const dir = tempdir()
const fs = new DatastoreFs(dir)
const fs = new FsDatastore(dir)
const key = new Key('5678')

await fs.delete(key)
Expand All @@ -113,7 +113,7 @@ describe('DatastoreFs', () => {

it('sharding files', async () => {
const dir = tempdir()
const fstore = new DatastoreFs(dir)
const fstore = new FsDatastore(dir)
await ShardingDatastore.create(fstore, new shard.NextToLast(2))

const file = await fs.promises.readFile(path.join(dir, shard.SHARDING_FN))
Expand All @@ -125,7 +125,7 @@ describe('DatastoreFs', () => {
})

it('query', async () => {
const fs = new DatastoreFs(path.join(process.cwd(), '/test/test-repo/blocks'))
const fs = new FsDatastore(path.join(process.cwd(), '/test/test-repo/blocks'))
const res = []
for await (const q of fs.query({})) {
res.push(q)
Expand All @@ -135,7 +135,7 @@ describe('DatastoreFs', () => {

it('interop with go', async () => {
const repodir = path.join(process.cwd(), '/test/test-repo/blocks')
const fstore = new DatastoreFs(repodir)
const fstore = new FsDatastore(repodir)
const key = new Key('CIQGFTQ7FSI2COUXWWLOQ45VUM2GUZCGAXLWCTOKKPGTUWPXHBNIVOY')
const expected = fs.readFileSync(path.join(repodir, 'VO', key.toString() + '.data'))
const flatfs = await ShardingDatastore.open(fstore)
Expand All @@ -152,7 +152,7 @@ describe('DatastoreFs', () => {

interfaceDatastoreTests({
setup: () => {
return new DatastoreFs(dir)
return new FsDatastore(dir)
},
teardown: () => {
return rimraf(dir)
Expand All @@ -165,7 +165,7 @@ describe('DatastoreFs', () => {

interfaceDatastoreTests({
setup: () => {
return new ShardingDatastore(new DatastoreFs(dir), new shard.NextToLast(2))
return new ShardingDatastore(new FsDatastore(dir), new shard.NextToLast(2))
},
teardown: () => {
return rimraf(dir)
Expand All @@ -175,7 +175,7 @@ describe('DatastoreFs', () => {

it('can survive concurrent writes', async () => {
const dir = tempdir()
const fstore = new DatastoreFs(dir)
const fstore = new FsDatastore(dir)
const key = new Key('CIQGFTQ7FSI2COUXWWLOQ45VUM2GUZCGAXLWCTOKKPGTUWPXHBNIVOY')
const value = utf8Encoder.encode('Hello world')

Expand All @@ -190,7 +190,7 @@ describe('DatastoreFs', () => {

it('can survive putRaw and getRaw with an empty extension', async () => {
const dir = tempdir()
const fstore = new DatastoreFs(dir, {
const fstore = new FsDatastore(dir, {
extension: ''
})
const key = new Key('CIQGFTQ7FSI2COUXWWLOQ45VUM2GUZCGAXLWCTOKKPGTUWPXHBNIVOY')
Expand Down