Skip to content

Commit

Permalink
chore: update deps and Deno v2
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Sep 5, 2024
1 parent ddd6094 commit 64bfe85
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 72 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ on: [push, pull_request]
jobs:
ci:
runs-on: ubuntu-latest
strategy:
matrix:
version: ["v1.x", canary]
steps:
- name: clone repository
uses: actions/checkout@v4

- name: install deno
uses: denoland/setup-deno@v1
with:
deno-version: 1.x
deno-version: ${{ matrix.version }}

- name: check format
run: deno fmt --check
Expand Down
39 changes: 23 additions & 16 deletions _test_util.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import { assert } from "jsr:@std/assert@0.225/assert";
export { concat } from "jsr:@std/bytes@0.224/concat";
export { delay } from "jsr:@std/async@0.224/delay";
export { assert } from "jsr:@std/assert@0.225/assert";
export { assertEquals } from "jsr:@std/assert@0.225/assert-equals";
export { assertNotEquals } from "jsr:@std/assert@0.225/assert-not-equals";
export { assertRejects } from "jsr:@std/assert@0.225/assert-rejects";
export { assertStrictEquals } from "jsr:@std/assert@0.225/assert-strict-equals";
export { timingSafeEqual } from "jsr:@std/crypto@0.224/timing-safe-equal";
import { assert } from "jsr:@std/assert@~1/assert";
export { concat } from "jsr:@std/bytes@~1/concat";
export { delay } from "jsr:@std/async@~1/delay";
export { assert } from "jsr:@std/assert@~1/assert";
export { assertEquals } from "jsr:@std/assert@~1/equals";
export { assertNotEquals } from "jsr:@std/assert@~1/not-equals";
export { assertRejects } from "jsr:@std/assert@~1/rejects";
export { assertStrictEquals } from "jsr:@std/assert@~1/strict-equals";
export { timingSafeEqual } from "jsr:@std/crypto@~1/timing-safe-equal";

let kv: Deno.Kv | undefined;
let kv: { close(): void } | undefined;
let path: string | undefined;

