revojs 0.0.47 → 0.0.49

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.
@@ -24,6 +24,6 @@ export type App = {
24
24
  config: Config;
25
25
  virtuals: Record<string, (environment: Environment) => string>;
26
26
  };
27
- export declare const createApp: <T>(config?: NestedPartial<Config>) => App;
27
+ export declare const createApp: (config?: NestedPartial<Config>) => App;
28
28
  export declare const SERVER = "ssr";
29
29
  export declare const CLIENT = "client";
@@ -87,7 +87,6 @@ export declare const registerComponent: <TEvents extends Events, TAttributes ext
87
87
  export declare function useEvent<T extends keyof ElementEventMap>(scope: Scope, target: EventTarget | undefined | null, event: T, input: EventListener<ElementEventMap[T]>, options?: AddEventListenerOptions): void;
88
88
  export declare function useEvent<T extends keyof WindowEventMap>(scope: Scope, target: Window | undefined | null, event: T, input: EventListener<WindowEventMap[T]>, options?: AddEventListenerOptions): void;
89
89
  export declare function useEvent<T extends keyof HTMLElementEventMap>(scope: Scope, target: HTMLElement | undefined | null, event: T, input: EventListener<HTMLElementEventMap[T]>, options?: AddEventListenerOptions): void;
90
- export declare const getCustomElement: (node: Node | null) => CustomElement<Events, Attributes> | undefined;
91
90
  export declare const isClient: () => boolean;
92
91
  export declare const isServer: () => boolean;
93
92
  export declare const preventDefault: (event: Event) => void;
@@ -13,26 +13,21 @@ export type HttpMethod = "GET" | "HEAD" | "PATCH" | "POST" | "PUT" | "DELETE" |
13
13
  export type Encoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex";
14
14
  export type StatusCode = 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 444 | 450 | 451 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 506 | 507 | 508 | 509 | 510 | 511 | 521 | 522 | 523 | 525 | 530 | 599;
15
15
  export type MimeType = "text/plain" | "text/css" | "text/html" | "text/csv" | "text/javascript" | "application/json" | "application/xml" | "image/jpeg" | "image/png" | "image/gif" | "image/webp" | "image/svg+xml" | "image/bmp" | "image/x-icon" | "font/ttf" | "font/otf" | "font/woff" | "font/woff2" | "audio/mpeg" | "audio/wav" | "audio/ogg" | "audio/mp4" | "video/mp4" | "video/webm" | "video/ogg" | "video/quicktime" | "video/x-msvideo" | "application/zip" | "application/vnd.rar" | "application/x-tar" | "application/gzip" | "application/x-7z-compressed" | "application/pdf" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "application/vnd.microsoft.portable-executable" | "application/vnd.android.package-archive";
16
- export type Set = {
16
+ export type ResponseOptions = {
17
17
  status?: StatusCode;
18
18
  message?: string;
19
19
  headers: Headers;
20
20
  };
21
- export declare class Event extends Scope {
22
- request: Request;
23
- response: Set;
24
- constructor(request: Request);
25
- }
26
- export type Handle = (event: Event) => void | Response | Promise<void | Response>;
27
- export type Middleware = (event: Event, next: Handle) => void | Response | Promise<void | Response>;
28
- export declare const sendText: (event: Event, text: string) => Response;
29
- export declare const sendHtml: (event: Event, text: string) => Response;
30
- export declare const sendJson: <T>(event: Event, value: T) => Response;
31
- export declare const sendRedirect: (event: Event, path: string) => Response;
32
- export declare const sendBadRequest: (event: Event, text: string) => Response;
33
- export declare const sendUnauthorized: (event: Event) => Response;
34
- export declare const getRequestUrl: (event: Event, base?: string) => URL;
35
- export declare const getCookies: (event: Event) => Record<string, string>;
36
- export declare const getSetCookies: (event: Event) => Record<string, string>;
37
- export declare const setCookie: (event: Event, name: string, value: string, options?: CookieOptions) => void;
38
- export declare const getMimeType: (file: string) => MimeType;
21
+ export type Handle = (scope: Scope) => void | Response | Promise<void | Response>;
22
+ export type Middleware = (scope: Scope, next: Handle) => void | Response | Promise<void | Response>;
23
+ export declare const sendText: (scope: Scope, text: string) => Response;
24
+ export declare const sendHtml: (scope: Scope, text: string) => Response;
25
+ export declare const sendJson: <T>(scope: Scope, value: T) => Response;
26
+ export declare const sendRedirect: (scope: Scope, path: string) => Response;
27
+ export declare const sendBadRequest: (scope: Scope, text: string) => Response;
28
+ export declare const sendUnauthorized: (scope: Scope) => Response;
29
+ export declare const useRequestUrl: (scope: Scope, base?: string) => URL;
30
+ export declare const useCookies: (scope: Scope) => Record<string, string>;
31
+ export declare const useSetCookies: (scope: Scope) => Record<string, string>;
32
+ export declare const setCookie: (scope: Scope, name: string, value: string, options?: CookieOptions) => void;
33
+ export declare const mimeType: (file: string) => MimeType;
package/dist/index.js CHANGED
@@ -462,12 +462,6 @@ function useEvent(scope, target, event, input, options) {
462
462
  });
