@restatedev/restate-sdk 0.6.0 → 0.7.1-worker

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 (113) hide show
  1. package/README.md +12 -2
  2. package/dist/cloudflare_bundle.js +27387 -0
  3. package/dist/connection/buffered_connection.d.ts +14 -0
  4. package/dist/connection/buffered_connection.d.ts.map +1 -0
  5. package/dist/connection/embedded_connection.d.ts +2 -4
  6. package/dist/connection/embedded_connection.d.ts.map +1 -1
  7. package/dist/connection/http_connection.d.ts +1 -1
  8. package/dist/connection/http_connection.d.ts.map +1 -1
  9. package/dist/generated/proto/protocol.d.ts +52 -16
  10. package/dist/generated/proto/protocol.d.ts.map +1 -1
  11. package/dist/invocation.d.ts +12 -2
  12. package/dist/invocation.d.ts.map +1 -1
  13. package/dist/io/encoder.d.ts +2 -1
  14. package/dist/io/encoder.d.ts.map +1 -1
  15. package/dist/journal.d.ts +2 -1
  16. package/dist/journal.d.ts.map +1 -1
  17. package/dist/restate_context_impl.d.ts.map +1 -1
  18. package/dist/server/base_restate_server.d.ts +1 -1
  19. package/dist/server/base_restate_server.d.ts.map +1 -1
  20. package/dist/server/restate_server.d.ts +45 -39
  21. package/dist/server/restate_server.d.ts.map +1 -1
  22. package/dist/state_machine.d.ts +1 -1
  23. package/dist/state_machine.d.ts.map +1 -1
  24. package/dist/types/errors.d.ts +1 -1
  25. package/dist/types/errors.d.ts.map +1 -1
  26. package/dist/types/protocol.d.ts +5 -3
  27. package/dist/types/protocol.d.ts.map +1 -1
  28. package/dist/types/types.d.ts.map +1 -1
  29. package/dist/utils/utils.d.ts +1 -0
  30. package/dist/utils/utils.d.ts.map +1 -1
  31. package/package.json +7 -3
  32. package/dist/connection/connection.js +0 -13
  33. package/dist/connection/connection.js.map +0 -1
  34. package/dist/connection/embedded_connection.js +0 -78
  35. package/dist/connection/embedded_connection.js.map +0 -1
  36. package/dist/connection/http_connection.js +0 -203
  37. package/dist/connection/http_connection.js.map +0 -1
  38. package/dist/connection/lambda_connection.js +0 -58
  39. package/dist/connection/lambda_connection.js.map +0 -1
  40. package/dist/embedded/api.js +0 -35
  41. package/dist/embedded/api.js.map +0 -1
  42. package/dist/embedded/handler.js +0 -28
  43. package/dist/embedded/handler.js.map +0 -1
  44. package/dist/embedded/http2_remote.js +0 -91
  45. package/dist/embedded/http2_remote.js.map +0 -1
  46. package/dist/embedded/invocation.js +0 -94
  47. package/dist/embedded/invocation.js.map +0 -1
  48. package/dist/generated/dev/restate/events.js +0 -371
  49. package/dist/generated/dev/restate/events.js.map +0 -1
  50. package/dist/generated/dev/restate/ext.js +0 -215
  51. package/dist/generated/dev/restate/ext.js.map +0 -1
  52. package/dist/generated/google/protobuf/descriptor.js +0 -6676
  53. package/dist/generated/google/protobuf/descriptor.js.map +0 -1
  54. package/dist/generated/google/protobuf/empty.js +0 -107
  55. package/dist/generated/google/protobuf/empty.js.map +0 -1
  56. package/dist/generated/google/protobuf/struct.js +0 -754
  57. package/dist/generated/google/protobuf/struct.js.map +0 -1
  58. package/dist/generated/proto/discovery.js +0 -364
  59. package/dist/generated/proto/discovery.js.map +0 -1
  60. package/dist/generated/proto/dynrpc.js +0 -668
  61. package/dist/generated/proto/dynrpc.js.map +0 -1
  62. package/dist/generated/proto/javascript.js +0 -297
  63. package/dist/generated/proto/javascript.js.map +0 -1
  64. package/dist/generated/proto/protocol.js +0 -2179
  65. package/dist/generated/proto/protocol.js.map +0 -1
  66. package/dist/generated/proto/services.js +0 -1535
  67. package/dist/generated/proto/services.js.map +0 -1
  68. package/dist/generated/proto/test.js +0 -321
  69. package/dist/generated/proto/test.js.map +0 -1
  70. package/dist/invocation.js +0 -138
  71. package/dist/invocation.js.map +0 -1
  72. package/dist/io/decoder.js +0 -133
  73. package/dist/io/decoder.js.map +0 -1
  74. package/dist/io/encoder.js +0 -57
  75. package/dist/io/encoder.js.map +0 -1
  76. package/dist/journal.js +0 -368
  77. package/dist/journal.js.map +0 -1
  78. package/dist/local_state_store.js +0 -72
  79. package/dist/local_state_store.js.map +0 -1
  80. package/dist/public_api.js +0 -59
  81. package/dist/public_api.js.map +0 -1
  82. package/dist/restate_context.js +0 -46
  83. package/dist/restate_context.js.map +0 -1
  84. package/dist/restate_context_impl.js +0 -375
  85. package/dist/restate_context_impl.js.map +0 -1
  86. package/dist/server/base_restate_server.js +0 -361
  87. package/dist/server/base_restate_server.js.map +0 -1
  88. package/dist/server/restate_lambda_handler.js +0 -247
  89. package/dist/server/restate_lambda_handler.js.map +0 -1
  90. package/dist/server/restate_server.js +0 -230
  91. package/dist/server/restate_server.js.map +0 -1
  92. package/dist/state_machine.js +0 -385
  93. package/dist/state_machine.js.map +0 -1
  94. package/dist/types/errors.js +0 -261
  95. package/dist/types/errors.js.map +0 -1
  96. package/dist/types/grpc.js +0 -68
  97. package/dist/types/grpc.js.map +0 -1
  98. package/dist/types/protocol.js +0 -115
  99. package/dist/types/protocol.js.map +0 -1
  100. package/dist/types/router.js +0 -36
  101. package/dist/types/router.js.map +0 -1
  102. package/dist/types/types.js +0 -125
  103. package/dist/types/types.js.map +0 -1
  104. package/dist/utils/assumpsions.js +0 -101
  105. package/dist/utils/assumpsions.js.map +0 -1
  106. package/dist/utils/logger.js +0 -102
  107. package/dist/utils/logger.js.map +0 -1
  108. package/dist/utils/public_utils.js +0 -49
  109. package/dist/utils/public_utils.js.map +0 -1
  110. package/dist/utils/rand.js +0 -114
  111. package/dist/utils/rand.js.map +0 -1
  112. package/dist/utils/utils.js +0 -119
  113. package/dist/utils/utils.js.map +0 -1
