Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Deno Fest 2023 @Tokyo - Chiezo

Chiezo
October 20, 2023

Deno Fest 2023 @Tokyo - Chiezo

Chiezo

October 20, 2023
Tweet

Other Decks in Programming

Transcript

  1. Who's speaking? Chiezo @hasundue Legal name: Shun Ueda A housemaker,

    PhD (Engineering) Field: high-temperature processing of materials e.g. Cooking Amateur programmer Vim/Neovim (2009-) Julia (2016-) Deno (2021-) 3
  2. What's Deno KV? Deno KV is a key-value database built

    directly into the Deno runtime, ... available in the Deno CLI and on Deno Deploy. https://docs.deno.com/kv/manual const kv = await Deno.openKv(); const prefs = { username: "ada", theme: "dark", language: "en-US", }; const result = await kv.set(["preferences", "ada"], prefs); const entry = await kv.get(["preferences", "ada"]); 5
  3. What to build? Logging on Deno Deploy: ... After closing

    the logs page, all streamed logs are discarded. https://docs.deno.com/deploy /manual/logs Can be persisted with Deno KV? 6
  4. Branding Name ... Paleon (paleontology) Character ... A cute illustration

    of a child dinosaur who is conducting a paleontological study (by Bing Image Creator) 7
  5. Time-series data in Deno KV? JavaScript arrays as keys const

    key = [...prefix, Date.now(), crypto.randomUUID()]; return kv.set(key, record); std/ulid is a better choice right now Ordering ... within a given type, they are ordered by their value. https://docs.deno.com/kv/manual/key_space const iter = kv.list<T>({ start, end }, { limit, reverse }); 8
  6. Designing APIs Abstraction of KV interface import { PaleonStorage }

    from "./mod.ts"; type TestLogRecord = { datetime: Date; msg: string; }; const paleon = await PaleonStorage.open<TestLogRecord>("my-app"); await paleon.write({ datetime: new Date(), msg: "hello" }); for await (const record of paleon.read()) { console.log(record); } 9
  7. Integration with std/log import * as log from "$std/log/mod.ts"; import

    { BaseHandler } from "$std/log/handlers.ts"; class LocalPaleonHandler extends BaseHandler { ... } setup({ handlers: { console: new handlers.ConsoleHandler("DEBUG"), paleon: await LocalPaleonHandler.init("DEBUG"), }, loggers: { default: { level: "DEBUG", handlers: ["console", "paleon"] }, }, }); const logger = getLogger(); 10
  8. Client integrated with std/log import * as log from "https://deno.land/std/log/mod.ts";

    import { PaleonAppHandler } from "./client.ts"; log.setup({ handlers: { console: new log.handlers.ConsoleHandler("DEBUG"), paleon: new PaleonAppHandler("DEBUG", { project: "{PROJECT_NAME}", id: "{DEPLOYMENT_ID}", }), }, loggers: { default: { level: "DEBUG", handlers: ["console", "paleon"] }, }, }); const logger = getLogger(); logger.info("Hello Paleon!"); 12
  9. See also... Other works by me: denopendabot ... https://github.com/apps/denopendabot Dependabot-like

    GitHub App on Deno Deploy deno-molt ... https://deno.land/x/molt Update dependencies using deno_graph and more ... Find me on: GitHub ... https://github.com/hasundue Slack → deno-ja, vim-jp Discord → Deno official 16