@getvision/server 0.3.5-5fbff2a-develop → 0.4.0-6e5c887-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/.env.example +0 -7
- package/CHANGELOG.md +13 -0
- package/package.json +2 -2
- package/src/service.ts +19 -13
package/.env.example
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
# Inngest Configuration
|
|
2
|
-
INNGEST_DEV=0
|
|
3
|
-
INNGEST_BASE_URL=http://localhost:8288
|
|
4
|
-
INNGEST_REDIS_URI=redis://localhost:6379/8
|
|
5
|
-
INNGEST_EVENT_KEY=a1b2c3d4e5f6789012345678901234567890abcdefabcdef1234567890abcd
|
|
6
|
-
INNGEST_SIGNING_KEY=fedcba0987654321fedcba0987654321fedcba0987654321fedcba0987654321
|
|
7
|
-
|
|
8
1
|
# Vision Server
|
|
9
2
|
VISION_PORT=9500
|
|
10
3
|
NODE_ENV=development
|
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getvision/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-6e5c887-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.0
|
|
16
|
+
"@getvision/core": "0.1.0",
|
|
17
17
|
"@hono/node-server": "^1.19.6",
|
|
18
18
|
"bullmq": "^5.62.0",
|
|
19
19
|
"hono-rate-limiter": "^0.4.2",
|
package/src/service.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { Hono, Context, MiddlewareHandler, Env, Input } from 'hono'
|
|
2
2
|
import type { z } from 'zod'
|
|
3
|
-
import { VisionCore,
|
|
3
|
+
import { VisionCore, generateTemplate } from '@getvision/core'
|
|
4
|
+
import {
|
|
5
|
+
ValidationError,
|
|
6
|
+
createValidationErrorResponse,
|
|
7
|
+
UniversalValidator
|
|
8
|
+
} from '@getvision/core'
|
|
4
9
|
import type { EndpointConfig, Handler } from './types'
|
|
5
10
|
import { getVisionContext } from './vision-app'
|
|
6
11
|
import { eventRegistry } from './event-registry'
|
|
@@ -152,11 +157,11 @@ export class ServiceBuilder<
|
|
|
152
157
|
this.endpoints.forEach((ep) => {
|
|
153
158
|
let requestBody = undefined
|
|
154
159
|
if (ep.schema.input && ['POST', 'PUT', 'PATCH'].includes(ep.method)) {
|
|
155
|
-
requestBody =
|
|
160
|
+
requestBody = generateTemplate(ep.schema.input)
|
|
156
161
|
}
|
|
157
162
|
let responseBody = undefined
|
|
158
163
|
if (ep.schema.output) {
|
|
159
|
-
responseBody =
|
|
164
|
+
responseBody = generateTemplate(ep.schema.output)
|
|
160
165
|
}
|
|
161
166
|
routes.push({
|
|
162
167
|
method: ep.method,
|
|
@@ -382,13 +387,13 @@ export class ServiceBuilder<
|
|
|
382
387
|
// Generate requestBody schema (input)
|
|
383
388
|
let requestBody = undefined
|
|
384
389
|
if (ep.schema.input && ['POST', 'PUT', 'PATCH'].includes(ep.method)) {
|
|
385
|
-
requestBody =
|
|
390
|
+
requestBody = generateTemplate(ep.schema.input)
|
|
386
391
|
}
|
|
387
392
|
|
|
388
393
|
// Generate responseBody schema (output) - NEW!
|
|
389
394
|
let responseBody = undefined
|
|
390
395
|
if (ep.schema.output) {
|
|
391
|
-
responseBody =
|
|
396
|
+
responseBody = generateTemplate(ep.schema.output)
|
|
392
397
|
}
|
|
393
398
|
|
|
394
399
|
return {
|
|
@@ -517,15 +522,15 @@ export class ServiceBuilder<
|
|
|
517
522
|
|
|
518
523
|
const input = { ...params, ...query, ...body }
|
|
519
524
|
|
|
520
|
-
// Validate input with Zod
|
|
521
|
-
const validated = ep.schema.input
|
|
525
|
+
// Validate input with UniversalValidator (supports Zod, Valibot, etc.)
|
|
526
|
+
const validated = UniversalValidator.parse(ep.schema.input, input)
|
|
522
527
|
|
|
523
528
|
// Execute handler
|
|
524
529
|
const result = await ep.handler(validated, c as any)
|
|
525
530
|
|
|
526
531
|
// If an output schema exists, validate and return JSON
|
|
527
532
|
if (ep.schema.output) {
|
|
528
|
-
const validatedOutput = ep.schema.output
|
|
533
|
+
const validatedOutput = UniversalValidator.parse(ep.schema.output, result)
|
|
529
534
|
return c.json(validatedOutput)
|
|
530
535
|
}
|
|
531
536
|
|
|
@@ -535,11 +540,12 @@ export class ServiceBuilder<
|
|
|
535
540
|
}
|
|
536
541
|
return c.json(result)
|
|
537
542
|
} catch (error) {
|
|
538
|
-
if (
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
+
if (error instanceof ValidationError) {
|
|
544
|
+
const requestId = c.req.header('x-request-id')
|
|
545
|
+
return c.json(
|
|
546
|
+
createValidationErrorResponse(error.issues, requestId),
|
|
547
|
+
400
|
|
548
|
+
)
|
|
543
549
|
}
|
|
544
550
|
throw error
|
|
545
551
|
}
|