npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

denokvclient

v1.0.2

Published

A simple client wrapper for the Deno KV (Key-Value) store.

Downloads

170

Readme

DenoKvClient - Wrapper for Deno KV

A simple client wrapper for the Deno KV (Key-Value) store, written in JavaScript. This library provides a convenient way to interact with the Deno KV service, with support for creating, reading, updating, and deleting data.

Installation

To use the DenoKvClient, you need install a dependency in your project:

yarn add denokvclient

I'm use this on my own Deno KV server.

Usage

  1. Import the DenoKvClient class:
import { DenoKvClient, createSchema } from "denokvclient";

import { z } from "zod";
import "dotenv/config";
import { v4 as uuidv4 } from "uuid";
  1. Initialize the client with the Deno KV service URL and an access token:
// Define your schemas
export const User = z.object({
  id: z.optional(z.string().uuid()).describe("primary"),
  createdAt: z.optional(z.date()),
  name: z.string(),
  email: z.string().email(),
});

export const Order = z.object({
  id: z.optional(z.string().uuid()).describe("primary"),
  createdAt: z.optional(z.date()),
  name: z.string(),
  userId: z.string().uuid(),
});

// Define schemas with relationscd
const schema = createSchema().model({
  users: {
    schema: User,
    relations: {
      orders: ["orders", [Order], "id", "userId"],
    },
  },
  orders: {
    schema: Order,
    relations: {
      user: ["users", User, "userId", "id"],
    },
  },
});

const client = new DenoKvClient(schema);
await client.init("http://0.0.0.0:4512", "your_access_token_here");
  1. Use the client to interact with the Deno KV store:
// Create a new entry
const newUser = await client.users.create({
  data: {
    username: "ola",
    name: "Ola",
    age: 31,
  },
  select: {
    age: true,
    name: true,
  },
});
console.log(newUser);

// Find a unique entry
const user = await client.users.findUnique({
  where: {
    username: "ola",
  },
  select: {
    age: true,
    username: true,
    tags: true,
  },
});
console.log(user);

// Update an entry
const updatedUser = await client.users.update({
  where: {
    username: "ola",
  },
  data: {
    name: "Ola Updated",
    age: 32,
    tags: [
      { id: 1, tag: "hello" },
      { id: 2, tag: "world" },
      { id: 3, tag: "example" },
    ],
  },
  select: {
    name: true,
    age: true,
  },
});
console.log(updatedUser);

////////////// matchesWhere //////////////

// Find users with email starting with "john"
const usersStartingWithJohn = await client.users.findMany({
  where: {
    email: {
      startsWith: "john",
    },
  },
});
console.log("Users with email starting with 'john':", usersStartingWithJohn);

// Filtered users
const filteredUsers = await client.users.findMany({
  where: {
    name: {
      contains: "John", // name contains "John"
    },
    email: {
      endsWith: "@example.com", // email ends with "@example.com"
    },
  },
});
console.log("Filtered users:", filteredUsers);

Features

  • Namespace Support: The client uses a proxy to dynamically create namespaces (e.g., client.users, client.bans) for managing data.

  • CRUD Operations: Supports creating, reading, updating, and deleting data in the Deno KV store.

  • Selective Data Fetching: The select option allows you to specify which fields should be returned in the response.

  • Error Handling: The client provides basic error handling and can be extended to handle more complex error scenarios.

Contributing

If you find any issues or would like to contribute to the project, feel free to open a pull request or submit an issue on the GitHub repository.

License

This project is licensed under the MIT License.