Skip to content

Commit

Permalink
Added more types.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTV12345 committed Oct 17, 2023
1 parent 3377139 commit 35c6205
Show file tree
Hide file tree
Showing 12 changed files with 1,076 additions and 905 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
# already-used version number. By running `npm publish` after `git push`,
# back-to-back merges will cause the first merge's workflow to fail but
# the second's will succeed.
- run: npx tsc
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
142 changes: 0 additions & 142 deletions README.md

This file was deleted.

Binary file removed bun.lockb
Binary file not shown.
13 changes: 7 additions & 6 deletions lib/dirty/dirty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import {createReadStream, createWriteStream, ReadStream, WriteStream} from 'fs'
import {EventEmitter} from 'events'
import * as fs from "fs";


type Error = {
Expand All @@ -15,14 +16,14 @@ type Row = {

class Dirty extends EventEmitter {
private readonly path: PathLike;
private readonly _data: Map<any, any>;
readonly _data: Map<any, any>;
private readonly _queue: Map<any, any>;
private _readStream: ReadStream;
private _writeStream: WriteStream;
private _waitForDrain: boolean;
private _inFlightWrites: number;

constructor(path: PathLike) {
constructor(path?: PathLike) {
super();

this.path = path;
Expand All @@ -42,7 +43,7 @@ class Dirty extends EventEmitter {
* cb is fired when the data is persisted.
* In memory, this is immediate - on disk, it will take some time.
*/
set(key: string, val: string, cb:Function) {
set(key: string|number, val: string|Object, cb?:Function) {
if (val === undefined) {
this._data.delete(key);
} else {
Expand All @@ -62,7 +63,7 @@ class Dirty extends EventEmitter {
* Get the value stored at a key in the database
* This is synchronous since a cache is maintained in-memory
*/
get(key: string) {
get(key: string|number) {
return this._data.get(key);
}

Expand All @@ -76,7 +77,7 @@ class Dirty extends EventEmitter {
/**
* Remove a key and the value stored there
*/
rm(key: string, cb:Function) {
rm(key: string|number, cb?: Function) {
this.set(key, undefined, cb);
}

Expand All @@ -94,7 +95,7 @@ class Dirty extends EventEmitter {
* This is synchronous since a cache is maintained in-memory
* cb is passed as per Dirty.prototype.set
*/
update(key: string, updater:Function, cb:Function) {
update(key: string, updater:Function, cb?:Function) {
this.set(key, updater(this.get(key)), cb);
}

Expand Down
Loading

0 comments on commit 35c6205

Please sign in to comment.