@restatedev/restate-sdk 0.0.0-SNAPSHOT-20231025205407

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.
Files changed (163) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +157 -0
  3. package/dist/connection/connection.d.ts +19 -0
  4. package/dist/connection/connection.d.ts.map +1 -0
  5. package/dist/connection/connection.js +13 -0
  6. package/dist/connection/connection.js.map +1 -0
  7. package/dist/connection/embedded_connection.d.ts +22 -0
  8. package/dist/connection/embedded_connection.d.ts.map +1 -0
  9. package/dist/connection/embedded_connection.js +78 -0
  10. package/dist/connection/embedded_connection.js.map +1 -0
  11. package/dist/connection/http_connection.d.ts +73 -0
  12. package/dist/connection/http_connection.d.ts.map +1 -0
  13. package/dist/connection/http_connection.js +203 -0
  14. package/dist/connection/http_connection.js.map +1 -0
  15. package/dist/connection/lambda_connection.d.ts +14 -0
  16. package/dist/connection/lambda_connection.d.ts.map +1 -0
  17. package/dist/connection/lambda_connection.js +56 -0
  18. package/dist/connection/lambda_connection.js.map +1 -0
  19. package/dist/embedded/api.d.ts +18 -0
  20. package/dist/embedded/api.d.ts.map +1 -0
  21. package/dist/embedded/api.js +37 -0
  22. package/dist/embedded/api.js.map +1 -0
  23. package/dist/embedded/handler.d.ts +4 -0
  24. package/dist/embedded/handler.d.ts.map +1 -0
  25. package/dist/embedded/handler.js +28 -0
  26. package/dist/embedded/handler.js.map +1 -0
  27. package/dist/embedded/http2_remote.d.ts +10 -0
  28. package/dist/embedded/http2_remote.d.ts.map +1 -0
  29. package/dist/embedded/http2_remote.js +85 -0
  30. package/dist/embedded/http2_remote.js.map +1 -0
  31. package/dist/embedded/invocation.d.ts +4 -0
  32. package/dist/embedded/invocation.d.ts.map +1 -0
  33. package/dist/embedded/invocation.js +90 -0
  34. package/dist/embedded/invocation.js.map +1 -0
  35. package/dist/generated/dev/restate/events.d.ts +96 -0
  36. package/dist/generated/dev/restate/events.d.ts.map +1 -0
  37. package/dist/generated/dev/restate/events.js +371 -0
  38. package/dist/generated/dev/restate/events.js.map +1 -0
  39. package/dist/generated/dev/restate/ext.d.ts +88 -0
  40. package/dist/generated/dev/restate/ext.d.ts.map +1 -0
  41. package/dist/generated/dev/restate/ext.js +212 -0
  42. package/dist/generated/dev/restate/ext.js.map +1 -0
  43. package/dist/generated/google/protobuf/descriptor.d.ts +1204 -0
  44. package/dist/generated/google/protobuf/descriptor.d.ts.map +1 -0
  45. package/dist/generated/google/protobuf/descriptor.js +6676 -0
  46. package/dist/generated/google/protobuf/descriptor.js.map +1 -0
  47. package/dist/generated/google/protobuf/empty.d.ts +86 -0
  48. package/dist/generated/google/protobuf/empty.d.ts.map +1 -0
  49. package/dist/generated/google/protobuf/empty.js +107 -0
  50. package/dist/generated/google/protobuf/empty.js.map +1 -0
  51. package/dist/generated/google/protobuf/struct.d.ts +175 -0
  52. package/dist/generated/google/protobuf/struct.d.ts.map +1 -0
  53. package/dist/generated/google/protobuf/struct.js +754 -0
  54. package/dist/generated/google/protobuf/struct.js.map +1 -0
  55. package/dist/generated/proto/discovery.d.ts +105 -0
  56. package/dist/generated/proto/discovery.d.ts.map +1 -0
  57. package/dist/generated/proto/discovery.js +364 -0
  58. package/dist/generated/proto/discovery.js.map +1 -0
  59. package/dist/generated/proto/dynrpc.d.ts +150 -0
  60. package/dist/generated/proto/dynrpc.d.ts.map +1 -0
  61. package/dist/generated/proto/dynrpc.js +668 -0
  62. package/dist/generated/proto/dynrpc.js.map +1 -0
  63. package/dist/generated/proto/javascript.d.ts +97 -0
  64. package/dist/generated/proto/javascript.d.ts.map +1 -0
  65. package/dist/generated/proto/javascript.js +297 -0
  66. package/dist/generated/proto/javascript.js.map +1 -0
  67. package/dist/generated/proto/protocol.d.ts +371 -0
  68. package/dist/generated/proto/protocol.d.ts.map +1 -0
  69. package/dist/generated/proto/protocol.js +2179 -0
  70. package/dist/generated/proto/protocol.js.map +1 -0
  71. package/dist/generated/proto/services.d.ts +307 -0
  72. package/dist/generated/proto/services.d.ts.map +1 -0
  73. package/dist/generated/proto/services.js +1535 -0
  74. package/dist/generated/proto/services.js.map +1 -0
  75. package/dist/generated/proto/test.d.ts +116 -0
  76. package/dist/generated/proto/test.d.ts.map +1 -0
  77. package/dist/generated/proto/test.js +321 -0
  78. package/dist/generated/proto/test.js.map +1 -0
  79. package/dist/invocation.d.ts +39 -0
  80. package/dist/invocation.d.ts.map +1 -0
  81. package/dist/invocation.js +138 -0
  82. package/dist/invocation.js.map +1 -0
  83. package/dist/io/decoder.d.ts +8 -0
  84. package/dist/io/decoder.d.ts.map +1 -0
  85. package/dist/io/decoder.js +133 -0
  86. package/dist/io/decoder.js.map +1 -0
  87. package/dist/io/encoder.d.ts +7 -0
  88. package/dist/io/encoder.d.ts.map +1 -0
  89. package/dist/io/encoder.js +57 -0
  90. package/dist/io/encoder.js.map +1 -0
  91. package/dist/journal.d.ts +42 -0
  92. package/dist/journal.d.ts.map +1 -0
  93. package/dist/journal.js +368 -0
  94. package/dist/journal.js.map +1 -0
  95. package/dist/local_state_store.d.ts +13 -0
  96. package/dist/local_state_store.d.ts.map +1 -0
  97. package/dist/local_state_store.js +72 -0
  98. package/dist/local_state_store.js.map +1 -0
  99. package/dist/public_api.d.ts +10 -0
  100. package/dist/public_api.d.ts.map +1 -0
  101. package/dist/public_api.js +59 -0
  102. package/dist/public_api.js.map +1 -0
  103. package/dist/restate_context.d.ts +405 -0
  104. package/dist/restate_context.d.ts.map +1 -0
  105. package/dist/restate_context.js +46 -0
  106. package/dist/restate_context.js.map +1 -0
  107. package/dist/restate_context_impl.d.ts +54 -0
  108. package/dist/restate_context_impl.d.ts.map +1 -0
  109. package/dist/restate_context_impl.js +364 -0
  110. package/dist/restate_context_impl.js.map +1 -0
  111. package/dist/server/base_restate_server.d.ts +30 -0
  112. package/dist/server/base_restate_server.d.ts.map +1 -0
  113. package/dist/server/base_restate_server.js +360 -0
  114. package/dist/server/base_restate_server.js.map +1 -0
  115. package/dist/server/restate_lambda_handler.d.ts +104 -0
  116. package/dist/server/restate_lambda_handler.d.ts.map +1 -0
  117. package/dist/server/restate_lambda_handler.js +245 -0
  118. package/dist/server/restate_lambda_handler.js.map +1 -0
  119. package/dist/server/restate_server.d.ts +91 -0
  120. package/dist/server/restate_server.d.ts.map +1 -0
  121. package/dist/server/restate_server.js +230 -0
  122. package/dist/server/restate_server.js.map +1 -0
  123. package/dist/state_machine.d.ts +75 -0
  124. package/dist/state_machine.d.ts.map +1 -0
  125. package/dist/state_machine.js +380 -0
  126. package/dist/state_machine.js.map +1 -0
  127. package/dist/types/errors.d.ts +40 -0
  128. package/dist/types/errors.d.ts.map +1 -0
  129. package/dist/types/errors.js +121 -0
  130. package/dist/types/errors.js.map +1 -0
  131. package/dist/types/grpc.d.ts +88 -0
  132. package/dist/types/grpc.d.ts.map +1 -0
  133. package/dist/types/grpc.js +68 -0
  134. package/dist/types/grpc.js.map +1 -0
  135. package/dist/types/protocol.d.ts +24 -0
  136. package/dist/types/protocol.d.ts.map +1 -0
  137. package/dist/types/protocol.js +115 -0
  138. package/dist/types/protocol.js.map +1 -0
  139. package/dist/types/router.d.ts +33 -0
  140. package/dist/types/router.d.ts.map +1 -0
  141. package/dist/types/router.js +36 -0
  142. package/dist/types/router.js.map +1 -0
  143. package/dist/types/types.d.ts +30 -0
  144. package/dist/types/types.d.ts.map +1 -0
  145. package/dist/types/types.js +125 -0
  146. package/dist/types/types.js.map +1 -0
  147. package/dist/utils/assumpsions.d.ts +8 -0
  148. package/dist/utils/assumpsions.d.ts.map +1 -0
  149. package/dist/utils/assumpsions.js +101 -0
  150. package/dist/utils/assumpsions.js.map +1 -0
  151. package/dist/utils/logger.d.ts +60 -0
  152. package/dist/utils/logger.d.ts.map +1 -0
  153. package/dist/utils/logger.js +102 -0
  154. package/dist/utils/logger.js.map +1 -0
  155. package/dist/utils/public_utils.d.ts +58 -0
  156. package/dist/utils/public_utils.d.ts.map +1 -0
  157. package/dist/utils/public_utils.js +49 -0
  158. package/dist/utils/public_utils.js.map +1 -0
  159. package/dist/utils/utils.d.ts +14 -0
  160. package/dist/utils/utils.d.ts.map +1 -0
  161. package/dist/utils/utils.js +119 -0
  162. package/dist/utils/utils.js.map +1 -0
  163. package/package.json +75 -0
