Breaking
-
(kv) The
read
export now returnsPromise<T | null>
instead ofPromise<T | false>
: a2edaa4
This is only breaking if your data integrity checks did strict comparison againstfalse
values.
Note: This also affects theDatabase.get
method.import { read } from 'worktop/kv'; import type { Item } from 'lib/example'; let item = await read<Item>(binding, 'my:key'); // ^ BEFORE: Item | false // ^ AFTER: Item | null
-
(kv): Move the
toJSON
parameter forwrite
andDatabase.put
into a newoptions
argument: 861a4e9
Note: The default behavior is unchanged.import { write, Database } from 'worktop/kv'; let DB = new Database(binding); // BEFORE: await write(binding, 'my:key', 'value', false); await DB.put('my:key', 'value', false); // AFTER: await write(binding, 'my:key', 'value', { toJSON: false }); await DB.put('my:key', 'value', { toJSON: false });
Features
-
Add
worktop/ws
module (#48): 8beefdf
Check out #48 for examples and documentationimport { Router, compose } from 'worktop'; import * as ws from 'worktop/ws'; // userland code import * as Token from 'lib/token'; import * as Chat from 'lib/chat'; const API = new Router; API.add('GET', '/chat/:lobby', compose( Token.isValid, // verify token exists & is valid Chat.isAuthorized, // verify user can access this room ws.listen(Chat.handler) // the SocketHandler for WS events ));
-
(kv) Add
list
method for keys generator (#47): e97bb57
Returns anAsyncGenerator
you can use to manually apply your own stop-until-X logic. -
(kv) Add
paginate
method for keys paging (#47): abbdf7f, e14e1bd
Applies the 90% use case for consuming thelist()
iterator:let keys = await database.paginate(BINDING, { prefix: 'users::1234::projects', limit: 25, page: 3 }); // ^ This will skip the first 50 keys (2 x 25) and // then return the 0-25 keys that constitute a "page 3". // If you supply a `limit` x `page` combination that exceeds // the total keys, then an empty array is returned early.
-
(kv) Add
options.metadata
support to allread
andwrite
methods (#46): 73e8160
Metadata allows you to assign additional information/context to a key. This is particularly useful whenlist
ing orpaginate
ing keys. -
(crypto) Add
timingSafeEqual
method (#34, #45): 200999a
A constant-time TypedArray comparison utility.
Examples
- Include new
paginate
utility within thekv-todos
example: e14e1bd
Patches
- (kv): Add
KV.Namespace[getWithMetadata]
types: d381808 - (kv): Aefine all
read
type overloads: e609be2 - (kv): Define
null
return type fromKV.Namespace[get]
: 58beaec - (kv): Add
options
variants toKV.Namespace[get]
method: 7c9ab8b