@spfn/core 0.1.0-alpha.86 → 0.2.0-beta.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 (71) hide show
  1. package/README.md +1046 -384
  2. package/dist/boss-D-fGtVgM.d.ts +187 -0
  3. package/dist/cache/index.d.ts +13 -33
  4. package/dist/cache/index.js +14 -703
  5. package/dist/cache/index.js.map +1 -1
  6. package/dist/codegen/index.d.ts +167 -17
  7. package/dist/codegen/index.js +76 -1419
  8. package/dist/codegen/index.js.map +1 -1
  9. package/dist/config/index.d.ts +1191 -0
  10. package/dist/config/index.js +264 -0
  11. package/dist/config/index.js.map +1 -0
  12. package/dist/db/index.d.ts +728 -59
  13. package/dist/db/index.js +1028 -1225
  14. package/dist/db/index.js.map +1 -1
  15. package/dist/env/index.d.ts +579 -308
  16. package/dist/env/index.js +438 -930
  17. package/dist/env/index.js.map +1 -1
  18. package/dist/errors/index.d.ts +417 -29
  19. package/dist/errors/index.js +359 -98
  20. package/dist/errors/index.js.map +1 -1
  21. package/dist/event/index.d.ts +108 -0
  22. package/dist/event/index.js +122 -0
  23. package/dist/event/index.js.map +1 -0
  24. package/dist/job/index.d.ts +172 -0
  25. package/dist/job/index.js +361 -0
  26. package/dist/job/index.js.map +1 -0
  27. package/dist/logger/index.d.ts +20 -79
  28. package/dist/logger/index.js +82 -387
  29. package/dist/logger/index.js.map +1 -1
  30. package/dist/middleware/index.d.ts +2 -11
  31. package/dist/middleware/index.js +49 -703
  32. package/dist/middleware/index.js.map +1 -1
  33. package/dist/nextjs/index.d.ts +120 -0
  34. package/dist/nextjs/index.js +416 -0
  35. package/dist/nextjs/index.js.map +1 -0
  36. package/dist/{client/nextjs/index.d.ts → nextjs/server.d.ts} +288 -262
  37. package/dist/nextjs/server.js +568 -0
  38. package/dist/nextjs/server.js.map +1 -0
  39. package/dist/route/index.d.ts +667 -25
  40. package/dist/route/index.js +437 -1287
  41. package/dist/route/index.js.map +1 -1
  42. package/dist/route/types.d.ts +38 -0
  43. package/dist/route/types.js +3 -0
  44. package/dist/route/types.js.map +1 -0
  45. package/dist/server/index.d.ts +201 -67
  46. package/dist/server/index.js +921 -3182
  47. package/dist/server/index.js.map +1 -1
  48. package/dist/types-BGl4QL1w.d.ts +77 -0
  49. package/dist/types-DRG2XMTR.d.ts +157 -0
  50. package/package.json +56 -48
  51. package/dist/auto-loader-JFaZ9gON.d.ts +0 -80
  52. package/dist/client/index.d.ts +0 -358
  53. package/dist/client/index.js +0 -357
  54. package/dist/client/index.js.map +0 -1
  55. package/dist/client/nextjs/index.js +0 -371
  56. package/dist/client/nextjs/index.js.map +0 -1
  57. package/dist/codegen/generators/index.d.ts +0 -19
  58. package/dist/codegen/generators/index.js +0 -1404
  59. package/dist/codegen/generators/index.js.map +0 -1
  60. package/dist/database-errors-BNNmLTJE.d.ts +0 -86
  61. package/dist/events/index.d.ts +0 -183
  62. package/dist/events/index.js +0 -77
  63. package/dist/events/index.js.map +0 -1
  64. package/dist/index-DHiAqhKv.d.ts +0 -101
  65. package/dist/index.d.ts +0 -8
  66. package/dist/index.js +0 -3674
  67. package/dist/index.js.map +0 -1
  68. package/dist/types/index.d.ts +0 -121
  69. package/dist/types/index.js +0 -38
  70. package/dist/types/index.js.map +0 -1
  71. package/dist/types-BXibIEyj.d.ts +0 -60
