revojs 0.1.21 → 0.1.22
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-gPmc1xyv.js → app-CZxSS8Ok.js} +28 -19
- package/dist/{index-D6BvOWjN.d.ts → index-CUwjaRno.d.ts} +10 -13
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/kit/index.d.ts +1 -1
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +10 -14
- package/package.json +1 -1
|
@@ -117,7 +117,7 @@ function withQuery(input, query) {
|
|
|
117
117
|
}
|
|
118
118
|
function useCookies(scope, schema) {
|
|
119
119
|
const { request } = useServer(scope);
|
|
120
|
-
const entries = (
|
|
120
|
+
const entries = (isClient ? document.cookie : request.headers.get("Cookie") ?? "").split("; ").reduce((result, cookie) => {
|
|
121
121
|
const [name, value] = cookie.split("=");
|
|
122
122
|
if (name && value) result[name] = decodeURIComponent(value);
|
|
123
123
|
return result;
|
|
@@ -144,11 +144,11 @@ function setCookie(scope, name, value, options) {
|
|
|
144
144
|
if (options?.priority) cookie += `; Priority=${options.priority}`;
|
|
145
145
|
if (options?.sameSite) cookie += `; SameSite=${options.sameSite}`;
|
|
146
146
|
if (options?.secure) cookie += `; Secure`;
|
|
147
|
-
if (
|
|
147
|
+
if (isServer) response.headers.append("Set-Cookie", cookie);
|
|
148
148
|
else document.cookie = cookie;
|
|
149
149
|
}
|
|
150
150
|
function getState(scope, name) {
|
|
151
|
-
if (
|
|
151
|
+
if (isServer) {
|
|
152
152
|
const { states } = useServer(scope);
|
|
153
153
|
return states[name];
|
|
154
154
|
} else {
|
|
@@ -160,7 +160,7 @@ function getState(scope, name) {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
function setState(scope, name, value) {
|
|
163
|
-
if (
|
|
163
|
+
if (isServer) {
|
|
164
164
|
const { states } = useServer(scope);
|
|
165
165
|
states[name] = value;
|
|
166
166
|
} else {
|
|
@@ -284,22 +284,34 @@ const mimeTypes = {
|
|
|
284
284
|
exe: "application/vnd.microsoft.portable-executable",
|
|
285
285
|
apk: "application/vnd.android.package-archive"
|
|
286
286
|
};
|
|
287
|
+
const isServer = import.meta.server ?? globalThis?.import?.meta?.server;
|
|
288
|
+
const isClient = import.meta.client ?? globalThis?.import?.meta?.client;
|
|
287
289
|
|
|
288
290
|
//#endregion
|
|
289
291
|
//#region src/shared/index.ts
|
|
290
|
-
var
|
|
291
|
-
constructor() {
|
|
292
|
-
super("stop");
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
var Scope = class extends EventTarget {
|
|
292
|
+
var Scope = class {
|
|
296
293
|
parentScope;
|
|
297
294
|
context;
|
|
295
|
+
hooks;
|
|
298
296
|
constructor(parentScope) {
|
|
299
|
-
super();
|
|
300
297
|
this.parentScope = parentScope;
|
|
301
|
-
this.parentScope?.onStop(() => this.stop());
|
|
302
298
|
this.context = {};
|
|
299
|
+
this.hooks = {};
|
|
300
|
+
}
|
|
301
|
+
registerHook(name, invoke$1) {
|
|
302
|
+
const targets = this.hooks[name] ?? [];
|
|
303
|
+
targets.push(invoke$1);
|
|
304
|
+
this.hooks[name] = targets;
|
|
305
|
+
return () => {
|
|
306
|
+
const index = this.hooks[name]?.indexOf(invoke$1);
|
|
307
|
+
if (index && index >= 0) this.hooks[name]?.splice(index, 1);
|
|
308
|
+
if (this.hooks[name]?.length === 0) delete this.hooks[name];
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
async dispatchHook(name, ...inputs) {
|
|
312
|
+
const results = new Array();
|
|
313
|
+
for (const invoke$1 of this.hooks[name] ?? []) results.push(await invoke$1(...inputs));
|
|
314
|
+
return results;
|
|
303
315
|
}
|
|
304
316
|
getContext(input) {
|
|
305
317
|
let scope = this;
|
|
@@ -312,13 +324,10 @@ var Scope = class extends EventTarget {
|
|
|
312
324
|
setContext(input, value) {
|
|
313
325
|
this.context[input] = value;
|
|
314
326
|
}
|
|
315
|
-
onStop(input) {
|
|
316
|
-
this.addEventListener("stop", input, { once: true });
|
|
317
|
-
}
|
|
318
|
-
stop() {
|
|
319
|
-
return this.dispatchEvent(new StopEvent());
|
|
320
|
-
}
|
|
321
327
|
};
|
|
328
|
+
function defineHook(name) {
|
|
329
|
+
return name;
|
|
330
|
+
}
|
|
322
331
|
function defineContext(name) {
|
|
323
332
|
return name;
|
|
324
333
|
}
|
|
@@ -367,4 +376,4 @@ const SERVER = "ssr";
|
|
|
367
376
|
const CLIENT = "client";
|
|
368
377
|
|
|
369
378
|
//#endregion
|
|
370
|
-
export { CLIENT, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope,
|
|
379
|
+
export { CLIENT, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope, WILDCARD, createApp, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
type Descriptor<T> = string & {
|
|
3
3
|
[descriptor]: T;
|
|
4
4
|
};
|
|
5
|
-
type
|
|
5
|
+
type Invoke = (...inputs: Array<any>) => any;
|
|
6
|
+
type Context = Record<string, any>;
|
|
6
7
|
type Output<T> = Success<T> | Failure;
|
|
7
8
|
type InferInput<T extends Schema> = NonNullable<T["~standard"]["types"]>["input"];
|
|
8
9
|
type InferOutput<T extends Schema> = NonNullable<T["~standard"]["types"]>["output"];
|
|
@@ -25,28 +26,22 @@ interface Schema<T = unknown, TOutput = T> {
|
|
|
25
26
|
};
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
|
-
declare class
|
|
29
|
-
constructor();
|
|
30
|
-
}
|
|
31
|
-
declare class Scope extends EventTarget {
|
|
29
|
+
declare class Scope {
|
|
32
30
|
parentScope?: Scope;
|
|
33
31
|
readonly context: Context;
|
|
32
|
+
readonly hooks: Record<string, Array<Invoke>>;
|
|
34
33
|
constructor(parentScope?: Scope);
|
|
34
|
+
registerHook<T extends Invoke>(name: Descriptor<T>, invoke: T): () => void;
|
|
35
|
+
dispatchHook<T extends Invoke>(name: Descriptor<T>, ...inputs: Parameters<T>): Promise<Awaited<ReturnType<T>>[]>;
|
|
35
36
|
getContext<T>(input: Descriptor<T>): T;
|
|
36
37
|
setContext<T>(input: Descriptor<T>, value: T): void;
|
|
37
|
-
onStop(input: (event: StopEvent) => void): void;
|
|
38
|
-
stop(): boolean;
|
|
39
38
|
}
|
|
39
|
+
declare function defineHook<T extends Invoke>(name: string): Descriptor<T>;
|
|
40
40
|
declare function defineContext<T>(name: string): Descriptor<T>;
|
|
41
41
|
declare function isFailure<T>(result: Output<T>): result is Failure;
|
|
42
42
|
declare function parseSchema<T extends Schema>(scope: Scope, schema: T, value: unknown): InferOutput<T>;
|
|
43
43
|
declare function mergeObjects<TBase, TInput>(base: TBase, input: TInput): TBase & TInput;
|
|
44
44
|
declare const descriptor: unique symbol;
|
|
45
|
-
declare global {
|
|
46
|
-
interface ElementEventMap {
|
|
47
|
-
stop: StopEvent;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
45
|
//#endregion
|
|
51
46
|
//#region src/server/index.d.ts
|
|
52
47
|
type CookiePriority = "Low" | "Medium" | "High";
|
|
@@ -152,6 +147,8 @@ declare const WILDCARD = "$";
|
|
|
152
147
|
declare const PARAMETER = ":";
|
|
153
148
|
declare let STATES: States;
|
|
154
149
|
declare const mimeTypes: Record<string, MimeType>;
|
|
150
|
+
declare const isServer: boolean;
|
|
151
|
+
declare const isClient: boolean;
|
|
155
152
|
//#endregion
|
|
156
153
|
//#region src/app/index.d.ts
|
|
157
154
|
type Environment = typeof CLIENT | typeof SERVER;
|
|
@@ -191,4 +188,4 @@ declare const CLIENT = "client";
|
|
|
191
188
|
//#region src/client/index.d.ts
|
|
192
189
|
declare function $fetch<T>(scope: Scope, input: string | URL, options?: RequestInit): Promise<T>;
|
|
193
190
|
//#endregion
|
|
194
|
-
export { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, 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, STATES, Schema, Scope, Server, ServerContext, Source, States, StatusCode,
|
|
191
|
+
export { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, HttpMethod, InferInput, InferOutput, Invoke, 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, Success, Virtual, WILDCARD, WildcardNode, createApp, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, 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, STATES, Schema, Scope, Server, ServerContext, Source, States, StatusCode,
|
|
2
|
-
export { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, 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, STATES, Schema, Scope, Server, ServerContext, Source, States, StatusCode,
|
|
1
|
+
import { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, HttpMethod, InferInput, InferOutput, Invoke, 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, Success, Virtual, WILDCARD, WildcardNode, createApp, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery } from "./index-CUwjaRno.js";
|
|
2
|
+
export { $fetch, App, BuildConfig, CLIENT, Config, Context, CookieOptions, CookiePriority, CookieSameSite, Descriptor, DevelopmentConfig, Encoding, Environment, Failure, HttpMethod, InferInput, InferOutput, Invoke, 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, Success, Virtual, WILDCARD, WildcardNode, createApp, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { CLIENT, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope,
|
|
1
|
+
import { CLIENT, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope, WILDCARD, createApp, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery } from "./app-CZxSS8Ok.js";
|
|
2
2
|
|
|
3
3
|
//#region src/client/index.ts
|
|
4
4
|
async function $fetch(scope, input, options) {
|
|
5
5
|
let response;
|
|
6
|
-
if (
|
|
6
|
+
if (isServer) {
|
|
7
7
|
const { states, request, variables } = useServer(scope);
|
|
8
8
|
const next = new Scope();
|
|
9
9
|
const url = new URL(input.toString(), request.url);
|
|
@@ -25,4 +25,4 @@ async function $fetch(scope, input, options) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
//#endregion
|
|
28
|
-
export { $fetch, CLIENT, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope,
|
|
28
|
+
export { $fetch, CLIENT, PARAMETER, ROUTER_CONTEXT, Radix, Router, SERVER, SERVER_CONTEXT, STATES, Scope, WILDCARD, createApp, createServer, defineContext, defineHook, defineMiddleware, defineRoute, getState, invoke, isClient, isFailure, isServer, mergeObjects, mimeType, mimeTypes, parseSchema, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, setState, toRoutePath, useCookies, useHeaders, useQuery, useRouter, useServer, useSetCookies, useUrl, withQuery };
|
package/dist/kit/index.d.ts
CHANGED
package/dist/vite/index.d.ts
CHANGED
package/dist/vite/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CLIENT, SERVER, SERVER_CONTEXT, Scope, createApp, invoke } from "../app-
|
|
1
|
+
import { CLIENT, SERVER, SERVER_CONTEXT, Scope, createApp, invoke } from "../app-CZxSS8Ok.js";
|
|
2
2
|
import { useKit } from "../kit-Bzr1NqHb.js";
|
|
3
3
|
import { basename, dirname, isAbsolute, join, posix, relative, win32 } from "path";
|
|
4
4
|
import { isRunnableDevEnvironment } from "vite";
|
|
@@ -307,7 +307,7 @@ function virtuals(virtuals$1) {
|
|
|
307
307
|
//#endregion
|
|
308
308
|
//#region package.json
|
|
309
309
|
var name = "revojs";
|
|
310
|
-
var version = "0.1.
|
|
310
|
+
var version = "0.1.22";
|
|
311
311
|
|
|
312
312
|
//#endregion
|
|
313
313
|
//#region src/vite/index.ts
|
|
@@ -406,18 +406,14 @@ function revojs(config) {
|
|
|
406
406
|
if (server) {
|
|
407
407
|
request.url = request.originalUrl;
|
|
408
408
|
const scope = new Scope();
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
if (result) await toNodeRequest(result, response);
|
|
418
|
-
} finally {
|
|
419
|
-
scope.stop();
|
|
420
|
-
}
|
|
409
|
+
scope.setContext(SERVER_CONTEXT, {
|
|
410
|
+
states: {},
|
|
411
|
+
request: fromNodeRequest(request, response),
|
|
412
|
+
response: { headers: new Headers() },
|
|
413
|
+
variables: process.env
|
|
414
|
+
});
|
|
415
|
+
var result = await invoke(scope, app.config.development.middlewares.concat({ fetch: server.fetch }));
|
|
416
|
+
if (result) await toNodeRequest(result, response);
|
|
421
417
|
}
|
|
422
418
|
next();
|
|
423
419
|
});
|