Skip to content

Commit c955bb2

Browse files
committed
Awakeable identifiers following the new ID scheme
Test Plan: Using sample code to generate an awakeable and resolved it with ``` curl localhost:8080/dev.restate.Awakeables/Resolve -H 'content-type: application/json' -d '{"id": "awk_1NMyOAvDK2CcBjUH4Rmb7eGBp0DNNDnmsAAAAAQ", "json_result": ""}' ``` ``` [restate] [2024-01-25T18:54:01.682Z] DEBUG: [CheckoutProcess/checkout] [inv_13q6r7rhzaG85fs0bfyqW8cubIUYJFjvBT] : Resuming (replaying) function. Awakeable is: awk_1NMyOAvDK2CcBjUH4Rmb7eGBp0DNNDnmsAAAAAQ Awakeable COMPLETED awk_1NMyOAvDK2CcBjUH4Rmb7eGBp0DNNDnmsAAAAAQ ```
1 parent 766a642 commit c955bb2

File tree

6 files changed

+12
-8
lines changed

6 files changed

+12
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@restatedev/restate-sdk",
3-
"version": "0.7.0",
3+
"version": "0.8.0",
44
"description": "Typescript SDK for Restate",
55
"engines": {
66
"node": ">= 10"

src/restate_context_impl.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
} from "./generated/proto/protocol";
2929
import {
3030
AWAKEABLE_ENTRY_MESSAGE_TYPE,
31+
AWAKEABLE_IDENTIFIER_PREFIX,
3132
BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE,
3233
CLEAR_STATE_ENTRY_MESSAGE_TYPE,
3334
COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE,
@@ -59,7 +60,7 @@ import {
5960
import { rlog } from "./utils/logger";
6061
import { Client, SendClient } from "./types/router";
6162
import { RpcRequest, RpcResponse } from "./generated/proto/dynrpc";
62-
import { requestFromArgs } from "./utils/assumpsions";
63+
import { requestFromArgs } from "./utils/assumptions";
6364
import { RandImpl } from "./utils/rand";
6465

6566
export enum CallContexType {
@@ -364,7 +365,7 @@ export class RestateGrpcContextImpl implements RestateGrpcContext {
364365
);
365366

366367
return {
367-
id: Buffer.concat([this.id, encodedEntryIndex]).toString("base64url"),
368+
id: AWAKEABLE_IDENTIFIER_PREFIX + Buffer.concat([this.id, encodedEntryIndex]).toString("base64url"),
368369
promise: promise,
369370
};
370371
}

src/server/base_restate_server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import {
4646
} from "../generated/proto/dynrpc";
4747
import { RestateContext, useContext } from "../restate_context";
4848
import { RpcContextImpl } from "../restate_context_impl";
49-
import { verifyAssumptions } from "../utils/assumpsions";
49+
import { verifyAssumptions } from "../utils/assumptions";
5050
import { TerminalError } from "../public_api";
5151
import { isEventHandler } from "../types/router";
5252
import { jsonSafeAny } from "../utils/utils";

src/types/protocol.ts

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export const BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE = 0x0c02n;
6767
export const AWAKEABLE_ENTRY_MESSAGE_TYPE = 0x0c03n;
6868
export const COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE = 0x0c04n;
6969

70+
export const AWAKEABLE_IDENTIFIER_PREFIX = "prom_1";
71+
7072
// Export the custom message types
7173
// Side effects are custom messages because the runtime does not need to inspect them
7274
export const SIDE_EFFECT_ENTRY_MESSAGE_TYPE = 0xfc01n;

src/utils/assumpsions.ts renamed to src/utils/assumptions.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ export const verifyAssumptions = (
7676
isKeyed: boolean,
7777
request: RpcRequest
7878
): { key?: string; request?: JsType } => {
79-
const assumpsion = request.senderAssumes ?? 0;
80-
switch (assumpsion) {
79+
const assumption = request.senderAssumes ?? 0;
80+
switch (assumption) {
8181
case 0: {
8282
// no assumption: this comes from an ingress.
8383
const hasKeyProperty =
@@ -124,7 +124,7 @@ export const verifyAssumptions = (
124124
}
125125
default: {
126126
throw new TerminalError(
127-
`Unknown assumption id ${assumpsion}. This indicates an incorrect (or involuntary) setting of the assumption property at the ingress request, or an SDK bug.`
127+
`Unknown assumption id ${assumption}. This indicates an incorrect (or involuntary) setting of the assumption property at the ingress request, or an SDK bug.`
128128
);
129129
}
130130
}

test/protoutils.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
EntryAckMessage,
4646
END_MESSAGE_TYPE,
4747
EndMessage,
48+
AWAKEABLE_IDENTIFIER_PREFIX,
4849
} from "../src/types/protocol";
4950
import { Message } from "../src/types/types";
5051
import { TestRequest, TestResponse } from "../src/generated/proto/test";
@@ -487,7 +488,7 @@ export function getAwakeableId(entryIndex: number): string {
487488
const encodedEntryIndex = Buffer.alloc(4 /* Size of u32 */);
488489
encodedEntryIndex.writeUInt32BE(entryIndex);
489490

490-
return Buffer.concat([
491+
return AWAKEABLE_IDENTIFIER_PREFIX + Buffer.concat([
491492
Buffer.from("f311f1fdcb9863f0018bd3400ecd7d69b547204e776218b2", "hex"),
492493
encodedEntryIndex,
493494
]).toString("base64url");

0 commit comments

Comments
 (0)