@spfn/core 0.1.0-alpha.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 (37) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +580 -0
  3. package/dist/auto-loader-C44TcLmM.d.ts +125 -0
  4. package/dist/bind-pssq1NRT.d.ts +34 -0
  5. package/dist/client/index.d.ts +174 -0
  6. package/dist/client/index.js +179 -0
  7. package/dist/client/index.js.map +1 -0
  8. package/dist/codegen/index.d.ts +126 -0
  9. package/dist/codegen/index.js +970 -0
  10. package/dist/codegen/index.js.map +1 -0
  11. package/dist/db/index.d.ts +83 -0
  12. package/dist/db/index.js +2099 -0
  13. package/dist/db/index.js.map +1 -0
  14. package/dist/index.d.ts +379 -0
  15. package/dist/index.js +13042 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/postgres-errors-CY_Es8EJ.d.ts +1703 -0
  18. package/dist/route/index.d.ts +72 -0
  19. package/dist/route/index.js +442 -0
  20. package/dist/route/index.js.map +1 -0
  21. package/dist/scripts/index.d.ts +24 -0
  22. package/dist/scripts/index.js +1157 -0
  23. package/dist/scripts/index.js.map +1 -0
  24. package/dist/scripts/templates/api-index.template.txt +10 -0
  25. package/dist/scripts/templates/api-tag.template.txt +11 -0
  26. package/dist/scripts/templates/contract.template.txt +87 -0
  27. package/dist/scripts/templates/entity-type.template.txt +31 -0
  28. package/dist/scripts/templates/entity.template.txt +19 -0
  29. package/dist/scripts/templates/index.template.txt +10 -0
  30. package/dist/scripts/templates/repository.template.txt +37 -0
  31. package/dist/scripts/templates/routes-id.template.txt +59 -0
  32. package/dist/scripts/templates/routes-index.template.txt +44 -0
  33. package/dist/server/index.d.ts +303 -0
  34. package/dist/server/index.js +12923 -0
  35. package/dist/server/index.js.map +1 -0
  36. package/dist/types-SlzTr8ZO.d.ts +143 -0
  37. package/package.json +119 -0
