@getvision/server 0.4.1 → 0.4.2-107ad21-develop
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 +20 -5
- package/package.json +2 -2
- package/src/event-bus.ts +18 -2
- package/src/vision-app.ts +7 -0
package/README.md
CHANGED
|
@@ -87,7 +87,7 @@ async (data, c) => {
|
|
|
87
87
|
Zod validation for inputs and outputs:
|
|
88
88
|
|
|
89
89
|
```typescript
|
|
90
|
-
.endpoint('POST', '/users', {
|
|
90
|
+
app.endpoint('POST', '/users', {
|
|
91
91
|
input: z.object({
|
|
92
92
|
name: z.string().min(1),
|
|
93
93
|
email: z.string().email()
|
|
@@ -107,11 +107,10 @@ BullMQ event bus is built-in:
|
|
|
107
107
|
|
|
108
108
|
```typescript
|
|
109
109
|
// Subscribe to events
|
|
110
|
-
.on('user/created', async (event) => {
|
|
110
|
+
app.on('user/created', async (event) => {
|
|
111
111
|
await sendWelcomeEmail(event.data.email)
|
|
112
112
|
})
|
|
113
|
-
|
|
114
|
-
// Schedule cron jobs
|
|
113
|
+
// Schedule cron jobs
|
|
115
114
|
.cron('0 0 * * *', async () => {
|
|
116
115
|
await cleanupInactiveUsers()
|
|
117
116
|
})
|
|
@@ -205,7 +204,23 @@ const app = new Vision({
|
|
|
205
204
|
logging: true // Console logging
|
|
206
205
|
},
|
|
207
206
|
pubsub: {
|
|
208
|
-
devMode: true
|
|
207
|
+
devMode: true, // In-memory BullMQ for local dev
|
|
208
|
+
// BullMQ options
|
|
209
|
+
queue: {
|
|
210
|
+
defaultJobOptions: {
|
|
211
|
+
lockDuration: 300000, // 5 minutes
|
|
212
|
+
stalledInterval: 300000,
|
|
213
|
+
maxStalledCount: 1,
|
|
214
|
+
removeOnComplete: 1000,
|
|
215
|
+
removeOnFail: 1000,
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
worker: {
|
|
219
|
+
lockDuration: 300000,
|
|
220
|
+
},
|
|
221
|
+
queueEvents: {
|
|
222
|
+
stalledInterval: 300000,
|
|
223
|
+
}
|
|
209
224
|
}
|
|
210
225
|
})
|
|
211
226
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getvision/server",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2-107ad21-develop",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Vision Server - Meta-framework with built-in observability, pub/sub, and type-safe APIs",
|
|
6
6
|
"exports": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@getvision/core": "0.1.
|
|
16
|
+
"@getvision/core": "0.1.1",
|
|
17
17
|
"@hono/node-server": "^1.19.6",
|
|
18
18
|
"bullmq": "^5.62.0",
|
|
19
19
|
"hono-rate-limiter": "^0.4.2",
|
package/src/event-bus.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Queue, Worker, QueueEvents } from 'bullmq'
|
|
2
|
-
import type {
|
|
2
|
+
import type { QueueEventsOptions, QueueOptions, WorkerOptions } from 'bullmq'
|
|
3
3
|
import { eventRegistry } from './event-registry'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -11,6 +11,9 @@ export interface EventBusConfig {
|
|
|
11
11
|
port?: number
|
|
12
12
|
password?: string
|
|
13
13
|
}
|
|
14
|
+
queue?: Omit<QueueOptions, 'connection'>
|
|
15
|
+
worker?: Omit<WorkerOptions, 'connection'>
|
|
16
|
+
queueEvents?: Omit<QueueEventsOptions, 'connection'>
|
|
14
17
|
/**
|
|
15
18
|
* Default BullMQ worker concurrency (per event). Per-handler options override this.
|
|
16
19
|
*/
|
|
@@ -77,6 +80,9 @@ export class EventBus {
|
|
|
77
80
|
devMode: resolvedDevMode,
|
|
78
81
|
redis: mergedRedis,
|
|
79
82
|
workerConcurrency: config.workerConcurrency,
|
|
83
|
+
queue: config.queue,
|
|
84
|
+
worker: config.worker,
|
|
85
|
+
queueEvents: config.queueEvents,
|
|
80
86
|
}
|
|
81
87
|
}
|
|
82
88
|
|
|
@@ -96,6 +102,7 @@ export class EventBus {
|
|
|
96
102
|
port: 6379,
|
|
97
103
|
}
|
|
98
104
|
queue = new Queue(eventName, {
|
|
105
|
+
...(this.config.queue || {}),
|
|
99
106
|
connection,
|
|
100
107
|
})
|
|
101
108
|
this.queues.set(eventName, queue)
|
|
@@ -223,8 +230,13 @@ export class EventBus {
|
|
|
223
230
|
}
|
|
224
231
|
},
|
|
225
232
|
{
|
|
233
|
+
...(this.config.worker || {}),
|
|
226
234
|
connection,
|
|
227
|
-
concurrency:
|
|
235
|
+
concurrency:
|
|
236
|
+
options?.concurrency ??
|
|
237
|
+
this.config.workerConcurrency ??
|
|
238
|
+
this.config.worker?.concurrency ??
|
|
239
|
+
1,
|
|
228
240
|
}
|
|
229
241
|
)
|
|
230
242
|
|
|
@@ -237,6 +249,7 @@ export class EventBus {
|
|
|
237
249
|
port: 6379,
|
|
238
250
|
}
|
|
239
251
|
const queueEvents = new QueueEvents(eventName, {
|
|
252
|
+
...(this.config.queueEvents || {}),
|
|
240
253
|
connection,
|
|
241
254
|
})
|
|
242
255
|
|
|
@@ -301,7 +314,9 @@ export class EventBus {
|
|
|
301
314
|
}
|
|
302
315
|
},
|
|
303
316
|
{
|
|
317
|
+
...(this.config.worker || {}),
|
|
304
318
|
connection,
|
|
319
|
+
concurrency: this.config.worker?.concurrency ?? 1,
|
|
305
320
|
}
|
|
306
321
|
)
|
|
307
322
|
|
|
@@ -310,6 +325,7 @@ export class EventBus {
|
|
|
310
325
|
// Listen to cron job events
|
|
311
326
|
if (!this.queueEvents.has(cronName)) {
|
|
312
327
|
const queueEvents = new QueueEvents(cronName, {
|
|
328
|
+
...(this.config.queueEvents || {}),
|
|
313
329
|
connection,
|
|
314
330
|
})
|
|
315
331
|
|
package/src/vision-app.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { ServiceBuilder } from './service'
|
|
|
9
9
|
import { EventBus } from './event-bus'
|
|
10
10
|
import { eventRegistry } from './event-registry'
|
|
11
11
|
import type { serve as honoServe } from '@hono/node-server'
|
|
12
|
+
import type { QueueEventsOptions, QueueOptions, WorkerOptions } from "bullmq";
|
|
12
13
|
|
|
13
14
|
export interface VisionALSContext {
|
|
14
15
|
vision: VisionCore
|
|
@@ -130,6 +131,9 @@ export interface VisionConfig {
|
|
|
130
131
|
* Default BullMQ worker concurrency for all handlers (overridable per handler)
|
|
131
132
|
*/
|
|
132
133
|
workerConcurrency?: number
|
|
134
|
+
queue?: Omit<QueueOptions, 'connection'>
|
|
135
|
+
worker?: Omit<WorkerOptions, 'connection'>
|
|
136
|
+
queueEvents?: Omit<QueueEventsOptions, 'connection'>
|
|
133
137
|
}
|
|
134
138
|
}
|
|
135
139
|
|
|
@@ -258,6 +262,9 @@ export class Vision<
|
|
|
258
262
|
redis: this.config.pubsub?.redis,
|
|
259
263
|
devMode: this.config.pubsub?.devMode,
|
|
260
264
|
workerConcurrency: this.config.pubsub?.workerConcurrency,
|
|
265
|
+
queue: this.config.pubsub?.queue,
|
|
266
|
+
worker: this.config.pubsub?.worker,
|
|
267
|
+
queueEvents: this.config.pubsub?.queueEvents,
|
|
261
268
|
})
|
|
262
269
|
|
|
263
270
|
// Register JSON-RPC methods for events/cron
|