revojs 0.1.23 → 0.1.25
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.
- package/dist/{app-COQSSDHs.js → app-DOdfHYPa.js} +84 -24
- package/dist/{index-DSP2l2h5.d.ts → index-xe4wwpuC.d.ts} +36 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/kit/index.d.ts +3 -2
- package/dist/kit/index.js +2 -2
- package/dist/{kit-CUuTaZz2.js → kit-BQv19une.js} +4 -1
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +88 -124
- package/package.json +1 -1
|
@@ -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(
|
|
10
|
+
use(segments, value) {
|
|
11
11
|
let node = this.rootNode;
|
|
12
|
-
for (const
|
|
13
|
-
|
|
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:
|
|
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
|
-
|
|
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:
|
|
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[
|
|
61
|
+
let childNode = node.children[next];
|
|
36
62
|
childNode ??= {
|
|
37
63
|
type: "PATH",
|
|
38
64
|
children: {}
|
|
39
65
|
};
|
|
40
|
-
node.children[
|
|
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
|
-
|
|
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
|
|
219
|
-
|
|
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
|
|
239
|
-
|
|
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: { "revojs.d.ts": () => `import "revojs/types"` },
|
|
374
433
|
virtuals: {},
|
|
375
434
|
alias: {}
|
|
376
435
|
}
|
|
@@ -380,6 +439,7 @@ var App = class extends Hookable {
|
|
|
380
439
|
};
|
|
381
440
|
const SERVER = "ssr";
|
|
382
441
|
const CLIENT = "client";
|
|
442
|
+
const CLOSE_HOOK = defineHook("CLOSE_HOOK");
|
|
383
443
|
|
|
384
444
|
//#endregion
|
|
385
|
-
export {
|
|
445
|
+
export { isClient as A, setCookie as B, WILDCARD as C, defineRoute as D, defineMiddleware as E, sendHtml as F, useRouter as G, useCookies as H, sendJson as I, useUrl as J, useServer as K, sendRedirect as L, mimeType as M, mimeTypes as N, getState as O, sendBadRequest as P, sendText as R, STATES as S, createServer as T, useHeaders as U, setState as V, useQuery as W, withQuery as Y, PARAMETER_MATCH as _, Hookable as a, Router as b, defineHook as c, parseSchema as d, OPTIONAL_PARAMETER as f, PARAMETER as g, OPTIONAL_WILDCARD_MATCH as h, SERVER as i, isServer as j, invoke as k, isFailure as l, OPTIONAL_WILDCARD as m, CLIENT as n, Scope as o, OPTIONAL_PARAMETER_MATCH as p, useSetCookies as q, CLOSE_HOOK as r, defineContext as s, App as t, mergeObjects as u, ROUTER_CONTEXT as v, WILDCARD_MATCH as w, SERVER_CONTEXT as x, Radix as y, sendUnauthorized 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> = { [
|
|
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(
|
|
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
|
|
151
|
-
declare
|
|
152
|
-
declare const
|
|
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;
|
|
@@ -187,8 +212,9 @@ declare class App extends Hookable {
|
|
|
187
212
|
}
|
|
188
213
|
declare const SERVER = "ssr";
|
|
189
214
|
declare const CLIENT = "client";
|
|
215
|
+
declare const CLOSE_HOOK: Descriptor<() => void>;
|
|
190
216
|
//#endregion
|
|
191
217
|
//#region src/client/index.d.ts
|
|
192
218
|
declare function $fetch<T>(scope: Scope, input: string | URL, options?: RequestInit): Promise<T>;
|
|
193
219
|
//#endregion
|
|
194
|
-
export {
|
|
220
|
+
export { invoke as $, PARAMETER_MATCH as A, Schema as At, SERVER_CONTEXT as B, OPTIONAL_PARAMETER as C, Hookable as Ct, OptionalParameterNode as D, Issue as Dt, OPTIONAL_WILDCARD_MATCH as E, Invoke as Et, ResponseConfig as F, isFailure as Ft, StatusCode as G, Server as H, Result as I, mergeObjects as It, WildcardNode as J, WILDCARD as K, Route as L, parseSchema as Lt, PathNode as M, Success as Mt, ROUTER_CONTEXT as N, defineContext as Nt, OptionalWildcardNode as O, Mergeable as Ot, Radix as P, defineHook as Pt, getState as Q, Router as R, Node as S, Failure as St, OPTIONAL_WILDCARD as T, InferOutput as Tt, ServerContext as U, STATES as V, States as W, defineMiddleware as X, createServer as Y, defineRoute as Z, CookieSameSite as _, useSetCookies as _t, CLOSE_HOOK as a, sendHtml as at, Middleware as b, Context as bt, DevelopmentConfig as c, sendText as ct, SERVER as d, setState as dt, isClient as et, Source as f, useCookies as ft, CookiePriority as g, useServer as gt, CookieOptions as h, useRouter as ht, CLIENT as i, sendBadRequest as it, ParameterNode as j, Scope as jt, PARAMETER as k, Output as kt, Environment as l, sendUnauthorized as lt, Virtual as m, useQuery as mt, App as n, mimeType as nt, Config as o, sendJson as ot, Template as p, useHeaders as pt, WILDCARD_MATCH as q, BuildConfig as r, mimeTypes as rt, Content as s, sendRedirect as st, $fetch as t, isServer as tt, Module as u, setCookie as ut, Encoding as v, useUrl as vt, OPTIONAL_PARAMETER_MATCH as w, InferInput as wt, MimeType as x, Descriptor as xt, HttpMethod as y, withQuery as yt, RouterContext as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $
|
|
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,
|
|
1
|
+
import { $ as invoke, A as PARAMETER_MATCH, At as Schema, B as SERVER_CONTEXT, C as OPTIONAL_PARAMETER, Ct as Hookable, D as OptionalParameterNode, Dt as Issue, E as OPTIONAL_WILDCARD_MATCH, Et as Invoke, F as ResponseConfig, Ft as isFailure, G as StatusCode, H as Server, I as Result, It as mergeObjects, J as WildcardNode, K as WILDCARD, L as Route, Lt as parseSchema, M as PathNode, Mt as Success, N as ROUTER_CONTEXT, Nt as defineContext, O as OptionalWildcardNode, Ot as Mergeable, P as Radix, Pt as defineHook, Q as getState, R as Router, S as Node, St as Failure, T as OPTIONAL_WILDCARD, Tt as InferOutput, U as ServerContext, V as STATES, W as States, X as defineMiddleware, Y as createServer, Z as defineRoute, _ as CookieSameSite, _t as useSetCookies, a as CLOSE_HOOK, at as sendHtml, b as Middleware, bt as Context, c as DevelopmentConfig, ct as sendText, d as SERVER, dt as setState, et as isClient, f as Source, ft as useCookies, g as CookiePriority, gt as useServer, h as CookieOptions, ht as useRouter, i as CLIENT, it as sendBadRequest, j as ParameterNode, jt as Scope, k as PARAMETER, kt as Output, l as Environment, lt as sendUnauthorized, m as Virtual, mt as useQuery, n as App, nt as mimeType, o as Config, ot as sendJson, p as Template, pt as useHeaders, q as WILDCARD_MATCH, r as BuildConfig, rt as mimeTypes, s as Content, st as sendRedirect, t as $fetch, tt as isServer, u as Module, ut as setCookie, v as Encoding, vt as useUrl, w as OPTIONAL_PARAMETER_MATCH, wt as InferInput, x as MimeType, xt as Descriptor, y as HttpMethod, yt as withQuery, z as RouterContext } from "./index-xe4wwpuC.js";
|
|
2
|
+
export { $fetch, App, BuildConfig, 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, 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 {
|
|
1
|
+
import { A as isClient, B as setCookie, C as WILDCARD, D as defineRoute, E as defineMiddleware, F as sendHtml, G as useRouter, H as useCookies, I as sendJson, J as useUrl, K as useServer, L as sendRedirect, M as mimeType, N as mimeTypes, O as getState, P as sendBadRequest, R as sendText, S as STATES, T as createServer, U as useHeaders, V as setState, W as useQuery, Y as withQuery, _ as PARAMETER_MATCH, a as Hookable, b as Router, c as defineHook, d as parseSchema, f as OPTIONAL_PARAMETER, g as PARAMETER, h as OPTIONAL_WILDCARD_MATCH, i as SERVER, j as isServer, k as invoke, l as isFailure, m as OPTIONAL_WILDCARD, n as CLIENT, o as Scope, p as OPTIONAL_PARAMETER_MATCH, q as useSetCookies, r as CLOSE_HOOK, s as defineContext, t as App, u as mergeObjects, v as ROUTER_CONTEXT, w as WILDCARD_MATCH, x as SERVER_CONTEXT, y as Radix, z as sendUnauthorized } from "./app-DOdfHYPa.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,
|
|
28
|
+
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, 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/kit/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { App,
|
|
1
|
+
import { m as Virtual, n as App, s as Content } from "../index-xe4wwpuC.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 {
|
|
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 {
|
|
26
|
+
export { useKit as a, addVirtual as i, addRoutes as n, addTypes as r, addAlias as t };
|
package/dist/vite/index.d.ts
CHANGED
package/dist/vite/index.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { addVirtual } from "../kit-
|
|
3
|
-
import { basename,
|
|
1
|
+
import { i as SERVER, k as invoke, n as CLIENT, o as Scope, r as CLOSE_HOOK, t as App, x as SERVER_CONTEXT } from "../app-DOdfHYPa.js";
|
|
2
|
+
import { a as useKit, i as addVirtual, r as addTypes } 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.25";
|
|
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
|
|
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,15 @@ 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
|
-
|
|
324
|
-
|
|
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
|
+
});
|
|
266
|
+
addTypes(app, "vite.d.ts", () => `import "vite/client"`);
|
|
325
267
|
for (const name$1 in app.config.sources) {
|
|
326
268
|
const source = app.config.sources[name$1];
|
|
327
269
|
addVirtual(app, name$1, () => {
|
|
@@ -330,13 +272,23 @@ function revojs(config) {
|
|
|
330
272
|
path = isAbsolute(path) ? path : resolve(path);
|
|
331
273
|
for (const asset of globSync(source.match, { cwd: path })) entries[asset] = join(path, asset).split(win32.sep).join(posix.sep);
|
|
332
274
|
}
|
|
333
|
-
|
|
334
|
-
const result = Object.keys(entries).map((name$2, index) => {
|
|
275
|
+
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
276
|
if (entries[name$2]) return `"${name$2}": $${index}`;
|
|
336
|
-
})
|
|
337
|
-
return `${content} export default {${result}}`;
|
|
277
|
+
})}}`;
|
|
338
278
|
});
|
|
339
279
|
}
|
|
280
|
+
const metaPath = resolve(".revojs");
|
|
281
|
+
rmSync(metaPath, {
|
|
282
|
+
recursive: true,
|
|
283
|
+
force: true
|
|
284
|
+
});
|
|
285
|
+
mkdirSync(metaPath, { recursive: true });
|
|
286
|
+
let types = "";
|
|
287
|
+
for (const type in app.config.build.types) {
|
|
288
|
+
const content = app.config.build.types[type];
|
|
289
|
+
types += content() + "\n";
|
|
290
|
+
}
|
|
291
|
+
writeFileSync(join(metaPath, "index.d.ts"), types);
|
|
340
292
|
return {
|
|
341
293
|
appType: "custom",
|
|
342
294
|
optimizeDeps: { exclude: ["revojs"] },
|
|
@@ -349,14 +301,14 @@ function revojs(config) {
|
|
|
349
301
|
builder: {
|
|
350
302
|
sharedConfigBuild: true,
|
|
351
303
|
async buildApp(builder) {
|
|
352
|
-
|
|
304
|
+
rmSync("./dist", {
|
|
353
305
|
recursive: true,
|
|
354
306
|
force: true
|
|
355
307
|
});
|
|
356
308
|
for (const key in builder.environments) {
|
|
357
309
|
const environment = builder.environments[key];
|
|
358
310
|
await builder.build(environment);
|
|
359
|
-
if (environment.name === CLIENT && typeof environment.config.build.rollupOptions.input === "string")
|
|
311
|
+
if (environment.name === CLIENT && typeof environment.config.build.rollupOptions.input === "string") rmSync(resolve(environment.config.build.outDir, basename(environment.config.build.rollupOptions.input)));
|
|
360
312
|
}
|
|
361
313
|
}
|
|
362
314
|
},
|
|
@@ -394,36 +346,48 @@ function revojs(config) {
|
|
|
394
346
|
}
|
|
395
347
|
};
|
|
396
348
|
},
|
|
349
|
+
transformIndexHtml: {
|
|
350
|
+
order: "pre",
|
|
351
|
+
handler() {
|
|
352
|
+
const entries = new Array();
|
|
353
|
+
const head = toHtmlTagDescriptor(app.config.template.head, "head");
|
|
354
|
+
if (Array.isArray(head.children)) entries.push(...head.children);
|
|
355
|
+
const body = toHtmlTagDescriptor(app.config.template.body, "body");
|
|
356
|
+
if (Array.isArray(body.children)) entries.push(...body.children);
|
|
357
|
+
return entries;
|
|
358
|
+
}
|
|
359
|
+
},
|
|
397
360
|
configResolved(config$1) {
|
|
398
361
|
if (app.config.client === void 0) delete config$1.environments[CLIENT];
|
|
399
362
|
if (app.config.server === void 0) delete config$1.environments[SERVER];
|
|
400
363
|
},
|
|
401
364
|
async configureServer(devServer) {
|
|
402
365
|
const target = devServer.environments[SERVER];
|
|
403
|
-
if (isRunnableDevEnvironment(target))
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
366
|
+
if (isRunnableDevEnvironment(target)) {
|
|
367
|
+
process.on("exit", () => app.dispatchHook(CLOSE_HOOK));
|
|
368
|
+
return () => {
|
|
369
|
+
devServer.middlewares.use(async (request, response, next) => {
|
|
370
|
+
const server = await target.runner.import("#virtual/server").then((module) => module.default);
|
|
371
|
+
if (server) {
|
|
372
|
+
request.url = request.originalUrl;
|
|
373
|
+
const scope = new Scope();
|
|
374
|
+
scope.setContext(SERVER_CONTEXT, {
|
|
375
|
+
states: {},
|
|
376
|
+
request: fromNodeRequest(request, response),
|
|
377
|
+
response: { headers: new Headers() },
|
|
378
|
+
variables: process.env
|
|
379
|
+
});
|
|
380
|
+
var result = await invoke(scope, app.config.development.middlewares.concat({ fetch: server.fetch }));
|
|
381
|
+
if (result) await toNodeRequest(result, response);
|
|
382
|
+
}
|
|
383
|
+
next();
|
|
384
|
+
});
|
|
385
|
+
};
|
|
386
|
+
}
|
|
421
387
|
}
|
|
422
388
|
},
|
|
423
389
|
virtuals(app.config.build.virtuals),
|
|
424
|
-
client()
|
|
425
|
-
entry(),
|
|
426
|
-
css()
|
|
390
|
+
client()
|
|
427
391
|
];
|
|
428
392
|
}
|
|
429
393
|
|