revojs 0.0.49 → 0.0.50
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/index.d.ts +6 -6
- package/dist/http/index.d.ts +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +11 -101
- package/dist/runtime/index.d.ts +5 -1
- package/package.json +1 -1
- package/dist/markdown/index.d.ts +0 -2
package/dist/app/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Middleware } from "../http";
|
|
1
|
+
import type { Middleware } from "../runtime";
|
|
3
2
|
export type NestedPartial<T> = T extends any[] ? T : T extends Record<string, any> ? {
|
|
4
3
|
[P in keyof T]?: NestedPartial<T[P]>;
|
|
5
4
|
} : T;
|
|
6
5
|
export type Environment = typeof CLIENT | typeof SERVER;
|
|
6
|
+
export type Virtual = (environment: Environment) => void | string;
|
|
7
|
+
export type ClientEntry = "index.html" | (string & {});
|
|
7
8
|
export type ServerEntry = "revojs/presets/node" | "revojs/presets/deno" | "revojs/presets/bun" | "revojs/presets/cloudflare" | (string & {});
|
|
8
9
|
export type ClientConfig = {
|
|
9
|
-
entry:
|
|
10
|
+
entry: ClientEntry;
|
|
10
11
|
};
|
|
11
12
|
export type ServerConfig = {
|
|
12
13
|
entry: ServerEntry;
|
|
@@ -15,14 +16,13 @@ export type DevelopmentConfig = {
|
|
|
15
16
|
middleware: Array<Middleware>;
|
|
16
17
|
};
|
|
17
18
|
export type Config = {
|
|
18
|
-
client: ClientConfig;
|
|
19
|
+
client: false | ClientConfig;
|
|
19
20
|
server: false | ServerConfig;
|
|
20
|
-
markdown: Record<string, Template>;
|
|
21
21
|
dev: DevelopmentConfig;
|
|
22
22
|
};
|
|
23
23
|
export type App = {
|
|
24
24
|
config: Config;
|
|
25
|
-
virtuals: Record<string,
|
|
25
|
+
virtuals: Record<string, Virtual>;
|
|
26
26
|
};
|
|
27
27
|
export declare const createApp: (config?: NestedPartial<Config>) => App;
|
|
28
28
|
export declare const SERVER = "ssr";
|
package/dist/http/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type ResponseOptions = {
|
|
|
19
19
|
headers: Headers;
|
|
20
20
|
};
|
|
21
21
|
export type Handle = (scope: Scope) => void | Response | Promise<void | Response>;
|
|
22
|
-
export type
|
|
22
|
+
export type Chain = (scope: Scope, next: Handle) => void | Response | Promise<void | Response>;
|
|
23
23
|
export declare const sendText: (scope: Scope, text: string) => Response;
|
|
24
24
|
export declare const sendHtml: (scope: Scope, text: string) => Response;
|
|
25
25
|
export declare const sendJson: <T>(scope: Scope, value: T) => Response;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -7,7 +7,6 @@ const createApp = (config) => {
|
|
|
7
7
|
config: defu(config, {
|
|
8
8
|
client: { entry: "./index.html" },
|
|
9
9
|
server: { entry: "revojs/presets/node" },
|
|
10
|
-
markdown: {},
|
|
11
10
|
dev: { middleware: [] }
|
|
12
11
|
}),
|
|
13
12
|
virtuals: {}
|
|
@@ -412,7 +411,7 @@ const toCustomElement = (Component) => {
|
|
|
412
411
|
internals: this.internals
|
|
413
412
|
});
|
|
414
413
|
await hydrate(this.component.scope, rootNode, await this.component.setup(), 0);
|
|
415
|
-
this.dispatchEvent(new MountedEvent());
|
|
414
|
+
requestAnimationFrame(() => this.dispatchEvent(new MountedEvent()));
|
|
416
415
|
}
|
|
417
416
|
attributeChangedCallback(name, oldValue, value) {
|
|
418
417
|
if (value === oldValue) return;
|
|
@@ -521,6 +520,9 @@ const useRoute = (scope) => {
|
|
|
521
520
|
const defineRoute = (route) => {
|
|
522
521
|
return route;
|
|
523
522
|
};
|
|
523
|
+
const defineMiddleware = (middleware) => {
|
|
524
|
+
return middleware;
|
|
525
|
+
};
|
|
524
526
|
const fileName = (path) => {
|
|
525
527
|
return path.split("/").pop()?.split(".").slice(0, -1).join(".");
|
|
526
528
|
};
|
|
@@ -570,8 +572,8 @@ const createRuntime = async () => {
|
|
|
570
572
|
response.headers.set("Content-Type", mimeType(path));
|
|
571
573
|
return new Response(await assets[path]?.(), response);
|
|
572
574
|
} }));
|
|
573
|
-
const invoke = (scope,
|
|
574
|
-
return middlewares.at(index)?.(scope, () => invoke(scope,
|
|
575
|
+
const invoke = (scope, route, index) => {
|
|
576
|
+
return middlewares.at(index)?.fetch(scope, () => invoke(scope, route, index + 1)) ?? route.fetch(scope);
|
|
575
577
|
};
|
|
576
578
|
return {
|
|
577
579
|
radix,
|
|
@@ -583,7 +585,7 @@ const createRuntime = async () => {
|
|
|
583
585
|
try {
|
|
584
586
|
scope.setContext(ROUTE_CONTEXT, { inputs: createState(inputs) });
|
|
585
587
|
if (route) {
|
|
586
|
-
const response = await invoke(scope, route
|
|
588
|
+
const response = await invoke(scope, route, 0);
|
|
587
589
|
if (response) return response;
|
|
588
590
|
}
|
|
589
591
|
return sendText(scope, "NOT_FOUND");
|
|
@@ -636,7 +638,7 @@ const useRequestUrl = (scope, base) => {
|
|
|
636
638
|
};
|
|
637
639
|
const useCookies = (scope) => {
|
|
638
640
|
const { request } = useRuntime(scope);
|
|
639
|
-
return (request.headers.get("Cookie")
|
|
641
|
+
return (isClient() ? document.cookie : request.headers.get("Cookie") ?? "").split("; ").reduce((result, cookie) => {
|
|
640
642
|
const [name, value] = cookie.split("=");
|
|
641
643
|
if (name && value) result[name] = decodeURIComponent(value);
|
|
642
644
|
return result;
|
|
@@ -661,7 +663,8 @@ const setCookie = (scope, name, value, options) => {
|
|
|
661
663
|
if (options?.priority) cookie += `; Priority=${options.priority}`;
|
|
662
664
|
if (options?.sameSite) cookie += `; SameSite=${options.sameSite}`;
|
|
663
665
|
if (options?.secure) cookie += `; Secure`;
|
|
664
|
-
|
|
666
|
+
if (isClient()) document.cookie = cookie;
|
|
667
|
+
else response.headers.append("Set-Cookie", cookie);
|
|
665
668
|
};
|
|
666
669
|
const mimeType = (file) => {
|
|
667
670
|
const extension = /\.([a-zA-Z0-9]+?)$/.exec(file)?.at(1);
|
|
@@ -835,97 +838,4 @@ const useLocale = (scope, context) => {
|
|
|
835
838
|
};
|
|
836
839
|
|
|
837
840
|
//#endregion
|
|
838
|
-
|
|
839
|
-
const charWhile = (buffer, start, ...chars) => {
|
|
840
|
-
let depth = 0;
|
|
841
|
-
let current = buffer.at(start + depth);
|
|
842
|
-
while (current && chars.includes(current)) {
|
|
843
|
-
depth += 1;
|
|
844
|
-
current = buffer.at(start + depth);
|
|
845
|
-
}
|
|
846
|
-
return depth;
|
|
847
|
-
};
|
|
848
|
-
const charUntil = (buffer, start, ...chars) => {
|
|
849
|
-
let depth = 0;
|
|
850
|
-
let current = buffer.at(start + depth);
|
|
851
|
-
while (current && !chars.includes(current)) {
|
|
852
|
-
depth += 1;
|
|
853
|
-
current = buffer.at(start + depth);
|
|
854
|
-
}
|
|
855
|
-
return depth;
|
|
856
|
-
};
|
|
857
|
-
const inlineText = (buffer, options) => {
|
|
858
|
-
const nodes = new Array();
|
|
859
|
-
let index = 0;
|
|
860
|
-
while (index < buffer.length) {
|
|
861
|
-
const char = buffer.charAt(index);
|
|
862
|
-
const text = charUntil(buffer, index, "*", "_", "\n");
|
|
863
|
-
if (text > 0) {
|
|
864
|
-
nodes.push(buffer.slice(index, index + text));
|
|
865
|
-
index += text;
|
|
866
|
-
continue;
|
|
867
|
-
}
|
|
868
|
-
if (char === "*" || char === "_") {
|
|
869
|
-
const start = charWhile(buffer, index, char);
|
|
870
|
-
const between = charUntil(buffer, index + start, char);
|
|
871
|
-
const end = charWhile(buffer, index + start + between, char);
|
|
872
|
-
const min = Math.min(start, end, 2);
|
|
873
|
-
const leading = start - min;
|
|
874
|
-
const trailing = end - min;
|
|
875
|
-
const slice = buffer.slice(index + leading + min, index + start + between + end - trailing - min);
|
|
876
|
-
if (slice.length > 0) {
|
|
877
|
-
const inline = inlineText(char.repeat(leading) + slice + char.repeat(trailing), options);
|
|
878
|
-
const tag = min === 2 ? "strong" : "em";
|
|
879
|
-
nodes.push(defu(options?.[tag], {
|
|
880
|
-
tag,
|
|
881
|
-
attributes: {},
|
|
882
|
-
children: inline
|
|
883
|
-
}));
|
|
884
|
-
}
|
|
885
|
-
index += start + between + end;
|
|
886
|
-
continue;
|
|
887
|
-
}
|
|
888
|
-
if (char === "\n") {
|
|
889
|
-
nodes.push(defu(options?.["br"], {
|
|
890
|
-
tag: "br",
|
|
891
|
-
attributes: {},
|
|
892
|
-
children: []
|
|
893
|
-
}));
|
|
894
|
-
index += 1;
|
|
895
|
-
continue;
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
return nodes;
|
|
899
|
-
};
|
|
900
|
-
const markdownToSlot = (input, options) => {
|
|
901
|
-
const nodes = new Array();
|
|
902
|
-
const buffer = input.replace(/[\r]+/g, "").trim();
|
|
903
|
-
let index = 0;
|
|
904
|
-
while (index < buffer.length) {
|
|
905
|
-
const start = index;
|
|
906
|
-
let lines = charWhile(buffer, index, "\n");
|
|
907
|
-
while (lines < 2 && index < buffer.length) {
|
|
908
|
-
index += lines + charUntil(buffer, index + lines, "\n");
|
|
909
|
-
lines = charWhile(buffer, index, "\n");
|
|
910
|
-
}
|
|
911
|
-
const block = buffer.slice(start, index);
|
|
912
|
-
if (block.startsWith("#")) {
|
|
913
|
-
const depth = charWhile(block, 0, "#");
|
|
914
|
-
const tag = "h" + depth;
|
|
915
|
-
nodes.push(defu(options?.[tag], {
|
|
916
|
-
tag,
|
|
917
|
-
attributes: {},
|
|
918
|
-
children: inlineText(block.slice(depth))
|
|
919
|
-
}));
|
|
920
|
-
} else nodes.push(defu(options?.["p"], {
|
|
921
|
-
tag: "p",
|
|
922
|
-
attributes: {},
|
|
923
|
-
children: inlineText(block)
|
|
924
|
-
}));
|
|
925
|
-
index += lines;
|
|
926
|
-
}
|
|
927
|
-
return nodes;
|
|
928
|
-
};
|
|
929
|
-
|
|
930
|
-
//#endregion
|
|
931
|
-
export { $fetch, CLIENT, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, Scope, StopEvent, activeCompute, components, createApp, createCompute, createElement, createLocale, createMemo, createRouter, createRuntime, createState, defineComponent, defineContext, defineRoute, fileName, fromValue, hydrate, isClient, isServer, isTemplate, markdownToSlot, mimeType, preventDefault, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, useCookies, useEvent, useHost, useLocale, useRequestUrl, useRoute, useRouter, useRuntime, useSetCookies };
|
|
841
|
+
export { $fetch, CLIENT, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, Scope, StopEvent, activeCompute, components, createApp, createCompute, createElement, createLocale, createMemo, createRouter, createRuntime, createState, defineComponent, defineContext, defineMiddleware, defineRoute, fileName, fromValue, hydrate, isClient, isServer, isTemplate, mimeType, preventDefault, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, useCookies, useEvent, useHost, useLocale, useRequestUrl, useRoute, useRouter, useRuntime, useSetCookies };
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Chain, type Handle, type ResponseOptions } from "../http";
|
|
2
2
|
import { Radix } from "../radix";
|
|
3
3
|
import { Scope, type State } from "../signals";
|
|
4
4
|
export type Route = {
|
|
5
5
|
fetch: Handle;
|
|
6
6
|
};
|
|
7
|
+
export type Middleware = {
|
|
8
|
+
fetch: Chain;
|
|
9
|
+
};
|
|
7
10
|
export type Runtime = {
|
|
8
11
|
radix: Radix<Route>;
|
|
9
12
|
middlewares: Array<Middleware>;
|
|
@@ -20,6 +23,7 @@ export type RouteContext = {
|
|
|
20
23
|
export declare const useRuntime: <T = Record<string, unknown>>(scope: Scope) => RuntimeContext<T>;
|
|
21
24
|
export declare const useRoute: (scope: Scope) => RouteContext;
|
|
22
25
|
export declare const defineRoute: (route: Route) => Route;
|
|
26
|
+
export declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
23
27
|
export declare const fileName: (path: string) => string | undefined;
|
|
24
28
|
export declare const toPath: (value: string) => (string | undefined)[];
|
|
25
29
|
export declare const $fetch: <T>(scope: Scope, input: string | URL, options?: RequestInit) => Promise<T>;
|
package/package.json
CHANGED
package/dist/markdown/index.d.ts
DELETED