bxo 0.0.5-dev.53 → 0.0.5-dev.54

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.53",
4
+ "version": "0.0.5-dev.54",
5
5
  "description": "A simple and lightweight web framework for Bun",
6
6
  "type": "module",
7
7
  "exports": {
@@ -90,22 +90,13 @@ export async function parseRequestBody(request: Request): Promise<any> {
90
90
  }
91
91
  } else if (contentType?.includes('multipart/form-data') || contentType?.includes('application/x-www-form-urlencoded')) {
92
92
  const formData = await request.formData();
93
- // Convert FormData to a structured object that preserves file information
93
+ // Convert FormData to a structured object
94
94
  const formBody: Record<string, any> = {};
95
95
 
96
96
  for (const [key, value] of formData.entries()) {
97
97
  if (value instanceof File) {
98
- // Handle file uploads
99
- formBody[key] = {
100
- type: 'file',
101
- name: value.name,
102
- size: value.size,
103
- lastModified: value.lastModified,
104
- file: value, // Keep the actual File object for access
105
- // Add convenience properties
106
- filename: value.name,
107
- mimetype: value.type || 'application/octet-stream'
108
- };
98
+ // Return File instances directly
99
+ formBody[key] = value;
109
100
  } else {
110
101
  // Handle regular form fields
111
102
  formBody[key] = value;
@@ -186,21 +177,13 @@ export function createRedirectResponse(
186
177
  }
187
178
 
188
179
  // Check if a value is a file upload
189
- export function isFileUpload(value: any): value is {
190
- type: 'file';
191
- file: File;
192
- name: string;
193
- size: number;
194
- lastModified: number;
195
- filename: string;
196
- mimetype: string;
197
- } {
198
- return value && typeof value === 'object' && value.type === 'file' && value.file instanceof File;
180
+ export function isFileUpload(value: any): value is File {
181
+ return value instanceof File;
199
182
  }
200
183
 
201
184
  // Extract File object from upload value
202
185
  export function getFileFromUpload(value: any): File | null {
203
- return isFileUpload(value) ? value.file : null;
186
+ return isFileUpload(value) ? value : null;
204
187
  }
205
188
 
206
189
  // Get file metadata without the File object
@@ -209,7 +192,7 @@ export function getFileInfo(value: any): { name: string; size: number; mimetype:
209
192
  return {
210
193
  name: value.name,
211
194
  size: value.size,
212
- mimetype: value.mimetype,
195
+ mimetype: value.type || 'application/octet-stream',
213
196
  lastModified: value.lastModified
214
197
  };
215
198
  }
@@ -240,7 +223,7 @@ export function getFileUploads(formData: Record<string, any>): Record<string, Fi
240
223
  const files: Record<string, File> = {};
241
224
  for (const [key, value] of Object.entries(formData)) {
242
225
  if (isFileUpload(value)) {
243
- files[key] = value.file;
226
+ files[key] = value;
244
227
  }
245
228
  }
246
229
  return files;
@@ -202,34 +202,17 @@ describe('Utility Functions', () => {
202
202
 
203
203
  describe('File Upload Utilities', () => {
204
204
  it('should identify file uploads correctly', () => {
205
- const fileUpload = {
206
- type: 'file',
207
- name: 'test.jpg',
208
- size: 1024,
209
- lastModified: 1234567890,
210
- file: new File(['test'], 'test.jpg'),
211
- filename: 'test.jpg',
212
- mimetype: 'image/jpeg'
213
- };
205
+ const file = new File(['test'], 'test.jpg', { type: 'image/jpeg' });
214
206
 
215
- expect(isFileUpload(fileUpload)).toBe(true);
207
+ expect(isFileUpload(file)).toBe(true);
216
208
  expect(isFileUpload('not a file')).toBe(false);
217
209
  expect(isFileUpload({ type: 'text' })).toBe(false);
218
210
  });
219
211
 
220
212
  it('should extract file from upload', () => {
221
- const file = new File(['test'], 'test.jpg');
222
- const fileUpload = {
223
- type: 'file',
224
- name: 'test.jpg',
225
- size: 1024,
226
- lastModified: 1234567890,
227
- file,
228
- filename: 'test.jpg',
229
- mimetype: 'image/jpeg'
230
- };
213
+ const file = new File(['test'], 'test.jpg', { type: 'image/jpeg' });
231
214
 
232
- const result = getFileFromUpload(fileUpload);
215
+ const result = getFileFromUpload(file);
233
216
  expect(result).toBe(file);
234
217
  });
235
218
 
@@ -239,22 +222,14 @@ describe('Utility Functions', () => {
239
222
  });
240
223
 
241
224
  it('should get file info', () => {
242
- const fileUpload = {
243
- type: 'file',
244
- name: 'test.jpg',
245
- size: 1024,
246
- lastModified: 1234567890,
247
- file: new File(['test'], 'test.jpg'),
248
- filename: 'test.jpg',
249
- mimetype: 'image/jpeg'
250
- };
225
+ const file = new File(['test'], 'test.jpg', { type: 'image/jpeg' });
251
226
 
252
- const result = getFileInfo(fileUpload);
227
+ const result = getFileInfo(file);
253
228
  expect(result).toEqual({
254
229
  name: 'test.jpg',
255
- size: 1024,
230
+ size: 4,
256
231
  mimetype: 'image/jpeg',
257
- lastModified: 1234567890
232
+ lastModified: expect.any(Number)
258
233
  });
259
234
  });
260
235
 
@@ -264,17 +239,10 @@ describe('Utility Functions', () => {
264
239
  });
265
240
 
266
241
  it('should get all file uploads from form data', () => {
242
+ const file = new File(['test'], 'avatar.jpg', { type: 'image/jpeg' });
267
243
  const formData = {
268
244
  name: 'john',
269
- avatar: {
270
- type: 'file',
271
- name: 'avatar.jpg',
272
- size: 1024,
273
- lastModified: 1234567890,
274
- file: new File(['test'], 'avatar.jpg'),
275
- filename: 'avatar.jpg',
276
- mimetype: 'image/jpeg'
277
- },
245
+ avatar: file,
278
246
  email: 'john@example.com'
279
247
  };
280
248
 
@@ -285,17 +253,10 @@ describe('Utility Functions', () => {
285
253
  });
286
254
 
287
255
  it('should get all non-file fields from form data', () => {
256
+ const file = new File(['test'], 'avatar.jpg', { type: 'image/jpeg' });
288
257
  const formData = {
289
258
  name: 'john',
290
- avatar: {
291
- type: 'file',
292
- name: 'avatar.jpg',
293
- size: 1024,
294
- lastModified: 1234567890,
295
- file: new File(['test'], 'avatar.jpg'),
296
- filename: 'avatar.jpg',
297
- mimetype: 'image/jpeg'
298
- },
259
+ avatar: file,
299
260
  email: 'john@example.com'
300
261
  };
301
262