revojs 0.0.47 → 0.0.48

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.
@@ -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;
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 getRequestUrl: (scope: Scope, base?: string) => URL;
30
+ export declare const getCookies: (scope: Scope) => Record<string, string>;
31
+ export declare const getSetCookies: (scope: Scope) => Record<string, string>;
32
+ export declare const setCookie: (scope: Scope, name: string, value: string, options?: CookieOptions) => void;
38
33
  export declare const getMimeType: (file: string) => MimeType;
package/dist/index.js CHANGED
@@ -476,123 +476,6 @@ const stopImmediatePropagation = (event) => event.stopImmediatePropagation();
476
476
  const components = new Map();
477
477
  const HOST_CONTEXT = defineContext("HOST_CONTEXT");
478
478
 
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
479
  //#endregion
597
480
  //#region src/radix/index.ts
598
481
  var Radix = class Radix {
@@ -638,8 +521,8 @@ var Radix = class Radix {
638
521
  const useRuntime = (scope) => {
639
522
  return scope.getContext(RUNTIME_CONTEXT);
640
523
  };
641
- const useVariables = (scope) => {
642
- return scope.getContext(VARIABLE_CONTEXT);
524
+ const useRoute = (scope) => {
525
+ return scope.getContext(ROUTE_CONTEXT);
643
526
  };
644
527
  const defineRoute = (route) => {
645
528
  return route;
@@ -654,18 +537,23 @@ const toPath = (value) => {
654
537
  return split.length === 3 ? [split.at(0), split.at(1)] : [split.at(0)];
655
538
  };
656
539
  const $fetch = async (scope, input, options) => {
657
- const { event } = useRuntime(scope);
540
+ const { request, variables } = useRuntime(scope);
658
541
  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);
542
+ if (request) {
543
+ const next = new Scope();
544
+ const url = new URL(input.toString(), request.url);
545
+ next.setContext(RUNTIME_CONTEXT, {
546
+ request: new Request(url, options),
547
+ response: { headers: new Headers() },
548
+ variables
549
+ });
550
+ const previous = new URL(request.url);
664
551
  if (url.origin === previous.origin) response = await (await import("#virtual/runtime")).runtime.fetch(next);
665
552
  }
666
553
  response ??= await fetch(input, options);
667
554
  if (response.ok === false) throw response;
668
- switch (response.headers.get("Content-Type")) {
555
+ const contentType = response.headers.get("Content-Type")?.split(";").shift() ?? "";
556
+ switch (contentType) {
669
557
  case "application/json": return response.json();
670
558
  default: return response;
671
559
  }
@@ -683,29 +571,28 @@ const createRuntime = async () => {
683
571
  } }));
684
572
  }
685
573
  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);
574
+ for (const path in assets) radix.insert("GET/" + path, defineRoute({ fetch: async (scope) => {
575
+ const { response } = useRuntime(scope);
576
+ response.headers.set("Content-Type", getMimeType(path));
577
+ return new Response(await assets[path]?.(), response);
689
578
  } }));
