@mauroandre/velojs 0.0.26 → 0.0.28
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/README.md +81 -2
- package/dist/events.d.ts +58 -3
- package/dist/events.js +174 -135
- package/dist/hooks.d.ts +56 -0
- package/dist/hooks.js +128 -68
- package/dist/index.d.ts +2 -1
- package/dist/server.js +51 -50
- package/dist/sockets.d.ts +109 -0
- package/dist/sockets.js +196 -0
- package/dist/testing/index.js +454 -291
- package/dist/testing/socketSession.d.ts +13 -0
- package/dist/testing/types.d.ts +36 -0
- package/dist/vite.d.ts +8 -0
- package/dist/vite.js +267 -236
- package/package.json +6 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory WebSocket session for tests.
|
|
3
|
+
*
|
|
4
|
+
* Invokes a `socket_*` handler directly with a mock Context — bypassing the
|
|
5
|
+
* real HTTP upgrade path. Middlewares do NOT run; set `opts.user` to supply
|
|
6
|
+
* `c.get("user")`.
|
|
7
|
+
*/
|
|
8
|
+
import type { Hono } from "hono";
|
|
9
|
+
import type { SocketHandler } from "../sockets.js";
|
|
10
|
+
import type { SocketTestOptions, TestSocketSession } from "./types.js";
|
|
11
|
+
export declare function buildSocketSession(hono: Hono, handlerInput: SocketHandler | {
|
|
12
|
+
__path?: string;
|
|
13
|
+
} | string, opts?: SocketTestOptions): Promise<TestSocketSession>;
|
package/dist/testing/types.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import type { Hono, Context } from "hono";
|
|
5
5
|
import type { AppRoutes } from "../types.js";
|
|
6
6
|
import type { EventStream } from "../events.js";
|
|
7
|
+
import type { SocketHandler, SocketStub } from "../sockets.js";
|
|
7
8
|
export type Cookies = Record<string, string>;
|
|
8
9
|
export type Headers = Record<string, string>;
|
|
9
10
|
export type Query = Record<string, string | string[]>;
|
|
@@ -64,6 +65,30 @@ export interface NextOptions {
|
|
|
64
65
|
/** Reject if no event arrives within this many ms. */
|
|
65
66
|
timeoutMs: number;
|
|
66
67
|
}
|
|
68
|
+
export interface SocketTestOptions extends RequestOptions {
|
|
69
|
+
/** Channel ID — sent as `?channel=...` on the WS URL. */
|
|
70
|
+
channel?: string;
|
|
71
|
+
/** URL params (for socket paths with `:param`). */
|
|
72
|
+
params?: Params;
|
|
73
|
+
/** `c.get("user")` value (shortcut — avoids a full middleware chain). */
|
|
74
|
+
user?: any;
|
|
75
|
+
}
|
|
76
|
+
export interface TestSocketSession {
|
|
77
|
+
/** Send a frame. Objects are `JSON.stringify`'d, strings/Uint8Array pass through. */
|
|
78
|
+
send(msg: string | Uint8Array | object): void;
|
|
79
|
+
/** Wait for the next incoming frame from the server. Rejects on timeout. */
|
|
80
|
+
next(opts: NextOptions): Promise<string | Uint8Array>;
|
|
81
|
+
/** Wait for N incoming frames total (order preserved). */
|
|
82
|
+
nextN(n: number, opts: NextOptions): Promise<(string | Uint8Array)[]>;
|
|
83
|
+
/** All frames received from the server so far. */
|
|
84
|
+
readonly messages: ReadonlyArray<string | Uint8Array>;
|
|
85
|
+
/** True once the server-side handler has finished (or the session was aborted). */
|
|
86
|
+
readonly closed: boolean;
|
|
87
|
+
/** Client-side close — aborts the server handler's abortSignal. */
|
|
88
|
+
close(code?: number, reason?: string): Promise<void>;
|
|
89
|
+
/** Resolves when the handler finishes or the session is aborted. */
|
|
90
|
+
readonly done: Promise<void>;
|
|
91
|
+
}
|
|
67
92
|
export interface TestSubscription<TEvent = any, TSnapshot = any> {
|
|
68
93
|
/** HTTP status of the initial SSE response (200, 403, etc). */
|
|
69
94
|
readonly status: number;
|
|
@@ -109,6 +134,17 @@ export interface TestApp {
|
|
|
109
134
|
*/
|
|
110
135
|
loader<T = any>(fn: Function | string, opts?: LoaderRequestOptions): Promise<T | TestResponse>;
|
|
111
136
|
subscribe<TEvent = any, TSnapshot = any>(stream: EventStream<TEvent, TSnapshot> | string, opts?: SubscribeOptions): Promise<TestSubscription<TEvent, TSnapshot>>;
|
|
137
|
+
/**
|
|
138
|
+
* Open an in-memory session against a `socket_*` handler.
|
|
139
|
+
*
|
|
140
|
+
* Accepts the socket handler function directly (server-imported), a
|
|
141
|
+
* `{ __path }` stub, or a string path. **Middleware is not simulated** —
|
|
142
|
+
* test middleware separately through a regular endpoint or page that uses
|
|
143
|
+
* it. Use `opts.user` to shortcut `c.get("user")`.
|
|
144
|
+
*/
|
|
145
|
+
socket(handler: SocketHandler | SocketStub | {
|
|
146
|
+
__path: string;
|
|
147
|
+
} | string, opts?: SocketTestOptions): Promise<TestSocketSession>;
|
|
112
148
|
/** Build cookies for a user via `getSessionCookie` config. */
|
|
113
149
|
sessionCookies(input: {
|
|
114
150
|
user: any;
|
package/dist/vite.d.ts
CHANGED
|
@@ -12,6 +12,14 @@ export declare function transformActionsForClient(code: string, moduleId: string
|
|
|
12
12
|
* só rodam no server. O client precisa apenas do path para abrir o EventSource.
|
|
13
13
|
*/
|
|
14
14
|
export declare function transformStreamsForClient(code: string, moduleId: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Transforms `export const socket_xxx = async (...) => {...}` on the client
|
|
17
|
+
* into a stub with only `{ __isVeloSocket: true, __path: "/_socket/{moduleId}/{name}" }`.
|
|
18
|
+
*
|
|
19
|
+
* The body is discarded — the handler runs only on the server. The client
|
|
20
|
+
* needs just the path to open the WebSocket.
|
|
21
|
+
*/
|
|
22
|
+
export declare function transformSocketsForClient(code: string, moduleId: string): string;
|
|
15
23
|
export declare function removeLoaders(code: string): string;
|
|
16
24
|
export declare function removeMiddlewares(code: string): string;
|
|
17
25
|
/**
|