Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove gRPC from the public API #270

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ as part of long-running processes, or as FaaS (AWS Lambda).
```typescript
// note that there is no failure handling in this example, because the combination of durable execution,
// communication, and state storage makes this unnecessary here.
const addToCart = async (ctx: restate.RpcContext, cartId: string /* the key */, ticketId: string) => {
const addToCart = async (ctx: restateObjectContext, ticketId: string) => {
// RPC participates in durable execution, so guaranteed to eventually happen and
// will never get duplicated. would suspend if the other takes too long
const success = await ctx.rpc<ticketApi>({ path: "tickets" }).reserve(ticketId);
const success = await ctx.service(ticketApi).reserve(ticketId);

if (success) {
const cart = (await ctx.get<string[]>("cart")) || []; // gets state 'cart' bound to current cartId
cart.push(ticketId);
ctx.set("cart", cart); // writes state bound to current cartId

// reliable delayed call sent from Restate, which also participaes in durable execution
ctx.sendDelayed<cartApi>({path: "cart"}, minutes(15)).expireTicket(ticketId);
ctx.objectSendDelayed(cartApi, minutes(15)).expireTicket(ticketId);
}
return success;
}
Expand All @@ -33,7 +33,7 @@ const addToCart = async (ctx: restate.RpcContext, cartId: string /* the key */,

restate
.createServer()
.bindKeyedRouter("cart", restate.keyedRouter({ addToCart, expireTicket }))
.object("cart", restate.object({ addToCart, expireTicket }))
.listen(9080);
```

Expand Down
6 changes: 0 additions & 6 deletions buf.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: restatedev
repository: proto
commit: 6ea2d15aed8f408590a1465844df5a8e
digest: shake256:e6599809ff13490a631f87d1a4b13ef1886d1bd1c0aa001ccb92806c0acc373d047a6ead761f8a21dfbd57a4fd9acd5915a52e47bd5b4e4a02dd1766f78511b3
4 changes: 2 additions & 2 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: v1
deps:
- buf.build/restatedev/proto
#deps:
# - buf.build/restatedev/proto
build:
excludes:
- node_modules
Expand Down
38 changes: 0 additions & 38 deletions examples/embedded_example.ts

This file was deleted.

32 changes: 10 additions & 22 deletions examples/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,18 @@
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
*/

/*
* A simple example program using the Restate dynamic RPC-based API.
*
* This example primarily exists to make it simple to test the code against
* a running Restate instance.
*/

import * as restate from "../src/public_api";

//
// The main entry point for the service, receiving the greeting request and name.
//
const greeter = restate.router({
const greeter = restate.service({
greet: async (ctx: restate.Context, name: string) => {
// blocking RPC call to a keyed service (here supplying type and path separately)
const countSoFar = await ctx
.rpc<counterApiType>({ path: "counter" })
.count(name);
const countSoFar = await ctx.object(counterApi, name).count();

const message = `Hello ${name}, for the ${countSoFar + 1}th time!`;

// sending messages to ourselves, immediately and delayed
ctx.send(greeterApi).logger(message);
ctx.sendDelayed(greeterApi, 100).logger("delayed " + message);
ctx.serviceSend(greeterApi).logger(message);
ctx.serviceSendDelayed(greeterApi, 100).logger("delayed " + message);

return message;
},
Expand All @@ -47,21 +35,21 @@ const greeter = restate.router({
// This could in principle be the same service as the greet service, we just separate
// them here to have this multi-service setup for testing.
//
const counter = restate.keyedRouter({
count: async (ctx: restate.KeyedContext): Promise<number> => {
const counter = restate.object({
count: async (ctx: restate.ObjectContext): Promise<number> => {
const seen = (await ctx.get<number>("seen")) ?? 0;
ctx.set("seen", seen + 1);
return seen;
},
});

const greeterApi: restate.ServiceApi<typeof greeter> = { path: "greeter" };
type counterApiType = typeof counter;
const greeterApi = restate.serviceApi("greeter", greeter);
const counterApi = restate.objectApi("counter", counter);

// restate server

restate
.endpoint()
.bindRouter("greeter", greeter)
.bindKeyedRouter("counter", counter)
.service(greeterApi.path, greeter)
.object(counterApi.path, counter)
.listen(9080);
54 changes: 0 additions & 54 deletions examples/grpc_example.ts

This file was deleted.

52 changes: 0 additions & 52 deletions examples/handler_example.ts

This file was deleted.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
"verify": "npm run format-check && npm run lint && npm run test && npm run build",
"release": "release-it",
"example": "RESTATE_DEBUG_LOGGING=OFF ts-node-dev --transpile-only ./examples/example.ts",
"grpcexample": "RESTATE_DEBUG_LOGGING=OFF ts-node-dev --transpile-only ./examples/grpc_example.ts",
"workflowexample": "RESTATE_DEBUG_LOGGING=OFF ts-node-dev --transpile-only ./examples/workflow_example.ts",
"handlerexample": "RESTATE_DEBUG_LOGGING=OFF ts-node-dev --transpile-only ./examples/handler_example.ts",
"expressexample": "RESTATE_DEBUG_LOGGING=OFF ts-node-dev --transpile-only ./examples/embedded_example.ts"
"workflowexample": "RESTATE_DEBUG_LOGGING=OFF ts-node-dev --transpile-only ./examples/workflow_example.ts"
},
"dependencies": {
"protobufjs": "^7.2.2",
Expand Down
48 changes: 0 additions & 48 deletions proto/discovery.proto

This file was deleted.

49 changes: 0 additions & 49 deletions proto/dynrpc.proto

This file was deleted.

Loading
Loading