@tupik/edge 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # @tupik/edge
2
2
 
3
- Edge adapter for **Tupik**: exposes an app as a fetch handler for Cloudflare Workers. Worker `env` and `ctx`
4
- are forwarded to `ctx.runtime`. Fastly and other fetch-based runtimes are not verified yet (planned).
3
+ Edge adapter for **Tupik**: exposes an app as a fetch handler for Cloudflare Workers and Deno. Worker `env` and
4
+ `ctx` are forwarded to `ctx.runtime`. Verified on Cloudflare Workers (production) and on Deno 2.9.6; Fastly and
5
+ other fetch-based runtimes are not verified yet (planned).
5
6
 
6
7
  ## Install
7
8
 
@@ -26,6 +27,28 @@ const response = await worker.fetch(new Request('https://example.com/'), { GREET
26
27
  console.log(await response.json()); // { greeting: 'hi from the edge' }
27
28
  ```
28
29
 
30
+ ## Deno
31
+
32
+ ```ts
33
+ import { createApp, createModule } from 'npm:@tupik/core';
34
+ import { toEdgeHandler } from 'npm:@tupik/edge';
35
+
36
+ const app = createApp().register(createModule().get('/', { access: 'public', handler: () => ({ hello: 'deno' }) }));
37
+
38
+ Deno.serve({ port: 8000 }, toEdgeHandler(app));
39
+ ```
40
+
41
+ `Deno.serve` passes its `ServeHandlerInfo` (`remoteAddr`, `completed`) as the second argument, so on Deno
42
+ `ctx.runtime.env` is that object, not Worker bindings. Read configuration with `Deno.env` instead of `getEnv`.
43
+
44
+ Verified on Deno 2.9.6 by a real smoke test (public and authenticated routes, 401, 404, 405, a validated JSON body
45
+ and malformed JSON), with the official `deno` npm package, so nothing is downloaded by a shell script:
46
+
47
+ ```bash
48
+ pnpm --filter @tupik/core --filter @tupik/edge build
49
+ pnpm --filter @tupik/edge smoke:deno # npx -y deno@2.9.6 run ... scripts/smoke-deno.ts
50
+ ```
51
+
29
52
  ## Cron, queues and email
30
53
 
31
54
  `createEdgeWorker` also takes the other Worker events. Only the handlers you pass are exported.
package/dist/index.d.mts CHANGED
@@ -85,7 +85,7 @@ interface EdgeWorker<TEnv> {
85
85
  readonly email?: EmailHandler<TEnv>;
86
86
  }
87
87
 
88
- /** Zero-conversion Fetch adapter for Edge runtimes (Cloudflare, Fastly, Deno). */
88
+ /** Zero-conversion Fetch adapter for Edge runtimes (Cloudflare Workers and Deno verified; Fastly not verified yet). */
89
89
  declare function toEdgeHandler<TEnv = unknown>(app: EdgeApp): EdgeHandler<TEnv>;
90
90
  /**
91
91
  * Worker-style module export: `export default createEdgeWorker<Env>(app, { scheduled, queue, email });`.
@@ -95,7 +95,8 @@ declare function toEdgeHandler<TEnv = unknown>(app: EdgeApp): EdgeHandler<TEnv>;
95
95
  declare function createEdgeWorker<TEnv = unknown>(app: EdgeApp, handlers?: EdgeWorkerHandlers<TEnv>): EdgeWorker<TEnv>;
96
96
  /**
97
97
  * Typed access to Worker bindings from a handler: `getEnv<Env>(ctx).MY_KV`.
98
- * Throws when the runtime did not provide an `env` (Deno, Fastly, tests).
98
+ * Throws when the runtime did not provide an `env` (Fastly, tests). On Deno, `Deno.serve` passes its
99
+ * `ServeHandlerInfo` (`remoteAddr`, `completed`) in that position, so `env` is that object.
99
100
  */
100
101
  declare function getEnv<TEnv>(ctx: {
101
102
  readonly runtime: RuntimeBindings;
package/dist/index.d.ts CHANGED
@@ -85,7 +85,7 @@ interface EdgeWorker<TEnv> {
85
85
  readonly email?: EmailHandler<TEnv>;
86
86
  }
87
87
 
88
- /** Zero-conversion Fetch adapter for Edge runtimes (Cloudflare, Fastly, Deno). */
88
+ /** Zero-conversion Fetch adapter for Edge runtimes (Cloudflare Workers and Deno verified; Fastly not verified yet). */
89
89
  declare function toEdgeHandler<TEnv = unknown>(app: EdgeApp): EdgeHandler<TEnv>;
90
90
  /**
91
91
  * Worker-style module export: `export default createEdgeWorker<Env>(app, { scheduled, queue, email });`.
@@ -95,7 +95,8 @@ declare function toEdgeHandler<TEnv = unknown>(app: EdgeApp): EdgeHandler<TEnv>;
95
95
  declare function createEdgeWorker<TEnv = unknown>(app: EdgeApp, handlers?: EdgeWorkerHandlers<TEnv>): EdgeWorker<TEnv>;
96
96
  /**
97
97
  * Typed access to Worker bindings from a handler: `getEnv<Env>(ctx).MY_KV`.
98
- * Throws when the runtime did not provide an `env` (Deno, Fastly, tests).
98
+ * Throws when the runtime did not provide an `env` (Fastly, tests). On Deno, `Deno.serve` passes its
99
+ * `ServeHandlerInfo` (`remoteAddr`, `completed`) in that position, so `env` is that object.
99
100
  */
100
101
  declare function getEnv<TEnv>(ctx: {
101
102
  readonly runtime: RuntimeBindings;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tupik/edge",
3
- "version": "1.1.0",
4
- "description": "Edge adapter for Tupik: Cloudflare Workers, Fastly and any fetch-handler runtime.",
3
+ "version": "1.2.0",
4
+ "description": "Edge adapter for Tupik: Cloudflare Workers, Deno and any fetch-handler runtime.",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "tupik",
@@ -9,6 +9,7 @@
9
9
  "web-framework",
10
10
  "edge",
11
11
  "cloudflare-workers",
12
+ "deno",
12
13
  "fastly",
13
14
  "serverless"
14
15
  ],
@@ -38,7 +39,7 @@
38
39
  "node": ">=22.12"
39
40
  },
40
41
  "dependencies": {
41
- "@tupik/core": "^1.1.0"
42
+ "@tupik/core": "^1.2.0"
42
43
  },
43
44
  "devDependencies": {
44
45
  "typescript": "^5.6.0",
@@ -48,6 +49,7 @@
48
49
  "scripts": {
49
50
  "build": "unbuild",
50
51
  "typecheck": "tsc --noEmit",
51
- "test": "vitest run"
52
+ "test": "vitest run",
53
+ "smoke:deno": "npx -y deno@2.9.6 run --allow-net=127.0.0.1 --allow-env --allow-read scripts/smoke-deno.ts"
52
54
  }
53
55
  }