Skip to content

Commit f5dae8a

Browse files
committed
feat: add blob support to query
1 parent da99dde commit f5dae8a

16 files changed

+535
-335
lines changed

CHANGELOG.md

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@
7171

7272
- feat: make sizeOf public (738b6bf)
7373

74-
`sizeOf()` was previously just internal, but it is generally useful when
75-
working with Deno KV to be able to estimate the size of keys and values. The
76-
Deno KV documentation currently suggests using the length of
77-
`JSON.stringify()` string, which can be very problematic when dealing with
78-
complex values that don't serialize to JSON but are storable in Deno KV.
74+
`sizeOf()` was previously just internal, but it is generally useful when working with Deno KV to be able to estimate
75+
the size of keys and values. The Deno KV documentation currently suggests using the length of `JSON.stringify()`
76+
string, which can be very problematic when dealing with complex values that don't serialize to JSON but are storable
77+
in Deno KV.
7978

8079
## Version 0.20.1
8180

@@ -85,10 +84,9 @@
8584

8685
- feat: arrays, objects, maps and sets are deeply serialized (bf8f285)
8786

88-
Previously only value supported by JSON directly were serialized as values and
89-
keys of arrays, objects, maps and sets. While kv-toolbox can deserialize the
90-
old format, it supports a new JSON format that allows all value supported by
91-
Deno KV to be properly serialized and deserialized.
87+
Previously only value supported by JSON directly were serialized as values and keys of arrays, objects, maps and sets.
88+
While kv-toolbox can deserialize the old format, it supports a new JSON format that allows all value supported by Deno
89+
KV to be properly serialized and deserialized.
9290

9391
- docs: update changelog (38bd7cd)
9492

@@ -141,29 +139,25 @@
141139

142140
- feat: re-work batching for batchedAtomic to align to current Deno KV (e3c8136)
143141

144-
`batchedAtomic()` now aligns to current versions of Deno KV in how it decides
145-
where to _segment_ atomic transactions. Because of the much higher increases
146-
users should consider only using `batchedAtomic()` when dealing with
147-
potentially large transactions where potentially failing due to the size
148-
restriction is awkward or difficult.
142+
`batchedAtomic()` now aligns to current versions of Deno KV in how it decides where to _segment_ atomic transactions.
143+
Because of the much higher increases users should consider only using `batchedAtomic()` when dealing with potentially
144+
large transactions where potentially failing due to the size restriction is awkward or difficult.
149145

150146
- feat: align blob set and get to Deno.Kv APIs (923faf1)
151147

152-
**BREAKING** Previously `set()` resolved with void and `get()` resolved with a
153-
value or `null`. In addition, `getMeta()` resolved with a value.
148+
**BREAKING** Previously `set()` resolved with void and `get()` resolved with a value or `null`. In addition,
149+
`getMeta()` resolved with a value.
154150

155-
Now `set()` resolves with a `Deno.KvCommitResult` and `get()` and `getMeta()`
156-
resolve with a `Deno.KvEntryMaybe` with the appropriate type.
151+
Now `set()` resolves with a `Deno.KvCommitResult` and `get()` and `getMeta()` resolve with a `Deno.KvEntryMaybe` with
152+
the appropriate type.
157153

158154
- feat: add support for checking blobs in batched_atomic (389730a)
159155

160-
`batchedAtomic()` transactions now support `.checkBlob()` checks as part of an
161-
atomic transaction.
156+
`batchedAtomic()` transactions now support `.checkBlob()` checks as part of an atomic transaction.
162157

163158
- feat: add `getAsResponse()` to blob (796ed64)
164159

165-
`getAsResponse()` will retrieve a blob entry as a `Response` which will stream
166-
the blob from the store to a client.
160+
`getAsResponse()` will retrieve a blob entry as a `Response` which will stream the blob from the store to a client.
167161

168162
- chore: linting in blob_util (bd6b888)
169163
- docs: update readme about batchAtomic (bca0fb6)

README.md

Lines changed: 98 additions & 147 deletions
Large diffs are not rendered by default.

batched_atomic.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
assert,
3-
assertEquals,
4-
assertNotEquals,
5-
delay,
6-
setup,
7-
teardown,
8-
} from "./_test_util.ts";
1+
import { assert, assertEquals, assertNotEquals, delay, setup, teardown } from "./_test_util.ts";
92
import { keys } from "./keys.ts";
103

114
import { batchedAtomic } from "./batched_atomic.ts";

