bxo 0.0.5-dev.61 → 0.0.5-dev.63

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,7 +1,7 @@
1
1
  {
2
2
  "name": "bxo",
3
3
  "module": "index.ts",
4
- "version": "0.0.5-dev.61",
4
+ "version": "0.0.5-dev.63",
5
5
  "description": "A simple and lightweight web framework for Bun",
6
6
  "type": "module",
7
7
  "exports": {
@@ -10,7 +10,7 @@ export type ResponseConfig = StatusResponseSchema;
10
10
 
11
11
  // Type utility to extract response type from response config
12
12
  export type InferResponseType<T> = T extends StatusResponseSchema
13
- ? { [K in keyof T]: InferZodType<T[K]> }[number]
13
+ ? T[keyof T] extends z.ZodType<infer U> ? U : never
14
14
  : never;
15
15
 
16
16
  // Cookie options interface for setting cookies
@@ -100,7 +100,9 @@ export interface InternalCookie {
100
100
  // Handler function type with proper response typing
101
101
  export type Handler<TConfig extends RouteConfig = {}, EC = {}> = (
102
102
  ctx: Context<TConfig> & EC
103
- ) => Promise<InferResponseType<TConfig['response']> | any> | InferResponseType<TConfig['response']> | any;
103
+ ) => TConfig['response'] extends StatusResponseSchema
104
+ ? Promise<InferResponseType<TConfig['response']>> | InferResponseType<TConfig['response']>
105
+ : Promise<any> | any;
104
106
 
105
107
  // Route definition
106
108
  export interface Route {
@@ -127,7 +127,10 @@ export function processResponse(
127
127
  const headers = mergeHeadersWithCookies(responseHeaders, internalCookies);
128
128
 
129
129
  if (typeof response === 'string') {
130
- headers.set('Content-Type', 'text/plain');
130
+ // Only set Content-Type to text/plain if not already set
131
+ if (!headers.has('Content-Type')) {
132
+ headers.set('Content-Type', 'text/plain');
133
+ }
131
134
  return new Response(response, {
132
135
  status: ctx.set.status || 200,
133
136
  headers: headers
@@ -182,12 +185,20 @@ export function processResponse(
182
185
  };
183
186
 
184
187
  if (typeof response === 'string') {
188
+ const finalHeaders: Record<string, string> = {};
189
+ // Copy existing headers if they exist
190
+ if (responseInit.headers) {
191
+ if (typeof responseInit.headers === 'object' && !Array.isArray(responseInit.headers)) {
192
+ Object.assign(finalHeaders, responseInit.headers);
193
+ }
194
+ }
195
+ // Only set Content-Type to text/plain if not already set
196
+ if (!finalHeaders['Content-Type']) {
197
+ finalHeaders['Content-Type'] = 'text/plain';
198
+ }
185
199
  return new Response(response, {
186
200
  ...responseInit,
187
- headers: {
188
- 'Content-Type': 'text/plain',
189
- ...responseInit.headers
190
- }
201
+ headers: finalHeaders
191
202
  });
192
203
  }
193
204
 
@@ -214,14 +214,14 @@ describe('BXO Framework Integration', () => {
214
214
  body: formData
215
215
  });
216
216
 
217
- const data = await response.json() as {
218
- formData: {
219
- app: string,
220
- model: string,
221
- recordIds: string[],
222
- fields: string
223
- },
224
- message: string
217
+ const data = await response.json() as {
218
+ formData: {
219
+ app: string,
220
+ model: string,
221
+ recordIds: string[],
222
+ fields: string
223
+ },
224
+ message: string
225
225
  };
226
226
 
227
227
  expect(response.status).toBe(200);
@@ -248,8 +248,8 @@ describe('BXO Framework Integration', () => {
248
248
  body: formData
249
249
  });
250
250
 
251
- const data = await response.json() as {
252
- formData: {
251
+ const data = await response.json() as {
252
+ formData: {
253
253
  test: {
254
254
  test: string,
255
255
  new: string,
@@ -257,8 +257,8 @@ describe('BXO Framework Integration', () => {
257
257
  hi: string
258
258
  }
259
259
  }
260
- },
261
- message: string
260
+ },
261
+ message: string
262
262
  };
263
263
 
264
264
  expect(response.status).toBe(200);
@@ -288,8 +288,8 @@ describe('BXO Framework Integration', () => {
288
288
  body: formData
289
289
  });
290
290
 
291
- const data = await response.json() as {
292
- formData: {
291
+ const data = await response.json() as {
292
+ formData: {
293
293
  records: Array<{
294
294
  qrPayment: {
295
295
  type: string;
@@ -299,8 +299,8 @@ describe('BXO Framework Integration', () => {
299
299
  },
300
300
  name: string
301
301
  }>
302
- },
303
- message: string
302
+ },
303
+ message: string
304
304
  };
305
305
 
306
306
  expect(response.status).toBe(200);
@@ -339,8 +339,8 @@ describe('BXO Framework Integration', () => {
339
339
  console.log('File name:', records[0]?.qrPayment.name);
340
340
  console.log('File size:', records[0]?.qrPayment.size);
341
341
  console.log('File type:', records[0]?.qrPayment.type);
342
-
343
- return {
342
+
343
+ return {
344
344
  message: 'Files received',
345
345
  fileInfo: {
346
346
  isFile0: records[0]?.qrPayment instanceof File,