@getvision/server 0.2.1 → 0.2.2
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/CHANGELOG.md +9 -0
- package/package.json +2 -2
- package/src/index.ts +4 -0
- package/src/router.ts +6 -1
- package/src/service.ts +4 -2
- package/src/vision-app.ts +13 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @getvision/server
|
|
2
2
|
|
|
3
|
+
## 0.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 94b139b: Bump @hono/node-server to 1.19.6
|
|
8
|
+
- da87b81: Update router to pass EventBus from root app to file-based sub-apps
|
|
9
|
+
- Updated dependencies [a88ad97]
|
|
10
|
+
- @getvision/core@0.0.4
|
|
11
|
+
|
|
3
12
|
## 0.2.1
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getvision/server",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Vision Server - Meta-framework with built-in observability, pub/sub, and type-safe APIs",
|
|
6
6
|
"exports": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@getvision/core": "0.0.3",
|
|
17
|
-
"@hono/node-server": "^1.19.
|
|
17
|
+
"@hono/node-server": "^1.19.6",
|
|
18
18
|
"bullmq": "^5.62.0",
|
|
19
19
|
"hono-rate-limiter": "^0.4.2",
|
|
20
20
|
"hono": "^4.10.4",
|
package/src/index.ts
CHANGED
|
@@ -51,6 +51,10 @@ export type { VisionConfig } from './vision-app'
|
|
|
51
51
|
// Service builder (usually accessed via app.service())
|
|
52
52
|
export { ServiceBuilder } from './service'
|
|
53
53
|
|
|
54
|
+
// Event bus
|
|
55
|
+
export { EventBus } from './event-bus'
|
|
56
|
+
export type { EventBusConfig } from './event-bus'
|
|
57
|
+
|
|
54
58
|
// Types
|
|
55
59
|
export type {
|
|
56
60
|
EndpointConfig,
|
package/src/router.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Hono } from 'hono'
|
|
|
2
2
|
import { readdirSync, statSync } from 'fs'
|
|
3
3
|
import { join, resolve, relative, sep } from 'path'
|
|
4
4
|
import { pathToFileURL } from 'url'
|
|
5
|
+
import type { EventBus } from './event-bus'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Autoload Vision/Hono sub-apps from a directory structure like app/routes/.../index.ts
|
|
@@ -12,7 +13,7 @@ import { pathToFileURL } from 'url'
|
|
|
12
13
|
* - app/routes/users/[id]/index.ts -> /users/:id
|
|
13
14
|
* - app/routes/index.ts -> /
|
|
14
15
|
*/
|
|
15
|
-
export async function loadSubApps(app: Hono, routesDir: string = './app/routes'): Promise<Array<{ name: string; routes: any[] }>> {
|
|
16
|
+
export async function loadSubApps(app: Hono, routesDir: string = './app/routes', eventBus?: EventBus): Promise<Array<{ name: string; routes: any[] }>> {
|
|
16
17
|
const mounted: Array<{ base: string }> = []
|
|
17
18
|
const allSubAppSummaries: Array<{ name: string; routes: any[] }> = []
|
|
18
19
|
|
|
@@ -37,6 +38,10 @@ export async function loadSubApps(app: Hono, routesDir: string = './app/routes')
|
|
|
37
38
|
const mod: any = await import(modUrl)
|
|
38
39
|
const subApp = mod?.default
|
|
39
40
|
if (subApp) {
|
|
41
|
+
// Inject EventBus into sub-app if it's a Vision instance
|
|
42
|
+
if (eventBus && typeof subApp?.setEventBus === 'function') {
|
|
43
|
+
subApp.setEventBus(eventBus)
|
|
44
|
+
}
|
|
40
45
|
const base = toBasePath(dir)
|
|
41
46
|
// If it's a Vision sub-app, build its services before mounting
|
|
42
47
|
try {
|
package/src/service.ts
CHANGED
|
@@ -459,8 +459,10 @@ export class ServiceBuilder<
|
|
|
459
459
|
throw error
|
|
460
460
|
}
|
|
461
461
|
}
|
|
462
|
-
|
|
463
|
-
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// Always provide emit() so events work in sub-apps without local VisionCore
|
|
465
|
+
if (!(c as any).emit) {
|
|
464
466
|
(c as any).emit = async <K extends keyof TEvents>(
|
|
465
467
|
eventName: K,
|
|
466
468
|
data: TEvents[K]
|
package/src/vision-app.ts
CHANGED
|
@@ -73,6 +73,7 @@ export interface VisionConfig {
|
|
|
73
73
|
password?: string
|
|
74
74
|
}
|
|
75
75
|
devMode?: boolean // Use in-memory event bus (no Redis required)
|
|
76
|
+
eventBus?: EventBus // Share EventBus instance across apps (for sub-apps)
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
|
|
@@ -193,8 +194,9 @@ export class Vision<
|
|
|
193
194
|
this.visionCore = null as any
|
|
194
195
|
}
|
|
195
196
|
|
|
196
|
-
//
|
|
197
|
-
|
|
197
|
+
// Use provided EventBus or create a new one
|
|
198
|
+
// Root app creates EventBus, sub-apps can share it via config.pubsub.eventBus
|
|
199
|
+
this.eventBus = this.config.pubsub?.eventBus || new EventBus({
|
|
198
200
|
redis: this.config.pubsub?.redis,
|
|
199
201
|
devMode: this.config.pubsub?.devMode,
|
|
200
202
|
})
|
|
@@ -545,7 +547,8 @@ export class Vision<
|
|
|
545
547
|
let allSubAppSummaries: Array<{ name: string; routes: any[] }> = []
|
|
546
548
|
for (const d of existing) {
|
|
547
549
|
try {
|
|
548
|
-
|
|
550
|
+
// Pass EventBus to sub-apps so they share the same instance
|
|
551
|
+
const summaries = await loadSubApps(this as any, d, this.eventBus)
|
|
549
552
|
allSubAppSummaries = allSubAppSummaries.concat(summaries)
|
|
550
553
|
} catch (e) {
|
|
551
554
|
console.error(`❌ Failed to load sub-apps from ${d}:`, (e as any)?.message || e)
|
|
@@ -619,6 +622,13 @@ export class Vision<
|
|
|
619
622
|
return this
|
|
620
623
|
}
|
|
621
624
|
}
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Set the EventBus instance (used internally by router to inject shared EventBus)
|
|
628
|
+
*/
|
|
629
|
+
setEventBus(eventBus: EventBus): void {
|
|
630
|
+
this.eventBus = eventBus
|
|
631
|
+
}
|
|
622
632
|
}
|
|
623
633
|
|
|
624
634
|
/**
|