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

remote-cloudflare-kv

v1.0.1

Published

A Cloudflare KV SDK for Remote use.

Downloads

7

Readme

remote-cloudflare-kv

npm npm npm

Setup

npm install --save remote-cloudflare-kv
# or
yarn add remote-cloudflare-kv
# or
pnpm install --save remote-cloudflare-kv

Usage

Init

import CloudflareKV from 'remote-cloudflare-kv';

export const NAMESPACE = new CloudflareKV({
  account_id: process.env.CF_ACCOUNT_ID || '',
  namespace_id: process.env.CF_NAMESPACE_ID || '',
  // use bearer token
  api_token: process.env.CF_API_TOKEN || '',
  // or use email & api key
  api_email: '',
  api_key: ''
});

Writing key-value pairs

To create a new key-value pair, or to update the value for a particular key, call the put method on any namespace you have bound to your script. The basic form of this method looks like this:

await NAMESPACE.put(key, value);
// void

Expiring keys:

await NAMESPACE.put(key, value, { expiration: secondsSinceEpoch });

await NAMESPACE.put(key, value, { expirationTtl: secondsFromNow });

Metadata:

await NAMESPACE.put(key, value, {
  metadata: { someMetadataKey: 'someMetadataValue' }
});

Get key-value pair

To get the value for a given key, you can call the get method on any namespace you have bound to your script:

// replace key & type
const result = await NAMESPACE.get('key', { type: 'json' });
console.log(result);
// {"hello": 1}

Supported types: text, json, arrayBuffer, stream.

Normalises type, ignoring cacheTtl as there is only one "edge location": the user's computer

Get key-value pair with Metadata

You can get the metadata associated with a key-value pair alongside its value by calling the getWithMetadata method on a namespace you have bound in your script:

const result = await NAMESPACE.getWithMetadata(key, { type: 'json' });
//  {"value": {"hello": 1}, "metadata": {"someKey": "someVal"}}

Deleting key-value pairs

To delete a key-value pair, call the delete method on any namespace you have bound to your script:

await NAMESPACE.delete(key);
// void

Listing keys

You can use a list operation to see all of the keys that live in a given namespace.

const result = await NAMESPACE.list();
console.log(result);

More detail:

The list method has this signature (in TypeScript):

await NAMESPACE.list({ prefix: string, limit: number, cursor: string });

The list method returns a promise which resolves with an object that looks like this:

{
  "keys": [
    {
      "name": "foo",
      "expiration": 1234,
      "metadata": { "someMetadataKey": "someMetadataValue" }
    }
  ],
  "list_complete": false,
  "cursor": "6Ck1la0VxJ0djhidm1MdX2FyD"
}

Refs

赞助 Sponsor

如果您对本项目感兴趣,可以通过以下方式支持我:

Donation ways:

许可证 License

Apache-2.0 © https://willin.wang