From 52d6fcfac0d405fd2bf5278840e7c6415fa5dfcf Mon Sep 17 00:00:00 2001 From: teyik0 Date: Fri, 21 Nov 2025 21:59:58 +0100 Subject: [PATCH] feat: support BunFile on t.Files type system for eden BunFile type error #1561 --- bun.lock | 7 +++++-- src/type-system/index.ts | 9 +++++---- src/type-system/types.ts | 5 +++-- test/types/index.ts | 3 ++- test/types/type-system.ts | 3 ++- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/bun.lock b/bun.lock index f54df20c..cd91edb0 100644 --- a/bun.lock +++ b/bun.lock @@ -1,11 +1,12 @@ { "lockfileVersion": 1, + "configVersion": 0, "workspaces": { "": { "name": "elysia", "dependencies": { "cookie": "^1.0.2", - "exact-mirror": "0.2.2", + "exact-mirror": "0.2.3", "fast-decode-uri-component": "^1.0.1", "memoirist": "^0.4.0", }, @@ -374,7 +375,7 @@ "esutils": ["esutils@2.0.3", "", {}, "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g=="], - "exact-mirror": ["exact-mirror@0.2.2", "", { "peerDependencies": { "@sinclair/typebox": "^0.34.15" }, "optionalPeers": ["@sinclair/typebox"] }, "sha512-CrGe+4QzHZlnrXZVlo/WbUZ4qQZq8C0uATQVGVgXIrNXgHDBBNFD1VRfssRA2C9t3RYvh3MadZSdg2Wy7HBoQA=="], + "exact-mirror": ["exact-mirror@0.2.3", "", { "peerDependencies": { "@sinclair/typebox": "^0.34.15" }, "optionalPeers": ["@sinclair/typebox"] }, "sha512-aLdARfO0W0ntufjDyytUJQMbNXoB9g+BbA8KcgIq4XOOTYRw48yUGON/Pr64iDrYNZKcKvKbqE0MPW56FF2BXA=="], "expect-type": ["expect-type@1.2.2", "", {}, "sha512-JhFGDVJ7tmDJItKhYgJCGLOWjuK9vPxiXoUFLwLDc99NlmklilbiQJwoctZtt13+xMw91MCk/REan6MWHqDjyA=="], @@ -660,6 +661,8 @@ "@typescript-eslint/typescript-estree/minimatch": ["minimatch@9.0.5", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow=="], + "elysia/exact-mirror": ["exact-mirror@0.2.2", "", { "peerDependencies": { "@sinclair/typebox": "^0.34.15" }, "optionalPeers": ["@sinclair/typebox"] }, "sha512-CrGe+4QzHZlnrXZVlo/WbUZ4qQZq8C0uATQVGVgXIrNXgHDBBNFD1VRfssRA2C9t3RYvh3MadZSdg2Wy7HBoQA=="], + "eslint/ignore": ["ignore@5.3.2", "", {}, "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g=="], "eslint-plugin-sonarjs/minimatch": ["minimatch@9.0.5", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow=="], diff --git a/src/type-system/index.ts b/src/type-system/index.ts index a5a3a082..270db6a8 100644 --- a/src/type-system/index.ts +++ b/src/type-system/index.ts @@ -48,6 +48,7 @@ import { import { ELYSIA_FORM_DATA, form } from '../utils' import { ValidationError } from '../error' import { parseDateTimeEmptySpace } from './format' +import { BunFile } from 'bun' const t = Object.assign({}, Type) as unknown as Omit< JavaScriptTypeBuilder, @@ -73,7 +74,7 @@ createType( (schema, value) => value instanceof ArrayBuffer ) -const internalFiles = createType( +const internalFiles = createType>( 'Files', (options, value) => { if (options.minItems && options.minItems > 1 && !Array.isArray(value)) @@ -478,19 +479,19 @@ export const ElysiaType = { }) as any as TArray }, - File: createType( + File: createType( 'File', validateFile ) as unknown as TFile, - Files: (options: FilesOptions = {}): TUnsafe => + Files: (options: FilesOptions = {}): TUnsafe> => t .Transform(internalFiles(options)) .Decode((value) => { if (Array.isArray(value)) return value return [value] }) - .Encode((value) => value) as unknown as TUnsafe, + .Encode((value) => value) as unknown as TUnsafe>, Nullable: (schema: T, options?: SchemaOptions) => t.Union([schema, t.Null()], { diff --git a/src/type-system/types.ts b/src/type-system/types.ts index 5b913c4a..6bed0ce4 100644 --- a/src/type-system/types.ts +++ b/src/type-system/types.ts @@ -17,6 +17,7 @@ import { ElysiaFormData } from '../utils' import type { CookieOptions } from '../cookies' import type { MaybeArray } from '../types' import { ElysiaFile } from '../universal/file' +import { BunFile } from 'bun' export type FileUnit = number | `${number}${'k' | 'm'}` @@ -119,11 +120,11 @@ export interface CookieValidatorOptions export type TFile = ( options?: Partial | undefined -) => TUnsafe +) => TUnsafe export type TFiles = ( options?: Partial | undefined -) => TUnsafe +) => TUnsafe> export type NonEmptyArray = [T, ...T[]] diff --git a/test/types/index.ts b/test/types/index.ts index 2b2ed42a..1a3f9a50 100644 --- a/test/types/index.ts +++ b/test/types/index.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ +import { BunFile } from 'bun' import { t, Elysia, @@ -1432,7 +1433,7 @@ app.get('/', ({ set }) => { const child = new Elysia().get( '/', ({ body: { file } }) => { - expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() return file }, diff --git a/test/types/type-system.ts b/test/types/type-system.ts index 40d5f770..7aecf49c 100644 --- a/test/types/type-system.ts +++ b/test/types/type-system.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ +import { BunFile } from 'bun' import { t, Elysia, form, file } from '../../src' import { expectTypeOf } from 'expect-type' @@ -54,7 +55,7 @@ import { expectTypeOf } from 'expect-type' '/', ({ body }) => { expectTypeOf().toEqualTypeOf<{ - images: File[] + images: Array }>() }, {