463
463
  scope.onStop(() => controller.abort());
464
464
  }
465
- const getCustomElement = (node) => {
466
- if (node) {
467
- if ("component" in node) return node;
468
- return getCustomElement(node.parentNode);
469
- }
470
- };
471
465
  const isClient = () => typeof window !== "undefined";
472
466
  const isServer = () => typeof window === "undefined";
473
467
  const preventDefault = (event) => event.preventDefault();
@@ -476,123 +470,6 @@ const stopImmediatePropagation = (event) => event.stopImmediatePropagation();
476
470
  const components = new Map();
477
471
  const HOST_CONTEXT = defineContext("HOST_CONTEXT");
478
472
 
479
- //#endregion
480
- //#region src/http/index.ts
481
- var Event$1 = class extends Scope {
482
- request;
483
- response;
484
- constructor(request) {
485
- super();
486
- this.request = request;
487
- this.response = { headers: new Headers() };
488
- }
489
- };
490
- const sendText = (event, text) => {
491
- event.response.headers.set("Content-Type", "text/plain");
492
- return new Response(text, event.response);
493
- };
494
- const sendHtml = (event, text) => {
495
- event.response.headers.set("Content-Type", "text/html");
496
- return new Response(text, event.response);
497
- };
498
- const sendJson = (event, value) => {
499
- event.response.headers.set("Content-Type", "application/json");
500
- return new Response(JSON.stringify(value), event.response);
501
- };
502
- const sendRedirect = (event, path) => {
503
- event.response.status = 302;
504
- event.response.headers.set("Location", path);
505
- return new Response(null, event.response);
506
- };
507
- const sendBadRequest = (event, text) => {
508
- event.response.status = 400;
509
- return new Response(text, event.response);
510
- };
511
- const sendUnauthorized = (event) => {
512
- event.response.status = 401;
513
- return new Response(null, event.response);
514
- };
515
- const getRequestUrl = (event, base) => {
516
- return new URL(event.request.url, base);
517
- };
518
- const getCookies = (event) => {
519
- const cookies = event.request.headers.get("Cookie")?.split("; ") ?? [];
520
- return cookies.reduce((result, cookie) => {
521
- const [name, value] = cookie.split("=");
522
- if (name && value) result[name] = decodeURIComponent(value);
523
- return result;
524
- }, {});
525
- };
526
- const getSetCookies = (event) => {
527
- const cookies = event.request.headers.getSetCookie();
528
- return cookies.reduce((result, cookie) => {
529
- const [name, value] = cookie.split("=");
530
- if (name && value) result[name] = decodeURIComponent(value);
531
- return result;
532
- }, {});
533
- };
534
- const setCookie = (event, name, value, options) => {
535
- let cookie = name + "=" + encodeURIComponent(value);
536
- if (options?.domain) cookie += `; Domain=${options.domain}`;
537
- if (options?.expires) cookie += `; Expires=${options.expires.toUTCString()}`;
538
- if (options?.httpOnly) cookie += `; HttpOnly`;
539
- if (options?.maxAge) cookie += `; Max-Age=${options.maxAge}`;
540
- if (options?.path) cookie += `; Path=${options.path}`;
541
- if (options?.priority) cookie += `; Priority=${options.priority}`;
542
- if (options?.sameSite) cookie += `; SameSite=${options.sameSite}`;
543
- if (options?.secure) cookie += `; Secure`;
544
- event.response.headers.append("Set-Cookie", cookie);
545
- };
546
- const getMimeType = (file) => {
547
- const extension = /\.([a-zA-Z0-9]+?)$/.exec(file)?.at(1);
548
- return mimeTypes[extension ?? ""] ?? "text/plain";
549
- };
550
- const mimeTypes = {
551
- txt: "text/plain",
552
- css: "text/css",
553
- html: "text/html",
554
- htm: "text/html",
555
- js: "text/javascript",
556
- json: "application/json",
557
- xml: "application/xml",
558
- csv: "text/csv",
559
- jpg: "image/jpeg",
560
- jpeg: "image/jpeg",
561
- png: "image/png",
562
- gif: "image/gif",
563
- webp: "image/webp",
564
- svg: "image/svg+xml",
565
- bmp: "image/bmp",
566
- ico: "image/x-icon",
567
- ttf: "font/ttf",
568
- otf: "font/otf",
569
- woff: "font/woff",
570
- woff2: "font/woff2",
571
- mp3: "audio/mpeg",
572
- wav: "audio/wav",
573
- ogg: "audio/ogg",
574
- m4a: "audio/mp4",
575
- mp4: "video/mp4",
576
- webm: "video/webm",
577
- ogv: "video/ogg",
578
- mov: "video/quicktime",
579
- avi: "video/x-msvideo",
580
- zip: "application/zip",
581
- rar: "application/vnd.rar",
582
- tar: "application/x-tar",
583
- gz: "application/gzip",
584
- "7z": "application/x-7z-compressed",
585
- pdf: "application/pdf",
586
- doc: "application/msword",
587
- docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
588
- xls: "application/vnd.ms-excel",
589
- xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
590
- ppt: "application/vnd.ms-powerpoint",
591
- pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
592
- exe: "application/vnd.microsoft.portable-executable",
593
- apk: "application/vnd.android.package-archive"
594
- };
595
-
596
473
  //#endregion
