@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.
Files changed (231) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +29 -51
  3. package/dist/clients/workflow_client.d.ts +77 -0
  4. package/dist/clients/workflow_client.d.ts.map +1 -0
  5. package/dist/clients/workflow_client.js +172 -0
  6. package/dist/clients/workflow_client.js.map +1 -0
  7. package/dist/connection/buffered_connection.js +44 -0
  8. package/dist/connection/buffered_connection.js.map +1 -0
  9. package/dist/connection/connection.js +13 -0
  10. package/dist/connection/connection.js.map +1 -0
  11. package/dist/connection/embedded_connection.js +59 -0
  12. package/dist/connection/embedded_connection.js.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.js +58 -0
  16. package/dist/connection/lambda_connection.js.map +1 -0
  17. package/dist/{restate_context.d.ts → context.d.ts} +239 -170
  18. package/dist/context.d.ts.map +1 -0
  19. package/dist/context.js +113 -0
  20. package/dist/context.js.map +1 -0
  21. package/dist/{restate_context_impl.d.ts → context_impl.d.ts} +26 -30
  22. package/dist/context_impl.d.ts.map +1 -0
  23. package/dist/context_impl.js +439 -0
  24. package/dist/context_impl.js.map +1 -0
  25. package/dist/embedded/api.d.ts +2 -2
  26. package/dist/embedded/api.d.ts.map +1 -1
  27. package/dist/embedded/api.js +35 -0
  28. package/dist/embedded/api.js.map +1 -0
  29. package/dist/embedded/handler.d.ts +2 -2
  30. package/dist/embedded/handler.d.ts.map +1 -1
  31. package/dist/embedded/handler.js +26 -0
  32. package/dist/embedded/handler.js.map +1 -0
  33. package/dist/embedded/http2_remote.js +91 -0
  34. package/dist/embedded/http2_remote.js.map +1 -0
  35. package/dist/embedded/invocation.d.ts.map +1 -1
  36. package/dist/embedded/invocation.js +94 -0
  37. package/dist/embedded/invocation.js.map +1 -0
  38. package/dist/endpoint/endpoint_impl.d.ts +35 -0
  39. package/dist/endpoint/endpoint_impl.d.ts.map +1 -0
  40. package/dist/endpoint/endpoint_impl.js +405 -0
  41. package/dist/endpoint/endpoint_impl.js.map +1 -0
  42. package/dist/endpoint/http2_handler.d.ts +11 -0
  43. package/dist/endpoint/http2_handler.d.ts.map +1 -0
  44. package/dist/endpoint/http2_handler.js +119 -0
  45. package/dist/endpoint/http2_handler.js.map +1 -0
  46. package/dist/endpoint/lambda_handler.d.ts +15 -0
  47. package/dist/endpoint/lambda_handler.d.ts.map +1 -0
  48. package/dist/endpoint/lambda_handler.js +144 -0
  49. package/dist/endpoint/lambda_handler.js.map +1 -0
  50. package/dist/endpoint.d.ts +161 -0
  51. package/dist/endpoint.d.ts.map +1 -0
  52. package/dist/endpoint.js +22 -0
  53. package/dist/endpoint.js.map +1 -0
  54. package/dist/generated/dev/restate/events.js +371 -0
  55. package/dist/generated/dev/restate/events.js.map +1 -0
  56. package/dist/generated/dev/restate/ext.js +215 -0
  57. package/dist/generated/dev/restate/ext.js.map +1 -0
  58. package/dist/generated/google/protobuf/descriptor.js +6676 -0
  59. package/dist/generated/google/protobuf/descriptor.js.map +1 -0
  60. package/dist/generated/google/protobuf/empty.js +107 -0
  61. package/dist/generated/google/protobuf/empty.js.map +1 -0
  62. package/dist/generated/google/protobuf/struct.js +754 -0
  63. package/dist/generated/google/protobuf/struct.js.map +1 -0
  64. package/dist/generated/proto/discovery.js +364 -0
  65. package/dist/generated/proto/discovery.js.map +1 -0
  66. package/dist/generated/proto/dynrpc.js +668 -0
  67. package/dist/generated/proto/dynrpc.js.map +1 -0
  68. package/dist/generated/proto/javascript.d.ts +13 -0
  69. package/dist/generated/proto/javascript.d.ts.map +1 -1
  70. package/dist/generated/proto/javascript.js +416 -0
  71. package/dist/generated/proto/javascript.js.map +1 -0
  72. package/dist/generated/proto/protocol.d.ts +43 -0
  73. package/dist/generated/proto/protocol.d.ts.map +1 -1
  74. package/dist/generated/proto/protocol.js +2641 -0
  75. package/dist/generated/proto/protocol.js.map +1 -0
  76. package/dist/generated/proto/services.js +1535 -0
  77. package/dist/generated/proto/services.js.map +1 -0
  78. package/dist/generated/proto/test.js +321 -0
  79. package/dist/generated/proto/test.js.map +1 -0
  80. package/dist/invocation.d.ts +4 -1
  81. package/dist/invocation.d.ts.map +1 -1
  82. package/dist/invocation.js +157 -0
  83. package/dist/invocation.js.map +1 -0
  84. package/dist/io/decoder.d.ts +1 -0
  85. package/dist/io/decoder.d.ts.map +1 -1
  86. package/dist/io/decoder.js +140 -0
  87. package/dist/io/decoder.js.map +1 -0
  88. package/dist/io/encoder.d.ts +1 -2
  89. package/dist/io/encoder.d.ts.map +1 -1
  90. package/dist/io/encoder.js +68 -0
  91. package/dist/io/encoder.js.map +1 -0
  92. package/dist/journal.d.ts +13 -4
  93. package/dist/journal.d.ts.map +1 -1
  94. package/dist/journal.js +405 -0
  95. package/dist/journal.js.map +1 -0
  96. package/dist/local_state_store.d.ts +5 -3
  97. package/dist/local_state_store.d.ts.map +1 -1
  98. package/dist/local_state_store.js +82 -0
  99. package/dist/local_state_store.js.map +1 -0
  100. package/dist/logger.d.ts +19 -0
  101. package/dist/logger.d.ts.map +1 -0
  102. package/dist/logger.js +90 -0
  103. package/dist/logger.js.map +1 -0
  104. package/dist/promise_combinator_tracker.d.ts +29 -0
  105. package/dist/promise_combinator_tracker.d.ts.map +1 -0
  106. package/dist/promise_combinator_tracker.js +128 -0
  107. package/dist/promise_combinator_tracker.js.map +1 -0
  108. package/dist/public_api.d.ts +5 -5
  109. package/dist/public_api.d.ts.map +1 -1
  110. package/dist/public_api.js +60 -0
  111. package/dist/public_api.js.map +1 -0
  112. package/dist/state_machine.d.ts +19 -12
  113. package/dist/state_machine.d.ts.map +1 -1
  114. package/dist/state_machine.js +437 -0
  115. package/dist/state_machine.js.map +1 -0
  116. package/dist/types/errors.d.ts +12 -3
  117. package/dist/types/errors.d.ts.map +1 -1
  118. package/dist/types/errors.js +273 -0
  119. package/dist/types/errors.js.map +1 -0
  120. package/dist/types/grpc.d.ts +6 -4
  121. package/dist/types/grpc.d.ts.map +1 -1
  122. package/dist/types/grpc.js +81 -0
  123. package/dist/types/grpc.js.map +1 -0
  124. package/dist/types/protocol.d.ts +9 -5
  125. package/dist/types/protocol.d.ts.map +1 -1
  126. package/dist/types/protocol.js +147 -0
  127. package/dist/types/protocol.js.map +1 -0
  128. package/dist/types/router.d.ts +8 -8
  129. package/dist/types/router.d.ts.map +1 -1
  130. package/dist/types/router.js +36 -0
  131. package/dist/types/router.js.map +1 -0
  132. package/dist/types/types.d.ts +1 -0
  133. package/dist/types/types.d.ts.map +1 -1
  134. package/dist/types/types.js +138 -0
  135. package/dist/types/types.js.map +1 -0
  136. package/dist/utils/{assumpsions.d.ts → assumptions.d.ts} +1 -1
  137. package/dist/utils/{assumpsions.d.ts.map → assumptions.d.ts.map} +1 -1
  138. package/dist/utils/assumptions.js +101 -0
  139. package/dist/utils/assumptions.js.map +1 -0
  140. package/dist/utils/message_logger.d.ts +28 -0
  141. package/dist/utils/message_logger.d.ts.map +1 -0
  142. package/dist/utils/message_logger.js +88 -0
  143. package/dist/utils/message_logger.js.map +1 -0
  144. package/dist/utils/promises.d.ts +15 -0
  145. package/dist/utils/promises.d.ts.map +1 -0
  146. package/dist/utils/promises.js +67 -0
  147. package/dist/utils/promises.js.map +1 -0
  148. package/dist/utils/public_utils.js +49 -0
  149. package/dist/utils/public_utils.js.map +1 -0
  150. package/dist/utils/rand.d.ts +1 -1
  151. package/dist/utils/rand.d.ts.map +1 -1
  152. package/dist/utils/rand.js +114 -0
  153. package/dist/utils/rand.js.map +1 -0
  154. package/dist/utils/utils.d.ts +1 -10
  155. package/dist/utils/utils.d.ts.map +1 -1
  156. package/dist/utils/utils.js +122 -0
  157. package/dist/utils/utils.js.map +1 -0
  158. package/dist/workflows/workflow.d.ts +101 -0
  159. package/dist/workflows/workflow.d.ts.map +1 -0
  160. package/dist/workflows/workflow.js +80 -0
  161. package/dist/workflows/workflow.js.map +1 -0
  162. package/dist/workflows/workflow_state_service.d.ts +35 -0
  163. package/dist/workflows/workflow_state_service.d.ts.map +1 -0
  164. package/dist/workflows/workflow_state_service.js +201 -0
  165. package/dist/workflows/workflow_state_service.js.map +1 -0
  166. package/dist/workflows/workflow_wrapper_service.d.ts +10 -0
  167. package/dist/workflows/workflow_wrapper_service.d.ts.map +1 -0
  168. package/dist/workflows/workflow_wrapper_service.js +264 -0
  169. package/dist/workflows/workflow_wrapper_service.js.map +1 -0
  170. package/package.json +38 -39
  171. package/src/clients/workflow_client.ts +290 -0
  172. package/src/connection/buffered_connection.ts +47 -0
  173. package/src/connection/connection.ts +34 -0
  174. package/src/connection/embedded_connection.ts +62 -0
  175. package/src/connection/http_connection.ts +228 -0
  176. package/src/connection/lambda_connection.ts +69 -0
  177. package/src/context.ts +633 -0
  178. package/src/context_impl.ts +721 -0
  179. package/src/embedded/api.ts +57 -0
  180. package/src/embedded/handler.ts +36 -0
  181. package/src/embedded/http2_remote.ts +103 -0
  182. package/src/embedded/invocation.ts +126 -0
  183. package/src/endpoint/endpoint_impl.ts +623 -0
  184. package/src/endpoint/http2_handler.ts +151 -0
  185. package/src/endpoint/lambda_handler.ts +181 -0
  186. package/src/endpoint.ts +187 -0
  187. package/src/generated/dev/restate/events.ts +430 -0
  188. package/src/generated/dev/restate/ext.ts +238 -0
  189. package/src/generated/google/protobuf/descriptor.ts +7889 -0
  190. package/src/generated/google/protobuf/empty.ts +150 -0
  191. package/src/generated/google/protobuf/struct.ts +878 -0
  192. package/src/generated/proto/discovery.ts +423 -0
  193. package/src/generated/proto/dynrpc.ts +768 -0
  194. package/src/generated/proto/javascript.ts +488 -0
  195. package/src/generated/proto/protocol.ts +3091 -0
  196. package/src/generated/proto/services.ts +1834 -0
  197. package/src/generated/proto/test.ts +387 -0
  198. package/src/invocation.ts +212 -0
  199. package/src/io/decoder.ts +171 -0
  200. package/src/io/encoder.ts +72 -0
  201. package/src/journal.ts +537 -0
  202. package/src/local_state_store.ts +94 -0
  203. package/src/logger.ts +121 -0
  204. package/src/promise_combinator_tracker.ts +191 -0
  205. package/src/public_api.ts +53 -0
  206. package/src/state_machine.ts +635 -0
  207. package/src/types/errors.ts +297 -0
  208. package/src/types/grpc.ts +97 -0
  209. package/src/types/protocol.ts +201 -0
  210. package/src/types/router.ts +118 -0
  211. package/src/types/types.ts +160 -0
  212. package/src/utils/assumptions.ts +131 -0
  213. package/src/utils/message_logger.ts +112 -0
  214. package/src/utils/promises.ts +118 -0
  215. package/src/utils/public_utils.ts +91 -0
  216. package/src/utils/rand.ts +142 -0
  217. package/src/utils/utils.ts +178 -0
  218. package/src/workflows/workflow.ts +178 -0
  219. package/src/workflows/workflow_state_service.ts +299 -0
  220. package/src/workflows/workflow_wrapper_service.ts +314 -0
  221. package/dist/cloudflare_bundle.js +0 -27387
  222. package/dist/restate_context.d.ts.map +0 -1
  223. package/dist/restate_context_impl.d.ts.map +0 -1
  224. package/dist/server/base_restate_server.d.ts +0 -32
  225. package/dist/server/base_restate_server.d.ts.map +0 -1
  226. package/dist/server/restate_lambda_handler.d.ts +0 -104
  227. package/dist/server/restate_lambda_handler.d.ts.map +0 -1
  228. package/dist/server/restate_server.d.ts +0 -97
  229. package/dist/server/restate_server.d.ts.map +0 -1
  230. package/dist/utils/logger.d.ts +0 -60
  231. package/dist/utils/logger.d.ts.map +0 -1
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2023-2024 - 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.failureToTerminalError = exports.errorToFailureWithTerminal = exports.errorToFailure = exports.RetryableError = exports.TimeoutError = exports.TerminalError = exports.RestateError = exports.ensureError = exports.RestateErrorCodes = 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
+ /**
21
+ * Not an error; returned on success.
22
+ * HTTP 200
23
+ */
24
+ ErrorCodes[ErrorCodes["OK"] = 0] = "OK";
25
+ /**
26
+ * The operation was cancelled, typically by the caller.
27
+ * HTTP 408
28
+ */
29
+ ErrorCodes[ErrorCodes["CANCELLED"] = 1] = "CANCELLED";
30
+ /**
31
+ * Unknown error. For example, this error may be returned when a
32
+ * Status value received from another address space belongs to an error
33
+ * space that is not known in this address space. Also errors raised by APIs
34
+ * that do not return enough error information may be converted to this
35
+ * error.
36
+ * HTTP 500
37
+ */
38
+ ErrorCodes[ErrorCodes["UNKNOWN"] = 2] = "UNKNOWN";
39
+ /**
40
+ * The client specified an invalid argument. Note that
41
+ * this differs from FAILED_PRECONDITION. INVALID_ARGUMENT indicates
42
+ * arguments that are problematic regardless of the state of the system
43
+ * (e.g., a malformed file name).
44
+ * HTTP 400
45
+ */
46
+ ErrorCodes[ErrorCodes["INVALID_ARGUMENT"] = 3] = "INVALID_ARGUMENT";
47
+ /**
48
+ * The deadline expired before the operation could
49
+ * complete. For operations that change the state of the system, this error
50
+ * may be returned even if the operation has completed successfully. For
51
+ * example, a successful response from a server could have been delayed
52
+ * long.
53
+ * HTTP 408
54
+ */
55
+ ErrorCodes[ErrorCodes["DEADLINE_EXCEEDED"] = 4] = "DEADLINE_EXCEEDED";
56
+ /**
57
+ * Some requested entity (e.g., file or directory) was not
58
+ * found. Note to server developers: if a request is denied for an entire
59
+ * class of users, such as gradual feature rollout or undocumented
60
+ * allowlist, NOT_FOUND may be used. If a request is denied for some users
61
+ * within a class of users, such as user-based access control,
62
+ * PERMISSION_DENIED must be used.
63
+ * HTTP 404
64
+ */
65
+ ErrorCodes[ErrorCodes["NOT_FOUND"] = 5] = "NOT_FOUND";
66
+ /**
67
+ * The entity that a client attempted to create (e.g., file
68
+ * or directory) already exists.
69
+ * HTTP 409
70
+ */
71
+ ErrorCodes[ErrorCodes["ALREADY_EXISTS"] = 6] = "ALREADY_EXISTS";
72
+ /**
73
+ * The caller does not have permission to execute the
74
+ * specified operation. PERMISSION_DENIED must not be used for rejections
75
+ * caused by exhausting some resource (use RESOURCE_EXHAUSTED instead for
76
+ * those errors). PERMISSION_DENIED must not be used if the caller can not
77
+ * be identified (use UNAUTHENTICATED instead for those errors). This error
78
+ * code does not imply the request is valid or the requested entity exists
79
+ * or satisfies other pre-conditions.
80
+ * HTTP 403
81
+ */
82
+ ErrorCodes[ErrorCodes["PERMISSION_DENIED"] = 7] = "PERMISSION_DENIED";
83
+ /**
84
+ * Some resource has been exhausted, perhaps a per-user
85
+ * quota, or perhaps the entire file system is out of space.
86
+ * HTTP 413
87
+ */
88
+ ErrorCodes[ErrorCodes["RESOURCE_EXHAUSTED"] = 8] = "RESOURCE_EXHAUSTED";
89
+ /**
90
+ * The operation was rejected because the system is
91
+ * not in a state required for the operation's execution. For example, the
92
+ * directory to be deleted is non-empty, an rmdir operation is applied to a
93
+ * non-directory, etc. Service implementors can use the following guidelines
94
+ * to decide between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE: (a) Use
95
+ * UNAVAILABLE if the client can retry just the failing call. (b) Use
96
+ * ABORTED if the client should retry at a higher level (e.g., when a
97
+ * client-specified test-and-set fails, indicating the client should restart
98
+ * a read-modify-write sequence). (c) Use FAILED_PRECONDITION if the client
99
+ * should not retry until the system state has been explicitly fixed. E.g.,
100
+ * if an "rmdir" fails because the directory is non-empty,
101
+ * FAILED_PRECONDITION should be returned since the client should not retry
102
+ * unless the files are deleted from the directory.
103
+ * HTTP 412
104
+ */
105
+ ErrorCodes[ErrorCodes["FAILED_PRECONDITION"] = 9] = "FAILED_PRECONDITION";
106
+ /**
107
+ * The operation was aborted, typically due to a concurrency issue
108
+ * such as a sequencer check failure or transaction abort. See the
109
+ * guidelines above for deciding between FAILED_PRECONDITION, ABORTED, and
110
+ * UNAVAILABLE.
111
+ * HTTP 409
112
+ */
113
+ ErrorCodes[ErrorCodes["ABORTED"] = 10] = "ABORTED";
114
+ /**
115
+ * The operation was attempted past the valid range. E.g.,
116
+ * seeking or reading past end-of-file. Unlike INVALID_ARGUMENT, this error
117
+ * indicates a problem that may be fixed if the system state changes. For
118
+ * example, a 32-bit file system will generate INVALID_ARGUMENT if asked to
119
+ * read at an offset that is not in the range [0,2^32-1], but it will
120
+ * generate OUT_OF_RANGE if asked to read from an offset past the current
121
+ * file size. There is a fair bit of overlap between FAILED_PRECONDITION and
122
+ * OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific error)
123
+ * when it applies so that callers who are iterating through a space can
124
+ * easily look for an OUT_OF_RANGE error to detect when they are done.
125
+ * HTTP 400
126
+ */
127
+ ErrorCodes[ErrorCodes["OUT_OF_RANGE"] = 11] = "OUT_OF_RANGE";
128
+ /**
129
+ * The operation is not implemented or is not
130
+ * supported/enabled in this service.
131
+ * HTTP 501
132
+ */
133
+ ErrorCodes[ErrorCodes["UNIMPLEMENTED"] = 12] = "UNIMPLEMENTED";
134
+ /**
135
+ * Internal errors. This means that some invariants expected by
136
+ * the underlying system have been broken. This error code is reserved for
137
+ * serious errors.
138
+ * HTTP 500
139
+ */
140
+ ErrorCodes[ErrorCodes["INTERNAL"] = 13] = "INTERNAL";
141
+ /**
142
+ * The service is currently unavailable. This is most likely a
143
+ * transient condition, which can be corrected by retrying with a backoff.
144
+ * Note that it is not always safe to retry non-idempotent operations.
145
+ * HTTP 503
146
+ */
147
+ ErrorCodes[ErrorCodes["UNAVAILABLE"] = 14] = "UNAVAILABLE";
148
+ /**
149
+ * Unrecoverable data loss or corruption.
150
+ * HTTP 500
151
+ */
152
+ ErrorCodes[ErrorCodes["DATA_LOSS"] = 15] = "DATA_LOSS";
153
+ /**
154
+ * The request does not have valid authentication
155
+ * credentials for the operation.
156
+ * HTTP 401
157
+ */
158
+ ErrorCodes[ErrorCodes["UNAUTHENTICATED"] = 16] = "UNAUTHENTICATED";
159
+ })(ErrorCodes = exports.ErrorCodes || (exports.ErrorCodes = {}));
160
+ var RestateErrorCodes;
161
+ (function (RestateErrorCodes) {
162
+ RestateErrorCodes[RestateErrorCodes["JOURNAL_MISMATCH"] = 32] = "JOURNAL_MISMATCH";
163
+ RestateErrorCodes[RestateErrorCodes["PROTOCOL_VIOLATION"] = 33] = "PROTOCOL_VIOLATION";
164
+ })(RestateErrorCodes = exports.RestateErrorCodes || (exports.RestateErrorCodes = {}));
165
+ function ensureError(e) {
166
+ if (e instanceof Error) {
167
+ return e;
168
+ }
169
+ let msg;
170
+ try {
171
+ msg = JSON.stringify(e);
172
+ }
173
+ catch (x) {
174
+ msg = "(no JSON representation)";
175
+ }
176
+ return new Error("Non-Error value: " + msg);
177
+ }
178
+ exports.ensureError = ensureError;
179
+ class RestateError extends Error {
180
+ code;
181
+ constructor(message, options) {
182
+ super(message, { cause: options?.cause });
183
+ this.code = options?.errorCode ?? ErrorCodes.INTERNAL;
184
+ }
185
+ toFailure() {
186
+ return protocol_1.Failure.create({
187
+ code: this.code,
188
+ message: this.message,
189
+ });
190
+ }
191
+ }
192
+ exports.RestateError = RestateError;
193
+ // Does not lead to Restate retries
194
+ // Leads to an output message with a failure defined
195
+ class TerminalError extends RestateError {
196
+ constructor(message, options) {
197
+ super(message, options);
198
+ }
199
+ }
200
+ exports.TerminalError = TerminalError;
201
+ class TimeoutError extends TerminalError {
202
+ constructor() {
203
+ super("Timeout occurred", { errorCode: ErrorCodes.DEADLINE_EXCEEDED });
204
+ }
205
+ }
206
+ exports.TimeoutError = TimeoutError;
207
+ // Leads to Restate retries
208
+ class RetryableError extends RestateError {
209
+ constructor(message, options) {
210
+ super(message, options);
211
+ }
212
+ static internal(message) {
213
+ return new RetryableError(message);
214
+ }
215
+ static journalMismatch(journalIndex, actualEntry, expectedEntry) {
216
+ const msg = `Journal mismatch: Replayed journal entries did not correspond to the user code. The user code has to be deterministic!
217
+ The journal entry at position ${journalIndex} was:
218
+ - In the user code: type: ${expectedEntry.messageType}, message:${(0, utils_1.formatMessageAsJson)(expectedEntry.message)}
219
+ - In the replayed messages: type: ${actualEntry.messageType}, message: ${(0, utils_1.formatMessageAsJson)(actualEntry.message)}`;
220
+ return new RetryableError(msg, {
221
+ errorCode: RestateErrorCodes.JOURNAL_MISMATCH,
222
+ });
223
+ }
224
+ static protocolViolation(message) {
225
+ return new RetryableError(message, {
226
+ errorCode: RestateErrorCodes.PROTOCOL_VIOLATION,
227
+ });
228
+ }
229
+ static apiViolation(message) {
230
+ return new RetryableError(`API violation: ${message}`, {
231
+ errorCode: ErrorCodes.INTERNAL,
232
+ });
233
+ }
234
+ }
235
+ exports.RetryableError = RetryableError;
236
+ function errorToFailure(err) {
237
+ return err instanceof RestateError
238
+ ? err.toFailure()
239
+ : protocol_1.Failure.create({
240
+ code: ErrorCodes.INTERNAL,
241
+ message: err.message,
242
+ });
243
+ }
244
+ exports.errorToFailure = errorToFailure;
245
+ function errorToFailureWithTerminal(err) {
246
+ const failure = errorToFailure(err);
247
+ return javascript_1.FailureWithTerminal.create({
248
+ failure,
249
+ terminal: err instanceof TerminalError,
250
+ });
251
+ }
252
+ exports.errorToFailureWithTerminal = errorToFailureWithTerminal;
253
+ function failureToTerminalError(failure) {
254
+ return failureToError(failure, true);
255
+ }
256
+ exports.failureToTerminalError = failureToTerminalError;
257
+ function failureToError(failure, terminalError) {
258
+ const errorMessage = failure.message ?? "(missing error message)";
259
+ const errorCode = failure.code ?? ErrorCodes.INTERNAL;
260
+ return terminalError
261
+ ? new TerminalError(errorMessage, { errorCode })
262
+ : new RestateError(errorMessage, { errorCode });
263
+ }
264
+ exports.failureToError = failureToError;
265
+ function errorToErrorMessage(err) {
266
+ const code = err instanceof RestateError ? err.code : ErrorCodes.INTERNAL;
267
+ return protocol_1.ErrorMessage.create({
268
+ code: code,
269
+ message: err.message,
270
+ });
271
+ }
272
+ exports.errorToErrorMessage = errorToErrorMessage;
273
+ //# 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,0CAAqD;AACrD,8DAAoE;AAGpE,IAAY,UA4IX;AA5ID,WAAY,UAAU;IACpB;;;OAGG;IACH,uCAAM,CAAA;IACN;;;OAGG;IACH,qDAAa,CAAA;IACb;;;;;;;OAOG;IACH,iDAAW,CAAA;IACX;;;;;;OAMG;IACH,mEAAoB,CAAA;IACpB;;;;;;;OAOG;IACH,qEAAqB,CAAA;IACrB;;;;;;;;OAQG;IACH,qDAAa,CAAA;IACb;;;;OAIG;IACH,+DAAkB,CAAA;IAClB;;;;;;;;;OASG;IACH,qEAAqB,CAAA;IACrB;;;;OAIG;IACH,uEAAsB,CAAA;IACtB;;;;;;;;;;;;;;;OAeG;IACH,yEAAuB,CAAA;IACvB;;;;;;OAMG;IACH,kDAAY,CAAA;IACZ;;;;;;;;;;;;OAYG;IACH,4DAAiB,CAAA;IACjB;;;;OAIG;IACH,8DAAkB,CAAA;IAClB;;;;;OAKG;IACH,oDAAa,CAAA;IACb;;;;;OAKG;IACH,0DAAgB,CAAA;IAChB;;;OAGG;IACH,sDAAc,CAAA;IACd;;;;OAIG;IACH,kEAAoB,CAAA;AACtB,CAAC,EA5IW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QA4IrB;AACD,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,kFAAqB,CAAA;IACrB,sFAAuB,CAAA;AACzB,CAAC,EAHW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAG5B;AAED,SAAgB,WAAW,CAAC,CAAU;IACpC,IAAI,CAAC,YAAY,KAAK,EAAE;QACtB,O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,OAAgB;IACrD,OAAO,cAAc,CAAC,OAAO,EAAE,IAAI,CAAkB,CAAC;AACxD,CAAC;AAFD,wDAEC;AAED,SAAgB,cAAc,CAC5B,OAAgB,EAChB,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"}
@@ -1,13 +1,15 @@
1
- import { RestateContext } from "../restate_context";
1
+ import { Context } from "../context";
2
2
  import { FileDescriptorProto } from "ts-proto-descriptors";
