revojs 0.1.49 → 0.1.51

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,128 +1,4 @@
1
1
  //#region src/server/index.ts
2
- var Radix = class {
3
- rootNode;
4
- constructor(rootNode) {
5
- this.rootNode = rootNode ?? {
6
- type: "PATH",
7
- children: {}
8
- };
9
- }
10
- use(segments, value) {
11
- let node = this.rootNode;
12
- for (const next of segments) {
13
- const optionalWildcardMatch = (next.match(OPTIONAL_WILDCARD_MATCH) ?? []).at(1);
14
- if (typeof optionalWildcardMatch === "string") {
15
- let childNode = node.children["@@"];
16
- childNode ??= {
17
- type: "OPTIONAL-WILDCARD",
18
- parameter: optionalWildcardMatch,
19
- children: {}
20
- };
21
- node.children["@@"] ??= childNode;
22
- node = childNode;
23
- continue;
24
- }
25
- const wildcardMatch = (next.match(WILDCARD_MATCH) ?? []).at(1);
26
- if (typeof wildcardMatch === "string") {
27
- let childNode = node.children["@"];
28
- childNode ??= {
29
- type: "WILDCARD",
30
- parameter: wildcardMatch,
31
- children: {}
32
- };
33
- node.children["@"] ??= childNode;
34
- node = childNode;
35
- continue;
36
- }
37
- const optionalParameterMatch = (next.match(OPTIONAL_PARAMETER_MATCH) ?? []).at(1);
38
- if (typeof optionalParameterMatch === "string") {
39
- let childNode = node.children[OPTIONAL_PARAMETER];
40
- childNode ??= {
41
- type: "OPTIONAL-PARAMETER",
42
- parameter: optionalParameterMatch,
43
- children: {}
44
- };
45
- node.children[OPTIONAL_PARAMETER] ??= childNode;
46
- node = childNode;
47
- continue;
48
- }
49
- const parameterMatch = (next.match(PARAMETER_MATCH) ?? []).at(1);
50
- if (typeof parameterMatch === "string") {
51
- let childNode = node.children["@@@"];
52
- childNode ??= {
53
- type: "PARAMETER",
54
- parameter: parameterMatch,
55
- children: {}
56
- };
57
- node.children["@@@"] ??= childNode;
58
- node = childNode;
59
- continue;
60
- }
61
- let childNode = node.children[next];
62
- childNode ??= {
63
- type: "PATH",
64
- children: {}
65
- };
66
- node.children[next] ??= childNode;
67
- node = childNode;
68
- }
69
- node.value = value;
70
- return node;
71
- }
72
- };
73
- var Router = class extends Radix {
74
- fetch(scope) {
75
- const { request } = useServer(scope);
76
- const { pathname } = useUrl(scope);
77
- const context = {
78
- route: this.rootNode,
79
- segments: (request.method.toLowerCase() + pathname).split("/"),
80
- parameters: {}
81
- };
82
- const invoke = (node, index) => {
83
- if (index === context.segments.length) return node.value;
84
- const segment = context.segments[index];
85
- if (node.children[segment]) {
86
- const route = invoke(node.children[segment], index + 1);
87
- if (route) return route;
88
- }
89
- if (node.children["@@@@"]) {
90
- const optionalParameterNode = node.children[OPTIONAL_PARAMETER];
91
- const route = invoke(optionalParameterNode, index + 1);
92
- if (route) {
93
- context.parameters[optionalParameterNode.parameter] = segment;
94
- return route;
95
- }
96
- }
97
- if (node.children["@@@"]) {
98
- const parameterNode = node.children["@@@"];
99
- const route = invoke(parameterNode, index + 1);
100
- if (route) {
101
- context.parameters[parameterNode.parameter] = segment;
102
- return route;
103
- }
104
- }
105
- if (node.children["@@"]) {
106
- const optionalWildcardNode = node.children["@@"];
107
- const wildcardPath = context.segments.slice(index).join("/");
108
- context.parameters[optionalWildcardNode.parameter] = wildcardPath;
109
- return optionalWildcardNode.value ?? invoke(optionalWildcardNode, context.segments.length);
110
- }
111
- if (node.children["@"]) {
112
- const wildcardNode = node.children["@"];
113
- const wildcardPath = context.segments.slice(index).join("/");
114
- context.parameters[wildcardNode.parameter] = wildcardPath;
115
- return wildcardNode.value ?? invoke(wildcardNode, context.segments.length);
116
- }
117
- };
118
- const route = invoke(this.rootNode, 0);
119
- if (route) {
120
- scope.setContext(ROUTER_CONTEXT, context);
121
- return route.fetch(scope);
122
- }
123
- throw sendNotFound(scope);
124
- }
125
- };
126
2
  function defineRoute(route) {
127
3
  return route;
128
4
  }
@@ -130,7 +6,7 @@ function defineMiddleware(middleware) {
130
6
  return middleware;
131
7
  }
132
8
  function useRouter(scope) {
133
- return scope.getContext(ROUTER_CONTEXT);
9
+ return scope.getContext(SERVER_ROUTER_CONTEXT);
134
10
  }
