yaxa-svelte 2.4.0 → 2.6.0
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 +111 -15
- package/dist/client/client.d.ts +27 -0
- package/dist/client/client.js +239 -0
- package/dist/client/client.test.d.ts +1 -0
- package/dist/client/client.test.js +197 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +2 -0
- package/dist/client/types.d.ts +222 -0
- package/dist/client/types.js +1 -0
- package/dist/composables/useSSE.svelte.d.ts +53 -0
- package/dist/composables/useSSE.svelte.js +209 -0
- package/dist/composables/useSSE.test.d.ts +1 -0
- package/dist/composables/useSSE.test.js +122 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +2 -0
- package/dist/server/openapi/handler.js +5 -3
- package/dist/server/openapi/openapi.test.js +13 -0
- package/dist/server/realtime/broadcaster.d.ts +31 -0
- package/dist/server/realtime/broadcaster.js +76 -0
- package/dist/server/realtime/index.d.ts +3 -0
- package/dist/server/realtime/index.js +3 -0
- package/dist/server/realtime/realtime.test.d.ts +1 -0
- package/dist/server/realtime/realtime.test.js +210 -0
- package/dist/server/realtime/sse.d.ts +28 -0
- package/dist/server/realtime/sse.js +225 -0
- package/dist/server/realtime/types.d.ts +116 -0
- package/dist/server/realtime/types.js +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +7 -5
- package/package.json +1 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { RequestEvent } from '@sveltejs/kit';
|
|
2
|
+
import type { Guard } from '../endpoint/types';
|
|
3
|
+
/**
|
|
4
|
+
* Structured Server-Sent Event message payload.
|
|
5
|
+
*/
|
|
6
|
+
export interface SSEMessage<T = unknown> {
|
|
7
|
+
/** Optional unique event ID for client Last-Event-ID tracking */
|
|
8
|
+
id?: string;
|
|
9
|
+
/** Optional named event type (defaults to 'message') */
|
|
10
|
+
event?: string;
|
|
11
|
+
/** Payload data to transmit. Objects/arrays are JSON-encoded automatically */
|
|
12
|
+
data: T;
|
|
13
|
+
/** Optional reconnection delay in milliseconds suggested to the client */
|
|
14
|
+
retry?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Context provided to onConnect and event callbacks.
|
|
18
|
+
*/
|
|
19
|
+
export interface SSEClientContext {
|
|
20
|
+
/** Unique connection ID */
|
|
21
|
+
connectionId: string;
|
|
22
|
+
/** Active channel name */
|
|
23
|
+
channel: string;
|
|
24
|
+
/** The incoming SvelteKit RequestEvent */
|
|
25
|
+
event: RequestEvent;
|
|
26
|
+
/** Resolved user from guards/locals */
|
|
27
|
+
user?: any;
|
|
28
|
+
/** Active organization ID from guards/locals */
|
|
29
|
+
orgId?: string | null;
|
|
30
|
+
/** Send an SSE message directly to this client */
|
|
31
|
+
send: <T = unknown>(eventOrMessage: string | SSEMessage<T>, data?: T) => boolean;
|
|
32
|
+
/** Explicitly close this SSE connection */
|
|
33
|
+
close: () => void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Configuration options for yaxaSSE endpoint handler.
|
|
37
|
+
*/
|
|
38
|
+
export interface YaxaSSEOptions {
|
|
39
|
+
/** Summary for OpenAPI documentation */
|
|
40
|
+
summary?: string;
|
|
41
|
+
/** Description for OpenAPI documentation */
|
|
42
|
+
description?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Declarative guards executed before establishing the SSE connection.
|
|
45
|
+
* If a guard fails, an RFC 7807 Problem Details response (e.g. 401, 403, 429) is returned.
|
|
46
|
+
*/
|
|
47
|
+
guards?: Guard[];
|
|
48
|
+
/**
|
|
49
|
+
* Channel name to subscribe this client to. Can be a static string or a dynamic function
|
|
50
|
+
* of the incoming RequestEvent (e.g. `(event) => \`org:\${event.locals.orgId}\``).
|
|
51
|
+
* Defaults to `'default'`.
|
|
52
|
+
*/
|
|
53
|
+
channel?: string | ((event: RequestEvent) => string | Promise<string>);
|
|
54
|
+
/**
|
|
55
|
+
* Keep-alive ping interval in milliseconds to prevent reverse proxies, firewalls,
|
|
56
|
+
* and serverless platforms (e.g. Vercel) from terminating idle connections.
|
|
57
|
+
* Set to 0 to disable. Defaults to 15,000ms (15s).
|
|
58
|
+
*/
|
|
59
|
+
keepAliveIntervalMs?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Custom comment or payload for keep-alive pings.
|
|
62
|
+
* Defaults to `: ping\n\n`.
|
|
63
|
+
*/
|
|
64
|
+
keepAliveComment?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Hook called immediately after connection establishment and headers transmission.
|
|
67
|
+
*/
|
|
68
|
+
onConnect?: (ctx: SSEClientContext) => void | Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Hook called when the client disconnects or the request is aborted.
|
|
71
|
+
*/
|
|
72
|
+
onDisconnect?: (ctx: Omit<SSEClientContext, 'send' | 'close'>) => void | Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Custom broadcaster instance. If omitted, uses the global broadcaster singleton.
|
|
75
|
+
*/
|
|
76
|
+
broadcaster?: Broadcaster;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Broadcast message contract.
|
|
80
|
+
*/
|
|
81
|
+
export interface BroadcastMessage<T = unknown> {
|
|
82
|
+
channel: string;
|
|
83
|
+
event: string;
|
|
84
|
+
payload: T;
|
|
85
|
+
id?: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Broadcaster subscription callback.
|
|
89
|
+
*/
|
|
90
|
+
export type BroadcastSubscriber<T = unknown> = (msg: BroadcastMessage<T>) => void;
|
|
91
|
+
/**
|
|
92
|
+
* Broadcaster adapter interface.
|
|
93
|
+
* Can be implemented by MemoryBroadcaster, RedisBroadcaster, ValkeyBroadcaster, etc.
|
|
94
|
+
*/
|
|
95
|
+
export interface Broadcaster {
|
|
96
|
+
/**
|
|
97
|
+
* Publish an event to all subscribers listening on the specified channel.
|
|
98
|
+
*/
|
|
99
|
+
publish: <T = unknown>(channel: string, event: string, payload: T, id?: string) => Promise<void> | void;
|
|
100
|
+
/**
|
|
101
|
+
* Subscribe to events on a specific channel. Returns an unsubscribe function.
|
|
102
|
+
*/
|
|
103
|
+
subscribe: <T = unknown>(channel: string, subscriber: BroadcastSubscriber<T>) => () => void;
|
|
104
|
+
/**
|
|
105
|
+
* Unsubscribe a callback from a channel.
|
|
106
|
+
*/
|
|
107
|
+
unsubscribe: <T = unknown>(channel: string, subscriber: BroadcastSubscriber<T>) => void;
|
|
108
|
+
/**
|
|
109
|
+
* Returns current number of active subscribers on a channel (optional).
|
|
110
|
+
*/
|
|
111
|
+
subscriberCount?: (channel: string) => number;
|
|
112
|
+
/**
|
|
113
|
+
* Remove all subscribers across all channels.
|
|
114
|
+
*/
|
|
115
|
+
clear?: () => void;
|
|
116
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -85,6 +85,8 @@ export interface MockRequestEventOptions {
|
|
|
85
85
|
params?: Record<string, string>;
|
|
86
86
|
locals?: Record<string, any>;
|
|
87
87
|
cookies?: Record<string, string>;
|
|
88
|
+
signal?: AbortSignal;
|
|
89
|
+
request?: Request;
|
|
88
90
|
}
|
|
89
91
|
/**
|
|
90
92
|
* Creates a mocked typed SvelteKit RequestEvent for unit testing endpoints and server hooks.
|
package/dist/testing/index.js
CHANGED
|
@@ -124,11 +124,13 @@ export function createMockRequestEvent(options = {}) {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
const request =
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
const request = options.request ||
|
|
128
|
+
new Request(url.toString(), {
|
|
129
|
+
method,
|
|
130
|
+
headers,
|
|
131
|
+
body: method !== 'GET' && method !== 'HEAD' ? bodyContent : undefined,
|
|
132
|
+
signal: options.signal
|
|
133
|
+
});
|
|
132
134
|
const cookieStore = new Map(Object.entries(options.cookies || {}));
|
|
133
135
|
const cookies = {
|
|
134
136
|
get: (name) => cookieStore.get(name),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yaxa-svelte",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "The Intuitive Svelte UI Library — Nuxt UI v4 equivalent for SvelteKit 2 & 3 & Svelte 5 with automated SEO, dynamic OpenGraph cards, sitemaps, robots.txt, and Tailwind CSS v4.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://yaxa.vercel.app",
|