0.6.3 • Published 9 months ago

cf-workers-proxy v0.6.3

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

cf-workers-proxy

Download Version

Enable Cloudflare Workers runtime for local development. Compatible with DrizzleORM.

Get Started

Install wrangler

npm i -D wrangler

Install cf-workers-proxy

npm i -D cf-workers-proxy

Example wrangler.toml

name = "worker"
compatibility_date = "2023-07-02"

[[d1_databases]]
binding = "D1"
database_name = "D1"
database_id = "<d1-id>"

[[kv_namespaces]]
binding = "KV"
id = "<kv-id>"
preview_id = "<same-kv-id-as-above>"

[[services]]
binding = "WORKER"
service = "<worker-name>"
environment = "production"

Start proxy

npx wrangler node_modules/cf-workers-proxy/dist/worker.js --remote

Example SvelteKit project

// file: app.d.ts

declare global {
  namespace App {
    interface Locals {
      D1: D1Database;
    }
    interface Platform {
      env?: {
        D1: D1Database;
      };
    }
  }
}

export {};
// file: src/hooks.server.ts

import { createD1 } from 'cf-workers-proxy';

export const handle = ({ event, resolve }) => {
  event.locals.D1 = event.platform?.env?.D1 ?? createD1('D1');
  // or createD1('D1', { hostname: 'custom-host-name' });
  // default hostname is `http://127.0.0.1:8787`
  return resolve(event);
};

Roadmap

  • ❌ Not started
  • 🟡 Partially implemented
  • ✅ Complete

D1Database

import { createD1 } from 'cf-workers-proxy';
FunctionStatus
prepare()
batch()
dump()
exec()

D1PreparedStatement

FunctionStatus
first()
run()
all()
raw()
bind()

Service Bindings

import { createServiceBinding } from 'cf-workers-proxy';
FunctionStatus
fetch()
connect()

KVNamespace

import { createKV } from 'cf-workers-proxy';
FunctionStatus
put()🟡
get()🟡
getWithMetadata()
delete()
list()

waitUntil

// file: app.d.ts
namespace App {
  interface Platform {
    context: {
      waitUntil(promise: Promise<any>): void;
    };
  }
}
// file: +page.server.ts
import { waitUntil } from 'cf-workers-proxy';

export const actions = {
  default: ({ locals, platform }) => {
    waitUntil(async () => {}, platform?.context.waitUntil);
    return { message: 'success' };
  },
};

Contributing

or pull request 😐

0.5.10

9 months ago

0.5.11

9 months ago

0.5.8

9 months ago

0.5.7

9 months ago

0.5.9

9 months ago

0.1.0

10 months ago

0.3.0

10 months ago

0.2.0

10 months ago

0.6.3

9 months ago

0.5.4

9 months ago

0.6.2

9 months ago

0.5.3

9 months ago

0.5.6

9 months ago

0.5.5

9 months ago

0.5.0

9 months ago

0.4.0

9 months ago

0.6.1

9 months ago

0.5.2

9 months ago

0.6.0

9 months ago

0.5.1

9 months ago

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago