@spfn/core 0.2.0-beta.3 → 0.2.0-beta.5

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.
@@ -0,0 +1,121 @@
1
+ import { E as EventRouterDef, I as InferEventNames, b as InferEventPayload } from './router-Di7ENoah.js';
2
+
3
+ /**
4
+ * SSE Types
5
+ *
6
+ * Type definitions for Server-Sent Events
7
+ */
8
+
9
+ /**
10
+ * SSE message sent from server
11
+ */
12
+ interface SSEMessage<TEvent extends string = string, TPayload = unknown> {
13
+ /** Event name */
14
+ event: TEvent;
15
+ /** Event payload */
16
+ data: TPayload;
17
+ /** Optional message ID for reconnection */
18
+ id?: string;
19
+ }
20
+ /**
21
+ * SSE Handler configuration
22
+ */
23
+ interface SSEHandlerConfig {
24
+ /**
25
+ * Keep-alive ping interval in milliseconds
26
+ * @default 30000
27
+ */
28
+ pingInterval?: number;
29
+ /**
30
+ * Custom headers for SSE response
31
+ */
32
+ headers?: Record<string, string>;
33
+ }
34
+ /**
35
+ * SSE Client configuration
36
+ */
37
+ interface SSEClientConfig {
38
+ /**
39
+ * Backend API host URL
40
+ * @default NEXT_PUBLIC_SPFN_API_URL || 'http://localhost:8790'
41
+ * @example 'http://localhost:8790'
42
+ * @example 'https://api.example.com'
43
+ */
44
+ host?: string;
45
+ /**
46
+ * SSE endpoint pathname
47
+ * @default '/events/stream'
48
+ */
49
+ pathname?: string;
50
+ /**
51
+ * Full URL (overrides host + pathname)
52
+ * @deprecated Use host and pathname instead
53
+ * @example 'http://localhost:8790/events/stream'
54
+ */
55
+ url?: string;
56
+ /**
57
+ * Auto reconnect on disconnect
58
+ * @default true
59
+ */
60
+ reconnect?: boolean;
61
+ /**
62
+ * Reconnect delay in milliseconds
63
+ * @default 3000
64
+ */
65
+ reconnectDelay?: number;
66
+ /**
67
+ * Maximum reconnect attempts (0 = infinite)
68
+ * @default 0
69
+ */
70
+ maxReconnectAttempts?: number;
71
+ /**
72
+ * Include credentials (cookies) in request
73
+ * @default false
74
+ */
75
+ withCredentials?: boolean;
76
+ }
77
+ /**
78
+ * Event handler function
79
+ */
80
+ type SSEEventHandler<TPayload> = (payload: TPayload) => void;
81
+ /**
82
+ * Event handlers map for EventRouter
83
+ */
84
+ type SSEEventHandlers<TRouter extends EventRouterDef<any>> = {
85
+ [K in InferEventNames<TRouter>]?: SSEEventHandler<InferEventPayload<TRouter, K>>;
86
+ };
87
+ /**
88
+ * Subscription options
89
+ */
90
+ interface SSESubscribeOptions<TRouter extends EventRouterDef<any>> {
91
+ /**
92
+ * Events to subscribe
93
+ */
94
+ events: InferEventNames<TRouter>[];
95
+ /**
96
+ * Event handlers
97
+ */
98
+ handlers: SSEEventHandlers<TRouter>;
99
+ /**
100
+ * Called when connection opens
101
+ */
102
+ onOpen?: () => void;
103
+ /**
104
+ * Called on connection error
105
+ */
106
+ onError?: (error: Event) => void;
107
+ /**
108
+ * Called when reconnecting
109
+ */
110
+ onReconnect?: (attempt: number) => void;
111
+ }
112
+ /**
113
+ * SSE connection state
114
+ */
115
+ type SSEConnectionState = 'connecting' | 'open' | 'closed' | 'error';
116
+ /**
117
+ * Unsubscribe function
118
+ */
119
+ type SSEUnsubscribe = () => void;
120
+
121
+ export type { SSEHandlerConfig as S, SSEMessage as a, SSEClientConfig as b, SSEEventHandler as c, SSEEventHandlers as d, SSESubscribeOptions as e, SSEConnectionState as f, SSEUnsubscribe as g };
@@ -47,6 +47,52 @@ type InferRouteInput<TRoute> = TRoute extends RouteDef<infer TInput, any, any> ?
47
47
  * ```
48
48
  */
49
49
  type InferRouteOutput<TRoute> = TRoute extends RouteDef<any, any, infer TResponse> ? TResponse : never;
50
+ /**
51
+ * Extract routes from Router type
52
+ * Router<TRoutes> has routes in `_routes` property
53
+ */
54
+ type ExtractRoutes<TRouter> = TRouter extends {
55
+ _routes: infer TRoutes;
56
+ } ? TRoutes : TRouter;
57
+ /**
58
+ * Extract output type for a specific route from router
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * import type { RouterOutput } from '@spfn/core/nextjs';
63
+ * import type { AppRouter } from '@/server/router';
64
+ *
65
+ * // Get output type for a specific route
66
+ * type ListData = RouterOutput<AppRouter, 'listExamples'>;
67
+ *
68
+ * // Use in props
69
+ * interface Props {
70
+ * data: RouterOutput<AppRouter, 'listExamples'>;
71
+ * }
72
+ *
73
+ * // Extract item type from paginated response
74
+ * type Example = RouterOutput<AppRouter, 'listExamples'>['items'][number];
75
+ * ```
76
+ */
77
+ type RouterOutput<TRouter, K extends keyof ExtractRoutes<TRouter>> = InferRouteOutput<ExtractRoutes<TRouter>[K]>;
78
+ /**
79
+ * Extract input type for a specific route from router
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * import type { RouterInput } from '@spfn/core/nextjs';
84
+ * import type { AppRouter } from '@/server/router';
85
+ *
86
+ * // Get input type for a specific route
87
+ * type CreateInput = RouterInput<AppRouter, 'createExample'>;
88
+ *
89
+ * // Use in function parameter
90
+ * function submitForm(data: RouterInput<AppRouter, 'createExample'>['body']) {
91
+ * // ...
92
+ * }
93
+ * ```
94
+ */
95
+ type RouterInput<TRouter, K extends keyof ExtractRoutes<TRouter>> = InferRouteInput<ExtractRoutes<TRouter>[K]>;
50
96
  /**
51
97
  * Cookie options for setCookie
52
98
  */
