@fastly/hono-fastly-compute 0.3.2 → 0.3.4

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/CHANGELOG.md CHANGED
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [unreleased]
9
9
 
10
+ ## [0.3.4] - 2025-10-17
11
+
12
+ ### Added
13
+
14
+ - Improve `executionCtx` and `event` integration
15
+
16
+ ## [0.3.3] - 2025-10-15
17
+
18
+ ### Changed
19
+
20
+ - Change debugging definition field to `_defs`
21
+
22
+ ### Added
23
+
24
+ - Expose default `fire` and `Bindings`
25
+
10
26
  ## [0.3.2] - 2025-10-14
11
27
 
12
28
  ### Added
@@ -32,7 +48,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
32
48
 
33
49
  - Initial public release
34
50
 
35
- [unreleased]: https://github.com/fastly/hono-fastly-compute/compare/v0.3.2...HEAD
51
+ [unreleased]: https://github.com/fastly/hono-fastly-compute/compare/v0.3.4...HEAD
52
+ [0.3.4]: https://github.com/fastly/hono-fastly-compute/compare/v0.3.3...v0.3.4
53
+ [0.3.3]: https://github.com/fastly/hono-fastly-compute/compare/v0.3.2...v0.3.3
36
54
  [0.3.2]: https://github.com/fastly/hono-fastly-compute/compare/v0.3.1...v0.3.2
37
55
  [0.3.1]: https://github.com/fastly/hono-fastly-compute/compare/v0.3.0...v0.3.1
38
56
  [0.3.0]: https://github.com/fastly/hono-fastly-compute/compare/v0.1.0...v0.3.0
package/README.md CHANGED
@@ -35,10 +35,7 @@ const fire = buildFire({
35
35
  });
36
36
 
37
37
  // Use the inferred Bindings type in your Hono environment
38
- type Env = {
39
- Bindings: typeof fire.Bindings;
40
- };
41
- const app = new Hono<Env>();
38
+ const app = new Hono<{ Bindings: typeof fire.Bindings }>();
42
39
 