@@ -1,230 +0,0 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
13
- return (mod && mod.__esModule) ? mod : { "default": mod };
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.RestateServer = exports.createServer = void 0;
17
- const events_1 = require("events");
18
- const stream_1 = __importDefault(require("stream"));
19
- const promises_1 = require("stream/promises");
20
- const http2_1 = __importDefault(require("http2"));
21
- const url_1 = require("url");
22
- const discovery_1 = require("../generated/proto/discovery");
23
- const base_restate_server_1 = require("./base_restate_server");
24
- const logger_1 = require("../utils/logger");
25
- const http_connection_1 = require("../connection/http_connection");
26
- const errors_1 = require("../types/errors");
27
- const invocation_1 = require("../invocation");
28
- const state_machine_1 = require("../state_machine");
29
- /**
30
- * Creates a Restate entrypoint based on a HTTP2 server. The entrypoint will listen
31
- * for requests to the services at a specified port.
32
- *
33
- * This is the entrypoint to be used in most scenarios (standalone, Docker, Kubernetes, ...);
34
- * any deployments that forwards requests to a network endpoint. The prominent exception is
35
- * AWS Lambda, which uses the {@link restate_lambda_handler#lambdaApiGatewayHandler}
36
- * function to create an entry point.
37
- *
38
- * After creating this endpoint, register services on this entrypoint via {@link RestateServer.bindService }
39
- * and start it via {@link RestateServer.listen }.
40
- *
41
- * @example
42
- * A typical entry point would look like this:
43
- * ```
44
- * import * as restate from "@restatedev/restate-sdk";
45
- *
46
- * export const handler = restate
47
- * .createServer()
48
- * .bindService({
49
- * service: "MyService",
50
- * instance: new myService.MyServiceImpl(),
51
- * descriptor: myService.protoMetadata,
52
- * })
53
- * .listen(8000);
54
- * ```
55
- */
56
- function createServer() {
57
- return new RestateServer();
58
- }
59
- exports.createServer = createServer;
60
- /**
61
- * Restate entrypoint implementation for services. This server receives and
62
- * decodes the requests, streams events between the service and the Restate runtime,
63
- * and drives the durable execution of the service invocations.
64
- */
65
- class RestateServer extends base_restate_server_1.BaseRestateServer {
66
- constructor() {
67
- super(discovery_1.ProtocolMode.BIDI_STREAM);
68
- }
69
- bindKeyedRouter(path, router) {
70
- // Implementation note: This override if here mainly to change the return type to the more
71
- // concrete type RestateServer (from BaseRestateServer).
72
- super.bindRpcService(path, router, true);
73
- return this;
74
- }
75
- bindRouter(path, router) {
76
- // Implementation note: This override if here mainly to change the return type to the more
77
- // concrete type RestateServer (from BaseRestateServer).
78
- super.bindRpcService(path, router, false);
79
- return this;
80
- }
81
- /**
82
- * Adds a gRPC service to be served from this endpoint.
83
- *
84
- * The {@link ServiceOpts} passed here need to describe the following properties:
85
- *
86
- * - The 'service' name: the name of the gRPC service (as in the service definition proto file).
87
- * - The service 'instance': the implementation of the service logic (must implement the generated
88
- * gRPC service interface).
89
- * - The gRPC/protobuf 'descriptor': The protoMetadata descriptor that describes the service, methods,
90
- * and parameter types. It is usually found as the value 'protoMetadata' in the generated
91
- * file '(service-name).ts'
92
- *
93
- * The descriptor is generated by the protobuf compiler and needed by Restate to reflectively discover
94
- * the service details, understand payload serialization, perform HTTP/JSON-to-gRPC transcoding, or
95
- * to proxy the service.
96
- *
97
- * If you define multiple services in the same '.proto' file, you may have only one descriptor that
98
- * describes all services together. You can pass the same descriptor to multiple calls of '.bindService()'.
99
- *
100
- * If you don't find the gRPC/protobuf descriptor, make your you generated the gRPC/ProtoBuf code with
101
- * the option to generate the descriptor. For example, using the 'ts-proto' plugin, make sure you pass
102
- * the 'outputSchema=true' option. If you are using Restate's project templates, this should all be
103
- * pre-configured for you.
104
- *
105
- * @example
106
- * ```
107
- * endpoint.bindService({
108
- * service: "MyService",
109
- * instance: new myService.MyServiceImpl(),
110
- * descriptor: myService.protoMetadata
111
- * })
112
- * ```
113
- *
114
- * @param serviceOpts The options describing the service to be bound. See above for a detailed description.
115
- * @returns An instance of this RestateServer
116
- */
117
- bindService(serviceOpts) {
118
- // Implementation note: This override if here mainly to change the return type to the more
119
- // concrete type RestateServer (from BaseRestateServer).
120
- super.bindService(serviceOpts);
121
- return this;
122
- }
123
- /**
124
- * Starts the Restate server and listens at the given port.
125
- *
126
- * If the port is undefined, this method will use the port set in the `PORT`
127
- * environment variable. If that variable is undefined as well, the method will
128
- * default to port 9080.
129
- *
130
- * This method's result promise never completes.
131
- *
132
- * @param port The port to listen at. May be undefined (see above).
133
- */
134
- async listen(port) {
135
- // Infer the port if not specified, or default it
136
- const actualPort = port ?? parseInt(process.env.PORT ?? "9080");
137
- logger_1.rlog.info(`Listening on ${actualPort}...`);
138
- for await (const connection of incomingConnectionAtPort(actualPort)) {
139
- this.handleConnection(connection.url, connection.stream).catch((e) => {
140
- const error = (0, errors_1.ensureError)(e);
141
- logger_1.rlog.error("Error while handling connection: " + (error.stack ?? error.message));
142
- connection.stream.end();
143
- connection.stream.destroy();
144
- });
145
- }
146
- }
147
- async handleConnection(url, stream) {
148
- const method = this.methodByUrl(url.path);
149
- if (method !== undefined) {
150
- // valid connection, let's dispatch the invocation
151
- stream.respond({
152
- "content-type": "application/restate",
153
- ":status": 200,
154
- });
155
- const restateStream = http_connection_1.RestateHttp2Connection.from(stream);
156
- await handleInvocation(method, restateStream);
157
- return;
158
- }
159
- // no method under that name. might be a discovery request
160
- if (url.path == "/discover") {
161
- logger_1.rlog.info("Answering discovery request. Registering these services: " +
162
- JSON.stringify(this.discovery.services));
163
- await respondDiscovery(this.discovery, stream);
164
- return;
165
- }
166
- // no discovery, so unknown method: 404
167
- logger_1.rlog.error(`No service and function found for URL ${url.path}`);
168
- await respondNotFound(stream);
169
- }
170
- }
171
- exports.RestateServer = RestateServer;
172
- async function* incomingConnectionAtPort(port) {
173
- const server = http2_1.default.createServer();
174
- server.on("error", (err) => logger_1.rlog.error("Error in Restate service endpoint http2 server: " + err));
175
- server.listen(port);
176
- let connectionId = 1n;
177
- for await (const [s, h] of (0, events_1.on)(server, "stream")) {
178
- const stream = s;
179
- const headers = h;
180
- const url = (0, url_1.parse)(headers[":path"] ?? "/");
181
- connectionId++;
182
- yield { connectionId, url, headers, stream };
183
- }
184
- }
185
- async function respondDiscovery(response, http2Stream) {
186
- const responseData = discovery_1.ServiceDiscoveryResponse.encode(response).finish();
187
- http2Stream.respond({
188
- ":status": 200,
189
- "content-type": "application/proto",
190
- });
191
- await (0, promises_1.pipeline)(stream_1.default.Readable.from(responseData), http2Stream, {
192
- end: true,
193
- });
194
- }
195
- async function respondNotFound(stream) {
196
- stream.respond({
197
- "content-type": "application/restate",
198
- ":status": 404,
199
- });
200
- stream.end();
201
- await (0, promises_1.finished)(stream);
202
- }
203
- async function handleInvocation(func, connection) {
204
- // step 1: collect all journal events
205
- const journalBuilder = new invocation_1.InvocationBuilder(func);
206
- connection.pipeToConsumer(journalBuilder);
207
- try {
208
- await journalBuilder.completion();
209
- }
210
- finally {
211
- // ensure GC friendliness, also in case of errors
212
- connection.removeCurrentConsumer();
213
- }
214
- // step 2: create the state machine
215
- const stateMachine = new state_machine_1.StateMachine(connection, journalBuilder.build(), discovery_1.ProtocolMode.BIDI_STREAM);
216
- connection.pipeToConsumer(stateMachine);
217
- // step 3: invoke the function
218
- // This call would propagate errors in the state machine logic, but not errors
219
- // in the application function code. Ending a function with an error as well
220
- // as failign an invocation and being retried are perfectly valid actions from the
221
- // SDK's perspective.
222
- try {
223
- await stateMachine.invoke();
224
- }
225
- finally {
226
- // ensure GC friendliness, also in case of errors
227
- connection.removeCurrentConsumer();
228
- }
229
- }
230
- //# sourceMappingURL=restate_server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"restate_server.js","sourceRoot":"","sources":["../../src/server/restate_server.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;AAEH,mCAA4B;AAC5B,oDAA4B;AAC5B,8CAAqD;AACrD,kDAA0B;AAC1B,6BAA6C;AAC7C,4DAGsC;AACtC,+DAAuE;AACvE,4CAAuC;AACvC,mEAAuE;AAEvE,4CAA8C;AAC9C,8CAAkD;AAClD,oDAAgD;AAGhD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,YAAY;IAC1B,OAAO,IAAI,aAAa,EAAE,CAAC;AAC7B,CAAC;AAFD,oCAEC;AAED;;;;GAIG;AACH,MAAa,aAAc,SAAQ,uCAAiB;IA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D,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;IAC1C,IAAI;QACF,MAAM,cAAc,CAAC,UAAU,EAAE,CAAC;KACnC;YAAS;QACR,iDAAiD;QACjD,UAAU,CAAC,qBAAqB,EAAE,CAAC;KACpC;IAED,mCAAmC;IACnC,MAAM,YAAY,GAAG,IAAI,4BAAY,CACnC,UAAU,EACV,cAAc,CAAC,KAAK,EAAE,EACtB,wBAAY,CAAC,WAAW,CACzB,CAAC;IACF,UAAU,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;IAExC,8BAA8B;IAE9B,8EAA8E;IAC9E,4EAA4E;IAC5E,kFAAkF;IAClF,qBAAqB;IACrB,IAAI;QACF,MAAM,YAAY,CAAC,MAAM,EAAE,CAAC;KAC7B;YAAS;QACR,iDAAiD;QACjD,UAAU,CAAC,qBAAqB,EAAE,CAAC;KACpC;AACH,CAAC"}
@@ -1,385 +0,0 @@
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
- suspensionMillis;
52
- journal;
53
- restateContext;
54
- invocationComplete = new utils_1.CompletablePromise();
55
- // when this flag is true, no more work will (and may) happen
56
- // this is set to true in case of
57
- // - a completed invocation
58
- // - a suspension
59
- // - an error in the state machine
60
- stateMachineClosed = false;
61
- localStateStore;
62
- // Whether the input channel (runtime -> service) is closed
63
- // If it is closed, then we suspend immediately upon the next suspension point
64
- // If it is open, then we suspend later because we might still get completions
65
- inputChannelClosed = false;
66
- // Suspension timeout that gets set and cleared based on completion messages;
67
- suspensionTimeout;
68
- constructor(connection, invocation, protocolMode, suspensionMillis = 30_000) {
69
- this.connection = connection;
70
- this.invocation = invocation;
71
- this.protocolMode = protocolMode;
72
- this.suspensionMillis = suspensionMillis;
73
- this.localStateStore = invocation.localStateStore;
74
- this.restateContext = new restate_context_impl_1.RestateGrpcContextImpl(this.invocation.id, this.invocation.method.service, this);
75
- this.journal = new journal_1.Journal(this.invocation);
76
- }
77
- handleMessage(m) {
78
- if (this.stateMachineClosed) {
79
- // ignore this message
80
- return false;
81
- }
82
- if (m.messageType !== protocol_1.COMPLETION_MESSAGE_TYPE) {
83
- throw errors_1.RetryableError.protocolViolation(`Received message of type ${m.messageType}. Can only accept completion messages after replay has finished.`);
84
- }
85
- logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Received completion message from Restate, adding to journal.", m.messageType, m.message);
86
- this.journal.handleRuntimeCompletionMessage(m.message);
87
- // Remove lingering suspension timeouts, if we are not waiting for completions anymore
88
- if (this.suspensionTimeout !== undefined &&
89
- this.journal.getCompletableIndices().length === 0) {
90
- (0, timers_1.clearTimeout)(this.suspensionTimeout);
91
- this.suspensionTimeout = undefined;
92
- }
93
- return false; // we are never complete
94
- }
95
- handleUserCodeMessage(messageType, message, completedFlag, protocolVersion, requiresAckFlag) {
96
- // if the state machine is already closed, return a promise that never
97
- // completes, so that the user code does not resume
98
- if (this.stateMachineClosed) {
99
- return wrapDeeply(new utils_1.CompletablePromise().promise);
100
- }
101
- const promise = this.journal.handleUserSideMessage(messageType, message);
102
- const journalIndex = this.journal.getUserCodeJournalIndex();
103
- // Only send the message to restate if we are not in replaying mode
104
- if (this.journal.isProcessing()) {
105
- logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Adding message to journal and sending to Restate", messageType, message);
106
- this.send(new types_1.Message(messageType, message, completedFlag, protocolVersion, requiresAckFlag));
107
- }
108
- else {
109
- logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Matched and replayed message from journal", messageType, message);
110
- }
111
- return wrapDeeply(promise, () => {
112
- if (!p.SUSPENSION_TRIGGERS.includes(messageType)) {
113
- return;
114
- }
115
- if (this.journal.isUnResolved(journalIndex)) {
116
- this.scheduleSuspension();
117
- }
118
- });
119
- }
120
- /**
121
- * Invokes the RPC function and returns a promise that completes when the state machine
122
- * stops processing the invocation, meaning when:
123
- * - The function completes with a result or an exception
124
- * - The execution suspends
125
- * - An error is raised in the state machine (network, API violation, ...)
126
- *
127
- * The returned promise resolves successfully for all the cases above, because the are (from
128
- * the perspective of the state machine) expected outcomes in which it send out corresponding
129
- * result messages and cleanly closed the connection.
130
- *
131
- * The returned promise is rejected when an unhandled error arises and the caller would be
132
- * expected to ensure that resources are properly cleaned up.
133
- */
134
- invoke() {
135
- // --------------------------------------------------------------------------------------------
136
- // Implementation note:
137
- //
138
- // This method is not async, because we don't want to actually await anything
139
- // in there. We cannot await the completion of the actual invocation, because for long-running
140
- // code (that suspends), the function invocation never completes. Instead, the state machine
141
- // triggers a suspension.
142
- // We need to do a bit of promise chaining for the rpc function promise, and return a different
143
- // promise that completes in also in suspension and error cases.
144
- // --------------------------------------------------------------------------------------------
145
- // it is unexpected for the state machine to be closed here, so we raise an error in
146
- // that case, unlike in other places, where we simply ignore things
147
- if (this.stateMachineClosed) {
148
- return Promise.reject(new Error("state machine is already closed"));
149
- }
150
- if (this.journal.nextEntryWillBeReplayed()) {
151
- logger_1.rlog.debugInvokeMessage(this.invocation.logPrefix, "Resuming (replaying) function.");
152
- }
153
- else {
154
- logger_1.rlog.debugInvokeMessage(this.invocation.logPrefix, "Invoking function.");
155
- }
156
- const resultBytes = this.invocation.method.invoke(this.restateContext, this.invocation.invocationValue);
157
- resultBytes
158
- .then((bytes) => {
159
- // invocation successfully returned with a result value
160
- try {
161
- // the state machine might be closed here in some cases like when there was an error (like
162
- // API violation) or a suspension, but the function code still completed
163
- if (this.stateMachineClosed) {
164
- logger_1.rlog.warn("Unexpected successful completion of the function after the state machine closed. " +
165
- "This may indicate that: \n" +
166
- "- the function code does not properly await some Restate calls " +
167
- "and did not notice an error \n" +
168
- "- the function code was delayed for longer than the suspension timeout \n" +
169
- "- the function code contained a try-catch block around a side effect which throws retryable errors. " +
170
- "This try-catch block should be placed inside the side effect.");
171
- return;
172
- }
173
- const value = Buffer.from(bytes);
174
- // handle the result value
175
- const msg = new types_1.Message(protocol_1.OUTPUT_STREAM_ENTRY_MESSAGE_TYPE, protocol_1.OutputStreamEntryMessage.create({
176
- value,
177
- }));
178
- this.journal.handleUserSideMessage(msg.messageType, msg.message);
179
- if (!this.journal.outputMsgWasReplayed()) {
180
- this.send(msg);
181
- logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Journaled and sent output message", msg.messageType, msg.message);
182
- }
183
- else {
184
- logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Replayed and matched output message from journal", msg.messageType, msg.message);
185
- }
186
- logger_1.rlog.debugInvokeMessage(this.invocation.logPrefix, "Function completed successfully.");
187
- this.finish(value);
188
- }
189
- catch (e) {
190
- this.unhandledError((0, errors_1.ensureError)(e));
191
- }
192
- })
193
- .catch((e) => {
194
- // because of how we try/catch in the promise handler above, this here exclusively handles
195
- // errors coming from the rpc function
196
- try {
197
- // Sometimes the function code fails as a consequence of the state machine encountering
198
- // an error before (possibly Restate closed the connection).
199
- if (this.stateMachineClosed) {
200
- return;
201
- }
202
- const error = (0, errors_1.ensureError)(e);
203
- logger_1.rlog.debugInvokeMessage(this.invocation.logPrefix, "Function completed with an error: " + error.message);
204
- this.finishWithError(error);
205
- }
206
- catch (ee) {
207
- this.unhandledError((0, errors_1.ensureError)(ee));
208
- }
209
- });
210
- // this promise here completes under any completion, including the cases where the
211
- // rpc function does not end (error, suspension, ...)
212
- return this.invocationComplete.promise;
213
- }
214
- async finishWithError(e) {
215
- if (e instanceof errors_1.TerminalError) {
216
- this.sendTerminalError(e);
217
- }
218
- else {
219
- this.sendRetryableError(e);
220
- }
221
- await this.finish();
222
- }
223
- sendRetryableError(e) {
224
- const msg = new types_1.Message(protocol_1.ERROR_MESSAGE_TYPE, (0, errors_1.errorToErrorMessage)(e));
225
- logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Invocation ended with retryable error.", msg.messageType, msg.message);
226
- this.send(msg);
227
- }
228
- sendTerminalError(e) {
229
- const msg = new types_1.Message(protocol_1.OUTPUT_STREAM_ENTRY_MESSAGE_TYPE, protocol_1.OutputStreamEntryMessage.create({
230
- failure: e.toFailure(),
231
- }));
232
- logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Invocation ended with failure message.", msg.messageType, msg.message);
233
- this.journal.handleUserSideMessage(msg.messageType, msg.message);
234
- if (!this.journal.outputMsgWasReplayed()) {
235
- this.send(msg);
236
- }
237
- }
238
- send(message) {
239
- this.connection.send(message).catch((err) => {
240
- this.handleStreamError(err);
241
- });
242
- }
243
- /**
244
- * Closes the state machine, flushes all output, and resolves the invocation promise.
245
- */
246
- async finish(value) {
247
- try {
248
- this.stateMachineClosed = true;
249
- this.journal.close();
250
- this.clearSuspensionTimeout();
251
- await this.connection.end();
252
- this.invocationComplete.resolve(value);
253
- }
254
- catch (e) {
255
- this.invocationComplete.reject((0, errors_1.ensureError)(e));
256
- }
257
- }
258
- /**
259
- * This function propagates errors up to the completion promise, to be handled
260
- * on the connection layer.
261
- */
262
- unhandledError(e) {
263
- this.invocationComplete.reject(e);
264
- this.stateMachineClosed = true;
265
- this.journal.close();
266
- this.clearSuspensionTimeout();
267
- }
268
- scheduleSuspension() {
269
- // If there was already a timeout set, we want to reset the time to postpone suspension as long as we make progress.
270
- // So we first clear the old timeout, and then we set a new one.
271
- if (this.suspensionTimeout !== undefined) {
272
- (0, timers_1.clearTimeout)(this.suspensionTimeout);
273
- this.suspensionTimeout = undefined;
274
- }
275
- const delay = this.getSuspensionMillis();
276
- logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Scheduling suspension in " + delay + " ms");
277
- if (delay >= 0) {
278
- // Set a new suspension with a new timeout
279
- // The suspension will only be sent if the timeout is not canceled due to a completion.
280
- // In case the delay is 0 we still schedule a timeout in order to process the suspension on the next process tick,
281
- // without interrupting the current work.
282
- this.suspensionTimeout = setTimeout(() => {
283
- this.suspend();
284
- }, delay);
285
- }
286
- }
287
- // Suspension timeouts:
288
- // Lambda case: suspend immediately when control is back in the user code
289
- // Bidi streaming case:
290
- // - suspend after 1 seconds if input channel is still open (can still get completions)
291
- // - suspend immediately if input channel is closed (cannot get completions)
292
- getSuspensionMillis() {
293
- return this.protocolMode === discovery_1.ProtocolMode.REQUEST_RESPONSE ||
294
- this.inputChannelClosed
295
- ? 0
296
- : this.suspensionMillis;
297
- }
298
- async suspend() {
299
- const indices = this.journal.getCompletableIndices();
300
- // If the state is closed then we either already send a suspension
301
- // or something else bad happened...
302
- if (this.journal.isClosed() || indices.length === 0) {
303
- return;
304
- }
305
- // There need to be journal entries to complete, otherwise this timeout should have been removed.
306
- // A suspension message is the end of the invocation.
307
- // Resolve the root call with the suspension message
308
- // This will lead to a onCallSuccess call where this msg will be sent.
309
- const msg = new types_1.Message(protocol_1.SUSPENSION_MESSAGE_TYPE, protocol_1.SuspensionMessage.create({
310
- entryIndexes: indices,
311
- }));
312
- logger_1.rlog.debugJournalMessage(this.invocation.logPrefix, "Writing suspension message to journal.", msg.messageType, msg.message);
313
- this.journal.handleUserSideMessage(msg.messageType, msg.message);
314
- if (!this.journal.outputMsgWasReplayed()) {
315
- this.send(msg);
316
- }
317
- logger_1.rlog.debugInvokeMessage(this.invocation.logPrefix, "Suspending function.");
318
- await this.finish();
319
- }
320
- async notifyHandlerExecutionError(e) {
321
- await this.finishWithError(e);
322
- }
323
- /**
324
- * WARNING: make sure you use this at the right point in the code
325
- * After the index has been incremented...
326
- * This is error-prone... Would be good to have a better solution for this.
327
- */
328
- getUserCodeJournalIndex() {
329
- return this.journal.getUserCodeJournalIndex();
330
- }
331
- getFullServiceName() {
332
- return (0, utils_1.makeFqServiceName)(this.invocation.method.packge, this.invocation.method.service);
333
- }
334
- handleInputClosed() {
335
- if (this.journal.isClosed() ||
336
- this.stateMachineClosed ||
337
- this.inputChannelClosed) {
338
- return;
339
- }
340
- this.inputChannelClosed = true;
341
- logger_1.rlog.debug(this.invocation.logPrefix +
342
- " : Restate closed connection to trigger suspension.");
343
- // If there is a timeout planned, reset the timout to execute immediately when the work is done.
344
- if (this.suspensionTimeout !== undefined) {
345
- this.scheduleSuspension();
346
- }
347
- }
348
- handleStreamError(e) {
349
- logger_1.rlog.info("Aborting function execution and closing state machine due to connection error: " +
350
- e.message);
351
- this.unhandledError(e);
352
- }
353
- nextEntryWillBeReplayed() {
354
- return this.journal.nextEntryWillBeReplayed();
355
- }
356
- clearSuspensionTimeout() {
357
- if (this.suspensionTimeout !== undefined) {
358
- (0, timers_1.clearTimeout)(this.suspensionTimeout);
359
- this.suspensionTimeout = undefined;
360
- }
361
- }
362
- }
363
- exports.StateMachine = StateMachine;
364
- const wrapDeeply = (promise, cb) => {
365
- /* eslint-disable @typescript-eslint/no-explicit-any */
366
- return {
367
- transform: function (onfulfilled, onrejected) {
368
- return wrapDeeply(promise.then(onfulfilled, onrejected), cb);
369
- },
370
- then: function (onfulfilled, onrejected) {
371
- if (cb !== undefined) {
372
- cb();
373
- }
374
- return promise.then(onfulfilled, onrejected);
375
- },
376
- catch: function (onrejected) {
377
- return wrapDeeply(promise.catch(onrejected), cb);
378
- },
379
- finally: function (onfinally) {
380
- return wrapDeeply(promise.finally(onfinally), cb);
381
- },
382
- [Symbol.toStringTag]: "",
383
- };
384
- };
385
- //# sourceMappingURL=state_machine.js.map
@@ -1 +0,0 @@
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;IAwBJ;IACA;IACA;IACA;IA1BX,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;IAE3C,YACmB,U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