@spfn/core 0.1.0-alpha.8 → 0.1.0-alpha.81

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 (59) hide show
  1. package/README.md +169 -195
  2. package/dist/auto-loader-JFaZ9gON.d.ts +80 -0
  3. package/dist/cache/index.d.ts +211 -0
  4. package/dist/cache/index.js +992 -0
  5. package/dist/cache/index.js.map +1 -0
  6. package/dist/client/index.d.ts +131 -92
  7. package/dist/client/index.js +93 -85
  8. package/dist/client/index.js.map +1 -1
  9. package/dist/codegen/generators/index.d.ts +19 -0
  10. package/dist/codegen/generators/index.js +1500 -0
  11. package/dist/codegen/generators/index.js.map +1 -0
  12. package/dist/codegen/index.d.ts +76 -60
  13. package/dist/codegen/index.js +1486 -736
  14. package/dist/codegen/index.js.map +1 -1
  15. package/dist/database-errors-BNNmLTJE.d.ts +86 -0
  16. package/dist/db/index.d.ts +844 -44
  17. package/dist/db/index.js +1262 -1309
  18. package/dist/db/index.js.map +1 -1
  19. package/dist/env/index.d.ts +508 -0
  20. package/dist/env/index.js +1106 -0
  21. package/dist/env/index.js.map +1 -0
  22. package/dist/error-handler-wjLL3v-a.d.ts +44 -0
  23. package/dist/errors/index.d.ts +136 -0
  24. package/dist/errors/index.js +172 -0
  25. package/dist/errors/index.js.map +1 -0
  26. package/dist/index-DHiAqhKv.d.ts +101 -0
  27. package/dist/index.d.ts +3 -374
  28. package/dist/index.js +2404 -2179
  29. package/dist/index.js.map +1 -1
  30. package/dist/logger/index.d.ts +94 -0
  31. package/dist/logger/index.js +774 -0
  32. package/dist/logger/index.js.map +1 -0
  33. package/dist/middleware/index.d.ts +33 -0
  34. package/dist/middleware/index.js +897 -0
  35. package/dist/middleware/index.js.map +1 -0
  36. package/dist/route/index.d.ts +21 -53
  37. package/dist/route/index.js +1238 -219
  38. package/dist/route/index.js.map +1 -1
  39. package/dist/server/index.d.ts +18 -0
  40. package/dist/server/index.js +2400 -2061
  41. package/dist/server/index.js.map +1 -1
  42. package/dist/types-DYueuoD6.d.ts +162 -0
  43. package/package.json +59 -15
  44. package/dist/auto-loader-C44TcLmM.d.ts +0 -125
  45. package/dist/bind-pssq1NRT.d.ts +0 -34
  46. package/dist/postgres-errors-CY_Es8EJ.d.ts +0 -1703
  47. package/dist/scripts/index.d.ts +0 -24
  48. package/dist/scripts/index.js +0 -1201
  49. package/dist/scripts/index.js.map +0 -1
  50. package/dist/scripts/templates/api-index.template.txt +0 -10
  51. package/dist/scripts/templates/api-tag.template.txt +0 -11
  52. package/dist/scripts/templates/contract.template.txt +0 -87
  53. package/dist/scripts/templates/entity-type.template.txt +0 -31
  54. package/dist/scripts/templates/entity.template.txt +0 -19
  55. package/dist/scripts/templates/index.template.txt +0 -10
  56. package/dist/scripts/templates/repository.template.txt +0 -37
  57. package/dist/scripts/templates/routes-id.template.txt +0 -59
  58. package/dist/scripts/templates/routes-index.template.txt +0 -44
  59. package/dist/types-SlzTr8ZO.d.ts +0 -143
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/errors/database-errors.ts","../../src/errors/http-errors.ts","../../src/errors/error-utils.ts"],"names":[],"mappings":";AAYO,IAAM,aAAA,GAAN,cAAgG,KAAA,CACvG;AAAA,EACoB,UAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EAEhB,WAAA,CACI,OAAA,EACA,UAAA,GAAqB,GAAA,EACrB,OAAA,EAEJ;AACI,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AACZ,IAAA,IAAA,CAAK,UAAA,GAAa,UAAA;AAClB,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,IAAA,CAAK,SAAA,uBAAgB,IAAA,EAAK;AAC1B,IAAA,KAAA,CAAM,iBAAA,CAAkB,IAAA,EAAM,IAAA,CAAK,WAAW,CAAA;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAA,GACA;AACI,IA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O,yBAAA;AAAA,EAChB;AACJ;;;AChMO,SAAS,gBAAgB,KAAA,EAChC;AACI,EAAA,OAAO,KAAA,YAAiB,aAAA;AAC5B;AAKO,SAAS,YAAY,KAAA,EAC5B;AACI,EAAA,OAAO,KAAA,YAAiB,SAAA;AAC5B;AAKO,SAAS,cAAc,KAAA,EAC9B;AACI,EAAA,OACI,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,YAAA,IAAgB,KAAA,IAChB,OAAQ,KAAA,CAAc,UAAA,KAAe,QAAA;AAE7C","file":"index.js","sourcesContent":["/**\n * Database Error Classes\n *\n * Type-safe error handling with custom error class hierarchy\n * Mapped to HTTP status codes for API responses\n */\n\n/**\n * Base Database Error\n *\n * Base class for all database-related errors\n */\nexport class DatabaseError<TDetails extends Record<string, unknown> = Record<string, unknown>> extends Error\n{\n public readonly statusCode: number;\n public readonly details?: TDetails;\n public readonly timestamp: Date;\n\n constructor(\n message: string,\n statusCode: number = 500,\n details?: TDetails\n )\n {\n super(message);\n this.name = 'DatabaseError';\n this.statusCode = statusCode;\n this.details = details;\n this.timestamp = new Date();\n Error.captureStackTrace(this, this.constructor);\n }\n\n /**\n * Serialize error for API response\n */\n toJSON()\n {\n return {\n name: this.name,\n message: this.message,\n statusCode: this.statusCode,\n details: this.details,\n timestamp: this.timestamp.toISOString()\n };\n }\n}\n\n/**\n * Connection Error (503 Service Unavailable)\n *\n * Database connection failure, connection pool exhaustion, etc.\n */\nexport class ConnectionError extends DatabaseError\n{\n constructor(message: string, details?: Record<string, any>)\n {\n super(message, 503, details);\n this.name = 'ConnectionError';\n }\n}\n\n/**\n * Query Error (500 Internal Server Error)\n *\n * SQL query execution failure, syntax errors, etc.\n */\nexport class QueryError extends DatabaseError\n{\n constructor(message: string, statusCode: number = 500, details?: Record<string, any>)\n {\n super(message, statusCode, details);\n this.name = 'QueryError';\n }\n}\n\n/**\n * Entity Not Found Error (404 Not Found)\n *\n * Database entity does not exist\n */\nexport class EntityNotFoundError extends QueryError\n{\n constructor(resource: string, id: string | number)\n {\n super(`${resource} with id ${id} not found`, 404, { resource, id });\n this.name = 'EntityNotFoundError';\n }\n}\n\n/**\n * Constraint Violation Error (400 Bad Request)\n *\n * Database constraint violation (NOT NULL, CHECK, FOREIGN KEY, etc.)\n * This is different from HTTP ValidationError which validates request input\n */\nexport class ConstraintViolationError extends QueryError\n{\n constructor(message: string, details?: Record<string, any>)\n {\n super(message, 400, details);\n this.name = 'ConstraintViolationError';\n }\n}\n\n/**\n * Transaction Error (500 Internal Server Error)\n *\n * Transaction start/commit/rollback failure\n */\nexport class TransactionError extends DatabaseError\n{\n constructor(message: string, statusCode: number = 500, details?: Record<string, any>)\n {\n super(message, statusCode, details);\n this.name = 'TransactionError';\n }\n}\n\n/**\n * Deadlock Error (409 Conflict)\n *\n * Database deadlock detected\n */\nexport class DeadlockError extends TransactionError\n{\n constructor(message: string, details?: Record<string, any>)\n {\n super(message, 409, details);\n this.name = 'DeadlockError';\n }\n}\n\n/**\n * Duplicate Entry Error (409 Conflict)\n *\n * Unique constraint violation (e.g., duplicate email)\n */\nexport class DuplicateEntryError extends QueryError\n{\n constructor(field: string, value: string | number)\n {\n super(`${field} '${value}' already exists`, 409, { field, value });\n this.name = 'DuplicateEntryError';\n }\n}","/**\n * HTTP Error Classes\n *\n * Standard HTTP error classes for API responses\n * Covers common HTTP status codes beyond database errors\n */\n\n/**\n * Base HTTP Error\n *\n * Base class for all HTTP-related errors\n */\nexport class HttpError<TDetails extends Record<string, unknown> = Record<string, unknown>> extends Error\n{\n public readonly statusCode: number;\n public readonly details?: TDetails;\n public readonly timestamp: Date;\n\n constructor(\n message: string,\n statusCode: number,\n details?: TDetails\n )\n {\n super(message);\n this.name = 'HttpError';\n this.statusCode = statusCode;\n this.details = details;\n this.timestamp = new Date();\n Error.captureStackTrace(this, this.constructor);\n }\n\n /**\n * Serialize error for API response\n */\n toJSON()\n {\n return {\n name: this.name,\n message: this.message,\n statusCode: this.statusCode,\n details: this.details,\n timestamp: this.timestamp.toISOString()\n };\n }\n}\n\n/**\n * Bad Request Error (400)\n *\n * Generic bad request - malformed syntax, invalid parameters, etc.\n */\nexport class BadRequestError extends HttpError\n{\n constructor(message: string = 'Bad request', details?: Record<string, any>)\n {\n super(message, 400, details);\n this.name = 'BadRequestError';\n }\n}\n\n/**\n * Validation Error (400)\n *\n * Input validation failure (request params, query, body)\n * Used by contract-based routing for automatic validation\n */\nexport class ValidationError extends HttpError\n{\n constructor(message: string, details?: Record<string, any>)\n {\n super(message, 400, details);\n this.name = 'ValidationError';\n }\n}\n\n/**\n * Unauthorized Error (401)\n *\n * Authentication required or authentication failed\n */\nexport class UnauthorizedError extends HttpError\n{\n constructor(message: string = 'Authentication required', details?: Record<string, any>)\n {\n super(message, 401, details);\n this.name = 'UnauthorizedError';\n }\n}\n\n/**\n * Forbidden Error (403)\n *\n * Authenticated but lacks permission to access resource\n */\nexport class ForbiddenError extends HttpError\n{\n constructor(message: string = 'Access forbidden', details?: Record<string, any>)\n {\n super(message, 403, details);\n this.name = 'ForbiddenError';\n }\n}\n\n/**\n * Not Found Error (404)\n *\n * Requested resource does not exist\n * Generic HTTP 404 error (for database-specific NotFoundError, see database-errors.ts)\n */\nexport class NotFoundError extends HttpError\n{\n constructor(message: string = 'Resource not found', details?: Record<string, any>)\n {\n super(message, 404, details);\n this.name = 'NotFoundError';\n }\n}\n\n/**\n * Conflict Error (409)\n *\n * Generic conflict - resource state conflict, concurrent modification, etc.\n * More general than DuplicateEntryError\n */\nexport class ConflictError extends HttpError\n{\n constructor(message: string = 'Resource conflict', details?: Record<string, any>)\n {\n super(message, 409, details);\n this.name = 'ConflictError';\n }\n}\n\n/**\n * Too Many Requests Error (429)\n *\n * Rate limit exceeded\n */\nexport class TooManyRequestsError extends HttpError\n{\n constructor(\n message: string = 'Too many requests',\n retryAfter?: number,\n details?: Record<string, any>\n )\n {\n const fullDetails = retryAfter\n ? { ...details, retryAfter }\n : details;\n\n super(message, 429, fullDetails);\n this.name = 'TooManyRequestsError';\n }\n}\n\n/**\n * Internal Server Error (500)\n *\n * Generic server error when no specific error type applies\n */\nexport class InternalServerError extends HttpError\n{\n constructor(message: string = 'Internal server error', details?: Record<string, any>)\n {\n super(message, 500, details);\n this.name = 'InternalServerError';\n }\n}\n\n/**\n * Unprocessable Entity Error (422)\n *\n * Request is well-formed but contains semantic errors\n */\nexport class UnprocessableEntityError extends HttpError\n{\n constructor(message: string = 'Unprocessable entity', details?: Record<string, any>)\n {\n super(message, 422, details);\n this.name = 'UnprocessableEntityError';\n }\n}\n\n/**\n * Service Unavailable Error (503)\n *\n * Service temporarily unavailable (maintenance, overload, etc.)\n */\nexport class ServiceUnavailableError extends HttpError\n{\n constructor(\n message: string = 'Service unavailable',\n retryAfter?: number,\n details?: Record<string, any>\n )\n {\n const fullDetails = retryAfter\n ? { ...details, retryAfter }\n : details;\n\n super(message, 503, fullDetails);\n this.name = 'ServiceUnavailableError';\n }\n}","/**\n * Error Utility Functions\n *\n * Generic error type checking utilities\n */\n\nimport { DatabaseError } from './database-errors.js';\nimport { HttpError } from './http-errors.js';\n\n/**\n * Check if error is a DatabaseError\n */\nexport function isDatabaseError(error: unknown): error is DatabaseError\n{\n return error instanceof DatabaseError;\n}\n\n/**\n * Check if error is an HttpError\n */\nexport function isHttpError(error: unknown): error is HttpError\n{\n return error instanceof HttpError;\n}\n\n/**\n * Check if error has a statusCode property\n */\nexport function hasStatusCode(error: unknown): error is { statusCode: number }\n{\n return (\n typeof error === 'object' &&\n error !== null &&\n 'statusCode' in error &&\n typeof (error as any).statusCode === 'number'\n );\n}\n"]}
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Generator Interface
3
+ *
4
+ * Defines the contract for code generators that can be orchestrated by the codegen system.
5
+ */
6
+ /**
7
+ * Generator execution trigger types
8
+ */
9
+ type GeneratorTrigger = 'watch' | 'manual' | 'build' | 'start';
10
+ interface GeneratorOptions {
11
+ /** Project root directory */
12
+ cwd: string;
13
+ /** Enable debug logging */
14
+ debug?: boolean;
15
+ /** Execution trigger information */
16
+ trigger?: {
17
+ /** How the generator was triggered */
18
+ type: GeneratorTrigger;
19
+ /** Changed file information (only for 'watch' trigger) */
20
+ changedFile?: {
21
+ path: string;
22
+ event: 'add' | 'change' | 'unlink';
23
+ };
24
+ };
25
+ /** Custom configuration options */
26
+ [key: string]: any;
27
+ }
28
+ interface Generator {
29
+ /** Unique generator name */
30
+ name: string;
31
+ /** File patterns to watch (glob patterns) */
32
+ watchPatterns: string[];
33
+ /**
34
+ * When this generator should run
35
+ *
36
+ * @default ['watch', 'manual', 'build']
37
+ *
38
+ * Examples:
39
+ * - ['watch', 'build']: Run during development and build (e.g., admin-nav-generator)
40
+ * - ['build', 'start']: Run during build and server start (e.g., db-migration)
41
+ * - ['watch', 'manual']: Run during development and manual CLI (e.g., contract-generator)
42
+ * - ['start']: Run only on server start (e.g., runtime config generator)
43
+ */
44
+ runOn?: GeneratorTrigger[];
45
+ /**
46
+ * Generate code
47
+ *
48
+ * Generator can implement incremental updates by checking `options.trigger.changedFile`.
49
+ * If incremental update is not possible, do full regeneration.
50
+ *
51
+ * @param options - Generator options with trigger context
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * async generate(options: GeneratorOptions): Promise<void>
56
+ * {
57
+ * // Check if incremental update is possible
58
+ * if (options.trigger?.changedFile)
59
+ * {
60
+ * const { path, event } = options.trigger.changedFile;
61
+ *
62
+ * if (canDoIncrementalUpdate(path, event))
63
+ * {
64
+ * await updateSingleFile(path);
65
+ * return;
66
+ * }
67
+ * }
68
+ *
69
+ * // Fallback: full regeneration
70
+ * await fullRegenerate();
71
+ * }
72
+ * ```
73
+ */
74
+ generate(options: GeneratorOptions): Promise<void>;
75
+ }
76
+
77
+ /**
78
+ * Contract Generator
79
+ *
80
+ * Generates type-safe API client from contract definitions
81
+ *
82
+ * Features:
83
+ * - Automatic scanning of contract files
84
+ * - Type-safe client generation with InferContract
85
+ * - Split output by resource for better code organization
86
+ * - Incremental updates when single files change (smart regeneration)
87
+ */
88
+
89
+ interface ContractGeneratorConfig {
90
+ /** Contracts directory (default: src/lib/contracts) */
91
+ contractsDir?: string;
92
+ /** Output directory (default: src/lib/api) */
93
+ outputPath?: string;
94
+ /** Base URL for API client */
95
+ baseUrl?: string;
96
+ /** When to run this generator (default: ['watch', 'manual', 'build']) */
97
+ runOn?: GeneratorTrigger[];
98
+ }
99
+ declare function createContractGenerator(config?: ContractGeneratorConfig): Generator;
100
+
101
+ export { type ContractGeneratorConfig as C, type Generator as G, type GeneratorTrigger as a, type GeneratorOptions as b, createContractGenerator as c };
package/dist/index.d.ts CHANGED
@@ -1,379 +1,8 @@
1
1
  export { AppFactory, ServerConfig, createServer, startServer } from './server/index.js';
