File tree Expand file tree Collapse file tree 4 files changed +28
-8
lines changed
examples/typescript-validator Expand file tree Collapse file tree 4 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ export interface ValidateResponse {
1313 sessionId : string ;
1414 compiled : boolean ;
1515 timings : {
16- install ?: number ;
1716 bundle ?: number ;
1817 load : number ;
1918 execute : number ;
Original file line number Diff line number Diff line change 11import { getSandbox } from '@cloudflare/sandbox' ;
2- import type { ValidateRequest , ValidateResponse , ErrorResponse } from './types' ;
2+ import type {
3+ ValidateRequest ,
4+ ValidateResponse ,
5+ ErrorResponse ,
6+ ZodParseResult
7+ } from './types' ;
38
49/**
510 * Compiler Durable Object
@@ -216,11 +221,7 @@ export class CompilerDO implements DurableObject {
216221 } ) ;
217222
218223 const response = await worker . getEntrypoint ( ) . fetch ( testRequest ) ;
219- const result = ( await response . json ( ) ) as {
220- success : boolean ;
221- data ?: unknown ;
222- error ?: { issues : unknown [ ] } ;
223- } ;
224+ const result = ( await response . json ( ) ) as ZodParseResult ;
224225
225226 timings . execute = Date . now ( ) - executeStart ;
226227
Original file line number Diff line number Diff line change @@ -9,7 +9,16 @@ export default {
99
1010 // Route API requests to Compiler DO
1111 if ( url . pathname === '/validate' ) {
12- const id = env . Compiler . idFromName ( 'singleton' ) ;
12+ // Use session ID from header to isolate per user
13+ const sessionId = request . headers . get ( 'X-Session-ID' ) ;
14+ if ( ! sessionId ) {
15+ return Response . json (
16+ { error : 'Missing X-Session-ID header' } ,
17+ { status : 400 }
18+ ) ;
19+ }
20+
21+ const id = env . Compiler . idFromName ( sessionId ) ;
1322 const stub = env . Compiler . get ( id ) ;
1423 return stub . fetch ( request ) ;
1524 }
Original file line number Diff line number Diff line change @@ -33,3 +33,14 @@ export interface ErrorResponse {
3333 error : string ;
3434 details ?: string ;
3535}
36+
37+ /**
38+ * Result from Zod schema validation
39+ */
40+ export interface ZodParseResult {
41+ success : boolean ;
42+ data ?: unknown ;
43+ error ?: {
44+ issues : unknown [ ] ;
45+ } ;
46+ }
You can’t perform that action at this time.
0 commit comments