pulse-js-framework 1.10.4 → 1.11.1

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.
Files changed (65) hide show
  1. package/README.md +11 -0
  2. package/cli/build.js +13 -3
  3. package/compiler/directives.js +356 -0
  4. package/compiler/lexer.js +18 -3
  5. package/compiler/parser/core.js +6 -0
  6. package/compiler/parser/view.js +2 -6
  7. package/compiler/preprocessor.js +43 -23
  8. package/compiler/sourcemap.js +3 -1
  9. package/compiler/transformer/actions.js +329 -0
  10. package/compiler/transformer/export.js +7 -0
  11. package/compiler/transformer/expressions.js +85 -33
  12. package/compiler/transformer/imports.js +3 -0
  13. package/compiler/transformer/index.js +2 -0
  14. package/compiler/transformer/store.js +1 -1
  15. package/compiler/transformer/style.js +45 -16
  16. package/compiler/transformer/view.js +23 -2
  17. package/loader/rollup-plugin-server-components.js +391 -0
  18. package/loader/vite-plugin-server-components.js +420 -0
  19. package/loader/webpack-loader-server-components.js +356 -0
  20. package/package.json +124 -82
  21. package/runtime/async.js +4 -0
  22. package/runtime/context.js +16 -3
  23. package/runtime/dom-adapter.js +5 -3
  24. package/runtime/dom-virtual-list.js +2 -1
  25. package/runtime/form.js +8 -3
  26. package/runtime/graphql/cache.js +1 -1
  27. package/runtime/graphql/client.js +22 -0
  28. package/runtime/graphql/hooks.js +12 -6
  29. package/runtime/graphql/subscriptions.js +2 -0
  30. package/runtime/hmr.js +6 -3
  31. package/runtime/http.js +1 -0
  32. package/runtime/i18n.js +2 -0
  33. package/runtime/lru-cache.js +3 -1
  34. package/runtime/native.js +46 -20
  35. package/runtime/pulse.js +3 -0
  36. package/runtime/router/core.js +5 -1
  37. package/runtime/router/index.js +17 -1
  38. package/runtime/router/psc-integration.js +301 -0
  39. package/runtime/security.js +58 -29
  40. package/runtime/server-components/actions-server.js +798 -0
  41. package/runtime/server-components/actions.js +389 -0
  42. package/runtime/server-components/client.js +447 -0
  43. package/runtime/server-components/error-sanitizer.js +438 -0
  44. package/runtime/server-components/index.js +275 -0
  45. package/runtime/server-components/security-csrf.js +593 -0
  46. package/runtime/server-components/security-errors.js +227 -0
  47. package/runtime/server-components/security-ratelimit.js +733 -0
  48. package/runtime/server-components/security-validation.js +467 -0
  49. package/runtime/server-components/security.js +598 -0
  50. package/runtime/server-components/serializer.js +617 -0
  51. package/runtime/server-components/server.js +382 -0
  52. package/runtime/server-components/types.js +383 -0
  53. package/runtime/server-components/utils/mutex.js +60 -0
  54. package/runtime/server-components/utils/path-sanitizer.js +109 -0
  55. package/runtime/ssr.js +2 -1
  56. package/runtime/store.js +19 -10
  57. package/runtime/utils.js +12 -128
  58. package/types/animation.d.ts +300 -0
  59. package/types/i18n.d.ts +283 -0
  60. package/types/persistence.d.ts +267 -0
  61. package/types/sse.d.ts +248 -0
  62. package/types/sw.d.ts +150 -0
  63. package/runtime/a11y.js.original +0 -1844
  64. package/runtime/graphql.js.original +0 -1326
  65. package/runtime/router.js.original +0 -1605
