Cloudflare Workers
Cursor rule: Workers runtime constraints
Puntuación: AAn auto-attached .mdc rule pinning workerd constraints: Web APIs only, no module-scope state, prepared statements, TTL'd KV writes.
---
description: Cloudflare Workers runtime constraints and binding usage
globs: src/**/*.ts
alwaysApply: false
---
# Workers runtime rules
- Target workerd, not Node: Web APIs only (`fetch`, `crypto.subtle`,
`URLPattern`, Web Streams). A dependency that imports `fs` or `net` cannot
ship here.
- Module scope is shared across requests on an isolate - never stash request
or user data there. Derive everything from the request or bindings.
- Access bindings through the typed `Env`:
```ts
app.get("/items/:id", async (c) => {
const row = await c.env.DB.prepare(
"select id, name from items where id = ?1",
).bind(c.req.param("id")).first<Item>();
return row ? c.json(row) : c.notFound();
});
```
- D1: prepared statements with bound params only; string interpolation into
SQL fails review.
- KV: every `put` sets `expirationTtl`. Follow @src/lib/cache.ts for key
naming and TTL tiers.
- After changing `wrangler.jsonc` bindings, regenerate types before writing
code against them.Estos ejemplos se publican bajo CC0: úsalos libremente, sin atribución. Se proveen tal cual, sin garantía de ningún tipo: revísalos y adáptalos a tu proyecto antes de usarlos, ya que eres responsable del resultado de aplicarlos.
Lleva PromptArch a tu equipo
Implementa PromptArch como herramienta interna en cada área de tu empresa. Obtén cuentas de equipo con créditos precargados compartidos y dominios personalizados para tu organización.
Contáctanos