@@ -0,0 +1,187 @@
1
+ import { TSchema } from '@sinclair/typebox';
2
+ import PgBoss from 'pg-boss';
3
+
4
+ /**
5
+ * Job System Types
6
+ *
7
+ * Type definitions for the pg-boss based job system
8
+ */
9
+
10
+ /**
11
+ * Job options passed to pg-boss
12
+ */
13
+ interface JobOptions {
14
+ /**
15
+ * Maximum retry attempts
16
+ * @default 3
17
+ */
18
+ retryLimit?: number;
19
+ /**
20
+ * Delay between retries in milliseconds
21
+ * @default 1000
22
+ */
23
+ retryDelay?: number;
24
+ /**
25
+ * Job expiration in seconds
26
+ * @default 300 (5 minutes)
27
+ */
28
+ expireInSeconds?: number;
29
+ /**
30
+ * Job priority (higher = more important)
31
+ * @default 0
32
+ */
33
+ priority?: number;
34
+ /**
35
+ * Singleton key - only one job with this key can exist
36
+ */
37
+ singletonKey?: string;
38
+ /**
39
+ * Keep completed jobs for this many seconds
40
+ * @default 604800 (7 days)
41
+ */
42
+ retentionSeconds?: number;
43
+ }
44
+ /**
45
+ * Send options for individual job dispatch
46
+ */
47
+ interface JobSendOptions {
48
+ /**
49
+ * Delay execution by this many seconds
50
+ */
51
+ startAfter?: number | Date;
52
+ /**
53
+ * Singleton key for this specific job instance
54
+ */
55
+ singletonKey?: string;
56
+ /**
57
+ * Priority override
58
+ */
59
+ priority?: number;
60
+ }
61
+ /**
62
+ * Job handler function type
63
+ */
64
+ type JobHandler<TInput> = TInput extends void ? () => Promise<void> : (input: TInput) => Promise<void>;
65
+ /**
66
+ * Job definition interface
67
+ */
68
+ interface JobDef<TInput = void> {
69
+ /**
70
+ * Unique job name
71
+ */
72
+ readonly name: string;
73
+ /**
74
+ * TypeBox input schema (optional)
75
+ */
76
+ readonly inputSchema?: TSchema;
77
+ /**
78
+ * Cron expression for scheduled jobs
79
+ */
80
+ readonly cronExpression?: string;
81
+ /**
82
+ * Run once on server start
83
+ */
84
+ readonly runOnce?: boolean;
85
+ /**
86
+ * Event name this job subscribes to
87
+ */
88
+ readonly subscribedEvent?: string;
89
+ /**
90
+ * Event definition this job subscribes to (internal use)
91
+ */
92
+ readonly _subscribedEventDef?: unknown;
93
+ /**
94
+ * Job options
95
+ */
96
+ readonly options?: JobOptions;
97
+ /**
98
+ * Job handler
99
+ */
100
+ readonly handler: JobHandler<TInput>;
101
+ /**
102
+ * Send job to queue (returns immediately, executes in background)
103
+ */
104
+ send: TInput extends void ? (options?: JobSendOptions) => Promise<string | null> : (input: TInput, options?: JobSendOptions) => Promise<string | null>;
105
+ /**
106
+ * Run job synchronously (for testing/debugging)
107
+ */
108
+ run: TInput extends void ? () => Promise<void> : (input: TInput) => Promise<void>;
109
+ /**
110
+ * Type inference helpers
111
+ */
112
+ _input: TInput;
113
+ }
114
+ /**
115
+ * Job router entry - can be a job or nested router
116
+ */
117
+ type JobRouterEntry = JobDef<any> | JobRouter<any>;
118
+ /**
119
+ * Job router interface
120
+ */
121
+ interface JobRouter<TJobs extends Record<string, JobRouterEntry> = Record<string, JobRouterEntry>> {
122
+ readonly jobs: TJobs;
123
+ readonly _jobs: TJobs;
124
+ }
125
+ /**
126
+ * Infer input type from JobDef
127
+ */
128
+ type InferJobInput<TJob> = TJob extends JobDef<infer TInput> ? TInput : never;
129
+
130
+ /**
131
+ * pg-boss Wrapper
132
+ *
133
+ * Manages pg-boss instance lifecycle
134
+ */
135
+
136
+ /**
137
+ * pg-boss configuration options
138
+ */
139
+ interface BossConfig {
140
+ /**
141
+ * PostgreSQL connection string
142
+ */
143
+ connectionString: string;
144
+ /**
145
+ * Schema name for pg-boss tables
146
+ * @default 'spfn_queue'
147
+ */
148
+ schema?: string;
149
+ /**
150
+ * Maintenance interval in seconds
151
+ * @default 120
152
+ */
153
+ maintenanceIntervalSeconds?: number;
154
+ /**
155
+ * Monitor state changes interval in seconds
156
+ * @default undefined (disabled)
157
+ */
158
+ monitorIntervalSeconds?: number;
159
+ /**
160
+ * Clear all pending/scheduled jobs on startup
161
+ * Useful for development mode
162
+ * @default false
163
+ */
164
+ clearOnStart?: boolean;
165
+ }
166
+ /**
167
+ * Initialize pg-boss with the given configuration
168
+ */
169
+ declare function initBoss(config: BossConfig): Promise<PgBoss>;
170
+ /**
171
+ * Get the current pg-boss instance
172
+ */
173
+ declare function getBoss(): PgBoss | null;
174
+ /**
175
+ * Stop pg-boss gracefully
176
+ */
177
+ declare function stopBoss(): Promise<void>;
178
+ /**
179
+ * Check if pg-boss is initialized and running
180
+ */
181
+ declare function isBossRunning(): boolean;
182
+ /**
183
+ * Check if jobs should be cleared on start
184
+ */
185
+ declare function shouldClearOnStart(): boolean;
186
+
187
+ export { type BossConfig as B, type InferJobInput as I, type JobRouter as J, type JobOptions as a, type JobHandler as b, type JobDef as c, type JobRouterEntry as d, type JobSendOptions as e, isBossRunning as f, getBoss as g, shouldClearOnStart as h, initBoss as i, stopBoss as s };
@@ -2,10 +2,6 @@ import { Redis, Cluster } from 'ioredis';
2
2
 
