@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,368 @@
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.NewExecutionState = exports.JournalEntry = exports.Journal = void 0;
37
+ const p = __importStar(require("./types/protocol"));
38
+ const protocol_1 = require("./types/protocol");
39
+ const utils_1 = require("./utils/utils");
40
+ const types_1 = require("./types/types");
41
+ const errors_1 = require("./types/errors");
42
+ class Journal {
43
+ invocation;
44
+ state = NewExecutionState.REPLAYING;
45
+ userCodeJournalIndex = 0;
46
+ // Journal entries waiting for arrival of runtime completion
47
+ // 0 = root promise of the method invocation
48
+ pendingJournalEntries = new Map();
49
+ constructor(invocation) {
50
+ this.invocation = invocation;
51
+ const inputMessage = invocation.replayEntries.get(0);
52
+ if (!inputMessage ||
53
+ inputMessage.messageType !== protocol_1.POLL_INPUT_STREAM_ENTRY_MESSAGE_TYPE) {
54
+ throw errors_1.RetryableError.protocolViolation("First message of replay entries needs to be PollInputStreamMessage");
55
+ }
56
+ this.handleInputMessage(inputMessage.message);
57
+ }
58
+ handleInputMessage(m) {
59
+ if (this.invocation.nbEntriesToReplay === 1) {
60
+ this.transitionState(NewExecutionState.PROCESSING);
61
+ }
62
+ const rootEntry = new JournalEntry(p.POLL_INPUT_STREAM_ENTRY_MESSAGE_TYPE, m);
63
+ this.pendingJournalEntries.set(0, rootEntry);
64
+ }
65
+ handleUserSideMessage(messageType, message
66
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
+ ) {
68
+ this.incrementUserCodeIndex();
69
+ switch (this.state) {
70
+ case NewExecutionState.REPLAYING: {
71
+ const replayEntry = this.invocation.replayEntries.get(this.userCodeJournalIndex);
72
+ if (replayEntry === undefined) {
73
+ throw errors_1.RetryableError.internal(`Illegal state: no replay message was received for the entry at journal index ${this.userCodeJournalIndex}`);
74
+ }
75
+ const journalEntry = new JournalEntry(messageType, message);
76
+ this.handleReplay(this.userCodeJournalIndex, replayEntry, journalEntry);
77
+ return journalEntry.promise;
78
+ }
79
+ case NewExecutionState.PROCESSING: {
80
+ switch (messageType) {
81
+ case p.SUSPENSION_MESSAGE_TYPE:
82
+ case p.OUTPUT_STREAM_ENTRY_MESSAGE_TYPE: {
83
+ this.handleClosingMessage(messageType, message);
84
+ return Promise.resolve(undefined);
85
+ }
86
+ case p.SET_STATE_ENTRY_MESSAGE_TYPE:
87
+ case p.CLEAR_STATE_ENTRY_MESSAGE_TYPE:
88
+ case p.COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE:
89
+ case p.BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE: {
90
+ // Do not need completion
91
+ return Promise.resolve(undefined);
92
+ }
93
+ case p.GET_STATE_ENTRY_MESSAGE_TYPE: {
94
+ const getStateMsg = message;
95
+ if (getStateMsg.value !== undefined ||
96
+ getStateMsg.empty !== undefined) {
97
+ // State was eagerly filled by the local state store
98
+ return Promise.resolve(getStateMsg.value || getStateMsg.empty);
99
+ }
100
+ else {
101
+ // Need to retrieve state by going to the runtime.
102
+ const journalEntry = new JournalEntry(messageType, message);
103
+ this.pendingJournalEntries.set(this.userCodeJournalIndex, journalEntry);
104
+ return journalEntry.promise;
105
+ }
106
+ }
107
+ default: {
108
+ // Need completion
109
+ const journalEntry = new JournalEntry(messageType, message);
110
+ this.pendingJournalEntries.set(this.userCodeJournalIndex, journalEntry);
111
+ return journalEntry.promise;
112
+ }
113
+ }
114
+ }
115
+ case NewExecutionState.CLOSED: {
116
+ // We cannot do anything anymore because an output was already sent back
117
+ // This should actually never happen because the state is only transitioned to closed if the root promise is resolved/rejected
118
+ // So no more user messages can come in...
119
+ // - Print warning log and continue...
120
+ //TODO received user-side message but state machine is closed
121
+ return Promise.resolve(undefined);
122
+ }
123
+ default: {
124
+ throw errors_1.RetryableError.protocolViolation("Did not receive input message before other messages.");
125
+ }
126
+ }
127
+ }
128
+ isUnResolved(index) {
129
+ const journalEntry = this.pendingJournalEntries.get(index);
130
+ return journalEntry !== undefined;
131
+ }
132
+ handleRuntimeCompletionMessage(m) {
133
+ // Get message at that entryIndex in pendingJournalEntries
134
+ const journalEntry = this.pendingJournalEntries.get(m.entryIndex);
135
+ if (journalEntry === undefined) {
136
+ //TODO received completion message but there is no pending promise for that index
137
+ return;
138
+ }
139
+ if (m.value !== undefined) {
140
+ journalEntry.resolve(m.value);
141
+ this.pendingJournalEntries.delete(m.entryIndex);
142
+ }
143
+ else if (m.failure !== undefined) {
144
+ // we do all completions with Terminal Errors, because failures triggered by those exceptions
145
+ // when the bubble up would otherwise lead to re-tries, deterministic replay, re-throwing, and
146
+ // thus an infinite loop that keeps replay-ing but never makes progress
147
+ // these failures here consequently need to cause terminal failures, unless caught and handled
148
+ // by the handler code
149
+ journalEntry.reject((0, errors_1.failureToError)(m.failure, true));
150
+ this.pendingJournalEntries.delete(m.entryIndex);
151
+ }
152
+ else if (m.empty !== undefined) {
153
+ journalEntry.resolve(m.empty);
154
+ this.pendingJournalEntries.delete(m.entryIndex);
155
+ }
156
+ else {
157
+ if (journalEntry.messageType === p.SIDE_EFFECT_ENTRY_MESSAGE_TYPE) {
158
+ // Just needs and ack without completion
159
+ journalEntry.resolve(undefined);
160
+ this.pendingJournalEntries.delete(m.entryIndex);
161
+ }
162
+ else {
163
+ //TODO completion message without a value/failure/empty and message is not a side effect
164
+ }
165
+ }
166
+ }
167
+ handleReplay(journalIndex, replayMessage, journalEntry) {
168
+ // Do the journal mismatch check
169
+ const match = this.checkJournalMatch(replayMessage.messageType, replayMessage.message, journalEntry.messageType, journalEntry.message);
170
+ // Journal mismatch check failedf
171
+ if (!match) {
172
+ throw errors_1.RetryableError.journalMismatch(journalIndex, replayMessage, journalEntry);
173
+ }
174
+ // If journal mismatch check passed
175
+ /*
176
+ - Else if the runtime replay message contains a completion
177
+ - If the completion is a value
178
+ - Return the resolved user code promise with the value
179
+ - Else if the completion is a failure
180
+ - Return the rejected user code promise with the failure as Error
181
+ - Else if the completion is an Empty message
182
+ - Return the resolved user code promise with the Empty message
183
+ - Remove the journal entry
184
+ - Else the replayed message was uncompleted
185
+ - Create the user code promise
186
+ - Add message to the pendingJournalEntries
187
+ - Return the user code promise
188
+ */
189
+ switch (journalEntry.messageType) {
190
+ case protocol_1.SUSPENSION_MESSAGE_TYPE:
191
+ case protocol_1.OUTPUT_STREAM_ENTRY_MESSAGE_TYPE: {
192
+ this.handleClosingMessage(journalEntry.messageType, journalEntry.message);
193
+ break;
194
+ }
195
+ case protocol_1.GET_STATE_ENTRY_MESSAGE_TYPE: {
196
+ const getStateMsg = replayMessage.message;
197
+ this.resolveResult(journalIndex, journalEntry, getStateMsg.value || getStateMsg.empty);
198
+ break;
199
+ }
200
+ case protocol_1.INVOKE_ENTRY_MESSAGE_TYPE: {
201
+ const invokeMsg = replayMessage.message;
202
+ this.resolveResult(journalIndex, journalEntry, invokeMsg.value, invokeMsg.failure);
203
+ break;
204
+ }
205
+ case protocol_1.SLEEP_ENTRY_MESSAGE_TYPE: {
206
+ const sleepMsg = replayMessage.message;
207
+ this.resolveResult(journalIndex, journalEntry, sleepMsg.result);
208
+ break;
209
+ }
210
+ case protocol_1.AWAKEABLE_ENTRY_MESSAGE_TYPE: {
211
+ const awakeableMsg = replayMessage.message;
212
+ this.resolveResult(journalIndex, journalEntry, awakeableMsg.value, awakeableMsg.failure);
213
+ break;
214
+ }
215
+ case protocol_1.SIDE_EFFECT_ENTRY_MESSAGE_TYPE: {
216
+ const sideEffectMsg = replayMessage.message;
217
+ if (sideEffectMsg.value !== undefined) {
218
+ this.resolveResult(journalIndex, journalEntry, (0, utils_1.jsonDeserialize)(sideEffectMsg.value.toString()));
219
+ }
220
+ else if (sideEffectMsg.failure !== undefined) {
221
+ this.resolveResult(journalIndex, journalEntry, undefined, sideEffectMsg.failure.failure, sideEffectMsg.failure.terminal);
222
+ }
223
+ else {
224
+ // A side effect can have a void return type
225
+ // If it was replayed, then it is acked, so we should resolve it.
226
+ journalEntry.resolve(undefined);
227
+ this.pendingJournalEntries.delete(journalIndex);
228
+ }
229
+ break;
230
+ }
231
+ case protocol_1.SET_STATE_ENTRY_MESSAGE_TYPE:
232
+ case protocol_1.CLEAR_STATE_ENTRY_MESSAGE_TYPE:
233
+ case protocol_1.COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE:
234
+ case protocol_1.BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE: {
235
+ // Do not need a completion. So if the match has passed then the entry can be deleted.
236
+ journalEntry.resolve(undefined);
237
+ this.pendingJournalEntries.delete(journalIndex);
238
+ break;
239
+ }
240
+ default: {
241
+ // TODO received replay message of unknown type
242
+ }
243
+ }
244
+ }
245
+ resolveResult(journalIndex, journalEntry, value, failure, failureWouldBeTerminal) {
246
+ if (value !== undefined) {
247
+ journalEntry.resolve(value);
248
+ this.pendingJournalEntries.delete(journalIndex);
249
+ }
250
+ else if (failure !== undefined) {
251
+ const error = (0, errors_1.failureToError)(failure, failureWouldBeTerminal ?? true);
252
+ journalEntry.reject(error);
253
+ this.pendingJournalEntries.delete(journalIndex);
254
+ }
255
+ else {
256
+ this.pendingJournalEntries.set(journalIndex, journalEntry);
257
+ }
258
+ }
259
+ handleClosingMessage(messageType, message) {
260
+ this.transitionState(NewExecutionState.CLOSED);
261
+ const rootJournalEntry = this.pendingJournalEntries.get(0);
262
+ if (rootJournalEntry === undefined) {
263
+ // We have no other option than to throw an error here
264
+ // Because without the root promise we cannot resolve the method or continue
265
+ throw errors_1.RetryableError.internal("Illegal state: No root journal entry found to resolve with output stream message");
266
+ }
267
+ this.pendingJournalEntries.delete(0);
268
+ rootJournalEntry.resolve(new types_1.Message(messageType, message));
269
+ }
270
+ checkJournalMatch(runtimeMsgType, runtimeMsg, userCodeMsgType, userCodeMsg) {
271
+ if (runtimeMsgType === userCodeMsgType) {
272
+ const equalityFct = utils_1.equalityCheckers.get(runtimeMsgType);
273
+ if (equalityFct === undefined) {
274
+ // TODO no equality function was defined for the message type
275
+ return true;
276
+ }
277
+ return equalityFct(runtimeMsg, userCodeMsg);
278
+ }
279
+ else {
280
+ return false;
281
+ }
282
+ }
283
+ // To get the indices that need to be completed with suspension
284
+ getCompletableIndices() {
285
+ // return all entries except for the root entry
286
+ return [...this.pendingJournalEntries.entries()]
287
+ .filter((el) => el[0] !== 0)
288
+ .map((el) => el[0]);
289
+ }
290
+ transitionState(newExecState) {
291
+ // If the state is already closed then you cannot transition anymore
292
+ if (this.state === NewExecutionState.CLOSED &&
293
+ newExecState !== NewExecutionState.CLOSED) {
294
+ // do nothing
295
+ return;
296
+ }
297
+ else {
298
+ this.state = newExecState;
299
+ return;
300
+ }
301
+ }
302
+ incrementUserCodeIndex() {
303
+ this.userCodeJournalIndex++;
304
+ if (this.userCodeJournalIndex === this.invocation.nbEntriesToReplay &&
305
+ this.state === NewExecutionState.REPLAYING) {
306
+ this.transitionState(NewExecutionState.PROCESSING);
307
+ }
308
+ }
309
+ isClosed() {
310
+ return this.state === NewExecutionState.CLOSED;
311
+ }
312
+ isProcessing() {
313
+ return this.state === NewExecutionState.PROCESSING;
314
+ }
315
+ getUserCodeJournalIndex() {
316
+ return this.userCodeJournalIndex;
317
+ }
318
+ close() {
319
+ this.transitionState(NewExecutionState.CLOSED);
320
+ }
321
+ outputMsgWasReplayed() {
322
+ // Check if the last message of the replay entries is an output message
323
+ const lastEntry = this.invocation.replayEntries.get(this.invocation.nbEntriesToReplay - 1);
324
+ return (lastEntry && lastEntry.messageType === protocol_1.OUTPUT_STREAM_ENTRY_MESSAGE_TYPE);
325
+ }
326
+ // We use this for side effects.
327
+ // The restate context needs to know if the user-defined fct needs to be executed or not.
328
+ // It needs to know this before it can craft the message and call this.stateMachine.handleUserSideMessage(...)
329
+ // so before the index got incremented and the state got transitioned.
330
+ // So we cannot use isReplaying().
331
+ // So we need to check in the journal if the next entry (= our side effect) will be replayed or not.
332
+ nextEntryWillBeReplayed() {
333
+ return this.userCodeJournalIndex + 1 < this.invocation.nbEntriesToReplay;
334
+ }
335
+ }
336
+ exports.Journal = Journal;
337
+ class JournalEntry {
338
+ messageType;
339
+ message;
340
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
341
+ promise;
342
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
343
+ resolve;
344
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
345
+ reject;
346
+ constructor(messageType, message) {
347
+ this.messageType = messageType;
348
+ this.message = message;
349
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
350
+ this.promise = new Promise((res, rej) => {
351
+ this.resolve = res;
352
+ this.reject = rej;
353
+ });
354
+ }
355
+ }
356
+ exports.JournalEntry = JournalEntry;
357
+ // "WAITING_FOR_START" before receiving start message
358
+ // "WAITING_FOR_REPLAY" when waiting for all replay entries to arrive from the runtime
359
+ // "REPLAYING" when receiving input stream message
360
+ // "PROCESSING" when both sides have finished replaying
361
+ // "CLOSED" when input stream connection channel gets closed
362
+ var NewExecutionState;
363
+ (function (NewExecutionState) {
364
+ NewExecutionState["REPLAYING"] = "REPLAYING";
365
+ NewExecutionState["PROCESSING"] = "PROCESSING";
366
+ NewExecutionState["CLOSED"] = "CLOSED";
367
+ })(NewExecutionState = exports.NewExecutionState || (exports.NewExecutionState = {}));
368
+ //# sourceMappingURL=journal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journal.js","sourceRoot":"","sources":["../src/journal.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oDAAsC;AAEtC,+CAqB0B;AAC1B,yCAAkE;AAClE,yCAAwC;AAGxC,2CAAgE;AAEhE,MAAa,OAAO;IASG;IARb,KAAK,GAAG,iBAAiB,CAAC,SAAS,CAAC;IAEpC,oBAAoB,GAAG,CAAC,CAAC;IAEjC,4DAA4D;IAC5D,4CAA4C;IACpC,qBAAqB,GAAG,IAAI,GAAG,EAAwB,CAAC;IAEhE,YAAqB,UAA4B;QAA5B,eAAU,GAAV,UAAU,CAAkB;QAC/C,MAAM,YAAY,GAAG,UAAU,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACrD,IACE,CAAC,YAAY;YACb,YAAY,CAAC,WAAW,KAAK,+CAAoC,EACjE;YACA,MAAM,uBAAc,CAAC,iBAAiB,CACpC,oEAAoE,CACrE,CAAC;SACH;QACD,IAAI,CAAC,kBAAkB,CACrB,YAAY,CAAC,OAAsC,CACpD,CAAC;IACJ,CAAC;IAED,kBAAkB,CAAC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A;AACnB,CAAC,EAJW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAI5B"}
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import { ClearStateEntryMessage, GetStateEntryMessage, SetStateEntryMessage, StartMessage_StateEntry } from "./generated/proto/protocol";
3
+ import { Empty } from "./generated/google/protobuf/empty";
4
+ export declare class LocalStateStore {
5
+ readonly isPartial: boolean;
6
+ private state;
7
+ constructor(isPartial: boolean, state: StartMessage_StateEntry[]);
8
+ get(key: string): GetStateEntryMessage;
9
+ set<T>(key: string, value: T): SetStateEntryMessage;
10
+ clear(key: string): ClearStateEntryMessage;
11
+ add(key: string, result: Buffer | Empty): void;
12
+ }
13
+ //# sourceMappingURL=local_state_store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local_state_store.d.ts","sourceRoot":"","sources":["../src/local_state_store.ts"],"names":[],"mappings":";AAWA,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAG1D,qBAAa,eAAe;IAGd,QAAQ,CAAC,SAAS,EAAE,OAAO;IAFvC,OAAO,CAAC,KAAK,CAA8B;gBAEtB,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,uBAAuB,EAAE;IAMlE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,oBAAoB;IA4BtC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,oBAAoB;IASnD,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB;IAQ1C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;CAGtD"}
@@ -0,0 +1,72 @@
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.LocalStateStore = void 0;
14
+ const protocol_1 = require("./generated/proto/protocol");
15
+ const empty_1 = require("./generated/google/protobuf/empty");
16
+ const utils_1 = require("./utils/utils");
17
+ class LocalStateStore {
18
+ isPartial;
19
+ state;
20
+ constructor(isPartial, state) {
21
+ this.isPartial = isPartial;
22
+ this.state = new Map(state.map(({ key, value }) => [key.toString(), value]));
23
+ }
24
+ get(key) {
25
+ const present = this.state.has(key.toString());
26
+ if (!present && this.isPartial) {
27
+ // Partial eager state, so retrieve state from the runtime
28
+ return protocol_1.GetStateEntryMessage.create({ key: Buffer.from(key) });
29
+ }
30
+ else if (!present) {
31
+ // Complete eager state, so state entry is null
32
+ return protocol_1.GetStateEntryMessage.create({
33
+ key: Buffer.from(key),
34
+ empty: empty_1.Empty.create({}),
35
+ });
36
+ }
37
+ const stateEntry = this.state.get(key.toString());
38
+ if (stateEntry instanceof Buffer) {
39
+ return protocol_1.GetStateEntryMessage.create({
40
+ key: Buffer.from(key),
41
+ value: stateEntry,
42
+ });
43
+ }
44
+ else {
45
+ // stateEntry is Empty
46
+ return protocol_1.GetStateEntryMessage.create({
47
+ key: Buffer.from(key),
48
+ empty: stateEntry,
49
+ });
50
+ }
51
+ }
52
+ set(key, value) {
53
+ const bytes = Buffer.from((0, utils_1.jsonSerialize)(value));
54
+ this.state.set(key, bytes);
55
+ return protocol_1.SetStateEntryMessage.create({
56
+ key: Buffer.from(key, "utf8"),
57
+ value: bytes,
58
+ });
59
+ }
60
+ clear(key) {
61
+ this.state.set(key, empty_1.Empty.create({}));
62
+ return protocol_1.ClearStateEntryMessage.create({ key: Buffer.from(key) });
63
+ }
64
+ // When a GetState request does not have a local entry and we have partial state,
65
+ // then the request goes to the runtime.
66
+ // When we get the response of the runtime, we add the state to the localStateStore.
67
+ add(key, result) {
68
+ this.state.set(key, result);
69
+ }
70
+ }
71
+ exports.LocalStateStore = LocalStateStore;
72
+ //# sourceMappingURL=local_state_store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local_state_store.js","sourceRoot":"","sources":["../src/local_state_store.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,yDAKoC;AACpC,6DAA0D;AAC1D,yCAA8C;AAE9C,MAAa,eAAe;IAGL;IAFb,KAAK,CAA8B;IAE3C,YAAqB,SAAkB,EAAE,KAAgC;QAApD,cAAS,GAAT,SAAS,CAAS;QACrC,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,CAClB,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,KAAK,CAAC,CAAC,CACvD,CAAC;IACJ,CAAC;IAEM,GAAG,CAAC,GAAW;QACpB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,EAAE;YAC9B,0DAA0D;YAC1D,OAAO,+BAAoB,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;SAC/D;aAAM,IAAI,CAAC,OAAO,EAAE;YACnB,+CAA+C;YAC/C,OAAO,+BAAoB,CAAC,MAAM,CAAC;gBACjC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;gBACrB,KAAK,EAAE,aAAK,CAAC,MAAM,CAAC,EAAE,CAAC;aACxB,CAAC,CAAC;SACJ;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,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ext, useContext, ServiceApi, RpcContext, } from "./restate_context";
2
+ export { router, keyedRouter, keyedEventHandler, UnKeyedRouter, KeyedRouter, KeyedEventHandler, Client, SendClient, } from "./types/router";
3
+ export { RestateServer, createServer } from "./server/restate_server";
4
+ export { ServiceOpts } from "./server/base_restate_server";
5
+ export { LambdaRestateServer, createLambdaApiGatewayHandler, } from "./server/restate_lambda_handler";
6
+ export * as RestateUtils from "./utils/public_utils";
7
+ export { ErrorCodes, RestateError, TerminalError } from "./types/errors";
8
+ export { Event } from "./types/types";
9
+ export { RestateConnection, connection, RestateConnectionOptions, } from "./embedded/api";
10
+ //# sourceMappingURL=public_api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public_api.d.ts","sourceRoot":"","sources":["../src/public_api.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,UAAU,EACV,UAAU,EACV,UAAU,GACX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,MAAM,EACN,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,UAAU,GACX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EACL,mBAAmB,EACnB,6BAA6B,GAC9B,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,YAAY,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,iBAAiB,EACjB,UAAU,EACV,wBAAwB,GACzB,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,59 @@
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.connection = exports.RestateConnection = exports.Event = exports.TerminalError = exports.RestateError = exports.ErrorCodes = exports.RestateUtils = exports.createLambdaApiGatewayHandler = exports.LambdaRestateServer = exports.createServer = exports.RestateServer = exports.keyedEventHandler = exports.keyedRouter = exports.router = exports.useContext = void 0;
37
+ var restate_context_1 = require("./restate_context");
38
+ Object.defineProperty(exports, "useContext", { enumerable: true, get: function () { return restate_context_1.useContext; } });
39
+ var router_1 = require("./types/router");
40
+ Object.defineProperty(exports, "router", { enumerable: true, get: function () { return router_1.router; } });
41
+ Object.defineProperty(exports, "keyedRouter", { enumerable: true, get: function () { return router_1.keyedRouter; } });
42
+ Object.defineProperty(exports, "keyedEventHandler", { enumerable: true, get: function () { return router_1.keyedEventHandler; } });
43
+ var restate_server_1 = require("./server/restate_server");
44
+ Object.defineProperty(exports, "RestateServer", { enumerable: true, get: function () { return restate_server_1.RestateServer; } });
45
+ Object.defineProperty(exports, "createServer", { enumerable: true, get: function () { return restate_server_1.createServer; } });
46
+ var restate_lambda_handler_1 = require("./server/restate_lambda_handler");
47
+ Object.defineProperty(exports, "LambdaRestateServer", { enumerable: true, get: function () { return restate_lambda_handler_1.LambdaRestateServer; } });
48
+ Object.defineProperty(exports, "createLambdaApiGatewayHandler", { enumerable: true, get: function () { return restate_lambda_handler_1.createLambdaApiGatewayHandler; } });
49
+ exports.RestateUtils = __importStar(require("./utils/public_utils"));
50
+ var errors_1 = require("./types/errors");
51
+ Object.defineProperty(exports, "ErrorCodes", { enumerable: true, get: function () { return errors_1.ErrorCodes; } });
52
+ Object.defineProperty(exports, "RestateError", { enumerable: true, get: function () { return errors_1.RestateError; } });
53
+ Object.defineProperty(exports, "TerminalError", { enumerable: true, get: function () { return errors_1.TerminalError; } });
54
+ var types_1 = require("./types/types");
55
+ Object.defineProperty(exports, "Event", { enumerable: true, get: function () { return types_1.Event; } });
56
+ var api_1 = require("./embedded/api");
57
+ Object.defineProperty(exports, "RestateConnection", { enumerable: true, get: function () { return api_1.RestateConnection; } });
58
+ Object.defineProperty(exports, "connection", { enumerable: true, get: function () { return api_1.connection; } });
59
+ //# sourceMappingURL=public_api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public_api.js","sourceRoot":"","sources":["../src/public_api.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,qDAM2B;AAHzB,6GAAA,UAAU,OAAA;AAIZ,yCASwB;AARtB,gGAAA,MAAM,OAAA;AACN,qGAAA,WAAW,OAAA;AACX,2GAAA,iBAAiB,OAAA;AAOnB,0DAAsE;AAA7D,+GAAA,aAAa,OAAA;AAAE,8GAAA,YAAY,OAAA;AAEpC,0EAGyC;AAFvC,6HAAA,mBAAmB,OAAA;AACnB,uIAAA,6BAA6B,OAAA;AAE/B,qEAAqD;AACrD,yCAAyE;AAAhE,oGAAA,UAAU,OAAA;AAAE,sGAAA,YAAY,OAAA;AAAE,uGAAA,aAAa,OAAA;AAChD,uCAAsC;AAA7B,8FAAA,KAAK,OAAA;AACd,sCAIwB;AAHtB,wGAAA,iBAAiB,OAAA;AACjB,iGAAA,UAAU,OAAA"}