revojs 0.1.11 → 0.1.12
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 +3 -2
- package/dist/index.js +15 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -131,6 +131,7 @@ declare function useServer<T extends Context>(scope: Scope): ServerContext<T>;
|
|
|
131
131
|
declare function useUrl(scope: Scope, base?: string): URL;
|
|
132
132
|
declare function useQuery(scope: Scope): Record<string, string>;
|
|
133
133
|
declare function useQuery<T extends Schema>(scope: Scope, schema: T): InferOutput<T>;
|
|
134
|
+
declare function withQuery(input: string, query: Record<string, string>): string;
|
|
134
135
|
declare function useCookies(scope: Scope): Record<string, string>;
|
|
135
136
|
declare function useCookies<T extends Schema>(scope: Scope, schema: T): InferOutput<T>;
|
|
136
137
|
declare function useSetCookies(scope: Scope): Record<string, string>;
|
|
@@ -146,7 +147,7 @@ declare function sendBadRequest(scope: Scope, text: string, config?: Mergeable<R
|
|
|
146
147
|
declare function sendUnauthorized(scope: Scope, config?: Mergeable<ResponseConfig>): Response;
|
|
147
148
|
declare function mimeType(file: string): MimeType;
|
|
148
149
|
declare function toRoutePath(path: string): [string, string | undefined];
|
|
149
|
-
declare function invoke(scope: Scope, pipeline: Array<Middleware>, index?: number): Result
|
|
150
|
+
declare function invoke(scope: Scope, pipeline: Array<Middleware>, index?: number): Promise<Result>;
|
|
150
151
|
declare function createServer(): Promise<Server>;
|
|
151
152
|
declare const ROUTER_CONTEXT: Descriptor<RouterContext>;
|
|
152
153
|
declare const SERVER_CONTEXT: Descriptor<ServerContext<Context>>;
|
|
@@ -193,4 +194,4 @@ declare const CLIENT = "client";
|
|
|
193
194
|
//#region src/client/index.d.ts
|
|
194
195
|
declare function $fetch<T>(scope: Scope, input: string | URL, options?: RequestInit): Promise<T>;
|
|
195
196
|
//#endregion
|
|
196
|
-
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, useQuery, useRouter, useServer, useSetCookies, useUrl };
|
|
197
|
+
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, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
|
package/dist/index.js
CHANGED
|
@@ -106,6 +106,14 @@ function useQuery(scope, schema) {
|
|
|
106
106
|
const entries = Object.fromEntries(searchParams);
|
|
107
107
|
return schema ? parseSchema(scope, schema, entries) : entries;
|
|
108
108
|
}
|
|
109
|
+
function withQuery(input, query) {
|
|
110
|
+
const url = new URL(input);
|
|
111
|
+
for (const name in query) {
|
|
112
|
+
const value = query[name];
|
|
113
|
+
if (value) url.searchParams.set(name, value);
|
|
114
|
+
}
|
|
115
|
+
return url.href;
|
|
116
|
+
}
|
|
109
117
|
function useCookies(scope, schema) {
|
|
110
118
|
const { request } = useServer(scope);
|
|
111
119
|
const entries = (import.meta.client ? document.cookie : request.headers.get("Cookie") ?? "").split("; ").reduce((result, cookie) => {
|
|
@@ -201,8 +209,8 @@ function toRoutePath(path) {
|
|
|
201
209
|
const result = ("/" + path).replaceAll(/\/index/g, "").replaceAll(/\[\.\.\.(.*?)\]/g, (_, value) => WILDCARD + value).replaceAll(/\[(.*?)\]/g, (_, value) => PARAMETER + value);
|
|
202
210
|
return (result.startsWith("/") ? result : "/" + result).split(".");
|
|
203
211
|
}
|
|
204
|
-
function invoke(scope, pipeline, index = 0) {
|
|
205
|
-
return pipeline.at(index)?.fetch(scope, () => invoke(scope, pipeline, index + 1));
|
|
212
|
+
async function invoke(scope, pipeline, index = 0) {
|
|
213
|
+
return await pipeline.at(index)?.fetch(scope, async () => await invoke(scope, pipeline, index + 1));
|
|
206
214
|
}
|
|
207
215
|
async function createServer() {
|
|
208
216
|
const router = new Router();
|
|
@@ -389,13 +397,15 @@ async function $fetch(scope, input, options) {
|
|
|
389
397
|
if (import.meta.server) {
|
|
390
398
|
const { states, request, variables } = useServer(scope);
|
|
391
399
|
const next = new Scope();
|
|
400
|
+
const url = new URL(input.toString(), request.url);
|
|
392
401
|
next.setContext(SERVER_CONTEXT, {
|
|
393
402
|
states,
|
|
394
|
-
request: new Request(
|
|
403
|
+
request: new Request(url, options),
|
|
395
404
|
response: { headers: new Headers() },
|
|
396
405
|
variables
|
|
397
406
|
});
|
|
398
|
-
|
|
407
|
+
const previous = new URL(request.url);
|
|
408
|
+
if (url.origin === previous.origin) response = await (await import("#virtual/server")).default.fetch(next);
|
|
399
409
|
}
|
|
400
410
|
response ??= await fetch(input, options);
|
|
401
411
|
if (response.ok === false) throw response;
|
|
@@ -406,4 +416,4 @@ async function $fetch(scope, input, options) {
|
|
|
406
416
|
}
|
|
407
417
|
|
|
408
418
|
//#endregion
|
|
409
|
-
export { $fetch, 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, useQuery, useRouter, useServer, useSetCookies, useUrl };
|
|
419
|
+
export { $fetch, 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, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
|