From 64bfe855be6dc715e63bab2ee24d4279e2ca6bcc Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Fri, 6 Sep 2024 08:35:22 +1000 Subject: [PATCH] chore: update deps and Deno v2 --- .github/workflows/ci.yml | 5 ++++- _test_util.ts | 39 +++++++++++++++++++++++---------------- batched_atomic.test.ts | 12 ++++++------ blob.test.ts | 34 +++++++++++++++++----------------- blob.ts | 10 +++++----- crypto.test.ts | 17 +++++++++-------- crypto.ts | 24 ++++++++++++------------ json.ts | 2 +- keys.ts | 2 +- ndjson.ts | 10 +++++----- 10 files changed, 83 insertions(+), 72 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cbe6e15..13ededa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,9 @@ on: [push, pull_request] jobs: ci: runs-on: ubuntu-latest + strategy: + matrix: + version: ["v1.x", canary] steps: - name: clone repository uses: actions/checkout@v4 @@ -12,7 +15,7 @@ jobs: - name: install deno uses: denoland/setup-deno@v1 with: - deno-version: 1.x + deno-version: ${{ matrix.version }} - name: check format run: deno fmt --check diff --git a/_test_util.ts b/_test_util.ts index df33404..9b369a5 100644 --- a/_test_util.ts +++ b/_test_util.ts @@ -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 { - 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(); } diff --git a/batched_atomic.test.ts b/batched_atomic.test.ts index 1d532e0..0e117a1 100644 --- a/batched_atomic.test.ts +++ b/batched_atomic.test.ts @@ -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) @@ -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) @@ -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(); @@ -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); diff --git a/blob.test.ts b/blob.test.ts index 28c3daf..1850726 100644 --- a/blob.test.ts +++ b/blob.test.ts @@ -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); @@ -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); @@ -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); @@ -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); @@ -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, @@ -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"] }); @@ -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); @@ -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); @@ -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; @@ -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); @@ -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"], @@ -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"], @@ -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); @@ -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", @@ -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" }), ); @@ -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); @@ -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"]); diff --git a/blob.ts b/blob.ts index 3497e65..eb41cd0 100644 --- a/blob.ts +++ b/blob.ts @@ -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 { @@ -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> { - return await asMeta(kv, key, options); + return asMeta(kv, key, options); } /** Options which can be used when calling {@linkcode getAsResponse}. */ diff --git a/crypto.test.ts b/crypto.test.ts index 0132ea4..1d500f9 100644 --- a/crypto.test.ts +++ b/crypto.test.ts @@ -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"]); @@ -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"]); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/crypto.ts b/crypto.ts index d1227dc..bbb9a25 100644 --- a/crypto.ts +++ b/crypto.ts @@ -19,7 +19,7 @@ * const kv = await openCryptoKv(generateKey()); * const res = await kv.setBlob( * ["hello"], - * window.crypto.getRandomValues(new Uint8Array(65_536)), + * globalThis.crypto.getRandomValues(new Uint8Array(65_536)), * ); * if (res.ok) { * const maybeValue = await kv.getBlob(["hello"]); @@ -31,9 +31,9 @@ * @module */ -import { assert } from "jsr:@std/assert@0.225/assert"; -import { decodeHex, encodeHex } from "jsr:@std/encoding@0.224/hex"; -import { concat } from "jsr:@std/bytes@0.224/concat"; +import { assert } from "jsr:@std/assert@~1/assert"; +import { decodeHex, encodeHex } from "jsr:@std/encoding@~1/hex"; +import { concat } from "jsr:@std/bytes@~1/concat"; import { batchedAtomic } from "./batched_atomic.ts"; import { BLOB_KEY, type BlobMeta } from "./blob.ts"; @@ -136,7 +136,7 @@ export class CryptoKv { console.log(); const cryptoKey = this.#cryptoKey ?? (this.#cryptoKey = await importKey(this.#key!)); - return window.crypto.subtle.decrypt( + return globalThis.crypto.subtle.decrypt( { name: "AES-GCM", iv }, cryptoKey, chunk, @@ -214,7 +214,7 @@ export class CryptoKv { assert(this.#key); const key = this.#cryptoKey ?? (this.#cryptoKey = await importKey(this.#key)); - const iv = window.crypto.getRandomValues(new Uint8Array(12)); + const iv = globalThis.crypto.getRandomValues(new Uint8Array(12)); if ( ArrayBuffer.isView(blob) || blob instanceof ArrayBuffer || blob instanceof SharedArrayBuffer @@ -222,7 +222,7 @@ export class CryptoKv { return concat([ iv, new Uint8Array( - await window.crypto.subtle.encrypt( + await globalThis.crypto.subtle.encrypt( { name: "AES-GCM", iv }, key, blob, @@ -236,7 +236,7 @@ export class CryptoKv { return new File( [ iv, - await window.crypto.subtle.encrypt( + await globalThis.crypto.subtle.encrypt( { name: "AES-GCM", iv }, key, buffer, @@ -249,7 +249,7 @@ export class CryptoKv { const { type } = blob; return new Blob([ iv, - await window.crypto.subtle.encrypt( + await globalThis.crypto.subtle.encrypt( { name: "AES-GCM", iv }, key, buffer, @@ -272,7 +272,7 @@ export class CryptoKv { const iv = blob.slice(0, 12); const message = blob.slice(12); return new Uint8Array( - await window.crypto.subtle.decrypt( + await globalThis.crypto.subtle.decrypt( { name: "AES-GCM", iv }, key, message, @@ -446,7 +446,7 @@ export class CryptoKv { * const kv = await openCryptoKv(generateKey()); * const res = await kv.setBlob( * ["hello"], - * window.crypto.getRandomValues(new Uint8Array(65_536)), + * globalThis.crypto.getRandomValues(new Uint8Array(65_536)), * ); * if (res.ok) { * // the commit was successful @@ -524,7 +524,7 @@ export function generateKey(bitLength: 128 | 192 | 256 = 256): string { if (![128, 192, 256].includes(bitLength)) { throw new RangeError("Bit length must be 128, 192, or 256."); } - const raw = window.crypto.getRandomValues(new Uint8Array(bitLength / 8)); + const raw = globalThis.crypto.getRandomValues(new Uint8Array(bitLength / 8)); return encodeHex(raw); } diff --git a/json.ts b/json.ts index d3378b3..f1f913c 100644 --- a/json.ts +++ b/json.ts @@ -37,7 +37,7 @@ import { decodeBase64Url, encodeBase64Url, -} from "jsr:@std/encoding@0.224/base64url"; +} from "jsr:@std/encoding@~1/base64url"; // Deno KV Key types diff --git a/keys.ts b/keys.ts index dde81fa..18cb4cf 100644 --- a/keys.ts +++ b/keys.ts @@ -144,7 +144,7 @@ * @module */ -import { timingSafeEqual } from "jsr:@std/crypto@0.224/timing-safe-equal"; +import { timingSafeEqual } from "jsr:@std/crypto@~1/timing-safe-equal"; import { BLOB_KEY, BLOB_META_KEY } from "./blob_util.ts"; diff --git a/ndjson.ts b/ndjson.ts index bb5fac2..899fffd 100644 --- a/ndjson.ts +++ b/ndjson.ts @@ -31,11 +31,11 @@ * @module */ -import { concat } from "jsr:@std/bytes@0.224/concat"; +import { concat } from "jsr:@std/bytes@~1/concat"; import { entryToJSON, type KvEntryJSON, toKey, toValue } from "./json.ts"; -interface ExportEntriesOptionsJSON extends Deno.KvListOptions { +export interface ExportEntriesOptionsJSON extends Deno.KvListOptions { /** * Determines if the function should close the provided KV store once all the * entities are exported. By default, the store won't be closed. @@ -49,7 +49,7 @@ interface ExportEntriesOptionsJSON extends Deno.KvListOptions { text: true; } -interface ExportEntriesOptionsBytes extends Deno.KvListOptions { +export interface ExportEntriesOptionsBytes extends Deno.KvListOptions { /** * Determines if the function should close the provided KV store once all the * entities are exported. By default, the store won't be closed. @@ -139,7 +139,7 @@ export interface ImportEntriesOptions { /** * The result returned from calling {@linkcode importEntries}. */ -interface ImportEntriesResult { +export interface ImportEntriesResult { /** If set, the import process was aborted prior to completing. */ aborted?: true; /** The number of entries read from the input data. */ @@ -450,7 +450,7 @@ export async function importEntries( let errors = 0; let skipped = 0; while (true) { - let result: ReadableStreamDefaultReadResult | undefined = undefined; + let result: ReadableStreamReadResult | undefined = undefined; try { result = await reader.read(); if (result.value) {