revojs 0.1.53 → 0.1.55

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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as version, t as name } from "../package-D8FgpUMW.mjs";
2
+ import { n as version, t as name } from "../package-BcN3Ewsh.mjs";
3
3
  import { resolvePaths } from "../kit/index.mjs";
4
4
  import { defineCommand, runMain } from "citty";
5
5
  import { copyFileSync, mkdirSync } from "fs";
@@ -1,45 +1,18 @@
1
1
  import { UserConfig } from "vite";
2
2
 
3
3
  //#region src/router/index.d.ts
4
- type Node<T> = PathNode<T> | WildcardNode<T> | OptionalWildcardNode<T> | ParameterNode<T> | OptionalParameterNode<T> | GroupNode<T> | HookNode<T>;
5
- interface PathNode<T> {
6
- type: "PATH";
7
- value?: T;
8
- children: Record<string, Node<T>>;
9
- }
10
- interface WildcardNode<T> {
11
- type: "WILDCARD";
12
- value?: T;
13
- parameter: string;
14
- children: Record<string, Node<T>>;
15
- }
16
- interface OptionalWildcardNode<T> {
17
- type: "OPTIONAL-WILDCARD";
18
- value?: T;
19
- parameter: string;
20
- children: Record<string, Node<T>>;
21
- }
22
- interface ParameterNode<T> {
23
- type: "PARAMETER";
24
- value?: T;
25
- parameter: string;
26
- children: Record<string, Node<T>>;
27
- }
28
- interface OptionalParameterNode<T> {
29
- type: "OPTIONAL-PARAMETER";
4
+ type NodeType = "PATH" | "PARAMETER" | "OPTIONAL-PARAMETER" | "WILDCARD" | "OPTIONAL-WILDCARD" | "GROUP";
5
+ interface Node<T> {
6
+ type: NodeType;
7
+ name: string;
30
8
  value?: T;
31
- parameter: string;
32
- children: Record<string, Node<T>>;
33
- }
34
- interface GroupNode<T> {
35
- type: "GROUP";
36
- label: string;
37
- children: Record<string, Node<T>>;
38
- }
39
- interface HookNode<T> {
40
- type: "HOOK";
41
- value?: Array<T>;
42
- children: Record<string, Node<T>>;
9
+ hooks: Array<T>;
10
+ parameter?: Node<T>;
11
+ optionalParameter?: Node<T>;
12
+ wildcard?: Node<T>;
13
+ optionalWildcard?: Node<T>;
14
+ groups: Map<string, Node<T>>;
15
+ children: Map<string, Node<T>>;
43
16
  }
44
17
  interface RouterContext<T> {
45
18
  route?: T;
@@ -54,12 +27,6 @@ declare class Router<T> {
54
27
  use(segments: Array<string>, value: T): Node<T>;
55
28
  match(segments: Array<string>): RouterContext<T>;
56
29
  }
57
- declare const WILDCARD = "@";
58
- declare const OPTIONAL_WILDCARD = "@@";
59
- declare const PARAMETER = "@@@";
60
- declare const OPTIONAL_PARAMETER = "@@@@";
61
- declare const GROUP = "@@@@@";
62
- declare const HOOK = "@@@@@@";
63
30
  declare const WILDCARD_MATCH: RegExp;
64
31
  declare const OPTIONAL_WILDCARD_MATCH: RegExp;
65
32
  declare const PARAMETER_MATCH: RegExp;
@@ -259,4 +226,4 @@ declare function createStaticMiddleware(resolve: (path: string | URL) => Awaitab
259
226
  fetch(scope: Scope, next: (() => Result) | undefined): Promise<void | Response>;
260
227
  };
261
228
  //#endregion
262
- export { sendUnauthorized as $, WILDCARD as $t, StatusCode as A, Scope as At, isClient as B, Node as Bt, Result as C, Awaitable as Ct, STATES as D, Invoke as Dt, SERVER_ROUTER_CONTEXT as E, Hookable as Et, defineRoute as F, GROUP_MATCH as Ft, sendBadRequest as G, OptionalParameterNode as Gt, mimeType as H, OPTIONAL_PARAMETER_MATCH as Ht, encodings as I, GroupNode as It, sendNoContent as J, PARAMETER_MATCH as Jt, sendCreated as K, OptionalWildcardNode as Kt, getState as L, HOOK as Lt, cookieSameSites as M, defineHook as Mt, createServer as N, mergeObjects as Nt, Server as O, Mergeable as Ot, defineMiddleware as P, GROUP as Pt, sendResponse as Q, RouterContext as Qt, httpMethods as R, HOOK_MATCH as Rt, ResponseConfig as S, parseSchema as St, SERVER_CONTEXT as T, Descriptor as Tt, mimeTypes as U, OPTIONAL_WILDCARD as Ut, isServer as V, OPTIONAL_PARAMETER as Vt, parseCookiePair as W, OPTIONAL_WILDCARD_MATCH as Wt, sendOk as X, PathNode as Xt, sendNotFound as Y, ParameterNode as Yt, sendRedirect as Z, Router as Zt, CookieSameSite as _, Output as _t, CLIENT as a, useHeaders as at, Middleware as b, isFailure as bt, Content as c, useRouter as ct, Module as d, useUrl as dt, WILDCARD_MATCH as en, setCookie as et, SERVER as f, withQuery as ft, CookiePriority as g, Issue as gt, CookieOptions as h, InferOutput as ht, Asset as i, useCookies as it, cookiePriorities as j, defineContext as jt, ServerContext as k, Primitive as kt, DevelopmentConfig as l, useServer as lt, Template as m, InferInput as mt, fetch as n, statusCodes as nt, CLOSE_HOOK as o, useParameters as ot, Source as p, Failure as pt, sendForbidden as q, PARAMETER as qt, App as r, useBody as rt, Config as s, useQuery as st, createStaticMiddleware as t, WildcardNode as tn, setState as tt, Environment as u, useSetCookies as ut, Encoding as v, Schema as vt, Route as w, Context as wt, MimeType as x, isSuccess as xt, HttpMethod as y, Success as yt, invoke as z, HookNode as zt };
229
+ export { sendUnauthorized as $, StatusCode as A, Scope as At, isClient as B, PARAMETER_MATCH as Bt, Result as C, Awaitable as Ct, STATES as D, Invoke as Dt, SERVER_ROUTER_CONTEXT as E, Hookable as Et, defineRoute as F, HOOK_MATCH as Ft, sendBadRequest as G, mimeType as H, RouterContext as Ht, encodings as I, Node as It, sendNoContent as J, sendCreated as K, getState as L, NodeType as Lt, cookieSameSites as M, defineHook as Mt, createServer as N, mergeObjects as Nt, Server as O, Mergeable as Ot, defineMiddleware as P, GROUP_MATCH as Pt, sendResponse as Q, httpMethods as R, OPTIONAL_PARAMETER_MATCH as Rt, ResponseConfig as S, parseSchema as St, SERVER_CONTEXT as T, Descriptor as Tt, mimeTypes as U, WILDCARD_MATCH as Ut, isServer as V, Router as Vt, parseCookiePair as W, sendOk as X, sendNotFound as Y, sendRedirect as Z, CookieSameSite as _, Output as _t, CLIENT as a, useHeaders as at, Middleware as b, isFailure as bt, Content as c, useRouter as ct, Module as d, useUrl as dt, setCookie as et, SERVER as f, withQuery as ft, CookiePriority as g, Issue as gt, CookieOptions as h, InferOutput as ht, Asset as i, useCookies as it, cookiePriorities as j, defineContext as jt, ServerContext as k, Primitive as kt, DevelopmentConfig as l, useServer as lt, Template as m, InferInput as mt, fetch as n, statusCodes as nt, CLOSE_HOOK as o, useParameters as ot, Source as p, Failure as pt, sendForbidden as q, App as r, useBody as rt, Config as s, useQuery as st, createStaticMiddleware as t, setState as tt, Environment as u, useSetCookies as ut, Encoding as v, Schema as vt, Route as w, Context as wt, MimeType as x, isSuccess as xt, HttpMethod as y, Success as yt, invoke as z, OPTIONAL_WILDCARD_MATCH as zt };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as sendUnauthorized, $t as WILDCARD, A as StatusCode, At as Scope, B as isClient, Bt as Node, C as Result, Ct as Awaitable, D as STATES, Dt as Invoke, E as SERVER_ROUTER_CONTEXT, Et as Hookable, F as defineRoute, Ft as GROUP_MATCH, G as sendBadRequest, Gt as OptionalParameterNode, H as mimeType, Ht as OPTIONAL_PARAMETER_MATCH, I as encodings, It as GroupNode, J as sendNoContent, Jt as PARAMETER_MATCH, K as sendCreated, Kt as OptionalWildcardNode, L as getState, Lt as HOOK, M as cookieSameSites, Mt as defineHook, N as createServer, Nt as mergeObjects, O as Server, Ot as Mergeable, P as defineMiddleware, Pt as GROUP, Q as sendResponse, Qt as RouterContext, R as httpMethods, Rt as HOOK_MATCH, S as ResponseConfig, St as parseSchema, T as SERVER_CONTEXT, Tt as Descriptor, U as mimeTypes, Ut as OPTIONAL_WILDCARD, V as isServer, Vt as OPTIONAL_PARAMETER, W as parseCookiePair, Wt as OPTIONAL_WILDCARD_MATCH, X as sendOk, Xt as PathNode, Y as sendNotFound, Yt as ParameterNode, Z as sendRedirect, Zt as Router, _ as CookieSameSite, _t as Output, a as CLIENT, at as useHeaders, b as Middleware, bt as isFailure, c as Content, ct as useRouter, d as Module, dt as useUrl, en as WILDCARD_MATCH, et as setCookie, f as SERVER, ft as withQuery, g as CookiePriority, gt as Issue, h as CookieOptions, ht as InferOutput, i as Asset, it as useCookies, j as cookiePriorities, jt as defineContext, k as ServerContext, kt as Primitive, l as DevelopmentConfig, lt as useServer, m as Template, mt as InferInput, n as fetch, nt as statusCodes, o as CLOSE_HOOK, ot as useParameters, p as Source, pt as Failure, q as sendForbidden, qt as PARAMETER, r as App, rt as useBody, s as Config, st as useQuery, t as createStaticMiddleware, tn as WildcardNode, tt as setState, u as Environment, ut as useSetCookies, v as Encoding, vt as Schema, w as Route, wt as Context, x as MimeType, xt as isSuccess, y as HttpMethod, yt as Success, z as invoke, zt as HookNode } from "./index-B4nGVcLE.mjs";
2
- export { App, Asset, Awaitable, CLIENT, CLOSE_HOOK, Config, Content, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, GROUP, GROUP_MATCH, GroupNode, HOOK, HOOK_MATCH, HookNode, 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, Primitive, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, SERVER_ROUTER_CONTEXT, STATES, Schema, Scope, Server, ServerContext, Source, StatusCode, Success, Template, WILDCARD, WILDCARD_MATCH, WildcardNode, cookiePriorities, cookieSameSites, createServer, createStaticMiddleware, defineContext, defineHook, defineMiddleware, defineRoute, encodings, fetch, getState, httpMethods, invoke, isClient, isFailure, isServer, isSuccess, 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
+ import { $ as sendUnauthorized, A as StatusCode, At as Scope, B as isClient, Bt as PARAMETER_MATCH, C as Result, Ct as Awaitable, D as STATES, Dt as Invoke, E as SERVER_ROUTER_CONTEXT, Et as Hookable, F as defineRoute, Ft as HOOK_MATCH, G as sendBadRequest, H as mimeType, Ht as RouterContext, I as encodings, It as Node, J as sendNoContent, K as sendCreated, L as getState, Lt as NodeType, M as cookieSameSites, Mt as defineHook, N as createServer, Nt as mergeObjects, O as Server, Ot as Mergeable, P as defineMiddleware, Pt as GROUP_MATCH, Q as sendResponse, R as httpMethods, Rt as OPTIONAL_PARAMETER_MATCH, S as ResponseConfig, St as parseSchema, T as SERVER_CONTEXT, Tt as Descriptor, U as mimeTypes, Ut as WILDCARD_MATCH, V as isServer, Vt as Router, W as parseCookiePair, X as sendOk, Y as sendNotFound, Z as sendRedirect, _ as CookieSameSite, _t as Output, a as CLIENT, at as useHeaders, b as Middleware, bt as isFailure, c as Content, ct as useRouter, d as Module, dt as useUrl, et as setCookie, f as SERVER, ft as withQuery, g as CookiePriority, gt as Issue, h as CookieOptions, ht as InferOutput, i as Asset, it as useCookies, j as cookiePriorities, jt as defineContext, k as ServerContext, kt as Primitive, l as DevelopmentConfig, lt as useServer, m as Template, mt as InferInput, n as fetch, nt as statusCodes, o as CLOSE_HOOK, ot as useParameters, p as Source, pt as Failure, q as sendForbidden, r as App, rt as useBody, s as Config, st as useQuery, t as createStaticMiddleware, tt as setState, u as Environment, ut as useSetCookies, v as Encoding, vt as Schema, w as Route, wt as Context, x as MimeType, xt as isSuccess, y as HttpMethod, yt as Success, z as invoke, zt as OPTIONAL_WILDCARD_MATCH } from "./index-DOmfkUsW.mjs";
2
+ export { App, Asset, Awaitable, CLIENT, CLOSE_HOOK, Config, Content, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, GROUP_MATCH, HOOK_MATCH, Hookable, HttpMethod, InferInput, InferOutput, Invoke, Issue, Mergeable, Middleware, MimeType, Module, Node, NodeType, OPTIONAL_PARAMETER_MATCH, OPTIONAL_WILDCARD_MATCH, Output, PARAMETER_MATCH, Primitive, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, SERVER_ROUTER_CONTEXT, STATES, Schema, Scope, Server, ServerContext, Source, StatusCode, Success, Template, WILDCARD_MATCH, cookiePriorities, cookieSameSites, createServer, createStaticMiddleware, defineContext, defineHook, defineMiddleware, defineRoute, encodings, fetch, getState, httpMethods, invoke, isClient, isFailure, isServer, isSuccess, 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 Router, A as useBody, B as isFailure, C as sendOk, D as setCookie, E as sendUnauthorized, F as useRouter, G as HOOK, H as parseSchema, I as useServer, J as OPTIONAL_PARAMETER_MATCH, K as HOOK_MATCH, L as useSetCookies, M as useHeaders, N as useParameters, O as setState, P as useQuery, Q as PARAMETER_MATCH, R as useUrl, S as sendNotFound, T as sendResponse, U as GROUP, V as isSuccess, W as GROUP_MATCH, X as OPTIONAL_WILDCARD_MATCH, Y as OPTIONAL_WILDCARD, Z as PARAMETER, _ as parseCookiePair, a as cookieSameSites, at as SERVER, b as sendForbidden, c as defineRoute, ct as defineContext, d as httpMethods, et as WILDCARD, f as invoke, g as mimeTypes, h as mimeType, i as cookiePriorities, it as CLOSE_HOOK, j as useCookies, k as statusCodes, l as encodings, lt as defineHook, m as isServer, n as SERVER_ROUTER_CONTEXT, nt as App, o as createServer, ot as Hookable, p as isClient, q as OPTIONAL_PARAMETER, r as STATES, rt as CLIENT, s as defineMiddleware, st as Scope, t as SERVER_CONTEXT, tt as WILDCARD_MATCH, u as getState, ut as mergeObjects, v as sendBadRequest, w as sendRedirect, x as sendNoContent, y as sendCreated, z as withQuery } from "./server-BKOK-LN2.mjs";
1
+ import { $ as SERVER, A as useBody, B as isFailure, C as sendOk, D as setCookie, E as sendUnauthorized, F as useRouter, G as OPTIONAL_PARAMETER_MATCH, H as parseSchema, I as useServer, J as Router, K as OPTIONAL_WILDCARD_MATCH, L as useSetCookies, M as useHeaders, N as useParameters, O as setState, P as useQuery, Q as CLOSE_HOOK, R as useUrl, S as sendNotFound, T as sendResponse, U as GROUP_MATCH, V as isSuccess, W as HOOK_MATCH, X as App, Y as WILDCARD_MATCH, Z as CLIENT, _ as parseCookiePair, a as cookieSameSites, b as sendForbidden, c as defineRoute, d as httpMethods, et as Hookable, f as invoke, g as mimeTypes, h as mimeType, i as cookiePriorities, it as mergeObjects, j as useCookies, k as statusCodes, l as encodings, m as isServer, n as SERVER_ROUTER_CONTEXT, nt as defineContext, o as createServer, p as isClient, q as PARAMETER_MATCH, r as STATES, rt as defineHook, s as defineMiddleware, t as SERVER_CONTEXT, tt as Scope, u as getState, v as sendBadRequest, w as sendRedirect, x as sendNoContent, y as sendCreated, z as withQuery } from "./server-BplNURRd.mjs";
2
2
  import assets from "#assets";
3
3
  //#region src/client/index.ts
4
4
  async function fetch(scope, input, options) {
@@ -52,4 +52,4 @@ function createStaticMiddleware(resolve) {
52
52
  } });
53
53
  }
