Skip to content

Commit

Permalink
switch to @farcasterxyz/rocksdb
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSulpiride committed Oct 2, 2023
1 parent e345246 commit 33f193b
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 2 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
"release:publish": "lerna publish from-package --yes --no-verify-access",
"release:docker": "exit 0"
},
"dependencies": {
"abstract-leveldown": "7.2.0"
},
"devDependencies": {
"@types/abstract-leveldown": "7.2.1",
"@types/compression": "1.7.2",
"@types/jest": "29.2.3",
"@types/node": "18.11.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"dependencies": {
"@chainsafe/ssz": "0.10.1",
"rocksdb": "5.2.1",
"@farcaster/rocksdb": "5.5.0",
"types": "1.0.3-alpha"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/db/src/rocksDb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "node:path";
import rocks from "rocksdb";
import rocks from "@farcaster/rocksdb";
// eslint-disable-next-line import/no-extraneous-dependencies
import { IDbController } from "types/lib";

Expand Down
122 changes: 122 additions & 0 deletions types/rocksdb/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Type definitions for @farcaster/rocksdb 3.0
// Project: https://github.com/farcasterxyz/rocksdb
// Definitions by: Meirion Hughes <https://github.com/MeirionHughes>
// Daniel Byrne <https://github.com/danwbyrne>
// Paul Fletcher-Hill <https://github.com/pfletcherhill>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

/// <reference types="node" />

// If we ever start using the upstream rocksdb package again, remove this
// wrapper `module` declaration. It's only needed because our forked package is
// scoped to @farcaster.
declare module "@farcaster/rocksdb" {
import {
AbstractBatch,
AbstractChainedBatch,
AbstractGetOptions,
AbstractIterator,
AbstractIteratorOptions,
AbstractLevelDOWN,
AbstractOpenOptions,
AbstractOptions,
ErrorCallback,
ErrorValueCallback,
} from "abstract-leveldown";

interface RocksDB extends AbstractLevelDOWN<RocksDB.Bytes, RocksDB.Bytes> {
open(cb: ErrorCallback): void;
open(options: RocksDB.OpenOptions, cb: ErrorCallback): void;

get(key: RocksDB.Bytes, cb: ErrorValueCallback<RocksDB.Bytes>): void;
get(
key: RocksDB.Bytes,
options: RocksDB.GetOptions,
cb: ErrorValueCallback<RocksDB.Bytes>
): void;

put(key: RocksDB.Bytes, value: RocksDB.Bytes, cb: ErrorCallback): void;
put(
key: RocksDB.Bytes,
value: RocksDB.Bytes,
options: RocksDB.PutOptions,
cb: ErrorCallback
): void;

del(key: RocksDB.Bytes, cb: ErrorCallback): void;
del(
key: RocksDB.Bytes,
options: RocksDB.DelOptions,
cb: ErrorCallback
): void;

batch(): AbstractChainedBatch<RocksDB.Bytes, RocksDB.Bytes>;
batch(
array: AbstractBatch[],
cb: ErrorCallback
): AbstractChainedBatch<RocksDB.Bytes, RocksDB.Bytes>;
batch(
array: AbstractBatch[],
options: RocksDB.BatchOptions,
cb: ErrorCallback
): AbstractChainedBatch<RocksDB.Bytes, RocksDB.Bytes>;

approximateSize(
start: RocksDB.Bytes,
end: RocksDB.Bytes,
cb: RocksDB.ErrorSizeCallback
): void;
compactRange(
start: RocksDB.Bytes,
end: RocksDB.Bytes,
cb: ErrorCallback
): void;
getProperty(property: string): string;
iterator(options?: RocksDB.IteratorOptions): RocksDB.Iterator;
}

namespace RocksDB {
type Bytes = string | Buffer;
type ErrorSizeCallback = (err: Error | undefined, size: number) => void;
type OpenOptions = AbstractOpenOptions;

interface GetOptions extends AbstractGetOptions {
fillCache?: boolean | undefined;
}

interface PutOptions extends AbstractOptions {
sync?: boolean | undefined;
}

interface DelOptions extends AbstractOptions {
sync?: boolean | undefined;
}

interface BatchOptions extends AbstractOptions {
sync?: boolean | undefined;
}

interface IteratorOptions extends AbstractIteratorOptions<Bytes> {
fillCache?: boolean | undefined;
}

interface Iterator extends AbstractIterator<Bytes, Bytes> {
seek(key: Bytes): void;
binding: any;
cache: any;
finished: any;
fastFuture: any;
}

interface Constructor {
new (location: string): RocksDB;
(location: string): RocksDB;
destroy(location: string, cb: ErrorCallback): void;
repair(location: string, cb: ErrorCallback): void;
}
}

const RocksDB: RocksDB.Constructor;
export default RocksDB;
}
9 changes: 9 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,15 @@
"@ethersproject/properties" "^5.7.0"
"@ethersproject/strings" "^5.7.0"

"@farcaster/[email protected]":
version "5.5.0"
resolved "https://registry.yarnpkg.com/@farcaster/rocksdb/-/rocksdb-5.5.0.tgz#c352480a7d6e08c2eee8e1690dc0a49e5a72c8fd"
integrity sha512-E5xavqAOrS9yXV2zw2lEyv7j4w1jZd0UNtsi5C9tqk5Kw9voCojA/zTgb5WugEqHAT6Bt/szahhnNuWxbo9NPg==
dependencies:
abstract-leveldown "^7.2.0"
napi-macros "^2.0.0"
node-gyp-build "^4.3.0"

"@fastify/ajv-compiler@^3.5.0":
version "3.5.0"
resolved "https://registry.yarnpkg.com/@fastify/ajv-compiler/-/ajv-compiler-3.5.0.tgz#459bff00fefbf86c96ec30e62e933d2379e46670"
Expand Down

0 comments on commit 33f193b

Please sign in to comment.