Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecated APIs warnings #259

Merged
merged 5 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ jobs:
run: /home/runner/.deno/bin/deno test --allow-read --allow-write
- name: Run tests (unstable)
run: /home/runner/.deno/bin/deno test --unstable --allow-read --allow-write
- name: Run tests (DENO_FUTURE)
run: DENO_FUTURE=1 /home/runner/.deno/bin/deno test --allow-read --allow-write
- name: Run tests (DENO_FUTURE and unstable)
run: DENO_FUTURE=1 /home/runner/.deno/bin/deno test --unstable --allow-read --allow-write
- name: Run benchmarks
run: /home/runner/.deno/bin/deno run bench.ts
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ encounter. Note that the `master` branch might contain new or breaking features.
The versioning guarantee applies only to
[tagged releases](https://github.com/dyedgreen/deno-sqlite/releases).

This module relies on filesystem APIs stabilized in Deno v1.44. To use it with
earlier Deno versions, you must pass the `--unstable-fs` flag when running your
application.

## Documentation

Documentation is available [Deno Docs](https://deno.land/x/sqlite). There is
Expand Down
50 changes: 36 additions & 14 deletions build/vfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import { getStr } from "../src/wasm.ts";

const isWindows = Deno.build.os === "windows";

const OPEN_FILES = [];

function getOpenFile(rid) {
const file = OPEN_FILES[rid];
if (!file) {
throw new Error(`Resource ID ${rid} does not exist.`);
}
return file;
}

// Closure to return an environment that links
// the current wasm context
export default function env(inst) {
Expand All @@ -26,12 +36,15 @@ export default function env(inst) {

const write = !!(flags & 0x00000002);
const create = !!(flags & 0x00000004);
const rid = Deno.openSync(path, { read: true, write, create }).rid;
return rid;
const file = Deno.openSync(path, { read: true, write, create });
OPEN_FILES.push(file);
return OPEN_FILES.length - 1;
},
// Close a file
js_close: (rid) => {
Deno.close(rid);
const file = getOpenFile(rid);
file.close();
OPEN_FILES[rid] = null;
},
// Delete file at path
js_delete: (path_ptr) => {
Expand All @@ -45,8 +58,9 @@ export default function env(inst) {
buffer_ptr,
amount,
);
Deno.seekSync(rid, offset, Deno.SeekMode.Start);
return Deno.readSync(rid, buffer);
const file = getOpenFile(rid);
file.seekSync(offset, Deno.SeekMode.Start);
return file.readSync(buffer);
},
// Write to a file from a buffer in the module
js_write: (rid, buffer_ptr, offset, amount) => {
Expand All @@ -55,30 +69,38 @@ export default function env(inst) {
buffer_ptr,
amount,
);
Deno.seekSync(rid, offset, Deno.SeekMode.Start);
return Deno.writeSync(rid, buffer);
const file = getOpenFile(rid);
file.seekSync(offset, Deno.SeekMode.Start);
return file.writeSync(buffer);
},
// Truncate the given file
js_truncate: (rid, size) => {
Deno.ftruncateSync(rid, size);
const file = getOpenFile(rid);
file.truncateSync(size);
},
// Sync file data to disk
js_sync: (rid) => {
Deno.fdatasyncSync(rid);
const file = getOpenFile(rid);
file.syncDataSync();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dyedgreen I don't know of a good way to make this method support Deno versions before v1.44.

  • We could make it a no-op like the lock/unlock method. Is that acceptable or would that break things?
  • Or we could bump the minimum supported Deno version to v1.44 after this lands.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dyedgreen Let me know when you get a chance to look at this. I'm thinking we may need to bump the minimum supported Deno version to get access to the new file flushing APIs. What are your thoughts?

},
// Retrieve the size of the given file
js_size: (rid) => {
return Deno.fstatSync(rid).size;
const file = getOpenFile(rid);
return file.statSync().size;
},
// Acquire a SHARED or EXCLUSIVE file lock
js_lock: (rid, exclusive) => {
// this is unstable and has issues on Windows ...
if (Deno.flockSync && !isWindows) Deno.flockSync(rid, exclusive !== 0);
// this has issues on Windows ...
if (!isWindows) {
getOpenFile(rid).lockSync(exclusive !== 0);
}
},
// Release a file lock
js_unlock: (rid) => {
// this is unstable and has issues on Windows ...
if (Deno.funlockSync && !isWindows) Deno.funlockSync(rid);
// this has issues on Windows ...
if (!isWindows) {
getOpenFile(rid).unlockSync();
}
},
// Return current time in ms since UNIX epoch
js_time: () => {
Expand Down