135
11
  function useServer(scope) {
136
12
  return scope.getContext(SERVER_CONTEXT);
@@ -313,8 +189,8 @@ async function invoke(scope, pipeline, index = 0) {
313
189
  }
314
190
  async function createServer() {
315
191
  const router = new Router();
316
- const middleware = new Array();
317
192
  const routes = await import("#routes").then((module) => Object.entries(module.default));
193
+ const middleware = await import("#middleware").then((module) => Object.values(module.default));
318
194
  for (const [path, route] of routes) {
319
195
  const segments = path.split("/");
320
196
  for (const attribute of segments.pop()?.split(".") ?? []) {
@@ -324,13 +200,17 @@ async function createServer() {
324
200
  }
325
201
  router.use(segments, route);
326
202
  }
327
- middleware.push(...await import("#middleware").then((module) => Object.values(module.default)), router);
328
203
  return {
329
204
  router,
330
205
  middleware,
331
206
  async fetch(scope) {
332
207
  try {
333
- return await invoke(scope, middleware) ?? sendNotFound(scope);
208
+ const { request } = useServer(scope);
209
+ const { pathname } = useUrl(scope);
210
+ const context = scope.setContext(SERVER_ROUTER_CONTEXT, router.match((request.method.toLowerCase() + pathname).split("/")));
211
+ const pipeline = middleware.concat(context.hooks);
212
+ if (context.route.value) pipeline.push(context.route.value);
213
+ return await invoke(scope, pipeline) ?? sendNotFound(scope);
334
214
  } catch (value) {
335
215
  if (value instanceof Response) return value;
336
216
  throw value;
@@ -339,16 +219,8 @@ async function createServer() {
339
219
  };
340
220
  }
341
221
  let STATES;
342
- const ROUTER_CONTEXT = defineContext("ROUTER_CONTEXT");
343
222
  const SERVER_CONTEXT = defineContext("SERVER_CONTEXT");
344
- const WILDCARD = "@";
345
- const OPTIONAL_WILDCARD = "@@";
346
- const PARAMETER = "@@@";
347
- const OPTIONAL_PARAMETER = "@@@@";
348
- const WILDCARD_MATCH = /\[\.\.\.(.*?)\]/;
349
- const OPTIONAL_WILDCARD_MATCH = /\[\[\.\.\.(.*?)\]\]/;
350
- const PARAMETER_MATCH = /\[(.*?)\]/;
351
- const OPTIONAL_PARAMETER_MATCH = /\[\[(.*?)\]\]/;
223
+ const SERVER_ROUTER_CONTEXT = defineContext("SERVER_ROUTER_CONTEXT");
352
224
  const isServer = import.meta.SERVER ?? globalThis?.import?.meta?.SERVER;
353
225
  const isClient = import.meta.CLIENT ?? globalThis?.import?.meta?.CLIENT;
354
226
  const cookiePriorities = [
@@ -546,6 +418,157 @@ var Scope = class extends Hookable {
546
418
  }
547
419
  setContext(input, value) {
548
420
  this.context[input] = value;
421
+ return value;
422
+ }
423
+ };
424
+ var Router = class {
425
+ rootNode;
426
+ constructor(rootNode) {
427
+ this.rootNode = rootNode ?? {
428
+ type: "PATH",
429
+ children: {}
430
+ };
431
+ }
432
+ use(segments, value) {
433
+ let node = this.rootNode;
434
+ for (const next of segments) {
435
+ const optionalWildcardMatch = (next.match(OPTIONAL_WILDCARD_MATCH) ?? []).at(1);
436
+ if (typeof optionalWildcardMatch === "string") {
437
+ let childNode = node.children["@@"];
438
+ childNode ??= {
439
+ type: "OPTIONAL-WILDCARD",
440
+ parameter: optionalWildcardMatch,
441
+ children: {}
442
+ };
443
+ node.children["@@"] ??= childNode;
444
+ node = childNode;
445
+ continue;
446
+ }
447
+ const wildcardMatch = (next.match(WILDCARD_MATCH) ?? []).at(1);
448
+ if (typeof wildcardMatch === "string") {
449
+ let childNode = node.children["@"];
450
+ childNode ??= {
451
+ type: "WILDCARD",
452
+ parameter: wildcardMatch,
453
+ children: {}
454
+ };
455
+ node.children["@"] ??= childNode;
456
+ node = childNode;
457
+ continue;
458
+ }
459
+ const optionalParameterMatch = (next.match(OPTIONAL_PARAMETER_MATCH) ?? []).at(1);
460
+ if (typeof optionalParameterMatch === "string") {
461
+ let childNode = node.children[OPTIONAL_PARAMETER];
462
+ childNode ??= {
463
+ type: "OPTIONAL-PARAMETER",
464
+ parameter: optionalParameterMatch,
465
+ children: {}
466
+ };
467
+ node.children[OPTIONAL_PARAMETER] ??= childNode;
468
+ node = childNode;
469
+ continue;
470
+ }
471
+ const parameterMatch = (next.match(PARAMETER_MATCH) ?? []).at(1);
472
+ if (typeof parameterMatch === "string") {
473
+ let childNode = node.children["@@@"];
474
+ childNode ??= {
475
+ type: "PARAMETER",
476
+ parameter: parameterMatch,
477
+ children: {}
478
+ };
479
+ node.children["@@@"] ??= childNode;
480
+ node = childNode;
481
+ continue;
482
+ }
483
+ const groupMatch = (next.match(GROUP_MATCH) ?? []).at(1);
484
+ if (groupMatch) {
485
+ let childNode = node.children[GROUP];
486
+ childNode ??= {
487
+ type: "GROUP",
488
+ label: groupMatch,
489
+ children: {}
490
+ };
491
+ node.children[GROUP] ??= childNode;
492
+ node = childNode;
493
+ continue;
494
+ }
495
+ if (next.match(HOOK_MATCH)?.[1]) {
496
+ let childNode = node.children[HOOK];
497
+ childNode ??= {
498
+ type: "HOOK",
499
+ children: {}
500
+ };
501
+ node.children[HOOK] ??= childNode;
502
+ node = childNode;
503
+ continue;
504
+ }
505
+ let childNode = node.children[next];
506
+ childNode ??= {
507
+ type: "PATH",
508
+ children: {}
509
+ };
510
+ node.children[next] ??= childNode;
511
+ node = childNode;
512
+ }
513
+ node.value = value;
514
+ return node;
515
+ }
516
+ match(segments) {
517
+ const context = {
518
+ route: this.rootNode,
519
+ segments,
520
+ parameters: {},
521
+ groups: [],
522
+ hooks: []
523
+ };
524
+ const invoke = (node, index) => {
525
+ const hook = node.children[HOOK]?.value;
526
+ if (hook) context.hooks.push(hook);
527
+ if (index === context.segments.length) return node;
528
+ const segment = context.segments[index];
529
+ if (node.children[segment]) {
530
+ const route = invoke(node.children[segment], index + 1);
531
+ if (route) return route;
532
+ }
533
+ if (node.children["@@@@@"]) {
534
+ const groupNode = node.children[GROUP];
535
+ const route = invoke(groupNode, index);
536
+ if (route) {
537
+ context.groups.push(groupNode.label);
538
+ return route;
539
+ }
540
+ }
541
+ if (node.children["@@@@"]) {
542
+ const optionalParameterNode = node.children[OPTIONAL_PARAMETER];
543
+ const route = invoke(optionalParameterNode, index + 1);
544
+ if (route) {
545
+ context.parameters[optionalParameterNode.parameter] = segment;
546
+ return route;
547
+ }
548
+ }
549
+ if (node.children["@@@"]) {
550
+ const parameterNode = node.children["@@@"];
551
+ const route = invoke(parameterNode, index + 1);
552
+ if (route) {
553
+ context.parameters[parameterNode.parameter] = segment;
554
+ return route;
555
+ }
556
+ }
557
+ if (node.children["@@"]) {
558
+ const optionalWildcardNode = node.children["@@"];
559
+ const wildcardPath = context.segments.slice(index).join("/");
560
+ context.parameters[optionalWildcardNode.parameter] = wildcardPath;
561
+ return optionalWildcardNode ?? invoke(optionalWildcardNode, context.segments.length);
562
+ }
563
+ if (node.children["@"]) {
564
+ const wildcardNode = node.children["@"];
565
+ const wildcardPath = context.segments.slice(index).join("/");
566
+ context.parameters[wildcardNode.parameter] = wildcardPath;
567
+ return wildcardNode ?? invoke(wildcardNode, context.segments.length);
568
+ }
569
+ };
570
+ context.route = invoke(this.rootNode, 0) ?? this.rootNode;
571
+ return context;
549
572
  }
550
573
  };
551
574
  function defineHook(name) {
@@ -575,6 +598,18 @@ function mergeObjects(base, input) {
575
598
  }
576
599
  return object;
577
600
  }
601
+ const WILDCARD = "@";
602
+ const OPTIONAL_WILDCARD = "@@";
603
+ const PARAMETER = "@@@";
604
+ const OPTIONAL_PARAMETER = "@@@@";
605
+ const GROUP = "@@@@@";
606
+ const HOOK = "@@@@@@";
607
+ const WILDCARD_MATCH = /\[\.\.\.(.*?)\]/;
608
+ const OPTIONAL_WILDCARD_MATCH = /\[\[\.\.\.(.*?)\]\]/;
609
+ const PARAMETER_MATCH = /\[(.*?)\]/;
610
+ const OPTIONAL_PARAMETER_MATCH = /\[\[(.*?)\]\]/;
611
+ const GROUP_MATCH = /^\((.*)\)$/;
612
+ const HOOK_MATCH = /^\+(.+)$/;
578
613
  //#endregion
579
614
  //#region src/app/index.ts
580
615
  var App = class extends Hookable {
@@ -598,11 +633,21 @@ var App = class extends Hookable {
598
633
  },
599
634
  sources: {
600
635
  routes: {
601
- match: ["**/{get,head,post,put,delete,connect,options,trace,patch}.{js,ts}", "!*.d.ts"],
636
+ match: [
637
+ "**/{get,head,post,put,delete,connect,options,trace,patch}.js",
638
+ "**/{get,head,post,put,delete,connect,options,trace,patch}.ts",
639
+ "**/+middleware.js",
640
+ "**/+middleware.ts",
641
+ "!*.d.ts"
642
+ ],
602
643
  entries: ["./routes"]
603
644
  },
604
645
  middleware: {
605
- match: ["**/*.{js,ts}", "!*.d.ts"],
646
+ match: [
647
+ "**/*.js",
648
+ "**/*.ts",
649
+ "!*.d.ts"
650
+ ],
606
651
  entries: ["./middleware"]
607
652
  }
608
653
  },
@@ -618,4 +663,4 @@ const SERVER = "ssr";
618
663
  const CLIENT = "client";
619
664
  const CLOSE_HOOK = defineHook("CLOSE_HOOK");
620
665
  //#endregion
621
- 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 };
666
+ export { statusCodes as $, createServer as A, mimeTypes as B, mergeObjects as C, STATES as D, SERVER_ROUTER_CONTEXT as E, httpMethods as F, sendNoContent as G, sendBadRequest as H, invoke as I, sendRedirect as J, sendNotFound as K, isClient as L, defineRoute as M, encodings as N, cookiePriorities as O, getState as P, setState as Q, isServer as R, isFailure as S, SERVER_CONTEXT as T, sendCreated as U, parseCookiePair as V, sendForbidden as W, sendUnauthorized as X, sendResponse as Y, setCookie as Z, Scope as _, GROUP as a, useRouter as at, defineContext as b, HOOK_MATCH as c, useUrl as ct, OPTIONAL_PARAMETER_MATCH as d, useBody as et, OPTIONAL_WILDCARD as f, Router as g, PARAMETER_MATCH as h, SERVER as i, useQuery as it, defineMiddleware as j, cookieSameSites as k, Hookable as l, withQuery as lt, PARAMETER as m, CLIENT as n, useHeaders as nt, GROUP_MATCH as o, useServer as ot, OPTIONAL_WILDCARD_MATCH as p, sendOk as q, CLOSE_HOOK as r, useParameters as rt, HOOK as s, useSetCookies as st, App as t, useCookies as tt, OPTIONAL_PARAMETER as u, WILDCARD as v, parseSchema as w, defineHook as x, WILDCARD_MATCH as y, mimeType as z };
@@ -1,16 +1,20 @@
1
1
  #!/usr/bin/env node
2
- import { n as version, t as name } from "../package-CL2E27Tm.mjs";
2
+ import { n as version, t as name } from "../package-DiFpQQya.mjs";
3
+ import { resolvePaths } from "../kit/index.mjs";
3
4
  import { defineCommand, runMain } from "citty";
4
5
  import { copyFileSync, mkdirSync } from "fs";
5
6
  import { dirname, join, relative } from "path";
6
7
  import { rolldown } from "rolldown";
7
8
  import { dts } from "rolldown-plugin-dts";
8
- import { glob } from "tinyglobby";
9
9
  //#endregion
10
10
  //#region src/commands/module/index.ts
11
11
  var module_default = defineCommand({ subCommands: { build: defineCommand({ async setup() {
12
12
  await (await rolldown({
13
- input: await glob(["./src/**/*.{js,ts}", "!./src/**/*.d.ts"]),
13
+ input: resolvePaths([
14
+ "./src/**/*.js",
15
+ "./src/**/*.ts",
16
+ "!./src/**/*.d.ts"
17
+ ]),
14
18
  plugins: [dts()],
15
19
  external: () => true
16
20
  })).write({
@@ -18,14 +22,15 @@ var module_default = defineCommand({ subCommands: { build: defineCommand({ async
18
22
  preserveModules: true,
19
23
  sanitizeFileName: false
20
24
  });
21
- for (const file of await glob([
25
+ for (const path of resolvePaths([
22
26
  "./src/**/*.*",
23
27
  "!./src/**/*.js",
24
- "!./src/**/!(*.d).ts"
28
+ "!./src/**/*.ts",
29
+ "!./src/**/**.d.ts"
25
30
  ])) {
26
- const target = join("./dist", relative("./src", file));
31
+ const target = join("./dist", relative("./src", path));
27
32
  mkdirSync(dirname(target), { recursive: true });
28
- copyFileSync(file, target);
33
+ copyFileSync(path, target);
29
34
  }
30
35
  } }) } });
31
36
  //#endregion
@@ -10,7 +10,56 @@ type Output<T> = Success<T> | Failure;
10
10
  type InferInput<T extends Schema> = NonNullable<T["~standard"]["types"]>["input"];
11
11
  type InferOutput<T extends Schema> = NonNullable<T["~standard"]["types"]>["output"];
12
12
  type Primitive = string | number | boolean | bigint | symbol | null | undefined;
13
+ type Awaitable<T> = T | PromiseLike<T>;
13
14
  type Mergeable<T> = T extends Primitive ? T : T extends Array<infer U> ? Array<Mergeable<U>> : { [K in keyof T]?: Mergeable<T[K]> };
15
+ type Node<T> = PathNode<T> | WildcardNode<T> | OptionalWildcardNode<T> | ParameterNode<T> | OptionalParameterNode<T> | GroupNode<T> | HookNode<T>;
16
+ interface PathNode<T> {
17
+ type: "PATH";
18
+ value?: T;
19
+ children: Record<string, Node<T>>;
20
+ }
21
+ interface WildcardNode<T> {
22
+ type: "WILDCARD";
23
+ value?: T;
24
+ parameter: string;
25
+ children: Record<string, Node<T>>;
26
+ }
27
+ interface OptionalWildcardNode<T> {
28
+ type: "OPTIONAL-WILDCARD";
29
+ value?: T;
30
+ parameter: string;
31
+ children: Record<string, Node<T>>;
32
+ }
33
+ interface ParameterNode<T> {
34
+ type: "PARAMETER";
35
+ value?: T;
36
+ parameter: string;
37
+ children: Record<string, Node<T>>;
38
+ }
39
+ interface OptionalParameterNode<T> {
40
+ type: "OPTIONAL-PARAMETER";
41
+ value?: T;
42
+ parameter: string;
43
+ children: Record<string, Node<T>>;
44
+ }
45
+ interface GroupNode<T> {
46
+ type: "GROUP";
47
+ label: string;
48
+ value?: T;
49
+ children: Record<string, Node<T>>;
50
+ }
51
+ interface HookNode<T> {
52
+ type: "HOOK";
53
+ value?: T;
54
+ children: Record<string, Node<T>>;
55
+ }
56
+ interface RouterContext<T> {
57
+ route: Node<T>;
58
+ segments: Array<string>;
59
+ parameters: Record<string, string>;
60
+ groups: Array<string>;
61
+ hooks: Array<T>;
62
+ }
14
63
  interface Issue {
15
64
  readonly message: string;
16
65
  }
@@ -40,13 +89,31 @@ declare class Scope extends Hookable {
40
89
  private readonly context;
41
90
  constructor(parentScope?: Scope);
42
91
  getContext<T>(input: Descriptor<T>): T;
43
- setContext<T>(input: Descriptor<T>, value: T): void;
92
+ setContext<T>(input: Descriptor<T>, value: T): T;
93
+ }
94
+ declare class Router<T> {
95
+ readonly rootNode: Node<T>;
96
+ constructor(rootNode?: Node<T>);
97
+ use(segments: Array<string>, value: T): Node<T>;
98
+ match(segments: Array<string>): RouterContext<T>;
44
99
  }
45
100
  declare function defineHook<T extends Invoke>(name: string): Descriptor<T>;
46
101
  declare function defineContext<T>(name: string): Descriptor<T>;
47
102
  declare function isFailure<T>(result: Output<T>): result is Failure;
48
103
  declare function parseSchema<T extends Schema>(scope: Scope, schema: T, value: unknown): InferOutput<T>;
49
104
  declare function mergeObjects<TBase, TInput>(base: TBase, input: TInput): TBase & TInput;
105
+ declare const WILDCARD = "@";
106
+ declare const OPTIONAL_WILDCARD = "@@";
107
+ declare const PARAMETER = "@@@";
108
+ declare const OPTIONAL_PARAMETER = "@@@@";
109
+ declare const GROUP = "@@@@@";
110
+ declare const HOOK = "@@@@@@";
111
+ declare const WILDCARD_MATCH: RegExp;
112
+ declare const OPTIONAL_WILDCARD_MATCH: RegExp;
113
+ declare const PARAMETER_MATCH: RegExp;
114
+ declare const OPTIONAL_PARAMETER_MATCH: RegExp;
115
+ declare const GROUP_MATCH: RegExp;
116
+ declare const HOOK_MATCH: RegExp;
50
117
  declare const descriptor: unique symbol;
51
118
  //#endregion
52
119
  //#region src/server/index.d.ts
@@ -57,8 +124,6 @@ type Encoding = (typeof encodings)[number];
57
124
  type StatusCode = (typeof statusCodes)[number];
58
125
  type MimeType = (typeof mimeTypes)[keyof typeof mimeTypes];
59
126
  type Result = void | Response | Promise<void | Response>;
60
- type Node<T> = OptionalWildcardNode<T> | WildcardNode<T> | OptionalParameterNode<T> | ParameterNode<T> | PathNode<T>;
61
- type States = Record<string, unknown>;
62
127
  interface CookieOptions {
63
128
  domain?: string;
64
129
  expires?: Date;
@@ -74,13 +139,8 @@ interface ResponseConfig {
74
139
  statusText?: string;
75
140
  headers: Headers;
76
141
  }
77
- interface RouterContext {
78
- route: Node<Route>;
79
- segments: Array<string>;
80
- parameters: Record<string, string>;
81
- }
82
142
  interface ServerContext<T extends Context = Context> {
83
- states: States;
143
+ states: Context;
84
144
  request: Request;
85
145
  response: ResponseConfig;
86
146
  variables: T;
@@ -92,50 +152,13 @@ interface Middleware {
92
152
  fetch: (scope: Scope, next?: () => Result) => Result;
93
153
  }
94
154
  interface Server {
95
- router: Router;
155
+ router: Router<Route>;
96
156
  middleware: Array<Middleware>;
97
157
  fetch: (scope: Scope) => Result;
98
158
  }
99
- interface PathNode<T> {
100
- type: "PATH";
101
- value?: T;
102
- children: Record<string, Node<T>>;
103
- }
104
- interface WildcardNode<T> {
105
- type: "WILDCARD";
106
- value?: T;
107
- parameter: string;
108
- children: Record<string, Node<T>>;
109
- }
110
- interface OptionalWildcardNode<T> {
111
- type: "OPTIONAL-WILDCARD";
112
- value?: T;
113
- parameter: string;
114
- children: Record<string, Node<T>>;
115
- }
116
- interface ParameterNode<T> {
117
- type: "PARAMETER";
118
- value?: T;
119
- parameter: string;
120
- children: Record<string, Node<T>>;
121
- }
122
- interface OptionalParameterNode<T> {
123
- type: "OPTIONAL-PARAMETER";
124
- value?: T;
125
- parameter: string;
126
- children: Record<string, Node<T>>;
127
- }
128
- declare class Radix<T> {
129
- readonly rootNode: Node<T>;
130
- constructor(rootNode?: Node<T>);
131
- use(segments: Array<string>, value: T): Node<T>;
132
- }
133
- declare class Router extends Radix<Route> implements Middleware {
134
- fetch(scope: Scope): Result;
135
- }
136
159
  declare function defineRoute<T extends Route>(route: T): T;
137
160
  declare function defineMiddleware<T extends Middleware>(middleware: T): T;
138
- declare function useRouter(scope: Scope): RouterContext;
161
+ declare function useRouter(scope: Scope): RouterContext<Route>;
139
162
  declare function useServer<T extends Context>(scope: Scope): ServerContext<T>;
140
163
  declare function useUrl(scope: Scope, base?: string): URL;
141
164
  declare function useParameters(scope: Scope): Record<string, string>;
@@ -167,17 +190,9 @@ declare function sendNotFound<T>(scope: Scope, body?: T | BodyInit, config?: Mer
167
190
  declare function mimeType(file: string): MimeType;
168
191
  declare function invoke(scope: Scope, pipeline: Array<Middleware>, index?: number): Promise<Result>;
169
192
  declare function createServer(): Promise<Server>;
170
- declare let STATES: States;
171
- declare const ROUTER_CONTEXT: Descriptor<RouterContext>;
193
+ declare let STATES: Context;
172
194
  declare const SERVER_CONTEXT: Descriptor<ServerContext<Context>>;
173
- declare const WILDCARD = "@";
174
- declare const OPTIONAL_WILDCARD = "@@";
175
- declare const PARAMETER = "@@@";
176
- declare const OPTIONAL_PARAMETER = "@@@@";
177
- declare const WILDCARD_MATCH: RegExp;
178
- declare const OPTIONAL_WILDCARD_MATCH: RegExp;
179
- declare const PARAMETER_MATCH: RegExp;
180
- declare const OPTIONAL_PARAMETER_MATCH: RegExp;
195
+ declare const SERVER_ROUTER_CONTEXT: Descriptor<RouterContext<Route>>;
181
196
  declare const isServer: boolean;
182
197
  declare const isClient: boolean;
183
198
  declare const cookiePriorities: readonly ["Low", "Medium", "High"];
@@ -189,11 +204,11 @@ declare const mimeTypes: Record<string, string>;
189
204
  //#endregion
190
205
  //#region src/app/index.d.ts
191
206
  type Environment = typeof CLIENT | typeof SERVER;
192
- type Virtual = (environment: Environment) => undefined | string | Promise<string>;
193
- type Content = () => string | Promise<string>;
207
+ type Virtual = (environment: Environment) => Awaitable<undefined | string>;
208
+ type Content = () => Awaitable<string>;
194
209
  interface Asset {
195
- type: string;
196
210
  name: string;
211
+ type: string;
197
212
  relative: string;
198
213
  entityTag: string;
199
214
  lastModified: string;
@@ -220,10 +235,10 @@ interface Config {
220
235
  vite: UserConfig;
221
236
  }
222
237
  interface Module {
223
- setup?: (app: App) => void | Mergeable<Config> | Promise<void | Mergeable<Config>>;
238
+ setup?: (app: App) => Awaitable<void | Mergeable<Config>>;
224
239
  }
225
240
  interface Source {
226
- match: string | Array<string>;
241
+ match: Array<string>;
227
242
  entries: Array<string>;
228
243
  resolve?: (path: string) => string;
229
244
  }
@@ -236,11 +251,11 @@ declare const CLIENT = "client";
236
251
  declare const CLOSE_HOOK: Descriptor<() => void>;
237
252
  //#endregion
238
253
  //#region src/client/index.d.ts
239
- declare function $fetch<T>(scope: Scope, input: string | URL, options?: RequestInit): Promise<T>;
254
+ declare function fetch<T>(scope: Scope, input: string | URL, options?: RequestInit): Promise<T>;
240
255
  //#endregion
241
256
  //#region src/middleware/index.d.ts
242
257
  declare function createStaticMiddleware<T>(resolve: (path: string | URL) => T | Promise<T>): {
243
258
  fetch(scope: Scope, next: (() => Result) | undefined): Promise<void | Response>;
244
259
  };
245
260
  //#endregion
246
- export { defineMiddleware as $, PARAMETER as A, useUrl as At, RouterContext as B, Mergeable as Bt, Node as C, useCookies as Ct, OPTIONAL_WILDCARD_MATCH as D, useRouter as Dt, OPTIONAL_WILDCARD as E, useQuery as Et, Radix as F, Hookable as Ft, States as G, Success as Gt, STATES as H, Primitive as Ht, ResponseConfig as I, InferInput as It, WILDCARD_MATCH as J, isFailure as Jt, StatusCode as K, defineContext as Kt, Result as L, InferOutput as Lt, ParameterNode as M, Context as Mt, PathNode as N, Descriptor as Nt, OptionalParameterNode as O, useServer as Ot, ROUTER_CONTEXT as P, Failure as Pt, createServer as Q, Route as R, Invoke as Rt, MimeType as S, useBody as St, OPTIONAL_PARAMETER_MATCH as T, useParameters as Tt, Server as U, Schema as Ut, SERVER_CONTEXT as V, Output as Vt, ServerContext as W, Scope as Wt, cookiePriorities as X, parseSchema as Xt, WildcardNode as Y, mergeObjects as Yt, cookieSameSites as Z, CookiePriority as _, sendResponse as _t, CLIENT as a, isClient as at, HttpMethod as b, setState as bt, Content as c, mimeTypes as ct, Module as d, sendCreated as dt, defineRoute as et, SERVER as f, sendForbidden as ft, CookieOptions as g, sendRedirect as gt, Virtual as h, sendOk as ht, Asset as i, invoke as it, PARAMETER_MATCH as j, withQuery as jt, OptionalWildcardNode as k, useSetCookies as kt, DevelopmentConfig as l, parseCookiePair as lt, Template as m, sendNotFound as mt, $fetch as n, getState as nt, CLOSE_HOOK as o, isServer as ot, Source as p, sendNoContent as pt, WILDCARD as q, defineHook as qt, App as r, httpMethods as rt, Config as s, mimeType as st, createStaticMiddleware as t, encodings as tt, Environment as u, sendBadRequest as ut, CookieSameSite as v, sendUnauthorized as vt, OPTIONAL_PARAMETER as w, useHeaders as wt, Middleware as x, statusCodes as xt, Encoding as y, setCookie as yt, Router as z, Issue as zt };
261
+ export { sendResponse as $, isFailure as $t, ServerContext as A, Node as At, invoke as B, ParameterNode as Bt, ResponseConfig as C, HookNode as Ct, SERVER_ROUTER_CONTEXT as D, Invoke as Dt, SERVER_CONTEXT as E, InferOutput as Et, defineMiddleware as F, OptionalParameterNode as Ft, parseCookiePair as G, Schema as Gt, isServer as H, Primitive as Ht, defineRoute as I, OptionalWildcardNode as It, sendForbidden as J, WILDCARD as Jt, sendBadRequest as K, Scope as Kt, encodings as L, Output as Lt, cookiePriorities as M, OPTIONAL_PARAMETER_MATCH as Mt, cookieSameSites as N, OPTIONAL_WILDCARD as Nt, STATES as O, Issue as Ot, createServer as P, OPTIONAL_WILDCARD_MATCH as Pt, sendRedirect as Q, defineHook as Qt, getState as R, PARAMETER as Rt, MimeType as S, HOOK_MATCH as St, Route as T, InferInput as Tt, mimeType as U, Router as Ut, isClient as V, PathNode as Vt, mimeTypes as W, RouterContext as Wt, sendNotFound as X, WildcardNode as Xt, sendNoContent as Y, WILDCARD_MATCH as Yt, sendOk as Z, defineContext as Zt, CookiePriority as _, Failure as _t, CLIENT as a, useCookies as at, HttpMethod as b, GroupNode as bt, Content as c, useQuery as ct, Module as d, useSetCookies as dt, mergeObjects as en, sendUnauthorized as et, SERVER as f, useUrl as ft, CookieOptions as g, Descriptor as gt, Virtual as h, Context as ht, Asset as i, useBody as it, StatusCode as j, OPTIONAL_PARAMETER as jt, Server as k, Mergeable as kt, DevelopmentConfig as l, useRouter as lt, Template as m, Awaitable as mt, fetch as n, setState as nt, CLOSE_HOOK as o, useHeaders as ot, Source as p, withQuery as pt, sendCreated as q, Success as qt, App as r, statusCodes as rt, Config as s, useParameters as st, createStaticMiddleware as t, parseSchema as tn, setCookie as tt, Environment as u, useServer as ut, CookieSameSite as v, GROUP as vt, Result as w, Hookable as wt, Middleware as x, HOOK as xt, Encoding as y, GROUP_MATCH as yt, httpMethods as z, PARAMETER_MATCH as zt };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as defineMiddleware, A as PARAMETER, At as useUrl, B as RouterContext, Bt as Mergeable, C as Node, Ct as useCookies, D as OPTIONAL_WILDCARD_MATCH, Dt as useRouter, E as OPTIONAL_WILDCARD, Et as useQuery, F as Radix, Ft as Hookable, G as States, Gt as Success, H as STATES, Ht as Primitive, I as ResponseConfig, It as InferInput, J as WILDCARD_MATCH, Jt as isFailure, K as StatusCode, Kt as defineContext, L as Result, Lt as InferOutput, M as ParameterNode, Mt as Context, N as PathNode, Nt as Descriptor, O as OptionalParameterNode, Ot as useServer, P as ROUTER_CONTEXT, Pt as Failure, Q as createServer, R as Route, Rt as Invoke, S as MimeType, St as useBody, T as OPTIONAL_PARAMETER_MATCH, Tt as useParameters, U as Server, Ut as Schema, V as SERVER_CONTEXT, Vt as Output, W as ServerContext, Wt as Scope, X as cookiePriorities, Xt as parseSchema, Y as WildcardNode, Yt as mergeObjects, Z as cookieSameSites, _ as CookiePriority, _t as sendResponse, a as CLIENT, at as isClient, b as HttpMethod, bt as setState, c as Content, ct as mimeTypes, d as Module, dt as sendCreated, et as defineRoute, f as SERVER, ft as sendForbidden, g as CookieOptions, gt as sendRedirect, h as Virtual, ht as sendOk, i as Asset, it as invoke, j as PARAMETER_MATCH, jt as withQuery, k as OptionalWildcardNode, kt as useSetCookies, l as DevelopmentConfig, lt as parseCookiePair, m as Template, mt as sendNotFound, n as $fetch, nt as getState, o as CLOSE_HOOK, ot as isServer, p as Source, pt as sendNoContent, q as WILDCARD, qt as defineHook, r as App, rt as httpMethods, s as Config, st as mimeType, t as createStaticMiddleware, tt as encodings, u as Environment, ut as sendBadRequest, v as CookieSameSite, vt as sendUnauthorized, w as OPTIONAL_PARAMETER, wt as useHeaders, x as Middleware, xt as statusCodes, y as Encoding, yt as setCookie, z as Router, zt as Issue } from "./index-nxflReVm.mjs";
2
- export { $fetch, App, Asset, 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, Primitive, 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, createStaticMiddleware, 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
+ import { $ as sendResponse, $t as isFailure, A as ServerContext, At as Node, B as invoke, Bt as ParameterNode, C as ResponseConfig, Ct as HookNode, D as SERVER_ROUTER_CONTEXT, Dt as Invoke, E as SERVER_CONTEXT, Et as InferOutput, F as defineMiddleware, Ft as OptionalParameterNode, G as parseCookiePair, Gt as Schema, H as isServer, Ht as Primitive, I as defineRoute, It as OptionalWildcardNode, J as sendForbidden, Jt as WILDCARD, K as sendBadRequest, Kt as Scope, L as encodings, Lt as Output, M as cookiePriorities, Mt as OPTIONAL_PARAMETER_MATCH, N as cookieSameSites, Nt as OPTIONAL_WILDCARD, O as STATES, Ot as Issue, P as createServer, Pt as OPTIONAL_WILDCARD_MATCH, Q as sendRedirect, Qt as defineHook, R as getState, Rt as PARAMETER, S as MimeType, St as HOOK_MATCH, T as Route, Tt as InferInput, U as mimeType, Ut as Router, V as isClient, Vt as PathNode, W as mimeTypes, Wt as RouterContext, X as sendNotFound, Xt as WildcardNode, Y as sendNoContent, Yt as WILDCARD_MATCH, Z as sendOk, Zt as defineContext, _ as CookiePriority, _t as Failure, a as CLIENT, at as useCookies, b as HttpMethod, bt as GroupNode, c as Content, ct as useQuery, d as Module, dt as useSetCookies, en as mergeObjects, et as sendUnauthorized, f as SERVER, ft as useUrl, g as CookieOptions, gt as Descriptor, h as Virtual, ht as Context, i as Asset, it as useBody, j as StatusCode, jt as OPTIONAL_PARAMETER, k as Server, kt as Mergeable, l as DevelopmentConfig, lt as useRouter, m as Template, mt as Awaitable, n as fetch, nt as setState, o as CLOSE_HOOK, ot as useHeaders, p as Source, pt as withQuery, q as sendCreated, qt as Success, r as App, rt as statusCodes, s as Config, st as useParameters, t as createStaticMiddleware, tn as parseSchema, tt as setCookie, u as Environment, ut as useServer, v as CookieSameSite, vt as GROUP, w as Result, wt as Hookable, x as Middleware, xt as HOOK, y as Encoding, yt as GROUP_MATCH, z as httpMethods, zt as PARAMETER_MATCH } from "./index-CZcqzWwl.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, Virtual, WILDCARD, WILDCARD_MATCH, WildcardNode, cookiePriorities, cookieSameSites, createServer, createStaticMiddleware, defineContext, defineHook, defineMiddleware, defineRoute, encodings, fetch, 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,7 +1,7 @@
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-BMQ38K-1.mjs";
1
+ import { $ as statusCodes, A as createServer, B as mimeTypes, C as mergeObjects, D as STATES, E as SERVER_ROUTER_CONTEXT, F as httpMethods, G as sendNoContent, H as sendBadRequest, I as invoke, J as sendRedirect, K as sendNotFound, L as isClient, M as defineRoute, N as encodings, O as cookiePriorities, P as getState, Q as setState, R as isServer, S as isFailure, T as SERVER_CONTEXT, U as sendCreated, V as parseCookiePair, W as sendForbidden, X as sendUnauthorized, Y as sendResponse, Z as setCookie, _ as Scope, a as GROUP, at as useRouter, b as defineContext, c as HOOK_MATCH, ct as useUrl, d as OPTIONAL_PARAMETER_MATCH, et as useBody, f as OPTIONAL_WILDCARD, g as Router, h as PARAMETER_MATCH, i as SERVER, it as useQuery, j as defineMiddleware, k as cookieSameSites, l as Hookable, lt as withQuery, m as PARAMETER, n as CLIENT, nt as useHeaders, o as GROUP_MATCH, ot as useServer, p as OPTIONAL_WILDCARD_MATCH, q as sendOk, r as CLOSE_HOOK, rt as useParameters, s as HOOK, st as useSetCookies, t as App, tt as useCookies, u as OPTIONAL_PARAMETER, v as WILDCARD, w as parseSchema, x as defineHook, y as WILDCARD_MATCH, z as mimeType } from "./app-VHSJTEkd.mjs";
2
2
  import assets from "#assets";
3
3
  //#region src/client/index.ts
4
- async function $fetch(scope, input, options) {
4
+ async function fetch(scope, input, options) {
5
5
  let response;
6
6
  if (isServer) {
7
7
  const { states, request, variables } = useServer(scope);
@@ -16,7 +16,7 @@ async function $fetch(scope, input, options) {
16
16
  const previous = new URL(request.url);
17
17
  if (url.origin === previous.origin) response = await (await import("#server")).default.fetch(next);
18
18
  }
19
- response ??= await fetch(input, options);
19
+ response ??= await globalThis.fetch(input, options);
20
20
  if (response.ok === false) throw response;
21
21
  switch (response.headers.get("Content-Type")?.split(";").shift() ?? "") {
22
22
  case "application/json": return response.json();
@@ -52,4 +52,4 @@ function createStaticMiddleware(resolve) {
52
52
  } });
53
53
  }
54
54
  //#endregion
55
- 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, createStaticMiddleware, 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 };
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, 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, h as Virtual, r as App } from "../index-nxflReVm.mjs";
1
+ import { c as Content, h as Virtual, r as App } from "../index-CZcqzWwl.mjs";
2
2
 
3
3
  //#region src/kit/index.d.ts
4
4
  declare function useKit(source: string | URL): {
@@ -9,5 +9,6 @@ declare function addVirtual(app: App, name: string, virtual: Virtual): void;
9
9
  declare function addRoutes(app: App, path: string): void;
10
10
  declare function addMiddleware(app: App, path: string): void;
11
11
  declare function addTypes(app: App, name: string, content: Content): void;
12
+ declare function resolvePaths(path: string | Array<string>, cwd?: string): string[];
12
13
  //#endregion
13
- export { addMiddleware, addRoutes, addTemplate, addTypes, addVirtual, useKit };
14
+ export { addMiddleware, addRoutes, addTemplate, addTypes, addVirtual, resolvePaths, useKit };
@@ -1,4 +1,5 @@
1
- import { dirname, join, posix, win32 } from "path";
1
+ import { globSync, statSync } from "fs";
2
+ import { dirname, join, posix, resolve, win32 } from "path";
2
3
  import { fileURLToPath } from "url";
3
4
  //#region src/kit/index.ts
4
5
  function useKit(source) {
@@ -23,5 +24,29 @@ function addMiddleware(app, path) {
23
24
  function addTypes(app, name, content) {
24
25
  addTemplate(app, `types/${name}.d.ts`, content);
25
26
  }
27
+ function resolvePaths(path, cwd) {
28
+ const from = resolve(cwd ?? ".");
29
+ const input = Array.isArray(path) ? path : [path];
30
+ const entries = /* @__PURE__ */ new Set();
31
+ const includes = new Array();
32
+ const excludes = new Array();
33
+ for (const pattern of input) if (pattern.startsWith("!")) excludes.push(pattern.slice(1));
34
+ else includes.push(pattern);
35
+ try {
36
+ for (const include of includes) for (const match of globSync(include, { cwd: from })) {
37
+ const path = join(from, match);
38
+ if (!statSync(path).isFile()) continue;
39
+ entries.add(resolve(path).split(win32.sep).join(posix.sep));
40
+ }
41
+ for (const exclude of excludes) for (const match of globSync(exclude, { cwd: from })) {
42
+ const path = join(from, match);
43
+ if (!statSync(path).isFile()) continue;
44
+ entries.delete(resolve(path).split(win32.sep).join(posix.sep));
45
+ }
46
+ } catch {
47
+ return [];
48
+ }
49
+ return Array.from(entries);
50
+ }
26
51
  //#endregion
27
- export { addMiddleware, addRoutes, addTemplate, addTypes, addVirtual, useKit };
52
+ export { addMiddleware, addRoutes, addTemplate, addTypes, addVirtual, resolvePaths, useKit };
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
2
  var name = "revojs";
3
- var version = "0.1.49";
3
+ var version = "0.1.51";
4
4
  //#endregion
5
5
  export { version as n, name as t };
@@ -1,4 +1,4 @@
1
- import { Bt as Mergeable, s as Config } from "../index-nxflReVm.mjs";
1
+ import { kt as Mergeable, s as Config } from "../index-CZcqzWwl.mjs";
2
2
  import { PluginOption } from "vite";
3
3
 
4
4
  //#region src/vite/index.d.ts
@@ -1,9 +1,8 @@
1
- import { I as mimeType, 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-BMQ38K-1.mjs";
2
- import { n as version, t as name } from "../package-CL2E27Tm.mjs";
3
- import { addTemplate, addTypes, addVirtual, useKit } from "../kit/index.mjs";
1
+ import { C as mergeObjects, I as invoke, T as SERVER_CONTEXT, _ as Scope, n as CLIENT, r as CLOSE_HOOK, t as App, z as mimeType } from "../app-VHSJTEkd.mjs";
2
+ import { n as version, t as name } from "../package-DiFpQQya.mjs";
3
+ import { addTemplate, addTypes, addVirtual, resolvePaths, useKit } from "../kit/index.mjs";
4
4
  import { mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "fs";
5
- import { basename, dirname, isAbsolute, join, posix, resolve, win32 } from "path";
6
- import { globSync } from "tinyglobby";
5
+ import { basename, dirname, isAbsolute, join, posix, relative, resolve, win32 } from "path";
7
6
  import { cwd } from "process";
8
7
  import { isRunnableDevEnvironment } from "vite";
9
8
  import { once } from "events";
@@ -167,11 +166,14 @@ async function revojs(config) {
167
166
  const entries = new Array();
168
167
  for (let path of source.entries) {
169
168
  path = isAbsolute(path) ? path : resolve(path);
170
- for (const name of globSync(source.match, { cwd: path })) entries.push({
171
- name,
172
- import: toImportName(name),
173
- path: join(path, name).split(win32.sep).join(posix.sep)
174
- });
169
+ for (const file of resolvePaths(source.match, path)) {
170
+ const name = relative(path, file).split(win32.sep).join(posix.sep);
171
+ entries.push({
172
+ name,
173
+ import: toImportName(name),
174
+ path: file
175
+ });
176
+ }
175
177
  }
176
178
  addVirtual(app, name, () => {
177
179
  let content = entries.reduce((content, entry) => content + `import ${entry.import} from "${entry.path}" \n`, "");
@@ -271,12 +273,13 @@ async function revojs(config) {
271
273
  configResolved(config) {
272
274
  addVirtual(app, "assets", () => {
273
275
  const client = config.environments[CLIENT].build.outDir;
274
- return `export default { ${globSync("**/*", { cwd: client }).reduce((assets, path) => {
275
- const meta = statSync(join(client, path));
276
+ return `export default { ${resolvePaths("**/*", client).reduce((assets, path) => {
277
+ const meta = statSync(path);
278
+ const name = relative(client, path).split(win32.sep).join(posix.sep);
276
279
  assets.push({
280
+ name,
277
281
  type: mimeType(path),
278
- name: path,
279
- relative: `./public/${path}`,
282
+ relative: `./public/${name}`,
280
283
  entityTag: `W/"${meta.size.toString(16)}-${Math.floor(meta.mtimeMs).toString(16)}"`,
281
284
  lastModified: meta.mtime.toJSON(),
282
285
  size: meta.size
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.1.49",
3
+ "version": "0.1.51",
4
4
  "license": "MIT",
5
5
  "repository": "tellua/revojs",
6
6
  "bin": {
@@ -37,14 +37,13 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "citty": "^0.2.2",
40
- "rolldown": "^1.0.0-rc.12",
40
+ "rolldown": "^1.0.0-rc.15",
41
41
  "rolldown-plugin-dts": "^0.23.2",
42
- "tinyglobby": "^0.2.15",
43
- "vite": "^8.0.3"
42
+ "vite": "^8.0.8"
44
43
  },
45
44
  "devDependencies": {
46
45
  "@revojs/tsconfig": "*",
47
- "@types/node": "^25.5.0",
46
+ "@types/node": "^25.6.0",
48
47
  "tsdown": "^0.21.7"
49
48
  }
50
49
  }