Skip to content

Commit

Permalink
Upgrade codehike to v1 (#460)
Browse files Browse the repository at this point in the history
* Upgrade docusaurus

* Upgrade codehike and other dependencies

* Upgrading to codehike v1

* Minimal working version codehike v1

* Fix styling of scrollycoding

* Fix styling of codehike v1

* Codehike v1 migration

* Add copy button

* Upgrade Tour to codehike v1

* Upgrade to codehike v1

* Fix scrollycoding for tabs and steps

* Fix invocations page to codehike v1

* Fix services page to codehike v1

* Upgrade codehike v1 docs

* make tabs work and update all code snippets

* fix lists

* Fix numbered lists and fix clients code snippets

* Fix invocations page

* Make tabs and scrollycoding word properly and add styling

* Cleanu

* Cleanup

* Fix focus and mark across the docs

* Fix terminal animations

* Collapse verbose terminal output in tour and invocations page

* Fix coloring of links in admonitions

* Fix styling of animations

* Small fixes

* Cleanup
  • Loading branch information
gvdongen authored Oct 31, 2024
1 parent 65eff6b commit 6126742
Show file tree
Hide file tree
Showing 117 changed files with 6,355 additions and 4,740 deletions.
18 changes: 9 additions & 9 deletions code_snippets/go/concepts/invocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ type MyService struct{}
/*
// <start_rpc_call>
func (MyService) MyRestateHandler(ctx restate.Context) error {
// focus
// !focus
greet, err := restate.
// focus
// !focus
Service[string](ctx, "Greeter", "Greet").
// focus
// !focus
Request("Hi")
return err
}
Expand All @@ -24,11 +24,11 @@ func (MyService) MyRestateHandler(ctx restate.Context) error {
// <start_one_way_call>
func (MyService) MyRestateHandler(ctx restate.Context) error {
// focus
// !focus
restate.
// focus
// !focus
ServiceSend(ctx, "Greeter", "Greet").
// focus
// !focus
Send("Hi")
return nil
}
Expand All @@ -38,11 +38,11 @@ func (MyService) MyRestateHandler(ctx restate.Context) error {

// <start_delayed_call>
func (MyService) MyRestateHandler(ctx restate.Context) error {
// focus
// !focus
restate.
// focus
// !focus
ServiceSend(ctx, "Greeter", "Greet").
// focus
// !focus
Send("Hi", restate.WithDelay(1*time.Second))
return nil
}
Expand Down
1 change: 0 additions & 1 deletion code_snippets/go/develop/codegen/proto/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ syntax = "proto3";
option go_package = "github.com/restatedev/documentation/code_snippets/go/codegen/proto";

// <start_service>
// service.proto
package greeter;

service Greeter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ public class DelayedCalls {
// <start_delayed_call>
@Handler
public void myRestateHandler(Context ctx) {
// focus
// !focus
GreeterServiceClient.fromContext(ctx)
// focus
// !focus
.send(Duration.ofMillis(1000))
// focus
// !focus
.greet("Hi");
}

// <end_delayed_call>

// <start_delayed_call_java>
public void myJavaHandler(Context ctx) {
// focus
public void myJavaHandler() {
// !focus
Client restate = Client.connect("http://localhost:8080");
// focus
// !focus
GreeterServiceClient.fromClient(restate)
// focus
// !focus
.send(Duration.ofMillis(1000))
// focus
// !focus
.greet("Hi");
}
// <end_delayed_call_java>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ public class OneWayCalls {
// <start_one_way_call>
@Handler
public void myRestateHandler(Context ctx) {
// focus
// !focus
GreeterServiceClient.fromContext(ctx)
// focus
// !focus
.send()
// focus
// !focus
.greet("Hi");
}

// <end_one_way_call>

// <start_one_way_call_java>
public void myJavaHandler(Context ctx) {
// focus
public void myJavaHandler() {
// !focus
Client restate = Client.connect("http://localhost:8080");
// focus
// !focus
GreeterServiceClient.fromClient(restate)
// focus
// !focus
.send()
// focus
// !focus
.greet("Hi");
}
// <end_one_way_call_java>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ public class RpcCalls {
// <start_rpc>
@Handler
public void myRestateHandler(Context ctx) {
// focus
// !focus
String greet =
// focus
// !focus
GreeterServiceClient.fromContext(ctx)
// focus
// !focus
.greet("Hi")
// focus
// !focus
.await();
}

// <end_rpc>

// <start_rpc_java>
public void myJavaHandler(Context ctx) {
// focus
public void myJavaHandler() {
// !focus
Client restate = Client.connect("http://localhost:8080");
// focus
// !focus
String greet =
// focus
// !focus
GreeterServiceClient.fromClient(restate)
// focus
// !focus
.greet("Hi");
}
// <end_rpc_java>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void oneWay(Context ctx) {

// <start_one_way>
MyServiceClient.fromContext(ctx)
// mark
// !mark
.send()
.myHandler(request);
// <end_one_way>
Expand All @@ -70,7 +70,7 @@ private void delayedCall(Context ctx) {

// <start_delayed>
MyServiceClient.fromContext(ctx)
// mark
// !mark
.send(Duration.ofSeconds(1))
.myHandler(request);
// <end_delayed>
Expand Down
18 changes: 9 additions & 9 deletions code_snippets/java/src/main/java/develop/clients/Ingress.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public void myOneWayCallHandler() {
// <start_one_way_call_java>
Client rs = Client.connect("http://localhost:8080");
GreeterServiceClient.fromClient(rs)
// mark
// !mark
.send()
.greet("Hi");

GreetCounterObjectClient.fromClient(rs, "Mary")
// mark
// !mark
.send()
.greet("Hi");
// <end_one_way_call_java>
Expand All @@ -38,12 +38,12 @@ public void myDelayedOneWayCallHandler() {
// <start_delayed_call_java>
Client rs = Client.connect("http://localhost:8080");
GreeterServiceClient.fromClient(rs)
// mark
// !mark
.send(Duration.ofMillis(1000))
.greet("Hi");

GreetCounterObjectClient.fromClient(rs, "Mary")
// mark
// !mark
.send(Duration.ofMillis(1000))
.greet("Hi");
// <end_delayed_call_java>
Expand All @@ -67,21 +67,21 @@ public void attach() {
SendResponse handle =
GreeterServiceClient.fromClient(rs)
.send()
// mark
// !mark
.greet("Hi", CallRequestOptions.DEFAULT.withIdempotency("abcde"));

// ... do something else ...

// Option 1: Attach later to retrieve the result
// mark
// !mark
String greeting =
// mark
// !mark
rs.invocationHandle(handle.getInvocationId(), JsonSerdes.STRING).attach();

// Option 2: Peek to see if the result is ready
// mark
// !mark
Output<String> output =
// mark
// !mark
rs.invocationHandle(handle.getInvocationId(), JsonSerdes.STRING).getOutput();
if (output.isReady()) {
String result = output.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ public class UserManagementService {
// <start_here>
@Handler
public void setup(ObjectContext ctx, Email email) {
// focus
// !focus
boolean result =
// focus
// !focus
SignupWorkflowClient.fromContext(ctx, "someone")
// focus
// !focus
.run(email)
// focus
// !focus
.await();
}

@Handler
public void queryStatus(ObjectContext ctx) {
// focus
// !focus
String status =
// focus
// !focus
SignupWorkflowClient.fromContext(ctx, "someone")
// focus
// !focus
.getStatus()
// focus
// !focus
.await();
}
// <end_here>
Expand Down
16 changes: 8 additions & 8 deletions code_snippets/java/src/main/java/get_started/Tour.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public void myFn(Context ctx) {
// <start_uuid>
@Handler
public boolean handle(Context ctx, CheckoutRequest request) {
// mark
// !mark
String idempotencyKey = ctx.random().nextUUID().toString();
// mark
// !mark
System.out.println("My idempotency key: " + idempotencyKey);

// mark
// !mark
throw new IllegalStateException("The handler failed");
}

Expand All @@ -48,18 +48,18 @@ class CheckoutService {
// <start_checkout>
@Handler
public boolean handle(Context ctx, CheckoutRequest request) {
// mark
// !mark
double totalPrice = request.getTickets().size() * 40.0;

String idempotencyKey = ctx.random().nextUUID().toString();

// mark
// !mark
boolean success =
// mark
// !mark
ctx.run(
// mark
// !mark
JsonSerdes.BOOLEAN,
// mark
// !mark
() -> PaymentClient.get().call(idempotencyKey, totalPrice));

return success;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ public void submit(User user) {
// <start_here>
// import dev.restate.sdk.client.Client;
Client rs = Client.connect("http://localhost:8080");
// mark
// !mark
SignupWorkflowClient.fromClient(rs, user.getId())
// mark
// !mark
.submit(user);

// do something else, with workflow running in the background

// attach back to the workflow
// mark
// !mark
boolean result =
SignupWorkflowClient.fromClient(rs, user.getId())
// mark
// !mark
.workflowHandle()
// mark
// !mark
.attach();
// <end_here>
}
Expand Down
10 changes: 5 additions & 5 deletions code_snippets/kotlin/src/main/kotlin/develop/clients/Ingress.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class Ingress {
// <start_one_way_call_kotlin>
val rs = Client.connect("http://localhost:8080")
GreeterServiceClient.fromClient(rs)
// mark
// !mark
.send()
.greet("Hi")

GreetCounterObjectClient.fromClient(rs, "Mary")
// mark
// !mark
.send()
.greet("Hi")
// <end_one_way_call_kotlin>
Expand Down Expand Up @@ -66,18 +66,18 @@ class Ingress {
val handle: SendResponse =
GreeterServiceClient.fromClient(rs)
.send()
// mark
// !mark
.greet("Hi", CallRequestOptions.DEFAULT.withIdempotency("abcde"))

// ... do something else ...

// Option 1: Attach later to retrieve the result
// mark(1:3)
// !mark(1:2)
val greeting: String =
rs.invocationHandle(handle.invocationId, KtSerdes.json<String>()).attach()

// Option 2: Peek to see if the result is ready
// mark(1:3)
// !mark(1:2)
val output: Output<String> =
rs.invocationHandle(handle.invocationId, KtSerdes.json<String>()).output
if (output.isReady) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class UserManagementService {
// <start_here>
@Handler
suspend fun setup(ctx: ObjectContext, email: Email) {
// focus(1:3)
// !focus
val result = SignupWorkflowClient.fromContext(ctx, "someone").run(email).await()
}

@Handler
suspend fun queryStatus(ctx: ObjectContext) {
// focus(1:3)
// !focus
val status = SignupWorkflowClient.fromContext(ctx, "someone").getStatus().await()
}
// <end_here>
Expand Down
Loading

0 comments on commit 6126742

Please sign in to comment.