2
- export { A as AutoRouteLoader, R as RouteInfo, a as RouteStats, l as loadRoutes } from './auto-loader-C44TcLmM.js';
3
- export { b as bind } from './bind-pssq1NRT.js';
4
- export { d as HttpMethod, I as InferContract, c as RouteContext, R as RouteContract, a as RouteHandler, i as isHttpMethod } from './types-SlzTr8ZO.js';
5
- import { K as DatabaseError } from './postgres-errors-CY_Es8EJ.js';
6
- export { a5 as ConnectionError, D as DbConnectionType, aa as DeadlockError, m as DrizzleConfigOptions, a4 as DrizzleTable, ab as DuplicateEntryError, Y as FilterCondition, V as FilterOperator, _ as FilterResult, X as FilterValue, Z as Filters, a7 as NotFoundError, y as Page, x as Pageable, a3 as PaginationMeta, a2 as PaginationParams, a6 as QueryError, n as Repository, t as RepositoryScope, a0 as SortCondition, $ as SortDirection, a1 as SortResult, G as TransactionContext, a9 as TransactionError, T as Transactional, I as TransactionalOptions, a8 as ValidationError, W as WrappedDb, O as applyPagination, L as buildFilters, M as buildSort, p as clearRepositoryCache, U as countTotal, S as createPaginationMeta, d as db, k as detectDialect, B as foreignKey, J as fromPostgresError, l as generateDrizzleConfigFile, a as getDb, j as getDrizzleConfig, g as getRawDb, o as getRepository, q as getRepositoryCacheSize, u as getScopedCacheSize, r as getScopedRepository, E as getTransaction, z as id, v as isInRepositoryScope, C as optionalForeignKey, N as orFilters, F as runWithTransaction, A as timestamps, w as withRepositoryScope } from './postgres-errors-CY_Es8EJ.js';
7
- import { Redis, Cluster } from 'ioredis';
8
- import { Context, Next } from 'hono';
2
+ export { H as HttpMethod, I as InferContract, R as RouteContext, a as RouteContract, b as RouteHandler, i as isHttpMethod } from './types-DYueuoD6.js';
3
+ import 'hono';
9
4
  import 'hono/cors';
