Skip to content

Commit 3f43ecc

Browse files
committed
Remove getOutput
1 parent f9f7bca commit 3f43ecc

File tree

5 files changed

+1462
-1153
lines changed

5 files changed

+1462
-1153
lines changed

packages/restate-sdk/src/common_api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export type {
2222
InvocationHandle,
2323
InvocationPromise,
2424
} from "./context.js";
25-
export { CombineablePromise } from "./context.js";
25+
export { InvocationIdParser, CombineablePromise } from "./context.js";
2626

2727
export type { Serde } from "@restatedev/restate-sdk-core";
2828
export { serde } from "@restatedev/restate-sdk-core";

packages/restate-sdk/src/context.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -554,19 +554,16 @@ export interface Context extends RestateContext {
554554
*/
555555
cancel(invocationId: InvocationId): void;
556556

557-
/**
558-
* Get the output of an invocation
559-
*
560-
* @param invocationId the invocation id to get the output for
561-
*/
562-
getOutput<T>(invocationId: InvocationId): CombineablePromise<T>;
563-
564557
/**
565558
* Attach to an invocation
566559
*
567560
* @param invocationId the invocation id to attach to
561+
* @param serde the serde to use for the result, default to JSON serde.
568562
*/
569-
attach<T>(invocationId: InvocationId): CombineablePromise<T>;
563+
attach<T>(
564+
invocationId: InvocationId,
565+
serde?: Serde<T>
566+
): CombineablePromise<T>;
570567
}
571568

572569
/**
@@ -654,8 +651,27 @@ export type CombineablePromise<T> = Promise<T> & {
654651
orTimeout(millis: number): CombineablePromise<T>;
655652
};
656653

654+
/**
655+
* Represents an invocation id.
656+
* @see {@link InvocationIdParser}
657+
*/
657658
export type InvocationId = string & { __brand: "InvocationId" };
658659

660+
export const InvocationIdParser = {
661+
/**
662+
* Creates an invocation id from a string.
663+
* @param id the string to use as invocation id.
664+
*/
665+
fromString(id: string): InvocationId {
666+
if (!id.startsWith("inv")) {
667+
throw new Error(
668+
`Expected invocation id to start with 'inv' but got ${id}`
669+
);
670+
}
671+
return id as InvocationId;
672+
},
673+
};
674+
659675
// eslint-disable-next-line @typescript-eslint/no-unused-vars
660676
export type InvocationHandle = {
661677
invocationId(): Promise<InvocationId>;

packages/restate-sdk/src/context_impl.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,6 @@ export class ContextImpl implements ObjectContext, WorkflowContext {
141141
);
142142
}
143143

144-
getOutput<T>(invocationId: InvocationId): CombineablePromise<T> {
145-
return this.processCompletableEntry(
146-
(vm) => vm.sys_get_invocation_output(invocationId),
147-
completeUsing(SuccessWithSerde(defaultSerde()), Failure)
148-
);
149-
}
150-
151144
public get key(): string {
152145
switch (this.handlerKind) {
153146
case HandlerKind.EXCLUSIVE:

packages/restate-sdk/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,45 @@ export enum LogLevel {
1717
ERROR = 4,
1818
}
1919
export interface WasmFailure {
20-
code: number;
21-
message: string;
20+
code: number;
21+
message: string;
2222
}
2323

2424
export interface WasmExponentialRetryConfig {
25-
initial_interval: number | undefined;
26-
factor: number;
27-
max_interval: number | undefined;
28-
max_attempts: number | undefined;
29-
max_duration: number | undefined;
25+
initial_interval: number | undefined;
26+
factor: number;
27+
max_interval: number | undefined;
28+
max_attempts: number | undefined;
29+
max_duration: number | undefined;
3030
}
3131

3232
export interface WasmAwakeable {
33-
id: string;
34-
handle: number;
33+
id: string;
34+
handle: number;
3535
}
3636

37-
export type WasmAsyncResultValue = "NotReady" | "Empty" | { Success: Uint8Array } | { Failure: WasmFailure } | { StateKeys: string[] } | { InvocationId: string };
37+
export type WasmAsyncResultValue =
38+
| "NotReady"
39+
| "Empty"
40+
| { Success: Uint8Array }
41+
| { Failure: WasmFailure }
42+
| { StateKeys: string[] }
43+
| { InvocationId: string };
3844

39-
export type WasmDoProgressResult = "AnyCompleted" | "ReadFromInput" | "WaitingPendingRun" | { ExecuteRun: number } | "CancelSignalReceived";
45+
export type WasmDoProgressResult =
46+
| "AnyCompleted"
47+
| "ReadFromInput"
48+
| "WaitingPendingRun"
49+
| { ExecuteRun: number }
50+
| "CancelSignalReceived";
4051

4152
export interface WasmCallHandle {
42-
invocation_id_completion_id: number;
43-
call_completion_id: number;
53+
invocation_id_completion_id: number;
54+
call_completion_id: number;
4455
}
4556

4657
export interface WasmSendHandle {
47-
invocation_id_completion_id: number;
58+
invocation_id_completion_id: number;
4859
}
4960

5061
export class WasmHeader {
@@ -93,8 +104,21 @@ export class WasmVM {
93104
sys_sleep(millis: bigint): number;
94105
sys_attach_invocation(invocation_id: string): number;
95106
sys_get_invocation_output(invocation_id: string): number;
96-
sys_call(service: string, handler: string, buffer: Uint8Array, key: string | null | undefined, headers: WasmHeader[]): WasmCallHandle;
97-
sys_send(service: string, handler: string, buffer: Uint8Array, key: string | null | undefined, headers: WasmHeader[], delay?: bigint | null): WasmSendHandle;
107+
sys_call(
108+
service: string,
109+
handler: string,
110+
buffer: Uint8Array,
111+
key: string | null | undefined,
112+
headers: WasmHeader[]
113+
): WasmCallHandle;
114+
sys_send(
115+
service: string,
116+
handler: string,
117+
buffer: Uint8Array,
118+
key: string | null | undefined,
119+
headers: WasmHeader[],
120+
delay?: bigint | null
121+
): WasmSendHandle;
98122
sys_awakeable(): WasmAwakeable;
99123
sys_complete_awakeable_success(id: string, buffer: Uint8Array): void;
100124
sys_complete_awakeable_failure(id: string, value: WasmFailure): void;
@@ -105,11 +129,16 @@ export class WasmVM {
105129
sys_run(name: string): number;
106130
propose_run_completion_success(handle: number, buffer: Uint8Array): void;
107131
propose_run_completion_failure(handle: number, value: WasmFailure): void;
108-
propose_run_completion_failure_transient(handle: number, error_message: string, error_stacktrace: string | null | undefined, attempt_duration: bigint, config: WasmExponentialRetryConfig): void;
132+
propose_run_completion_failure_transient(
133+
handle: number,
134+
error_message: string,
135+
error_stacktrace: string | null | undefined,
136+
attempt_duration: bigint,
137+
config: WasmExponentialRetryConfig
138+
): void;
109139
sys_cancel_invocation(target_invocation_id: string): void;
110140
sys_write_output_success(buffer: Uint8Array): void;
111141
sys_write_output_failure(value: WasmFailure): void;
112142
sys_end(): void;
113143
is_processing(): boolean;
114144
}
115-

packages/restate-sdk/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js

Lines changed: 1390 additions & 1119 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)