9
9
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
10
10
*/
11
11
12
- import * as restate from "@restatedev/restate-sdk" ;
12
+ import {
13
+ createObjectHandler ,
14
+ createObjectSharedHandler ,
15
+ object ,
16
+ type ObjectContext ,
17
+ type ObjectSharedContext ,
18
+ serde ,
19
+ serve ,
20
+ } from "@restatedev/restate-sdk" ;
13
21
14
- export const counter = restate . object ( {
22
+ export const counter = object ( {
15
23
name : "counter" ,
16
24
handlers : {
17
25
/**
18
26
* Add amount to the currently stored count
19
27
*/
20
- add : async ( ctx : restate . ObjectContext , amount : number ) => {
28
+ add : async ( ctx : ObjectContext , amount : number ) => {
21
29
const current = await ctx . get < number > ( "count" ) ;
22
30
const updated = ( current ?? 0 ) + amount ;
23
31
ctx . set ( "count" , updated ) ;
@@ -31,8 +39,8 @@ export const counter = restate.object({
31
39
* These handlers can be executed concurrently to the exclusive handlers (i.e. add)
32
40
* But they can not modify the state (set is missing from the ctx).
33
41
*/
34
- current : restate . handlers . object . shared (
35
- async ( ctx : restate . ObjectSharedContext ) : Promise < number > => {
42
+ current : createObjectSharedHandler (
43
+ async ( ctx : ObjectSharedContext ) : Promise < number > => {
36
44
return ( await ctx . get ( "count" ) ) ?? 0 ;
37
45
}
38
46
) ,
@@ -44,12 +52,12 @@ export const counter = restate.object({
44
52
* to call that handler with binary data, you can use the following curl command:
45
53
* curl -X POST -H "Content-Type: application/octet-stream" --data-binary 'hello' ${RESTATE_INGRESS_URL}/counter/mykey/binary
46
54
*/
47
- binary : restate . handlers . object . exclusive (
55
+ binary : createObjectHandler (
48
56
{
49
- input : restate . serde . binary ,
50
- output : restate . serde . binary ,
57
+ input : serde . binary ,
58
+ output : serde . binary ,
51
59
} ,
52
- async ( ctx : restate . ObjectContext , data : Uint8Array ) => {
60
+ async ( ctx : ObjectContext , data : Uint8Array ) => {
53
61
// console.log("Received binary data", data);
54
62
return data ;
55
63
}
@@ -59,4 +67,4 @@ export const counter = restate.object({
59
67
60
68
export type Counter = typeof counter ;
61
69
62
- restate . serve ( { services : [ counter ] } ) ;
70
+ serve ( { services : [ counter ] } ) ;
0 commit comments