github lukeed/worktop v0.6.0

latest releases: v0.8.0-next.18, v0.8.0-next.16, v0.8.0-next.17...
2 years ago

Breaking

  • (kv) The read export now returns Promise<T | null> instead of Promise<T | false>: a2edaa4
    This is only breaking if your data integrity checks did strict comparison against false values.
    Note: This also affects the Database.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 for write and Database.put into a new options 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 documentation

    import { 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 an AsyncGenerator 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 the list() 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 all read and write methods (#46): 73e8160
    Metadata allows you to assign additional information/context to a key. This is particularly useful when listing or paginateing keys.

  • (crypto) Add timingSafeEqual method (#34, #45): 200999a
    A constant-time TypedArray comparison utility.

Examples

  • Include new paginate utility within the kv-todos example: e14e1bd

Patches

  • (kv): Add KV.Namespace[getWithMetadata] types: d381808
  • (kv): Aefine all read type overloads: e609be2
  • (kv): Define null return type from KV.Namespace[get]: 58beaec
  • (kv): Add options variants to KV.Namespace[get] method: 7c9ab8b

Chores

  • (utils): Decrease unique-check test counts (1M -> 50k): 9717931
  • (kv): Reorganize KV types: 807f927

Don't miss a new worktop release

NewReleases is sending notifications on new releases.