1
+ import { ExecutionContext , Request as CfRequest , ExportedHandlerFetchHandler } from '@cloudflare/workers-types' ;
2
+ import { createFrames , types } from '.' ;
3
+
4
+ const framesWithoutState = createFrames ( ) ;
5
+ framesWithoutState ( async ( ctx ) => {
6
+ ctx . initialState satisfies types . JsonValue | undefined ;
7
+ ctx . state satisfies types . JsonValue | undefined ;
8
+
9
+ return {
10
+ image : 'http://test.png' ,
11
+ } ;
12
+ } ) satisfies ExportedHandlerFetchHandler ;
13
+
14
+ const framesWithInferredState = createFrames ( {
15
+ initialState : { test : true } ,
16
+ } ) ;
17
+
18
+ framesWithInferredState ( async ( ctx ) => {
19
+ ctx . state satisfies { test : boolean ; } ;
20
+
21
+ return {
22
+ image : 'http://test.png' ,
23
+ } ;
24
+ } ) satisfies ExportedHandlerFetchHandler ;
25
+
26
+ const framesWithExplicitState = createFrames < { test : boolean } > ( { } ) ;
27
+ framesWithExplicitState ( async ( ctx ) => {
28
+ ctx . state satisfies { test : boolean } ;
29
+ ctx satisfies { initialState ?: { test : boolean } ; message ?: any , pressedButton ?: any } ;
30
+ ctx satisfies { cf : { env : unknown ; ctx : ExecutionContext ; req : CfRequest } }
31
+
32
+ return {
33
+ image : 'http://test.png' ,
34
+ } ;
35
+ } ) satisfies ExportedHandlerFetchHandler ;
36
+
37
+ const framesWithExplicitStateAndEnv = createFrames < { test : boolean } , { secret : string } > ( { } ) ;
38
+ framesWithExplicitStateAndEnv ( async ( ctx ) => {
39
+ ctx . state satisfies { test : boolean } ;
40
+ ctx satisfies { initialState ?: { test : boolean } ; message ?: any , pressedButton ?: any ; request : Request ; } ;
41
+ ctx satisfies { cf : { env : { secret : string } ; ctx : ExecutionContext ; req : CfRequest } }
42
+
43
+ return {
44
+ image : 'http://test.png' ,
45
+ } ;
46
+ } ) satisfies ExportedHandlerFetchHandler < { secret : string } > ;
0 commit comments