Skip to content

Commit

Permalink
bugfix: deno assumes relative path for worker (#3)
Browse files Browse the repository at this point in the history
Fixes #2

* bugfix: deno assumes relative path for worker

* add a log

* try using URL()

* Update mod.ts

* chore: remove test import

* chore: test dirname

* Update connector.ts

* Update README.md

* chore: remove test console.log

Co-authored-by: Aditi Mohanty <[email protected]>
  • Loading branch information
abinavseelan and rheaditi authored Jun 8, 2020
1 parent acb4328 commit e36505d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ interface Schema {
const db = new CasualDB<Schema>();
```

Note: When running via deno, this module will require you to pass the following flags:-
Note: When running via deno, this module will require you to pass the following flags (all flags are mandatory):-

* `--allow-read` : in order to be able to **read** the JSON files
* `--allow-write`: in order to be able to **read** the JSON files
* `--allow-write`: in order to be able to **write** to the JSON files
* `--unstable` : this module uses the experimental Worker API in deno, and hence requires this flag
* `--allow-net` : this is to enable to download of the Worker file.

If you want to always run the latest code (from the `master` branch) of this module, install via:
```ts
Expand Down
8 changes: 6 additions & 2 deletions connector.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { dirname, join } from "https://deno.land/[email protected]/path/mod.ts"
import { readJson } from "https://deno.land/std/fs/read_json.ts";
import { writeJson } from "https://deno.land/std/fs/write_json.ts";

Expand All @@ -10,7 +11,7 @@ const getNow = Date.now;
export class Connector<Schema = any> {
private _filePath: string = "";
private readonly WRITE_TIMEOUT: number = 10000;
private readonly WRITE_WORKER_PATH: string = "./writeWorker.ts";
private readonly WRITE_WORKER_PATH: string = join(dirname(import.meta.url), "writeWorker.ts");
private readonly WRITE_WORKER_OPTIONS: { type: "module"; deno: boolean } = {
type: "module",
deno: true,
Expand Down Expand Up @@ -76,7 +77,10 @@ export class Connector<Schema = any> {
} else if (error) {
reject(error);
} else {
console.debug("[casualdb:connector:debug]", { returnedTaskId, taskId, error });
console.debug(
"[casualdb:connector:debug]",
{ returnedTaskId, taskId, error },
);
reject(new Error(`[casualdb] unknown error while writing to file`));
}
if (timeout) {
Expand Down

0 comments on commit e36505d

Please sign in to comment.