@spfn/core 0.2.0-beta.2 → 0.2.0-beta.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.
Files changed (43) hide show
  1. package/README.md +91 -6
  2. package/dist/{boss-D-fGtVgM.d.ts → boss-BO8ty33K.d.ts} +45 -5
  3. package/dist/config/index.d.ts +36 -0
  4. package/dist/config/index.js +15 -6
  5. package/dist/config/index.js.map +1 -1
  6. package/dist/env/index.d.ts +29 -3
  7. package/dist/env/index.js +13 -13
  8. package/dist/env/index.js.map +1 -1
  9. package/dist/env/loader.d.ts +87 -0
  10. package/dist/env/loader.js +70 -0
  11. package/dist/env/loader.js.map +1 -0
  12. package/dist/event/index.d.ts +3 -70
  13. package/dist/event/index.js +10 -1
  14. package/dist/event/index.js.map +1 -1
  15. package/dist/event/sse/client.d.ts +82 -0
  16. package/dist/event/sse/client.js +115 -0
  17. package/dist/event/sse/client.js.map +1 -0
  18. package/dist/event/sse/index.d.ts +40 -0
  19. package/dist/event/sse/index.js +92 -0
  20. package/dist/event/sse/index.js.map +1 -0
  21. package/dist/job/index.d.ts +34 -3
  22. package/dist/job/index.js +18 -9
  23. package/dist/job/index.js.map +1 -1
  24. package/dist/middleware/index.d.ts +102 -11
  25. package/dist/middleware/index.js +2 -2
  26. package/dist/middleware/index.js.map +1 -1
  27. package/dist/nextjs/index.d.ts +2 -2
  28. package/dist/nextjs/index.js +1 -1
  29. package/dist/nextjs/index.js.map +1 -1
  30. package/dist/nextjs/server.d.ts +2 -2
  31. package/dist/nextjs/server.js +4 -1
  32. package/dist/nextjs/server.js.map +1 -1
  33. package/dist/route/index.d.ts +72 -13
  34. package/dist/route/index.js +82 -27
  35. package/dist/route/index.js.map +1 -1
  36. package/dist/route/types.d.ts +2 -31
  37. package/dist/router-Di7ENoah.d.ts +151 -0
  38. package/dist/server/index.d.ts +82 -6
  39. package/dist/server/index.js +175 -14
  40. package/dist/server/index.js.map +1 -1
  41. package/dist/types-B-e_f2dQ.d.ts +121 -0
  42. package/dist/{types-DRG2XMTR.d.ts → types-D_N_U-Py.d.ts} +76 -3
  43. package/package.json +18 -3
@@ -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 };
@@ -4,6 +4,8 @@ import { RouteDef, RouteInput } from '@spfn/core/route';
4
4
 
5
5
  /**
6
6
  * Extract structured input from RouteInput
7
+ *
8
+ * Converts TypeBox schemas to their static types for each input field.
7
9
  */
8
10
  type StructuredInput<TInput extends RouteInput> = {
9
11
  params: TInput['params'] extends TSchema ? Static<TInput['params']> : {};
@@ -13,13 +15,84 @@ type StructuredInput<TInput extends RouteInput> = {
13
15
  cookies: TInput['cookies'] extends TSchema ? Static<TInput['cookies']> : {};
14
16
  };
15
17
  /**
16
- * Infer route input type
18
+ * Infer route input type from RouteDef
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * // Server route definition
23
+ * const getUser = route.get('/users/:id')
24
+ * .input({ params: Type.Object({ id: Type.String() }) })
25
+ * .handler(...);
26
+ *
27
+ * // Client: extract input type
28
+ * type Input = InferRouteInput<typeof getUser>;
29
+ * // { params: { id: string }, query: {}, body: {}, ... }
30
+ * ```
17
31
  */
18
32
  type InferRouteInput<TRoute> = TRoute extends RouteDef<infer TInput, any, any> ? StructuredInput<TInput> : never;
19
33
  /**
20
- * Infer route output type
34
+ * Infer route output type from RouteDef
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // Server route definition
39
+ * const getUser = route.get('/users/:id')
40
+ * .handler(async (c) => {
41
+ * return { id: '1', name: 'John' };
42
+ * });
43
+ *
44
+ * // Client: extract output type
45
+ * type Output = InferRouteOutput<typeof getUser>;
46
+ * // { id: string, name: string }
47
+ * ```
21
48
  */
22
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]>;
23
96
  /**
24
97
  * Cookie options for setCookie
25
98
  */
@@ -154,4 +227,4 @@ interface CallOptions {
154
227
  };
155
228
  }
156
229
 
157
- export type { ApiConfig as A, CallOptions as C, InferRouteInput as I, RequestInterceptor as R, SetCookie as S, ResponseInterceptor as a, InferRouteOutput as b };
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.2",
3
+ "version": "0.2.0-beta.4",
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
  },
@@ -168,7 +183,7 @@
168
183
  ],
169
184
  "publishConfig": {
170
185
  "access": "public",
171
- "tag": "alpha"
186
+ "tag": "beta"
172
187
  },
173
188
  "scripts": {
174
189
  "build": "pnpm check:circular && tsup",