-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Picolab/dependency-updates
Dependency Updates
- Loading branch information
Showing
20 changed files
with
143 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
name: Test | ||
|
||
on: push | ||
|
||
on: [push, pull_request] | ||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
node-version: | ||
- lts/* # LTS version | ||
- "17" # latest version | ||
node: | ||
- lts/* | ||
- current | ||
os: [ubuntu-latest, macOS-latest, windows-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Node ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
- uses: actions/checkout@v3 | ||
- name: Node ${{ matrix.node }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- run: npm i | ||
node-version: ${{ matrix.node }} | ||
- run: npm install | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,21 @@ | ||
import { LevelUp } from "levelup"; | ||
import * as _ from "lodash"; | ||
import { AbstractIteratorOptions } from "abstract-level"; | ||
import { PicoDb, PicoDbKey } from "./utils"; | ||
|
||
export function dbRange<T = any>( | ||
ldb: LevelUp, | ||
opts: any, | ||
onData: (data: any, stop: () => void) => Promise<T> | T | ||
export async function dbRange<T = any>( | ||
db: PicoDb, | ||
opts: { prefix?: PicoDbKey }, | ||
onData: (data: any) => Promise<T> | T, | ||
): Promise<T[]> { | ||
return new Promise(function(resolve, reject) { | ||
const promises: Promise<T>[] = []; | ||
const promises: Promise<T>[] = []; | ||
|
||
let hasCalledback = false; | ||
function callback(err?: any) { | ||
if (hasCalledback) return; | ||
hasCalledback = true; | ||
if (err) { | ||
return reject(err); | ||
} | ||
Promise.all(promises) | ||
.then(resolve) | ||
.catch(reject); | ||
} | ||
|
||
if (_.has(opts, "prefix")) { | ||
opts = _.assign({}, opts, { | ||
gte: opts.prefix, | ||
lte: opts.prefix.concat([undefined]) // bytewise sorts with null at the bottom and undefined at the top | ||
}); | ||
delete opts.prefix; | ||
} | ||
const s = ldb.createReadStream(opts); | ||
function stopRange() { | ||
(s as any).destroy(); | ||
callback(); | ||
} | ||
s.on("error", function(err) { | ||
callback(err); | ||
}); | ||
s.on("end", callback); | ||
s.on("data", function(data) { | ||
promises.push(Promise.resolve(onData(data, stopRange))); | ||
}); | ||
}); | ||
let streamOpts: AbstractIteratorOptions<PicoDbKey, any> = {}; | ||
if (opts && Array.isArray(opts.prefix)) { | ||
streamOpts.gte = opts.prefix; | ||
streamOpts.lte = opts.prefix.concat([undefined] as any); // bytewise sorts with null at the bottom and undefined at the top | ||
} | ||
const iter = db.iterator(streamOpts); | ||
for await (const [key, value] of iter) { | ||
promises.push(Promise.resolve(onData({ key, value }))); | ||
} | ||
return await Promise.all(promises); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,9 @@ | ||
import { AbstractLevel, AbstractBatchOperation } from "abstract-level"; | ||
|
||
export function isNotStringOrBlank(val: any) { | ||
return typeof val !== "string" || val.trim().length === 0; | ||
} | ||
|
||
/** | ||
* Copied AbstractBatch from "abstract-leveldown" | ||
* b/c typescript module resolution doesn't work very well with lerna (used in pico-engine) | ||
*/ | ||
export type LevelBatch = PutBatch | DelBatch; | ||
type LevelKey = (string | number | null | boolean)[]; | ||
interface PutBatch { | ||
readonly type: "put"; | ||
readonly key: LevelKey; | ||
readonly value: any; | ||
} | ||
interface DelBatch { | ||
readonly type: "del"; | ||
readonly key: LevelKey; | ||
} | ||
export type PicoDbKey = (string | number | null | boolean)[]; | ||
export type PicoDb = AbstractLevel<any, PicoDbKey, any>; | ||
export type LevelBatch = AbstractBatchOperation<PicoDb, PicoDbKey, any>; |
Oops, something went wrong.