revojs 0.1.23 → 0.1.24

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,43 +1,69 @@
1
1
  //#region src/server/index.ts
2
2
  var Radix = class {
3
3
  rootNode;
4
- constructor() {
5
- this.rootNode = {
4
+ constructor(rootNode) {
5
+ this.rootNode = rootNode ?? {
6
6
  type: "PATH",
7
7
  children: {}
8
8
  };
9
9
  }
10
- use(path, value) {
10
+ use(segments, value) {
11
11
  let node = this.rootNode;
12
- for (const segment of path.split("/")) {
13
- if (segment.startsWith(WILDCARD)) {
12
+ for (const next of segments) {
13
+ const optionalWildcardMatch = (next.match(OPTIONAL_WILDCARD_MATCH) ?? []).at(1);
14
+ if (typeof optionalWildcardMatch === "string") {
15
+ let childNode$1 = node.children[WILDCARD];
16
+ childNode$1 ??= {
17
+ type: "OPTIONAL-WILDCARD",
18
+ parameter: optionalWildcardMatch,
19
+ children: {}
20
+ };
21
+ node.children[WILDCARD] ??= childNode$1;
22
+ node = childNode$1;
23
+ continue;
24
+ }
25
+ const wildcardMatch = (next.match(WILDCARD_MATCH) ?? []).at(1);
26
+ if (typeof wildcardMatch === "string") {
14
27
  let childNode$1 = node.children[WILDCARD];
15
28
  childNode$1 ??= {
16
29
  type: "WILDCARD",
17
- parameter: segment.substring(WILDCARD.length),
30
+ parameter: wildcardMatch,
18
31
  children: {}
19
32
  };
20
33
  node.children[WILDCARD] ??= childNode$1;
21
34
  node = childNode$1;
22
35
  continue;
23
36
  }
24
- if (segment.startsWith(PARAMETER)) {
37
+ const optionalParameterMatch = (next.match(OPTIONAL_PARAMETER_MATCH) ?? []).at(1);
38
+ if (typeof optionalParameterMatch === "string") {
39
+ let childNode$1 = node.children[PARAMETER];
40
+ childNode$1 ??= {
41
+ type: "OPTIONAL-PARAMETER",
42
+ parameter: optionalParameterMatch,
43
+ children: {}
44
+ };
45
+ node.children[PARAMETER] ??= childNode$1;
46
+ node = childNode$1;
47
+ continue;
48
+ }
49
+ const parameterMatch = (next.match(PARAMETER_MATCH) ?? []).at(1);
50
+ if (typeof parameterMatch === "string") {
25
51
  let childNode$1 = node.children[PARAMETER];
26
52
  childNode$1 ??= {
27
53
  type: "PARAMETER",
28
- parameter: segment.substring(PARAMETER.length),
54
+ parameter: parameterMatch,
29
55
  children: {}
30
56
  };
31
57
  node.children[PARAMETER] ??= childNode$1;
32
58
  node = childNode$1;
33
59
  continue;
34
60
  }
35
- let childNode = node.children[segment];
61
+ let childNode = node.children[next];
36
62
  childNode ??= {
37
63
  type: "PATH",
38
64
  children: {}
39
65
  };
40
- node.children[segment] ??= childNode;
66
+ node.children[next] ??= childNode;
41
67
  node = childNode;
42
68
  }
43
69
  node.value = value;
@@ -60,6 +86,14 @@ var Router = class extends Radix {
60
86
  const route$1 = invoke$1(node.children[segment], index + 1);
61
87
  if (route$1) return route$1;
62
88
  }
89
+ if (node.children[OPTIONAL_PARAMETER]) {
90
+ const optionalParameterNode = node.children[OPTIONAL_PARAMETER];
91
+ const route$1 = invoke$1(optionalParameterNode, index + 1);
92
+ if (route$1) {
93
+ context.parameters[optionalParameterNode.parameter] = segment;
94
+ return route$1;
95
+ }
96
+ }
63
97
  if (node.children[PARAMETER]) {
64
98
  const parameterNode = node.children[PARAMETER];
65
99
  const route$1 = invoke$1(parameterNode, index + 1);
@@ -68,6 +102,11 @@ var Router = class extends Radix {
68
102
  return route$1;
69
103
  }
70
104
  }
105
+ if (node.children[OPTIONAL_WILDCARD]) {
106
+ const optionalWildcardNode = node.children[OPTIONAL_WILDCARD];
107
+ context.parameters[optionalWildcardNode.parameter] = segment;
108
+ return optionalWildcardNode.value ?? invoke$1(optionalWildcardNode, context.segments.length);
109
+ }
71
110
  if (node.children[WILDCARD]) {
72
111
  const wildcardNode = node.children[WILDCARD];
73
112
  context.parameters[wildcardNode.parameter] = segment;
@@ -200,12 +239,7 @@ function sendUnauthorized(scope, config) {
200
239
  return new Response(null, mergeObjects(response, config));
201
240
  }
202
241
  function mimeType(file) {
203
- const extension = /\.([a-zA-Z0-9]+?)$/.exec(file)?.at(1);
204
- return mimeTypes[extension ?? ""] ?? "text/plain";
205
- }
206
- function toRoutePath(path) {
207
- const segments = path.toLowerCase().replaceAll(/\[\.\.\.(.*?)\]/g, (_, value) => WILDCARD + value).replaceAll(/\[(.*?)\]/g, (_, value) => PARAMETER + value).split(".");
208
- return [(segments.shift() ?? "").split("/").filter((value) => value !== "index").join("/"), ...segments];
242
+ return mimeTypes[/\.([a-zA-Z0-9]+?)$/.exec(file)?.at(1) ?? ""] ?? "text/plain";
209
243
  }
210
244
  async function invoke(scope, pipeline, index = 0) {
211
245
  return await pipeline.at(index)?.fetch(scope, async () => await invoke(scope, pipeline, index + 1));
@@ -215,8 +249,13 @@ async function createServer() {
215
249
  const middlewares = new Array();
216
250
  const routes = await import("#virtual/routes").then((module) => Object.entries(module.default));
217
251
  for (const [path, route] of routes) {
218
- const [result, method] = toRoutePath(path);
219
- router.use(method + "/" + result, route);
252
+ const segments = path.toLowerCase().split("/");
253
+ for (const attribute of segments.pop()?.split(".") ?? []) {
254
+ if (attribute === "index" || attribute === "js" || attribute === "ts") continue;
255
+ if (attribute === "get" || attribute === "post" || attribute === "put" || attribute === "delete" || attribute === "patch" || attribute === "options" || attribute === "head" || attribute === "trace" || attribute === "connect") segments.unshift(attribute);
256
+ else segments.push(attribute);
257
+ }
258
+ router.use(segments, route);
220
259
  }
221
260
  middlewares.push(router);
222
261
  return {
@@ -232,11 +271,19 @@ async function createServer() {
232
271
  }
233
272
  };
234
273
  }
274
+ let STATES;
235
275
  const ROUTER_CONTEXT = defineContext("ROUTER_CONTEXT");
236
276
  const SERVER_CONTEXT = defineContext("SERVER_CONTEXT");
237
- const WILDCARD = "$";
238
- const PARAMETER = ":";
239
- let STATES;
277
+ const WILDCARD = "@";
278
+ const OPTIONAL_WILDCARD = "@@";
279
+ const PARAMETER = "@@@";
280
+ const OPTIONAL_PARAMETER = "@@@";
281
+ const WILDCARD_MATCH = /\[\.\.\.(.*?)\]/;
282
+ const OPTIONAL_WILDCARD_MATCH = /\[\[\.\.\.(.*?)\]\]/;
283
+ const PARAMETER_MATCH = /\[(.*?)\]/;
284
+ const OPTIONAL_PARAMETER_MATCH = /\[\[(.*?)\]\]/;
285
+ const isServer = import.meta.server ?? globalThis?.import?.meta?.server;
286
+ const isClient = import.meta.client ?? globalThis?.import?.meta?.client;
240
287
  const mimeTypes = {
241
288
  txt: "text/plain",
242
289
  css: "text/css",
@@ -282,8 +329,6 @@ const mimeTypes = {
282
329
  exe: "application/vnd.microsoft.portable-executable",
283
330
  apk: "application/vnd.android.package-archive"
284
331
  };
285
- const isServer = import.meta.server ?? globalThis?.import?.meta?.server;
286
- const isClient = import.meta.client ?? globalThis?.import?.meta?.client;
287
332
 
288
333
  //#endregion
289
334
  //#region src/shared/index.ts
@@ -364,6 +409,19 @@ var App = class extends Hookable {
364
409
  super();
365
410
  this.config = mergeObjects(inputConfig, {
366
411
  modules: [],
412
+ client: "./index.html",
413
+ template: {
414
+ head: {
415
+ tagName: "head",
416
+ attributes: {},
417
+ children: []
418
+ },
419
+ body: {
420
+ tagName: "body",
421
+ attributes: {},
422
+ children: []
423
+ }
424
+ },
367
425
  sources: { routes: {
368
426
  match: "**/*.{get,head,post,put,delete,connect,options,trace,patch}.{js,ts}",
369
427
  entries: ["./routes"]
@@ -371,6 +429,7 @@ var App = class extends Hookable {
371
429
  development: { middlewares: [] },
372
430
  build: {
373
431
  externals: [],
432
+ types: {},
374
433
  virtuals: {},
375
434
  alias: {}
376
435
  }
@@ -382,4 +441,4 @@ const SERVER = "ssr";
382
441
  const CLIENT = "client";
383
442
 
384
443
  //#endregion
385
- export { App, CLIENT, Hookable, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope, WILDCARD, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
444
+ export { isServer as A, setState as B, WILDCARD_MATCH as C, getState as D, defineRoute as E, sendJson as F, useServer as G, useHeaders as H, sendRedirect as I, withQuery as J, useSetCookies as K, sendText as L, mimeTypes as M, sendBadRequest as N, invoke as O, sendHtml as P, sendUnauthorized as R, WILDCARD as S, defineMiddleware as T, useQuery as U, useCookies as V, useRouter as W, ROUTER_CONTEXT as _, Scope as a, SERVER_CONTEXT as b, isFailure as c, OPTIONAL_PARAMETER as d, OPTIONAL_PARAMETER_MATCH as f, PARAMETER_MATCH as g, PARAMETER as h, Hookable as i, mimeType as j, isClient as k, mergeObjects as l, OPTIONAL_WILDCARD_MATCH as m, CLIENT as n, defineContext as o, OPTIONAL_WILDCARD as p, useUrl as q, SERVER as r, defineHook as s, App as t, parseSchema as u, Radix as v, createServer as w, STATES as x, Router as y, setCookie as z };
@@ -7,7 +7,7 @@ type Context = Record<string, any>;
7
7
  type Output<T> = Success<T> | Failure;
8
8
  type InferInput<T extends Schema> = NonNullable<T["~standard"]["types"]>["input"];
9
9
  type InferOutput<T extends Schema> = NonNullable<T["~standard"]["types"]>["output"];
10
- type Mergeable<T> = { [P in keyof T]?: Mergeable<T[P]> };
10
+ type Mergeable<T> = { [Key in keyof T]?: Mergeable<T[Key]> };
11
11
  interface Issue {
12
12
  readonly message: string;
13
13
  }
@@ -54,7 +54,7 @@ type Encoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "bas
54
54
  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;
55
55
  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";
56
56
  type Result = void | Response | Promise<void | Response>;
57
- type Node<T> = WildcardNode<T> | ParameterNode<T> | PathNode<T>;
57
+ type Node<T> = OptionalWildcardNode<T> | WildcardNode<T> | OptionalParameterNode<T> | ParameterNode<T> | PathNode<T>;
58
58
  type States = Record<string, unknown>;
59
59
  interface CookieOptions {
60
60
  domain?: string;
@@ -99,6 +99,18 @@ interface WildcardNode<T> {
99
99
  parameter: string;
100
100
  children: Record<string, Node<T>>;
101
101
  }
102
+ interface OptionalWildcardNode<T> {
103
+ type: "OPTIONAL-WILDCARD";
104
+ value?: T;
105
+ parameter: string;
106
+ children: Record<string, Node<T>>;
107
+ }
108
+ interface OptionalParameterNode<T> {
109
+ type: "OPTIONAL-PARAMETER";
110
+ value?: T;
111
+ parameter: string;
112
+ children: Record<string, Node<T>>;
113
+ }
102
114
  interface ParameterNode<T> {
103
115
  type: "PARAMETER";
104
116
  value?: T;
@@ -112,8 +124,8 @@ interface PathNode<T> {
112
124
  }
113
125
  declare class Radix<T> {
114
126
  readonly rootNode: Node<T>;
115
- constructor();
116
- use(path: string, value: T): Node<T>;
127
+ constructor(rootNode?: Node<T>);
128
+ use(segments: Array<string>, value: T): Node<T>;
117
129
  }
118
130
  declare class Router extends Radix<Route> implements Middleware {
119
131
  fetch(scope: Scope): Result;
@@ -141,26 +153,38 @@ declare function sendRedirect(scope: Scope, path: string, config?: Mergeable<Res
141
153
  declare function sendBadRequest(scope: Scope, text: string, config?: Mergeable<ResponseConfig>): Response;
142
154
  declare function sendUnauthorized(scope: Scope, config?: Mergeable<ResponseConfig>): Response;
143
155
  declare function mimeType(file: string): MimeType;
144
- declare function toRoutePath(path: string): [string, ...Array<string>];
145
156
  declare function invoke(scope: Scope, pipeline: Array<Middleware>, index?: number): Promise<Result>;
146
157
  declare function createServer(): Promise<Server>;
158
+ declare let STATES: States;
147
159
  declare const ROUTER_CONTEXT: Descriptor<RouterContext>;
148
160
  declare const SERVER_CONTEXT: Descriptor<ServerContext<Context>>;
149
- declare const WILDCARD = "$";
150
- declare const PARAMETER = ":";
151
- declare let STATES: States;
152
- declare const mimeTypes: Record<string, MimeType>;
161
+ declare const WILDCARD = "@";
162
+ declare const OPTIONAL_WILDCARD = "@@";
163
+ declare const PARAMETER = "@@@";
164
+ declare const OPTIONAL_PARAMETER = "@@@";
165
+ declare const WILDCARD_MATCH: RegExp;
166
+ declare const OPTIONAL_WILDCARD_MATCH: RegExp;
167
+ declare const PARAMETER_MATCH: RegExp;
168
+ declare const OPTIONAL_PARAMETER_MATCH: RegExp;
153
169
  declare const isServer: boolean;
154
170
  declare const isClient: boolean;
171
+ declare const mimeTypes: Record<string, MimeType>;
155
172
  //#endregion
156
173
  //#region src/app/index.d.ts
157
174
  type Environment = typeof CLIENT | typeof SERVER;
158
175
  type Virtual = (environment: Environment) => undefined | string | Promise<string>;
176
+ type Content = () => string;
177
+ interface Template {
178
+ tagName: string;
179
+ attributes: Record<string, string>;
180
+ children: Array<string | Template>;
181
+ }
159
182
  interface DevelopmentConfig {
160
183
  middlewares: Array<Middleware>;
161
184
  }
162
185
  interface BuildConfig {
163
186
  externals: Array<string>;
187
+ types: Record<string, Content>;
164
188
  virtuals: Record<string, Virtual>;
165
189
  alias: Record<string, string>;
166
190
  }
@@ -168,6 +192,7 @@ interface Config {
168
192
  modules: Array<Module>;
169
193
  client?: string;
170
194
  server?: string;
195
+ template: Record<"head" | "body", Template>;
171
196
  sources: Record<string, Source>;
172
197
  development: DevelopmentConfig;
173
198
  build: BuildConfig;
@@ -191,4 +216,4 @@ declare const CLIENT = "client";
191
216
  //#region src/client/index.d.ts
192
217
  declare function $fetch<T>(scope: Scope, input: string | URL, options?: RequestInit): Promise<T>;
193
218
  //#endregion
194
- export { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, Hookable, HttpMethod, InferInput, InferOutput, Invoke, Issue, Mergeable, Middleware, MimeType, Module, Node, Output, PARAMETER, ParameterNode, PathNode, ROUTER_CONTEXT, Radix, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, STATES, Schema, Scope, Server, ServerContext, Source, States, StatusCode, Success, Virtual, WILDCARD, WildcardNode, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
219
+ export { isClient as $, ParameterNode as A, Scope as At, STATES as B, OPTIONAL_PARAMETER_MATCH as C, InferInput as Ct, OptionalWildcardNode as D, Mergeable as Dt, OptionalParameterNode as E, Issue as Et, Result as F, mergeObjects as Ft, WILDCARD as G, ServerContext as H, Route as I, parseSchema as It, createServer as J, WILDCARD_MATCH as K, Router as L, ROUTER_CONTEXT as M, defineContext as Mt, Radix as N, defineHook as Nt, PARAMETER as O, Output as Ot, ResponseConfig as P, isFailure as Pt, invoke as Q, RouterContext as R, OPTIONAL_PARAMETER as S, Hookable as St, OPTIONAL_WILDCARD_MATCH as T, Invoke as Tt, States as U, Server as V, StatusCode as W, defineRoute as X, defineMiddleware as Y, getState as Z, Encoding as _, useUrl as _t, Config as a, sendJson as at, MimeType as b, Descriptor as bt, Environment as c, sendUnauthorized as ct, Source as d, useCookies as dt, isServer as et, Template as f, useHeaders as ft, CookieSameSite as g, useSetCookies as gt, CookiePriority as h, useServer as ht, CLIENT as i, sendHtml as it, PathNode as j, Success as jt, PARAMETER_MATCH as k, Schema as kt, Module as l, setCookie as lt, CookieOptions as m, useRouter as mt, App as n, mimeTypes as nt, Content as o, sendRedirect as ot, Virtual as p, useQuery as pt, WildcardNode as q, BuildConfig as r, sendBadRequest as rt, DevelopmentConfig as s, sendText as st, $fetch as t, mimeType as tt, SERVER as u, setState as ut, HttpMethod as v, withQuery as vt, OPTIONAL_WILDCARD as w, InferOutput as wt, Node as x, Failure as xt, Middleware as y, Context as yt, SERVER_CONTEXT as z };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, Hookable, HttpMethod, InferInput, InferOutput, Invoke, Issue, Mergeable, Middleware, MimeType, Module, Node, Output, PARAMETER, ParameterNode, PathNode, ROUTER_CONTEXT, Radix, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, STATES, Schema, Scope, Server, ServerContext, Source, States, StatusCode, Success, Virtual, WILDCARD, WildcardNode, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery } from "./index-DSP2l2h5.js";
2
- export { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, Hookable, HttpMethod, InferInput, InferOutput, Invoke, Issue, Mergeable, Middleware, MimeType, Module, Node, Output, PARAMETER, ParameterNode, PathNode, ROUTER_CONTEXT, Radix, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, STATES, Schema, Scope, Server, ServerContext, Source, States, StatusCode, Success, Virtual, WILDCARD, WildcardNode, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
1
+ import { $ as isClient, A as ParameterNode, At as Scope, B as STATES, C as OPTIONAL_PARAMETER_MATCH, Ct as InferInput, D as OptionalWildcardNode, Dt as Mergeable, E as OptionalParameterNode, Et as Issue, F as Result, Ft as mergeObjects, G as WILDCARD, H as ServerContext, I as Route, It as parseSchema, J as createServer, K as WILDCARD_MATCH, L as Router, M as ROUTER_CONTEXT, Mt as defineContext, N as Radix, Nt as defineHook, O as PARAMETER, Ot as Output, P as ResponseConfig, Pt as isFailure, Q as invoke, R as RouterContext, S as OPTIONAL_PARAMETER, St as Hookable, T as OPTIONAL_WILDCARD_MATCH, Tt as Invoke, U as States, V as Server, W as StatusCode, X as defineRoute, Y as defineMiddleware, Z as getState, _ as Encoding, _t as useUrl, a as Config, at as sendJson, b as MimeType, bt as Descriptor, c as Environment, ct as sendUnauthorized, d as Source, dt as useCookies, et as isServer, f as Template, ft as useHeaders, g as CookieSameSite, gt as useSetCookies, h as CookiePriority, ht as useServer, i as CLIENT, it as sendHtml, j as PathNode, jt as Success, k as PARAMETER_MATCH, kt as Schema, l as Module, lt as setCookie, m as CookieOptions, mt as useRouter, n as App, nt as mimeTypes, o as Content, ot as sendRedirect, p as Virtual, pt as useQuery, q as WildcardNode, r as BuildConfig, rt as sendBadRequest, s as DevelopmentConfig, st as sendText, t as $fetch, tt as mimeType, u as SERVER, ut as setState, v as HttpMethod, vt as withQuery, w as OPTIONAL_WILDCARD, wt as InferOutput, x as Node, xt as Failure, y as Middleware, yt as Context, z as SERVER_CONTEXT } from "./index-NJXRiTAn.js";
2
+ export { $fetch, App, BuildConfig, CLIENT, Config, Content, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, Hookable, HttpMethod, InferInput, InferOutput, Invoke, Issue, Mergeable, Middleware, MimeType, Module, Node, OPTIONAL_PARAMETER, OPTIONAL_PARAMETER_MATCH, OPTIONAL_WILDCARD, OPTIONAL_WILDCARD_MATCH, OptionalParameterNode, OptionalWildcardNode, Output, PARAMETER, PARAMETER_MATCH, ParameterNode, PathNode, ROUTER_CONTEXT, Radix, ResponseConfig, Result, Route, Router, RouterContext, SERVER, SERVER_CONTEXT, STATES, Schema, Scope, Server, ServerContext, Source, States, StatusCode, Success, Template, Virtual, WILDCARD, WILDCARD_MATCH, WildcardNode, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { App, CLIENT, Hookable, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope, WILDCARD, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery } from "./app-COQSSDHs.js";
1
+ import { A as isServer, B as setState, C as WILDCARD_MATCH, D as getState, E as defineRoute, F as sendJson, G as useServer, H as useHeaders, I as sendRedirect, J as withQuery, K as useSetCookies, L as sendText, M as mimeTypes, N as sendBadRequest, O as invoke, P as sendHtml, R as sendUnauthorized, S as WILDCARD, T as defineMiddleware, U as useQuery, V as useCookies, W as useRouter, _ as ROUTER_CONTEXT, a as Scope, b as SERVER_CONTEXT, c as isFailure, d as OPTIONAL_PARAMETER, f as OPTIONAL_PARAMETER_MATCH, g as PARAMETER_MATCH, h as PARAMETER, i as Hookable, j as mimeType, k as isClient, l as mergeObjects, m as OPTIONAL_WILDCARD_MATCH, n as CLIENT, o as defineContext, p as OPTIONAL_WILDCARD, q as useUrl, r as SERVER, s as defineHook, t as App, u as parseSchema, v as Radix, w as createServer, x as STATES, y as Router, z as setCookie } from "./app-B3x9-FYe.js";
2
2
 
3
3
  //#region src/client/index.ts
4
4
  async function $fetch(scope, input, options) {
@@ -25,4 +25,4 @@ async function $fetch(scope, input, options) {
25
25
  }
26
26
 
27
27
  //#endregion
28
- export { $fetch, App, CLIENT, Hookable, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope, WILDCARD, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
28
+ export { $fetch, App, CLIENT, 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, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
@@ -1,4 +1,4 @@
1
- import { App, Virtual } from "../index-DSP2l2h5.js";
1
+ import { n as App, o as Content, p as Virtual } from "../index-NJXRiTAn.js";
2
2
 
3
3
  //#region src/kit/index.d.ts
4
4
  declare function useKit(source: string | URL): {
@@ -6,6 +6,7 @@ declare function useKit(source: string | URL): {
6
6
  };
7
7
  declare function addAlias(app: App, name: string, path: string): void;
8
8
  declare function addVirtual(app: App, name: string, virtual: Virtual): void;
9
+ declare function addTypes(app: App, name: string, types: Content): void;
9
10
  declare function addRoutes(app: App, path: string): void;
10
11
  //#endregion
11
- export { addAlias, addRoutes, addVirtual, useKit };
12
+ export { addAlias, addRoutes, addTypes, addVirtual, useKit };
package/dist/kit/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { addAlias, addRoutes, addVirtual, useKit } from "../kit-CUuTaZz2.js";
1
+ import { a as useKit, i as addVirtual, n as addRoutes, r as addTypes, t as addAlias } from "../kit-BQv19une.js";
2
2
 
3
- export { addAlias, addRoutes, addVirtual, useKit };
3
+ export { addAlias, addRoutes, addTypes, addVirtual, useKit };
@@ -15,9 +15,12 @@ function addAlias(app, name, path) {
15
15
  function addVirtual(app, name, virtual) {
16
16
  app.config.build.virtuals["#virtual/" + name] = virtual;
17
17
  }
18
+ function addTypes(app, name, types) {
19
+ app.config.build.types[name] = types;
20
+ }
18
21
  function addRoutes(app, path) {
19
22
  app.config.sources.routes?.entries.push(path);
20
23
  }
21
24
 
22
25
  //#endregion
23
- export { addAlias, addRoutes, addVirtual, useKit };
26
+ export { useKit as a, addVirtual as i, addRoutes as n, addTypes as r, addAlias as t };
@@ -1,4 +1,4 @@
1
- import { Config, Mergeable } from "../index-DSP2l2h5.js";
1
+ import { Dt as Mergeable, a as Config } from "../index-NJXRiTAn.js";
2
2
  import { Plugin } from "vite";
3
3
 
4
4
  //#region src/vite/index.d.ts
@@ -1,13 +1,18 @@
1
- import { App, CLIENT, SERVER, SERVER_CONTEXT, Scope, invoke } from "../app-COQSSDHs.js";
2
- import { addVirtual } from "../kit-CUuTaZz2.js";
3
- import { basename, dirname, isAbsolute, join, posix, relative, resolve, win32 } from "path";
1
+ import { O as invoke, a as Scope, b as SERVER_CONTEXT, n as CLIENT, r as SERVER, t as App } from "../app-B3x9-FYe.js";
2
+ import { a as useKit, i as addVirtual } from "../kit-BQv19une.js";
3
+ import { basename, isAbsolute, join, posix, resolve, win32 } from "path";
4
+ import { mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
5
+ import { cwd } from "process";
6
+ import { globSync } from "tinyglobby";
4
7
  import { isRunnableDevEnvironment } from "vite";
5
8
  import { once } from "events";
6
9
  import { Readable, Stream } from "stream";
7
- import { existsSync, readFileSync } from "fs";
8
- import { globSync } from "tinyglobby";
9
- import { rm } from "fs/promises";
10
10
 
11
+ //#region package.json
12
+ var name = "revojs";
13
+ var version = "0.1.24";
14
+
15
+ //#endregion
11
16
  //#region src/vite/node/index.ts
12
17
  function splitSetCookieString(cookiesString) {
13
18
  if (Array.isArray(cookiesString)) return cookiesString.flatMap((c) => splitSetCookieString(c));
@@ -191,89 +196,6 @@ function client() {
191
196
  };
192
197
  }
193
198
 
194
- //#endregion
195
- //#region src/vite/plugins/css.ts
196
- function css() {
197
- let devServer;
198
- const styles = new Array();
199
- return {
200
- name: "css",
201
- apply: "serve",
202
- configureServer(server) {
203
- devServer = server;
204
- },
205
- transform(_, source) {
206
- if (source.match(/\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/)) {
207
- if (!styles.includes(source) && !source.includes("?") && !source.includes(".node_modules") && !source.includes("@vite")) styles.push(relative(devServer.config.root, source));
208
- }
209
- },
210
- transformIndexHtml() {
211
- return [...styles.map((path) => ({
212
- tag: "link",
213
- injectTo: "head",
214
- attrs: {
215
- rel: "stylesheet",
216
- href: "/" + path,
217
- "data-preload": true
218
- }
219
- })), {
220
- tag: "script",
221
- injectTo: "head",
222
- attrs: { type: "module" },
223
- children: `
224
- const observer = new MutationObserver(() => {
225
- if (document.querySelector('style[data-vite-dev-id]')) {
226
- document.querySelectorAll('[data-preload]').forEach((node) => node.remove());
227
-
228
- observer.disconnect();
229
- }
230
- });
231
-
232
- observer.observe(document.head, { childList: true });
233
- `
234
- }];
235
- }
236
- };
237
- }
238
-
239
- //#endregion
240
- //#region src/vite/plugins/entry.ts
241
- function entry() {
242
- let entryName;
243
- let entryPath;
244
- return {
245
- name: "entry",
246
- enforce: "pre",
247
- sharedDuringBuild: true,
248
- resolveId: {
249
- filter: { id: /\.html$/ },
250
- handler(source, importer, options) {
251
- if (this.environment.name === CLIENT) {
252
- if (importer && entryPath) {
253
- const path = join(dirname(importer), source);
254
- if (existsSync(path)) return path;
255
- }
256
- if (options.isEntry) {
257
- entryName = basename(source);
258
- entryPath = source;
259
- return entryName;
260
- }
261
- }
262
- }
263
- },
264
- load: {
265
- filter: { id: /\.html$/ },
266
- handler(source) {
267
- if (entryName && entryPath && source === entryName) return readFileSync(entryPath, {
268
- encoding: "utf-8",
269
- flag: "r"
270
- });
271
- return null;
272
- }
273
- }
274
- };
275
- }
276
-
277
199
  //#endregion
278
200
  //#region src/vite/plugins/virtuals.ts
279
201
  function virtuals(virtuals$1) {
@@ -282,7 +204,7 @@ function virtuals(virtuals$1) {
282
204
  name: "virtuals",
283
205
  enforce: "pre",
284
206
  sharedDuringBuild: true,
285
- resolveId(key, importer) {
207
+ resolveId(key) {
286
208
  if (cache.has(key)) return key;
287
209
  if (key.startsWith("#")) {
288
210
  const path = "/" + key.slice(1);
@@ -304,13 +226,27 @@ function virtuals(virtuals$1) {
304
226
  };
305
227
  }
306
228
 
307
- //#endregion
308
- //#region package.json
309
- var name = "revojs";
310
- var version = "0.1.23";
311
-
312
229
  //#endregion
313
230
  //#region src/vite/index.ts
231
+ function toHtmlTagDescriptor(template, injectTo) {
232
+ let children;
233
+ for (const entry of template.children) {
234
+ if (typeof entry === "string") {
235
+ children ??= "";
236
+ if (typeof children === "string") children += entry;
237
+ }
238
+ if (typeof entry === "object") {
239
+ children ??= [];
240
+ if (Array.isArray(children)) children.push(toHtmlTagDescriptor(entry, injectTo));
241
+ }
242
+ }
243
+ return {
244
+ tag: template.tagName,
245
+ attrs: template.attributes,
246
+ children,
247
+ injectTo
248
+ };
249
+ }
314
250
  function revojs(config) {
315
251
  const app = new App(config);
316
252
  return [
@@ -319,9 +255,14 @@ function revojs(config) {
319
255
  version,
320
256
  sharedDuringBuild: true,
321
257
  async config() {
258
+ const { fromModule } = useKit(cwd());
322
259
  for (const module of app.config.modules) await module.setup?.(app);
323
- if (app.config.client) addVirtual(app, "client", () => `import client from "${app.config.client}?client"; export default client`);
324
- if (app.config.server) addVirtual(app, "server", () => `import { createServer } from "revojs"; export default await createServer()`);
260
+ addVirtual(app, "client", () => {
261
+ if (app.config.client) return `import client from "${fromModule(app.config.client)}?client"; export default client`;
262
+ });
263
+ addVirtual(app, "server", () => {
264
+ if (app.config.server) return `import { createServer } from "revojs"; export default await createServer()`;
265
+ });
325
266
  for (const name$1 in app.config.sources) {
326
267
  const source = app.config.sources[name$1];
327
268
  addVirtual(app, name$1, () => {
@@ -330,13 +271,21 @@ function revojs(config) {
330
271
  path = isAbsolute(path) ? path : resolve(path);
331
272
  for (const asset of globSync(source.match, { cwd: path })) entries[asset] = join(path, asset).split(win32.sep).join(posix.sep);
332
273
  }
333
- const content = Object.values(entries).reduce((content$1, path, index) => content$1 + `import $${index} from "${source.resolve?.(path) ?? path}" \n`, "");
334
- const result = Object.keys(entries).map((name$2, index) => {
274
+ return `${Object.values(entries).reduce((content, path, index) => content + `import $${index} from "${source.resolve?.(path) ?? path}" \n`, "")} export default {${Object.keys(entries).map((name$2, index) => {
335
275
  if (entries[name$2]) return `"${name$2}": $${index}`;
336
- });
337
- return `${content} export default {${result}}`;
276
+ })}}`;
338
277
  });
339
278
  }
279
+ const metaTypesPath = join(resolve(".revojs"), "types");
280
+ rmSync(metaTypesPath, {
281
+ recursive: true,
282
+ force: true
283
+ });
284
+ mkdirSync(metaTypesPath, { recursive: true });
285
+ for (const type in app.config.build.types) {
286
+ const content = app.config.build.types[type];
287
+ writeFileSync(join(metaTypesPath, type), content());
288
+ }
340
289
  return {
341
290
  appType: "custom",
342
291
  optimizeDeps: { exclude: ["revojs"] },
@@ -349,14 +298,14 @@ function revojs(config) {
349
298
  builder: {
350
299
  sharedConfigBuild: true,
351
300
  async buildApp(builder) {
352
- await rm("./dist", {
301
+ rmSync("./dist", {
353
302
  recursive: true,
354
303
  force: true
355
304
  });
356
305
  for (const key in builder.environments) {
357
306
  const environment = builder.environments[key];
358
307
  await builder.build(environment);
359
- if (environment.name === CLIENT && typeof environment.config.build.rollupOptions.input === "string") await rm(resolve(environment.config.build.outDir, basename(environment.config.build.rollupOptions.input)));
308
+ if (environment.name === CLIENT && typeof environment.config.build.rollupOptions.input === "string") rmSync(resolve(environment.config.build.outDir, basename(environment.config.build.rollupOptions.input)));
360
309
  }
361
310
  }
362
311
  },
@@ -394,6 +343,17 @@ function revojs(config) {
394
343
  }
395
344
  };
396
345
  },
346
+ transformIndexHtml: {
347
+ order: "pre",
348
+ handler() {
349
+ const entries = new Array();
350
+ const head = toHtmlTagDescriptor(app.config.template.head, "head");
351
+ if (Array.isArray(head.children)) entries.push(...head.children);
352
+ const body = toHtmlTagDescriptor(app.config.template.body, "body");
353
+ if (Array.isArray(body.children)) entries.push(...body.children);
354
+ return entries;
355
+ }
356
+ },
397
357
  configResolved(config$1) {
398
358
  if (app.config.client === void 0) delete config$1.environments[CLIENT];
399
359
  if (app.config.server === void 0) delete config$1.environments[SERVER];
@@ -421,9 +381,7 @@ function revojs(config) {
421
381
  }
422
382
  },
423
383
  virtuals(app.config.build.virtuals),
424
- client(),
425
- entry(),
426
- css()
384
+ client()
427
385
  ];
428
386
  }
429
387
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",