@hyperspan/framework 1.0.2 → 1.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperspan/framework",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Hyperspan Web Framework",
5
5
  "main": "src/server.ts",
6
6
  "types": "src/server.ts",
@@ -2,7 +2,6 @@ import { test, expect, describe } from 'bun:test';
2
2
  import { createAction } from './actions';
3
3
  import { html, render, type HSHtml } from '@hyperspan/html';
4
4
  import { createContext } from './server';
5
- import type { Hyperspan as HS } from './types';
6
5
  import * as z from 'zod/v4';
7
6
 
8
7
  describe('createAction', () => {
@@ -144,7 +144,7 @@ test('createContext() can get and set cookies', () => {
144
144
  }
145
145
  });
146
146
 
147
- test('createContext() merge() function preserves custom headers when using response methods', () => {
147
+ test('createContext() merge() function preserves custom headers when using response methods', async () => {
148
148
  // Create a request
149
149
  const request = new Request('http://localhost:3000/');
150
150
 
@@ -157,7 +157,7 @@ test('createContext() merge() function preserves custom headers when using respo
157
157
  context.res.headers.set('Authorization', 'Bearer token123');
158
158
 
159
159
  // Use html() method which should merge headers
160
- const response = context.res.html('<h1>Test</h1>');
160
+ const response = await context.res.html('<h1>Test</h1>');
161
161
 
162
162
  // Verify the response has both the custom headers and the Content-Type header
163
163
  expect(response.headers.get('X-Custom-Header')).toBe('custom-value');
@@ -169,7 +169,7 @@ test('createContext() merge() function preserves custom headers when using respo
169
169
  expect(response.status).toBe(200);
170
170
  });
171
171
 
172
- test('createContext() merge() function preserves custom headers with json() method', () => {
172
+ test('createContext() merge() function preserves custom headers with json() method', async () => {
173
173
  const request = new Request('http://localhost:3000/');
174
174
  const context = createContext(request);
175
175
 
@@ -178,7 +178,7 @@ test('createContext() merge() function preserves custom headers with json() meth
178
178
  context.res.headers.set('X-Request-ID', 'req-123');
179
179
 
180
180
  // Use json() method
181
- const response = context.res.json({ message: 'Hello' });
181
+ const response = await context.res.json({ message: 'Hello' });
182
182
 
183
183
  // Verify headers are merged
184
184
  expect(response.headers.get('X-API-Version')).toBe('v1');
@@ -186,7 +186,7 @@ test('createContext() merge() function preserves custom headers with json() meth
186
186
  expect(response.headers.get('Content-Type')).toBe('application/json');
187
187
  });
188
188
 
189
- test('createContext() merge() function allows response headers to override context headers', () => {
189
+ test('createContext() merge() function allows response headers to override context headers', async () => {
190
190
  const request = new Request('http://localhost:3000/');
191
191
  const context = createContext(request);
192
192
 
@@ -194,7 +194,7 @@ test('createContext() merge() function allows response headers to override conte
194
194
  context.res.headers.set('X-Header', 'context-value');
195
195
 
196
196
  // Use html() with options that include the same header (should override)
197
- const response = context.res.html('<h1>Test</h1>', {
197
+ const response = await context.res.html('<h1>Test</h1>', {
198
198
  headers: {
199
199
  'X-Header': 'response-value',
200
200
  },
package/src/server.ts CHANGED
@@ -64,14 +64,14 @@ export function createContext(req: Request, route?: HS.Route): HS.Context {
64
64
  // Status override for the response. Will use if set. (e.g. c.res.status = 400)
65
65
  let status: number | undefined = undefined;
66
66
 
67
- const merge = (response: Response) => {
67
+ const merge = async (response: Response) => {
68
68
  // Convert headers to plain objects and merge (response headers override context headers)
69
69
  const mergedHeaders = {
70
70
  ...Object.fromEntries(headers.entries()),
71
71
  ...Object.fromEntries(response.headers.entries()),
72
72
  };
73
73
 
74
- return new Response(response.body, {
74
+ return new Response(await response.text(), {
75
75
  status: context.res.status ?? response.status,
76
76
  headers: mergedHeaders,
77
77
  });
package/src/types.ts CHANGED
@@ -69,13 +69,13 @@ export namespace Hyperspan {
69
69
  cookies: Hyperspan.Cookies;
70
70
  headers: Headers; // Headers to merge with final outgoing response
71
71
  status: number | undefined;
72
- html: (html: string, options?: ResponseInit) => Response
73
- json: (json: any, options?: ResponseInit) => Response;
74
- text: (text: string, options?: ResponseInit) => Response;
75
- redirect: (url: string, options?: ResponseInit) => Response;
76
- error: (error: Error, options?: ResponseInit) => Response;
77
- notFound: (options?: ResponseInit) => Response;
78
- merge: (response: Response) => Response;
72
+ html: (html: string, options?: ResponseInit) => Promise<Response>;
73
+ json: (json: any, options?: ResponseInit) => Promise<Response>;
74
+ text: (text: string, options?: ResponseInit) => Promise<Response>;
75
+ redirect: (url: string, options?: ResponseInit) => Promise<Response>;
76
+ error: (error: Error, options?: ResponseInit) => Promise<Response>;
77
+ notFound: (options?: ResponseInit) => Promise<Response>;
78
+ merge: (response: Response) => Promise<Response>;
79
79
  };
80
80
 
81
81
  export interface Context {