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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@shukoi/cloudflare

v1.0.4

Published

Cloudflare Workers V8 Isolate runtime adapter with waitUntil lifecycle integration for Shukoi.

Readme

@shukoi/cloudflare

Cloudflare Workers (V8 Isolates) Runtime Adapter for Shukoi Applications

npm version License: MIT Pure Web Standard

@shukoi/cloudflare adapts Shukoi Hono applications to Cloudflare Workers edge runtimes. It operates entirely within V8 Isolate constraints without requiring Node.js compatibility flags, seamlessly bridges Cloudflare environment bindings (D1, KV, R2, Queues), and connects executionCtx.waitUntil for post-response background task execution.


Key Features & Invariants

  • Pure Web-Standard Implementation: Contains zero node:* imports or native C++ addons, guaranteeing compliance with Cloudflare's strict edge isolate runtime.
  • Sub-5ms Cold Starts: Zero bundling overhead and lightweight AST-fallback validation deliver instantaneous edge execution.
  • Platform Environment Injection: Injects Cloudflare Workers env directly into ctx.platform.env across all action executions.
  • executionCtx.waitUntil Integration: Bridges asynchronous ctx.onFinally() hooks and telemetry directly to executionCtx.waitUntil(...), allowing responses to be returned to clients immediately while locks and audit logs complete in the background.

Installation

pnpm add @shukoi/cloudflare @shukoi/api @shukoi/core hono
# or
npm install @shukoi/cloudflare @shukoi/api @shukoi/core hono
# or
bun add @shukoi/cloudflare @shukoi/api @shukoi/core hono

Usage

1. Worker Entrypoint (src/entries/cloudflare.ts)

import { createRestRouter } from '@shukoi/api';
import { toCloudflareWorker } from '@shukoi/cloudflare';
import { createDefaultConfig } from '@shukoi/core';
import { myAction } from '../actions/myAction.js';

const config = createDefaultConfig();
const app = createRestRouter([myAction], config);

// Exports default object with { fetch(request, env, executionCtx) }
export default toCloudflareWorker(app);

2. Wrangler Configuration (wrangler.jsonc)

{
  "$schema": "node_modules/wrangler/config-schema.json",
  "name": "my-shukoi-worker",
  "main": "src/entries/cloudflare.ts",
  "compatibility_date": "2026-11-15",
  "compatibility_flags": ["nodejs_compat"],
  "observability": {
    "enabled": true
  }
  // Optional Cloudflare D1 / KV / R2 bindings
  // "kv_namespaces": [{ "binding": "CACHE", "id": "..." }],
  // "d1_databases": [{ "binding": "DB", "database_name": "db", "database_id": "..." }]
}

3. Accessing Bindings in Actions (getCloudflareContext)

import { defineAction } from '@shukoi/core';
import { getCloudflareContext } from '@shukoi/cloudflare';
import { Type } from '@sinclair/typebox';

interface Env {
  DB: D1Database;
  CACHE: KVNamespace;
}

export const myAction = defineAction({
  name: 'myAction',
  input: Type.Object({ id: Type.String() }),
  output: Type.Object({ name: Type.String() }),
  async handler(input, ctx) {
    const { env, waitUntil } = getCloudflareContext<Env>(ctx);

    // 100% Type-Safe access to D1 and KV:
    const user = await env.DB.prepare('SELECT name FROM users WHERE id = ?')
      .bind(input.id)
      .first<{ name: string }>();

    // Background task via executionCtx.waitUntil:
    waitUntil(env.CACHE.put(`user:${input.id}`, JSON.stringify(user)));

    return user ?? { name: 'Anonymous' };
  },
});

4. Lightning-Fast Unit Testing (@shukoi/cloudflare/testing)

Test actions with in-memory KV and D1 test doubles in Vitest without Miniflare or Docker:

import { createActionTestHarness } from '@shukoi/core/testing';
import { createMockD1, createMockKv } from '@shukoi/cloudflare/testing';
import { describe, expect, it } from 'vitest';
import { myAction } from '../src/actions/myAction.js';

describe('myAction', () => {
  it('reads from D1 and writes to KV cache', async () => {
    const mockDb = createMockD1({ defaultRows: [{ name: 'Alice' }] });
    const mockCache = createMockKv();

    const harness = createActionTestHarness({
      platform: {
        env: { DB: mockDb, CACHE: mockCache },
        waitUntil: (p) => void p,
      },
    });

    const result = await harness.execute(myAction, { id: '1' });
    expect(result.name).toBe('Alice');
  });
});

API Reference

toCloudflareWorker(app)

Wraps a Hono application instance into a standard Cloudflare Worker module export.

getCloudflareContext<TEnv>(ctx)

Extracts strongly-typed Cloudflare Workers bindings (env) and lifecycle helpers (waitUntil) from ActionExecutionContext.

@shukoi/cloudflare/testing

  • createMockKv(initialData?): In-memory KVNamespace test double.
  • createMockD1(options?): In-memory D1Database test double supporting .prepare(), .bind(), .first(), .all(), and .run().

Related Documentation & Architecture


License

MIT © Shukoi Contributors