@sx3/ultra 0.0.3 → 0.0.4
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/auth.d.mts +12 -15
- package/dist/auth.mjs +1 -1
- package/dist/client.d.mts +6 -6
- package/dist/{context-DNamt_XE.d.mts → context-BZAzgugo.d.mts} +1 -1
- package/dist/context.d.mts +1 -1
- package/dist/context.mjs +1 -1
- package/dist/cors.d.mts +3 -3
- package/dist/cors.mjs +1 -1
- package/dist/crypto.mjs +1 -1
- package/dist/error.mjs +1 -1
- package/dist/{http-CD8MvQOV.d.mts → http-NhhQxMv8.d.mts} +2 -2
- package/dist/http.d.mts +2 -2
- package/dist/{middleware-DVREjjkO.d.mts → middleware-DB4PWjb4.d.mts} +4 -4
- package/dist/middleware.d.mts +3 -3
- package/dist/{procedure-BekIoOQX.mjs → procedure-AntXykJT.mjs} +1 -1
- package/dist/procedure.d.mts +3 -3
- package/dist/procedure.mjs +1 -1
- package/dist/{response-D9PTLpdq.mjs → response-D935Hx3o.mjs} +1 -1
- package/dist/response.mjs +1 -1
- package/dist/{rpc-DADpT17P.d.mts → rpc-Ch2UXReT.d.mts} +1 -1
- package/dist/rpc.d.mts +1 -1
- package/dist/rpc.mjs +1 -1
- package/dist/session.d.mts +13 -8
- package/dist/session.mjs +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/ultra-Dawe5ndl.d.mts +69 -0
- package/dist/ultra.d.mts +4 -68
- package/dist/ultra.mjs +1 -1
- package/dist/{validation-s1s8P8HO.mjs → validation-dJpfcBud.mjs} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +1 -1
- package/dist/context-BAOh_2qI.mjs +0 -1
- package/dist/crypto-DrpstqPB.mjs +0 -1
- package/dist/test.d.mts +0 -1
- package/dist/test.mjs +0 -1
- /package/dist/{error-CvEWFOYT.mjs → error-Dq1biCC8.mjs} +0 -0
- /package/dist/{rpc-D9H6IkRD.mjs → rpc-CAwkzxZe.mjs} +0 -0
- /package/dist/{types-CzIiTHWF.d.mts → types-Cn69QrjS.d.mts} +0 -0
- /package/dist/{validation-Dfgqsq2f.d.mts → validation-CkRfxQJ_.d.mts} +0 -0
package/dist/auth.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { o as Promisable } from "./types-
|
|
3
|
-
import "./http-
|
|
4
|
-
import { t as Middleware } from "./middleware-
|
|
5
|
-
import
|
|
6
|
-
import { Session } from "./session.mjs";
|
|
1
|
+
import { t as BaseContext } from "./context-BZAzgugo.mjs";
|
|
2
|
+
import { o as Promisable } from "./types-Cn69QrjS.mjs";
|
|
3
|
+
import "./http-NhhQxMv8.mjs";
|
|
4
|
+
import { t as Middleware } from "./middleware-DB4PWjb4.mjs";
|
|
5
|
+
import "./ultra-Dawe5ndl.mjs";
|
|
6
|
+
import { Session, SessionContext } from "./session.mjs";
|
|
7
7
|
|
|
8
8
|
//#region src/auth.d.ts
|
|
9
9
|
interface AuthProvider<User> {
|
|
@@ -13,7 +13,7 @@ interface AuthProvider<User> {
|
|
|
13
13
|
logout: () => Promisable<void>;
|
|
14
14
|
setUser: (user: User) => Promisable<void>;
|
|
15
15
|
}
|
|
16
|
-
type AuthProviderFactory<User = any> = (context:
|
|
16
|
+
type AuthProviderFactory<User = any> = (context: SessionContext) => AuthProvider<User>;
|
|
17
17
|
interface AuthConfig<P extends Record<string, AuthProviderFactory> = Record<string, AuthProviderFactory>> {
|
|
18
18
|
provider: keyof P;
|
|
19
19
|
providers: P;
|
|
@@ -23,17 +23,14 @@ type AuthContext<User> = BaseContext & {
|
|
|
23
23
|
auth: Auth<User>;
|
|
24
24
|
};
|
|
25
25
|
declare function defineConfig<User, P extends Record<string, AuthProviderFactory<User>> = Record<string, AuthProviderFactory<User>>>(config: AuthConfig<P>): AuthConfig<P>;
|
|
26
|
-
declare function createAuthModule<User, P extends Record<string, AuthProviderFactory<User>> = Record<string, AuthProviderFactory<User>>>(config: AuthConfig<P>): Ultra<ProceduresMap, BaseContext & {
|
|
27
|
-
auth: Auth<User, P>;
|
|
28
|
-
}, DefaultSocketData>;
|
|
29
26
|
declare const isAuthenticated: Middleware<any, any, AuthContext<any>>;
|
|
30
27
|
declare const isGuest: Middleware<any, any, AuthContext<any>>;
|
|
31
28
|
declare class Auth<User, Providers extends Record<string, AuthProviderFactory<User>> = Record<string, AuthProviderFactory<User>>> {
|
|
32
29
|
protected readonly config: AuthConfig<Providers>;
|
|
33
|
-
protected readonly context:
|
|
30
|
+
protected readonly context: SessionContext;
|
|
34
31
|
protected readonly usingProvider: keyof Providers;
|
|
35
32
|
protected readonly providerCache: Map<keyof Providers, AuthProvider<User>>;
|
|
36
|
-
constructor(config: AuthConfig<Providers>, context:
|
|
33
|
+
constructor(config: AuthConfig<Providers>, context: SessionContext, provider?: keyof Providers, providerCache?: Map<keyof Providers, AuthProvider<User>>);
|
|
37
34
|
use(provider: keyof Providers): Auth<User, Providers>;
|
|
38
35
|
get user(): User | null;
|
|
39
36
|
check(): Promisable<boolean>;
|
|
@@ -43,9 +40,9 @@ declare class Auth<User, Providers extends Record<string, AuthProviderFactory<Us
|
|
|
43
40
|
protected get provider(): AuthProvider<User>;
|
|
44
41
|
}
|
|
45
42
|
declare class SessionAuthProvider<User> implements AuthProvider<User> {
|
|
46
|
-
protected readonly context:
|
|
43
|
+
protected readonly context: SessionContext;
|
|
47
44
|
protected readonly sessionKey: string;
|
|
48
|
-
constructor(context:
|
|
45
|
+
constructor(context: SessionContext, sessionKey?: string);
|
|
49
46
|
get user(): NonNullable<User> | null;
|
|
50
47
|
check(): boolean;
|
|
51
48
|
login(user: User): void;
|
|
@@ -53,4 +50,4 @@ declare class SessionAuthProvider<User> implements AuthProvider<User> {
|
|
|
53
50
|
setUser(user: User): void;
|
|
54
51
|
}
|
|
55
52
|
//#endregion
|
|
56
|
-
export { Auth, AuthContext, AuthProvider, SessionAuthProvider,
|
|
53
|
+
export { Auth, AuthContext, AuthProvider, SessionAuthProvider, defineConfig, isAuthenticated, isGuest };
|
package/dist/auth.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./error-
|
|
1
|
+
import{r as e}from"./error-Dq1biCC8.mjs";function t(e){return e}const n=async t=>await t.context.auth.check()?t.next():new e,r=async t=>await t.context.auth.check()?new e:t.next();var i=class e{config;context;usingProvider;providerCache;constructor(e,t,n=e.provider,r=new Map){this.config=e,this.context=t,this.usingProvider=n,this.providerCache=r}use(t){return new e(this.config,this.context,t,this.providerCache)}get user(){return this.provider.user}check(){return this.provider.check()}login(e){return this.provider.login(e)}logout(){return this.provider.logout()}setUser(e){return this.provider.setUser(e)}get provider(){let e=this.providerCache.get(this.usingProvider);if(e)return e;let t=this.config.providers[this.usingProvider];if(!t)throw Error(`Auth provider "${String(this.usingProvider)}" is not configured.`);let n=t(this.context);return this.providerCache.set(this.usingProvider,n),n}},a=class{context;sessionKey;constructor(e,t=`user`){this.context=e,this.sessionKey=t}get user(){return this.context.session.get(this.sessionKey)||null}check(){return this.user!==null}login(e){this.setUser(e),this.context.session.regenerate()}logout(){this.context.session.delete(this.sessionKey)}setUser(e){this.context.session.set(this.sessionKey,e)}};export{i as Auth,a as SessionAuthProvider,t as defineConfig,n as isAuthenticated,r as isGuest};
|
package/dist/client.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "./context-
|
|
2
|
-
import "./http-
|
|
3
|
-
import { i as Procedure } from "./middleware-
|
|
4
|
-
import {
|
|
1
|
+
import "./context-BZAzgugo.mjs";
|
|
2
|
+
import "./http-NhhQxMv8.mjs";
|
|
3
|
+
import { i as Procedure } from "./middleware-DB4PWjb4.mjs";
|
|
4
|
+
import { n as Ultra, t as ProceduresMap } from "./ultra-Dawe5ndl.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/client.d.ts
|
|
7
7
|
type GetProcedures<T> = T extends Ultra<infer P, any, any> ? P : never;
|
|
@@ -12,12 +12,12 @@ interface HTTPClientOptions extends Omit<RequestInit, 'body'> {
|
|
|
12
12
|
baseUrl: string;
|
|
13
13
|
timeout?: number;
|
|
14
14
|
}
|
|
15
|
-
declare function createHTTPClient<
|
|
15
|
+
declare function createHTTPClient<U extends Ultra<any, any, any>>(clientOptions: HTTPClientOptions): BuildClient<GetProcedures<U>, Partial<HTTPClientOptions>>;
|
|
16
16
|
interface WebSocketClientOptions {
|
|
17
17
|
socket: () => WebSocket | null;
|
|
18
18
|
timeout?: number;
|
|
19
19
|
}
|
|
20
|
-
declare function createWebSocketClient<
|
|
20
|
+
declare function createWebSocketClient<U extends Ultra<any, any, any>>(options: WebSocketClientOptions): BuildClient<GetProcedures<U>, Partial<WebSocketClientOptions>>;
|
|
21
21
|
type ClientsCallsParams = Partial<WebSocketClientOptions> | Partial<HTTPClientOptions>;
|
|
22
22
|
interface SuperClientOptions<B extends Ultra<any, any, any>> {
|
|
23
23
|
pick: (...args: Parameters<Invoke<ClientsCallsParams>>) => BuildClient<GetProcedures<B>, ClientsCallsParams>;
|
|
@@ -10,7 +10,7 @@ interface WSContext<SocketData> {
|
|
|
10
10
|
server: Server<SocketData>;
|
|
11
11
|
ws: ServerWebSocket<SocketData>;
|
|
12
12
|
}
|
|
13
|
-
type BaseContext<SocketData extends DefaultSocketData =
|
|
13
|
+
type BaseContext<SocketData extends DefaultSocketData = any> = HTTPContext | WSContext<SocketData>;
|
|
14
14
|
declare function isHTTP(context: BaseContext): context is HTTPContext;
|
|
15
15
|
declare function isWS<SocketData extends DefaultSocketData = DefaultSocketData>(context: BaseContext): context is WSContext<SocketData>;
|
|
16
16
|
//#endregion
|
package/dist/context.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as isHTTP, i as WSContext, n as DefaultSocketData, o as isWS, r as HTTPContext, t as BaseContext } from "./context-
|
|
1
|
+
import { a as isHTTP, i as WSContext, n as DefaultSocketData, o as isWS, r as HTTPContext, t as BaseContext } from "./context-BZAzgugo.mjs";
|
|
2
2
|
export { BaseContext, DefaultSocketData, HTTPContext, WSContext, isHTTP, isWS };
|
package/dist/context.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function e(e){return`request`in e}function t(e){return`ws`in e}export{e as isHTTP,t as isWS};
|
package/dist/cors.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as BaseContext } from "./context-
|
|
2
|
-
import "./http-
|
|
3
|
-
import { t as Middleware } from "./middleware-
|
|
1
|
+
import { t as BaseContext } from "./context-BZAzgugo.mjs";
|
|
2
|
+
import "./http-NhhQxMv8.mjs";
|
|
3
|
+
import { t as Middleware } from "./middleware-DB4PWjb4.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/cors.d.ts
|
|
6
6
|
interface CorsConfig {
|
package/dist/cors.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./response-
|
|
1
|
+
import{t as e}from"./response-D935Hx3o.mjs";const t={"Access-Control-Allow-Methods":[`GET`,`POST`,`PUT`,`PATCH`,`DELETE`,`OPTIONS`].join(`, `),"Access-Control-Allow-Headers":[`Accept-Language`,`Accept`,`Content-Type`,`Content-Language`,`Range`].join(`, `),"Access-Control-Expose-Headers":[`Cache-Control`,`Content-Language`,`Content-Type`,`Expires`,`Last-Modified`,`Pragma`].join(`, `),"Access-Control-Max-Age":`3600`};function n(n){let r={...t,...n.methods?.length&&{"Access-Control-Allow-Methods":n.methods.join(`, `)},...n.allowedHeaders?.length&&{"Access-Control-Allow-Headers":n.allowedHeaders.join(`, `)},...n.exposedHeaders?.length&&{"Access-Control-Expose-Headers":n.exposedHeaders.join(`, `)},...n.credentials&&!n.origin.includes(`*`)&&{"Access-Control-Allow-Credentials":`true`},...n.maxAge&&{"Access-Control-Max-Age":n.maxAge.toString()}};return async t=>{if(!(`request`in t.context))return t.next();let i=t.context.request.headers.get(`Origin`);if(!i||!n.origin.includes(i))return t.next();if(t.context.request.method===`OPTIONS`)return new Response(null,{status:204,headers:{"Access-Control-Allow-Origin":i,...r}});let a=e(await t.next());for(let e in a.headers.set(`Access-Control-Allow-Origin`,i),r)a.headers.set(e,r[e]);return a}}export{n as createCORSMiddleware};
|
package/dist/crypto.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createCipheriv as e,createDecipheriv as t,createHmac as n,randomBytes as r,timingSafeEqual as i}from"node:crypto";const a=`aes-256-gcm`,o=`base64url`;function s(e,t){let r=Buffer.from(e).toString(o);return`${r}.${n(`sha256`,t).update(r).digest(o)}`}function c(e,t){let[r,a]=e.split(`.`);if(!r||!a)return null;let s=n(`sha256`,t).update(r).digest(o),c=Buffer.from(a,o),l=Buffer.from(s,o);return c.length!==l.length||!i(c,l)?null:Buffer.from(r,o).toString()}function l(t,n){let i=r(12),s=e(a,n,i),c=s.update(t,`utf-8`,o);return c+=s.final(o),Buffer.concat([i,s.getAuthTag(),Buffer.from(c,o)]).toString(o)}function u(e,n){let r=Buffer.from(e,o);if(r.length<28)return null;let i=r.subarray(0,12),s=r.subarray(12,28),c=r.subarray(28),l=t(a,n,i);return l.setAuthTag(s),`${l.update(c,void 0,`utf-8`)}${l.final(`utf-8`)}`}export{u as decrypt,l as encrypt,s as sign,c as unsign};
|
package/dist/error.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,i as t,n,r,t as i}from"./error-
|
|
1
|
+
import{a as e,i as t,n,r,t as i}from"./error-Dq1biCC8.mjs";export{i as NotFoundError,n as UltraError,r as UnauthorizedError,t as UnsupportedProtocolError,e as ValidationError};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as DefaultSocketData } from "./context-
|
|
2
|
-
import { o as Promisable } from "./types-
|
|
1
|
+
import { n as DefaultSocketData } from "./context-BZAzgugo.mjs";
|
|
2
|
+
import { o as Promisable } from "./types-Cn69QrjS.mjs";
|
|
3
3
|
import { BunRequest, Server } from "bun";
|
|
4
4
|
|
|
5
5
|
//#region src/http.d.ts
|
package/dist/http.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./context-
|
|
2
|
-
import { n as BunRoutes, r as HTTPMethod, t as BunRouteHandler } from "./http-
|
|
1
|
+
import "./context-BZAzgugo.mjs";
|
|
2
|
+
import { n as BunRoutes, r as HTTPMethod, t as BunRouteHandler } from "./http-NhhQxMv8.mjs";
|
|
3
3
|
export { BunRouteHandler, BunRoutes, HTTPMethod };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as BaseContext } from "./context-
|
|
2
|
-
import { o as Promisable } from "./types-
|
|
3
|
-
import { r as HTTPMethod } from "./http-
|
|
4
|
-
import { c as StandardSchemaV1 } from "./validation-
|
|
1
|
+
import { t as BaseContext } from "./context-BZAzgugo.mjs";
|
|
2
|
+
import { o as Promisable } from "./types-Cn69QrjS.mjs";
|
|
3
|
+
import { r as HTTPMethod } from "./http-NhhQxMv8.mjs";
|
|
4
|
+
import { c as StandardSchemaV1 } from "./validation-CkRfxQJ_.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/procedure.d.ts
|
|
7
7
|
interface ProcedureOptions<I, C> {
|
package/dist/middleware.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./context-
|
|
2
|
-
import "./http-
|
|
3
|
-
import { n as MiddlewareOptions, t as Middleware } from "./middleware-
|
|
1
|
+
import "./context-BZAzgugo.mjs";
|
|
2
|
+
import "./http-NhhQxMv8.mjs";
|
|
3
|
+
import { n as MiddlewareOptions, t as Middleware } from "./middleware-DB4PWjb4.mjs";
|
|
4
4
|
export { Middleware, MiddlewareOptions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./validation-
|
|
1
|
+
import{t as e}from"./validation-dJpfcBud.mjs";var t=class{inputSchema;outputSchema;handlerFunction;middleware=new Set;httpOptions;input(e){return e&&(this.inputSchema=e),this}output(e){return e&&(this.outputSchema=e),this}handler(e){return this.handlerFunction=e,this}http(e){return this.httpOptions={...e,enabled:!0},this}use(e){return this.middleware.add(e),this}wrap(){if(!this.handlerFunction)throw Error(`Procedure handler is not defined`);if(!this.inputSchema&&!this.outputSchema&&!this.middleware.size)return this.handlerFunction;let t=this.handlerFunction;switch(!0){case!this.inputSchema&&!this.outputSchema:break;case!this.inputSchema:{let n=t;t=async t=>e(this.outputSchema,await n(t));break}case!this.outputSchema:{let n=t;t=async t=>n({...t,input:await e(this.inputSchema,t.input)});break}default:{let n=t;t=async t=>{let r=await n({...t,input:await e(this.inputSchema,t.input)});return e(this.outputSchema,r)}}}if(this.middleware.size){let e=Array.from(this.middleware);for(let n=e.length-1;n>=0;n--){let r=e[n],i=t;t=e=>r({...e,next:()=>i(e)})}}return t}getInfo(){return{http:this.httpOptions,hasInput:!!this.inputSchema,hasOutput:!!this.outputSchema}}};export{t};
|
package/dist/procedure.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./context-
|
|
2
|
-
import "./http-
|
|
3
|
-
import { a as ProcedureHandler, i as Procedure, o as ProcedureOptions, r as HTTPOptions } from "./middleware-
|
|
1
|
+
import "./context-BZAzgugo.mjs";
|
|
2
|
+
import "./http-NhhQxMv8.mjs";
|
|
3
|
+
import { a as ProcedureHandler, i as Procedure, o as ProcedureOptions, r as HTTPOptions } from "./middleware-DB4PWjb4.mjs";
|
|
4
4
|
export { HTTPOptions, Procedure, ProcedureHandler, ProcedureOptions };
|
package/dist/procedure.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./procedure-
|
|
1
|
+
import{t as e}from"./procedure-AntXykJT.mjs";export{e as Procedure};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./error-
|
|
1
|
+
import{n as e}from"./error-Dq1biCC8.mjs";function t(t){switch(!0){case t instanceof Response:return t;case t instanceof e:return t.toResponse();case t instanceof Error:return new Response(`Internal Server Error`,{status:500});case typeof t==`object`:return Response.json(t);case!t:return new Response(null,{status:204});default:return new Response(String(t))}}function n(t,n){let r;switch(!0){case n instanceof e:r={id:t,error:{code:n.status,message:n.message}};break;case n instanceof Error:r={id:t,error:{code:500,message:n.message}};break;case n instanceof Response:r={id:t,error:{code:n.status,message:n.statusText}};break;case typeof n==`object`||typeof n==`number`||typeof n==`boolean`:r={id:t,result:n};break;default:r={id:t,result:String(n)}}return JSON.stringify(r)}export{n,t};
|
package/dist/response.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,t}from"./response-
|
|
1
|
+
import{n as e,t}from"./response-D935Hx3o.mjs";export{t as toHTTPResponse,e as toRPCResponse};
|
package/dist/rpc.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as isRPC, i as SuccessResult, n as Payload, r as Result, t as ErrorResult } from "./rpc-
|
|
1
|
+
import { a as isRPC, i as SuccessResult, n as Payload, r as Result, t as ErrorResult } from "./rpc-Ch2UXReT.mjs";
|
|
2
2
|
export { ErrorResult, Payload, Result, SuccessResult, isRPC };
|
package/dist/rpc.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./rpc-
|
|
1
|
+
import{t as e}from"./rpc-CAwkzxZe.mjs";export{e as isRPC};
|
package/dist/session.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { n as DefaultSocketData,
|
|
2
|
-
import { a as JSONValue, o as Promisable, r as JSONObject, t as DeepReadonly } from "./types-
|
|
3
|
-
import "./http-
|
|
4
|
-
import "./middleware-
|
|
5
|
-
import {
|
|
1
|
+
import { n as DefaultSocketData, t as BaseContext } from "./context-BZAzgugo.mjs";
|
|
2
|
+
import { a as JSONValue, o as Promisable, r as JSONObject, t as DeepReadonly } from "./types-Cn69QrjS.mjs";
|
|
3
|
+
import "./http-NhhQxMv8.mjs";
|
|
4
|
+
import "./middleware-DB4PWjb4.mjs";
|
|
5
|
+
import { n as Ultra, t as ProceduresMap } from "./ultra-Dawe5ndl.mjs";
|
|
6
6
|
import { BunRequest, CookieSameSite, RedisClient } from "bun";
|
|
7
7
|
|
|
8
8
|
//#region src/session.d.ts
|
|
@@ -47,13 +47,18 @@ interface SessionConfig<S extends Record<string, SessionStoreFactory> = Record<s
|
|
|
47
47
|
interface SessionSocketData {
|
|
48
48
|
sessionId: string;
|
|
49
49
|
}
|
|
50
|
+
type SessionContext = BaseContext<{
|
|
51
|
+
sessionId: string;
|
|
52
|
+
}> & {
|
|
53
|
+
session: Session<any>;
|
|
54
|
+
};
|
|
50
55
|
declare function defineConfig<S extends Record<string, SessionStoreFactory>>(config: SessionConfig<S>): SessionConfig<S>;
|
|
51
56
|
/** Extends context and socket data, initiate session instance every request */
|
|
52
57
|
declare function createSessionModule<S extends Record<string, SessionStoreFactory>>(config: SessionConfig<S>): Ultra<ProceduresMap, (BaseContext & {
|
|
53
58
|
session: Session<S>;
|
|
54
|
-
}) & BaseContext, DefaultSocketData &
|
|
59
|
+
}) & BaseContext, DefaultSocketData & {
|
|
55
60
|
sessionId: string;
|
|
56
|
-
}
|
|
61
|
+
}>;
|
|
57
62
|
/** Stores the ID in a cookie, then moves it to the socket and uses it for requests */
|
|
58
63
|
declare class Session<Stores extends Record<string, SessionStoreFactory> = Record<string, SessionStoreFactory>> {
|
|
59
64
|
/** Make random session id */
|
|
@@ -112,4 +117,4 @@ declare class MemorySessionStore implements SessionStore {
|
|
|
112
117
|
protected maybeSweep(now?: number): void;
|
|
113
118
|
}
|
|
114
119
|
//#endregion
|
|
115
|
-
export { MemorySessionStore, RedisSessionStore, Session, SessionConfig, SessionData, SessionSocketData, SessionStore, SessionStoreFactory, createSessionModule, defineConfig };
|
|
120
|
+
export { MemorySessionStore, RedisSessionStore, Session, SessionConfig, SessionContext, SessionData, SessionSocketData, SessionStore, SessionStoreFactory, createSessionModule, defineConfig };
|
package/dist/session.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./error-
|
|
1
|
+
import{i as e}from"./error-Dq1biCC8.mjs";import{isHTTP as t,isWS as n}from"./context.mjs";import{sign as r,unsign as i}from"./crypto.mjs";import{Ultra as a}from"./ultra.mjs";import{randomBytes as o}from"node:crypto";function s(e){return{...e,cookie:{path:`/`,httpOnly:!0,secure:!0,sameSite:`lax`,maxAge:e.ttlSec,...e?.cookie}}}function c(e){return new a().deriveWS(t=>({sessionId:l.getOrCreateId(t.request,e)})).derive(t=>({session:new l(e,t)})).use(async({context:e,next:t})=>{await e.session.initiate();let n=await t();return await e.session.commit(),n})}var l=class a{static makeId(){return o(16).toString(`base64url`)}static getOrCreateId(e,t){let n=e.cookies.get(t.name);return n&&i(n,t.secret)||a.makeId()}config;context;store;sessionIdFromClient=null;sessionId;sessionState=null;modified=!1;constructor(r,o){switch(this.config=r,this.context=o,this.store=r.stores[r.store](r,o),!0){case t(o):{let e=o.request.cookies.get(r.name);e&&(this.sessionIdFromClient=i(e,r.secret));break}case n(o):this.sessionIdFromClient=o.ws.data.sessionId||null;break;default:throw new e(`Session management is only supported for HTTP and WebSocket protocols.`)}this.sessionId=this.sessionIdFromClient||a.makeId()}get id(){return this.sessionId}async initiate(){this.sessionState||=await this.store.read(this.sessionId)||{}}async commit(){if(this.touch(),this.isEmpty&&this.sessionIdFromClient)return this.store.destroy(this.sessionIdFromClient);this.sessionIdFromClient&&this.sessionIdFromClient!==this.sessionId?(await this.store.destroy(this.sessionIdFromClient),await this.store.write(this.sessionId,this.state)):this.modified?await this.store.write(this.sessionId,this.state):await this.store.touch(this.sessionId)}regenerate(){this.sessionId=a.makeId()}get(e,t){return this.state[e]??t??null}set(e,t){this.state[e]=t,this.modified=!0}has(e){return Object.hasOwn(this.state,e)}all(){return this.state}delete(e){delete this.state[e],this.modified=!0}clear(){this.sessionState={},this.modified=!0}get state(){if(!this.sessionState)throw Error(`Session is not initiated yet.`);return this.sessionState}get isEmpty(){return Object.keys(this.state).length===0}touch(){`request`in this.context&&this.context.request.cookies.set(this.config.name,r(this.sessionId,this.config.secret),this.config.cookie)}},u=class{config;connection;constructor(e,t){this.config=e,this.connection=t}async read(e){let t=await this.connection.get(`${this.config.name}:${e}`);return t?JSON.parse(t):null}async write(e,t){await this.connection.set(`${this.config.name}:${e}`,JSON.stringify(t),`EX`,this.config.ttlSec)}async destroy(e){await this.connection.del(`${this.config.name}:${e}`)}async touch(e){await this.connection.expire(`${this.config.name}:${e}`,this.config.ttlSec)}},d=class{config;sessions=new Map;sweepIntervalMs;ttlMs;lastSweepAt=Date.now();constructor(e,t=e.ttlSec){this.config=e,this.sweepIntervalMs=t*1e3,this.ttlMs=e.ttlSec*1e3}read(e){return this.maybeSweep(),this.sessions.get(e)?.data||null}write(e,t){this.maybeSweep(),this.sessions.set(e,{data:t,touched:Date.now()})}destroy(e){this.maybeSweep(),this.sessions.delete(e)}touch(e){this.maybeSweep();let t=this.sessions.get(e);t&&(t.touched=Date.now())}maybeSweep(e=Date.now()){if(!(e-this.lastSweepAt<this.sweepIntervalMs)){this.lastSweepAt=e;for(let[t,n]of this.sessions)e-n.touched>this.ttlMs&&this.sessions.delete(t)}}};export{d as MemorySessionStore,u as RedisSessionStore,l as Session,c as createSessionModule,s as defineConfig};
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as JSONValue, i as JSONPrimitive, n as JSONArray, o as Promisable, r as JSONObject, t as DeepReadonly } from "./types-
|
|
1
|
+
import { a as JSONValue, i as JSONPrimitive, n as JSONArray, o as Promisable, r as JSONObject, t as DeepReadonly } from "./types-Cn69QrjS.mjs";
|
|
2
2
|
export { DeepReadonly, JSONArray, JSONObject, JSONPrimitive, JSONValue, Promisable };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { n as DefaultSocketData, t as BaseContext } from "./context-BZAzgugo.mjs";
|
|
2
|
+
import { o as Promisable } from "./types-Cn69QrjS.mjs";
|
|
3
|
+
import { n as BunRoutes } from "./http-NhhQxMv8.mjs";
|
|
4
|
+
import { c as StandardSchemaV1 } from "./validation-CkRfxQJ_.mjs";
|
|
5
|
+
import { a as ProcedureHandler, i as Procedure, t as Middleware } from "./middleware-DB4PWjb4.mjs";
|
|
6
|
+
import { n as Payload } from "./rpc-Ch2UXReT.mjs";
|
|
7
|
+
import { BunRequest, ErrorLike, Server, ServerWebSocket } from "bun";
|
|
8
|
+
|
|
9
|
+
//#region src/ultra.d.ts
|
|
10
|
+
interface ProceduresMap {
|
|
11
|
+
[key: string]: Procedure<any, any, any> | ProceduresMap;
|
|
12
|
+
}
|
|
13
|
+
interface ServerEventMap<SocketData extends DefaultSocketData = DefaultSocketData> {
|
|
14
|
+
'error': [ErrorLike];
|
|
15
|
+
'unhandled:error': [ErrorLike];
|
|
16
|
+
'http:request': [BunRequest, Server<SocketData>];
|
|
17
|
+
'ws:open': [ServerWebSocket<SocketData>];
|
|
18
|
+
'ws:message': [ServerWebSocket<SocketData>, string | Buffer<ArrayBuffer>];
|
|
19
|
+
'ws:close': [ServerWebSocket<SocketData>, number, string];
|
|
20
|
+
'server:started': [Server<SocketData>];
|
|
21
|
+
'server:stopped': [Server<SocketData>, closeActiveConnections: boolean];
|
|
22
|
+
}
|
|
23
|
+
type ServerEventListener<K extends keyof ServerEventMap> = (...args: ServerEventMap[K]) => any;
|
|
24
|
+
type DeriveFunction<C extends BaseContext> = (context: C) => Promisable<Record<PropertyKey, any>>;
|
|
25
|
+
type DeriveValue<C extends BaseContext> = DeriveFunction<C> | Record<PropertyKey, any>;
|
|
26
|
+
type ExtractDerive<C extends BaseContext, T extends DeriveValue<C>> = T extends DeriveFunction<C> ? Awaited<ReturnType<T>> : T;
|
|
27
|
+
type StartOptions<SocketData extends DefaultSocketData> = Omit<Partial<Bun.Serve.Options<SocketData>>, 'websocket' | 'error' | 'routes'>;
|
|
28
|
+
interface UltraOptions {
|
|
29
|
+
http: boolean;
|
|
30
|
+
}
|
|
31
|
+
type InputFactory<C extends BaseContext> = <I>(schema?: StandardSchemaV1<I>) => Procedure<I, unknown, C>;
|
|
32
|
+
type ProcedureMapInitializer<R extends ProceduresMap, C extends BaseContext = BaseContext> = (input: InputFactory<C>) => R;
|
|
33
|
+
declare class Ultra<Procedures extends ProceduresMap = ProceduresMap, Context extends BaseContext = BaseContext, SocketData extends DefaultSocketData = DefaultSocketData> {
|
|
34
|
+
protected readonly initializers: Set<ProcedureMapInitializer<any, Context>>;
|
|
35
|
+
protected readonly handlers: Map<string, ProcedureHandler<any, any, Context>>;
|
|
36
|
+
protected readonly events: Map<keyof ServerEventMap<SocketData>, Set<ServerEventListener<any>>>;
|
|
37
|
+
protected readonly middlewares: Set<Middleware<any, any, Context>>;
|
|
38
|
+
protected readonly derived: Set<DeriveValue<Context>>;
|
|
39
|
+
protected readonly derivedWS: Set<DeriveValue<Context>>;
|
|
40
|
+
protected readonly options: UltraOptions;
|
|
41
|
+
protected server?: Server<SocketData>;
|
|
42
|
+
constructor(options?: Partial<UltraOptions>);
|
|
43
|
+
/** Register procedures */
|
|
44
|
+
routes<const P extends ProceduresMap>(initializer: ProcedureMapInitializer<P, Context>): Ultra<Procedures & P, Context, SocketData>;
|
|
45
|
+
/** Register middleware or another Ultra instance */
|
|
46
|
+
use<const PluginProcedures extends ProceduresMap, const PluginContext extends BaseContext, const PluginSocketData extends DefaultSocketData>(entity: Middleware<any, any, Context> | Ultra<PluginProcedures, PluginContext, PluginSocketData>): Ultra<Procedures & PluginProcedures, Context & PluginContext, SocketData & PluginSocketData>;
|
|
47
|
+
/** Extends context values for every request with provided values */
|
|
48
|
+
derive<const D extends DeriveValue<Context>>(derive: D): Ultra<Procedures, Context & ExtractDerive<Context, D>, SocketData>;
|
|
49
|
+
/** Extends WS data for every ws connection */
|
|
50
|
+
deriveWS<const D extends DeriveValue<Context>>(derive: D): Ultra<Procedures, Context, SocketData & ExtractDerive<Context, D>>;
|
|
51
|
+
start(options?: StartOptions<SocketData>): Server<SocketData>;
|
|
52
|
+
stop(closeActiveConnections?: boolean): Promise<void>;
|
|
53
|
+
on<E extends keyof ServerEventMap>(event: E, listener: ServerEventListener<E>): this;
|
|
54
|
+
off<E extends keyof ServerEventMap>(event: E, listener: ServerEventListener<E>): this;
|
|
55
|
+
emit<E extends keyof ServerEventMap>(event: E, ...args: ServerEventMap[E]): this;
|
|
56
|
+
protected handleRPC(ws: ServerWebSocket<SocketData>, payload: Payload): Promise<void>;
|
|
57
|
+
/** Enrich context with derived values */
|
|
58
|
+
protected enrichContext(context: BaseContext): Promise<Context>;
|
|
59
|
+
/** Merge other Ultra instance with deduplication */
|
|
60
|
+
protected merge(module: Ultra<any, any, any>): void;
|
|
61
|
+
/** Wrap procedure handler with global middlewares */
|
|
62
|
+
protected wrapHandler(handler: ProcedureHandler<any, any, any>): ProcedureHandler<any, any, any>;
|
|
63
|
+
/** Build flat map from procedures tree and write handles map */
|
|
64
|
+
protected buildProcedures(): Map<string, Procedure<any, any, Context>>;
|
|
65
|
+
/** Build Bun native HTTP routes */
|
|
66
|
+
protected buildRoutes(procedures: Map<string, Procedure<any, any, Context>>): BunRoutes;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { Ultra as n, ProceduresMap as t };
|
package/dist/ultra.d.mts
CHANGED
|
@@ -1,69 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { a as ProcedureHandler, i as Procedure, t as Middleware } from "./middleware-DVREjjkO.mjs";
|
|
6
|
-
import { n as Payload } from "./rpc-DADpT17P.mjs";
|
|
7
|
-
import { BunRequest, ErrorLike, Server, ServerWebSocket } from "bun";
|
|
8
|
-
|
|
9
|
-
//#region src/ultra.d.ts
|
|
10
|
-
interface ProceduresMap {
|
|
11
|
-
[key: string]: Procedure<any, any, any> | ProceduresMap;
|
|
12
|
-
}
|
|
13
|
-
interface ServerEventMap<SocketData extends DefaultSocketData = DefaultSocketData> {
|
|
14
|
-
'error': [ErrorLike];
|
|
15
|
-
'unhandled:error': [ErrorLike];
|
|
16
|
-
'http:request': [BunRequest, Server<SocketData>];
|
|
17
|
-
'ws:open': [ServerWebSocket<SocketData>];
|
|
18
|
-
'ws:message': [ServerWebSocket<SocketData>, string | Buffer<ArrayBuffer>];
|
|
19
|
-
'ws:close': [ServerWebSocket<SocketData>, number, string];
|
|
20
|
-
'server:started': [Server<SocketData>];
|
|
21
|
-
'server:stopped': [Server<SocketData>, closeActiveConnections: boolean];
|
|
22
|
-
}
|
|
23
|
-
type ServerEventListener<K extends keyof ServerEventMap> = (...args: ServerEventMap[K]) => any;
|
|
24
|
-
type DeriveFunction<C extends BaseContext> = (context: C) => Promisable<Record<PropertyKey, any>>;
|
|
25
|
-
type DeriveValue<C extends BaseContext> = DeriveFunction<C> | Record<PropertyKey, any>;
|
|
26
|
-
type ExtractDerive<C extends BaseContext, T extends DeriveValue<C>> = T extends DeriveFunction<C> ? Awaited<ReturnType<T>> : T;
|
|
27
|
-
type StartOptions<SocketData extends DefaultSocketData> = Omit<Partial<Bun.Serve.Options<SocketData>>, 'websocket' | 'error' | 'routes'>;
|
|
28
|
-
interface UltraOptions {
|
|
29
|
-
http: boolean;
|
|
30
|
-
}
|
|
31
|
-
type InputFactory<C extends BaseContext> = <I>(schema?: StandardSchemaV1<I>) => Procedure<I, unknown, C>;
|
|
32
|
-
type ProcedureMapInitializer<R extends ProceduresMap, C extends BaseContext = BaseContext> = (input: InputFactory<C>) => R;
|
|
33
|
-
declare class Ultra<Procedures extends ProceduresMap = ProceduresMap, Context extends BaseContext = BaseContext, SocketData extends DefaultSocketData = DefaultSocketData> {
|
|
34
|
-
protected readonly initializers: Set<ProcedureMapInitializer<any, Context>>;
|
|
35
|
-
protected readonly handlers: Map<string, ProcedureHandler<any, any, Context>>;
|
|
36
|
-
protected readonly events: Map<keyof ServerEventMap<SocketData>, Set<ServerEventListener<any>>>;
|
|
37
|
-
protected readonly middlewares: Set<Middleware<any, any, Context>>;
|
|
38
|
-
protected readonly derived: Set<DeriveValue<Context>>;
|
|
39
|
-
protected readonly derivedWS: Set<DeriveValue<Context>>;
|
|
40
|
-
protected readonly options: UltraOptions;
|
|
41
|
-
protected server?: Server<SocketData>;
|
|
42
|
-
constructor(options?: Partial<UltraOptions>);
|
|
43
|
-
/** Register procedures */
|
|
44
|
-
routes<const P extends ProceduresMap>(initializer: ProcedureMapInitializer<P, Context>): Ultra<Procedures & P, Context, SocketData>;
|
|
45
|
-
/** Register middleware or another Ultra instance */
|
|
46
|
-
use<const PluginProcedures extends ProceduresMap, const PluginContext extends BaseContext, const PluginSocketData extends DefaultSocketData>(entity: Middleware<any, any, Context> | Ultra<PluginProcedures, PluginContext, PluginSocketData>): Ultra<Procedures & PluginProcedures, Context & PluginContext, SocketData & PluginSocketData>;
|
|
47
|
-
/** Extends context values for every request with provided values */
|
|
48
|
-
derive<const D extends DeriveValue<Context>>(derive: D): Ultra<Procedures, Context & ExtractDerive<Context, D>, SocketData>;
|
|
49
|
-
/** Extends WS data for every ws connection */
|
|
50
|
-
deriveWS<const D extends DeriveValue<Context>>(derive: D): Ultra<Procedures, Context, SocketData & ExtractDerive<Context, D>>;
|
|
51
|
-
start(options?: StartOptions<SocketData>): Server<SocketData>;
|
|
52
|
-
stop(closeActiveConnections?: boolean): Promise<void>;
|
|
53
|
-
on<E extends keyof ServerEventMap>(event: E, listener: ServerEventListener<E>): this;
|
|
54
|
-
off<E extends keyof ServerEventMap>(event: E, listener: ServerEventListener<E>): this;
|
|
55
|
-
emit<E extends keyof ServerEventMap>(event: E, ...args: ServerEventMap[E]): this;
|
|
56
|
-
protected handleRPC(ws: ServerWebSocket<SocketData>, payload: Payload): Promise<void>;
|
|
57
|
-
/** Enrich context with derived values */
|
|
58
|
-
protected enrichContext(context: BaseContext): Promise<Context>;
|
|
59
|
-
/** Merge other Ultra instance with deduplication */
|
|
60
|
-
protected merge(module: Ultra<any, any, any>): void;
|
|
61
|
-
/** Wrap procedure handler with global middlewares */
|
|
62
|
-
protected wrapHandler(handler: ProcedureHandler<any, any, any>): ProcedureHandler<any, any, any>;
|
|
63
|
-
/** Build flat map from procedures tree and write handles map */
|
|
64
|
-
protected buildProcedures(): Map<string, Procedure<any, any, Context>>;
|
|
65
|
-
/** Build Bun native HTTP routes */
|
|
66
|
-
protected buildRoutes(procedures: Map<string, Procedure<any, any, Context>>): BunRoutes;
|
|
67
|
-
}
|
|
68
|
-
//#endregion
|
|
1
|
+
import "./context-BZAzgugo.mjs";
|
|
2
|
+
import "./http-NhhQxMv8.mjs";
|
|
3
|
+
import "./middleware-DB4PWjb4.mjs";
|
|
4
|
+
import { n as Ultra, t as ProceduresMap } from "./ultra-Dawe5ndl.mjs";
|
|
69
5
|
export { ProceduresMap, Ultra };
|
package/dist/ultra.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{n as e,t}from"./response-D935Hx3o.mjs";import{t as n}from"./procedure-AntXykJT.mjs";import{t as r}from"./rpc-CAwkzxZe.mjs";import{serve as i}from"bun";var a=class{initializers=new Set;handlers=new Map;events=new Map;middlewares=new Set;derived=new Set;derivedWS=new Set;options={http:!0};server;constructor(e){Object.assign(this.options,e)}routes(e){return this.initializers.add(e),this}use(e){return typeof e==`function`?(this.middlewares.add(e),this):(this.merge(e),this)}derive(e){return this.derived.add(e),this}deriveWS(e){return this.derivedWS.add(e),this}start(e){if(this.server)return console.warn(`Server is already running`),this.server;let t=this.buildProcedures(),n=this.wrapHandler(()=>new Response(`Not Found`,{status:404}));return this.server=i({...e??{},routes:{...this.options.http&&{...this.buildRoutes(t),"/*":async(e,t)=>(this.emit(`http:request`,e,t),n({input:null,context:this.derived.size?await this.enrichContext({server:t,request:e}):{server:t,request:e}}))},"/ws":async(e,t)=>{if(this.derivedWS.size){let n={},r=this.derived.size?await this.enrichContext({server:t,request:e}):{server:t,request:e};for(let e of this.derivedWS)Object.assign(n,typeof e==`function`?await e(r):e);t.upgrade(e,{data:n});return}t.upgrade(e)}},websocket:{open:e=>{this.emit(`ws:open`,e)},close:(e,t,n)=>{this.emit(`ws:close`,e,t,n)},message:(e,t)=>{if(this.emit(`ws:message`,e,t),typeof t!=`string`)return;let n=JSON.parse(t);r(n)&&this.handleRPC(e,n)}},error:e=>(this.emit(`unhandled:error`,e),console.error(`Unhandled server error:`,e),new Response(`Internal Server Error`,{status:500}))}),this.emit(`server:started`,this.server),this.server}async stop(e=!1){if(!this.server)return console.error(`Server is not running`);await this.server.stop(e),this.emit(`server:stopped`,this.server,e)}on(e,t){return this.events.has(e)||this.events.set(e,new Set),this.events.get(e).add(t),this}off(e,t){return this.events.get(e)?.delete(t),this}emit(e,...t){return this.events.get(e)?.forEach(e=>e(...t)),this}async handleRPC(t,n){let r=this.handlers.get(n.method);if(!r){t.send(`{"id": "${n.id}", "error": {"code": 404, "message": "Not found"}}`);return}try{t.send(e(n.id,await r({input:n.params,context:await this.enrichContext({server:this.server,ws:t})})))}catch(r){this.emit(`error`,r),t.send(e(n.id,r))}}async enrichContext(e){for(let t of this.derived)Object.assign(e,typeof t==`function`?await t(e):t);return e}merge(e){e.initializers.forEach(e=>this.initializers.add(e)),e.derived.forEach(e=>this.derived.add(e)),e.derivedWS.forEach(e=>this.derivedWS.add(e)),e.middlewares.forEach(e=>this.middlewares.add(e)),e.events.forEach((e,t)=>{this.events.has(t)||this.events.set(t,new Set);let n=this.events.get(t);e.forEach(e=>n.add(e))})}wrapHandler(e){if(!this.middlewares.size)return e;let t=Array.from(this.middlewares);return async n=>{let r=0,i=()=>r===t.length?e(n):t[r++]({...n,next:i});return i()}}buildProcedures(){let e=new Map,t=e=>{let t=new n;return e?t.input(e):t};for(let r of this.initializers){let i=r(t),a=[];for(let[e,t]of Object.entries(i))a.push({path:e,value:t});for(;a.length;){let{path:t,value:r}=a.pop();if(r instanceof n){if(e.has(t))throw Error(`Procedure conflict at path "${t}"`);e.set(t,r),this.handlers.set(t,this.wrapHandler(r.wrap()));continue}for(let[e,n]of Object.entries(r)){let r=t?`${t}/${e}`:e;a.push({path:r,value:n})}}}return e}buildRoutes(e){let n={};for(let[r,i]of e){let e=i.getInfo();if(!e.http?.enabled)continue;let a=`/${r}`,o=this.handlers.get(r);if(!o)throw Error(`Handler for procedure at path "${r}" is not defined`);let s=async(n,i)=>{this.emit(`http:request`,n,i);let a=n.body,s={server:i,request:n},c=this.derived.size?await this.enrichContext(s):s;if(a&&e.hasInput){if(n.method===`GET`){let e=n.url.indexOf(`?`);e!==-1&&e<n.url.length-1&&(a=Object.fromEntries(new URLSearchParams(n.url.slice(e+1)).entries()))}else if(n.headers.get(`Content-Length`)!==`0`){let e=n.headers.get(`Content-Type`);if(e)switch(!0){case e.startsWith(`application/json`):a=await n.json();break;case e.startsWith(`text`):a=await n.text();break;case e.startsWith(`multipart/form-data`):a=await n.formData();break;default:console.error(`Unsupported Content-Type for procedure ${r}: ${e}`);break}}}try{return t(await o({input:a,context:c}))}catch(e){return this.emit(`error`,e),t(e)}};if(!e.http.method){n[a]=s;continue}n[a]||(n[a]={}),n[a][e.http.method]=s}return n}};export{a as Ultra};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./error-
|
|
1
|
+
import{a as e}from"./error-Dq1biCC8.mjs";async function t(t,n){let r=t[`~standard`].validate(n);if(r instanceof Promise&&(r=await r),r.issues)throw new e(JSON.stringify(r.issues,null,2));return r.value}export{t};
|
package/dist/validation.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as PathSegment, c as StandardSchemaV1, d as validate, i as Issue, l as SuccessResult, n as InferInput, o as Props, r as InferOutput, s as Result, t as FailureResult, u as Types } from "./validation-
|
|
1
|
+
import { a as PathSegment, c as StandardSchemaV1, d as validate, i as Issue, l as SuccessResult, n as InferInput, o as Props, r as InferOutput, s as Result, t as FailureResult, u as Types } from "./validation-CkRfxQJ_.mjs";
|
|
2
2
|
export { FailureResult, InferInput, InferOutput, Issue, PathSegment, Props, Result, StandardSchemaV1, SuccessResult, Types, validate };
|
package/dist/validation.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./validation-
|
|
1
|
+
import{t as e}from"./validation-dJpfcBud.mjs";export{e as validate};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function e(e){return`request`in e}function t(e){return`ws`in e}export{t as n,e as t};
|
package/dist/crypto-DrpstqPB.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createCipheriv as e,createDecipheriv as t,createHmac as n,randomBytes as r,timingSafeEqual as i}from"node:crypto";const a=`aes-256-gcm`,o=`base64url`;function s(e,t){let r=Buffer.from(e).toString(o);return`${r}.${n(`sha256`,t).update(r).digest(o)}`}function c(e,t){let[r,a]=e.split(`.`);if(!r||!a)return null;let s=n(`sha256`,t).update(r).digest(o),c=Buffer.from(a,o),l=Buffer.from(s,o);return c.length!==l.length||!i(c,l)?null:Buffer.from(r,o).toString()}function l(t,n){let i=r(12),s=e(a,n,i),c=s.update(t,`utf-8`,o);return c+=s.final(o),Buffer.concat([i,s.getAuthTag(),Buffer.from(c,o)]).toString(o)}function u(e,n){let r=Buffer.from(e,o);if(r.length<28)return null;let i=r.subarray(0,12),s=r.subarray(12,28),c=r.subarray(28),l=t(a,n,i);return l.setAuthTag(s),`${l.update(c,void 0,`utf-8`)}${l.final(`utf-8`)}`}export{c as i,l as n,s as r,u as t};
|
package/dist/test.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/test.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Ultra as e}from"./ultra.mjs";import{SessionAuthProvider as t,createAuthModule as n,isGuest as r}from"./auth.mjs";import{createHTTPClient as i}from"./client.mjs";import{MemorySessionStore as a,createSessionModule as o,defineConfig as s}from"./session.mjs";const c=o(s({secret:`supersecretkey`,name:``,ttlSec:0,store:`memory`,cookie:{},stores:{memory:e=>new a(e)}})),l=n({provider:`session`,providers:{session:e=>new t(e)}}).use(c);new e().use(l).use(r),i({baseUrl:`dasd`});export{};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|