54
54
  //#endregion
55
- export { App, CLIENT, CLOSE_HOOK, GROUP, GROUP_MATCH, HOOK, HOOK_MATCH, Hookable, OPTIONAL_PARAMETER, OPTIONAL_PARAMETER_MATCH, OPTIONAL_WILDCARD, OPTIONAL_WILDCARD_MATCH, PARAMETER, PARAMETER_MATCH, Router, SERVER, SERVER_CONTEXT, SERVER_ROUTER_CONTEXT, STATES, Scope, WILDCARD, WILDCARD_MATCH, cookiePriorities, cookieSameSites, createServer, createStaticMiddleware, defineContext, defineHook, defineMiddleware, defineRoute, encodings, fetch, getState, httpMethods, invoke, isClient, isFailure, isServer, isSuccess, 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 };
55
+ export { App, CLIENT, CLOSE_HOOK, GROUP_MATCH, HOOK_MATCH, Hookable, OPTIONAL_PARAMETER_MATCH, OPTIONAL_WILDCARD_MATCH, PARAMETER_MATCH, Router, SERVER, SERVER_CONTEXT, SERVER_ROUTER_CONTEXT, STATES, Scope, WILDCARD_MATCH, cookiePriorities, cookieSameSites, createServer, createStaticMiddleware, defineContext, defineHook, defineMiddleware, defineRoute, encodings, fetch, getState, httpMethods, invoke, isClient, isFailure, isServer, isSuccess, 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 { c as Content, r as App } from "../index-B4nGVcLE.mjs";
1
+ import { c as Content, r as App } from "../index-DOmfkUsW.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.53";
3
+ var version = "0.1.55";
4
4
  //#endregion
5
5
  export { version as n, name as t };
@@ -109,94 +109,97 @@ var Router = class {
109
109
  constructor(rootNode) {
110
110
  this.rootNode = rootNode ?? {
111
111
  type: "PATH",
112
- children: {}
112
+ name: "",
113
+ children: /* @__PURE__ */ new Map(),
114
+ groups: /* @__PURE__ */ new Map(),
115
+ hooks: []
113
116
  };
114
117
  }
115
118
  use(segments, value) {
116
119
  let node = this.rootNode;
117
- for (const next of segments) {
118
- const optionalWildcardMatch = (next.match(OPTIONAL_WILDCARD_MATCH) ?? []).at(1);
119
- if (typeof optionalWildcardMatch === "string") {
120
- let childNode = node.children["@@"];
121
- childNode ??= {
120
+ for (const segment of segments) {
121
+ const optionalWildcard = OPTIONAL_WILDCARD_MATCH.exec(segment)?.[1];
122
+ if (typeof optionalWildcard === "string") {
123
+ node.optionalWildcard ??= {
122
124
  type: "OPTIONAL-WILDCARD",
123
- parameter: optionalWildcardMatch,
124
- children: {}
125
+ name: optionalWildcard,
126
+ children: /* @__PURE__ */ new Map(),
127
+ groups: /* @__PURE__ */ new Map(),
128
+ hooks: []
125
129
  };
126
- node.children["@@"] ??= childNode;
127
- node = childNode;
130
+ node = node.optionalWildcard;
128
131
  continue;
129
132
  }
130
- const wildcardMatch = (next.match(WILDCARD_MATCH) ?? []).at(1);
131
- if (typeof wildcardMatch === "string") {
132
- let childNode = node.children["@"];
133
- childNode ??= {
133
+ const wildcard = WILDCARD_MATCH.exec(segment)?.[1];
134
+ if (typeof wildcard === "string") {
135
+ node.wildcard ??= {
134
136
  type: "WILDCARD",
135
- parameter: wildcardMatch,
136
- children: {}
137
+ name: wildcard,
138
+ children: /* @__PURE__ */ new Map(),
139
+ groups: /* @__PURE__ */ new Map(),
140
+ hooks: []
137
141
  };
138
- node.children["@"] ??= childNode;
139
- node = childNode;
142
+ node = node.wildcard;
140
143
  continue;
141
144
  }
142
- const optionalParameterMatch = (next.match(OPTIONAL_PARAMETER_MATCH) ?? []).at(1);
143
- if (typeof optionalParameterMatch === "string") {
144
- let childNode = node.children[OPTIONAL_PARAMETER];
145
- childNode ??= {
145
+ const optionalParameter = OPTIONAL_PARAMETER_MATCH.exec(segment)?.[1];
146
+ if (typeof optionalParameter === "string") {
147
+ node.optionalParameter ??= {
146
148
  type: "OPTIONAL-PARAMETER",
147
- parameter: optionalParameterMatch,
148
- children: {}
149
+ name: optionalParameter,
150
+ children: /* @__PURE__ */ new Map(),
151
+ groups: /* @__PURE__ */ new Map(),
152
+ hooks: []
149
153
  };
150
- node.children[OPTIONAL_PARAMETER] ??= childNode;
151
- node = childNode;
154
+ node = node.optionalParameter;
152
155
  continue;
153
156
  }
154
- const parameterMatch = (next.match(PARAMETER_MATCH) ?? []).at(1);
155
- if (typeof parameterMatch === "string") {
156
- let childNode = node.children["@@@"];
157
- childNode ??= {
157
+ const parameter = PARAMETER_MATCH.exec(segment)?.[1];
158
+ if (typeof parameter === "string") {
159
+ node.parameter ??= {
158
160
  type: "PARAMETER",
159
- parameter: parameterMatch,
160
- children: {}
161
+ name: parameter,
162
+ children: /* @__PURE__ */ new Map(),
163
+ groups: /* @__PURE__ */ new Map(),
164
+ hooks: []
161
165
  };
162
- node.children["@@@"] ??= childNode;
163
- node = childNode;
166
+ node = node.parameter;
164
167
  continue;
165
168
  }
166
- const groupMatch = (next.match(GROUP_MATCH) ?? []).at(1);
167
- if (groupMatch) {
168
- let childNode = node.children[GROUP];
169
- childNode ??= {
170
- type: "GROUP",
171
- label: groupMatch,
172
- children: {}
173
- };
174
- node.children[GROUP] ??= childNode;
175
- node = childNode;
169
+ const group = GROUP_MATCH.exec(segment)?.[1];
170
+ if (typeof group === "string") {
171
+ let child = node.groups.get(group);
172
+ if (!child) {
173
+ child = {
174
+ type: "GROUP",
175
+ name: group,
176
+ children: /* @__PURE__ */ new Map(),
177
+ groups: /* @__PURE__ */ new Map(),
178
+ hooks: []
179
+ };
180
+ node.groups.set(group, child);
181
+ }
182
+ node = child;
176
183
  continue;
177
184
  }
178
- if (next.match(HOOK_MATCH)?.[1]) {
179
- let childNode = node.children[HOOK];
180
- childNode ??= {
181
- type: "HOOK",
182
- children: {}
185
+ if (typeof HOOK_MATCH.exec(segment)?.[1] === "string") {
186
+ node.hooks.push(value);
187
+ return node;
188
+ }
189
+ let child = node.children.get(segment);
190
+ if (!child) {
191
+ child = {
192
+ type: "PATH",
193
+ name: segment,
194
+ children: /* @__PURE__ */ new Map(),
195
+ groups: /* @__PURE__ */ new Map(),
196
+ hooks: []
183
197
  };
184
- node.children[HOOK] ??= childNode;
185
- node = childNode;
186
- continue;
198
+ node.children.set(segment, child);
187
199
  }
188
- let childNode = node.children[next];
189
- childNode ??= {
190
- type: "PATH",
191
- children: {}
192
- };
193
- node.children[next] ??= childNode;
194
- node = childNode;
200
+ node = child;
195
201
  }
196
- if (node.type === "HOOK") {
197
- node.value ??= [];
198
- node.value.push(value);
199
- } else if (node.type === "PATH" || node.type === "PARAMETER" || node.type === "OPTIONAL-PARAMETER" || node.type === "WILDCARD" || node.type === "OPTIONAL-WILDCARD") node.value = value;
202
+ node.value = value;
200
203
  return node;
201
204
  }
202
205
  match(segments) {
@@ -206,67 +209,57 @@ var Router = class {
206
209
  groups: [],
207
210
  hooks: []
208
211
  };
209
- const invoke = (node, index) => {
210
- const hookNode = node.children[HOOK];
211
- if (hookNode?.value) context.hooks.push(...hookNode.value);
212
- if (index === context.segments.length) return node;
213
- const segment = context.segments[index];
214
- if (node.children[segment]) {
215
- const route = invoke(node.children[segment], index + 1);
216
- if (route) return route;
217
- }
218
- if (node.children["@@@@@"]) {
219
- const groupNode = node.children[GROUP];
220
- const route = invoke(groupNode, index);
221
- if (route) {
222
- context.groups.push(groupNode.label);
223
- return route;
224
- }
225
- }
226
- if (node.children["@@@@"]) {
227
- const optionalParameterNode = node.children[OPTIONAL_PARAMETER];
228
- const route = invoke(optionalParameterNode, index + 1);
229
- if (route) {
230
- context.parameters[optionalParameterNode.parameter] = segment;
231
- return route;
232
- }
233
- }
234
- if (node.children["@@@"]) {
235
- const parameterNode = node.children["@@@"];
236
- const route = invoke(parameterNode, index + 1);
237
- if (route) {
238
- context.parameters[parameterNode.parameter] = segment;
239
- return route;
240
- }
241
- }
242
- if (node.children["@@"]) {
243
- const optionalWildcardNode = node.children["@@"];
244
- const wildcardPath = context.segments.slice(index).join("/");
245
- context.parameters[optionalWildcardNode.parameter] = wildcardPath;
246
- return optionalWildcardNode ?? invoke(optionalWildcardNode, context.segments.length);
247
- }
248
- if (node.children["@"]) {
249
- const wildcardNode = node.children["@"];
250
- const wildcardPath = context.segments.slice(index).join("/");
251
- context.parameters[wildcardNode.parameter] = wildcardPath;
252
- return wildcardNode ?? invoke(wildcardNode, context.segments.length);
253
- }
254
- };
255
- const match = invoke(this.rootNode, 0);
256
- if (match?.type === "PATH" || match?.type === "PARAMETER" || match?.type === "OPTIONAL-PARAMETER" || match?.type === "WILDCARD" || match?.type === "OPTIONAL-WILDCARD") context.route = match.value;
212
+ visit(this.rootNode, 0, context);
257
213
  return context;
258
214
  }
259
215
  };
260
- const WILDCARD = "@";
261
- const OPTIONAL_WILDCARD = "@@";
262
- const PARAMETER = "@@@";
263
- const OPTIONAL_PARAMETER = "@@@@";
264
- const GROUP = "@@@@@";
265
- const HOOK = "@@@@@@";
266
- const WILDCARD_MATCH = /\[\.\.\.(.*?)\]/;
267
- const OPTIONAL_WILDCARD_MATCH = /\[\[\.\.\.(.*?)\]\]/;
268
- const PARAMETER_MATCH = /\[(.*?)\]/;
269
- const OPTIONAL_PARAMETER_MATCH = /\[\[(.*?)\]\]/;
216
+ function visit(node, index, context) {
217
+ const hookCount = context.hooks.length;
218
+ const groupCount = context.groups.length;
219
+ if (node.hooks.length > 0) context.hooks.push(...node.hooks);
220
+ if (node.type === "GROUP") context.groups.push(node.name);
221
+ if (match(node, index, context)) return true;
222
+ context.hooks.length = hookCount;
223
+ context.groups.length = groupCount;
224
+ return false;
225
+ }
226
+ function match(node, index, context) {
227
+ if (index === context.segments.length) {
228
+ if (node.value !== void 0) {
229
+ context.route = node.value;
230
+ return true;
231
+ }
232
+ for (const group of node.groups.values()) if (visit(group, index, context)) return true;
233
+ if (node.optionalParameter && visit(node.optionalParameter, index, context)) return true;
234
+ if (node.optionalWildcard && assign(node.optionalWildcard, "", index, context)) return true;
235
+ return false;
236
+ }
237
+ for (const group of node.groups.values()) if (visit(group, index, context)) return true;
238
+ const segment = context.segments[index] ?? "";
239
+ const child = node.children.get(segment);
240
+ if (child && visit(child, index + 1, context)) return true;
241
+ if (node.parameter && assign(node.parameter, segment, index + 1, context)) return true;
242
+ if (node.optionalParameter && assign(node.optionalParameter, segment, index + 1, context)) return true;
243
+ if (node.wildcard) {
244
+ const rest = context.segments.slice(index).join("/");
245
+ if (assign(node.wildcard, rest, context.segments.length, context)) return true;
246
+ }
247
+ if (node.optionalWildcard) {
248
+ const rest = context.segments.slice(index).join("/");
249
+ if (assign(node.optionalWildcard, rest, context.segments.length, context)) return true;
250
+ }
251
+ return false;
252
+ }
253
+ function assign(node, value, index, context) {
254
+ context.parameters[node.name] = value;
255
+ if (visit(node, index, context)) return true;
256
+ delete context.parameters[node.name];
257
+ return false;
258
+ }
259
+ const WILDCARD_MATCH = /^\[\.\.\.(.*)\]$/;
260
+ const OPTIONAL_WILDCARD_MATCH = /^\[\[\.\.\.(.*)\]\]$/;
261
+ const PARAMETER_MATCH = /^\[(.*)\]$/;
262
+ const OPTIONAL_PARAMETER_MATCH = /^\[\[(.*)\]\]$/;
270
263
  const GROUP_MATCH = /^\((.*)\)$/;
271
264
  const HOOK_MATCH = /^\+(.+)$/;
272
265
  //#endregion
@@ -659,4 +652,4 @@ const mimeTypes = {
659
652
  "apk": "application/vnd.android.package-archive"
660
653
  };
661
654
  //#endregion
662
- export { Router as $, useBody as A, isFailure as B, sendOk as C, setCookie as D, sendUnauthorized as E, useRouter as F, HOOK as G, parseSchema as H, useServer as I, OPTIONAL_PARAMETER_MATCH as J, HOOK_MATCH as K, useSetCookies as L, useHeaders as M, useParameters as N, setState as O, useQuery as P, PARAMETER_MATCH as Q, useUrl as R, sendNotFound as S, sendResponse as T, GROUP as U, isSuccess as V, GROUP_MATCH as W, OPTIONAL_WILDCARD_MATCH as X, OPTIONAL_WILDCARD as Y, PARAMETER as Z, parseCookiePair as _, cookieSameSites as a, SERVER as at, sendForbidden as b, defineRoute as c, defineContext as ct, httpMethods as d, WILDCARD as et, invoke as f, mimeTypes as g, mimeType as h, cookiePriorities as i, CLOSE_HOOK as it, useCookies as j, statusCodes as k, encodings as l, defineHook as lt, isServer as m, SERVER_ROUTER_CONTEXT as n, App as nt, createServer as o, Hookable as ot, isClient as p, OPTIONAL_PARAMETER as q, STATES as r, CLIENT as rt, defineMiddleware as s, Scope as st, SERVER_CONTEXT as t, WILDCARD_MATCH as tt, getState as u, mergeObjects as ut, sendBadRequest as v, sendRedirect as w, sendNoContent as x, sendCreated as y, withQuery as z };
655
+ export { SERVER as $, useBody as A, isFailure as B, sendOk as C, setCookie as D, sendUnauthorized as E, useRouter as F, OPTIONAL_PARAMETER_MATCH as G, parseSchema as H, useServer as I, Router as J, OPTIONAL_WILDCARD_MATCH as K, useSetCookies as L, useHeaders as M, useParameters as N, setState as O, useQuery as P, CLOSE_HOOK as Q, useUrl as R, sendNotFound as S, sendResponse as T, GROUP_MATCH as U, isSuccess as V, HOOK_MATCH as W, App as X, WILDCARD_MATCH as Y, CLIENT as Z, parseCookiePair as _, cookieSameSites as a, sendForbidden as b, defineRoute as c, httpMethods as d, Hookable as et, invoke as f, mimeTypes as g, mimeType as h, cookiePriorities as i, mergeObjects as it, useCookies as j, statusCodes as k, encodings as l, isServer as m, SERVER_ROUTER_CONTEXT as n, defineContext as nt, createServer as o, isClient as p, PARAMETER_MATCH as q, STATES as r, defineHook as rt, defineMiddleware as s, SERVER_CONTEXT as t, Scope as tt, getState as u, sendBadRequest as v, sendRedirect as w, sendNoContent as x, sendCreated as y, withQuery as z };
@@ -1,4 +1,4 @@
1
- import { Ot as Mergeable, s as Config } from "../index-B4nGVcLE.mjs";
1
+ import { Ot as Mergeable, s as Config } from "../index-DOmfkUsW.mjs";
2
2
  import { PluginOption } from "vite";
3
3
 
4
4
  //#region src/vite/index.d.ts
@@ -1,5 +1,5 @@
1
- import { f as invoke, h as mimeType, it as CLOSE_HOOK, nt as App, rt as CLIENT, st as Scope, t as SERVER_CONTEXT, ut as mergeObjects } from "../server-BKOK-LN2.mjs";
2
- import { n as version, t as name } from "../package-D8FgpUMW.mjs";
1
+ import { Q as CLOSE_HOOK, X as App, Z as CLIENT, f as invoke, h as mimeType, it as mergeObjects, t as SERVER_CONTEXT, tt as Scope } from "../server-BplNURRd.mjs";
2
+ import { n as version, t as name } from "../package-BcN3Ewsh.mjs";
3
3
  import { addTemplate, addTypes, addVirtual, resolvePaths, useKit } from "../kit/index.mjs";
4
4
  import { mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "fs";
5
5
  import { basename, dirname, isAbsolute, join, posix, relative, resolve, win32 } from "path";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.1.53",
3
+ "version": "0.1.55",
4
4
  "license": "MIT",
5
5
  "repository": "tellua/revojs",
6
6
  "bin": {