3
3
  /**
4
4
  * Cache factory with automatic environment variable detection
5
- * Supports Valkey and Redis with multiple deployment patterns
6
- *
7
- * Valkey is a Redis fork (7.2.4 base) with 100% protocol compatibility
8
- * https://valkey.io
9
5
  */
10
6
 
11
7
  interface CacheClients {
@@ -18,35 +14,31 @@ interface CacheClients {
18
14
  * Create cache client(s) from environment variables
19
15
  *
20
16
  * Supported patterns (priority order):
21
- * 1. Single instance: VALKEY_URL or CACHE_URL or REDIS_URL
22
- * 2. Master-Replica: VALKEY_WRITE_URL + VALKEY_READ_URL (or CACHE_*, REDIS_*)
23
- * 3. Sentinel: VALKEY_SENTINEL_HOSTS + VALKEY_MASTER_NAME (or REDIS_*)
24
- * 4. Cluster: VALKEY_CLUSTER_NODES (or REDIS_*)
17
+ * 1. Single instance: CACHE_URL
18
+ * 2. Master-Replica: CACHE_WRITE_URL + CACHE_READ_URL
19
+ * 3. Sentinel: CACHE_SENTINEL_HOSTS + CACHE_MASTER_NAME
20
+ * 4. Cluster: CACHE_CLUSTER_NODES
25
21
  *
26
22
  * @returns Cache client(s) or undefined if no configuration found
27
23
  *
28
24
  * @example
29
25
  * ```bash
30
26
  * # Single (most common)
31
- * VALKEY_URL=valkey://localhost:6379
32
27
  * CACHE_URL=redis://localhost:6379
33
- *
34
- * # Legacy (still supported)
35
- * REDIS_URL=redis://localhost:6379
36
- * REDIS_URL=rediss://secure.redis.com:6380 # TLS
28
+ * CACHE_URL=rediss://secure.cache.com:6380 # TLS
37
29
  *
38
30
  * # Master-Replica
39
- * VALKEY_WRITE_URL=valkey://master:6379
40
- * VALKEY_READ_URL=valkey://replica:6379
31
+ * CACHE_WRITE_URL=redis://master:6379
32
+ * CACHE_READ_URL=redis://replica:6379
41
33
  *
42
34
  * # Sentinel
43
- * VALKEY_SENTINEL_HOSTS=sentinel1:26379,sentinel2:26379
44
- * VALKEY_MASTER_NAME=mymaster
45
- * VALKEY_PASSWORD=secret
35
+ * CACHE_SENTINEL_HOSTS=sentinel1:26379,sentinel2:26379
36
+ * CACHE_MASTER_NAME=mymaster
37
+ * CACHE_PASSWORD=secret
46
38
  *
47
39
  * # Cluster
48
- * VALKEY_CLUSTER_NODES=node1:6379,node2:6379,node3:6379
49
- * VALKEY_PASSWORD=secret
40
+ * CACHE_CLUSTER_NODES=node1:6379,node2:6379,node3:6379
41
+ * CACHE_PASSWORD=secret
50
42
  * ```
51
43
  */
52
44
  declare function createCacheFromEnv(): Promise<CacheClients>;
@@ -195,17 +187,5 @@ declare function getCacheInfo(): {
195
187
  isReplica: boolean;
196
188
  disabled: boolean;
197
189
  };
198
- /** @deprecated Use getCache() instead */
199
- declare const getRedis: typeof getCache;
200
- /** @deprecated Use getCacheRead() instead */
201
- declare const getRedisRead: typeof getCacheRead;
202
- /** @deprecated Use setCache() instead */
203
- declare const setRedis: typeof setCache;
204
- /** @deprecated Use initCache() instead */
205
- declare const initRedis: typeof initCache;
206
- /** @deprecated Use closeCache() instead */
207
- declare const closeRedis: typeof closeCache;
208
- /** @deprecated Use getCacheInfo() instead */
209
- declare const getRedisInfo: typeof getCacheInfo;
210
190
 
211
- export { type CacheClients, type CacheClients as RedisClients, closeCache, closeRedis, createCacheFromEnv, createCacheFromEnv as createRedisFromEnv, createSingleCacheFromEnv, createSingleCacheFromEnv as createSingleRedisFromEnv, getCache, getCacheInfo, getCacheRead, getRedis, getRedisInfo, getRedisRead, initCache, initRedis, isCacheDisabled, setCache, setRedis };
191
+ export { type CacheClients, type CacheClients as RedisClients, closeCache, createCacheFromEnv, createCacheFromEnv as createRedisFromEnv, createSingleCacheFromEnv, createSingleCacheFromEnv as createSingleRedisFromEnv, getCache, getCacheInfo, getCacheRead, initCache, isCacheDisabled, setCache };