10
5
  import '@hono/node-server';
11
6
  import 'hono/utils/http-status';
12
7
  import '@sinclair/typebox';
13
- import 'drizzle-orm/postgres-js';
14
- import 'drizzle-orm/pg-core';
15
- import 'postgres';
16
- import 'drizzle-orm/pg-core/query-builders/raw';
17
- import 'drizzle-orm';
18
-
19
- /**
20
- * Redis factory with automatic environment variable detection
21
- * Supports: Single, Master-Replica, Sentinel, Cluster
22
- */
23
-
24
- interface RedisClients {
25
- /** Primary Redis for writes (or both read/write if no replica) */
26
- write?: Redis | Cluster;
27
- /** Replica Redis for reads (optional, falls back to write) */
28
- read?: Redis | Cluster;
29
- }
30
- /**
31
- * Create Redis client(s) from environment variables
32
- *
33
- * Supported patterns (priority order):
34
- * 1. Single instance: REDIS_URL
35
- * 2. Master-Replica: REDIS_WRITE_URL + REDIS_READ_URL
36
- * 3. Sentinel: REDIS_SENTINEL_HOSTS + REDIS_MASTER_NAME
37
- * 4. Cluster: REDIS_CLUSTER_NODES
38
- *
39
- * @returns Redis client(s) or undefined if no configuration found
40
- *
41
- * @example
42
- * ```bash
43
- * # Single (most common)
44
- * REDIS_URL=redis://localhost:6379
45
- * REDIS_URL=rediss://secure.redis.com:6380 # TLS
46
- *
47
- * # Master-Replica
48
- * REDIS_WRITE_URL=redis://master:6379
49
- * REDIS_READ_URL=redis://replica:6379
50
- *
51
- * # Sentinel
52
- * REDIS_SENTINEL_HOSTS=sentinel1:26379,sentinel2:26379
53
- * REDIS_MASTER_NAME=mymaster
54
- * REDIS_PASSWORD=secret
55
- *
56
- * # Cluster
57
- * REDIS_CLUSTER_NODES=node1:6379,node2:6379,node3:6379
58
- * REDIS_PASSWORD=secret
59
- * ```
60
- */
61
- declare function createRedisFromEnv(): Promise<RedisClients>;
62
- /**
63
- * Create single Redis client (backward compatibility)
64
- * Only returns write instance
65
- */
66
- declare function createSingleRedisFromEnv(): Promise<Redis | Cluster | undefined>;
67
-
68
- /**
69
- * Global Redis instance manager
70
- * Provides singleton access to Redis across all modules
71
- * Supports Master-Replica pattern with separate read/write instances
72
- */
73
-
74
- /**
75
- * Get global Redis write instance
76
- *
77
- * @returns Redis write instance or undefined if not initialized
78
- *
79
- * @example
80
- * ```typescript
81
- * import { getRedis } from '@spfn/core/cache';
82
- *
83
- * const redis = getRedis();
84
- * if (redis) {
85
- * await redis.set('key', 'value');
86
- * }
87
- * ```
88
- */
89
- declare function getRedis(): Redis | Cluster | undefined;
90
- /**
91
- * Get global Redis read instance (falls back to write if no replica)
92
- *
93
- * @returns Redis read instance or write instance as fallback
94
- *
95
- * @example
96
- * ```typescript
97
- * import { getRedisRead } from '@spfn/core/cache';
98
- *
99
- * const redis = getRedisRead();
100
- * if (redis) {
101
- * const value = await redis.get('key');
102
- * }
103
- * ```
104
- */
105
- declare function getRedisRead(): Redis | Cluster | undefined;
106
- /**
107
- * Set global Redis instances (for testing or manual configuration)
108
- *
109
- * @param write - Redis write instance
110
- * @param read - Redis read instance (optional, defaults to write)
111
- *
112
- * @example
113
- * ```typescript
114
- * import { setRedis } from '@spfn/core/cache';
115
- * import Redis from 'ioredis';
116
- *
117
- * const write = new Redis('redis://master:6379');
118
- * const read = new Redis('redis://replica:6379');
119
- * setRedis(write, read);
120
- * ```
121
- */
122
- declare function setRedis(write: Redis | Cluster | undefined, read?: Redis | Cluster | undefined): void;
123
- /**
124
- * Initialize Redis from environment variables
125
- * Automatically called by startServer()
126
- *
127
- * Supported environment variables:
128
- * - REDIS_URL (single instance)
129
- * - REDIS_WRITE_URL + REDIS_READ_URL (master-replica)
130
- * - REDIS_SENTINEL_HOSTS + REDIS_MASTER_NAME (sentinel)
131
- * - REDIS_CLUSTER_NODES (cluster)
132
- * - REDIS_TLS_REJECT_UNAUTHORIZED (TLS config)
133
- *
134
- * @returns Object with write and read instances
135
- *
136
- * @example
137
- * ```typescript
138
- * import { initRedis } from '@spfn/core/cache';
139
- *
140
- * // Manual initialization (not needed if using startServer)
141
- * const { write, read } = await initRedis();
142
- * ```
143
- */
144
- declare function initRedis(): Promise<{
145
- write?: Redis | Cluster;
146
- read?: Redis | Cluster;
147
- }>;
148
- /**
149
- * Close all Redis connections and cleanup
150
- *
151
- * @example
152
- * ```typescript
153
- * import { closeRedis } from '@spfn/core/cache';
154
- *
155
- * // During graceful shutdown
156
- * await closeRedis();
157
- * ```
158
- */
159
- declare function closeRedis(): Promise<void>;
160
- /**
161
- * Get Redis connection info (for debugging)
162
- */
163
- declare function getRedisInfo(): {
164
- hasWrite: boolean;
165
- hasRead: boolean;
166
- isReplica: boolean;
167
- };
168
-
169
- /**
170
- * Logger Type Definitions
171
- *
172
- * 로깅 시스템 타입 정의
173
- *
174
- * ✅ 구현 완료:
175
- * - LogLevel 타입 정의
176
- * - LogMetadata 인터페이스
177
- * - Transport 인터페이스
178
- * - 환경별 설정 타입
179
- *
180
- * 🔗 관련 파일:
181
- * - src/logger/logger.ts (Logger 클래스)
182
- * - src/logger/transports/ (Transport 구현체)
183
- * - src/logger/config.ts (설정)
184
- */
185
- /**
186
- * 로그 레벨
187
- * debug < info < warn < error < fatal
188
- */
189
- type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'fatal';
190
-
191
- /**
192
- * Logger Adapter Interface
193
- *
194
- * Logger 구현을 추상화하는 Adapter 인터페이스
195
- * Pino, Winston, Custom 등 다양한 구현체로 교체 가능
196
- *
197
- * ✅ 구현 완료:
198
- * - LoggerAdapter 인터페이스 정의
199
- * - Child logger 지원
200
- * - Error + Context 지원
201
- *
202
- * 💡 향후 고려사항:
203
- * - Winston Adapter
204
- * - Bunyan Adapter
205
- *
206
- * 🔗 관련 파일:
207
- * - src/logger/adapters/pino.ts (Pino 구현)
208
- * - src/logger/adapters/custom.ts (Custom 구현)
209
- * - src/logger/index.ts (Adapter 선택)
210
- */
211
-
212
- /**
213
- * Logger Adapter 인터페이스
214
- *
215
- * 모든 Logger 구현체는 이 인터페이스를 구현해야 함
216
- */
217
- interface LoggerAdapter {
218
- /**
219
- * Child logger 생성
220
- */
221
- child(module: string): LoggerAdapter;
222
- /**
223
- * Debug 로그
224
- */
225
- debug(message: string, context?: Record<string, unknown>): void;
226
- /**
227
- * Info 로그
228
- */
229
- info(message: string, context?: Record<string, unknown>): void;
230
- /**
231
- * Warn 로그
232
- */
233
- warn(message: string, context?: Record<string, unknown>): void;
234
- warn(message: string, error: Error, context?: Record<string, unknown>): void;
235
- /**
236
- * Error 로그
237
- */
238
- error(message: string, context?: Record<string, unknown>): void;
239
- error(message: string, error: Error, context?: Record<string, unknown>): void;
240
- /**
241
- * Fatal 로그
242
- */
243
- fatal(message: string, context?: Record<string, unknown>): void;
244
- fatal(message: string, error: Error, context?: Record<string, unknown>): void;
245
- /**
246
- * 리소스 정리
247
- */
248
- close?(): Promise<void>;
249
- }
250
-
251
- /**
252
- * Logger Adapter Factory
253
- *
254
- * Adapter creation and initialization logic
255
- */
256
-
257
- /**
258
- * Singleton Logger instance
259
- */
260
- declare const logger: LoggerAdapter;
261
-
262
- /**
263
- * Request Logger Middleware
264
- *
265
- * Automatic API request/response logging middleware
266
- *
267
- * ✅ Features:
268
- * - Automatic request start/completion logging
269
- * - Response time measurement
270
- * - Automatic error logging
271
- * - Request ID generation (distributed tracing)
272
- * - Sensitive data masking
273
- * - Exclude path configuration (health checks, etc.)
274
- *
275
- * 💡 Benefits:
276
- * - Automatic monitoring of all API requests
277
- * - Identify performance bottlenecks
278
- * - Easy error tracking
279
- *
280
- * 💡 Usage:
281
- * ```typescript
282
- * import { RequestLogger } from '@spfn/core';
283
- *
284
- * app.use(RequestLogger());
285
- * ```
286
- *
287
- * 🔗 Related files:
288
- * - src/logger/ (Logger)
289
- * - src/index.ts (Export)
290
- */
291
-
292
- /**
293
- * Request Logger configuration
294
- */
295
- interface RequestLoggerConfig {
296
- /**
297
- * Paths to exclude from logging (health checks, etc.)
298
- */
299
- excludePaths?: string[];
300
- /**
301
- * Field names to mask for sensitive data
302
- */
303
- sensitiveFields?: string[];
304
- /**
305
- * Slow request threshold (ms)
306
- */
307
- slowRequestThreshold?: number;
308
- }
309
- /**
310
- * Mask sensitive data with circular reference handling
311
- *
312
- * Optimizations:
313
- * - Pre-computes lowercase fields to avoid repeated toLowerCase() calls
314
- * - Handles circular references with WeakSet
315
- */
316
- declare function maskSensitiveData(obj: any, sensitiveFields: string[], seen?: WeakSet<object>): any;
317
- /**
318
- * Request Logger middleware
319
- */
320
- declare function RequestLogger(config?: RequestLoggerConfig): (c: Context, next: Next) => Promise<void>;
321
-
322
- /**
323
- * Error Handler Middleware
324
- *
325
- * Generic middleware that converts errors with statusCode to HTTP responses
326
- *
327
- * ✅ Features:
328
- * - Convert any error with statusCode property to appropriate HTTP status codes
329
- * - Error logging (log level by status code)
330
- * - Environment-specific error response format (Production/Development)
331
- * - Stack trace inclusion (development only)
332
- * - Support for additional error details
333
- *
334
- * 💡 Design:
335
- * - Domain-independent (doesn't depend on specific error types)
336
- * - Works with any error that has a statusCode property
337
- * - Follows dependency inversion principle
338
- */
339
-
340
- /**
341
- * Error handler options
342
- */
343
- interface ErrorHandlerOptions {
344
- /**
345
- * Include stack trace in response
346
- * @default process.env.NODE_ENV !== 'production'
347
- */
348
- includeStack?: boolean;
349
- /**
350
- * Enable error logging
351
- * @default true
352
- */
353
- enableLogging?: boolean;
354
- }
355
- /**
356
- * Error handler middleware
357
- *
358
- * Used in Hono's onError hook
359
- *
360
- * @example
361
- * ```typescript
362
- * const app = new Hono();
363
- * app.onError(ErrorHandler());
364
- * ```
365
- */
366
- declare function ErrorHandler(options?: ErrorHandlerOptions): (err: Error, c: Context) => Response | Promise<Response>;
367
-
368
- /**
369
- * Error Utility Functions
370
- *
371
- * Generic error type checking utilities
372
- */
373
-
374
- /**
375
- * Check if error is a DatabaseError
376
- */
377
- declare function isDatabaseError(error: unknown): error is DatabaseError;
378
-
379
- export { DatabaseError, ErrorHandler, type ErrorHandlerOptions, type LogLevel, type LoggerAdapter, type RedisClients, RequestLogger, type RequestLoggerConfig, closeRedis, createRedisFromEnv, createSingleRedisFromEnv, getRedis, getRedisInfo, getRedisRead, initRedis, isDatabaseError, logger, maskSensitiveData, setRedis };
8
+ import './error-handler-wjLL3v-a.js';