43
40
  app.get('/', async (c) => {
44
41
  // Access your bindings from the context
@@ -50,15 +47,33 @@ app.get('/', async (c) => {
50
47
  fire(app);
51
48
  ```
52
49
 
50
+ ### Example with no user resources
51
+
52
+ An application that defines no user resources is even simpler:
53
+
54
+ ```typescript
55
+ import { Hono } from 'hono';
56
+ import { fire, type Bindings } from '@fastly/hono-fastly-compute';
57
+
58
+ const app = new Hono<{ Bindings: Bindings }>();
59
+
60
+ app.get('/', async (c) => {
61
+ // `clientInfo` and `serverInfo` are always available on `c.env`.
62
+ const clientInfo = c.env.clientInfo;
63
+ c.text(`Accessed from ${clientInfo.address}`);
64
+ });
65
+
66
+ fire(app);
67
+ ```
68
+
53
69
  ### Using the `logFastlyServiceVersion` Middleware
54
70
 
55
71
  This package includes a simple middleware to log the `FASTLY_SERVICE_VERSION` for debugging purposes.
56
72
 
57
73
  ```typescript
58
74
  import { Hono } from 'hono';
59
- import { buildFire, logFastlyServiceVersion } from '@fastly/hono-fastly-compute';
75
+ import { fire, logFastlyServiceVersion } from '@fastly/hono-fastly-compute';
60
76
 
61
- const fire = buildFire({});
62
77
  const app = new Hono();
63
78
 
64
79
  // Use the middleware
@@ -86,9 +101,18 @@ The returned `fire` function has two purposes:
86
101
  1. When called with a Hono app instance (`fire(app)`), it registers the app to handle fetch events.
87
102
  2. It exposes a `Bindings` type (`typeof fire.Bindings`) that you can use to define your Hono `Env`.
88
103
 
104
+ ### `fire(app, options)`
105
+
106
+ Registers your Hono app to handle fetch events. No user-defined bindings are
107
+ applied to `c.env`. Equivalent to the return value of `buildFire({})`.
108
+
109
+ ### Type `Bindings`
110
+
111
+ Default bindings which can be used when no user-defined bindings are present. Alias of `fire.Bindings`.
112
+
89
113
  ### `handle(app, bindingsDefs, options)`
90
114
 
91
- The core adapter function that connects Hono to the Fastly Compute `FetchEvent`. The `buildFire` function is a higher-level utility that uses `handle` internally.
115
+ The core adapter function that connects Hono to the Fastly Compute `FetchEvent`. The `fire` function is a higher-level utility that uses `handle` internally.
92
116
 
93
117
  - **`app`**: The Hono application instance.
94
118
  - **`bindingsDefs`**: The environment bindings definition.
@@ -96,14 +120,13 @@ The core adapter function that connects Hono to the Fastly Compute `FetchEvent`.
96
120
 
97
121
  ### `clientInfo` and `serverInfo`
98
122
 
99
- `clientInfo` ([ClientInfo](https://github.com/fastly/js-compute-runtime/blob/f9d6a121f13efbb586d6af210dedec61661dfc6d/types/globals.d.ts#L419-L436)) and `serverInfo` ([ServerInfo](https://github.com/fastly/js-compute-runtime/blob/f9d6a121f13efbb586d6af210dedec61661dfc6d/types/globals.d.ts#L438-L446)) are defined on `fire.Bindings` and available on `c.env`, even if the bindings definitions are empty:
123
+ `clientInfo` ([ClientInfo](https://github.com/fastly/js-compute-runtime/blob/f9d6a121f13efbb586d6af210dedec61661dfc6d/types/globals.d.ts#L419-L436)) and `serverInfo` ([ServerInfo](https://github.com/fastly/js-compute-runtime/blob/f9d6a121f13efbb586d6af210dedec61661dfc6d/types/globals.d.ts#L438-L446)) are always defined on `fire.Bindings` and can be made available on `c.env`, even if the bindings definitions are empty:
100
124
 
101
125
  ```typescript
102
126
  import { Hono } from 'hono';
103
- import { buildFire } from '@fastly/hono-fastly-compute';
127
+ import { fire, type Bindings } from '@fastly/hono-fastly-compute';
104
128
 
105
- const fire = buildFire({});
106
- const app = new Hono<{Bindings: typeof fire.Bindings}>();
129
+ const app = new Hono<{ Bindings: Bindings }>();
107
130
 
108
131
  app.get('/', (c) => {
109
132
  const clientInfo = c.env.clientInfo;
@@ -125,9 +148,8 @@ An implementation of the [ConnInfo helper](https://hono.dev/docs/helpers/conninf
125
148
 
126
149
  ```typescript
127
150
  import { Hono } from 'hono';
128
- import { buildFire, getConnInfo } from '@fastly/hono-fastly-compute';
151
+ import { fire, getConnInfo } from '@fastly/hono-fastly-compute';
129
152
 
130
- const fire = buildFire({});
131
153
  const app = new Hono();
132
154
 
133
155
  app.get('/', (c) => {
package/build/fire.d.ts CHANGED
@@ -37,7 +37,7 @@ type FireFn<D extends BindingsDefs> = {
37
37
  */
38
38
  Bindings: BindingsWithClientInfo<D>;
39
39
  /** For debugging: the raw defs object you passed to buildFire */
40
- defs: D;
40
+ _defs: D;
41
41
  };
42
42
  /**
43
43
  * Creates a `fire` function bound to a specific set of environment bindings.
@@ -71,8 +71,22 @@ type FireFn<D extends BindingsDefs> = {
71
71
  * (e.g. `{ foo: "KVStore", bar: "ConfigStore" }`).
72
72
  * @returns A `fire` function that:
73
73
  * - Registers your Hono app to handle fetch events
74
+ * - Applies `bindingsDefs` to `c.env`
74
75
  * - Exposes a `.Bindings` type inferred from the given defs
75
76
  */
76
77
  export declare function buildFire<D extends BindingsDefs>(bindingsDefs: D): FireFn<D>;
78
+ /**
79
+ * Registers your Hono app to handle fetch events. No user-defined bindings are
80
+ * applied to `c.env`.
81
+ * `fire.Bindings` is a type you can use when defining your `Env`,
82
+ * providing access to platform-defined bindings such as `clientInfo` and
83
+ * `serverInfo`.
84
+ */
85
+ export declare const fire: FireFn<{}>;
86
+ /**
87
+ * Default bindings which can be used when no user-defined bindings are present.
88
+ * Alias of `fire.Bindings`.
89
+ */
90
+ export type Bindings = typeof fire.Bindings;
77
91
  export {};
78
92
  //# sourceMappingURL=fire.d.ts.map
package/build/fire.js CHANGED
@@ -35,12 +35,21 @@ import { handle } from './handler.js';
35
35
  * (e.g. `{ foo: "KVStore", bar: "ConfigStore" }`).
36
36
  * @returns A `fire` function that:
37
37
  * - Registers your Hono app to handle fetch events
38
+ * - Applies `bindingsDefs` to `c.env`
38
39
  * - Exposes a `.Bindings` type inferred from the given defs
39
40
  */
40
41
  export function buildFire(bindingsDefs) {
41
42
  const fireFn = ((app, options = { fetch: undefined, }) => {
42
43
  addEventListener('fetch', handle(app, bindingsDefs, options));
43
44
  });
44
- fireFn.defs = bindingsDefs;
45
+ fireFn._defs = bindingsDefs;
45
46
  return fireFn;
46
47
  }
48
+ /**
49
+ * Registers your Hono app to handle fetch events. No user-defined bindings are
50
+ * applied to `c.env`.
51
+ * `fire.Bindings` is a type you can use when defining your `Env`,
52
+ * providing access to platform-defined bindings such as `clientInfo` and
53
+ * `serverInfo`.
54
+ */
55
+ export const fire = buildFire({});
package/build/handler.js CHANGED
@@ -17,13 +17,13 @@ export const handle = (app, envBindingsDefs, opts = {
17
17
  serverInfo: evt.server,
18
18
  };
19
19
  const env = buildContextProxyOn(envBase, envBindingsDefs);
20
- const res = await app.fetch(evt.request, env, {
21
- waitUntil: evt.waitUntil.bind(evt),
20
+ const executionCtx = Object.assign(evt, {
22
21
  passThroughOnException() {
23
22
  throw new Error('Not implemented');
24
23
  },
25
- props: undefined,
24
+ props: {},
26
25
  });
26
+ const res = await app.fetch(evt.request, env, executionCtx);
27
27
  if (opts.fetch && res.status === 404) {
28
28
  return await opts.fetch(evt.request);
29
29
  }
package/build/index.d.ts CHANGED
@@ -3,4 +3,10 @@ export * from './handler.js';
3
3
  export * from './utils.js';
4
4
  export * from './conninfo.js';
5
5
  export type { ResourceType, Context, ContextProxy, BindingsDefs, } from '@fastly/compute-js-context';
6
+ declare module 'hono/types' {
7
+ interface FetchEventLike {
8
+ readonly client: ClientInfo;
9
+ readonly server: ServerInfo;
10
+ }
11
+ }
6
12
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastly/hono-fastly-compute",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "Helper utilities for using Hono with Fastly Compute",
5
5
  "license": "MIT",
6
6
  "repository": {