@spfn/core 0.1.0-alpha.88 → 0.2.0-beta.10
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.
- package/README.md +298 -466
- package/dist/boss-DI1r4kTS.d.ts +244 -0
- package/dist/cache/index.d.ts +13 -33
- package/dist/cache/index.js +14 -703
- package/dist/cache/index.js.map +1 -1
- package/dist/codegen/index.d.ts +214 -17
- package/dist/codegen/index.js +231 -1420
- package/dist/codegen/index.js.map +1 -1
- package/dist/config/index.d.ts +1227 -0
- package/dist/config/index.js +273 -0
- package/dist/config/index.js.map +1 -0
- package/dist/db/index.d.ts +741 -59
- package/dist/db/index.js +1063 -1226
- package/dist/db/index.js.map +1 -1
- package/dist/env/index.d.ts +658 -308
- package/dist/env/index.js +503 -928
- package/dist/env/index.js.map +1 -1
- package/dist/env/loader.d.ts +87 -0
- package/dist/env/loader.js +70 -0
- package/dist/env/loader.js.map +1 -0
- package/dist/errors/index.d.ts +417 -29
- package/dist/errors/index.js +359 -98
- package/dist/errors/index.js.map +1 -1
- package/dist/event/index.d.ts +41 -0
- package/dist/event/index.js +131 -0
- package/dist/event/index.js.map +1 -0
- package/dist/event/sse/client.d.ts +82 -0
- package/dist/event/sse/client.js +115 -0
- package/dist/event/sse/client.js.map +1 -0
- package/dist/event/sse/index.d.ts +40 -0
- package/dist/event/sse/index.js +92 -0
- package/dist/event/sse/index.js.map +1 -0
- package/dist/job/index.d.ts +218 -0
- package/dist/job/index.js +410 -0
- package/dist/job/index.js.map +1 -0
- package/dist/logger/index.d.ts +20 -79
- package/dist/logger/index.js +82 -387
- package/dist/logger/index.js.map +1 -1
- package/dist/middleware/index.d.ts +102 -20
- package/dist/middleware/index.js +51 -705
- package/dist/middleware/index.js.map +1 -1
- package/dist/nextjs/index.d.ts +120 -0
- package/dist/nextjs/index.js +448 -0
- package/dist/nextjs/index.js.map +1 -0
- package/dist/{client/nextjs/index.d.ts → nextjs/server.d.ts} +335 -262
- package/dist/nextjs/server.js +637 -0
- package/dist/nextjs/server.js.map +1 -0
- package/dist/route/index.d.ts +879 -25
- package/dist/route/index.js +697 -1271
- package/dist/route/index.js.map +1 -1
- package/dist/route/types.d.ts +9 -0
- package/dist/route/types.js +3 -0
- package/dist/route/types.js.map +1 -0
- package/dist/router-Di7ENoah.d.ts +151 -0
- package/dist/server/index.d.ts +345 -64
- package/dist/server/index.js +1174 -3233
- package/dist/server/index.js.map +1 -1
- package/dist/types-B-e_f2dQ.d.ts +121 -0
- package/dist/types-BGl4QL1w.d.ts +77 -0
- package/dist/types-BOPTApC2.d.ts +245 -0
- package/docs/cache.md +133 -0
- package/docs/codegen.md +74 -0
- package/docs/database.md +346 -0
- package/docs/entity.md +539 -0
- package/docs/env.md +477 -0
- package/docs/errors.md +319 -0
- package/docs/event.md +116 -0
- package/docs/file-upload.md +717 -0
- package/docs/job.md +131 -0
- package/docs/logger.md +108 -0
- package/docs/middleware.md +337 -0
- package/docs/nextjs.md +241 -0
- package/docs/repository.md +496 -0
- package/docs/route.md +497 -0
- package/docs/server.md +307 -0
- package/package.json +68 -48
- package/dist/auto-loader-JFaZ9gON.d.ts +0 -80
- package/dist/client/index.d.ts +0 -358
- package/dist/client/index.js +0 -357
- package/dist/client/index.js.map +0 -1
- package/dist/client/nextjs/index.js +0 -371
- package/dist/client/nextjs/index.js.map +0 -1
- package/dist/codegen/generators/index.d.ts +0 -19
- package/dist/codegen/generators/index.js +0 -1404
- package/dist/codegen/generators/index.js.map +0 -1
- package/dist/database-errors-BNNmLTJE.d.ts +0 -86
- package/dist/events/index.d.ts +0 -183
- package/dist/events/index.js +0 -77
- package/dist/events/index.js.map +0 -1
- package/dist/index-DHiAqhKv.d.ts +0 -101
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -3674
- package/dist/index.js.map +0 -1
- package/dist/types/index.d.ts +0 -121
- package/dist/types/index.js +0 -38
- package/dist/types/index.js.map +0 -1
- package/dist/types-BXibIEyj.d.ts +0 -60
|
@@ -0,0 +1,244 @@
|
|
|
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, TOutput = void> = TInput extends void ? () => Promise<TOutput> : (input: TInput) => Promise<TOutput>;
|
|
65
|
+
/**
|
|
66
|
+
* Compensate handler function type (for rollback)
|
|
67
|
+
*/
|
|
68
|
+
type CompensateHandler<TInput, TOutput> = (input: TInput, output: TOutput) => Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Job definition interface
|
|
71
|
+
*/
|
|
72
|
+
interface JobDef<TInput = void, TOutput = void> {
|
|
73
|
+
/**
|
|
74
|
+
* Unique job name
|
|
75
|
+
*/
|
|
76
|
+
readonly name: string;
|
|
77
|
+
/**
|
|
78
|
+
* TypeBox input schema (optional)
|
|
79
|
+
*/
|
|
80
|
+
readonly inputSchema?: TSchema;
|
|
81
|
+
/**
|
|
82
|
+
* TypeBox output schema (optional, for workflow integration)
|
|
83
|
+
*/
|
|
84
|
+
readonly outputSchema?: TSchema;
|
|
85
|
+
/**
|
|
86
|
+
* Cron expression for scheduled jobs
|
|
87
|
+
*/
|
|
88
|
+
readonly cronExpression?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Run once on server start
|
|
91
|
+
*/
|
|
92
|
+
readonly runOnce?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Event name this job subscribes to
|
|
95
|
+
*/
|
|
96
|
+
readonly subscribedEvent?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Event definition this job subscribes to (internal use)
|
|
99
|
+
*/
|
|
100
|
+
readonly _subscribedEventDef?: unknown;
|
|
101
|
+
/**
|
|
102
|
+
* Job options
|
|
103
|
+
*/
|
|
104
|
+
readonly options?: JobOptions;
|
|
105
|
+
/**
|
|
106
|
+
* Job handler
|
|
107
|
+
*/
|
|
108
|
+
readonly handler: JobHandler<TInput, TOutput>;
|
|
109
|
+
/**
|
|
110
|
+
* Compensate handler for rollback (optional, for workflow integration)
|
|
111
|
+
*/
|
|
112
|
+
readonly compensate?: CompensateHandler<TInput, TOutput>;
|
|
113
|
+
/**
|
|
114
|
+
* Send job to queue (returns immediately, executes in background)
|
|
115
|
+
*/
|
|
116
|
+
send: TInput extends void ? (options?: JobSendOptions) => Promise<string | null> : (input: TInput, options?: JobSendOptions) => Promise<string | null>;
|
|
117
|
+
/**
|
|
118
|
+
* Run job synchronously (for testing/debugging)
|
|
119
|
+
*/
|
|
120
|
+
run: TInput extends void ? () => Promise<TOutput> : (input: TInput) => Promise<TOutput>;
|
|
121
|
+
/**
|
|
122
|
+
* Type inference helpers
|
|
123
|
+
*/
|
|
124
|
+
_input: TInput;
|
|
125
|
+
_output: TOutput;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Job router entry - can be a job or nested router
|
|
129
|
+
*/
|
|
130
|
+
type JobRouterEntry = JobDef<any, any> | JobRouter<any>;
|
|
131
|
+
/**
|
|
132
|
+
* Job router interface
|
|
133
|
+
*/
|
|
134
|
+
interface JobRouter<TJobs extends Record<string, JobRouterEntry> = Record<string, JobRouterEntry>> {
|
|
135
|
+
readonly jobs: TJobs;
|
|
136
|
+
readonly _jobs: TJobs;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Infer input type from JobDef
|
|
140
|
+
*/
|
|
141
|
+
type InferJobInput<TJob> = TJob extends JobDef<infer TInput, any> ? TInput : never;
|
|
142
|
+
/**
|
|
143
|
+
* Infer output type from JobDef
|
|
144
|
+
*/
|
|
145
|
+
type InferJobOutput<TJob> = TJob extends JobDef<any, infer TOutput> ? TOutput : never;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* pg-boss Wrapper
|
|
149
|
+
*
|
|
150
|
+
* Manages pg-boss instance lifecycle
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Options for pg-boss initialization
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* await initBoss({
|
|
159
|
+
* connectionString: process.env.DATABASE_URL,
|
|
160
|
+
* schema: 'spfn_queue',
|
|
161
|
+
* clearOnStart: process.env.NODE_ENV === 'development',
|
|
162
|
+
* });
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
interface BossOptions {
|
|
166
|
+
/**
|
|
167
|
+
* PostgreSQL connection string
|
|
168
|
+
*
|
|
169
|
+
* @example 'postgresql://user:password@localhost:5432/mydb'
|
|
170
|
+
*/
|
|
171
|
+
connectionString: string;
|
|
172
|
+
/**
|
|
173
|
+
* Schema name for pg-boss tables
|
|
174
|
+
*
|
|
175
|
+
* pg-boss creates its own tables in this schema.
|
|
176
|
+
*
|
|
177
|
+
* @default 'spfn_queue'
|
|
178
|
+
*/
|
|
179
|
+
schema?: string;
|
|
180
|
+
/**
|
|
181
|
+
* Maintenance interval in seconds
|
|
182
|
+
*
|
|
183
|
+
* pg-boss runs maintenance tasks (cleanup, archiving) at this interval.
|
|
184
|
+
*
|
|
185
|
+
* @default 120
|
|
186
|
+
*/
|
|
187
|
+
maintenanceIntervalSeconds?: number;
|
|
188
|
+
/**
|
|
189
|
+
* Monitor state changes interval in seconds
|
|
190
|
+
*
|
|
191
|
+
* When set, pg-boss emits state change events at this interval.
|
|
192
|
+
*
|
|
193
|
+
* @default undefined (disabled)
|
|
194
|
+
*/
|
|
195
|
+
monitorIntervalSeconds?: number;
|
|
196
|
+
/**
|
|
197
|
+
* Clear all pending/scheduled jobs on startup
|
|
198
|
+
*
|
|
199
|
+
* Useful for development mode to start with a clean queue.
|
|
200
|
+
* Should be false in production.
|
|
201
|
+
*
|
|
202
|
+
* @default false
|
|
203
|
+
*/
|
|
204
|
+
clearOnStart?: boolean;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* @deprecated Use BossOptions instead
|
|
208
|
+
*/
|
|
209
|
+
type BossConfig = BossOptions;
|
|
210
|
+
/**
|
|
211
|
+
* Initialize pg-boss with the given configuration
|
|
212
|
+
*
|
|
213
|
+
* Must be called before registerJobs(). Typically handled by defineServerConfig().
|
|
214
|
+
*
|
|
215
|
+
* @param options - pg-boss configuration options
|
|
216
|
+
* @returns The pg-boss instance
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const boss = await initBoss({
|
|
221
|
+
* connectionString: process.env.DATABASE_URL!,
|
|
222
|
+
* schema: 'spfn_queue',
|
|
223
|
+
* });
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
declare function initBoss(options: BossOptions): Promise<PgBoss>;
|
|
227
|
+
/**
|
|
228
|
+
* Get the current pg-boss instance
|
|
229
|
+
*/
|
|
230
|
+
declare function getBoss(): PgBoss | null;
|
|
231
|
+
/**
|
|
232
|
+
* Stop pg-boss gracefully
|
|
233
|
+
*/
|
|
234
|
+
declare function stopBoss(): Promise<void>;
|
|
235
|
+
/**
|
|
236
|
+
* Check if pg-boss is initialized and running
|
|
237
|
+
*/
|
|
238
|
+
declare function isBossRunning(): boolean;
|
|
239
|
+
/**
|
|
240
|
+
* Check if jobs should be cleared on start
|
|
241
|
+
*/
|
|
242
|
+
declare function shouldClearOnStart(): boolean;
|
|
243
|
+
|
|
244
|
+
export { type BossOptions as B, type CompensateHandler as C, 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, type InferJobOutput as f, getBoss as g, isBossRunning as h, initBoss as i, shouldClearOnStart as j, type BossConfig as k, stopBoss as s };
|
package/dist/cache/index.d.ts
CHANGED
|
@@ -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:
|
|
22
|
-
* 2. Master-Replica:
|
|
23
|
-
* 3. Sentinel:
|
|
24
|
-
* 4. Cluster:
|
|
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
|
-
*
|
|
40
|
-
*
|
|
31
|
+
* CACHE_WRITE_URL=redis://master:6379
|
|
32
|
+
* CACHE_READ_URL=redis://replica:6379
|
|
41
33
|
*
|
|
42
34
|
* # Sentinel
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
35
|
+
* CACHE_SENTINEL_HOSTS=sentinel1:26379,sentinel2:26379
|
|
36
|
+
* CACHE_MASTER_NAME=mymaster
|
|
37
|
+
* CACHE_PASSWORD=secret
|
|
46
38
|
*
|
|
47
39
|
* # Cluster
|
|
48
|
-
*
|
|
49
|
-
*
|
|
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,
|
|
191
|
+
export { type CacheClients, type CacheClients as RedisClients, closeCache, createCacheFromEnv, createCacheFromEnv as createRedisFromEnv, createSingleCacheFromEnv, createSingleCacheFromEnv as createSingleRedisFromEnv, getCache, getCacheInfo, getCacheRead, initCache, isCacheDisabled, setCache };
|