batched_atomic.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,7 @@ export class BatchedAtomicOperation {
307307
// if there are multiple mutations, we need to batch them
308308
if (args.length > 1) {
309309
this.#queue.unshift(
310-
...args.map((mutation) =>
311-
[method, [mutation]] as [AtomicOperationKeys, unknown[]]
312-
),
310+
...args.map((mutation) => [method, [mutation]] as [AtomicOperationKeys, unknown[]]),
313311
);
314312
continue;
315313
} else {

blob.test.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import {
2-
assert,
3-
assertEquals,
4-
assertRejects,
5-
assertThrows,
6-
setup,
7-
teardown,
8-
timingSafeEqual,
9-
} from "./_test_util.ts";
1+
import { assert, assertEquals, assertRejects, assertThrows, setup, teardown, timingSafeEqual } from "./_test_util.ts";
102

113
import {
124
get,

blob.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ async function asJSON(
189189
}
190190

191191
function toParts(blob: ArrayBufferLike | ArrayBufferView): string[] {
192-
const buffer = ArrayBuffer.isView(blob)
193-
? new Uint8Array(blob.buffer)
194-
: new Uint8Array(blob);
192+
const buffer = ArrayBuffer.isView(blob) ? new Uint8Array(blob.buffer) : new Uint8Array(blob);
195193
const parts: string[] = [];
196194
let offset = 0;
197195
while (buffer.byteLength > offset) {
@@ -539,13 +537,7 @@ export function list(
539537
if ([stream, blob, bytes, meta].filter(Boolean).length > 1) {
540538
throw new TypeError("Cannot set multiple value types as once.");
541539
}
542-
const valueKind = stream
543-
? "stream"
544-
: blob
545-
? "blob"
546-
: bytes
547-
? "bytes"
548-
: "meta";
540+
const valueKind = stream ? "stream" : blob ? "blob" : bytes ? "bytes" : "meta";
549541
return new BlobListIterator(kv, selector, options, valueKind);
550542
}
551543

@@ -704,8 +696,7 @@ export async function getAsResponse(
704696
});
705697
}
706698
const headers = new Headers(options.headers);
707-
const contentType =
708-
(maybeMeta.value.kind !== "buffer" && maybeMeta.value.type) ||
699+
const contentType = (maybeMeta.value.kind !== "buffer" && maybeMeta.value.type) ||
709700
"application/octet-stream";
710701
headers.set("content-type", contentType);
711702
if (maybeMeta.value.size) {

blob_util.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,10 @@ export async function removeBlob(kv: Deno.Kv, key: Deno.KvKey) {
327327

328328
const AsyncIterator = Object.getPrototypeOf(async function* () {}).constructor;
329329

330-
export class BlobListIterator extends AsyncIterator
331-
implements
332-
Deno.KvListIterator<
333-
BlobMeta | Uint8Array | Blob | File | ReadableStream<Uint8Array>
334-
> {
330+
export class BlobListIterator extends AsyncIterator implements
331+
Deno.KvListIterator<
332+
BlobMeta | Uint8Array | Blob | File | ReadableStream<Uint8Array>
333+
> {
335334
#iterator: Deno.KvListIterator<unknown>;
336335
#count = 0;
337336
#kv: Deno.Kv;

crypto.test.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
assert,
3-
assertEquals,
4-
setup,
5-
teardown,
6-
timingSafeEqual,
7-
} from "./_test_util.ts";
1+
import { assert, assertEquals, setup, teardown, timingSafeEqual } from "./_test_util.ts";
82

93
import { CryptoKv, generateKey } from "./crypto.ts";
104

@@ -31,8 +25,7 @@ Deno.test({
3125
const kv = await setup();
3226
const key = generateKey();
3327
const cryptoKv = new CryptoKv(kv, key);
34-
const value =
35-
globalThis.crypto.getRandomValues(new Uint8Array(65_536)).buffer;
28+
const value = globalThis.crypto.getRandomValues(new Uint8Array(65_536)).buffer;
3629
const res = await cryptoKv.setBlob(["example"], value);
3730
assert(res.ok);
3831
const actual = await cryptoKv.getBlob(["example"]);

crypto.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,7 @@ import { concat } from "@std/bytes/concat";
3737

3838
import { batchedAtomic } from "./batched_atomic.ts";
3939
import { BLOB_KEY, type BlobJSON, type BlobMeta, toJSON } from "./blob.ts";
40-
import {
41-
asMeta,
42-
asUint8Array,
43-
BATCH_SIZE,
44-
removeBlob,
45-
setBlob,
46-
} from "./blob_util.ts";
40+
import { asMeta, asUint8Array, BATCH_SIZE, removeBlob, setBlob } from "./blob_util.ts";
4741
import { keys } from "./keys.ts";
4842

4943
/** Valid data types that can be used when supplying an encryption key. */

deno.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
"test:ci": "deno test --allow-read --allow-write --unstable-kv --junit-path=junit.xml --coverage=./cov --parallel"
2828
},
2929
"lock": false,
30-
"format": {
31-
"lineWidth": 120
32-
},
30+
"fmt": { "lineWidth": 120 },
3331
"imports": {
3432
"@deno/kv-utils": "jsr:@deno/kv-utils@^0.1.3",
3533
"@std/assert": "jsr:@std/assert@~1",

0 commit comments

Comments
 (0)