@fastly/hono-fastly-compute 0.3.2 → 0.3.3

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,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [unreleased]
9
9
 
10
+ ## [0.3.3] - 2025-10-15
11
+
12
+ ### Changed
13
+
14
+ - Change debugging definition field to `_defs`
15
+
16
+ ### Added
17
+
18
+ - Expose default `fire` and `Bindings`
19
+
10
20
  ## [0.3.2] - 2025-10-14
11
21
 
12
22
  ### Added
@@ -32,7 +42,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
32
42
 
33
43
  - Initial public release
34
44
 
35
- [unreleased]: https://github.com/fastly/hono-fastly-compute/compare/v0.3.2...HEAD
45
+ [unreleased]: https://github.com/fastly/hono-fastly-compute/compare/v0.3.3...HEAD
46
+ [0.3.3]: https://github.com/fastly/hono-fastly-compute/compare/v0.3.2...v0.3.3
36
47
  [0.3.2]: https://github.com/fastly/hono-fastly-compute/compare/v0.3.1...v0.3.2
37
48
  [0.3.1]: https://github.com/fastly/hono-fastly-compute/compare/v0.3.0...v0.3.1
38
49
  [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
@@ -96,14 +111,13 @@ The core adapter function that connects Hono to the Fastly Compute `FetchEvent`.
96
111
 
97
112
  ### `clientInfo` and `serverInfo`
98
113
 
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:
114
+ `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
115
 
101
116
  ```typescript
102
117
  import { Hono } from 'hono';
103
- import { buildFire } from '@fastly/hono-fastly-compute';
118
+ import { fire, type Bindings } from '@fastly/hono-fastly-compute';
104
119
 
105
- const fire = buildFire({});
106
- const app = new Hono<{Bindings: typeof fire.Bindings}>();
120
+ const app = new Hono<{ Bindings: Bindings }>();
107
121
 
108
122
  app.get('/', (c) => {
109
123
  const clientInfo = c.env.clientInfo;
@@ -125,9 +139,8 @@ An implementation of the [ConnInfo helper](https://hono.dev/docs/helpers/conninf
125
139
 
126
140
  ```typescript
127
141
  import { Hono } from 'hono';
128
- import { buildFire, getConnInfo } from '@fastly/hono-fastly-compute';
142
+ import { fire, getConnInfo } from '@fastly/hono-fastly-compute';
129
143
 
130
- const fire = buildFire({});
131
144
  const app = new Hono();
132
145
 
133
146
  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/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.3",
4
4
  "description": "Helper utilities for using Hono with Fastly Compute",
5
5
  "license": "MIT",
6
6
  "repository": {