revojs 0.1.17 → 0.1.19

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/index.d.ts CHANGED
@@ -1,198 +1,2 @@
1
- //#region src/shared/index.d.ts
2
- type Descriptor<T> = string & {
3
- [descriptor]: T;
4
- };
5
- type Context = Record<string, unknown>;
6
- type Output<T> = Success<T> | Failure;
7
- type InferInput<T extends Schema> = NonNullable<T["~standard"]["types"]>["input"];
8
- type InferOutput<T extends Schema> = NonNullable<T["~standard"]["types"]>["output"];
9
- type Mergeable<T> = { [P in keyof T]?: Mergeable<T[P]> };
10
- interface Issue {
11
- readonly message: string;
12
- }
13
- interface Success<T> {
14
- readonly value: T;
15
- }
16
- interface Failure {
17
- readonly issues: ReadonlyArray<Issue>;
18
- }
19
- interface Schema<T = unknown, TOutput = T> {
20
- readonly "~standard": {
21
- readonly validate: (value: unknown) => Output<TOutput> | Promise<Output<TOutput>>;
22
- readonly types?: {
23
- readonly input: T;
24
- readonly output: TOutput;
25
- };
26
- };
27
- }
28
- declare class StopEvent extends Event {
29
- constructor();
30
- }
31
- declare class Scope extends EventTarget {
32
- parentScope?: Scope;
33
- readonly context: Context;
34
- constructor(parentScope?: Scope);
35
- getContext<T>(input: Descriptor<T>): T;
36
- setContext<T>(input: Descriptor<T>, value: T): void;
37
- onStop(input: (event: StopEvent) => void): void;
38
- stop(): boolean;
39
- }
40
- declare function defineContext<T>(name: string): Descriptor<T>;
41
- declare function isFailure<T>(result: Output<T>): result is Failure;
42
- declare function parseSchema<T extends Schema>(scope: Scope, schema: T, value: unknown): InferOutput<T>;
43
- declare function mergeObjects<TBase, TInput>(base: TBase, input: TInput): TBase & TInput;
44
- declare const descriptor: unique symbol;
45
- declare global {
46
- interface ElementEventMap {
47
- stop: StopEvent;
48
- }
49
- }
50
- //#endregion
51
- //#region src/server/index.d.ts
52
- type CookiePriority = "Low" | "Medium" | "High";
53
- type CookieSameSite = "Lax" | "Strict" | "None";
54
- type HttpMethod = "GET" | "HEAD" | "PATCH" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE";
55
- type Encoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex";
56
- 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;
57
- 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";
58
- type Result = void | Response | Promise<void | Response>;
59
- type Node<T> = WildcardNode<T> | ParameterNode<T> | PathNode<T>;
60
- type States = Record<string, unknown>;
61
- interface CookieOptions {
62
- domain?: string;
63
- expires?: Date;
64
- httpOnly?: boolean;
65
- maxAge?: number;
66
- path?: string;
67
- priority?: CookiePriority;
68
- sameSite?: CookieSameSite;
69
- secure?: boolean;
70
- }
71
- interface ResponseConfig {
72
- status?: StatusCode;
73
- message?: string;
74
- headers: Headers;
75
- }
76
- interface RouterContext {
77
- route: Node<Route>;
78
- segments: Array<string>;
79
- parameters: Record<string, string>;
80
- }
81
- interface ServerContext<T extends Context = Context> {
82
- states: States;
83
- request: Request;
84
- response: ResponseConfig;
85
- variables: T;
86
- }
87
- interface Route {
88
- fetch: (scope: Scope) => Result;
89
- }
90
- interface Middleware {
91
- fetch: (scope: Scope, next?: () => Result) => Result;
92
- }
93
- interface Exception {
94
- fetch: (scope: Scope, exception: unknown) => Result;
95
- }
96
- interface Server {
97
- router: Router;
98
- middlewares: Array<Middleware>;
99
- fetch: (scope: Scope) => Promise<Response>;
100
- }
101
- interface WildcardNode<T> {
102
- type: "WILDCARD";
103
- value?: T;
104
- parameter: string;
105
- children: Record<string, Node<T>>;
106
- }
107
- interface ParameterNode<T> {
108
- type: "PARAMETER";
109
- value?: T;
110
- parameter: string;
111
- children: Record<string, Node<T>>;
112
- }
113
- interface PathNode<T> {
114
- type: "PATH";
115
- value?: T;
116
- children: Record<string, Node<T>>;
117
- }
118
- declare class Radix<T> {
119
- readonly rootNode: Node<T>;
120
- constructor();
121
- use(path: string, value: T): Node<T>;
122
- }
123
- declare class Router extends Radix<Route> implements Middleware {
124
- fetch(scope: Scope, next?: () => Result): Result;
125
- }
126
- declare function defineRoute<T extends Route>(route: T): T;
127
- declare function defineMiddleware<T extends Middleware>(middleware: T): T;
128
- declare function defineException<T extends Exception>(exception: T): T;
129
- declare function useRouter(scope: Scope): RouterContext;
130
- declare function useServer<T extends Context>(scope: Scope): ServerContext<T>;
131
- declare function useUrl(scope: Scope, base?: string): URL;
132
- declare function useHeaders(scope: Scope): Headers;
133
- declare function useQuery(scope: Scope): Record<string, string>;
134
- declare function useQuery<T extends Schema>(scope: Scope, schema: T): InferOutput<T>;
135
- declare function withQuery(input: string, query: Record<string, string>): string;
136
- declare function useCookies(scope: Scope): Record<string, string>;
137
- declare function useCookies<T extends Schema>(scope: Scope, schema: T): InferOutput<T>;
138
- declare function useSetCookies(scope: Scope): Record<string, string>;
139
- declare function useSetCookies<T extends Schema>(scope: Scope, schema: T): InferOutput<T>;
140
- declare function setCookie(scope: Scope, name: string, value: string, options?: CookieOptions): void;
141
- declare function getState<T>(scope: Scope, name: string): T;
142
- declare function setState<T>(scope: Scope, name: string, value: T): void;
143
- declare function sendText(scope: Scope, text: string, config?: Mergeable<ResponseConfig>): Response;
144
- declare function sendHtml(scope: Scope, text: string, config?: Mergeable<ResponseConfig>): Response;
145
- declare function sendJson<T>(scope: Scope, value: T, config?: Mergeable<ResponseConfig>): Response;
146
- declare function sendRedirect(scope: Scope, path: string, config?: Mergeable<ResponseConfig>): Response;
147
- declare function sendBadRequest(scope: Scope, text: string, config?: Mergeable<ResponseConfig>): Response;
148
- declare function sendUnauthorized(scope: Scope, config?: Mergeable<ResponseConfig>): Response;
149
- declare function mimeType(file: string): MimeType;
150
- declare function toRoutePath(path: string): [string, string | undefined];
151
- declare function invoke(scope: Scope, pipeline: Array<Middleware>, index?: number): Promise<Result>;
152
- declare function createServer(): Promise<Server>;
153
- declare const ROUTER_CONTEXT: Descriptor<RouterContext>;
154
- declare const SERVER_CONTEXT: Descriptor<ServerContext<Context>>;
155
- declare const WILDCARD = "$";
156
- declare const PARAMETER = ":";
157
- declare let STATES: States;
158
- declare const mimeTypes: Record<string, MimeType>;
159
- //#endregion
160
- //#region src/app/index.d.ts
161
- type Environment = typeof CLIENT | typeof SERVER;
162
- type Virtual = (environment: Environment) => undefined | string | Promise<string>;
163
- interface DevelopmentConfig {
164
- middlewares: Array<Middleware>;
165
- }
166
- interface BuildConfig {
167
- externals: Array<string>;
168
- }
169
- interface Config {
170
- modules: Array<Module>;
171
- client?: string;
172
- server?: string;
173
- sources: Record<string, Source>;
174
- development: DevelopmentConfig;
175
- build: BuildConfig;
176
- }
177
- interface Module {
178
- config?: Mergeable<Config>;
179
- setup?: (app: App) => void | Promise<void>;
180
- }
181
- interface Source {
182
- match: string;
183
- entries: Array<string>;
184
- resolve?: (path: string) => string;
185
- }
186
- interface App {
187
- config: Config;
188
- virtuals: Record<string, Virtual>;
189
- alias: Record<string, string>;
190
- }
191
- declare function createApp(inputConfig?: Mergeable<Config>): App;
192
- declare const SERVER = "ssr";
193
- declare const CLIENT = "client";
194
- //#endregion
195
- //#region src/client/index.d.ts
196
- declare function $fetch<T>(scope: Scope, input: string | URL, options?: RequestInit): Promise<T>;
197
- //#endregion
1
+ import { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Exception, Failure, HttpMethod, InferInput, InferOutput, 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, StopEvent, Success, Virtual, WILDCARD, WildcardNode, createApp, createServer, defineContext, defineException, defineMiddleware, defineRoute, getState, invoke, isFailure, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery } from "./index-nAhU8KOA.js";
198
2
  export { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Exception, Failure, HttpMethod, InferInput, InferOutput, 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, StopEvent, Success, Virtual, WILDCARD, WildcardNode, createApp, createServer, defineContext, defineException, defineMiddleware, defineRoute, getState, invoke, isFailure, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
package/dist/index.js CHANGED
@@ -1,400 +1,5 @@
1
- //#region src/server/index.ts
2
- var Radix = class {
3
- rootNode;
4
- constructor() {
5
- this.rootNode = {
6
- type: "PATH",
7
- children: {}
8
- };
9
- }
10
- use(path, value) {
11
- let node = this.rootNode;
12
- for (const segment of path.split("/")) {
13
- if (segment.startsWith(WILDCARD)) {
14
- let childNode$1 = node.children[WILDCARD];
15
- childNode$1 ??= {
16
- type: "WILDCARD",
17
- parameter: segment.substring(WILDCARD.length),
18
- children: {}
19
- };
20
- node.children[WILDCARD] ??= childNode$1;
21
- node = childNode$1;
22
- continue;
23
- }
24
- if (segment.startsWith(PARAMETER)) {
25
- let childNode$1 = node.children[PARAMETER];
26
- childNode$1 ??= {
27
- type: "PARAMETER",
28
- parameter: segment.substring(PARAMETER.length),
29
- children: {}
30
- };
31
- node.children[PARAMETER] ??= childNode$1;
32
- node = childNode$1;
33
- continue;
34
- }
35
- let childNode = node.children[segment];
36
- childNode ??= {
37
- type: "PATH",
38
- children: {}
39
- };
40
- node.children[segment] ??= childNode;
41
- node = childNode;
42
- }
43
- node.value = value;
44
- return node;
45
- }
46
- };
47
- var Router = class extends Radix {
48
- fetch(scope, next) {
49
- const { request } = useServer(scope);
50
- const { pathname } = useUrl(scope);
51
- const context = {
52
- route: this.rootNode,
53
- segments: (request.method.toUpperCase() + pathname).split("/"),
54
- parameters: {}
55
- };
56
- const invoke$1 = (node, index) => {
57
- if (index === context.segments.length) return node.value;
58
- const segment = context.segments[index];
59
- if (node.children[segment]) {
60
- const route$1 = invoke$1(node.children[segment], index + 1);
61
- if (route$1) return route$1;
62
- }
63
- if (node.children[PARAMETER]) {
64
- const parameterNode = node.children[PARAMETER];
65
- const route$1 = invoke$1(parameterNode, index + 1);
66
- if (route$1) {
67
- context.parameters[parameterNode.parameter] = segment;
68
- return route$1;
69
- }
70
- }
71
- if (node.children[WILDCARD]) {
72
- const wildcardNode = node.children[WILDCARD];
73
- context.parameters[wildcardNode.parameter] = segment;
74
- return wildcardNode.value ?? invoke$1(wildcardNode, segment.length);
75
- }
76
- };
77
- const route = invoke$1(this.rootNode, 0);
78
- if (route) {
79
- scope.setContext(ROUTER_CONTEXT, context);
80
- return route.fetch(scope);
81
- }
82
- return next?.();
83
- }
84
- };
85
- function defineRoute(route) {
86
- return route;
87
- }
88
- function defineMiddleware(middleware) {
89
- return middleware;
90
- }
91
- function defineException(exception) {
92
- return exception;
93
- }
94
- function useRouter(scope) {
95
- return scope.getContext(ROUTER_CONTEXT);
96
- }
97
- function useServer(scope) {
98
- return scope.getContext(SERVER_CONTEXT);
99
- }
100
- function useUrl(scope, base) {
101
- const { request } = useServer(scope);
102
- return new URL(request?.url ?? window?.location.href, base);
103
- }
104
- function useHeaders(scope) {
105
- const { request } = useServer(scope);
106
- return request?.headers;
107
- }
108
- function useQuery(scope, schema) {
109
- const { searchParams } = useUrl(scope);
110
- const entries = Object.fromEntries(searchParams);
111
- return schema ? parseSchema(scope, schema, entries) : entries;
112
- }
113
- function withQuery(input, query) {
114
- const url = new URL(input);
115
- for (const name in query) {
116
- const value = query[name];
117
- if (value) url.searchParams.set(name, value);
118
- }
119
- return url.href;
120
- }
121
- function useCookies(scope, schema) {
122
- const { request } = useServer(scope);
123
- const entries = (import.meta.client ? document.cookie : request.headers.get("Cookie") ?? "").split("; ").reduce((result, cookie) => {
124
- const [name, value] = cookie.split("=");
125
- if (name && value) result[name] = decodeURIComponent(value);
126
- return result;
127
- }, {});
128
- return schema ? parseSchema(scope, schema, entries) : entries;
129
- }
130
- function useSetCookies(scope, schema) {
131
- const { request } = useServer(scope);
132
- const entries = request.headers.getSetCookie().reduce((result, cookie) => {
133
- const [name, value] = cookie.split("=");
134
- if (name && value) result[name] = decodeURIComponent(value);
135
- return result;
136
- }, {});
137
- return schema ? parseSchema(scope, schema, entries) : entries;
138
- }
139
- function setCookie(scope, name, value, options) {
140
- const { response } = useServer(scope);
141
- let cookie = name + "=" + encodeURIComponent(value);
142
- if (options?.domain) cookie += `; Domain=${options.domain}`;
143
- if (options?.expires) cookie += `; Expires=${options.expires.toUTCString()}`;
144
- if (options?.httpOnly) cookie += `; HttpOnly`;
145
- if (options?.maxAge) cookie += `; Max-Age=${options.maxAge}`;
146
- if (options?.path) cookie += `; Path=${options.path}`;
147
- if (options?.priority) cookie += `; Priority=${options.priority}`;
148
- if (options?.sameSite) cookie += `; SameSite=${options.sameSite}`;
149
- if (options?.secure) cookie += `; Secure`;
150
- if (import.meta.server) response.headers.append("Set-Cookie", cookie);
151
- else document.cookie = cookie;
152
- }
153
- function getState(scope, name) {
154
- if (import.meta.server) {
155
- const { states } = useServer(scope);
156
- return states[name];
157
- } else {
158
- if (STATES === void 0) {
159
- const element = document.getElementById("STATES");
160
- STATES = element?.textContent ? JSON.parse(element.textContent) : {};
161
- }
162
- return STATES[name];
163
- }
164
- }
165
- function setState(scope, name, value) {
166
- if (import.meta.server) {
167
- const { states } = useServer(scope);
168
- states[name] = value;
169
- } else {
170
- if (STATES === void 0) {
171
- const element = document.getElementById("STATES");
172
- STATES = element?.textContent ? JSON.parse(element.textContent) : {};
173
- }
174
- STATES[name] = value;
175
- }
176
- }
177
- function sendText(scope, text, config) {
178
- const { response } = useServer(scope);
179
- response.headers.set("Content-Type", "text/plain");
180
- return new Response(text, mergeObjects(response, config));
181
- }
182
- function sendHtml(scope, text, config) {
183
- const { response } = useServer(scope);
184
- response.headers.set("Content-Type", "text/html");
185
- return new Response(text, mergeObjects(response, config));
186
- }
187
- function sendJson(scope, value, config) {
188
- const { response } = useServer(scope);
189
- response.headers.set("Content-Type", "application/json");
190
- return new Response(JSON.stringify(value), mergeObjects(response, config));
191
- }
192
- function sendRedirect(scope, path, config) {
193
- const { response } = useServer(scope);
194
- response.status = 302;
195
- response.headers.set("Location", path);
196
- return new Response(null, mergeObjects(response, config));
197
- }
198
- function sendBadRequest(scope, text, config) {
199
- const { response } = useServer(scope);
200
- response.status = 400;
201
- return new Response(text, mergeObjects(response, config));
202
- }
203
- function sendUnauthorized(scope, config) {
204
- const { response } = useServer(scope);
205
- response.status = 401;
206
- return new Response(null, mergeObjects(response, config));
207
- }
208
- function mimeType(file) {
209
- const extension = /\.([a-zA-Z0-9]+?)$/.exec(file)?.at(1);
210
- return mimeTypes[extension ?? ""] ?? "text/plain";
211
- }
212
- function toRoutePath(path) {
213
- const result = ("/" + path).replaceAll(/\/index/g, "").replaceAll(/\[\.\.\.(.*?)\]/g, (_, value) => WILDCARD + value).replaceAll(/\[(.*?)\]/g, (_, value) => PARAMETER + value);
214
- return (result.startsWith("/") ? result : "/" + result).split(".");
215
- }
216
- async function invoke(scope, pipeline, index = 0) {
217
- return await pipeline.at(index)?.fetch(scope, async () => await invoke(scope, pipeline, index + 1));
218
- }
219
- async function createServer() {
220
- const router = new Router();
221
- const middlewares = new Array();
222
- const assets = await import("#virtual/assets").then((module) => Object.entries(module.default));
223
- for (const [path, asset] of assets) router.use(`GET/${path}`, defineRoute({ async fetch(scope) {
224
- const { response } = useServer(scope);
225
- response.headers.set("Content-Type", mimeType(path));
226
- return new Response(asset, response);
227
- } }));
228
- const routes = await import("#virtual/routes").then((module) => Object.entries(module.default));
229
- for (const [path, route] of routes) {
230
- const [name, method] = toRoutePath(path);
231
- router.use(method?.toUpperCase() + name, route);
232
- }
233
- const exceptions = await import("#virtual/exceptions").then((module) => Object.values(module.default));
234
- middlewares.push(defineMiddleware({ async fetch(scope, next) {
235
- try {
236
- return await next?.();
237
- } catch (value) {
238
- for (const exception of exceptions) {
239
- const result = exception.fetch(scope, value);
240
- if (result) return result;
241
- }
242
- if (value instanceof Response) return value;
243
- }
244
- } }));
245
- middlewares.push(router);
246
- return {
247
- router,
248
- middlewares,
249
- async fetch(scope) {
250
- return await invoke(scope, middlewares) ?? sendText(scope, "NOT_FOUND", { status: 404 });
251
- }
252
- };
253
- }
254
- const ROUTER_CONTEXT = defineContext("ROUTER_CONTEXT");
255
- const SERVER_CONTEXT = defineContext("SERVER_CONTEXT");
256
- const WILDCARD = "$";
257
- const PARAMETER = ":";
258
- let STATES;
259
- const mimeTypes = {
260
- txt: "text/plain",
261
- css: "text/css",
262
- html: "text/html",
263
- htm: "text/html",
264
- js: "text/javascript",
265
- json: "application/json",
266
- xml: "application/xml",
267
- csv: "text/csv",
268
- jpg: "image/jpeg",
269
- jpeg: "image/jpeg",
270
- png: "image/png",
271
- gif: "image/gif",
272
- webp: "image/webp",
273
- svg: "image/svg+xml",
274
- bmp: "image/bmp",
275
- ico: "image/x-icon",
276
- ttf: "font/ttf",
277
- otf: "font/otf",
278
- woff: "font/woff",
279
- woff2: "font/woff2",
280
- mp3: "audio/mpeg",
281
- wav: "audio/wav",
282
- ogg: "audio/ogg",
283
- m4a: "audio/mp4",
284
- mp4: "video/mp4",
285
- webm: "video/webm",
286
- ogv: "video/ogg",
287
- mov: "video/quicktime",
288
- avi: "video/x-msvideo",
289
- zip: "application/zip",
290
- rar: "application/vnd.rar",
291
- tar: "application/x-tar",
292
- gz: "application/gzip",
293
- "7z": "application/x-7z-compressed",
294
- pdf: "application/pdf",
295
- doc: "application/msword",
296
- docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
297
- xls: "application/vnd.ms-excel",
298
- xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
299
- ppt: "application/vnd.ms-powerpoint",
300
- pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
301
- exe: "application/vnd.microsoft.portable-executable",
302
- apk: "application/vnd.android.package-archive"
303
- };
1
+ import { CLIENT, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope, StopEvent, WILDCARD, createApp, createServer, defineContext, defineException, defineMiddleware, defineRoute, getState, invoke, isFailure, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery } from "./app-D1k2p6G_.js";
304
2
 
305
- //#endregion
306
- //#region src/shared/index.ts
307
- var StopEvent = class extends Event {
308
- constructor() {
309
- super("stop");
310
- }
311
- };
312
- var Scope = class extends EventTarget {
313
- parentScope;
314
- context;
315
- constructor(parentScope) {
316
- super();
317
- this.parentScope = parentScope;
318
- this.parentScope?.onStop(() => this.stop());
319
- this.context = {};
320
- }
321
- getContext(input) {
322
- let scope = this;
323
- while (scope) {
324
- if (scope.context[input]) return scope.context[input];
325
- scope = scope.parentScope;
326
- }
327
- return {};
328
- }
329
- setContext(input, value) {
330
- this.context[input] = value;
331
- }
332
- onStop(input) {
333
- this.addEventListener("stop", input, { once: true });
334
- }
335
- stop() {
336
- return this.dispatchEvent(new StopEvent());
337
- }
338
- };
339
- function defineContext(name) {
340
- return name;
341
- }
342
- function isFailure(result) {
343
- return "issues" in result;
344
- }
345
- function parseSchema(scope, schema, value) {
346
- const result = schema["~standard"].validate(value);
347
- if (isFailure(result)) throw sendBadRequest(scope, result.issues.map((issue) => issue.message).join(", "));
348
- return result.value;
349
- }
350
- function mergeObjects(base, input) {
351
- if (input === null || input === void 0) return mergeObjects(base, {});
352
- const object = Object.assign({}, input);
353
- for (const key in base) {
354
- if (key === "__proto__" || key === "constructor") continue;
355
- const value = base[key];
356
- if (value === null || value === void 0) continue;
357
- if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
358
- else if (typeof value === "object" && typeof object[key] === "object") object[key] = mergeObjects(value, object[key]);
359
- else object[key] = value;
360
- }
361
- return object;
362
- }
363
-
364
- //#endregion
365
- //#region src/app/index.ts
366
- function createApp(inputConfig) {
367
- let config = mergeObjects(inputConfig, {
368
- modules: [],
369
- sources: {
370
- assets: {
371
- match: "**/*",
372
- entries: ["./public"],
373
- resolve: (path) => path + "?raw"
374
- },
375
- routes: {
376
- match: "**/*.{js,ts}",
377
- entries: ["./routes"]
378
- },
379
- exceptions: {
380
- match: "**/*.{js,ts}",
381
- entries: ["./exceptions"]
382
- }
383
- },
384
- development: { middlewares: [] },
385
- build: { externals: [] }
386
- });
387
- for (const module of config.modules) config = mergeObjects(config, module.config);
388
- return {
389
- config,
390
- virtuals: {},
391
- alias: {}
392
- };
393
- }
394
- const SERVER = "ssr";
395
- const CLIENT = "client";
396
-
397
- //#endregion
398
3
  //#region src/client/index.ts
399
4
  async function $fetch(scope, input, options) {
400
5
  let response;
@@ -0,0 +1,15 @@
1
+ import { App, Config, Mergeable, Virtual } from "../index-nAhU8KOA.js";
2
+ import { Plugin } from "vite";
3
+
4
+ //#region src/vite/index.d.ts
5
+ declare function useKit(app: App, source: string | URL): {
6
+ source: string;
7
+ toPath: (...paths: Array<string>) => string;
8
+ addVirtual: (name: string, virtual: Virtual) => void;
9
+ addAlias: (name: string, path: string) => void;
10
+ };
11
+ declare function addRoutes(app: App, path: string): void;
12
+ declare function addAssets(app: App, path: string): void;
13
+ declare function revojs(config?: Mergeable<Config>): Array<Plugin>;
14
+ //#endregion
15
+ export { addAssets, addRoutes, revojs, useKit };