Comparing version 1.2.13 to 1.2.14
@@ -92,2 +92,41 @@ "use strict"; | ||
}; | ||
const responseToSetHeaders = (response, set2) => { | ||
if (set2?.headers) { | ||
if (response) { | ||
if (import_utils.hasHeaderShorthand) | ||
Object.assign(set2.headers, response.headers.toJSON()); | ||
else | ||
for (const [key, value] of response.headers.entries()) | ||
if (key in set2.headers) set2.headers[key] = value; | ||
} | ||
if (set2.status === 200) set2.status = response.status; | ||
if (set2.headers["content-encoding"]) | ||
delete set2.headers["content-encoding"]; | ||
return set2; | ||
} | ||
if (!response) | ||
return { | ||
headers: {}, | ||
status: set2?.status ?? 200 | ||
}; | ||
if (import_utils.hasHeaderShorthand) { | ||
set2 = { | ||
// @ts-expect-error | ||
headers: response.headers.toJSON(), | ||
status: set2?.status ?? 200 | ||
}; | ||
if (set2.headers["content-encoding"]) | ||
delete set2.headers["content-encoding"]; | ||
return set2; | ||
} | ||
set2 = { | ||
headers: {}, | ||
status: set2?.status ?? 200 | ||
}; | ||
for (const [key, value] of response.headers.entries()) { | ||
if (key === "content-encoding") continue; | ||
if (key in set2.headers) set2.headers[key] = value; | ||
} | ||
return set2; | ||
}; | ||
const handleStream = async (generator, set2, request) => { | ||
@@ -100,2 +139,16 @@ let init = generator.next(); | ||
} | ||
if (set2?.headers) { | ||
if (!set2.headers["transfer-encoding"]) | ||
set2.headers["transfer-encoding"] = "chunked"; | ||
if (!set2.headers["content-type"]) | ||
set2.headers["content-type"] = "text/event-stream; charset=utf-8"; | ||
} else { | ||
set2 = { | ||
status: 200, | ||
headers: { | ||
"content-type": "text/event-stream; charset=utf-8", | ||
"transfer-encoding": "chunked" | ||
} | ||
}; | ||
} | ||
return new Response( | ||
@@ -161,11 +214,3 @@ new ReadableStream({ | ||
}), | ||
{ | ||
...set2, | ||
headers: { | ||
// Manually set transfer-encoding for direct response, eg. app.handle, eden | ||
"transfer-encoding": "chunked", | ||
"content-type": "text/event-stream; charset=utf-8", | ||
...set2?.headers | ||
} | ||
} | ||
set2 | ||
); | ||
@@ -268,6 +313,6 @@ }; | ||
); | ||
if (response.headers.get("transfer-encoding") === "chunked") | ||
if (!response.headers.has("content-length") && response.headers.get("transfer-encoding") === "chunked") | ||
return handleStream( | ||
streamResponse(response), | ||
set2, | ||
responseToSetHeaders(response, set2), | ||
request | ||
@@ -307,3 +352,3 @@ ); | ||
streamResponse(response), | ||
set2, | ||
responseToSetHeaders(response, set2), | ||
request | ||
@@ -345,5 +390,11 @@ ); | ||
} | ||
if (response instanceof Response && !response.headers.has("content-length") && response.headers.get("transfer-encoding") === "chunked") | ||
return handleStream( | ||
streamResponse(response), | ||
responseToSetHeaders(response, set2), | ||
request | ||
); | ||
if ( | ||
// @ts-expect-error | ||
typeof response?.next === "function" || response instanceof ReadableStream || response instanceof Response && response.headers.get("transfer-encoding") === "chunked" | ||
typeof response?.next === "function" || response instanceof ReadableStream | ||
) | ||
@@ -400,6 +451,6 @@ return handleStream(response, set2, request); | ||
); | ||
if (response.headers.get("transfer-encoding") === "chunked") | ||
if (!response.headers.has("content-length") && response.headers.get("transfer-encoding") === "chunked") | ||
return handleStream( | ||
streamResponse(response), | ||
set2, | ||
responseToSetHeaders(response, set2), | ||
request | ||
@@ -439,3 +490,3 @@ ); | ||
streamResponse(response), | ||
set2, | ||
responseToSetHeaders(response, set2), | ||
request | ||
@@ -520,5 +571,7 @@ ); | ||
case "Response": | ||
if (response.headers.get("transfer-encoding") === "chunked") | ||
if (!response.headers.has("content-length") && response.headers.get("transfer-encoding") === "chunked") | ||
return handleStream( | ||
streamResponse(response) | ||
streamResponse(response), | ||
responseToSetHeaders(response), | ||
request | ||
); | ||
@@ -624,3 +677,7 @@ return response; | ||
if (response.headers.get("transfer-encoding") === "chunked") | ||
return handleStream(streamResponse(response)); | ||
return handleStream( | ||
streamResponse(response), | ||
responseToSetHeaders(response), | ||
request | ||
); | ||
return response; | ||
@@ -627,0 +684,0 @@ case "Error": |
@@ -462,5 +462,7 @@ "use strict"; | ||
if(a${index}===undefined)a${index}=[] | ||
if(memory===-1){a${index}.push(decodeURIComponent(url.slice(start)).replace(/\\+/g,' ')) | ||
break}else a${index}.push(decodeURIComponent(url.slice(start, memory)).replace(/\\+/g,' ')) | ||
memory=url.indexOf('&${key}=',memory) | ||
if(memory===-1){const temp=decodeURIComponent(url.slice(start)).replace(/\\+/g,' ') | ||
if(temp.includes(',')){a${index}=a${index}.concat(temp.split(','))}else{a${index}.push(decodeURIComponent(url.slice(start)).replace(/\\+/g,' '))} | ||
break}else{const temp=decodeURIComponent(url.slice(start, memory)).replace(/\\+/g,' ') | ||
if(temp.includes(',')){a${index}=a${index}.concat(temp.split(','))}else{a${index}.push(temp)} | ||
}memory=url.indexOf('&${key}=',memory) | ||
if(memory===-1) break | ||
@@ -467,0 +469,0 @@ }`; |
@@ -65,3 +65,3 @@ import type { Server } from 'bun'; | ||
body: Route['body']; | ||
query: undefined extends Route['query'] ? Record<string, string | undefined> : Route['query']; | ||
query: undefined extends Route['query'] ? Record<string, string> : Route['query']; | ||
params: undefined extends Route['params'] ? undefined extends Path ? Record<string, string> : Path extends `${string}/${':' | '*'}${string}` ? ResolvePath<Path> : never : Route['params']; | ||
@@ -68,0 +68,0 @@ headers: undefined extends Route['headers'] ? Record<string, string | undefined> : Route['headers']; |
@@ -254,2 +254,5 @@ "use strict"; | ||
} | ||
getParent() { | ||
return null; | ||
} | ||
get promisedModules() { | ||
@@ -1268,5 +1271,3 @@ if (!this._promisedModules) this._promisedModules = new import_utils.PromiseGroup(); | ||
if (plugin2.constructor.name === "Elysia") | ||
return this._use( | ||
plugin2 | ||
).compile(); | ||
return this._use(plugin2).compile(); | ||
if (typeof plugin2.default === "function") | ||
@@ -1288,3 +1289,3 @@ return plugin2.default(this); | ||
} | ||
}).then((x) => x.compile()) | ||
}) | ||
); | ||
@@ -1295,2 +1296,12 @@ return this; | ||
} | ||
propagatePromiseModules(plugin) { | ||
if (plugin.promisedModules.size <= 0) return this; | ||
for (const promise of plugin.promisedModules.promises) | ||
this.promisedModules.add( | ||
promise.then((value) => { | ||
if (value) return this._use(value); | ||
}) | ||
); | ||
return this; | ||
} | ||
_use(plugin) { | ||
@@ -1322,2 +1333,4 @@ if (typeof plugin === "function") { | ||
plugin2.compile(); | ||
if (plugin2 === this) return; | ||
this.propagatePromiseModules(plugin2); | ||
return plugin2; | ||
@@ -1334,3 +1347,3 @@ } | ||
return this._use(plugin2); | ||
}).then((x) => x.compile()) | ||
}).then((v) => v?.compile()) | ||
); | ||
@@ -1340,9 +1353,6 @@ return this; | ||
return instance; | ||
} else if (plugin.promisedModules.size > 0) { | ||
for (const promise of plugin.promisedModules.promises) | ||
this.promisedModules.add(promise); | ||
this.promisedModules.then(() => this._use(plugin)).then((x) => x.compile()); | ||
return this; | ||
} | ||
this.propagatePromiseModules(plugin); | ||
const { name, seed } = plugin.config; | ||
plugin.getParent = () => this; | ||
plugin.getServer = () => this.getServer(); | ||
@@ -2055,3 +2065,3 @@ plugin.getGlobalRoutes = () => this.getGlobalRoutes(); | ||
get modules() { | ||
return Promise.all(this.promisedModules.promises); | ||
return this.promisedModules; | ||
} | ||
@@ -2058,0 +2068,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import { TString } from '@sinclair/typebox'; | ||
import { ArrayOptions, DateOptions, Kind, NumberOptions, TArray, TDate, TUnsafe, TInteger, IntegerOptions, SchemaOptions, TSchema, TProperties, ObjectOptions, TObject, TNumber, TBoolean } from '@sinclair/typebox'; | ||
@@ -51,3 +52,3 @@ import { type ValueError, type TypeCheck } from '@sinclair/typebox/compiler'; | ||
readonly ObjectString: <T extends TProperties>(properties: T, options?: ObjectOptions) => TObject<T>; | ||
readonly ArrayString: <T extends TSchema>(children?: T, options?: ArrayOptions) => TArray<T>; | ||
readonly ArrayString: <T extends TSchema = TString>(children?: T, options?: ArrayOptions) => TArray<T>; | ||
readonly File: ElysiaFile; | ||
@@ -54,0 +55,0 @@ readonly Files: (options?: ElysiaTypeOptions.Files) => import("@sinclair/typebox").TTransform<TUnsafe<File[]>, File[]>; |
@@ -88,3 +88,2 @@ "use strict"; | ||
const checkFileExtension = (type, extension) => { | ||
console.log({ type, extension }); | ||
if (type.startsWith(extension)) return true; | ||
@@ -310,3 +309,3 @@ return extension.charCodeAt(extension.length - 1) === 42 && extension.charCodeAt(extension.length - 2) === 47 && type.startsWith(extension.slice(0, -1)); | ||
}, | ||
ArrayString: (children = {}, options) => { | ||
ArrayString: (children = t.String(), options) => { | ||
const schema = t.Array(children, options); | ||
@@ -319,14 +318,4 @@ const defaultValue = JSON.stringify(import_value.Value.Create(schema)); | ||
} | ||
return t.Transform( | ||
t.Union([ | ||
t.String({ | ||
format: "ArrayString", | ||
default: defaultValue | ||
}), | ||
schema | ||
]) | ||
).Decode((value) => { | ||
if (typeof value === "string") { | ||
if (value.charCodeAt(0) !== 91) | ||
throw new import_error.ValidationError("property", schema, value); | ||
const decode = (value, isProperty = false) => { | ||
if (value.charCodeAt(0) === 91) { | ||
try { | ||
@@ -346,3 +335,41 @@ value = JSON.parse(value); | ||
} | ||
return value; | ||
if (value.indexOf(",") !== -1) { | ||
const newValue = value.split(",").map((v) => v.trim()); | ||
if (compiler) { | ||
if (!compiler.Check(newValue)) | ||
throw new import_error.ValidationError("property", schema, value); | ||
return compiler.Decode(newValue); | ||
} | ||
if (!import_value.Value.Check(schema, newValue)) | ||
throw new import_error.ValidationError("property", schema, newValue); | ||
return import_value.Value.Decode(schema, newValue); | ||
} | ||
if (isProperty) return value; | ||
throw new import_error.ValidationError("property", schema, value); | ||
}; | ||
return t.Transform( | ||
t.Union([ | ||
t.String({ | ||
format: "ArrayString", | ||
default: defaultValue | ||
}), | ||
schema | ||
]) | ||
).Decode((value) => { | ||
if (Array.isArray(value)) { | ||
let values = []; | ||
for (let i = 0; i < value.length; i++) { | ||
const v = value[i]; | ||
if (typeof v === "string") { | ||
const t2 = decode(v, true); | ||
if (Array.isArray(t2)) values = values.concat(t2); | ||
else values.push(t2); | ||
continue; | ||
} | ||
values.push(v); | ||
} | ||
return values; | ||
} | ||
if (typeof value === "string") return decode(value); | ||
throw new import_error.ValidationError("property", schema, value); | ||
}).Encode((value) => { | ||
@@ -349,0 +376,0 @@ if (typeof value === "string") |
@@ -132,7 +132,7 @@ "use strict"; | ||
if (!createReadStream || !stat) { | ||
this.value = import("fs").then((fs) => { | ||
createReadStream = fs.createReadStream; | ||
return fs.createReadStream(path); | ||
}); | ||
try { | ||
this.value = import("fs").then((fs) => { | ||
createReadStream = fs.createReadStream; | ||
return fs.createReadStream(path); | ||
}); | ||
this.stats = import("fs/promises").then((fs) => { | ||
@@ -139,0 +139,0 @@ stat = fs.stat; |
@@ -397,3 +397,3 @@ "use strict"; | ||
default: | ||
if (value.items) | ||
if (Array.isArray(value.items)) { | ||
for (let i = 0; i < value.items.length; i++) { | ||
@@ -406,3 +406,3 @@ value.items[i] = _replaceSchemaType( | ||
} | ||
else if (value.anyOf || value.oneOf || value.allOf || value.not) | ||
} else if (value.anyOf || value.oneOf || value.allOf || value.not) | ||
properties[key] = _replaceSchemaType( | ||
@@ -413,2 +413,9 @@ value, | ||
); | ||
else if (value.type === "array") { | ||
value.items = _replaceSchemaType( | ||
value.items, | ||
options, | ||
false | ||
); | ||
} | ||
break; | ||
@@ -415,0 +422,0 @@ } |
@@ -65,3 +65,3 @@ import type { Server } from 'bun'; | ||
body: Route['body']; | ||
query: undefined extends Route['query'] ? Record<string, string | undefined> : Route['query']; | ||
query: undefined extends Route['query'] ? Record<string, string> : Route['query']; | ||
params: undefined extends Route['params'] ? undefined extends Path ? Record<string, string> : Path extends `${string}/${':' | '*'}${string}` ? ResolvePath<Path> : never : Route['params']; | ||
@@ -68,0 +68,0 @@ headers: undefined extends Route['headers'] ? Record<string, string | undefined> : Route['headers']; |
@@ -0,1 +1,2 @@ | ||
import { TString } from '@sinclair/typebox'; | ||
import { ArrayOptions, DateOptions, Kind, NumberOptions, TArray, TDate, TUnsafe, TInteger, IntegerOptions, SchemaOptions, TSchema, TProperties, ObjectOptions, TObject, TNumber, TBoolean } from '@sinclair/typebox'; | ||
@@ -51,3 +52,3 @@ import { type ValueError, type TypeCheck } from '@sinclair/typebox/compiler'; | ||
readonly ObjectString: <T extends TProperties>(properties: T, options?: ObjectOptions) => TObject<T>; | ||
readonly ArrayString: <T extends TSchema>(children?: T, options?: ArrayOptions) => TArray<T>; | ||
readonly ArrayString: <T extends TSchema = TString>(children?: T, options?: ArrayOptions) => TArray<T>; | ||
readonly File: ElysiaFile; | ||
@@ -54,0 +55,0 @@ readonly Files: (options?: ElysiaTypeOptions.Files) => import("@sinclair/typebox").TTransform<TUnsafe<File[]>, File[]>; |
{ | ||
"name": "elysia", | ||
"description": "Ergonomic Framework for Human", | ||
"version": "1.2.13", | ||
"version": "1.2.14", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "saltyAom", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1879121
30168