revojs 0.1.3 → 0.1.5
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 +4 -3
- package/dist/index.js +25 -9
- package/dist/vite/index.js +23 -19
- package/package.json +1 -1
- package/src/types/index.d.ts +5 -0
package/dist/index.d.ts
CHANGED
|
@@ -38,8 +38,6 @@ declare class Scope extends EventTarget {
|
|
|
38
38
|
stop(): boolean;
|
|
39
39
|
}
|
|
40
40
|
declare function defineContext<T>(name: string): Descriptor<T>;
|
|
41
|
-
declare function isClient(): boolean;
|
|
42
|
-
declare function isServer(): boolean;
|
|
43
41
|
declare function isFailure<T>(result: Output<T>): result is Failure;
|
|
44
42
|
declare function parseSchema<T extends Schema>(scope: Scope, schema: T, value: unknown): InferOutput<T>;
|
|
45
43
|
declare function mergeObjects<TBase, TInput>(base: TBase, input: TInput): TBase & TInput;
|
|
@@ -78,6 +76,9 @@ declare function createApp(inputConfig?: Mergeable<Config>): App;
|
|
|
78
76
|
declare const SERVER = "ssr";
|
|
79
77
|
declare const CLIENT = "client";
|
|
80
78
|
//#endregion
|
|
79
|
+
//#region src/client/index.d.ts
|
|
80
|
+
declare function $fetch<T>(scope: Scope, input: string | URL, options?: RequestInit): Promise<T>;
|
|
81
|
+
//#endregion
|
|
81
82
|
//#region src/server/index.d.ts
|
|
82
83
|
type CookiePriority = "Low" | "Medium" | "High";
|
|
83
84
|
type CookieSameSite = "Lax" | "Strict" | "None";
|
|
@@ -174,4 +175,4 @@ declare const WILDCARD = "$";
|
|
|
174
175
|
declare const PARAMETER = ":";
|
|
175
176
|
declare const mimeTypes: Record<string, MimeType>;
|
|
176
177
|
//#endregion
|
|
177
|
-
export { App, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, Encoding, Environment, 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, Schema, Scope, Server, ServerContext, Source, StatusCode, StopEvent, Success, Virtual, WILDCARD, WildcardNode, createApp, createServer, defineContext, defineMiddleware, defineRoute,
|
|
178
|
+
export { $fetch, App, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, Encoding, Environment, 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, Schema, Scope, Server, ServerContext, Source, StatusCode, StopEvent, Success, Virtual, WILDCARD, WildcardNode, createApp, createServer, defineContext, defineMiddleware, defineRoute, isFailure, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, toRoutePath, useCookies, useQuery, useServer, useSetCookies, useUrl };
|
package/dist/index.js
CHANGED
|
@@ -102,7 +102,7 @@ function useQuery(scope, schema) {
|
|
|
102
102
|
}
|
|
103
103
|
function useCookies(scope, schema) {
|
|
104
104
|
const { request } = useServer(scope);
|
|
105
|
-
const entries = (
|
|
105
|
+
const entries = (import.meta.client ? document.cookie : request.headers.get("Cookie") ?? "").split("; ").reduce((result, cookie) => {
|
|
106
106
|
const [name, value] = cookie.split("=");
|
|
107
107
|
if (name && value) result[name] = decodeURIComponent(value);
|
|
108
108
|
return result;
|
|
@@ -129,7 +129,7 @@ function setCookie(scope, name, value, options) {
|
|
|
129
129
|
if (options?.priority) cookie += `; Priority=${options.priority}`;
|
|
130
130
|
if (options?.sameSite) cookie += `; SameSite=${options.sameSite}`;
|
|
131
131
|
if (options?.secure) cookie += `; Secure`;
|
|
132
|
-
if (
|
|
132
|
+
if (import.meta.client) document.cookie = cookie;
|
|
133
133
|
else response.headers.append("Set-Cookie", cookie);
|
|
134
134
|
}
|
|
135
135
|
function sendText(scope, text, config) {
|
|
@@ -286,12 +286,6 @@ var Scope = class extends EventTarget {
|
|
|
286
286
|
function defineContext(name) {
|
|
287
287
|
return name;
|
|
288
288
|
}
|
|
289
|
-
function isClient() {
|
|
290
|
-
return typeof window !== "undefined";
|
|
291
|
-
}
|
|
292
|
-
function isServer() {
|
|
293
|
-
return typeof window === "undefined";
|
|
294
|
-
}
|
|
295
289
|
function isFailure(result) {
|
|
296
290
|
return "issues" in result;
|
|
297
291
|
}
|
|
@@ -347,4 +341,26 @@ const SERVER = "ssr";
|
|
|
347
341
|
const CLIENT = "client";
|
|
348
342
|
|
|
349
343
|
//#endregion
|
|
350
|
-
|
|
344
|
+
//#region src/client/index.ts
|
|
345
|
+
async function $fetch(scope, input, options) {
|
|
346
|
+
let response;
|
|
347
|
+
if (import.meta.server) {
|
|
348
|
+
const { request, variables } = useServer(scope);
|
|
349
|
+
const next = new Scope();
|
|
350
|
+
next.setContext(SERVER_CONTEXT, {
|
|
351
|
+
request: new Request(new URL(input.toString(), request.url), options),
|
|
352
|
+
response: { headers: new Headers() },
|
|
353
|
+
variables
|
|
354
|
+
});
|
|
355
|
+
response = await (await import("#virtual/server")).default.fetch(next);
|
|
356
|
+
}
|
|
357
|
+
response ??= await fetch(input, options);
|
|
358
|
+
if (response.ok === false) throw response;
|
|
359
|
+
switch (response.headers.get("Content-Type")?.split(";").shift() ?? "") {
|
|
360
|
+
case "application/json": return response.json();
|
|
361
|
+
default: return response;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
//#endregion
|
|
366
|
+
export { $fetch, CLIENT, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, Scope, StopEvent, WILDCARD, createApp, createServer, defineContext, defineMiddleware, defineRoute, isFailure, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, toRoutePath, useCookies, useQuery, useServer, useSetCookies, useUrl };
|
package/dist/vite/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { existsSync, readFileSync } from "fs";
|
|
|
8
8
|
|
|
9
9
|
//#region package.json
|
|
10
10
|
var name = "revojs";
|
|
11
|
-
var version = "0.1.
|
|
11
|
+
var version = "0.1.5";
|
|
12
12
|
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/server/index.ts
|
|
@@ -291,27 +291,31 @@ function entry() {
|
|
|
291
291
|
name: "entry",
|
|
292
292
|
enforce: "pre",
|
|
293
293
|
sharedDuringBuild: true,
|
|
294
|
-
resolveId
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
294
|
+
resolveId: {
|
|
295
|
+
filter: { id: /\.html$/ },
|
|
296
|
+
handler(source, importer, options) {
|
|
297
|
+
if (this.environment.name === CLIENT) {
|
|
298
|
+
if (importer && entryPath) {
|
|
299
|
+
const path = join(dirname(importer), source);
|
|
300
|
+
if (existsSync(path)) return path;
|
|
301
|
+
}
|
|
302
|
+
if (options.isEntry) {
|
|
303
|
+
entryName = basename(source);
|
|
304
|
+
entryPath = source;
|
|
305
|
+
return entryName;
|
|
306
|
+
}
|
|
305
307
|
}
|
|
306
308
|
}
|
|
307
|
-
return null;
|
|
308
309
|
},
|
|
309
|
-
load
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
310
|
+
load: {
|
|
311
|
+
filter: { id: /\.html$/ },
|
|
312
|
+
handler(source) {
|
|
313
|
+
if (entryName && entryPath && source === entryName) return readFileSync(entryPath, {
|
|
314
|
+
encoding: "utf-8",
|
|
315
|
+
flag: "r"
|
|
316
|
+
});
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
315
319
|
}
|
|
316
320
|
};
|
|
317
321
|
}
|
package/package.json
CHANGED