597
474
  //#region src/radix/index.ts
598
475
  var Radix = class Radix {
@@ -638,8 +515,8 @@ var Radix = class Radix {
638
515
  const useRuntime = (scope) => {
639
516
  return scope.getContext(RUNTIME_CONTEXT);
640
517
  };
641
- const useVariables = (scope) => {
642
- return scope.getContext(VARIABLE_CONTEXT);
518
+ const useRoute = (scope) => {
519
+ return scope.getContext(ROUTE_CONTEXT);
643
520
  };
644
521
  const defineRoute = (route) => {
645
522
  return route;
@@ -654,18 +531,23 @@ const toPath = (value) => {
654
531
  return split.length === 3 ? [split.at(0), split.at(1)] : [split.at(0)];
655
532
  };
656
533
  const $fetch = async (scope, input, options) => {
657
- const { event } = useRuntime(scope);
534
+ const { request, variables } = useRuntime(scope);
658
535
  let response;
659
- if (event) {
660
- const url = new URL(input.toString(), event.request.url);
661
- const next = new Event$1(new Request(url, options));
662
- next.setContext(VARIABLE_CONTEXT, useVariables(event));
663
- const previous = new URL(event.request.url);
536
+ if (request) {
537
+ const next = new Scope();
538
+ const url = new URL(input.toString(), request.url);
539
+ next.setContext(RUNTIME_CONTEXT, {
540
+ request: new Request(url, options),
541
+ response: { headers: new Headers() },
542
+ variables
543
+ });
544
+ const previous = new URL(request.url);
664
545
  if (url.origin === previous.origin) response = await (await import("#virtual/runtime")).runtime.fetch(next);
665
546
  }
666
547
  response ??= await fetch(input, options);
667
548
  if (response.ok === false) throw response;
668
- switch (response.headers.get("Content-Type")) {
549
+ const contentType = response.headers.get("Content-Type")?.split(";").shift() ?? "";
550
+ switch (contentType) {
669
551
  case "application/json": return response.json();
670
552
  default: return response;
671
553
  }
@@ -683,29 +565,28 @@ const createRuntime = async () => {
683
565
  } }));
684
566
  }
685
567
  const assets = await import("#virtual/assets").then((module) => module.assets);
686
- for (const path in assets) radix.insert("GET/" + path, defineRoute({ fetch: async (event) => {
687
- event.response.headers.set("Content-Type", getMimeType(path));
688
- return new Response(await assets[path]?.(), event.response);
568
+ for (const path in assets) radix.insert("GET/" + path, defineRoute({ fetch: async (scope) => {
569
+ const { response } = useRuntime(scope);
570
+ response.headers.set("Content-Type", mimeType(path));
571
+ return new Response(await assets[path]?.(), response);
689
572
  } }));
690
- const invoke = (event, next, index) => {
691
- return middlewares.at(index)?.(event, () => invoke(event, next, index + 1)) ?? next(event);
573
+ const invoke = (scope, next, index) => {
574
+ return middlewares.at(index)?.(scope, () => invoke(scope, next, index + 1)) ?? next(scope);
692
575
  };
693
576
  return {
694
577
  radix,
695
578
  middlewares,
696
- fetch: async (event) => {
697
- const url = getRequestUrl(event);
698
- const { value: route, inputs } = radix.match(event.request.method + url.pathname);
579
+ fetch: async (scope) => {
580
+ const { request } = useRuntime(scope);
581
+ const { pathname } = useRequestUrl(scope);
582
+ const { value: route, inputs } = radix.match(request.method + pathname);
699
583
  try {
700
- event.setContext(RUNTIME_CONTEXT, {
701
- event,
702
- inputs
703
- });
584
+ scope.setContext(ROUTE_CONTEXT, { inputs: createState(inputs) });
704
585
  if (route) {
705
- const response = await invoke(event, route.fetch, 0);
586
+ const response = await invoke(scope, route.fetch, 0);
706
587
  if (response) return response;
707
588
  }
708
- return sendText(event, "NOT_FOUND");
589
+ return sendText(scope, "NOT_FOUND");
709
590
  } catch (exception) {
710
591
  if (exception instanceof Response) return exception;
711
592
  throw exception;
@@ -714,7 +595,123 @@ const createRuntime = async () => {
714
595
  };
715
596
  };
716
597
  const RUNTIME_CONTEXT = defineContext("RUNTIME_CONTEXT");
717
- const VARIABLE_CONTEXT = defineContext("VARIABLE_CONTEXT");
598
+ const ROUTE_CONTEXT = defineContext("ROUTE_CONTEXT");
599
+
600
+ //#endregion
601
+ //#region src/http/index.ts
602
+ const sendText = (scope, text) => {
603
+ const { response } = useRuntime(scope);
604
+ response.headers.set("Content-Type", "text/plain");
605
+ return new Response(text, response);
606
+ };
607
+ const sendHtml = (scope, text) => {
608
+ const { response } = useRuntime(scope);
609
+ response.headers.set("Content-Type", "text/html");
610
+ return new Response(text, response);
611
+ };
612
+ const sendJson = (scope, value) => {
613
+ const { response } = useRuntime(scope);
614
+ response.headers.set("Content-Type", "application/json");
615
+ return new Response(JSON.stringify(value), response);
616
+ };
617
+ const sendRedirect = (scope, path) => {
618
+ const { response } = useRuntime(scope);
619
+ response.status = 302;
620
+ response.headers.set("Location", path);
621
+ return new Response(null, response);
622
+ };
623
+ const sendBadRequest = (scope, text) => {
624
+ const { response } = useRuntime(scope);
625
+ response.status = 400;
626
+ return new Response(text, response);
627
+ };
628
+ const sendUnauthorized = (scope) => {
629
+ const { response } = useRuntime(scope);
630
+ response.status = 401;
631
+ return new Response(null, response);
632
+ };
633
+ const useRequestUrl = (scope, base) => {
634
+ const { request } = useRuntime(scope);
635
+ return new URL(request.url, base);
636
+ };
637
+ const useCookies = (scope) => {
638
+ const { request } = useRuntime(scope);
639
+ return (request.headers.get("Cookie")?.split("; ") ?? []).reduce((result, cookie) => {
640
+ const [name, value] = cookie.split("=");
641
+ if (name && value) result[name] = decodeURIComponent(value);
642
+ return result;
643
+ }, {});
644
+ };
645
+ const useSetCookies = (scope) => {
646
+ const { request } = useRuntime(scope);
647
+ return request.headers.getSetCookie().reduce((result, cookie) => {
648
+ const [name, value] = cookie.split("=");
649
+ if (name && value) result[name] = decodeURIComponent(value);
650
+ return result;
651
+ }, {});
652
+ };
653
+ const setCookie = (scope, name, value, options) => {
654
+ const { response } = useRuntime(scope);
655
+ let cookie = name + "=" + encodeURIComponent(value);
656
+ if (options?.domain) cookie += `; Domain=${options.domain}`;
657
+ if (options?.expires) cookie += `; Expires=${options.expires.toUTCString()}`;
658
+ if (options?.httpOnly) cookie += `; HttpOnly`;
659
+ if (options?.maxAge) cookie += `; Max-Age=${options.maxAge}`;
660
+ if (options?.path) cookie += `; Path=${options.path}`;
661
+ if (options?.priority) cookie += `; Priority=${options.priority}`;
662
+ if (options?.sameSite) cookie += `; SameSite=${options.sameSite}`;
663
+ if (options?.secure) cookie += `; Secure`;
664
+ response.headers.append("Set-Cookie", cookie);
665
+ };
666
+ const mimeType = (file) => {
667
+ const extension = /\.([a-zA-Z0-9]+?)$/.exec(file)?.at(1);
668
+ return mimeTypes[extension ?? ""] ?? "text/plain";
669
+ };
670
+ const mimeTypes = {
671
+ txt: "text/plain",
672
+ css: "text/css",
673
+ html: "text/html",
674
+ htm: "text/html",
675
+ js: "text/javascript",
676
+ json: "application/json",
677
+ xml: "application/xml",
678
+ csv: "text/csv",
679
+ jpg: "image/jpeg",
680
+ jpeg: "image/jpeg",
681
+ png: "image/png",
682
+ gif: "image/gif",
683
+ webp: "image/webp",
684
+ svg: "image/svg+xml",
685
+ bmp: "image/bmp",
686
+ ico: "image/x-icon",
687
+ ttf: "font/ttf",
688
+ otf: "font/otf",
689
+ woff: "font/woff",
690
+ woff2: "font/woff2",
691
+ mp3: "audio/mpeg",
692
+ wav: "audio/wav",
693
+ ogg: "audio/ogg",
694
+ m4a: "audio/mp4",
695
+ mp4: "video/mp4",
696
+ webm: "video/webm",
697
+ ogv: "video/ogg",
698
+ mov: "video/quicktime",
699
+ avi: "video/x-msvideo",
700
+ zip: "application/zip",
701
+ rar: "application/vnd.rar",
702
+ tar: "application/x-tar",
703
+ gz: "application/gzip",
704
+ "7z": "application/x-7z-compressed",
705
+ pdf: "application/pdf",
706
+ doc: "application/msword",
707
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
708
+ xls: "application/vnd.ms-excel",
709
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
710
+ ppt: "application/vnd.ms-powerpoint",
711
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
712
+ exe: "application/vnd.microsoft.portable-executable",
713
+ apk: "application/vnd.android.package-archive"
714
+ };
718
715
 
719
716
  //#endregion
720
717
  //#region src/router/index.tsx
@@ -738,13 +735,10 @@ const createRouter = (options) => {
738
735
  }
739
736
  const registerRouterContext = async (scope) => {
740
737
  const fetch$1 = async () => {
741
- const { event } = useRuntime(scope);
742
- url.value = new URL(event?.request.url ?? window?.location.href);
738
+ const { request } = useRuntime(scope);
739
+ url.value = new URL(request?.url ?? window?.location.href);
743
740
  const match = radix.match(url.value.pathname);
744
- scope.setContext(RUNTIME_CONTEXT, {
745
- event,
746
- inputs: match.inputs
747
- });
741
+ scope.setContext(ROUTE_CONTEXT, { inputs: createState(match.inputs) });
748
742
  const Page$1 = await match.value?.();
749
743
  if (Page$1) route.value = /* @__PURE__ */ h(Page$1, null);
750
744
  };
@@ -787,7 +781,7 @@ const useRouter = (scope, context) => {
787
781
  const Page = defineComponent({
788
782
  name: "x-page",
789
783
  setup: ({ scope }) => {
790
- const { route } = scope.getContext(ROUTER_CONTEXT);
784
+ const { route } = useRouter(scope);
791
785
  return () => route.value;
792
786
  }
793
787
  });
@@ -799,11 +793,11 @@ const createLocale = (options) => {
799
793
  const locale = createState(options.defaultLocale);
800
794
  const messages = createState();
801
795
  const registerLocaleContext = async (scope) => {
802
- const { inputs } = useRuntime(scope);
796
+ const { inputs } = useRoute(scope);
803
797
  const { navigator } = useRouter(scope);
804
798
  const fetch$1 = async () => {
805
799
  if (options.input) {
806
- const input = inputs[options.input];
800
+ const input = inputs.value[options.input];
807
801
  if (input && input in options.locales) locale.value = input;
808
802
  }
809
803
  if (locale.value) {
@@ -934,4 +928,4 @@ const markdownToSlot = (input, options) => {
934
928
  };
935
929
 
936
930
  //#endregion
937
- export { $fetch, CLIENT, Compute, Event$1 as Event, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, Scope, StopEvent, VARIABLE_CONTEXT, activeCompute, components, createApp, createCompute, createElement, createLocale, createMemo, createRouter, createRuntime, createState, defineComponent, defineContext, defineRoute, fileName, fromValue, getCookies, getCustomElement, getMimeType, getRequestUrl, getSetCookies, hydrate, isClient, isServer, isTemplate, markdownToSlot, preventDefault, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, useEvent, useHost, useLocale, useRouter, useRuntime, useVariables };
931
+ export { $fetch, CLIENT, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, Scope, StopEvent, activeCompute, components, createApp, createCompute, createElement, createLocale, createMemo, createRouter, createRuntime, createState, defineComponent, defineContext, defineRoute, fileName, fromValue, hydrate, isClient, isServer, isTemplate, markdownToSlot, mimeType, preventDefault, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, useCookies, useEvent, useHost, useLocale, useRequestUrl, useRoute, useRouter, useRuntime, useSetCookies };
@@ -1,15 +1,19 @@
1
- import { Event, VARIABLE_CONTEXT } from "./runtime-7PuIOxLz.js";
1
+ import { RUNTIME_CONTEXT, Scope } from "./runtime-CnZe26-A.js";
2
2
  import { runtime } from "#virtual/runtime";
3
3
  import { serve } from "bun";
4
4
 
5
5
  //#region src/presets/bun.ts
6
6
  serve({ fetch: (request) => {
7
- const event = new Event(request);
8
- event.setContext(VARIABLE_CONTEXT, process.env);
7
+ const scope = new Scope();
8
+ scope.setContext(RUNTIME_CONTEXT, {
9
+ request,
10
+ response: { headers: new Headers() },
11
+ variables: process.env
12
+ });
9
13
  try {
10
- return runtime.fetch(event);
14
+ return runtime.fetch(scope);
11
15
  } finally {
12
- event.stop();
16
+ scope.stop();
13
17
  }
14
18
  } });
15
19
 
@@ -1,14 +1,18 @@
1
- import { Event, VARIABLE_CONTEXT } from "./runtime-7PuIOxLz.js";
1
+ import { RUNTIME_CONTEXT, Scope } from "./runtime-CnZe26-A.js";
2
2
  import { runtime } from "#virtual/runtime";
3
3
 
4
4
  //#region src/presets/cloudflare.ts
5
5
  var cloudflare_default = { fetch: (request, variables) => {
6
- const event = new Event(request);
7
- event.setContext(VARIABLE_CONTEXT, variables);
6
+ const scope = new Scope();
7
+ scope.setContext(RUNTIME_CONTEXT, {
8
+ request,
9
+ response: { headers: new Headers() },
10
+ variables
11
+ });
8
12
  try {
9
- return runtime.fetch(event);
13
+ return runtime.fetch(scope);
10
14
  } finally {
11
- event.stop();
15
+ scope.stop();
12
16
  }
13
17
  } };
14
18
 
@@ -36,18 +36,6 @@ function defineContext(key) {
36
36
  return key;
37
37
  }
38
38
 
39
- //#endregion
40
- //#region src/http/index.ts
41
- var Event$1 = class extends Scope {
42
- request;
43
- response;
44
- constructor(request) {
45
- super();
46
- this.request = request;
47
- this.response = { headers: new Headers() };
48
- }
49
- };
50
-
51
39
  //#endregion
52
40
  //#region src/html/index.ts
53
41
  const HOST_CONTEXT = defineContext("HOST_CONTEXT");
@@ -55,7 +43,7 @@ const HOST_CONTEXT = defineContext("HOST_CONTEXT");
55
43
  //#endregion
56
44
  //#region src/runtime/index.ts
57
45
  const RUNTIME_CONTEXT = defineContext("RUNTIME_CONTEXT");
58
- const VARIABLE_CONTEXT = defineContext("VARIABLE_CONTEXT");
46
+ const ROUTE_CONTEXT = defineContext("ROUTE_CONTEXT");
59
47
 
60
48
  //#endregion
61
- export { Event$1 as Event, VARIABLE_CONTEXT };
49
+ export { RUNTIME_CONTEXT, Scope };
@@ -1,24 +1,28 @@
1
- import { Event, type Handle, type Middleware } from "../http";
1
+ import { type Handle, type Middleware, type ResponseOptions } from "../http";
2
2
  import { Radix } from "../radix";
3
- import { Scope } from "../signals";
3
+ import { Scope, type State } from "../signals";
4
4
  export type Route = {
5
5
  fetch: Handle;
6
6
  };
7
7
  export type Runtime = {
8
8
  radix: Radix<Route>;
9
9
  middlewares: Array<Middleware>;
10
- fetch: (event: Event) => Promise<Response>;
10
+ fetch: (scope: Scope) => Promise<Response>;
11
11
  };
12
- export type RuntimeContext = {
13
- event?: Event;
14
- inputs: Record<string, string>;
12
+ export type RuntimeContext<T = Record<string, unknown>> = {
13
+ request: Request;
14
+ response: ResponseOptions;
15
+ variables: T;
15
16
  };
16
- export declare const useRuntime: (scope: Scope) => RuntimeContext;
17
- export declare const useVariables: <T>(scope: Scope) => T;
17
+ export type RouteContext = {
18
+ inputs: State<Record<string, string>>;
19
+ };
20
+ export declare const useRuntime: <T = Record<string, unknown>>(scope: Scope) => RuntimeContext<T>;
21
+ export declare const useRoute: (scope: Scope) => RouteContext;
18
22
  export declare const defineRoute: (route: Route) => Route;
19
23
  export declare const fileName: (path: string) => string | undefined;
20
24
  export declare const toPath: (value: string) => (string | undefined)[];
21
25
  export declare const $fetch: <T>(scope: Scope, input: string | URL, options?: RequestInit) => Promise<T>;
22
26
  export declare const createRuntime: () => Promise<Runtime>;
23
- export declare const RUNTIME_CONTEXT: import("..").Descriptor<RuntimeContext>;
24
- export declare const VARIABLE_CONTEXT: import("..").Descriptor<Record<string, unknown>>;
27
+ export declare const RUNTIME_CONTEXT: import("..").Descriptor<RuntimeContext<Record<string, unknown>>>;
28
+ export declare const ROUTE_CONTEXT: import("..").Descriptor<RouteContext>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.0.47",
3
+ "version": "0.0.49",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",