Skip to content

Commit

Permalink
Renamed defaultSubspace to root
Browse files Browse the repository at this point in the history
  • Loading branch information
josephg committed Apr 8, 2020
1 parent 4e172f0 commit fd6d592
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 19 deletions.
11 changes: 3 additions & 8 deletions lib/database.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import * as fdb from './native'
import Transaction, {
RangeOptions,
Watch,
WatchOptions,
} from './transaction'
import Transaction, { RangeOptions, Watch } from './transaction'
import {Transformer, defaultTransformer} from './transformer'
import {NativeValue} from './native'
import {KeySelector} from './keySelector'
import Subspace, { defaultSubspace, GetSubspace, isGetSubspace } from './subspace'
import {asBuf} from './util'
import Subspace, { root, GetSubspace, isGetSubspace } from './subspace'
import {eachOption} from './opts'
import {DatabaseOptions,
TransactionOptions,
Expand Down Expand Up @@ -38,7 +33,7 @@ export default class Database<KeyIn = NativeValue, KeyOut = Buffer, ValIn = Nati
// **** Scoping functions

getRoot(): Database {
return new Database(this._db, defaultSubspace)
return new Database(this._db, root)
}

getSubspace() { return this.subspace }
Expand Down
4 changes: 2 additions & 2 deletions lib/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Database, tuple, TupleItem, util } from ".";
import { Transformer, defaultTransformer } from "./transformer";
import { TransactionOptionCode } from "./opts.g";
import { concat2, startsWith, strInc, asBuf } from "./util";
import Subspace, { defaultSubspace } from "./subspace";
import Subspace, { root } from "./subspace";
import { inspect } from "util";
import { NativeValue, NativeTransaction } from "./native";
// import FDBError from './error'
Expand Down Expand Up @@ -597,7 +597,7 @@ export class DirectoryLayer {
if (prefix == null) {
// const subspace = this._contentSubspace.at(await this._allocator.allocate(txn))
prefix = concat2(this._contentSubspace.prefix, await this._allocator.allocate(txn))
if ((await txn.at(defaultSubspace).getRangeAllStartsWith(prefix, {limit: 1})).length > 0) {
if ((await txn.at(root).getRangeAllStartsWith(prefix, {limit: 1})).length > 0) {
throw new DirectoryError('The database has keys stored at the prefix chosen by the automatic prefix allocator: ' + inspect(prefix))
}

Expand Down
6 changes: 3 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Database from './database'
import {eachOption} from './opts'
import {NetworkOptions, networkOptionData, DatabaseOptions} from './opts.g'
import {Transformer} from './transformer'
import {defaultSubspace} from './subspace'
import {root} from './subspace'
import {DirectoryLayer} from './directory'

import * as apiVersion from './apiVersion'
Expand Down Expand Up @@ -49,7 +49,7 @@ export {default as keySelector, KeySelector} from './keySelector'
// always be constructed using open or via a cluster object.
export {default as Database} from './database'
export {default as Transaction, Watch} from './transaction'
export {default as Subspace, defaultSubspace} from './subspace'
export {default as Subspace, root} from './subspace'
export {Directory, DirectoryLayer} from './directory'

export {
Expand Down Expand Up @@ -122,7 +122,7 @@ export function configNetwork(netOpts: NetworkOptions) {
export function open(clusterFile?: string, dbOpts?: DatabaseOptions) {
init()

const db = new Database(nativeMod.createDatabase(clusterFile), defaultSubspace)
const db = new Database(nativeMod.createDatabase(clusterFile), root)
if (dbOpts) db.setNativeOptions(dbOpts)
return db
}
Expand Down
2 changes: 1 addition & 1 deletion lib/subspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class Subspace<KeyIn = NativeValue, KeyOut = Buffer, ValIn = Nati
}
}

export const defaultSubspace: Subspace = new Subspace(null, defaultTransformer, defaultTransformer)
export const root: Subspace = new Subspace(null, defaultTransformer, defaultTransformer)

export interface GetSubspace<KI, KO, VI, VO> {
getSubspace(): Subspace<KI, KO, VI, VO>
Expand Down
9 changes: 5 additions & 4 deletions lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,11 @@ export default class Transaction<KeyIn = NativeValue, KeyOut = Buffer, ValIn = N
getKey(_sel: KeySelector<KeyIn> | KeyIn): Promise<KeyOut | undefined> {
const sel = keySelector.from(_sel)
return this._tn.getKey(this._keyEncoding.pack(sel.key), sel.orEqual, sel.offset, this.isSnapshot)
.then(key => {
if (key.length === 0 || !this.subspace.contains(key)) return undefined
else return this._keyEncoding.unpack(key)
})
.then(key => (
(key.length === 0 || !this.subspace.contains(key))
? undefined
: this._keyEncoding.unpack(key)
))
}

/** Set the specified key/value pair in the database */
Expand Down
1 change: 0 additions & 1 deletion test/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'mocha'
import * as fdb from '../lib'
import Subspace, { defaultSubspace } from '../lib/subspace'

// We'll tuck everything behind this prefix and delete it all when the tests finish running.
export const prefix = '__test_data__/'
Expand Down

0 comments on commit fd6d592

Please sign in to comment.