From b00459b48c94bd612097a4cd994c41a560d8e673 Mon Sep 17 00:00:00 2001 From: Giselle van Dongen Date: Fri, 29 Nov 2024 17:19:16 +0100 Subject: [PATCH] Update highlights for codehike v1 (#221) --- tutorials/tour-of-restate-go/part1/cartobject.go | 6 +++--- tutorials/tour-of-restate-go/part2/cartobject.go | 8 ++++---- tutorials/tour-of-restate-go/part3/cartobject.go | 8 ++++---- tutorials/tour-of-restate-go/part4/cartobject.go | 2 +- .../src/main/java/dev/restate/tour/part1/CartObject.java | 6 +++--- .../src/main/java/dev/restate/tour/part2/CartObject.java | 2 +- .../src/main/java/dev/restate/tour/part3/CartObject.java | 8 ++++---- .../src/main/java/dev/restate/tour/part4/CartObject.java | 2 +- .../tour-of-restate-python/tour/part1/cart_object.py | 6 +++--- .../tour-of-restate-python/tour/part2/cart_object.py | 4 ++-- .../tour-of-restate-python/tour/part3/cart_object.py | 8 ++++---- .../src/app/checkout_service.ts | 1 - .../tour-of-restate-typescript/src/part1/cart_object.ts | 6 +++--- .../tour-of-restate-typescript/src/part2/cart_object.ts | 6 +++--- .../tour-of-restate-typescript/src/part3/cart_object.ts | 6 +++--- 15 files changed, 39 insertions(+), 40 deletions(-) diff --git a/tutorials/tour-of-restate-go/part1/cartobject.go b/tutorials/tour-of-restate-go/part1/cartobject.go index 8a126c0a..7bf9892e 100644 --- a/tutorials/tour-of-restate-go/part1/cartobject.go +++ b/tutorials/tour-of-restate-go/part1/cartobject.go @@ -6,7 +6,7 @@ type CartObject struct{} // func (CartObject) AddTicket(ctx restate.ObjectContext, ticketId string) (bool, error) { - // withClass highlight-line + // !mark reservationSuccess, err := restate.Object[bool](ctx, "TicketObject", ticketId, "Reserve").Request(restate.Void{}) if err != nil { return false, err @@ -19,7 +19,7 @@ func (CartObject) AddTicket(ctx restate.ObjectContext, ticketId string) (bool, e // func (CartObject) Checkout(ctx restate.ObjectContext) (bool, error) { - // withClass(1:2) highlight-line + // !mark(1:2) success, err := restate.Service[bool](ctx, "CheckoutService", "Handle"). Request(CheckoutRequest{UserId: restate.Key(ctx), Tickets: []string{"seat2B"}}) if err != nil { @@ -33,7 +33,7 @@ func (CartObject) Checkout(ctx restate.ObjectContext) (bool, error) { // func (CartObject) ExpireTicket(ctx restate.ObjectContext, ticketId string) error { - // withClass highlight-line + // !mark restate.ObjectSend(ctx, "TicketObject", ticketId, "Unreserve").Send(restate.Void{}) return nil diff --git a/tutorials/tour-of-restate-go/part2/cartobject.go b/tutorials/tour-of-restate-go/part2/cartobject.go index 024d5e0f..643f659c 100644 --- a/tutorials/tour-of-restate-go/part2/cartobject.go +++ b/tutorials/tour-of-restate-go/part2/cartobject.go @@ -10,14 +10,14 @@ type CartObject struct{} // func (CartObject) AddTicket(ctx restate.ObjectContext, ticketId string) (bool, error) { - // withClass highlight-line + // !mark reservationSuccess, err := restate.Object[bool](ctx, "TicketObject", ticketId, "Reserve").Request(restate.Void{}) if err != nil { return false, err } if reservationSuccess { - // withClass highlight-line + // !mark restate.ObjectSend(ctx, "CartObject", restate.Key(ctx), "ExpireTicket").Send(ticketId, restate.WithDelay(15*time.Minute)) } @@ -28,7 +28,7 @@ func (CartObject) AddTicket(ctx restate.ObjectContext, ticketId string) (bool, e // func (CartObject) Checkout(ctx restate.ObjectContext) (bool, error) { - // withClass(1:2) highlight-line + // !mark(1:2) success, err := restate.Service[bool](ctx, "CheckoutService", "Handle"). Request(CheckoutRequest{UserId: restate.Key(ctx), Tickets: []string{"seat2B"}}) if err != nil { @@ -42,7 +42,7 @@ func (CartObject) Checkout(ctx restate.ObjectContext) (bool, error) { // func (CartObject) ExpireTicket(ctx restate.ObjectContext, ticketId string) error { - // withClass highlight-line + // !mark restate.ObjectSend(ctx, "TicketObject", ticketId, "Unreserve").Send(restate.Void{}) return nil diff --git a/tutorials/tour-of-restate-go/part3/cartobject.go b/tutorials/tour-of-restate-go/part3/cartobject.go index d00e59ec..f26a5eaa 100644 --- a/tutorials/tour-of-restate-go/part3/cartobject.go +++ b/tutorials/tour-of-restate-go/part3/cartobject.go @@ -11,14 +11,14 @@ type CartObject struct{} // func (CartObject) AddTicket(ctx restate.ObjectContext, ticketId string) (bool, error) { - // withClass highlight-line + // !mark reservationSuccess, err := restate.Object[bool](ctx, "TicketObject", ticketId, "Reserve").Request(restate.Void{}) if err != nil { return false, err } if reservationSuccess { - // withClass(1:6) highlight-line + // !mark(1:6) tickets, err := restate.Get[[]string](ctx, "tickets") if err != nil { return false, err @@ -36,7 +36,7 @@ func (CartObject) AddTicket(ctx restate.ObjectContext, ticketId string) (bool, e // func (CartObject) Checkout(ctx restate.ObjectContext) (bool, error) { - // withClass(1:4) highlight-line + // !mark(1:4) tickets, err := restate.Get[[]string](ctx, "tickets") if err != nil || len(tickets) == 0 { return false, err @@ -49,7 +49,7 @@ func (CartObject) Checkout(ctx restate.ObjectContext) (bool, error) { } if success { - // withClass highlight-line + // !mark restate.Clear(ctx, "tickets") } diff --git a/tutorials/tour-of-restate-go/part4/cartobject.go b/tutorials/tour-of-restate-go/part4/cartobject.go index 5070054c..287653c7 100644 --- a/tutorials/tour-of-restate-go/part4/cartobject.go +++ b/tutorials/tour-of-restate-go/part4/cartobject.go @@ -43,7 +43,7 @@ func (CartObject) Checkout(ctx restate.ObjectContext) (bool, error) { } if success { - // withClass(1:3) highlight-line + // !mark(1:3) for _, ticketId := range tickets { restate.ObjectSend(ctx, "TicketObject", ticketId, "MarkAsSold").Send(restate.Void{}) } diff --git a/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part1/CartObject.java b/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part1/CartObject.java index 0fbde970..21fccd39 100644 --- a/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part1/CartObject.java +++ b/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part1/CartObject.java @@ -24,7 +24,7 @@ public class CartObject { // @Handler public boolean addTicket(ObjectContext ctx, String ticketId) { - // withClass highlight-line + // !mark boolean reservationSuccess = TicketObjectClient.fromContext(ctx, ticketId).reserve().await(); return true; @@ -34,7 +34,7 @@ public boolean addTicket(ObjectContext ctx, String ticketId) { // @Handler public void expireTicket(ObjectContext ctx, String ticketId) { - // withClass highlight-line + // !mark TicketObjectClient.fromContext(ctx, ticketId).send().unreserve(); } // @@ -42,7 +42,7 @@ public void expireTicket(ObjectContext ctx, String ticketId) { // @Handler public boolean checkout(ObjectContext ctx) { - // withClass(1:3) highlight-line + // !mark(1:3) boolean checkoutSuccess = CheckoutServiceClient.fromContext(ctx) .handle(new CheckoutRequest("Mary", Set.of("seat2B"))) .await(); diff --git a/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part2/CartObject.java b/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part2/CartObject.java index 6e578cf2..5073d97f 100644 --- a/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part2/CartObject.java +++ b/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part2/CartObject.java @@ -28,7 +28,7 @@ public boolean addTicket(ObjectContext ctx, String ticketId) { boolean reservationSuccess = TicketObjectClient.fromContext(ctx, ticketId).reserve().await(); if (reservationSuccess) { - // withClass(1:3) highlight-line + // !mark(1:3) CartObjectClient.fromContext(ctx, ctx.key()) .send(Duration.ofMinutes(15)) .expireTicket(ticketId); diff --git a/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part3/CartObject.java b/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part3/CartObject.java index cb2a4303..caeddb82 100644 --- a/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part3/CartObject.java +++ b/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part3/CartObject.java @@ -28,7 +28,7 @@ public class CartObject { // // At the top of the class, define the state key: supply a name and (de)serializer - // withClass(1,2) highlight-line + // !mark(1,2) public static final StateKey> STATE_KEY = StateKey.of("tickets", JacksonSerdes.of(new TypeReference<>() {})); @@ -37,7 +37,7 @@ public boolean addTicket(ObjectContext ctx, String ticketId) { boolean reservationSuccess = TicketObjectClient.fromContext(ctx, ticketId).reserve().await(); if (reservationSuccess) { - // withClass(1:3) highlight-line + // !mark(1:3) Set tickets = ctx.get(STATE_KEY).orElseGet(HashSet::new); tickets.add(ticketId); ctx.set(STATE_KEY, tickets); @@ -68,7 +68,7 @@ public void expireTicket(ObjectContext ctx, String ticketId) { // @Handler public boolean checkout(ObjectContext ctx) { - // withClass(1:5) highlight-line + // !mark(1:5) Set tickets = ctx.get(STATE_KEY).orElseGet(HashSet::new); if (tickets.isEmpty()) { @@ -80,7 +80,7 @@ public boolean checkout(ObjectContext ctx) { .await(); if (checkoutSuccess) { - // withClass highlight-line + // !mark ctx.clear(STATE_KEY); } diff --git a/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part4/CartObject.java b/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part4/CartObject.java index 6e701140..f1feb94d 100644 --- a/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part4/CartObject.java +++ b/tutorials/tour-of-restate-java/src/main/java/dev/restate/tour/part4/CartObject.java @@ -72,7 +72,7 @@ public boolean checkout(ObjectContext ctx) { .await(); if (checkoutSuccess) { - // withClass(1:3) highlight-line + // !mark(1:3) tickets.forEach(t -> TicketObjectClient.fromContext(ctx, t).send().markAsSold() ); diff --git a/tutorials/tour-of-restate-python/tour/part1/cart_object.py b/tutorials/tour-of-restate-python/tour/part1/cart_object.py index 653fcef7..e29b25c2 100644 --- a/tutorials/tour-of-restate-python/tour/part1/cart_object.py +++ b/tutorials/tour-of-restate-python/tour/part1/cart_object.py @@ -19,7 +19,7 @@ # @cart.handler("addTicket") async def add_ticket(ctx: ObjectContext, ticket_id: str) -> bool: - # withClass highlight-line + # !mark reserved = await ctx.object_call(reserve, key=ticket_id, arg=None) return reserved @@ -31,7 +31,7 @@ async def add_ticket(ctx: ObjectContext, ticket_id: str) -> bool: # @cart.handler() async def checkout(ctx: ObjectContext) -> bool: - # withClass(1:2) highlight-line + # !mark(1:2) success = await ctx.service_call(handle, arg={'user_id': ctx.key(), 'tickets': ["seat2B"]}) @@ -42,6 +42,6 @@ async def checkout(ctx: ObjectContext) -> bool: # @cart.handler("expireTicket") async def expire_ticket(ctx: ObjectContext, ticket_id: str): - # withClass highlight-line + # !mark ctx.object_send(unreserve, key=ticket_id, arg=None) # diff --git a/tutorials/tour-of-restate-python/tour/part2/cart_object.py b/tutorials/tour-of-restate-python/tour/part2/cart_object.py index f6d7b549..5c101fcd 100644 --- a/tutorials/tour-of-restate-python/tour/part2/cart_object.py +++ b/tutorials/tour-of-restate-python/tour/part2/cart_object.py @@ -24,7 +24,7 @@ async def add_ticket(ctx: ObjectContext, ticket_id: str) -> bool: reserved = await ctx.object_call(reserve, key=ticket_id, arg=None) if reserved: - # withClass highlight-line + # !mark ctx.object_send(expire_ticket, key=ctx.key(), arg=ticket_id, send_delay=timedelta(minutes=15)) return reserved @@ -34,7 +34,7 @@ async def add_ticket(ctx: ObjectContext, ticket_id: str) -> bool: # @cart.handler() async def checkout(ctx: ObjectContext) -> bool: - # withClass(1:2) highlight-line + # !mark(1:2) success = await ctx.service_call(handle, arg={'user_id': ctx.key(), 'tickets': ["seat2B"]}) diff --git a/tutorials/tour-of-restate-python/tour/part3/cart_object.py b/tutorials/tour-of-restate-python/tour/part3/cart_object.py index 24934ad3..9e7e4ae3 100644 --- a/tutorials/tour-of-restate-python/tour/part3/cart_object.py +++ b/tutorials/tour-of-restate-python/tour/part3/cart_object.py @@ -24,7 +24,7 @@ async def add_ticket(ctx: ObjectContext, ticket_id: str) -> bool: reserved = await ctx.object_call(reserve, key=ticket_id, arg=None) if reserved: - # withClass(1:3) highlight-line + # !mark(1:3) tickets = await ctx.get("tickets") or [] tickets.append(ticket_id) ctx.set("tickets", tickets) @@ -38,10 +38,10 @@ async def add_ticket(ctx: ObjectContext, ticket_id: str) -> bool: # @cart.handler() async def checkout(ctx: ObjectContext) -> bool: - # withClass highlight-line + # !mark tickets = await ctx.get("tickets") or [] - # withClass(1:2) highlight-line + # !mark(1:2) if len(tickets) == 0: return False @@ -49,7 +49,7 @@ async def checkout(ctx: ObjectContext) -> bool: 'tickets': tickets}) if success: - # withClass(1:2) highlight-line + # !mark(1:2) for ticket in tickets: ctx.object_send(mark_as_sold, key=ticket, arg=None) diff --git a/tutorials/tour-of-restate-typescript/src/app/checkout_service.ts b/tutorials/tour-of-restate-typescript/src/app/checkout_service.ts index 9a5d5e6e..707ea27a 100644 --- a/tutorials/tour-of-restate-typescript/src/app/checkout_service.ts +++ b/tutorials/tour-of-restate-typescript/src/app/checkout_service.ts @@ -16,7 +16,6 @@ export const checkoutService = restate.service({ name: "CheckoutService", handlers: { async handle(ctx: restate.Context, request: { userId: string; tickets: string[] }){ - console.info("Hello") return true; }, } diff --git a/tutorials/tour-of-restate-typescript/src/part1/cart_object.ts b/tutorials/tour-of-restate-typescript/src/part1/cart_object.ts index 8489ec52..e032035c 100644 --- a/tutorials/tour-of-restate-typescript/src/part1/cart_object.ts +++ b/tutorials/tour-of-restate-typescript/src/part1/cart_object.ts @@ -18,7 +18,7 @@ export const cartObject = restate.object({ handlers: { // async addTicket(ctx: restate.ObjectContext, ticketId: string) { - // withClass highlight-line + // !mark const reservationSuccess = await ctx.objectClient(TicketObject, ticketId).reserve(); return true; @@ -27,7 +27,7 @@ export const cartObject = restate.object({ // async checkout(ctx: restate.ObjectContext) { - // withClass(1:2) highlight-line + // !mark(1:2) const success = await ctx.serviceClient(CheckoutService) .handle({userId: ctx.key, tickets: ["seat2B"]}); @@ -37,7 +37,7 @@ export const cartObject = restate.object({ // async expireTicket(ctx: restate.ObjectContext, ticketId: string) { - // withClass highlight-line + // !mark ctx.objectSendClient(TicketObject, ticketId).unreserve(); }, // diff --git a/tutorials/tour-of-restate-typescript/src/part2/cart_object.ts b/tutorials/tour-of-restate-typescript/src/part2/cart_object.ts index a18343f4..85e1f052 100644 --- a/tutorials/tour-of-restate-typescript/src/part2/cart_object.ts +++ b/tutorials/tour-of-restate-typescript/src/part2/cart_object.ts @@ -21,7 +21,7 @@ export const cartObject = restate.object({ const reservationSuccess = await ctx.objectClient(TicketObject, ticketId).reserve(); if (reservationSuccess) { - // withClass(1,2) highlight-line + // !mark(1,2) ctx.objectSendClient(CartObject, ctx.key, {delay: 15 * 60 * 1000}) .expireTicket(ticketId); } @@ -32,7 +32,7 @@ export const cartObject = restate.object({ // async checkout(ctx: restate.ObjectContext) { - // withClass(1:2) highlight-line + // !mark(1:2) const success = await ctx.serviceClient(CheckoutService) .handle({userId: ctx.key, tickets: ["seat2B"]}); @@ -42,7 +42,7 @@ export const cartObject = restate.object({ // async expireTicket(ctx: restate.ObjectContext, ticketId: string) { - // withClass highlight-line + // !mark ctx.objectSendClient(TicketObject, ticketId).unreserve(); } // diff --git a/tutorials/tour-of-restate-typescript/src/part3/cart_object.ts b/tutorials/tour-of-restate-typescript/src/part3/cart_object.ts index 15b38d20..e46e84b1 100644 --- a/tutorials/tour-of-restate-typescript/src/part3/cart_object.ts +++ b/tutorials/tour-of-restate-typescript/src/part3/cart_object.ts @@ -21,7 +21,7 @@ export const cartObject = restate.object({ const reservationSuccess = await ctx.objectClient(TicketObject, ticketId).reserve(); if (reservationSuccess) { - // withClass(1:3) highlight-line + // !mark(1:3) const tickets = (await ctx.get("tickets")) ?? []; tickets.push(ticketId); ctx.set("tickets", tickets); @@ -36,7 +36,7 @@ export const cartObject = restate.object({ // async checkout(ctx: restate.ObjectContext) { - // withClass(1:5) highlight-line + // !mark(1:5) const tickets = (await ctx.get("tickets")) ?? []; if (tickets.length === 0) { @@ -47,7 +47,7 @@ export const cartObject = restate.object({ .handle({userId: ctx.key, tickets}); if (success) { - // withClass highlight-line + // !mark ctx.clear("tickets"); }