@@ -0,0 +1,303 @@
1
+ import { MiddlewareHandler, Hono } from 'hono';
2
+ import { cors } from 'hono/cors';
3
+ import { serve } from '@hono/node-server';
4
+
5
+ /**
6
+ * CORS configuration options - inferred from hono/cors
7
+ */
8
+ type CorsConfig = Parameters<typeof cors>[0];
9
+ /**
10
+ * Server Configuration Options
11
+ *
12
+ * Level 2: Partial customization with server.config.ts
13
+ */
14
+ interface ServerConfig {
15
+ /**
16
+ * Server port (default: 4000)
17
+ */
18
+ port?: number;
19
+ /**
20
+ * Server hostname (default: 'localhost')
21
+ */
22
+ host?: string;
23
+ /**
24
+ * CORS configuration
25
+ * Set to false to disable default CORS middleware
26
+ */
27
+ cors?: CorsConfig | false;
28
+ /**
29
+ * Enable/disable built-in middleware
30
+ */
31
+ middleware?: {
32
+ /**
33
+ * Request logger (default: true)
34
+ */
35
+ logger?: boolean;
36
+ /**
37
+ * CORS (default: true)
38
+ */
39
+ cors?: boolean;
40
+ /**
41
+ * Error handler (default: true)
42
+ */
43
+ errorHandler?: boolean;
44
+ };
45
+ /**
46
+ * Additional custom middleware
47
+ */
48
+ use?: MiddlewareHandler[];
49
+ /**
50
+ * Global middlewares with names for route-level skip control
51
+ * Each middleware can be skipped per route using meta.skipMiddlewares
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * import { authMiddleware } from '@spfn/auth';
56
+ *
57
+ * export default {
58
+ * middlewares: [
59
+ * { name: 'auth', handler: authMiddleware() },
60
+ * { name: 'rateLimit', handler: rateLimitMiddleware() },
61
+ * ]
62
+ * } satisfies ServerConfig;
63
+ * ```
64
+ */
65
+ middlewares?: Array<{
66
+ name: string;
67
+ handler: MiddlewareHandler;
68
+ }>;
69
+ /**
70
+ * Routes directory path (default: src/server/routes)
71
+ */
72
+ routesPath?: string;
73
+ /**
74
+ * Enable debug mode (default: NODE_ENV === 'development')
75
+ */
76
+ debug?: boolean;
77
+ /**
78
+ * Database configuration
79
+ */
80
+ database?: {
81
+ /**
82
+ * Connection pool configuration
83
+ * Overrides environment variables and defaults
84
+ */
85
+ pool?: {
86
+ /**
87
+ * Maximum number of connections in pool
88
+ * @default Production: 20, Development: 10
89
+ * @env DB_POOL_MAX
90
+ */
91
+ max?: number;
92
+ /**
93
+ * Idle connection timeout in seconds
94
+ * @default Production: 30, Development: 20
95
+ * @env DB_POOL_IDLE_TIMEOUT
96
+ */
97
+ idleTimeout?: number;
98
+ };
99
+ /**
100
+ * Health check configuration
101
+ * Periodic checks to ensure database connection is alive
102
+ */
103
+ healthCheck?: {
104
+ /**
105
+ * Enable/disable health checks
106
+ * @default true
107
+ * @env DB_HEALTH_CHECK_ENABLED
108
+ */
109
+ enabled?: boolean;
110
+ /**
111
+ * Health check interval in milliseconds
112
+ * @default 60000 (60 seconds)
113
+ * @env DB_HEALTH_CHECK_INTERVAL
114
+ */
115
+ interval?: number;
116
+ /**
117
+ * Enable automatic reconnection on failure
118
+ * @default true
119
+ * @env DB_HEALTH_CHECK_RECONNECT
120
+ */
121
+ reconnect?: boolean;
122
+ /**
123
+ * Maximum reconnection attempts
124
+ * @default 3
125
+ * @env DB_HEALTH_CHECK_MAX_RETRIES
126
+ */
127
+ maxRetries?: number;
128
+ /**
129
+ * Delay between reconnection attempts in milliseconds
130
+ * @default 5000 (5 seconds)
131
+ * @env DB_HEALTH_CHECK_RETRY_INTERVAL
132
+ */
133
+ retryInterval?: number;
134
+ };
135
+ /**
136
+ * Query performance monitoring configuration
137
+ * Tracks slow queries and logs performance metrics
138
+ */
139
+ monitoring?: {
140
+ /**
141
+ * Enable/disable query performance monitoring
142
+ * @default true in development, false in production
143
+ * @env DB_MONITORING_ENABLED
144
+ */
145
+ enabled?: boolean;
146
+ /**
147
+ * Slow query threshold in milliseconds
148
+ * Queries exceeding this duration will be logged as warnings
149
+ * @default 1000 (1 second)
150
+ * @env DB_MONITORING_SLOW_THRESHOLD
151
+ */
152
+ slowThreshold?: number;
153
+ /**
154
+ * Log actual SQL queries in performance logs
155
+ * ⚠️ Warning: May expose sensitive data in logs
156
+ * @default false
157
+ * @env DB_MONITORING_LOG_QUERIES
158
+ */
159
+ logQueries?: boolean;
160
+ };
161
+ };
162
+ /**
163
+ * Server timeout configuration
164
+ * Controls HTTP server timeout behavior for security and resource management
165
+ */
166
+ timeout?: {
167
+ /**
168
+ * Request timeout in milliseconds
169
+ * Time limit for entire request/response cycle
170
+ * Set to 0 to disable (not recommended in production)
171
+ * @default 120000 (2 minutes)
172
+ * @env SERVER_TIMEOUT
173
+ */
174
+ request?: number;
175
+ /**
176
+ * Keep-alive timeout in milliseconds
177
+ * How long to keep idle HTTP connections open for reuse
178
+ * Should be slightly longer than load balancer timeout (typically 60s)
179
+ * @default 65000 (65 seconds)
180
+ * @env SERVER_KEEPALIVE_TIMEOUT
181
+ */
182
+ keepAlive?: number;
183
+ /**
184
+ * Headers timeout in milliseconds
185
+ * Time limit for receiving complete HTTP request headers
186
+ * Protects against Slowloris attacks
187
+ * @default 60000 (60 seconds)
188
+ * @env SERVER_HEADERS_TIMEOUT
189
+ */
190
+ headers?: number;
191
+ };
192
+ /**
193
+ * Graceful shutdown configuration
194
+ * Controls server shutdown behavior during SIGTERM/SIGINT signals
195
+ */
196
+ shutdown?: {
197
+ /**
198
+ * Graceful shutdown timeout in milliseconds
199
+ * Maximum time to wait for ongoing requests and resource cleanup
200
+ * After timeout, forces process termination
201
+ * @default 30000 (30 seconds)
202
+ * @env SHUTDOWN_TIMEOUT
203
+ */
204
+ timeout?: number;
205
+ };
206
+ /**
207
+ * Health check endpoint configuration
208
+ * Provides monitoring endpoints for Kubernetes probes and load balancers
209
+ */
210
+ healthCheck?: {
211
+ /**
212
+ * Enable health check endpoint
213
+ * @default true
214
+ * @env HEALTH_CHECK_ENABLED
215
+ */
216
+ enabled?: boolean;
217
+ /**
218
+ * Health check endpoint path
219
+ * @default '/health'
220
+ * @env HEALTH_CHECK_PATH
221
+ */
222
+ path?: string;
223
+ /**
224
+ * Include detailed status (DB, Redis, etc.)
225
+ * Detailed mode checks connectivity to external services
226
+ * @default false in production, true in development
227
+ * @env HEALTH_CHECK_DETAILED
228
+ */
229
+ detailed?: boolean;
230
+ };
231
+ /**
232
+ * Hook: Run before routes are loaded
233
+ */
234
+ beforeRoutes?: (app: Hono) => void | Promise<void>;
235
+ /**
236
+ * Hook: Run after routes are loaded
237
+ */
238
+ afterRoutes?: (app: Hono) => void | Promise<void>;
239
+ }
240
+ /**
241
+ * App Factory Function
242
+ *
243
+ * Level 3: Full control with app.ts
244
+ */
245
+ type AppFactory = () => Promise<Hono> | Hono;
246
+ /**
247
+ * Server Instance
248
+ *
249
+ * Returned by startServer() to provide access to server internals
250
+ * Allows programmatic control over the server lifecycle
251
+ */
252
+ interface ServerInstance {
253
+ /**
254
+ * Underlying Node.js HTTP server
255
+ * Provides low-level access to the HTTP server instance
256
+ */
257
+ server: ReturnType<typeof serve>;
258
+ /**
259
+ * Hono app instance
260
+ * Allows runtime route registration and middleware management
261
+ */
262
+ app: Hono;
263
+ /**
264
+ * Final server configuration used
265
+ * Contains resolved values from all sources (runtime > file > env > defaults)
266
+ */
267
+ config: ServerConfig;
268
+ /**
269
+ * Manually close the server
270
+ * Performs graceful shutdown: stops accepting connections, closes DB/Redis, exits process
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * const instance = await startServer({ port: 3000 });
275
+ *
276
+ * // Later...
277
+ * await instance.close(); // Clean shutdown
278
+ * ```
279
+ */
280
+ close: () => Promise<void>;
281
+ }
282
+
283
+ /**
284
+ * Create Hono app with automatic configuration
285
+ *
286
+ * Levels:
287
+ * 1. No app.ts -> Full auto config
288
+ * 2. server.config.ts -> Partial customization
289
+ * 3. app.ts -> Full control (no auto config)
290
+ */
291
+ declare function createServer(config?: ServerConfig): Promise<Hono>;
292
+ /**
293
+ * Start SPFN server
294
+ *
295
+ * Automatically loads server.config.ts if exists
296
+ * Automatically initializes Database and Redis from environment
297
+ * Sets up graceful shutdown handlers for SIGTERM and SIGINT
298
+ *
299
+ * @returns ServerInstance with server, app, config, and close() method
300
+ */
301
+ declare function startServer(config?: ServerConfig): Promise<ServerInstance>;
302
+
303
+ export { type AppFactory, type ServerConfig, type ServerInstance, createServer, startServer };