@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,133 +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.decodeMessagesBuffer = exports.decodeLambdaBody = exports.streamDecoder = void 0;
17
- // This is a NodeJs stream transformer. It is used to convert a chunked stream of bytes to
18
- // a stream of JavaScript objects of the form { header: .. , message: ..} where:
19
- // * header has some information about the frame like, the message type, and some flags.
20
- // * message is the Protobuf decoded message.
21
- //
22
- // To use this one would need to do the following:
23
- //
24
- // let decodedStream = stream.pipe(streamDecoder());
25
- //
26
- // at this point the decodedStream is a high level stream of objects {header, message}
27
- const stream_1 = __importDefault(require("stream"));
28
- const protocol_1 = require("../types/protocol");
29
- const types_1 = require("../types/types");
30
- const assert_1 = __importDefault(require("assert"));
31
- const errors_1 = require("../types/errors");
32
- const WAITING_FOR_HEADER = 0;
33
- const WAITING_FOR_BODY = 1;
34
- function initalDecoderState(buf) {
35
- return {
36
- state: WAITING_FOR_HEADER,
37
- header: undefined,
38
- buf,
39
- };
40
- }
41
- function appendBufferToDecoder(state, chunk) {
42
- state.buf = Buffer.concat([state.buf, chunk]);
43
- }
44
- function decodeMessages(decoderState, out) {
45
- let buf = decoderState.buf;
46
- while (buf.length > 0 || decoderState.state === WAITING_FOR_BODY) {
47
- switch (decoderState.state) {
48
- case WAITING_FOR_HEADER: {
49
- (0, assert_1.default)(decoderState.header === undefined);
50
- if (buf.length < 8) {
51
- decoderState.buf = buf;
52
- return decoderState;
53
- }
54
- const h = buf.readBigUInt64BE();
55
- buf = buf.subarray(8);
56
- decoderState.header = types_1.Header.fromU64be(h);
57
- decoderState.state = WAITING_FOR_BODY;
58
- break;
59
- }
60
- case WAITING_FOR_BODY: {
61
- const header = decoderState.header;
62
- (0, assert_1.default)(header !== undefined);
63
- if (buf.length < header.frameLength) {
64
- decoderState.buf = buf;
65
- return decoderState;
66
- }
67
- const frame = buf.subarray(0, header.frameLength);
68
- buf = buf.subarray(header.frameLength);
69
- decoderState.state = WAITING_FOR_HEADER;
70
- decoderState.header = undefined;
71
- const pbType = protocol_1.PROTOBUF_MESSAGE_BY_TYPE.get(header.messageType);
72
- if (pbType === undefined) {
73
- throw new Error("Got unknown message type " + header.messageType);
74
- }
75
- else {
76
- const message = pbType.decode(frame);
77
- out.push(new types_1.Message(header.messageType, message, header.completedFlag, header.protocolVersion, header.requiresAckFlag));
78
- }
79
- break;
80
- }
81
- }
82
- }
83
- decoderState.buf = buf;
84
- return decoderState;
85
- }
86
- function streamDecoder() {
87
- let decoderState = initalDecoderState(Buffer.alloc(0));
88
- return new stream_1.default.Transform({
89
- writableObjectMode: true,
90
- objectMode: true,
91
- transform(chunk, _encoding, cb) {
92
- try {
93
- appendBufferToDecoder(decoderState, chunk);
94
- decoderState = decodeMessages(decoderState, this);
95
- cb();
96
- }
97
- catch (e) {
98
- cb((0, errors_1.ensureError)(e), null);
99
- }
100
- },
101
- });
102
- }
103
- exports.streamDecoder = streamDecoder;
104
- // Decodes messages from Lambda requests to an array of headers + protocol messages
105
- const base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
106
- function decodeLambdaBody(msgBase64) {
107
- if (!base64regex.test(msgBase64)) {
108
- throw new Error("Cannot parse the lambda request body, body was not valid base64 encoded: " +
109
- msgBase64);
110
- }
111
- const buffer = Buffer.from(msgBase64, "base64");
112
- return decodeMessagesBuffer(buffer);
113
- }
114
- exports.decodeLambdaBody = decodeLambdaBody;
115
- function decodeMessagesBuffer(buffer) {
116
- const decodedEntries = [];
117
- let finalState;
118
- try {
119
- finalState = decodeMessages(initalDecoderState(buffer), decodedEntries);
120
- }
121
- catch (e) {
122
- const err = (0, errors_1.ensureError)(e);
123
- throw new Error("Cannot parse the lambda request body, message was not a valid sequence of Restate messages: " +
124
- err.message, { cause: err });
125
- }
126
- if (finalState.buf.length > 0) {
127
- throw new Error("Cannot parse the request body: Trailing data (incomplete message) in request body: " +
128
- finalState.buf.toString("hex"));
129
- }
130
- return decodedEntries;
131
- }
132
- exports.decodeMessagesBuffer = decodeMessagesBuffer;
133
- //# sourceMappingURL=decoder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decoder.js","sourceRoot":"","sources":["../../src/io/decoder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;AAEH,0FAA0F;AAC1F,gFAAgF;AAChF,wFAAwF;AACxF,6CAA6C;AAC7C,EAAE;AACF,kDAAkD;AAClD,EAAE;AACF,oDAAoD;AACpD,EAAE;AACF,sFAAsF;AAEtF,oDAA4B;AAC5B,gDAA6D;AAC7D,0CAAiD;AACjD,oDAA4B;AAC5B,4CAA8C;AAK9C,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,SAAS,kBAAkB,CAAC,GAAW;IACrC,OAAO;QACL,KAAK,EAAE,kBAAkB;QACzB,MAAM,EAAE,SAAS;QACjB,GAAG;KACJ,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAmB,EAAE,KAAa;IAC/D,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,cAAc,CAAC,YAA0B,EAAE,GAAW;IAC7D,IAAI,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC;IAE3B,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,YAAY,CAAC,KAAK,KAAK,gBAAgB,EAAE;QAChE,QAAQ,YAAY,CAAC,KAAK,EAAE;YAC1B,KAAK,kBAAkB,CAAC,CAAC;gBACvB,IAAA,gBAAM,EAAC,YAAY,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC;gBAC1C,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;oBAClB,YAAY,CAAC,GAAG,GAAG,GAAG,CAAC;oBACvB,OAAO,YAAY,CAAC;iBACrB;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AC,EAAE;QACV,MAAM,GAAG,GAAG,IAAA,oBAAW,EAAC,CAAC,CAAC,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,8FAA8F;YAC5F,GAAG,CAAC,OAAO,EACb,EAAE,KAAK,EAAE,GAAG,EAAE,CACf,CAAC;KACH;IAED,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;QAC7B,MAAM,IAAI,KAAK,CACb,qFAAqF;YACnF,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CACjC,CAAC;KACH;IAED,OAAO,cAAc,CAAC;AACxB,CAAC;AAtBD,oDAsBC"}
@@ -1,57 +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.encodeMessages = exports.encodeMessage = exports.streamEncoder = void 0;
17
- const stream_1 = __importDefault(require("stream"));
18
- const protocol_1 = require("../types/protocol");
19
- const types_1 = require("../types/types");
20
- function streamEncoder() {
21
- return new stream_1.default.Transform({
22
- writableObjectMode: true,
23
- objectMode: true,
24
- transform(msg, _encoding, cb) {
25
- // We do not catch errors here because we want them to be handled at the Connection level,
26
- // so we can close the state machine.
27
- const result = encodeMessage(msg);
28
- cb(null, result);
29
- },
30
- });
31
- }
32
- exports.streamEncoder = streamEncoder;
33
- function encodeMessage(msg) {
34
- return encodeMessages([msg]);
35
- }
36
- exports.encodeMessage = encodeMessage;
37
- function encodeMessages(messages) {
38
- const chunks = [];
39
- for (const message of messages) {
40
- const pbType = protocol_1.PROTOBUF_MESSAGE_BY_TYPE.get(BigInt(message.messageType));
41
- if (pbType === undefined) {
42
- throw new Error("Trying to encode a message with unknown message type " +
43
- message.messageType);
44
- }
45
- const bodyBuf = pbType.encode(message.message).finish();
46
- const header = new types_1.Header(BigInt(message.messageType), bodyBuf.length, message.completed, message.protocolVersion, // only set for incoming start message
47
- message.requiresAck);
48
- const encoded = header.toU64be();
49
- const headerBuf = Buffer.alloc(8);
50
- headerBuf.writeBigUInt64BE(encoded);
51
- chunks.push(headerBuf);
52
- chunks.push(bodyBuf);
53
- }
54
- return Buffer.concat(chunks);
55
- }
56
- exports.encodeMessages = encodeMessages;
57
- //# sourceMappingURL=encoder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encoder.js","sourceRoot":"","sources":["../../src/io/encoder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;AAEH,oDAA4B;AAC5B,gDAA6D;AAC7D,0CAAiD;AAEjD,SAAgB,aAAa;IAC3B,OAAO,IAAI,gBAAM,CAAC,SAAS,CAAC;QAC1B,kBAAkB,EAAE,IAAI;QACxB,UAAU,EAAE,IAAI;QAEhB,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE;YAC1B,0FAA0F;YAC1F,qCAAqC;YACrC,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;YAClC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnB,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAZD,sCAYC;AAED,SAAgB,aAAa,CAAC,GAAY;IACxC,OAAO,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAC/B,CAAC;AAFD,sCAEC;AAED,SAAgB,cAAc,CAAC,QAAmB;IAChD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;QAC9B,MAAM,MAAM,GAAG,mCAAwB,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;QACzE,IAAI,MAAM,KAAK,SAAS,EAAE;YACxB,MAAM,IAAI,KAAK,CACb,uDAAuD;gBACrD,OAAO,CAAC,WAAW,CACtB,CAAC;SACH;QACD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;QACxD,MAAM,MAAM,GAAG,IAAI,cAAM,CACvB,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAC3B,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,SAAS,EACjB,OAAO,CAAC,eAAe,EAAE,sCAAsC;QAC/D,OAAO,CAAC,WAAW,CACpB,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QACjC,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAClC,SAAS,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACpC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;KACtB;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC;AAzBD,wCAyBC"}
package/dist/journal.js DELETED
@@ -1,368 +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.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
@@ -1 +0,0 @@
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,Y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;IACL,CAAC;CACF;AAlBD,oCAkBC;AAED,qDAAqD;AACrD,sFAAsF;AACtF,kDAAkD;AAClD,uDAAuD;AACvD,4DAA4D;AAC5D,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,4CAAuB,CAAA;IACvB,8CAAyB,CAAA;IACzB,sCAAiB,CAAA;AACnB,CAAC,EAJW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAI5B"}
@@ -1,72 +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
- 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