@@ -0,0 +1,380 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
4
+ *
5
+ * This file is part of the Restate SDK for Node.js/TypeScript,
6
+ * which is released under the MIT license.
7
+ *
8
+ * You can find a copy of the license in file LICENSE in the root
9
+ * directory of this repository or package, or at
10
+ * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
11
+ */
12
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
25
+ }) : function(o, v) {
26
+ o["default"] = v;
27
+ });
28
+ var __importStar = (this && this.__importStar) || function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.StateMachine = void 0;
37
+ const p = __importStar(require("./types/protocol"));
38
+ const restate_context_impl_1 = require("./restate_context_impl");
39
+ const discovery_1 = require("./generated/proto/discovery");
40
+ const types_1 = require("./types/types");
41
+ const utils_1 = require("./utils/utils");
42
+ const logger_1 = require("./utils/logger");
43
+ const timers_1 = require("timers");
44
+ const protocol_1 = require("./types/protocol");
45
+ const journal_1 = require("./journal");
46
+ const errors_1 = require("./types/errors");
47
+ class StateMachine {
48
+ connection;
49
+ invocation;
50
+ protocolMode;
51
+ journal;
52
+ restateContext;
53
+ invocationComplete = new utils_1.CompletablePromise();
54
+ // when this flag is true, no more work will (and may) happen
55
+ // this is set to true in case of
56
+ // - a completed invocation
57
+ // - a suspension
58
+ // - an error in the state machine
59
+ stateMachineClosed = false;
60
+ localStateStore;
61
+ // Whether the input channel (runtime -> service) is closed
62
+ // If it is closed, then we suspend immediately upon the next suspension point
63
+ // If it is open, then we suspend later because we might still get completions
64
+ inputChannelClosed = false;
65
+ // Suspension timeout that gets set and cleared based on completion messages;
66
+ suspensionTimeout;
67
+ suspensionMillis = 30_000;
68
+ constructor(connection, invocation, protocolMode) {
69
+ this.connection = connection;
70
+ this.invocation = invocation;
71
+ this.protocolMode = protocolMode;
72
+ this.localStateStore = invocation.localStateStore;
73
+ this.restateContext = new restate_context_impl_1.RestateGrpcContextImpl(this.invocation.id, this.invocation.method.service, this);
74
+ this.journal = new journal_1.Journal(this.invocation);
75
+ }
76
+ handleMessage(m) {
77
+ if (this.stateMachineClosed) {
78
+ // ignore this message
79
+ return false;
80
+ }
81
+ if (m.messageType !== protocol_1.COMPLETION_MESSAGE_TYPE) {
82
+ throw errors_1.RetryableError.protocolViolation(`Received message of type ${m.messageType}. Can only accept completion messages after replay has finished.`);
83
+ }
84
+ logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Received completion message from Restate, adding to journal.", m.messageType, m.message);
85
+ this.journal.handleRuntimeCompletionMessage(m.message);
86
+ // Remove lingering suspension timeouts, if we are not waiting for completions anymore
87
+ if (this.suspensionTimeout !== undefined &&
88
+ this.journal.getCompletableIndices().length === 0) {
89
+ (0, timers_1.clearTimeout)(this.suspensionTimeout);
90
+ this.suspensionTimeout = undefined;
91
+ }
92
+ return false; // we are never complete
93
+ }
94
+ handleUserCodeMessage(messageType, message, completedFlag, protocolVersion, requiresAckFlag) {
95
+ // if the state machine is already closed, return a promise that never
96
+ // completes, so that the user code does not resume
97
+ if (this.stateMachineClosed) {
98
+ return wrapDeeply(new utils_1.CompletablePromise().promise);
99
+ }
100
+ const promise = this.journal.handleUserSideMessage(messageType, message);
101
+ const journalIndex = this.journal.getUserCodeJournalIndex();
102
+ // Only send the message to restate if we are not in replaying mode
103
+ if (this.journal.isProcessing()) {
104
+ logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Adding message to journal and sending to Restate", messageType, message);
105
+ this.send(new types_1.Message(messageType, message, completedFlag, protocolVersion, requiresAckFlag));
106
+ }
107
+ else {
108
+ logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Matched and replayed message from journal", messageType, message);
109
+ }
110
+ return wrapDeeply(promise, () => {
111
+ if (!p.SUSPENSION_TRIGGERS.includes(messageType)) {
112
+ return;
113
+ }
114
+ if (this.journal.isUnResolved(journalIndex)) {
115
+ this.scheduleSuspension();
116
+ }
117
+ });
118
+ }
119
+ /**
120
+ * Invokes the RPC function and returns a promise that completes when the state machine
121
+ * stops processing the invocation, meaning when:
122
+ * - The function completes with a result or an exception
123
+ * - The execution suspends
124
+ * - An error is raised in the state machine (network, API violation, ...)
125
+ *
126
+ * The returned promise resolves successfully for all the cases above, because the are (from
127
+ * the perspective of the state machine) expected outcomes in which it send out corresponding
128
+ * result messages and cleanly closed the connection.
129
+ *
130
+ * The returned promise is rejected when an unhandled error arises and the caller would be
131
+ * expected to ensure that resources are properly cleaned up.
132
+ */
133
+ invoke() {
134
+ // --------------------------------------------------------------------------------------------
135
+ // Implementation note:
136
+ //
137
+ // This method is not async, because we don't want to actually await anything
138
+ // in there. We cannot await the completion of the actual invocation, because for long-running
139
+ // code (that suspends), the function invocation never completes. Instead, the state machine
140
+ // triggers a suspension.
141
+ // We need to do a bit of promise chaining for the rpc function promise, and return a different
142
+ // promise that completes in also in suspension and error cases.
143
+ // --------------------------------------------------------------------------------------------
144
+ // it is unexpected for the state machine to be closed here, so we raise an error in
145
+ // that case, unlike in other places, where we simply ignore things
146
+ if (this.stateMachineClosed) {
147
+ return Promise.reject(new Error("state machine is already closed"));
148
+ }
149
+ if (this.journal.nextEntryWillBeReplayed()) {
150
+ logger_1.rlog.debugInvokeMessage(this.invocation.logPrefix, "Resuming (replaying) function.");
151
+ }
152
+ else {
153
+ logger_1.rlog.debugInvokeMessage(this.invocation.logPrefix, "Invoking function.");
154
+ }
155
+ const resultBytes = this.invocation.method.invoke(this.restateContext, this.invocation.invocationValue);
156
+ resultBytes
157
+ .then((bytes) => {
158
+ // invocation successfully returned with a result value
159
+ try {
160
+ // the state machine might be closed here in some cases like when there was an error (like
161
+ // API violation) or a suspension, but the function code still completed
162
+ if (this.stateMachineClosed) {
163
+ logger_1.rlog.warn("Unexpected successful completion of the function after the state machine closed. " +
164
+ "This may indicate that: \n" +
165
+ "- the function code does not properly await some Restate calls " +
166
+ "and did not notice an error \n" +
167
+ "- the function code was delayed for longer than the suspension timeout \n" +
168
+ "- the function code contained a try-catch block around a side effect which throws retryable errors. " +
169
+ "This try-catch block should be placed inside the side effect.");
170
+ return;
171
+ }
172
+ const value = Buffer.from(bytes);
173
+ // handle the result value
174
+ const msg = new types_1.Message(protocol_1.OUTPUT_STREAM_ENTRY_MESSAGE_TYPE, protocol_1.OutputStreamEntryMessage.create({
175
+ value,
176
+ }));
177
+ this.journal.handleUserSideMessage(msg.messageType, msg.message);
178
+ if (!this.journal.outputMsgWasReplayed()) {
179
+ this.send(msg);
180
+ logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Journaled and sent output message", msg.messageType, msg.message);
181
+ }
182
+ else {
183
+ logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Replayed and matched output message from journal", msg.messageType, msg.message);
184
+ }
185
+ logger_1.rlog.debugInvokeMessage(this.invocation.logPrefix, "Function completed successfully.");
186
+ this.finish(value);
187
+ }
188
+ catch (e) {
189
+ this.unhandledError((0, errors_1.ensureError)(e));
190
+ }
191
+ })
192
+ .catch((e) => {
193
+ // because of how we try/catch in the promise handler above, this here exclusively handles
194
+ // errors coming from the rpc function
195
+ try {
196
+ // Sometimes the function code fails as a consequence of the state machine encountering
197
+ // an error before (possibly Restate closed the connection).
198
+ if (this.stateMachineClosed) {
199
+ return;
200
+ }
201
+ const error = (0, errors_1.ensureError)(e);
202
+ logger_1.rlog.debugInvokeMessage(this.invocation.logPrefix, "Function completed with an error: " + error.message);
203
+ this.finishWithError(error);
204
+ }
205
+ catch (ee) {
206
+ this.unhandledError((0, errors_1.ensureError)(ee));
207
+ }
208
+ });
209
+ // this promise here completes under any completion, including the cases where the
210
+ // rpc function does not end (error, suspension, ...)
211
+ return this.invocationComplete.promise;
212
+ }
213
+ async finishWithError(e) {
214
+ if (e instanceof errors_1.TerminalError) {
215
+ this.sendTerminalError(e);
216
+ }
217
+ else {
218
+ this.sendRetryableError(e);
219
+ }
220
+ await this.finish();
221
+ }
222
+ sendRetryableError(e) {
223
+ const msg = new types_1.Message(protocol_1.ERROR_MESSAGE_TYPE, (0, errors_1.errorToErrorMessage)(e));
224
+ logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Invocation ended with retryable error.", msg.messageType, msg.message);
225
+ this.send(msg);
226
+ }
227
+ sendTerminalError(e) {
228
+ const msg = new types_1.Message(protocol_1.OUTPUT_STREAM_ENTRY_MESSAGE_TYPE, protocol_1.OutputStreamEntryMessage.create({
229
+ failure: e.toFailure(),
230
+ }));
231
+ logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Invocation ended with failure message.", msg.messageType, msg.message);
232
+ this.journal.handleUserSideMessage(msg.messageType, msg.message);
233
+ if (!this.journal.outputMsgWasReplayed()) {
234
+ this.send(msg);
235
+ }
236
+ }
237
+ send(message) {
238
+ this.connection.send(message).catch((err) => {
239
+ this.handleStreamError(err);
240
+ });
241
+ }
242
+ /**
243
+ * Closes the state machine, flushes all output, and resolves the invocation promise.
244
+ */
245
+ async finish(value) {
246
+ try {
247
+ this.stateMachineClosed = true;
248
+ this.journal.close();
249
+ this.clearSuspensionTimeout();
250
+ await this.connection.end();
251
+ this.invocationComplete.resolve(value);
252
+ }
253
+ catch (e) {
254
+ this.invocationComplete.reject((0, errors_1.ensureError)(e));
255
+ }
256
+ }
257
+ /**
258
+ * This function propagates errors up to the completion promise, to be handled
259
+ * on the connection layer.
260
+ */
261
+ unhandledError(e) {
262
+ this.invocationComplete.reject(e);
263
+ this.stateMachineClosed = true;
264
+ this.journal.close();
265
+ this.clearSuspensionTimeout();
266
+ }
267
+ scheduleSuspension() {
268
+ // If there was already a timeout set, we want to reset the time to postpone suspension as long as we make progress.
269
+ // So we first clear the old timeout, and then we set a new one.
270
+ if (this.suspensionTimeout !== undefined) {
271
+ (0, timers_1.clearTimeout)(this.suspensionTimeout);
272
+ this.suspensionTimeout = undefined;
273
+ }
274
+ const delay = this.getSuspensionMillis();
275
+ logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Scheduling suspension in " + delay + " ms");
276
+ // Set a new suspension with a new timeout
277
+ // The suspension will only be sent if the timeout is not canceled due to a completion.
278
+ this.suspensionTimeout = setTimeout(() => {
279
+ this.suspend();
280
+ }, delay);
281
+ }
282
+ // Suspension timeouts:
283
+ // Lambda case: suspend immediately when control is back in the user code
284
+ // Bidi streaming case:
285
+ // - suspend after 1 seconds if input channel is still open (can still get completions)
286
+ // - suspend immediately if input channel is closed (cannot get completions)
287
+ getSuspensionMillis() {
288
+ return this.protocolMode === discovery_1.ProtocolMode.REQUEST_RESPONSE ||
289
+ this.inputChannelClosed
290
+ ? 0
291
+ : this.suspensionMillis;
292
+ }
293
+ async suspend() {
294
+ const indices = this.journal.getCompletableIndices();
295
+ // If the state is closed then we either already send a suspension
296
+ // or something else bad happened...
297
+ if (this.journal.isClosed() || indices.length === 0) {
298
+ return;
299
+ }
300
+ // There need to be journal entries to complete, otherwise this timeout should have been removed.
301
+ // A suspension message is the end of the invocation.
302
+ // Resolve the root call with the suspension message
303
+ // This will lead to a onCallSuccess call where this msg will be sent.
304
+ const msg = new types_1.Message(protocol_1.SUSPENSION_MESSAGE_TYPE, protocol_1.SuspensionMessage.create({
305
+ entryIndexes: indices,
306
+ }));
307
+ logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Writing suspension message to journal.", msg.messageType, msg.message);
308
+ this.journal.handleUserSideMessage(msg.messageType, msg.message);
309
+ if (!this.journal.outputMsgWasReplayed()) {
310
+ this.send(msg);
311
+ }
312
+ logger_1.rlog.debugInvokeMessage(this.invocation.logPrefix, "Suspending function.");
313
+ await this.finish();
314
+ }
315
+ async notifyHandlerExecutionError(e) {
316
+ await this.finishWithError(e);
317
+ }
318
+ /**
319
+ * WARNING: make sure you use this at the right point in the code
320
+ * After the index has been incremented...
321
+ * This is error-prone... Would be good to have a better solution for this.
322
+ */
323
+ getUserCodeJournalIndex() {
324
+ return this.journal.getUserCodeJournalIndex();
325
+ }
326
+ getFullServiceName() {
327
+ return (0, utils_1.makeFqServiceName)(this.invocation.method.packge, this.invocation.method.service);
328
+ }
329
+ handleInputClosed() {
330
+ if (this.journal.isClosed() ||
331
+ this.stateMachineClosed ||
332
+ this.inputChannelClosed) {
333
+ return;
334
+ }
335
+ this.inputChannelClosed = true;
336
+ logger_1.rlog.debug(this.invocation.logPrefix +
337
+ " : Restate closed connection to trigger suspension.");
338
+ // If there is a timeout planned, reset the timout to execute immediately when the work is done.
339
+ if (this.suspensionTimeout !== undefined) {
340
+ this.scheduleSuspension();
341
+ }
342
+ }
343
+ handleStreamError(e) {
344
+ logger_1.rlog.info("Aborting function execution and closing state machine due to connection error: " +
345
+ e.message);
346
+ this.unhandledError(e);
347
+ }
348
+ nextEntryWillBeReplayed() {
349
+ return this.journal.nextEntryWillBeReplayed();
350
+ }
351
+ clearSuspensionTimeout() {
352
+ if (this.suspensionTimeout !== undefined) {
353
+ (0, timers_1.clearTimeout)(this.suspensionTimeout);
354
+ this.suspensionTimeout = undefined;
355
+ }
356
+ }
357
+ }
358
+ exports.StateMachine = StateMachine;
359
+ const wrapDeeply = (promise, cb) => {
360
+ /* eslint-disable @typescript-eslint/no-explicit-any */
361
+ return {
362
+ transform: function (onfulfilled, onrejected) {
363
+ return wrapDeeply(promise.then(onfulfilled, onrejected), cb);
364
+ },
365
+ then: function (onfulfilled, onrejected) {
366
+ if (cb !== undefined) {
367
+ cb();
368
+ }
369
+ return promise.then(onfulfilled, onrejected);
370
+ },
371
+ catch: function (onrejected) {
372
+ return wrapDeeply(promise.catch(onrejected), cb);
373
+ },
374
+ finally: function (onfinally) {
375
+ return wrapDeeply(promise.finally(onfinally), cb);
376
+ },
377
+ [Symbol.toStringTag]: "",
378
+ };
379
+ };
380
+ //# sourceMappingURL=state_machine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state_machine.js","sourceRoot":"","sources":["../src/state_machine.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oDAAsC;AACtC,iEAAgE;AAEhE,2DAA2D;AAC3D,yCAAwC;AACxC,yCAAsE;AACtE,2CAAsC;AACtC,mCAAsC;AACtC,+CAO0B;AAC1B,uCAAoC;AAEpC,2CAKwB;AAGxB,MAAa,YAAY;IA0BJ;IACA;IACA;IA3BX,OAAO,CAAgB;IACvB,cAAc,CAAyB;IAE9B,kBAAkB,GAAG,IAAI,0BAAkB,EAAiB,CAAC;IAE9E,6DAA6D;IAC7D,iCAAiC;IACjC,4BAA4B;IAC5B,kBAAkB;IAClB,mCAAmC;IAC3B,kBAAkB,GAAG,KAAK,CAAC;IAEnB,eAAe,CAAkB;IAEjD,2DAA2D;IAC3D,8EAA8E;IAC9E,8EAA8E;IACtE,kBAAkB,GAAG,KAAK,CAAC;IAEnC,6EAA6E;IACrE,iBAAiB,CAAkB;IAE1B,gBAAgB,GAAG,MAAM,CAAC;IAE3C,YACmB,UAAsB,EACtB,UAA4B,EAC5B,YAA0B;Q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e,EACI,EAAE;IACrB,uDAAuD;IACvD,OAAO;QACL,SAAS,EAAE,UACT,WAGa,EACb,UAGa;YAEb,OAAO,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC;QAC/D,CAAC;QAED,IAAI,EAAE,UACJ,WAGa,EACb,UAGa;YAEb,IAAI,EAAE,KAAK,SAAS,EAAE;gBACpB,EAAE,EAAE,CAAC;aACN;YACD,OAAO,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAC/C,CAAC;QACD,KAAK,EAAE,UACL,UAGa;YAEb,OAAO,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,EAAE,UACP,SAA2C;YAE3C,OAAO,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;QACpD,CAAC;QACD,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE;KACzB,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { ErrorMessage, Failure } from "../generated/proto/protocol";
2
+ import { Message } from "./types";
3
+ import { JournalEntry } from "../journal";
4
+ import { FailureWithTerminal } from "../generated/proto/javascript";
5
+ export declare enum ErrorCodes {
6
+ UNKNOWN = 2,
7
+ INTERNAL = 13,
8
+ JOURNAL_MISMATCH = 32,
9
+ PROTOCOL_VIOLATION = 33
10
+ }
11
+ export declare function ensureError(e: unknown): Error;
12
+ export declare class RestateError extends Error {
13
+ readonly code: number;
14
+ constructor(message: string, options?: {
15
+ errorCode?: number;
16
+ cause?: any;
17
+ });
18
+ toFailure(): Failure;
19
+ }
20
+ export declare class TerminalError extends RestateError {
21
+ constructor(message: string, options?: {
22
+ errorCode?: number;
23
+ cause?: any;
24
+ });
25
+ }
26
+ export declare class RetryableError extends RestateError {
27
+ constructor(message: string, options?: {
28
+ errorCode?: number;
29
+ cause?: any;
30
+ });
31
+ static internal(message: string): RetryableError;
32
+ static journalMismatch(journalIndex: number, replayMessage: Message, journalEntry: JournalEntry): RetryableError;
33
+ static protocolViolation(message: string): RetryableError;
34
+ static apiViolation(message: string): RetryableError;
35
+ }
36
+ export declare function errorToFailure(err: Error): Failure;
37
+ export declare function errorToFailureWithTerminal(err: Error): FailureWithTerminal;
38
+ export declare function failureToError(failure: Failure, terminalError: boolean): Error;
39
+ export declare function errorToErrorMessage(err: Error): ErrorMessage;
40
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/types/errors.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEpE,oBAAY,UAAU;IACpB,OAAO,IAAI;IACX,QAAQ,KAAK;IACb,gBAAgB,KAAK;IACrB,kBAAkB,KAAK;CACxB;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,KAAK,CAa7C;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAgB,IAAI,EAAE,MAAM,CAAC;gBAEjB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,GAAG,CAAA;KAAE;IAKnE,SAAS,IAAI,OAAO;CAM5B;AAID,qBAAa,aAAc,SAAQ,YAAY;gBACjC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,GAAG,CAAA;KAAE;CAG3E;AAGD,qBAAa,cAAe,SAAQ,YAAY;gBAClC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,GAAG,CAAA;KAAE;WAI5D,QAAQ,CAAC,OAAO,EAAE,MAAM;WAIxB,eAAe,CAC3B,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,OAAO,EACtB,YAAY,EAAE,YAAY;WAad,iBAAiB,CAAC,OAAO,EAAE,MAAM;WAMjC,YAAY,CAAC,OAAO,EAAE,MAAM;CAK3C;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,KAAK,GAAG,OAAO,CAOlD;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,KAAK,GAAG,mBAAmB,CAM1E;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,OAAO,GACrB,KAAK,CAOP;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,KAAK,GAAG,YAAY,CAO5D"}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
4
+ *
5
+ * This file is part of the Restate SDK for Node.js/TypeScript,
6
+ * which is released under the MIT license.
7
+ *
8
+ * You can find a copy of the license in file LICENSE in the root
9
+ * directory of this repository or package, or at
10
+ * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.errorToErrorMessage = exports.failureToError = exports.errorToFailureWithTerminal = exports.errorToFailure = exports.RetryableError = exports.TerminalError = exports.RestateError = exports.ensureError = exports.ErrorCodes = void 0;
14
+ /* eslint-disable @typescript-eslint/no-explicit-any */
15
+ const protocol_1 = require("../generated/proto/protocol");
16
+ const utils_1 = require("../utils/utils");
17
+ const javascript_1 = require("../generated/proto/javascript");
18
+ var ErrorCodes;
19
+ (function (ErrorCodes) {
20
+ ErrorCodes[ErrorCodes["UNKNOWN"] = 2] = "UNKNOWN";
21
+ ErrorCodes[ErrorCodes["INTERNAL"] = 13] = "INTERNAL";
22
+ ErrorCodes[ErrorCodes["JOURNAL_MISMATCH"] = 32] = "JOURNAL_MISMATCH";
23
+ ErrorCodes[ErrorCodes["PROTOCOL_VIOLATION"] = 33] = "PROTOCOL_VIOLATION";
24
+ })(ErrorCodes = exports.ErrorCodes || (exports.ErrorCodes = {}));
25
+ function ensureError(e) {
26
+ if (e instanceof Error) {
27
+ return e;
28
+ }
29
+ let msg;
30
+ try {
31
+ msg = JSON.stringify(e);
32
+ }
33
+ catch (x) {
34
+ msg = "(no JSON representation)";
35
+ }
36
+ return new Error("Non-Error value: " + msg);
37
+ }
38
+ exports.ensureError = ensureError;
39
+ class RestateError extends Error {
40
+ code;
41
+ constructor(message, options) {
42
+ super(message, { cause: options?.cause });
43
+ this.code = options?.errorCode ?? ErrorCodes.INTERNAL;
44
+ }
45
+ toFailure() {
46
+ return protocol_1.Failure.create({
47
+ code: this.code,
48
+ message: this.message,
49
+ });
50
+ }
51
+ }
52
+ exports.RestateError = RestateError;
53
+ // Does not lead to Restate retries
54
+ // Leads to an output message with a failure defined
55
+ class TerminalError extends RestateError {
56
+ constructor(message, options) {
57
+ super(message, options);
58
+ }
59
+ }
60
+ exports.TerminalError = TerminalError;
61
+ // Leads to Restate retries
62
+ class RetryableError extends RestateError {
63
+ constructor(message, options) {
64
+ super(message, options);
65
+ }
66
+ static internal(message) {
67
+ return new RetryableError(message);
68
+ }
69
+ static journalMismatch(journalIndex, replayMessage, journalEntry) {
70
+ const msg = `Journal mismatch: Replayed journal entries did not correspond to the user code. The user code has to be deterministic!
71
+ The journal entry at position ${journalIndex} was:
72
+ - In the user code: type: ${journalEntry.messageType}, message:${(0, utils_1.printMessageAsJson)(journalEntry.message)}
73
+ - In the replayed messages: type: ${replayMessage.messageType}, message: ${(0, utils_1.printMessageAsJson)(replayMessage.message)}`;
74
+ return new RetryableError(msg, { errorCode: ErrorCodes.JOURNAL_MISMATCH });
75
+ }
76
+ static protocolViolation(message) {
77
+ return new RetryableError(message, {
78
+ errorCode: ErrorCodes.PROTOCOL_VIOLATION,
79
+ });
80
+ }
81
+ static apiViolation(message) {
82
+ return new RetryableError(`API violation: ${message}`, {
83
+ errorCode: ErrorCodes.INTERNAL,
84
+ });
85
+ }
86
+ }
87
+ exports.RetryableError = RetryableError;
88
+ function errorToFailure(err) {
89
+ return err instanceof RestateError
90
+ ? err.toFailure()
91
+ : protocol_1.Failure.create({
92
+ code: ErrorCodes.INTERNAL,
93
+ message: err.message,
94
+ });
95
+ }
96
+ exports.errorToFailure = errorToFailure;
97
+ function errorToFailureWithTerminal(err) {
98
+ const failure = errorToFailure(err);
99
+ return javascript_1.FailureWithTerminal.create({
100
+ failure,
101
+ terminal: err instanceof TerminalError,
102
+ });
103
+ }
104
+ exports.errorToFailureWithTerminal = errorToFailureWithTerminal;
105
+ function failureToError(failure, terminalError) {
106
+ const errorMessage = failure.message ?? "(missing error message)";
107
+ const errorCode = failure.code ?? ErrorCodes.INTERNAL;
108
+ return terminalError
109
+ ? new TerminalError(errorMessage, { errorCode })
110
+ : new RestateError(errorMessage, { errorCode });
111
+ }
112
+ exports.failureToError = failureToError;
113
+ function errorToErrorMessage(err) {
114
+ const code = err instanceof RestateError ? err.code : ErrorCodes.INTERNAL;
115
+ return protocol_1.ErrorMessage.create({
116
+ code: code,
117
+ message: err.message,
118
+ });
119
+ }
120
+ exports.errorToErrorMessage = errorToErrorMessage;
121
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/types/errors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,uDAAuD;AAEvD,0DAAoE;AACpE,0CAAoD;AAGpD,8DAAoE;AAEpE,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,iDAAW,CAAA;IACX,oDAAa,CAAA;IACb,oEAAqB,CAAA;IACrB,wE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,aAAsB;IAEtB,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,IAAI,yBAAyB,CAAC;IAClE,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,IAAI,UAAU,CAAC,QAAQ,CAAC;IAEtD,OAAO,aAAa;QAClB,CAAC,CAAC,IAAI,aAAa,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,CAAC;QAChD,CAAC,CAAC,IAAI,YAAY,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACpD,CAAC;AAVD,wCAUC;AAED,SAAgB,mBAAmB,CAAC,GAAU;IAC5C,MAAM,IAAI,GAAG,GAAG,YAAY,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC;IAE1E,OAAO,uBAAY,CAAC,MAAM,CAAC;QACzB,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,GAAG,CAAC,OAAO;KACrB,CAAC,CAAC;AACL,CAAC;AAPD,kDAOC"}
@@ -0,0 +1,88 @@
1
+ import { RestateContext } from "../restate_context";
2
+ import { FileDescriptorProto } from "ts-proto-descriptors";
3
+ export declare class GrpcServiceMethod<I, O> {
4
+ readonly name: string;
5
+ readonly localName: string;
6
+ readonly localFn: (instance: unknown, input: I) => Promise<O>;
7
+ readonly inputDecoder: (buf: Uint8Array) => I;
8
+ readonly outputEncoder: (output: O) => Uint8Array;
9
+ constructor(name: string, // the gRPC name as defined in the .proto file
10
+ localName: string, // the method name as defined in the class.
11
+ localFn: (instance: unknown, input: I) => Promise<O>, // the actual function
12
+ inputDecoder: (buf: Uint8Array) => I, // the protobuf decoder
13
+ outputEncoder: (output: O) => Uint8Array);
14
+ }
15
+ export declare class GrpcService {
16
+ readonly name: string;
17
+ readonly packge: string;
18
+ readonly impl: object;
19
+ readonly methods: Array<GrpcServiceMethod<unknown, unknown>>;
20
+ constructor(name: string, packge: string, impl: object, methods: Array<GrpcServiceMethod<unknown, unknown>>);
21
+ }
22
+ export declare class HostedGrpcServiceMethod<I, O> {
23
+ readonly instance: unknown;
24
+ readonly packge: string;
25
+ readonly service: string;
26
+ readonly method: GrpcServiceMethod<I, O>;
27
+ constructor(instance: unknown, packge: string, service: string, method: GrpcServiceMethod<I, O>);
28
+ invoke(context: RestateContext, inBytes: Uint8Array): Promise<Uint8Array>;
29
+ }
30
+ type ProtoMetaMessageOptions = {
31
+ options?: {
32
+ [key: string]: any;
33
+ };
34
+ fields?: {
35
+ [key: string]: {
36
+ [key: string]: any;
37
+ };
38
+ };
39
+ oneof?: {
40
+ [key: string]: {
41
+ [key: string]: any;
42
+ };
43
+ };
44
+ nested?: {
45
+ [key: string]: ProtoMetaMessageOptions;
46
+ };
47
+ };
48
+ export interface ProtoMetadata {
49
+ fileDescriptor: FileDescriptorProto;
50
+ references: {
51
+ [key: string]: any;
52
+ };
53
+ dependencies?: ProtoMetadata[];
54
+ options?: {
55
+ options?: {
56
+ [key: string]: any;
57
+ };
58
+ services?: {
59
+ [key: string]: {
60
+ options?: {
61
+ [key: string]: any;
62
+ };
63
+ methods?: {
64
+ [key: string]: {
65
+ [key: string]: any;
66
+ };
67
+ };
68
+ };
69
+ };
70
+ messages?: {
71
+ [key: string]: ProtoMetaMessageOptions;
72
+ };
73
+ enums?: {
74
+ [key: string]: {
75
+ options?: {
76
+ [key: string]: any;
77
+ };
78
+ values?: {
79
+ [key: string]: {
80
+ [key: string]: any;
81
+ };
82
+ };
83
+ };
84
+ };
85
+ };
86
+ }
87
+ export {};
88
+ //# sourceMappingURL=grpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grpc.d.ts","sourceRoot":"","sources":["../../src/types/grpc.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,cAAc,EAAc,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,qBAAa,iBAAiB,CAAC,CAAC,EAAE,CAAC;IAE/B,QAAQ,CAA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