export async function setup(): Promise<Deno.Kv> {
path = `${await Deno.makeTempDir()}/test.db`;
return kv = await Deno.openKv(path);
export async function getPath() {
return path = `${await Deno.makeTempDir()}/test.db`;
}

export async function teardown() {
export async function setup() {
return kv = await Deno.openKv(await getPath());
}

export function cleanup() {
assert(path);
return Deno.remove(path);
}

export function teardown() {
assert(kv);
kv.close();
assert(path);
await Deno.remove(path);
return cleanup();
}
12 changes: 6 additions & 6 deletions batched_atomic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ Deno.test({
async fn() {
const kv = await setup();
let value = new Uint8Array(65_536);
window.crypto.getRandomValues(value);
globalThis.crypto.getRandomValues(value);
const res = await set(kv, ["hello"], value);
assert(res.ok);
value = new Uint8Array(65_536);
window.crypto.getRandomValues(value);
globalThis.crypto.getRandomValues(value);
const actual = await batchedAtomic(kv)
.checkBlob({ key: ["hello"], versionstamp: res.versionstamp })
.setBlob(["hello"], value)
Expand All @@ -55,11 +55,11 @@ Deno.test({
async fn() {
const kv = await setup();
let value = new Uint8Array(65_536);
window.crypto.getRandomValues(value);
globalThis.crypto.getRandomValues(value);
const res = await set(kv, ["hello"], value);
assert(res.ok);
value = new Uint8Array(65_536);
window.crypto.getRandomValues(value);
globalThis.crypto.getRandomValues(value);
const actual = await batchedAtomic(kv)
.checkBlob({ key: ["hello"], versionstamp: null })
.setBlob(["hello"], value)
Expand Down Expand Up @@ -125,7 +125,7 @@ Deno.test({
async fn() {
const kv = await setup();
const blob = new Uint8Array(65_536);
window.crypto.getRandomValues(blob);
globalThis.crypto.getRandomValues(blob);
const operation = batchedAtomic(kv);
operation.setBlob(["hello"], blob);
await operation.commit();
Expand All @@ -144,7 +144,7 @@ Deno.test({
async fn() {
const kv = await setup();
const blob = new Uint8Array(65_536);
window.crypto.getRandomValues(blob);
globalThis.crypto.getRandomValues(blob);
await set(kv, ["hello"], blob);
assertEquals((await keys(kv, { prefix: ["hello"] })).length, 3);
const operation = batchedAtomic(kv);
Expand Down
34 changes: 17 additions & 17 deletions blob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Deno.test({
async fn() {
const kv = await setup();
const blob = new Uint8Array(65_536);
window.crypto.getRandomValues(blob);
globalThis.crypto.getRandomValues(blob);
const res = await set(kv, ["hello"], blob);
assert(res.ok);
assert(res.versionstamp);
Expand All @@ -46,7 +46,7 @@ Deno.test({
async fn() {
const kv = await setup();
const u8 = new Uint8Array(65_536);
window.crypto.getRandomValues(u8);
globalThis.crypto.getRandomValues(u8);
const blob = new DataView(u8.buffer);
const res = await set(kv, ["hello"], blob);
assert(res.ok);
Expand All @@ -66,7 +66,7 @@ Deno.test({
async fn() {
const kv = await setup();
const data = new Uint8Array(65_536);
window.crypto.getRandomValues(data);
globalThis.crypto.getRandomValues(data);
const blob = new Blob([data]);
const res = await set(kv, ["hello"], blob.stream());
assert(res.ok);
Expand All @@ -85,7 +85,7 @@ Deno.test({
async fn() {
const kv = await setup();
const data = new Uint8Array(65_536);
window.crypto.getRandomValues(data);
globalThis.crypto.getRandomValues(data);
const blob = new Blob([data], { type: "application/octet-stream" });
const res = await set(kv, ["hello"], blob);
assert(res.ok);
Expand All @@ -110,7 +110,7 @@ Deno.test({
async fn() {
const kv = await setup();
const data = new Uint8Array(65_536);
window.crypto.getRandomValues(data);
globalThis.crypto.getRandomValues(data);
const blob = new File([data], "test.bin", {
type: "application/octet-stream",
lastModified: 12345678,
Expand Down Expand Up @@ -140,7 +140,7 @@ Deno.test({
async fn() {
const kv = await setup();
const blob = new Uint8Array(65_536);
window.crypto.getRandomValues(blob);
globalThis.crypto.getRandomValues(blob);
const res = await set(kv, ["hello"], blob);
assert(res.ok);
const actual = await keys(kv, { prefix: ["hello"] });
Expand Down Expand Up @@ -207,7 +207,7 @@ Deno.test({
async fn() {
const kv = await setup();
const blob = new Uint8Array(65_536);
window.crypto.getRandomValues(blob);
globalThis.crypto.getRandomValues(blob);
await set(kv, ["hello"], blob);
const actual = await get(kv, ["hello"]);
assert(actual.value);
Expand All @@ -221,7 +221,7 @@ Deno.test({
async fn() {
const kv = await setup();
const blob = new Uint8Array(65_536);
window.crypto.getRandomValues(blob);
globalThis.crypto.getRandomValues(blob);
await set(kv, ["hello"], blob);
const entry = await get(kv, ["hello"], { stream: true });
assert(entry.value);
Expand All @@ -239,7 +239,7 @@ Deno.test({
async fn() {
const kv = await setup();
const blob = new Uint8Array(65_536);
window.crypto.getRandomValues(blob);
globalThis.crypto.getRandomValues(blob);
await set(kv, ["hello"], blob);
const stream = getAsStream(kv, ["hello"]);
let count = 0;
Expand Down Expand Up @@ -353,7 +353,7 @@ Deno.test({
async fn() {
const kv = await setup();
const u8 = new Uint8Array(65_536);
window.crypto.getRandomValues(u8);
globalThis.crypto.getRandomValues(u8);
await set(kv, ["hello"], u8);
const json = await getAsJSON(kv, ["hello"]);
assert(json);
Expand All @@ -368,7 +368,7 @@ Deno.test({
async fn() {
const kv = await setup();
const u8 = new Uint8Array(65_536);
window.crypto.getRandomValues(u8);
globalThis.crypto.getRandomValues(u8);
await set(
kv,
["hello"],
Expand All @@ -391,7 +391,7 @@ Deno.test({
async fn() {
const kv = await setup();
const u8 = new Uint8Array(65_536);
window.crypto.getRandomValues(u8);
globalThis.crypto.getRandomValues(u8);
await set(
kv,
["hello"],
Expand Down Expand Up @@ -419,7 +419,7 @@ Deno.test({
async fn() {
const kv = await setup();
const u8 = new Uint8Array(65_536);
window.crypto.getRandomValues(u8);
globalThis.crypto.getRandomValues(u8);
await set(kv, ["hello"], u8);
const meta = await getMeta(kv, ["hello"]);
assert(meta);
Expand All @@ -432,7 +432,7 @@ Deno.test({
name: "toJSON/toValue - File",
async fn() {
const u8 = new Uint8Array(65_536);
window.crypto.getRandomValues(u8);
globalThis.crypto.getRandomValues(u8);
const json = await toJSON(
new File([u8], "test.bin", {
type: "application/octet-stream",
Expand All @@ -459,7 +459,7 @@ Deno.test({
name: "toJSON/toValue - Blob",
async fn() {
const u8 = new Uint8Array(65_536);
window.crypto.getRandomValues(u8);
globalThis.crypto.getRandomValues(u8);
const json = await toJSON(
new Blob([u8], { type: "application/octet-stream" }),
);
Expand All @@ -477,7 +477,7 @@ Deno.test({
name: "toJSON/toValue - buffer",
async fn() {
const u8 = new Uint8Array(65_536);
window.crypto.getRandomValues(u8);
globalThis.crypto.getRandomValues(u8);
const json = await toJSON(u8);
assertEquals(json.meta, { kind: "buffer" });
assertEquals(json.parts.length, 2);
Expand Down Expand Up @@ -541,7 +541,7 @@ Deno.test({
async fn() {
const kv = await setup();
const data = new Uint8Array(65_536);
window.crypto.getRandomValues(data);
globalThis.crypto.getRandomValues(data);
await set(kv, ["hello"], new Blob([data]));
assertEquals((await keys(kv, { prefix: ["hello"] })).length, 3);
await remove(kv, ["hello"]);
Expand Down
10 changes: 5 additions & 5 deletions blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@
* @module
*/

import { concat } from "jsr:@std/bytes@0.224/concat";
import { concat } from "jsr:@std/bytes@~1/concat";
import {
decodeBase64Url,
encodeBase64Url,
} from "jsr:@std/encoding@0.224/base64url";
import { extension } from "jsr:@std/media-types@0.224/extension";
} from "jsr:@std/encoding@~1/base64url";
import { extension } from "jsr:@std/media-types@~1/extension";

import { batchedAtomic } from "./batched_atomic.ts";
import {
Expand Down Expand Up @@ -436,12 +436,12 @@ export function getAsJSON(
* await kv.close();
* ```
*/
export async function getMeta(
export function getMeta(
kv: Deno.Kv,
key: Deno.KvKey,
options: { consistency?: Deno.KvConsistencyLevel | undefined } = {},
): Promise<Deno.KvEntryMaybe<BlobMeta>> {
return await asMeta(kv, key, options);
return asMeta(kv, key, options);
}

/** Options which can be used when calling {@linkcode getAsResponse}. */
Expand Down
17 changes: 9 additions & 8 deletions crypto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Deno.test({
const kv = await setup();
const key = generateKey();
const cryptoKv = new CryptoKv(kv, key);
const value = window.crypto.getRandomValues(new Uint8Array(65_536));
const value = globalThis.crypto.getRandomValues(new Uint8Array(65_536));
const res = await cryptoKv.setBlob(["example"], value);
assert(res.ok);
const actual = await cryptoKv.getBlob(["example"]);
Expand All @@ -31,7 +31,8 @@ Deno.test({
const kv = await setup();
const key = generateKey();
const cryptoKv = new CryptoKv(kv, key);
const value = window.crypto.getRandomValues(new Uint8Array(65_536)).buffer;
const value =
globalThis.crypto.getRandomValues(new Uint8Array(65_536)).buffer;
const res = await cryptoKv.setBlob(["example"], value);
assert(res.ok);
const actual = await cryptoKv.getBlob(["example"]);
Expand All @@ -48,7 +49,7 @@ Deno.test({
const kv = await setup();
const key = generateKey();
const cryptoKv = new CryptoKv(kv, key);
const part = window.crypto.getRandomValues(new Uint8Array(65_536));
const part = globalThis.crypto.getRandomValues(new Uint8Array(65_536));
const value = new Blob([part], { type: "text/plain" });
const res = await cryptoKv.setBlob(["example"], value);
assert(res.ok);
Expand All @@ -66,7 +67,7 @@ Deno.test({
const kv = await setup();
const key = generateKey();
const cryptoKv = new CryptoKv(kv, key);
const part = window.crypto.getRandomValues(new Uint8Array(65_536));
const part = globalThis.crypto.getRandomValues(new Uint8Array(65_536));
const value = new File([part], "test.bin", { type: "text/plain" });
const res = await cryptoKv.setBlob(["example"], value);
assert(res.ok);
Expand All @@ -84,7 +85,7 @@ Deno.test({
const kv = await setup();
const key = generateKey();
const cryptoKv = new CryptoKv(kv, key);
const part = window.crypto.getRandomValues(new Uint8Array(65_536));
const part = globalThis.crypto.getRandomValues(new Uint8Array(65_536));
const value = new File([part], "test.bin", { type: "text/plain" });
const res = await cryptoKv.setBlob(["example"], value);
assert(res.ok);
Expand All @@ -104,7 +105,7 @@ Deno.test({
const kv = await setup();
const key = generateKey();
const cryptoKv = new CryptoKv(kv, key);
const part = window.crypto.getRandomValues(new Uint8Array(65_536));
const part = globalThis.crypto.getRandomValues(new Uint8Array(65_536));
const value = new File([part], "test.bin", { type: "text/plain" });
const res = await cryptoKv.setBlob(["example"], value);
assert(res.ok);
Expand All @@ -123,7 +124,7 @@ Deno.test({
const kv = await setup();
const key = generateKey();
const cryptoKv = new CryptoKv(kv, key);
const part = window.crypto.getRandomValues(new Uint8Array(65_536));
const part = globalThis.crypto.getRandomValues(new Uint8Array(65_536));
const value = new File([part], "test.bin", { type: "text/plain" });
const res = await cryptoKv.setBlob(["example"], value);
assert(res.ok);
Expand All @@ -141,7 +142,7 @@ Deno.test({
const kv = await setup();
const key = generateKey();
const cryptoKv = new CryptoKv(kv, key);
const part = window.crypto.getRandomValues(new Uint8Array(65_536));
const part = globalThis.crypto.getRandomValues(new Uint8Array(65_536));
const value = new File([part], "test.bin", { type: "text/plain" });
const res = await cryptoKv.setBlob(["example"], value);
assert(res.ok);
Expand Down
Loading

0 comments on commit 64bfe85

Please sign in to comment.