revojs 0.1.41 → 0.1.43

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.
@@ -120,7 +120,7 @@ var Router = class extends Radix {
120
120
  scope.setContext(ROUTER_CONTEXT, context);
121
121
  return route.fetch(scope);
122
122
  }
123
- throw sendText(scope, "NOT_FOUND", { status: 404 });
123
+ throw sendNotFound(scope);
124
124
  }
125
125
  };
126
126
  function defineRoute(route) {
@@ -237,41 +237,68 @@ function setState(scope, name, value) {
237
237
  STATES[name] = value;
238
238
  }
239
239
  }
240
- function sendText(scope, text, config) {
240
+ function sendResponse(scope, body, config) {
241
241
  const { response } = useServer(scope);
242
- response.headers.set("Content-Type", "text/plain");
243
- return new Response(text, mergeObjects(response, config));
242
+ if (body !== null && body !== void 0) {
243
+ if (typeof body === "object" && !ArrayBuffer.isView(body)) {
244
+ if (body instanceof FormData) response.headers.set("Content-Type", "multipart/form-data");
245
+ else if (body instanceof URLSearchParams) response.headers.set("Content-Type", "application/x-www-form-urlencoded");
246
+ else if (body instanceof ReadableStream) response.headers.set("Content-Type", "application/octet-stream");
247
+ else if (!(body instanceof Blob)) {
248
+ response.headers.set("Content-Type", "application/json");
249
+ body = JSON.stringify(body);
250
+ }
251
+ } else if (typeof body === "string") {
252
+ const content = body.trimStart();
253
+ if (content.startsWith("<!DOCTYPE") || content.startsWith("<html") || /<[a-z][\s\S]*>/i.test(content)) response.headers.set("Content-Type", "text/html");
254
+ else response.headers.set("Content-Type", "text/plain");
255
+ } else if (typeof body === "boolean" || typeof body === "number") {
256
+ response.headers.set("Content-Type", "application/json");
257
+ body = JSON.stringify(body);
258
+ }
259
+ }
260
+ return new Response(body, mergeObjects(response, config));
261
+ }
262
+ function sendOk(scope, body, config) {
263
+ const { response } = useServer(scope);
264
+ response.status = 200;
265
+ return sendResponse(scope, body, config);
244
266
  }
245
- function sendHtml(scope, html, config) {
267
+ function sendCreated(scope, body, config) {
246
268
  const { response } = useServer(scope);
247
- response.headers.set("Content-Type", "text/html");
248
- return new Response(html, mergeObjects(response, config));
269
+ response.status = 201;
270
+ return sendResponse(scope, body, config);
249
271
  }
250
- function sendJson(scope, value, config) {
272
+ function sendNoContent(scope, config) {
251
273
  const { response } = useServer(scope);
252
- response.headers.set("Content-Type", "application/json");
253
- return new Response(JSON.stringify(value), mergeObjects(response, config));
274
+ response.status = 204;
275
+ return sendResponse(scope, void 0, config);
254
276
  }
255
277
  function sendRedirect(scope, path, config) {
256
278
  const { response } = useServer(scope);
257
279
  response.status = 302;
258
280
  response.headers.set("Location", path);
259
- return new Response(null, mergeObjects(response, config));
281
+ return sendResponse(scope, void 0, config);
260
282
  }
261
283
  function sendBadRequest(scope, body, config) {
262
284
  const { response } = useServer(scope);
263
285
  response.status = 400;
264
- return new Response(body, mergeObjects(response, config));
286
+ return sendResponse(scope, body, config);
265
287
  }
266
288
  function sendUnauthorized(scope, body, config) {
267
289
  const { response } = useServer(scope);
268
290
  response.status = 401;
269
- return new Response(body, mergeObjects(response, config));
291
+ return sendResponse(scope, body, config);
292
+ }
293
+ function sendForbidden(scope, body, config) {
294
+ const { response } = useServer(scope);
295
+ response.status = 403;
296
+ return sendResponse(scope, body, config);
270
297
  }
271
298
  function sendNotFound(scope, body, config) {
272
299
  const { response } = useServer(scope);
273
300
  response.status = 404;
274
- return new Response(body, mergeObjects(response, config));
301
+ return sendResponse(scope, body, config);
275
302
  }
276
303
  function mimeType(file) {
277
304
  return mimeTypes[/\.([a-zA-Z0-9]+?)$/.exec(file)?.at(1) ?? ""] ?? "text/plain";
@@ -526,9 +553,9 @@ function isFailure(result) {
526
553
  return "issues" in result;
527
554
  }
528
555
  function parseSchema(scope, schema, value) {
529
- const result = schema["~standard"].validate(value);
530
- if (isFailure(result)) throw sendJson(scope, result, { status: 400 });
531
- return result.value;
556
+ const output = schema["~standard"].validate(value);
557
+ if (isFailure(output)) throw sendBadRequest(scope, output);
558
+ return output.value;
532
559
  }
533
560
  function mergeObjects(base, input) {
534
561
  if (input === null || input === void 0) return mergeObjects(base, {});
@@ -583,4 +610,4 @@ const SERVER = "ssr";
583
610
  const CLIENT = "client";
584
611
  const CLOSE_HOOK = defineHook("CLOSE_HOOK");
585
612
  //#endregion
586
- export { useQuery as $, encodings as A, sendHtml as B, WILDCARD as C, createServer as D, cookieSameSites as E, isServer as F, sendUnauthorized as G, sendNotFound as H, mimeType as I, statusCodes as J, setCookie as K, mimeTypes as L, httpMethods as M, invoke as N, defineMiddleware as O, isClient as P, useParameters as Q, parseCookiePair as R, STATES as S, cookiePriorities as T, sendRedirect as U, sendJson as V, sendText as W, useCookies as X, useBody as Y, useHeaders as Z, PARAMETER_MATCH as _, Hookable as a, Router as b, defineHook as c, parseSchema as d, useRouter as et, OPTIONAL_PARAMETER as f, PARAMETER as g, OPTIONAL_WILDCARD_MATCH as h, SERVER as i, withQuery as it, getState as j, defineRoute as k, isFailure as l, OPTIONAL_WILDCARD as m, CLIENT as n, useSetCookies as nt, Scope as o, OPTIONAL_PARAMETER_MATCH as p, setState as q, CLOSE_HOOK as r, useUrl as rt, defineContext as s, App as t, useServer as tt, mergeObjects as u, ROUTER_CONTEXT as v, WILDCARD_MATCH as w, SERVER_CONTEXT as x, Radix as y, sendBadRequest as z };
613
+ export { useHeaders as $, encodings as A, sendCreated as B, WILDCARD as C, createServer as D, cookieSameSites as E, isServer as F, sendRedirect as G, sendNoContent as H, mimeType as I, setCookie as J, sendResponse as K, mimeTypes as L, httpMethods as M, invoke as N, defineMiddleware as O, isClient as P, useCookies as Q, parseCookiePair as R, STATES as S, cookiePriorities as T, sendNotFound as U, sendForbidden as V, sendOk as W, statusCodes as X, setState as Y, useBody as Z, PARAMETER_MATCH as _, Hookable as a, useUrl as at, Router as b, defineHook as c, parseSchema as d, useParameters as et, OPTIONAL_PARAMETER as f, PARAMETER as g, OPTIONAL_WILDCARD_MATCH as h, SERVER as i, useSetCookies as it, getState as j, defineRoute as k, isFailure as l, OPTIONAL_WILDCARD as m, CLIENT as n, useRouter as nt, Scope as o, withQuery as ot, OPTIONAL_PARAMETER_MATCH as p, sendUnauthorized as q, CLOSE_HOOK as r, useServer as rt, defineContext as s, App as t, useQuery as tt, mergeObjects as u, ROUTER_CONTEXT as v, WILDCARD_MATCH as w, SERVER_CONTEXT as x, Radix as y, sendBadRequest as z };
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as version, t as name } from "../package-DZpKMl3M.mjs";
2
+ import { n as version, t as name } from "../package-DCyffKe-.mjs";
3
3
  import { defineCommand, runMain } from "citty";
4
4
  //#region src/commands/run/index.ts
5
5
  var run_default = defineCommand({ setup() {} });
@@ -152,13 +152,15 @@ declare function useSetCookies<T extends Schema>(scope: Scope, schema: T): Infer
152
152
  declare function setCookie(scope: Scope, name: string, value: string, options?: CookieOptions): void;
153
153
  declare function getState<T>(scope: Scope, name: string): T;
154
154
  declare function setState<T>(scope: Scope, name: string, value: T): void;
155
- declare function sendText(scope: Scope, text: string, config?: Mergeable<ResponseConfig>): Response;
156
- declare function sendHtml(scope: Scope, html: string, config?: Mergeable<ResponseConfig>): Response;
157
- declare function sendJson<T>(scope: Scope, value: T, config?: Mergeable<ResponseConfig>): Response;
155
+ declare function sendResponse<T>(scope: Scope, body?: T | BodyInit, config?: Mergeable<ResponseConfig>): Response;
156
+ declare function sendOk<T>(scope: Scope, body?: T | BodyInit, config?: Mergeable<ResponseConfig>): Response;
157
+ declare function sendCreated<T>(scope: Scope, body?: T | BodyInit, config?: Mergeable<ResponseConfig>): Response;
158
+ declare function sendNoContent(scope: Scope, config?: Mergeable<ResponseConfig>): Response;
158
159
  declare function sendRedirect(scope: Scope, path: string, config?: Mergeable<ResponseConfig>): Response;
159
- declare function sendBadRequest(scope: Scope, body?: BodyInit, config?: Mergeable<ResponseConfig>): Response;
160
- declare function sendUnauthorized(scope: Scope, body?: BodyInit, config?: Mergeable<ResponseConfig>): Response;
161
- declare function sendNotFound(scope: Scope, body?: BodyInit, config?: Mergeable<ResponseConfig>): Response;
160
+ declare function sendBadRequest<T>(scope: Scope, body?: T | BodyInit, config?: Mergeable<ResponseConfig>): Response;
161
+ declare function sendUnauthorized<T>(scope: Scope, body?: T | BodyInit, config?: Mergeable<ResponseConfig>): Response;
162
+ declare function sendForbidden<T>(scope: Scope, body?: T | BodyInit, config?: Mergeable<ResponseConfig>): Response;
163
+ declare function sendNotFound<T>(scope: Scope, body?: T | BodyInit, config?: Mergeable<ResponseConfig>): Response;
162
164
  declare function mimeType(file: string): MimeType;
163
165
  declare function invoke(scope: Scope, pipeline: Array<Middleware>, index?: number): Promise<Result>;
164
166
  declare function createServer(): Promise<Server>;
@@ -230,4 +232,4 @@ declare const CLOSE_HOOK: Descriptor<() => void>;
230
232
  //#region src/client/index.d.ts
231
233
  declare function $fetch<T>(scope: Scope, input: string | URL, options?: RequestInit): Promise<T>;
232
234
  //#endregion
233
- export { defineRoute as $, PARAMETER_MATCH as A, Descriptor as At, SERVER_CONTEXT as B, Scope as Bt, OPTIONAL_PARAMETER as C, useQuery as Ct, OptionalParameterNode as D, useUrl as Dt, OPTIONAL_WILDCARD_MATCH as E, useSetCookies as Et, ResponseConfig as F, Invoke as Ft, StatusCode as G, mergeObjects as Gt, Server as H, defineContext as Ht, Result as I, Issue as It, WildcardNode as J, WILDCARD as K, parseSchema as Kt, Route as L, Mergeable as Lt, PathNode as M, Hookable as Mt, ROUTER_CONTEXT as N, InferInput as Nt, OptionalWildcardNode as O, withQuery as Ot, Radix as P, InferOutput as Pt, defineMiddleware as Q, Router as R, Output as Rt, Node as S, useParameters as St, OPTIONAL_WILDCARD as T, useServer as Tt, ServerContext as U, defineHook as Ut, STATES as V, Success as Vt, States as W, isFailure as Wt, cookieSameSites as X, cookiePriorities as Y, createServer as Z, CookieSameSite as _, setState as _t, CLOSE_HOOK as a, isServer as at, Middleware as b, useCookies as bt, DevelopmentConfig as c, parseCookiePair as ct, SERVER as d, sendJson as dt, encodings as et, Source as f, sendNotFound as ft, CookiePriority as g, setCookie as gt, CookieOptions as h, sendUnauthorized as ht, CLIENT as i, isClient as it, ParameterNode as j, Failure as jt, PARAMETER as k, Context as kt, Environment as l, sendBadRequest as lt, Virtual as m, sendText as mt, App as n, httpMethods as nt, Config as o, mimeType as ot, Template as p, sendRedirect as pt, WILDCARD_MATCH as q, BuildConfig as r, invoke as rt, Content as s, mimeTypes as st, $fetch as t, getState as tt, Module as u, sendHtml as ut, Encoding as v, statusCodes as vt, OPTIONAL_PARAMETER_MATCH as w, useRouter as wt, MimeType as x, useHeaders as xt, HttpMethod as y, useBody as yt, RouterContext as z, Schema as zt };
235
+ export { defineRoute as $, PARAMETER_MATCH as A, withQuery as At, SERVER_CONTEXT as B, Output as Bt, OPTIONAL_PARAMETER as C, useHeaders as Ct, OptionalParameterNode as D, useServer as Dt, OPTIONAL_WILDCARD_MATCH as E, useRouter as Et, ResponseConfig as F, InferInput as Ft, StatusCode as G, defineHook as Gt, Server as H, Scope as Ht, Result as I, InferOutput as It, WildcardNode as J, parseSchema as Jt, WILDCARD as K, isFailure as Kt, Route as L, Invoke as Lt, PathNode as M, Descriptor as Mt, ROUTER_CONTEXT as N, Failure as Nt, OptionalWildcardNode as O, useSetCookies as Ot, Radix as P, Hookable as Pt, defineMiddleware as Q, Router as R, Issue as Rt, Node as S, useCookies as St, OPTIONAL_WILDCARD as T, useQuery as Tt, ServerContext as U, Success as Ut, STATES as V, Schema as Vt, States as W, defineContext as Wt, cookieSameSites as X, cookiePriorities as Y, createServer as Z, CookieSameSite as _, sendUnauthorized as _t, CLOSE_HOOK as a, isServer as at, Middleware as b, statusCodes as bt, DevelopmentConfig as c, parseCookiePair as ct, SERVER as d, sendForbidden as dt, encodings as et, Source as f, sendNoContent as ft, CookiePriority as g, sendResponse as gt, CookieOptions as h, sendRedirect as ht, CLIENT as i, isClient as it, ParameterNode as j, Context as jt, PARAMETER as k, useUrl as kt, Environment as l, sendBadRequest as lt, Virtual as m, sendOk as mt, App as n, httpMethods as nt, Config as o, mimeType as ot, Template as p, sendNotFound as pt, WILDCARD_MATCH as q, mergeObjects as qt, BuildConfig as r, invoke as rt, Content as s, mimeTypes as st, $fetch as t, getState as tt, Module as u, sendCreated as ut, Encoding as v, setCookie as vt, OPTIONAL_PARAMETER_MATCH as w, useParameters as wt, MimeType as x, useBody as xt, HttpMethod as y, setState as yt, RouterContext as z, Mergeable as zt };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as defineRoute, A as PARAMETER_MATCH, At as Descriptor, B as SERVER_CONTEXT, Bt as Scope, C as OPTIONAL_PARAMETER, Ct as useQuery, D as OptionalParameterNode, Dt as useUrl, E as OPTIONAL_WILDCARD_MATCH, Et as useSetCookies, F as ResponseConfig, Ft as Invoke, G as StatusCode, Gt as mergeObjects, H as Server, Ht as defineContext, I as Result, It as Issue, J as WildcardNode, K as WILDCARD, Kt as parseSchema, L as Route, Lt as Mergeable, M as PathNode, Mt as Hookable, N as ROUTER_CONTEXT, Nt as InferInput, O as OptionalWildcardNode, Ot as withQuery, P as Radix, Pt as InferOutput, Q as defineMiddleware, R as Router, Rt as Output, S as Node, St as useParameters, T as OPTIONAL_WILDCARD, Tt as useServer, U as ServerContext, Ut as defineHook, V as STATES, Vt as Success, W as States, Wt as isFailure, X as cookieSameSites, Y as cookiePriorities, Z as createServer, _ as CookieSameSite, _t as setState, a as CLOSE_HOOK, at as isServer, b as Middleware, bt as useCookies, c as DevelopmentConfig, ct as parseCookiePair, d as SERVER, dt as sendJson, et as encodings, f as Source, ft as sendNotFound, g as CookiePriority, gt as setCookie, h as CookieOptions, ht as sendUnauthorized, i as CLIENT, it as isClient, j as ParameterNode, jt as Failure, k as PARAMETER, kt as Context, l as Environment, lt as sendBadRequest, m as Virtual, mt as sendText, n as App, nt as httpMethods, o as Config, ot as mimeType, p as Template, pt as sendRedirect, q as WILDCARD_MATCH, r as BuildConfig, rt as invoke, s as Content, st as mimeTypes, t as $fetch, tt as getState, u as Module, ut as sendHtml, v as Encoding, vt as statusCodes, w as OPTIONAL_PARAMETER_MATCH, wt as useRouter, x as MimeType, xt as useHeaders, y as HttpMethod, yt as useBody, z as RouterContext, zt as Schema } from "./index-luIDvYxN.mjs";
2
- export { $fetch, App, BuildConfig, CLIENT, CLOSE_HOOK, Config, Content, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, Hookable, HttpMethod, InferInput, InferOutput, Invoke, Issue, Mergeable, Middleware, MimeType, Module, Node, OPTIONAL_PARAMETER, OPTIONAL_PARAMETER_MATCH, OPTIONAL_WILDCARD, OPTIONAL_WILDCARD_MATCH, OptionalParameterNode, OptionalWildcardNode, Output, PARAMETER, PARAMETER_MATCH, ParameterNode, PathNode, ROUTER_CONTEXT, Radix, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, STATES, Schema, Scope, Server, ServerContext, Source, States, StatusCode, Success, Template, Virtual, WILDCARD, WILDCARD_MATCH, WildcardNode, cookiePriorities, cookieSameSites, createServer, defineContext, defineHook, defineMiddleware, defineRoute, encodings, getState, httpMethods, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseCookiePair, parseSchema, sendBadRequest, sendHtml, sendJson, sendNotFound, sendRedirect, sendText, sendUnauthorized, setCookie, setState, statusCodes, useBody, useCookies, useHeaders, useParameters, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
1
+ import { $ as defineRoute, A as PARAMETER_MATCH, At as withQuery, B as SERVER_CONTEXT, Bt as Output, C as OPTIONAL_PARAMETER, Ct as useHeaders, D as OptionalParameterNode, Dt as useServer, E as OPTIONAL_WILDCARD_MATCH, Et as useRouter, F as ResponseConfig, Ft as InferInput, G as StatusCode, Gt as defineHook, H as Server, Ht as Scope, I as Result, It as InferOutput, J as WildcardNode, Jt as parseSchema, K as WILDCARD, Kt as isFailure, L as Route, Lt as Invoke, M as PathNode, Mt as Descriptor, N as ROUTER_CONTEXT, Nt as Failure, O as OptionalWildcardNode, Ot as useSetCookies, P as Radix, Pt as Hookable, Q as defineMiddleware, R as Router, Rt as Issue, S as Node, St as useCookies, T as OPTIONAL_WILDCARD, Tt as useQuery, U as ServerContext, Ut as Success, V as STATES, Vt as Schema, W as States, Wt as defineContext, X as cookieSameSites, Y as cookiePriorities, Z as createServer, _ as CookieSameSite, _t as sendUnauthorized, a as CLOSE_HOOK, at as isServer, b as Middleware, bt as statusCodes, c as DevelopmentConfig, ct as parseCookiePair, d as SERVER, dt as sendForbidden, et as encodings, f as Source, ft as sendNoContent, g as CookiePriority, gt as sendResponse, h as CookieOptions, ht as sendRedirect, i as CLIENT, it as isClient, j as ParameterNode, jt as Context, k as PARAMETER, kt as useUrl, l as Environment, lt as sendBadRequest, m as Virtual, mt as sendOk, n as App, nt as httpMethods, o as Config, ot as mimeType, p as Template, pt as sendNotFound, q as WILDCARD_MATCH, qt as mergeObjects, r as BuildConfig, rt as invoke, s as Content, st as mimeTypes, t as $fetch, tt as getState, u as Module, ut as sendCreated, v as Encoding, vt as setCookie, w as OPTIONAL_PARAMETER_MATCH, wt as useParameters, x as MimeType, xt as useBody, y as HttpMethod, yt as setState, z as RouterContext, zt as Mergeable } from "./index-CNiAmGY8.mjs";
2
+ export { $fetch, App, BuildConfig, CLIENT, CLOSE_HOOK, Config, Content, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, Hookable, HttpMethod, InferInput, InferOutput, Invoke, Issue, Mergeable, Middleware, MimeType, Module, Node, OPTIONAL_PARAMETER, OPTIONAL_PARAMETER_MATCH, OPTIONAL_WILDCARD, OPTIONAL_WILDCARD_MATCH, OptionalParameterNode, OptionalWildcardNode, Output, PARAMETER, PARAMETER_MATCH, ParameterNode, PathNode, ROUTER_CONTEXT, Radix, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, STATES, Schema, Scope, Server, ServerContext, Source, States, StatusCode, Success, Template, Virtual, WILDCARD, WILDCARD_MATCH, WildcardNode, cookiePriorities, cookieSameSites, createServer, defineContext, defineHook, defineMiddleware, defineRoute, encodings, getState, httpMethods, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseCookiePair, parseSchema, sendBadRequest, sendCreated, sendForbidden, sendNoContent, sendNotFound, sendOk, sendRedirect, sendResponse, sendUnauthorized, setCookie, setState, statusCodes, useBody, useCookies, useHeaders, useParameters, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as useQuery, A as encodings, B as sendHtml, C as WILDCARD, D as createServer, E as cookieSameSites, F as isServer, G as sendUnauthorized, H as sendNotFound, I as mimeType, J as statusCodes, K as setCookie, L as mimeTypes, M as httpMethods, N as invoke, O as defineMiddleware, P as isClient, Q as useParameters, R as parseCookiePair, S as STATES, T as cookiePriorities, U as sendRedirect, V as sendJson, W as sendText, X as useCookies, Y as useBody, Z as useHeaders, _ as PARAMETER_MATCH, a as Hookable, b as Router, c as defineHook, d as parseSchema, et as useRouter, f as OPTIONAL_PARAMETER, g as PARAMETER, h as OPTIONAL_WILDCARD_MATCH, i as SERVER, it as withQuery, j as getState, k as defineRoute, l as isFailure, m as OPTIONAL_WILDCARD, n as CLIENT, nt as useSetCookies, o as Scope, p as OPTIONAL_PARAMETER_MATCH, q as setState, r as CLOSE_HOOK, rt as useUrl, s as defineContext, t as App, tt as useServer, u as mergeObjects, v as ROUTER_CONTEXT, w as WILDCARD_MATCH, x as SERVER_CONTEXT, y as Radix, z as sendBadRequest } from "./app-BLvLmc8N.mjs";
1
+ import { $ as useHeaders, A as encodings, B as sendCreated, C as WILDCARD, D as createServer, E as cookieSameSites, F as isServer, G as sendRedirect, H as sendNoContent, I as mimeType, J as setCookie, K as sendResponse, L as mimeTypes, M as httpMethods, N as invoke, O as defineMiddleware, P as isClient, Q as useCookies, R as parseCookiePair, S as STATES, T as cookiePriorities, U as sendNotFound, V as sendForbidden, W as sendOk, X as statusCodes, Y as setState, Z as useBody, _ as PARAMETER_MATCH, a as Hookable, at as useUrl, b as Router, c as defineHook, d as parseSchema, et as useParameters, f as OPTIONAL_PARAMETER, g as PARAMETER, h as OPTIONAL_WILDCARD_MATCH, i as SERVER, it as useSetCookies, j as getState, k as defineRoute, l as isFailure, m as OPTIONAL_WILDCARD, n as CLIENT, nt as useRouter, o as Scope, ot as withQuery, p as OPTIONAL_PARAMETER_MATCH, q as sendUnauthorized, r as CLOSE_HOOK, rt as useServer, s as defineContext, t as App, tt as useQuery, u as mergeObjects, v as ROUTER_CONTEXT, w as WILDCARD_MATCH, x as SERVER_CONTEXT, y as Radix, z as sendBadRequest } from "./app-BDHw-biB.mjs";
2
2
  //#region src/client/index.ts
3
3
  async function $fetch(scope, input, options) {
4
4
  let response;
@@ -19,8 +19,26 @@ async function $fetch(scope, input, options) {
19
19
  if (response.ok === false) throw response;
20
20
  switch (response.headers.get("Content-Type")?.split(";").shift() ?? "") {
21
21
  case "application/json": return response.json();
22
+ case "text/plain":
23
+ case "text/html":
24
+ case "text/css":
25
+ case "text/xml":
26
+ case "application/xml":
27
+ case "application/javascript":
28
+ case "application/json": return response.text();
29
+ case "application/octet-stream":
30
+ case "application/pdf":
31
+ case "application/zip":
32
+ case "image/png":
33
+ case "image/jpeg":
34
+ case "image/gif":
35
+ case "image/webp":
36
+ case "image/svg+xml":
37
+ case "audio/mpeg":
38
+ case "video/mp4": return response.blob();
39
+ case "multipart/form-data": return response.formData();
22
40
  default: return response;
23
41
  }
24
42
  }
25
43
  //#endregion
26
- export { $fetch, App, CLIENT, CLOSE_HOOK, Hookable, OPTIONAL_PARAMETER, OPTIONAL_PARAMETER_MATCH, OPTIONAL_WILDCARD, OPTIONAL_WILDCARD_MATCH, PARAMETER, PARAMETER_MATCH, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope, WILDCARD, WILDCARD_MATCH, cookiePriorities, cookieSameSites, createServer, defineContext, defineHook, defineMiddleware, defineRoute, encodings, getState, httpMethods, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseCookiePair, parseSchema, sendBadRequest, sendHtml, sendJson, sendNotFound, sendRedirect, sendText, sendUnauthorized, setCookie, setState, statusCodes, useBody, useCookies, useHeaders, useParameters, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
44
+ export { $fetch, App, CLIENT, CLOSE_HOOK, Hookable, OPTIONAL_PARAMETER, OPTIONAL_PARAMETER_MATCH, OPTIONAL_WILDCARD, OPTIONAL_WILDCARD_MATCH, PARAMETER, PARAMETER_MATCH, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope, WILDCARD, WILDCARD_MATCH, cookiePriorities, cookieSameSites, createServer, defineContext, defineHook, defineMiddleware, defineRoute, encodings, getState, httpMethods, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseCookiePair, parseSchema, sendBadRequest, sendCreated, sendForbidden, sendNoContent, sendNotFound, sendOk, sendRedirect, sendResponse, sendUnauthorized, setCookie, setState, statusCodes, useBody, useCookies, useHeaders, useParameters, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
@@ -1,4 +1,4 @@
1
- import { m as Virtual, n as App, s as Content } from "../index-luIDvYxN.mjs";
1
+ import { m as Virtual, n as App, s as Content } from "../index-CNiAmGY8.mjs";
2
2
 
3
3
  //#region src/kit/index.d.ts
4
4
  declare function useKit(source: string | URL): {
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
2
  var name = "revojs";
3
- var version = "0.1.41";
3
+ var version = "0.1.43";
4
4
  //#endregion
5
5
  export { version as n, name as t };
@@ -1,4 +1,4 @@
1
- import { Lt as Mergeable, o as Config } from "../index-luIDvYxN.mjs";
1
+ import { o as Config, zt as Mergeable } from "../index-CNiAmGY8.mjs";
2
2
  import { Plugin } from "vite";
3
3
 
4
4
  //#region src/vite/index.d.ts
@@ -1,5 +1,5 @@
1
- import { N as invoke, n as CLIENT, o as Scope, r as CLOSE_HOOK, t as App, u as mergeObjects, x as SERVER_CONTEXT } from "../app-BLvLmc8N.mjs";
2
- import { n as version, t as name } from "../package-DZpKMl3M.mjs";
1
+ import { N as invoke, n as CLIENT, o as Scope, r as CLOSE_HOOK, t as App, u as mergeObjects, x as SERVER_CONTEXT } from "../app-BDHw-biB.mjs";
2
+ import { n as version, t as name } from "../package-DCyffKe-.mjs";
3
3
  import { addTemplate, addTypes, addVirtual, useKit } from "../kit/index.mjs";
4
4
  import { basename, dirname, isAbsolute, join, posix, resolve, win32 } from "path";
5
5
  import { mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
@@ -7,127 +7,22 @@ import { cwd } from "process";
7
7
  import { globSync } from "tinyglobby";
8
8
  import { isRunnableDevEnvironment } from "vite";
9
9
  import { once } from "events";
10
- import { Readable, Stream } from "stream";
10
+ import { Readable } from "stream";
11
11
  //#region src/vite/node/index.ts
12
- function splitSetCookieString(cookiesString) {
13
- if (Array.isArray(cookiesString)) return cookiesString.flatMap((c) => splitSetCookieString(c));
14
- if (typeof cookiesString !== "string") return [];
15
- const cookiesStrings = [];
16
- let pos = 0;
17
- let start;
18
- let ch;
19
- let lastComma;
20
- let nextStart;
21
- let cookiesSeparatorFound;
22
- const skipWhitespace = () => {
23
- while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) pos += 1;
24
- return pos < cookiesString.length;
25
- };
26
- const notSpecialChar = () => {
27
- ch = cookiesString.charAt(pos);
28
- return ch !== "=" && ch !== ";" && ch !== ",";
29
- };
30
- while (pos < cookiesString.length) {
31
- start = pos;
32
- cookiesSeparatorFound = false;
33
- while (skipWhitespace()) {
34
- ch = cookiesString.charAt(pos);
35
- if (ch === ",") {
36
- lastComma = pos;
37
- pos += 1;
38
- skipWhitespace();
39
- nextStart = pos;
40
- while (pos < cookiesString.length && notSpecialChar()) pos += 1;
41
- if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
42
- cookiesSeparatorFound = true;
43
- pos = nextStart;
44
- cookiesStrings.push(cookiesString.slice(start, lastComma));
45
- start = pos;
46
- } else pos = lastComma + 1;
47
- } else pos += 1;
48
- }
49
- if (!cookiesSeparatorFound || pos >= cookiesString.length) cookiesStrings.push(cookiesString.slice(start));
50
- }
51
- return cookiesStrings;
52
- }
53
12
  function createReadableStreamFromReadable(source) {
54
- let pump = new StreamPump(source);
55
- return new ReadableStream(pump, pump);
13
+ return Readable.toWeb(source);
56
14
  }
57
- var StreamPump = class {
58
- highWaterMark;
59
- accumalatedSize;
60
- stream;
61
- controller;
62
- constructor(stream) {
63
- this.highWaterMark = stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;
64
- this.accumalatedSize = 0;
65
- this.stream = stream;
66
- this.enqueue = this.enqueue.bind(this);
67
- this.error = this.error.bind(this);
68
- this.close = this.close.bind(this);
69
- }
70
- size(chunk) {
71
- return chunk?.byteLength || 0;
72
- }
73
- start(controller) {
74
- this.controller = controller;
75
- this.stream.on("data", this.enqueue);
76
- this.stream.once("error", this.error);
77
- this.stream.once("end", this.close);
78
- this.stream.once("close", this.close);
79
- }
80
- pull() {
81
- this.resume();
82
- }
83
- cancel(reason) {
84
- if (this.stream.destroy) this.stream.destroy(reason);
85
- this.stream.off("data", this.enqueue);
86
- this.stream.off("error", this.error);
87
- this.stream.off("end", this.close);
88
- this.stream.off("close", this.close);
89
- }
90
- enqueue(chunk) {
91
- if (this.controller) try {
92
- let bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
93
- let available = (this.controller.desiredSize || 0) - bytes.byteLength;
94
- this.controller.enqueue(bytes);
95
- if (available <= 0) this.pause();
96
- } catch (error) {
97
- this.controller.error(/* @__PURE__ */ new Error("Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object"));
98
- this.cancel();
99
- }
100
- }
101
- pause() {
102
- if (this.stream.pause) this.stream.pause();
103
- }
104
- resume() {
105
- if (this.stream.readable && this.stream.resume) this.stream.resume();
106
- }
107
- close() {
108
- if (this.controller) {
109
- this.controller.close();
110
- delete this.controller;
111
- }
112
- }
113
- error(error) {
114
- if (this.controller) {
115
- this.controller.error(error);
116
- delete this.controller;
117
- }
118
- }
119
- };
120
15
  function fromNodeHeaders(nodeHeaders) {
121
- let headers = new Headers();
122
- for (let [key, values] of Object.entries(nodeHeaders)) if (values) if (Array.isArray(values)) for (let value of values) headers.append(key, value);
123
- else headers.set(key, values);
16
+ const headers = new Headers();
17
+ for (const [key, value] of Object.entries(nodeHeaders)) if (value) if (Array.isArray(value)) for (const v of value) headers.append(key, v);
18
+ else headers.set(key, value);
124
19
  return headers;
125
20
  }
126
21
  function fromNodeRequest(nodeReq, nodeRes) {
127
- let origin = nodeReq.headers.origin && "null" !== nodeReq.headers.origin ? nodeReq.headers.origin : `http://${nodeReq.headers.host}`;
128
- let url = new URL(nodeReq.url ?? "", origin);
22
+ const origin = nodeReq.headers.origin && "null" !== nodeReq.headers.origin ? nodeReq.headers.origin : `http://${nodeReq.headers.host}`;
23
+ const url = new URL(nodeReq.url ?? "", origin);
129
24
  let controller = new AbortController();
130
- let init = {
25
+ const init = {
131
26
  method: nodeReq.method,
132
27
  headers: fromNodeHeaders(nodeReq.headers),
133
28
  signal: controller.signal
@@ -136,20 +31,23 @@ function fromNodeRequest(nodeReq, nodeRes) {
136
31
  init.body = createReadableStreamFromReadable(nodeReq);
137
32
  init.duplex = "half";
138
33
  }
139
- nodeRes.on("finish", () => controller = null);
34
+ nodeRes.on("finish", () => {
35
+ controller = null;
36
+ });
140
37
  nodeRes.on("close", () => controller?.abort());
141
38
  return new Request(url.href, init);
142
39
  }
143
40
  async function toNodeRequest(res, nodeRes) {
144
41
  nodeRes.statusCode = res.status;
145
42
  nodeRes.statusMessage = res.statusText;
146
- let cookiesStrings = [];
147
- for (let [name, value] of res.headers) if (name === "set-cookie") cookiesStrings.push(...splitSetCookieString(value));
148
- else nodeRes.setHeader(name, value);
43
+ const cookiesStrings = [];
44
+ for (const [name, value] of res.headers) if (name === "set-cookie") {
45
+ const cookieArray = Array.isArray(value) ? value : [value ?? ""];
46
+ cookiesStrings.push(...cookieArray.flatMap((c) => c.split(/,\s*(?=[^=]+=)/)));
47
+ } else nodeRes.setHeader(name, value);
149
48
  if (cookiesStrings.length) nodeRes.setHeader("set-cookie", cookiesStrings);
150
49
  if (res.body) {
151
- let responseBody = res.body;
152
- let readable = Readable.from(responseBody);
50
+ const readable = Readable.fromWeb(res.body);
153
51
  readable.pipe(nodeRes);
154
52
  await once(readable, "end");
155
53
  } else nodeRes.end();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.1.41",
3
+ "version": "0.1.43",
4
4
  "license": "MIT",
5
5
  "repository": "tellua/revojs",
6
6
  "bin": {