revojs 0.0.85 → 0.0.86
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 +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +30 -13
- package/dist/locale/index.d.ts +2 -2
- package/dist/runtime/index.d.ts +7 -4
- package/dist/schema/index.d.ts +21 -0
- package/package.json +1 -1
package/dist/app/index.d.ts
CHANGED
|
@@ -11,9 +11,11 @@ export type Module = {
|
|
|
11
11
|
};
|
|
12
12
|
export type ClientConfig = {
|
|
13
13
|
entry: ClientEntry;
|
|
14
|
+
externals: Array<string>;
|
|
14
15
|
};
|
|
15
16
|
export type ServerConfig = {
|
|
16
17
|
entry: ServerEntry;
|
|
18
|
+
externals: Array<string>;
|
|
17
19
|
};
|
|
18
20
|
export type DevelopmentConfig = {
|
|
19
21
|
middleware: Array<Middleware>;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,8 +16,14 @@ function createApp(config) {
|
|
|
16
16
|
return {
|
|
17
17
|
config: mergeObjects(config, {
|
|
18
18
|
modules: [],
|
|
19
|
-
client: {
|
|
20
|
-
|
|
19
|
+
client: {
|
|
20
|
+
entry: "index.html",
|
|
21
|
+
externals: []
|
|
22
|
+
},
|
|
23
|
+
server: {
|
|
24
|
+
entry: "@revojs/bun/runtime",
|
|
25
|
+
externals: []
|
|
26
|
+
},
|
|
21
27
|
dev: { middleware: [] }
|
|
22
28
|
}),
|
|
23
29
|
virtuals: {}
|
|
@@ -399,6 +405,15 @@ function useRuntime(scope) {
|
|
|
399
405
|
function useRoute(scope) {
|
|
400
406
|
return scope.getContext(ROUTE_CONTEXT);
|
|
401
407
|
}
|
|
408
|
+
async function useRoutes() {
|
|
409
|
+
return await import("#virtual/routes").then((module) => module.default);
|
|
410
|
+
}
|
|
411
|
+
async function useAssets() {
|
|
412
|
+
return await import("#virtual/assets").then((module) => module.default);
|
|
413
|
+
}
|
|
414
|
+
async function useLocales() {
|
|
415
|
+
return await import("#virtual/locales").then((module) => module.default);
|
|
416
|
+
}
|
|
402
417
|
function defineRoute(route) {
|
|
403
418
|
return route;
|
|
404
419
|
}
|
|
@@ -454,24 +469,26 @@ function useState(scope, name, value) {
|
|
|
454
469
|
}
|
|
455
470
|
return state;
|
|
456
471
|
}
|
|
457
|
-
function useAsync(scope, name, invoke,
|
|
472
|
+
function useAsync(scope, name, invoke, defaultOptions) {
|
|
458
473
|
const { tasks } = useRuntime(scope);
|
|
459
474
|
const state = useState(scope, name);
|
|
460
475
|
const isLoading = createState(false);
|
|
461
|
-
const execute = async () => {
|
|
476
|
+
const execute = async (options) => {
|
|
477
|
+
const onCatch = options?.catch ?? defaultOptions?.catch;
|
|
478
|
+
const viewTransition = options?.viewTransition ?? defaultOptions?.viewTransition;
|
|
462
479
|
isLoading.value = true;
|
|
463
480
|
try {
|
|
464
481
|
const result = await invoke();
|
|
465
|
-
if (JSON.stringify(state.value ?? {}) !== JSON.stringify(result)) if (
|
|
482
|
+
if (JSON.stringify(state.value ?? {}) !== JSON.stringify(result)) if (viewTransition) await startViewTransition(viewTransition, () => state.value = result);
|
|
466
483
|
else state.value = result;
|
|
467
484
|
} catch (error) {
|
|
468
|
-
|
|
485
|
+
onCatch?.(error);
|
|
469
486
|
} finally {
|
|
470
487
|
isLoading.value = false;
|
|
471
488
|
}
|
|
472
489
|
return state.value;
|
|
473
490
|
};
|
|
474
|
-
const task = execute();
|
|
491
|
+
const task = execute(defaultOptions);
|
|
475
492
|
if (isServer()) tasks.push(task);
|
|
476
493
|
return {
|
|
477
494
|
state,
|
|
@@ -485,7 +502,7 @@ function useFetch(scope, input, options) {
|
|
|
485
502
|
async function createRuntime() {
|
|
486
503
|
const radix = new Radix();
|
|
487
504
|
const middlewares = new Array();
|
|
488
|
-
const routes = await
|
|
505
|
+
const routes = await useRoutes();
|
|
489
506
|
for (const path in routes) {
|
|
490
507
|
const [name, method] = toPath(path);
|
|
491
508
|
radix.insert((method ?? "GET").toUpperCase() + name, defineRoute({ fetch: async (scope) => {
|
|
@@ -509,7 +526,7 @@ async function createRuntime() {
|
|
|
509
526
|
})));
|
|
510
527
|
} }));
|
|
511
528
|
}
|
|
512
|
-
const assets = await
|
|
529
|
+
const assets = await useAssets();
|
|
513
530
|
for (const path in assets) radix.insert("GET/" + path, defineRoute({ fetch: async (scope) => {
|
|
514
531
|
const { response } = useRuntime(scope);
|
|
515
532
|
let content = assets[path];
|
|
@@ -980,19 +997,19 @@ function useLocale(scope, context) {
|
|
|
980
997
|
const $ = (key) => {
|
|
981
998
|
return () => messages.value?.[key] ?? key;
|
|
982
999
|
};
|
|
983
|
-
const date = (date
|
|
1000
|
+
const $date = (date, options$1) => {
|
|
984
1001
|
const format = new Intl.DateTimeFormat(locale.value, options$1);
|
|
985
|
-
if (date
|
|
1002
|
+
if (date) return format.format(date);
|
|
986
1003
|
};
|
|
987
1004
|
return {
|
|
988
1005
|
locale,
|
|
989
1006
|
messages,
|
|
990
1007
|
options,
|
|
991
1008
|
$,
|
|
992
|
-
date
|
|
1009
|
+
$date
|
|
993
1010
|
};
|
|
994
1011
|
}
|
|
995
1012
|
const LOCALE_CONTEXT = defineContext("LOCALE_CONTEXT");
|
|
996
1013
|
|
|
997
1014
|
//#endregion
|
|
998
|
-
export { $fetch, AfterNavigateEvent, CLIENT, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, STATES, Scope, StopEvent, activeCompute, activeViewTransition, components, createApp, createCompute, createElement, createMemo, createRuntime, createState, defineComponent, defineContext, defineMiddleware, defineRoute, fileName, fromValue, hydrate, isClient, isComponent, isCustomElement, isRoute, isServer, isTemplate, mergeObjects, mimeType, onMounted, onViewTransition, preventDefault, provideLocaleContext, provideRouterContext, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, startViewTransition, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, untrack, useAsync, useCookies, useEvent, useFetch, useHost, useLocale, useQuery, useRoute, useRouter, useRuntime, useSetCookies, useState, useUrl };
|
|
1015
|
+
export { $fetch, AfterNavigateEvent, CLIENT, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, ROUTE_CONTEXT, RUNTIME_CONTEXT, Radix, SERVER, STATES, Scope, StopEvent, activeCompute, activeViewTransition, components, createApp, createCompute, createElement, createMemo, createRuntime, createState, defineComponent, defineContext, defineMiddleware, defineRoute, fileName, fromValue, hydrate, isClient, isComponent, isCustomElement, isRoute, isServer, isTemplate, mergeObjects, mimeType, onMounted, onViewTransition, preventDefault, provideLocaleContext, provideRouterContext, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, startViewTransition, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, untrack, useAssets, useAsync, useCookies, useEvent, useFetch, useHost, useLocale, useLocales, useQuery, useRoute, useRouter, useRoutes, useRuntime, useSetCookies, useState, useUrl };
|
package/dist/locale/index.d.ts
CHANGED
|
@@ -14,13 +14,13 @@ export declare function provideLocaleContext(scope: Scope, options: LocaleOption
|
|
|
14
14
|
messages: State<Record<string, string> | undefined>;
|
|
15
15
|
options: LocaleOptions;
|
|
16
16
|
$: (key: string) => () => string | number | symbol;
|
|
17
|
-
date: (date?: Date, options?: Intl.DateTimeFormatOptions) => string | undefined;
|
|
17
|
+
$date: (date?: Date, options?: Intl.DateTimeFormatOptions) => string | undefined;
|
|
18
18
|
};
|
|
19
19
|
export declare function useLocale<T extends LocaleContext>(scope: Scope, context?: Descriptor<T>): {
|
|
20
20
|
locale: State<string | undefined>;
|
|
21
21
|
messages: State<Record<string, string> | undefined>;
|
|
22
22
|
options: LocaleOptions;
|
|
23
23
|
$: (key: keyof T["options"]["locales"][keyof T["options"]["locales"]]) => () => string | number | symbol;
|
|
24
|
-
date: (date?: Date, options?: Intl.DateTimeFormatOptions) => string | undefined;
|
|
24
|
+
$date: (date?: Date, options?: Intl.DateTimeFormatOptions) => string | undefined;
|
|
25
25
|
};
|
|
26
26
|
export declare const LOCALE_CONTEXT: Descriptor<LocaleContext>;
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -23,12 +23,15 @@ export type RouteContext = {
|
|
|
23
23
|
inputs: State<Record<string, string>>;
|
|
24
24
|
};
|
|
25
25
|
export type AsyncOptions<T> = {
|
|
26
|
-
viewTransition?: string;
|
|
26
|
+
viewTransition?: false | string;
|
|
27
27
|
catch?: (error: T) => void | Promise<void>;
|
|
28
28
|
};
|
|
29
29
|
export declare function isRoute<T>(value?: T): value is Route & T;
|
|
30
30
|
export declare function useRuntime<T = Record<string, unknown>>(scope: Scope): RuntimeContext<T>;
|
|
31
31
|
export declare function useRoute(scope: Scope): RouteContext;
|
|
32
|
+
export declare function useRoutes(): Promise<Record<string, unknown>>;
|
|
33
|
+
export declare function useAssets(): Promise<Record<string, string>>;
|
|
34
|
+
export declare function useLocales(): Promise<Record<string, Record<string, string>>>;
|
|
32
35
|
export declare function defineRoute(route: Route): Route;
|
|
33
36
|
export declare function defineMiddleware(middleware: Middleware): Middleware;
|
|
34
37
|
export declare function fileName(path: string): string | undefined;
|
|
@@ -36,15 +39,15 @@ export declare function toPath(value: string): (string | undefined)[];
|
|
|
36
39
|
export declare function $fetch<T>(scope: Scope, input: string | URL, options?: RequestInit): Promise<T>;
|
|
37
40
|
export declare function useState<T>(scope: Scope, name: string): State<T | undefined>;
|
|
38
41
|
export declare function useState<T>(scope: Scope, name: string, value: T): State<T>;
|
|
39
|
-
export declare function useAsync<T, TError = Error>(scope: Scope, name: string, invoke: () => Promise<T>,
|
|
42
|
+
export declare function useAsync<T, TError = Error>(scope: Scope, name: string, invoke: () => Promise<T>, defaultOptions?: AsyncOptions<TError>): {
|
|
40
43
|
state: State<T | undefined>;
|
|
41
44
|
isLoading: State<boolean>;
|
|
42
|
-
execute: () => Promise<T | undefined>;
|
|
45
|
+
execute: (options?: AsyncOptions<TError>) => Promise<T | undefined>;
|
|
43
46
|
};
|
|
44
47
|
export declare function useFetch<T, TError = Error>(scope: Scope, input: string | URL, options?: RequestInit & AsyncOptions<TError>): {
|
|
45
48
|
state: State<T | undefined>;
|
|
46
49
|
isLoading: State<boolean>;
|
|
47
|
-
execute: () => Promise<T | undefined>;
|
|
50
|
+
execute: (options?: AsyncOptions<TError> | undefined) => Promise<T | undefined>;
|
|
48
51
|
};
|
|
49
52
|
export declare function createRuntime(): Promise<Runtime>;
|
|
50
53
|
export declare let STATES: Record<string, unknown>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type Issue = {
|
|
2
|
+
readonly message: string;
|
|
3
|
+
};
|
|
4
|
+
export type Success<T> = {
|
|
5
|
+
readonly value: T;
|
|
6
|
+
};
|
|
7
|
+
export type Failure = {
|
|
8
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
9
|
+
};
|
|
10
|
+
export type Result<Output> = Success<Output> | Failure;
|
|
11
|
+
export type Schema<T = unknown, TOutput = T> = {
|
|
12
|
+
readonly "~standard": {
|
|
13
|
+
readonly validate: (value: unknown) => Result<TOutput> | Promise<Result<TOutput>>;
|
|
14
|
+
readonly types?: {
|
|
15
|
+
readonly input: T;
|
|
16
|
+
readonly output: TOutput;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type InferInput<T extends Schema> = NonNullable<T["~standard"]["types"]>["input"];
|
|
21
|
+
export type InferOutput<T extends Schema> = NonNullable<T["~standard"]["types"]>["output"];
|