3
3
  export declare class GrpcServiceMethod<I, O> {
4
4
  readonly name: string;
5
5
  readonly localName: string;
6
+ readonly keyedContext: boolean;
6
7
  readonly localFn: (instance: unknown, input: I) => Promise<O>;
7
8
  readonly inputDecoder: (buf: Uint8Array) => I;
8
9
  readonly outputEncoder: (output: O) => Uint8Array;
9
10
  constructor(name: string, // the gRPC name as defined in the .proto file
10
11
  localName: string, // the method name as defined in the class.
12
+ keyedContext: boolean, // If the method expects a keyed context
11
13
  localFn: (instance: unknown, input: I) => Promise<O>, // the actual function
12
14
  inputDecoder: (buf: Uint8Array) => I, // the protobuf decoder
13
15
  outputEncoder: (output: O) => Uint8Array);
@@ -21,11 +23,11 @@ export declare class GrpcService {
21
23
  }
22
24
  export declare class HostedGrpcServiceMethod<I, O> {
23
25
  readonly instance: unknown;
24
- readonly packge: string;
26
+ readonly pkg: string;
25
27
  readonly service: string;
26
28
  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
+ constructor(instance: unknown, pkg: string, service: string, method: GrpcServiceMethod<I, O>);
30
+ invoke(context: Context, inBytes: Uint8Array): Promise<Uint8Array>;
29
31
  }
30
32
  type ProtoMetaMessageOptions = {
31
33
  options?: {
@@ -1 +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,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,SAAS,EAAE,MAAM;IAC1B,QAAQ,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC;IAC7D,QAAQ,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,CAAC;IAC7C,QAAQ,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,UAAU;gBAJxC,IAAI,EAAE,MAAM,EAAE,8CAA8C;IAC5D,SAAS,EAAE,MAAM,EAAE,2CAA2C;IAC9D,OAAO,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,sBAAsB;IAC5E,YAAY,EAAE,C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E,MAAM,GAAG,GAAG,CAAA;SAAE,CAAC;QACjC,QAAQ,CAAC,EAAE;YACT,CAAC,GAAG,EAAE,MAAM,GAAG;gBACb,OAAO,CAAC,EAAE;oBAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;iBAAE,CAAC;gBACjC,OAAO,CAAC,EAAE;oBAAE,CAAC,GAAG,EAAE,MAAM,GAAG;wBAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;qBAAE,CAAA;iBAAE,CAAC;aACrD,CAAC;SACH,CAAC;QACF,QAAQ,CAAC,EAAE;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,uBAAuB,CAAA;SAAE,CAAC;QACtD,KAAK,CAAC,EAAE;YACN,CAAC,GAAG,EAAE,MAAM,GAAG;gBACb,OAAO,CAAC,EAAE;oBAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;iBAAE,CAAC;gBACjC,MAAM,CAAC,EAAE;oBAAE,CAAC,GAAG,EAAE,MAAM,GAAG;wBAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;qBAAE,CAAA;iBAAE,CAAC;aACpD,CAAC;SACH,CAAC;KACH,CAAC;CACH"}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2023-2024 - 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.HostedGrpcServiceMethod = exports.GrpcService = exports.GrpcServiceMethod = void 0;
14
+ class GrpcServiceMethod {
15
+ name;
16
+ localName;
17
+ keyedContext;
18
+ localFn;
19
+ inputDecoder;
20
+ outputEncoder;
21
+ constructor(name, // the gRPC name as defined in the .proto file
22
+ localName, // the method name as defined in the class.
23
+ keyedContext, // If the method expects a keyed context
24
+ localFn, // the actual function
25
+ inputDecoder, // the protobuf decoder
26
+ outputEncoder // protobuf encoder
27
+ ) {
28
+ this.name = name;
29
+ this.localName = localName;
30
+ this.keyedContext = keyedContext;
31
+ this.localFn = localFn;
32
+ this.inputDecoder = inputDecoder;
33
+ this.outputEncoder = outputEncoder;
34
+ }
35
+ }
36
+ exports.GrpcServiceMethod = GrpcServiceMethod;
37
+ class GrpcService {
38
+ name;
39
+ packge;
40
+ impl;
41
+ methods;
42
+ constructor(name, packge, impl, methods) {
43
+ this.name = name;
44
+ this.packge = packge;
45
+ this.impl = impl;
46
+ this.methods = methods;
47
+ }
48
+ }
49
+ exports.GrpcService = GrpcService;
50
+ class HostedGrpcServiceMethod {
51
+ instance;
52
+ pkg;
53
+ service;
54
+ method;
55
+ constructor(instance, pkg, service, method) {
56
+ this.instance = instance;
57
+ this.pkg = pkg;
58
+ this.service = service;
59
+ this.method = method;
60
+ }
61
+ // The end of an invoke is either a response (Uint8Array) or a SuspensionMessage
62
+ async invoke(context, inBytes) {
63
+ const instanceWithContext = setContext(this.instance, context);
64
+ const input = this.method.inputDecoder(inBytes);
65
+ const result = await this.method.localFn(instanceWithContext, input);
66
+ return this.method.outputEncoder(result);
67
+ }
68
+ }
69
+ exports.HostedGrpcServiceMethod = HostedGrpcServiceMethod;
70
+ function setContext(instance, context) {
71
+ // creates a *new*, per call object that shares all the properties that @instance has
72
+ // except '$$restate' which is a unique, per call pointer to a restate context.
73
+ //
74
+ // The following line create a new object, that its prototype is @instance.
75
+ // and that object has a $$restate property.
76
+ const wrapper = Object.create(instance, {
77
+ $$restate: { value: context },
78
+ });
79
+ return wrapper;
80
+ }
81
+ //# sourceMappingURL=grpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grpc.js","sourceRoot":"","sources":["../../src/types/grpc.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAKH,MAAa,iBAAiB;I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C;QACxE,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;CACF;AAfD,0DAeC;AAED,SAAS,UAAU,CAAI,QAAW,EAAE,OAAgB;IAClD,qFAAqF;IACrF,+EAA+E;IAC/E,EAAE;IACF,2EAA2E;IAC3E,4CAA4C;IAC5C,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,QAAkB,EAAE;QAChD,SAAS,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE;KAC9B,CAAC,CAAC;IACH,OAAO,OAAY,CAAC;AACtB,CAAC"}
@@ -1,6 +1,6 @@
1
- import { SideEffectEntryMessage } from "../generated/proto/javascript";
2
- import { AwakeableEntryMessage, BackgroundInvokeEntryMessage, ClearStateEntryMessage, CompleteAwakeableEntryMessage, CompletionMessage, EntryAckMessage, ErrorMessage, EndMessage, GetStateEntryMessage, InvokeEntryMessage, OutputStreamEntryMessage, PollInputStreamEntryMessage, SetStateEntryMessage, SleepEntryMessage, StartMessage, SuspensionMessage } from "../generated/proto/protocol";
3
- export { AwakeableEntryMessage, BackgroundInvokeEntryMessage, ClearStateEntryMessage, CompleteAwakeableEntryMessage, CompletionMessage, ErrorMessage, EndMessage, GetStateEntryMessage, InvokeEntryMessage, OutputStreamEntryMessage, PollInputStreamEntryMessage, SetStateEntryMessage, SleepEntryMessage, StartMessage, SuspensionMessage, EntryAckMessage, } from "../generated/proto/protocol";
1
+ import { SideEffectEntryMessage, CombinatorEntryMessage } from "../generated/proto/javascript";
2
+ import { AwakeableEntryMessage, BackgroundInvokeEntryMessage, ClearStateEntryMessage, ClearAllStateEntryMessage, CompleteAwakeableEntryMessage, CompletionMessage, EntryAckMessage, ErrorMessage, EndMessage, GetStateEntryMessage, GetStateKeysEntryMessage, InvokeEntryMessage, OutputStreamEntryMessage, PollInputStreamEntryMessage, SetStateEntryMessage, SleepEntryMessage, StartMessage, SuspensionMessage } from "../generated/proto/protocol";
3
+ export { AwakeableEntryMessage, BackgroundInvokeEntryMessage, ClearStateEntryMessage, ClearAllStateEntryMessage, CompleteAwakeableEntryMessage, CompletionMessage, ErrorMessage, EndMessage, GetStateEntryMessage, GetStateKeysEntryMessage, InvokeEntryMessage, OutputStreamEntryMessage, PollInputStreamEntryMessage, SetStateEntryMessage, SleepEntryMessage, StartMessage, SuspensionMessage, EntryAckMessage, } from "../generated/proto/protocol";
4
4
  export declare const START_MESSAGE_TYPE = 0n;
5
5
  export declare const COMPLETION_MESSAGE_TYPE = 1n;
6
6
  export declare const SUSPENSION_MESSAGE_TYPE = 2n;
@@ -12,15 +12,19 @@ export declare const OUTPUT_STREAM_ENTRY_MESSAGE_TYPE = 1025n;
12
12
  export declare const GET_STATE_ENTRY_MESSAGE_TYPE = 2048n;
13
13
  export declare const SET_STATE_ENTRY_MESSAGE_TYPE = 2049n;
14
14
  export declare const CLEAR_STATE_ENTRY_MESSAGE_TYPE = 2050n;
15
+ export declare const CLEAR_ALL_STATE_ENTRY_MESSAGE_TYPE = 2051n;
16
+ export declare const GET_STATE_KEYS_ENTRY_MESSAGE_TYPE = 2052n;
15
17
  export declare const SLEEP_ENTRY_MESSAGE_TYPE = 3072n;
16
18
  export declare const INVOKE_ENTRY_MESSAGE_TYPE = 3073n;
17
19
  export declare const BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE = 3074n;
18
20
  export declare const AWAKEABLE_ENTRY_MESSAGE_TYPE = 3075n;
19
21
  export declare const COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE = 3076n;
22
+ export declare const AWAKEABLE_IDENTIFIER_PREFIX = "prom_1";
20
23
  export declare const SIDE_EFFECT_ENTRY_MESSAGE_TYPE = 64513n;
24
+ export declare const COMBINATOR_ENTRY_MESSAGE = 64514n;
21
25
  export declare const KNOWN_MESSAGE_TYPES: Set<bigint>;
22
- export declare const PROTOBUF_MESSAGE_NAME_BY_TYPE: Map<bigint, string>;
26
+ export declare function formatMessageType(messageType: bigint): string;
23
27
  export declare const PROTOBUF_MESSAGE_BY_TYPE: Map<bigint, any>;
24
- export type ProtocolMessage = StartMessage | CompletionMessage | SuspensionMessage | ErrorMessage | EntryAckMessage | EndMessage | PollInputStreamEntryMessage | OutputStreamEntryMessage | GetStateEntryMessage | SetStateEntryMessage | ClearStateEntryMessage | SleepEntryMessage | InvokeEntryMessage | BackgroundInvokeEntryMessage | AwakeableEntryMessage | CompleteAwakeableEntryMessage | SideEffectEntryMessage;
28
+ export type ProtocolMessage = StartMessage | CompletionMessage | SuspensionMessage | ErrorMessage | EntryAckMessage | EndMessage | PollInputStreamEntryMessage | OutputStreamEntryMessage | GetStateEntryMessage | GetStateKeysEntryMessage | SetStateEntryMessage | ClearStateEntryMessage | ClearAllStateEntryMessage | SleepEntryMessage | InvokeEntryMessage | BackgroundInvokeEntryMessage | AwakeableEntryMessage | CompleteAwakeableEntryMessage | SideEffectEntryMessage | CombinatorEntryMessage;
25
29
  export declare const SUSPENSION_TRIGGERS: bigint[];
26
30
  //# sourceMappingURL=protocol.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/types/protocol.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EACL,qBAAqB,EACrB,4BAA4B,EAC5B,sBAAsB,EACtB,6BAA6B,EAC7B,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,EACxB,2BAA2B,EAC3B,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EACL,qBAAqB,EACrB,4BAA4B,EAC5B,sBAAsB,EACtB,6BAA6B,EAC7B,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,EACxB,2BAA2B,EAC3B,oBAAoB,EACpB,iBAAiB,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M,yBAAyB,QAAU,CAAC;AACjD,eAAO,MAAM,oCAAoC,QAAU,CAAC;AAC5D,eAAO,MAAM,4BAA4B,QAAU,CAAC;AACpD,eAAO,MAAM,qCAAqC,QAAU,CAAC;AAE7D,eAAO,MAAM,2BAA2B,WAAW,CAAC;AAIpD,eAAO,MAAM,8BAA8B,SAAU,CAAC;AACtD,eAAO,MAAM,wBAAwB,SAAU,CAAC;AAMhD,eAAO,MAAM,mBAAmB,aAqB9B,CAAC;AAyBH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,UAIpD;AA0BD,eAAO,MAAM,wBAAwB,kBAA6B,CAAC;AAEnE,MAAM,MAAM,eAAe,GACvB,YAAY,GACZ,iBAAiB,GACjB,iBAAiB,GACjB,YAAY,GACZ,eAAe,GACf,UAAU,GACV,2BAA2B,GAC3B,wBAAwB,GACxB,oBAAoB,GACpB,wBAAwB,GACxB,oBAAoB,GACpB,sBAAsB,GACtB,yBAAyB,GACzB,iBAAiB,GACjB,kBAAkB,GAClB,4BAA4B,GAC5B,qBAAqB,GACrB,6BAA6B,GAC7B,sBAAsB,GACtB,sBAAsB,CAAC;AAI3B,eAAO,MAAM,mBAAmB,EAAE,MAAM,EASvC,CAAC"}
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2023-2024 - 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.SUSPENSION_TRIGGERS = exports.PROTOBUF_MESSAGE_BY_TYPE = exports.formatMessageType = exports.KNOWN_MESSAGE_TYPES = exports.COMBINATOR_ENTRY_MESSAGE = exports.SIDE_EFFECT_ENTRY_MESSAGE_TYPE = exports.AWAKEABLE_IDENTIFIER_PREFIX = exports.COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE = exports.AWAKEABLE_ENTRY_MESSAGE_TYPE = exports.BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE = exports.INVOKE_ENTRY_MESSAGE_TYPE = exports.SLEEP_ENTRY_MESSAGE_TYPE = exports.GET_STATE_KEYS_ENTRY_MESSAGE_TYPE = exports.CLEAR_ALL_STATE_ENTRY_MESSAGE_TYPE = exports.CLEAR_STATE_ENTRY_MESSAGE_TYPE = exports.SET_STATE_ENTRY_MESSAGE_TYPE = exports.GET_STATE_ENTRY_MESSAGE_TYPE = exports.OUTPUT_STREAM_ENTRY_MESSAGE_TYPE = exports.POLL_INPUT_STREAM_ENTRY_MESSAGE_TYPE = exports.END_MESSAGE_TYPE = exports.ENTRY_ACK_MESSAGE_TYPE = exports.ERROR_MESSAGE_TYPE = exports.SUSPENSION_MESSAGE_TYPE = exports.COMPLETION_MESSAGE_TYPE = exports.START_MESSAGE_TYPE = exports.EntryAckMessage = exports.SuspensionMessage = exports.StartMessage = exports.SleepEntryMessage = exports.SetStateEntryMessage = exports.PollInputStreamEntryMessage = exports.OutputStreamEntryMessage = exports.InvokeEntryMessage = exports.GetStateKeysEntryMessage = exports.GetStateEntryMessage = exports.EndMessage = exports.ErrorMessage = exports.CompletionMessage = exports.CompleteAwakeableEntryMessage = exports.ClearAllStateEntryMessage = exports.ClearStateEntryMessage = exports.BackgroundInvokeEntryMessage = exports.AwakeableEntryMessage = void 0;
14
+ const javascript_1 = require("../generated/proto/javascript");
15
+ const protocol_1 = require("../generated/proto/protocol");
16
+ // Re-export the protobuf messages.
17
+ var protocol_2 = require("../generated/proto/protocol");
18
+ Object.defineProperty(exports, "AwakeableEntryMessage", { enumerable: true, get: function () { return protocol_2.AwakeableEntryMessage; } });
19
+ Object.defineProperty(exports, "BackgroundInvokeEntryMessage", { enumerable: true, get: function () { return protocol_2.BackgroundInvokeEntryMessage; } });
20
+ Object.defineProperty(exports, "ClearStateEntryMessage", { enumerable: true, get: function () { return protocol_2.ClearStateEntryMessage; } });
21
+ Object.defineProperty(exports, "ClearAllStateEntryMessage", { enumerable: true, get: function () { return protocol_2.ClearAllStateEntryMessage; } });
22
+ Object.defineProperty(exports, "CompleteAwakeableEntryMessage", { enumerable: true, get: function () { return protocol_2.CompleteAwakeableEntryMessage; } });
23
+ Object.defineProperty(exports, "CompletionMessage", { enumerable: true, get: function () { return protocol_2.CompletionMessage; } });
24
+ Object.defineProperty(exports, "ErrorMessage", { enumerable: true, get: function () { return protocol_2.ErrorMessage; } });
25
+ Object.defineProperty(exports, "EndMessage", { enumerable: true, get: function () { return protocol_2.EndMessage; } });
26
+ Object.defineProperty(exports, "GetStateEntryMessage", { enumerable: true, get: function () { return protocol_2.GetStateEntryMessage; } });
27
+ Object.defineProperty(exports, "GetStateKeysEntryMessage", { enumerable: true, get: function () { return protocol_2.GetStateKeysEntryMessage; } });
28
+ Object.defineProperty(exports, "InvokeEntryMessage", { enumerable: true, get: function () { return protocol_2.InvokeEntryMessage; } });
29
+ Object.defineProperty(exports, "OutputStreamEntryMessage", { enumerable: true, get: function () { return protocol_2.OutputStreamEntryMessage; } });
30
+ Object.defineProperty(exports, "PollInputStreamEntryMessage", { enumerable: true, get: function () { return protocol_2.PollInputStreamEntryMessage; } });
31
+ Object.defineProperty(exports, "SetStateEntryMessage", { enumerable: true, get: function () { return protocol_2.SetStateEntryMessage; } });
32
+ Object.defineProperty(exports, "SleepEntryMessage", { enumerable: true, get: function () { return protocol_2.SleepEntryMessage; } });
33
+ Object.defineProperty(exports, "StartMessage", { enumerable: true, get: function () { return protocol_2.StartMessage; } });
34
+ Object.defineProperty(exports, "SuspensionMessage", { enumerable: true, get: function () { return protocol_2.SuspensionMessage; } });
35
+ Object.defineProperty(exports, "EntryAckMessage", { enumerable: true, get: function () { return protocol_2.EntryAckMessage; } });
36
+ // Export the protocol message types as defined by the restate protocol.
37
+ exports.START_MESSAGE_TYPE = 0x0000n;
38
+ exports.COMPLETION_MESSAGE_TYPE = 0x0001n;
39
+ exports.SUSPENSION_MESSAGE_TYPE = 0x0002n;
40
+ exports.ERROR_MESSAGE_TYPE = 0x0003n;
41
+ exports.ENTRY_ACK_MESSAGE_TYPE = 0x0004n;
42
+ exports.END_MESSAGE_TYPE = 0x0005n;
43
+ exports.POLL_INPUT_STREAM_ENTRY_MESSAGE_TYPE = 0x0400n;
44
+ exports.OUTPUT_STREAM_ENTRY_MESSAGE_TYPE = 0x0401n;
45
+ exports.GET_STATE_ENTRY_MESSAGE_TYPE = 0x0800n;
46
+ exports.SET_STATE_ENTRY_MESSAGE_TYPE = 0x0801n;
47
+ exports.CLEAR_STATE_ENTRY_MESSAGE_TYPE = 0x0802n;
48
+ exports.CLEAR_ALL_STATE_ENTRY_MESSAGE_TYPE = 0x0803n;
49
+ exports.GET_STATE_KEYS_ENTRY_MESSAGE_TYPE = 0x0804n;
50
+ exports.SLEEP_ENTRY_MESSAGE_TYPE = 0x0c00n;
51
+ exports.INVOKE_ENTRY_MESSAGE_TYPE = 0x0c01n;
52
+ exports.BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE = 0x0c02n;
53
+ exports.AWAKEABLE_ENTRY_MESSAGE_TYPE = 0x0c03n;
54
+ exports.COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE = 0x0c04n;
55
+ exports.AWAKEABLE_IDENTIFIER_PREFIX = "prom_1";
56
+ // Export the custom message types
57
+ // Side effects are custom messages because the runtime does not need to inspect them
58
+ exports.SIDE_EFFECT_ENTRY_MESSAGE_TYPE = 0xfc01n;
59
+ exports.COMBINATOR_ENTRY_MESSAGE = 0xfc02n;
60
+ // Restate DuplexStream
61
+ // Message types in the protocol.
62
+ // Custom message types (per SDK) such as side effect entry message should not be included here.
63
+ exports.KNOWN_MESSAGE_TYPES = new Set([
64
+ exports.START_MESSAGE_TYPE,
65
+ exports.COMPLETION_MESSAGE_TYPE,
66
+ exports.SUSPENSION_MESSAGE_TYPE,
67
+ exports.ERROR_MESSAGE_TYPE,
68
+ exports.ENTRY_ACK_MESSAGE_TYPE,
69
+ exports.END_MESSAGE_TYPE,
70
+ exports.POLL_INPUT_STREAM_ENTRY_MESSAGE_TYPE,
71
+ exports.OUTPUT_STREAM_ENTRY_MESSAGE_TYPE,
72
+ exports.GET_STATE_ENTRY_MESSAGE_TYPE,
73
+ exports.GET_STATE_KEYS_ENTRY_MESSAGE_TYPE,
74
+ exports.SET_STATE_ENTRY_MESSAGE_TYPE,
75
+ exports.CLEAR_STATE_ENTRY_MESSAGE_TYPE,
76
+ exports.CLEAR_ALL_STATE_ENTRY_MESSAGE_TYPE,
77
+ exports.SLEEP_ENTRY_MESSAGE_TYPE,
78
+ exports.INVOKE_ENTRY_MESSAGE_TYPE,
79
+ exports.BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE,
80
+ exports.AWAKEABLE_ENTRY_MESSAGE_TYPE,
81
+ exports.COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE,
82
+ exports.SIDE_EFFECT_ENTRY_MESSAGE_TYPE,
83
+ exports.COMBINATOR_ENTRY_MESSAGE,
84
+ ]);
85
+ const PROTOBUF_MESSAGE_NAME_BY_TYPE = new Map([
86
+ [exports.START_MESSAGE_TYPE, "StartMessage"],
87
+ [exports.COMPLETION_MESSAGE_TYPE, "CompletionMessage"],
88
+ [exports.SUSPENSION_MESSAGE_TYPE, "SuspensionMessage"],
89
+ [exports.ERROR_MESSAGE_TYPE, "ErrorMessage"],
90
+ [exports.ENTRY_ACK_MESSAGE_TYPE, "EntryAckMessage"],
91
+ [exports.END_MESSAGE_TYPE, "EndMessage"],
92
+ [exports.POLL_INPUT_STREAM_ENTRY_MESSAGE_TYPE, "PollInputStreamEntryMessage"],
93
+ [exports.OUTPUT_STREAM_ENTRY_MESSAGE_TYPE, "OutputStreamEntryMessage"],
94
+ [exports.GET_STATE_ENTRY_MESSAGE_TYPE, "GetStateEntryMessage"],
95
+ [exports.GET_STATE_KEYS_ENTRY_MESSAGE_TYPE, "GetStateKeysEntryMessage"],
96
+ [exports.SET_STATE_ENTRY_MESSAGE_TYPE, "SetStateEntryMessage"],
97
+ [exports.CLEAR_STATE_ENTRY_MESSAGE_TYPE, "ClearStateEntryMessage"],
98
+ [exports.CLEAR_ALL_STATE_ENTRY_MESSAGE_TYPE, "ClearAllStateEntryMessage"],
99
+ [exports.SLEEP_ENTRY_MESSAGE_TYPE, "SleepEntryMessage"],
100
+ [exports.INVOKE_ENTRY_MESSAGE_TYPE, "InvokeEntryMessage"],
101
+ [exports.BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE, "BackgroundInvokeEntryMessage"],
102
+ [exports.AWAKEABLE_ENTRY_MESSAGE_TYPE, "AwakeableEntryMessage"],
103
+ [exports.COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE, "CompleteAwakeableEntryMessage"],
104
+ [exports.SIDE_EFFECT_ENTRY_MESSAGE_TYPE, "SideEffectEntryMessage"],
105
+ [exports.COMBINATOR_ENTRY_MESSAGE, "CombinatorEntryMessage"],
106
+ ]);
107
+ function formatMessageType(messageType) {
108
+ return (PROTOBUF_MESSAGE_NAME_BY_TYPE.get(messageType) || messageType.toString());
109
+ }
110
+ exports.formatMessageType = formatMessageType;
111
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
112
+ const PROTOBUF_MESSAGES = [
113
+ [exports.START_MESSAGE_TYPE, protocol_1.StartMessage],
114
+ [exports.COMPLETION_MESSAGE_TYPE, protocol_1.CompletionMessage],
115
+ [exports.SUSPENSION_MESSAGE_TYPE, protocol_1.SuspensionMessage],
116
+ [exports.ERROR_MESSAGE_TYPE, protocol_1.ErrorMessage],
117
+ [exports.ENTRY_ACK_MESSAGE_TYPE, protocol_1.EntryAckMessage],
118
+ [exports.END_MESSAGE_TYPE, protocol_1.EndMessage],
119
+ [exports.POLL_INPUT_STREAM_ENTRY_MESSAGE_TYPE, protocol_1.PollInputStreamEntryMessage],
120
+ [exports.OUTPUT_STREAM_ENTRY_MESSAGE_TYPE, protocol_1.OutputStreamEntryMessage],
121
+ [exports.GET_STATE_ENTRY_MESSAGE_TYPE, protocol_1.GetStateEntryMessage],
122
+ [exports.GET_STATE_KEYS_ENTRY_MESSAGE_TYPE, protocol_1.GetStateKeysEntryMessage],
123
+ [exports.SET_STATE_ENTRY_MESSAGE_TYPE, protocol_1.SetStateEntryMessage],
124
+ [exports.CLEAR_STATE_ENTRY_MESSAGE_TYPE, protocol_1.ClearStateEntryMessage],
125
+ [exports.CLEAR_ALL_STATE_ENTRY_MESSAGE_TYPE, protocol_1.ClearAllStateEntryMessage],
126
+ [exports.SLEEP_ENTRY_MESSAGE_TYPE, protocol_1.SleepEntryMessage],
127
+ [exports.INVOKE_ENTRY_MESSAGE_TYPE, protocol_1.InvokeEntryMessage],
128
+ [exports.BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE, protocol_1.BackgroundInvokeEntryMessage],
129
+ [exports.AWAKEABLE_ENTRY_MESSAGE_TYPE, protocol_1.AwakeableEntryMessage],
130
+ [exports.COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE, protocol_1.CompleteAwakeableEntryMessage],
131
+ [exports.SIDE_EFFECT_ENTRY_MESSAGE_TYPE, javascript_1.SideEffectEntryMessage],
132
+ [exports.COMBINATOR_ENTRY_MESSAGE, javascript_1.CombinatorEntryMessage],
133
+ ];
134
+ exports.PROTOBUF_MESSAGE_BY_TYPE = new Map(PROTOBUF_MESSAGES);
135
+ // These message types will trigger sending a suspension message from the runtime
136
+ // for each of the protocol modes
137
+ exports.SUSPENSION_TRIGGERS = [
138
+ exports.INVOKE_ENTRY_MESSAGE_TYPE,
139
+ exports.GET_STATE_ENTRY_MESSAGE_TYPE,
140
+ exports.GET_STATE_KEYS_ENTRY_MESSAGE_TYPE,
141
+ exports.AWAKEABLE_ENTRY_MESSAGE_TYPE,
142
+ exports.SLEEP_ENTRY_MESSAGE_TYPE,
143
+ exports.COMBINATOR_ENTRY_MESSAGE,
144
+ // We need it because of the ack
145
+ exports.SIDE_EFFECT_ENTRY_MESSAGE_TYPE,
146
+ ];
147
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/types/protocol.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,8DAGuC;AACvC,0DAmBqC;AAErC,mCAAmC;AACnC,wDAmBqC;AAlBnC,iHAAA,qBAAqB,OAAA;AACrB,wHAAA,4BAA4B,OAAA;AAC5B,kHAAA,sBAAsB,OAAA;AACtB,qHAAA,yBAAyB,OAAA;AACzB,yHAAA,6BAA6B,OAAA;AAC7B,6GAAA,iBAAiB,OAAA;AACjB,wGAAA,YAAY,OAAA;AACZ,sGAAA,UAAU,OAAA;AACV,gHAAA,oBAAoB,OAAA;AACpB,oHAAA,wBAAwB,OAAA;AACxB,8GAAA,kBAAkB,OAAA;AAClB,oHAAA,wBAAwB,OAAA;AACxB,uHAAA,2BAA2B,OAAA;AAC3B,gHAAA,oBAAoB,OAAA;AACpB,6GAAA,iBAAiB,OAAA;AACjB,wGAAA,YAAY,OAAA;AACZ,6GAAA,iBAAiB,OAAA;AACjB,2GAAA,eAAe,OAAA;AAGjB,wEAAwE;AAC3D,QAAA,kBAAkB,GAAG,OAAO,CAAC;AAC7B,QAAA,uBAAuB,GAAG,OAAO,CAAC;AAClC,QAAA,uBAAuB,GAAG,OAAO,CAAC;AAClC,QAAA,kBAAkB,GAAG,OAAO,CAAC;AAC7B,QAAA,sBAAsB,GAAG,OAAO,CAAC;AACjC,QAAA,gBAAgB,GAAG,OAAO,CAAC;AAC3B,QAAA,oCAAoC,GAAG,OAAO,CAAC;AAC/C,QAAA,gCAAgC,GAAG,OAAO,CAAC;AAC3C,QAAA,4BAA4B,GAAG,OAAO,CAAC;AACvC,QAAA,4BAA4B,GAAG,OAAO,CAAC;AACvC,QAAA,8BAA8B,GAAG,OAAO,CAAC;AACzC,QAAA,kCAAkC,GAAG,OAAO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