@restatedev/restate-sdk 0.7.3-worker → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +29 -51
- package/dist/clients/workflow_client.d.ts +77 -0
- package/dist/clients/workflow_client.d.ts.map +1 -0
- package/dist/clients/workflow_client.js +172 -0
- package/dist/clients/workflow_client.js.map +1 -0
- package/dist/connection/buffered_connection.js +44 -0
- package/dist/connection/buffered_connection.js.map +1 -0
- package/dist/connection/connection.js +13 -0
- package/dist/connection/connection.js.map +1 -0
- package/dist/connection/embedded_connection.js +59 -0
- package/dist/connection/embedded_connection.js.map +1 -0
- package/dist/connection/http_connection.js +203 -0
- package/dist/connection/http_connection.js.map +1 -0
- package/dist/connection/lambda_connection.js +58 -0
- package/dist/connection/lambda_connection.js.map +1 -0
- package/dist/{restate_context.d.ts → context.d.ts} +239 -170
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +113 -0
- package/dist/context.js.map +1 -0
- package/dist/{restate_context_impl.d.ts → context_impl.d.ts} +26 -30
- package/dist/context_impl.d.ts.map +1 -0
- package/dist/context_impl.js +439 -0
- package/dist/context_impl.js.map +1 -0
- package/dist/embedded/api.d.ts +2 -2
- package/dist/embedded/api.d.ts.map +1 -1
- package/dist/embedded/api.js +35 -0
- package/dist/embedded/api.js.map +1 -0
- package/dist/embedded/handler.d.ts +2 -2
- package/dist/embedded/handler.d.ts.map +1 -1
- package/dist/embedded/handler.js +26 -0
- package/dist/embedded/handler.js.map +1 -0
- package/dist/embedded/http2_remote.js +91 -0
- package/dist/embedded/http2_remote.js.map +1 -0
- package/dist/embedded/invocation.d.ts.map +1 -1
- package/dist/embedded/invocation.js +94 -0
- package/dist/embedded/invocation.js.map +1 -0
- package/dist/endpoint/endpoint_impl.d.ts +35 -0
- package/dist/endpoint/endpoint_impl.d.ts.map +1 -0
- package/dist/endpoint/endpoint_impl.js +405 -0
- package/dist/endpoint/endpoint_impl.js.map +1 -0
- package/dist/endpoint/http2_handler.d.ts +11 -0
- package/dist/endpoint/http2_handler.d.ts.map +1 -0
- package/dist/endpoint/http2_handler.js +119 -0
- package/dist/endpoint/http2_handler.js.map +1 -0
- package/dist/endpoint/lambda_handler.d.ts +15 -0
- package/dist/endpoint/lambda_handler.d.ts.map +1 -0
- package/dist/endpoint/lambda_handler.js +144 -0
- package/dist/endpoint/lambda_handler.js.map +1 -0
- package/dist/endpoint.d.ts +161 -0
- package/dist/endpoint.d.ts.map +1 -0
- package/dist/endpoint.js +22 -0
- package/dist/endpoint.js.map +1 -0
- package/dist/generated/dev/restate/events.js +371 -0
- package/dist/generated/dev/restate/events.js.map +1 -0
- package/dist/generated/dev/restate/ext.js +215 -0
- package/dist/generated/dev/restate/ext.js.map +1 -0
- package/dist/generated/google/protobuf/descriptor.js +6676 -0
- package/dist/generated/google/protobuf/descriptor.js.map +1 -0
- package/dist/generated/google/protobuf/empty.js +107 -0
- package/dist/generated/google/protobuf/empty.js.map +1 -0
- package/dist/generated/google/protobuf/struct.js +754 -0
- package/dist/generated/google/protobuf/struct.js.map +1 -0
- package/dist/generated/proto/discovery.js +364 -0
- package/dist/generated/proto/discovery.js.map +1 -0
- package/dist/generated/proto/dynrpc.js +668 -0
- package/dist/generated/proto/dynrpc.js.map +1 -0
- package/dist/generated/proto/javascript.d.ts +13 -0
- package/dist/generated/proto/javascript.d.ts.map +1 -1
- package/dist/generated/proto/javascript.js +416 -0
- package/dist/generated/proto/javascript.js.map +1 -0
- package/dist/generated/proto/protocol.d.ts +43 -0
- package/dist/generated/proto/protocol.d.ts.map +1 -1
- package/dist/generated/proto/protocol.js +2641 -0
- package/dist/generated/proto/protocol.js.map +1 -0
- package/dist/generated/proto/services.js +1535 -0
- package/dist/generated/proto/services.js.map +1 -0
- package/dist/generated/proto/test.js +321 -0
- package/dist/generated/proto/test.js.map +1 -0
- package/dist/invocation.d.ts +4 -1
- package/dist/invocation.d.ts.map +1 -1
- package/dist/invocation.js +157 -0
- package/dist/invocation.js.map +1 -0
- package/dist/io/decoder.d.ts +1 -0
- package/dist/io/decoder.d.ts.map +1 -1
- package/dist/io/decoder.js +140 -0
- package/dist/io/decoder.js.map +1 -0
- package/dist/io/encoder.d.ts +1 -2
- package/dist/io/encoder.d.ts.map +1 -1
- package/dist/io/encoder.js +68 -0
- package/dist/io/encoder.js.map +1 -0
- package/dist/journal.d.ts +13 -4
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +405 -0
- package/dist/journal.js.map +1 -0
- package/dist/local_state_store.d.ts +5 -3
- package/dist/local_state_store.d.ts.map +1 -1
- package/dist/local_state_store.js +82 -0
- package/dist/local_state_store.js.map +1 -0
- package/dist/logger.d.ts +19 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +90 -0
- package/dist/logger.js.map +1 -0
- package/dist/promise_combinator_tracker.d.ts +29 -0
- package/dist/promise_combinator_tracker.d.ts.map +1 -0
- package/dist/promise_combinator_tracker.js +128 -0
- package/dist/promise_combinator_tracker.js.map +1 -0
- package/dist/public_api.d.ts +5 -5
- package/dist/public_api.d.ts.map +1 -1
- package/dist/public_api.js +60 -0
- package/dist/public_api.js.map +1 -0
- package/dist/state_machine.d.ts +19 -12
- package/dist/state_machine.d.ts.map +1 -1
- package/dist/state_machine.js +437 -0
- package/dist/state_machine.js.map +1 -0
- package/dist/types/errors.d.ts +12 -3
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +273 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/grpc.d.ts +6 -4
- package/dist/types/grpc.d.ts.map +1 -1
- package/dist/types/grpc.js +81 -0
- package/dist/types/grpc.js.map +1 -0
- package/dist/types/protocol.d.ts +9 -5
- package/dist/types/protocol.d.ts.map +1 -1
- package/dist/types/protocol.js +147 -0
- package/dist/types/protocol.js.map +1 -0
- package/dist/types/router.d.ts +8 -8
- package/dist/types/router.d.ts.map +1 -1
- package/dist/types/router.js +36 -0
- package/dist/types/router.js.map +1 -0
- package/dist/types/types.d.ts +1 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +138 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/{assumpsions.d.ts → assumptions.d.ts} +1 -1
- package/dist/utils/{assumpsions.d.ts.map → assumptions.d.ts.map} +1 -1
- package/dist/utils/assumptions.js +101 -0
- package/dist/utils/assumptions.js.map +1 -0
- package/dist/utils/message_logger.d.ts +28 -0
- package/dist/utils/message_logger.d.ts.map +1 -0
- package/dist/utils/message_logger.js +88 -0
- package/dist/utils/message_logger.js.map +1 -0
- package/dist/utils/promises.d.ts +15 -0
- package/dist/utils/promises.d.ts.map +1 -0
- package/dist/utils/promises.js +67 -0
- package/dist/utils/promises.js.map +1 -0
- package/dist/utils/public_utils.js +49 -0
- package/dist/utils/public_utils.js.map +1 -0
- package/dist/utils/rand.d.ts +1 -1
- package/dist/utils/rand.d.ts.map +1 -1
- package/dist/utils/rand.js +114 -0
- package/dist/utils/rand.js.map +1 -0
- package/dist/utils/utils.d.ts +1 -10
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +122 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist/workflows/workflow.d.ts +101 -0
- package/dist/workflows/workflow.d.ts.map +1 -0
- package/dist/workflows/workflow.js +80 -0
- package/dist/workflows/workflow.js.map +1 -0
- package/dist/workflows/workflow_state_service.d.ts +35 -0
- package/dist/workflows/workflow_state_service.d.ts.map +1 -0
- package/dist/workflows/workflow_state_service.js +201 -0
- package/dist/workflows/workflow_state_service.js.map +1 -0
- package/dist/workflows/workflow_wrapper_service.d.ts +10 -0
- package/dist/workflows/workflow_wrapper_service.d.ts.map +1 -0
- package/dist/workflows/workflow_wrapper_service.js +264 -0
- package/dist/workflows/workflow_wrapper_service.js.map +1 -0
- package/package.json +38 -39
- package/src/clients/workflow_client.ts +290 -0
- package/src/connection/buffered_connection.ts +47 -0
- package/src/connection/connection.ts +34 -0
- package/src/connection/embedded_connection.ts +62 -0
- package/src/connection/http_connection.ts +228 -0
- package/src/connection/lambda_connection.ts +69 -0
- package/src/context.ts +633 -0
- package/src/context_impl.ts +721 -0
- package/src/embedded/api.ts +57 -0
- package/src/embedded/handler.ts +36 -0
- package/src/embedded/http2_remote.ts +103 -0
- package/src/embedded/invocation.ts +126 -0
- package/src/endpoint/endpoint_impl.ts +623 -0
- package/src/endpoint/http2_handler.ts +151 -0
- package/src/endpoint/lambda_handler.ts +181 -0
- package/src/endpoint.ts +187 -0
- package/src/generated/dev/restate/events.ts +430 -0
- package/src/generated/dev/restate/ext.ts +238 -0
- package/src/generated/google/protobuf/descriptor.ts +7889 -0
- package/src/generated/google/protobuf/empty.ts +150 -0
- package/src/generated/google/protobuf/struct.ts +878 -0
- package/src/generated/proto/discovery.ts +423 -0
- package/src/generated/proto/dynrpc.ts +768 -0
- package/src/generated/proto/javascript.ts +488 -0
- package/src/generated/proto/protocol.ts +3091 -0
- package/src/generated/proto/services.ts +1834 -0
- package/src/generated/proto/test.ts +387 -0
- package/src/invocation.ts +212 -0
- package/src/io/decoder.ts +171 -0
- package/src/io/encoder.ts +72 -0
- package/src/journal.ts +537 -0
- package/src/local_state_store.ts +94 -0
- package/src/logger.ts +121 -0
- package/src/promise_combinator_tracker.ts +191 -0
- package/src/public_api.ts +53 -0
- package/src/state_machine.ts +635 -0
- package/src/types/errors.ts +297 -0
- package/src/types/grpc.ts +97 -0
- package/src/types/protocol.ts +201 -0
- package/src/types/router.ts +118 -0
- package/src/types/types.ts +160 -0
- package/src/utils/assumptions.ts +131 -0
- package/src/utils/message_logger.ts +112 -0
- package/src/utils/promises.ts +118 -0
- package/src/utils/public_utils.ts +91 -0
- package/src/utils/rand.ts +142 -0
- package/src/utils/utils.ts +178 -0
- package/src/workflows/workflow.ts +178 -0
- package/src/workflows/workflow_state_service.ts +299 -0
- package/src/workflows/workflow_wrapper_service.ts +314 -0
- package/dist/cloudflare_bundle.js +0 -27387
- package/dist/restate_context.d.ts.map +0 -1
- package/dist/restate_context_impl.d.ts.map +0 -1
- package/dist/server/base_restate_server.d.ts +0 -32
- package/dist/server/base_restate_server.d.ts.map +0 -1
- package/dist/server/restate_lambda_handler.d.ts +0 -104
- package/dist/server/restate_lambda_handler.d.ts.map +0 -1
- package/dist/server/restate_server.d.ts +0 -97
- package/dist/server/restate_server.d.ts.map +0 -1
- package/dist/utils/logger.d.ts +0 -60
- package/dist/utils/logger.d.ts.map +0 -1
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import _m0 from "protobufjs/minimal";
|
|
3
|
+
import { FileDescriptorProto as FileDescriptorProto1 } from "ts-proto-descriptors";
|
|
4
|
+
import { protoMetadata as protoMetadata1 } from "../dev/restate/ext";
|
|
5
|
+
import { Empty, protoMetadata as protoMetadata2 } from "../google/protobuf/empty";
|
|
6
|
+
|
|
7
|
+
export const protobufPackage = "test";
|
|
8
|
+
|
|
9
|
+
export interface TestRequest {
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface TestResponse {
|
|
14
|
+
greeting: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface TestEmpty {
|
|
18
|
+
greeting: Empty | undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function createBaseTestRequest(): TestRequest {
|
|
22
|
+
return { name: "" };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const TestRequest = {
|
|
26
|
+
encode(message: TestRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
|
|
27
|
+
if (message.name !== "") {
|
|
28
|
+
writer.uint32(10).string(message.name);
|
|
29
|
+
}
|
|
30
|
+
return writer;
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): TestRequest {
|
|
34
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
35
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
36
|
+
const message = createBaseTestRequest();
|
|
37
|
+
while (reader.pos < end) {
|
|
38
|
+
const tag = reader.uint32();
|
|
39
|
+
switch (tag >>> 3) {
|
|
40
|
+
case 1:
|
|
41
|
+
if (tag !== 10) {
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
message.name = reader.string();
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
reader.skipType(tag & 7);
|
|
52
|
+
}
|
|
53
|
+
return message;
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
fromJSON(object: any): TestRequest {
|
|
57
|
+
return { name: isSet(object.name) ? globalThis.String(object.name) : "" };
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
toJSON(message: TestRequest): unknown {
|
|
61
|
+
const obj: any = {};
|
|
62
|
+
if (message.name !== "") {
|
|
63
|
+
obj.name = message.name;
|
|
64
|
+
}
|
|
65
|
+
return obj;
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
create(base?: DeepPartial<TestRequest>): TestRequest {
|
|
69
|
+
return TestRequest.fromPartial(base ?? {});
|
|
70
|
+
},
|
|
71
|
+
fromPartial(object: DeepPartial<TestRequest>): TestRequest {
|
|
72
|
+
const message = createBaseTestRequest();
|
|
73
|
+
message.name = object.name ?? "";
|
|
74
|
+
return message;
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
function createBaseTestResponse(): TestResponse {
|
|
79
|
+
return { greeting: "" };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const TestResponse = {
|
|
83
|
+
encode(message: TestResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
|
|
84
|
+
if (message.greeting !== "") {
|
|
85
|
+
writer.uint32(10).string(message.greeting);
|
|
86
|
+
}
|
|
87
|
+
return writer;
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): TestResponse {
|
|
91
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
92
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
93
|
+
const message = createBaseTestResponse();
|
|
94
|
+
while (reader.pos < end) {
|
|
95
|
+
const tag = reader.uint32();
|
|
96
|
+
switch (tag >>> 3) {
|
|
97
|
+
case 1:
|
|
98
|
+
if (tag !== 10) {
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
message.greeting = reader.string();
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
reader.skipType(tag & 7);
|
|
109
|
+
}
|
|
110
|
+
return message;
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
fromJSON(object: any): TestResponse {
|
|
114
|
+
return { greeting: isSet(object.greeting) ? globalThis.String(object.greeting) : "" };
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
toJSON(message: TestResponse): unknown {
|
|
118
|
+
const obj: any = {};
|
|
119
|
+
if (message.greeting !== "") {
|
|
120
|
+
obj.greeting = message.greeting;
|
|
121
|
+
}
|
|
122
|
+
return obj;
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
create(base?: DeepPartial<TestResponse>): TestResponse {
|
|
126
|
+
return TestResponse.fromPartial(base ?? {});
|
|
127
|
+
},
|
|
128
|
+
fromPartial(object: DeepPartial<TestResponse>): TestResponse {
|
|
129
|
+
const message = createBaseTestResponse();
|
|
130
|
+
message.greeting = object.greeting ?? "";
|
|
131
|
+
return message;
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
function createBaseTestEmpty(): TestEmpty {
|
|
136
|
+
return { greeting: undefined };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export const TestEmpty = {
|
|
140
|
+
encode(message: TestEmpty, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
|
|
141
|
+
if (message.greeting !== undefined) {
|
|
142
|
+
Empty.encode(message.greeting, writer.uint32(10).fork()).ldelim();
|
|
143
|
+
}
|
|
144
|
+
return writer;
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): TestEmpty {
|
|
148
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
149
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
150
|
+
const message = createBaseTestEmpty();
|
|
151
|
+
while (reader.pos < end) {
|
|
152
|
+
const tag = reader.uint32();
|
|
153
|
+
switch (tag >>> 3) {
|
|
154
|
+
case 1:
|
|
155
|
+
if (tag !== 10) {
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
message.greeting = Empty.decode(reader, reader.uint32());
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
reader.skipType(tag & 7);
|
|
166
|
+
}
|
|
167
|
+
return message;
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
fromJSON(object: any): TestEmpty {
|
|
171
|
+
return { greeting: isSet(object.greeting) ? Empty.fromJSON(object.greeting) : undefined };
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
toJSON(message: TestEmpty): unknown {
|
|
175
|
+
const obj: any = {};
|
|
176
|
+
if (message.greeting !== undefined) {
|
|
177
|
+
obj.greeting = Empty.toJSON(message.greeting);
|
|
178
|
+
}
|
|
179
|
+
return obj;
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
create(base?: DeepPartial<TestEmpty>): TestEmpty {
|
|
183
|
+
return TestEmpty.fromPartial(base ?? {});
|
|
184
|
+
},
|
|
185
|
+
fromPartial(object: DeepPartial<TestEmpty>): TestEmpty {
|
|
186
|
+
const message = createBaseTestEmpty();
|
|
187
|
+
message.greeting = (object.greeting !== undefined && object.greeting !== null)
|
|
188
|
+
? Empty.fromPartial(object.greeting)
|
|
189
|
+
: undefined;
|
|
190
|
+
return message;
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export interface TestGreeter {
|
|
195
|
+
greet(request: TestRequest): Promise<TestResponse>;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export const TestGreeterServiceName = "test.TestGreeter";
|
|
199
|
+
export class TestGreeterClientImpl implements TestGreeter {
|
|
200
|
+
private readonly rpc: Rpc;
|
|
201
|
+
private readonly service: string;
|
|
202
|
+
constructor(rpc: Rpc, opts?: { service?: string }) {
|
|
203
|
+
this.service = opts?.service || TestGreeterServiceName;
|
|
204
|
+
this.rpc = rpc;
|
|
205
|
+
this.greet = this.greet.bind(this);
|
|
206
|
+
}
|
|
207
|
+
greet(request: TestRequest): Promise<TestResponse> {
|
|
208
|
+
const data = TestRequest.encode(request).finish();
|
|
209
|
+
const promise = this.rpc.request(this.service, "Greet", data);
|
|
210
|
+
return promise.then((data) => TestResponse.decode(_m0.Reader.create(data)));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
interface Rpc {
|
|
215
|
+
request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
type ProtoMetaMessageOptions = {
|
|
219
|
+
options?: { [key: string]: any };
|
|
220
|
+
fields?: { [key: string]: { [key: string]: any } };
|
|
221
|
+
oneof?: { [key: string]: { [key: string]: any } };
|
|
222
|
+
nested?: { [key: string]: ProtoMetaMessageOptions };
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
export interface ProtoMetadata {
|
|
226
|
+
fileDescriptor: FileDescriptorProto1;
|
|
227
|
+
references: { [key: string]: any };
|
|
228
|
+
dependencies?: ProtoMetadata[];
|
|
229
|
+
options?: {
|
|
230
|
+
options?: { [key: string]: any };
|
|
231
|
+
services?: {
|
|
232
|
+
[key: string]: { options?: { [key: string]: any }; methods?: { [key: string]: { [key: string]: any } } };
|
|
233
|
+
};
|
|
234
|
+
messages?: { [key: string]: ProtoMetaMessageOptions };
|
|
235
|
+
enums?: { [key: string]: { options?: { [key: string]: any }; values?: { [key: string]: { [key: string]: any } } } };
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export const protoMetadata: ProtoMetadata = {
|
|
240
|
+
fileDescriptor: FileDescriptorProto1.fromPartial({
|
|
241
|
+
"name": "proto/test.proto",
|
|
242
|
+
"package": "test",
|
|
243
|
+
"dependency": ["dev/restate/ext.proto", "google/protobuf/empty.proto"],
|
|
244
|
+
"publicDependency": [],
|
|
245
|
+
"weakDependency": [],
|
|
246
|
+
"messageType": [{
|
|
247
|
+
"name": "TestRequest",
|
|
248
|
+
"field": [{
|
|
249
|
+
"name": "name",
|
|
250
|
+
"number": 1,
|
|
251
|
+
"label": 1,
|
|
252
|
+
"type": 9,
|
|
253
|
+
"typeName": "",
|
|
254
|
+
"extendee": "",
|
|
255
|
+
"defaultValue": "",
|
|
256
|
+
"oneofIndex": 0,
|
|
257
|
+
"jsonName": "name",
|
|
258
|
+
"options": {
|
|
259
|
+
"ctype": 0,
|
|
260
|
+
"packed": false,
|
|
261
|
+
"jstype": 0,
|
|
262
|
+
"lazy": false,
|
|
263
|
+
"deprecated": false,
|
|
264
|
+
"weak": false,
|
|
265
|
+
"uninterpretedOption": [],
|
|
266
|
+
},
|
|
267
|
+
"proto3Optional": false,
|
|
268
|
+
}],
|
|
269
|
+
"extension": [],
|
|
270
|
+
"nestedType": [],
|
|
271
|
+
"enumType": [],
|
|
272
|
+
"extensionRange": [],
|
|
273
|
+
"oneofDecl": [],
|
|
274
|
+
"options": undefined,
|
|
275
|
+
"reservedRange": [],
|
|
276
|
+
"reservedName": [],
|
|
277
|
+
}, {
|
|
278
|
+
"name": "TestResponse",
|
|
279
|
+
"field": [{
|
|
280
|
+
"name": "greeting",
|
|
281
|
+
"number": 1,
|
|
282
|
+
"label": 1,
|
|
283
|
+
"type": 9,
|
|
284
|
+
"typeName": "",
|
|
285
|
+
"extendee": "",
|
|
286
|
+
"defaultValue": "",
|
|
287
|
+
"oneofIndex": 0,
|
|
288
|
+
"jsonName": "greeting",
|
|
289
|
+
"options": undefined,
|
|
290
|
+
"proto3Optional": false,
|
|
291
|
+
}],
|
|
292
|
+
"extension": [],
|
|
293
|
+
"nestedType": [],
|
|
294
|
+
"enumType": [],
|
|
295
|
+
"extensionRange": [],
|
|
296
|
+
"oneofDecl": [],
|
|
297
|
+
"options": undefined,
|
|
298
|
+
"reservedRange": [],
|
|
299
|
+
"reservedName": [],
|
|
300
|
+
}, {
|
|
301
|
+
"name": "TestEmpty",
|
|
302
|
+
"field": [{
|
|
303
|
+
"name": "greeting",
|
|
304
|
+
"number": 1,
|
|
305
|
+
"label": 1,
|
|
306
|
+
"type": 11,
|
|
307
|
+
"typeName": ".google.protobuf.Empty",
|
|
308
|
+
"extendee": "",
|
|
309
|
+
"defaultValue": "",
|
|
310
|
+
"oneofIndex": 0,
|
|
311
|
+
"jsonName": "greeting",
|
|
312
|
+
"options": undefined,
|
|
313
|
+
"proto3Optional": false,
|
|
314
|
+
}],
|
|
315
|
+
"extension": [],
|
|
316
|
+
"nestedType": [],
|
|
317
|
+
"enumType": [],
|
|
318
|
+
"extensionRange": [],
|
|
319
|
+
"oneofDecl": [],
|
|
320
|
+
"options": undefined,
|
|
321
|
+
"reservedRange": [],
|
|
322
|
+
"reservedName": [],
|
|
323
|
+
}],
|
|
324
|
+
"enumType": [],
|
|
325
|
+
"service": [{
|
|
326
|
+
"name": "TestGreeter",
|
|
327
|
+
"method": [{
|
|
328
|
+
"name": "Greet",
|
|
329
|
+
"inputType": ".test.TestRequest",
|
|
330
|
+
"outputType": ".test.TestResponse",
|
|
331
|
+
"options": { "deprecated": false, "idempotencyLevel": 0, "uninterpretedOption": [] },
|
|
332
|
+
"clientStreaming": false,
|
|
333
|
+
"serverStreaming": false,
|
|
334
|
+
}],
|
|
335
|
+
"options": { "deprecated": false, "uninterpretedOption": [] },
|
|
336
|
+
}],
|
|
337
|
+
"extension": [],
|
|
338
|
+
"options": {
|
|
339
|
+
"javaPackage": "com.test",
|
|
340
|
+
"javaOuterClassname": "TestProto",
|
|
341
|
+
"javaMultipleFiles": true,
|
|
342
|
+
"javaGenerateEqualsAndHash": false,
|
|
343
|
+
"javaStringCheckUtf8": false,
|
|
344
|
+
"optimizeFor": 1,
|
|
345
|
+
"goPackage": "",
|
|
346
|
+
"ccGenericServices": false,
|
|
347
|
+
"javaGenericServices": false,
|
|
348
|
+
"pyGenericServices": false,
|
|
349
|
+
"phpGenericServices": false,
|
|
350
|
+
"deprecated": false,
|
|
351
|
+
"ccEnableArenas": false,
|
|
352
|
+
"objcClassPrefix": "TXX",
|
|
353
|
+
"csharpNamespace": "Test",
|
|
354
|
+
"swiftPrefix": "",
|
|
355
|
+
"phpClassPrefix": "",
|
|
356
|
+
"phpNamespace": "Test",
|
|
357
|
+
"phpMetadataNamespace": "Test\\GPBMetadata",
|
|
358
|
+
"rubyPackage": "Test",
|
|
359
|
+
"uninterpretedOption": [],
|
|
360
|
+
},
|
|
361
|
+
"sourceCodeInfo": { "location": [] },
|
|
362
|
+
"syntax": "proto3",
|
|
363
|
+
}),
|
|
364
|
+
references: {
|
|
365
|
+
".test.TestRequest": TestRequest,
|
|
366
|
+
".test.TestResponse": TestResponse,
|
|
367
|
+
".test.TestEmpty": TestEmpty,
|
|
368
|
+
".test.TestGreeter": TestGreeterClientImpl,
|
|
369
|
+
},
|
|
370
|
+
dependencies: [protoMetadata1, protoMetadata2],
|
|
371
|
+
options: {
|
|
372
|
+
messages: { "TestRequest": { fields: { "name": { "field": 0 } } } },
|
|
373
|
+
services: { "TestGreeter": { options: { "service_type": 1 }, methods: {} } },
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
378
|
+
|
|
379
|
+
export type DeepPartial<T> = T extends Builtin ? T
|
|
380
|
+
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
|
|
381
|
+
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
|
|
382
|
+
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
|
|
383
|
+
: Partial<T>;
|
|
384
|
+
|
|
385
|
+
function isSet(value: any): boolean {
|
|
386
|
+
return value !== null && value !== undefined;
|
|
387
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
|
|
3
|
+
*
|
|
4
|
+
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
5
|
+
* which is released under the MIT license.
|
|
6
|
+
*
|
|
7
|
+
* You can find a copy of the license in file LICENSE in the root
|
|
8
|
+
* directory of this repository or package, or at
|
|
9
|
+
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/*eslint-disable @typescript-eslint/no-non-null-assertion*/
|
|
13
|
+
|
|
14
|
+
import { Message } from "./types/types";
|
|
15
|
+
import { HostedGrpcServiceMethod } from "./types/grpc";
|
|
16
|
+
import {
|
|
17
|
+
Failure,
|
|
18
|
+
PollInputStreamEntryMessage,
|
|
19
|
+
StartMessage,
|
|
20
|
+
} from "./generated/proto/protocol";
|
|
21
|
+
import { formatMessageAsJson } from "./utils/utils";
|
|
22
|
+
import {
|
|
23
|
+
POLL_INPUT_STREAM_ENTRY_MESSAGE_TYPE,
|
|
24
|
+
START_MESSAGE_TYPE,
|
|
25
|
+
} from "./types/protocol";
|
|
26
|
+
import { RestateStreamConsumer } from "./connection/connection";
|
|
27
|
+
import { LocalStateStore } from "./local_state_store";
|
|
28
|
+
import { ensureError } from "./types/errors";
|
|
29
|
+
import { LoggerContext } from "./logger";
|
|
30
|
+
import { CompletablePromise } from "./utils/promises";
|
|
31
|
+
|
|
32
|
+
enum State {
|
|
33
|
+
ExpectingStart = 0,
|
|
34
|
+
ExpectingInput = 1,
|
|
35
|
+
ExpectingFurtherReplay = 2,
|
|
36
|
+
Complete = 3,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type InvocationValue =
|
|
40
|
+
| { kind: "value"; value: Buffer }
|
|
41
|
+
| { kind: "failure"; failure: Failure };
|
|
42
|
+
|
|
43
|
+
export class InvocationBuilder<I, O> implements RestateStreamConsumer {
|
|
44
|
+
private readonly complete = new CompletablePromise<void>();
|
|
45
|
+
|
|
46
|
+
private state: State = State.ExpectingStart;
|
|
47
|
+
|
|
48
|
+
private runtimeReplayIndex = 0;
|
|
49
|
+
private replayEntries = new Map<number, Message>();
|
|
50
|
+
private id?: Buffer = undefined;
|
|
51
|
+
private debugId?: string = undefined;
|
|
52
|
+
private invocationValue?: InvocationValue = undefined;
|
|
53
|
+
private nbEntriesToReplay?: number = undefined;
|
|
54
|
+
private localStateStore?: LocalStateStore;
|
|
55
|
+
|
|
56
|
+
constructor(private readonly method: HostedGrpcServiceMethod<I, O>) {}
|
|
57
|
+
|
|
58
|
+
public handleMessage(m: Message): boolean {
|
|
59
|
+
try {
|
|
60
|
+
switch (this.state) {
|
|
61
|
+
case State.ExpectingStart:
|
|
62
|
+
checkState(State.ExpectingStart, START_MESSAGE_TYPE, m);
|
|
63
|
+
this.handleStartMessage(m.message as StartMessage);
|
|
64
|
+
this.state = State.ExpectingInput;
|
|
65
|
+
return false;
|
|
66
|
+
|
|
67
|
+
case State.ExpectingInput:
|
|
68
|
+
checkState(
|
|
69
|
+
State.ExpectingInput,
|
|
70
|
+
POLL_INPUT_STREAM_ENTRY_MESSAGE_TYPE,
|
|
71
|
+
m
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
this.handlePollInputStreamEntry(m);
|
|
75
|
+
this.addReplayEntry(m);
|
|
76
|
+
break;
|
|
77
|
+
|
|
78
|
+
case State.ExpectingFurtherReplay:
|
|
79
|
+
this.addReplayEntry(m);
|
|
80
|
+
break;
|
|
81
|
+
|
|
82
|
+
case State.Complete:
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Journal builder is getting a message after the journal was complete. entries-to-replay: ${
|
|
85
|
+
this.nbEntriesToReplay
|
|
86
|
+
}, message: ${formatMessageAsJson(m)}`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.state =
|
|
91
|
+
this.replayEntries.size === this.nbEntriesToReplay
|
|
92
|
+
? State.Complete
|
|
93
|
+
: State.ExpectingFurtherReplay;
|
|
94
|
+
|
|
95
|
+
if (this.state === State.Complete) {
|
|
96
|
+
this.complete.resolve();
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return false;
|
|
101
|
+
} catch (e) {
|
|
102
|
+
const error = ensureError(e);
|
|
103
|
+
this.complete.reject(error);
|
|
104
|
+
return true; // we want no further messages
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private handlePollInputStreamEntry(m: Message) {
|
|
109
|
+
const pollInputStreamMessage = m.message as PollInputStreamEntryMessage;
|
|
110
|
+
|
|
111
|
+
if (pollInputStreamMessage.value !== undefined) {
|
|
112
|
+
this.invocationValue = {
|
|
113
|
+
kind: "value",
|
|
114
|
+
value: pollInputStreamMessage.value,
|
|
115
|
+
};
|
|
116
|
+
} else if (pollInputStreamMessage.failure !== undefined) {
|
|
117
|
+
this.invocationValue = {
|
|
118
|
+
kind: "failure",
|
|
119
|
+
failure: pollInputStreamMessage.failure,
|
|
120
|
+
};
|
|
121
|
+
} else {
|
|
122
|
+
throw new Error(
|
|
123
|
+
`PollInputStreamEntry neither contains value nor failure: ${formatMessageAsJson(
|
|
124
|
+
m
|
|
125
|
+
)}`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public handleStreamError(e: Error): void {
|
|
131
|
+
this.complete.reject(e);
|
|
132
|
+
}
|
|
133
|
+
public handleInputClosed(): void {
|
|
134
|
+
this.complete.reject(new Error("Input closed before journal is complete"));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public completion(): Promise<void> {
|
|
138
|
+
return this.complete.promise;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private handleStartMessage(m: StartMessage): InvocationBuilder<I, O> {
|
|
142
|
+
this.nbEntriesToReplay = m.knownEntries;
|
|
143
|
+
this.id = m.id;
|
|
144
|
+
this.debugId = m.debugId;
|
|
145
|
+
this.localStateStore = new LocalStateStore(m.partialState, m.stateMap);
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private addReplayEntry(m: Message): InvocationBuilder<I, O> {
|
|
150
|
+
// Will be retrieved when the user code reaches this point
|
|
151
|
+
this.replayEntries.set(this.runtimeReplayIndex, m);
|
|
152
|
+
this.incrementRuntimeReplayIndex();
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private incrementRuntimeReplayIndex() {
|
|
157
|
+
this.runtimeReplayIndex++;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public isComplete(): boolean {
|
|
161
|
+
return this.state === State.Complete;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
public build(): Invocation<I, O> {
|
|
165
|
+
if (!this.isComplete()) {
|
|
166
|
+
throw new Error(
|
|
167
|
+
`Cannot build invocation. Not all data present: ${JSON.stringify(this)}`
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
return new Invocation(
|
|
171
|
+
this.method!,
|
|
172
|
+
this.id!,
|
|
173
|
+
this.debugId!,
|
|
174
|
+
this.nbEntriesToReplay!,
|
|
175
|
+
this.replayEntries!,
|
|
176
|
+
this.invocationValue!,
|
|
177
|
+
this.localStateStore!
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export class Invocation<I, O> {
|
|
183
|
+
constructor(
|
|
184
|
+
public readonly method: HostedGrpcServiceMethod<I, O>,
|
|
185
|
+
public readonly id: Buffer,
|
|
186
|
+
public readonly debugId: string,
|
|
187
|
+
public readonly nbEntriesToReplay: number,
|
|
188
|
+
public readonly replayEntries: Map<number, Message>,
|
|
189
|
+
public readonly invocationValue: InvocationValue,
|
|
190
|
+
public readonly localStateStore: LocalStateStore
|
|
191
|
+
) {}
|
|
192
|
+
|
|
193
|
+
public inferLoggerContext(additionalContext?: {
|
|
194
|
+
[name: string]: string;
|
|
195
|
+
}): LoggerContext {
|
|
196
|
+
return new LoggerContext(
|
|
197
|
+
this.debugId,
|
|
198
|
+
this.method.pkg,
|
|
199
|
+
this.method.service,
|
|
200
|
+
this.method.method.name,
|
|
201
|
+
additionalContext
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function checkState(state: State, expected: bigint, m: Message) {
|
|
207
|
+
if (m.messageType !== expected) {
|
|
208
|
+
throw new Error(
|
|
209
|
+
`Unexpected message in state ${state}: ${formatMessageAsJson(m)}`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
}
|