revojs 0.0.86 → 0.0.87
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/http/index.d.ts +1 -3
- package/dist/index.js +31 -7
- package/dist/schema/index.d.ts +2 -1
- package/package.json +1 -1
package/dist/http/index.d.ts
CHANGED
|
@@ -29,9 +29,7 @@ export declare function sendRedirect(scope: Scope, path: string): Response;
|
|
|
29
29
|
export declare function sendBadRequest(scope: Scope, text: string): Response;
|
|
30
30
|
export declare function sendUnauthorized(scope: Scope): Response;
|
|
31
31
|
export declare function useUrl(scope: Scope, base?: string): URL;
|
|
32
|
-
export declare function useQuery(scope: Scope):
|
|
33
|
-
[k: string]: string;
|
|
34
|
-
};
|
|
32
|
+
export declare function useQuery(scope: Scope): Record<string, string>;
|
|
35
33
|
export declare function useCookies(scope: Scope): Record<string, string>;
|
|
36
34
|
export declare function useSetCookies(scope: Scope): Record<string, string>;
|
|
37
35
|
export declare function setCookie(scope: Scope, name: string, value: string, options?: CookieOptions): void;
|
package/dist/index.js
CHANGED
|
@@ -117,6 +117,12 @@ function namespace(tag) {
|
|
|
117
117
|
return svgElements.has(tag) ? "http://www.w3.org/2000/svg" : "http://www.w3.org/1999/xhtml";
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/schema/index.ts
|
|
122
|
+
function isFailure(result) {
|
|
123
|
+
return "issues" in result;
|
|
124
|
+
}
|
|
125
|
+
|
|
120
126
|
//#endregion
|
|
121
127
|
//#region src/http/index.ts
|
|
122
128
|
function sendText(scope, text) {
|
|
@@ -154,25 +160,43 @@ function useUrl(scope, base) {
|
|
|
154
160
|
const { request } = useRuntime(scope);
|
|
155
161
|
return new URL(request?.url ?? window?.location.href, base);
|
|
156
162
|
}
|
|
157
|
-
function useQuery(scope) {
|
|
163
|
+
function useQuery(scope, schema) {
|
|
158
164
|
const { searchParams } = useUrl(scope);
|
|
159
|
-
|
|
165
|
+
const entries = Object.fromEntries(searchParams);
|
|
166
|
+
if (schema) {
|
|
167
|
+
const result = schema["~standard"].validate(entries);
|
|
168
|
+
if (isFailure(result)) throw sendBadRequest(scope, result.issues.join(", "));
|
|
169
|
+
return result.value;
|
|
170
|
+
}
|
|
171
|
+
return entries;
|
|
160
172
|
}
|
|
161
|
-
function useCookies(scope) {
|
|
173
|
+
function useCookies(scope, schema) {
|
|
162
174
|
const { request } = useRuntime(scope);
|
|
163
|
-
|
|
175
|
+
const entries = (isClient() ? document.cookie : request.headers.get("Cookie") ?? "").split("; ").reduce((result, cookie) => {
|
|
164
176
|
const [name, value] = cookie.split("=");
|
|
165
177
|
if (name && value) result[name] = decodeURIComponent(value);
|
|
166
178
|
return result;
|
|
167
179
|
}, {});
|
|
180
|
+
if (schema) {
|
|
181
|
+
const result = schema["~standard"].validate(entries);
|
|
182
|
+
if (isFailure(result)) throw sendBadRequest(scope, result.issues.join(", "));
|
|
183
|
+
return result.value;
|
|
184
|
+
}
|
|
185
|
+
return entries;
|
|
168
186
|
}
|
|
169
|
-
function useSetCookies(scope) {
|
|
187
|
+
function useSetCookies(scope, schema) {
|
|
170
188
|
const { request } = useRuntime(scope);
|
|
171
|
-
|
|
189
|
+
const entries = request.headers.getSetCookie().reduce((result, cookie) => {
|
|
172
190
|
const [name, value] = cookie.split("=");
|
|
173
191
|
if (name && value) result[name] = decodeURIComponent(value);
|
|
174
192
|
return result;
|
|
175
193
|
}, {});
|
|
194
|
+
if (schema) {
|
|
195
|
+
const result = schema["~standard"].validate(entries);
|
|
196
|
+
if (isFailure(result)) throw sendBadRequest(scope, result.issues.join(", "));
|
|
197
|
+
return result.value;
|
|
198
|
+
}
|
|
199
|
+
return entries;
|
|
176
200
|
}
|
|
177
201
|
function setCookie(scope, name, value, options) {
|
|
178
202
|
const { response } = useRuntime(scope);
|
|
@@ -1012,4 +1036,4 @@ function useLocale(scope, context) {
|
|
|
1012
1036
|
const LOCALE_CONTEXT = defineContext("LOCALE_CONTEXT");
|
|
1013
1037
|
|
|
1014
1038
|
//#endregion
|
|
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 };
|
|
1039
|
+
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, isFailure, 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/schema/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type Failure = {
|
|
|
10
10
|
export type Result<Output> = Success<Output> | Failure;
|
|
11
11
|
export type Schema<T = unknown, TOutput = T> = {
|
|
12
12
|
readonly "~standard": {
|
|
13
|
-
readonly validate: (value: unknown) => Result<TOutput
|
|
13
|
+
readonly validate: (value: unknown) => Result<TOutput>;
|
|
14
14
|
readonly types?: {
|
|
15
15
|
readonly input: T;
|
|
16
16
|
readonly output: TOutput;
|
|
@@ -19,3 +19,4 @@ export type Schema<T = unknown, TOutput = T> = {
|
|
|
19
19
|
};
|
|
20
20
|
export type InferInput<T extends Schema> = NonNullable<T["~standard"]["types"]>["input"];
|
|
21
21
|
export type InferOutput<T extends Schema> = NonNullable<T["~standard"]["types"]>["output"];
|
|
22
|
+
export declare function isFailure<T>(result: Result<T>): result is Failure;
|