690
- const invoke = (event, next, index) => {
691
- return middlewares.at(index)?.(event, () => invoke(event, next, index + 1)) ?? next(event);
579
+ const invoke = (scope, next, index) => {
580
+ return middlewares.at(index)?.(scope, () => invoke(scope, next, index + 1)) ?? next(scope);
692
581
  };
693
582
  return {
694
583
  radix,
695
584
  middlewares,
696
- fetch: async (event) => {
697
- const url = getRequestUrl(event);
698
- const { value: route, inputs } = radix.match(event.request.method + url.pathname);
585
+ fetch: async (scope) => {
586
+ const { request } = useRuntime(scope);
587
+ const url = getRequestUrl(scope);
588
+ const { value: route, inputs } = radix.match(request.method + url.pathname);
699
589
  try {
700
- event.setContext(RUNTIME_CONTEXT, {
701
- event,
702
- inputs
703
- });
590
+ scope.setContext(ROUTE_CONTEXT, { inputs: createState(inputs) });
704
591
  if (route) {
705
- const response = await invoke(event, route.fetch, 0);
592
+ const response = await invoke(scope, route.fetch, 0);
706
593
  if (response) return response;
707
594
  }
708
- return sendText(event, "NOT_FOUND");
595
+ return sendText(scope, "NOT_FOUND");
709
596
  } catch (exception) {
710
597
  if (exception instanceof Response) return exception;
711
598
  throw exception;
@@ -714,7 +601,123 @@ const createRuntime = async () => {
714
601
  };
715
602
  };
716
603
  const RUNTIME_CONTEXT = defineContext("RUNTIME_CONTEXT");
717
- const VARIABLE_CONTEXT = defineContext("VARIABLE_CONTEXT");
604
+ const ROUTE_CONTEXT = defineContext("ROUTE_CONTEXT");
605
+
606
+ //#endregion
607
+ //#region src/http/index.ts
608
+ const sendText = (scope, text) => {
609
+ const { response } = useRuntime(scope);
610
+ response.headers.set("Content-Type", "text/plain");
611
+ return new Response(text, response);
612
+ };
613
+ const sendHtml = (scope, text) => {
614
+ const { response } = useRuntime(scope);
615
+ response.headers.set("Content-Type", "text/html");
616
+ return new Response(text, response);
617
+ };
618
+ const sendJson = (scope, value) => {
619
+ const { response } = useRuntime(scope);
620
+ response.headers.set("Content-Type", "application/json");
621
+ return new Response(JSON.stringify(value), response);
622
+ };
623
+ const sendRedirect = (scope, path) => {
624
+ const { response } = useRuntime(scope);
625
+ response.status = 302;
626
+ response.headers.set("Location", path);
627
+ return new Response(null, response);
628
+ };
629
+ const sendBadRequest = (scope, text) => {
630
+ const { response } = useRuntime(scope);
631
+ response.status = 400;
632
+ return new Response(text, response);
633
+ };
634
+ const sendUnauthorized = (scope) => {
635
+ const { response } = useRuntime(scope);
636
+ response.status = 401;
637
+ return new Response(null, response);
638
+ };
639
+ const getRequestUrl = (scope, base) => {
640
+ const { request } = useRuntime(scope);
641
+ return new URL(request.url, base);
642
+ };
643
+ const getCookies = (scope) => {
644
+ const { request } = useRuntime(scope);
645
+ return (request.headers.get("Cookie")?.split("; ") ?? []).reduce((result, cookie) => {
646
+ const [name, value] = cookie.split("=");
647
+ if (name && value) result[name] = decodeURIComponent(value);
648
+ return result;
649
+ }, {});
650
+ };
651
+ const getSetCookies = (scope) => {
652
+ const { request } = useRuntime(scope);
653
+ return request.headers.getSetCookie().reduce((result, cookie) => {
654
+ const [name, value] = cookie.split("=");
655
+ if (name && value) result[name] = decodeURIComponent(value);
656
+ return result;
657
+ }, {});
658
+ };
659
+ const setCookie = (scope, name, value, options) => {
660
+ const { response } = useRuntime(scope);
661
+ let cookie = name + "=" + encodeURIComponent(value);
662
+ if (options?.domain) cookie += `; Domain=${options.domain}`;
663
+ if (options?.expires) cookie += `; Expires=${options.expires.toUTCString()}`;
664
+ if (options?.httpOnly) cookie += `; HttpOnly`;
665
+ if (options?.maxAge) cookie += `; Max-Age=${options.maxAge}`;
666
+ if (options?.path) cookie += `; Path=${options.path}`;
667
+ if (options?.priority) cookie += `; Priority=${options.priority}`;
668
+ if (options?.sameSite) cookie += `; SameSite=${options.sameSite}`;
669
+ if (options?.secure) cookie += `; Secure`;
670
+ response.headers.append("Set-Cookie", cookie);
671
+ };
672
+ const getMimeType = (file) => {
673
+ const extension = /\.([a-zA-Z0-9]+?)$/.exec(file)?.at(1);
674
+ return mimeTypes[extension ?? ""] ?? "text/plain";
675
+ };
676
+ const mimeTypes = {
677
+ txt: "text/plain",
678
+ css: "text/css",
679
+ html: "text/html",
680
+ htm: "text/html",
681
+ js: "text/javascript",
682
+ json: "application/json",
683
+ xml: "application/xml",
684
+ csv: "text/csv",
685
+ jpg: "image/jpeg",
686
+ jpeg: "image/jpeg",
687
+ png: "image/png",
688
+ gif: "image/gif",
689
+ webp: "image/webp",
690
+ svg: "image/svg+xml",
691
+ bmp: "image/bmp",
692
+ ico: "image/x-icon",
693
+ ttf: "font/ttf",
694
+ otf: "font/otf",
695
+ woff: "font/woff",
696
+ woff2: "font/woff2",
697
+ mp3: "audio/mpeg",
698
+ wav: "audio/wav",
699
+ ogg: "audio/ogg",
700
+ m4a: "audio/mp4",
701
+ mp4: "video/mp4",
702
+ webm: "video/webm",
703
+ ogv: "video/ogg",
704
+ mov: "video/quicktime",
705
+ avi: "video/x-msvideo",
706
+ zip: "application/zip",
707
+ rar: "application/vnd.rar",
708
+ tar: "application/x-tar",
709
+ gz: "application/gzip",
710
+ "7z": "application/x-7z-compressed",
711
+ pdf: "application/pdf",
712
+ doc: "application/msword",
713
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
714
+ xls: "application/vnd.ms-excel",
715
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
716
+ ppt: "application/vnd.ms-powerpoint",
717
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
718
+ exe: "application/vnd.microsoft.portable-executable",
719
+ apk: "application/vnd.android.package-archive"
720
+ };
718
721
 
719
722
  //#endregion
720
723
  //#region src/router/index.tsx
@@ -738,13 +741,10 @@ const createRouter = (options) => {
738
741
  }
739
742
  const registerRouterContext = async (scope) => {
740
743
  const fetch$1 = async () => {
741
- const { event } = useRuntime(scope);
742
- url.value = new URL(event?.request.url ?? window?.location.href);
744
+ const { request } = useRuntime(scope);
745
+ url.value = new URL(request?.url ?? window?.location.href);
743
746
  const match = radix.match(url.value.pathname);
744
- scope.setContext(RUNTIME_CONTEXT, {
745
- event,
746
- inputs: match.inputs
747
- });
747
+ scope.setContext(ROUTE_CONTEXT, { inputs: createState(match.inputs) });
748
748
  const Page$1 = await match.value?.();
749
749
  if (Page$1) route.value = /* @__PURE__ */ h(Page$1, null);
750
750
  };
@@ -799,11 +799,11 @@ const createLocale = (options) => {
799
799
  const locale = createState(options.defaultLocale);
800
800
  const messages = createState();
801
801
  const registerLocaleContext = async (scope) => {
802
- const { inputs } = useRuntime(scope);
802
+ const { inputs } = useRoute(scope);
803
803
  const { navigator } = useRouter(scope);
804
804
  const fetch$1 = async () => {
805
805
  if (options.input) {
806
- const input = inputs[options.input];
806
+ const input = inputs.value[options.input];
807
807
  if (input && input in options.locales) locale.value = input;
808
808
  }
809
809
  if (locale.value) {
@@ -934,4 +934,4 @@ const markdownToSlot = (input, options) => {
934
934
  };
935
935
 
936
936
  //#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 };
937
+ 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, 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, useRoute, useRouter, useRuntime };
@@ -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: (scope: Scope) => RuntimeContext<Record<string, unknown>>;
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.48",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",