@@ -181,4 +227,4 @@ interface CallOptions {
181
227
  };
182
228
  }
183
229
 
184
- export type { ApiConfig as A, CallOptions as C, InferRouteInput as I, RequestInterceptor as R, StructuredInput as S, ResponseInterceptor as a, InferRouteOutput as b, CookieOptions as c, SetCookie as d };
230
+ export type { ApiConfig as A, CallOptions as C, InferRouteInput as I, RequestInterceptor as R, StructuredInput as S, ResponseInterceptor as a, InferRouteOutput as b, RouterInput as c, RouterOutput as d, CookieOptions as e, SetCookie as f };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spfn/core",
3
- "version": "0.2.0-beta.3",
3
+ "version": "0.2.0-beta.5",
4
4
  "description": "SPFN Framework Core - File-based routing, transactions, repository pattern",
5
5
  "type": "module",
6
6
  "exports": {
@@ -64,6 +64,11 @@
64
64
  "import": "./dist/env/index.js",
65
65
  "require": "./dist/env/index.js"
66
66
  },
67
+ "./env/loader": {
68
+ "types": "./dist/env/loader.d.ts",
69
+ "import": "./dist/env/loader.js",
70
+ "require": "./dist/env/loader.js"
71
+ },
67
72
  "./logger": {
68
73
  "types": "./dist/logger/index.d.ts",
69
74
  "import": "./dist/logger/index.js",
@@ -83,6 +88,16 @@
83
88
  "types": "./dist/event/index.d.ts",
84
89
  "import": "./dist/event/index.js",
85
90
  "require": "./dist/event/index.js"
91
+ },
92
+ "./event/sse": {
93
+ "types": "./dist/event/sse/index.d.ts",
94
+ "import": "./dist/event/sse/index.js",
95
+ "require": "./dist/event/sse/index.js"
96
+ },
97
+ "./event/sse/client": {
98
+ "types": "./dist/event/sse/client.d.ts",
99
+ "import": "./dist/event/sse/client.js",
100
+ "require": "./dist/event/sse/client.js"
86
101
  }
87
102
  },
88
103
  "keywords": [
@@ -148,7 +163,7 @@
148
163
  "@vitest/coverage-v8": "^4.0.6",
149
164
  "drizzle-kit": "^0.31.6",
150
165
  "madge": "^8.0.0",
151
- "next": "16.0.7",
166
+ "next": "^16.0.0",
152
167
  "tsup": "^8.5.0",
153
168
  "vitest": "^4.0.6"
154
169
  },