package/types/sse.d.ts ADDED
@@ -0,0 +1,248 @@
1
+ /**
2
+ * Pulse SSE (Server-Sent Events) Type Definitions
3
+ * @module pulse-js-framework/runtime/sse
4
+ */
5
+
6
+ import { Pulse } from './pulse';
7
+
8
+ // ============================================================================
9
+ // SSE Connection State
10
+ // ============================================================================
11
+
12
+ /** SSE connection state */
13
+ export type SSEState = 'connecting' | 'open' | 'closed';
14
+
15
+ // ============================================================================
16
+ // SSE Error
17
+ // ============================================================================
18
+
19
+ /** SSE error code */
20
+ export type SSEErrorCode =
21
+ | 'CONNECT_FAILED'
22
+ | 'TIMEOUT'
23
+ | 'MAX_RETRIES'
24
+ | 'CLOSED'
25
+ | 'UNKNOWN';
26
+
27
+ /**
28
+ * SSE-specific error with structured codes
29
+ */
30
+ export declare class SSEError extends Error {
31
+ readonly name: 'SSEError';
32
+ readonly sseCode: SSEErrorCode;
33
+
34
+ constructor(message: string, options?: {
35
+ sseCode?: SSEErrorCode;
36
+ suggestion?: string;
37
+ });
38
+
39
+ /** Check if an error is an SSEError */
40
+ static isSSEError(error: unknown): error is SSEError;
41
+
42
+ /** Check if this is a connection failure */
43
+ isConnectFailed(): boolean;
44
+
45
+ /** Check if this is a timeout error */
46
+ isTimeout(): boolean;
47
+
48
+ /** Check if max retries were exhausted */
49
+ isMaxRetries(): boolean;
50
+
51
+ /** Check if connection was closed */
52
+ isClosed(): boolean;
53
+ }
54
+
55
+ // ============================================================================
56
+ // createSSE Options
57
+ // ============================================================================
58
+
59
+ /** Event handler for SSE messages */
60
+ export type SSEMessageHandler = (data: unknown, event: MessageEvent) => void;
61
+
62
+ /** Options for createSSE */
63
+ export interface CreateSSEOptions {
64
+ /** Include credentials in the request (default: false) */
65
+ withCredentials?: boolean;
66
+
67
+ /** Enable auto-reconnect on connection loss (default: true) */
68
+ reconnect?: boolean;
69
+
70
+ /** Maximum number of reconnection attempts (default: 5) */
71
+ maxRetries?: number;
72
+
73
+ /** Base delay for exponential backoff in ms (default: 1000) */
74
+ baseDelay?: number;
75
+
76
+ /** Maximum delay between reconnection attempts in ms (default: 30000) */
77
+ maxDelay?: number;
78
+
79
+ /** Event types to listen for (default: ['message']) */
80
+ events?: string[];
81
+
82
+ /** Auto-parse JSON message data (default: true) */
83
+ parseJSON?: boolean;
84
+
85
+ /** Connect immediately on creation (default: true) */
86
+ immediate?: boolean;
87
+
88
+ /** Callback invoked on each message */
89
+ onMessage?: SSEMessageHandler | null;
90
+
91
+ /** Callback invoked when connection opens */
92
+ onOpen?: (() => void) | null;
93
+
94
+ /** Callback invoked on error */
95
+ onError?: ((error: SSEError) => void) | null;
96
+ }
97
+
98
+ // ============================================================================
99
+ // createSSE Return Type
100
+ // ============================================================================
101
+
102
+ /** Return type of createSSE */
103
+ export interface SSEInstance {
104
+ /** Reactive connection state ('connecting' | 'open' | 'closed') */
105
+ state: Pulse<SSEState>;
106
+
107
+ /** Reactive connected flag (true when state is 'open') */
108
+ connected: Pulse<boolean>;
109
+
110
+ /** Reactive reconnecting state */
111
+ reconnecting: Pulse<boolean>;
112
+
113
+ /** Reactive current reconnection attempt number */
114
+ reconnectAttempt: Pulse<number>;
115
+
116
+ /** Reactive last error */
117
+ error: Pulse<SSEError | null>;
118
+
119
+ /** Reactive last event ID from the server */
120
+ lastEventId: Pulse<string | null>;
121
+
122
+ /** Manually initiate a connection (resets reconnection state) */
123
+ connect(): void;
124
+
125
+ /** Close the connection and stop reconnecting */
126
+ close(): void;
127
+
128
+ /** Add an event listener for a specific event type */
129
+ addEventListener(event: string, handler: SSEMessageHandler): void;
130
+
131
+ /** Remove an event listener */
132
+ removeEventListener(event: string, handler: SSEMessageHandler): void;
133
+
134
+ /** Permanently dispose the SSE instance and clean up all resources */
135
+ dispose(): void;
136
+
137
+ /** Alias for addEventListener */
138
+ on(event: string, handler: SSEMessageHandler): void;
139
+
140
+ /** Alias for removeEventListener */
141
+ off(event: string, handler: SSEMessageHandler): void;
142
+ }
143
+
144
+ /**
145
+ * Create a low-level SSE connection with auto-reconnect and exponential backoff.
146
+ *
147
+ * @param url SSE endpoint URL
148
+ * @param options Configuration options
149
+ * @returns SSE instance with reactive state and control methods
150
+ *
151
+ * @example
152
+ * const sse = createSSE('https://api.example.com/events', {
153
+ * reconnect: true,
154
+ * maxRetries: 5,
155
+ * events: ['message', 'update'],
156
+ * onMessage: (data) => console.log('Received:', data),
157
+ * });
158
+ *
159
+ * sse.on('update', (data) => handleUpdate(data));
160
+ * sse.close();
161
+ */
162
+ export declare function createSSE(url: string, options?: CreateSSEOptions): SSEInstance;
163
+
164
+ // ============================================================================
165
+ // useSSE Options and Return Type
166
+ // ============================================================================
167
+
168
+ /** Options for useSSE hook */
169
+ export interface UseSSEOptions extends CreateSSEOptions {
170
+ /** Number of messages to keep in history (default: 0 = disabled) */
171
+ messageHistorySize?: number;
172
+ }
173
+
174
+ /** Return type of useSSE (without message history) */
175
+ export interface UseSSEReturnBase {
176
+ /** Reactive last received message data */
177
+ data: Pulse<unknown>;
178
+
179
+ /** Reactive connected flag */
180
+ connected: Pulse<boolean>;
181
+
182
+ /** Reactive last error */
183
+ error: Pulse<SSEError | null>;
184
+
185
+ /** Reactive reconnecting state */
186
+ reconnecting: Pulse<boolean>;
187
+
188
+ /** Reactive last event ID */
189
+ lastEventId: Pulse<string | null>;
190
+
191
+ /** Close the SSE connection */
192
+ close(): void;
193
+
194
+ /** Reconnect to the SSE endpoint */
195
+ reconnect(): void;
196
+
197
+ /** Underlying SSE instance */
198
+ sse: SSEInstance;
199
+ }
200
+
201
+ /** Return type of useSSE (with message history) */
202
+ export interface UseSSEReturnWithHistory extends UseSSEReturnBase {
203
+ /** Reactive message history array */
204
+ messages: Pulse<unknown[]>;
205
+
206
+ /** Clear the message history */
207
+ clearMessages(): void;
208
+ }
209
+
210
+ /** Return type of useSSE */
211
+ export type UseSSEReturn = UseSSEReturnBase | UseSSEReturnWithHistory;
212
+
213
+ /**
214
+ * Reactive SSE hook with automatic lifecycle management.
215
+ * Automatically disposes the connection when the enclosing effect is cleaned up.
216
+ *
217
+ * @param url SSE endpoint URL
218
+ * @param options Configuration options
219
+ * @returns Reactive SSE state and control methods
220
+ *
221
+ * @example
222
+ * const { data, connected, error, close } = useSSE(
223
+ * 'https://api.example.com/stream',
224
+ * {
225
+ * parseJSON: true,
226
+ * messageHistorySize: 50,
227
+ * onMessage: (data) => console.log('New event:', data),
228
+ * }
229
+ * );
230
+ *
231
+ * effect(() => {
232
+ * if (connected.get()) console.log('SSE connected');
233
+ * if (data.get()) console.log('Latest:', data.get());
234
+ * });
235
+ */
236
+ export declare function useSSE(url: string, options?: UseSSEOptions): UseSSEReturn;
237
+
238
+ // ============================================================================
239
+ // Default Export
240
+ // ============================================================================
241
+
242
+ declare const _default: {
243
+ createSSE: typeof createSSE;
244
+ useSSE: typeof useSSE;
245
+ SSEError: typeof SSEError;
246
+ };
247
+
248
+ export default _default;
package/types/sw.d.ts ADDED
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Pulse Service Worker Utilities Type Definitions
3
+ * @module pulse-js-framework/sw
4
+ */
5
+
6
+ // ============================================================================
7
+ // Cache Strategy Types
8
+ // ============================================================================
9
+
10
+ /** Supported cache strategy names */
11
+ export type CacheStrategyName =
12
+ | 'cache-first'
13
+ | 'network-first'
14
+ | 'stale-while-revalidate'
15
+ | 'network-only'
16
+ | 'cache-only';
17
+
18
+ /** URL matcher: regex pattern or predicate function */
19
+ export type URLMatcher = RegExp | ((url: string) => boolean);
20
+
21
+ /** Options for createCacheStrategy */
22
+ export interface CacheStrategyOptions {
23
+ /** Cache storage name (required) */
24
+ cacheName: string;
25
+
26
+ /** URL matching pattern or function (default: matches all) */
27
+ match?: URLMatcher | null;
28
+
29
+ /** Maximum cache age in ms (default: 0 = no expiry) */
30
+ maxAge?: number;
31
+
32
+ /** Maximum number of cached entries (default: 0 = unlimited) */
33
+ maxEntries?: number;
34
+
35
+ /** Network timeout in ms for network-first strategy (default: 5000) */
36
+ timeout?: number;
37
+ }
38
+
39
+ /** Cache strategy instance returned by createCacheStrategy */
40
+ export interface CacheStrategy {
41
+ /** Strategy name */
42
+ readonly name: CacheStrategyName;
43
+
44
+ /** Cache storage name */
45
+ readonly cacheName: string;
46
+
47
+ /**
48
+ * Handle a fetch event with this strategy.
49
+ * Calls event.respondWith() if the request matches.
50
+ *
51
+ * @param event The service worker FetchEvent
52
+ * @returns True if this strategy handled the event, false if the request did not match
53
+ */
54
+ handle(event: FetchEvent): boolean;
55
+
56
+ /**
57
+ * Fetch a request using this strategy (without FetchEvent).
58
+ *
59
+ * @param request The request URL string or Request object
60
+ * @returns Response promise
61
+ */
62
+ fetch(request: Request | string): Promise<Response>;
63
+
64
+ /**
65
+ * Precache a list of URLs into this strategy's cache.
66
+ *
67
+ * @param urls Array of URLs to precache
68
+ */
69
+ precache(urls: string[]): Promise<void>;
70
+
71
+ /**
72
+ * Delete this strategy's entire cache.
73
+ *
74
+ * @returns True if the cache was successfully deleted
75
+ */
76
+ clearCache(): Promise<boolean>;
77
+ }
78
+
79
+ /**
80
+ * Create a cache strategy for handling service worker fetch events.
81
+ *
82
+ * @param name Strategy type
83
+ * @param options Strategy configuration
84
+ * @returns Cache strategy instance with handle(), fetch(), precache(), and clearCache() methods
85
+ * @throws Error if cacheName is not provided or strategy name is unknown
86
+ *
87
+ * @example
88
+ * // In your sw.js:
89
+ * import { createCacheStrategy } from 'pulse-js-framework/sw';
90
+ *
91
+ * const staticCache = createCacheStrategy('cache-first', {
92
+ * cacheName: 'static-v1',
93
+ * match: /\.(js|css|png|woff2)$/,
94
+ * maxEntries: 100,
95
+ * });
96
+ *
97
+ * const apiCache = createCacheStrategy('network-first', {
98
+ * cacheName: 'api-v1',
99
+ * match: /\/api\//,
100
+ * timeout: 3000,
101
+ * maxAge: 5 * 60 * 1000, // 5 minutes
102
+ * });
103
+ *
104
+ * const swrCache = createCacheStrategy('stale-while-revalidate', {
105
+ * cacheName: 'swr-v1',
106
+ * match: /\/assets\//,
107
+ * });
108
+ *
109
+ * self.addEventListener('fetch', (event) => {
110
+ * if (staticCache.handle(event)) return;
111
+ * if (apiCache.handle(event)) return;
112
+ * if (swrCache.handle(event)) return;
113
+ * });
114
+ */
115
+ export declare function createCacheStrategy(
116
+ name: CacheStrategyName,
117
+ options: CacheStrategyOptions
118
+ ): CacheStrategy;
119
+
120
+ // ============================================================================
121
+ // Skip Waiting
122
+ // ============================================================================
123
+
124
+ /**
125
+ * Install a message listener for SKIP_WAITING messages.
126
+ * Call this in your service worker to enable skipWaiting from the main thread.
127
+ *
128
+ * When the main thread sends `{ type: 'SKIP_WAITING' }` via postMessage,
129
+ * the service worker will call self.skipWaiting() to activate immediately.
130
+ *
131
+ * @example
132
+ * // In your sw.js:
133
+ * import { enableSkipWaiting } from 'pulse-js-framework/sw';
134
+ * enableSkipWaiting();
135
+ *
136
+ * // In your main thread:
137
+ * navigator.serviceWorker.controller?.postMessage({ type: 'SKIP_WAITING' });
138
+ */
139
+ export declare function enableSkipWaiting(): void;
140
+
141
+ // ============================================================================
142
+ // Default Export
143
+ // ============================================================================
144
+
145
+ declare const _default: {
146
+ createCacheStrategy: typeof createCacheStrategy;
147
+ enableSkipWaiting: typeof enableSkipWaiting;
148
+ };
149
+
150
+ export default _default;